1 /***************************************************************************
2                           networkthread.h  -  Listening to messages from clients
3                              -------------------
4     begin                : do jan 13 2005
5     copyright            : (C) 2005 by CJP
6     email                : cornware-cjp@users.sourceforge.net
7  ***************************************************************************/
8 
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  ***************************************************************************/
17 
18 #ifndef NETWORKTHREAD_H
19 #define NETWORKTHREAD_H
20 
21 #include "bthread.h"
22 #include "stuntsnet.h"
23 #include "client.h"
24 #include "criticalvector.h"
25 #include "uploadmanager.h"
26 
27 //Message types:
28 #include "chatmessage.h"
29 #include "textmessage.h"
30 #include "objectchoice.h"
31 
32 /**
33   *@author CJP
34   */
35 
36 class CNetworkThread : public CBThread  {
37 public:
38 	CNetworkThread();
39 	virtual ~CNetworkThread();
40 
41 	void setPort(unsigned int port);
getPort()42 	unsigned int getPort()
43 		{return m_Port;}
44 
45 	void setServerName(const CString &servername);
getServerName()46 	CString getServerName()
47 		{return m_ServerName;}
48 
49 	virtual void threadFunc();
50 
51 	//thrrad-safe sending of messages:
52 	void sendToClient(const CMessageBuffer &b, unsigned int ID);
53 	void sendToPlayer(const CMessageBuffer &b, unsigned int ID);
54 	void sendToAll(const CMessageBuffer &b);
55 	void sendToClient(const CString &s, unsigned int ID);
56 	void sendToPlayer(const CString &s, unsigned int ID);
57 	void sendToAll(const CString &s);
58 
getFPS()59 	float getFPS(){return m_FPS;}
60 protected:
61 	unsigned int m_Port;
62 	CString m_ServerName;
63 	CStuntsNet *m_Net;
64 
65 	CUploadManager m_UploadManager;
66 
67 	CCriticalVector<CMessageBuffer> m_OutputBuffer;
68 
69 
70 	int identify(const CIPNumber &ip, unsigned int port);
71 	void addClient(const CIPNumber &ip, unsigned int port);
72 
73 	Uint8 processMessage(const CMessageBuffer &buffer);
74 	Uint8 processMessage(int ID, const CString &message);
75 
76 	CTimer m_Timer; //for the FPS counter
77 	float m_FPS;
78 };
79 
80 #endif
81