123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- #include <csignal>
- #include <cstdlib>
- #include <Datei.h>
- #include <fstream>
- #include <Globals.h>
- #include <iostream>
- #include <Klient.h>
- #include <sys/resource.h>
- #include <Text.h>
- #include <Zeit.h>
- #include <AsynchronCall.h>
- #include "Server.h"
- FactoryCraftServer* mserver = 0;
- void exit()
- {
- if (mserver)
- {
- std::cout << "The server terminated unexpectedly. Trying to save game progress.\n";
- mserver->close();
- }
- }
- int main()
- {
- initializeBlockTypes();
- initializeItemTypes();
- initializeEntityTypes();
- initializeDimensions();
- initializeMultiblockTypes();
- struct rlimit core_limits;
- core_limits.rlim_cur = core_limits.rlim_max = RLIM_INFINITY;
- setrlimit(RLIMIT_CORE, &core_limits);
- Framework::initFramework();
- 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();
- // std::cout.rdbuf( file.rdbuf() );
- 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;
- }
- }
- });
- 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;
- }
|