summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormadmaxoft <github@xoft.cz>2013-08-11 19:18:06 +0200
committermadmaxoft <github@xoft.cz>2013-08-11 19:18:06 +0200
commiteb9d45e9065a94c93dc2f1624c22f026b9be3d5f (patch)
treee88be00ec679f95f23199a7056166ef792d74cf7
parentAdded doxyComments for cIsThread. (diff)
downloadcuberite-eb9d45e9065a94c93dc2f1624c22f026b9be3d5f.tar
cuberite-eb9d45e9065a94c93dc2f1624c22f026b9be3d5f.tar.gz
cuberite-eb9d45e9065a94c93dc2f1624c22f026b9be3d5f.tar.bz2
cuberite-eb9d45e9065a94c93dc2f1624c22f026b9be3d5f.tar.lz
cuberite-eb9d45e9065a94c93dc2f1624c22f026b9be3d5f.tar.xz
cuberite-eb9d45e9065a94c93dc2f1624c22f026b9be3d5f.tar.zst
cuberite-eb9d45e9065a94c93dc2f1624c22f026b9be3d5f.zip
-rw-r--r--source/Bindings.cpp235
-rw-r--r--source/Bindings.h2
-rw-r--r--source/ClientHandle.cpp14
-rw-r--r--source/Protocol/ProtocolRecognizer.cpp17
-rw-r--r--source/Server.cpp64
-rw-r--r--source/Server.h17
-rw-r--r--source/World.cpp73
-rw-r--r--source/World.h38
8 files changed, 274 insertions, 186 deletions
diff --git a/source/Bindings.cpp b/source/Bindings.cpp
index fb532b6f2..ca6b42902 100644
--- a/source/Bindings.cpp
+++ b/source/Bindings.cpp
@@ -1,6 +1,6 @@
/*
** Lua binding: AllToLua
-** Generated automatically by tolua++-1.0.92 on 08/11/13 14:53:45.
+** Generated automatically by tolua++-1.0.92 on 08/11/13 19:12:37.
*/
#ifndef __cplusplus
@@ -11306,6 +11306,135 @@ static int tolua_get_cPlugin_NewLua___cWebPlugin__(lua_State* tolua_S)
}
#endif //#ifndef TOLUA_DISABLE
+/* method: GetDescription of class cServer */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cServer_GetDescription00
+static int tolua_AllToLua_cServer_GetDescription00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"const cServer",0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,2,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ const cServer* self = (const cServer*) tolua_tousertype(tolua_S,1,0);
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetDescription'", NULL);
+#endif
+ {
+ const AString tolua_ret = (const AString) self->GetDescription();
+ tolua_pushcppstring(tolua_S,(const char*)tolua_ret);
+ }
+ }
+ return 1;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'GetDescription'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* method: GetMaxPlayers of class cServer */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cServer_GetMaxPlayers00
+static int tolua_AllToLua_cServer_GetMaxPlayers00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"const cServer",0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,2,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ const cServer* self = (const cServer*) tolua_tousertype(tolua_S,1,0);
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetMaxPlayers'", NULL);
+#endif
+ {
+ int tolua_ret = (int) self->GetMaxPlayers();
+ tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
+ }
+ }
+ return 1;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'GetMaxPlayers'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* method: GetNumPlayers of class cServer */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cServer_GetNumPlayers00
+static int tolua_AllToLua_cServer_GetNumPlayers00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"const cServer",0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,2,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ const cServer* self = (const cServer*) tolua_tousertype(tolua_S,1,0);
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetNumPlayers'", NULL);
+#endif
+ {
+ int tolua_ret = (int) self->GetNumPlayers();
+ tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
+ }
+ }
+ return 1;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'GetNumPlayers'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* method: SetMaxPlayers of class cServer */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cServer_SetMaxPlayers00
+static int tolua_AllToLua_cServer_SetMaxPlayers00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"cServer",0,&tolua_err) ||
+ !tolua_isnumber(tolua_S,2,0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,3,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ cServer* self = (cServer*) tolua_tousertype(tolua_S,1,0);
+ int a_MaxPlayers = ((int) tolua_tonumber(tolua_S,2,0));
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'SetMaxPlayers'", NULL);
+#endif
+ {
+ self->SetMaxPlayers(a_MaxPlayers);
+ }
+ }
+ return 0;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'SetMaxPlayers'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
/* method: BroadcastChat of class cServer */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cServer_BroadcastChat00
static int tolua_AllToLua_cServer_BroadcastChat00(lua_State* tolua_S)
@@ -11954,103 +12083,6 @@ static int tolua_AllToLua_cWorld_UnloadUnusedChunks00(lua_State* tolua_S)
}
#endif //#ifndef TOLUA_DISABLE
-/* method: GetMaxPlayers of class cWorld */
-#ifndef TOLUA_DISABLE_tolua_AllToLua_cWorld_GetMaxPlayers00
-static int tolua_AllToLua_cWorld_GetMaxPlayers00(lua_State* tolua_S)
-{
-#ifndef TOLUA_RELEASE
- tolua_Error tolua_err;
- if (
- !tolua_isusertype(tolua_S,1,"const cWorld",0,&tolua_err) ||
- !tolua_isnoobj(tolua_S,2,&tolua_err)
- )
- goto tolua_lerror;
- else
-#endif
- {
- const cWorld* self = (const cWorld*) tolua_tousertype(tolua_S,1,0);
-#ifndef TOLUA_RELEASE
- if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetMaxPlayers'", NULL);
-#endif
- {
- unsigned int tolua_ret = (unsigned int) self->GetMaxPlayers();
- tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
- }
- }
- return 1;
-#ifndef TOLUA_RELEASE
- tolua_lerror:
- tolua_error(tolua_S,"#ferror in function 'GetMaxPlayers'.",&tolua_err);
- return 0;
-#endif
-}
-#endif //#ifndef TOLUA_DISABLE
-
-/* method: SetMaxPlayers of class cWorld */
-#ifndef TOLUA_DISABLE_tolua_AllToLua_cWorld_SetMaxPlayers00
-static int tolua_AllToLua_cWorld_SetMaxPlayers00(lua_State* tolua_S)
-{
-#ifndef TOLUA_RELEASE
- tolua_Error tolua_err;
- if (
- !tolua_isusertype(tolua_S,1,"cWorld",0,&tolua_err) ||
- !tolua_isnumber(tolua_S,2,0,&tolua_err) ||
- !tolua_isnoobj(tolua_S,3,&tolua_err)
- )
- goto tolua_lerror;
- else
-#endif
- {
- cWorld* self = (cWorld*) tolua_tousertype(tolua_S,1,0);
- int iMax = ((int) tolua_tonumber(tolua_S,2,0));
-#ifndef TOLUA_RELEASE
- if (!self) tolua_error(tolua_S,"invalid 'self' in function 'SetMaxPlayers'", NULL);
-#endif
- {
- self->SetMaxPlayers(iMax);
- }
- }
- return 0;
-#ifndef TOLUA_RELEASE
- tolua_lerror:
- tolua_error(tolua_S,"#ferror in function 'SetMaxPlayers'.",&tolua_err);
- return 0;
-#endif
-}
-#endif //#ifndef TOLUA_DISABLE
-
-/* method: GetNumPlayers of class cWorld */
-#ifndef TOLUA_DISABLE_tolua_AllToLua_cWorld_GetNumPlayers00
-static int tolua_AllToLua_cWorld_GetNumPlayers00(lua_State* tolua_S)
-{
-#ifndef TOLUA_RELEASE
- tolua_Error tolua_err;
- if (
- !tolua_isusertype(tolua_S,1,"cWorld",0,&tolua_err) ||
- !tolua_isnoobj(tolua_S,2,&tolua_err)
- )
- goto tolua_lerror;
- else
-#endif
- {
- cWorld* self = (cWorld*) tolua_tousertype(tolua_S,1,0);
-#ifndef TOLUA_RELEASE
- if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetNumPlayers'", NULL);
-#endif
- {
- unsigned int tolua_ret = (unsigned int) self->GetNumPlayers();
- tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
- }
- }
- return 1;
-#ifndef TOLUA_RELEASE
- tolua_lerror:
- tolua_error(tolua_S,"#ferror in function 'GetNumPlayers'.",&tolua_err);
- return 0;
-#endif
-}
-#endif //#ifndef TOLUA_DISABLE
-
/* method: RegenerateChunk of class cWorld */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cWorld_RegenerateChunk00
static int tolua_AllToLua_cWorld_RegenerateChunk00(lua_State* tolua_S)
@@ -29783,6 +29815,10 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_endmodule(tolua_S);
tolua_cclass(tolua_S,"cServer","cServer","",NULL);
tolua_beginmodule(tolua_S,"cServer");
+ tolua_function(tolua_S,"GetDescription",tolua_AllToLua_cServer_GetDescription00);
+ tolua_function(tolua_S,"GetMaxPlayers",tolua_AllToLua_cServer_GetMaxPlayers00);
+ tolua_function(tolua_S,"GetNumPlayers",tolua_AllToLua_cServer_GetNumPlayers00);
+ tolua_function(tolua_S,"SetMaxPlayers",tolua_AllToLua_cServer_SetMaxPlayers00);
tolua_function(tolua_S,"BroadcastChat",tolua_AllToLua_cServer_BroadcastChat00);
tolua_function(tolua_S,"SendMessage",tolua_AllToLua_cServer_SendMessage00);
tolua_function(tolua_S,"GetServerID",tolua_AllToLua_cServer_GetServerID00);
@@ -29806,9 +29842,6 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_function(tolua_S,"GetDimension",tolua_AllToLua_cWorld_GetDimension00);
tolua_function(tolua_S,"GetHeight",tolua_AllToLua_cWorld_GetHeight00);
tolua_function(tolua_S,"UnloadUnusedChunks",tolua_AllToLua_cWorld_UnloadUnusedChunks00);
- tolua_function(tolua_S,"GetMaxPlayers",tolua_AllToLua_cWorld_GetMaxPlayers00);
- tolua_function(tolua_S,"SetMaxPlayers",tolua_AllToLua_cWorld_SetMaxPlayers00);
- tolua_function(tolua_S,"GetNumPlayers",tolua_AllToLua_cWorld_GetNumPlayers00);
tolua_function(tolua_S,"RegenerateChunk",tolua_AllToLua_cWorld_RegenerateChunk00);
tolua_function(tolua_S,"GenerateChunk",tolua_AllToLua_cWorld_GenerateChunk00);
tolua_function(tolua_S,"SetBlock",tolua_AllToLua_cWorld_SetBlock00);
diff --git a/source/Bindings.h b/source/Bindings.h
index ec1e372f7..d80c98782 100644
--- a/source/Bindings.h
+++ b/source/Bindings.h
@@ -1,6 +1,6 @@
/*
** Lua binding: AllToLua
-** Generated automatically by tolua++-1.0.92 on 08/11/13 14:53:46.
+** Generated automatically by tolua++-1.0.92 on 08/11/13 19:12:37.
*/
/* Exported function */
diff --git a/source/ClientHandle.cpp b/source/ClientHandle.cpp
index 102153de1..14b052652 100644
--- a/source/ClientHandle.cpp
+++ b/source/ClientHandle.cpp
@@ -421,11 +421,11 @@ void cClientHandle::HandlePing(void)
// Somebody tries to retrieve information about the server
AString Reply;
Printf(Reply, "%s%s%i%s%i",
- cRoot::Get()->GetDefaultWorld()->GetDescription().c_str(),
- cChatColor::Delimiter.c_str(),
- cRoot::Get()->GetDefaultWorld()->GetNumPlayers(),
- cChatColor::Delimiter.c_str(),
- cRoot::Get()->GetDefaultWorld()->GetMaxPlayers()
+ cRoot::Get()->GetServer()->GetDescription().c_str(),
+ cChatColor::Delimiter.c_str(),
+ cRoot::Get()->GetServer()->GetNumPlayers(),
+ cChatColor::Delimiter.c_str(),
+ cRoot::Get()->GetServer()->GetMaxPlayers()
);
Kick(Reply.c_str());
}
@@ -1176,7 +1176,7 @@ bool cClientHandle::HandleHandshake(const AString & a_Username)
{
if (!cRoot::Get()->GetPluginManager()->CallHookHandshake(this, a_Username))
{
- if (cRoot::Get()->GetDefaultWorld()->GetNumPlayers() >= cRoot::Get()->GetDefaultWorld()->GetMaxPlayers())
+ if (cRoot::Get()->GetServer()->GetNumPlayers() >= cRoot::Get()->GetServer()->GetMaxPlayers())
{
Kick("The server is currently full :(-- Try again later");
return false;
@@ -1191,7 +1191,7 @@ bool cClientHandle::HandleHandshake(const AString & a_Username)
void cClientHandle::HandleEntityAction(int a_EntityID, char a_ActionID)
{
- if( a_EntityID != m_Player->GetUniqueID() )
+ if (a_EntityID != m_Player->GetUniqueID())
{
// We should only receive entity actions from the entity that is performing the action
return;
diff --git a/source/Protocol/ProtocolRecognizer.cpp b/source/Protocol/ProtocolRecognizer.cpp
index 290f2df75..35c8fe993 100644
--- a/source/Protocol/ProtocolRecognizer.cpp
+++ b/source/Protocol/ProtocolRecognizer.cpp
@@ -14,6 +14,7 @@
#include "Protocol16x.h"
#include "../ClientHandle.h"
#include "../Root.h"
+#include "../Server.h"
#include "../World.h"
#include "../ChatColor.h"
@@ -729,11 +730,11 @@ void cProtocolRecognizer::HandleServerPing(void)
{
// http://wiki.vg/wiki/index.php?title=Protocol&oldid=3099#Server_List_Ping_.280xFE.29
Printf(Reply, "%s%s%i%s%i",
- cRoot::Get()->GetDefaultWorld()->GetDescription().c_str(),
- cChatColor::Delimiter.c_str(),
- cRoot::Get()->GetDefaultWorld()->GetNumPlayers(),
- cChatColor::Delimiter.c_str(),
- cRoot::Get()->GetDefaultWorld()->GetMaxPlayers()
+ cRoot::Get()->GetServer()->GetDescription().c_str(),
+ cChatColor::Delimiter.c_str(),
+ cRoot::Get()->GetServer()->GetNumPlayers(),
+ cChatColor::Delimiter.c_str(),
+ cRoot::Get()->GetServer()->GetMaxPlayers()
);
break;
}
@@ -759,9 +760,9 @@ void cProtocolRecognizer::HandleServerPing(void)
// http://wiki.vg/wiki/index.php?title=Server_List_Ping&oldid=3100
AString NumPlayers;
- Printf(NumPlayers, "%d", cRoot::Get()->GetDefaultWorld()->GetNumPlayers());
+ Printf(NumPlayers, "%d", cRoot::Get()->GetServer()->GetNumPlayers());
AString MaxPlayers;
- Printf(MaxPlayers, "%d", cRoot::Get()->GetDefaultWorld()->GetMaxPlayers());
+ Printf(MaxPlayers, "%d", cRoot::Get()->GetServer()->GetMaxPlayers());
AString ProtocolVersionNum;
Printf(ProtocolVersionNum, "%d", cRoot::Get()->m_PrimaryServerVersion);
@@ -775,7 +776,7 @@ void cProtocolRecognizer::HandleServerPing(void)
Reply.push_back(0);
Reply.append(ProtocolVersionTxt);
Reply.push_back(0);
- Reply.append(cRoot::Get()->GetDefaultWorld()->GetDescription());
+ Reply.append(cRoot::Get()->GetServer()->GetDescription());
Reply.push_back(0);
Reply.append(NumPlayers);
Reply.push_back(0);
diff --git a/source/Server.cpp b/source/Server.cpp
index b07c65f04..509c84af3 100644
--- a/source/Server.cpp
+++ b/source/Server.cpp
@@ -76,6 +76,38 @@ struct cServer::sServerState
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// cServer:
+
+cServer::cServer(void) :
+ m_pState(new sServerState),
+ m_ListenThreadIPv4(*this, cSocket::IPv4, "Client"),
+ m_ListenThreadIPv6(*this, cSocket::IPv6, "Client"),
+ m_Millisecondsf(0),
+ m_Milliseconds(0),
+ m_bIsConnected(false),
+ m_bRestarting(false),
+ m_RCONServer(*this)
+{
+}
+
+
+
+
+
+cServer::~cServer()
+{
+ // TODO: Shut down the server gracefully
+ m_pState->bStopTickThread = true;
+ delete m_pState->pTickThread; m_pState->pTickThread = NULL;
+
+ delete m_pState;
+}
+
+
+
+
+
void cServer::ClientDestroying(const cClientHandle * a_Client)
{
m_SocketThreads.StopReading(a_Client);
@@ -123,6 +155,9 @@ void cServer::RemoveClient(const cClientHandle * a_Client)
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);
+
if (m_bIsConnected)
{
LOGERROR("ERROR: Trying to initialize server while server is already running!");
@@ -201,35 +236,6 @@ bool cServer::InitServer(cIniFile & a_SettingsIni)
-cServer::cServer(void)
- : m_pState(new sServerState)
- , m_ListenThreadIPv4(*this, cSocket::IPv4, "Client")
- , m_ListenThreadIPv6(*this, cSocket::IPv6, "Client")
- , m_Millisecondsf(0)
- , m_Milliseconds(0)
- , m_bIsConnected(false)
- , m_bRestarting(false)
- , m_RCONServer(*this)
-{
-}
-
-
-
-
-
-cServer::~cServer()
-{
- // TODO: Shut down the server gracefully
- m_pState->bStopTickThread = true;
- delete m_pState->pTickThread; m_pState->pTickThread = NULL;
-
- delete m_pState;
-}
-
-
-
-
-
void cServer::PrepareKeys(void)
{
// TODO: Save and load key for persistence across sessions
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();
diff --git a/source/World.cpp b/source/World.cpp
index 776bacff8..ebfee971b 100644
--- a/source/World.cpp
+++ b/source/World.cpp
@@ -128,6 +128,9 @@ protected:
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// cWorldLightingProgress:
+
/// A simple thread that displays the progress of world lighting in cWorld::InitializeSpawn()
class cWorldLightingProgress :
public cIsThread
@@ -188,9 +191,45 @@ cWorld::cLock::cLock(cWorld & a_World) :
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// cWorld::cTickThread:
+
+cWorld::cTickThread::cTickThread(cWorld & a_World) :
+ super(Printf("WorldTickThread: %s", a_World.GetName().c_str())),
+ m_World(a_World)
+{
+}
+
+
+
+
+
+void cWorld::cTickThread::Execute(void)
+{
+ const int ClocksPerTick = CLOCKS_PER_SEC / 20;
+ clock_t LastTime = clock();
+ while (!m_ShouldTerminate)
+ {
+ clock_t Start = clock();
+ m_World.Tick((float)(LastTime - Start) / CLOCKS_PER_SEC);
+ clock_t Now = clock();
+ if (Now - Start < ClocksPerTick)
+ {
+ cSleep::MilliSleep(1000 * (ClocksPerTick - (Now - Start)) / CLOCKS_PER_SEC);
+ }
+ LastTime = Start;
+ }
+}
+
+
+
+
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cWorld:
cWorld::cWorld(const AString & a_WorldName) :
+ m_WorldName(a_WorldName),
+ m_IniFileName(m_WorldName + "/world.ini"),
m_WorldAgeSecs(0),
m_TimeOfDaySecs(0),
m_WorldAge(0),
@@ -199,24 +238,26 @@ cWorld::cWorld(const AString & a_WorldName) :
m_LastSpawnMonster(0),
m_RSList(0),
m_Weather(eWeather_Sunny),
- m_WeatherInterval(24000) // Guaranteed 1 day of sunshine at server start :)
+ m_WeatherInterval(24000), // Guaranteed 1 day of sunshine at server start :)
+ m_TickThread(*this)
{
LOGD("cWorld::cWorld(%s)", a_WorldName.c_str());
- m_WorldName = a_WorldName;
- m_IniFileName = m_WorldName + "/world.ini";
cMakeDir::MakeDir(m_WorldName.c_str());
- MTRand r1;
- m_SpawnX = (double)((r1.randInt() % 1000) - 500);
+ // TODO: Find a proper spawn location, based on the biomes (not in ocean)
+ m_SpawnX = (double)((m_TickRand.randInt() % 1000) - 500);
m_SpawnY = cChunkDef::Height;
- m_SpawnZ = (double)((r1.randInt() % 1000) - 500);
+ m_SpawnZ = (double)((m_TickRand.randInt() % 1000) - 500);
m_GameMode = eGameMode_Creative;
AString StorageSchema("Default");
cIniFile IniFile(m_IniFileName);
- IniFile.ReadFile();
+ if (!IniFile.ReadFile())
+ {
+ LOGWARNING("Cannot read world settings from \"%s\", defaults will be used.", m_IniFileName.c_str());
+ }
AString Dimension = IniFile.GetValueSet("General", "Dimension", "Overworld");
m_Dimension = StringToDimension(Dimension);
switch (m_Dimension)
@@ -268,9 +309,6 @@ cWorld::cWorld(const AString & a_WorldName) :
m_bAnimals = IniFile2.GetValueB("Monsters", "AnimalsOn", true);
m_SpawnMonsterRate = (Int64)(IniFile2.GetValueF("Monsters", "AnimalSpawnInterval", 10) * 20); // Convert from secs to ticks
- // TODO: Move this into cServer instead:
- SetMaxPlayers(IniFile2.GetValueI("Server", "MaxPlayers", 100));
- m_Description = IniFile2.GetValue("Server", "Description", "MCServer! - In C++!").c_str();
}
m_ChunkMap = new cChunkMap(this);
@@ -1893,19 +1931,6 @@ void cWorld::CollectPickupsByPlayer(cPlayer * a_Player)
-void cWorld::SetMaxPlayers(int iMax)
-{
- m_MaxPlayers = MAX_PLAYERS;
- if (iMax > 0 && iMax < MAX_PLAYERS)
- {
- m_MaxPlayers = iMax;
- }
-}
-
-
-
-
-
void cWorld::AddPlayer(cPlayer * a_Player)
{
cCSLock Lock(m_CSPlayers);
@@ -2299,11 +2324,13 @@ void cWorld::RemoveEntity(cEntity * a_Entity)
+/*
unsigned int cWorld::GetNumPlayers(void)
{
cCSLock Lock(m_CSPlayers);
return m_Players.size();
}
+*/
diff --git a/source/World.h b/source/World.h
index b9182e300..1ae56a410 100644
--- a/source/World.h
+++ b/source/World.h
@@ -204,13 +204,6 @@ public:
void CollectPickupsByPlayer(cPlayer * a_Player);
- // MOTD
- const AString & GetDescription(void) const {return m_Description; } // FIXME: This should not be in cWorld
-
- // Max Players
- unsigned int GetMaxPlayers(void) const {return m_MaxPlayers; } // tolua_export
- void SetMaxPlayers(int iMax); // tolua_export
-
void AddPlayer( cPlayer* a_Player );
void RemovePlayer( cPlayer* a_Player );
@@ -223,8 +216,6 @@ public:
/// Finds a player from a partial or complete player name and calls the callback - case-insensitive
bool FindAndDoWithPlayer(const AString & a_PlayerNameHint, cPlayerListCallback & a_Callback); // >> EXPORTED IN MANUALBINDINGS <<
- unsigned int GetNumPlayers(); // tolua_export
-
// TODO: This interface is dangerous - rewrite to DoWithClosestPlayer(pos, sight, action)
cPlayer * FindClosestPlayer(const Vector3f & a_Pos, float a_SightLimit);
@@ -484,8 +475,6 @@ public:
inline int GetStorageLoadQueueLength(void) { return m_Storage.GetLoadQueueLength(); } // tolua_export
inline int GetStorageSaveQueueLength(void) { return m_Storage.GetSaveQueueLength(); } // tolua_export
- void Tick(float a_Dt);
-
void InitializeSpawn(void);
/// Stops threads that belong to this world (part of deinit)
@@ -540,7 +529,25 @@ public:
private:
friend class cRoot;
+
+ class cTickThread :
+ public cIsThread
+ {
+ typedef cIsThread super;
+ public:
+ cTickThread(cWorld & a_World);
+
+ protected:
+ cWorld & m_World;
+
+ // cIsThread overrides:
+ virtual void Execute(void) override;
+ } ;
+
+ AString m_WorldName;
+ AString m_IniFileName;
+
/// The dimension of the world, used by the client to provide correct lighting scheme
eDimension m_Dimension;
@@ -583,8 +590,6 @@ private:
cWorldStorage m_Storage;
- AString m_Description;
-
unsigned int m_MaxPlayers;
cChunkMap * m_ChunkMap;
@@ -616,13 +621,14 @@ private:
cChunkSender m_ChunkSender;
cLightingThread m_Lighting;
+ cTickThread m_TickThread;
+
- AString m_WorldName;
- AString m_IniFileName;
-
cWorld(const AString & a_WorldName);
~cWorld();
+ void Tick(float a_Dt);
+
void TickWeather(float a_Dt); // Handles weather each tick
void TickSpawnMobs(float a_Dt); // Handles mob spawning each tick