summaryrefslogtreecommitdiffstats
path: root/source/Server.cpp
diff options
context:
space:
mode:
authormadmaxoft <github@xoft.cz>2013-08-14 10:24:34 +0200
committermadmaxoft <github@xoft.cz>2013-08-14 10:24:34 +0200
commit8c3837987bd5f74563790c15a1d52755383135ae (patch)
treeb91188a05d3a3053d5ad08cd7bb550c9d4b5518b /source/Server.cpp
parentExported cWorld:BroadcastChat() to the Lua API; used in the Core. (diff)
downloadcuberite-8c3837987bd5f74563790c15a1d52755383135ae.tar
cuberite-8c3837987bd5f74563790c15a1d52755383135ae.tar.gz
cuberite-8c3837987bd5f74563790c15a1d52755383135ae.tar.bz2
cuberite-8c3837987bd5f74563790c15a1d52755383135ae.tar.lz
cuberite-8c3837987bd5f74563790c15a1d52755383135ae.tar.xz
cuberite-8c3837987bd5f74563790c15a1d52755383135ae.tar.zst
cuberite-8c3837987bd5f74563790c15a1d52755383135ae.zip
Diffstat (limited to '')
-rw-r--r--source/Server.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/source/Server.cpp b/source/Server.cpp
index 31a1925a8..c01222e5a 100644
--- a/source/Server.cpp
+++ b/source/Server.cpp
@@ -172,10 +172,34 @@ void cServer::ClientMovedToWorld(const cClientHandle * a_Client)
+void cServer::PlayerCreated(const cPlayer * a_Player)
+{
+ // To avoid deadlocks, the player count is not handled directly, but rather posted onto the tick thread
+ cCSLock Lock(m_CSPlayerCountDiff);
+ m_PlayerCountDiff += 1;
+}
+
+
+
+
+
+void cServer::PlayerDestroyed(const cPlayer * a_Player)
+{
+ // To avoid deadlocks, the player count is not handled directly, but rather posted onto the tick thread
+ cCSLock Lock(m_CSPlayerCountDiff);
+ m_PlayerCountDiff -= 1;
+}
+
+
+
+
+
bool cServer::InitServer(cIniFile & a_SettingsIni)
{
m_Description = a_SettingsIni.GetValue ("Server", "Description", "MCServer! - In C++!").c_str();
m_MaxPlayers = a_SettingsIni.GetValueI("Server", "MaxPlayers", 100);
+ m_PlayerCount = 0;
+ m_PlayerCountDiff = 0;
if (m_bIsConnected)
{
@@ -254,6 +278,16 @@ bool cServer::InitServer(cIniFile & a_SettingsIni)
+int cServer::GetNumPlayers(void)
+{
+ cCSLock Lock(m_CSPlayerCount);
+ return m_PlayerCount;
+}
+
+
+
+
+
void cServer::PrepareKeys(void)
{
// TODO: Save and load key for persistence across sessions
@@ -310,6 +344,17 @@ void cServer::OnConnectionAccepted(cSocket & a_Socket)
bool cServer::Tick(float a_Dt)
{
+ // Apply the queued playercount adjustments (postponed to avoid deadlocks)
+ int PlayerCountDiff = 0;
+ {
+ cCSLock Lock(m_CSPlayerCountDiff);
+ std::swap(PlayerCountDiff, m_PlayerCountDiff);
+ }
+ {
+ cCSLock Lock(m_CSPlayerCount);
+ m_PlayerCount += PlayerCountDiff;
+ }
+
cRoot::Get()->TickCommands();
TickClients(a_Dt);