From eb9d45e9065a94c93dc2f1624c22f026b9be3d5f Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 11 Aug 2013 19:18:06 +0200 Subject: Moved MaxPlayers and Description from cWorld to cServer. Also started creating a new cWorld::cTickThread class, but not used yet. --- source/Server.h | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'source/Server.h') diff --git a/source/Server.h b/source/Server.h index dd7a08735..44e20eec1 100644 --- a/source/Server.h +++ b/source/Server.h @@ -37,7 +37,18 @@ class cServer // tolua_export public: // tolua_export bool InitServer(cIniFile & a_SettingsIni); - bool IsConnected(void) const { return m_bIsConnected;} // returns connection status + // tolua_begin + + const AString & GetDescription(void) const {return m_Description; } + + // Player counts: + int GetMaxPlayers(void) const {return m_MaxPlayers; } + int GetNumPlayers(void) const { return m_NumPlayers; } + void SetMaxPlayers(int a_MaxPlayers) { m_MaxPlayers = a_MaxPlayers; } + + // tolua_end + + // bool IsConnected(void) const { return m_bIsConnected;} // returns connection status void BroadcastChat(const AString & a_Message, const cClientHandle * a_Exclude = NULL); // tolua_export @@ -131,6 +142,10 @@ private: cRCONServer m_RCONServer; + AString m_Description; + int m_MaxPlayers; + int m_NumPlayers; + cServer(void); ~cServer(); -- cgit v1.2.3 From c59d80a2af12d902577ea8cb022e81dd0740247f Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 11 Aug 2013 19:46:27 +0200 Subject: Removed cServer::m_pState, dissolved into direct member variables. The server tick thread is now in the cServer::cTickThread object. --- source/Server.h | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) (limited to 'source/Server.h') diff --git a/source/Server.h b/source/Server.h index 44e20eec1..983dc4de8 100644 --- a/source/Server.h +++ b/source/Server.h @@ -52,8 +52,6 @@ public: // tolua_export void BroadcastChat(const AString & a_Message, const cClientHandle * a_Exclude = NULL); // tolua_export - bool Tick(float a_Dt); - bool Start(void); bool Command(cClientHandle & a_Client, AString & a_Cmd); @@ -71,7 +69,7 @@ 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 - const AString & GetServerID(void) const; // tolua_export + const AString & GetServerID(void) const { return m_ServerID; } // tolua_export void ClientDestroying(const cClientHandle * a_Client); // Called by cClientHandle::Destroy(); stop m_SocketThreads from calling back into a_Client @@ -114,8 +112,22 @@ private: void NotifyClientWrite(const cClientHandle * a_Client); } ; - struct sServerState; - sServerState * m_pState; + /// The server tick thread takes care of the players who aren't yet spawned in a world + class cTickThread : + public cIsThread + { + typedef cIsThread super; + + public: + cTickThread(cServer & a_Server); + + protected: + cServer & m_Server; + + // cIsThread overrides: + virtual void Execute(void) override; + } ; + cNotifyWriteThread m_NotifyWriteThread; @@ -129,10 +141,6 @@ private: int m_ClientViewDistance; // The default view distance for clients; settable in Settings.ini - // Time since server was started - float m_Millisecondsf; - unsigned int m_Milliseconds; - bool m_bIsConnected; // true - connected false - not connected bool m_bRestarting; @@ -146,13 +154,20 @@ private: int m_MaxPlayers; int m_NumPlayers; + cTickThread m_TickThread; + cEvent m_RestartEvent; + + /// The server ID used for client authentication + AString m_ServerID; + cServer(void); - ~cServer(); /// Loads, or generates, if missing, RSA keys for protocol encryption void PrepareKeys(void); + bool Tick(float a_Dt); + // cListenThread::cCallback overrides: virtual void OnConnectionAccepted(cSocket & a_Socket) override; }; // tolua_export -- cgit v1.2.3 From 4c5590636cf4a311f03e735878557b1e7b3362dd Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 11 Aug 2013 20:16:41 +0200 Subject: Each world now ticks in a separate thread. --- source/Server.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/Server.h') diff --git a/source/Server.h b/source/Server.h index 983dc4de8..a00485fa2 100644 --- a/source/Server.h +++ b/source/Server.h @@ -62,7 +62,7 @@ public: // tolua_export /// Binds the built-in console commands with the plugin manager static void BindBuiltInConsoleCommands(void); - void Shutdown(); + void Shutdown(void); void SendMessage(const AString & a_Message, cPlayer * a_Player = NULL, bool a_bExclude = false ); // tolua_export -- cgit v1.2.3 From 6914bf4c65425172f3535b3a81936d7f75bdd42c Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 12 Aug 2013 07:55:53 +0200 Subject: Removed unused cServer::IsConnected() function. --- source/Server.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'source/Server.h') diff --git a/source/Server.h b/source/Server.h index a00485fa2..176c82a40 100644 --- a/source/Server.h +++ b/source/Server.h @@ -46,11 +46,9 @@ public: // tolua_export int GetNumPlayers(void) const { return m_NumPlayers; } void SetMaxPlayers(int a_MaxPlayers) { m_MaxPlayers = a_MaxPlayers; } - // tolua_end + void BroadcastChat(const AString & a_Message, const cClientHandle * a_Exclude = NULL); - // bool IsConnected(void) const { return m_bIsConnected;} // returns connection status - - void BroadcastChat(const AString & a_Message, const cClientHandle * a_Exclude = NULL); // tolua_export + // tolua_end bool Start(void); -- cgit v1.2.3 From c628ab03e9aae0b8e56f260ad02cfc7d51285a71 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 12 Aug 2013 08:35:13 +0200 Subject: Removed cServer::BroadcastChat() and cServer::SendMessage(). These two functions make it difficult to move to the new ticking system, and they aren't used anyway. If so required, they can be emulated by ForEachWorld / ForEachPlayer calls. --- source/Server.h | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'source/Server.h') diff --git a/source/Server.h b/source/Server.h index 176c82a40..fad7fc12a 100644 --- a/source/Server.h +++ b/source/Server.h @@ -46,8 +46,6 @@ public: // tolua_export int GetNumPlayers(void) const { return m_NumPlayers; } void SetMaxPlayers(int a_MaxPlayers) { m_MaxPlayers = a_MaxPlayers; } - void BroadcastChat(const AString & a_Message, const cClientHandle * a_Exclude = NULL); - // tolua_end bool Start(void); @@ -62,8 +60,6 @@ public: // tolua_export void Shutdown(void); - void SendMessage(const AString & a_Message, cPlayer * a_Player = NULL, bool a_bExclude = false ); // tolua_export - void KickUser(int a_ClientID, const AString & a_Reason); void AuthenticateUser(int a_ClientID); // Called by cAuthenticator to auth the specified user @@ -79,6 +75,9 @@ public: // tolua_export void RemoveClient(const cClientHandle * a_Client); // Removes the clienthandle from m_SocketThreads + /// Don't tick a_Client anymore, it will be ticked from its cPlayer instead + void ClientMovedToWorld(const cClientHandle * a_Client); + CryptoPP::RSA::PrivateKey & GetPrivateKey(void) { return m_PrivateKey; } CryptoPP::RSA::PublicKey & GetPublicKey (void) { return m_PublicKey; } @@ -132,8 +131,8 @@ private: cListenThread m_ListenThreadIPv4; cListenThread m_ListenThreadIPv6; - cCriticalSection m_CSClients; // Locks client list - cClientHandleList m_Clients; // Clients that are connected to the server + cCriticalSection m_CSClients; ///< Locks client list + cClientHandleList m_Clients; ///< Clients that are connected to the server and not yet assigned to a cWorld cSocketThreads m_SocketThreads; -- cgit v1.2.3 From 9020dc993241a4a90e8e98b3435d9b2576f313ea Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 13 Aug 2013 22:45:29 +0200 Subject: Clients are now ticked in cServer first, then in cWorld once they get assigned a world. --- source/Server.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'source/Server.h') diff --git a/source/Server.h b/source/Server.h index fad7fc12a..6f8576ece 100644 --- a/source/Server.h +++ b/source/Server.h @@ -131,8 +131,9 @@ private: cListenThread m_ListenThreadIPv4; cListenThread m_ListenThreadIPv6; - cCriticalSection m_CSClients; ///< Locks client list - cClientHandleList m_Clients; ///< Clients that are connected to the server and not yet assigned to a cWorld + cCriticalSection m_CSClients; ///< Locks client lists + cClientHandleList m_Clients; ///< Clients that are connected to the server and not yet assigned to a cWorld + cClientHandleList m_ClientsToRemove; ///< Clients that have just been moved into a world and are to be removed from m_Clients in the next Tick() cSocketThreads m_SocketThreads; @@ -164,6 +165,9 @@ private: void PrepareKeys(void); bool Tick(float a_Dt); + + /// Ticks the clients in m_Clients, manages the list in respect to removing clients + void TickClients(float a_Dt); // cListenThread::cCallback overrides: virtual void OnConnectionAccepted(cSocket & a_Socket) override; -- cgit v1.2.3 From 8c3837987bd5f74563790c15a1d52755383135ae Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 14 Aug 2013 10:24:34 +0200 Subject: Player counts are now properly handled. Fixes #80 --- source/Server.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'source/Server.h') diff --git a/source/Server.h b/source/Server.h index 6f8576ece..87e472465 100644 --- a/source/Server.h +++ b/source/Server.h @@ -43,7 +43,7 @@ public: // tolua_export // Player counts: int GetMaxPlayers(void) const {return m_MaxPlayers; } - int GetNumPlayers(void) const { return m_NumPlayers; } + int GetNumPlayers(void); void SetMaxPlayers(int a_MaxPlayers) { m_MaxPlayers = a_MaxPlayers; } // tolua_end @@ -78,6 +78,12 @@ public: // tolua_export /// Don't tick a_Client anymore, it will be ticked from its cPlayer instead void ClientMovedToWorld(const cClientHandle * a_Client); + /// Notifies the server that a player was created; the server uses this to adjust the number of players + void PlayerCreated(const cPlayer * a_Player); + + /// Notifies the server that a player was destroyed; the server uses this to adjust the number of players + void PlayerDestroyed(const cPlayer * a_Player); + CryptoPP::RSA::PrivateKey & GetPrivateKey(void) { return m_PrivateKey; } CryptoPP::RSA::PublicKey & GetPublicKey (void) { return m_PublicKey; } @@ -135,6 +141,11 @@ private: cClientHandleList m_Clients; ///< Clients that are connected to the server and not yet assigned to a cWorld cClientHandleList m_ClientsToRemove; ///< Clients that have just been moved into a world and are to be removed from m_Clients in the next Tick() + cCriticalSection m_CSPlayerCount; ///< Locks the m_PlayerCount + int m_PlayerCount; ///< Number of players currently playing in the server + cCriticalSection m_CSPlayerCountDiff; ///< Locks the m_PlayerCountDiff + int m_PlayerCountDiff; ///< Adjustment to m_PlayerCount to be applied in the Tick thread + cSocketThreads m_SocketThreads; int m_ClientViewDistance; // The default view distance for clients; settable in Settings.ini @@ -150,7 +161,6 @@ private: AString m_Description; int m_MaxPlayers; - int m_NumPlayers; cTickThread m_TickThread; cEvent m_RestartEvent; -- cgit v1.2.3 From 17b2353d71c405bc626de22e5467d13be792c317 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 14 Aug 2013 19:11:54 +0200 Subject: Server counts the players correctly. Was missing the PlayerDestroying() call, so players weren't removed from the playercount. --- source/Server.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source/Server.h') diff --git a/source/Server.h b/source/Server.h index 87e472465..b4fe81d8f 100644 --- a/source/Server.h +++ b/source/Server.h @@ -81,8 +81,8 @@ public: // tolua_export /// Notifies the server that a player was created; the server uses this to adjust the number of players void PlayerCreated(const cPlayer * a_Player); - /// Notifies the server that a player was destroyed; the server uses this to adjust the number of players - void PlayerDestroyed(const cPlayer * a_Player); + /// Notifies the server that a player is being destroyed; the server uses this to adjust the number of players + void PlayerDestroying(const cPlayer * a_Player); CryptoPP::RSA::PrivateKey & GetPrivateKey(void) { return m_PrivateKey; } CryptoPP::RSA::PublicKey & GetPublicKey (void) { return m_PublicKey; } -- cgit v1.2.3