/*========================================== * map鯖初期化の大元 *------------------------------------------ */ int do_init(int argc,char *argv[]) { srand(gettick()); if(map_config_read((argc<2)? MAP_CONF_NAME:argv[1])) exit(1); battle_config_read((argc>2)? argv[2]:BATTLE_CONF_FILENAME); atcommand_config_read((argc>3)? argv[3]:ATCOMMAND_CONF_FILENAME); script_config_read((argc>4)? argv[4]:SCRIPT_CONF_NAME); msg_config_read((argc>5)? argv[5]:MSG_CONF_NAME); atexit(do_final); id_db = numdb_init(); map_db = strdb_init(16); nick_db = strdb_init(24); charid_db = numdb_init(); grfio_init((argc>6)? argv[6]:GRF_PATH_FILENAME); map_readallmap(); add_timer_func_list(map_clearflooritem_timer,"map_clearflooritem_timer"); do_init_chrif(); do_init_clif(); do_init_itemdb(); do_init_mob(); // npcの初期化時内でmob_spawnして、mob_dbを参照するのでinit_npcより先 do_init_script(); do_init_npc(); do_init_pc(); do_init_storage(); do_init_party(); do_init_guild(); do_init_skill(); do_init_pet(); npc_event_do_oninit(); // npcのOnInitイベント実行 return 0; }
int32 map_config_read(const int8* cfgName) { int8 line[1024], w1[1024], w2[1024]; FILE* fp; fp = fopen(cfgName, "r"); if (fp == nullptr) { ShowError("Map configuration file not found at: %s\n", cfgName); return 1; } while (fgets(line, sizeof(line), fp)) { int8* ptr; if (line[0] == '#') { continue; } if (sscanf(line, "%[^:]: %[^\t\r\n]", w1, w2) < 2) { continue; } //Strip trailing spaces ptr = w2 + strlen(w2); while (--ptr >= w2 && *ptr == ' '); ptr++; *ptr = '\0'; if (strcmpi(w1, "timestamp_format") == 0) { strncpy(timestamp_format, w2, 20); } else if (strcmpi(w1, "stdout_with_ansisequence") == 0) { stdout_with_ansisequence = config_switch(w2); } else if (strcmpi(w1, "console_silent") == 0) { ShowInfo("Console Silent Setting: %d", atoi(w2)); msg_silent = atoi(w2); } else if (strcmpi(w1, "map_port") == 0) { map_config.usMapPort = (atoi(w2)); } else if (strcmp(w1, "buff_maxsize") == 0) { map_config.buffer_size = atoi(w2); } else if (strcmp(w1, "max_time_lastupdate") == 0) { map_config.max_time_lastupdate = atoi(w2); } else if (strcmp(w1, "vanadiel_time_offset") == 0) { map_config.vanadiel_time_offset = atoi(w2); } else if (strcmp(w1, "lightluggage_block") == 0) { map_config.lightluggage_block = atoi(w2); } else if (strcmp(w1, "exp_rate") == 0) { map_config.exp_rate = atof(w2); } else if (strcmp(w1, "exp_loss_rate") == 0) { map_config.exp_loss_rate = atof(w2); } else if (strcmp(w1, "exp_party_gap_penalties") == 0) { map_config.exp_party_gap_penalties = atof(w2); } else if (strcmp(w1, "fov_party_gap_penalties") == 0) { map_config.fov_party_gap_penalties = atof(w2); } else if (strcmp(w1, "fov_allow_alliance") == 0) { map_config.fov_allow_alliance = atof(w2); } else if (strcmp(w1, "mob_tp_multiplier") == 0) { map_config.mob_tp_multiplier = atof(w2); } else if (strcmp(w1, "player_tp_multiplier") == 0) { map_config.player_tp_multiplier = atof(w2); } else if (strcmp(w1, "nm_hp_multiplier") == 0) { map_config.nm_hp_multiplier = atof(w2); } else if (strcmp(w1, "mob_hp_multiplier") == 0) { map_config.mob_hp_multiplier = atof(w2); } else if (strcmp(w1, "player_hp_multiplier") == 0) { map_config.player_hp_multiplier = atof(w2); } else if (strcmp(w1, "nm_mp_multiplier") == 0) { map_config.nm_mp_multiplier = atof(w2); } else if (strcmp(w1, "mob_mp_multiplier") == 0) { map_config.mob_mp_multiplier = atof(w2); } else if (strcmp(w1, "player_mp_multiplier") == 0) { map_config.player_mp_multiplier = atof(w2); } else if (strcmp(w1, "sj_mp_divisor") == 0) { map_config.sj_mp_divisor = atof(w2); } else if (strcmp(w1, "nm_stat_multiplier") == 0) { map_config.nm_stat_multiplier = atof(w2); } else if (strcmp(w1, "mob_stat_multiplier") == 0) { map_config.mob_stat_multiplier = atof(w2); } else if (strcmp(w1, "player_stat_multiplier") == 0) { map_config.player_stat_multiplier = atof(w2); } else if (strcmp(w1, "drop_rate_multiplier") == 0) { map_config.drop_rate_multiplier = atof(w2); } else if (strcmp(w1, "all_mobs_gil_bonus") == 0) { map_config.all_mobs_gil_bonus = atoi(w2); } else if (strcmp(w1, "max_gil_bonus") == 0) { map_config.max_gil_bonus = atoi(w2); } else if (strcmp(w1, "exp_retain") == 0) { map_config.exp_retain = dsp_cap(atof(w2), 0.0f, 1.0f); } else if (strcmp(w1, "exp_loss_level") == 0) { map_config.exp_loss_level = atoi(w2); } else if (strcmp(w1, "level_sync_enable") == 0) { map_config.level_sync_enable = atoi(w2); } else if (strcmp(w1, "all_jobs_widescan") == 0) { map_config.all_jobs_widescan = atoi(w2); } else if (strcmp(w1, "speed_mod") == 0) { map_config.speed_mod = atoi(w2); } else if (strcmp(w1, "mob_speed_mod") == 0) { map_config.mob_speed_mod = atoi(w2); } else if (strcmp(w1, "skillup_chance_multiplier") == 0) { map_config.skillup_chance_multiplier = atof(w2); } else if (strcmp(w1, "craft_chance_multiplier") == 0) { map_config.craft_chance_multiplier = atof(w2); } else if (strcmp(w1, "skillup_amount_multiplier") == 0) { map_config.skillup_amount_multiplier = atof(w2); } else if (strcmp(w1, "craft_amount_multiplier") == 0) { map_config.craft_amount_multiplier = atof(w2); } else if (strcmp(w1, "craft_day_matters") == 0) { map_config.craft_day_matters = atof(w2); } else if (strcmp(w1, "craft_moonphase_matters") == 0) { map_config.craft_moonphase_matters = atof(w2); } else if (strcmp(w1, "craft_direction_matters") == 0) { map_config.craft_direction_matters = atof(w2); } else if (strcmp(w1, "mysql_host") == 0) { map_config.mysql_host = aStrdup(w2); } else if (strcmp(w1, "mysql_login") == 0) { map_config.mysql_login = aStrdup(w2); } else if (strcmp(w1, "mysql_password") == 0) { map_config.mysql_password = aStrdup(w2); } else if (strcmp(w1, "mysql_port") == 0) { map_config.mysql_port = atoi(w2); } else if (strcmp(w1, "mysql_database") == 0) { map_config.mysql_database = aStrdup(w2); } else if (strcmpi(w1, "import") == 0) { map_config_read(w2); } else if (strcmpi(w1, "newstyle_skillups") == 0) { map_config.newstyle_skillups = atoi(w2); } else if (strcmp(w1, "Battle_cap_tweak") == 0) { map_config.Battle_cap_tweak = atoi(w2); } else if (strcmp(w1, "CoP_Battle_cap") == 0) { map_config.CoP_Battle_cap = atoi(w2); } else if (strcmp(w1, "max_merit_points") == 0) { map_config.max_merit_points = atoi(w2); } else if (strcmp(w1, "yell_cooldown") == 0) { map_config.yell_cooldown = atoi(w2); } else if (strcmp(w1, "audit_chat") == 0) { map_config.audit_chat = atoi(w2); } else if (strcmp(w1, "audit_say") == 0) { map_config.audit_say = atoi(w2); } else if (strcmp(w1, "audit_shout") == 0) { map_config.audit_shout = atoi(w2); } else if (strcmp(w1, "audit_tell") == 0) { map_config.audit_tell = atoi(w2); } else if (strcmp(w1, "audit_yell") == 0) { map_config.audit_yell = atoi(w2); } else if (strcmp(w1, "audit_linkshell") == 0) { map_config.audit_linkshell = atoi(w2); } else if (strcmp(w1, "audit_party") == 0) { map_config.audit_party = atoi(w2); } else if (strcmp(w1, "msg_server_port") == 0) { map_config.msg_server_port = atoi(w2); } else if (strcmp(w1, "msg_server_ip") == 0) { map_config.msg_server_ip = aStrdup(w2); } else { ShowWarning(CL_YELLOW"Unknown setting '%s' in file %s\n" CL_RESET, w1, cfgName); } } fclose(fp); // Load the English server message.. fp = fopen("./conf/server_message.conf", "rb"); if (fp == nullptr) { ShowError("Could not read English server message from: ./conf/server_message.conf\n"); return 1; } while (fgets(line, sizeof(line), fp)) { string_t sline(line); map_config.server_message += sline; } fclose(fp); // Load the French server message.. fp = fopen("./conf/server_message_fr.conf", "rb"); if (fp == nullptr) { ShowError("Could not read English server message from: ./conf/server_message_fr.conf\n"); return 1; } while (fgets(line, sizeof(line), fp)) { string_t sline(line); map_config.server_message_fr += sline; } fclose(fp); // Ensure both messages have nullptr terminates.. if (map_config.server_message.at(map_config.server_message.length() - 1) != 0x00) { map_config.server_message += (char)0x00; } if (map_config.server_message_fr.at(map_config.server_message_fr.length() - 1) != 0x00) { map_config.server_message_fr += (char)0x00; } 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; }
int32 do_init(int32 argc, int8** argv) { ShowStatus("do_init: begin server initialization...\n"); MAP_CONF_FILENAME = "./conf/map_darkstar.conf"; srand((uint32)time(NULL)); WELL512::seed((uint32)time(NULL)); 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 ) { exit(EXIT_FAILURE); } Sql_Keepalive(SqlHandle); // отчищаем таблицу сессий при старте сервера (временное решение, т.к. в кластере это не будет работать) Sql_Query(SqlHandle, "TRUNCATE TABLE accounts_sessions"); 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"); 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"); charutils::ResetAllTwoHours(); guildutils::Initialize(); charutils::LoadExpTable(); linkshell::LoadLinkshellList(); traits::LoadTraitsList(); effects::LoadEffectsParameters(); battleutils::LoadSkillTable(); meritNameSpace::LoadMeritsList(); nameSpaceUnlockableWeapons::LoadUnlockableWeaponList(); ability::LoadAbilitiesList(); battleutils::LoadWeaponSkillsList(); battleutils::LoadMobSkillsList(); battleutils::LoadEnmityTable(); battleutils::LoadSkillChainDamageModifiers(); petutils::LoadPetList(); conquest::LoadConquestSystem(); mobutils::LoadCustomMods(); ShowStatus("do_init: loading zones"); zoneutils::LoadZoneList(); ShowMessage("\t\t\t - " CL_GREEN"[OK]" CL_RESET"\n"); luautils::OnServerStart(); fishingutils::LoadFishingMessages(); ShowStatus("do_init: server is binding with port %u",map_config.usMapPort); map_fd = makeBind_udp(map_config.uiMapIp,map_config.usMapPort); ShowMessage("\t - " CL_GREEN"[OK]" CL_RESET"\n"); CVanaTime::getInstance()->setCustomOffset(map_config.vanadiel_time_offset); CTaskMgr::getInstance()->AddTask("time_server", gettick(), NULL, CTaskMgr::TASK_INTERVAL, time_server, 2400); CTaskMgr::getInstance()->AddTask("map_cleanup", gettick(), NULL, CTaskMgr::TASK_INTERVAL, map_cleanup, 5000); CTaskMgr::getInstance()->AddTask("garbage_collect", gettick(), NULL, 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); aFree((void*)map_config.mysql_login); aFree((void*)map_config.mysql_password); ShowStatus("The map-server is " CL_GREEN"ready" CL_RESET" to work...\n"); ShowMessage("=======================================================================\n"); return 0; }
int32 map_config_read(const int8* cfgName) { int8 line[1024], w1[1024], w2[1024]; FILE* fp; fp = fopen(cfgName,"r"); if( fp == NULL ) { ShowError("Map configuration file not found at: %s\n", cfgName); return 1; } while( fgets(line, sizeof(line), fp) ) { int8* ptr; if( line[0] == '#' ) continue; if( sscanf(line, "%[^:]: %[^\t\r\n]", w1, w2) < 2 ) continue; //Strip trailing spaces ptr = w2 + strlen(w2); while (--ptr >= w2 && *ptr == ' '); ptr++; *ptr = '\0'; if(strcmpi(w1,"timestamp_format") == 0) { strncpy(timestamp_format, w2, 20); } else if(strcmpi(w1,"stdout_with_ansisequence") == 0) { stdout_with_ansisequence = config_switch(w2); } else if(strcmpi(w1,"console_silent") == 0) { ShowInfo("Console Silent Setting: %d", atoi(w2)); msg_silent = atoi(w2); } else if (strcmpi(w1,"map_port") == 0) { map_config.usMapPort = (atoi(w2)); } else if (strcmp(w1,"buff_maxsize") == 0) { map_config.buffer_size = atoi(w2); } else if (strcmp(w1,"max_time_lastupdate") == 0) { map_config.max_time_lastupdate = atoi(w2); } else if (strcmp(w1,"vanadiel_time_offset") == 0) { map_config.vanadiel_time_offset = atoi(w2); } else if (strcmp(w1,"lightluggage_block") == 0) { map_config.lightluggage_block = atoi(w2); } else if (strcmp(w1,"mysql_host") == 0) { map_config.mysql_host = aStrdup(w2); } else if (strcmp(w1,"mysql_login") == 0) { map_config.mysql_login = aStrdup(w2); } else if (strcmp(w1,"mysql_password") == 0) { map_config.mysql_password = aStrdup(w2); } else if (strcmp(w1,"mysql_port") == 0) { map_config.mysql_port = atoi(w2); } else if (strcmp(w1,"mysql_database") == 0) { map_config.mysql_database = aStrdup(w2); } else if (strcmpi(w1,"server_message") == 0) { map_config.server_message = aStrdup(w2); uint32 length = (uint32)strlen(map_config.server_message); for(uint32 count = 0; count < length; ++count) { if (RBUFW(map_config.server_message, count) == 0x6E5C) // \n = 0x6E5C in hex { WBUFW(map_config.server_message, count) = 0x0A0D; } } } else if (strcmpi(w1,"import") == 0) { map_config_read(w2); } else { ShowWarning(CL_YELLOW"Unknown setting '%s' in file %s\n"CL_RESET, w1, cfgName); } } fclose(fp); return 0; }
int32 do_init(int32 argc, int8** argv) { ShowStatus("do_init: begin server initialization...\n"); MAP_CONF_FILENAME = "./conf/map_darkstar.conf"; srand((uint32)time(NULL)); 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("conf/commands.conf",luautils::LuaHandle); PacketParderInitialize(); 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 ) { exit(EXIT_FAILURE); } Sql_Keepalive(SqlHandle); 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"); ShowStatus("do_init: loading items"); itemutils::LoadItemList(); ShowMessage("\t\t\t - "CL_GREEN"[OK]"CL_RESET"\n"); // нужно будет написать один метод для инициализации всех данных в battleutils // и один метод для освобождения этих данных ShowStatus("do_init: loading spells"); battleutils::LoadSpellList(); ShowMessage("\t\t\t - "CL_GREEN"[OK]"CL_RESET"\n"); guildutils::Initialize(); charutils::LoadExpTable(); battleutils::LoadSkillTable(); battleutils::LoadAbilitiesList(); battleutils::LoadWeaponSkillsList(); battleutils::LoadTraitsList(); battleutils::LoadMobSkillsList(); battleutils::LoadEnmityTable(); petutils::LoadPetList(); ShowStatus("do_init: loading zones"); zoneutils::LoadZoneList(); ShowMessage("\t\t\t - "CL_GREEN"[OK]"CL_RESET"\n"); luautils::OnServerStart(); ShowStatus("do_init: server is binding with port %u",map_config.usMapPort); map_fd = makeBind_udp(map_config.uiMapIp,map_config.usMapPort); ShowMessage("\t - "CL_GREEN"[OK]"CL_RESET"\n"); CVanaTime::getInstance()->setCustomOffset(map_config.vanadiel_time_offset); CTaskMgr::getInstance()->AddTask("time_server", gettick()+1000, NULL, CTaskMgr::TASK_INTERVAL, time_server, 2400); CTaskMgr::getInstance()->AddTask("map_cleanup", gettick()+5000, NULL, CTaskMgr::TASK_INTERVAL, map_cleanup, map_config.max_time_lastupdate); 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; }