Cuberite
A lightweight, fast and extensible game server for Minecraft
Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
cServer Class Reference

#include <Server.h>

Collaboration diagram for cServer:
Collaboration graph
[legend]

Classes

class  cTickThread
 The server tick thread takes care of the players who aren't yet spawned in a world. More...
 

Public Member Functions

void AuthenticateUser (int a_ClientID, const AString &a_Name, const cUUID &a_UUID, const Json::Value &a_Properties)
 Authenticates the specified user, called by cAuthenticator. More...
 
void ClientMovedToWorld (const cClientHandle *a_Client)
 Don't tick a_Client anymore, it will be ticked from its cPlayer instead. More...
 
bool Command (cClientHandle &a_Client, AString &a_Cmd)
 
bool DoesAllowMultiLogin (void)
 Can login more than once with same username. More...
 
void ExecuteConsoleCommand (const AString &a_Cmd, cCommandOutputCallback &a_Output)
 Executes the console command, sends output through the specified callback. More...
 
const AStringGetDescription (void) const
 
const AStringGetFaviconData (void) const
 Returns base64 encoded favicon data (obtained from favicon.png) More...
 
size_t GetMaxPlayers (void) const
 
size_t GetNumPlayers (void) const
 
cRsaPrivateKeyGetPrivateKey (void)
 
const AStringGetPublicKeyDER (void) const
 
const AStringMapGetRegisteredForgeMods (const UInt32 a_Protocol)
 Get the Forge mods (map of ModName -> ModVersionString) registered for a given protocol. More...
 
const AStringGetServerID (void) const
 
const AStringGetShutdownMessage (void) const
 
bool InitServer (cSettingsRepositoryInterface &a_Settings, bool a_ShouldAuth)
 
bool IsHardcore (void) const
 
bool IsPlayerInQueue (AString a_Username)
 Check if the player is queued to be transferred to a World. More...
 
void KickUser (int a_ClientID, const AString &a_Reason)
 
void PlayerCreated ()
 Notifies the server that a player was created; the server uses this to adjust the number of players. More...
 
void PlayerDestroyed ()
 Notifies the server that a player is being destroyed; the server uses this to adjust the number of players. More...
 
void PrintHelp (const AStringVector &a_Split, cCommandOutputCallback &a_Output)
 Lists all available console commands and their helpstrings. More...
 
bool RegisterForgeMod (const AString &a_ModName, const AString &a_ModVersion, UInt32 a_ProtocolVersionNumber)
 Add a Forge mod to the server ping list. More...
 
void SetMaxPlayers (size_t a_MaxPlayers)
 
