summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/MersenneTwister.h3
-rw-r--r--source/cClientHandle.cpp14
-rw-r--r--source/cMonster.cpp2
-rw-r--r--source/cMonsterConfig.cpp8
-rw-r--r--source/cMonsterConfig.h3
-rw-r--r--source/cPlayer.cpp5
-rw-r--r--source/cRoot.cpp28
-rw-r--r--source/cRoot.h8
-rw-r--r--source/cServer.cpp6
-rw-r--r--source/cWebAdmin.cpp2
-rw-r--r--source/cWorld.cpp51
-rw-r--r--source/cWorld.h2
12 files changed, 83 insertions, 49 deletions
diff --git a/source/MersenneTwister.h b/source/MersenneTwister.h
index cdb1730c0..c6184ec0b 100644
--- a/source/MersenneTwister.h
+++ b/source/MersenneTwister.h
@@ -58,7 +58,6 @@
#include <cstdio>
#include <ctime>
#include <cmath>
-#pragma warning(disable:4996;disable:4800)
class MTRand {
// Data
@@ -454,4 +453,4 @@ inline MTRand& MTRand::operator=( const MTRand& o )
// - Cleaned declarations and definitions to please Intel compiler
// - Revised twist() operator to work on ones'-complement machines
// - Fixed reload() function to work when N and M are unsigned
-// - Added copy constructor and copy operator from Salvador Espana \ No newline at end of file
+// - Added copy constructor and copy operator from Salvador Espana
diff --git a/source/cClientHandle.cpp b/source/cClientHandle.cpp
index 58bfad7dc..c610f91a3 100644
--- a/source/cClientHandle.cpp
+++ b/source/cClientHandle.cpp
@@ -306,7 +306,7 @@ void cClientHandle::Authenticate(void)
LoginResponse.m_MapSeed = cRoot::Get()->GetWorld()->GetWorldSeed();
#endif
LoginResponse.m_Dimension = 0;
- LoginResponse.m_MaxPlayers = (unsigned char)cRoot::Get()->GetWorld()->GetMaxPlayers();
+ LoginResponse.m_MaxPlayers = (unsigned char)cRoot::Get()->GetDefaultWorld()->GetMaxPlayers();
LoginResponse.m_Difficulty = 2;
Send(LoginResponse);
@@ -627,11 +627,11 @@ void cClientHandle::HandlePing(void)
// Somebody tries to retrieve information about the server
AString Reply;
Printf(Reply, "%s%s%i%s%i",
- cRoot::Get()->GetWorld()->GetDescription().c_str(),
+ cRoot::Get()->GetDefaultWorld()->GetDescription().c_str(),
cChatColor::Delimiter.c_str(),
- cRoot::Get()->GetWorld()->GetNumPlayers(),
+ cRoot::Get()->GetDefaultWorld()->GetNumPlayers(),
cChatColor::Delimiter.c_str(),
- cRoot::Get()->GetWorld()->GetMaxPlayers()
+ cRoot::Get()->GetDefaultWorld()->GetMaxPlayers()
);
Kick(Reply.c_str());
}
@@ -656,7 +656,7 @@ void cClientHandle::HandleHandshake(cPacket_Handshake * a_Packet)
LOG("HANDSHAKE %s", m_Username.c_str());
- if (cRoot::Get()->GetWorld()->GetNumPlayers() >= cRoot::Get()->GetWorld()->GetMaxPlayers())
+ if (cRoot::Get()->GetDefaultWorld()->GetNumPlayers() >= cRoot::Get()->GetDefaultWorld()->GetMaxPlayers())
{
Kick("The server is currently full :(-- Try again later");
return;
@@ -1647,8 +1647,10 @@ void cClientHandle::HandleKeepAlive(cPacket_KeepAlive * a_Packet)
bool cClientHandle::CheckBlockInteractionsRate(void)
{
+ ASSERT(m_Player != NULL);
+ ASSERT(m_Player->GetWorld() != NULL);
int LastActionCnt = m_Player->GetLastBlockActionCnt();
- if ((cRoot::Get()->GetWorld()->GetTime() - m_Player->GetLastBlockActionTime()) < 0.1)
+ if ((m_Player->GetWorld()->GetTime() - m_Player->GetLastBlockActionTime()) < 0.1)
{
// Limit the number of block interactions per tick
m_Player->SetLastBlockActionTime(); //Player tried to interact with a block. Reset last block interation time.
diff --git a/source/cMonster.cpp b/source/cMonster.cpp
index 6fa8561e5..764d7d67a 100644
--- a/source/cMonster.cpp
+++ b/source/cMonster.cpp
@@ -506,7 +506,7 @@ cPlayer * cMonster::FindClosestPlayer(void)
void cMonster::GetMonsterConfig(const char* pm_name)
{
- cRoot::Get()->GetMonsterConfig()->Get()->AssignAttributes(this, pm_name);
+ cRoot::Get()->GetMonsterConfig()->AssignAttributes(this, pm_name);
}
diff --git a/source/cMonsterConfig.cpp b/source/cMonsterConfig.cpp
index a0ff9914d..92f65aeec 100644
--- a/source/cMonsterConfig.cpp
+++ b/source/cMonsterConfig.cpp
@@ -112,11 +112,3 @@ void cMonsterConfig::AssignAttributes(cMonster *m, const char* n)
-// _X: WTF?
-cMonsterConfig *cMonsterConfig::Get() {
- return this;
-}
-
-
-
-
diff --git a/source/cMonsterConfig.h b/source/cMonsterConfig.h
index 8c0807d73..fbe537802 100644
--- a/source/cMonsterConfig.h
+++ b/source/cMonsterConfig.h
@@ -7,9 +7,6 @@ public:
cMonsterConfig(void);
~cMonsterConfig();
- // _X: WTF? shouldn't this be static? Setting to OBSOLETE
- OBSOLETE cMonsterConfig *Get();
-
void AssignAttributes(cMonster *m, const char* n);
private:
diff --git a/source/cPlayer.cpp b/source/cPlayer.cpp
index a5e2b7565..01c99f1dc 100644
--- a/source/cPlayer.cpp
+++ b/source/cPlayer.cpp
@@ -463,7 +463,10 @@ void cPlayer::CloseWindow(char a_WindowType)
void cPlayer::SetLastBlockActionTime()
{
- m_LastBlockActionTime = cRoot::Get()->GetWorld()->GetTime();
+ if (m_World != NULL)
+ {
+ m_LastBlockActionTime = m_World->GetTime();
+ }
}
diff --git a/source/cRoot.cpp b/source/cRoot.cpp
index 17471d6d9..69127f78e 100644
--- a/source/cRoot.cpp
+++ b/source/cRoot.cpp
@@ -364,3 +364,31 @@ int cRoot::GetTotalChunkCount(void)
+
+void cRoot::SaveAllChunks(void)
+{
+ for (WorldMap::iterator itr = m_pState->WorldsByName.begin(); itr != m_pState->WorldsByName.end(); ++itr)
+ {
+ itr->second->SaveAllChunks();
+ }
+}
+
+
+
+
+
+bool cRoot::ForEachPlayer(cPlayerListCallback & a_Callback)
+{
+ for (WorldMap::iterator itr = m_pState->WorldsByName.begin(); itr != m_pState->WorldsByName.end(); ++itr)
+ {
+ if (!itr->second->ForEachPlayer(a_Callback))
+ {
+ return false;
+ }
+ }
+ return true;
+}
+
+
+
+
diff --git a/source/cRoot.h b/source/cRoot.h
index 9505ff6f0..702768b0e 100644
--- a/source/cRoot.h
+++ b/source/cRoot.h
@@ -19,6 +19,8 @@ class cWebAdmin;
class cPluginManager;
class cServer;
class cWorld;
+class cPlayer;
+typedef cItemCallback<cPlayer> cPlayerListCallback;
@@ -56,6 +58,12 @@ public:
int GetTotalChunkCount(void); // tolua_export
+ /// Saves all chunks in all worlds
+ void SaveAllChunks(void);
+
+ /// Calls the callback for each player in all worlds
+ bool ForEachPlayer(cPlayerListCallback & a_Callback);
+
private:
void LoadGlobalSettings();
diff --git a/source/cServer.cpp b/source/cServer.cpp
index b36d353cb..88bf9d240 100644
--- a/source/cServer.cpp
+++ b/source/cServer.cpp
@@ -520,7 +520,7 @@ void cServer::ServerCommand( const char * a_Cmd )
}
if( split[0].compare( "save-all" ) == 0 )
{
- cRoot::Get()->GetWorld()->SaveAllChunks(); // TODO - Force ALL worlds to save their chunks
+ cRoot::Get()->SaveAllChunks(); // TODO - Force ALL worlds to save their chunks
return;
}
if (split[0].compare("unload") == 0)
@@ -540,7 +540,7 @@ void cServer::ServerCommand( const char * a_Cmd )
return false;
}
} Logger;
- cRoot::Get()->GetWorld()->ForEachPlayer(Logger);
+ cRoot::Get()->ForEachPlayer(Logger);
return;
}
if( split[0].compare( "numchunks" ) == 0 )
@@ -596,7 +596,7 @@ void cServer::Shutdown()
m_bRestarting = true;
m_pState->RestartEvent.Wait();
- cRoot::Get()->GetWorld()->SaveAllChunks();
+ cRoot::Get()->SaveAllChunks();
cCSLock Lock(m_CSClients);
for( ClientList::iterator itr = m_Clients.begin(); itr != m_Clients.end(); ++itr )
diff --git a/source/cWebAdmin.cpp b/source/cWebAdmin.cpp
index 692fc5baf..57aea3146 100644
--- a/source/cWebAdmin.cpp
+++ b/source/cWebAdmin.cpp
@@ -213,7 +213,7 @@ void cWebAdmin::Request_Handler(webserver::http_request* r)
Content += "<h4>Players:</h4><ul>";
cPlayerAccum PlayerAccum;
- cWorld * World = cRoot::Get()->GetWorld(); // TODO - Create a list of worlds and players
+ cWorld * World = cRoot::Get()->GetDefaultWorld(); // TODO - Create a list of worlds and players
World->ForEachPlayer(PlayerAccum);
Content.append(PlayerAccum.m_Contents);
Content += "</ul><br>";
diff --git a/source/cWorld.cpp b/source/cWorld.cpp
index aab874b7e..1695a6427 100644
--- a/source/cWorld.cpp
+++ b/source/cWorld.cpp
@@ -132,8 +132,8 @@ protected:
cWorld* cWorld::GetWorld()
{
- LOGWARN("WARNING: Using deprecated function cWorld::GetWorld() use cRoot::Get()->GetWorld() instead!");
- return cRoot::Get()->GetWorld();
+ LOGWARN("WARNING: Using deprecated function cWorld::GetWorld() use cRoot::Get()->GetDefaultWorld() instead!");
+ return cRoot::Get()->GetDefaultWorld();
}
@@ -275,29 +275,34 @@ cWorld::cWorld( const AString & a_WorldName )
g_BlockLightValue[ E_BLOCK_GLOWSTONE ] = 15;
// Spread blocks
- g_BlockSpreadLightFalloff[ E_BLOCK_AIR ] = 1;
- g_BlockSpreadLightFalloff[ E_BLOCK_TORCH ] = 1;
- g_BlockSpreadLightFalloff[ E_BLOCK_FIRE ] = 1;
- g_BlockSpreadLightFalloff[ E_BLOCK_LAVA ] = 1;
- g_BlockSpreadLightFalloff[ E_BLOCK_STATIONARY_LAVA ] = 1;
- g_BlockSpreadLightFalloff[ E_BLOCK_WATER ] = 4; // Light in water dissapears faster
- g_BlockSpreadLightFalloff[ E_BLOCK_STATIONARY_WATER ] = 4;
- g_BlockSpreadLightFalloff[ E_BLOCK_LEAVES ] = 1;
- g_BlockSpreadLightFalloff[ E_BLOCK_GLASS ] = 1;
- g_BlockSpreadLightFalloff[ E_BLOCK_GLOWSTONE ] = 1;
- g_BlockSpreadLightFalloff[ E_BLOCK_SIGN_POST ] = 1;
- g_BlockSpreadLightFalloff[ E_BLOCK_WALLSIGN ] = 1;
+ g_BlockSpreadLightFalloff[ E_BLOCK_AIR ] = 1;
+ g_BlockSpreadLightFalloff[ E_BLOCK_TORCH ] = 1;
+ g_BlockSpreadLightFalloff[ E_BLOCK_FIRE ] = 1;
+ g_BlockSpreadLightFalloff[ E_BLOCK_LAVA ] = 1;
+ g_BlockSpreadLightFalloff[ E_BLOCK_STATIONARY_LAVA ] = 1;
+ g_BlockSpreadLightFalloff[ E_BLOCK_WATER ] = 4; // Light in water dissapears faster
+ g_BlockSpreadLightFalloff[ E_BLOCK_STATIONARY_WATER ] = 4;
+ g_BlockSpreadLightFalloff[ E_BLOCK_LEAVES ] = 1;
+ g_BlockSpreadLightFalloff[ E_BLOCK_GLASS ] = 1;
+ g_BlockSpreadLightFalloff[ E_BLOCK_GLOWSTONE ] = 1;
+ g_BlockSpreadLightFalloff[ E_BLOCK_SIGN_POST ] = 1;
+ g_BlockSpreadLightFalloff[ E_BLOCK_WALLSIGN ] = 1;
// Transparent blocks
- g_BlockTransparent[ E_BLOCK_AIR ] = true;
- g_BlockTransparent[ E_BLOCK_GLASS ] = true;
- g_BlockTransparent[ E_BLOCK_FIRE ] = true;
- g_BlockTransparent[ E_BLOCK_ICE ] = true;
- g_BlockTransparent[ E_BLOCK_TORCH ] = true;
- g_BlockTransparent[ E_BLOCK_SIGN_POST ] = true;
- g_BlockTransparent[ E_BLOCK_WALLSIGN ] = true;
-
- // TODO: Also set flowers, mushrooms etc as transparent
+ g_BlockTransparent[ E_BLOCK_AIR ] = true;
+ g_BlockTransparent[ E_BLOCK_GLASS ] = true;
+ g_BlockTransparent[ E_BLOCK_FIRE ] = true;
+ g_BlockTransparent[ E_BLOCK_ICE ] = true;
+ g_BlockTransparent[ E_BLOCK_TORCH ] = true;
+ g_BlockTransparent[ E_BLOCK_SIGN_POST ] = true;
+ g_BlockTransparent[ E_BLOCK_WALLSIGN ] = true;
+ g_BlockTransparent[ E_BLOCK_TALL_GRASS ] = true;
+ g_BlockTransparent[ E_BLOCK_YELLOW_FLOWER ] = true;
+ g_BlockTransparent[ E_BLOCK_RED_ROSE ] = true;
+ g_BlockTransparent[ E_BLOCK_RED_MUSHROOM ] = true;
+ g_BlockTransparent[ E_BLOCK_BROWN_MUSHROOM ] = true;
+
+ // TODO: Any other transparent blocks?
// One hit break blocks
g_BlockOneHitDig[ E_BLOCK_SAPLING ] = true;
diff --git a/source/cWorld.h b/source/cWorld.h
index ea91a854a..fa00a78bc 100644
--- a/source/cWorld.h
+++ b/source/cWorld.h
@@ -48,7 +48,7 @@ class cWorld //tolua_export
{ //tolua_export
public:
- static cWorld* GetWorld(); //tolua_export
+ OBSOLETE static cWorld* GetWorld(); //tolua_export
// Return time in seconds
inline static float GetTime() //tolua_export