diff options
author | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-11-11 15:23:47 +0100 |
---|---|---|
committer | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-11-11 15:23:47 +0100 |
commit | f46d4bd5611a285d1c71e7ee56c7b6913fd28a2d (patch) | |
tree | 5dff7a9e977464d9efc4e43824ece9e47e0a5ac1 | |
parent | PrimaryServerVersion is not force-saved into settings.ini. (diff) | |
download | cuberite-f46d4bd5611a285d1c71e7ee56c7b6913fd28a2d.tar cuberite-f46d4bd5611a285d1c71e7ee56c7b6913fd28a2d.tar.gz cuberite-f46d4bd5611a285d1c71e7ee56c7b6913fd28a2d.tar.bz2 cuberite-f46d4bd5611a285d1c71e7ee56c7b6913fd28a2d.tar.lz cuberite-f46d4bd5611a285d1c71e7ee56c7b6913fd28a2d.tar.xz cuberite-f46d4bd5611a285d1c71e7ee56c7b6913fd28a2d.tar.zst cuberite-f46d4bd5611a285d1c71e7ee56c7b6913fd28a2d.zip |
Diffstat (limited to '')
-rw-r--r-- | source/Root.cpp | 9 | ||||
-rw-r--r-- | source/Server.cpp | 65 | ||||
-rw-r--r-- | source/Server.h | 3 |
3 files changed, 38 insertions, 39 deletions
diff --git a/source/Root.cpp b/source/Root.cpp index c624ef9aa..1e901739f 100644 --- a/source/Root.cpp +++ b/source/Root.cpp @@ -96,10 +96,11 @@ void cRoot::Start(void) LOG("Creating new server instance..."); m_Server = new cServer(); - LOG("Starting server..."); + LOG("Reading server config..."); 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.ReadFile(); IniFile.Path("settings.ini"); @@ -115,8 +116,8 @@ void cRoot::Start(void) LOGINFO("settings.ini: [Server].PrimaryServerVersion set to %d.", m_PrimaryServerVersion); } - int Port = IniFile.GetValueSetI("Server", "Port", 25565 ); - if (!m_Server->InitServer(Port)) + LOG("Starting server..."); + if (!m_Server->InitServer(IniFile)) { LOGERROR("Failed to start server, shutting down."); return; diff --git a/source/Server.cpp b/source/Server.cpp index ea25392a5..95d5617cb 100644 --- a/source/Server.cpp +++ b/source/Server.cpp @@ -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!"); return false; @@ -175,7 +175,7 @@ bool cServer::InitServer( int a_Port ) LOG("Starting up server."); 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"); return false; @@ -195,10 +195,12 @@ bool cServer::InitServer( int a_Port ) return false; } + int Port = a_SettingsIni.GetValueSetI("Server", "Port", 25565); + cSocket::SockAddr_In local; local.Family = cSocket::ADDRESS_FAMILY_INTERNET; 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 ) { @@ -212,39 +214,34 @@ bool cServer::InitServer( int a_Port ) return false; } - m_iServerPort = a_Port; - LOG("Port %i has been bound, server is open for connections", m_iServerPort); + m_iServerPort = Port; + LOG("Port %i has been bound", m_iServerPort); m_bIsConnected = true; - cIniFile IniFile("settings.ini"); - if (IniFile.ReadFile()) + m_pState->ServerID = "-"; + if (a_SettingsIni.GetValueSetB("Authentication", "Authenticate", true)) { - m_pState->ServerID = "-"; - if (IniFile.GetValueSetB("Authentication", "Authenticate", true)) - { - MTRand mtrand1; - unsigned int r1 = (mtrand1.randInt()%1147483647) + 1000000000; - unsigned int r2 = (mtrand1.randInt()%1147483647) + 1000000000; - std::ostringstream sid; - sid << std::hex << r1; - sid << std::hex << r2; - std::string ServerID = sid.str(); - ServerID.resize(16, '0'); - m_pState->ServerID = ServerID; - } - - m_ClientViewDistance = IniFile.GetValueSetI("Server", "DefaultViewDistance", cClientHandle::DEFAULT_VIEW_DISTANCE); - if (m_ClientViewDistance < cClientHandle::MIN_VIEW_DISTANCE) - { - m_ClientViewDistance = cClientHandle::MIN_VIEW_DISTANCE; - LOGINFO("Setting default viewdistance to the minimum of %d", m_ClientViewDistance); - } - if (m_ClientViewDistance > cClientHandle::MAX_VIEW_DISTANCE) - { - m_ClientViewDistance = cClientHandle::MAX_VIEW_DISTANCE; - LOGINFO("Setting default viewdistance to the maximum of %d", m_ClientViewDistance); - } - IniFile.WriteFile(); + MTRand mtrand1; + unsigned int r1 = (mtrand1.randInt()%1147483647) + 1000000000; + unsigned int r2 = (mtrand1.randInt()%1147483647) + 1000000000; + std::ostringstream sid; + sid << std::hex << r1; + sid << std::hex << r2; + 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 = cClientHandle::MIN_VIEW_DISTANCE; + LOGINFO("Setting default viewdistance to the minimum of %d", m_ClientViewDistance); + } + if (m_ClientViewDistance > cClientHandle::MAX_VIEW_DISTANCE) + { + m_ClientViewDistance = cClientHandle::MAX_VIEW_DISTANCE; + LOGINFO("Setting default viewdistance to the maximum of %d", m_ClientViewDistance); } m_NotifyWriteThread.Start(this); diff --git a/source/Server.h b/source/Server.h index 8d21e7834..a93ee454a 100644 --- a/source/Server.h +++ b/source/Server.h @@ -21,6 +21,7 @@ class cPlayer; class cClientHandle; +class cIniFile; typedef std::list<cClientHandle *> cClientHandleList; @@ -33,7 +34,7 @@ class cServer //tolua_export public: //tolua_export static cServer * GetServer(); //tolua_export - bool InitServer( int a_Port = 25565 ); + bool InitServer(cIniFile & a_SettingsIni); int GetPort() { return m_iServerPort; } bool IsConnected(){return m_bIsConnected;} // returns connection status |