bool ShouldAllowBungeeCord (void) const
 Returns true if BungeeCord logins (that specify the player's UUID) are allowed. More...
 
bool ShouldAllowMultiWorldTabCompletion (void) const
 Returns true if usernames should be completed across worlds. More...
 
bool ShouldAuthenticate (void) const
 Returns true if authentication has been turned on in server settings. More...
 
bool ShouldLimitPlayerBlockChanges (void) const
 Returns true if limit for number of block changes per tick by a player has been turned on in server settings. More...
 
bool ShouldLoadNamedPlayerData (void) const
 Returns true if old-style playernames should be used to load data for players whose regular datafiles cannot be found. More...
 
bool ShouldLoadOfflinePlayerData (void) const
 Returns true if offline UUIDs should be used to load data for players whose normal UUIDs cannot be found. More...
 
void Shutdown (void)
 
bool Start (void)
 
void UnregisterForgeMod (const AString &a_ModName, UInt32 a_ProtocolVersionNumber)
 Remove a Forge mod to the server ping list. More...
 
virtual ~cServer ()
 

Static Public Member Functions

static void BindBuiltInConsoleCommands (void)
 Binds the built-in console commands with the plugin manager. More...
 

Private Member Functions

 cServer (void)
 
cTCPLink::cCallbacksPtr OnConnectionAccepted (const AString &a_RemoteIPAddress)
 Creates a new cClientHandle instance and adds it to the list of clients. More...
 
void PrepareKeys (void)
 Loads, or generates, if missing, RSA keys for protocol encryption. More...
 
AStringMapRegisteredForgeMods (const UInt32 a_Protocol)
 Get the Forge mods registered for a given protocol, for modification. More...
 
bool Tick (float a_Dt)
 
void TickClients (float a_Dt)
 Ticks the clients in m_Clients, manages the list in respect to removing clients. More...
 

Private Attributes

bool m_bAllowMultiLogin
 True - allow same username to login more than once False - only once. More...
 
bool m_bIsConnected
 
bool m_bIsHardcore
 
std::atomic< bool > m_bRestarting
 
cClientHandlePtrs m_Clients
 Clients that are connected to the server and not yet assigned to a cWorld. More...
 
cClientHandles m_ClientsToRemove
 Clients that have just been moved into a world and are to be removed from m_Clients in the next Tick(). More...
 
int m_ClientViewDistance
 
cCriticalSection m_CSClients
 Protects m_Clients and m_ClientsToRemove against multithreaded access. More...
 
AString m_Description
 
AString m_FaviconData
 
std::map< UInt32, AStringMapm_ForgeModsByVersion
 Map of protocol version to Forge mods (map of ModName -> ModVersionString) More...
 
size_t m_MaxPlayers
 
std::atomic_size_t m_PlayerCount
 Number of players currently playing in the server. More...
 
AStringVector m_Ports
 The list of ports on which the server should listen for connections. More...
 
cRsaPrivateKey m_PrivateKey
 The private key used for the assymetric encryption start in the protocols. More...
 
AString m_PublicKeyDER
 Public key for m_PrivateKey, ASN1-DER-encoded. More...
 
cRCONServer m_RCONServer
 
cEvent m_RestartEvent
 
cServerHandlePtrs m_ServerHandles
 The network sockets listening for client connections. More...
 
AString m_ServerID
 The server ID used for client authentication. More...
 
bool m_ShouldAllowBungeeCord
 True if BungeeCord handshake packets (with player UUID) should be accepted. More...
 
bool m_ShouldAllowMultiWorldTabCompletion
 True if usernames should be completed across worlds. More...
 
bool m_ShouldAuthenticate
 If true, players will be online-authenticated agains Mojang servers. More...
 
bool m_ShouldLimitPlayerBlockChanges
 True if limit for number of block changes per tick by a player should be enabled. More...
 
bool m_ShouldLoadNamedPlayerData
 True if old-style playernames should be used to load data for players whose regular datafiles cannot be found. More...
 
bool m_ShouldLoadOfflinePlayerData
 True if offline UUIDs should be used to load data for players whose normal UUIDs cannot be found. More...
 
AString m_ShutdownMessage
 
cTickThread m_TickThread
 

Friends

class cRoot
 
class cServerListenCallbacks
 

Detailed Description

Definition at line 55 of file Server.h.

Constructor & Destructor Documentation

virtual cServer::~cServer ( )
inlinevirtual

Definition at line 60 of file Server.h.

cServer::cServer ( void  )
private

Definition at line 117 of file Server.cpp.

Member Function Documentation

void cServer::AuthenticateUser ( int  a_ClientID,
const AString a_Name,
const cUUID a_UUID,
const Json::Value &  a_Properties 
)

Authenticates the specified user, called by cAuthenticator.

Definition at line 672 of file Server.cpp.

void cServer::BindBuiltInConsoleCommands ( void  )
static

Binds the built-in console commands with the plugin manager.

Definition at line 594 of file Server.cpp.

void cServer::ClientMovedToWorld ( const cClientHandle a_Client)

Don't tick a_Client anymore, it will be ticked from its cPlayer instead.

Definition at line 138 of file Server.cpp.

bool cServer::Command ( cClientHandle a_Client,
AString a_Cmd 
)

Definition at line 435 of file Server.cpp.

bool cServer::DoesAllowMultiLogin ( void  )
inline

Can login more than once with same username.

Returns false if it is not allowed, true otherwise.

Definition at line 90 of file Server.h.

void cServer::ExecuteConsoleCommand ( const AString a_Cmd,
cCommandOutputCallback a_Output 
)

Executes the console command, sends output through the specified callback.

Definition at line 444 of file Server.cpp.

const AString& cServer::GetDescription ( void  ) const
inline

Definition at line 65 of file Server.h.

const AString& cServer::GetFaviconData ( void  ) const
inline

Returns base64 encoded favicon data (obtained from favicon.png)

Definition at line 129 of file Server.h.

size_t cServer::GetMaxPlayers ( void  ) const
inline

Definition at line 70 of file Server.h.

size_t cServer::GetNumPlayers ( void  ) const
inline

Definition at line 71 of file Server.h.

cRsaPrivateKey& cServer::GetPrivateKey ( void  )
inline

Definition at line 131 of file Server.h.

const AString& cServer::GetPublicKeyDER ( void  ) const
inline

Definition at line 132 of file Server.h.

const AStringMap & cServer::GetRegisteredForgeMods ( const UInt32  a_Protocol)

Get the Forge mods (map of ModName -> ModVersionString) registered for a given protocol.

Definition at line 282 of file Server.cpp.

const AString& cServer::GetServerID ( void  ) const
inline

Definition at line 117 of file Server.h.

const AString& cServer::GetShutdownMessage ( void  ) const
inline

Definition at line 67 of file Server.h.

bool cServer::InitServer ( cSettingsRepositoryInterface a_Settings,
bool  a_ShouldAuth 
)

Definition at line 166 of file Server.cpp.

bool cServer::IsHardcore ( void  ) const
inline

Definition at line 93 of file Server.h.

bool cServer::IsPlayerInQueue ( AString  a_Username)

Check if the player is queued to be transferred to a World.

Returns true is Player is found in queue.

Definition at line 291 of file Server.cpp.

void cServer::KickUser ( int  a_ClientID,
const AString a_Reason 
)

Definition at line 656 of file Server.cpp.

cTCPLink::cCallbacksPtr cServer::OnConnectionAccepted ( const AString a_RemoteIPAddress)
private

Creates a new cClientHandle instance and adds it to the list of clients.

Returns the cClientHandle reinterpreted as cTCPLink callbacks.

Definition at line 319 of file Server.cpp.

void cServer::PlayerCreated ( )

Notifies the server that a player was created; the server uses this to adjust the number of players.

Definition at line 148 of file Server.cpp.

void cServer::PlayerDestroyed ( )

Notifies the server that a player is being destroyed; the server uses this to adjust the number of players.

Definition at line 157 of file Server.cpp.

void cServer::PrepareKeys ( void  )
private

Loads, or generates, if missing, RSA keys for protocol encryption.

Definition at line 308 of file Server.cpp.

void cServer::PrintHelp ( const AStringVector a_Split,
cCommandOutputCallback a_Output 
)

Lists all available console commands and their helpstrings.

Definition at line 551 of file Server.cpp.

AStringMap & cServer::RegisteredForgeMods ( const UInt32  a_Protocol)
private

Get the Forge mods registered for a given protocol, for modification.

Definition at line 264 of file Server.cpp.

bool cServer::RegisterForgeMod ( const AString a_ModName,
const AString a_ModVersion,
UInt32  a_ProtocolVersionNumber 
)

Add a Forge mod to the server ping list.

Definition at line 238 of file Server.cpp.

void cServer::SetMaxPlayers ( size_t  a_MaxPlayers)
inline

Definition at line 72 of file Server.h.

bool cServer::ShouldAllowBungeeCord ( void  ) const
inline

Returns true if BungeeCord logins (that specify the player's UUID) are allowed.

Read from settings, admins should set this to true only when they chain to BungeeCord, it makes the server vulnerable to identity theft through direct connections.

Definition at line 152 of file Server.h.

bool cServer::ShouldAllowMultiWorldTabCompletion ( void  ) const
inline

Returns true if usernames should be completed across worlds.

This is read from the settings.

Definition at line 156 of file Server.h.

bool cServer::ShouldAuthenticate ( void  ) const
inline

Returns true if authentication has been turned on in server settings.

Definition at line 135 of file Server.h.

bool cServer::ShouldLimitPlayerBlockChanges ( void  ) const
inline

Returns true if limit for number of block changes per tick by a player has been turned on in server settings.

Definition at line 138 of file Server.h.

bool cServer::ShouldLoadNamedPlayerData ( void  ) const
inline

Returns true if old-style playernames should be used to load data for players whose regular datafiles cannot be found.

This allows a seamless transition from name-based to UUID-based player storage. Loaded from the settings.ini [PlayerData].LoadNamedPlayerData setting.

Definition at line 147 of file Server.h.

bool cServer::ShouldLoadOfflinePlayerData ( void  ) const
inline

Returns true if offline UUIDs should be used to load data for players whose normal UUIDs cannot be found.

Loaded from the settings.ini [PlayerData].LoadOfflinePlayerData setting.

Definition at line 142 of file Server.h.

void cServer::Shutdown ( void  )

Definition at line 628 of file Server.cpp.

bool cServer::Start ( void  )

Definition at line 403 of file Server.cpp.

bool cServer::Tick ( float  a_Dt)
private

Definition at line 333 of file Server.cpp.

void cServer::TickClients ( float  a_Dt)
private

Ticks the clients in m_Clients, manages the list in respect to removing clients.

Definition at line 360 of file Server.cpp.

void cServer::UnregisterForgeMod ( const AString a_ModName,
UInt32  a_ProtocolVersionNumber 
)

Remove a Forge mod to the server ping list.

Definition at line 249 of file Server.cpp.

Friends And Related Function Documentation

friend class cRoot
friend

Definition at line 163 of file Server.h.

friend class cServerListenCallbacks
friend

Definition at line 164 of file Server.h.

Member Data Documentation

bool cServer::m_bAllowMultiLogin
private

True - allow same username to login more than once False - only once.

Definition at line 222 of file Server.h.

bool cServer::m_bIsConnected
private

Definition at line 200 of file Server.h.

bool cServer::m_bIsHardcore
private

Definition at line 216 of file Server.h.

std::atomic<bool> cServer::m_bRestarting
private

Definition at line 202 of file Server.h.

cClientHandlePtrs cServer::m_Clients
private

Clients that are connected to the server and not yet assigned to a cWorld.

Definition at line 190 of file Server.h.

cClientHandles cServer::m_ClientsToRemove
private

Clients that have just been moved into a world and are to be removed from m_Clients in the next Tick().

Definition at line 193 of file Server.h.

int cServer::m_ClientViewDistance
private

Definition at line 198 of file Server.h.

cCriticalSection cServer::m_CSClients
private

Protects m_Clients and m_ClientsToRemove against multithreaded access.

Definition at line 187 of file Server.h.

AString cServer::m_Description
private

Definition at line 212 of file Server.h.

AString cServer::m_FaviconData
private

Definition at line 214 of file Server.h.

std::map<UInt32, AStringMap> cServer::m_ForgeModsByVersion
private

Map of protocol version to Forge mods (map of ModName -> ModVersionString)

Definition at line 219 of file Server.h.

size_t cServer::m_MaxPlayers
private

Definition at line 215 of file Server.h.

std::atomic_size_t cServer::m_PlayerCount
private

Number of players currently playing in the server.

Definition at line 196 of file Server.h.

AStringVector cServer::m_Ports
private

The list of ports on which the server should listen for connections.

Initialized in InitServer(), used in Start().

Definition at line 255 of file Server.h.

cRsaPrivateKey cServer::m_PrivateKey
private

The private key used for the assymetric encryption start in the protocols.

Definition at line 205 of file Server.h.

AString cServer::m_PublicKeyDER
private

Public key for m_PrivateKey, ASN1-DER-encoded.

Definition at line 208 of file Server.h.

cRCONServer cServer::m_RCONServer
private

Definition at line 210 of file Server.h.

cEvent cServer::m_RestartEvent
private

Definition at line 225 of file Server.h.

cServerHandlePtrs cServer::m_ServerHandles
private

The network sockets listening for client connections.

Definition at line 184 of file Server.h.

AString cServer::m_ServerID
private

The server ID used for client authentication.

Definition at line 228 of file Server.h.

bool cServer::m_ShouldAllowBungeeCord
private

True if BungeeCord handshake packets (with player UUID) should be accepted.

Definition at line 248 of file Server.h.

bool cServer::m_ShouldAllowMultiWorldTabCompletion
private

True if usernames should be completed across worlds.

Definition at line 251 of file Server.h.

bool cServer::m_ShouldAuthenticate
private

If true, players will be online-authenticated agains Mojang servers.

This setting is the same as the "online-mode" setting in Vanilla.

Definition at line 232 of file Server.h.

bool cServer::m_ShouldLimitPlayerBlockChanges
private

True if limit for number of block changes per tick by a player should be enabled.

Definition at line 235 of file Server.h.

bool cServer::m_ShouldLoadNamedPlayerData
private

True if old-style playernames should be used to load data for players whose regular datafiles cannot be found.

This allows a seamless transition from name-based to UUID-based player storage. Loaded from the settings.ini [PlayerData].LoadNamedPlayerData setting.

Definition at line 245 of file Server.h.

bool cServer::m_ShouldLoadOfflinePlayerData
private

True if offline UUIDs should be used to load data for players whose normal UUIDs cannot be found.

This allows transitions from an offline (no-auth) server to an online one. Loaded from the settings.ini [PlayerData].LoadOfflinePlayerData setting.

Definition at line 240 of file Server.h.

AString cServer::m_ShutdownMessage
private

Definition at line 213 of file Server.h.

cTickThread cServer::m_TickThread
private

Definition at line 224 of file Server.h.


The documentation for this class was generated from the following files: