summaryrefslogtreecommitdiffstats
path: root/source/Server.cpp
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-11-11 15:23:47 +0100
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-11-11 15:23:47 +0100
commitf46d4bd5611a285d1c71e7ee56c7b6913fd28a2d (patch)
tree5dff7a9e977464d9efc4e43824ece9e47e0a5ac1 /source/Server.cpp
parentPrimaryServerVersion is not force-saved into settings.ini. (diff)
downloadcuberite-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/Server.cpp65
1 files changed, 31 insertions, 34 deletions
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);