ConnectionServer::~ConnectionServer(void) { LOG(warning) << "ConnectionServer Shutting down..."; // Update our status for the LoginServer mDatabase->executeProcedureAsync(0, 0, "CALL %s.sp_GalaxyStatusUpdate(%u, %u);",mDatabase->galaxy(), 0, mClusterId); // Status set to offline // We're shuttind down, so update the DB again. _updateDBServerList(0); delete mClientManager; delete mServerManager; delete mMessageRouter; delete mConnectionDispatch; // Destroy our network services. mNetworkManager->DestroyService(mServerService); mNetworkManager->DestroyService(mClientService); // Shutdown our core modules delete mDatabaseManager; delete mNetworkManager; MessageFactory::getSingleton()->destroySingleton(); // Delete message factory and call shutdown(); LOG(warning) << "ConnectionServer Shutdown Complete"; }
void ZoneServer::handleWMReady() { _updateDBServerList(2); gLogger->logMsg("ZoneServer::Startup Complete"); //gLogger->printLogo(); // std::string BuildString(GetBuildString()); gLogger->logMsgF("ZoneServer:%s %s",MSG_NORMAL,getZoneName().getAnsi(),ConfigManager::getBuildString().c_str()); gLogger->logMsg("Welcome to your SWGANH Experience!"); // Connect to the ConnectionServer; _connectToConnectionServer(); }
ZoneServer::~ZoneServer(void) { gLogger->logMsg("ZoneServer shutting down..."); // We're shutting down, so update the DB again. _updateDBServerList(0); // Shutdown and delete the game modules. delete mCharacterLoginHandler; gTravelMapHandler->Shutdown(); gTradeManager->Shutdown(); delete mObjectControllerDispatch; AdminManager::deleteManager(); gWorldManager->Shutdown(); // Should be closed before script engine and script support, due to halting of scripts. gScriptEngine->shutdown(); ScriptSupport::Instance()->destroyInstance(); delete mMessageDispatch; // gMessageFactory->Shutdown(); // Nothing to do there yet, since deleting of the heap is done in the destructor. // Delete the non persistent factories, that are possible to delete. // NonPersistentContainerFactory::getSingletonPtr()->destroySingleton(); NonPersistentItemFactory::deleteFactory(); NonPersistentNpcFactory::deleteFactory(); ScoutManager::deleteManager(); WorldConfig::deleteManager(); NonPersistantObjectFactory::deleteFactory(); // Shutdown and delete our core services. mNetworkManager->DestroyService(mRouterService); delete mNetworkManager; delete mDatabaseManager; delete gSkillManager->getSingletonPtr(); delete gMedicManager->getSingletonPtr(); delete gBuffManager->getSingletonPtr(); // NOW, I can feel that it should be safe to delete the data holding messages. gMessageFactory->destroySingleton(); gLogger->logMsg("ZoneServer::Shutdown Complete\n"); }
ConnectionServer::ConnectionServer(int argc, char* argv[]) : BaseServer(), mDatabaseManager(0), mDatabase(0), mNetworkManager(0), mMessageRouter(0), mClientManager(0), mServerManager(0), mConnectionDispatch(0), mClusterId(0), mClientService(0), mServerService(0), mLocked(false), mLastHeartbeat(0) { Anh_Utils::Clock::Init(); LOG(warning) << "ConnectionServer Startup"; configuration_options_description_.add_options() ("ClientServiceMessageHeap", boost::program_options::value<uint32_t>()->default_value(50000), "") ("ServerServiceMessageHeap", boost::program_options::value<uint32_t>()->default_value(50000), "") ("ClusterBindAddress", boost::program_options::value<std::string>()->default_value("127.0.0.1"), "") ("ClusterBindPort", boost::program_options::value<uint16_t>()->default_value(5000)) ("ClusterId", boost::program_options::value<uint32_t>()->default_value(2)) ; // Load Configuration Options std::list<std::string> config_files; config_files.push_back("config/general.cfg"); config_files.push_back("config/connectionserver.cfg"); LoadOptions_(argc, argv, config_files); // Startup our core modules MessageFactory::getSingleton(configuration_variables_map_["GlobalMessageHeap"].as<uint32_t>()); mNetworkManager = new NetworkManager( NetworkConfig(configuration_variables_map_["ReliablePacketSizeServerToServer"].as<uint16_t>(), configuration_variables_map_["UnreliablePacketSizeServerToServer"].as<uint16_t>(), configuration_variables_map_["ReliablePacketSizeServerToClient"].as<uint16_t>(), configuration_variables_map_["UnreliablePacketSizeServerToClient"].as<uint16_t>(), configuration_variables_map_["ServerPacketWindowSize"].as<uint32_t>(), configuration_variables_map_["ClientPacketWindowSize"].as<uint32_t>(), configuration_variables_map_["UdpBufferSize"].as<uint32_t>())); // Create our status service //clientservice mClientService = mNetworkManager->GenerateService((char*)configuration_variables_map_["BindAddress"].as<std::string>().c_str(), configuration_variables_map_["BindPort"].as<uint16_t>(),configuration_variables_map_["ClientServiceMessageHeap"].as<uint32_t>()*1024, false);//,5); //serverservice mServerService = mNetworkManager->GenerateService((char*)configuration_variables_map_["ClusterBindAddress"].as<std::string>().c_str(), configuration_variables_map_["ClusterBindPort"].as<uint16_t>(),configuration_variables_map_["ServerServiceMessageHeap"].as<uint32_t>()*1024, true);//,15); mDatabaseManager = new DatabaseManager(DatabaseConfig(configuration_variables_map_["DBMinThreads"].as<uint32_t>(), configuration_variables_map_["DBMaxThreads"].as<uint32_t>(), configuration_variables_map_["DBGlobalSchema"].as<std::string>(), configuration_variables_map_["DBGalaxySchema"].as<std::string>(), configuration_variables_map_["DBConfigSchema"].as<std::string>())); mDatabase = mDatabaseManager->connect(DBTYPE_MYSQL, (char*)(configuration_variables_map_["DBServer"].as<std::string>()).c_str(), configuration_variables_map_["DBPort"].as<uint16_t>(), (char*)(configuration_variables_map_["DBUser"].as<std::string>()).c_str(), (char*)(configuration_variables_map_["DBPass"].as<std::string>()).c_str(), (char*)(configuration_variables_map_["DBName"].as<std::string>()).c_str()); mClusterId = configuration_variables_map_["ClusterId"].as<uint32_t>(); mDatabase->executeProcedureAsync(0, 0, "CALL %s.sp_GalaxyStatusUpdate(%u, %u);",mDatabase->galaxy(), 1, mClusterId); // Set status to online mDatabase->executeProcedureAsync(0, 0, "CALL %s.sp_ServerStatusUpdate('connection', NULL, NULL, NULL);",mDatabase->galaxy()); // In case of a crash, we need to cleanup the DB a little. mDatabase->executeSynchSql("UPDATE %s.account SET account_loggedin=0 WHERE account_loggedin=%u;",mDatabase->galaxy(), mClusterId); // Status: 0=offline, 1=loading, 2=online _updateDBServerList(1); // Startup our router modules. mConnectionDispatch = new ConnectionDispatch(); mMessageRouter = new MessageRouter(mDatabase, mConnectionDispatch); mClientManager = new ClientManager(mClientService, mDatabase, mMessageRouter, mConnectionDispatch, mClusterId); mServerManager = new ServerManager(mServerService, mDatabase, mMessageRouter, mConnectionDispatch,mClientManager, mClusterId); // We're done initiailizing. _updateDBServerList(2); LOG(warning) << "Connection server startup complete"; #ifdef _WIN32 //I cannot speak for *nix but under windows the main thread pauses for times, leaving the services workthreads unemployed //SetPriorityClass(GetCurrentThread(),REALTIME_PRIORITY_CLASS); #endif }
ZoneServer::ZoneServer(int8* zoneName) : mZoneName(zoneName), mNetworkManager(0), mDatabaseManager(0), mRouterService(0), mDatabase(0) { Anh_Utils::Clock::Init(); // gLogger->logMsgF("ZoneServer - %s Startup %s",MSG_NORMAL,zoneName,GetBuildString()); gLogger->logMsg("ZoneServer Startup", FOREGROUND_GREEN | FOREGROUND_RED); // Create and startup our core services. mDatabaseManager = new DatabaseManager(); mNetworkManager = new NetworkManager(); // Connect to the DB and start listening for the RouterServer. mDatabase = mDatabaseManager->Connect(DBTYPE_MYSQL, (int8*)(gConfig->read<std::string>("DBServer")).c_str(), gConfig->read<int>("DBPort"), (int8*)(gConfig->read<std::string>("DBUser")).c_str(), (int8*)(gConfig->read<std::string>("DBPass")).c_str(), (int8*)(gConfig->read<std::string>("DBName")).c_str()); //make sure our logger has db access gLogger->connecttoDB(mDatabaseManager); //create an error log int8 log[128]; sprintf(log,"%s.log",zoneName); gLogger->createErrorLog(log,(LogLevel)(gConfig->read<int>("LogLevel",2)), (bool)(gConfig->read<bool>("LogToFile", true)), (bool)(gConfig->read<bool>("ConsoleOut",true)), (bool)(gConfig->read<bool>("LogAppend",true))); //increase the server start that will help us to organize our logs to the corresponding serverstarts (mostly for errors) mDatabase->ExecuteSqlAsync(0,0,"UPDATE config_process_list SET serverstartID = serverstartID+1 WHERE name like \'%s\'",zoneName); mRouterService = mNetworkManager->GenerateService((char*)gConfig->read<std::string>("BindAddress").c_str(), gConfig->read<uint16>("BindPort"),gConfig->read<uint32>("ServiceMessageHeap")*1024,true); // Grab our zoneId out of the DB for this zonename. uint32 zoneId = 0; DatabaseResult* result = mDatabase->ExecuteSynchSql("SELECT planet_id FROM planet WHERE name=\'%s\';", zoneName); if (!result->getRowCount()) { gLogger->logMsgF("FATAL: Map \'%s\' not found. Aborting startup.", MSG_HIGH, zoneName); abort(); } // Yea, I'm getting annoyed with the DataBinding for such simple tasks. Will implement a simple interface soon. gLogger->logMsgF("ZoneServer initializing for zone %s", MSG_NORMAL, zoneName); DataBinding* binding = mDatabase->CreateDataBinding(1); binding->addField(DFT_uint32, 0, 4); result->GetNextRow(binding, &zoneId); mDatabase->DestroyDataBinding(binding); mDatabase->DestroyResult(result); // We need to register our IP and port in the DB so the connection server can connect to us. // Status: 0=offline, 1=loading, 2=online _updateDBServerList(1); // Place all startup code here. mMessageDispatch = new MessageDispatch(mRouterService); WorldConfig::Init(zoneId,mDatabase,zoneName); ObjectControllerCommandMap::Init(mDatabase); MessageLib::Init(); ObjectFactory::Init(mDatabase); //attribute commands for foodbuffs FoodCommandMapClass::Init(); //structuremanager callback functions StructureManagerCommandMapClass::Init(); WorldManager::Init(zoneId,this,mDatabase); // Init the non persistent factories. For now we take them one-by-one here, until we have a collection of them. // We can NOT create these factories among the already existing ones, if we want to have any kind of "ownership structure", // since the existing factories are impossible to delete without crashing the server. // NonPersistentContainerFactory::Init(mDatabase); (void)NonPersistentItemFactory::Instance(); // This call is just for clarity, when matching the deletion of classes. // The object will create itself upon first usage, (void)NonPersistentNpcFactory::Instance(); (void)ForageManager::Instance(); (void)ScoutManager::Instance(); (void)NonPersistantObjectFactory::Instance(); UIManager::Init(mDatabase,mMessageDispatch); CombatManager::Init(mDatabase); TravelMapHandler::Init(mDatabase,mMessageDispatch,zoneId); CharSheetManager::Init(mDatabase,mMessageDispatch); TradeManager::Init(mDatabase,mMessageDispatch); BuffManager::Init(mDatabase); MedicManager::Init(mMessageDispatch); AdminManager::Init(mMessageDispatch); EntertainerManager::Init(mDatabase,mMessageDispatch); GroupManager::Init(mDatabase,mMessageDispatch); StructureManager::Init(mDatabase,mMessageDispatch); // Invoked when all creature regions for spawning of lairs are loaded // (void)NpcManager::Instance(); ScriptEngine::Init(); mCharacterLoginHandler = new CharacterLoginHandler(mDatabase,mMessageDispatch); mObjectControllerDispatch = new ObjectControllerDispatch(mDatabase,mMessageDispatch); }