2020-08-18 20:42:30 +00:00
|
|
|
#include "CNLoginServer.hpp"
|
|
|
|
#include "CNShardServer.hpp"
|
|
|
|
#include "PlayerManager.hpp"
|
|
|
|
#include "ChatManager.hpp"
|
2020-08-21 02:10:14 +00:00
|
|
|
#include "ItemManager.hpp"
|
2020-08-24 21:04:56 +00:00
|
|
|
#include "MissionManager.hpp"
|
2020-08-20 15:43:37 +00:00
|
|
|
#include "NanoManager.hpp"
|
2020-08-20 21:43:48 +00:00
|
|
|
#include "NPCManager.hpp"
|
2020-08-28 18:02:03 +00:00
|
|
|
#include "Database.hpp"
|
2020-08-18 20:42:30 +00:00
|
|
|
|
|
|
|
#include "settings.hpp"
|
|
|
|
|
2020-08-19 20:42:44 +00:00
|
|
|
#if defined(__MINGW32__) && !defined(_GLIBCXX_HAS_GTHREADS)
|
2020-08-18 20:42:30 +00:00
|
|
|
#include "mingw/mingw.thread.h"
|
|
|
|
#else
|
2020-08-24 21:04:56 +00:00
|
|
|
#include <thread>
|
2020-08-18 20:42:30 +00:00
|
|
|
#endif
|
|
|
|
#include <string>
|
|
|
|
|
2020-08-27 19:42:04 +00:00
|
|
|
CNShardServer *shardServer;
|
|
|
|
std::thread *shardThread;
|
|
|
|
|
2020-08-19 00:52:02 +00:00
|
|
|
void startShard(CNShardServer* server) {
|
|
|
|
server->start();
|
2020-08-18 20:42:30 +00:00
|
|
|
}
|
|
|
|
|
2020-08-27 19:42:04 +00:00
|
|
|
// terminate gracefully on SIGINT (for gprof)
|
|
|
|
void terminate(int arg) {
|
|
|
|
std::cout << "OpenFusion: terminating" << std::endl;
|
|
|
|
shardServer->kill();
|
|
|
|
shardThread->join();
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2020-08-18 20:42:30 +00:00
|
|
|
int main() {
|
|
|
|
#ifdef _WIN32
|
|
|
|
WSADATA wsaData;
|
2020-08-24 21:04:56 +00:00
|
|
|
if (WSAStartup(MAKEWORD(1, 1), &wsaData) != 0) {
|
|
|
|
std::cerr << "OpenFusion: WSAStartup failed" << std::endl;
|
|
|
|
exit(EXIT_FAILURE);
|
2020-08-18 20:42:30 +00:00
|
|
|
}
|
2020-08-26 19:38:09 +00:00
|
|
|
#else
|
|
|
|
// tell the OS to not kill us if you use a broken pipe, just let us know thru recv() or send()
|
|
|
|
signal(SIGPIPE, SIG_IGN);
|
2020-08-27 19:42:04 +00:00
|
|
|
signal(SIGINT, terminate); // TODO: use sigaction() instead
|
2020-08-18 20:42:30 +00:00
|
|
|
#endif
|
|
|
|
settings::init();
|
2020-08-21 17:38:45 +00:00
|
|
|
std::cout << "[INFO] Protocol version: " << PROTOCOL_VERSION << std::endl;
|
2020-08-18 20:42:30 +00:00
|
|
|
std::cout << "[INFO] Intializing Packet Managers..." << std::endl;
|
|
|
|
PlayerManager::init();
|
|
|
|
ChatManager::init();
|
2020-08-21 02:10:14 +00:00
|
|
|
ItemManager::init();
|
2020-08-24 21:04:56 +00:00
|
|
|
MissionManager::init();
|
2020-08-20 15:43:37 +00:00
|
|
|
NanoManager::init();
|
2020-08-20 21:43:48 +00:00
|
|
|
NPCManager::init();
|
2020-08-18 20:42:30 +00:00
|
|
|
|
2020-08-28 18:02:03 +00:00
|
|
|
Database::open();
|
|
|
|
|
2020-08-18 20:42:30 +00:00
|
|
|
std::cout << "[INFO] Starting Server Threads..." << std::endl;
|
2020-08-19 01:34:39 +00:00
|
|
|
CNLoginServer loginServer(settings::LOGINPORT);
|
2020-08-27 19:42:04 +00:00
|
|
|
shardServer = new CNShardServer(settings::SHARDPORT);
|
2020-08-19 00:52:02 +00:00
|
|
|
|
2020-08-27 19:42:04 +00:00
|
|
|
shardThread = new std::thread(startShard, (CNShardServer*)shardServer);
|
2020-08-24 21:04:56 +00:00
|
|
|
|
2020-08-19 00:52:02 +00:00
|
|
|
loginServer.start();
|
|
|
|
|
2020-08-27 19:42:04 +00:00
|
|
|
shardServer->kill();
|
|
|
|
shardThread->join();
|
2020-08-24 21:04:56 +00:00
|
|
|
|
2020-08-18 20:42:30 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
WSACleanup();
|
|
|
|
#endif
|
|
|
|
return 0;
|
2020-08-21 17:38:45 +00:00
|
|
|
}
|