1
0
Fork 0

Settings.ini is read only once on server start

git-svn-id: http://mc-server.googlecode.com/svn/trunk@1035 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
madmaxoft@gmail.com 2012-11-11 14:23:47 +00:00
parent 83b949f490
commit f46d4bd561
3 changed files with 38 additions and 39 deletions

View File

@ -96,10 +96,11 @@ void cRoot::Start(void)
LOG("Creating new server instance..."); LOG("Creating new server instance...");
m_Server = new cServer(); m_Server = new cServer();
LOG("Starting server..."); LOG("Reading server config...");
cIniFile IniFile("settings.ini"); cIniFile IniFile("settings.ini");
if ( IniFile.ReadFile() == false ) if (!IniFile.ReadFile())
{ {
LOGINFO("settings.ini inaccessible, using settings.example.ini for defaults!");
IniFile.Path("settings.example.ini"); IniFile.Path("settings.example.ini");
IniFile.ReadFile(); IniFile.ReadFile();
IniFile.Path("settings.ini"); IniFile.Path("settings.ini");
@ -115,8 +116,8 @@ void cRoot::Start(void)
LOGINFO("settings.ini: [Server].PrimaryServerVersion set to %d.", m_PrimaryServerVersion); LOGINFO("settings.ini: [Server].PrimaryServerVersion set to %d.", m_PrimaryServerVersion);
} }
int Port = IniFile.GetValueSetI("Server", "Port", 25565 ); LOG("Starting server...");
if (!m_Server->InitServer(Port)) if (!m_Server->InitServer(IniFile))
{ {
LOGERROR("Failed to start server, shutting down."); LOGERROR("Failed to start server, shutting down.");
return; return;

View File

@ -150,9 +150,9 @@ void cServer::RemoveClient(const cClientHandle * a_Client)
bool cServer::InitServer( int a_Port ) bool cServer::InitServer(cIniFile & a_SettingsIni)
{ {
if( m_bIsConnected ) if (m_bIsConnected)
{ {
LOGERROR("ERROR: Trying to initialize server while server is already running!"); LOGERROR("ERROR: Trying to initialize server while server is already running!");
return false; return false;
@ -175,7 +175,7 @@ bool cServer::InitServer( int a_Port )
LOG("Starting up server."); LOG("Starting up server.");
LOGINFO("Compatible clients: %s, protocol versions %s", MCS_CLIENT_VERSIONS, MCS_PROTOCOL_VERSIONS); LOGINFO("Compatible clients: %s, protocol versions %s", MCS_CLIENT_VERSIONS, MCS_PROTOCOL_VERSIONS);
if( cSocket::WSAStartup() != 0 ) // Only does anything on Windows, but whatever if (cSocket::WSAStartup() != 0) // Only does anything on Windows, but whatever
{ {
LOGERROR("WSAStartup() != 0"); LOGERROR("WSAStartup() != 0");
return false; return false;
@ -195,10 +195,12 @@ bool cServer::InitServer( int a_Port )
return false; return false;
} }
int Port = a_SettingsIni.GetValueSetI("Server", "Port", 25565);
cSocket::SockAddr_In local; cSocket::SockAddr_In local;
local.Family = cSocket::ADDRESS_FAMILY_INTERNET; local.Family = cSocket::ADDRESS_FAMILY_INTERNET;
local.Address = cSocket::INTERNET_ADDRESS_ANY; local.Address = cSocket::INTERNET_ADDRESS_ANY;
local.Port = (unsigned short)a_Port; // 25565 local.Port = (unsigned short)Port;
if( m_pState->SListenClient.Bind( local ) != 0 ) if( m_pState->SListenClient.Bind( local ) != 0 )
{ {
@ -212,39 +214,34 @@ bool cServer::InitServer( int a_Port )
return false; return false;
} }
m_iServerPort = a_Port; m_iServerPort = Port;
LOG("Port %i has been bound, server is open for connections", m_iServerPort); LOG("Port %i has been bound", m_iServerPort);
m_bIsConnected = true; m_bIsConnected = true;
cIniFile IniFile("settings.ini"); m_pState->ServerID = "-";
if (IniFile.ReadFile()) if (a_SettingsIni.GetValueSetB("Authentication", "Authenticate", true))
{ {
m_pState->ServerID = "-"; MTRand mtrand1;
if (IniFile.GetValueSetB("Authentication", "Authenticate", true)) unsigned int r1 = (mtrand1.randInt()%1147483647) + 1000000000;
{ unsigned int r2 = (mtrand1.randInt()%1147483647) + 1000000000;
MTRand mtrand1; std::ostringstream sid;
unsigned int r1 = (mtrand1.randInt()%1147483647) + 1000000000; sid << std::hex << r1;
unsigned int r2 = (mtrand1.randInt()%1147483647) + 1000000000; sid << std::hex << r2;
std::ostringstream sid; std::string ServerID = sid.str();
sid << std::hex << r1; ServerID.resize(16, '0');
sid << std::hex << r2; m_pState->ServerID = ServerID;
std::string ServerID = sid.str(); }
ServerID.resize(16, '0');
m_pState->ServerID = ServerID; m_ClientViewDistance = a_SettingsIni.GetValueSetI("Server", "DefaultViewDistance", cClientHandle::DEFAULT_VIEW_DISTANCE);
} if (m_ClientViewDistance < cClientHandle::MIN_VIEW_DISTANCE)
{
m_ClientViewDistance = IniFile.GetValueSetI("Server", "DefaultViewDistance", cClientHandle::DEFAULT_VIEW_DISTANCE); m_ClientViewDistance = cClientHandle::MIN_VIEW_DISTANCE;
if (m_ClientViewDistance < cClientHandle::MIN_VIEW_DISTANCE) LOGINFO("Setting default viewdistance to the minimum of %d", m_ClientViewDistance);
{ }
m_ClientViewDistance = cClientHandle::MIN_VIEW_DISTANCE; if (m_ClientViewDistance > cClientHandle::MAX_VIEW_DISTANCE)
LOGINFO("Setting default viewdistance to the minimum of %d", m_ClientViewDistance); {
} m_ClientViewDistance = cClientHandle::MAX_VIEW_DISTANCE;
if (m_ClientViewDistance > cClientHandle::MAX_VIEW_DISTANCE) LOGINFO("Setting default viewdistance to the maximum of %d", m_ClientViewDistance);
{
m_ClientViewDistance = cClientHandle::MAX_VIEW_DISTANCE;
LOGINFO("Setting default viewdistance to the maximum of %d", m_ClientViewDistance);
}
IniFile.WriteFile();
} }
m_NotifyWriteThread.Start(this); m_NotifyWriteThread.Start(this);

View File

@ -21,6 +21,7 @@
class cPlayer; class cPlayer;
class cClientHandle; class cClientHandle;
class cIniFile;
typedef std::list<cClientHandle *> cClientHandleList; typedef std::list<cClientHandle *> cClientHandleList;
@ -33,7 +34,7 @@ class cServer //tolua_export
public: //tolua_export public: //tolua_export
static cServer * GetServer(); //tolua_export static cServer * GetServer(); //tolua_export
bool InitServer( int a_Port = 25565 ); bool InitServer(cIniFile & a_SettingsIni);
int GetPort() { return m_iServerPort; } int GetPort() { return m_iServerPort; }
bool IsConnected(){return m_bIsConnected;} // returns connection status bool IsConnected(){return m_bIsConnected;} // returns connection status