summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent <vincent.leung60@gmail.com>2014-11-29 09:36:15 +0100
committerVincent <vincent.leung60@gmail.com>2014-11-29 09:36:15 +0100
commit61e761fdc2bfa5c77002d68bb24e0470def37b48 (patch)
treeefb8e5a7b544f9402d186201c1f9150511bcc1a9
parentMerge pull request #1619 from mc-server/WarningFixes (diff)
downloadcuberite-61e761fdc2bfa5c77002d68bb24e0470def37b48.tar
cuberite-61e761fdc2bfa5c77002d68bb24e0470def37b48.tar.gz
cuberite-61e761fdc2bfa5c77002d68bb24e0470def37b48.tar.bz2
cuberite-61e761fdc2bfa5c77002d68bb24e0470def37b48.tar.lz
cuberite-61e761fdc2bfa5c77002d68bb24e0470def37b48.tar.xz
cuberite-61e761fdc2bfa5c77002d68bb24e0470def37b48.tar.zst
cuberite-61e761fdc2bfa5c77002d68bb24e0470def37b48.zip
-rw-r--r--src/ClientHandle.cpp18
-rw-r--r--src/Server.cpp17
-rw-r--r--src/Server.h9
-rw-r--r--src/World.cpp12
-rw-r--r--src/World.h2
5 files changed, 58 insertions, 0 deletions
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index a6cbad32a..ae794d7cb 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -1798,6 +1798,24 @@ bool cClientHandle::HandleHandshake(const AString & a_Username)
return false;
}
}
+ if (!(cRoot::Get()->GetServer()->isAllowMultiLogin()))
+ {
+ std::list<std::string> usernamesServer = cRoot::Get()->GetServer()->GetUsernames();
+ std::list<std::string> usernamesWorld = cRoot::Get()->GetDefaultWorld()-> GetUsernames();
+
+ usernamesServer.sort();
+ usernamesWorld.sort();
+ usernamesServer.merge(usernamesWorld);
+
+ for (std::list<std::string>::iterator itr = usernamesServer.begin(); itr != usernamesServer.end(); ++itr)
+ {
+ if ((*itr).compare(a_Username) == 0)
+ {
+ Kick("User already logged in.");
+ return false;
+ }
+ }
+ }
return true;
}
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<std::string> cServer::GetUsernames()
+{
+ std::list<std::string> 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...");
diff --git a/src/Server.h b/src/Server.h
index 022794bbc..91e6e5c45 100644
--- a/src/Server.h
+++ b/src/Server.h
@@ -67,6 +67,12 @@ public: // tolua_export
int GetNumPlayers(void) const;
void SetMaxPlayers(int a_MaxPlayers) { m_MaxPlayers = a_MaxPlayers; }
+ // Get the users waiting to be put into the World.
+ std::list<std::string> GetUsernames(void);
+
+ // Can login more than once with same username.
+ bool isAllowMultiLogin(void) { return m_bAllowMultiLogin; }
+
// Hardcore mode or not:
bool IsHardcore(void) const { return m_bIsHardcore; }
@@ -216,6 +222,9 @@ private:
int m_MaxPlayers;
bool m_bIsHardcore;
+ /** True - allow same username to login more than once False - only once */
+ bool m_bAllowMultiLogin;
+
cTickThread m_TickThread;
cEvent m_RestartEvent;
diff --git a/src/World.cpp b/src/World.cpp
index 0dec0bd96..9ae9e41d9 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -3666,3 +3666,15 @@ void cWorld::cChunkGeneratorCallbacks::CallHookChunkGenerated (cChunkDesc & a_Ch
+
+std::list<std::string> cWorld::GetUsernames()
+{
+ std::list<std::string> usernames;
+ cCSLock Lock(m_CSPlayers);
+ for (cPlayerList::iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr)
+ {
+ std::string username = (*itr)->GetName();
+ usernames.insert(usernames.begin(),username);
+ }
+ return usernames;
+}
diff --git a/src/World.h b/src/World.h
index 68d0654ee..81470f869 100644
--- a/src/World.h
+++ b/src/World.h
@@ -808,6 +808,8 @@ public:
as at least one requests is active the chunk will be ticked). */
void SetChunkAlwaysTicked(int a_ChunkX, int a_ChunkZ, bool a_AlwaysTicked = true); // tolua_export
+ /** Get the usernames from the World. */
+ std::list<std::string> GetUsernames(void);
private:
friend class cRoot;