/*====================================== * CORE : MAINROUTINE *--------------------------------------*/ int main (int argc, char **argv) { {// initialize program arguments char *p1 = SERVER_NAME = argv[0]; char *p2 = p1; while ((p1 = strchr(p2, '/')) != NULL || (p1 = strchr(p2, '\\')) != NULL) { SERVER_NAME = ++p1; p2 = p1; } arg_c = argc; arg_v = argv; } malloc_init();// needed for Show* in display_title() [FlavioJS] #ifdef MINICORE // minimalist Core display_title(); usercheck(); do_init(argc,argv); do_final(); #else// not MINICORE set_server_type(); display_title(); usercheck(); db_init(); signals_init(); timer_init(); socket_init(); plugins_init(); do_init(argc,argv); plugin_event_trigger(EVENT_ATHENA_INIT); {// Main runtime cycle int next; while (runflag != CORE_ST_STOP) { next = do_timer(gettick_nocache()); do_sockets(next); } } plugin_event_trigger(EVENT_ATHENA_FINAL); do_final(); timer_final(); plugins_final(); socket_final(); db_final(); #endif malloc_final(); return 0; }
/*====================================== * CORE : MAINROUTINE *--------------------------------------*/ int main (int argc, char **argv) { { // Inicializa os argumentos do programa char *p1 = SERVER_NAME = argv[0]; char *p2 = p1; while ( (p1 = strchr (p2, '/')) != NULL || (p1 = strchr (p2, '\\')) != NULL) { SERVER_NAME = ++p1; p2 = p1; } arg_c = argc; arg_v = argv; } malloc_init(); // needed for Show* in display_title() [FlavioJS] #ifndef _WIN32 usercheck(); #endif #ifdef MINICORE // minimalist Core display_title(); do_init (argc, argv); do_final(); #else// not MINICORE set_server_type(); // Define o tipo de servidor (função exclusiva de cada servidor) display_title(); // Mostra o título db_init(); signals_init(); #ifdef _WIN32 cevents_init(); #endif timer_init(); socket_init(); do_init (argc, argv); // Inicializa as funções do servidor { // Ciclo principal do servidor int next; // Enquanto a runflag não for a de Parar, o servidor rodará; do contrário, entrará em processo de finalização while (runflag != CORE_ST_STOP) { next = do_timer (gettick_nocache()); do_sockets (next); } } do_final(); timer_final(); socket_final(); db_final(); #endif malloc_final(); return 0; }
static void sig_proc(int sn) { static int is_called = 0; switch (sn) { case SIGINT: case SIGTERM: if (++is_called > 3) do_final(EXIT_SUCCESS); runflag = 0; break; case SIGSEGV: case SIGFPE: dump_backtrace(); do_abort(); // Pass the signal to the system's default handler compat_signal(sn, SIG_DFL); raise(sn); break; #ifndef _WIN32 case SIGXFSZ: // ignore and allow it to set errno to EFBIG ShowWarning ("Max file size reached!\n"); //run_flag = 0; // should we quit? break; case SIGPIPE: //ShowInfo ("Broken pipe found... closing socket\n"); // set to eof in socket.c break; // does nothing here #endif } }
void md5_final(unsigned char *digest, MD5_CONTEXT *ctx) { if (!ctx->finalized) do_final(ctx); memcpy(digest, ctx->buf, 16); }
int main (int argc, char **argv) { int next; // initialise program arguments { char *p = SERVER_NAME = argv[0]; while ((p = strchr(p, '/')) != NULL) SERVER_NAME = ++p; arg_c = argc; arg_v = argv; } set_server_type(); display_title(); usercheck(); malloc_init(); /* 一番最初に実行する必要がある */ db_init(); signals_init(); timer_init(); socket_init(); plugins_init(); do_init(argc,argv); graph_init(); plugin_event_trigger("Athena_Init"); while (runflag) { next = do_timer(gettick_nocache()); do_sendrecv(next); #ifndef TURBO do_parsepacket(); #endif } plugin_event_trigger("Athena_Final"); graph_final(); do_final(); timer_final(); plugins_final(); socket_final(); db_final(); malloc_final(); return 0; }
void md5_final_text(char *buf, MD5_CONTEXT *ctx) { static const char *chars = "abcdefghijklmnopqrstuvwxyz234567"; int bit; if (!ctx->finalized) do_final(ctx); for (bit = 0; bit < 16*8; bit += 5) { int first_char = bit / 8; int val = ctx->buf[first_char] >> (bit % 8); if (bit + 8 > (first_char + 1) * 8 && first_char < 15) val += ctx->buf[first_char + 1] << (8 - (bit % 8)); *buf++ = chars[val & 0x1F]; } *buf++ = 0; }
int main (int argc, char **argv) { // initialise program arguments { char *p = SERVER_NAME = argv[0]; while ((p = strchr(p, '/')) != NULL) SERVER_NAME = ++p; arg_c = argc; arg_v = argv; } display_title(); usercheck(); do_init(argc,argv); do_final(); return 0; }
int main (int argc, char **argv) { {// initialize program arguments char *p1 = SERVER_NAME = argv[0]; char *p2 = p1; while ((p1 = strchr(p2, '/')) != NULL || (p1 = strchr(p2, '\\')) != NULL) { SERVER_NAME = ++p1; p2 = p1; } arg_c = argc; arg_v = argv; } malloc_init(); set_server_type(); display_title(); usercheck(); signals_init(); timer_init(); socket_init(); do_init(argc,argv); {// Main runtime cycle int next; while (runflag) { next = CTaskMgr::getInstance()->DoTimer(gettick_nocache()); do_sockets(next); } } do_final(); timer_final(); socket_final(); malloc_final(); return 0; }
CInstanceLoader::CInstanceLoader(uint8 instanceid, CZone* PZone, CCharEntity* PRequester) { DSP_DEBUG_BREAK_IF(PZone->GetType() != ZONETYPE_DUNGEON_INSTANCED); requester = PRequester; zone = PZone; CInstance* instance = ((CZoneInstance*)PZone)->CreateInstance(instanceid); SqlInstanceHandle = Sql_Malloc(); if (Sql_Connect(SqlInstanceHandle, map_config.mysql_login, map_config.mysql_password, map_config.mysql_host, map_config.mysql_port, map_config.mysql_database) == SQL_ERROR) { do_final(EXIT_FAILURE); } Sql_Keepalive(SqlInstanceHandle); task = std::async(std::launch::async, &CInstanceLoader::LoadInstance, this, instance); }
int main (int argc, char **argv) { {// initialize program arguments char *p1 = SERVER_NAME = argv[0]; char *p2 = p1; while ((p1 = strchr(p2, '/')) != NULL || (p1 = strchr(p2, '\\')) != NULL) { SERVER_NAME = ++p1; p2 = p1; } arg_c = argc; arg_v = argv; } log_init(argc, argv); malloc_init(); set_server_type(); display_title(); usercheck(); signals_init(); timer_init(); socket_init(); do_init(argc,argv); fd_set rfd; {// Main runtime cycle duration next; while (runflag) { next = CTaskMgr::getInstance()->DoTimer(server_clock::now()); do_sockets(&rfd,next); } } do_final(EXIT_SUCCESS); return 0; }
/*====================================== * CORE : MAINROUTINE *--------------------------------------*/ int main (int argc, char **argv) { {// initialize program arguments char *p1; if((p1 = strrchr(argv[0], '/')) != NULL || (p1 = strrchr(argv[0], '\\')) != NULL ){ char *pwd = NULL; //path working directory int n=0; SERVER_NAME = ++p1; n = p1-argv[0]; //calc dir name len pwd = safestrncpy(malloc(n + 1), argv[0], n); if(chdir(pwd) != 0) ShowError("Couldn't change working directory to %s for %s, runtime will probably fail",pwd,SERVER_NAME); free(pwd); } } malloc_init();// needed for Show* in display_title() [FlavioJS] #ifdef MINICORE // minimalist Core display_title(); usercheck(); do_init(argc,argv); do_final(); #else// not MINICORE set_server_type(); display_title(); usercheck(); Sql_Init(); rathread_init(); mempool_init(); db_init(); signals_init(); #ifdef _WIN32 cevents_init(); #endif timer_init(); socket_init(); do_init(argc,argv); // Main runtime cycle while (runflag != CORE_ST_STOP) { int next = do_timer(gettick_nocache()); do_sockets(next); } do_final(); timer_final(); socket_final(); db_final(); mempool_final(); rathread_final(); ers_final(); #endif malloc_final(); return 0; }
void do_abort(void) { do_final(EXIT_FAILURE); }
/*====================================== * CORE : MAINROUTINE *--------------------------------------*/ int main (int argc, char **argv) { {// Inicializa os argumentos do programa char *p1 = SERVER_NAME = argv[0]; char *p2 = p1; while ((p1 = strchr(p2, '/')) != NULL || (p1 = strchr(p2, '\\')) != NULL) { SERVER_NAME = ++p1; p2 = p1; } arg_c = argc; arg_v = argv; } // Não precisamos chamar o malloc_init se o Memory Manager não está ativo [Keoy] #ifdef USE_MEMMGR malloc_init(); // needed for Show* in display_title() [FlavioJS] #endif #ifdef MINICORE // minimalist Core display_title(); #ifndef _WIN32 usercheck(); #endif do_init(argc,argv); do_final(); #else// not MINICORE set_server_type(); // Define o tipo de servidor (função exclusiva de cada servidor) display_title(); // Mostra o título // Não precisamos verificar se estamos em root se não estamos em um sistema WIN32 [Keoy] #ifndef _WIN32 usercheck(); #endif db_init(); signals_init(); timer_init(); socket_init(); plugins_init(); do_init(argc,argv); // Inicializa as funções do servidor plugin_event_trigger(EVENT_ATHENA_INIT); // Evento inicial dos plugins {// Ciclo principal do servidor int next; // Enquanto a runflag for verdadeira (1) o servidor rodará, do contrário entrará em processo de finalização while (runflag) { next = do_timer(gettick_nocache()); do_sockets(next); } } plugin_event_trigger(EVENT_ATHENA_FINAL); // Evento final dos plugins do_final(); timer_final(); plugins_final(); socket_final(); db_final(); #endif // Não precisamos chamar o malloc_init se o Memory Manager não está ativo [Keoy] #ifdef USE_MEMMGR malloc_final(); #endif return 0; }
int32 do_sockets(fd_set* rfd, int32 next) { struct timeval timeout; int32 ret; memcpy(rfd, &readfds, sizeof(*rfd)); timeout.tv_sec = next / 1000; timeout.tv_usec = next % 1000 * 1000; ret = sSelect(fd_max, rfd, nullptr, nullptr, &timeout); if (ret == SOCKET_ERROR) { if (sErrno != S_EINTR) { ShowFatalError("do_sockets: select() failed, error code %d!\n", sErrno); do_final(EXIT_FAILURE); } return 0; // interrupted by a signal, just loop and try again } last_tick = time(nullptr); if (sFD_ISSET(map_fd, rfd)) { struct sockaddr_in from; socklen_t fromlen = sizeof(from); int32 ret = recvudp(map_fd, g_PBuff, map_config.buffer_size, 0, (struct sockaddr*)&from, &fromlen); if (ret != -1) { // find player char # ifdef WIN32 uint32 ip = ntohl(from.sin_addr.S_un.S_addr); # else uint32 ip = ntohl(from.sin_addr.s_addr); # endif uint64 port = ntohs(from.sin_port); uint64 ipp = ip; ipp |= port << 32; map_session_data_t* map_session_data = mapsession_getbyipp(ipp); if (map_session_data == nullptr) { map_session_data = mapsession_createsession(ip, ntohs(from.sin_port)); if (map_session_data == nullptr) { map_session_list.erase(ipp); return -1; } } map_session_data->last_update = time(nullptr); size_t size = ret; if (recv_parse(g_PBuff, &size, &from, map_session_data) != -1) { // если предыдущий пакет был потерян, то мы не собираем новый, // а отправляем предыдущий пакет повторно if (!parse(g_PBuff, &size, &from, map_session_data)) { send_parse(g_PBuff, &size, &from, map_session_data); } ret = sendudp(map_fd, g_PBuff, size, 0, (const struct sockaddr*)&from, fromlen); int8* data = g_PBuff; g_PBuff = map_session_data->server_packet_data; map_session_data->server_packet_data = data; map_session_data->server_packet_size = size; } if (map_session_data->shuttingDown > 0) { map_close_session(gettick(), map_session_data); } } } return 0; }
int32 do_init(int32 argc, int8** argv) { ShowStatus("do_init: begin server initialization...\n"); map_ip.s_addr = 0; for (int i = 1; i < argc; i++) { if (strcmp(argv[i], "--ip") == 0) map_ip.s_addr = inet_addr(argv[i + 1]); else if (strcmp(argv[i], "--port") == 0) map_port = std::stoi(argv[i + 1]); } MAP_CONF_FILENAME = "./conf/map_darkstar.conf"; srand((uint32)time(nullptr)); dsprand::seed(); map_config_default(); map_config_read(MAP_CONF_FILENAME); ShowMessage("\t\t\t - " CL_GREEN"[OK]" CL_RESET"\n"); ShowStatus("do_init: map_config is reading"); ShowMessage("\t\t - " CL_GREEN"[OK]" CL_RESET"\n"); luautils::init(); CmdHandler.init(luautils::LuaHandle); PacketParserInitialize(); SqlHandle = Sql_Malloc(); ShowStatus("do_init: sqlhandle is allocating"); if (Sql_Connect(SqlHandle, map_config.mysql_login, map_config.mysql_password, map_config.mysql_host, map_config.mysql_port, map_config.mysql_database) == SQL_ERROR) { do_final(EXIT_FAILURE); } Sql_Keepalive(SqlHandle); // отчищаем таблицу сессий при старте сервера (временное решение, т.к. в кластере это не будет работать) Sql_Query(SqlHandle, "DELETE FROM accounts_sessions WHERE IF(%u = 0 AND %u = 0, true, server_addr = %u AND server_port = %u);", map_ip, map_port, map_ip, map_port); ShowMessage("\t\t - " CL_GREEN"[OK]" CL_RESET"\n"); ShowStatus("do_init: zlib is reading"); zlib_init(); ShowMessage("\t\t\t - " CL_GREEN"[OK]" CL_RESET"\n"); messageThread = std::thread(message::init, map_config.msg_server_ip, map_config.msg_server_port); ShowStatus("do_init: loading items"); itemutils::Initialize(); ShowMessage("\t\t\t - " CL_GREEN"[OK]" CL_RESET"\n"); // нужно будет написать один метод для инициализации всех данных в battleutils // и один метод для освобождения этих данных ShowStatus("do_init: loading spells"); spell::LoadSpellList(); mobSpellList::LoadMobSpellList(); ShowMessage("\t\t\t - " CL_GREEN"[OK]" CL_RESET"\n"); guildutils::Initialize(); charutils::LoadExpTable(); linkshell::LoadLinkshellList(); traits::LoadTraitsList(); effects::LoadEffectsParameters(); battleutils::LoadSkillTable(); meritNameSpace::LoadMeritsList(); ability::LoadAbilitiesList(); battleutils::LoadWeaponSkillsList(); battleutils::LoadMobSkillsList(); battleutils::LoadSkillChainDamageModifiers(); petutils::LoadPetList(); mobutils::LoadCustomMods(); ShowStatus("do_init: loading zones\n"); zoneutils::LoadZoneList(); ShowMessage("\t\t\t - " CL_GREEN"[OK]" CL_RESET"\n"); fishingutils::LoadFishingMessages(); ShowStatus("do_init: server is binding with port %u", map_port == 0 ? map_config.usMapPort : map_port); map_fd = makeBind_udp(map_config.uiMapIp, map_port == 0 ? map_config.usMapPort : map_port); ShowMessage("\t - " CL_GREEN"[OK]" CL_RESET"\n"); CVanaTime::getInstance()->setCustomOffset(map_config.vanadiel_time_offset); zoneutils::InitializeWeather(); // Need VanaTime initialized CTransportHandler::getInstance()->InitializeTransport(); CTaskMgr::getInstance()->AddTask("time_server", gettick(), nullptr, CTaskMgr::TASK_INTERVAL, time_server, 2400); CTaskMgr::getInstance()->AddTask("map_cleanup", gettick(), nullptr, CTaskMgr::TASK_INTERVAL, map_cleanup, 5000); CTaskMgr::getInstance()->AddTask("garbage_collect", gettick(), nullptr, CTaskMgr::TASK_INTERVAL, map_garbage_collect, 15 * 60 * 1000); CREATE(g_PBuff, int8, map_config.buffer_size + 20); CREATE(PTempBuff, int8, map_config.buffer_size + 20); ShowStatus("The map-server is " CL_GREEN"ready" CL_RESET" to work...\n"); ShowMessage("=======================================================================\n"); return 0; }
void do_abort(void) { do_final(); }