Max. players and MOTD are now changeable in the settings.ini
Thanks to mtilden ( http://forum.mc-server.org/showthread.php?tid=183&pid=1381#pid1381 ) git-svn-id: http://mc-server.googlecode.com/svn/trunk@101 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
parent
aa392170a2
commit
ad610e63ba
@ -1,6 +1,8 @@
|
|||||||
[Server]
|
[Server]
|
||||||
Port=25565
|
Port=25565
|
||||||
ServerID=-
|
ServerID=-
|
||||||
|
MaxPlayers=10000
|
||||||
|
Description=MCServer - Slightly more custom!
|
||||||
|
|
||||||
[Worlds]
|
[Worlds]
|
||||||
DefaultWorld=world
|
DefaultWorld=world
|
||||||
|
@ -395,9 +395,10 @@ void cClientHandle::HandlePacket( cPacket* a_Packet )
|
|||||||
case E_PING: // Somebody tries to retreive information about the server
|
case E_PING: // Somebody tries to retreive information about the server
|
||||||
{
|
{
|
||||||
LOGINFO("Got ping");
|
LOGINFO("Got ping");
|
||||||
char NumPlayers[8];
|
char NumPlayers[8], cMaxPlayers[8];
|
||||||
sprintf_s(NumPlayers, 8, "%i", cRoot::Get()->GetWorld()->GetNumPlayers() );
|
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" );
|
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() );
|
Kick( response.c_str() );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -407,6 +408,11 @@ void cClientHandle::HandlePacket( cPacket* a_Packet )
|
|||||||
m_pState->Username = PacketData->m_Username;
|
m_pState->Username = PacketData->m_Username;
|
||||||
LOG("HANDSHAKE %s", GetUsername() );
|
LOG("HANDSHAKE %s", GetUsername() );
|
||||||
cPacket_Chat Connecting(m_pState->Username + " is connecting.");
|
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 );
|
cRoot::Get()->GetServer()->Broadcast( Connecting, this );
|
||||||
|
|
||||||
// Give a server handshake thingy back
|
// Give a server handshake thingy back
|
||||||
|
@ -183,6 +183,8 @@ cWorld::cWorld( const char* a_WorldName )
|
|||||||
{
|
{
|
||||||
m_bAnimals = IniFile2.GetValueB("Monsters", "AnimalsOn", true );
|
m_bAnimals = IniFile2.GetValueB("Monsters", "AnimalsOn", true );
|
||||||
m_SpawnMonsterRate = (float)IniFile2.GetValueF("Monsters", "AnimalSpawnInterval", 10 );
|
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 );
|
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 )
|
void cWorld::AddPlayer( cPlayer* a_Player )
|
||||||
{
|
{
|
||||||
m_pState->m_Players.remove( a_Player );
|
m_pState->m_Players.remove( a_Player );
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
enum ENUM_ITEM_ID;
|
enum ENUM_ITEM_ID;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define MAX_PLAYERS 65535
|
||||||
|
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@ -55,6 +57,13 @@ public:
|
|||||||
|
|
||||||
void Broadcast( const cPacket & a_Packet, cClientHandle* a_Exclude = 0 );
|
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 AddPlayer( cPlayer* a_Player );
|
||||||
void RemovePlayer( cPlayer* a_Player );
|
void RemovePlayer( cPlayer* a_Player );
|
||||||
PlayerList & GetAllPlayers();
|
PlayerList & GetAllPlayers();
|
||||||
@ -169,12 +178,11 @@ private:
|
|||||||
cCriticalSection* m_EntitiesCriticalSection;
|
cCriticalSection* m_EntitiesCriticalSection;
|
||||||
cCriticalSection* m_ChunksCriticalSection;
|
cCriticalSection* m_ChunksCriticalSection;
|
||||||
|
|
||||||
|
std::string m_Description;
|
||||||
|
unsigned int m_MaxPlayers;
|
||||||
|
|
||||||
cChunkMap* m_ChunkMap;
|
cChunkMap* m_ChunkMap;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool m_bAnimals;
|
bool m_bAnimals;
|
||||||
float m_SpawnMonsterTime;
|
float m_SpawnMonsterTime;
|
||||||
float m_SpawnMonsterRate;
|
float m_SpawnMonsterRate;
|
||||||
|
Loading…
Reference in New Issue
Block a user