#include #include #include #include #include #include #include #ifndef _WINDOWS #include #endif #include #include #include #include "Server.h" #include "ChunkMap.h" FactoryCraftServer* mserver = 0; void exit() { if (mserver) { std::cout << "The server terminated unexpectedly. Trying to save game progress.\n"; mserver->close(); } } int main() { Framework::initFramework(); initializeBlockTypes(); initializeItemTypes(); initializeEntityTypes(); initializeDimensions(); initializeMultiblockTypes(); #ifndef _WINDOWS struct rlimit core_limits; core_limits.rlim_cur = core_limits.rlim_max = RLIM_INFINITY; setrlimit(RLIMIT_CORE, &core_limits); #endif Zeit* z = getZeit(); Text* pfad = new Text("log/"); pfad->append(z->getZeit("y-m-d_h-i-s.log")); z->release(); DateiPfadErstellen(pfad->getText()); std::ofstream file; file.open(pfad->getText()); std::streambuf* sbuf = std::cout.rdbuf(); #ifndef _DEBUG std::cout.rdbuf( file.rdbuf() ); #endif pfad->release(); std::cout << "Starting...\n"; std::cout << "Loading config file fcInit.ini ...\n"; InitDatei* dat = new InitDatei("fcInit.ini"); if (!dat->laden()) { std::cout << "error: Datei konnte nicht gelesen werden. Das Programm " "wird geschlossen.\n"; dat->release(); file.close(); std::cout.rdbuf(sbuf); exit(1); } const char* wichtig[] = {"SSLPort", "SSLCert", "SSLKey", "SSLPasswort", "Port"}; for (const char* w : wichtig) { if (!dat->wertExistiert(w)) { std::cout << "error: The value '" << w << "' was not specified. The Server can not start.\n"; dat->release(); file.close(); std::cout.rdbuf(sbuf); exit(1); } } mserver = new FactoryCraftServer(dat); std::atexit(exit); signal(SIGTERM, exit); signal(SIGSEGV, exit); signal(SIGILL, exit); signal(SIGABRT, exit); signal(SIGFPE, exit); signal(SIGINT, exit); new Framework::AsynchronCall("Commander", []() { while (mserver) { std::string line; std::getline(std::cin, line); if (Text(line.c_str()) == Text("exit")) { std::cout << "The server will be terminated and the game progress will be saved.\n"; mserver->close(); return; } else if (Game::INSTANCE) { Game::INSTANCE->zChat()->zCommandExecutor()->execute( line.c_str(), 0); } } }); std::cout << "The Server is now running.\n"; mserver->run(); mserver->release(); mserver = 0; if (Game::INSTANCE) { Game::INSTANCE->warteAufThread(100000000); Game::INSTANCE->release(); Game::INSTANCE = 0; } dat->release(); std::cout << "The server was shut down successfully.\n"; file.close(); std::cout.rdbuf(sbuf); Framework::releaseFramework(); return 0; }