int main() { WriteVersion(); #ifdef __FreeBSD__ _malloc_options = "A"; #endif CConfig Config; CNetPoller poller; CDBManager DBManager; CClientManager ClientManager; PlayerHB player_hb; CGuildManager GuildManager; CPrivManager PrivManager; CMoneyLog MoneyLog; ItemAwardManager ItemAwardManager; marriage::CManager MarriageManager; CMonarch Monarch; CBlockCountry BlockCountry; CItemIDRangeManager ItemIDRangeManager; #ifdef __AUCTION__ AuctionManager auctionManager; #endif if (!Start()) return 1; GuildManager.Initialize(); MarriageManager.Initialize(); BlockCountry.Load(); ItemIDRangeManager.Build(); #ifdef __AUCTION__ AuctionManager::instance().Initialize(); #endif sys_log(0, "Metin2DBCacheServer Start\n"); CClientManager::instance().MainLoop(); signal_timer_disable(); DBManager.Quit(); int iCount; while (1) { iCount = 0; iCount += CDBManager::instance().CountReturnQuery(SQL_PLAYER); iCount += CDBManager::instance().CountAsyncQuery(SQL_PLAYER); if (iCount == 0) break; usleep(1000); sys_log(0, "WAITING_QUERY_COUNT %d", iCount); } return 1; }
int start(int argc, char ** argv) { //extern const char * _malloc_options; //_malloc_options = "A"; if (lzo_init() != LZO_E_OK) { sys_err("lzo_init() failed"); return 0; } thecore_init(25, heartbeat); signal_timer_disable(); return 1; }
int main(int argc, char ** argv) { SECTREE_MANAGER sectree_manager; DESC_MANAGER desc_manager; CHARACTER_MANAGER char_manager; quest::CQuestManager quest_manager; // CHARACTER::Intiailize에서 필요함 CArenaManager arena_manager; CPVPManager pvp_manager; LZOManager lzo; if (!start(argc, argv)) return 0; signal_timer_disable(); char buf[256]; char last_cmd[256]; char * p; bool bEnd = false; while (!bEnd && fgets(buf, 256, stdin)) { while ((p = strrchr(buf, '\r'))) *p = '\0'; while ((p = strrchr(buf, '\n'))) *p = '\0'; if (buf[0] == '!') strlcpy(buf, last_cmd, sizeof(buf)); strlcpy(last_cmd, buf, sizeof(last_cmd)); char arg1[64], arg2[64];//, arg3[64], arg4[64]; const char * line = one_argument(buf, arg1, sizeof(arg1)); switch (arg1[0]) { case 'a': { two_arguments(line, arg1, sizeof(arg1), arg2, sizeof(arg2)); if (!*arg1 || !*arg2) { printf("Syntax: a <collision data filename> <map directory>\n"); break; } ConvertAttribute(arg1, arg2); puts("build server_attr done"); } break; case 'c': { one_argument(line, arg1, sizeof(arg1)); if (!*arg1) { printf("Syntax: c <filename>\n"); break; } ConvertAttribute2(arg1); } //ReadColorMapRecursive(line); break; case 'b': { // Buffer overflow test (must use with valgrind or gdb at least) LPCHARACTER ch = CHARACTER_MANAGER::instance().CreateCharacter("test"); // 스택에 할당하면 valgrind가 제대로 오류를 잡지 못함 size_t bufsize = 512 + 1; size_t linesize = 1024 + 1; if (bufsize > 0 && linesize > 0) { char *buf = (char *) malloc(bufsize); char *line = (char *) malloc(linesize); memset(buf, 0, bufsize); memset(line, 0, linesize); for (size_t i = 0; i < bufsize - 1; ++i) { buf[i] = '$'; int linelen = snprintf(line, linesize, "pvp %s", buf); if (linelen < 0 || linelen >= (int) linesize) linelen = linesize - 1; printf("%d %s\n", i, line); interpret_command(ch, line, linelen); } free(buf); free(line); } else { printf("size error!\n"); abort(); } printf("Buffer overflow test finished\n"); } break; case 'q': bEnd = true; break; } } thecore_destroy(); event_destroy(); return 0; }
int start(int argc, char **argv) { std::string st_localeServiceName; bool bVerbose = false; char ch; //_malloc_options = "A"; #if defined(__FreeBSD__) && defined(DEBUG_ALLOC) _malloc_message = WriteMallocMessage; #endif while ((ch = getopt(argc, argv, "npverltI")) != -1) { char* ep = NULL; switch (ch) { case 'I': // IP enhance_strlcpymt(g_szPublicIP, argv[optind], sizeof(g_szPublicIP)); printf("IP %s\n", g_szPublicIP); optind++; optreset = 1; break; case 'p': // port mother_port = strtol(argv[optind], &ep, 10); if (mother_port <= 1024) { usage(); return 0; } printf("port %d\n", mother_port); optind++; optreset = 1; break; case 'l': { long l = strtol(argv[optind], &ep, 10); log_set_level(l); optind++; optreset = 1; } break; // LOCALE_SERVICE case 'n': { if (optind < argc) { st_localeServiceName = argv[optind++]; optreset = 1; } } break; // END_OF_LOCALE_SERVICE case 'v': // verbose bVerbose = true; break; case 'r': g_bNoRegen = true; break; // TRAFFIC_PROFILER case 't': g_bTrafficProfileOn = true; break; // END_OF_TRAFFIC_PROFILER } } // LOCALE_SERVICE config_init(st_localeServiceName); // END_OF_LOCALE_SERVICE #ifdef _WIN32 // In Windows dev mode, "verbose" option is [on] by default. bVerbose = true; #endif if (!bVerbose) freopen("stdout", "a", stdout); bool is_thecore_initialized = thecore_init(25, heartbeat); if (!is_thecore_initialized) { fprintf(stderr, "Could not initialize thecore, check owner of pid, syslog\n"); exit(0); } if (false == CThreeWayWar::instance().LoadSetting("forkedmapindex.txt")) { if (false == g_bAuthServer) { fprintf(stderr, "Could not Load ThreeWayWar Setting file"); exit(0); } } signal_timer_disable(); main_fdw = fdwatch_new(4096); fprintf(stderr, "PUBLIC_IP: %s\n", g_szPublicIP); fprintf(stderr, "INTERNAL_IP: %s\n", g_szInternalIP); if ((tcp_socket = socket_tcp_bind(g_szPublicIP, mother_port)) == INVALID_SOCKET) { perror("socket_tcp_bind: tcp_socket"); return 0; } #ifndef __UDP_BLOCK__ if ((udp_socket = socket_udp_bind(g_szPublicIP, mother_port)) == INVALID_SOCKET) { perror("socket_udp_bind: udp_socket"); return 0; } #endif // if internal ip exists, p2p socket uses internal ip, if not use public ip //if ((p2p_socket = socket_tcp_bind(*g_szInternalIP ? g_szInternalIP : g_szPublicIP, p2p_port)) == INVALID_SOCKET) if ((p2p_socket = socket_tcp_bind(g_szPublicIP, p2p_port)) == INVALID_SOCKET) { perror("socket_tcp_bind: p2p_socket"); return 0; } fdwatch_add_fd(main_fdw, tcp_socket, NULL, FDW_READ, false); #ifndef __UDP_BLOCK__ fdwatch_add_fd(main_fdw, udp_socket, NULL, FDW_READ, false); #endif fdwatch_add_fd(main_fdw, p2p_socket, NULL, FDW_READ, false); db_clientdesc = DESC_MANAGER::instance().CreateConnectionDesc(main_fdw, db_addr, db_port, PHASE_DBCLIENT, true); if (!g_bAuthServer) { db_clientdesc->UpdateChannelStatus(0, true); } if (g_bAuthServer) { if (g_stAuthMasterIP.length() != 0) { fprintf(stderr, "SlaveAuth"); g_pkAuthMasterDesc = DESC_MANAGER::instance().CreateConnectionDesc(main_fdw, g_stAuthMasterIP.c_str(), g_wAuthMasterPort, PHASE_P2P, true); P2P_MANAGER::instance().RegisterConnector(g_pkAuthMasterDesc); g_pkAuthMasterDesc->SetP2P(g_stAuthMasterIP.c_str(), g_wAuthMasterPort, g_bChannel); } else { fprintf(stderr, "MasterAuth %d", LC_GetLocalType()); } } /* game server to teen server */ else { if (teen_addr[0] && teen_port) g_TeenDesc = DESC_MANAGER::instance().CreateConnectionDesc(main_fdw, teen_addr, teen_port, PHASE_TEEN, true); extern unsigned int g_uiSpamBlockDuration; extern unsigned int g_uiSpamBlockScore; extern unsigned int g_uiSpamReloadCycle; sys_log(0, "SPAM_CONFIG: duration %u score %u reload cycle %u\n", g_uiSpamBlockDuration, g_uiSpamBlockScore, g_uiSpamReloadCycle); extern void LoadSpamDB(); LoadSpamDB(); } signal_timer_enable(30); return 1; }
int main(int argc, char **argv) { #ifdef DEBUG_ALLOC DebugAllocator::StaticSetUp(); #endif ilInit(); // DevIL Initialize WriteVersion(); SECTREE_MANAGER sectree_manager; CHARACTER_MANAGER char_manager; ITEM_MANAGER item_manager; CShopManager shop_manager; CMobManager mob_manager; CMotionManager motion_manager; CPartyManager party_manager; CSkillManager skill_manager; CPVPManager pvp_manager; LZOManager lzo_manager; DBManager db_manager; AccountDB account_db; LogManager log_manager; MessengerManager messenger_manager; P2P_MANAGER p2p_manager; CGuildManager guild_manager; CGuildMarkManager mark_manager; CDungeonManager dungeon_manager; CRefineManager refine_manager; CBanwordManager banword_manager; CPrivManager priv_manager; CWarMapManager war_map_manager; building::CManager building_manager; CTargetManager target_manager; marriage::CManager marriage_manager; marriage::WeddingManager wedding_manager; CItemAddonManager item_addon_manager; CArenaManager arena_manager; COXEventManager OXEvent_manager; CMonarch Monarch; CHorseNameManager horsename_manager; DESC_MANAGER desc_manager; TrafficProfiler trafficProfiler; CTableBySkill SkillPowerByLevel; CPolymorphUtils polymorph_utils; CProfiler profiler; CBattleArena ba; SpamManager spam_mgr; CThreeWayWar threeway_war; CDragonLairManager dl_manager; CSpeedServerManager SSManager; DSManager dsManager; #ifdef __AUCTION__ AuctionManager auctionManager; #endif if (!start(argc, argv)) { CleanUpForEarlyExit(); return 0; } quest::CQuestManager quest_manager; if (!quest_manager.Initialize()) { CleanUpForEarlyExit(); return 0; } MessengerManager::instance().Initialize(); CGuildManager::instance().Initialize(); fishing::Initialize(); OXEvent_manager.Initialize(); if (speed_server) CSpeedServerManager::instance().Initialize(); Cube_init(); Blend_Item_init(); ani_init(); PanamaLoad(); if ( g_bTrafficProfileOn ) TrafficProfiler::instance().Initialize( TRAFFIC_PROFILE_FLUSH_CYCLE, "ProfileLog" ); // Client PackageCrypt //TODO : make it config const std::string strPackageCryptInfoDir = "package/"; if( !desc_manager.LoadClientPackageCryptInfo( strPackageCryptInfoDir.c_str() ) ) { sys_err("Failed to Load ClientPackageCryptInfo File(%s)", strPackageCryptInfoDir.c_str()); } #if defined (__FreeBSD__) && defined(__FILEMONITOR__) PFN_FileChangeListener pPackageNotifyFunc = &(DESC_MANAGER::NotifyClientPackageFileChanged); //FileMonitorFreeBSD::Instance().AddWatch( strPackageCryptInfoName, pPackageNotifyFunc ); #endif while (idle()); sys_log(0, "<shutdown> Starting..."); g_bShutdown = true; g_bNoMoreClient = true; if (g_bAuthServer) { int iLimit = DBManager::instance().CountQuery() / 50; int i = 0; do { DWORD dwCount = DBManager::instance().CountQuery(); sys_log(0, "Queries %u", dwCount); if (dwCount == 0) break; usleep(500000); if (++i >= iLimit) if (dwCount == DBManager::instance().CountQuery()) break; } while (1); } sys_log(0, "<shutdown> Destroying CArenaManager..."); arena_manager.Destroy(); sys_log(0, "<shutdown> Destroying COXEventManager..."); OXEvent_manager.Destroy(); sys_log(0, "<shutdown> Disabling signal timer..."); signal_timer_disable(); sys_log(0, "<shutdown> Shutting down CHARACTER_MANAGER..."); char_manager.GracefulShutdown(); sys_log(0, "<shutdown> Shutting down ITEM_MANAGER..."); item_manager.GracefulShutdown(); sys_log(0, "<shutdown> Flushing db_clientdesc..."); db_clientdesc->FlushOutput(); sys_log(0, "<shutdown> Flushing p2p_manager..."); p2p_manager.FlushOutput(); sys_log(0, "<shutdown> Destroying CShopManager..."); shop_manager.Destroy(); sys_log(0, "<shutdown> Destroying CHARACTER_MANAGER..."); char_manager.Destroy(); sys_log(0, "<shutdown> Destroying ITEM_MANAGER..."); item_manager.Destroy(); sys_log(0, "<shutdown> Destroying DESC_MANAGER..."); desc_manager.Destroy(); sys_log(0, "<shutdown> Destroying quest::CQuestManager..."); quest_manager.Destroy(); sys_log(0, "<shutdown> Destroying building::CManager..."); building_manager.Destroy(); sys_log(0, "<shutdown> Flushing TrafficProfiler..."); trafficProfiler.Flush(); destroy(); #ifdef DEBUG_ALLOC DebugAllocator::StaticTearDown(); #endif return 1; }