2012-06-14 06:06:06 -07:00
// cServer.h
// Interfaces to the cServer object representing the network server
# pragma once
2012-09-23 14:23:33 -07:00
# include "OSSupport/SocketThreads.h"
2013-03-05 12:47:29 -08:00
# include "OSSupport/ListenThread.h"
2012-08-30 14:06:13 -07:00
# include "CryptoPP/rsa.h"
2012-09-04 03:17:27 -07:00
# include "CryptoPP/randpool.h"
2013-06-27 08:14:20 -07:00
# include "RCONServer.h"
2012-06-14 06:06:06 -07:00
class cPlayer ;
class cClientHandle ;
2012-11-11 06:23:47 -08:00
class cIniFile ;
2012-06-14 06:06:06 -07:00
typedef std : : list < cClientHandle * > cClientHandleList ;
2013-01-11 20:46:01 -08:00
class cServer // tolua_export
2013-03-04 13:13:08 -08:00
: public cListenThread : : cCallback
2013-01-11 20:46:01 -08:00
{ // tolua_export
public : // tolua_export
2012-11-11 06:23:47 -08:00
bool InitServer ( cIniFile & a_SettingsIni ) ;
2012-06-14 06:06:06 -07:00
2013-03-04 13:13:08 -08:00
bool IsConnected ( void ) const { return m_bIsConnected ; } // returns connection status
2013-02-15 05:00:59 -08:00
void BroadcastChat ( const AString & a_Message , const cClientHandle * a_Exclude = NULL ) ; // tolua_export
2012-06-14 06:06:06 -07:00
bool Tick ( float a_Dt ) ;
2013-03-04 13:13:08 -08:00
bool Start ( void ) ;
2012-06-14 06:06:06 -07:00
2013-06-22 12:08:34 -07:00
bool Command ( cClientHandle & a_Client , AString & a_Cmd ) ;
2013-02-15 05:00:59 -08:00
void ExecuteConsoleCommand ( const AString & a_Cmd ) ;
/// Binds the built-in console commands with the plugin manager
static void BindBuiltInConsoleCommands ( void ) ;
2012-06-14 06:06:06 -07:00
void Shutdown ( ) ;
2012-08-24 00:58:26 -07:00
void SendMessage ( const AString & a_Message , cPlayer * a_Player = NULL , bool a_bExclude = false ) ; // tolua_export
2012-06-14 06:06:06 -07:00
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 ;
void ClientDestroying ( const cClientHandle * a_Client ) ; // Called by cClientHandle::Destroy(); stop m_SocketThreads from calling back into a_Client
void NotifyClientWrite ( const cClientHandle * a_Client ) ; // Notifies m_SocketThreads that client has something to be written
2012-09-25 01:23:19 -07:00
void WriteToClient ( const cClientHandle * a_Client , const AString & a_Data ) ; // Queues outgoing data for the client through m_SocketThreads
2012-06-14 06:06:06 -07:00
2012-09-25 01:23:19 -07:00
void QueueClientClose ( const cClientHandle * a_Client ) ; // Queues the clienthandle to close when all its outgoing data is sent
2012-06-14 06:06:06 -07:00
2012-09-25 01:23:19 -07:00
void RemoveClient ( const cClientHandle * a_Client ) ; // Removes the clienthandle from m_SocketThreads
2012-06-14 06:06:06 -07:00
2012-08-30 14:06:13 -07:00
CryptoPP : : RSA : : PrivateKey & GetPrivateKey ( void ) { return m_PrivateKey ; }
CryptoPP : : RSA : : PublicKey & GetPublicKey ( void ) { return m_PublicKey ; }
2012-06-14 06:06:06 -07:00
private :
friend class cRoot ; // so cRoot can create and destroy cServer
/// When NotifyClientWrite() is called, it is queued for this thread to process (to avoid deadlocks between cSocketThreads, cClientHandle and cChunkMap)
class cNotifyWriteThread :
public cIsThread
{
typedef cIsThread super ;
cEvent m_Event ; // Set when m_Clients gets appended
cServer * m_Server ;
cCriticalSection m_CS ;
cClientHandleList m_Clients ;
virtual void Execute ( void ) ;
public :
cNotifyWriteThread ( void ) ;
~ cNotifyWriteThread ( ) ;
bool Start ( cServer * a_Server ) ;
void NotifyClientWrite ( const cClientHandle * a_Client ) ;
} ;
struct sServerState ;
2013-03-05 01:53:29 -08:00
sServerState * m_pState ;
2012-06-14 06:06:06 -07:00
cNotifyWriteThread m_NotifyWriteThread ;
2013-03-05 01:53:29 -08:00
2013-06-27 08:14:20 -07:00
cListenThread m_ListenThreadIPv4 ;
cListenThread m_ListenThreadIPv6 ;
2012-06-14 06:06:06 -07:00
cCriticalSection m_CSClients ; // Locks client list
2013-06-27 08:14:20 -07:00
cClientHandleList m_Clients ; // Clients that are connected to the server
2012-06-14 06:06:06 -07:00
cSocketThreads m_SocketThreads ;
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 ;
2012-08-30 14:06:13 -07:00
2013-06-27 08:14:20 -07:00
CryptoPP : : RSA : : PrivateKey m_PrivateKey ;
CryptoPP : : RSA : : PublicKey m_PublicKey ;
cRCONServer m_RCONServer ;
2012-06-14 06:06:06 -07:00
2013-03-04 13:13:08 -08:00
cServer ( void ) ;
2012-06-14 06:06:06 -07:00
~ cServer ( ) ;
2012-08-30 14:06:13 -07:00
/// Loads, or generates, if missing, RSA keys for protocol encryption
void PrepareKeys ( void ) ;
2013-03-04 13:13:08 -08:00
// cListenThread::cCallback overrides:
virtual void OnConnectionAccepted ( cSocket & a_Socket ) override ;
2013-01-11 20:46:01 -08:00
} ; // tolua_export
2012-06-14 06:06:06 -07:00