From 34f0540da418b01dd4d49f6ecf72569d3cfecfdf Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Sat, 25 Jan 2014 09:43:09 -0800 Subject: Implement unified config parsing (mostly) --- src/map/atcommand.cpp | 91 ++++----------------- src/map/atcommand.hpp | 2 +- src/map/battle.cpp | 46 +++++++---- src/map/battle.hpp | 3 +- src/map/chrif.cpp | 4 +- src/map/chrif.hpp | 2 +- src/map/clif.cpp | 8 +- src/map/clif.hpp | 2 +- src/map/itemdb.cpp | 74 +++--------------- src/map/itemdb.hpp | 2 +- src/map/magic-interpreter-parser.ypp | 19 +++-- src/map/magic-interpreter.hpp | 3 +- src/map/magic.cpp | 5 -- src/map/magic.hpp | 5 -- src/map/map.cpp | 148 ++++++++++++++++++++++------------- src/map/map.hpp | 1 - src/map/mob.cpp | 69 +++++----------- src/map/mob.hpp | 5 +- src/map/npc.cpp | 19 +++-- src/map/npc.hpp | 2 +- src/map/pc.cpp | 8 +- src/map/pc.hpp | 2 +- src/map/script.cpp | 32 ++++---- src/map/script.hpp | 1 - src/map/skill.cpp | 61 +++++---------- src/map/skill.hpp | 2 +- src/map/storage.cpp | 4 - src/map/storage.hpp | 1 - 28 files changed, 248 insertions(+), 373 deletions(-) (limited to 'src/map') diff --git a/src/map/atcommand.cpp b/src/map/atcommand.cpp index 5256121..9687968 100644 --- a/src/map/atcommand.cpp +++ b/src/map/atcommand.cpp @@ -14,6 +14,7 @@ #include "../io/read.hpp" #include "../io/write.hpp" +#include "../common/config_parse.hpp" #include "../common/core.hpp" #include "../common/extract.hpp" #include "../common/human_time_diff.hpp" @@ -317,22 +318,29 @@ AtCommandInfo *get_atcommandinfo_byname(XString name) return atcommand_info.search(name); } -int atcommand_config_read(ZString cfgName) +bool atcommand_config_read(ZString cfgName) { io::ReadFile in(cfgName); if (!in.is_open()) { PRINTF("At commands configuration file not found: %s\n", cfgName); - return 1; + return false; } + bool rv = true; FString line; while (in.getline(line)) { + if (is_comment(line)) + continue; XString w1; ZString w2; - if (!split_key_value(line, &w1, &w2)) + if (!config_split(line, &w1, &w2)) + { + PRINTF("Bad config line: %s\n", line); + rv = false; continue; + } AtCommandInfo *p = get_atcommandinfo_byname(w1); if (p != NULL) { @@ -343,12 +351,15 @@ int atcommand_config_read(ZString cfgName) p->level = 0; } else if (w1 == "import") - atcommand_config_read(w2); + rv &= atcommand_config_read(w2); else + { PRINTF("%s: bad line: %s\n", cfgName, line); + rv = false; + } } - return 0; + return rv; } /// @ command processing functions @@ -3383,61 +3394,6 @@ ATCE atcommand_partyrecall(const int fd, dumb_ptr sd, return ATCE::OKAY; } -static -ATCE atcommand_reloaditemdb(const int fd, dumb_ptr, - ZString) -{ - itemdb_reload(); - clif_displaymessage(fd, "Item database reloaded."); - - return ATCE::OKAY; -} - -static -ATCE atcommand_reloadmobdb(const int fd, dumb_ptr, - ZString) -{ - mob_reload(); - clif_displaymessage(fd, "Monster database reloaded."); - - return ATCE::OKAY; -} - -static -ATCE atcommand_reloadskilldb(const int fd, dumb_ptr, - ZString) -{ - skill_reload(); - clif_displaymessage(fd, "Skill database reloaded."); - - return ATCE::OKAY; -} - -static -ATCE atcommand_reloadscript(const int fd, dumb_ptr, - ZString) -{ - do_init_npc(); - do_init_script(); - - npc_event_do_oninit(); - - clif_displaymessage(fd, "Scripts reloaded."); - - return ATCE::OKAY; -} - -static -ATCE atcommand_reloadgmdb(const int fd, dumb_ptr, - ZString) -{ - chrif_reloadGMdb(); - - clif_displaymessage(fd, "Login-server asked to reload GM accounts and their level."); - - return ATCE::OKAY; -} - static ATCE atcommand_mapinfo(const int fd, dumb_ptr sd, ZString message) @@ -5331,21 +5287,6 @@ Map atcommand_info = {"charstreset", {"", 60, atcommand_charstreset, "Reset a player's stat points"}}, - {"reloaditemdb", {"", - 99, atcommand_reloaditemdb, - "Allegedly to reload the item database"}}, - {"reloadmobdb", {"", - 99, atcommand_reloadmobdb, - "Allegedly to reload the mob database"}}, - {"reloadskilldb", {"", - 99, atcommand_reloadskilldb, - "Allegedly to reload the skill database"}}, - {"reloadscript", {"", - 99, atcommand_reloadscript, - "Allegedly to reload the script database"}}, - {"reloadgmdb", {"", - 99, atcommand_reloadgmdb, - "Unnecessarily reload the GM database"}}, {"charreset", {"", 60, atcommand_charreset, "Reset a player's skills, stats, and magic"}}, diff --git a/src/map/atcommand.hpp b/src/map/atcommand.hpp index 31f1432..b494a25 100644 --- a/src/map/atcommand.hpp +++ b/src/map/atcommand.hpp @@ -10,7 +10,7 @@ bool is_atcommand(const int fd, dumb_ptr sd, ZString message, int gmlvl); -int atcommand_config_read(ZString cfgName); +bool atcommand_config_read(ZString cfgName); void log_atcommand(dumb_ptr sd, ZString cmd); diff --git a/src/map/battle.cpp b/src/map/battle.cpp index 05bacd4..35cef79 100644 --- a/src/map/battle.cpp +++ b/src/map/battle.cpp @@ -8,6 +8,7 @@ #include "../io/cxxstdio.hpp" #include "../io/read.hpp" +#include "../common/config_parse.hpp" #include "../common/nullpo.hpp" #include "../common/random.hpp" @@ -21,7 +22,13 @@ #include "../poison.hpp" -struct Battle_Config battle_config; + +static Battle_Config init_battle_config(); + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wshadow" +struct Battle_Config battle_config = init_battle_config(); +#pragma GCC diagnostic pop /*========================================== * 自分をロックしている対象の数を返す(汎用) @@ -2289,15 +2296,12 @@ int battle_check_range(dumb_ptr src, dumb_ptr bl, bl->bl_x - dx, bl->bl_y - dy, 0x10001) != -1) ? 1 : 0; } -/*========================================== - * 設定ファイルを読み込む - *------------------------------------------ - */ -int battle_config_read(ZString cfgName) +Battle_Config init_battle_config() { - static int count = 0; - - if ((count++) == 0) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wshadow" + Battle_Config battle_config; +#pragma GCC diagnostic pop { battle_config.warp_point_debug = 0; battle_config.enemy_critical = 0; @@ -2403,12 +2407,17 @@ int battle_config_read(ZString cfgName) battle_config.mob_splash_radius = -1; } + return battle_config; +} +bool battle_config_read(ZString cfgName) +{ + bool rv = true; io::ReadFile in(cfgName); if (!in.is_open()) { PRINTF("file not found: %s\n", cfgName); - return 1; + return false; } FString line; @@ -2522,10 +2531,16 @@ int battle_config_read(ZString cfgName) BATTLE_CONFIG_VAR(mob_splash_radius), }; + if (is_comment(line)) + continue; XString w1; ZString w2; - if (!split_key_value(line, &w1, &w2)) + if (!config_split(line, &w1, &w2)) + { + PRINTF("Bad config line: %s\n", line); + rv = false; continue; + } if (w1 == "import") { @@ -2541,12 +2556,17 @@ int battle_config_read(ZString cfgName) } PRINTF("WARNING: unknown battle conf key: %s\n", FString(w1)); + rv = false; continue_outer: ; } - if (--count == 0) + return rv; +} + +void battle_config_check() +{ { if (static_cast(battle_config.flooritem_lifetime) < std::chrono::seconds(1)) battle_config.flooritem_lifetime = std::chrono::duration_cast(LIFETIME_FLOORITEM).count(); @@ -2657,6 +2677,4 @@ int battle_config_read(ZString cfgName) else if (battle_config.mask_ip_gms > 1) battle_config.mask_ip_gms = 1; } - - return 0; } diff --git a/src/map/battle.hpp b/src/map/battle.hpp index 02a32ad..32c479e 100644 --- a/src/map/battle.hpp +++ b/src/map/battle.hpp @@ -202,6 +202,7 @@ extern struct Battle_Config int mob_splash_radius; } battle_config; -int battle_config_read(ZString cfgName); +bool battle_config_read(ZString cfgName); +void battle_config_check(); #endif // BATTLE_HPP diff --git a/src/map/chrif.cpp b/src/map/chrif.cpp index 4afccb7..5b9f96f 100644 --- a/src/map/chrif.cpp +++ b/src/map/chrif.cpp @@ -1187,7 +1187,7 @@ void check_connect_char_server(TimerData *, tick_t) * *------------------------------------------ */ -int do_init_chrif (void) +void do_init_chrif(void) { Timer(gettick() + std::chrono::seconds(1), check_connect_char_server, @@ -1197,6 +1197,4 @@ int do_init_chrif (void) send_users_tochar, std::chrono::seconds(5) ).detach(); - - return 0; } diff --git a/src/map/chrif.hpp b/src/map/chrif.hpp index 51c6d20..dfa2d35 100644 --- a/src/map/chrif.hpp +++ b/src/map/chrif.hpp @@ -34,7 +34,7 @@ int chrif_saveaccountreg2(dumb_ptr sd); int chrif_reloadGMdb(void); int chrif_send_divorce(int char_id); -int do_init_chrif (void); +void do_init_chrif(void); // only used by intif.cpp extern int char_fd; diff --git a/src/map/clif.cpp b/src/map/clif.cpp index 5b7c21d..b4ac24a 100644 --- a/src/map/clif.cpp +++ b/src/map/clif.cpp @@ -5597,14 +5597,8 @@ void clif_parse(int fd) RFIFOSKIP(fd, packet_len); } -/*========================================== - * - *------------------------------------------ - */ -int do_init_clif (void) +void do_init_clif(void) { set_defaultparse(clif_parse); make_listen_port(map_port); - - return 0; } diff --git a/src/map/clif.hpp b/src/map/clif.hpp index bf7393c..ad51fc8 100644 --- a/src/map/clif.hpp +++ b/src/map/clif.hpp @@ -161,6 +161,6 @@ int clif_GM_kick(dumb_ptr sd, dumb_ptr tsd, int clif_foreachclient(std::function)>); -int do_init_clif (void); +void do_init_clif(void); #endif // CLIF_HPP diff --git a/src/map/itemdb.cpp b/src/map/itemdb.cpp index 313ff23..bcef583 100644 --- a/src/map/itemdb.cpp +++ b/src/map/itemdb.cpp @@ -10,6 +10,7 @@ #include "../io/cxxstdio.hpp" #include "../io/read.hpp" +#include "../common/config_parse.hpp" #include "../common/db.hpp" #include "../common/extract.hpp" #include "../common/nullpo.hpp" @@ -29,11 +30,6 @@ Map item_db; // Function declarations -static -void itemdb_read(void); -static -int itemdb_readdb(void); - /*========================================== * 名前で検索用 *------------------------------------------ @@ -148,15 +144,11 @@ int itemdb_isequip3(int nameid) || type == ItemType::_8); } -/*========================================== - * アイテムデータベースの読み込み - *------------------------------------------ - */ -static -int itemdb_readdb(void) +bool itemdb_readdb(ZString filename) { + bool rv = true; + int ln = 0, lines = 0; - ZString filename = "db/item_db.txt"; { io::ReadFile in(filename); @@ -164,7 +156,7 @@ int itemdb_readdb(void) if (!in.is_open()) { PRINTF("can't read %s\n", filename); - exit(1); + return false; } lines = 0; @@ -173,9 +165,7 @@ int itemdb_readdb(void) while (in.getline(line)) { lines++; - if (!line) - continue; - if (line.startswith("//")) + if (is_comment(line)) continue; // a line is 17 normal fields followed by 2 {} fields // the fields are separated by ", *", but there may be , @@ -212,6 +202,7 @@ int itemdb_readdb(void) { PRINTF("%s:%d: error: bad item line: %s\n", filename, lines, line); + rv = false; continue; } @@ -245,7 +236,8 @@ int itemdb_readdb(void) } PRINTF("read %s done (count=%d)\n", filename, ln); } - return 0; + + return rv; } /*========================================== @@ -259,18 +251,6 @@ void itemdb_final(struct item_data *id) id->equip_script.reset(); } -void itemdb_reload(void) -{ - /* - * - * - * itemdb_read(); - * - */ - - do_init_itemdb(); -} - /*========================================== * *------------------------------------------ @@ -281,39 +261,3 @@ void do_final_itemdb(void) itemdb_final(&pair.second); item_db.clear(); } - -/* -static -FILE *dfp; -static -int itemdebug(void *key,void *data,_va_list ap){ -// struct item_data *id=(struct item_data *)data; - FPRINTF(dfp,"%6d", (int)key); - return 0; -} -void itemdebugtxt() -{ - dfp=fopen_("itemdebug.txt","wt"); - numdb_foreach(item_db,itemdebug); - fclose_(dfp); -} -*/ - -/*==================================== - * Removed item_value_db, don't re-add - *------------------------------------ - */ -static -void itemdb_read(void) -{ - itemdb_readdb(); -} - -/*========================================== - * - *------------------------------------------ - */ -void do_init_itemdb(void) -{ - itemdb_read(); -} diff --git a/src/map/itemdb.hpp b/src/map/itemdb.hpp index e41be41..2ec8f1c 100644 --- a/src/map/itemdb.hpp +++ b/src/map/itemdb.hpp @@ -77,6 +77,6 @@ int itemdb_isequip3(int); void itemdb_reload(void); void do_final_itemdb(void); -void do_init_itemdb(void); +bool itemdb_readdb(ZString filename); #endif // ITEMDB_HPP diff --git a/src/map/magic-interpreter-parser.ypp b/src/map/magic-interpreter-parser.ypp index d59519a..0e03afb 100644 --- a/src/map/magic-interpreter-parser.ypp +++ b/src/map/magic-interpreter-parser.ypp @@ -1381,16 +1381,17 @@ void INTERN_ASSERT(ZString name, int id) { int zid = intern_id(name); if (zid != id) + { FPRINTF(stderr, "[magic-conf] INTERNAL ERROR: Builtin special var %s interned to %d, not %d as it should be!\n", name, zid, id); - error_flag = 1; + error_flag = 1; + } } extern FILE *magic_frontend_in; -// must be called after itemdb initialisation -int magic_init(const char *conffile) +bool magic_init0() { error_flag = 0; @@ -1404,18 +1405,24 @@ int magic_init(const char *conffile) INTERN_ASSERT("script_target", VAR_SCRIPTTARGET); INTERN_ASSERT("location", VAR_LOCATION); - magic_frontend_in = fopen(conffile, "r"); + return !error_flag; +} + +// must be called after itemdb initialisation +bool magic_init1(ZString conffile) +{ + magic_frontend_in = fopen(conffile.c_str(), "r"); if (!magic_frontend_in) { FPRINTF(stderr, "[magic-conf] Magic configuration file `%s' not found -> no magic.\n", conffile); - return 0; + return false; } magic_frontend_parse(); PRINTF("[magic-conf] Magic initialised. %zu spells, %zu teleport anchors.\n", magic_conf.spells_by_name.size(), magic_conf.anchors_by_name.size()); - return error_flag; + return !error_flag; } extern int magic_frontend_lineno; diff --git a/src/map/magic-interpreter.hpp b/src/map/magic-interpreter.hpp index 8afb8af..19f8574 100644 --- a/src/map/magic-interpreter.hpp +++ b/src/map/magic-interpreter.hpp @@ -445,8 +445,9 @@ struct proc_t {} }; +bool magic_init0(); // must be called after itemdb initialisation -int magic_init(const char *); +bool magic_init1(ZString filename); void spell_update_location(dumb_ptr invocation); #endif // MAGIC_INTERPRETER_HPP diff --git a/src/map/magic.cpp b/src/map/magic.cpp index fd848f5..2e521b2 100644 --- a/src/map/magic.cpp +++ b/src/map/magic.cpp @@ -104,8 +104,3 @@ int magic_message(dumb_ptr caster, XString source_invocation) return 0; /* Not a spell */ } - -void do_init_magic(void) -{ - magic_init(MAGIC_CONFIG_FILE); -} diff --git a/src/map/magic.hpp b/src/map/magic.hpp index 79e2a84..30c6e62 100644 --- a/src/map/magic.hpp +++ b/src/map/magic.hpp @@ -43,11 +43,6 @@ void magic_unshroud(dumb_ptr character); void spell_effect_report_termination(int invocation, int bl_id, StatusChange sc_id, int supplanted); -/** - * Initialise all spells, read config data - */ -void do_init_magic(void); - /** * Identifies the invocation used to trigger a spell * diff --git a/src/map/map.cpp b/src/map/map.cpp index 32df1fd..e141ae1 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -19,6 +19,7 @@ #include "../io/write.hpp" #include "../io/read.hpp" +#include "../common/config_parse.hpp" #include "../common/core.hpp" #include "../common/db.hpp" #include "../common/extract.hpp" @@ -26,6 +27,7 @@ #include "../common/nullpo.hpp" #include "../common/socket.hpp" #include "../common/timer.hpp" +#include "../common/version.hpp" #include "atcommand.hpp" #include "battle.hpp" @@ -73,7 +75,6 @@ interval_t autosave_time = DEFAULT_AUTOSAVE_INTERVAL; int save_settings = 0xFFFF; FString motd_txt = "conf/motd.txt"; -FString help_txt = "conf/help.txt"; CharName wisp_server_name = stringish("Server"); // can be modified in char-server configuration file @@ -1271,8 +1272,10 @@ bool map_readmap(map_local *m, size_t num, MapName fn) *------------------------------------------ */ static -int map_readallmap(void) +bool map_readallmap(void) { + // I am increasingly of the opinion that this needs to be moved earlier. + int maps_removed = 0; int num = 0; @@ -1299,9 +1302,10 @@ int map_readallmap(void) { PRINTF("Cowardly refusing to keep going after removing %d maps.\n", maps_removed); - exit(1); + return false; } - return 0; + + return true; } /*========================================== @@ -1427,7 +1431,7 @@ void map_log(XString line) *------------------------------------------ */ static -int map_config_read(ZString cfgName) +bool map_config_read(ZString cfgName) { struct hostent *h = NULL; @@ -1435,16 +1439,23 @@ int map_config_read(ZString cfgName) if (!in.is_open()) { PRINTF("Map configuration file not found at: %s\n", cfgName); - exit(1); + return false; } + bool rv = true; FString line; while (in.getline(line)) { + if (is_comment(line)) + continue; XString w1; ZString w2; - if (!split_key_value(line, &w1, &w2)) + if (!config_split(line, &w1, &w2)) + { + PRINTF("Bad config line: %s\n", line); + rv = false; continue; + } if (w1 == "userid") { AccountName name = stringish(w2); @@ -1473,7 +1484,7 @@ int map_config_read(ZString cfgName) else { PRINTF("Bad IP value: %s\n", line); - abort(); + return false; } chrif_setip(w2ip); } @@ -1499,7 +1510,7 @@ int map_config_read(ZString cfgName) else { PRINTF("Bad IP value: %s\n", line); - abort(); + return false; } clif_setip(w2ip); } @@ -1535,10 +1546,6 @@ int map_config_read(ZString cfgName) { motd_txt = w2; } - else if (w1 == "help_txt") - { - help_txt = w2; - } else if (w1 == "mapreg_txt") { mapreg_txt = w2; @@ -1553,11 +1560,11 @@ int map_config_read(ZString cfgName) } else if (w1 == "import") { - map_config_read(w2); + rv &= map_config_read(w2); } } - return 0; + return rv; } static @@ -1618,14 +1625,6 @@ void term_func(void) map_close_logfile(); } -/// --help was passed -// FIXME this should produce output -static __attribute__((noreturn)) -void map_helpscreen(void) -{ - exit(1); -} - int compare_item(struct item *a, struct item *b) { return ((a->nameid == b->nameid) && @@ -1637,56 +1636,93 @@ int compare_item(struct item *a, struct item *b) (a->card[2] == b->card[2]) && (a->card[3] == b->card[3])); } +static +bool map_confs(XString key, ZString value) +{ + if (key == "map_conf") + return map_config_read(value); + if (key == "battle_conf") + return battle_config_read(value); + if (key == "atcommand_conf") + return atcommand_config_read(value); + + if (key == "item_db") + return itemdb_readdb(value); + if (key == "mob_db") + return mob_readdb(value); + if (key == "mob_skill_db") + return mob_readskilldb(value); + if (key == "skill_db") + return skill_readdb(value); + if (key == "magic_conf") + return magic_init1(value); + PRINTF("unknown map conf key: %s\n", FString(key)); + return false; +} + /*====================================================== * Map-Server Init and Command-line Arguments [Valaris] *------------------------------------------------------ */ int do_init(int argc, ZString *argv) { - int i; - - ZString MAP_CONF_NAME = "conf/map_athena.conf"; - ZString BATTLE_CONF_FILENAME = "conf/battle_athena.conf"; - ZString ATCOMMAND_CONF_FILENAME = "conf/atcommand_athena.conf"; + runflag &= magic_init0(); - for (i = 1; i < argc; i++) + bool loaded_config_yet = false; + for (int i = 1; i < argc; ++i) { - - if (argv[i] == "--help" || argv[i] == "-h" - || argv[i] == "-?" || argv[i] == "/?") - map_helpscreen(); - else if (argv[i] == "--map_config") - MAP_CONF_NAME = argv[++i]; - else if (argv[i] == "--battle_config") - BATTLE_CONF_FILENAME = argv[++i]; - else if (argv[i] == "--atcommand_config") - ATCOMMAND_CONF_FILENAME = argv[++i]; - else if (argv[i] == "--write-atcommand-config") + if (argv[i].startswith('-')) + { + if (argv[i] == "--help") + { + PRINTF("Usage: %s [--help] [--version] [--write_atcommand_config outfile] [files...]\n", + argv[0]); + exit(0); + } + else if (argv[i] == "--version") + { + PRINTF("%s\n", CURRENT_VERSION_STRING); + exit(0); + } + else if (argv[i] == "--write-atcommand-config") + { + ++i; + if (i == argc) + { + PRINTF("Missing argument\n"); + exit(1); + } + ZString filename = argv[i]; + atcommand_config_write(filename); + exit(0); + } + else + { + FPRINTF(stderr, "Unknown argument: %s\n", argv[i]); + runflag = false; + } + } + else { - ZString filename = argv[++i]; - atcommand_config_write(filename); - exit(0); + loaded_config_yet = true; + runflag &= load_config_file(argv[i], map_confs); } } - map_config_read(MAP_CONF_NAME); - battle_config_read(BATTLE_CONF_FILENAME); - atcommand_config_read(ATCOMMAND_CONF_FILENAME); - script_config_read(); + if (!loaded_config_yet) + runflag &= load_config_file("conf/tmwa-map.conf", map_confs); - map_readallmap(); + battle_config_check(); + runflag &= map_readallmap(); - do_init_chrif (); - do_init_clif (); - do_init_itemdb(); - do_init_mob(); // npcの初期化時内でmob_spawnして、mob_dbを参照するのでinit_npcより先 + do_init_chrif(); + do_init_clif(); + do_init_mob2(); do_init_script(); - do_init_npc(); + + runflag &= do_init_npc(); do_init_pc(); do_init_party(); - do_init_storage(); - do_init_skill(); - do_init_magic(); npc_event_do_oninit(); // npcのOnInitイベント実行 diff --git a/src/map/map.hpp b/src/map/map.hpp index 882fde6..0038e67 100644 --- a/src/map/map.hpp +++ b/src/map/map.hpp @@ -575,7 +575,6 @@ extern interval_t autosave_time; extern int save_settings; extern FString motd_txt; -extern FString help_txt; extern CharName wisp_server_name; diff --git a/src/map/mob.cpp b/src/map/mob.cpp index 960c58e..d68c580 100644 --- a/src/map/mob.cpp +++ b/src/map/mob.cpp @@ -14,6 +14,7 @@ #include "../io/cxxstdio.hpp" #include "../io/read.hpp" +#include "../common/config_parse.hpp" #include "../common/extract.hpp" #include "../common/nullpo.hpp" #include "../common/random.hpp" @@ -3408,31 +3409,24 @@ bool extract(XString str, LevelElement *le) return false; } -/*========================================== - * db/mob_db.txt reading - *------------------------------------------ - */ -static -int mob_readdb(void) +bool mob_readdb(ZString filename) { - ZString filename = "db/mob_db.txt"; - - for (mob_db_& e : mob_db) - e = mob_db_{}; - + bool rv = true; { io::ReadFile in(filename); if (!in.is_open()) { - return -1; + PRINTF("Unable to read mob db: %s\n", filename); + return false; } FString line; while (in.getline(line)) { int mob_class; - if (!line || line.startswith("//")) + if (is_comment(line)) continue; + struct mob_db_ mdbv {}; XString ignore; @@ -3501,6 +3495,7 @@ int mob_readdb(void) if (!okay || mob_class <= 1000 || mob_class > 2000) { PRINTF("bad mob line: %s\n", line); + rv = false; continue; } @@ -3554,7 +3549,7 @@ int mob_readdb(void) } PRINTF("read %s done\n", filename); } - return 0; + return rv; } template<> @@ -3625,28 +3620,22 @@ bool extract(XString str, MobSkillTarget *mst) return false; } -/*========================================== - * db/mob_skill_db.txt reading - *------------------------------------------ - */ -static -int mob_readskilldb(void) +bool mob_readskilldb(ZString filename) { - ZString filename = "db/mob_skill_db.txt"; - + bool rv = true; { io::ReadFile in(filename); if (!in.is_open()) { PRINTF("can't read %s\n", filename); - return 0; + return false; } FString line; while (in.getline(line)) { int mob_id; - if (line.startswith("//")) + if (is_comment(line)) continue; XString blah; @@ -3692,43 +3681,29 @@ int mob_readskilldb(void) else if (cancellable == "no") msv.cancel = false; else + { + rv = false; continue; + } msv.casttime = std::chrono::milliseconds(casttime); msv.delay = std::chrono::milliseconds(delay); if (mob_id <= 0) + { + rv = false; continue; + } mob_db[mob_id].skills.push_back(std::move(msv)); } PRINTF("read %s done\n", filename); } - return 0; + return rv; } -void mob_reload(void) +void do_init_mob2(void) { - /* - * - * - * mob_read(); - * - */ - - do_init_mob(); -} - -/*========================================== - * Circumference initialization of mob - *------------------------------------------ - */ -int do_init_mob(void) -{ - mob_readdb(); - - mob_readskilldb(); - Timer(gettick() + MIN_MOBTHINKTIME, mob_ai_hard, MIN_MOBTHINKTIME @@ -3737,6 +3712,4 @@ int do_init_mob(void) mob_ai_lazy, MIN_MOBTHINKTIME * 10 ).detach(); - - return 0; } diff --git a/src/map/mob.hpp b/src/map/mob.hpp index b0445de..bc8350a 100644 --- a/src/map/mob.hpp +++ b/src/map/mob.hpp @@ -84,7 +84,10 @@ short mob_get_head_mid(int); short mob_get_head_buttom(int); short mob_get_clothes_color(int); //player mob dye [Valaris] int mob_get_equip(int); // mob equip [Valaris] -int do_init_mob(void); + +bool mob_readdb(ZString filename); +bool mob_readskilldb(ZString filename); +void do_init_mob2(void); int mob_delete(dumb_ptr md); int mob_catch_delete(dumb_ptr md, BeingRemoveWhy type); diff --git a/src/map/npc.cpp b/src/map/npc.cpp index f5a1f21..4a116b2 100644 --- a/src/map/npc.cpp +++ b/src/map/npc.cpp @@ -15,6 +15,7 @@ #include "../io/cxxstdio.hpp" #include "../io/read.hpp" +#include "../common/config_parse.hpp" #include "../common/db.hpp" #include "../common/extract.hpp" #include "../common/nullpo.hpp" @@ -1711,8 +1712,9 @@ void npc_free(dumb_ptr nd) * npc初期化 *------------------------------------------ */ -int do_init_npc(void) +bool do_init_npc(void) { + bool rv = true; // other fields unused ev_tm_b.tm_min = -1; ev_tm_b.tm_hour = -1; @@ -1725,7 +1727,8 @@ int do_init_npc(void) if (!fp.is_open()) { PRINTF("file not found : %s\n", nsl); - exit(1); + rv = false; + continue; } PRINTF("\rLoading NPCs [%d]: %-54s", npc_id - START_NPC_NUM, nsl); @@ -1737,14 +1740,13 @@ int do_init_npc(void) ZString w4z; lines++; - if (!zline) - continue; - if (zline.startswith("//")) + if (is_comment(zline)) continue; if (!extract(zline, record<'|', 3>(&w1, &w2, &w3, &w4x)) || !w1 || !w2 || !w3) { FPRINTF(stderr, "%s:%d: Broken script line: %s\n", nsl, lines, zline); + rv = false; continue; } if (&*w4x.end() == &*zline.end()) @@ -1762,6 +1764,7 @@ int do_init_npc(void) { // "mapname" is not assigned to this server FPRINTF(stderr, "%s:%d: Map not found: %s\n", nsl, lines, mapname); + rv = false; continue; } } @@ -1801,6 +1804,7 @@ int do_init_npc(void) else { PRINTF("odd script line: %s\n", zline); + script_errors++; } } fflush(stdout); @@ -1811,8 +1815,7 @@ int do_init_npc(void) if (script_errors) { PRINTF("Cowardly refusing to continue after %d errors\n", script_errors); - abort(); + rv = false; } - - return 0; + return rv; } diff --git a/src/map/npc.hpp b/src/map/npc.hpp index 0bc00ed..17eea04 100644 --- a/src/map/npc.hpp +++ b/src/map/npc.hpp @@ -48,7 +48,7 @@ void npc_free(dumb_ptr npc); void npc_addsrcfile(FString); void npc_delsrcfile(FString); -int do_init_npc(void); +bool do_init_npc(void); int npc_event_do_oninit(void); int npc_event_doall_l(ScriptLabel name, int rid, int argc, struct argrec_t *argv); diff --git a/src/map/pc.cpp b/src/map/pc.cpp index 4cfa107..73639dd 100644 --- a/src/map/pc.cpp +++ b/src/map/pc.cpp @@ -5269,11 +5269,7 @@ void pc_calc_sigma(void) } } -/*========================================== - * pc関 係初期化 - *------------------------------------------ - */ -int do_init_pc(void) +void do_init_pc(void) { pc_calc_sigma(); natural_heal_prev_tick = gettick() + NATURAL_HEAL_INTERVAL; @@ -5284,8 +5280,6 @@ int do_init_pc(void) Timer(gettick() + autosave_time, pc_autosave ).detach(); - - return 0; } void pc_cleanup(dumb_ptr sd) diff --git a/src/map/pc.hpp b/src/map/pc.hpp index 40d0e76..54394a2 100644 --- a/src/map/pc.hpp +++ b/src/map/pc.hpp @@ -153,6 +153,6 @@ int pc_logout(dumb_ptr sd); // [fate] Player logs out void pc_show_motd(dumb_ptr sd); -int do_init_pc(void); +void do_init_pc(void); #endif // PC_HPP diff --git a/src/map/script.cpp b/src/map/script.cpp index e947208..51f228f 100644 --- a/src/map/script.cpp +++ b/src/map/script.cpp @@ -16,6 +16,7 @@ #include "../io/lock.hpp" #include "../io/read.hpp" +#include "../common/config_parse.hpp" #include "../common/core.hpp" #include "../common/db.hpp" #include "../common/extract.hpp" @@ -89,13 +90,20 @@ const char *pos_str[11] = static struct Script_Config { - int warn_func_no_comma; - int warn_cmd_no_comma; - int warn_func_mismatch_paramnum; - int warn_cmd_mismatch_paramnum; - int check_cmdcount; - int check_gotocount; + static const + int warn_func_no_comma = 1; + static const + int warn_cmd_no_comma = 1; + static const + int warn_func_mismatch_paramnum = 1; + static const + int warn_cmd_mismatch_paramnum = 1; + static const + int check_cmdcount = 8192; + static const + int check_gotocount = 512; } script_config; + static int parse_cmd_if = 0; static @@ -698,7 +706,7 @@ void read_constdb(void) FString line; while (in.getline(line)) { - if (line.startswith("//")) + if (is_comment(line)) continue; FString name; @@ -5001,16 +5009,6 @@ void script_autosave_mapreg(TimerData *, tick_t) script_save_mapreg(); } -void script_config_read() -{ - script_config.warn_func_no_comma = 1; - script_config.warn_cmd_no_comma = 1; - script_config.warn_func_mismatch_paramnum = 1; - script_config.warn_cmd_mismatch_paramnum = 1; - script_config.check_cmdcount = 8192; - script_config.check_gotocount = 512; -} - void do_final_script(void) { if (mapreg_dirty >= 0) diff --git a/src/map/script.hpp b/src/map/script.hpp index da1d3ce..a05ecf6 100644 --- a/src/map/script.hpp +++ b/src/map/script.hpp @@ -159,7 +159,6 @@ Map scriptlabel_db; extern UPMap userfunc_db; -void script_config_read(); void do_init_script(void); void do_final_script(void); diff --git a/src/map/skill.cpp b/src/map/skill.cpp index 5c8ba09..2253d9d 100644 --- a/src/map/skill.cpp +++ b/src/map/skill.cpp @@ -1173,29 +1173,21 @@ SP scan_stat(XString statname) return SP::ZERO; } -/*========================================== - * スキル関係ファイル読み込み - * skill_db.txt スキルデータ - * skill_cast_db.txt スキルの詠唱時間とディレイデータ - *------------------------------------------ - */ -static -int skill_readdb(void) +bool skill_readdb(ZString filename) { - /* The main skill database */ - for (skill_db_& skdb : skill_db) - skdb = skill_db_{}; - - io::ReadFile in("db/skill_db.txt"); + io::ReadFile in(filename); if (!in.is_open()) { - PRINTF("can't read db/skill_db.txt\n"); - return 1; + PRINTF("can't read %s\n", filename); + return false; } + bool rv = true; FString line_; while (in.getline(line_)) { + // is_comment only works for whole-line comments + // that could change once the Z dependency is dropped ... XString comment = "//"; XString line = line_.xislice_h(std::search(line_.begin(), line_.end(), comment.begin(), comment.end())).rstrip(); if (!line) @@ -1228,16 +1220,25 @@ int skill_readdb(void) ) ) ) + { + rv = false; continue; + } if (/*i < SkillID() ||*/ i > SkillID::MAX_SKILL_DB) + { + rv = false; continue; + } if (castcancel == "yes") skdb.castcancel = true; else if (castcancel == "no") skdb.castcancel = false; else + { + rv = false; continue; + } if (flags == "passive") { @@ -1252,7 +1253,10 @@ int skill_readdb(void) else if (flags == "no") skdb.poolflags = SkillFlags::ZERO; else + { + rv = false; continue; + } skdb.stat = scan_stat(stat); @@ -1265,32 +1269,9 @@ int skill_readdb(void) skill_db[i] = skdb; skill_lookup_by_id(i).desc = FString(tmp); } - PRINTF("read db/skill_db.txt done\n"); - - return 0; -} - -void skill_reload(void) -{ - /* - * - * - * - * - */ - - do_init_skill(); -} + PRINTF("read %s done\n", filename); -/*========================================== - * スキル関係初期化処理 - *------------------------------------------ - */ -int do_init_skill(void) -{ - skill_readdb(); - - return 0; + return rv; } constexpr size_t num_names = sizeof(skill_names) / sizeof(skill_names[0]); diff --git a/src/map/skill.hpp b/src/map/skill.hpp index 14ff1b5..5f29443 100644 --- a/src/map/skill.hpp +++ b/src/map/skill.hpp @@ -57,7 +57,7 @@ skill_name_db& skill_lookup_by_name(XString name); struct block_list; struct map_session_data; -int do_init_skill(void); +bool skill_readdb(ZString filename); // スキルデータベースへのアクセサ int skill_get_hit(SkillID id); diff --git a/src/map/storage.cpp b/src/map/storage.cpp index 54bc792..d6832c8 100644 --- a/src/map/storage.cpp +++ b/src/map/storage.cpp @@ -21,10 +21,6 @@ static Map storage_db; -void do_init_storage(void) -{ -} - void do_final_storage(void) { storage_db.clear(); diff --git a/src/map/storage.hpp b/src/map/storage.hpp index f923ebe..76be7d6 100644 --- a/src/map/storage.hpp +++ b/src/map/storage.hpp @@ -10,7 +10,6 @@ int storage_storageopen(dumb_ptr sd); int storage_storageadd(dumb_ptr sd, int index, int amount); int storage_storageget(dumb_ptr sd, int index, int amount); int storage_storageclose(dumb_ptr sd); -void do_init_storage(void); void do_final_storage(void); struct storage *account2storage(int account_id); struct storage *account2storage2(int account_id); -- cgit v1.2.3-70-g09d2