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, AString &&a_Username, const cUUID &a_UUID, Json::Value &&a_Properties)
 Authenticates the specified user, called by cAuthenticator supplying player details from Mojang. 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...
 
std::string_view GetCustomRedirectUrl (void)
 
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 AStringGetProxySharedSecret (void) const
 
ContiguousByteBufferView GetPublicKeyDER (void) const
 
const AStringMapGetRegisteredForgeMods (const UInt32 a_Protocol)
 Get the Forge mods (map of ModName -> ModVersionString) registered for a given protocol. More...
 
const AStringGetResourcePackUrl (void)
 
const AStringGetServerID (void) const
 
const AStringGetShutdownMessage (void) const
 
bool InitServer (cSettingsRepositoryInterface &a_Settings, bool a_ShouldAuth)
 
bool IsHardcore (void) const
 
bool IsPlayerInQueue (const 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)
 
bool OnlyAllowBungeeCord (void) const
 
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...
 
void QueueExecuteConsoleCommand (const AString &a_Cmd, cCommandOutputCallback &a_Output)
 Queues a console command for execution through the cServer class. 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 ScheduleTask (cTickTime a_DelayTicks, std::function< void(class cServer &)> a_Task)
 Queues a lambda task onto the server tick thread, with the specified delay in ticks. 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 ShouldRequireResourcePack (void)
 Returns true if clients must accept resource pack. 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)
 
void ExecuteConsoleCommand (const AString &a_Cmd, cCommandOutputCallback &a_Output)
 Executes the console command, sends output through the specified callback. More...
 
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...
 
void Tick (float a_Dt)
 
void TickClients (float a_Dt)
 Ticks the clients in m_Clients, manages the list in respect to removing clients. More...
 
void TickCommands (void)
 Executes commands queued in the command queue. More...
 
void TickQueuedTasks (void)
 Executes all tasks queued onto the tick thread. 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
 
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...
 
cCriticalSection m_CSPendingCommands
 
cCriticalSection m_CSTasks
 Guards the m_Tasks. More...
 
AString m_CustomRedirectUrl
 
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
 
bool m_OnlyAllowBungeeCord
 True if BungeeCord handshake packets should be the only ones accepted. More...
 
std::vector< std::pair< AString, cCommandOutputCallback * > > m_PendingCommands
 
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_ProxySharedSecret
 Security string that the proxy server should send, compatible with BungeeGuard. More...
 
ContiguousByteBuffer m_PublicKeyDER
 Public key for m_PrivateKey, ASN1-DER-encoded. More...
 
cRCONServer m_RCONServer
 
bool m_RequireResourcePack
 
AString m_ResourcePackUrl
 
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...
 
AString m_ShutdownMessage
 
std::vector< std::pair< std::chrono::milliseconds, std::function< void(class cServer &)> > > m_Tasks
 Tasks that have been queued onto the tick thread, possibly to be executed at target tick in the future; guarded by m_CSTasks. More...
 
cTickThread m_TickThread
 
cTickTimeLong m_UpTime
 Time, in ticks, since the server started Not persistent across server restarts. More...
 

Friends

class cRoot
 
class cServerListenCallbacks
 

Detailed Description

Definition at line 55 of file Server.h.

Constructor & Destructor Documentation

◆ ~cServer()

virtual cServer::~cServer ( )
inlinevirtual

Definition at line 60 of file Server.h.

◆ cServer()

cServer::cServer ( void  )
private

Definition at line 106 of file Server.cpp.

Member Function Documentation

◆ AuthenticateUser()

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

Authenticates the specified user, called by cAuthenticator supplying player details from Mojang.

Definition at line 715 of file Server.cpp.

◆ BindBuiltInConsoleCommands()

void cServer::BindBuiltInConsoleCommands ( void  )
static

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

Definition at line 636 of file Server.cpp.

◆ ClientMovedToWorld()

void cServer::ClientMovedToWorld ( const cClientHandle a_Client)

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

Definition at line 125 of file Server.cpp.

◆ Command()

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

Definition at line 429 of file Server.cpp.

◆ DoesAllowMultiLogin()

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.

◆ ExecuteConsoleCommand()

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

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

Definition at line 470 of file Server.cpp.

◆ GetCustomRedirectUrl()

std::string_view cServer::GetCustomRedirectUrl ( void  )
inline

Definition at line 102 of file Server.h.

◆ GetDescription()

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

Definition at line 65 of file Server.h.

◆ GetFaviconData()

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

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

Definition at line 141 of file Server.h.

◆ GetMaxPlayers()

size_t cServer::GetMaxPlayers ( void  ) const
inline

Definition at line 70 of file Server.h.

