1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-19 22:23:51 +00:00

[Server] Log all exceptions

This commit is contained in:
Koncord 2017-06-11 20:04:33 +08:00
parent 51b95f35cd
commit 7b98f9f7ff

View file

@ -247,8 +247,7 @@ int main(int argc, char *argv[])
setenv("LUA_CPATH", Utils::convertPath(plugin_home + "/lib/?.so").c_str(), 1); setenv("LUA_CPATH", Utils::convertPath(plugin_home + "/lib/?.so").c_str(), 1);
#endif #endif
for (auto plugin : plugins) int code;
Script::LoadScript(plugin.c_str(), plugin_home.c_str());
RakNet::RakPeerInterface *peer = RakNet::RakPeerInterface::GetInstance(); RakNet::RakPeerInterface *peer = RakNet::RakPeerInterface::GetInstance();
@ -265,8 +264,33 @@ int main(int argc, char *argv[])
} }
RakNet::SocketDescriptor sd((unsigned short) port, addr.c_str()); RakNet::SocketDescriptor sd((unsigned short) port, addr.c_str());
if (peer->Startup((unsigned)players, &sd, 1) != RakNet::RAKNET_STARTED)
return 1; try
{
for (auto plugin : plugins)
Script::LoadScript(plugin.c_str(), plugin_home.c_str());
switch (peer->Startup((unsigned) players, &sd, 1))
{
case RakNet::RAKNET_STARTED:
break;
case RakNet::RAKNET_ALREADY_STARTED:
throw runtime_error("Already started");
case RakNet::INVALID_SOCKET_DESCRIPTORS:
throw runtime_error("Incorrect port or address");
case RakNet::INVALID_MAX_CONNECTIONS:
throw runtime_error("Max players cannot be negative or 0");
case RakNet::SOCKET_FAILED_TO_BIND:
case RakNet::SOCKET_PORT_ALREADY_IN_USE:
case RakNet::PORT_CANNOT_BE_ZERO:
throw runtime_error("Failed to bind port");
case RakNet::SOCKET_FAILED_TEST_SEND:
case RakNet::SOCKET_FAMILY_NOT_SUPPORTED:
case RakNet::FAILED_TO_CREATE_NETWORK_THREAD:
case RakNet::COULD_NOT_GENERATE_GUID:
case RakNet::STARTUP_OTHER_FAILURE:
throw runtime_error("Cannot start server");
}
peer->SetMaximumIncomingConnections((unsigned short) (players)); peer->SetMaximumIncomingConnections((unsigned short) (players));
@ -292,11 +316,17 @@ int main(int argc, char *argv[])
networking.postInit(); networking.postInit();
int code = networking.mainLoop(); code = networking.mainLoop();
RakNet::RakPeerInterface::DestroyInstance(peer);
networking.getMasterClient()->Stop(); networking.getMasterClient()->Stop();
}
catch (std::exception &e)
{
LOG_MESSAGE_SIMPLE(Log::LOG_ERROR, e.what());
throw; //fall through
}
RakNet::RakPeerInterface::DestroyInstance(peer);
if (code == 0) if (code == 0)
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Quitting peacefully."); LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Quitting peacefully.");
@ -308,6 +338,7 @@ int main(int argc, char *argv[])
std::cerr.rdbuf(cerr_rdbuf); std::cerr.rdbuf(cerr_rdbuf);
} }
breakpad_close(); breakpad_close();
return code; return code;
} }