From fb58ef55beddc73500029ae6c0fe08400de550d2 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Thu, 8 May 2014 20:16:35 +0200 Subject: Fixed MSVC 64-bit build warnings. --- src/Root.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src/Root.cpp') diff --git a/src/Root.cpp b/src/Root.cpp index 5d32bdd87..c82b05a66 100644 --- a/src/Root.cpp +++ b/src/Root.cpp @@ -590,13 +590,13 @@ bool cRoot::FindAndDoWithPlayer(const AString & a_PlayerName, cPlayerListCallbac { class cCallback : public cPlayerListCallback { - unsigned m_BestRating; - unsigned m_NameLength; + size_t m_BestRating; + size_t m_NameLength; const AString m_PlayerName; virtual bool Item (cPlayer * a_pPlayer) { - unsigned int Rating = RateCompareString (m_PlayerName, a_pPlayer->GetName()); + size_t Rating = RateCompareString (m_PlayerName, a_pPlayer->GetName()); if ((Rating > 0) && (Rating >= m_BestRating)) { m_BestMatch = a_pPlayer; @@ -626,7 +626,7 @@ bool cRoot::FindAndDoWithPlayer(const AString & a_PlayerName, cPlayerListCallbac cPlayer * m_BestMatch; unsigned m_NumMatches; } Callback (a_PlayerName); - ForEachPlayer( Callback ); + ForEachPlayer(Callback); if (Callback.m_NumMatches == 1) { @@ -763,8 +763,8 @@ void cRoot::LogChunkStats(cCommandOutputCallback & a_Output) { cWorld * World = itr->second; int NumInGenerator = World->GetGeneratorQueueLength(); - int NumInSaveQueue = World->GetStorageSaveQueueLength(); - int NumInLoadQueue = World->GetStorageLoadQueueLength(); + int NumInSaveQueue = (int)World->GetStorageSaveQueueLength(); + int NumInLoadQueue = (int)World->GetStorageLoadQueueLength(); int NumValid = 0; int NumDirty = 0; int NumInLighting = 0; @@ -784,8 +784,6 @@ void cRoot::LogChunkStats(cCommandOutputCallback & a_Output) a_Output.Out(" block lighting: " SIZE_T_FMT_PRECISION(6) " bytes (" SIZE_T_FMT_PRECISION(3) " KiB)", 2 * sizeof(cChunkDef::BlockNibbles), (2 * sizeof(cChunkDef::BlockNibbles) + 1023) / 1024); a_Output.Out(" heightmap: " SIZE_T_FMT_PRECISION(6) " bytes (" SIZE_T_FMT_PRECISION(3) " KiB)", sizeof(cChunkDef::HeightMap), (sizeof(cChunkDef::HeightMap) + 1023) / 1024); a_Output.Out(" biomemap: " SIZE_T_FMT_PRECISION(6) " bytes (" SIZE_T_FMT_PRECISION(3) " KiB)", sizeof(cChunkDef::BiomeMap), (sizeof(cChunkDef::BiomeMap) + 1023) / 1024); - int Rest = sizeof(cChunk) - sizeof(cChunkDef::BlockTypes) - 3 * sizeof(cChunkDef::BlockNibbles) - sizeof(cChunkDef::HeightMap) - sizeof(cChunkDef::BiomeMap); - a_Output.Out(" other: %6d bytes (%3d KiB)", Rest, (Rest + 1023) / 1024); SumNumValid += NumValid; SumNumDirty += NumDirty; SumNumInLighting += NumInLighting; -- cgit v1.2.3 From 8bff3e5af220070ecc789ef551c0b8428b8953ef Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 31 May 2014 22:28:51 +0100 Subject: Implemented end and nether portals --- src/Root.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'src/Root.cpp') diff --git a/src/Root.cpp b/src/Root.cpp index c82b05a66..2a80baeb3 100644 --- a/src/Root.cpp +++ b/src/Root.cpp @@ -320,7 +320,7 @@ cWorld * cRoot::CreateAndInitializeWorld(const AString & a_WorldName) { return NULL; } - cWorld* NewWorld = new cWorld(a_WorldName.c_str()); + cWorld * NewWorld = new cWorld(a_WorldName.c_str()); m_WorldsByName[a_WorldName] = NewWorld; NewWorld->Start(); NewWorld->InitializeSpawn(); @@ -372,7 +372,7 @@ void cRoot::UnloadWorlds(void) -cWorld* cRoot::GetDefaultWorld() +cWorld * cRoot::GetDefaultWorld() { return m_pDefaultWorld; } @@ -381,12 +381,14 @@ cWorld* cRoot::GetDefaultWorld() -cWorld* cRoot::GetWorld( const AString & a_WorldName ) +cWorld * cRoot::GetWorld(const AString & a_WorldName) { - WorldMap::iterator itr = m_WorldsByName.find( a_WorldName ); - if( itr != m_WorldsByName.end() ) + WorldMap::iterator itr = m_WorldsByName.find(a_WorldName); + if (itr != m_WorldsByName.end()) + { return itr->second; - return 0; + } + return NULL; } @@ -398,9 +400,12 @@ bool cRoot::ForEachWorld(cWorldListCallback & a_Callback) for (WorldMap::iterator itr = m_WorldsByName.begin(), itr2 = itr; itr != m_WorldsByName.end(); itr = itr2) { ++itr2; - if (a_Callback.Item(itr->second)) + if (itr->second != NULL) { - return false; + if (a_Callback.Item(itr->second)) + { + return false; + } } } return true; -- cgit v1.2.3 From 35b79e5d710862f957bc494638a8d8906992665d Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 10 Jun 2014 20:43:27 +0100 Subject: Portal improvements and suggestions --- src/Root.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/Root.cpp') diff --git a/src/Root.cpp b/src/Root.cpp index 2a80baeb3..572cbf1fc 100644 --- a/src/Root.cpp +++ b/src/Root.cpp @@ -314,15 +314,15 @@ void cRoot::LoadWorlds(cIniFile & IniFile) -cWorld * cRoot::CreateAndInitializeWorld(const AString & a_WorldName) +cWorld * cRoot::CreateAndInitializeWorld(const AString & a_WorldName, eDimension a_Dimension, const AString & a_OverworldName) { if (m_WorldsByName[a_WorldName] != NULL) { return NULL; } - cWorld * NewWorld = new cWorld(a_WorldName.c_str()); + cWorld * NewWorld = new cWorld(a_WorldName.c_str(), a_Dimension, a_OverworldName); m_WorldsByName[a_WorldName] = NewWorld; - NewWorld->Start(); + NewWorld->Start(!a_OverworldName.empty()); NewWorld->InitializeSpawn(); m_PluginManager->CallHookWorldStarted(*NewWorld); return NewWorld; -- cgit v1.2.3 From 4e24f711abd3d6a93f01ee7c297eb67c8aedbd37 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 14 Jul 2014 19:49:31 +0100 Subject: Player properties are now retrieved --- src/Root.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Root.cpp') diff --git a/src/Root.cpp b/src/Root.cpp index c82b05a66..c578fe6a3 100644 --- a/src/Root.cpp +++ b/src/Root.cpp @@ -499,9 +499,9 @@ void cRoot::KickUser(int a_ClientID, const AString & a_Reason) -void cRoot::AuthenticateUser(int a_ClientID, const AString & a_Name, const AString & a_UUID) +void cRoot::AuthenticateUser(int a_ClientID, const AString & a_Name, const AString & a_UUID, const AString & a_Properties) { - m_Server->AuthenticateUser(a_ClientID, a_Name, a_UUID); + m_Server->AuthenticateUser(a_ClientID, a_Name, a_UUID, a_Properties); } -- cgit v1.2.3 From 1f6854792cdd6792b27c4f9f3d7d857df9dd64bf Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 16 Jul 2014 00:03:47 +0100 Subject: Store properties as Json::Value --- src/Root.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Root.cpp') diff --git a/src/Root.cpp b/src/Root.cpp index c578fe6a3..ec1351ef1 100644 --- a/src/Root.cpp +++ b/src/Root.cpp @@ -499,7 +499,7 @@ void cRoot::KickUser(int a_ClientID, const AString & a_Reason) -void cRoot::AuthenticateUser(int a_ClientID, const AString & a_Name, const AString & a_UUID, const AString & a_Properties) +void cRoot::AuthenticateUser(int a_ClientID, const AString & a_Name, const AString & a_UUID, const Json::Value & a_Properties) { m_Server->AuthenticateUser(a_ClientID, a_Name, a_UUID, a_Properties); } -- cgit v1.2.3 From 993fd14ddfc881cf5be951df77da0338124d68cc Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 17 Jul 2014 16:33:09 +0200 Subject: Fixed basic whitespace problems. Indenting by spaces and alignment by spaces, as well as trailing whitespace on non-empty lines. --- src/Root.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/Root.cpp') diff --git a/src/Root.cpp b/src/Root.cpp index ec1351ef1..235a1b108 100644 --- a/src/Root.cpp +++ b/src/Root.cpp @@ -84,7 +84,7 @@ void cRoot::InputThread(void * a_Params) AString Command; std::getline(std::cin, Command); if (!Command.empty()) - { + { self.ExecuteConsoleCommand(TrimString(Command), Output); } } @@ -194,7 +194,7 @@ void cRoot::Start(void) #if !defined(ANDROID_NDK) LOGD("Starting InputThread..."); m_InputThread = new cThread( InputThread, this, "cRoot::InputThread" ); - m_InputThread->Start( false ); // We should NOT wait? Otherwise we can't stop the server from other threads than the input thread + m_InputThread->Start( false ); // We should NOT wait? Otherwise we can't stop the server from other threads than the input thread #endif long long finishmseconds = Time.GetNowTime(); @@ -687,7 +687,7 @@ int cRoot::GetVirtualRAMUsage(void) &t_info_count )) { - return (int)(t_info.virtual_size / 1024); + return (int)(t_info.virtual_size / 1024); } return -1; #else @@ -739,7 +739,7 @@ int cRoot::GetPhysicalRAMUsage(void) &t_info_count )) { - return (int)(t_info.resident_size / 1024); + return (int)(t_info.resident_size / 1024); } return -1; #else -- cgit v1.2.3 From 7fff12bfacbb4bef1c02cea0ec10fdc9a6fb64e4 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 17 Jul 2014 19:13:23 +0200 Subject: Fixed spaces around single-line comments. There should be at least two spaces in front and one space after //-style comments. --- src/Root.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/Root.cpp') diff --git a/src/Root.cpp b/src/Root.cpp index 235a1b108..6347adcf0 100644 --- a/src/Root.cpp +++ b/src/Root.cpp @@ -105,7 +105,7 @@ void cRoot::Start(void) #ifdef _WIN32 HWND hwnd = GetConsoleWindow(); HMENU hmenu = GetSystemMenu(hwnd, FALSE); - EnableMenuItem(hmenu, SC_CLOSE, MF_GRAYED); // Disable close button when starting up; it causes problems with our CTRL-CLOSE handling + EnableMenuItem(hmenu, SC_CLOSE, MF_GRAYED); // Disable close button when starting up; it causes problems with our CTRL-CLOSE handling #endif cDeadlockDetect dd; @@ -202,7 +202,7 @@ void cRoot::Start(void) LOG("Startup complete, took %lld ms!", finishmseconds); #ifdef _WIN32 - EnableMenuItem(hmenu, SC_CLOSE, MF_ENABLED); // Re-enable close button + EnableMenuItem(hmenu, SC_CLOSE, MF_ENABLED); // Re-enable close button #endif while (!m_bStop && !m_bRestart && !g_TERMINATE_EVENT_RAISED) // These are modified by external threads @@ -607,7 +607,7 @@ bool cRoot::FindAndDoWithPlayer(const AString & a_PlayerName, cPlayerListCallbac m_BestRating = Rating; ++m_NumMatches; } - if (Rating == m_NameLength) // Perfect match + if (Rating == m_NameLength) // Perfect match { return true; } -- cgit v1.2.3 From ed01e12ed732fc9e3516ed263ebb73978b6f82f6 Mon Sep 17 00:00:00 2001 From: archshift Date: Sat, 19 Jul 2014 14:50:01 -0700 Subject: main.cpp: Fixed warnings with g_TERMINATE_EVENT_RAISED and g_SERVER_TERMINATED --- src/Root.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/Root.cpp') diff --git a/src/Root.cpp b/src/Root.cpp index 6347adcf0..d727e34a3 100644 --- a/src/Root.cpp +++ b/src/Root.cpp @@ -30,8 +30,6 @@ #include #endif -extern bool g_TERMINATE_EVENT_RAISED; - -- cgit v1.2.3 From 14826b660649c87c002b4ba23a255007f141dab4 Mon Sep 17 00:00:00 2001 From: archshift Date: Sat, 19 Jul 2014 15:44:19 -0700 Subject: main.cpp: field style fixes --- src/Root.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/Root.cpp') diff --git a/src/Root.cpp b/src/Root.cpp index d727e34a3..ba25b97eb 100644 --- a/src/Root.cpp +++ b/src/Root.cpp @@ -77,7 +77,7 @@ void cRoot::InputThread(void * a_Params) cLogCommandOutputCallback Output; - while (!self.m_bStop && !self.m_bRestart && !g_TERMINATE_EVENT_RAISED && std::cin.good()) + while (!self.m_bStop && !self.m_bRestart && !m_TerminateEventRaised && std::cin.good()) { AString Command; std::getline(std::cin, Command); @@ -87,7 +87,7 @@ void cRoot::InputThread(void * a_Params) } } - if (g_TERMINATE_EVENT_RAISED || !std::cin.good()) + if (m_TerminateEventRaised || !std::cin.good()) { // We have come here because the std::cin has received an EOF / a terminate signal has been sent, and the server is still running; stop the server: self.m_bStop = true; @@ -203,12 +203,12 @@ void cRoot::Start(void) EnableMenuItem(hmenu, SC_CLOSE, MF_ENABLED); // Re-enable close button #endif - while (!m_bStop && !m_bRestart && !g_TERMINATE_EVENT_RAISED) // These are modified by external threads + while (!m_bStop && !m_bRestart && !m_TerminateEventRaised) // These are modified by external threads { cSleep::MilliSleep(1000); } - if (g_TERMINATE_EVENT_RAISED) + if (m_TerminateEventRaised) { m_bStop = true; } -- cgit v1.2.3 From 6ab9afd0fd808fad99cd8387c72ce461c37aef80 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 20 Jul 2014 10:46:45 +0100 Subject: Bug and crash fixes * Fixes end portals' solidity * Fixed crashes to do with multithreading and removing an entity from the wrong world * Fixed crashes due to bad merge * Fixed crashes due to an object being deleted twice * Simplified cWorld::Start() and added comments to configuration files --- src/Root.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/Root.cpp') diff --git a/src/Root.cpp b/src/Root.cpp index 822be92ff..e1eebb711 100644 --- a/src/Root.cpp +++ b/src/Root.cpp @@ -322,7 +322,7 @@ cWorld * cRoot::CreateAndInitializeWorld(const AString & a_WorldName, eDimension } cWorld * NewWorld = new cWorld(a_WorldName.c_str(), a_Dimension, a_OverworldName); m_WorldsByName[a_WorldName] = NewWorld; - NewWorld->Start(!a_OverworldName.empty()); + NewWorld->Start(); NewWorld->InitializeSpawn(); m_PluginManager->CallHookWorldStarted(*NewWorld); return NewWorld; @@ -381,13 +381,18 @@ cWorld * cRoot::GetDefaultWorld() -cWorld * cRoot::GetWorld(const AString & a_WorldName) +cWorld * cRoot::GetWorld(const AString & a_WorldName, bool a_SearchForFolder) { WorldMap::iterator itr = m_WorldsByName.find(a_WorldName); if (itr != m_WorldsByName.end()) { return itr->second; } + + if (a_SearchForFolder && cFile::IsFolder(FILE_IO_PREFIX + a_WorldName)) + { + return CreateAndInitializeWorld(a_WorldName); + } return NULL; } -- cgit v1.2.3 From 6be79575fd50e37ac275bd0cb9d16f9e51e8a225 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 20 Jul 2014 23:10:31 +0200 Subject: Style: Normalized spaces after if, for and while. --- src/Root.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/Root.cpp') diff --git a/src/Root.cpp b/src/Root.cpp index ba25b97eb..e195b59ff 100644 --- a/src/Root.cpp +++ b/src/Root.cpp @@ -359,7 +359,7 @@ void cRoot::StopWorlds(void) void cRoot::UnloadWorlds(void) { m_pDefaultWorld = NULL; - for( WorldMap::iterator itr = m_WorldsByName.begin(); itr != m_WorldsByName.end(); ++itr ) + for (WorldMap::iterator itr = m_WorldsByName.begin(); itr != m_WorldsByName.end(); ++itr ) { delete itr->second; } @@ -382,7 +382,7 @@ cWorld* cRoot::GetDefaultWorld() cWorld* cRoot::GetWorld( const AString & a_WorldName ) { WorldMap::iterator itr = m_WorldsByName.find( a_WorldName ); - if( itr != m_WorldsByName.end() ) + if (itr != m_WorldsByName.end() ) return itr->second; return 0; } @@ -509,7 +509,7 @@ void cRoot::AuthenticateUser(int a_ClientID, const AString & a_Name, const AStri int cRoot::GetTotalChunkCount(void) { int res = 0; - for ( WorldMap::iterator itr = m_WorldsByName.begin(); itr != m_WorldsByName.end(); ++itr ) + for (WorldMap::iterator itr = m_WorldsByName.begin(); itr != m_WorldsByName.end(); ++itr ) { res += itr->second->GetNumChunks(); } -- cgit v1.2.3 From 93d29555e58df172bafba530afbc593c16ec66a3 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 21 Jul 2014 15:19:48 +0200 Subject: Style: Normalized to no spaces before closing parenthesis. --- src/Root.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src/Root.cpp') diff --git a/src/Root.cpp b/src/Root.cpp index e195b59ff..b03a13382 100644 --- a/src/Root.cpp +++ b/src/Root.cpp @@ -191,8 +191,8 @@ void cRoot::Start(void) #if !defined(ANDROID_NDK) LOGD("Starting InputThread..."); - m_InputThread = new cThread( InputThread, this, "cRoot::InputThread" ); - m_InputThread->Start( false ); // We should NOT wait? Otherwise we can't stop the server from other threads than the input thread + m_InputThread = new cThread( InputThread, this, "cRoot::InputThread"); + m_InputThread->Start( false); // We should NOT wait? Otherwise we can't stop the server from other threads than the input thread #endif long long finishmseconds = Time.GetNowTime(); @@ -269,12 +269,12 @@ void cRoot::LoadWorlds(cIniFile & IniFile) { // First get the default world AString DefaultWorldName = IniFile.GetValueSet("Worlds", "DefaultWorld", "world"); - m_pDefaultWorld = new cWorld( DefaultWorldName.c_str() ); + m_pDefaultWorld = new cWorld( DefaultWorldName.c_str()); m_WorldsByName[ DefaultWorldName ] = m_pDefaultWorld; // Then load the other worlds unsigned int KeyNum = IniFile.FindKey("Worlds"); - unsigned int NumWorlds = IniFile.GetNumValues( KeyNum ); + unsigned int NumWorlds = IniFile.GetNumValues( KeyNum); if (NumWorlds <= 0) { return; @@ -283,18 +283,18 @@ void cRoot::LoadWorlds(cIniFile & IniFile) bool FoundAdditionalWorlds = false; for (unsigned int i = 0; i < NumWorlds; i++) { - AString ValueName = IniFile.GetValueName(KeyNum, i ); + AString ValueName = IniFile.GetValueName(KeyNum, i); if (ValueName.compare("World") != 0) { continue; } - AString WorldName = IniFile.GetValue(KeyNum, i ); + AString WorldName = IniFile.GetValue(KeyNum, i); if (WorldName.empty()) { continue; } FoundAdditionalWorlds = true; - cWorld* NewWorld = new cWorld( WorldName.c_str() ); + cWorld* NewWorld = new cWorld( WorldName.c_str()); m_WorldsByName[ WorldName ] = NewWorld; } // for i - Worlds @@ -359,7 +359,7 @@ void cRoot::StopWorlds(void) void cRoot::UnloadWorlds(void) { m_pDefaultWorld = NULL; - for (WorldMap::iterator itr = m_WorldsByName.begin(); itr != m_WorldsByName.end(); ++itr ) + for (WorldMap::iterator itr = m_WorldsByName.begin(); itr != m_WorldsByName.end(); ++itr) { delete itr->second; } @@ -379,10 +379,10 @@ cWorld* cRoot::GetDefaultWorld() -cWorld* cRoot::GetWorld( const AString & a_WorldName ) +cWorld* cRoot::GetWorld( const AString & a_WorldName) { - WorldMap::iterator itr = m_WorldsByName.find( a_WorldName ); - if (itr != m_WorldsByName.end() ) + WorldMap::iterator itr = m_WorldsByName.find( a_WorldName); + if (itr != m_WorldsByName.end()) return itr->second; return 0; } @@ -509,7 +509,7 @@ void cRoot::AuthenticateUser(int a_ClientID, const AString & a_Name, const AStri int cRoot::GetTotalChunkCount(void) { int res = 0; - for (WorldMap::iterator itr = m_WorldsByName.begin(); itr != m_WorldsByName.end(); ++itr ) + for (WorldMap::iterator itr = m_WorldsByName.begin(); itr != m_WorldsByName.end(); ++itr) { res += itr->second->GetNumChunks(); } -- cgit v1.2.3 From a28b0dc1201dca7c34d9a6c33232157e45a6d4f8 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 22 Jul 2014 17:26:48 +0100 Subject: Speed improvements, crash fixes, & self-suggestions --- src/Root.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/Root.cpp') diff --git a/src/Root.cpp b/src/Root.cpp index b793cb154..b65e9b067 100644 --- a/src/Root.cpp +++ b/src/Root.cpp @@ -314,10 +314,12 @@ void cRoot::LoadWorlds(cIniFile & IniFile) cWorld * cRoot::CreateAndInitializeWorld(const AString & a_WorldName, eDimension a_Dimension, const AString & a_OverworldName) { - if (m_WorldsByName[a_WorldName] != NULL) + cWorld * World = m_WorldsByName[a_WorldName]; + if (World != NULL) { - return NULL; + return World; } + cWorld * NewWorld = new cWorld(a_WorldName.c_str(), a_Dimension, a_OverworldName); m_WorldsByName[a_WorldName] = NewWorld; NewWorld->Start(); -- cgit v1.2.3