◆ GetNumPlayers()

size_t cServer::GetNumPlayers ( void  ) const
inline

Definition at line 71 of file Server.h.

◆ GetPrivateKey()

cRsaPrivateKey& cServer::GetPrivateKey ( void  )
inline

Definition at line 143 of file Server.h.

◆ GetProxySharedSecret()

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

Definition at line 159 of file Server.h.

◆ GetPublicKeyDER()

ContiguousByteBufferView cServer::GetPublicKeyDER ( void  ) const
inline

Definition at line 144 of file Server.h.

◆ GetRegisteredForgeMods()

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.

◆ GetResourcePackUrl()

const AString& cServer::GetResourcePackUrl ( void  )
inline

Definition at line 100 of file Server.h.

◆ GetServerID()

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

Definition at line 129 of file Server.h.

◆ GetShutdownMessage()

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

Definition at line 67 of file Server.h.

◆ InitServer()

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

Definition at line 153 of file Server.cpp.

◆ IsHardcore()

bool cServer::IsHardcore ( void  ) const
inline

Definition at line 93 of file Server.h.

◆ IsPlayerInQueue()

bool cServer::IsPlayerInQueue ( const 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.

◆ KickUser()

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

Definition at line 699 of file Server.cpp.

◆ OnConnectionAccepted()

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.

◆ OnlyAllowBungeeCord()

bool cServer::OnlyAllowBungeeCord ( void  ) const
inline

Definition at line 157 of file Server.h.

◆ PlayerCreated()

void cServer::PlayerCreated ( )

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

Definition at line 135 of file Server.cpp.

◆ PlayerDestroyed()

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 144 of file Server.cpp.

◆ PrepareKeys()

void cServer::PrepareKeys ( void  )
private

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

Definition at line 308 of file Server.cpp.

◆ PrintHelp()

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

Lists all available console commands and their helpstrings.

Definition at line 592 of file Server.cpp.

◆ QueueExecuteConsoleCommand()

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

Queues a console command for execution through the cServer class.

The command will be executed in the server tick thread. The command's output will be written to the a_Output callback.

Definition at line 445 of file Server.cpp.

◆ RegisteredForgeMods()

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.

◆ RegisterForgeMod()

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.

◆ ScheduleTask()

void cServer::ScheduleTask ( cTickTime  a_DelayTicks,
std::function< void(class cServer &)>  a_Task 
)

Queues a lambda task onto the server tick thread, with the specified delay in ticks.

Definition at line 456 of file Server.cpp.

◆ SetMaxPlayers()

void cServer::SetMaxPlayers ( size_t  a_MaxPlayers)
inline

Definition at line 72 of file Server.h.

◆ ShouldAllowBungeeCord()

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 155 of file Server.h.

◆ ShouldAllowMultiWorldTabCompletion()

bool cServer::ShouldAllowMultiWorldTabCompletion ( void  ) const
inline

Returns true if usernames should be completed across worlds.

This is read from the settings.

Definition at line 163 of file Server.h.

◆ ShouldAuthenticate()

bool cServer::ShouldAuthenticate ( void  ) const
inline

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

Definition at line 147 of file Server.h.

◆ ShouldLimitPlayerBlockChanges()

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 150 of file Server.h.

◆ ShouldRequireResourcePack()

bool cServer::ShouldRequireResourcePack ( void  )
inline

Returns true if clients must accept resource pack.

This is read from the settings.

Definition at line 98 of file Server.h.

◆ Shutdown()

void cServer::Shutdown ( void  )

Definition at line 671 of file Server.cpp.

◆ Start()

bool cServer::Start ( void  )

Definition at line 400 of file Server.cpp.

◆ Tick()

void cServer::Tick ( float  a_Dt)
private

Definition at line 332 of file Server.cpp.

◆ TickClients()

void cServer::TickClients ( float  a_Dt)
private

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

Definition at line 354 of file Server.cpp.

◆ TickCommands()

void cServer::TickCommands ( void  )
private

Executes commands queued in the command queue.

Definition at line 740 of file Server.cpp.

◆ TickQueuedTasks()

void cServer::TickQueuedTasks ( void  )
private

Executes all tasks queued onto the tick thread.

Definition at line 759 of file Server.cpp.

◆ UnregisterForgeMod()

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

◆ cRoot

friend class cRoot
friend

Definition at line 170 of file Server.h.

◆ cServerListenCallbacks

friend class cServerListenCallbacks
friend

Definition at line 171 of file Server.h.

Member Data Documentation

◆ m_bAllowMultiLogin

bool cServer::m_bAllowMultiLogin
private

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

Definition at line 237 of file Server.h.

◆ m_bIsConnected

bool cServer::m_bIsConnected
private

Definition at line 214 of file Server.h.

◆ m_bIsHardcore

bool cServer::m_bIsHardcore
private

Definition at line 228 of file Server.h.

◆ m_Clients

cClientHandlePtrs cServer::m_Clients
private

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

Definition at line 201 of file Server.h.

◆ m_ClientsToRemove

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 204 of file Server.h.

◆ m_ClientViewDistance

int cServer::m_ClientViewDistance
private

Definition at line 212 of file Server.h.

◆ m_CSClients

cCriticalSection cServer::m_CSClients
private

Protects m_Clients and m_ClientsToRemove against multithreaded access.

Definition at line 198 of file Server.h.

◆ m_CSPendingCommands

cCriticalSection cServer::m_CSPendingCommands
private

Definition at line 209 of file Server.h.

◆ m_CSTasks

cCriticalSection cServer::m_CSTasks
private

Guards the m_Tasks.

Definition at line 273 of file Server.h.

◆ m_CustomRedirectUrl

AString cServer::m_CustomRedirectUrl
private

Definition at line 231 of file Server.h.

◆ m_Description

AString cServer::m_Description
private

Definition at line 224 of file Server.h.

◆ m_FaviconData

AString cServer::m_FaviconData
private

Definition at line 226 of file Server.h.

◆ m_ForgeModsByVersion

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

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

Definition at line 234 of file Server.h.

◆ m_MaxPlayers

size_t cServer::m_MaxPlayers
private

Definition at line 227 of file Server.h.

◆ m_OnlyAllowBungeeCord

bool cServer::m_OnlyAllowBungeeCord
private

True if BungeeCord handshake packets should be the only ones accepted.

Definition at line 255 of file Server.h.

◆ m_PendingCommands

std::vector<std::pair<AString, cCommandOutputCallback *> > cServer::m_PendingCommands
private

Definition at line 210 of file Server.h.

◆ m_PlayerCount

std::atomic_size_t cServer::m_PlayerCount
private

Number of players currently playing in the server.

Definition at line 207 of file Server.h.

◆ m_Ports

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 265 of file Server.h.

◆ m_PrivateKey

cRsaPrivateKey cServer::m_PrivateKey
private

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

Definition at line 217 of file Server.h.

◆ m_ProxySharedSecret

AString cServer::m_ProxySharedSecret
private

Security string that the proxy server should send, compatible with BungeeGuard.

Definition at line 258 of file Server.h.

◆ m_PublicKeyDER

ContiguousByteBuffer cServer::m_PublicKeyDER
private

Public key for m_PrivateKey, ASN1-DER-encoded.

Definition at line 220 of file Server.h.

◆ m_RCONServer

cRCONServer cServer::m_RCONServer
private

Definition at line 222 of file Server.h.

◆ m_RequireResourcePack

bool cServer::m_RequireResourcePack
private

Definition at line 229 of file Server.h.

◆ m_ResourcePackUrl

AString cServer::m_ResourcePackUrl
private

Definition at line 230 of file Server.h.

◆ m_ServerHandles

cServerHandlePtrs cServer::m_ServerHandles
private

The network sockets listening for client connections.

Definition at line 195 of file Server.h.

◆ m_ServerID

AString cServer::m_ServerID
private

The server ID used for client authentication.

Definition at line 242 of file Server.h.

◆ m_ShouldAllowBungeeCord

bool cServer::m_ShouldAllowBungeeCord
private

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

Definition at line 252 of file Server.h.

◆ m_ShouldAllowMultiWorldTabCompletion

bool cServer::m_ShouldAllowMultiWorldTabCompletion
private

True if usernames should be completed across worlds.

Definition at line 261 of file Server.h.

◆ m_ShouldAuthenticate

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 246 of file Server.h.

◆ m_ShouldLimitPlayerBlockChanges

bool cServer::m_ShouldLimitPlayerBlockChanges
private

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

Definition at line 249 of file Server.h.

◆ m_ShutdownMessage

AString cServer::m_ShutdownMessage
private

Definition at line 225 of file Server.h.

◆ m_Tasks

std::vector<std::pair<std::chrono::milliseconds, std::function<void(class cServer &)> > > cServer::m_Tasks
private

Tasks that have been queued onto the tick thread, possibly to be executed at target tick in the future; guarded by m_CSTasks.

Definition at line 277 of file Server.h.

◆ m_TickThread

cTickThread cServer::m_TickThread
private

Definition at line 239 of file Server.h.

◆ m_UpTime

cTickTimeLong cServer::m_UpTime
private

Time, in ticks, since the server started Not persistent across server restarts.

Definition at line 270 of file Server.h.


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