summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlapayo94@gmail.com <lapayo94@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2011-12-24 00:58:54 +0100
committerlapayo94@gmail.com <lapayo94@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2011-12-24 00:58:54 +0100
commitad610e63ba6ff21b84b455d310052985ecb78585 (patch)
treeaa371ec6f4895d48fb828bf28e1111aaf7b5d9d5
parentAdded thread names to cThread so when debugging in Visual Studio you actually know what thread you're looking at (diff)
downloadcuberite-ad610e63ba6ff21b84b455d310052985ecb78585.tar
cuberite-ad610e63ba6ff21b84b455d310052985ecb78585.tar.gz
cuberite-ad610e63ba6ff21b84b455d310052985ecb78585.tar.bz2
cuberite-ad610e63ba6ff21b84b455d310052985ecb78585.tar.lz
cuberite-ad610e63ba6ff21b84b455d310052985ecb78585.tar.xz
cuberite-ad610e63ba6ff21b84b455d310052985ecb78585.tar.zst
cuberite-ad610e63ba6ff21b84b455d310052985ecb78585.zip
-rw-r--r--settings.ini14
-rw-r--r--source/cClientHandle.cpp12
-rw-r--r--source/cWorld.cpp21
-rw-r--r--source/cWorld.h16
4 files changed, 50 insertions, 13 deletions
diff --git a/settings.ini b/settings.ini
index 09bd77466..825e23b65 100644
--- a/settings.ini
+++ b/settings.ini
@@ -1,9 +1,11 @@
-[Server]
-Port=25565
-ServerID=-
-
-[Worlds]
-DefaultWorld=world
+[Server]
+Port=25565
+ServerID=-
+MaxPlayers=10000
+Description=MCServer - Slightly more custom!
+
+[Worlds]
+DefaultWorld=world
World=world_sexy
[Plugins]
diff --git a/source/cClientHandle.cpp b/source/cClientHandle.cpp
index 8374a8045..548dafeb6 100644
--- a/source/cClientHandle.cpp
+++ b/source/cClientHandle.cpp
@@ -395,9 +395,10 @@ void cClientHandle::HandlePacket( cPacket* a_Packet )
case E_PING: // Somebody tries to retreive information about the server
{
LOGINFO("Got ping");
- char NumPlayers[8];
- sprintf_s(NumPlayers, 8, "%i", cRoot::Get()->GetWorld()->GetNumPlayers() );
- std::string response = std::string("MCServer! - It's OVER 9000!" + cChatColor::Delimiter + NumPlayers + cChatColor::Delimiter + "9001" );
+ char NumPlayers[8], cMaxPlayers[8];
+ sprintf_s(NumPlayers, 8, "%i", cRoot::Get()->GetWorld()->GetNumPlayers());
+ sprintf_s(cMaxPlayers, 8, "%i", cRoot::Get()->GetWorld()->GetMaxPlayers());
+ std::string response = std::string(cRoot::Get()->GetWorld()->GetDescription() + cChatColor::Delimiter + NumPlayers + cChatColor::Delimiter + cMaxPlayers );
Kick( response.c_str() );
}
break;
@@ -407,6 +408,11 @@ void cClientHandle::HandlePacket( cPacket* a_Packet )
m_pState->Username = PacketData->m_Username;
LOG("HANDSHAKE %s", GetUsername() );
cPacket_Chat Connecting(m_pState->Username + " is connecting.");
+
+ if (cRoot::Get()->GetWorld()->GetNumPlayers() == cRoot::Get()->GetWorld()->GetMaxPlayers()) {
+ Kick("The server is currently full :( -- Try again later");
+ break;
+ }
cRoot::Get()->GetServer()->Broadcast( Connecting, this );
// Give a server handshake thingy back
diff --git a/source/cWorld.cpp b/source/cWorld.cpp
index b1a0d1813..2f5ed1c2b 100644
--- a/source/cWorld.cpp
+++ b/source/cWorld.cpp
@@ -183,6 +183,8 @@ cWorld::cWorld( const char* a_WorldName )
{
m_bAnimals = IniFile2.GetValueB("Monsters", "AnimalsOn", true );
m_SpawnMonsterRate = (float)IniFile2.GetValueF("Monsters", "AnimalSpawnInterval", 10 );
+ SetMaxPlayers(IniFile2.GetValueI("Server", "MaxPlayers", 9001));
+ m_Description = IniFile2.GetValue("Server", "Description", "MCServer! - It's OVER 9000!").c_str();
}
m_ChunkMap = new cChunkMap( 32, 32, this );
@@ -766,6 +768,25 @@ void cWorld::Broadcast( const cPacket & a_Packet, cClientHandle* a_Exclude /* =
}
}
+std::string cWorld::GetDescription()
+{
+ return this->m_Description;
+}
+
+unsigned int cWorld::GetMaxPlayers()
+{
+ return this->m_MaxPlayers;
+}
+
+void cWorld::SetMaxPlayers(int iMax)
+{
+ this->m_MaxPlayers = MAX_PLAYERS;
+ if (iMax > 0 && iMax < MAX_PLAYERS)
+ {
+ this->m_MaxPlayers = iMax;
+ }
+}
+
void cWorld::AddPlayer( cPlayer* a_Player )
{
m_pState->m_Players.remove( a_Player );
diff --git a/source/cWorld.h b/source/cWorld.h
index 6e407f656..83a9bcf66 100644
--- a/source/cWorld.h
+++ b/source/cWorld.h
@@ -6,6 +6,8 @@
enum ENUM_ITEM_ID;
#endif
+#define MAX_PLAYERS 65535
+
#include <list>
#include <vector>
@@ -54,6 +56,13 @@ public:
//ClientList & GetClients();
void Broadcast( const cPacket & a_Packet, cClientHandle* a_Exclude = 0 );
+
+ // MOTD
+ std::string GetDescription();
+
+ // Max Players
+ unsigned int GetMaxPlayers();
+ void SetMaxPlayers(int iMax);
void AddPlayer( cPlayer* a_Player );
void RemovePlayer( cPlayer* a_Player );
@@ -168,13 +177,12 @@ private:
cCriticalSection* m_ClientHandleCriticalSection;
cCriticalSection* m_EntitiesCriticalSection;
cCriticalSection* m_ChunksCriticalSection;
-
-
+
+ std::string m_Description;
+ unsigned int m_MaxPlayers;
cChunkMap* m_ChunkMap;
-
-
bool m_bAnimals;
float m_SpawnMonsterTime;
float m_SpawnMonsterRate;