From 28d8d8419a5b900e9d20ce91dc63e28349b6470a Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Mon, 4 Mar 2013 21:13:08 +0000 Subject: Moved client socket accepting into a separate thread object, cListenThread MCServer can now listen on multiple ports FS #312 git-svn-id: http://mc-server.googlecode.com/svn/trunk@1252 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/Server.h | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'source/Server.h') diff --git a/source/Server.h b/source/Server.h index 707f91261..ec91bb6c0 100644 --- a/source/Server.h +++ b/source/Server.h @@ -14,6 +14,7 @@ #include "OSSupport/SocketThreads.h" #include "CryptoPP/rsa.h" #include "CryptoPP/randpool.h" +#include "ListenThread.h" @@ -30,19 +31,18 @@ typedef std::list cClientHandleList; class cServer // tolua_export + : public cListenThread::cCallback { // tolua_export public: // tolua_export bool InitServer(cIniFile & a_SettingsIni); - int GetPort() { return m_iServerPort; } - bool IsConnected(){return m_bIsConnected;} // returns connection status - void StartListenClient(); // Listen to client - + bool IsConnected(void) const { return m_bIsConnected;} // returns connection status + void BroadcastChat(const AString & a_Message, const cClientHandle * a_Exclude = NULL); // tolua_export bool Tick(float a_Dt); - void StartListenThread(); + bool Start(void); bool Command(cClientHandle & a_Client, const AString & a_Cmd); void ExecuteConsoleCommand(const AString & a_Cmd); @@ -57,8 +57,6 @@ public: // tolua_export void KickUser(int a_ClientID, const AString & a_Reason); void AuthenticateUser(int a_ClientID); // Called by cAuthenticator to auth the specified user - static void ServerListenThread( void* a_Args ); - const AString & GetServerID(void) const; void ClientDestroying(const cClientHandle * a_Client); // Called by cClientHandle::Destroy(); stop m_SocketThreads from calling back into a_Client @@ -106,6 +104,7 @@ private: sServerState* m_pState; cNotifyWriteThread m_NotifyWriteThread; + cListenThread m_ListenThread; cCriticalSection m_CSClients; // Locks client list cClientHandleList m_Clients; // Clients that are connected to the server @@ -126,11 +125,14 @@ private: CryptoPP::RSA::PrivateKey m_PrivateKey; CryptoPP::RSA::PublicKey m_PublicKey; - cServer(); + cServer(void); ~cServer(); /// Loads, or generates, if missing, RSA keys for protocol encryption void PrepareKeys(void); + + // cListenThread::cCallback overrides: + virtual void OnConnectionAccepted(cSocket & a_Socket) override; }; // tolua_export -- cgit v1.2.3