From aa19a3afb0b94e8b5fe055eeb38b1fb2ee1a67b0 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 19 Oct 2014 14:10:18 +0100 Subject: Migrated random generators to std::random --- src/Server.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/Server.cpp') diff --git a/src/Server.cpp b/src/Server.cpp index 8e5755a75..c5f4f9042 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -20,8 +20,6 @@ #include "Protocol/ProtocolRecognizer.h" #include "CommandOutput.h" -#include "MersenneTwister.h" - #include "inifile/iniFile.h" #include "Vector3.h" -- cgit v1.2.3 From bde99d684e0bb51adaa053a240abe61cf4af07fb Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 20 Oct 2014 18:59:40 +0100 Subject: Migrated cSleep and cTimer to std::chrono --- src/Server.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'src/Server.cpp') diff --git a/src/Server.cpp b/src/Server.cpp index c5f4f9042..f29683b21 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -4,7 +4,6 @@ #include "Server.h" #include "ClientHandle.h" -#include "OSSupport/Timer.h" #include "Mobs/Monster.h" #include "OSSupport/Socket.h" #include "Root.h" @@ -73,22 +72,19 @@ cServer::cTickThread::cTickThread(cServer & a_Server) : void cServer::cTickThread::Execute(void) { - cTimer Timer; - - long long msPerTick = 50; - long long LastTime = Timer.GetNowTime(); + auto LastTime = std::chrono::steady_clock::now(); + static const auto msPerTick = std::chrono::milliseconds(50); while (!m_ShouldTerminate) { - long long NowTime = Timer.GetNowTime(); - float DeltaTime = (float)(NowTime-LastTime); - m_ShouldTerminate = !m_Server.Tick(DeltaTime); - long long TickTime = Timer.GetNowTime() - NowTime; + auto NowTime = std::chrono::steady_clock::now(); + m_ShouldTerminate = !m_Server.Tick(std::chrono::duration_cast(NowTime - LastTime).count()); + auto TickTime = std::chrono::steady_clock::now() - NowTime; if (TickTime < msPerTick) { // Stretch tick time until it's at least msPerTick - cSleep::MilliSleep((unsigned int)(msPerTick - TickTime)); + std::this_thread::sleep_for(msPerTick -TickTime); } LastTime = NowTime; -- cgit v1.2.3 From 987f79afdd8945966d0dfa2d52539e005f771590 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 20 Oct 2014 21:55:07 +0100 Subject: En masse NULL -> nullptr replace --- src/Server.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src/Server.cpp') diff --git a/src/Server.cpp b/src/Server.cpp index 38e5cebb3..11da36868 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -332,7 +332,7 @@ void cServer::OnConnectionAccepted(cSocket & a_Socket) LOGERROR("Client \"%s\" cannot be handled, server probably unstable", ClientIP.c_str()); a_Socket.CloseSocket(); delete NewHandle; - NewHandle = NULL; + NewHandle = nullptr; return; } @@ -631,17 +631,17 @@ void cServer::PrintHelp(const AStringVector & a_Split, cCommandOutputCallback & void cServer::BindBuiltInConsoleCommands(void) { cPluginManager * PlgMgr = cPluginManager::Get(); - PlgMgr->BindConsoleCommand("help", NULL, " - Shows the available commands"); - PlgMgr->BindConsoleCommand("reload", NULL, " - Reloads all plugins"); - PlgMgr->BindConsoleCommand("restart", NULL, " - Restarts the server cleanly"); - PlgMgr->BindConsoleCommand("stop", NULL, " - Stops the server cleanly"); - PlgMgr->BindConsoleCommand("chunkstats", NULL, " - Displays detailed chunk memory statistics"); - PlgMgr->BindConsoleCommand("load ", NULL, " - Adds and enables the specified plugin"); - PlgMgr->BindConsoleCommand("unload ", NULL, " - Disables the specified plugin"); - PlgMgr->BindConsoleCommand("destroyentities", NULL, " - Destroys all entities in all worlds"); + PlgMgr->BindConsoleCommand("help", nullptr, " - Shows the available commands"); + PlgMgr->BindConsoleCommand("reload", nullptr, " - Reloads all plugins"); + PlgMgr->BindConsoleCommand("restart", nullptr, " - Restarts the server cleanly"); + PlgMgr->BindConsoleCommand("stop", nullptr, " - Stops the server cleanly"); + PlgMgr->BindConsoleCommand("chunkstats", nullptr, " - Displays detailed chunk memory statistics"); + PlgMgr->BindConsoleCommand("load ", nullptr, " - Adds and enables the specified plugin"); + PlgMgr->BindConsoleCommand("unload ", nullptr, " - Disables the specified plugin"); + PlgMgr->BindConsoleCommand("destroyentities", nullptr, " - Destroys all entities in all worlds"); #if defined(_MSC_VER) && defined(_DEBUG) && defined(ENABLE_LEAK_FINDER) - PlgMgr->BindConsoleCommand("dumpmem", NULL, " - Dumps all used memory blocks together with their callstacks into memdump.xml"); + PlgMgr->BindConsoleCommand("dumpmem", nullptr, " - Dumps all used memory blocks together with their callstacks into memdump.xml"); #endif } @@ -710,7 +710,7 @@ void cServer::AuthenticateUser(int a_ClientID, const AString & a_Name, const ASt cServer::cNotifyWriteThread::cNotifyWriteThread(void) : super("ClientPacketThread"), - m_Server(NULL) + m_Server(nullptr) { } -- cgit v1.2.3 From 3e0f7c2b1c9b371307a570e445d0178599abd92d Mon Sep 17 00:00:00 2001 From: Alexander Harkness Date: Tue, 21 Oct 2014 14:17:36 +0100 Subject: Missing space. --- src/Server.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Server.cpp') diff --git a/src/Server.cpp b/src/Server.cpp index 11da36868..6f7d494be 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -84,7 +84,7 @@ void cServer::cTickThread::Execute(void) if (TickTime < msPerTick) { // Stretch tick time until it's at least msPerTick - std::this_thread::sleep_for(msPerTick -TickTime); + std::this_thread::sleep_for(msPerTick - TickTime); } LastTime = NowTime; -- cgit v1.2.3 From 61e761fdc2bfa5c77002d68bb24e0470def37b48 Mon Sep 17 00:00:00 2001 From: Vincent Date: Sat, 29 Nov 2014 00:36:15 -0800 Subject: issue 1253 - prevent multiple logins with same username --- src/Server.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/Server.cpp') diff --git a/src/Server.cpp b/src/Server.cpp index bbb5ecff3..157bad43e 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -201,6 +201,7 @@ bool cServer::InitServer(cIniFile & a_SettingsIni, bool a_ShouldAuth) m_Description = a_SettingsIni.GetValueSet("Server", "Description", "MCServer - in C++!"); m_MaxPlayers = a_SettingsIni.GetValueSetI("Server", "MaxPlayers", 100); m_bIsHardcore = a_SettingsIni.GetValueSetB("Server", "HardcoreEnabled", false); + m_bAllowMultiLogin = a_SettingsIni.GetValueSetB("Server", "AllowMultiLogin", false); m_PlayerCount = 0; m_PlayerCountDiff = 0; @@ -303,6 +304,22 @@ int cServer::GetNumPlayers(void) const +std::list cServer::GetUsernames() +{ + std::list usernames; + cCSLock Lock(m_CSClients); + for (ClientList::iterator itr = m_Clients.begin(); itr != m_Clients.end(); ++itr) + { + std::string username = (*itr)->GetUsername(); + usernames.insert(usernames.begin(),username); + } + return usernames; +} + + + + + void cServer::PrepareKeys(void) { LOGD("Generating protocol encryption keypair..."); -- cgit v1.2.3 From a7bf2725c8bd5f8ec3e03584af87a7055cb15a60 Mon Sep 17 00:00:00 2001 From: Vincent Date: Sat, 29 Nov 2014 11:22:03 -0800 Subject: fixed naming of strings and changed from i to I --- src/Server.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/Server.cpp') diff --git a/src/Server.cpp b/src/Server.cpp index 157bad43e..ed02500ff 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -304,13 +304,13 @@ int cServer::GetNumPlayers(void) const -std::list cServer::GetUsernames() +std::list cServer::GetUsernames() { - std::list usernames; + std::list usernames; cCSLock Lock(m_CSClients); for (ClientList::iterator itr = m_Clients.begin(); itr != m_Clients.end(); ++itr) { - std::string username = (*itr)->GetUsername(); + AString username = (*itr)->GetUsername(); usernames.insert(usernames.begin(),username); } return usernames; -- cgit v1.2.3 From f206f34a3d1d5bdda7625a61dcf35514f485af79 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Wed, 3 Dec 2014 18:04:21 +0100 Subject: Server: Fixed a MSVC warning. --- src/Server.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Server.cpp') diff --git a/src/Server.cpp b/src/Server.cpp index 8759d5747..db1522602 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -78,7 +78,7 @@ void cServer::cTickThread::Execute(void) while (!m_ShouldTerminate) { auto NowTime = std::chrono::steady_clock::now(); - m_ShouldTerminate = !m_Server.Tick(std::chrono::duration_cast(NowTime - LastTime).count()); + m_ShouldTerminate = !m_Server.Tick(static_cast(std::chrono::duration_cast(NowTime - LastTime).count())); auto TickTime = std::chrono::steady_clock::now() - NowTime; if (TickTime < msPerTick) -- cgit v1.2.3 From 3c3cb198f33fd55b9cb20188cc42034b21660d21 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sun, 7 Dec 2014 15:46:27 +0100 Subject: Fixed c++11 branch issues. --- src/Server.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/Server.cpp') diff --git a/src/Server.cpp b/src/Server.cpp index db1522602..d6163df7e 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -78,7 +78,8 @@ void cServer::cTickThread::Execute(void) while (!m_ShouldTerminate) { auto NowTime = std::chrono::steady_clock::now(); - m_ShouldTerminate = !m_Server.Tick(static_cast(std::chrono::duration_cast(NowTime - LastTime).count())); + auto msec = std::chrono::duration_cast(NowTime - LastTime).count(); + m_ShouldTerminate = !m_Server.Tick(static_cast(msec)); auto TickTime = std::chrono::steady_clock::now() - NowTime; if (TickTime < msPerTick) -- cgit v1.2.3 From 8edfd7829505d43c7d6bf7fcc582e0d7cb29e1d5 Mon Sep 17 00:00:00 2001 From: Vincent Date: Sun, 7 Dec 2014 12:41:42 -0800 Subject: changed from using iterator to auto for server and clienthandle --- src/Server.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Server.cpp') diff --git a/src/Server.cpp b/src/Server.cpp index ed02500ff..15c9521b9 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -308,9 +308,9 @@ std::list cServer::GetUsernames() { std::list usernames; cCSLock Lock(m_CSClients); - for (ClientList::iterator itr = m_Clients.begin(); itr != m_Clients.end(); ++itr) + for (auto client : m_Clients) { - AString username = (*itr)->GetUsername(); + AString username = (client)->GetUsername(); usernames.insert(usernames.begin(),username); } return usernames; -- cgit v1.2.3 From 6de07d4a39096f19c075695824aa87a1907e4edc Mon Sep 17 00:00:00 2001 From: Vincent Date: Mon, 8 Dec 2014 00:45:29 -0800 Subject: Fixed compile errors --- src/Server.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/Server.cpp') diff --git a/src/Server.cpp b/src/Server.cpp index 15c9521b9..a1dd27c57 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -304,16 +304,17 @@ int cServer::GetNumPlayers(void) const -std::list cServer::GetUsernames() +bool cServer::IsPlayerInQueue(AString a_Username) { - std::list usernames; cCSLock Lock(m_CSClients); for (auto client : m_Clients) { - AString username = (client)->GetUsername(); - usernames.insert(usernames.begin(),username); + if ((client->GetUsername()).compare(a_Username) == 0) + { + return true; + } } - return usernames; + return false; } -- cgit v1.2.3