MCPcopy Create free account
hub / github.com/cuberite/cuberite / InitServer

Method InitServer

src/Server.cpp:191–272  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

189
190
191bool cServer::InitServer(cIniFile & a_SettingsIni)
192{
193 m_Description = a_SettingsIni.GetValueSet("Server", "Description", "MCServer - in C++!").c_str();
194 m_MaxPlayers = a_SettingsIni.GetValueSetI("Server", "MaxPlayers", 100);
195 m_bIsHardcore = a_SettingsIni.GetValueSetB("Server", "HardcoreEnabled", false);
196 m_PlayerCount = 0;
197 m_PlayerCountDiff = 0;
198
199 m_FaviconData = Base64Encode(cFile::ReadWholeFile(FILE_IO_PREFIX + AString("favicon.png"))); // Will return empty string if file nonexistant; client doesn't mind
200
201 if (m_bIsConnected)
202 {
203 LOGERROR("ERROR: Trying to initialize server while server is already running!");
204 return false;
205 }
206
207 LOGINFO("Compatible clients: %s", MCS_CLIENT_VERSIONS);
208 LOGINFO("Compatible protocol versions %s", MCS_PROTOCOL_VERSIONS);
209
210 if (cSocket::WSAStartup() != 0) // Only does anything on Windows, but whatever
211 {
212 LOGERROR("WSAStartup() != 0");
213 return false;
214 }
215
216 bool HasAnyPorts = false;
217 AString Ports = a_SettingsIni.GetValueSet("Server", "Port", "25565");
218 m_ListenThreadIPv4.SetReuseAddr(true);
219 if (m_ListenThreadIPv4.Initialize(Ports))
220 {
221 HasAnyPorts = true;
222 }
223
224 Ports = a_SettingsIni.GetValueSet("Server", "PortsIPv6", "25565");
225 m_ListenThreadIPv6.SetReuseAddr(true);
226 if (m_ListenThreadIPv6.Initialize(Ports))
227 {
228 HasAnyPorts = true;
229 }
230
231 if (!HasAnyPorts)
232 {
233 LOGERROR("Couldn't open any ports. Aborting the server");
234 return false;
235 }
236
237 m_RCONServer.Initialize(a_SettingsIni);
238
239 m_bIsConnected = true;
240
241 m_ServerID = "-";
242 m_ShouldAuthenticate = a_SettingsIni.GetValueSetB("Authentication", "Authenticate", true);
243 if (m_ShouldAuthenticate)
244 {
245 MTRand mtrand1;
246 unsigned int r1 = (mtrand1.randInt() % 1147483647) + 1000000000;
247 unsigned int r2 = (mtrand1.randInt() % 1147483647) + 1000000000;
248 std::ostringstream sid;

Callers 1

StartMethod · 0.80

Calls 12

Base64EncodeFunction · 0.85
LOGERRORFunction · 0.85
LOGINFOFunction · 0.85
c_strMethod · 0.80
GetValueSetMethod · 0.80
GetValueSetIMethod · 0.80
GetValueSetBMethod · 0.80
SetReuseAddrMethod · 0.80
randIntMethod · 0.80
resizeMethod · 0.80
InitializeMethod · 0.45
StartMethod · 0.45

Tested by

no test coverage detected