From 3b98f3439e33b15bba2036c402f9925340fdb2b9 Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Sat, 29 Jun 2013 23:23:43 -0700 Subject: Poison std::string and use the various string classes --- src/map/atcommand.cpp | 1751 +++++++++++++++------------------- src/map/atcommand.hpp | 8 +- src/map/battle.cpp | 338 +++---- src/map/battle.hpp | 2 +- src/map/chrif.cpp | 95 +- src/map/chrif.hpp | 20 +- src/map/clif.cpp | 309 +++--- src/map/clif.hpp | 48 +- src/map/grfio.cpp | 29 +- src/map/grfio.hpp | 5 +- src/map/intif.cpp | 76 +- src/map/intif.hpp | 12 +- src/map/itemdb.cpp | 121 +-- src/map/itemdb.hpp | 6 +- src/map/magic-expr-eval.hpp | 4 +- src/map/magic-expr.cpp | 270 +++--- src/map/magic-expr.hpp | 24 +- src/map/magic-interpreter-base.cpp | 23 +- src/map/magic-interpreter-parser.ypp | 63 +- src/map/magic-interpreter.hpp | 30 +- src/map/magic-stmt.cpp | 124 +-- src/map/magic.cpp | 22 +- src/map/magic.hpp | 10 +- src/map/map.cpp | 189 ++-- src/map/map.hpp | 100 +- src/map/map.t.hpp | 5 + src/map/mob.cpp | 379 ++++---- src/map/mob.hpp | 20 +- src/map/npc.cpp | 571 +++++------ src/map/npc.hpp | 29 +- src/map/party.cpp | 40 +- src/map/party.hpp | 17 +- src/map/pc.cpp | 231 +++-- src/map/pc.hpp | 22 +- src/map/script.cpp | 532 +++++------ src/map/script.hpp | 45 +- src/map/skill.cpp | 142 +-- src/map/skill.hpp | 5 +- src/map/tmw.cpp | 80 +- src/map/tmw.hpp | 5 +- 40 files changed, 2706 insertions(+), 3096 deletions(-) (limited to 'src/map') diff --git a/src/map/atcommand.cpp b/src/map/atcommand.cpp index 1926f83..18ea0e0 100644 --- a/src/map/atcommand.cpp +++ b/src/map/atcommand.cpp @@ -8,9 +8,12 @@ #include "../common/core.hpp" #include "../common/cxxstdio.hpp" +#include "../common/extract.hpp" +#include "../common/human_time_diff.hpp" +#include "../common/io.hpp" #include "../common/mmo.hpp" -#include "../common/random.hpp" #include "../common/nullpo.hpp" +#include "../common/random.hpp" #include "../common/socket.hpp" #include "../common/timer.hpp" #include "../common/utils2.hpp" @@ -34,7 +37,7 @@ #include "../poison.hpp" #define ATCOMMAND_FUNC(x) static \ -int atcommand_##x(const int fd, dumb_ptr sd, const char *, const char *message) +int atcommand_##x(const int fd, dumb_ptr sd, ZString message) ATCOMMAND_FUNC(setup); ATCOMMAND_FUNC(broadcast); ATCOMMAND_FUNC(localbroadcast); @@ -175,13 +178,16 @@ ATCOMMAND_FUNC(doomspot); *AtCommandInfo atcommand_info[]構造体の定義 *------------------------------------------ */ - struct AtCommandInfo { - const char *command; + ZString command; int level; - int(*proc)(const int, dumb_ptr, - const char *command, const char *message); + int (*proc)(const int fd, dumb_ptr sd, ZString message); + + + AtCommandInfo(ZString c, int l, int (*p)(const int, dumb_ptr, ZString)) + : command(c), level(l), proc(p) + {} }; // First char of commands is configured in atcommand_athena.conf. Leave @ in this list for default value. @@ -335,9 +341,50 @@ AtCommandInfo atcommand_info[] = {"@doomspot", 60, atcommand_doomspot}, // add new commands before this line - {NULL, 1, NULL} + {ZString(), 1, nullptr} }; +// If your last arg is not a ZString, you probably wanted extract() +// but not always ... +static +bool asplit(ZString raw, ZString *last) +{ + *last = raw; + return true; +} + +// but this case is just so common and useful. In fact, is the previous ever used otherwise? +static +bool asplit(ZString raw, CharName *last) +{ + if (raw.size() < 4 || raw.size() > 23) + return false; + *last = stringish(raw); + return true; +} + +// huh. +static +bool asplit(ZString raw, NpcName *last) +{ + if (!raw || raw.size() > 23) + return false; + *last = stringish(raw); + return true; +} + +// This differs from extract() in that it does not consume extra spaces. +template::type> +bool asplit(ZString raw, F *first_arg, R *... rest_args) +{ + ZString::iterator it = std::find(raw.begin(), raw.end(), ' '); + XString frist = raw.xislice_h(it); + while (*it == ' ') + ++it; + ZString rest = raw.xislice_t(it); + return extract(frist, first_arg) && asplit(rest, rest_args...); +} + /*========================================== * get_atcommand_level @コマンドの必要レベルを取得 *------------------------------------------ @@ -357,28 +404,28 @@ FILE *get_gm_log(); /*======================================== * At-command logging */ -void log_atcommand(dumb_ptr sd, const_string cmd) +void log_atcommand(dumb_ptr sd, XString cmd) { FILE *fp = get_gm_log(); if (!fp) return; timestamp_seconds_buffer tmpstr; stamp_time(tmpstr); - fprintf(fp, "[%s] %s(%d,%d) %s(%d) : ", + FPRINTF(fp, "[%s] %s(%d,%d) %s(%d) : ", tmpstr, sd->bl_m->name_, sd->bl_x, sd->bl_y, sd->status.name, sd->status.account_id); fwrite(cmd.data(), 1, cmd.size(), fp); } -std::string gm_logfile_name; +FString gm_logfile_name; /*========================================== * Log a timestamped line to GM log file *------------------------------------------ */ FILE *get_gm_log() { - if (gm_logfile_name.empty()) + if (!gm_logfile_name) return NULL; struct tm ctime = TimeT::now(); @@ -393,65 +440,56 @@ FILE *get_gm_log() return gm_logfile; last_logfile_nr = logfile_nr; - std::string fullname = STRPRINTF("%s.%04d-%02d", + FString fullname = STRPRINTF("%s.%04d-%02d", gm_logfile_name, year, month); if (gm_logfile) - fclose_(gm_logfile); + fclose(gm_logfile); - gm_logfile = fopen_(fullname.c_str(), "a"); + gm_logfile = fopen(fullname.c_str(), "a"); if (!gm_logfile) { perror("GM log file"); - gm_logfile_name.clear(); + gm_logfile_name = FString(); } return gm_logfile; } static -AtCommandInfo *atcommand(const int level, const char *message); +AtCommandInfo *atcommand(const int level, ZString message); /*========================================== *is_atcommand @コマンドに存在するかどうか確認する *------------------------------------------ */ bool is_atcommand(const int fd, dumb_ptr sd, - const char *message, int gmlvl) + ZString message, int gmlvl) { nullpo_retr(false, sd); - if (!message || message[0] != '@') + if (!message.startswith('@')) return false; AtCommandInfo *info = atcommand(gmlvl > 0 ? gmlvl : pc_isGM(sd), message); if (!info) { - std::string output = STRPRINTF("GM command not found: %s", + FString output = STRPRINTF("GM command not found: %s", message); clif_displaymessage(fd, output); return true; // don't show in chat } { - const char *str = message; - const char *p = message; - // split the first word - while (*p && !isspace(*p)) - p++; - size_t len = p - str; - char command[len + 1]; - strzcpy(command, str, len + 1); - // skip the spaces; pass as argv - while (isspace(*p)) - p++; + XString command; + ZString arg; + asplit(message, &command, &arg); { - if (info->proc(fd, sd, command, p) != 0) + if (info->proc(fd, sd, arg) != 0) { // Command can not be executed - const char *command_ = command; - std::string output = STRPRINTF("%s failed.", command_); + FString output = STRPRINTF("%s failed.", FString(command)); clif_displaymessage(fd, output); } else @@ -469,28 +507,27 @@ bool is_atcommand(const int fd, dumb_ptr sd, * *------------------------------------------ */ -AtCommandInfo *atcommand(const int level, const char *message) +AtCommandInfo *atcommand(const int level, ZString message) { - const char *p = message; + ZString p = message; if (battle_config.atc_gmonly != 0 && !level) // level = pc_isGM(sd) return nullptr; - if (!p || !*p) + if (!p) { FPRINTF(stderr, "at command message is empty\n"); return nullptr; } - if (*p == '@') - { // check first char. - char command[101]; + if (p.startswith('@')) + { + ZString::iterator space = std::find(p.begin(), p.end(), ' '); + XString command = p.xislice_h(space); int i = 0; - sscanf(p, "%100s", command); - command[sizeof(command) - 1] = '\0'; while (atcommand_info[i].command) { - if (strcasecmp(command, atcommand_info[i].command) == 0 + if (command == atcommand_info[i].command && level >= atcommand_info[i].level) { return &atcommand_info[i]; @@ -522,12 +559,10 @@ void atkillmonster_sub(dumb_ptr bl, int flag) *------------------------------------------ */ static -AtCommandInfo *get_atcommandinfo_byname(const char *name) +AtCommandInfo *get_atcommandinfo_byname(XString name) { - int i; - - for (i = 0; atcommand_info[i].command; i++) - if (strcasecmp(atcommand_info[i].command + 1, name) == 0) + for (int i = 0; atcommand_info[i].command; i++) + if (atcommand_info[i].command.xslice_t(1) == name) return &atcommand_info[i]; return NULL; @@ -537,39 +572,36 @@ AtCommandInfo *get_atcommandinfo_byname(const char *name) * *------------------------------------------ */ -int atcommand_config_read(const char *cfgName) +int atcommand_config_read(ZString cfgName) { - char line[1024], w1[1024], w2[1024]; - AtCommandInfo *p; - FILE *fp; - - if ((fp = fopen_(cfgName, "r")) == NULL) + std::ifstream in(cfgName.c_str()); + if (!in.is_open()) { PRINTF("At commands configuration file not found: %s\n", cfgName); return 1; } - while (fgets(line, sizeof(line) - 1, fp)) + FString line; + while (io::getline(in, line)) { - if (line[0] == '/' && line[1] == '/') - continue; - - if (sscanf(line, "%1023[^:]:%1023s", w1, w2) != 2) + SString w1; + TString w2; + if (!split_key_value(line, &w1, &w2)) continue; - p = get_atcommandinfo_byname(w1); + AtCommandInfo *p = get_atcommandinfo_byname(w1); if (p != NULL) { - p->level = atoi(w2); + p->level = atoi(w2.c_str()); if (p->level > 100) p->level = 100; else if (p->level < 0) p->level = 0; } - - if (strcasecmp(w1, "import") == 0) + else if (w1 == "import") atcommand_config_read(w2); + else + PRINTF("%s: bad line: %s\n", cfgName, line); } - fclose_(fp); return 0; } @@ -585,42 +617,41 @@ int atcommand_config_read(const char *cfgName) *------------------------------------------ */ int atcommand_setup(const int fd, dumb_ptr sd, - const char *, const char *message) + ZString message) { - char character[100] {}; int level = 1; + CharName character; - if (!message || !*message - || sscanf(message, "%d %99[^\n]", &level, character) < 2) + if (!asplit(message, &level, &character)) { clif_displaymessage(fd, "Usage: @setup "); return -1; } level--; - std::string buf; + FString buf; buf = STRPRINTF("-255 %s", character); - atcommand_character_baselevel(fd, sd, "@charbaselvl", buf.c_str()); + atcommand_character_baselevel(fd, sd, buf); buf = STRPRINTF("%d %s", level, character); - atcommand_character_baselevel(fd, sd, "@charbaselvl", buf.c_str()); + atcommand_character_baselevel(fd, sd, buf); // Emote skill buf = STRPRINTF("1 1 %s", character); - atcommand_skill_learn(fd, sd, "@skill-learn", buf.c_str()); + atcommand_skill_learn(fd, sd, buf); // Trade skill buf = STRPRINTF("2 1 %s", character); - atcommand_skill_learn(fd, sd, "@skill-learn", buf.c_str()); + atcommand_skill_learn(fd, sd, buf); // Party skill STRPRINTF("2 2 %s", character); - atcommand_skill_learn(fd, sd, "@skill-learn", buf.c_str()); + atcommand_skill_learn(fd, sd, buf); STRPRINTF("018-1.gat 24 98 %s", character); - atcommand_charwarp(fd, sd, "@charwarp", buf.c_str()); + atcommand_charwarp(fd, sd, buf); - return (0); + return 0; } @@ -629,19 +660,16 @@ int atcommand_setup(const int fd, dumb_ptr sd, *------------------------------------------ */ int atcommand_charwarp(const int fd, dumb_ptr sd, - const char *, const char *message) + ZString message) { - char map_name[100] {}; - char character[100] {}; + MapName map_name; + CharName character; int x = 0, y = 0; - dumb_ptr pl_sd; - if (!message || !*message - || sscanf(message, "%99s %d %d %99[^\n]", map_name, &x, &y, - character) < 4) + if (!asplit(message, &map_name, &x, &y, &character)) { clif_displaymessage(fd, - "Usage: @charwarp/@rura+ "); + "Usage: @charwarp/@rura+ "); return -1; } @@ -649,13 +677,13 @@ int atcommand_charwarp(const int fd, dumb_ptr sd, x = random_::in(1, 399); if (y <= 0) y = random_::in(1, 399); - if (strstr(map_name, ".gat") == NULL && strstr(map_name, ".afm") == NULL && strlen(map_name) < 13) // 16 - 4 (.gat) - strcat(map_name, ".gat"); - if ((pl_sd = map_nick2sd(character)) != NULL) + dumb_ptr pl_sd = map_nick2sd(character); + if (pl_sd) { if (pc_isGM(sd) >= pc_isGM(pl_sd)) - { // you can rura+ only lower or same GM level + { + // you can rura+ only lower or same GM level if (x > 0 && x < 800 && y > 0 && y < 800) { map_local *m = map_mapname2mapid(map_name); @@ -663,14 +691,14 @@ int atcommand_charwarp(const int fd, dumb_ptr sd, && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(fd, - "You are not authorised to warp someone to this map."); + "You are not authorised to warp someone to this map."); return -1; } if (pl_sd->bl_m && pl_sd->bl_m->flag.nowarp && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(fd, - "You are not authorised to warp this player from its actual map."); + "You are not authorised to warp this player from its actual map."); return -1; } if (pc_setpos(pl_sd, map_name, x, y, BeingRemoveWhy::WARPED) == 0) @@ -710,16 +738,16 @@ int atcommand_charwarp(const int fd, dumb_ptr sd, *------------------------------------------ */ int atcommand_warp(const int fd, dumb_ptr sd, - const char *, const char *message) + ZString message) { - char map_name[100] {}; + MapName map_name; int x = 0, y = 0; - if (!message || !*message - || sscanf(message, "%99s %d %d", map_name, &x, &y) < 1) + if (!message + || !extract(message, record<' ', 1>(&map_name, &x, &y))) { clif_displaymessage(fd, - "Please, enter a map (usage: @warp )."); + "Please, enter a map (usage: @warp )."); return -1; } @@ -728,9 +756,6 @@ int atcommand_warp(const int fd, dumb_ptr sd, if (y <= 0) y = random_::in(1, 399); - if (strstr(map_name, ".gat") == NULL && strstr(map_name, ".afm") == NULL && strlen(map_name) < 13) // 16 - 4 (.gat) - strcat(map_name, ".gat"); - if (x > 0 && x < 800 && y > 0 && y < 800) { map_local *m = map_mapname2mapid(map_name); @@ -738,14 +763,14 @@ int atcommand_warp(const int fd, dumb_ptr sd, && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(fd, - "You are not authorised to warp you to this map."); + "You are not authorised to warp you to this map."); return -1; } if (sd->bl_m && sd->bl_m->flag.nowarp && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(fd, - "You are not authorised to warp you from your actual map."); + "You are not authorised to warp you from your actual map."); return -1; } if (pc_setpos(sd, map_name, x, y, BeingRemoveWhy::WARPED) == 0) @@ -770,20 +795,18 @@ int atcommand_warp(const int fd, dumb_ptr sd, *------------------------------------------ */ int atcommand_where(const int fd, dumb_ptr sd, - const char *, const char *message) + ZString message) { - char character[100] {}; - dumb_ptr pl_sd; + CharName character; + extract(message, &character); - if (sscanf(message, "%99[^\n]", character) < 1) - strcpy(character, sd->status.name); - - if ((pl_sd = map_nick2sd(character)) != NULL && + dumb_ptr pl_sd = character.to__actual() ? map_nick2sd(character) : sd; + if (pl_sd != NULL && !((battle_config.hide_GM_session || bool(pl_sd->status.option & Option::HIDE)) && (pc_isGM(pl_sd) > pc_isGM(sd)))) { // you can look only lower or same level - std::string output = STRPRINTF("%s: %s (%d,%d)", + FString output = STRPRINTF("%s: %s (%d,%d)", pl_sd->status.name, pl_sd->mapname_, pl_sd->bl_x, pl_sd->bl_y); clif_displaymessage(fd, output); @@ -802,36 +825,36 @@ int atcommand_where(const int fd, dumb_ptr sd, *------------------------------------------ */ int atcommand_goto(const int fd, dumb_ptr sd, - const char *, const char *message) + ZString message) { - char character[100] {}; - dumb_ptr pl_sd; + CharName character; - if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1) + if (!asplit(message, &character)) { clif_displaymessage(fd, - "Please, enter a player name (usage: @jumpto/@warpto/@goto )."); + "Please, enter a player name (usage: @jumpto/@warpto/@goto )."); return -1; } - if ((pl_sd = map_nick2sd(character)) != NULL) + dumb_ptr pl_sd = map_nick2sd(character); + if (pl_sd != NULL) { if (pl_sd->bl_m && pl_sd->bl_m->flag.nowarpto && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(fd, - "You are not authorised to warp you to the map of this player."); + "You are not authorised to warp you to the map of this player."); return -1; } if (sd->bl_m && sd->bl_m->flag.nowarp && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(fd, - "You are not authorised to warp you from your actual map."); + "You are not authorised to warp you from your actual map."); return -1; } pc_setpos(sd, pl_sd->mapname_, pl_sd->bl_x, pl_sd->bl_y, BeingRemoveWhy::WARPED); - std::string output = STRPRINTF("Jump to %s", character); + FString output = STRPRINTF("Jump to %s", character); clif_displaymessage(fd, output); } else @@ -848,10 +871,11 @@ int atcommand_goto(const int fd, dumb_ptr sd, *------------------------------------------ */ int atcommand_jump(const int fd, dumb_ptr sd, - const char *, const char *message) + ZString message) { int x = 0, y = 0; - sscanf(message, "%d %d", &x, &y); + // may fail + extract(message, record<' '>(&x, &y)); if (x <= 0) x = random_::in(1, 399); @@ -863,18 +887,18 @@ int atcommand_jump(const int fd, dumb_ptr sd, && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(fd, - "You are not authorised to warp you to your actual map."); + "You are not authorised to warp you to your actual map."); return -1; } if (sd->bl_m && sd->bl_m->flag.nowarp && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(fd, - "You are not authorised to warp you from your actual map."); + "You are not authorised to warp you from your actual map."); return -1; } pc_setpos(sd, sd->mapname_, x, y, BeingRemoveWhy::WARPED); - std::string output = STRPRINTF("Jump to %d %d", x, y); + FString output = STRPRINTF("Jump to %d %d", x, y); clif_displaymessage(fd, output); } else @@ -891,17 +915,12 @@ int atcommand_jump(const int fd, dumb_ptr sd, *------------------------------------------ */ int atcommand_who(const int fd, dumb_ptr sd, - const char *, const char *message) + ZString message) { int count; int pl_GM_level, GM_level; - char match_text[100] {}; - char player_name[24] {}; - - if (sscanf(message, "%99[^\n]", match_text) < 1) - strcpy(match_text, ""); - for (int j = 0; match_text[j]; j++) - match_text[j] = tolower(match_text[j]); + VString<23> match_text = message; + match_text = match_text.to_lower(); count = 0; GM_level = pc_isGM(sd); @@ -919,13 +938,11 @@ int atcommand_who(const int fd, dumb_ptr sd, && (pl_GM_level > GM_level))) { // you can look only lower or same level - strzcpy(player_name, pl_sd->status.name, 24); - for (int j = 0; player_name[j]; j++) - player_name[j] = tolower(player_name[j]); - if (strstr(player_name, match_text) != NULL) + VString<23> player_name = pl_sd->status.name.to__lower(); + if (player_name.contains_seq(match_text)) { // search with no case sensitive - std::string output; + FString output; if (pl_GM_level > 0) output = STRPRINTF( "Name: %s (GM:%d) | Location: %s %d %d", @@ -949,7 +966,7 @@ int atcommand_who(const int fd, dumb_ptr sd, clif_displaymessage(fd, "1 player found."); else { - std::string output = STRPRINTF("%d players found.", count); + FString output = STRPRINTF("%d players found.", count); clif_displaymessage(fd, output); } @@ -961,18 +978,14 @@ int atcommand_who(const int fd, dumb_ptr sd, *------------------------------------------ */ int atcommand_whogroup(const int fd, dumb_ptr sd, - const char *, const char *message) + ZString message) { int count; int pl_GM_level, GM_level; - char match_text[100] {}; - char player_name[24] {}; struct party *p; - if (sscanf(message, "%99[^\n]", match_text) < 1) - strcpy(match_text, ""); - for (int j = 0; match_text[j]; j++) - match_text[j] = tolower(match_text[j]); + VString<23> match_text = message; + match_text = match_text.to_lower(); count = 0; GM_level = pc_isGM(sd); @@ -990,15 +1003,13 @@ int atcommand_whogroup(const int fd, dumb_ptr sd, && (pl_GM_level > GM_level))) { // you can look only lower or same level - strzcpy(player_name, pl_sd->status.name, 24); - for (int j = 0; player_name[j]; j++) - player_name[j] = tolower(player_name[j]); - if (strstr(player_name, match_text) != NULL) + VString<23> player_name = pl_sd->status.name.to__lower(); + if (player_name.contains_seq(match_text)) { // search with no case sensitive p = party_search(pl_sd->status.party_id); - const char *temp0 = p ? p->name : "None"; - std::string output; + PartyName temp0 = p ? p->name : stringish("None"); + FString output; if (pl_GM_level > 0) output = STRPRINTF( "Name: %s (GM:%d) | Party: '%s'", @@ -1016,7 +1027,7 @@ int atcommand_whogroup(const int fd, dumb_ptr sd, clif_displaymessage(fd, "1 player found."); else { - std::string output = STRPRINTF("%d players found.", count); + FString output = STRPRINTF("%d players found.", count); clif_displaymessage(fd, output); } @@ -1028,20 +1039,15 @@ int atcommand_whogroup(const int fd, dumb_ptr sd, *------------------------------------------ */ int atcommand_whomap(const int fd, dumb_ptr sd, - const char *, const char *message) + ZString message) { int count; int pl_GM_level, GM_level; map_local *map_id; - char map_name[100] {}; - if (!message || !*message) - map_id = sd->bl_m; - else { - sscanf(message, "%99s", map_name); - if (strstr(map_name, ".gat") == NULL && strstr(map_name, ".afm") == NULL && strlen(map_name) < 13) // 16 - 4 (.gat) - strcat(map_name, ".gat"); + MapName map_name; + extract(message, &map_name); map_id = map_mapname2mapid(map_name); if (map_id == nullptr) map_id = sd->bl_m; @@ -1064,7 +1070,7 @@ int atcommand_whomap(const int fd, dumb_ptr sd, { // you can look only lower or same level if (pl_sd->bl_m == map_id) { - std::string output; + FString output; if (pl_GM_level > 0) output = STRPRINTF( "Name: %s (GM:%d) | Location: %s %d %d", @@ -1082,7 +1088,7 @@ int atcommand_whomap(const int fd, dumb_ptr sd, } } - std::string output = STRPRINTF("%d players found in map '%s'.", + FString output = STRPRINTF("%d players found in map '%s'.", count, map_id->name_); clif_displaymessage(fd, output); @@ -1094,21 +1100,16 @@ int atcommand_whomap(const int fd, dumb_ptr sd, *------------------------------------------ */ int atcommand_whomapgroup(const int fd, dumb_ptr sd, - const char *, const char *message) + ZString message) { int count; int pl_GM_level, GM_level; - char map_name[100] {}; struct party *p; map_local *map_id; - if (!message || !*message) - map_id = sd->bl_m; - else { - sscanf(message, "%99s", map_name); - if (strstr(map_name, ".gat") == NULL && strstr(map_name, ".afm") == NULL && strlen(map_name) < 13) // 16 - 4 (.gat) - strcat(map_name, ".gat"); + MapName map_name; + extract(message, &map_name); map_id = map_mapname2mapid(map_name); if (map_id == nullptr) map_id = sd->bl_m; @@ -1133,8 +1134,8 @@ int atcommand_whomapgroup(const int fd, dumb_ptr sd, if (pl_sd->bl_m == map_id) { p = party_search(pl_sd->status.party_id); - const char *temp0 = p ? p->name : "None"; - std::string output; + PartyName temp0 = p ? p->name : stringish("None"); + FString output; if (pl_GM_level > 0) output = STRPRINTF("Name: %s (GM:%d) | Party: '%s'", pl_sd->status.name, pl_GM_level, temp0); @@ -1148,7 +1149,7 @@ int atcommand_whomapgroup(const int fd, dumb_ptr sd, } } - std::string output; + FString output; if (count == 0) output = STRPRINTF("No player found in map '%s'.", map_id->name_); else if (count == 1) @@ -1167,18 +1168,14 @@ int atcommand_whomapgroup(const int fd, dumb_ptr sd, *------------------------------------------ */ int atcommand_whogm(const int fd, dumb_ptr sd, - const char *, const char *message) + ZString message) { int count; int pl_GM_level, GM_level; - char match_text[100] {}; - char player_name[24] {}; struct party *p; - if (sscanf(message, "%99[^\n]", match_text) < 1) - strcpy(match_text, ""); - for (int j = 0; match_text[j]; j++) - match_text[j] = tolower(match_text[j]); + VString<23> match_text = message; + match_text = match_text.to_lower(); count = 0; GM_level = pc_isGM(sd); @@ -1198,13 +1195,11 @@ int atcommand_whogm(const int fd, dumb_ptr sd, && (pl_GM_level > GM_level))) { // you can look only lower or same level - strzcpy(player_name, pl_sd->status.name, 24); - for (int j = 0; player_name[j]; j++) - player_name[j] = tolower(player_name[j]); - if (strstr(player_name, match_text) != NULL) + VString<23> player_name = pl_sd->status.name.to__lower(); + if (player_name.contains_seq(match_text)) { // search with no case sensitive - std::string output; + FString output; output = STRPRINTF( "Name: %s (GM:%d) | Location: %s %d %d", pl_sd->status.name, pl_GM_level, @@ -1217,7 +1212,7 @@ int atcommand_whogm(const int fd, dumb_ptr sd, pl_sd->status.job_level); clif_displaymessage(fd, output); p = party_search(pl_sd->status.party_id); - const char *temp0 = p ? p->name : "None"; + PartyName temp0 = p ? p->name : stringish("None"); output = STRPRINTF( " Party: '%s'", temp0); @@ -1235,7 +1230,7 @@ int atcommand_whogm(const int fd, dumb_ptr sd, clif_displaymessage(fd, "1 GM found."); else { - std::string output = STRPRINTF("%d GMs found.", count); + FString output = STRPRINTF("%d GMs found.", count); clif_displaymessage(fd, output); } @@ -1247,7 +1242,7 @@ int atcommand_whogm(const int fd, dumb_ptr sd, *------------------------------------------ */ int atcommand_save(const int fd, dumb_ptr sd, - const char *, const char *) + ZString) { nullpo_retr(-1, sd); @@ -1264,7 +1259,7 @@ int atcommand_save(const int fd, dumb_ptr sd, *------------------------------------------ */ int atcommand_load(const int fd, dumb_ptr sd, - const char *, const char *) + ZString) { map_local *m = map_mapname2mapid(sd->status.save_point.map_); if (m != nullptr && m->flag.nowarpto @@ -1294,11 +1289,11 @@ int atcommand_load(const int fd, dumb_ptr sd, *------------------------------------------ */ int atcommand_speed(const int fd, dumb_ptr sd, - const char *, const char *message) + ZString message) { - if (!message || !*message) + if (!message) { - std::string output = STRPRINTF( + FString output = STRPRINTF( "Please, enter a speed value (usage: @speed <%d-%d>).", static_cast(MIN_WALK_SPEED.count()), static_cast(MAX_WALK_SPEED.count())); @@ -1306,7 +1301,7 @@ int atcommand_speed(const int fd, dumb_ptr sd, return -1; } - interval_t speed = static_cast(atoi(message)); + interval_t speed = static_cast(atoi(message.c_str())); if (speed >= MIN_WALK_SPEED && speed <= MAX_WALK_SPEED) { sd->speed = speed; @@ -1317,7 +1312,7 @@ int atcommand_speed(const int fd, dumb_ptr sd, } else { - std::string output = STRPRINTF( + FString output = STRPRINTF( "Please, enter a valid speed value (usage: @speed <%d-%d>).", static_cast(MIN_WALK_SPEED.count()), static_cast(MAX_WALK_SPEED.count())); @@ -1333,7 +1328,7 @@ int atcommand_speed(const int fd, dumb_ptr sd, *------------------------------------------ */ int atcommand_storage(const int fd, dumb_ptr sd, - const char *, const char *) + ZString) { struct storage *stor; //changes from Freya/Yor nullpo_retr(-1, sd); @@ -1361,24 +1356,21 @@ int atcommand_storage(const int fd, dumb_ptr sd, *------------------------------------------ */ int atcommand_option(const int fd, dumb_ptr sd, - const char *, const char *message) + ZString message) { - int param1_ = 0, param2_ = 0, param3_ = 0; nullpo_retr(-1, sd); - if (!message || !*message - || sscanf(message, "%d %d %d", ¶m1_, ¶m2_, ¶m3_) < 1 - || param1_ < 0 || param2_ < 0 || param3_ < 0) + Opt1 param1 = Opt1::ZERO; + Opt2 param2 = Opt2::ZERO; + Option param3 = Option::ZERO; + + if (!extract(message, record<',', 1>(¶m1, ¶m2, ¶m3))) { clif_displaymessage(fd, - "Please, enter at least a option (usage: @option )."); + "Please, enter at least a option (usage: @option )."); return -1; } - Opt1 param1 = Opt1(param1_); - Opt2 param2 = Opt2(param2_); - Option param3 = Option(param3_); - sd->opt1 = param1; sd->opt2 = param2; sd->status.option = param3; @@ -1395,7 +1387,7 @@ int atcommand_option(const int fd, dumb_ptr sd, *------------------------------------------ */ int atcommand_hide(const int fd, dumb_ptr sd, - const char *, const char *) + ZString) { if (bool(sd->status.option & Option::HIDE)) { @@ -1417,7 +1409,7 @@ int atcommand_hide(const int fd, dumb_ptr sd, *------------------------------------------ */ int atcommand_die(const int fd, dumb_ptr sd, - const char *, const char *) + ZString) { pc_damage(NULL, sd, sd->status.hp + 1); clif_displaymessage(fd, "A pity! You've died."); @@ -1430,19 +1422,19 @@ int atcommand_die(const int fd, dumb_ptr sd, *------------------------------------------ */ int atcommand_kill(const int fd, dumb_ptr sd, - const char *, const char *message) + ZString message) { - char character[100] {}; - dumb_ptr pl_sd; + CharName character; - if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1) + if (!asplit(message, &character)) { clif_displaymessage(fd, - "Please, enter a player name (usage: @kill )."); + "Please, enter a player name (usage: @kill )."); return -1; } - if ((pl_sd = map_nick2sd(character)) != NULL) + dumb_ptr pl_sd = map_nick2sd(character); + if (pl_sd != NULL) { if (pc_isGM(sd) >= pc_isGM(pl_sd)) { // you can kill only lower or same level @@ -1469,7 +1461,7 @@ int atcommand_kill(const int fd, dumb_ptr sd, *------------------------------------------ */ int atcommand_alive(const int fd, dumb_ptr sd, - const char *, const char *) + ZString) { sd->status.hp = sd->status.max_hp; sd->status.sp = sd->status.max_sp; @@ -1489,12 +1481,12 @@ int atcommand_alive(const int fd, dumb_ptr sd, *------------------------------------------ */ int atcommand_kami(const int fd, dumb_ptr, - const char *, const char *message) + ZString message) { - if (!message || !*message) + if (!message) { clif_displaymessage(fd, - "Please, enter a message (usage: @kami )."); + "Please, enter a message (usage: @kami )."); return -1; } @@ -1508,11 +1500,11 @@ int atcommand_kami(const int fd, dumb_ptr, *------------------------------------------ */ int atcommand_heal(const int fd, dumb_ptr sd, - const char *, const char *message) + ZString message) { int hp = 0, sp = 0; // [Valaris] thanks to fov - sscanf(message, "%d %d", &hp, &sp); + extract(message, record<' '>(&hp, &sp)); if (hp == 0 && sp == 0) { @@ -1556,18 +1548,17 @@ int atcommand_heal(const int fd, dumb_ptr sd, *------------------------------------------ */ int atcommand_item(const int fd, dumb_ptr sd, - const char *, const char *message) + ZString message) { - char item_name[100] {}; + ItemName item_name; int number = 0, item_id; struct item_data *item_data; int get_count, i; - if (!message || !*message - || sscanf(message, "%99s %d", item_name, &number) < 1) + if (!extract(message, record<' ', 1>(&item_name, &number))) { clif_displaymessage(fd, - "Please, enter an item name/id (usage: @item [quantity])."); + "Please, enter an item name/id (usage: @item [quantity])."); return -1; } @@ -1576,7 +1567,7 @@ int atcommand_item(const int fd, dumb_ptr sd, item_id = 0; if ((item_data = itemdb_searchname(item_name)) != NULL || - (item_data = itemdb_exists(atoi(item_name))) != NULL) + (item_data = itemdb_exists(atoi(item_name.c_str()))) != NULL) item_id = item_data->nameid; if (item_id >= 500) @@ -1615,7 +1606,7 @@ int atcommand_item(const int fd, dumb_ptr sd, *------------------------------------------ */ int atcommand_itemreset(const int fd, dumb_ptr sd, - const char *, const char *) + ZString) { int i; @@ -1635,7 +1626,7 @@ int atcommand_itemreset(const int fd, dumb_ptr sd, *------------------------------------------ */ int atcommand_itemcheck(const int, dumb_ptr sd, - const char *, const char *) + ZString) { pc_checkitem(sd); @@ -1647,14 +1638,14 @@ int atcommand_itemcheck(const int, dumb_ptr sd, *------------------------------------------ */ int atcommand_baselevelup(const int fd, dumb_ptr sd, - const char *, const char *message) + ZString message) { int level, i; - if (!message || !*message || (level = atoi(message)) == 0) + if (!extract(message, &level) || !level) { clif_displaymessage(fd, - "Please, enter a level adjustement (usage: @blvl )."); + "Please, enter a level adjustement (usage: @blvl )."); return -1; } @@ -1713,14 +1704,14 @@ int atcommand_baselevelup(const int fd, dumb_ptr sd, // TODO: merge this with pc_setparam(SP::JOBLEVEL) // then fix the funny 50 and/or 10 limitation. int atcommand_joblevelup(const int fd, dumb_ptr sd, - const char *, const char *message) + ZString message) { int up_level = 50, level; - if (!message || !*message || (level = atoi(message)) == 0) + if (!extract(message, &level) || !level) { clif_displaymessage(fd, - "Please, enter a level adjustement (usage: @jlvl )."); + "Please, enter a level adjustement (usage: @jlvl )."); return -1; } @@ -1775,20 +1766,23 @@ int atcommand_joblevelup(const int fd, dumb_ptr sd, *------------------------------------------ */ int atcommand_help(const int fd, dumb_ptr sd, - const char *, const char *) + ZString) { - std::ifstream in(help_txt); + std::ifstream in(help_txt.c_str()); if (in.is_open()) { clif_displaymessage(fd, "Help commands:"); int gm_level = pc_isGM(sd); - std::string line; - while (std::getline(in, line)) + FString line; + while (io::getline(in, line)) { - std::string w1, w2; + SString w1; + TString w2; if (!split_key_value(line, &w1, &w2)) continue; - if (gm_level >= atoi(w1.c_str())) + int level; + extract(w1, &level); + if (gm_level >= level) clif_displaymessage(fd, w2); } } @@ -1806,14 +1800,12 @@ int atcommand_help(const int fd, dumb_ptr sd, *------------------------------------------ */ int atcommand_gm(const int fd, dumb_ptr sd, - const char *, const char *message) + ZString message) { - char password[100] {}; - - if (!message || !*message || sscanf(message, "%99[^\n]", password) < 1) + if (!message) { clif_displaymessage(fd, - "Please, enter a password (usage: @gm )."); + "Please, enter a password (usage: @gm )."); return -1; } @@ -1823,8 +1815,7 @@ int atcommand_gm(const int fd, dumb_ptr sd, return -1; } else - chrif_changegm(sd->status.account_id, password, - strlen(password) + 1); + chrif_changegm(sd->status.account_id, message); return 0; } @@ -1834,7 +1825,7 @@ int atcommand_gm(const int fd, dumb_ptr sd, *------------------------------------------ */ int atcommand_pvpoff(const int fd, dumb_ptr sd, - const char *, const char *) + ZString) { if (battle_config.pk_mode) { //disable command if server is in PK mode [Valaris] @@ -1874,7 +1865,7 @@ int atcommand_pvpoff(const int fd, dumb_ptr sd, *------------------------------------------ */ int atcommand_pvpon(const int fd, dumb_ptr sd, - const char *, const char *) + ZString) { if (battle_config.pk_mode) { //disable command if server is in PK mode [Valaris] @@ -1918,15 +1909,13 @@ int atcommand_pvpon(const int fd, dumb_ptr sd, *------------------------------------------ */ int atcommand_model(const int fd, dumb_ptr sd, - const char *, const char *message) + ZString message) { int hair_style = 0, hair_color = 0, cloth_color = 0; - if (!message || !*message - || sscanf(message, "%d %d %d", &hair_style, &hair_color, - &cloth_color) < 1) + if (!extract(message, record<' ', 1>(&hair_style, &hair_color, &cloth_color))) { - std::string output = STRPRINTF( + FString output = STRPRINTF( "Please, enter at least a value (usage: @model ).", MIN_HAIR_STYLE, MAX_HAIR_STYLE, MIN_HAIR_COLOR, MAX_HAIR_COLOR, @@ -1960,13 +1949,13 @@ int atcommand_model(const int fd, dumb_ptr sd, *------------------------------------------ */ int atcommand_dye(const int fd, dumb_ptr sd, - const char *, const char *message) + ZString message) { int cloth_color = 0; - if (!message || !*message || sscanf(message, "%d", &cloth_color) < 1) + if (!extract(message, &cloth_color)) { - std::string output = STRPRINTF( + FString output = STRPRINTF( "Please, enter a clothes color (usage: @dye/@ccolor ).", MIN_CLOTH_COLOR, MAX_CLOTH_COLOR); clif_displaymessage(fd, output); @@ -1994,13 +1983,13 @@ int atcommand_dye(const int fd, dumb_ptr sd, *------------------------------------------ */ int atcommand_hair_style(const int fd, dumb_ptr sd, - const char *, const char *message) + ZString message) { int hair_style = 0; - if (!message || !*message || sscanf(message, "%d", &hair_style) < 1) + if (!extract(message, &hair_style)) { - std::string output = STRPRINTF( + FString output = STRPRINTF( "Please, enter a hair style (usage: @hairstyle/@hstyle ).", MIN_HAIR_STYLE, MAX_HAIR_STYLE); clif_displaymessage(fd, output); @@ -2028,13 +2017,13 @@ int atcommand_hair_style(const int fd, dumb_ptr sd, *------------------------------------------ */ int atcommand_hair_color(const int fd, dumb_ptr sd, - const char *, const char *message) + ZString message) { int hair_color = 0; - if (!message || !*message || sscanf(message, "%d", &hair_color) < 1) + if (!extract(message, &hair_color)) { - std::string output = STRPRINTF( + FString output = STRPRINTF( "Please, enter a hair color (usage: @haircolor/@hcolor ).", MIN_HAIR_COLOR, MAX_HAIR_COLOR); clif_displaymessage(fd, output); @@ -2062,9 +2051,9 @@ int atcommand_hair_color(const int fd, dumb_ptr sd, *------------------------------------------ */ int atcommand_spawn(const int fd, dumb_ptr sd, - const char *command, const char *message) + ZString message) { - char monster[100] {}; + MobName monster; int mob_id; int number = 0; int x = 0, y = 0; @@ -2072,8 +2061,7 @@ int atcommand_spawn(const int fd, dumb_ptr sd, int i, j, k; int mx, my, range; - if (!message || !*message - || sscanf(message, "%99s %d %d %d", monster, &number, &x, &y) < 1) + if (!extract(message, record<' ', 1>(&monster, &number, &x, &y))) { clif_displaymessage(fd, "Give a monster name/id please."); return -1; @@ -2081,7 +2069,7 @@ int atcommand_spawn(const int fd, dumb_ptr sd, // If monster identifier/name argument is a name if ((mob_id = mobdb_searchname(monster)) == 0) // check name first (to avoid possible name begining by a number) - mob_id = mobdb_checkid(atoi(monster)); + mob_id = mobdb_checkid(atoi(monster.c_str())); if (mob_id == 0) { @@ -2089,12 +2077,6 @@ int atcommand_spawn(const int fd, dumb_ptr sd, return -1; } - if (mob_id == 1288) - { - clif_displaymessage(fd, "Cannot spawn emperium."); - return -1; - } - if (number <= 0) number = 1; @@ -2104,8 +2086,8 @@ int atcommand_spawn(const int fd, dumb_ptr sd, number = battle_config.atc_spawn_quantity_limit; if (battle_config.etc_log) - PRINTF("%s monster='%s' id=%d count=%d (%d,%d)\n", command, monster, - mob_id, number, x, y); + PRINTF("@spawn monster='%s' id=%d count=%d (%d,%d)\n", + monster, mob_id, number, x, y); count = 0; range = sqrt(number) / 2; @@ -2125,7 +2107,7 @@ int atcommand_spawn(const int fd, dumb_ptr sd, my = sd->bl_y + random_::in(-range / 2, range / 2); else my = y; - k = mob_once_spawn(sd, "this", mx, my, "", mob_id, 1, ""); + k = mob_once_spawn(sd, MOB_THIS_MAP, mx, my, MobName(), mob_id, 1, NpcEvent()); } count += (k != 0) ? 1 : 0; } @@ -2135,7 +2117,7 @@ int atcommand_spawn(const int fd, dumb_ptr sd, clif_displaymessage(fd, "All monster summoned!"); else { - std::string output = STRPRINTF("%d monster(s) summoned!", + FString output = STRPRINTF("%d monster(s) summoned!", count); clif_displaymessage(fd, output); } @@ -2154,17 +2136,12 @@ int atcommand_spawn(const int fd, dumb_ptr sd, */ static void atcommand_killmonster_sub(const int fd, dumb_ptr sd, - const char *message, const int drop) + ZString message, const int drop) { - char map_name[100] {}; - map_local *map_id; - if (!message || !*message || sscanf(message, "%99s", map_name) < 1) - map_id = sd->bl_m; - else { - if (strstr(map_name, ".gat") == NULL && strstr(map_name, ".afm") == NULL && strlen(map_name) < 13) // 16 - 4 (.gat) - strcat(map_name, ".gat"); + MapName map_name; + extract(message, &map_name); map_id = map_mapname2mapid(map_name); if (map_id == nullptr) map_id = sd->bl_m; @@ -2177,8 +2154,6 @@ void atcommand_killmonster_sub(const int fd, dumb_ptr sd, BL::MOB); clif_displaymessage(fd, "All monsters killed!"); - - return; } /*========================================== @@ -2186,7 +2161,7 @@ void atcommand_killmonster_sub(const int fd, dumb_ptr sd, *------------------------------------------ */ int atcommand_killmonster(const int fd, dumb_ptr sd, - const char *, const char *message) + ZString message) { atcommand_killmonster_sub(fd, sd, message, 1); @@ -2202,7 +2177,7 @@ void atlist_nearby_sub(dumb_ptr bl, int fd) { nullpo_retv(bl); - std::string buf = STRPRINTF(" - \"%s\"", + FString buf = STRPRINTF(" - \"%s\"", bl->as_player()->status.name); clif_displaymessage(fd, buf); } @@ -2212,7 +2187,7 @@ void atlist_nearby_sub(dumb_ptr bl, int fd) *------------------------------------------ */ int atcommand_list_nearby(const int fd, dumb_ptr sd, - const char *, const char *) + ZString) { clif_displaymessage(fd, "Nearby players:"); map_foreachinarea(std::bind(atlist_nearby_sub, ph::_1, fd), @@ -2229,7 +2204,7 @@ int atcommand_list_nearby(const int fd, dumb_ptr sd, *------------------------------------------ */ int atcommand_killmonster2(const int fd, dumb_ptr sd, - const char *, const char *message) + ZString message) { atcommand_killmonster_sub(fd, sd, message, 0); @@ -2241,13 +2216,13 @@ int atcommand_killmonster2(const int fd, dumb_ptr sd, *------------------------------------------ */ int atcommand_gat(const int fd, dumb_ptr sd, - const char *, const char *) + ZString) { int y; for (y = 2; y >= -2; y--) { - std::string output = STRPRINTF( + FString output = STRPRINTF( "%s (x= %d, y= %d) %02X %02X %02X %02X %02X", sd->bl_m->name_, sd->bl_x - 2, sd->bl_y + y, map_getcell(sd->bl_m, sd->bl_x - 2, sd->bl_y + y), @@ -2266,18 +2241,19 @@ int atcommand_gat(const int fd, dumb_ptr sd, *------------------------------------------ */ int atcommand_packet(const int fd, dumb_ptr sd, - const char *, const char *message) + ZString message) { - int type = 0, flag = 0; + StatusChange type {}; + int flag = 0; - if (!message || !*message || sscanf(message, "%d %d", &type, &flag) < 2) + if (!extract(message, record<' '>(&type, &flag))) { clif_displaymessage(fd, - "Please, enter a status type/flag (usage: @packet )."); + "Please, enter a status type/flag (usage: @packet )."); return -1; } - clif_status_change(sd, StatusChange(type), flag); + clif_status_change(sd, type, flag); return 0; } @@ -2287,14 +2263,14 @@ int atcommand_packet(const int fd, dumb_ptr sd, *------------------------------------------ */ int atcommand_statuspoint(const int fd, dumb_ptr sd, - const char *, const char *message) + ZString message) { int point, new_status_point; - if (!message || !*message || (point = atoi(message)) == 0) + if (!extract(message, &point) || point == 0) { clif_displaymessage(fd, - "Please, enter a number (usage: @stpoint )."); + "Please, enter a number (usage: @stpoint )."); return -1; } @@ -2327,14 +2303,14 @@ int atcommand_statuspoint(const int fd, dumb_ptr sd, *------------------------------------------ */ int atcommand_skillpoint(const int fd, dumb_ptr sd, - const char *, const char *message) + ZString message) { int point, new_skill_point; - if (!message || !*message || (point = atoi(message)) == 0) + if (!extract(message, &point) || point == 0) { clif_displaymessage(fd, - "Please, enter a number (usage: @skpoint )."); + "Please, enter a number (usage: @skpoint )."); return -1; } @@ -2367,14 +2343,14 @@ int atcommand_skillpoint(const int fd, dumb_ptr sd, *------------------------------------------ */ int atcommand_zeny(const int fd, dumb_ptr sd, - const char *, const char *message) + ZString message) { int zeny, new_zeny; - if (!message || !*message || (zeny = atoi(message)) == 0) + if (!extract(message, &zeny) || zeny == 0) { clif_displaymessage(fd, - "Please, enter an amount (usage: @zeny )."); + "Please, enter an amount (usage: @zeny )."); return -1; } @@ -2408,14 +2384,13 @@ int atcommand_zeny(const int fd, dumb_ptr sd, */ template int atcommand_param(const int fd, dumb_ptr sd, - const char *, const char *message) + ZString message) { int value = 0, new_value; - if (!message || !*message || sscanf(message, "%d", &value) < 1 + if (!extract(message, &value) || value == 0) { - // there was a clang bug here // fortunately, STRPRINTF was not actually needed clif_displaymessage(fd, @@ -2455,11 +2430,11 @@ int atcommand_param(const int fd, dumb_ptr sd, */ //** Stat all by fritz (rewritten by [Yor]) int atcommand_all_stats(const int fd, dumb_ptr sd, - const char *, const char *message) + ZString message) { int count, value = 0, new_value; - if (!message || !*message || sscanf(message, "%d", &value) < 1 + if (!extract(message, &value) || value == 0) value = battle_config.max_parameter; @@ -2501,19 +2476,19 @@ int atcommand_all_stats(const int fd, dumb_ptr sd, *------------------------------------------ */ int atcommand_recall(const int fd, dumb_ptr sd, - const char *, const char *message) + ZString message) { - char character[100] {}; - dumb_ptr pl_sd; + CharName character; - if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1) + if (!asplit(message, &character)) { clif_displaymessage(fd, - "Please, enter a player name (usage: @recall )."); + "Please, enter a player name (usage: @recall )."); return -1; } - if ((pl_sd = map_nick2sd(character)) != NULL) + dumb_ptr pl_sd = map_nick2sd(character); + if (pl_sd != NULL) { if (pc_isGM(sd) >= pc_isGM(pl_sd)) { // you can recall only lower or same level @@ -2521,18 +2496,18 @@ int atcommand_recall(const int fd, dumb_ptr sd, && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(fd, - "You are not authorised to warp somenone to your actual map."); + "You are not authorised to warp somenone to your actual map."); return -1; } if (pl_sd->bl_m && pl_sd->bl_m->flag.nowarp && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(fd, - "You are not authorised to warp this player from its actual map."); + "You are not authorised to warp this player from its actual map."); return -1; } pc_setpos(pl_sd, sd->mapname_, sd->bl_x, sd->bl_y, BeingRemoveWhy::QUIT); - std::string output = STRPRINTF("%s recalled!", character); + FString output = STRPRINTF("%s recalled!", character); clif_displaymessage(fd, output); } else @@ -2555,19 +2530,19 @@ int atcommand_recall(const int fd, dumb_ptr sd, *------------------------------------------ */ int atcommand_revive(const int fd, dumb_ptr sd, - const char *, const char *message) + ZString message) { - char character[100] {}; - dumb_ptr pl_sd; + CharName character; - if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1) + if (!asplit(message, &character)) { clif_displaymessage(fd, - "Please, enter a player name (usage: @revive )."); + "Please, enter a player name (usage: @revive )."); return -1; } - if ((pl_sd = map_nick2sd(character)) != NULL) + dumb_ptr pl_sd = map_nick2sd(character); + if (pl_sd != NULL) { pl_sd->status.hp = pl_sd->status.max_hp; pc_setstand(pl_sd); @@ -2592,21 +2567,21 @@ int atcommand_revive(const int fd, dumb_ptr sd, *------------------------------------------ */ int atcommand_character_stats(const int fd, dumb_ptr, - const char *, const char *message) + ZString message) { - char character[100] {}; - dumb_ptr pl_sd; + CharName character; - if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1) + if (!asplit(message, &character)) { clif_displaymessage(fd, - "Please, enter a player name (usage: @charstats )."); + "Please, enter a player name (usage: @charstats )."); return -1; } - if ((pl_sd = map_nick2sd(character)) != NULL) + dumb_ptr pl_sd = map_nick2sd(character); + if (pl_sd != NULL) { - std::string output; + FString output; output = STRPRINTF("'%s' stats:", pl_sd->status.name); clif_displaymessage(fd, output); output = STRPRINTF("Base Level - %d", pl_sd->status.base_level), @@ -2651,7 +2626,7 @@ int atcommand_character_stats(const int fd, dumb_ptr, */ //** Character Stats All by fritz int atcommand_character_stats_all(const int fd, dumb_ptr, - const char *, const char *) + ZString) { int count; @@ -2663,13 +2638,13 @@ int atcommand_character_stats_all(const int fd, dumb_ptr, dumb_ptr pl_sd = dumb_ptr(static_cast(session[i]->session_data.get())); if (pl_sd && pl_sd->state.auth) { - std::string gmlevel; + FString gmlevel; if (pc_isGM(pl_sd) > 0) gmlevel = STRPRINTF("| GM Lvl: %d", pc_isGM(pl_sd)); else gmlevel = " "; - std::string output; + FString output; output = STRPRINTF( "Name: %s | BLvl: %d | Job: Novice/Human (Lvl: %d) | HP: %d/%d | SP: %d/%d", pl_sd->status.name, pl_sd->status.base_level, @@ -2698,7 +2673,7 @@ int atcommand_character_stats_all(const int fd, dumb_ptr, clif_displaymessage(fd, "1 player found."); else { - std::string output = STRPRINTF("%d players found.", count); + FString output = STRPRINTF("%d players found.", count); clif_displaymessage(fd, output); } @@ -2710,26 +2685,21 @@ int atcommand_character_stats_all(const int fd, dumb_ptr, *------------------------------------------ */ int atcommand_character_option(const int fd, dumb_ptr sd, - const char *, const char *message) + ZString message) { - char character[100] {}; - int opt1_ = 0, opt2_ = 0, opt3_ = 0; - dumb_ptr pl_sd; - - if (!message || !*message - || sscanf(message, "%d %d %d %99[^\n]", &opt1_, &opt2_, &opt3_, - character) < 4 || opt1_ < 0 || opt2_ < 0 || opt3_ < 0) + Opt1 opt1; + Opt2 opt2; + Option opt3; + CharName character; + if (!asplit(message, &opt1, &opt2, &opt3, &character)) { clif_displaymessage(fd, - "Please, enter valid options and a player name (usage: @charoption )."); + "Please, enter valid options and a player name (usage: @charoption )."); return -1; } - Opt1 opt1 = Opt1(opt1_); - Opt2 opt2 = Opt2(opt2_); - Option opt3 = Option(opt3_); - - if ((pl_sd = map_nick2sd(character)) != NULL) + dumb_ptr pl_sd = map_nick2sd(character); + if (pl_sd != NULL) { if (pc_isGM(sd) >= pc_isGM(pl_sd)) { @@ -2762,31 +2732,19 @@ int atcommand_character_option(const int fd, dumb_ptr sd, *------------------------------------------ */ int atcommand_char_change_sex(const int fd, dumb_ptr sd, - const char *, const char *message) + ZString message) { - char character[100] {}; + CharName character; - if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1) + if (!asplit(message, &character)) { clif_displaymessage(fd, - "Please, enter a player name (usage: @charchangesex )."); + "Please, enter a player name (usage: @charchangesex )."); return -1; } - // check player name - if (strlen(character) < 4) { - clif_displaymessage(fd, "Sorry, but a player name have at least 4 characters."); - return -1; - } - else if (strlen(character) > 23) - { - clif_displaymessage(fd, "Sorry, but a player name have 23 characters maximum."); - return -1; - } - else - { - chrif_char_ask_name(sd->status.account_id, character, 5, 0, 0, 0, 0, 0, 0); // type: 5 - changesex + chrif_char_ask_name(sd->status.account_id, character, 5, HumanTimeDiff()); // type: 5 - changesex clif_displaymessage(fd, "Character name sends to char-server to ask it."); } @@ -2799,31 +2757,19 @@ int atcommand_char_change_sex(const int fd, dumb_ptr sd, *------------------------------------------ */ int atcommand_char_block(const int fd, dumb_ptr sd, - const char *, const char *message) + ZString message) { - char character[100] {}; + CharName character; - if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1) + if (!asplit(message, &character)) { clif_displaymessage(fd, - "Please, enter a player name (usage: @block )."); + "Please, enter a player name (usage: @block )."); return -1; } - // check player name - if (strlen(character) < 4) { - clif_displaymessage(fd, "Sorry, but a player name have at least 4 characters."); - return -1; - } - else if (strlen(character) > 23) - { - clif_displaymessage(fd, "Sorry, but a player name have 23 characters maximum."); - return -1; - } - else - { - chrif_char_ask_name(sd->status.account_id, character, 1, 0, 0, 0, 0, 0, 0); // type: 1 - block + chrif_char_ask_name(sd->status.account_id, character, 1, HumanTimeDiff()); // type: 1 - block clif_displaymessage(fd, "Character name sends to char-server to ask it."); } @@ -2847,94 +2793,21 @@ int atcommand_char_block(const int fd, dumb_ptr sd, *------------------------------------------ */ int atcommand_char_ban(const int fd, dumb_ptr sd, - const char *, const char *message) + ZString message) { - char modif[100] {}; - char character[100] {}; - char *modif_p; - int year, month, day, hour, minute, second, value; + HumanTimeDiff modif; + CharName character; - if (!message || !*message - || sscanf(message, "%s %99[^\n]", modif, character) < 2) + if (!asplit(message, &modif, &character) + || !modif) { clif_displaymessage(fd, - "Please, enter ban time and a player name (usage: @charban/@ban/@banish/@charbanish