From c080e504e4d74027b985b1ed675c172c083cea76 Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Thu, 27 Dec 2012 21:23:46 -0800 Subject: Use cxxstdio --- src/map/atcommand.cpp | 1276 +++++++++++++--------------------- src/map/atcommand.hpp | 9 +- src/map/battle.cpp | 671 ++++++------------ src/map/chrif.cpp | 166 +++-- src/map/chrif.hpp | 6 +- src/map/clif.cpp | 163 ++--- src/map/clif.hpp | 7 +- src/map/intif.cpp | 69 +- src/map/intif.hpp | 4 +- src/map/itemdb.cpp | 147 +--- src/map/magic-expr.cpp | 74 +- src/map/magic-interpreter-base.cpp | 12 +- src/map/magic-interpreter-lexer.lpp | 2 +- src/map/magic-interpreter-parser.ypp | 16 +- src/map/magic-stmt.cpp | 48 +- src/map/magic.cpp | 2 +- src/map/map.cpp | 366 +++++----- src/map/map.hpp | 11 +- src/map/mob.cpp | 64 +- src/map/npc.cpp | 92 ++- src/map/npc.hpp | 4 +- src/map/party.cpp | 12 +- src/map/path.cpp | 8 +- src/map/pc.cpp | 146 ++-- src/map/script.cpp | 299 ++++---- src/map/script.hpp | 39 +- src/map/skill-pools.cpp | 2 +- src/map/skill.cpp | 74 +- src/map/tmw.cpp | 33 +- src/map/tmw.hpp | 3 +- 30 files changed, 1494 insertions(+), 2331 deletions(-) (limited to 'src/map') diff --git a/src/map/atcommand.cpp b/src/map/atcommand.cpp index 853d8b4..fa3d23d 100644 --- a/src/map/atcommand.cpp +++ b/src/map/atcommand.cpp @@ -8,7 +8,6 @@ #include #include -#include // exception to "no va_list" rule #include #include #include @@ -17,6 +16,7 @@ #include #include "../common/core.hpp" +#include "../common/cxxstdio.hpp" #include "../common/mt_rand.hpp" #include "../common/nullpo.hpp" #include "../common/socket.hpp" @@ -76,7 +76,6 @@ ATCOMMAND_FUNC(gm); ATCOMMAND_FUNC(pvpoff); ATCOMMAND_FUNC(pvpon); ATCOMMAND_FUNC(model); -ATCOMMAND_FUNC(go); ATCOMMAND_FUNC(spawn); ATCOMMAND_FUNC(killmonster); ATCOMMAND_FUNC(killmonster2); @@ -243,7 +242,6 @@ AtCommandInfo atcommand_info[] = { {AtCommand_PvPOff, "@pvpoff", 40, atcommand_pvpoff}, {AtCommand_PvPOn, "@pvpon", 40, atcommand_pvpon}, {AtCommand_Model, "@model", 20, atcommand_model}, - {AtCommand_Go, "@go", 10, atcommand_go}, {AtCommand_Spawn, "@spawn", 50, atcommand_spawn}, {AtCommand_KillMonster, "@killmonster", 60, atcommand_killmonster}, {AtCommand_KillMonster2, "@killmonster2", 40, atcommand_killmonster2}, @@ -556,22 +554,24 @@ int get_atcommand_level(const AtCommandType type) return 100; // 100: command can not be used } -// TODO: remove the hard limit of 512 +static +FILE *get_gm_log(); /*======================================== * At-command logging */ -void log_atcommand(struct map_session_data *sd, const char *fmt, ...) +void log_atcommand(struct map_session_data *sd, const_string cmd) { - char message[512]; - va_list ap; - - va_start(ap, fmt); - vsnprintf(message, 511, fmt, ap); - va_end(ap); - - gm_log("%s(%d,%d) %s(%d) : %s", map[sd->bl.m].name, sd->bl.x, - sd->bl.y, sd->status.name, sd->status.account_id, message); + FILE *fp = get_gm_log(); + if (!fp) + return; + timestamp_seconds_buffer tmpstr; + stamp_time(tmpstr); + fprintf(fp, "[%s] %s(%d,%d) %s(%d) : ", + tmpstr, + map[sd->bl.m].name, sd->bl.x, sd->bl.y, + sd->status.name, sd->status.account_id); + fwrite(cmd.data(), 1, cmd.size(), fp); } char *gm_logfile_name = NULL; @@ -579,54 +579,38 @@ char *gm_logfile_name = NULL; * Log a timestamped line to GM log file *------------------------------------------ */ -void gm_log(const char *fmt, ...) +FILE *get_gm_log() { - static int last_logfile_nr = 0; - static FILE *gm_logfile = NULL; - time_t time_v; - struct tm ctime; - int month, year, logfile_nr; - char message[512]; - va_list ap; - if (!gm_logfile_name) - return; + return NULL; - va_start(ap, fmt); - vsnprintf(message, 511, fmt, ap); - va_end(ap); + time_t ts = time(NULL); + struct tm ctime = *gmtime(&ts); - time(&time_v); - gmtime_r(&time_v, &ctime); + int year = ctime.tm_year + 1900; + int month = ctime.tm_mon + 1; + int logfile_nr = (year * 12) + month; - year = ctime.tm_year + 1900; - month = ctime.tm_mon + 1; - logfile_nr = (year * 12) + month; + static FILE *gm_logfile = NULL; + static int last_logfile_nr = 0; + if (logfile_nr == last_logfile_nr) + return gm_logfile; + last_logfile_nr = logfile_nr; - if (logfile_nr != last_logfile_nr) - { - char *fullname = (char *)malloc(strlen(gm_logfile_name) + 10); - sprintf(fullname, "%s.%04d-%02d", gm_logfile_name, year, month); + std::string fullname = STRPRINTF("%s.%04d-%02d", + gm_logfile_name, year, month); - if (gm_logfile) - fclose_(gm_logfile); + if (gm_logfile) + fclose_(gm_logfile); - gm_logfile = fopen_(fullname, "a"); - free(fullname); + gm_logfile = fopen_(fullname.c_str(), "a"); - if (!gm_logfile) - { - perror("GM log file"); - gm_logfile_name = NULL; - } - last_logfile_nr = logfile_nr; + if (!gm_logfile) + { + perror("GM log file"); + gm_logfile_name = NULL; } - - fprintf(gm_logfile, "[%04d-%02d-%02d %02d:%02d:%02d] %s\n", - year, month, ctime.tm_mday, ctime.tm_hour, - ctime.tm_min, ctime.tm_sec, message); - - fflush(gm_logfile); + return gm_logfile; } static @@ -636,16 +620,16 @@ AtCommandType atcommand(const int level, const char *message, *is_atcommand @コマンドに存在するかどうか確認する *------------------------------------------ */ -AtCommandType is_atcommand(const int fd, struct map_session_data *sd, const char *message, - int gmlvl) +bool is_atcommand(const int fd, struct map_session_data *sd, + const char *message, int gmlvl) { AtCommandInfo info; AtCommandType type; - nullpo_retr(AtCommand_None, sd); + nullpo_retr(false, sd); if (!message || !*message) - return AtCommand_None; + return false; memset(&info, 0, sizeof(info)); @@ -653,22 +637,21 @@ AtCommandType is_atcommand(const int fd, struct map_session_data *sd, const char if (type != AtCommand_None) { char command[100]; - char output[200]; const char *str = message; const char *p = message; memset(command, '\0', sizeof(command)); - memset(output, '\0', sizeof(output)); while (*p && !isspace(*p)) p++; if (p - str >= sizeof(command)) // too long - return AtCommand_Unknown; + return true; strncpy(command, str, p - str); while (isspace(*p)) p++; if (type == AtCommand_Unknown || info.proc == NULL) { - sprintf(output, "%s is Unknown Command.", command); + std::string output = STRPRINTF("%s is Unknown Command.", + command); clif_displaymessage(fd, output); } else @@ -676,20 +659,20 @@ AtCommandType is_atcommand(const int fd, struct map_session_data *sd, const char if (info.proc(fd, sd, command, p) != 0) { // Command can not be executed - sprintf(output, "%s failed.", command); + std::string output = STRPRINTF("%s failed.", command); clif_displaymessage(fd, output); } else { if (get_atcommand_level(type) != 0) // Don't log level 0 commands - log_atcommand(sd, "%s %s", command, p); + log_atcommand(sd, message); } } - return info.type; + return true; } - return AtCommand_None; + return false; } /*========================================== @@ -707,7 +690,7 @@ AtCommandType atcommand(const int level, const char *message, return AtCommand_None; if (!p || !*p) { - fprintf(stderr, "at command message is empty\n"); + FPRINTF(stderr, "at command message is empty\n"); return AtCommand_None; } @@ -792,7 +775,7 @@ int atcommand_config_read(const char *cfgName) if ((fp = fopen_(cfgName, "r")) == NULL) { - printf("At commands configuration file not found: %s\n", cfgName); + PRINTF("At commands configuration file not found: %s\n", cfgName); return 1; } @@ -837,7 +820,6 @@ int atcommand_config_read(const char *cfgName) int atcommand_setup(const int fd, struct map_session_data *sd, const char *, const char *message) { - char buf[256]; char character[100]; int level = 1; @@ -851,26 +833,27 @@ int atcommand_setup(const int fd, struct map_session_data *sd, } level--; - snprintf(buf, 255, "-255 %s", character); - atcommand_character_baselevel(fd, sd, "@charbaselvl", buf); + std::string buf; + buf = STRPRINTF("-255 %s", character); + atcommand_character_baselevel(fd, sd, "@charbaselvl", buf.c_str()); - snprintf(buf, 255, "%d %s", level, character); - atcommand_character_baselevel(fd, sd, "@charbaselvl", buf); + buf = STRPRINTF("%d %s", level, character); + atcommand_character_baselevel(fd, sd, "@charbaselvl", buf.c_str()); // Emote skill - snprintf(buf, 255, "1 1 %s", character); - atcommand_skill_learn(fd, sd, "@skill-learn", buf); + buf = STRPRINTF("1 1 %s", character); + atcommand_skill_learn(fd, sd, "@skill-learn", buf.c_str()); // Trade skill - snprintf(buf, 255, "2 1 %s", character); - atcommand_skill_learn(fd, sd, "@skill-learn", buf); + buf = STRPRINTF("2 1 %s", character); + atcommand_skill_learn(fd, sd, "@skill-learn", buf.c_str()); // Party skill - snprintf(buf, 255, "2 2 %s", character); - atcommand_skill_learn(fd, sd, "@skill-learn", buf); + STRPRINTF("2 2 %s", character); + atcommand_skill_learn(fd, sd, "@skill-learn", buf.c_str()); - snprintf(buf, 255, "018-1.gat 24 98 %s", character); - atcommand_charwarp(fd, sd, "@charwarp", buf); + STRPRINTF("018-1.gat 24 98 %s", character); + atcommand_charwarp(fd, sd, "@charwarp", buf.c_str()); return (0); @@ -1032,11 +1015,9 @@ int atcommand_where(const int fd, struct map_session_data *sd, const char *, const char *message) { char character[100]; - char output[200]; struct map_session_data *pl_sd; memset(character, '\0', sizeof(character)); - memset(output, '\0', sizeof(output)); if (sscanf(message, "%99[^\n]", character) < 1) strcpy(character, sd->status.name); @@ -1046,8 +1027,9 @@ int atcommand_where(const int fd, struct map_session_data *sd, || bool(pl_sd->status.option & Option::HIDE)) && (pc_isGM(pl_sd) > pc_isGM(sd)))) { // you can look only lower or same level - sprintf(output, "%s: %s (%d,%d)", pl_sd->status.name, pl_sd->mapname, - pl_sd->bl.x, pl_sd->bl.y); + std::string 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); } else @@ -1067,11 +1049,9 @@ int atcommand_goto(const int fd, struct map_session_data *sd, const char *, const char *message) { char character[100]; - char output[200]; struct map_session_data *pl_sd; memset(character, '\0', sizeof(character)); - memset(output, '\0', sizeof(output)); if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1) { @@ -1097,7 +1077,7 @@ int atcommand_goto(const int fd, struct map_session_data *sd, return -1; } pc_setpos(sd, pl_sd->mapname, pl_sd->bl.x, pl_sd->bl.y, 3); - sprintf(output, "Jump to %s", character); + std::string output = STRPRINTF("Jump to %s", character); clif_displaymessage(fd, output); } else @@ -1116,11 +1096,7 @@ int atcommand_goto(const int fd, struct map_session_data *sd, int atcommand_jump(const int fd, struct map_session_data *sd, const char *, const char *message) { - char output[200]; int x = 0, y = 0; - - memset(output, '\0', sizeof(output)); - sscanf(message, "%d %d", &x, &y); if (x <= 0) @@ -1144,7 +1120,7 @@ int atcommand_jump(const int fd, struct map_session_data *sd, return -1; } pc_setpos(sd, sd->mapname, x, y, 3); - sprintf(output, "Jump to %d %d", x, y); + std::string output = STRPRINTF("Jump to %d %d", x, y); clif_displaymessage(fd, output); } else @@ -1163,14 +1139,12 @@ int atcommand_jump(const int fd, struct map_session_data *sd, int atcommand_who(const int fd, struct map_session_data *sd, const char *, const char *message) { - char output[200]; struct map_session_data *pl_sd; int i, j, count; int pl_GM_level, GM_level; char match_text[100]; char player_name[24]; - memset(output, '\0', sizeof(output)); memset(match_text, '\0', sizeof(match_text)); memset(player_name, '\0', sizeof(player_name)); @@ -1196,16 +1170,19 @@ int atcommand_who(const int fd, struct map_session_data *sd, for (j = 0; player_name[j]; j++) player_name[j] = tolower(player_name[j]); if (strstr(player_name, match_text) != NULL) - { // search with no case sensitive + { + // search with no case sensitive + std::string output; if (pl_GM_level > 0) - sprintf(output, - "Name: %s (GM:%d) | Location: %s %d %d", - pl_sd->status.name, pl_GM_level, - pl_sd->mapname, pl_sd->bl.x, pl_sd->bl.y); + output = STRPRINTF( + "Name: %s (GM:%d) | Location: %s %d %d", + pl_sd->status.name, pl_GM_level, + pl_sd->mapname, pl_sd->bl.x, pl_sd->bl.y); else - sprintf(output, "Name: %s | Location: %s %d %d", - pl_sd->status.name, pl_sd->mapname, - pl_sd->bl.x, pl_sd->bl.y); + output = STRPRINTF( + "Name: %s | Location: %s %d %d", + pl_sd->status.name, pl_sd->mapname, + pl_sd->bl.x, pl_sd->bl.y); clif_displaymessage(fd, output); count++; } @@ -1219,7 +1196,7 @@ int atcommand_who(const int fd, struct map_session_data *sd, clif_displaymessage(fd, "1 player found."); else { - sprintf(output, "%d players found.", count); + std::string output = STRPRINTF("%d players found.", count); clif_displaymessage(fd, output); } @@ -1233,9 +1210,6 @@ int atcommand_who(const int fd, struct map_session_data *sd, int atcommand_whogroup(const int fd, struct map_session_data *sd, const char *, const char *message) { - char temp0[100]; - char temp1[100]; - char output[200]; struct map_session_data *pl_sd; int i, j, count; int pl_GM_level, GM_level; @@ -1243,9 +1217,6 @@ int atcommand_whogroup(const int fd, struct map_session_data *sd, char player_name[24]; struct party *p; - memset(temp0, '\0', sizeof(temp0)); - memset(temp1, '\0', sizeof(temp1)); - memset(output, '\0', sizeof(output)); memset(match_text, '\0', sizeof(match_text)); memset(player_name, '\0', sizeof(player_name)); @@ -1273,18 +1244,12 @@ int atcommand_whogroup(const int fd, struct map_session_data *sd, if (strstr(player_name, match_text) != NULL) { // search with no case sensitive p = party_search(pl_sd->status.party_id); - if (p == NULL) - sprintf(temp0, "None"); - else - sprintf(temp0, "%s", p->name); + const char *temp0 = p ? p->name : "None"; + std::string output; if (pl_GM_level > 0) - sprintf(output, - "Name: %s (GM:%d) | Party: '%s'", - pl_sd->status.name, pl_GM_level, temp0); - else - sprintf(output, - "Name: %s | Party: '%s' | Guild: '%s'", - pl_sd->status.name, temp0, temp1); + output = STRPRINTF( + "Name: %s (GM:%d) | Party: '%s'", + pl_sd->status.name, pl_GM_level, temp0); clif_displaymessage(fd, output); count++; } @@ -1298,7 +1263,7 @@ int atcommand_whogroup(const int fd, struct map_session_data *sd, clif_displaymessage(fd, "1 player found."); else { - sprintf(output, "%d players found.", count); + std::string output = STRPRINTF("%d players found.", count); clif_displaymessage(fd, output); } @@ -1312,14 +1277,12 @@ int atcommand_whogroup(const int fd, struct map_session_data *sd, int atcommand_whomap(const int fd, struct map_session_data *sd, const char *, const char *message) { - char output[200]; struct map_session_data *pl_sd; int i, count; int pl_GM_level, GM_level; int map_id; char map_name[100]; - memset(output, '\0', sizeof(output)); memset(map_name, '\0', sizeof(map_name)); if (!message || !*message) @@ -1348,15 +1311,17 @@ int atcommand_whomap(const int fd, struct map_session_data *sd, { // you can look only lower or same level if (pl_sd->bl.m == map_id) { + std::string output; if (pl_GM_level > 0) - sprintf(output, - "Name: %s (GM:%d) | Location: %s %d %d", - pl_sd->status.name, pl_GM_level, - pl_sd->mapname, pl_sd->bl.x, pl_sd->bl.y); + output = STRPRINTF( + "Name: %s (GM:%d) | Location: %s %d %d", + pl_sd->status.name, pl_GM_level, + pl_sd->mapname, pl_sd->bl.x, pl_sd->bl.y); else - sprintf(output, "Name: %s | Location: %s %d %d", - pl_sd->status.name, pl_sd->mapname, - pl_sd->bl.x, pl_sd->bl.y); + output = STRPRINTF( + "Name: %s | Location: %s %d %d", + pl_sd->status.name, pl_sd->mapname, + pl_sd->bl.x, pl_sd->bl.y); clif_displaymessage(fd, output); count++; } @@ -1364,14 +1329,8 @@ int atcommand_whomap(const int fd, struct map_session_data *sd, } } - if (count == 0) - sprintf(output, "No player found in map '%s'.", map[map_id].name); - else if (count == 1) - sprintf(output, "1 player found in map '%s'.", map[map_id].name); - else - { - sprintf(output, "%d players found in map '%s'.", count, map[map_id].name); - } + std::string output = STRPRINTF("%d players found in map '%s'.", + count, map[map_id].name); clif_displaymessage(fd, output); return 0; @@ -1384,8 +1343,6 @@ int atcommand_whomap(const int fd, struct map_session_data *sd, int atcommand_whomapgroup(const int fd, struct map_session_data *sd, const char *, const char *message) { - char temp0[100]; - char output[200]; struct map_session_data *pl_sd; int i, count; int pl_GM_level, GM_level; @@ -1393,8 +1350,6 @@ int atcommand_whomapgroup(const int fd, struct map_session_data *sd, char map_name[100]; struct party *p; - memset(temp0, '\0', sizeof(temp0)); - memset(output, '\0', sizeof(output)); memset(map_name, '\0', sizeof(map_name)); if (!message || !*message) @@ -1425,18 +1380,14 @@ int atcommand_whomapgroup(const int fd, struct map_session_data *sd, if (pl_sd->bl.m == map_id) { p = party_search(pl_sd->status.party_id); - if (p == NULL) - sprintf(temp0, "None"); - else - sprintf(temp0, "%s", p->name); + const char *temp0 = p ? p->name : "None"; + std::string output; if (pl_GM_level > 0) - sprintf(output, - "Name: %s (GM:%d) | Party: '%s'", - pl_sd->status.name, pl_GM_level, temp0); + output = STRPRINTF("Name: %s (GM:%d) | Party: '%s'", + pl_sd->status.name, pl_GM_level, temp0); else - sprintf(output, - "Name: %s | Party: '%s'", - pl_sd->status.name, temp0); + output = STRPRINTF("Name: %s | Party: '%s'", + pl_sd->status.name, temp0); clif_displaymessage(fd, output); count++; } @@ -1444,13 +1395,14 @@ int atcommand_whomapgroup(const int fd, struct map_session_data *sd, } } + std::string output; if (count == 0) - sprintf(output, "No player found in map '%s'.", map[map_id].name); + output = STRPRINTF("No player found in map '%s'.", map[map_id].name); else if (count == 1) - sprintf(output, "1 player found in map '%s'.", map[map_id].name); + output = STRPRINTF("1 player found in map '%s'.", map[map_id].name); else { - sprintf(output, "%d players found in map '%s'.", count, map[map_id].name); + output = STRPRINTF("%d players found in map '%s'.", count, map[map_id].name); } clif_displaymessage(fd, output); @@ -1464,8 +1416,6 @@ int atcommand_whomapgroup(const int fd, struct map_session_data *sd, int atcommand_whogm(const int fd, struct map_session_data *sd, const char *, const char *message) { - char temp0[100]; - char output[200]; struct map_session_data *pl_sd; int i, j, count; int pl_GM_level, GM_level; @@ -1473,8 +1423,6 @@ int atcommand_whogm(const int fd, struct map_session_data *sd, char player_name[24]; struct party *p; - memset(temp0, '\0', sizeof(temp0)); - memset(output, '\0', sizeof(output)); memset(match_text, '\0', sizeof(match_text)); memset(player_name, '\0', sizeof(player_name)); @@ -1497,30 +1445,31 @@ int atcommand_whogm(const int fd, struct map_session_data *sd, ((battle_config.hide_GM_session || bool(pl_sd->status.option & Option::HIDE)) && (pl_GM_level > GM_level))) - { // you can look only lower or same level + { + // you can look only lower or same level memcpy(player_name, pl_sd->status.name, 24); for (j = 0; player_name[j]; j++) player_name[j] = tolower(player_name[j]); if (strstr(player_name, match_text) != NULL) - { // search with no case sensitive - sprintf(output, - "Name: %s (GM:%d) | Location: %s %d %d", - pl_sd->status.name, pl_GM_level, - pl_sd->mapname, pl_sd->bl.x, pl_sd->bl.y); + { + // search with no case sensitive + std::string output; + output = STRPRINTF( + "Name: %s (GM:%d) | Location: %s %d %d", + pl_sd->status.name, pl_GM_level, + pl_sd->mapname, pl_sd->bl.x, pl_sd->bl.y); clif_displaymessage(fd, output); - sprintf(output, - " BLvl: %d | Job: %s (Lvl: %d)", - pl_sd->status.base_level, - job_name(pl_sd->status.pc_class), - pl_sd->status.job_level); + output = STRPRINTF( + " BLvl: %d | Job: %s (Lvl: %d)", + pl_sd->status.base_level, + job_name(pl_sd->status.pc_class), + pl_sd->status.job_level); clif_displaymessage(fd, output); p = party_search(pl_sd->status.party_id); - if (p == NULL) - sprintf(temp0, "None"); - else - sprintf(temp0, "%s", p->name); - sprintf(output, " Party: '%s'", - temp0); + const char *temp0 = p ? p->name : "None"; + output = STRPRINTF( + " Party: '%s'", + temp0); clif_displaymessage(fd, output); count++; } @@ -1535,7 +1484,7 @@ int atcommand_whogm(const int fd, struct map_session_data *sd, clif_displaymessage(fd, "1 GM found."); else { - sprintf(output, "%d GMs found.", count); + std::string output = STRPRINTF("%d GMs found.", count); clif_displaymessage(fd, output); } @@ -1598,21 +1547,16 @@ int atcommand_load(const int fd, struct map_session_data *sd, int atcommand_speed(const int fd, struct map_session_data *sd, const char *, const char *message) { - char output[200]; - int speed; - - memset(output, '\0', sizeof(output)); - if (!message || !*message) { - sprintf(output, - "Please, enter a speed value (usage: @speed <%d-%d>).", - MIN_WALK_SPEED, MAX_WALK_SPEED); + std::string output = STRPRINTF( + "Please, enter a speed value (usage: @speed <%d-%d>).", + MIN_WALK_SPEED, MAX_WALK_SPEED); clif_displaymessage(fd, output); return -1; } - speed = atoi(message); + int speed = atoi(message); if (speed >= MIN_WALK_SPEED && speed <= MAX_WALK_SPEED) { sd->speed = speed; @@ -1623,9 +1567,9 @@ int atcommand_speed(const int fd, struct map_session_data *sd, } else { - sprintf(output, - "Please, enter a valid speed value (usage: @speed <%d-%d>).", - MIN_WALK_SPEED, MAX_WALK_SPEED); + std::string output = STRPRINTF( + "Please, enter a valid speed value (usage: @speed <%d-%d>).", + MIN_WALK_SPEED, MAX_WALK_SPEED); clif_displaymessage(fd, output); return -1; } @@ -1837,10 +1781,6 @@ int atcommand_alive(const int fd, struct map_session_data *sd, int atcommand_kami(const int fd, struct map_session_data *, const char *, const char *message) { - char output[200]; - - memset(output, '\0', sizeof(output)); - if (!message || !*message) { clif_displaymessage(fd, @@ -1848,8 +1788,7 @@ int atcommand_kami(const int fd, struct map_session_data *, return -1; } - sscanf(message, "%199[^\n]", output); - intif_GMmessage(output, strlen(output) + 1, 0); + intif_GMmessage(message, 0); return 0; } @@ -2302,18 +2241,16 @@ int atcommand_model(const int fd, struct map_session_data *sd, const char *, const char *message) { int hair_style = 0, hair_color = 0, cloth_color = 0; - char output[200]; - - memset(output, '\0', sizeof(output)); if (!message || !*message || sscanf(message, "%d %d %d", &hair_style, &hair_color, &cloth_color) < 1) { - sprintf(output, - "Please, enter at least a value (usage: @model ).", - MIN_HAIR_STYLE, MAX_HAIR_STYLE, MIN_HAIR_COLOR, - MAX_HAIR_COLOR, MIN_CLOTH_COLOR, MAX_CLOTH_COLOR); + std::string output = STRPRINTF( + "Please, enter at least a value (usage: @model ).", + MIN_HAIR_STYLE, MAX_HAIR_STYLE, + MIN_HAIR_COLOR, MAX_HAIR_COLOR, + MIN_CLOTH_COLOR, MAX_CLOTH_COLOR); clif_displaymessage(fd, output); return -1; } @@ -2355,15 +2292,12 @@ int atcommand_dye(const int fd, struct map_session_data *sd, const char *, const char *message) { int cloth_color = 0; - char output[200]; - - memset(output, '\0', sizeof(output)); if (!message || !*message || sscanf(message, "%d", &cloth_color) < 1) { - sprintf(output, - "Please, enter a clothes color (usage: @dye/@ccolor ).", - MIN_CLOTH_COLOR, MAX_CLOTH_COLOR); + std::string output = STRPRINTF( + "Please, enter a clothes color (usage: @dye/@ccolor ).", + MIN_CLOTH_COLOR, MAX_CLOTH_COLOR); clif_displaymessage(fd, output); return -1; } @@ -2399,15 +2333,12 @@ int atcommand_hair_style(const int fd, struct map_session_data *sd, const char *, const char *message) { int hair_style = 0; - char output[200]; - - memset(output, '\0', sizeof(output)); if (!message || !*message || sscanf(message, "%d", &hair_style) < 1) { - sprintf(output, - "Please, enter a hair style (usage: @hairstyle/@hstyle ).", - MIN_HAIR_STYLE, MAX_HAIR_STYLE); + std::string output = STRPRINTF( + "Please, enter a hair style (usage: @hairstyle/@hstyle ).", + MIN_HAIR_STYLE, MAX_HAIR_STYLE); clif_displaymessage(fd, output); return -1; } @@ -2443,15 +2374,12 @@ int atcommand_hair_color(const int fd, struct map_session_data *sd, const char *, const char *message) { int hair_color = 0; - char output[200]; - - memset(output, '\0', sizeof(output)); if (!message || !*message || sscanf(message, "%d", &hair_color) < 1) { - sprintf(output, - "Please, enter a hair color (usage: @haircolor/@hcolor ).", - MIN_HAIR_COLOR, MAX_HAIR_COLOR); + std::string output = STRPRINTF( + "Please, enter a hair color (usage: @haircolor/@hcolor ).", + MIN_HAIR_COLOR, MAX_HAIR_COLOR); clif_displaymessage(fd, output); return -1; } @@ -2479,253 +2407,6 @@ int atcommand_hair_color(const int fd, struct map_session_data *sd, return 0; } -/*========================================== - * @go [city_number/city_name]: improved by [yor] to add city names and help - *------------------------------------------ - */ -int atcommand_go(const int fd, struct map_session_data *sd, - const char *, const char *message) -{ - int i; - int town; - char map_name[100]; - char output[200]; - int m; - - struct - { - char map[16]; - int x, y; - } data[] = - { - { - "prontera.gat", 156, 191}, // 0=Prontera - { - "morocc.gat", 156, 93}, // 1=Morroc - { - "geffen.gat", 119, 59}, // 2=Geffen - { - "payon.gat", 162, 233}, // 3=Payon - { - "alberta.gat", 192, 147}, // 4=Alberta - { - "izlude.gat", 128, 114}, // 5=Izlude - { - "aldebaran.gat", 140, 131}, // 6=Al de Baran - { - "xmas.gat", 147, 134}, // 7=Lutie - { - "comodo.gat", 209, 143}, // 8=Comodo - { - "yuno.gat", 157, 51}, // 9=Yuno - { - "amatsu.gat", 198, 84}, // 10=Amatsu - { - "gonryun.gat", 160, 120}, // 11=Gon Ryun - { - "umbala.gat", 89, 157}, // 12=Umbala - { - "niflheim.gat", 21, 153}, // 13=Niflheim - { - "louyang.gat", 217, 40}, // 14=Lou Yang - { - "new_1-1.gat", 53, 111}, // 15=Start point - { - "sec_pri.gat", 23, 61}, // 16=Prison - }; - - memset(map_name, '\0', sizeof(map_name)); - memset(output, '\0', sizeof(output)); - - // get the number - town = atoi(message); - - // if no value, display all value - if (!message || !*message || sscanf(message, "%99s", map_name) < 1 - || town < -3 || town >= (int)(sizeof(data) / sizeof(data[0]))) - { - clif_displaymessage(fd, "Invalid location number or name."); - clif_displaymessage(fd, "Please, use one of this number/name:"); - clif_displaymessage(fd, - "-3=(Memo point 2) 4=Alberta 11=Gon Ryun"); - clif_displaymessage(fd, - "-2=(Memo point 1) 5=Izlude 12=Umbala"); - clif_displaymessage(fd, - "-1=(Memo point 0) 6=Al de Baran 13=Niflheim"); - clif_displaymessage(fd, - " 0=Prontera 7=Lutie 14=Lou Yang"); - clif_displaymessage(fd, - " 1=Morroc 8=Comodo 15=Start point"); - clif_displaymessage(fd, - " 2=Geffen 9=Yuno 16=Prison"); - clif_displaymessage(fd, " 3=Payon 10=Amatsu"); - return -1; - } - else - { - // get possible name of the city and add .gat if not in the name - map_name[sizeof(map_name) - 1] = '\0'; - for (i = 0; map_name[i]; i++) - map_name[i] = tolower(map_name[i]); - if (strstr(map_name, ".gat") == NULL && strstr(map_name, ".afm") == NULL && strlen(map_name) < 13) // 16 - 4 (.gat) - strcat(map_name, ".gat"); - // try to see if it's a name, and not a number (try a lot of possibilities, write errors and abbreviations too) - if (strncmp(map_name, "prontera.gat", 3) == 0) - { // 3 first characters - town = 0; - } - else if (strncmp(map_name, "morocc.gat", 3) == 0) - { // 3 first characters - town = 1; - } - else if (strncmp(map_name, "geffen.gat", 3) == 0) - { // 3 first characters - town = 2; - } - else if (strncmp(map_name, "payon.gat", 3) == 0 || // 3 first characters - strncmp(map_name, "paion.gat", 3) == 0) - { // writing error (3 first characters) - town = 3; - } - else if (strncmp(map_name, "alberta.gat", 3) == 0) - { // 3 first characters - town = 4; - } - else if (strncmp(map_name, "izlude.gat", 3) == 0 || // 3 first characters - strncmp(map_name, "islude.gat", 3) == 0) - { // writing error (3 first characters) - town = 5; - } - else if (strncmp(map_name, "aldebaran.gat", 3) == 0 || // 3 first characters - strcmp(map_name, "al.gat") == 0) - { // al (de baran) - town = 6; - } - else if (strncmp(map_name, "lutie.gat", 3) == 0 || // name of the city, not name of the map (3 first characters) - strcmp(map_name, "christmas.gat") == 0 || // name of the symbol - strncmp(map_name, "xmas.gat", 3) == 0 || // 3 first characters - strncmp(map_name, "x-mas.gat", 3) == 0) - { // writing error (3 first characters) - town = 7; - } - else if (strncmp(map_name, "comodo.gat", 3) == 0) - { // 3 first characters - town = 8; - } - else if (strncmp(map_name, "yuno.gat", 3) == 0) - { // 3 first characters - town = 9; - } - else if (strncmp(map_name, "amatsu.gat", 3) == 0 || // 3 first characters - strncmp(map_name, "ammatsu.gat", 3) == 0) - { // writing error (3 first characters) - town = 10; - } - else if (strncmp(map_name, "gonryun.gat", 3) == 0) - { // 3 first characters - town = 11; - } - else if (strncmp(map_name, "umbala.gat", 3) == 0) - { // 3 first characters - town = 12; - } - else if (strncmp(map_name, "niflheim.gat", 3) == 0) - { // 3 first characters - town = 13; - } - else if (strncmp(map_name, "louyang.gat", 3) == 0) - { // 3 first characters - town = 14; - } - else if (strncmp(map_name, "new_1-1.gat", 3) == 0 || // 3 first characters (or "newbies") - strncmp(map_name, "startpoint.gat", 3) == 0 || // name of the position (3 first characters) - strncmp(map_name, "begining.gat", 3) == 0) - { // name of the position (3 first characters) - town = 15; - } - else if (strncmp(map_name, "sec_pri.gat", 3) == 0 || // 3 first characters - strncmp(map_name, "prison.gat", 3) == 0 || // name of the position (3 first characters) - strncmp(map_name, "jails.gat", 3) == 0) - { // name of the position - town = 16; - } - - if (town >= -3 && town <= -1) - { - if (sd->status.memo_point[-town - 1].map[0]) - { - m = map_mapname2mapid(sd->status.memo_point[-town - 1].map); - if (m >= 0 && map[m].flag.nowarpto - && battle_config.any_warp_GM_min_level > pc_isGM(sd)) - { - clif_displaymessage(fd, - "You are not authorised to warp you to this memo map."); - return -1; - } - if (sd->bl.m >= 0 && map[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."); - return -1; - } - if (pc_setpos(sd, sd->status.memo_point[-town - 1].map, - sd->status.memo_point[-town - 1].x, - sd->status.memo_point[-town - 1].y, 3) == 0) - { - clif_displaymessage(fd, "Warped."); - } - else - { - clif_displaymessage(fd, "Map not found."); - return -1; - } - } - else - { - sprintf(output, "Your memo point #%d doesn't exist.", -town - 1); - clif_displaymessage(fd, output); - return -1; - } - } - else if (town >= 0 && town < (int)(sizeof(data) / sizeof(data[0]))) - { - m = map_mapname2mapid(data[town].map); - if (m >= 0 && map[m].flag.nowarpto - && battle_config.any_warp_GM_min_level > pc_isGM(sd)) - { - clif_displaymessage(fd, - "You are not authorised to warp you to this destination map."); - return -1; - } - if (sd->bl.m >= 0 && map[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."); - return -1; - } - if (pc_setpos(sd, data[town].map, data[town].x, data[town].y, 3) - == 0) - { - clif_displaymessage(fd, "Warped."); - } - else - { - clif_displaymessage(fd, "Map not found."); - return -1; - } - } - else - { // if you arrive here, you have an error in town variable when reading of names - clif_displaymessage(fd, "Invalid location number or name."); - return -1; - } - } - - return 0; -} - /*========================================== * *------------------------------------------ @@ -2734,7 +2415,6 @@ int atcommand_spawn(const int fd, struct map_session_data *sd, const char *command, const char *message) { char monster[100]; - char output[200]; int mob_id; int number = 0; int x = 0, y = 0; @@ -2743,7 +2423,6 @@ int atcommand_spawn(const int fd, struct map_session_data *sd, int mx, my, range; memset(monster, '\0', sizeof(monster)); - memset(output, '\0', sizeof(output)); if (!message || !*message || sscanf(message, "%99s %d %d %d", monster, &number, &x, &y) < 1) @@ -2777,7 +2456,7 @@ int atcommand_spawn(const int fd, struct map_session_data *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, + PRINTF("%s monster='%s' id=%d count=%d (%d,%d)\n", command, monster, mob_id, number, x, y); count = 0; @@ -2808,7 +2487,8 @@ int atcommand_spawn(const int fd, struct map_session_data *sd, clif_displaymessage(fd, "All monster summoned!"); else { - sprintf(output, "%d monster(s) summoned!", count); + std::string output = STRPRINTF("%d monster(s) summoned!", + count); clif_displaymessage(fd, output); } else @@ -2870,10 +2550,10 @@ int atcommand_killmonster(const int fd, struct map_session_data *sd, static void atlist_nearby_sub(struct block_list *bl, int fd) { - char buf[32]; nullpo_retv(bl); - sprintf(buf, " - \"%s\"", ((struct map_session_data *) bl)->status.name); + std::string buf = STRPRINTF(" - \"%s\"", + ((struct map_session_data *) bl)->status.name); clif_displaymessage(fd, buf); } @@ -2915,9 +2595,7 @@ int atcommand_produce(const int fd, struct map_session_data *sd, int item_id, attribute = 0, star = 0; struct item_data *item_data; struct item tmp_item; - char output[200]; - memset(output, '\0', sizeof(output)); memset(item_name, '\0', sizeof(item_name)); if (!message || !*message @@ -2957,11 +2635,12 @@ int atcommand_produce(const int fd, struct map_session_data *sd, else { if (battle_config.error_log) - printf("@produce NOT WEAPON [%d]\n", item_id); + PRINTF("@produce NOT WEAPON [%d]\n", item_id); + std::string output; if (item_id != 0 && itemdb_exists(item_id)) - sprintf(output, "This item (%d: '%s') is not an equipment.", item_id, item_data->name); + output = STRPRINTF("This item (%d: '%s') is not an equipment.", item_id, item_data->name); else - sprintf(output, "%s", "This item is not an equipment."); + output = STRPRINTF("%s", "This item is not an equipment."); clif_displaymessage(fd, output); return -1; } @@ -2976,21 +2655,19 @@ int atcommand_produce(const int fd, struct map_session_data *sd, static void atcommand_memo_sub(struct map_session_data *sd) { - int i; - char output[200]; - - memset(output, '\0', sizeof(output)); - clif_displaymessage(sd->fd, "Your actual memo positions are (except respawn point):"); - for (i = MIN_PORTAL_MEMO; i <= MAX_PORTAL_MEMO; i++) + for (int i = MIN_PORTAL_MEMO; i <= MAX_PORTAL_MEMO; i++) { + std::string output; if (sd->status.memo_point[i].map[0]) - sprintf(output, "%d - %s (%d,%d)", i, - sd->status.memo_point[i].map, sd->status.memo_point[i].x, - sd->status.memo_point[i].y); + output = STRPRINTF("%d - %s (%d,%d)", + i, + sd->status.memo_point[i].map, + sd->status.memo_point[i].x, + sd->status.memo_point[i].y); else - sprintf(output, "%d - void", i); + output = STRPRINTF("%d - void", i); clif_displaymessage(sd->fd, output); } @@ -3005,9 +2682,6 @@ int atcommand_memo(const int fd, struct map_session_data *sd, const char *, const char *message) { int position = 0; - char output[200]; - - memset(output, '\0', sizeof(output)); if (!message || !*message || sscanf(message, "%d", &position) < 1) atcommand_memo_sub(sd); @@ -3024,7 +2698,12 @@ int atcommand_memo(const int fd, struct map_session_data *sd, } if (sd->status.memo_point[position].map[0]) { - sprintf(output, "You replace previous memo position %d - %s (%d,%d).", position, sd->status.memo_point[position].map, sd->status.memo_point[position].x, sd->status.memo_point[position].y); + std::string output = STRPRINTF( + "You replace previous memo position %d - %s (%d,%d).", + position, + sd->status.memo_point[position].map, + sd->status.memo_point[position].x, + sd->status.memo_point[position].y); clif_displaymessage(fd, output); } memcpy(sd->status.memo_point[position].map, map[sd->bl.m].name, @@ -3037,9 +2716,9 @@ int atcommand_memo(const int fd, struct map_session_data *sd, } else { - sprintf(output, - "Please, enter a valid position (usage: @memo ).", - MIN_PORTAL_MEMO, MAX_PORTAL_MEMO); + std::string output = STRPRINTF( + "Please, enter a valid position (usage: @memo ).", + MIN_PORTAL_MEMO, MAX_PORTAL_MEMO); clif_displaymessage(fd, output); atcommand_memo_sub(sd); return -1; @@ -3056,20 +2735,18 @@ int atcommand_memo(const int fd, struct map_session_data *sd, int atcommand_gat(const int fd, struct map_session_data *sd, const char *, const char *) { - char output[200]; int y; - memset(output, '\0', sizeof(output)); - for (y = 2; y >= -2; y--) { - sprintf(output, "%s (x= %d, y= %d) %02X %02X %02X %02X %02X", - map[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), - map_getcell(sd->bl.m, sd->bl.x - 1, sd->bl.y + y), - map_getcell(sd->bl.m, sd->bl.x, sd->bl.y + y), - map_getcell(sd->bl.m, sd->bl.x + 1, sd->bl.y + y), - map_getcell(sd->bl.m, sd->bl.x + 2, sd->bl.y + y)); + std::string output = STRPRINTF( + "%s (x= %d, y= %d) %02X %02X %02X %02X %02X", + map[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), + map_getcell(sd->bl.m, sd->bl.x - 1, sd->bl.y + y), + map_getcell(sd->bl.m, sd->bl.x, sd->bl.y + y), + map_getcell(sd->bl.m, sd->bl.x + 1, sd->bl.y + y), + map_getcell(sd->bl.m, sd->bl.x + 2, sd->bl.y + y)); clif_displaymessage(fd, output); } @@ -3226,16 +2903,15 @@ int atcommand_param(const int fd, struct map_session_data *sd, const char *, const char *message) { int value = 0, new_value; - char output[200]; - - memset(output, '\0', sizeof(output)); if (!message || !*message || sscanf(message, "%d", &value) < 1 || value == 0) { - sprintf(output, - "Please, enter a valid value (usage: @str,@agi,@vit,@int,@dex,@luk <+/-adjustement>)."); - clif_displaymessage(fd, output); + + // there was a clang bug here + // fortunately, STRPRINTF was not actually needed + clif_displaymessage(fd, + "Please, enter a valid value (usage: @str,@agi,@vit,@int,@dex,@luk <+/-adjustement>)."); return -1; } @@ -3320,11 +2996,9 @@ int atcommand_recall(const int fd, struct map_session_data *sd, const char *, const char *message) { char character[100]; - char output[200]; struct map_session_data *pl_sd; memset(character, '\0', sizeof(character)); - memset(output, '\0', sizeof(output)); if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1) { @@ -3352,7 +3026,7 @@ int atcommand_recall(const int fd, struct map_session_data *sd, return -1; } pc_setpos(pl_sd, sd->mapname, sd->bl.x, sd->bl.y, 2); - sprintf(output, "%s recalled!", character); + std::string output = STRPRINTF("%s recalled!", character); clif_displaymessage(fd, output); } else @@ -3417,11 +3091,9 @@ int atcommand_character_stats(const int fd, struct map_session_data *, const char *, const char *message) { char character[100]; - char output[200]; struct map_session_data *pl_sd; memset(character, '\0', sizeof(character)); - memset(output, '\0', sizeof(output)); if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1) { @@ -3432,34 +3104,35 @@ int atcommand_character_stats(const int fd, struct map_session_data *, if ((pl_sd = map_nick2sd(character)) != NULL) { - sprintf(output, "'%s' stats:", pl_sd->status.name); + std::string output; + output = STRPRINTF("'%s' stats:", pl_sd->status.name); clif_displaymessage(fd, output); - sprintf(output, "Base Level - %d", pl_sd->status.base_level), + output = STRPRINTF("Base Level - %d", pl_sd->status.base_level), clif_displaymessage(fd, output); - sprintf(output, "Job - %s (level %d)", + output = STRPRINTF("Job - %s (level %d)", job_name(pl_sd->status.pc_class), pl_sd->status.job_level); clif_displaymessage(fd, output); - sprintf(output, "Hp - %d", pl_sd->status.hp); + output = STRPRINTF("Hp - %d", pl_sd->status.hp); clif_displaymessage(fd, output); - sprintf(output, "MaxHp - %d", pl_sd->status.max_hp); + output = STRPRINTF("MaxHp - %d", pl_sd->status.max_hp); clif_displaymessage(fd, output); - sprintf(output, "Sp - %d", pl_sd->status.sp); + output = STRPRINTF("Sp - %d", pl_sd->status.sp); clif_displaymessage(fd, output); - sprintf(output, "MaxSp - %d", pl_sd->status.max_sp); + output = STRPRINTF("MaxSp - %d", pl_sd->status.max_sp); clif_displaymessage(fd, output); - sprintf(output, "Str - %3d", pl_sd->status.attrs[ATTR::STR]); + output = STRPRINTF("Str - %3d", pl_sd->status.attrs[ATTR::STR]); clif_displaymessage(fd, output); - sprintf(output, "Agi - %3d", pl_sd->status.attrs[ATTR::AGI]); + output = STRPRINTF("Agi - %3d", pl_sd->status.attrs[ATTR::AGI]); clif_displaymessage(fd, output); - sprintf(output, "Vit - %3d", pl_sd->status.attrs[ATTR::VIT]); + output = STRPRINTF("Vit - %3d", pl_sd->status.attrs[ATTR::VIT]); clif_displaymessage(fd, output); - sprintf(output, "Int - %3d", pl_sd->status.attrs[ATTR::INT]); + output = STRPRINTF("Int - %3d", pl_sd->status.attrs[ATTR::INT]); clif_displaymessage(fd, output); - sprintf(output, "Dex - %3d", pl_sd->status.attrs[ATTR::DEX]); + output = STRPRINTF("Dex - %3d", pl_sd->status.attrs[ATTR::DEX]); clif_displaymessage(fd, output); - sprintf(output, "Luk - %3d", pl_sd->status.attrs[ATTR::LUK]); + output = STRPRINTF("Luk - %3d", pl_sd->status.attrs[ATTR::LUK]); clif_displaymessage(fd, output); - sprintf(output, "Zeny - %d", pl_sd->status.zeny); + output = STRPRINTF("Zeny - %d", pl_sd->status.zeny); clif_displaymessage(fd, output); } else @@ -3479,38 +3152,39 @@ int atcommand_character_stats(const int fd, struct map_session_data *, int atcommand_character_stats_all(const int fd, struct map_session_data *, const char *, const char *) { - char output[1024], gmlevel[1024]; int i; int count; struct map_session_data *pl_sd; - memset(output, '\0', sizeof(output)); - memset(gmlevel, '\0', sizeof(gmlevel)); - count = 0; for (i = 0; i < fd_max; i++) { if (session[i] && (pl_sd = (struct map_session_data *)session[i]->session_data) && pl_sd->state.auth) { - + std::string gmlevel; if (pc_isGM(pl_sd) > 0) - sprintf(gmlevel, "| GM Lvl: %d", pc_isGM(pl_sd)); + gmlevel = STRPRINTF("| GM Lvl: %d", pc_isGM(pl_sd)); else - sprintf(gmlevel, " "); - - sprintf(output, - "Name: %s | BLvl: %d | Job: %s (Lvl: %d) | HP: %d/%d | SP: %d/%d", - pl_sd->status.name, pl_sd->status.base_level, - job_name(pl_sd->status.pc_class), pl_sd->status.job_level, - pl_sd->status.hp, pl_sd->status.max_hp, pl_sd->status.sp, - pl_sd->status.max_sp); + gmlevel = " "; + + std::string output; + output = STRPRINTF( + "Name: %s | BLvl: %d | Job: %s (Lvl: %d) | HP: %d/%d | SP: %d/%d", + pl_sd->status.name, pl_sd->status.base_level, + job_name(pl_sd->status.pc_class), pl_sd->status.job_level, + pl_sd->status.hp, pl_sd->status.max_hp, + pl_sd->status.sp, pl_sd->status.max_sp); clif_displaymessage(fd, output); - sprintf(output, - "STR: %d | AGI: %d | VIT: %d | INT: %d | DEX: %d | LUK: %d | Zeny: %d %s", - pl_sd->status.attrs[ATTR::STR], pl_sd->status.attrs[ATTR::AGI], pl_sd->status.attrs[ATTR::VIT], - pl_sd->status.attrs[ATTR::INT], pl_sd->status.attrs[ATTR::DEX], pl_sd->status.attrs[ATTR::LUK], - pl_sd->status.zeny, gmlevel); + output = STRPRINTF("STR: %d | AGI: %d | VIT: %d | INT: %d | DEX: %d | LUK: %d | Zeny: %d %s", + pl_sd->status.attrs[ATTR::STR], + pl_sd->status.attrs[ATTR::AGI], + pl_sd->status.attrs[ATTR::VIT], + pl_sd->status.attrs[ATTR::INT], + pl_sd->status.attrs[ATTR::DEX], + pl_sd->status.attrs[ATTR::LUK], + pl_sd->status.zeny, + gmlevel); clif_displaymessage(fd, output); clif_displaymessage(fd, "--------"); count++; @@ -3523,7 +3197,7 @@ int atcommand_character_stats_all(const int fd, struct map_session_data *, clif_displaymessage(fd, "1 player found."); else { - sprintf(output, "%d players found.", count); + std::string output = STRPRINTF("%d players found.", count); clif_displaymessage(fd, output); } @@ -4673,12 +4347,10 @@ int atcommand_idsearch(const int fd, struct map_session_data *, const char *, const char *message) { char item_name[100]; - char output[200]; int i, match; struct item_data *item; memset(item_name, '\0', sizeof(item_name)); - memset(output, '\0', sizeof(output)); if (!message || !*message || sscanf(message, "%99s", item_name) < 0) { @@ -4687,7 +4359,7 @@ int atcommand_idsearch(const int fd, struct map_session_data *, return -1; } - sprintf(output, "The reference result of '%s' (name: id):", item_name); + std::string output = STRPRINTF("The reference result of '%s' (name: id):", item_name); clif_displaymessage(fd, output); match = 0; for (i = 0; i < 20000; i++) @@ -4696,11 +4368,11 @@ int atcommand_idsearch(const int fd, struct map_session_data *, && strstr(item->jname, item_name) != NULL) { match++; - sprintf(output, "%s: %d", item->jname, item->nameid); + output = STRPRINTF("%s: %d", item->jname, item->nameid); clif_displaymessage(fd, output); } } - sprintf(output, "It is %d affair above.", match); + output = STRPRINTF("It is %d affair above.", match); clif_displaymessage(fd, output); return 0; @@ -4714,11 +4386,9 @@ int atcommand_charskreset(const int fd, struct map_session_data *sd, const char *, const char *message) { char character[100]; - char output[200]; struct map_session_data *pl_sd; memset(character, '\0', sizeof(character)); - memset(output, '\0', sizeof(output)); if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1) { @@ -4732,7 +4402,8 @@ int atcommand_charskreset(const int fd, struct map_session_data *sd, if (pc_isGM(sd) >= pc_isGM(pl_sd)) { // you can reset skill points only lower or same gm level pc_resetskill(pl_sd); - sprintf(output, "'%s' skill points reseted!", character); + std::string output = STRPRINTF( + "'%s' skill points reseted!", character); clif_displaymessage(fd, output); } else @@ -4758,11 +4429,9 @@ int atcommand_charstreset(const int fd, struct map_session_data *sd, const char *, const char *message) { char character[100]; - char output[200]; struct map_session_data *pl_sd; memset(character, '\0', sizeof(character)); - memset(output, '\0', sizeof(output)); if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1) { @@ -4776,7 +4445,9 @@ int atcommand_charstreset(const int fd, struct map_session_data *sd, if (pc_isGM(sd) >= pc_isGM(pl_sd)) { // you can reset stats points only lower or same gm level pc_resetstate(pl_sd); - sprintf(output, "'%s' stats points reseted!", character); + std::string output = STRPRINTF( + "'%s' stats points reseted!", + character); clif_displaymessage(fd, output); } else @@ -4802,11 +4473,9 @@ int atcommand_charreset(const int fd, struct map_session_data *sd, const char *, const char *message) { char character[100]; - char output[200]; struct map_session_data *pl_sd; memset(character, '\0', sizeof(character)); - memset(output, '\0', sizeof(output)); if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1) { @@ -4823,7 +4492,8 @@ int atcommand_charreset(const int fd, struct map_session_data *sd, pc_resetskill(pl_sd); pc_setglobalreg(pl_sd, "MAGIC_FLAGS", 0); // [Fate] Reset magic quest variables pc_setglobalreg(pl_sd, "MAGIC_EXP", 0); // [Fate] Reset magic experience - sprintf(output, "'%s' skill and stats points reseted!", character); + std::string output = STRPRINTF( + "'%s' skill and stats points reseted!", character); clif_displaymessage(fd, output); } else @@ -4849,11 +4519,9 @@ int atcommand_char_wipe(const int fd, struct map_session_data *sd, const char *, const char *message) { char character[100]; - char output[200]; struct map_session_data *pl_sd; memset(character, '\0', sizeof(character)); - memset(output, '\0', sizeof(output)); if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1) { @@ -4913,7 +4581,7 @@ int atcommand_char_wipe(const int fd, struct map_session_data *sd, pc_setglobalreg(pl_sd, "MAGIC_FLAGS", 0); // [Fate] Reset magic quest variables pc_setglobalreg(pl_sd, "MAGIC_EXP", 0); // [Fate] Reset magic experience - sprintf(output, "%s: wiped.", character); + std::string output = STRPRINTF("%s: wiped.", character); clif_displaymessage(fd, output); } else @@ -4941,20 +4609,19 @@ int atcommand_charmodel(const int fd, struct map_session_data *, int hair_style = 0, hair_color = 0, cloth_color = 0; struct map_session_data *pl_sd; char character[100]; - char output[200]; memset(character, '\0', sizeof(character)); - memset(output, '\0', sizeof(output)); if (!message || !*message || sscanf(message, "%d %d %d %99[^\n]", &hair_style, &hair_color, &cloth_color, character) < 4 || hair_style < 0 || hair_color < 0 || cloth_color < 0) { - sprintf(output, - "Please, enter a valid model and a player name (usage: @charmodel ).", - MIN_HAIR_STYLE, MAX_HAIR_STYLE, MIN_HAIR_COLOR, - MAX_HAIR_COLOR, MIN_CLOTH_COLOR, MAX_CLOTH_COLOR); + std::string output = STRPRINTF( + "Please, enter a valid model and a player name (usage: @charmodel ).", + MIN_HAIR_STYLE, MAX_HAIR_STYLE, + MIN_HAIR_COLOR, MAX_HAIR_COLOR, + MIN_CLOTH_COLOR, MAX_CLOTH_COLOR); clif_displaymessage(fd, output); return -1; } @@ -5166,9 +4833,6 @@ int atcommand_recallall(const int fd, struct map_session_data *sd, struct map_session_data *pl_sd; int i; int count; - char output[200]; - - memset(output, '\0', sizeof(output)); if (sd->bl.m >= 0 && map[sd->bl.m].flag.nowarpto && battle_config.any_warp_GM_min_level > pc_isGM(sd)) @@ -5197,9 +4861,9 @@ int atcommand_recallall(const int fd, struct map_session_data *sd, clif_displaymessage(fd, "All characters recalled!"); if (count) { - sprintf(output, - "Because you are not authorised to warp from some maps, %d player(s) have not been recalled.", - count); + std::string output = STRPRINTF( + "Because you are not authorised to warp from some maps, %d player(s) have not been recalled.", + count); clif_displaymessage(fd, output); } @@ -5216,12 +4880,10 @@ int atcommand_partyrecall(const int fd, struct map_session_data *sd, int i; struct map_session_data *pl_sd; char party_name[100]; - char output[200]; struct party *p; int count; memset(party_name, '\0', sizeof(party_name)); - memset(output, '\0', sizeof(output)); if (!message || !*message || sscanf(message, "%99[^\n]", party_name) < 1) { @@ -5256,13 +4918,13 @@ int atcommand_partyrecall(const int fd, struct map_session_data *sd, pc_setpos(pl_sd, sd->mapname, sd->bl.x, sd->bl.y, 2); } } - sprintf(output, "All online characters of the %s party are near you.", p->name); + std::string output = STRPRINTF("All online characters of the %s party are near you.", p->name); clif_displaymessage(fd, output); if (count) { - sprintf(output, - "Because you are not authorised to warp from some maps, %d player(s) have not been recalled.", - count); + output = STRPRINTF( + "Because you are not authorised to warp from some maps, %d player(s) have not been recalled.", + count); clif_displaymessage(fd, output); } } @@ -5360,11 +5022,10 @@ int atcommand_mapinfo(const int fd, struct map_session_data *sd, struct map_session_data *pl_sd; struct npc_data *nd = NULL; struct chat_data *cd = NULL; - char output[200], map_name[100]; + char map_name[100]; char direction[12]; int m_id, i, chat_num, list = 0; - memset(output, '\0', sizeof(output)); memset(map_name, '\0', sizeof(map_name)); memset(direction, '\0', sizeof(direction)); @@ -5389,11 +5050,11 @@ int atcommand_mapinfo(const int fd, struct map_session_data *sd, } clif_displaymessage(fd, "------ Map Info ------"); - sprintf(output, "Map Name: %s", map_name); + std::string output = STRPRINTF("Map Name: %s", map_name); clif_displaymessage(fd, output); - sprintf(output, "Players In Map: %d", map[m_id].users); + output = STRPRINTF("Players In Map: %d", map[m_id].users); clif_displaymessage(fd, output); - sprintf(output, "NPCs In Map: %d", map[m_id].npc_num); + output = STRPRINTF("NPCs In Map: %d", map[m_id].npc_num); clif_displaymessage(fd, output); chat_num = 0; for (i = 0; i < fd_max; i++) @@ -5405,35 +5066,35 @@ int atcommand_mapinfo(const int fd, struct map_session_data *sd, chat_num++; } } - sprintf(output, "Chats In Map: %d", chat_num); + output = STRPRINTF("Chats In Map: %d", chat_num); clif_displaymessage(fd, output); clif_displaymessage(fd, "------ Map Flags ------"); - sprintf(output, "Player vs Player: %s | No Party: %s", + output = STRPRINTF("Player vs Player: %s | No Party: %s", (map[m_id].flag.pvp) ? "True" : "False", (map[m_id].flag.pvp_noparty) ? "True" : "False"); clif_displaymessage(fd, output); - sprintf(output, "No Dead Branch: %s", + output = STRPRINTF("No Dead Branch: %s", (map[m_id].flag.nobranch) ? "True" : "False"); clif_displaymessage(fd, output); - sprintf(output, "No Memo: %s", + output = STRPRINTF("No Memo: %s", (map[m_id].flag.nomemo) ? "True" : "False"); clif_displaymessage(fd, output); - sprintf(output, "No Penalty: %s", + output = STRPRINTF("No Penalty: %s", (map[m_id].flag.nopenalty) ? "True" : "False"); clif_displaymessage(fd, output); - sprintf(output, "No Return: %s", + output = STRPRINTF("No Return: %s", (map[m_id].flag.noreturn) ? "True" : "False"); clif_displaymessage(fd, output); - sprintf(output, "No Save: %s", + output = STRPRINTF("No Save: %s", (map[m_id].flag.nosave) ? "True" : "False"); clif_displaymessage(fd, output); - sprintf(output, "No Teleport: %s", + output = STRPRINTF("No Teleport: %s", (map[m_id].flag.noteleport) ? "True" : "False"); clif_displaymessage(fd, output); - sprintf(output, "No Monster Teleport: %s", + output = STRPRINTF("No Monster Teleport: %s", (map[m_id].flag.monster_noteleport) ? "True" : "False"); clif_displaymessage(fd, output); - sprintf(output, "No Zeny Penalty: %s", + output = STRPRINTF("No Zeny Penalty: %s", (map[m_id].flag.nozenypenalty) ? "True" : "False"); clif_displaymessage(fd, output); @@ -5450,7 +5111,7 @@ int atcommand_mapinfo(const int fd, struct map_session_data *sd, && pl_sd->state.auth && strcmp(pl_sd->mapname, map_name) == 0) { - sprintf(output, + output = STRPRINTF( "Player '%s' (session #%d) | Location: %d,%d", pl_sd->status.name, i, pl_sd->bl.x, pl_sd->bl.y); clif_displaymessage(fd, output); @@ -5495,7 +5156,7 @@ int atcommand_mapinfo(const int fd, struct map_session_data *sd, strcpy(direction, "Unknown"); break; } - sprintf(output, + output = STRPRINTF( "NPC %d: %s | Direction: %s | Sprite: %d | Location: %d %d", ++i, nd->name, direction, nd->npc_class, nd->bl.x, nd->bl.y); @@ -5512,12 +5173,12 @@ int atcommand_mapinfo(const int fd, struct map_session_data *sd, && strcmp(pl_sd->mapname, map_name) == 0 && cd->usersd[0] == pl_sd) { - sprintf(output, + output = STRPRINTF( "Chat %d: %s | Player: %s | Location: %d %d", i, cd->title, pl_sd->status.name, cd->bl.x, cd->bl.y); clif_displaymessage(fd, output); - sprintf(output, + output = STRPRINTF( " Users: %d/%d | Password: %s | Public: %s", cd->users, cd->limit, cd->pass, (cd->pub) ? "Yes" : "No"); @@ -5667,11 +5328,9 @@ int atcommand_partyspy(const int fd, struct map_session_data *sd, const char *, const char *message) { char party_name[100]; - char output[200]; struct party *p; memset(party_name, '\0', sizeof(party_name)); - memset(output, '\0', sizeof(output)); if (!message || !*message || sscanf(message, "%99[^\n]", party_name) < 1) { @@ -5686,13 +5345,13 @@ int atcommand_partyspy(const int fd, struct map_session_data *sd, if (sd->partyspy == p->party_id) { sd->partyspy = 0; - sprintf(output, "No longer spying on the %s party.", p->name); + std::string output = STRPRINTF("No longer spying on the %s party.", p->name); clif_displaymessage(fd, output); } else { sd->partyspy = p->party_id; - sprintf(output, "Spying on the %s party.", p->name); + std::string output = STRPRINTF("Spying on the %s party.", p->name); clif_displaymessage(fd, output); } } @@ -5774,40 +5433,17 @@ int atcommand_disablenpc(const int fd, struct map_session_data *, *------------------------------------------ */ static -const char *txt_time(unsigned int duration) +std::string txt_time(unsigned int duration) { - int days, hours, minutes, seconds; - char temp[256]; - static char temp1[256]; - - memset(temp, '\0', sizeof(temp)); - memset(temp1, '\0', sizeof(temp1)); - - days = duration / (60 * 60 * 24); - duration = duration - (60 * 60 * 24 * days); - hours = duration / (60 * 60); - duration = duration - (60 * 60 * hours); - minutes = duration / 60; - seconds = duration - (60 * minutes); - - if (days < 2) - sprintf(temp, "%d day", days); - else - sprintf(temp, "%d days", days); - if (hours < 2) - sprintf(temp1, "%s %d hour", temp, hours); - else - sprintf(temp1, "%s %d hours", temp, hours); - if (minutes < 2) - sprintf(temp, "%s %d minute", temp1, minutes); - else - sprintf(temp, "%s %d minutes", temp1, minutes); - if (seconds < 2) - sprintf(temp1, "%s and %d second", temp, seconds); - else - sprintf(temp1, "%s and %d seconds", temp, seconds); + int days = duration / (60 * 60 * 24); + duration -= (60 * 60 * 24 * days); + int hours = duration / (60 * 60); + duration -= (60 * 60 * hours); + int minutes = duration / 60; + int seconds = duration - (60 * minutes); - return temp1; + return STRPRINTF("%d day(s), %d hour(s), %d minute(s), %d second(s)", + days, hours, minutes, seconds); } /*========================================== @@ -5820,16 +5456,10 @@ int atcommand_servertime(const int fd, struct map_session_data *, { struct TimerData *timer_data; struct TimerData *timer_data2; - time_t time_server; // variable for number of seconds (used with time() function) - struct tm *datetime; // variable for time in structure ->tm_mday, ->tm_sec, ... - char temp[256]; - memset(temp, '\0', sizeof(temp)); - - time(&time_server); // get time in seconds since 1/1/1970 - datetime = gmtime(&time_server); // convert seconds in structure - // like sprintf, but only for date/time (Sunday, November 02 2003 15:12:52) - strftime(temp, sizeof(temp) - 1, "Server time (normal time): %A, %B %d %Y %X.", datetime); + timestamp_seconds_buffer tsbuf; + stamp_time(tsbuf); + std::string temp = STRPRINTF("Server time: %s", tsbuf); clif_displaymessage(fd, temp); if (battle_config.night_duration == 0 && battle_config.day_duration == 0) @@ -5843,7 +5473,8 @@ int atcommand_servertime(const int fd, struct map_session_data *, if (night_flag == 1) { // we start with night timer_data = get_timer(day_timer_tid); - sprintf(temp, "Game time: The game is actualy in night for %s.", txt_time((timer_data->tick - gettick()) / 1000)); + temp = STRPRINTF("Game time: The game is actualy in night for %s.", + txt_time((timer_data->tick - gettick()) / 1000)); clif_displaymessage(fd, temp); clif_displaymessage(fd, "Game time: After, the game will be in permanent daylight."); } @@ -5853,7 +5484,8 @@ int atcommand_servertime(const int fd, struct map_session_data *, if (night_flag == 0) { // we start with day timer_data = get_timer(night_timer_tid); - sprintf(temp, "Game time: The game is actualy in daylight for %s.", txt_time((timer_data->tick - gettick()) / 1000)); + temp = STRPRINTF("Game time: The game is actualy in daylight for %s.", + txt_time((timer_data->tick - gettick()) / 1000)); clif_displaymessage(fd, temp); clif_displaymessage(fd, "Game time: After, the game will be in permanent night."); } @@ -5865,28 +5497,35 @@ int atcommand_servertime(const int fd, struct map_session_data *, { timer_data = get_timer(night_timer_tid); timer_data2 = get_timer(day_timer_tid); - sprintf(temp, "Game time: The game is actualy in daylight for %s.", txt_time((timer_data->tick - gettick()) / 1000)); + temp = STRPRINTF("Game time: The game is actualy in daylight for %s.", + txt_time((timer_data->tick - gettick()) / 1000)); clif_displaymessage(fd, temp); if (timer_data->tick > timer_data2->tick) - sprintf(temp, "Game time: After, the game will be in night for %s.", txt_time((timer_data->interval - abs(timer_data->tick - timer_data2->tick)) / 1000)); + temp = STRPRINTF("Game time: After, the game will be in night for %s.", + txt_time((timer_data->interval - abs(timer_data->tick - timer_data2->tick)) / 1000)); else - sprintf(temp, "Game time: After, the game will be in night for %s.", txt_time(abs(timer_data->tick - timer_data2->tick) / 1000)); + temp = STRPRINTF("Game time: After, the game will be in night for %s.", + txt_time(abs(timer_data->tick - timer_data2->tick) / 1000)); clif_displaymessage(fd, temp); - sprintf(temp, "Game time: A day cycle has a normal duration of %s.", txt_time(timer_data->interval / 1000)); + temp = STRPRINTF("Game time: A day cycle has a normal duration of %s.", + txt_time(timer_data->interval / 1000)); clif_displaymessage(fd, temp); } else { timer_data = get_timer(day_timer_tid); timer_data2 = get_timer(night_timer_tid); - sprintf(temp, "Game time: The game is actualy in night for %s.", txt_time((timer_data->tick - gettick()) / 1000)); + temp = STRPRINTF("Game time: The game is actualy in night for %s.", + txt_time((timer_data->tick - gettick()) / 1000)); clif_displaymessage(fd, temp); if (timer_data->tick > timer_data2->tick) - sprintf(temp, "Game time: After, the game will be in daylight for %s.", txt_time((timer_data->interval - abs(timer_data->tick - timer_data2->tick)) / 1000)); + temp = STRPRINTF("Game time: After, the game will be in daylight for %s.", + txt_time((timer_data->interval - abs(timer_data->tick - timer_data2->tick)) / 1000)); else - sprintf(temp, "Game time: After, the game will be in daylight for %s.", txt_time(abs(timer_data->tick - timer_data2->tick) / 1000)); + temp = STRPRINTF("Game time: After, the game will be in daylight for %s.", txt_time(abs(timer_data->tick - timer_data2->tick) / 1000)); clif_displaymessage(fd, temp); - sprintf(temp, "Game time: A day cycle has a normal duration of %s.", txt_time(timer_data->interval / 1000)); + temp = STRPRINTF("Game time: A day cycle has a normal duration of %s.", + txt_time(timer_data->interval / 1000)); clif_displaymessage(fd, temp); } } @@ -5908,12 +5547,10 @@ int atcommand_chardelitem(const int fd, struct map_session_data *sd, char character[100]; char item_name[100]; int i, number = 0, item_id, item_position, count; - char output[200]; struct item_data *item_data; memset(character, '\0', sizeof(character)); memset(item_name, '\0', sizeof(item_name)); - memset(output, '\0', sizeof(output)); if (!message || !*message || sscanf(message, "%s %d %99[^\n]", item_name, &number, @@ -5945,12 +5582,15 @@ int atcommand_chardelitem(const int fd, struct map_session_data *sd, count++; item_position = pc_search_inventory(pl_sd, item_id); // for next loop } - sprintf(output, "%d item(s) removed by a GM.", count); + std::string output = STRPRINTF( + "%d item(s) removed by a GM.", + count); clif_displaymessage(pl_sd->fd, output); + if (number == count) - sprintf(output, "%d item(s) removed from the player.", count); + output = STRPRINTF("%d item(s) removed from the player.", count); else - sprintf(output, "%d item(s) removed. Player had only %d on %d items.", count, count, number); + output = STRPRINTF("%d item(s) removed. Player had only %d on %d items.", count, count, number); clif_displaymessage(fd, output); } else @@ -6172,10 +5812,6 @@ int atcommand_undisguise(const int fd, struct map_session_data *sd, int atcommand_broadcast(const int fd, struct map_session_data *sd, const char *, const char *message) { - char output[200]; - - memset(output, '\0', sizeof(output)); - if (!message || !*message) { clif_displaymessage(fd, @@ -6183,8 +5819,8 @@ int atcommand_broadcast(const int fd, struct map_session_data *sd, return -1; } - snprintf(output, 199, "%s : %s", sd->status.name, message); - intif_GMmessage(output, strlen(output) + 1, 0); + std::string output = STRPRINTF("%s : %s", sd->status.name, message); + intif_GMmessage(output, 0); return 0; } @@ -6196,10 +5832,6 @@ int atcommand_broadcast(const int fd, struct map_session_data *sd, int atcommand_localbroadcast(const int fd, struct map_session_data *sd, const char *, const char *message) { - char output[200]; - - memset(output, '\0', sizeof(output)); - if (!message || !*message) { clif_displaymessage(fd, @@ -6207,9 +5839,9 @@ int atcommand_localbroadcast(const int fd, struct map_session_data *sd, return -1; } - snprintf(output, 199, "%s : %s", sd->status.name, message); + std::string output = STRPRINTF("%s : %s", sd->status.name, message); - clif_GMmessage(&sd->bl, output, strlen(output) + 1, 1); // 1: ALL_SAMEMAP + clif_GMmessage(&sd->bl, output, 1); // 1: ALL_SAMEMAP return 0; } @@ -6221,12 +5853,9 @@ int atcommand_localbroadcast(const int fd, struct map_session_data *sd, int atcommand_ignorelist(const int fd, struct map_session_data *sd, const char *, const char *) { - char output[200]; int count; int i; - memset(output, '\0', sizeof(output)); - count = 0; for (i = 0; i < (int)(sizeof(sd->ignore) / sizeof(sd->ignore[0])); i++) if (sd->ignore[i].name[0]) @@ -6237,14 +5866,18 @@ int atcommand_ignorelist(const int fd, struct map_session_data *sd, clif_displaymessage(fd, "You accept any wisp (no wisper is refused)."); else { - sprintf(output, "You accept any wisp, except thoses from %d player (s):", count); + std::string output = STRPRINTF( + "You accept any wisp, except thoses from %d player (s):", + count); clif_displaymessage(fd, output); } else if (count == 0) clif_displaymessage(fd, "You refuse all wisps (no specifical wisper is refused)."); else { - sprintf(output, "You refuse all wisps, AND refuse wisps from %d player (s):", count); + std::string output = STRPRINTF( + "You refuse all wisps, AND refuse wisps from %d player (s):", + count); clif_displaymessage(fd, output); } @@ -6266,17 +5899,15 @@ int atcommand_charignorelist(const int fd, struct map_session_data *, { char character[100]; struct map_session_data *pl_sd; - char output[200]; int count; int i; memset(character, '\0', sizeof(character)); - memset(output, '\0', sizeof(output)); if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1) { clif_displaymessage(fd, - "Please, enter a player name (usage: @charignorelist )."); + "Please, enter a player name (usage: @charignorelist )."); return -1; } @@ -6292,22 +5923,30 @@ int atcommand_charignorelist(const int fd, struct map_session_data *, if (pl_sd->ignoreAll == 0) if (count == 0) { - sprintf(output, "'%s' accept any wisp (no wisper is refused).", pl_sd->status.name); + std::string output = STRPRINTF( + "'%s' accept any wisp (no wisper is refused).", + pl_sd->status.name); clif_displaymessage(fd, output); } else { - sprintf(output, "'%s' accept any wisp, except thoses from %d player(s):", pl_sd->status.name, count); + std::string output = STRPRINTF( + "'%s' accept any wisp, except thoses from %d player(s):", + pl_sd->status.name, count); clif_displaymessage(fd, output); } else if (count == 0) { - sprintf(output, "'%s' refuse all wisps (no specifical wisper is refused).", pl_sd->status.name); + std::string output = STRPRINTF( + "'%s' refuse all wisps (no specifical wisper is refused).", + pl_sd->status.name); clif_displaymessage(fd, output); } else { - sprintf(output, "'%s' refuse all wisps, AND refuse wisps from %d player(s):", pl_sd->status.name, count); + std::string output = STRPRINTF( + "'%s' refuse all wisps, AND refuse wisps from %d player(s):", + pl_sd->status.name, count); clif_displaymessage(fd, output); } @@ -6337,11 +5976,9 @@ int atcommand_inall(const int fd, struct map_session_data *sd, const char *, const char *message) { char character[100]; - char output[200]; struct map_session_data *pl_sd; memset(character, '\0', sizeof(character)); - memset(output, '\0', sizeof(output)); if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1) { @@ -6356,14 +5993,18 @@ int atcommand_inall(const int fd, struct map_session_data *sd, { // you can change wisp option only to lower or same level if (pl_sd->ignoreAll == 0) { - sprintf(output, "'%s' already accepts all wispers.", pl_sd->status.name); + std::string output = STRPRINTF( + "'%s' already accepts all wispers.", + pl_sd->status.name); clif_displaymessage(fd, output); return -1; } else { pl_sd->ignoreAll = 0; - sprintf(output, "'%s' now accepts all wispers.", pl_sd->status.name); + std::string output = STRPRINTF( + "'%s' now accepts all wispers.", + pl_sd->status.name); clif_displaymessage(fd, output); // message to player clif_displaymessage(pl_sd->fd, "A GM has authorised all wispers for you."); @@ -6396,11 +6037,9 @@ int atcommand_exall(const int fd, struct map_session_data *sd, const char *, const char *message) { char character[100]; - char output[200]; struct map_session_data *pl_sd; memset(character, '\0', sizeof(character)); - memset(output, '\0', sizeof(output)); if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1) { @@ -6415,14 +6054,18 @@ int atcommand_exall(const int fd, struct map_session_data *sd, { // you can change wisp option only to lower or same level if (pl_sd->ignoreAll == 1) { - sprintf(output, "'%s' already blocks all wispers.", pl_sd->status.name); + std::string output = STRPRINTF( + "'%s' already blocks all wispers.", + pl_sd->status.name); clif_displaymessage(fd, output); return -1; } else { pl_sd->ignoreAll = 1; - sprintf(output, "'%s' blocks now all wispers.", pl_sd->status.name); + std::string output = STRPRINTF( + "'%s' blocks now all wispers.", + pl_sd->status.name); clif_displaymessage(fd, output); // message to player clif_displaymessage(pl_sd->fd, "A GM has blocked all wispers for you."); @@ -6663,12 +6306,10 @@ int atcommand_character_item_list(const int fd, struct map_session_data *sd, struct map_session_data *pl_sd; struct item_data *item_data, *item_temp; int i, j, count, counter, counter2; - char character[100], output[200], equipstr[100], outputtmp[200]; + char character[100], equipstr[100]; memset(character, '\0', sizeof(character)); - memset(output, '\0', sizeof(output)); memset(equipstr, '\0', sizeof(equipstr)); - memset(outputtmp, '\0', sizeof(outputtmp)); if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1) { @@ -6694,8 +6335,9 @@ int atcommand_character_item_list(const int fd, struct map_session_data *sd, count++; if (count == 1) { - sprintf(output, "------ Items list of '%s' ------", - pl_sd->status.name); + std::string output = STRPRINTF( + "------ Items list of '%s' ------", + pl_sd->status.name); clif_displaymessage(fd, output); } EPOS equip; @@ -6735,8 +6377,10 @@ int atcommand_character_item_list(const int fd, struct map_session_data *sd, } else memset(equipstr, '\0', sizeof(equipstr)); + + std::string output; if (sd->status.inventory[i].refine) - sprintf(output, "%d %s %+d (%s %+d, id: %d) %s", + output = STRPRINTF("%d %s %+d (%s %+d, id: %d) %s", pl_sd->status.inventory[i].amount, item_data->name, pl_sd->status.inventory[i].refine, @@ -6744,12 +6388,13 @@ int atcommand_character_item_list(const int fd, struct map_session_data *sd, pl_sd->status.inventory[i].refine, pl_sd->status.inventory[i].nameid, equipstr); else - sprintf(output, "%d %s (%s, id: %d) %s", + output = STRPRINTF("%d %s (%s, id: %d) %s", pl_sd->status.inventory[i].amount, item_data->name, item_data->jname, pl_sd->status.inventory[i].nameid, equipstr); clif_displaymessage(fd, output); - memset(output, '\0', sizeof(output)); + + output.clear(); counter2 = 0; for (j = 0; j < item_data->slot; j++) { @@ -6760,23 +6405,31 @@ int atcommand_character_item_list(const int fd, struct map_session_data *sd, inventory[i].card[j])) != NULL) { - if (output[0] == '\0') - sprintf(outputtmp, - " -> (card(s): #%d %s (%s), ", - ++counter2, item_temp->name, - item_temp->jname); + if (output.empty()) + output = STRPRINTF( + " -> (card(s): #%d %s (%s), ", + ++counter2, + item_temp->name, + item_temp->jname); else - sprintf(outputtmp, "#%d %s (%s), ", - ++counter2, item_temp->name, - item_temp->jname); - strcat(output, outputtmp); + output += STRPRINTF( + "#%d %s (%s), ", + ++counter2, + item_temp->name, + item_temp->jname); } } } - if (output[0] != '\0') + if (!output.empty()) { - output[strlen(output) - 2] = ')'; - output[strlen(output) - 1] = '\0'; + // replace trailing ", " +#ifdef ANNOYING_GCC46_WORKAROUNDS +# warning " and " + output.resize(output.size() - 1); +#else + output.pop_back(); +#endif + output.back() = ')'; clif_displaymessage(fd, output); } } @@ -6785,8 +6438,9 @@ int atcommand_character_item_list(const int fd, struct map_session_data *sd, clif_displaymessage(fd, "No item found on this player."); else { - sprintf(output, "%d item(s) found in %d kind(s) of items.", - counter, count); + std::string output = STRPRINTF( + "%d item(s) found in %d kind(s) of items.", + counter, count); clif_displaymessage(fd, output); } } @@ -6816,11 +6470,9 @@ int atcommand_character_storage_list(const int fd, struct map_session_data *sd, struct map_session_data *pl_sd; struct item_data *item_data, *item_temp; int i, j, count, counter, counter2; - char character[100], output[200], outputtmp[200]; + char character[100]; memset(character, '\0', sizeof(character)); - memset(output, '\0', sizeof(output)); - memset(outputtmp, '\0', sizeof(outputtmp)); if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1) { @@ -6847,13 +6499,14 @@ int atcommand_character_storage_list(const int fd, struct map_session_data *sd, count++; if (count == 1) { - sprintf(output, + std::string output = STRPRINTF( "------ Storage items list of '%s' ------", pl_sd->status.name); clif_displaymessage(fd, output); } + std::string output; if (stor->storage_[i].refine) - sprintf(output, "%d %s %+d (%s %+d, id: %d)", + output = STRPRINTF("%d %s %+d (%s %+d, id: %d)", stor->storage_[i].amount, item_data->name, stor->storage_[i].refine, @@ -6861,12 +6514,13 @@ int atcommand_character_storage_list(const int fd, struct map_session_data *sd, stor->storage_[i].refine, stor->storage_[i].nameid); else - sprintf(output, "%d %s (%s, id: %d)", + output = STRPRINTF("%d %s (%s, id: %d)", stor->storage_[i].amount, item_data->name, item_data->jname, stor->storage_[i].nameid); clif_displaymessage(fd, output); - memset(output, '\0', sizeof(output)); + + output.clear(); counter2 = 0; for (j = 0; j < item_data->slot; j++) { @@ -6877,23 +6531,31 @@ int atcommand_character_storage_list(const int fd, struct map_session_data *sd, storage_[i].card[j])) != NULL) { - if (output[0] == '\0') - sprintf(outputtmp, - " -> (card(s): #%d %s (%s), ", - ++counter2, item_temp->name, - item_temp->jname); + if (output.empty()) + output = STRPRINTF( + " -> (card(s): #%d %s (%s), ", + ++counter2, + item_temp->name, + item_temp->jname); else - sprintf(outputtmp, "#%d %s (%s), ", - ++counter2, item_temp->name, - item_temp->jname); - strcat(output, outputtmp); + output += STRPRINTF( + "#%d %s (%s), ", + ++counter2, + item_temp->name, + item_temp->jname); } } } - if (output[0] != '\0') + if (!output.empty()) { - output[strlen(output) - 2] = ')'; - output[strlen(output) - 1] = '\0'; + // replace last ", " +#ifdef ANNOYING_GCC46_WORKAROUNDS +# warning " all of " + output.resize(output.size() - 1); +#else + output.pop_back(); +#endif + output.back() = ')'; clif_displaymessage(fd, output); } } @@ -6903,7 +6565,7 @@ int atcommand_character_storage_list(const int fd, struct map_session_data *sd, "No item found in the storage of this player."); else { - sprintf(output, + std::string output = STRPRINTF( "%d item(s) found in %d kind(s) of items.", counter, count); clif_displaymessage(fd, output); @@ -6940,11 +6602,9 @@ int atcommand_character_cart_list(const int fd, struct map_session_data *sd, struct map_session_data *pl_sd; struct item_data *item_data, *item_temp; int i, j, count, counter, counter2; - char character[100], output[200], outputtmp[200]; + char character[100]; memset(character, '\0', sizeof(character)); - memset(output, '\0', sizeof(output)); - memset(outputtmp, '\0', sizeof(outputtmp)); if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1) { @@ -6969,26 +6629,30 @@ int atcommand_character_cart_list(const int fd, struct map_session_data *sd, count++; if (count == 1) { - sprintf(output, - "------ Cart items list of '%s' ------", - pl_sd->status.name); + std::string output = STRPRINTF( + "------ Cart items list of '%s' ------", + pl_sd->status.name); clif_displaymessage(fd, output); } + + std::string output; if (pl_sd->status.cart[i].refine) - sprintf(output, "%d %s %+d (%s %+d, id: %d)", - pl_sd->status.cart[i].amount, - item_data->name, - pl_sd->status.cart[i].refine, - item_data->jname, - pl_sd->status.cart[i].refine, - pl_sd->status.cart[i].nameid); + output = STRPRINTF("%d %s %+d (%s %+d, id: %d)", + pl_sd->status.cart[i].amount, + item_data->name, + pl_sd->status.cart[i].refine, + item_data->jname, + pl_sd->status.cart[i].refine, + pl_sd->status.cart[i].nameid); else - sprintf(output, "%d %s (%s, id: %d)", - pl_sd->status.cart[i].amount, - item_data->name, item_data->jname, - pl_sd->status.cart[i].nameid); + + output = STRPRINTF("%d %s (%s, id: %d)", + pl_sd->status.cart[i].amount, + item_data->name, item_data->jname, + pl_sd->status.cart[i].nameid); clif_displaymessage(fd, output); - memset(output, '\0', sizeof(output)); + + output.clear(); counter2 = 0; for (j = 0; j < item_data->slot; j++) { @@ -6998,23 +6662,30 @@ int atcommand_character_cart_list(const int fd, struct map_session_data *sd, itemdb_search(pl_sd->status. cart[i].card[j])) != NULL) { - if (output[0] == '\0') - sprintf(outputtmp, - " -> (card(s): #%d %s (%s), ", - ++counter2, item_temp->name, - item_temp->jname); + if (output.empty()) + output = STRPRINTF( + " -> (card(s): #%d %s (%s), ", + ++counter2, + item_temp->name, + item_temp->jname); else - sprintf(outputtmp, "#%d %s (%s), ", - ++counter2, item_temp->name, - item_temp->jname); - strcat(output, outputtmp); + output += STRPRINTF( + "#%d %s (%s), ", + ++counter2, + item_temp->name, + item_temp->jname); } } } - if (output[0] != '\0') + if (!output.empty()) { - output[strlen(output) - 2] = ')'; - output[strlen(output) - 1] = '\0'; +#ifdef ANNOYING_GCC46_WORKAROUNDS +# warning " these ... " + output.resize(output.size() - 1); +#else + output.pop_back(); +#endif + output.back() = '0'; clif_displaymessage(fd, output); } } @@ -7024,7 +6695,7 @@ int atcommand_character_cart_list(const int fd, struct map_session_data *sd, "No item found in the cart of this player."); else { - sprintf(output, "%d item(s) found in %d kind(s) of items.", + std::string output = STRPRINTF("%d item(s) found in %d kind(s) of items.", counter, count); clif_displaymessage(fd, output); } @@ -7177,24 +6848,22 @@ int atcommand_npcmove(const int, struct map_session_data *sd, int atcommand_addwarp(const int fd, struct map_session_data *sd, const char *, const char *message) { - char w1[64], w3[64], w4[64]; - char mapname[30], output[200]; + char mapname[30]; int x, y, ret; if (!message || !*message) return -1; - if (sscanf(message, "%99s %d %d[^\n]", mapname, &x, &y) < 3) + if (sscanf(message, "%29s %d %d[^\n]", mapname, &x, &y) < 3) return -1; - sprintf(w1, "%s,%d,%d", sd->mapname, sd->bl.x, sd->bl.y); - sprintf(w3, "%s%d%d%d%d", mapname, sd->bl.x, sd->bl.y, x, y); - sprintf(w4, "1,1,%s.gat,%d,%d", mapname, x, y); - - ret = npc_parse_warp(w1, "warp", w3, w4); + std::string w1 = STRPRINTF("%s,%d,%d", sd->mapname, sd->bl.x, sd->bl.y); + std::string w3 = STRPRINTF("%s%d%d%d%d", mapname, sd->bl.x, sd->bl.y, x, y); + std::string w4 = STRPRINTF("1,1,%s.gat,%d,%d", mapname, x, y); - sprintf(output, "New warp NPC => %s", w3); + ret = npc_parse_warp(w1.c_str(), "warp", w3.c_str(), w4.c_str()); + std::string output = STRPRINTF("New warp NPC => %s", w3); clif_displaymessage(fd, output); return ret; @@ -7390,9 +7059,8 @@ int atcommand_skillid(const int fd, struct map_session_data *, if ((strncasecmp(skill_names[idx].name, message, skillen) == 0) || (strncasecmp(skill_names[idx].desc, message, skillen) == 0)) { - char output[255]; - sprintf(output, "skill %d: %s", - uint16_t(skill_names[idx].id), skill_names[idx].desc); + std::string output = STRPRINTF("skill %d: %s", + skill_names[idx].id, skill_names[idx].desc); clif_displaymessage(fd, output); } idx++; @@ -7717,7 +7385,6 @@ int atcommand_magic_info(const int fd, struct map_session_data *, const char *, const char *message) { char character[100]; - char buf[200]; struct map_session_data *pl_sd; memset(character, '\0', sizeof(character)); @@ -7730,14 +7397,18 @@ int atcommand_magic_info(const int fd, struct map_session_data *, if ((pl_sd = map_nick2sd(character)) != NULL) { - sprintf(buf, "`%s' has the following magic skills:", character); + std::string buf = STRPRINTF( + "`%s' has the following magic skills:", + character); clif_displaymessage(fd, buf); for (size_t i = 0; i < magic_skills_nr; i++) { SkillID sk = magic_skills[i]; - sprintf(buf, "%d in %s", - pl_sd->status.skill[sk].lv, magic_skill_names[i]); + buf = STRPRINTF( + "%d in %s", + pl_sd->status.skill[sk].lv, + magic_skill_names[i]); if (pl_sd->status.skill[sk].id == sk) clif_displaymessage(fd, buf); } @@ -7825,7 +7496,7 @@ int atcommand_log(const int, struct map_session_data *, int atcommand_tee(const int, struct map_session_data *sd, const char *, const char *message) { - char *data = (char *)malloc(strlen(message) + 28); + char data[strlen(message) + 28]; strcpy(data, sd->status.name); strcat(data, " : "); strcat(data, message); @@ -7853,11 +7524,8 @@ int atcommand_jump_iterate(const int fd, struct map_session_data *sd, struct map_session_data *(*get_start)(void), struct map_session_data *(*get_next)(struct map_session_data*)) { - char output[200]; struct map_session_data *pl_sd; - memset(output, '\0', sizeof(output)); - pl_sd = (struct map_session_data *) map_id2bl(sd->followtarget); if (pl_sd) @@ -7888,7 +7556,7 @@ int atcommand_jump_iterate(const int fd, struct map_session_data *sd, return -1; } pc_setpos(sd, map[pl_sd->bl.m].name, pl_sd->bl.x, pl_sd->bl.y, 3); - sprintf(output, "Jump to %s", pl_sd->status.name); + std::string output = STRPRINTF("Jump to %s", pl_sd->status.name); clif_displaymessage(fd, output); sd->followtarget = pl_sd->bl.id; @@ -7921,7 +7589,8 @@ int atcommand_wgm(const int fd, struct map_session_data *sd, { if (tmw_CheckChatSpam(sd, message)) return 0; - tmw_GmHackMsg("%s: %s", sd->status.name, message); + + tmw_GmHackMsg(static_cast(STRPRINTF("[GM] %s: %s", sd->status.name, message))); if (!pc_isGM(sd)) clif_displaymessage(fd, "Message sent."); @@ -7943,25 +7612,25 @@ int atcommand_skillpool_info(const int fd, struct map_session_data *, if ((pl_sd = map_nick2sd(character)) != NULL) { - char buf[200]; SkillID pool_skills[MAX_SKILL_POOL]; int pool_skills_nr = skill_pool(pl_sd, pool_skills); int i; - sprintf(buf, "Active skills %d out of %d for %s:", pool_skills_nr, - skill_pool_max(pl_sd), character); + std::string buf = STRPRINTF( + "Active skills %d out of %d for %s:", + pool_skills_nr, skill_pool_max(pl_sd), character); clif_displaymessage(fd, buf); for (i = 0; i < pool_skills_nr; ++i) { - sprintf(buf, " - %s [%d]: power %d", + buf = STRPRINTF(" - %s [%d]: power %d", skill_name(pool_skills[i]), - uint16_t(pool_skills[i]), + pool_skills[i], skill_power(pl_sd, pool_skills[i])); clif_displaymessage(fd, buf); } - sprintf(buf, "Learned skills out of %d for %s:", - skill_pool_skills_size, character); + buf = STRPRINTF("Learned skills out of %d for %s:", + skill_pool_skills_size, character); clif_displaymessage(fd, buf); for (i = 0; i < skill_pool_skills_size; ++i) @@ -7971,8 +7640,8 @@ int atcommand_skillpool_info(const int fd, struct map_session_data *, if (lvl) { - sprintf(buf, " - %s [%d]: lvl %d", - name, uint16_t(skill_pool_skills[i]), lvl); + buf = STRPRINTF(" - %s [%d]: lvl %d", + name, skill_pool_skills[i], lvl); clif_displaymessage(fd, buf); } } @@ -8075,7 +7744,6 @@ int atcommand_ipcheck(const int fd, struct map_session_data *, { struct map_session_data *pl_sd; struct sockaddr_in sai; - char output[200]; char character[25]; int i; socklen_t sa_len = sizeof(struct sockaddr); @@ -8118,10 +7786,10 @@ int atcommand_ipcheck(const int fd, struct map_session_data *, // Is checking GM levels really needed here? if (ip == sai.sin_addr.s_addr) { - snprintf(output, sizeof(output), - "Name: %s | Location: %s %d %d", - pl_sd->status.name, pl_sd->mapname, - pl_sd->bl.x, pl_sd->bl.y); + std::string output = STRPRINTF( + "Name: %s | Location: %s %d %d", + pl_sd->status.name, pl_sd->mapname, + pl_sd->bl.x, pl_sd->bl.y); clif_displaymessage(fd, output); } } diff --git a/src/map/atcommand.hpp b/src/map/atcommand.hpp index 50ad9b2..ec69cc7 100644 --- a/src/map/atcommand.hpp +++ b/src/map/atcommand.hpp @@ -190,16 +190,13 @@ typedef struct AtCommandInfo const char *command, const char *message); } AtCommandInfo; -AtCommandType is_atcommand(const int fd, struct map_session_data *sd, - const char *message, int gmlvl); +bool is_atcommand(const int fd, struct map_session_data *sd, + const char *message, int gmlvl); int get_atcommand_level(const AtCommandType type); int atcommand_config_read(const char *cfgName); -__attribute__((format(printf, 2, 3))) -void log_atcommand(struct map_session_data *sd, const char *fmt, ...); -__attribute__((format(printf, 1, 2))) -void gm_log(const char *fmt, ...); +void log_atcommand(struct map_session_data *sd, const_string cmd); #endif // ATCOMMAND_HPP diff --git a/src/map/battle.cpp b/src/map/battle.cpp index 88a322b..a6aebcb 100644 --- a/src/map/battle.cpp +++ b/src/map/battle.cpp @@ -5,6 +5,8 @@ #include #include +#include + #include "../common/mt_rand.hpp" #include "../common/nullpo.hpp" #include "../common/socket.hpp" @@ -1316,7 +1318,7 @@ int battle_get_mexp(struct block_list *bl) const int retval = (mob_db[mob->mob_class].mexp * (int)(mob->stats[MOB_XP_BONUS])) >> MOB_XP_BONUS_SHIFT; - fprintf(stderr, "Modifier of %x: -> %d\n", mob->stats[MOB_XP_BONUS], + FPRINTF(stderr, "Modifier of %x: -> %d\n", mob->stats[MOB_XP_BONUS], retval); return retval; } @@ -1570,7 +1572,7 @@ int battle_attr_fix(int damage, int atk_elem, int def_elem) def_lv < 1 || def_lv > 4) { // 属 性値がおかしいのでとりあえずそのまま返す if (battle_config.error_log) - printf("battle_attr_fix: unknown attr type: atk=%d def_type=%d def_lv=%d\n", + PRINTF("battle_attr_fix: unknown attr type: atk=%d def_type=%d def_lv=%d\n", atk_elem, def_type, def_lv); return damage; } @@ -4183,7 +4185,7 @@ struct Damage battle_calc_magic_attack(struct block_list *bl, if (thres > 700) thres = 700; // if(battle_config.battle_log) -// printf("ターンアンデッド! 確率%d ‰(千分率)\n", thres); +// PRINTF("ターンアンデッド! 確率%d ‰(千分率)\n", thres); if (MRAND(1000) < thres && !(t_mode & 0x20)) // 成功 damage = hp; else // 失敗 @@ -4203,7 +4205,7 @@ struct Damage battle_calc_magic_attack(struct block_list *bl, else { if (battle_config.error_log) - printf("battle_calc_magic_attack(): napam enemy count=0 !\n"); + PRINTF("battle_calc_magic_attack(): napam enemy count=0 !\n"); } break; case MG_FIREBALL: // ファイヤーボール @@ -4277,7 +4279,7 @@ struct Damage battle_calc_magic_attack(struct block_list *bl, else { if (battle_config.error_log) - printf("battle_calc_magic_attack(): napalmvulcan enemy count=0 !\n"); + PRINTF("battle_calc_magic_attack(): napalmvulcan enemy count=0 !\n"); } break; } @@ -4613,8 +4615,8 @@ struct Damage battle_calc_attack(BF attack_type, flag); default: if (battle_config.error_log) - printf("battle_calc_attack: unknwon attack type ! %d\n", - uint16_t(attack_type)); + PRINTF("battle_calc_attack: unknwon attack type ! %d\n", + attack_type); break; } return d; @@ -5213,8 +5215,8 @@ int battle_check_target(struct block_list *src, struct block_list *target, return 0; } -//printf("ss:%d src:%d target:%d flag:0x%x %d %d ",ss->id,src->id,target->id,flag,src->type,target->type); -//printf("p:%d %d g:%d %d\n",s_p,t_p,s_g,t_g); +//PRINTF("ss:%d src:%d target:%d flag:0x%x %d %d ",ss->id,src->id,target->id,flag,src->type,target->type); +//PRINTF("p:%d %d g:%d %d\n",s_p,t_p,s_g,t_g); if (ss->type == BL_PC && target->type == BL_PC) { // 両方PVPモードなら否定(敵) @@ -5293,9 +5295,6 @@ int battle_check_range(struct block_list *src, struct block_list *bl, */ int battle_config_read(const char *cfgName) { - int i; - char line[1024], w1[1024], w2[1024]; - FILE *fp; static int count = 0; if ((count++) == 0) @@ -5499,451 +5498,239 @@ int battle_config_read(const char *cfgName) battle_config.mob_splash_radius = -1; } - fp = fopen_(cfgName, "r"); - if (fp == NULL) + std::ifstream in(cfgName); + if (!in.is_open()) { - printf("file not found: %s\n", cfgName); + PRINTF("file not found: %s\n", cfgName); return 1; } - while (fgets(line, 1020, fp)) + + std::string line; + while (std::getline(in, line)) { + // s/{"\([a-zA-Z_0-9]*\)", &battle_config.\1}/BATTLE_CONFIG_VAR(\1)/ const struct { - char str[128]; + const char *str; int *val; } data[] = { - { - "warp_point_debug", &battle_config.warp_point_debug}, - { - "enemy_critical", &battle_config.enemy_critical}, - { - "enemy_critical_rate", &battle_config.enemy_critical_rate}, - { - "enemy_str", &battle_config.enemy_str}, - { - "enemy_perfect_flee", &battle_config.enemy_perfect_flee}, - { - "casting_rate", &battle_config.cast_rate}, - { - "delay_rate", &battle_config.delay_rate}, - { - "delay_dependon_dex", &battle_config.delay_dependon_dex}, - { - "skill_delay_attack_enable", - &battle_config.sdelay_attack_enable}, - { - "left_cardfix_to_right", &battle_config.left_cardfix_to_right}, - { - "player_skill_add_range", &battle_config.pc_skill_add_range}, - { - "skill_out_range_consume", - &battle_config.skill_out_range_consume}, - { - "monster_skill_add_range", &battle_config.mob_skill_add_range}, - { - "player_damage_delay", &battle_config.pc_damage_delay}, - { - "player_damage_delay_rate", - &battle_config.pc_damage_delay_rate}, - { - "defunit_not_enemy", &battle_config.defnotenemy}, - { - "random_monster_checklv", - &battle_config.random_monster_checklv}, - { - "attribute_recover", &battle_config.attr_recover}, - { - "flooritem_lifetime", &battle_config.flooritem_lifetime}, - { - "item_auto_get", &battle_config.item_auto_get}, - { - "drop_pickup_safety_zone", - &battle_config.drop_pickup_safety_zone}, - { - "item_first_get_time", &battle_config.item_first_get_time}, - { - "item_second_get_time", &battle_config.item_second_get_time}, - { - "item_third_get_time", &battle_config.item_third_get_time}, - { - "mvp_item_first_get_time", - &battle_config.mvp_item_first_get_time}, - { - "mvp_item_second_get_time", - &battle_config.mvp_item_second_get_time}, - { - "mvp_item_third_get_time", - &battle_config.mvp_item_third_get_time}, - { - "item_rate", &battle_config.item_rate}, - { - "drop_rate0item", &battle_config.drop_rate0item}, - { - "base_exp_rate", &battle_config.base_exp_rate}, - { - "job_exp_rate", &battle_config.job_exp_rate}, - { - "pvp_exp", &battle_config.pvp_exp}, - { - "gtb_pvp_only", &battle_config.gtb_pvp_only}, - { - "death_penalty_type", &battle_config.death_penalty_type}, - { - "death_penalty_base", &battle_config.death_penalty_base}, - { - "death_penalty_job", &battle_config.death_penalty_job}, - { - "zeny_penalty", &battle_config.zeny_penalty}, - { - "restart_hp_rate", &battle_config.restart_hp_rate}, - { - "restart_sp_rate", &battle_config.restart_sp_rate}, - { - "mvp_hp_rate", &battle_config.mvp_hp_rate}, - { - "mvp_item_rate", &battle_config.mvp_item_rate}, - { - "mvp_exp_rate", &battle_config.mvp_exp_rate}, - { - "monster_hp_rate", &battle_config.monster_hp_rate}, - { - "monster_max_aspd", &battle_config.monster_max_aspd}, - { - "atcommand_gm_only", &battle_config.atc_gmonly}, - { - "atcommand_spawn_quantity_limit", - &battle_config.atc_spawn_quantity_limit}, - { - "gm_all_skill", &battle_config.gm_allskill}, - { - "gm_all_skill_add_abra", &battle_config.gm_allskill_addabra}, - { - "gm_all_equipment", &battle_config.gm_allequip}, - { - "gm_skill_unconditional", &battle_config.gm_skilluncond}, - { - "player_skillfree", &battle_config.skillfree}, - { - "player_skillup_limit", &battle_config.skillup_limit}, - { - "weapon_produce_rate", &battle_config.wp_rate}, - { - "potion_produce_rate", &battle_config.pp_rate}, - { - "monster_active_enable", &battle_config.monster_active_enable}, - { - "monster_damage_delay_rate", - &battle_config.monster_damage_delay_rate}, - { - "monster_loot_type", &battle_config.monster_loot_type}, - { - "mob_skill_use", &battle_config.mob_skill_use}, - { - "mob_count_rate", &battle_config.mob_count_rate}, - { - "quest_skill_learn", &battle_config.quest_skill_learn}, - { - "quest_skill_reset", &battle_config.quest_skill_reset}, - { - "basic_skill_check", &battle_config.basic_skill_check}, - { - "player_invincible_time", &battle_config.pc_invincible_time}, - { - "skill_min_damage", &battle_config.skill_min_damage}, - { - "finger_offensive_type", &battle_config.finger_offensive_type}, - { - "heal_exp", &battle_config.heal_exp}, - { - "resurrection_exp", &battle_config.resurrection_exp}, - { - "shop_exp", &battle_config.shop_exp}, - { - "combo_delay_rate", &battle_config.combo_delay_rate}, - { - "item_check", &battle_config.item_check}, - { - "wedding_modifydisplay", &battle_config.wedding_modifydisplay}, - { - "natural_healhp_interval", - &battle_config.natural_healhp_interval}, - { - "natural_healsp_interval", - &battle_config.natural_healsp_interval}, - { - "natural_heal_skill_interval", - &battle_config.natural_heal_skill_interval}, - { - "natural_heal_weight_rate", - &battle_config.natural_heal_weight_rate}, - { - "itemheal_regeneration_factor", - &battle_config.itemheal_regeneration_factor}, - { - "item_name_override_grffile", - &battle_config.item_name_override_grffile}, - { - "arrow_decrement", &battle_config.arrow_decrement}, - { - "max_aspd", &battle_config.max_aspd}, - { - "max_hp", &battle_config.max_hp}, - { - "max_sp", &battle_config.max_sp}, - { - "max_lv", &battle_config.max_lv}, - { - "max_parameter", &battle_config.max_parameter}, - { - "max_cart_weight", &battle_config.max_cart_weight}, - { - "player_skill_log", &battle_config.pc_skill_log}, - { - "monster_skill_log", &battle_config.mob_skill_log}, - { - "battle_log", &battle_config.battle_log}, - { - "save_log", &battle_config.save_log}, - { - "error_log", &battle_config.error_log}, - { - "etc_log", &battle_config.etc_log}, - { - "save_clothcolor", &battle_config.save_clothcolor}, - { - "undead_detect_type", &battle_config.undead_detect_type}, - { - "player_auto_counter_type", - &battle_config.pc_auto_counter_type}, - { - "monster_auto_counter_type", - &battle_config.monster_auto_counter_type}, - { - "agi_penaly_type", &battle_config.agi_penaly_type}, - { - "agi_penaly_count", &battle_config.agi_penaly_count}, - { - "agi_penaly_num", &battle_config.agi_penaly_num}, - { - "agi_penaly_count_lv", &battle_config.agi_penaly_count_lv}, - { - "vit_penaly_type", &battle_config.vit_penaly_type}, - { - "vit_penaly_count", &battle_config.vit_penaly_count}, - { - "vit_penaly_num", &battle_config.vit_penaly_num}, - { - "vit_penaly_count_lv", &battle_config.vit_penaly_count_lv}, - { - "player_defense_type", &battle_config.player_defense_type}, - { - "monster_defense_type", &battle_config.monster_defense_type}, - { - "magic_defense_type", &battle_config.magic_defense_type}, - { - "player_skill_reiteration", - &battle_config.pc_skill_reiteration}, - { - "monster_skill_reiteration", - &battle_config.monster_skill_reiteration}, - { - "player_skill_nofootset", &battle_config.pc_skill_nofootset}, - { - "monster_skill_nofootset", - &battle_config.monster_skill_nofootset}, - { - "player_cloak_check_type", &battle_config.pc_cloak_check_type}, - { - "monster_cloak_check_type", - &battle_config.monster_cloak_check_type}, - { - "mob_changetarget_byskill", - &battle_config.mob_changetarget_byskill}, - { - "player_attack_direction_change", - &battle_config.pc_attack_direction_change}, - { - "monster_attack_direction_change", - &battle_config.monster_attack_direction_change}, - { - "player_land_skill_limit", &battle_config.pc_land_skill_limit}, - { - "monster_land_skill_limit", - &battle_config.monster_land_skill_limit}, - { - "party_skill_penaly", &battle_config.party_skill_penaly}, - { - "monster_class_change_full_recover", - &battle_config.monster_class_change_full_recover}, - { - "produce_item_name_input", - &battle_config.produce_item_name_input}, - { - "produce_potion_name_input", - &battle_config.produce_potion_name_input}, - { - "making_arrow_name_input", - &battle_config.making_arrow_name_input}, - { - "holywater_name_input", &battle_config.holywater_name_input}, - { - "display_delay_skill_fail", - &battle_config.display_delay_skill_fail}, - { - "chat_warpportal", &battle_config.chat_warpportal}, - { - "mob_warpportal", &battle_config.mob_warpportal}, - { - "dead_branch_active", &battle_config.dead_branch_active}, - { - "show_steal_in_same_party", - &battle_config.show_steal_in_same_party}, - { - "enable_upper_class", &battle_config.enable_upper_class}, - { - "mob_attack_attr_none", &battle_config.mob_attack_attr_none}, - { - "mob_ghostring_fix", &battle_config.mob_ghostring_fix}, - { - "pc_attack_attr_none", &battle_config.pc_attack_attr_none}, - { - "gx_allhit", &battle_config.gx_allhit}, - { - "gx_cardfix", &battle_config.gx_cardfix}, - { - "gx_dupele", &battle_config.gx_dupele}, - { - "gx_disptype", &battle_config.gx_disptype}, - { - "player_skill_partner_check", - &battle_config.player_skill_partner_check}, - { - "hide_GM_session", &battle_config.hide_GM_session}, - { - "unit_movement_type", &battle_config.unit_movement_type}, - { - "invite_request_check", &battle_config.invite_request_check}, - { - "skill_removetrap_type", &battle_config.skill_removetrap_type}, - { - "disp_experience", &battle_config.disp_experience}, - { - "riding_weight", &battle_config.riding_weight}, - { - "item_rate_common", &battle_config.item_rate_common}, // Added by RoVeRT - { - "item_rate_equip", &battle_config.item_rate_equip}, - { - "item_rate_card", &battle_config.item_rate_card}, // End Addition - { - "item_rate_heal", &battle_config.item_rate_heal}, // Added by Valaris - { - "item_rate_use", &battle_config.item_rate_use}, // End - { - "item_drop_common_min", &battle_config.item_drop_common_min}, // Added by TyrNemesis^ - { - "item_drop_common_max", &battle_config.item_drop_common_max}, - { - "item_drop_equip_min", &battle_config.item_drop_equip_min}, - { - "item_drop_equip_max", &battle_config.item_drop_equip_max}, - { - "item_drop_card_min", &battle_config.item_drop_card_min}, - { - "item_drop_card_max", &battle_config.item_drop_card_max}, - { - "item_drop_mvp_min", &battle_config.item_drop_mvp_min}, - { - "item_drop_mvp_max", &battle_config.item_drop_mvp_max}, // End Addition - { - "prevent_logout", &battle_config.prevent_logout}, // Added by RoVeRT - { - "alchemist_summon_reward", &battle_config.alchemist_summon_reward}, // [Valaris] - { - "maximum_level", &battle_config.maximum_level}, // [Valaris] - { - "drops_by_luk", &battle_config.drops_by_luk}, // [Valaris] - { - "monsters_ignore_gm", &battle_config.monsters_ignore_gm}, // [Valaris] - { - "equipment_breaking", &battle_config.equipment_breaking}, // [Valaris] - { - "equipment_break_rate", &battle_config.equipment_break_rate}, // [Valaris] - { - "pk_mode", &battle_config.pk_mode}, // [Valaris] - { - "multi_level_up", &battle_config.multi_level_up}, // [Valaris] - { - "backstab_bow_penalty", &battle_config.backstab_bow_penalty}, - { - "night_at_start", &battle_config.night_at_start}, // added by [Yor] - { - "day_duration", &battle_config.day_duration}, // added by [Yor] - { - "night_duration", &battle_config.night_duration}, // added by [Yor] - { - "show_mob_hp", &battle_config.show_mob_hp}, // [Valaris] - { - "hack_info_GM_level", &battle_config.hack_info_GM_level}, // added by [Yor] - { - "any_warp_GM_min_level", &battle_config.any_warp_GM_min_level}, // added by [Yor] - { - "packet_ver_flag", &battle_config.packet_ver_flag}, // added by [Yor] - { - "min_hair_style", &battle_config.min_hair_style}, // added by [MouseJstr] - { - "max_hair_style", &battle_config.max_hair_style}, // added by [MouseJstr] - { - "min_hair_color", &battle_config.min_hair_color}, // added by [MouseJstr] - { - "max_hair_color", &battle_config.max_hair_color}, // added by [MouseJstr] - { - "min_cloth_color", &battle_config.min_cloth_color}, // added by [MouseJstr] - { - "max_cloth_color", &battle_config.max_cloth_color}, // added by [MouseJstr] - { - "castrate_dex_scale", &battle_config.castrate_dex_scale}, // added by [MouseJstr] - { - "area_size", &battle_config.area_size}, // added by [MouseJstr] - { - "muting_players", &battle_config.muting_players}, // added by [Apple] - { - "chat_lame_penalty", &battle_config.chat_lame_penalty}, - { - "chat_spam_threshold", &battle_config.chat_spam_threshold}, - { - "chat_spam_flood", &battle_config.chat_spam_flood}, - { - "chat_spam_ban", &battle_config.chat_spam_ban}, - { - "chat_spam_warn", &battle_config.chat_spam_warn}, - { - "chat_maxline", &battle_config.chat_maxline}, - { - "packet_spam_threshold", &battle_config.packet_spam_threshold}, - { - "packet_spam_flood", &battle_config.packet_spam_flood}, - { - "packet_spam_kick", &battle_config.packet_spam_kick}, - { - "mask_ip_gms", &battle_config.mask_ip_gms}, - { - "mob_splash_radius", &battle_config.mob_splash_radius}, + {"warp_point_debug", &battle_config.warp_point_debug}, + {"enemy_critical", &battle_config.enemy_critical}, + {"enemy_critical_rate", &battle_config.enemy_critical_rate}, + {"enemy_str", &battle_config.enemy_str}, + {"enemy_perfect_flee", &battle_config.enemy_perfect_flee}, + {"casting_rate", &battle_config.cast_rate}, + {"delay_rate", &battle_config.delay_rate}, + {"delay_dependon_dex", &battle_config.delay_dependon_dex}, + {"skill_delay_attack_enable", &battle_config.sdelay_attack_enable}, + {"left_cardfix_to_right", &battle_config.left_cardfix_to_right}, + {"player_skill_add_range", &battle_config.pc_skill_add_range}, + {"skill_out_range_consume", &battle_config.skill_out_range_consume}, + {"monster_skill_add_range", &battle_config.mob_skill_add_range}, + {"player_damage_delay", &battle_config.pc_damage_delay}, + {"player_damage_delay_rate", &battle_config.pc_damage_delay_rate}, + {"defunit_not_enemy", &battle_config.defnotenemy}, + {"random_monster_checklv", &battle_config.random_monster_checklv}, + {"attribute_recover", &battle_config.attr_recover}, + {"flooritem_lifetime", &battle_config.flooritem_lifetime}, + {"item_auto_get", &battle_config.item_auto_get}, + {"drop_pickup_safety_zone", &battle_config.drop_pickup_safety_zone}, + {"item_first_get_time", &battle_config.item_first_get_time}, + {"item_second_get_time", &battle_config.item_second_get_time}, + {"item_third_get_time", &battle_config.item_third_get_time}, + {"mvp_item_first_get_time", &battle_config.mvp_item_first_get_time}, + {"mvp_item_second_get_time", &battle_config.mvp_item_second_get_time}, + {"mvp_item_third_get_time", &battle_config.mvp_item_third_get_time}, + {"item_rate", &battle_config.item_rate}, + {"drop_rate0item", &battle_config.drop_rate0item}, + {"base_exp_rate", &battle_config.base_exp_rate}, + {"job_exp_rate", &battle_config.job_exp_rate}, + {"pvp_exp", &battle_config.pvp_exp}, + {"gtb_pvp_only", &battle_config.gtb_pvp_only}, + {"death_penalty_type", &battle_config.death_penalty_type}, + {"death_penalty_base", &battle_config.death_penalty_base}, + {"death_penalty_job", &battle_config.death_penalty_job}, + {"zeny_penalty", &battle_config.zeny_penalty}, + {"restart_hp_rate", &battle_config.restart_hp_rate}, + {"restart_sp_rate", &battle_config.restart_sp_rate}, + {"mvp_hp_rate", &battle_config.mvp_hp_rate}, + {"mvp_item_rate", &battle_config.mvp_item_rate}, + {"mvp_exp_rate", &battle_config.mvp_exp_rate}, + {"monster_hp_rate", &battle_config.monster_hp_rate}, + {"monster_max_aspd", &battle_config.monster_max_aspd}, + {"atcommand_gm_only", &battle_config.atc_gmonly}, + {"atcommand_spawn_quantity_limit", &battle_config.atc_spawn_quantity_limit}, + {"gm_all_skill", &battle_config.gm_allskill}, + {"gm_all_skill_add_abra", &battle_config.gm_allskill_addabra}, + {"gm_all_equipment", &battle_config.gm_allequip}, + {"gm_skill_unconditional", &battle_config.gm_skilluncond}, + {"player_skillfree", &battle_config.skillfree}, + {"player_skillup_limit", &battle_config.skillup_limit}, + {"weapon_produce_rate", &battle_config.wp_rate}, + {"potion_produce_rate", &battle_config.pp_rate}, + {"monster_active_enable", &battle_config.monster_active_enable}, + {"monster_damage_delay_rate", &battle_config.monster_damage_delay_rate}, + {"monster_loot_type", &battle_config.monster_loot_type}, + {"mob_skill_use", &battle_config.mob_skill_use}, + {"mob_count_rate", &battle_config.mob_count_rate}, + {"quest_skill_learn", &battle_config.quest_skill_learn}, + {"quest_skill_reset", &battle_config.quest_skill_reset}, + {"basic_skill_check", &battle_config.basic_skill_check}, + {"player_invincible_time", &battle_config.pc_invincible_time}, + {"skill_min_damage", &battle_config.skill_min_damage}, + {"finger_offensive_type", &battle_config.finger_offensive_type}, + {"heal_exp", &battle_config.heal_exp}, + {"resurrection_exp", &battle_config.resurrection_exp}, + {"shop_exp", &battle_config.shop_exp}, + {"combo_delay_rate", &battle_config.combo_delay_rate}, + {"item_check", &battle_config.item_check}, + {"wedding_modifydisplay", &battle_config.wedding_modifydisplay}, + {"natural_healhp_interval", &battle_config.natural_healhp_interval}, + {"natural_healsp_interval", &battle_config.natural_healsp_interval}, + {"natural_heal_skill_interval", &battle_config.natural_heal_skill_interval}, + {"natural_heal_weight_rate", &battle_config.natural_heal_weight_rate}, + {"itemheal_regeneration_factor", &battle_config.itemheal_regeneration_factor}, + {"item_name_override_grffile", &battle_config.item_name_override_grffile}, + {"arrow_decrement", &battle_config.arrow_decrement}, + {"max_aspd", &battle_config.max_aspd}, + {"max_hp", &battle_config.max_hp}, + {"max_sp", &battle_config.max_sp}, + {"max_lv", &battle_config.max_lv}, + {"max_parameter", &battle_config.max_parameter}, + {"max_cart_weight", &battle_config.max_cart_weight}, + {"player_skill_log", &battle_config.pc_skill_log}, + {"monster_skill_log", &battle_config.mob_skill_log}, + {"battle_log", &battle_config.battle_log}, + {"save_log", &battle_config.save_log}, + {"error_log", &battle_config.error_log}, + {"etc_log", &battle_config.etc_log}, + {"save_clothcolor", &battle_config.save_clothcolor}, + {"undead_detect_type", &battle_config.undead_detect_type}, + {"player_auto_counter_type", &battle_config.pc_auto_counter_type}, + {"monster_auto_counter_type", &battle_config.monster_auto_counter_type}, + {"agi_penaly_type", &battle_config.agi_penaly_type}, + {"agi_penaly_count", &battle_config.agi_penaly_count}, + {"agi_penaly_num", &battle_config.agi_penaly_num}, + {"agi_penaly_count_lv", &battle_config.agi_penaly_count_lv}, + {"vit_penaly_type", &battle_config.vit_penaly_type}, + {"vit_penaly_count", &battle_config.vit_penaly_count}, + {"vit_penaly_num", &battle_config.vit_penaly_num}, + {"vit_penaly_count_lv", &battle_config.vit_penaly_count_lv}, + {"player_defense_type", &battle_config.player_defense_type}, + {"monster_defense_type", &battle_config.monster_defense_type}, + {"magic_defense_type", &battle_config.magic_defense_type}, + {"player_skill_reiteration", &battle_config.pc_skill_reiteration}, + {"monster_skill_reiteration", &battle_config.monster_skill_reiteration}, + {"player_skill_nofootset", &battle_config.pc_skill_nofootset}, + {"monster_skill_nofootset", &battle_config.monster_skill_nofootset}, + {"player_cloak_check_type", &battle_config.pc_cloak_check_type}, + {"monster_cloak_check_type", &battle_config.monster_cloak_check_type}, + {"mob_changetarget_byskill", &battle_config.mob_changetarget_byskill}, + {"player_attack_direction_change", &battle_config.pc_attack_direction_change}, + {"monster_attack_direction_change", &battle_config.monster_attack_direction_change}, + {"player_land_skill_limit", &battle_config.pc_land_skill_limit}, + {"monster_land_skill_limit", &battle_config.monster_land_skill_limit}, + {"party_skill_penaly", &battle_config.party_skill_penaly}, + {"monster_class_change_full_recover", &battle_config.monster_class_change_full_recover}, + {"produce_item_name_input", &battle_config.produce_item_name_input}, + {"produce_potion_name_input", &battle_config.produce_potion_name_input}, + {"making_arrow_name_input", &battle_config.making_arrow_name_input}, + {"holywater_name_input", &battle_config.holywater_name_input}, + {"display_delay_skill_fail", &battle_config.display_delay_skill_fail}, + {"chat_warpportal", &battle_config.chat_warpportal}, + {"mob_warpportal", &battle_config.mob_warpportal}, + {"dead_branch_active", &battle_config.dead_branch_active}, + {"show_steal_in_same_party", &battle_config.show_steal_in_same_party}, + {"enable_upper_class", &battle_config.enable_upper_class}, + {"mob_attack_attr_none", &battle_config.mob_attack_attr_none}, + {"mob_ghostring_fix", &battle_config.mob_ghostring_fix}, + {"pc_attack_attr_none", &battle_config.pc_attack_attr_none}, + {"gx_allhit", &battle_config.gx_allhit}, + {"gx_cardfix", &battle_config.gx_cardfix}, + {"gx_dupele", &battle_config.gx_dupele}, + {"gx_disptype", &battle_config.gx_disptype}, + {"player_skill_partner_check", &battle_config.player_skill_partner_check}, + {"hide_GM_session", &battle_config.hide_GM_session}, + {"unit_movement_type", &battle_config.unit_movement_type}, + {"invite_request_check", &battle_config.invite_request_check}, + {"skill_removetrap_type", &battle_config.skill_removetrap_type}, + {"disp_experience", &battle_config.disp_experience}, + {"riding_weight", &battle_config.riding_weight}, + {"item_rate_common", &battle_config.item_rate_common}, // Added by RoVeRT + {"item_rate_equip", &battle_config.item_rate_equip}, + {"item_rate_card", &battle_config.item_rate_card}, // End Addition + {"item_rate_heal", &battle_config.item_rate_heal}, // Added by Valaris + {"item_rate_use", &battle_config.item_rate_use}, // End + {"item_drop_common_min", &battle_config.item_drop_common_min}, // Added by TyrNemesis^ + {"item_drop_common_max", &battle_config.item_drop_common_max}, + {"item_drop_equip_min", &battle_config.item_drop_equip_min}, + {"item_drop_equip_max", &battle_config.item_drop_equip_max}, + {"item_drop_card_min", &battle_config.item_drop_card_min}, + {"item_drop_card_max", &battle_config.item_drop_card_max}, + {"item_drop_mvp_min", &battle_config.item_drop_mvp_min}, + {"item_drop_mvp_max", &battle_config.item_drop_mvp_max}, // End Addition + {"prevent_logout", &battle_config.prevent_logout}, // Added by RoVeRT + {"alchemist_summon_reward", &battle_config.alchemist_summon_reward}, // [Valaris] + {"maximum_level", &battle_config.maximum_level}, // [Valaris] + {"drops_by_luk", &battle_config.drops_by_luk}, // [Valaris] + {"monsters_ignore_gm", &battle_config.monsters_ignore_gm}, // [Valaris] + {"equipment_breaking", &battle_config.equipment_breaking}, // [Valaris] + {"equipment_break_rate", &battle_config.equipment_break_rate}, // [Valaris] + {"pk_mode", &battle_config.pk_mode}, // [Valaris] + {"multi_level_up", &battle_config.multi_level_up}, // [Valaris] + {"backstab_bow_penalty", &battle_config.backstab_bow_penalty}, + {"night_at_start", &battle_config.night_at_start}, // added by [Yor] + {"day_duration", &battle_config.day_duration}, // added by [Yor] + {"night_duration", &battle_config.night_duration}, // added by [Yor] + {"show_mob_hp", &battle_config.show_mob_hp}, // [Valaris] + {"hack_info_GM_level", &battle_config.hack_info_GM_level}, // added by [Yor] + {"any_warp_GM_min_level", &battle_config.any_warp_GM_min_level}, // added by [Yor] + {"packet_ver_flag", &battle_config.packet_ver_flag}, // added by [Yor] + {"min_hair_style", &battle_config.min_hair_style}, // added by [MouseJstr] + {"max_hair_style", &battle_config.max_hair_style}, // added by [MouseJstr] + {"min_hair_color", &battle_config.min_hair_color}, // added by [MouseJstr] + {"max_hair_color", &battle_config.max_hair_color}, // added by [MouseJstr] + {"min_cloth_color", &battle_config.min_cloth_color}, // added by [MouseJstr] + {"max_cloth_color", &battle_config.max_cloth_color}, // added by [MouseJstr] + {"castrate_dex_scale", &battle_config.castrate_dex_scale}, // added by [MouseJstr] + {"area_size", &battle_config.area_size}, // added by [MouseJstr] + {"muting_players", &battle_config.muting_players}, // added by [Apple] + {"chat_lame_penalty", &battle_config.chat_lame_penalty}, + {"chat_spam_threshold", &battle_config.chat_spam_threshold}, + {"chat_spam_flood", &battle_config.chat_spam_flood}, + {"chat_spam_ban", &battle_config.chat_spam_ban}, + {"chat_spam_warn", &battle_config.chat_spam_warn}, + {"chat_maxline", &battle_config.chat_maxline}, + {"packet_spam_threshold", &battle_config.packet_spam_threshold}, + {"packet_spam_flood", &battle_config.packet_spam_flood}, + {"packet_spam_kick", &battle_config.packet_spam_kick}, + {"mask_ip_gms", &battle_config.mask_ip_gms}, + {"mob_splash_radius", &battle_config.mob_splash_radius}, }; - if (line[0] == '/' && line[1] == '/') + std::string w1, w2; + if (!split_key_value(line, &w1, &w2)) continue; - if (sscanf(line, "%[^:]:%s", w1, w2) != 2) + + if (w1 == "import") + { + battle_config_read(w2.c_str()); continue; - for (i = 0; i < sizeof(data) / (sizeof(data[0])); i++) - if (strcasecmp(w1, data[i].str) == 0) - *data[i].val = config_switch(w2); + } + + for (auto datum : data) + if (w1 == datum.str) + { + *datum.val = config_switch(w2.c_str()); + goto continue_outer; + } + + PRINTF("WARNING: unknown battle conf key: %s", w1); - if (strcasecmp(w1, "import") == 0) - battle_config_read(w2); + continue_outer: + ; } - fclose_(fp); if (--count == 0) { diff --git a/src/map/chrif.cpp b/src/map/chrif.cpp index c7b8554..41c1381 100644 --- a/src/map/chrif.cpp +++ b/src/map/chrif.cpp @@ -12,6 +12,7 @@ #include #include +#include "../common/cxxstdio.hpp" #include "../common/nullpo.hpp" #include "../common/socket.hpp" #include "../common/timer.hpp" @@ -50,20 +51,18 @@ int chrif_state; * *------------------------------------------ */ -void chrif_setuserid(char *id) +void chrif_setuserid(const char *id) { - strncpy(userid, id, sizeof(userid)-1); - userid[sizeof(userid)-1] = '\0'; + strzcpy(userid, id, sizeof(userid)); } /*========================================== * *------------------------------------------ */ -void chrif_setpasswd(char *pwd) +void chrif_setpasswd(const char *pwd) { - strncpy(passwd, pwd, sizeof(passwd)-1); - passwd[sizeof(passwd)-1] = '\0'; + strzcpy(passwd, pwd, sizeof(passwd)); } char *chrif_getpasswd(void) @@ -75,10 +74,9 @@ char *chrif_getpasswd(void) * *------------------------------------------ */ -void chrif_setip(char *ip) +void chrif_setip(const char *ip) { - strncpy(char_ip_str, ip, sizeof(char_ip_str)-1); - char_ip_str[sizeof(char_ip_str)-1] = '\0'; + strzcpy(char_ip_str, ip, sizeof(char_ip_str)); char_ip = inet_addr(char_ip_str); } @@ -185,10 +183,10 @@ int chrif_recvmap(int fd) { map_setipport((const char *)RFIFOP(fd, i), ip, port); // if (battle_config.etc_log) -// printf("recv map %d %s\n", j, RFIFOP(fd,i)); +// PRINTF("recv map %d %s\n", j, RFIFOP(fd,i)); } if (battle_config.etc_log) - printf("recv map on %s:%d (%d maps)\n", ip2str(ip), port, j); + PRINTF("recv map on %s:%d (%d maps)\n", ip2str(ip), port, j); return 0; } @@ -244,7 +242,7 @@ int chrif_changemapserverack(int fd) if (RFIFOL(fd, 6) == 1) { if (battle_config.error_log) - printf("map server change failed.\n"); + PRINTF("map server change failed.\n"); pc_authfail(sd->fd); return 0; } @@ -263,21 +261,21 @@ int chrif_connectack(int fd) { if (RFIFOB(fd, 2)) { - printf("Connected to char-server failed %d.\n", RFIFOB(fd, 2)); + PRINTF("Connected to char-server failed %d.\n", RFIFOB(fd, 2)); exit(1); } - printf("Connected to char-server (connection #%d).\n", fd); + PRINTF("Connected to char-server (connection #%d).\n", fd); chrif_state = 1; chrif_sendmap(fd); - printf("chrif: OnCharIfInit event done. (%d events)\n", + PRINTF("chrif: OnCharIfInit event done. (%d events)\n", npc_event_doall("OnCharIfInit")); - printf("chrif: OnInterIfInit event done. (%d events)\n", + PRINTF("chrif: OnInterIfInit event done. (%d events)\n", npc_event_doall("OnInterIfInit")); // Run Event [AgitInit] -// printf("NPC_Event:[OnAgitInit] do (%d) events (Agit Initialize).\n", npc_event_doall("OnAgitInit")); +// PRINTF("NPC_Event:[OnAgitInit] do (%d) events (Agit Initialize).\n", npc_event_doall("OnAgitInit")); return 0; } @@ -291,7 +289,7 @@ int chrif_sendmapack(int fd) { if (RFIFOB(fd, 2)) { - printf("chrif : send map list to char server failed %d\n", + PRINTF("chrif : send map list to char server failed %d\n", RFIFOB(fd, 2)); exit(1); } @@ -386,7 +384,7 @@ int chrif_searchcharid(int char_id) int chrif_changegm(int id, const char *pass, int len) { if (battle_config.etc_log) - printf("chrif_changegm: account: %d, password: '%s'.\n", id, pass); + PRINTF("chrif_changegm: account: %d, password: '%s'.\n", id, pass); WFIFOW(char_fd, 0) = 0x2b0a; WFIFOW(char_fd, 2) = len + 8; @@ -405,7 +403,7 @@ int chrif_changeemail(int id, const char *actual_email, const char *new_email) { if (battle_config.etc_log) - printf("chrif_changeemail: account: %d, actual_email: '%s', new_email: '%s'.\n", + PRINTF("chrif_changeemail: account: %d, actual_email: '%s', new_email: '%s'.\n", id, actual_email, new_email); WFIFOW(char_fd, 0) = 0x2b0c; @@ -445,7 +443,7 @@ int chrif_char_ask_name(int id, char *character_name, short operation_type, WFIFOW(char_fd, 40) = minute; WFIFOW(char_fd, 42) = second; } - printf("chrif : sended 0x2b0e\n"); + PRINTF("chrif : sended 0x2b0e\n"); WFIFOSET(char_fd, 44); return 0; @@ -472,7 +470,6 @@ int chrif_char_ask_name_answer(int fd) { int acc; struct map_session_data *sd; - char output[256]; char player_name[24]; acc = RFIFOL(fd, 2); // account_id of who has asked (-1 if nobody) @@ -482,8 +479,10 @@ int chrif_char_ask_name_answer(int fd) sd = map_id2sd(acc); if (acc >= 0 && sd != NULL) { + std::string output; if (RFIFOW(fd, 32) == 1) // player not found - sprintf(output, "The player '%s' doesn't exist.", player_name); + output = STRPRINTF("The player '%s' doesn't exist.", + player_name); else { switch (RFIFOW(fd, 30)) @@ -492,20 +491,20 @@ int chrif_char_ask_name_answer(int fd) switch (RFIFOW(fd, 32)) { case 0: // login-server resquest done - sprintf(output, - "Login-server has been asked to block the player '%s'.", - player_name); + output = STRPRINTF( + "Login-server has been asked to block the player '%s'.", + player_name); break; //case 1: // player not found case 2: // gm level too low - sprintf(output, - "Your GM level don't authorise you to block the player '%s'.", - player_name); + output = STRPRINTF( + "Your GM level don't authorise you to block the player '%s'.", + player_name); break; case 3: // login-server offline - sprintf(output, - "Login-server is offline. Impossible to block the the player '%s'.", - player_name); + output = STRPRINTF( + "Login-server is offline. Impossible to block the the player '%s'.", + player_name); break; } break; @@ -513,20 +512,20 @@ int chrif_char_ask_name_answer(int fd) switch (RFIFOW(fd, 32)) { case 0: // login-server resquest done - sprintf(output, - "Login-server has been asked to ban the player '%s'.", - player_name); + output = STRPRINTF( + "Login-server has been asked to ban the player '%s'.", + player_name); break; //case 1: // player not found case 2: // gm level too low - sprintf(output, - "Your GM level don't authorise you to ban the player '%s'.", - player_name); + output = STRPRINTF( + "Your GM level don't authorise you to ban the player '%s'.", + player_name); break; case 3: // login-server offline - sprintf(output, - "Login-server is offline. Impossible to ban the the player '%s'.", - player_name); + output = STRPRINTF( + "Login-server is offline. Impossible to ban the the player '%s'.", + player_name); break; } break; @@ -534,20 +533,20 @@ int chrif_char_ask_name_answer(int fd) switch (RFIFOW(fd, 32)) { case 0: // login-server resquest done - sprintf(output, - "Login-server has been asked to unblock the player '%s'.", - player_name); + output = STRPRINTF( + "Login-server has been asked to unblock the player '%s'.", + player_name); break; //case 1: // player not found case 2: // gm level too low - sprintf(output, - "Your GM level don't authorise you to unblock the player '%s'.", - player_name); + output = STRPRINTF( + "Your GM level don't authorise you to unblock the player '%s'.", + player_name); break; case 3: // login-server offline - sprintf(output, - "Login-server is offline. Impossible to unblock the the player '%s'.", - player_name); + output = STRPRINTF( + "Login-server is offline. Impossible to unblock the the player '%s'.", + player_name); break; } break; @@ -555,20 +554,20 @@ int chrif_char_ask_name_answer(int fd) switch (RFIFOW(fd, 32)) { case 0: // login-server resquest done - sprintf(output, - "Login-server has been asked to unban the player '%s'.", - player_name); + output = STRPRINTF( + "Login-server has been asked to unban the player '%s'.", + player_name); break; //case 1: // player not found case 2: // gm level too low - sprintf(output, - "Your GM level don't authorise you to unban the player '%s'.", - player_name); + output = STRPRINTF( + "Your GM level don't authorise you to unban the player '%s'.", + player_name); break; case 3: // login-server offline - sprintf(output, - "Login-server is offline. Impossible to unban the the player '%s'.", - player_name); + output = STRPRINTF( + "Login-server is offline. Impossible to unban the the player '%s'.", + player_name); break; } break; @@ -576,33 +575,30 @@ int chrif_char_ask_name_answer(int fd) switch (RFIFOW(fd, 32)) { case 0: // login-server resquest done - sprintf(output, - "Login-server has been asked to change the sex of the player '%s'.", - player_name); + output = STRPRINTF( + "Login-server has been asked to change the sex of the player '%s'.", + player_name); break; //case 1: // player not found case 2: // gm level too low - sprintf(output, - "Your GM level don't authorise you to change the sex of the player '%s'.", - player_name); + output = STRPRINTF( + "Your GM level don't authorise you to change the sex of the player '%s'.", + player_name); break; case 3: // login-server offline - sprintf(output, - "Login-server is offline. Impossible to change the sex of the the player '%s'.", - player_name); + output = STRPRINTF( + "Login-server is offline. Impossible to change the sex of the the player '%s'.", + player_name); break; } break; } } - if (output[0] != '\0') - { - output[sizeof(output) - 1] = '\0'; + if (!output.empty()) clif_displaymessage(sd->fd, output); - } } else - printf("chrif_char_ask_name_answer failed - player not online.\n"); + PRINTF("chrif_char_ask_name_answer failed - player not online.\n"); return 0; } @@ -623,7 +619,7 @@ int chrif_changedgm(int fd) sd = map_id2sd(acc); if (battle_config.etc_log) - printf("chrif_changedgm: account: %d, GM level 0 -> %d.\n", acc, + PRINTF("chrif_changedgm: account: %d, GM level 0 -> %d.\n", acc, level); if (sd != NULL) { @@ -650,7 +646,7 @@ int chrif_changedsex(int fd) acc = RFIFOL(fd, 2); sex = RFIFOL(fd, 6); if (battle_config.etc_log) - printf("chrif_changedsex %d.\n", acc); + PRINTF("chrif_changedsex %d.\n", acc); sd = map_id2sd(acc); if (acc > 0) { @@ -702,7 +698,7 @@ int chrif_changedsex(int fd) { if (sd != NULL) { - printf("chrif_changedsex failed.\n"); + PRINTF("chrif_changedsex failed.\n"); } } @@ -757,7 +753,7 @@ int chrif_accountreg2(int fd) sd->status.account_reg2[j].value = RFIFOL(fd, p + 32); } sd->status.account_reg2_num = j; -// printf("chrif: accountreg2\n"); +// PRINTF("chrif: accountreg2\n"); return 0; } @@ -823,7 +819,7 @@ int chrif_accountdeletion(int fd) acc = RFIFOL(fd, 2); if (battle_config.etc_log) - printf("chrif_accountdeletion %d.\n", acc); + PRINTF("chrif_accountdeletion %d.\n", acc); sd = map_id2sd(acc); if (acc > 0) { @@ -838,7 +834,7 @@ int chrif_accountdeletion(int fd) else { if (sd != NULL) - printf("chrif_accountdeletion failed - player not online.\n"); + PRINTF("chrif_accountdeletion failed - player not online.\n"); } return 0; @@ -856,7 +852,7 @@ int chrif_accountban(int fd) acc = RFIFOL(fd, 2); if (battle_config.etc_log) - printf("chrif_accountban %d.\n", acc); + PRINTF("chrif_accountban %d.\n", acc); sd = map_id2sd(acc); if (acc > 0) { @@ -929,7 +925,7 @@ int chrif_accountban(int fd) else { if (sd != NULL) - printf("chrif_accountban failed - player not online.\n"); + PRINTF("chrif_accountban failed - player not online.\n"); } return 0; @@ -942,7 +938,7 @@ int chrif_accountban(int fd) static int chrif_recvgmaccounts(int fd) { - printf("From login-server: receiving of %d GM accounts information.\n", + PRINTF("From login-server: receiving of %d GM accounts information.\n", pc_read_gm_account(fd)); return 0; @@ -1081,7 +1077,7 @@ void chrif_parse(int fd) { if (fd == char_fd) { - printf("Map-server can't connect to char-server (connection #%d).\n", + PRINTF("Map-server can't connect to char-server (connection #%d).\n", fd); char_fd = -1; } @@ -1181,7 +1177,7 @@ void chrif_parse(int fd) default: if (battle_config.error_log) - printf("chrif_parse : unknown packet %d %d\n", fd, + PRINTF("chrif_parse : unknown packet %d %d\n", fd, RFIFOW(fd, 0)); session[fd]->eof = 1; return; @@ -1231,7 +1227,7 @@ void check_connect_char_server(timer_id, tick_t, custom_id_t, custom_data_t) { if (char_fd <= 0 || session[char_fd] == NULL) { - printf("Attempt to connect to char-server...\n"); + PRINTF("Attempt to connect to char-server...\n"); chrif_state = 0; if ((char_fd = make_connection(char_ip, char_port)) < 0) return; diff --git a/src/map/chrif.hpp b/src/map/chrif.hpp index b262a7f..7c4a431 100644 --- a/src/map/chrif.hpp +++ b/src/map/chrif.hpp @@ -1,11 +1,11 @@ #ifndef CHRIF_HPP #define CHRIF_HPP -void chrif_setuserid(char *); -void chrif_setpasswd(char *); +void chrif_setuserid(const char *); +void chrif_setpasswd(const char *); char *chrif_getpasswd(void); -void chrif_setip(char *); +void chrif_setip(const char *); void chrif_setport(int); int chrif_isconnect(void); diff --git a/src/map/clif.cpp b/src/map/clif.cpp index cf47d2f..913a6ac 100644 --- a/src/map/clif.cpp +++ b/src/map/clif.cpp @@ -13,6 +13,7 @@ #include #include +#include "../common/cxxstdio.hpp" #include "../common/md5calc.hpp" #include "../common/mt_rand.hpp" #include "../common/nullpo.hpp" @@ -280,10 +281,10 @@ void clif_send_sub(struct block_list *bl, const unsigned char *buf, int len, { if (WFIFOP(sd->fd, 0) == buf) { - printf("WARNING: Invalid use of clif_send function\n"); - printf(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n", + PRINTF("WARNING: Invalid use of clif_send function\n"); + PRINTF(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n", WBUFW(buf, 0)); - printf(" Please correct your code.\n"); + PRINTF(" Please correct your code.\n"); // don't send to not move the pointer of the packet for next sessions in the loop } else @@ -482,7 +483,7 @@ int clif_send(const uint8_t *buf, int len, struct block_list *bl, SendWho type) default: if (battle_config.error_log) - printf("clif_send まだ作ってないよー\n"); + PRINTF("clif_send まだ作ってないよー\n"); return -1; } @@ -2127,8 +2128,8 @@ int clif_updatestatus(struct map_session_data *sd, SP type) default: if (battle_config.error_log) - printf("clif_updatestatus : make %d routine\n", - uint16_t(type)); + PRINTF("clif_updatestatus : make %d routine\n", + type); return 1; } WFIFOSET(fd, len); @@ -3099,8 +3100,8 @@ void clif_getareachar(struct block_list *bl, struct map_session_data *sd) break; default: if (battle_config.error_log) - printf("get area char ??? %d\n", - uint8_t(bl->type)); + PRINTF("get area char ??? %d\n", + bl->type); break; } } @@ -3432,43 +3433,39 @@ int clif_status_change(struct block_list *bl, StatusChange type, int flag) * Send message (modified by [Yor]) *------------------------------------------ */ -int clif_displaymessage(int fd, const char *mes) +void clif_displaymessage(int fd, const_string mes) { - int len_mes = strlen(mes); - - if (len_mes > 0) - { // don't send a void message (it's not displaying on the client chat). @help can send void line. + if (mes) + { + // don't send a void message (it's not displaying on the client chat). @help can send void line. WFIFOW(fd, 0) = 0x8e; - WFIFOW(fd, 2) = 5 + len_mes; // 4 + len + NULL teminate - memcpy(WFIFOP(fd, 4), mes, len_mes + 1); - WFIFOSET(fd, 5 + len_mes); + WFIFOW(fd, 2) = 5 + mes.size(); // 4 + len + NULL teminate + memcpy(WFIFOP(fd, 4), mes.data(), mes.size()); + WFIFOB(fd, 4 + mes.size()) = '\0'; + WFIFOSET(fd, 5 + mes.size()); } - - return 0; } /*========================================== * 天の声を送信する *------------------------------------------ */ -int clif_GMmessage(struct block_list *bl, const char *mes, int len, int flag) +void clif_GMmessage(struct block_list *bl, const_string mes, int flag) { - unsigned char lbuf[255]; - unsigned char *buf = - ((len + 16) >= sizeof(lbuf)) ? (unsigned char*)malloc(len + 16) : lbuf; + unsigned char buf[mes.size() + 16]; int lp = (flag & 0x10) ? 8 : 4; WBUFW(buf, 0) = 0x9a; - WBUFW(buf, 2) = len + lp; + WBUFW(buf, 2) = mes.size() + 1 + lp; WBUFL(buf, 4) = 0x65756c62; - memcpy(WBUFP(buf, lp), mes, len); + memcpy(WBUFP(buf, lp), mes.data(), mes.size()); + WBUFB(buf, lp + mes.size()) = '\0'; flag &= 0x07; clif_send(buf, WBUFW(buf, 2), bl, (flag == 1) ? ALL_SAMEMAP : - (flag == 2) ? AREA : (flag == 3) ? SELF : ALL_CLIENT); - if (buf != lbuf) - free(buf); - return 0; + (flag == 2) ? AREA : + (flag == 3) ? SELF : + ALL_CLIENT); } /*========================================== @@ -3659,7 +3656,7 @@ int clif_party_option(struct party *p, struct map_session_data *sd, int flag) nullpo_ret(p); // if(battle_config.etc_log) -// printf("clif_party_option: %d %d %d\n",p->exp,p->item,flag); +// PRINTF("clif_party_option: %d %d %d\n",p->exp,p->item,flag); if (sd == NULL && flag == 0) { int i; @@ -3760,7 +3757,7 @@ int clif_party_xy(struct party *, struct map_session_data *sd) WBUFW(buf, 8) = sd->bl.y; clif_send(buf, packet_len_table[0x107], &sd->bl, PARTY_SAMEMAP_WOS); // if(battle_config.etc_log) -// printf("clif_party_xy %d\n",sd->status.account_id); +// PRINTF("clif_party_xy %d\n",sd->status.account_id); return 0; } @@ -3781,7 +3778,7 @@ int clif_party_hp(struct party *, struct map_session_data *sd) (sd->status.max_hp > 0x7fff) ? 0x7fff : sd->status.max_hp; clif_send(buf, packet_len_table[0x106], &sd->bl, PARTY_AREA_WOS); // if(battle_config.etc_log) -// printf("clif_party_hp %d\n",sd->status.account_id); +// PRINTF("clif_party_hp %d\n",sd->status.account_id); return 0; } @@ -3878,30 +3875,6 @@ void clif_sitting(int, struct map_session_data *sd) clif_send(buf, packet_len_table[0x8a], &sd->bl, AREA); } -/*========================================== - * - *------------------------------------------ - */ -int clif_disp_onlyself(struct map_session_data *sd, const char *mes, int len) -{ - unsigned char lbuf[255]; - unsigned char *buf = - (len + 32 >= sizeof(lbuf)) ? (unsigned char *)malloc(len + 32) : lbuf; - - nullpo_ret(sd); - - WBUFW(buf, 0) = 0x17f; - WBUFW(buf, 2) = len + 8; - memcpy(WBUFP(buf, 4), mes, len + 4); - - clif_send(buf, WBUFW(buf, 2), &sd->bl, SELF); - - if (buf != lbuf) - free(buf); - - return 0; -} - /*========================================== * *------------------------------------------ @@ -3988,7 +3961,7 @@ void clif_parse_WantToConnection(int fd, struct map_session_data *sd) if (sd) { if (battle_config.error_log) - printf("clif_parse_WantToConnection : invalid request?\n"); + PRINTF("clif_parse_WantToConnection : invalid request?\n"); return; } @@ -4007,7 +3980,7 @@ void clif_parse_WantToConnection(int fd, struct map_session_data *sd) { clif_authfail_fd(fd, 2); // same id clif_authfail_fd(old_sd->fd, 2); // same id - printf("clif_parse_WantToConnection: Double connection for account %d (sessions: #%d (new) and #%d (old)).\n", + PRINTF("clif_parse_WantToConnection: Double connection for account %d (sessions: #%d (new) and #%d (old)).\n", account_id, fd, old_sd->fd); } else @@ -4363,8 +4336,8 @@ void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd) break; default: if (battle_config.error_log) - printf("clif_parse_GetCharNameRequest : bad type %d (%d)\n", - uint8_t(bl->type), account_id); + PRINTF("clif_parse_GetCharNameRequest : bad type %d (%d)\n", + bl->type, account_id); break; } } @@ -4393,7 +4366,7 @@ void clif_parse_GlobalMessage(int fd, struct map_session_data *sd) return; } - if (is_atcommand(fd, sd, message, 0) != AtCommand_None + if (is_atcommand(fd, sd, message, 0) || ((sd->sc_data[SC_BERSERK].timer != -1 //バーサーク時は会話も不可 || sd->sc_data[SC_NOCHAT].timer != -1)))//チャット禁止 { @@ -4659,7 +4632,7 @@ void clif_parse_Wis(int fd, struct map_session_data *sd) return; } - if (is_atcommand(fd, sd, message, 0) != AtCommand_None + if (is_atcommand(fd, sd, message, 0) || ((sd->sc_data[SC_BERSERK].timer != -1 || sd->sc_data[SC_NOCHAT].timer != -1))) { @@ -4734,21 +4707,21 @@ void clif_parse_Wis(int fd, struct map_session_data *sd) static void clif_parse_GMmessage(int fd, struct map_session_data *sd) { - char m[512]; - char output[200]; + char m[(RFIFOW(fd, 2) - 4) + 1]; nullpo_retv(sd); if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) && (pc_isGM(sd) >= get_atcommand_level(AtCommand_Broadcast))) { strncpy(m, (const char *)RFIFOP(fd, 4), RFIFOW(fd, 2) - 4); - m[RFIFOW(fd, 2) - 4] = 0; - log_atcommand(sd, "/announce %s", m); + m[RFIFOW(fd, 2) - 4] = '\0'; + const char *m_p = m; // because VLAs can't be passed to STRPRINTF + std::string fake_command = STRPRINTF("/announce %s", m_p); + log_atcommand(sd, fake_command); - memset(output, '\0', sizeof(output)); - snprintf(output, 199, "%s : %s", sd->status.name, m); + std::string output = STRPRINTF("%s : %s", sd->status.name, m_p); - intif_GMmessage(output, strlen(output) + 1, 0); + intif_GMmessage(output, 0); } } @@ -5345,7 +5318,7 @@ void clif_parse_NpcStringInput(int fd, struct map_session_data *sd) if (len >= sizeof(sd->npc_str) - 1) { - printf("clif_parse_NpcStringInput(): Input string too long!\n"); + PRINTF("clif_parse_NpcStringInput(): Input string too long!\n"); len = sizeof(sd->npc_str) - 1; } @@ -5551,7 +5524,7 @@ void clif_parse_PartyMessage(int fd, struct map_session_data *sd) return; } - if (is_atcommand(fd, sd, message, 0) != AtCommand_None + if (is_atcommand(fd, sd, message, 0) || ((sd->sc_data[SC_BERSERK].timer != -1 //バーサーク時は会話も不可 || sd->sc_data[SC_NOCHAT].timer != -1))) //チャット禁止 { @@ -5590,7 +5563,9 @@ void clif_parse_GMKick(int fd, struct map_session_data *sd) { struct map_session_data *tsd = (struct map_session_data *) target; - log_atcommand(sd, "@kick %s", tsd->status.name); + std::string fake_command = STRPRINTF("kick %s", + tsd->status.name); + log_atcommand(sd, fake_command); if (pc_isGM(sd) > pc_isGM(tsd)) clif_GM_kick(sd, tsd, 1); else @@ -5615,7 +5590,7 @@ void clif_parse_GMHide(int fd, struct map_session_data *sd) { // Modified by [Yor] nullpo_retv(sd); - //printf("%2x %2x %2x\n", RFIFOW(fd,0), RFIFOW(fd,2), RFIFOW(fd,4)); // R 019d .2B .2B + //PRINTF("%2x %2x %2x\n", RFIFOW(fd,0), RFIFOW(fd,2), RFIFOW(fd,4)); // R 019d .2B .2B if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) && (pc_isGM(sd) >= get_atcommand_level(AtCommand_Hide))) { @@ -5638,7 +5613,7 @@ void clif_parse_GMHide(int fd, struct map_session_data *sd) static void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd) { // Rewritten by [Yor] - //printf("Ignore all: state: %d\n", RFIFOB(fd,2)); + //PRINTF("Ignore all: state: %d\n", RFIFOB(fd,2)); if (RFIFOB(fd, 2) == 0) { // S 00d0 len.B: 00 (/exall) deny all speech, 01 (/inall) allow all speech WFIFOW(fd, 0) = 0x0d2; // R 00d2 .B .B: type: 0: deny, 1: allow, fail: 0: success, 1: fail @@ -6306,7 +6281,7 @@ int clif_check_packet_flood(int fd, int cmd) if (sd->packet_flood_in >= battle_config.packet_spam_flood) { - printf("packet flood detected from %s [0x%x]\n", sd->status.name, cmd); + PRINTF("packet flood detected from %s [0x%x]\n", sd->status.name, cmd); if (battle_config.packet_spam_kick) { session[fd]->eof = 1; // Kick @@ -6323,7 +6298,7 @@ int clif_check_packet_flood(int fd, int cmd) } #define WARN_MALFORMED_MSG(sd, msg) \ - printf("clif_validate_chat(): %s (ID %d) sent a malformed" \ + PRINTF("clif_validate_chat(): %s (ID %d) sent a malformed" \ " message: %s.\n", sd->status.name, sd->status.account_id, msg) /** * Validate message integrity (inspired by upstream source (eAthena)). @@ -6482,13 +6457,13 @@ void clif_parse(int fd) pc_logout(sd); clif_quitsave(fd, sd); if (sd->status.name != NULL) - printf("Player [%s] has logged off your server.\n", sd->status.name); // Player logout display [Valaris] + PRINTF("Player [%s] has logged off your server.\n", sd->status.name); // Player logout display [Valaris] else - printf("Player with account [%d] has logged off your server.\n", sd->bl.id); // Player logout display [Yor] + PRINTF("Player with account [%d] has logged off your server.\n", sd->bl.id); // Player logout display [Yor] } else if (sd) { // not authentified! (refused by char-server or disconnect before to be authentified) - printf("Player with account [%d] has logged off your server (not auth account).\n", sd->bl.id); // Player logout display [Yor] + PRINTF("Player with account [%d] has logged off your server (not auth account).\n", sd->bl.id); // Player logout display [Yor] map_deliddb(&sd->bl); // account_id has been included in the DB before auth answer } if (fd) @@ -6571,7 +6546,7 @@ void clif_parse(int fd) if (battle_config.error_log) { if (fd) - printf("\nclif_parse: session #%d, packet 0x%x, lenght %d\n", + PRINTF("\nclif_parse: session #%d, packet 0x%x, lenght %d\n", fd, cmd, packet_len); #ifdef DUMP_UNKNOWN_PACKET { @@ -6579,28 +6554,28 @@ void clif_parse(int fd) FILE *fp; char packet_txt[256] = "save/packet.txt"; time_t now; - printf("---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F"); + PRINTF("---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F"); for (i = 0; i < packet_len; i++) { if ((i & 15) == 0) - printf("\n%04X ", i); - printf("%02X ", RFIFOB(fd, i)); + PRINTF("\n%04X ", i); + PRINTF("%02X ", RFIFOB(fd, i)); } if (sd && sd->state.auth) { if (sd->status.name != NULL) - printf("\nAccount ID %d, character ID %d, player name %s.\n", + PRINTF("\nAccount ID %d, character ID %d, player name %s.\n", sd->status.account_id, sd->status.char_id, sd->status.name); else - printf("\nAccount ID %d.\n", sd->bl.id); + PRINTF("\nAccount ID %d.\n", sd->bl.id); } else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified) - printf("\nAccount ID %d.\n", sd->bl.id); + PRINTF("\nAccount ID %d.\n", sd->bl.id); if ((fp = fopen_(packet_txt, "a")) == NULL) { - printf("clif.c: cant write [%s] !!! data is lost !!!\n", + PRINTF("clif.c: cant write [%s] !!! data is lost !!!\n", packet_txt); return; } @@ -6610,30 +6585,30 @@ void clif_parse(int fd) if (sd && sd->state.auth) { if (sd->status.name != NULL) - fprintf(fp, + FPRINTF(fp, "%sPlayer with account ID %d (character ID %d, player name %s) sent wrong packet:\n", asctime(gmtime(&now)), sd->status.account_id, sd->status.char_id, sd->status.name); else - fprintf(fp, + FPRINTF(fp, "%sPlayer with account ID %d sent wrong packet:\n", asctime(gmtime(&now)), sd->bl.id); } else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified) - fprintf(fp, + FPRINTF(fp, "%sPlayer with account ID %d sent wrong packet:\n", asctime(gmtime(&now)), sd->bl.id); - fprintf(fp, + FPRINTF(fp, "\t---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F"); for (i = 0; i < packet_len; i++) { if ((i & 15) == 0) - fprintf(fp, "\n\t%04X ", i); - fprintf(fp, "%02X ", RFIFOB(fd, i)); + FPRINTF(fp, "\n\t%04X ", i); + FPRINTF(fp, "%02X ", RFIFOB(fd, i)); } - fprintf(fp, "\n\n"); + FPRINTF(fp, "\n\n"); fclose_(fp); } } @@ -6664,7 +6639,7 @@ int do_init_clif (void) } if (i == 10) { - printf("cant bind game port\n"); + PRINTF("cant bind game port\n"); exit(1); } diff --git a/src/map/clif.hpp b/src/map/clif.hpp index 2158d3a..75dc73d 100644 --- a/src/map/clif.hpp +++ b/src/map/clif.hpp @@ -6,6 +6,8 @@ #include #include +#include "../common/const_array.hpp" + #include "pc.t.hpp" #include "map.hpp" @@ -140,9 +142,8 @@ int clif_party_xy(struct party *p, struct map_session_data *sd); int clif_party_hp(struct party *p, struct map_session_data *sd); // atcommand -int clif_displaymessage(int fd, const char *mes); -int clif_disp_onlyself(struct map_session_data *sd, const char *mes, int len); -int clif_GMmessage(struct block_list *bl, const char *mes, int len, int flag); +void clif_displaymessage(int fd, const_string mes); +void clif_GMmessage(struct block_list *bl, const_string mes, int flag); int clif_resurrection(struct block_list *bl, int type); int clif_specialeffect(struct block_list *bl, int type, int flag); // special effects [Valaris] diff --git a/src/map/intif.cpp b/src/map/intif.cpp index 87ea5d0..44d381b 100644 --- a/src/map/intif.cpp +++ b/src/map/intif.cpp @@ -47,16 +47,15 @@ extern int char_fd; // inter serverのfdはchar_fdを使う // inter serverへの送信 // Message for all GMs on all map servers -int intif_GMmessage(const char *mes, int len, int flag) +void intif_GMmessage(const_string mes, int flag) { int lp = (flag & 0x10) ? 8 : 4; WFIFOW(inter_fd, 0) = 0x3000; - WFIFOW(inter_fd, 2) = lp + len; + WFIFOW(inter_fd, 2) = lp + mes.size() + 1; WFIFOL(inter_fd, 4) = 0x65756c62; - memcpy(WFIFOP(inter_fd, lp), mes, len); + memcpy(WFIFOP(inter_fd, lp), mes.data(), mes.size()); + WFIFOB(inter_fd, lp + mes.size()) = '\0'; WFIFOSET(inter_fd, WFIFOW(inter_fd, 2)); - - return 0; } // The transmission of Wisp/Page to inter-server (player not found on this server) @@ -73,7 +72,7 @@ int intif_wis_message(struct map_session_data *sd, const char *nick, const char WFIFOSET(inter_fd, WFIFOW(inter_fd, 2)); if (battle_config.etc_log) - printf("intif_wis_message from %s to %s (message: '%s')\n", + PRINTF("intif_wis_message from %s to %s (message: '%s')\n", sd->status.name, nick, mes); return 0; @@ -89,7 +88,7 @@ int intif_wis_replay(int id, int flag) WFIFOSET(inter_fd, 7); if (battle_config.etc_log) - printf("intif_wis_replay: id: %d, flag:%d\n", id, flag); + PRINTF("intif_wis_replay: id: %d, flag:%d\n", id, flag); return 0; } @@ -106,7 +105,7 @@ int intif_wis_message_to_gm(const char *Wisp_name, int min_gm_level, const char WFIFOSET(inter_fd, WFIFOW(inter_fd, 2)); if (battle_config.etc_log) - printf("intif_wis_message_to_gm: from: '%s', min level: %d, message: '%s'.\n", + PRINTF("intif_wis_message_to_gm: from: '%s', min level: %d, message: '%s'.\n", Wisp_name, min_gm_level, mes); return 0; @@ -176,7 +175,7 @@ int intif_create_party(struct map_session_data *sd, const char *name) WFIFOW(inter_fd, 70) = sd->status.base_level; WFIFOSET(inter_fd, 72); // if(battle_config.etc_log) -// printf("intif: create party\n"); +// PRINTF("intif: create party\n"); return 0; } @@ -187,7 +186,7 @@ int intif_request_partyinfo(int party_id) WFIFOL(inter_fd, 2) = party_id; WFIFOSET(inter_fd, 6); // if(battle_config.etc_log) -// printf("intif: request party info\n"); +// PRINTF("intif: request party info\n"); return 0; } @@ -197,7 +196,7 @@ int intif_party_addmember(int party_id, int account_id) struct map_session_data *sd; sd = map_id2sd(account_id); // if(battle_config.etc_log) -// printf("intif: party add member %d %d\n",party_id,account_id); +// PRINTF("intif: party add member %d %d\n",party_id,account_id); if (sd != NULL) { WFIFOW(inter_fd, 0) = 0x3022; @@ -227,7 +226,7 @@ int intif_party_changeoption(int party_id, int account_id, int exp, int item) int intif_party_leave(int party_id, int account_id) { // if(battle_config.etc_log) -// printf("intif: party leave %d %d\n",party_id,account_id); +// PRINTF("intif: party leave %d %d\n",party_id,account_id); WFIFOW(inter_fd, 0) = 0x3024; WFIFOL(inter_fd, 2) = party_id; WFIFOL(inter_fd, 6) = account_id; @@ -249,7 +248,7 @@ int intif_party_changemap(struct map_session_data *sd, int online) WFIFOSET(inter_fd, 29); } // if(battle_config.etc_log) -// printf("party: change map\n"); +// PRINTF("party: change map\n"); return 0; } @@ -257,7 +256,7 @@ int intif_party_changemap(struct map_session_data *sd, int online) int intif_party_message(int party_id, int account_id, const char *mes, int len) { // if(battle_config.etc_log) -// printf("intif_party_message: %s\n",mes); +// PRINTF("intif_party_message: %s\n",mes); WFIFOW(inter_fd, 0) = 0x3027; WFIFOW(inter_fd, 2) = len + 12; WFIFOL(inter_fd, 4) = party_id; @@ -289,7 +288,7 @@ int intif_parse_WisMessage(int fd) int i; if (battle_config.etc_log) - printf("intif_parse_wismessage: id: %d, from: %s, to: %s, message: '%s'\n", + PRINTF("intif_parse_wismessage: id: %d, from: %s, to: %s, message: '%s'\n", RFIFOL(fd, 4), RFIFOP(fd, 8), RFIFOP(fd, 32), RFIFOP(fd, 56)); sd = map_nick2sd((const char *)RFIFOP(fd, 32)); // Searching destination player @@ -330,7 +329,7 @@ int intif_parse_WisEnd(int fd) struct map_session_data *sd; if (battle_config.etc_log) - printf("intif_parse_wisend: player: %s, flag: %d\n", RFIFOP(fd, 2), RFIFOB(fd, 26)); // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target + PRINTF("intif_parse_wisend: player: %s, flag: %d\n", RFIFOP(fd, 2), RFIFOB(fd, 26)); // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target sd = map_nick2sd((const char *)RFIFOP(fd, 2)); if (sd != NULL) clif_wis_end(sd->fd, RFIFOB(fd, 26)); @@ -388,7 +387,7 @@ int intif_parse_AccountReg(int fd) sd->status.account_reg[j].value = RFIFOL(fd, p + 32); } sd->status.account_reg_num = j; -// printf("intif: accountreg\n"); +// PRINTF("intif: accountreg\n"); return 0; } @@ -404,7 +403,7 @@ int intif_parse_LoadStorage(int fd) if (sd == NULL) { if (battle_config.error_log) - printf("intif_parse_LoadStorage: user not found %d\n", + PRINTF("intif_parse_LoadStorage: user not found %d\n", RFIFOL(fd, 4)); return 1; } @@ -412,14 +411,14 @@ int intif_parse_LoadStorage(int fd) if (stor->storage_status == 1) { // Already open.. lets ignore this update if (battle_config.error_log) - printf("intif_parse_LoadStorage: storage received for a client already open (User %d:%d)\n", + PRINTF("intif_parse_LoadStorage: storage received for a client already open (User %d:%d)\n", sd->status.account_id, sd->status.char_id); return 1; } if (stor->dirty) { // Already have storage, and it has been modified and not saved yet! Exploit! [Skotlex] if (battle_config.error_log) - printf("intif_parse_LoadStorage: received storage for an already modified non-saved storage! (User %d:%d)\n", + PRINTF("intif_parse_LoadStorage: received storage for an already modified non-saved storage! (User %d:%d)\n", sd->status.account_id, sd->status.char_id); return 1; } @@ -427,12 +426,12 @@ int intif_parse_LoadStorage(int fd) if (RFIFOW(fd, 2) - 8 != sizeof(struct storage)) { if (battle_config.error_log) - printf("intif_parse_LoadStorage: data size error %d %d\n", + PRINTF("intif_parse_LoadStorage: data size error %d %d\n", RFIFOW(fd, 2) - 8, sizeof(struct storage)); return 1; } if (battle_config.save_log) - printf("intif_openstorage: %d\n", RFIFOL(fd, 4)); + PRINTF("intif_openstorage: %d\n", RFIFOL(fd, 4)); memcpy(stor, RFIFOP(fd, 8), sizeof(struct storage)); stor->dirty = 0; stor->storage_status = 1; @@ -449,7 +448,7 @@ static int intif_parse_SaveStorage(int fd) { if (battle_config.save_log) - printf("intif_savestorage: done %d %d\n", RFIFOL(fd, 2), + PRINTF("intif_savestorage: done %d %d\n", RFIFOL(fd, 2), RFIFOB(fd, 6)); storage_storage_saved(RFIFOL(fd, 2)); return 0; @@ -460,7 +459,7 @@ static int intif_parse_PartyCreated(int fd) { if (battle_config.etc_log) - printf("intif: party created\n"); + PRINTF("intif: party created\n"); party_created(RFIFOL(fd, 2), RFIFOB(fd, 6), RFIFOL(fd, 7), (const char *)RFIFOP(fd, 11)); return 0; @@ -473,16 +472,16 @@ int intif_parse_PartyInfo(int fd) if (RFIFOW(fd, 2) == 8) { if (battle_config.error_log) - printf("intif: party noinfo %d\n", RFIFOL(fd, 4)); + PRINTF("intif: party noinfo %d\n", RFIFOL(fd, 4)); party_recv_noinfo(RFIFOL(fd, 4)); return 0; } -// printf("intif: party info %d\n",RFIFOL(fd,4)); +// PRINTF("intif: party info %d\n",RFIFOL(fd,4)); if (RFIFOW(fd, 2) != sizeof(struct party) + 4) { if (battle_config.error_log) - printf("intif: party info : data size error %d %d %d\n", + PRINTF("intif: party info : data size error %d %d %d\n", RFIFOL(fd, 4), RFIFOW(fd, 2), sizeof(struct party) + 4); } @@ -495,7 +494,7 @@ static int intif_parse_PartyMemberAdded(int fd) { if (battle_config.etc_log) - printf("intif: party member added %d %d %d\n", RFIFOL(fd, 2), + PRINTF("intif: party member added %d %d %d\n", RFIFOL(fd, 2), RFIFOL(fd, 6), RFIFOB(fd, 10)); party_member_added(RFIFOL(fd, 2), RFIFOL(fd, 6), RFIFOB(fd, 10)); return 0; @@ -515,7 +514,7 @@ static int intif_parse_PartyMemberLeaved(int fd) { if (battle_config.etc_log) - printf("intif: party member leaved %d %d %s\n", RFIFOL(fd, 2), + PRINTF("intif: party member leaved %d %d %s\n", RFIFOL(fd, 2), RFIFOL(fd, 6), (const char *)RFIFOP(fd, 10)); party_member_leaved(RFIFOL(fd, 2), RFIFOL(fd, 6), (const char *)RFIFOP(fd, 10)); return 0; @@ -534,7 +533,7 @@ static int intif_parse_PartyMove(int fd) { // if(battle_config.etc_log) -// printf("intif: party move %d %d %s %d %d\n",RFIFOL(fd,2),RFIFOL(fd,6),RFIFOP(fd,10),RFIFOB(fd,26),RFIFOW(fd,27)); +// PRINTF("intif: party move %d %d %s %d %d\n",RFIFOL(fd,2),RFIFOL(fd,6),RFIFOP(fd,10),RFIFOB(fd,26),RFIFOW(fd,27)); party_recv_movemap(RFIFOL(fd, 2), RFIFOL(fd, 6), (const char *)RFIFOP(fd, 10), RFIFOB(fd, 26), RFIFOW(fd, 27)); return 0; @@ -545,7 +544,7 @@ static int intif_parse_PartyMessage(int fd) { // if(battle_config.etc_log) -// printf("intif_parse_PartyMessage: %s\n",RFIFOP(fd,12)); +// PRINTF("intif_parse_PartyMessage: %s\n",RFIFOP(fd,12)); party_recv_message(RFIFOL(fd, 4), RFIFOL(fd, 8), (const char *)RFIFOP(fd, 12), RFIFOW(fd, 2) - 12); return 0; @@ -576,7 +575,7 @@ int intif_parse(int fd) packet_len = RFIFOW(fd, 2); } // if(battle_config.etc_log) -// printf("intif_parse %d %x %d %d\n",fd,cmd,packet_len,RFIFOREST(fd)); +// PRINTF("intif_parse %d %x %d %d\n",fd,cmd,packet_len,RFIFOREST(fd)); if (RFIFOREST(fd) < packet_len) { return 2; @@ -585,7 +584,9 @@ int intif_parse(int fd) switch (cmd) { case 0x3800: - clif_GMmessage(NULL, (const char *)RFIFOP(fd, 4), packet_len - 4, 0); + clif_GMmessage(NULL, + const_string((const char *)RFIFOP(fd, 4), + (packet_len - 4) - 1), 0); break; case 0x3801: intif_parse_WisMessage(fd); @@ -631,7 +632,7 @@ int intif_parse(int fd) break; default: if (battle_config.error_log) - printf("intif_parse : unknown packet %d %x\n", fd, + PRINTF("intif_parse : unknown packet %d %x\n", fd, RFIFOW(fd, 0)); return 0; } diff --git a/src/map/intif.hpp b/src/map/intif.hpp index 720c7cd..7a03483 100644 --- a/src/map/intif.hpp +++ b/src/map/intif.hpp @@ -1,9 +1,11 @@ #ifndef INTIF_HPP #define INTIF_HPP +#include "../common/const_array.hpp" + int intif_parse(int fd); -int intif_GMmessage(const char *mes, int len, int flag); +void intif_GMmessage(const_string mes, int flag); int intif_wis_message(struct map_session_data *sd, const char *nick, const char *mes, int mes_len); diff --git a/src/map/itemdb.cpp b/src/map/itemdb.cpp index 58206ba..fc3f59e 100644 --- a/src/map/itemdb.cpp +++ b/src/map/itemdb.cpp @@ -46,8 +46,6 @@ int itemdb_read_randomitem(void); static int itemdb_read_itemavail(void); static -int itemdb_read_itemnametable(void); -static int itemdb_read_noequip(void); /*========================================== @@ -220,43 +218,6 @@ int itemdb_isequip3(int nameid) || type == ItemType::_8); } -// -// 初期化 -// -/*========================================== - * - *------------------------------------------ - */ -static -int itemdb_read_itemslottable(void) -{ - char *buf, *p; - size_t s; - - buf = (char *)grfio_reads("data\\itemslottable.txt", &s); - if (buf == NULL) - return -1; - buf[s] = 0; - for (p = buf; p - buf < s;) - { - int nameid, equip_; - sscanf(p, "%d#%d#", &nameid, &equip_); - EPOS equip = EPOS(equip_); - itemdb_search(nameid)->equip = equip; - p = strchr(p, 10); - if (!p) - break; - p++; - p = strchr(p, 10); - if (!p) - break; - p++; - } - free(buf); - - return 0; -} - /*========================================== * アイテムデータベースの読み込み *------------------------------------------ @@ -281,7 +242,7 @@ int itemdb_readdb(void) { if (i > 0) continue; - printf("can't read %s\n", filename[i]); + PRINTF("can't read %s\n", filename[i]); exit(1); } @@ -358,7 +319,7 @@ int itemdb_readdb(void) id->equip_script = parse_script(p, lines); } fclose_(fp); - printf("read %s done (count=%d)\n", filename[i], ln); + PRINTF("read %s done (count=%d)\n", filename[i], ln); } return 0; } @@ -410,7 +371,7 @@ int itemdb_read_randomitem(void) *pdefault = 0; if ((fp = fopen_(fn, "r")) == NULL) { - printf("can't read %s\n", fn); + PRINTF("can't read %s\n", fn); continue; } @@ -451,7 +412,7 @@ int itemdb_read_randomitem(void) ln++; } fclose_(fp); - printf("read %s done (count=%d)\n", fn, *pc); + PRINTF("read %s done (count=%d)\n", fn, *pc); } return 0; @@ -472,7 +433,7 @@ int itemdb_read_itemavail(void) if ((fp = fopen_("db/item_avail.txt", "r")) == NULL) { - printf("can't read db/item_avail.txt\n"); + PRINTF("can't read db/item_avail.txt\n"); return -1; } @@ -507,93 +468,7 @@ int itemdb_read_itemavail(void) ln++; } fclose_(fp); - printf("read db/item_avail.txt done (count=%d)\n", ln); - return 0; -} - -/*========================================== - * アイテムの名前テーブルを読み込む - *------------------------------------------ - */ -static -int itemdb_read_itemnametable(void) -{ - char *buf, *p; - size_t s; - - buf = (char *)grfio_reads("data\\idnum2itemdisplaynametable.txt", &s); - - if (buf == NULL) - return -1; - - buf[s] = 0; - for (p = buf; p - buf < s;) - { - int nameid; - char buf2[64]; - - if (sscanf(p, "%d#%[^#]#", &nameid, buf2) == 2) - { - -#ifdef ITEMDB_OVERRIDE_NAME_VERBOSE - if (itemdb_exists(nameid) && - strncmp(itemdb_search(nameid)->jname, buf2, 24) != 0) - { - printf("[override] %d %s => %s\n", nameid, - itemdb_search(nameid)->jname, buf2); - } -#endif - - memcpy(itemdb_search(nameid)->jname, buf2, 24); - } - - p = strchr(p, 10); - if (!p) - break; - p++; - } - free(buf); - printf("read data\\idnum2itemdisplaynametable.txt done.\n"); - - return 0; -} - -/*========================================== - * カードイラストのリソース名前テーブルを読み込む - *------------------------------------------ - */ -static -int itemdb_read_cardillustnametable(void) -{ - char *buf, *p; - size_t s; - - buf = (char *)grfio_reads("data\\num2cardillustnametable.txt", &s); - - if (buf == NULL) - return -1; - - buf[s] = 0; - for (p = buf; p - buf < s;) - { - int nameid; - char buf2[64]; - - if (sscanf(p, "%d#%[^#]#", &nameid, buf2) == 2) - { - strcat(buf2, ".bmp"); - memcpy(itemdb_search(nameid)->cardillustname, buf2, 64); -// printf("%d %s\n",nameid,itemdb_search(nameid)->cardillustname); - } - - p = strchr(p, 10); - if (!p) - break; - p++; - } - free(buf); - printf("read data\\num2cardillustnametable.txt done.\n"); - + PRINTF("read db/item_avail.txt done (count=%d)\n", ln); return 0; } @@ -613,7 +488,7 @@ int itemdb_read_noequip(void) if ((fp = fopen_("db/item_noequip.txt", "r")) == NULL) { - printf("can't read db/item_noequip.txt\n"); + PRINTF("can't read db/item_noequip.txt\n"); return -1; } while (fgets(line, 1020, fp)) @@ -641,7 +516,7 @@ int itemdb_read_noequip(void) } fclose_(fp); - printf("read db/item_noequip.txt done (count=%d)\n", ln); + PRINTF("read db/item_noequip.txt done (count=%d)\n", ln); return 0; } @@ -694,7 +569,7 @@ 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); + FPRINTF(dfp,"%6d", (int)key); return 0; } void itemdebugtxt() @@ -712,14 +587,10 @@ void itemdebugtxt() static void itemdb_read(void) { - itemdb_read_itemslottable(); itemdb_readdb(); itemdb_read_randomitem(); itemdb_read_itemavail(); itemdb_read_noequip(); - itemdb_read_cardillustnametable(); - if (!battle_config.item_name_override_grffile) - itemdb_read_itemnametable(); } /*========================================== diff --git a/src/map/magic-expr.cpp b/src/map/magic-expr.cpp index 4a5449d..d544234 100644 --- a/src/map/magic-expr.cpp +++ b/src/map/magic-expr.cpp @@ -2,6 +2,7 @@ #include +#include "../common/cxxstdio.hpp" #include "../common/mt_rand.hpp" #include "itemdb.hpp" @@ -116,63 +117,67 @@ static void stringify(val_t *v, int within_op) { static const char *dirs[8] = - { "south", "south-west", "west", "north-west", "north", "north-east", + { + "south", "south-west", + "west", "north-west", + "north", "north-east", "east", "south-east" }; - char *buf; + std::string buf; switch (v->ty) { case TY_UNDEF: - buf = strdup("UNDEF"); + buf = "UNDEF"; break; case TY_INT: - buf = (char *)malloc(32); - sprintf(buf, "%i", v->v.v_int); + buf = STRPRINTF("%i", v->v.v_int); break; case TY_STRING: return; case TY_DIR: - buf = strdup(dirs[v->v.v_int]); + buf = dirs[v->v.v_int]; break; case TY_ENTITY: - buf = strdup(show_entity(v->v.v_entity)); + buf = show_entity(v->v.v_entity); break; case TY_LOCATION: - buf = (char *) malloc(128); - sprintf(buf, "<\"%s\", %d, %d>", map[v->v.v_location.m].name, - v->v.v_location.x, v->v.v_location.y); + buf = STRPRINTF("<\"%s\", %d, %d>", + map[v->v.v_location.m].name, + v->v.v_location.x, + v->v.v_location.y); break; case TY_AREA: - buf = strdup("%area"); + buf = "%area"; free_area(v->v.v_area); break; case TY_SPELL: - buf = strdup(v->v.v_spell->name); + buf = v->v.v_spell->name; break; case TY_INVOCATION: { invocation_t *invocation = within_op - ? v->v.v_invocation : (invocation_t *) map_id2bl(v->v.v_int); - buf = strdup(invocation->spell->name); + ? v->v.v_invocation + : (invocation_t *) map_id2bl(v->v.v_int); + buf = invocation->spell->name; } break; default: - fprintf(stderr, "[magic] INTERNAL ERROR: Cannot stringify %d\n", - uint8_t(v->ty)); + FPRINTF(stderr, "[magic] INTERNAL ERROR: Cannot stringify %d\n", + v->ty); return; } - v->v.v_string = buf; + v->v.v_string = strdup(buf.c_str()); v->ty = TY_STRING; } @@ -534,7 +539,7 @@ void magic_area_rect(int *m, int *x, int *y, int *width, int *height, break; default: - fprintf(stderr, + FPRINTF(stderr, "Error: Trying to compute area of NE/SE/NW/SW-facing bar"); *x = tx; *y = ty; @@ -564,7 +569,7 @@ int magic_location_in_area(int m, int x, int y, area_t *area) && (x < ax + awidth) && (y < ay + aheight)); } default: - fprintf(stderr, "INTERNAL ERROR: Invalid area\n"); + FPRINTF(stderr, "INTERNAL ERROR: Invalid area\n"); return 0; } } @@ -978,8 +983,8 @@ void magic_random_location(location_t *dest, area_t *area) } default: - fprintf(stderr, "Unknown area type %d\n", - uint8_t(area->ty)); + FPRINTF(stderr, "Unknown area type %d\n", + area->ty); } } @@ -1472,8 +1477,8 @@ area_t *eval_area(env_t *env, e_area_t *expr) } default: - fprintf(stderr, "INTERNAL ERROR: Unknown area type %d\n", - uint8_t(area->ty)); + FPRINTF(stderr, "INTERNAL ERROR: Unknown area type %d\n", + area->ty); free(area); return NULL; } @@ -1532,7 +1537,7 @@ int magic_signature_check(const char *opname, const char *funname, const char *s if (!ty_key) { - fprintf(stderr, + FPRINTF(stderr, "[magic-eval]: L%d:%d: Too many arguments (%d) to %s `%s'\n", line, column, args_nr, opname, funname); return 1; @@ -1546,7 +1551,7 @@ int magic_signature_check(const char *opname, const char *funname, const char *s if (ty == TY_UNDEF) { - fprintf(stderr, + FPRINTF(stderr, "[magic-eval]: L%d:%d: Argument #%d to %s `%s' undefined\n", line, column, i + 1, opname, funname); return 1; @@ -1578,10 +1583,10 @@ int magic_signature_check(const char *opname, const char *funname, const char *s if (ty != desired_ty) { /* Coercion failed? */ if (ty != TY_FAIL) - fprintf(stderr, + FPRINTF(stderr, "[magic-eval]: L%d:%d: Argument #%d to %s `%s' of incorrect type (%d)\n", line, column, i + 1, opname, funname, - uint8_t(ty)); + ty); return 1; } } @@ -1593,9 +1598,7 @@ int magic_signature_check(const char *opname, const char *funname, const char *s #pragma GCC diagnostic ignored "-Wshadow" void magic_eval(env_t *env, val_t *dest, expr_t *expr) { -#ifdef RECENT_GCC #pragma GCC diagnostic pop -#endif switch (expr->ty) { case EXPR_VAL: @@ -1671,21 +1674,17 @@ void magic_eval(env_t *env, val_t *dest, expr_t *expr) dest->ty = TY_UNDEF; else { -#ifdef RECENT_GCC #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wshadow" -#endif env_t *env = t->env; -#ifdef RECENT_GCC #pragma GCC diagnostic pop -#endif val_t val = VAR(id); magic_copy_var(dest, &val); } } else { - fprintf(stderr, + FPRINTF(stderr, "[magic] Attempt to access field %s on non-spell\n", env->base_env->var_name[id]); dest->ty = TY_FAIL; @@ -1694,15 +1693,12 @@ void magic_eval(env_t *env, val_t *dest, expr_t *expr) } default: - fprintf(stderr, + FPRINTF(stderr, "[magic] INTERNAL ERROR: Unknown expression type %d\n", - uint8_t(expr->ty)); + expr->ty); break; } } -#ifndef RECENT_GCC -#pragma GCC diagnostic pop -#endif int magic_eval_int(env_t *env, expr_t *expr) { diff --git a/src/map/magic-interpreter-base.cpp b/src/map/magic-interpreter-base.cpp index ec59d38..e970eb2 100644 --- a/src/map/magic-interpreter-base.cpp +++ b/src/map/magic-interpreter-base.cpp @@ -207,8 +207,8 @@ env_t *spell_create_env(magic_conf_t *conf, spell_t *spell, default: free(param); - fprintf(stderr, "Unexpected spellarg type %d\n", - uint8_t(spell->spellarg_ty)); + FPRINTF(stderr, "Unexpected spellarg type %d\n", + spell->spellarg_ty); } set_env_entity(VAR_CASTER, &caster->bl); @@ -307,7 +307,7 @@ int spellguard_can_satisfy(spellguard_check_t *check, character_t *caster, int retval = check_prerequisites(caster, check->catalysts); /* - fprintf(stderr, "MC(%d/%s)? %d%d%d%d (%u <= %u)\n", + FPRINTF(stderr, "MC(%d/%s)? %d%d%d%d (%u <= %u)\n", caster->bl.id, caster->status.name, retval, caster->cast_tick <= tick, @@ -401,8 +401,8 @@ effect_set_t *spellguard_check_sub(spellguard_check_t *check, return NULL; default: - fprintf(stderr, "Unexpected spellguard type %d\n", - uint8_t(guard->ty)); + FPRINTF(stderr, "Unexpected spellguard type %d\n", + guard->ty); return NULL; } @@ -540,7 +540,7 @@ void spell_bind(character_t *subject, invocation_t *invocation) || invocation->subject || invocation->next_invocation) { int *i = NULL; - fprintf(stderr, + FPRINTF(stderr, "[magic] INTERNAL ERROR: Attempt to re-bind spell invocation `%s'\n", invocation->spell->name); *i = 1; diff --git a/src/map/magic-interpreter-lexer.lpp b/src/map/magic-interpreter-lexer.lpp index 0ae6494..34461f5 100644 --- a/src/map/magic-interpreter-lexer.lpp +++ b/src/map/magic-interpreter-lexer.lpp @@ -136,7 +136,7 @@ "#".*$ /* Ignore comments */ "//".*$ /* Ignore comments */ [ \n\t\r] /* ignore whitespace */ -. fprintf(stderr, "%s: Unexpected character in line %d\n", MAGIC_CONFIG_FILE, magic_frontend_lineno); +. FPRINTF(stderr, "%s: Unexpected character in line %d\n", MAGIC_CONFIG_FILE, magic_frontend_lineno); %% diff --git a/src/map/magic-interpreter-parser.ypp b/src/map/magic-interpreter-parser.ypp index 2b80ffb..3cabf24 100644 --- a/src/map/magic-interpreter-parser.ypp +++ b/src/map/magic-interpreter-parser.ypp @@ -2,10 +2,12 @@ #include "magic-expr.hpp" } %code{ -#include // exception to "no va_list" rule - #include "magic-interpreter-parser.hpp" +#include // exception to "no va_list" rule, even after cxxstdio + +#include "../common/cxxstdio.hpp" + #include "magic-interpreter.hpp" #define YYLEX_PARAM 0, 0 @@ -783,7 +785,7 @@ static __attribute__((format(printf, 3, 4))) void fail(int line, int column, const char *fmt, ...) { va_list ap; - fprintf(stderr, "[magic-init] L%d:%d: ", line, column); + FPRINTF(stderr, "[magic-init] L%d:%d: ", line, column); va_start(ap, fmt); vfprintf(stderr, fmt, ap); failed_flag = 1; @@ -1034,7 +1036,7 @@ val_t *find_constant(char *name) -#define INTERN_ASSERT(name, 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; } +#define INTERN_ASSERT(name, 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; } extern FILE *magic_frontend_in; @@ -1069,7 +1071,7 @@ int magic_init(const char *conffile) magic_frontend_in = fopen(conffile, "r"); if (!magic_frontend_in) { - fprintf(stderr, "[magic-conf] Magic configuration file `%s' not found -> no magic.\n", conffile); + FPRINTF(stderr, "[magic-conf] Magic configuration file `%s' not found -> no magic.\n", conffile); return 0; } magic_frontend_parse(); @@ -1080,7 +1082,7 @@ int magic_init(const char *conffile) if (magic_conf.vars[VAR_OBSCURE_CHANCE].ty == TY_INT) magic_conf.obscure_chance = magic_conf.vars[VAR_OBSCURE_CHANCE].v.v_int; - printf("[magic-conf] Magic initialised; obscure at %d%%. %d spells, %d teleport anchors.\n", + PRINTF("[magic-conf] Magic initialised; obscure at %d%%. %d spells, %d teleport anchors.\n", magic_conf.obscure_chance, magic_conf.spells_nr, magic_conf.anchors_nr); if (procs) @@ -1093,6 +1095,6 @@ extern int magic_frontend_lineno; static void magic_frontend_error(const char *msg) { - fprintf(stderr, "[magic-conf] Parse error: %s at line %d\n", msg, magic_frontend_lineno); + FPRINTF(stderr, "[magic-conf] Parse error: %s at line %d\n", msg, magic_frontend_lineno); failed_flag = 1; } diff --git a/src/map/magic-stmt.cpp b/src/map/magic-stmt.cpp index d176dad..de4a15e 100644 --- a/src/map/magic-stmt.cpp +++ b/src/map/magic-stmt.cpp @@ -1,3 +1,5 @@ +#include "../common/cxxstdio.hpp" + #include "magic-expr.hpp" #include "magic-expr-eval.hpp" #include "magic-interpreter.hpp" @@ -14,19 +16,19 @@ void print_val(val_t *v) switch (v->ty) { case TY_UNDEF: - fprintf(stderr, "UNDEF"); + FPRINTF(stderr, "UNDEF"); break; case TY_INT: - fprintf(stderr, "%d", v->v.v_int); + FPRINTF(stderr, "%d", v->v.v_int); break; case TY_DIR: - fprintf(stderr, "dir%d", v->v.v_int); + FPRINTF(stderr, "dir%d", v->v.v_int); break; case TY_STRING: - fprintf(stderr, "`%s'", v->v.v_string); + FPRINTF(stderr, "`%s'", v->v.v_string); break; default: - fprintf(stderr, "ty%d", v->ty); + FPRINTF(stderr, "ty%d", v->ty); break; } } @@ -40,11 +42,11 @@ void dump_env(env_t *env) val_t *v = &env->vars[i]; val_t *bv = &env->base_env->vars[i]; - fprintf(stderr, "%02x %30s ", i, env->base_env->var_name[i]); + FPRINTF(stderr, "%02x %30s ", i, env->base_env->var_name[i]); print_val(v); - fprintf(stderr, "\t("); + FPRINTF(stderr, "\t("); print_val(bv); - fprintf(stderr, ")\n"); + FPRINTF(stderr, ")\n"); } } #endif @@ -950,9 +952,9 @@ void spell_effect_report_termination(int invocation_id, int bl_id, { entity_t *entity = map_id2bl(bl_id); if (entity->type == BL_PC) - fprintf(stderr, + FPRINTF(stderr, "[magic] INTERNAL ERROR: spell-effect-report-termination: tried to terminate on unexpected bl %d, sc %d\n", - bl_id, uint16_t(sc_id)); + bl_id, sc_id); return; } @@ -1041,7 +1043,7 @@ effect_t *return_to_stack(invocation_t *invocation) return ar->c.c_for.body; default: - fprintf(stderr, + FPRINTF(stderr, "[magic] INTERNAL ERROR: While executing spell `%s': stack corruption\n", invocation->spell->name); return NULL; @@ -1057,7 +1059,7 @@ cont_activation_record_t *add_stack_entry(invocation_t *invocation, invocation->stack + invocation->stack_size++; if (invocation->stack_size >= MAX_STACK_SIZE) { - fprintf(stderr, + FPRINTF(stderr, "[magic] Execution stack size exceeded in spell `%s'; truncating effect\n", invocation->spell->name); invocation->stack_size--; @@ -1181,7 +1183,7 @@ effect_t *run_foreach(invocation_t *invocation, effect_t *foreach, if (area.ty != TY_AREA) { magic_clear_var(&area); - fprintf(stderr, + FPRINTF(stderr, "[magic] Error in spell `%s': FOREACH loop over non-area\n", invocation->spell->name); return return_location; @@ -1252,7 +1254,7 @@ effect_t *run_for (invocation_t *invocation, effect_t *for_, { magic_clear_var(&start); magic_clear_var(&stop); - fprintf(stderr, + FPRINTF(stderr, "[magic] Error in spell `%s': FOR loop start or stop point is not an integer\n", invocation->spell->name); return return_location; @@ -1305,9 +1307,9 @@ void print_cfg(int i, effect_t *e) { int j; for (j = 0; j < i; j++) - printf(" "); + PRINTF(" "); - printf("%p: ", e); + PRINTF("%p: ", e); if (!e) { @@ -1340,11 +1342,11 @@ void print_cfg(int i, effect_t *e) case EFFECT_IF: puts("IF"); for (j = 0; j < i; j++) - printf(" "); + PRINTF(" "); puts("THEN"); print_cfg(i + 1, e->e.e_if.true_branch); for (j = 0; j < i; j++) - printf(" "); + PRINTF(" "); puts("ELSE"); print_cfg(i + 1, e->e.e_if.false_branch); break; @@ -1381,7 +1383,7 @@ int spell_run(invocation_t *invocation, int allow_delete) #define REFRESH_INVOCATION invocation = (invocation_t *) map_id2bl(invocation_id); if (!invocation) return 0; #ifdef DEBUG - fprintf(stderr, "Resuming execution: invocation of `%s'\n", + FPRINTF(stderr, "Resuming execution: invocation of `%s'\n", invocation->spell->name); print_cfg(1, invocation->current_effect); #endif @@ -1392,7 +1394,7 @@ int spell_run(invocation_t *invocation, int allow_delete) int i; #ifdef DEBUG - fprintf(stderr, "Next step of type %d\n", e->ty); + FPRINTF(stderr, "Next step of type %d\n", e->ty); dump_env(invocation->env); #endif @@ -1524,9 +1526,9 @@ int spell_run(invocation_t *invocation, int allow_delete) break; default: - fprintf(stderr, + FPRINTF(stderr, "[magic] INTERNAL ERROR: Unknown effect %d\n", - uint8_t(e->ty)); + e->ty); } if (!next) @@ -1553,7 +1555,7 @@ void spell_execute_d(invocation_t *invocation, int allow_deletion) { if (invocation->timer) { - fprintf(stderr, + FPRINTF(stderr, "[magic] FATAL ERROR: Trying to add multiple timers to the same spell! Already had timer: %d\n", invocation->timer); /* *((int *)0x0) = 0; */ diff --git a/src/map/magic.cpp b/src/map/magic.cpp index 5c2daf3..d50d5a7 100644 --- a/src/map/magic.cpp +++ b/src/map/magic.cpp @@ -95,7 +95,7 @@ int magic_message(character_t *caster, char *spell_, size_t) effects = NULL; #ifdef DEBUG - fprintf(stderr, "Found spell `%s', triggered = %d\n", spell_, + FPRINTF(stderr, "Found spell `%s', triggered = %d\n", spell_, effects != NULL); #endif if (bool(caster->status.option & Option::HIDE)) diff --git a/src/map/map.cpp b/src/map/map.cpp index 6323a96..e1b96a8 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -2,11 +2,12 @@ #include -#include // exception to "no va_list" rule #include #include #include +#include + #include "../common/core.hpp" #include "../common/db.hpp" #include "../common/grfio.hpp" @@ -81,6 +82,9 @@ char help_txt[256] = "conf/help.txt"; char wisp_server_name[24] = "Server"; // can be modified in char-server configuration file +static +int map_delmap(const char *mapname); + /*========================================== * 全map鯖総計での接続数設定 * (char鯖から送られてくる) @@ -121,7 +125,7 @@ int map_freeblock(void *bl) if (block_free_count >= block_free_max) { if (battle_config.error_log) - printf("map_freeblock: *WARNING* too many free block! %d %d\n", + PRINTF("map_freeblock: *WARNING* too many free block! %d %d\n", block_free_count, block_free_lock); } else @@ -152,7 +156,7 @@ int map_freeblock_unlock(void) int i; // if(block_free_count>0) { // if(battle_config.error_log) -// printf("map_freeblock_unlock: free %d object\n",block_free_count); +// PRINTF("map_freeblock_unlock: free %d object\n",block_free_count); // } for (i = 0; i < block_free_count; i++) { @@ -164,7 +168,7 @@ int map_freeblock_unlock(void) else if (block_free_lock < 0) { if (battle_config.error_log) - printf("map_freeblock_unlock: lock count < 0 !\n"); + PRINTF("map_freeblock_unlock: lock count < 0 !\n"); } return block_free_lock; } @@ -196,7 +200,7 @@ int map_addblock(struct block_list *bl) if (bl->prev != NULL) { if (battle_config.error_log) - printf("map_addblock error : bl->prev!=NULL\n"); + PRINTF("map_addblock error : bl->prev!=NULL\n"); return 0; } @@ -251,7 +255,7 @@ int map_delblock(struct block_list *bl) { // prevがNULLでnextがNULLでないのは有ってはならない if (battle_config.error_log) - printf("map_delblock error : bl->next!=NULL\n"); + PRINTF("map_delblock error : bl->next!=NULL\n"); } return 0; } @@ -385,7 +389,7 @@ void map_foreachinarea(std::function func, if (bl_list_count >= BL_LIST_MAX) { if (battle_config.error_log) - printf("map_foreachinarea: *WARNING* block count too many!\n"); + PRINTF("map_foreachinarea: *WARNING* block count too many!\n"); } map_freeblock_lock(); // メモリからの解放を禁止する @@ -539,7 +543,7 @@ void map_foreachinmovearea(std::function func, if (bl_list_count >= BL_LIST_MAX) { if (battle_config.error_log) - printf("map_foreachinarea: *WARNING* block count too many!\n"); + PRINTF("map_foreachinarea: *WARNING* block count too many!\n"); } map_freeblock_lock(); // メモリからの解放を禁止する @@ -596,7 +600,7 @@ void map_foreachincell(std::function func, if (bl_list_count >= BL_LIST_MAX) { if (battle_config.error_log) - printf("map_foreachincell: *WARNING* block count too many!\n"); + PRINTF("map_foreachincell: *WARNING* block count too many!\n"); } map_freeblock_lock(); // メモリからの解放を禁止する @@ -622,7 +626,7 @@ int map_addobject(struct block_list *bl) int i; if (bl == NULL) { - printf("map_addobject nullpo?\n"); + PRINTF("map_addobject nullpo?\n"); return 0; } if (first_free_object_id < 2 || first_free_object_id >= MAX_FLOORITEM) @@ -633,7 +637,7 @@ int map_addobject(struct block_list *bl) if (i >= MAX_FLOORITEM) { if (battle_config.error_log) - printf("no free object id\n"); + PRINTF("no free object id\n"); return 0; } first_free_object_id = i; @@ -656,9 +660,9 @@ int map_delobjectnofree(int id, BL type) if (object[id]->type != type) { - fprintf(stderr, "Incorrect type: expected %d, got %d\n", - uint8_t(type), - uint8_t(object[id]->type)); + FPRINTF(stderr, "Incorrect type: expected %d, got %d\n", + type, + object[id]->type); abort(); } @@ -720,7 +724,7 @@ void map_foreachobject(std::function func, if (bl_list_count >= BL_LIST_MAX) { if (battle_config.error_log) - printf("map_foreachobject: too many block !\n"); + PRINTF("map_foreachobject: too many block !\n"); } else bl_list[bl_list_count++] = object[i]; @@ -757,7 +761,7 @@ void map_clearflooritem_timer(timer_id tid, tick_t, custom_id_t id, custom_data_ || (!data && fitem->cleartimer != tid)) { if (battle_config.error_log) - printf("map_clearflooritem_timer : error\n"); + PRINTF("map_clearflooritem_timer : error\n"); return; } if (data) @@ -1305,7 +1309,7 @@ int map_addnpc(int m, struct npc_data *nd) if (i == MAX_NPC_PER_MAP) { if (battle_config.error_log) - printf("too many NPCs in one map %s\n", map[m].name); + PRINTF("too many NPCs in one map %s\n", map[m].name); return -1; } if (i == map[m].npc_num) @@ -1347,7 +1351,7 @@ void map_removenpc(void) } } } - printf("%d NPCs removed.\n", n); + PRINTF("%d NPCs removed.\n", n); } /*========================================== @@ -1521,7 +1525,7 @@ int map_setipport(const char *name, struct in_addr ip, int port) { // local -> check data if (ip.s_addr != clif_getip().s_addr || port != clif_getport()) { - printf("from char server : %s -> %s:%d\n", name, ip2str(ip), + PRINTF("from char server : %s -> %s:%d\n", name, ip2str(ip), port); return 1; } @@ -1548,48 +1552,12 @@ struct Waterlist int waterheight; } *waterlist = NULL; -static -void map_readwater(char *watertxt) -{ - char line[1024], w1[1024]; - FILE *fp = NULL; - int n = 0; - - fp = fopen_(watertxt, "r"); - if (fp == NULL) - { - printf("file not found: %s\n", watertxt); - return; - } - if (waterlist == NULL) - { - CREATE(waterlist, struct Waterlist, MAX_MAP_PER_SERVER); - } - while (fgets(line, 1020, fp) && n < MAX_MAP_PER_SERVER) - { - int wh, count; - if (line[0] == '/' && line[1] == '/') - continue; - if ((count = sscanf(line, "%s%d", w1, &wh)) < 1) - { - continue; - } - strcpy(waterlist[n].mapname, w1); - if (count >= 2) - waterlist[n].waterheight = wh; - else - waterlist[n].waterheight = 3; - n++; - } - fclose_(fp); -} - /*========================================== * マップ1枚読み込み *------------------------------------------ */ static -int map_readmap(int m, char *fn, char *) +int map_readmap(int m, const char *fn, char *) { int s; int x, y, xs, ys; @@ -1604,17 +1572,17 @@ int map_readmap(int m, char *fn, char *) if (gat == NULL) return -1; - printf("\rLoading Maps [%d/%d]: %-50s ", m, map_num, fn); + PRINTF("\rLoading Maps [%d/%d]: %-50s ", m, map_num, fn); fflush(stdout); map[m].m = m; xs = map[m].xs = *(short *)(gat); ys = map[m].ys = *(short *)(gat + 2); - printf("\n%i %i\n", xs, ys); + PRINTF("\n%i %i\n", xs, ys); map[m].gat = (uint8_t *)calloc(s = map[m].xs * map[m].ys, 1); if (map[m].gat == NULL) { - printf("out of memory : map_readmap gat\n"); + PRINTF("out of memory : map_readmap gat\n"); exit(1); } @@ -1653,7 +1621,7 @@ int map_readmap(int m, char *fn, char *) strdb_insert(map_db, map[m].name, &map[m]); -// printf("%s read done\n",fn); +// PRINTF("%s read done\n",fn); return 0; } @@ -1666,16 +1634,16 @@ static int map_readallmap(void) { int i, maps_removed = 0; - char fn[256] = ""; // 先に全部のャbプの存在を確認 for (i = 0; i < map_num; i++) { if (strstr(map[i].name, ".gat") == NULL) continue; - sprintf(fn, "data\\%s", map[i].name); + // TODO replace this + std::string fn = STRPRINTF("data\\%s", map[i].name); // TODO - remove this, it is the last call to grfio_size, which is deprecated - if (!grfio_size(fn)) + if (!grfio_size(fn.c_str())) { map_delmap(map[i].name); maps_removed++; @@ -1692,8 +1660,8 @@ int map_readallmap(void) *p = '\0'; strcpy(alias, map[i].name); strcpy(map[i].name, p + 1); - sprintf(fn, "data\\%s", map[i].name); - if (map_readmap(i, fn, alias) == -1) + std::string fn = STRPRINTF("data\\%s", map[i].name); + if (map_readmap(i, fn.c_str(), alias) == -1) { map_delmap(map[i].name); maps_removed++; @@ -1701,8 +1669,8 @@ int map_readallmap(void) } else { - sprintf(fn, "data\\%s", map[i].name); - if (map_readmap(i, fn, NULL) == -1) + std::string fn = STRPRINTF("data\\%s", map[i].name); + if (map_readmap(i, fn.c_str(), NULL) == -1) { map_delmap(map[i].name); maps_removed++; @@ -1712,8 +1680,8 @@ int map_readallmap(void) } free(waterlist); - printf("\rMaps Loaded: %d %60s\n", map_num, ""); - printf("\rMaps Removed: %d \n", maps_removed); + PRINTF("\rMaps Loaded: %d %60s\n", map_num, ""); + PRINTF("\rMaps Removed: %d \n", maps_removed); return 0; } @@ -1722,7 +1690,7 @@ int map_readallmap(void) *------------------------------------------ */ static -int map_addmap(char *mapname) +int map_addmap(const char *mapname) { if (strcasecmp(mapname, "clear") == 0) { @@ -1732,7 +1700,7 @@ int map_addmap(char *mapname) if (map_num >= MAX_MAP_PER_SERVER - 1) { - printf("too many map\n"); + PRINTF("too many map\n"); return 1; } memcpy(map[map_num].name, mapname, 24); @@ -1744,7 +1712,8 @@ int map_addmap(char *mapname) * 読み込むmapを削除する *------------------------------------------ */ -int map_delmap(char *mapname) +static +int map_delmap(const char *mapname) { int i; @@ -1758,7 +1727,7 @@ int map_delmap(char *mapname) { if (strcmp(map[i].name, mapname) == 0) { - printf("Removing map [ %s ] from maplist\n", map[i].name); + PRINTF("Removing map [ %s ] from maplist\n", map[i].name); memmove(map + i, map + i + 1, sizeof(map[0]) * (map_num - i - 1)); map_num--; @@ -1781,31 +1750,30 @@ void map_close_logfile(void) { if (map_logfile) { - char *filenameop_buf = (char*)malloc(strlen(map_logfile_name) + 50); - sprintf(filenameop_buf, "gzip -f %s.%ld", map_logfile_name, - map_logfile_index); + std::string filenameop_buf = STRPRINTF( + "gzip -f %s.%ld", + map_logfile_name, + map_logfile_index); fclose(map_logfile); - if (!system(filenameop_buf)) - perror(filenameop_buf); - - free(filenameop_buf); + if (!system(filenameop_buf.c_str())) + perror(filenameop_buf.c_str()); } } static void map_start_logfile(long suffix) { - char *filename_buf = (char*)malloc(strlen(map_logfile_name) + 50); map_logfile_index = suffix >> LOGFILE_SECONDS_PER_CHUNK_SHIFT; - sprintf(filename_buf, "%s.%ld", map_logfile_name, map_logfile_index); - map_logfile = fopen(filename_buf, "w+"); + std::string filename_buf = STRPRINTF( + "%s.%ld", + map_logfile_name, + map_logfile_index); + map_logfile = fopen(filename_buf.c_str(), "w+"); if (!map_logfile) perror(map_logfile_name); - - free(filename_buf); } static @@ -1821,12 +1789,12 @@ void map_set_logfile(const char *filename) MAP_LOG("log-start v3"); } -void map_write_log(const char *format, ...) +void map_log(const_string line) { - struct timeval tv; - va_list args; - va_start(args, format); + if (!map_logfile) + return; + struct timeval tv; gettimeofday(&tv, NULL); if ((tv.tv_sec >> LOGFILE_SECONDS_PER_CHUNK_SHIFT) != map_logfile_index) @@ -1835,9 +1803,16 @@ void map_write_log(const char *format, ...) map_start_logfile(tv.tv_sec); } - fprintf(map_logfile, "%ld.%06ld ", (long) tv.tv_sec, (long) tv.tv_usec); - vfprintf(map_logfile, format, args); - fputc('\n', map_logfile); + if (!line) + { + fputc('\n', map_logfile); + return; + } + + FPRINTF(map_logfile, "%ld.%06ld ", (long) tv.tv_sec, (long) tv.tv_usec); + fwrite(line.data(), 1, line.size(), map_logfile); + if (line.back() != '\n') + fputc('\n', map_logfile); } /*========================================== @@ -1847,126 +1822,118 @@ void map_write_log(const char *format, ...) static int map_config_read(const char *cfgName) { - char line[1024], w1[1024], w2[1024]; - FILE *fp; struct hostent *h = NULL; - fp = fopen_(cfgName, "r"); - if (fp == NULL) + std::ifstream in(cfgName); + if (!in.is_open()) { - printf("Map configuration file not found at: %s\n", cfgName); + PRINTF("Map configuration file not found at: %s\n", cfgName); exit(1); } - while (fgets(line, sizeof(line) - 1, fp)) + + std::string line; + while (std::getline(in, line)) { - if (line[0] == '/' && line[1] == '/') + std::string w1, w2; + if (!split_key_value(line, &w1, &w2)) continue; - if (sscanf(line, "%[^:]: %[^\r\n]", w1, w2) == 2) + if (w1 == "userid") { - if (strcasecmp(w1, "userid") == 0) - { - chrif_setuserid(w2); - } - else if (strcasecmp(w1, "passwd") == 0) - { - chrif_setpasswd(w2); - } - else if (strcasecmp(w1, "char_ip") == 0) + chrif_setuserid(w2.c_str()); + } + else if (w1 == "passwd") + { + chrif_setpasswd(w2.c_str()); + } + else if (w1 == "char_ip") + { + h = gethostbyname(w2.c_str()); + if (h != NULL) { - h = gethostbyname(w2); - if (h != NULL) - { - printf("Character server IP address : %s -> %d.%d.%d.%d\n", - w2, (unsigned char) h->h_addr[0], + PRINTF("Character server IP address : %s -> %d.%d.%d.%d\n", + w2, (unsigned char) h->h_addr[0], + (unsigned char) h->h_addr[1], + (unsigned char) h->h_addr[2], + (unsigned char) h->h_addr[3]); + SPRINTF(w2, "%d.%d.%d.%d", (unsigned char) h->h_addr[0], (unsigned char) h->h_addr[1], (unsigned char) h->h_addr[2], (unsigned char) h->h_addr[3]); - sprintf(w2, "%d.%d.%d.%d", (unsigned char) h->h_addr[0], - (unsigned char) h->h_addr[1], - (unsigned char) h->h_addr[2], - (unsigned char) h->h_addr[3]); - } - chrif_setip(w2); - } - else if (strcasecmp(w1, "char_port") == 0) - { - chrif_setport(atoi(w2)); - } - else if (strcasecmp(w1, "map_ip") == 0) - { - h = gethostbyname(w2); - if (h != NULL) - { - printf("Map server IP address : %s -> %d.%d.%d.%d\n", w2, - (unsigned char) h->h_addr[0], - (unsigned char) h->h_addr[1], - (unsigned char) h->h_addr[2], - (unsigned char) h->h_addr[3]); - sprintf(w2, "%d.%d.%d.%d", (unsigned char) h->h_addr[0], - (unsigned char) h->h_addr[1], - (unsigned char) h->h_addr[2], - (unsigned char) h->h_addr[3]); - } - clif_setip(w2); - } - else if (strcasecmp(w1, "map_port") == 0) - { - clif_setport(atoi(w2)); - map_port = (atoi(w2)); - } - else if (strcasecmp(w1, "water_height") == 0) - { - map_readwater(w2); } - else if (strcasecmp(w1, "map") == 0) - { - map_addmap(w2); - } - else if (strcasecmp(w1, "delmap") == 0) - { - map_delmap(w2); - } - else if (strcasecmp(w1, "npc") == 0) - { - npc_addsrcfile(w2); - } - else if (strcasecmp(w1, "delnpc") == 0) - { - npc_delsrcfile(w2); - } - else if (strcasecmp(w1, "autosave_time") == 0) - { - autosave_interval = atoi(w2) * 1000; - if (autosave_interval <= 0) - autosave_interval = DEFAULT_AUTOSAVE_INTERVAL; - } - else if (strcasecmp(w1, "motd_txt") == 0) - { - strcpy(motd_txt, w2); - } - else if (strcasecmp(w1, "help_txt") == 0) - { - strcpy(help_txt, w2); - } - else if (strcasecmp(w1, "mapreg_txt") == 0) - { - strcpy(mapreg_txt, w2); - } - else if (strcasecmp(w1, "gm_log") == 0) - { - gm_logfile_name = strdup(w2); - } - else if (strcasecmp(w1, "log_file") == 0) - { - map_set_logfile(w2); - } - else if (strcasecmp(w1, "import") == 0) + chrif_setip(w2.c_str()); + } + else if (w1 == "char_port") + { + chrif_setport(atoi(w2.c_str())); + } + else if (w1 == "map_ip") + { + h = gethostbyname(w2.c_str()); + if (h != NULL) { - map_config_read(w2); + PRINTF("Map server IP address : %s -> %d.%d.%d.%d\n", w2, + (unsigned char) h->h_addr[0], + (unsigned char) h->h_addr[1], + (unsigned char) h->h_addr[2], + (unsigned char) h->h_addr[3]); + SPRINTF(w2, "%d.%d.%d.%d", (unsigned char) h->h_addr[0], + (unsigned char) h->h_addr[1], + (unsigned char) h->h_addr[2], + (unsigned char) h->h_addr[3]); } + clif_setip(w2.c_str()); + } + else if (w1 == "map_port") + { + clif_setport(atoi(w2.c_str())); + } + else if (w1 == "map") + { + map_addmap(w2.c_str()); + } + else if (w1 == "delmap") + { + map_delmap(w2.c_str()); + } + else if (w1 == "npc") + { + npc_addsrcfile(w2.c_str()); + } + else if (w1 == "delnpc") + { + npc_delsrcfile(w2.c_str()); + } + else if (w1 == "autosave_time") + { + autosave_interval = atoi(w2.c_str()) * 1000; + if (autosave_interval <= 0) + autosave_interval = DEFAULT_AUTOSAVE_INTERVAL; + } + else if (w1 == "motd_txt") + { + strzcpy(motd_txt, w2.c_str(), sizeof(motd_txt)); + } + else if (w1 == "help_txt") + { + strzcpy(help_txt, w2.c_str(), sizeof(help_txt)); + } + else if (w1 == "mapreg_txt") + { + strzcpy(mapreg_txt, w2.c_str(), sizeof(mapreg_txt)); + } + else if (w1 == "gm_log") + { + gm_logfile_name = strdup(w2.c_str()); + } + else if (w1 == "log_file") + { + map_set_logfile(w2.c_str()); + } + else if (w1 == "import") + { + map_config_read(w2.c_str()); } } - fclose_(fp); return 0; } @@ -2075,7 +2042,6 @@ int do_init(int argc, char *argv[]) const char *MAP_CONF_NAME = "conf/map_athena.conf"; const char *BATTLE_CONF_FILENAME = "conf/battle_athena.conf"; const char *ATCOMMAND_CONF_FILENAME = "conf/atcommand_athena.conf"; - const char *SCRIPT_CONF_NAME = "conf/script_athena.conf"; for (i = 1; i < argc; i++) { @@ -2089,14 +2055,12 @@ int do_init(int argc, char *argv[]) BATTLE_CONF_FILENAME = argv[i + 1]; else if (strcmp(argv[i], "--atcommand_config") == 0) ATCOMMAND_CONF_FILENAME = argv[i + 1]; - else if (strcmp(argv[i], "--script_config") == 0) - SCRIPT_CONF_NAME = argv[i + 1]; } map_config_read(MAP_CONF_NAME); battle_config_read(BATTLE_CONF_FILENAME); atcommand_config_read(ATCOMMAND_CONF_FILENAME); - script_config_read(SCRIPT_CONF_NAME); + script_config_read(); id_db = numdb_init(); map_db = strdb_init(16); @@ -2122,9 +2086,9 @@ int do_init(int argc, char *argv[]) npc_event_do_oninit(); // npcのOnInitイベント実行 if (battle_config.pk_mode == 1) - printf("The server is running in \033[1;31mPK Mode\033[0m.\n"); + PRINTF("The server is running in \033[1;31mPK Mode\033[0m.\n"); - printf("The map-server is \033[1;32mready\033[0m (Server is listening on the port %d).\n\n", + PRINTF("The map-server is \033[1;32mready\033[0m (Server is listening on the port %d).\n\n", map_port); return 0; diff --git a/src/map/map.hpp b/src/map/map.hpp index 7f75427..3d15bb5 100644 --- a/src/map/map.hpp +++ b/src/map/map.hpp @@ -9,6 +9,7 @@ #include #include +#include "../common/cxxstdio.hpp" #include "../common/db.hpp" #include "../common/mmo.hpp" #include "../common/timer.hpp" @@ -699,10 +700,9 @@ int map_quit(struct map_session_data *); // npc int map_addnpc(int, struct npc_data *); -extern FILE *map_logfile; -__attribute__((format(printf, 1, 2))) -void map_write_log(const char *format, ...); -#define MAP_LOG(format, args...) {if (map_logfile) map_write_log(format, ##args);} +void map_log(const_string line); +#define MAP_LOG(format, args...) \ + map_log(static_cast(STRPRINTF(format, ##args))); #define MAP_LOG_PC(sd, fmt, args...) MAP_LOG("PC%d %d:%d,%d " fmt, sd->status.char_id, sd->bl.m, sd->bl.x, sd->bl.y, ## args) @@ -754,7 +754,4 @@ int map_calc_dir(struct block_list *src, int x, int y); int path_search(struct walkpath_data *, int, int, int, int, int, int); int path_blownpos(int m, int x0, int y0, int dx, int dy, int count); - -int map_delmap(char *mapname); - #endif // MAP_HPP diff --git a/src/map/mob.cpp b/src/map/mob.cpp index abd6260..7c26ceb 100644 --- a/src/map/mob.cpp +++ b/src/map/mob.cpp @@ -295,7 +295,7 @@ int mob_gen_exp(struct mob_db *mob) (double) battle_config.base_exp_rate / 100.); if (xp < 1) xp = 1; - printf("Exp for mob '%s' generated: %d\n", mob->name, xp); + PRINTF("Exp for mob '%s' generated: %d\n", mob->name, xp); return xp; } @@ -395,7 +395,7 @@ int mob_once_spawn(struct map_session_data *sd, const char *mapname, return 0; } // if(battle_config.etc_log==1) -// printf("mobmob_class=%d try=%d\n",mob_class,i); +// PRINTF("mobmob_class=%d try=%d\n",mob_class,i); } if (sd) { @@ -406,7 +406,7 @@ int mob_once_spawn(struct map_session_data *sd, const char *mapname, } else if (x <= 0 || y <= 0) { - printf("mob_once_spawn: ??\n"); + PRINTF("mob_once_spawn: ??\n"); } for (count = 0; count < amount; count++) @@ -522,7 +522,7 @@ int mob_spawn_guardian(struct map_session_data *sd, const char *mapname, } else if (x <= 0 || y <= 0) - printf("mob_spawn_guardian: ??\n"); + PRINTF("mob_spawn_guardian: ??\n"); for (count = 0; count < amount; count++) { @@ -1021,7 +1021,7 @@ void mob_timer(timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) if (md->timer != tid) { if (battle_config.error_log == 1) - printf("mob_timer %d != %d\n", md->timer, tid); + PRINTF("mob_timer %d != %d\n", md->timer, tid); return; } md->timer = -1; @@ -1043,8 +1043,8 @@ void mob_timer(timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) break; default: if (battle_config.error_log == 1) - printf("mob_timer : %d ?\n", - uint8_t(md->state.state)); + PRINTF("mob_timer : %d ?\n", + md->state.state); break; } map_freeblock_unlock(); @@ -1223,7 +1223,7 @@ int mob_spawn(int id) if (i >= 50) { // if(battle_config.error_log==1) - // printf("MOB spawn error %d @ %s\n",id,map[md->bl.m].name); + // PRINTF("MOB spawn error %d @ %s\n",id,map[md->bl.m].name); add_timer(tick + 5000, mob_delayspawn, id, 0); return 1; } @@ -1848,7 +1848,7 @@ int mob_randomwalk(struct mob_data *md, int tick) if (md->move_fail_count > 1000) { if (battle_config.error_log == 1) - printf("MOB cant move. random spawn %d, mob_class = %d\n", + PRINTF("MOB cant move. random spawn %d, mob_class = %d\n", md->bl.id, md->mob_class); md->move_fail_count = 0; mob_spawn(md->bl.id); @@ -2532,11 +2532,11 @@ int mob_damage(struct block_list *src, struct mob_data *md, int damage, } // if(battle_config.battle_log) -// printf("mob_damage %d %d %d\n",md->hp,max_hp,damage); +// PRINTF("mob_damage %d %d %d\n",md->hp,max_hp,damage); if (md->bl.prev == NULL) { if (battle_config.error_log == 1) - printf("mob_damage : BlockError!!\n"); + PRINTF("mob_damage : BlockError!!\n"); return 0; } @@ -3112,7 +3112,7 @@ void mob_warpslave_sub(struct block_list *bl, int id, int x, int y) static int mob_warpslave(struct mob_data *md, int x, int y) { -//printf("warp slave\n"); +//PRINTF("warp slave\n"); map_foreachinarea(std::bind(mob_warpslave_sub, ph::_1, md->bl.id, md->bl.x, md->bl.y), md->bl.m, x - AREA_SIZE, y - AREA_SIZE, x + AREA_SIZE, y + AREA_SIZE, BL_MOB); @@ -3174,7 +3174,7 @@ int mob_warp(struct mob_data *md, int m, int x, int y, int type) { m = md->bl.m; if (battle_config.error_log == 1) - printf("MOB %d warp failed, mob_class = %d\n", md->bl.id, md->mob_class); + PRINTF("MOB %d warp failed, mob_class = %d\n", md->bl.id, md->mob_class); } md->target_id = 0; // タゲを解除する @@ -3186,7 +3186,7 @@ int mob_warp(struct mob_data *md, int m, int x, int y, int type) if (type > 0 && i == 1000) { if (battle_config.battle_log == 1) - printf("MOB %d warp to (%d,%d), mob_class = %d\n", md->bl.id, x, y, + PRINTF("MOB %d warp to (%d,%d), mob_class = %d\n", md->bl.id, x, y, md->mob_class); } @@ -3399,7 +3399,7 @@ void mobskill_castend_id(timer_id tid, tick_t tick, custom_id_t id, custom_data_ return; if ((md = (struct mob_data *) mbl) == NULL) { - printf("mobskill_castend_id nullpo mbl->id:%d\n", mbl->id); + PRINTF("mobskill_castend_id nullpo mbl->id:%d\n", mbl->id); return; } if (md->bl.type != BL_MOB || md->bl.prev == NULL) @@ -3426,7 +3426,7 @@ void mobskill_castend_id(timer_id tid, tick_t tick, custom_id_t id, custom_data_ if ((bl = map_id2bl(md->skilltarget)) == NULL || bl->prev == NULL) { //スキルターゲットが存在しない - //printf("mobskill_castend_id nullpo\n");//ターゲットがいないときはnullpoじゃなくて普通に終了 + //PRINTF("mobskill_castend_id nullpo\n");//ターゲットがいないときはnullpoじゃなくて普通に終了 return; } if (md->bl.m != bl->m) @@ -3462,8 +3462,8 @@ void mobskill_castend_id(timer_id tid, tick_t tick, custom_id_t id, custom_data_ md->skilldelay[md->skillidx] = tick; if (battle_config.mob_skill_log == 1) - printf("MOB skill castend skill=%d, mob_class = %d\n", - uint16_t(md->skillid), md->mob_class); + PRINTF("MOB skill castend skill=%d, mob_class = %d\n", + md->skillid, md->mob_class); mob_stop_walking(md, 0); switch (skill_get_nk(md->skillid)) @@ -3611,8 +3611,8 @@ void mobskill_castend_pos(timer_id tid, tick_t tick, custom_id_t id, custom_data md->skilldelay[md->skillidx] = tick; if (battle_config.mob_skill_log == 1) - printf("MOB skill castend skill=%d, mob_class = %d\n", - uint16_t(md->skillid), md->mob_class); + PRINTF("MOB skill castend skill=%d, mob_class = %d\n", + md->skillid, md->mob_class); mob_stop_walking(md, 0); skill_castend_pos2(&md->bl, md->skillx, md->skilly, md->skillid, @@ -3697,8 +3697,8 @@ int mobskill_use_id(struct mob_data *md, struct block_list *target, } if (battle_config.mob_skill_log == 1) - printf("MOB skill use target_id=%d skill=%d lv=%d cast=%d, mob_class = %d\n", - target->id, uint16_t(skill_id), skill_lv, + PRINTF("MOB skill use target_id=%d skill=%d lv=%d cast=%d, mob_class = %d\n", + target->id, skill_id, skill_lv, casttime, md->mob_class); if (casttime <= 0) // 詠唱の無いものはキャンセルされない @@ -3784,8 +3784,8 @@ int mobskill_use_pos(struct mob_data *md, md->state.skillcastcancel = ms->cancel; if (battle_config.mob_skill_log == 1) - printf("MOB skill use target_pos= (%d,%d) skill=%d lv=%d cast=%d, mob_class = %d\n", - skill_x, skill_y, uint16_t(skill_id), skill_lv, + PRINTF("MOB skill use target_pos= (%d,%d) skill=%d lv=%d cast=%d, mob_class = %d\n", + skill_x, skill_y, skill_id, skill_lv, casttime, md->mob_class); if (casttime <= 0) // A skill without a cast time wont be cancelled. @@ -4368,7 +4368,7 @@ int mob_readdb(void) mob_db[mob_class].base_exp = mob_gen_exp(&mob_db[mob_class]); } fclose_(fp); - printf("read %s done\n", filename[j]); + PRINTF("read %s done\n", filename[j]); } return 0; } @@ -4388,7 +4388,7 @@ int mob_readdb_mobavail(void) if ((fp = fopen_("db/mob_avail.txt", "r")) == NULL) { - printf("can't read db/mob_avail.txt\n"); + PRINTF("can't read db/mob_avail.txt\n"); return -1; } @@ -4442,7 +4442,7 @@ int mob_readdb_mobavail(void) ln++; } fclose_(fp); - printf("read db/mob_avail.txt done (count=%d)\n", ln); + PRINTF("read db/mob_avail.txt done (count=%d)\n", ln); return 0; } @@ -4470,7 +4470,7 @@ int mob_read_randommonster(void) fp = fopen_(mobfile[i], "r"); if (fp == NULL) { - printf("can't read %s\n", mobfile[i]); + PRINTF("can't read %s\n", mobfile[i]); return -1; } while (fgets(line, 1020, fp)) @@ -4496,7 +4496,7 @@ int mob_read_randommonster(void) mob_db[mob_class].summonper[i] = per; } fclose_(fp); - printf("read %s done\n", mobfile[i]); + PRINTF("read %s done\n", mobfile[i]); } return 0; } @@ -4599,7 +4599,7 @@ int mob_readskilldb(void) if (fp == NULL) { if (x == 0) - printf("can't read %s\n", filename[x]); + PRINTF("can't read %s\n", filename[x]); continue; } while (fgets(line, 1020, fp)) @@ -4635,7 +4635,7 @@ int mob_readskilldb(void) break; if (i == MAX_MOBSKILL) { - printf("mob_skill: readdb: too many skill ! [%s] in %d[%s]\n", + PRINTF("mob_skill: readdb: too many skill ! [%s] in %d[%s]\n", sp[1], mob_id, mob_db[mob_id].jname); continue; } @@ -4687,7 +4687,7 @@ int mob_readskilldb(void) mob_db[mob_id].maxskill = i + 1; } fclose_(fp); - printf("read %s done\n", filename[x]); + PRINTF("read %s done\n", filename[x]); } return 0; } diff --git a/src/map/npc.cpp b/src/map/npc.cpp index c40e946..8966d49 100644 --- a/src/map/npc.cpp +++ b/src/map/npc.cpp @@ -142,7 +142,7 @@ int npc_event_dequeue(struct map_session_data *sd) { if (!pc_addeventtimer(sd, 100, sd->eventqueue[0])) { - printf("npc_event_dequeue(): Event timer is full.\n"); + PRINTF("npc_event_dequeue(): Event timer is full.\n"); return 0; } @@ -191,7 +191,7 @@ int npc_timer_event(const char *eventname) // Added by RoVeRT if ((ev == NULL || (nd = ev->nd) == NULL)) { - printf("npc_event: event not found [%s]\n", eventname); + PRINTF("npc_event: event not found [%s]\n", eventname); return 0; } @@ -269,30 +269,28 @@ int npc_event_do_l(const char *name, int rid, int argc, argrec_t *args) static void npc_event_do_clock(timer_id, tick_t, custom_id_t, custom_data_t) { - time_t timer; - struct tm *t; - char buf[64]; - int c = 0; - - time(&timer); - t = gmtime(&timer); + time_t timer = time(NULL); + struct tm *t = gmtime(&timer); if (t->tm_min != ev_tm_b.tm_min) { - sprintf(buf, "OnMinute%02d", t->tm_min); - c += npc_event_doall(buf); - sprintf(buf, "OnClock%02d%02d", t->tm_hour, t->tm_min); - c += npc_event_doall(buf); + std::string buf; + buf = STRPRINTF("OnMinute%02d", t->tm_min); + npc_event_doall(buf.c_str()); + buf = STRPRINTF("OnClock%02d%02d", t->tm_hour, t->tm_min); + npc_event_doall(buf.c_str()); } if (t->tm_hour != ev_tm_b.tm_hour) { - sprintf(buf, "OnHour%02d", t->tm_hour); - c += npc_event_doall(buf); + std::string buf; + buf = STRPRINTF("OnHour%02d", t->tm_hour); + npc_event_doall(buf.c_str()); } if (t->tm_mday != ev_tm_b.tm_mday) { - sprintf(buf, "OnDay%02d%02d", t->tm_mon + 1, t->tm_mday); - c += npc_event_doall(buf); + std::string buf; + buf = STRPRINTF("OnDay%02d%02d", t->tm_mon + 1, t->tm_mday); + npc_event_doall(buf.c_str()); } memcpy(&ev_tm_b, t, sizeof(ev_tm_b)); } @@ -304,7 +302,7 @@ void npc_event_do_clock(timer_id, tick_t, custom_id_t, custom_data_t) int npc_event_do_oninit(void) { int c = npc_event_doall("OnInit"); - printf("npc: OnInit Event done. (%d npc)\n", c); + PRINTF("npc: OnInit Event done. (%d npc)\n", c); add_timer_interval(gettick() + 100, npc_event_do_clock, 0, 0, 1000); @@ -332,7 +330,7 @@ int npc_addeventtimer(struct npc_data *nd, int tick, const char *name) (int) evname); } else - printf("npc_addtimer: event timer is full !\n"); + PRINTF("npc_addtimer: event timer is full !\n"); return 0; } @@ -404,7 +402,7 @@ void npc_timerevent(timer_id, tick_t tick, custom_id_t id, custom_data_t data) struct npc_timerevent_list *te; if (nd == NULL || nd->u.scr.nexttimer < 0) { - printf("npc_timerevent: ??\n"); + PRINTF("npc_timerevent: ??\n"); return; } nd->u.scr.timertick = tick; @@ -522,7 +520,7 @@ int npc_event(struct map_session_data *sd, const char *eventname, if (sd == NULL) { - printf("npc_event nullpo?\n"); + PRINTF("npc_event nullpo?\n"); } if (ev == NULL && eventname @@ -539,14 +537,14 @@ int npc_event(struct map_session_data *sd, const char *eventname, if (ev == NULL || (nd = ev->nd) == NULL) { if (strncasecmp(eventname, "GM_MONSTER", 10) != 0) - printf("npc_event: event not found [%s]\n", mobevent); + PRINTF("npc_event: event not found [%s]\n", mobevent); return 0; } } else { if (battle_config.error_log) - printf("npc_event: event not found [%s]\n", eventname); + PRINTF("npc_event: event not found [%s]\n", eventname); return 0; } } @@ -568,7 +566,7 @@ int npc_event(struct map_session_data *sd, const char *eventname, if (sd->npc_id != 0) { // if (battle_config.error_log) -// printf("npc_event: npc_id != 0\n"); +// PRINTF("npc_event: npc_id != 0\n"); int i; for (i = 0; i < MAX_EVENTQUEUE; i++) if (!sd->eventqueue[i][0]) @@ -576,12 +574,12 @@ int npc_event(struct map_session_data *sd, const char *eventname, if (i == MAX_EVENTQUEUE) { if (battle_config.error_log) - printf("npc_event: event queue is full !\n"); + PRINTF("npc_event: event queue is full !\n"); } else { // if (battle_config.etc_log) -// printf("npc_event: enqueue\n"); +// PRINTF("npc_event: enqueue\n"); strncpy(sd->eventqueue[i], eventname, 50); sd->eventqueue[i][49] = '\0'; } @@ -670,7 +668,7 @@ int npc_touch_areanpc(struct map_session_data *sd, int m, int x, int y) if (f) { if (battle_config.error_log) - printf("npc_touch_areanpc : some bug \n"); + PRINTF("npc_touch_areanpc : some bug \n"); } return 1; } @@ -714,7 +712,7 @@ int npc_checknear(struct map_session_data *sd, int id) if (nd == NULL || nd->bl.type != BL_NPC) { if (battle_config.error_log) - printf("no such npc : %d\n", id); + PRINTF("no such npc : %d\n", id); return 1; } @@ -745,7 +743,7 @@ int npc_click(struct map_session_data *sd, int id) if (sd->npc_id != 0) { if (battle_config.error_log) - printf("npc_click: npc_id != 0\n"); + PRINTF("npc_click: npc_id != 0\n"); return 1; } @@ -829,7 +827,7 @@ int npc_buysellsel(struct map_session_data *sd, int id, int type) if (nd->bl.subtype != SHOP) { if (battle_config.error_log) - printf("no such shop npc : %d\n", id); + PRINTF("no such shop npc : %d\n", id); sd->npc_id = 0; return 1; } @@ -1060,7 +1058,7 @@ void npc_clearsrcfile(void) * 読み込むnpcファイルの追加 *------------------------------------------ */ -void npc_addsrcfile(char *name) +void npc_addsrcfile(const char *name) { struct npc_src_list *new_src; size_t len; @@ -1087,7 +1085,7 @@ void npc_addsrcfile(char *name) * 読み込むnpcファイルの削除 *------------------------------------------ */ -void npc_delsrcfile(char *name) +void npc_delsrcfile(const char *name) { struct npc_src_list *p = npc_src_first, *pp = NULL, **lp = &npc_src_first; @@ -1126,7 +1124,7 @@ int npc_parse_warp(const char *w1, const char *, const char *w3, const char *w4) sscanf(w4, "%d,%d,%[^,],%d,%d", &xs, &ys, to_mapname, &to_x, &to_y) != 5) { - printf("bad warp line : %s\n", w3); + PRINTF("bad warp line : %s\n", w3); return 1; } @@ -1175,7 +1173,7 @@ int npc_parse_warp(const char *w1, const char *, const char *w3, const char *w4) } } -// printf("warp npc %s %d read done\n",mapname,nd->bl.id); +// PRINTF("warp npc %s %d read done\n",mapname,nd->bl.id); npc_warp++; nd->bl.type = BL_NPC; nd->bl.subtype = WARP; @@ -1203,7 +1201,7 @@ int npc_parse_shop(char *w1, char *, char *w3, char *w4) if (sscanf(w1, "%[^,],%d,%d,%d", mapname, &x, &y, &dir) != 4 || strchr(w4, ',') == NULL) { - printf("bad shop line : %s\n", w3); + PRINTF("bad shop line : %s\n", w3); return 1; } m = map_mapname2mapid(mapname); @@ -1274,7 +1272,7 @@ int npc_parse_shop(char *w1, char *, char *w3, char *w4) nd = (struct npc_data *) realloc(nd, sizeof(struct npc_data) + sizeof(nd->u.shop_item[0]) * pos); - //printf("shop npc %s %d read done\n",mapname,nd->bl.id); + //PRINTF("shop npc %s %d read done\n",mapname,nd->bl.id); npc_shop++; nd->bl.type = BL_NPC; nd->bl.subtype = SHOP; @@ -1359,7 +1357,7 @@ int npc_parse_script(char *w1, char *w2, char *w3, char *w4, if (sscanf(w1, "%[^,],%d,%d,%d", mapname, &x, &y, &dir) != 4 || (strcmp(w2, "script") == 0 && strchr(w4, ',') == NULL)) { - printf("bad script line : %s\n", w3); + PRINTF("bad script line : %s\n", w3); return 1; } m = map_mapname2mapid(mapname); @@ -1421,12 +1419,12 @@ int npc_parse_script(char *w1, char *w2, char *w3, char *w4, struct npc_data *nd2; if (sscanf(w2, "duplicate (%[^)])", srcname) != 1) { - printf("bad duplicate name! : %s", w2); + PRINTF("bad duplicate name! : %s", w2); return 0; } if ((nd2 = npc_name2id(srcname)) == NULL) { - printf("bad duplicate name! (not exist) : %s\n", srcname); + PRINTF("bad duplicate name! (not exist) : %s\n", srcname); return 0; } script = nd2->u.scr.script; @@ -1518,7 +1516,7 @@ int npc_parse_script(char *w1, char *w2, char *w3, char *w4, nd->opt2 = Opt2::ZERO; nd->opt3 = Opt3::ZERO; - //printf("script npc %s %d %d read done\n",mapname,nd->bl.id,nd->class); + //PRINTF("script npc %s %d %d read done\n",mapname,nd->bl.id,nd->class); npc_script++; nd->bl.type = BL_NPC; nd->bl.subtype = SCRIPT; @@ -1583,7 +1581,7 @@ int npc_parse_script(char *w1, char *w2, char *w3, char *w4, buf = (char *) calloc(50, sizeof(char)); if (strlen(lname) > 24) { - printf("npc_parse_script: label name error !\n"); + PRINTF("npc_parse_script: label name error !\n"); exit(1); } else @@ -1709,7 +1707,7 @@ int npc_parse_function(char *, char *, char *w3, char *, // もう使わないのでバッファ解放 free(srcbuf); -// printf("function %s => %p\n",p,script); +// PRINTF("function %s => %p\n",p,script); return 0; } @@ -1734,7 +1732,7 @@ int npc_parse_mob(const char *w1, const char *, const char *w3, const char *w4) sscanf(w4, "%d,%d,%d,%d,%s", &mob_class, &num, &delay1, &delay2, eventname) < 2) { - printf("bad monster line : %s\n", w3); + PRINTF("bad monster line : %s\n", w3); return 1; } @@ -1797,7 +1795,7 @@ int npc_parse_mob(const char *w1, const char *, const char *w3, const char *w4) npc_mob++; } - //printf("warp npc %s %d read done\n",mapname,nd->bl.id); + //PRINTF("warp npc %s %d read done\n",mapname,nd->bl.id); return 0; } @@ -2088,7 +2086,7 @@ int do_init_npc(void) fp = fopen_(nsl->name, "r"); if (fp == NULL) { - printf("file not found : %s\n", nsl->name); + PRINTF("file not found : %s\n", nsl->name); exit(1); } lines = 0; @@ -2177,11 +2175,11 @@ int do_init_npc(void) } } fclose_(fp); - printf("\rLoading NPCs [%d]: %-54s", npc_id - START_NPC_NUM, + PRINTF("\rLoading NPCs [%d]: %-54s", npc_id - START_NPC_NUM, nsl->name); fflush(stdout); } - printf("\rNPCs Loaded: %d [Warps:%d Shops:%d Scripts:%d Mobs:%d]\n", + PRINTF("\rNPCs Loaded: %d [Warps:%d Shops:%d Scripts:%d Mobs:%d]\n", npc_id - START_NPC_NUM, npc_warp, npc_shop, npc_script, npc_mob); return 0; diff --git a/src/map/npc.hpp b/src/map/npc.hpp index 0654701..fba0ec0 100644 --- a/src/map/npc.hpp +++ b/src/map/npc.hpp @@ -38,8 +38,8 @@ struct npc_data *npc_spawn_text(int m, int x, int y, int class_, const char *nam */ void npc_free(struct npc_data *npc); -void npc_addsrcfile(char *); -void npc_delsrcfile(char *); +void npc_addsrcfile(const char *); +void npc_delsrcfile(const char *); int do_init_npc(void); int npc_event_do_oninit(void); int npc_do_ontimer(int, struct map_session_data *, int); diff --git a/src/map/party.cpp b/src/map/party.cpp index 46374d3..9b9470c 100644 --- a/src/map/party.cpp +++ b/src/map/party.cpp @@ -97,7 +97,7 @@ int party_created(int account_id, int fail, int party_id, const char *name) if ((p = (struct party *)numdb_search(party_db, party_id)) != NULL) { - printf("party_created(): ID already exists!\n"); + PRINTF("party_created(): ID already exists!\n"); exit(1); } @@ -152,7 +152,7 @@ int party_check_member(struct party *p) { sd->status.party_id = 0; if (battle_config.error_log) - printf("party: check_member %d[%s] is not member\n", + PRINTF("party: check_member %d[%s] is not member\n", sd->status.account_id, sd->status.name); } } @@ -327,7 +327,7 @@ int party_member_added(int party_id, int account_id, int flag) if (flag == 0) { if (battle_config.error_log) - printf("party: member added error %d is not online\n", + PRINTF("party: member added error %d is not online\n", account_id); intif_party_leave(party_id, account_id); // キャラ側に登録できなかったため脱退要求を出す } @@ -339,7 +339,7 @@ int party_member_added(int party_id, int account_id, int flag) if (p == NULL) { - printf("party_member_added: party %d not found.\n", party_id); + PRINTF("party_member_added: party %d not found.\n", party_id); intif_party_leave(party_id, account_id); return 0; } @@ -509,7 +509,7 @@ int party_recv_movemap(int party_id, int account_id, const char *mapname, int on struct party_member *m = &p->member[i]; if (m == NULL) { - printf("party_recv_movemap nullpo?\n"); + PRINTF("party_recv_movemap nullpo?\n"); return 0; } if (m->account_id == account_id) @@ -523,7 +523,7 @@ int party_recv_movemap(int party_id, int account_id, const char *mapname, int on if (i == MAX_PARTY) { if (battle_config.error_log) - printf("party: not found member %d on %d[%s]", account_id, + PRINTF("party: not found member %d on %d[%s]", account_id, party_id, p->name); return 0; } diff --git a/src/map/path.cpp b/src/map/path.cpp index afdae03..596332c 100644 --- a/src/map/path.cpp +++ b/src/map/path.cpp @@ -28,7 +28,7 @@ void push_heap_path(int *heap, struct tmp_path *tp, int index) if (heap == NULL || tp == NULL) { - printf("push_heap_path nullpo\n"); + PRINTF("push_heap_path nullpo\n"); return; } @@ -58,7 +58,7 @@ void update_heap_path(int *heap, struct tmp_path *tp, int index) break; if (h == heap[0]) { - fprintf(stderr, "update_heap_path bug\n"); + FPRINTF(stderr, "update_heap_path bug\n"); exit(1); } for (i = (h - 1) / 2; @@ -232,13 +232,13 @@ int path_blownpos(int m, int x0, int y0, int dx, int dy, int count) if (count > 15) { // 最大10マスに制限 if (battle_config.error_log) - printf("path_blownpos: count too many %d !\n", count); + PRINTF("path_blownpos: count too many %d !\n", count); count = 15; } if (dx > 1 || dx < -1 || dy > 1 || dy < -1) { if (battle_config.error_log) - printf("path_blownpos: illeagal dx=%d or dy=%d !\n", dx, dy); + PRINTF("path_blownpos: illeagal dx=%d or dy=%d !\n", dx, dy); dx = (dx >= 0) ? 1 : ((dx < 0) ? -1 : 0); dy = (dy >= 0) ? 1 : ((dy < 0) ? -1 : 0); } diff --git a/src/map/pc.cpp b/src/map/pc.cpp index 8a5a587..c25f512 100644 --- a/src/map/pc.cpp +++ b/src/map/pc.cpp @@ -224,7 +224,7 @@ void pc_invincible_timer(timer_id tid, tick_t, custom_id_t id, custom_data_t) if (sd->invincible_timer != tid) { if (battle_config.error_log) - printf("invincible_timer %d != %d\n", sd->invincible_timer, tid); + PRINTF("invincible_timer %d != %d\n", sd->invincible_timer, tid); return; } sd->invincible_timer = -1; @@ -266,7 +266,7 @@ void pc_spiritball_timer(timer_id tid, tick_t, custom_id_t id, custom_data_t) if (sd->spirit_timer[0] != tid) { if (battle_config.error_log) - printf("spirit_timer %d != %d\n", sd->spirit_timer[0], tid); + PRINTF("spirit_timer %d != %d\n", sd->spirit_timer[0], tid); return; } sd->spirit_timer[0] = -1; @@ -440,7 +440,7 @@ void pc_counttargeted_sub(struct block_list *bl, && md->state.state == MS_ATTACK && md->target_lv >= target_lv) (*c)++; - //printf("md->target_lv:%d, target_lv:%d\n",((struct mob_data *)bl)->target_lv,target_lv); + //PRINTF("md->target_lv:%d, target_lv:%d\n",((struct mob_data *)bl)->target_lv,target_lv); } } @@ -698,7 +698,6 @@ int pc_isequip(struct map_session_data *sd, int n) int pc_breakweapon(struct map_session_data *sd) { struct item_data *item; - char output[255]; int i; if (sd == NULL) @@ -721,7 +720,7 @@ int pc_breakweapon(struct map_session_data *sd) && bool(sd->status.inventory[i].equip & EPOS::WEAPON) && sd->status.inventory[i].broken == 1) { - sprintf(output, "%s has broken.", item->jname); + std::string output = STRPRINTF("%s has broken.", item->jname); clif_emotion(&sd->bl, 23); clif_displaymessage(sd->fd, output); clif_equiplist(sd); @@ -742,10 +741,6 @@ int pc_breakweapon(struct map_session_data *sd) */ int pc_breakarmor(struct map_session_data *sd) { - struct item_data *item; - char output[255]; - int i; - if (sd == NULL) return -1; if (sd->unbreakable >= MRAND(100)) @@ -753,20 +748,20 @@ int pc_breakarmor(struct map_session_data *sd) if (sd->sc_data[SC_CP_ARMOR].timer != -1) return 0; - for (i = 0; i < MAX_INVENTORY; i++) + for (int i = 0; i < MAX_INVENTORY; i++) { if (bool(sd->status.inventory[i].equip) && bool(sd->status.inventory[i].equip & EPOS::MISC1) && !sd->status.inventory[i].broken) { - item = sd->inventory_data[i]; + struct item_data *item = sd->inventory_data[i]; sd->status.inventory[i].broken = 1; - //pc_unequipitem(sd,i,CalcStatus::NOW); if (bool(sd->status.inventory[i].equip) && bool(sd->status.inventory[i].equip & EPOS::MISC1) && sd->status.inventory[i].broken == 1) { - sprintf(output, "%s has broken.", item->jname); + std::string output = STRPRINTF("%s has broken.", + item->jname); clif_emotion(&sd->bl, 23); clif_displaymessage(sd->fd, output); clif_equiplist(sd); @@ -949,12 +944,12 @@ int pc_authok(int id, int login_id2, time_t connect_until_time, if (pc_isGM(sd)) { - printf("Connection accepted: character '%s' (account: %d; GM level %d).\n", + PRINTF("Connection accepted: character '%s' (account: %d; GM level %d).\n", sd->status.name, sd->status.account_id, pc_isGM(sd)); clif_updatestatus(sd, SP_GM); } else - printf("Connection accepted: Character '%s' (account: %d).\n", + PRINTF("Connection accepted: Character '%s' (account: %d).\n", sd->status.name, sd->status.account_id); // Message of the Dayの送信 @@ -1217,7 +1212,7 @@ int pc_calc_skilltree(struct map_session_data *sd) while (flag); } // if(battle_config.etc_log) -// printf("calc skill_tree\n"); +// PRINTF("calc skill_tree\n"); return 0; } @@ -1801,7 +1796,7 @@ int pc_calcstatus(struct map_session_data *sd, int first) } dstr = str / 10; sd->base_atk += str + dstr * dstr + dex / 5 + sd->paramc[ATTR::LUK] / 5; -//fprintf(stderr, "baseatk = %d = x + %d + %d + %d + %d\n", sd->base_atk, str, dstr*dstr, dex/5, sd->paramc[ATTR::LUK]/5); +//FPRINTF(stderr, "baseatk = %d = x + %d + %d + %d + %d\n", sd->base_atk, str, dstr*dstr, dex/5, sd->paramc[ATTR::LUK]/5); sd->matk1 += sd->paramc[ATTR::INT] + (sd->paramc[ATTR::INT] / 5) * (sd->paramc[ATTR::INT] / 5); sd->matk2 += sd->paramc[ATTR::INT] + (sd->paramc[ATTR::INT] / 7) * (sd->paramc[ATTR::INT] / 7); if (sd->matk1 < sd->matk2) @@ -2889,8 +2884,8 @@ int pc_bonus(struct map_session_data *sd, SP type, int val) break; default: if (battle_config.error_log) - printf("pc_bonus: unknown type %d %d !\n", - uint16_t(type), val); + PRINTF("pc_bonus: unknown type %d %d !\n", + type, val); break; } return 0; @@ -3113,8 +3108,8 @@ int pc_bonus2(struct map_session_data *sd, SP type, int type2, int val) } // end addition default: if (battle_config.error_log) - printf("pc_bonus2: unknown type %d %d %d!\n", - uint16_t(type), type2, val); + PRINTF("pc_bonus2: unknown type %d %d %d!\n", + type, type2, val); break; } return 0; @@ -3162,8 +3157,8 @@ int pc_bonus3(struct map_session_data *sd, SP type, int type2, int type3, break; default: if (battle_config.error_log) - printf("pc_bonus3: unknown type %d %d %d %d!\n", - uint16_t(type), type2, type3, val); + PRINTF("pc_bonus3: unknown type %d %d %d %d!\n", + type, type2, type3, val); break; } @@ -3181,7 +3176,7 @@ int pc_skill(struct map_session_data *sd, SkillID id, int level, int flag) if (level > MAX_SKILL_LEVEL) { if (battle_config.error_log) - printf("support card skill only!\n"); + PRINTF("support card skill only!\n"); return 0; } if (!flag && (sd->status.skill[id].id == id || level == 0)) @@ -3721,25 +3716,26 @@ static void pc_show_steal(struct block_list *bl, struct map_session_data *sd, int itemid, int type) { - struct item_data *item = NULL; - char output[100]; - nullpo_retv(bl); nullpo_retv(sd); + std::string output; if (!type) { - if ((item = itemdb_exists(itemid)) == NULL) - sprintf(output, "%s stole an Unknown_Item.", sd->status.name); + struct item_data *item = itemdb_exists(itemid); + if (item == NULL) + output = STRPRINTF("%s stole an Unknown_Item.", + sd->status.name); else - sprintf(output, "%s stole %s.", sd->status.name, item->jname); + output = STRPRINTF("%s stole %s.", + sd->status.name, item->jname); clif_displaymessage(((struct map_session_data *) bl)->fd, output); } else { - sprintf(output, - "%s has not stolen the item because of being overweight.", - sd->status.name); + output = STRPRINTF( + "%s has not stolen the item because of being overweight.", + sd->status.name); clif_displaymessage(((struct map_session_data *) bl)->fd, output); } } @@ -3949,7 +3945,7 @@ int pc_setpos(struct map_session_data *sd, const char *mapname_org, int x, int y if (x || y) { if (battle_config.error_log) - printf("stacked (%d,%d)\n", x, y); + PRINTF("stacked (%d,%d)\n", x, y); } do { @@ -4077,7 +4073,7 @@ void pc_walk(timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) if (sd->walktimer != tid) { if (battle_config.error_log) - printf("pc_walk %d != %d\n", sd->walktimer, tid); + PRINTF("pc_walk %d != %d\n", sd->walktimer, tid); return; } sd->walktimer = -1; @@ -4545,7 +4541,7 @@ void pc_attack_timer(timer_id tid, tick_t tick, custom_id_t id, custom_data_t) if (sd->attacktimer != tid) { if (battle_config.error_log) - printf("pc_attack_timer %d != %d\n", sd->attacktimer, tid); + PRINTF("pc_attack_timer %d != %d\n", sd->attacktimer, tid); return; } sd->attacktimer = -1; @@ -4866,7 +4862,6 @@ int pc_gainexp(struct map_session_data *sd, int base_exp, int job_exp) int pc_gainexp_reason(struct map_session_data *sd, int base_exp, int job_exp, PC_GAINEXP_REASON reason) { - char output[256]; nullpo_ret(sd); if (sd->bl.prev == NULL || pc_isdead(sd)) @@ -4940,9 +4935,10 @@ int pc_gainexp_reason(struct map_session_data *sd, int base_exp, int job_exp, if (battle_config.disp_experience) { - sprintf(output, - "Experienced Gained Base:%d Job:%d", base_exp, job_exp); - clif_disp_onlyself(sd, output, strlen(output)); + std::string output = STRPRINTF( + "Experienced Gained Base:%d Job:%d", + base_exp, job_exp); + clif_displaymessage(sd->fd, output); } return 0; @@ -5872,7 +5868,7 @@ int pc_setparam(struct map_session_data *sd, SP type, int val) int pc_heal(struct map_session_data *sd, int hp, int sp) { // if(battle_config.battle_log) -// printf("heal %d %d\n",hp,sp); +// PRINTF("heal %d %d\n",hp,sp); nullpo_ret(sd); @@ -5998,7 +5994,7 @@ int pc_itemheal_effect(struct map_session_data *sd, int hp, int sp) { int bonus; // if(battle_config.battle_log) -// printf("heal %d %d\n",hp,sp); +// PRINTF("heal %d %d\n",hp,sp); nullpo_ret(sd); @@ -6451,7 +6447,7 @@ int pc_setregstr(struct map_session_data *sd, int reg, const char *str) if (strlen(str) + 1 > sizeof(sd->regstr[0].data)) { - printf("pc_setregstr(): String too long!\n"); + PRINTF("pc_setregstr(): String too long!\n"); return 0; } @@ -6534,7 +6530,7 @@ int pc_setglobalreg(struct map_session_data *sd, const char *reg, int val) return 0; } if (battle_config.error_log) - printf("pc_setglobalreg : couldn't set %s (GLOBAL_REG_NUM = %d)\n", + PRINTF("pc_setglobalreg : couldn't set %s (GLOBAL_REG_NUM = %d)\n", reg, GLOBAL_REG_NUM); return 1; @@ -6602,7 +6598,7 @@ int pc_setaccountreg(struct map_session_data *sd, const char *reg, int val) return 0; } if (battle_config.error_log) - printf("pc_setaccountreg : couldn't set %s (ACCOUNT_REG_NUM = %d)\n", + PRINTF("pc_setaccountreg : couldn't set %s (ACCOUNT_REG_NUM = %d)\n", reg, ACCOUNT_REG_NUM); return 1; @@ -6670,7 +6666,7 @@ int pc_setaccountreg2(struct map_session_data *sd, const char *reg, int val) return 0; } if (battle_config.error_log) - printf("pc_setaccountreg2 : couldn't set %s (ACCOUNT_REG2_NUM = %d)\n", + PRINTF("pc_setaccountreg2 : couldn't set %s (ACCOUNT_REG2_NUM = %d)\n", reg, ACCOUNT_REG2_NUM); return 1; @@ -6727,7 +6723,7 @@ void pc_eventtimer(timer_id tid, tick_t, custom_id_t id, custom_data_t data) if (i == MAX_EVENTTIMER) { if (battle_config.error_log) - printf("pc_eventtimer: no such event timer\n"); + PRINTF("pc_eventtimer: no such event timer\n"); } } @@ -6869,8 +6865,8 @@ int pc_equipitem(struct map_session_data *sd, int n, EPOS) EPOS pos = pc_equippoint(sd, n); if (battle_config.battle_log) - printf("equip %d (%d) %x:%x\n", - nameid, n, uint16_t(id->equip), uint16_t(pos)); + PRINTF("equip %d (%d) %x:%x\n", + nameid, n, id->equip, pos); if (!pc_isequip(sd, n) || pos == EPOS::ZERO || sd->status.inventory[n].broken == 1) { // [Valaris] clif_equipitemack(sd, n, EPOS::ZERO, 0); // fail @@ -7044,9 +7040,9 @@ int pc_unequipitem(struct map_session_data *sd, int n, CalcStatus type) } if (battle_config.battle_log) - printf("unequip %d %x:%x\n", - n, uint16_t(pc_equippoint(sd, n)), - uint16_t(sd->status.inventory[n].equip)); + PRINTF("unequip %d %x:%x\n", + n, pc_equippoint(sd, n), + sd->status.inventory[n].equip); if (bool(sd->status.inventory[n].equip)) { for (EQUIP i : EQUIPs) @@ -7151,7 +7147,7 @@ int pc_checkitem(struct map_session_data *sd) if (battle_config.item_check && !itemdb_available(id)) { if (battle_config.error_log) - printf("illeagal item id %d in %d[%s] inventory.\n", id, + PRINTF("illeagal item id %d in %d[%s] inventory.\n", id, sd->bl.id, sd->status.name); pc_delitem(sd, i, sd->status.inventory[i].amount, 3); continue; @@ -7178,7 +7174,7 @@ int pc_checkitem(struct map_session_data *sd) if (battle_config.item_check && !itemdb_available(id)) { if (battle_config.error_log) - printf("illeagal item id %d in %d[%s] cart.\n", id, + PRINTF("illeagal item id %d in %d[%s] cart.\n", id, sd->bl.id, sd->status.name); pc_cart_delitem(sd, i, sd->status.cart[i].amount, 1); continue; @@ -7359,7 +7355,7 @@ int pc_divorce(struct map_session_data *sd) if (p_sd->status.partner_id != sd->status.char_id || sd->status.partner_id != p_sd->status.char_id) { - printf("pc_divorce: Illegal partner_id sd=%d p_sd=%d\n", + PRINTF("pc_divorce: Illegal partner_id sd=%d p_sd=%d\n", sd->status.partner_id, p_sd->status.partner_id); return -1; } @@ -7935,7 +7931,7 @@ int pc_read_gm_account(int fd) { gm_account[GM_num].account_id = RFIFOL(fd, i); gm_account[GM_num].level = (int) RFIFOB(fd, i + 4); - //printf("GM account: %d -> level %d\n", gm_account[GM_num].account_id, gm_account[GM_num].level); + //PRINTF("GM account: %d -> level %d\n", gm_account[GM_num].account_id, gm_account[GM_num].level); GM_num++; } return GM_num; @@ -8043,7 +8039,7 @@ int pc_readdb(void) fp = fopen_("db/exp.txt", "r"); if (fp == NULL) { - printf("can't read db/exp.txt\n"); + PRINTF("can't read db/exp.txt\n"); return 1; } i = 0; @@ -8074,13 +8070,13 @@ int pc_readdb(void) break; } fclose_(fp); - printf("read db/exp.txt done\n"); + PRINTF("read db/exp.txt done\n"); // JOB補正数値1 fp = fopen_("db/job_db1.txt", "r"); if (fp == NULL) { - printf("can't read db/job_db1.txt\n"); + PRINTF("can't read db/job_db1.txt\n"); return 1; } i = 0; @@ -8112,13 +8108,13 @@ int pc_readdb(void) break; } fclose_(fp); - printf("read db/job_db1.txt done\n"); + PRINTF("read db/job_db1.txt done\n"); // JOBボーナス fp = fopen_("db/job_db2.txt", "r"); if (fp == NULL) { - printf("can't read db/job_db2.txt\n"); + PRINTF("can't read db/job_db2.txt\n"); return 1; } i = 0; @@ -8144,13 +8140,13 @@ int pc_readdb(void) break; } fclose_(fp); - printf("read db/job_db2.txt done\n"); + PRINTF("read db/job_db2.txt done\n"); // JOBボーナス2 転生職用 fp = fopen_("db/job_db2-2.txt", "r"); if (fp == NULL) { - printf("can't read db/job_db2-2.txt\n"); + PRINTF("can't read db/job_db2-2.txt\n"); return 1; } i = 0; @@ -8172,14 +8168,14 @@ int pc_readdb(void) break; } fclose_(fp); - printf("read db/job_db2-2.txt done\n"); + PRINTF("read db/job_db2-2.txt done\n"); // スキルツリー memset(skill_tree, 0, sizeof(skill_tree)); fp = fopen_("db/skill_tree.txt", "r"); if (fp == NULL) { - printf("can't read db/skill_tree.txt\n"); + PRINTF("can't read db/skill_tree.txt\n"); return 1; } while (fgets(line, sizeof(line) - 1, fp)) @@ -8211,7 +8207,7 @@ int pc_readdb(void) } } fclose_(fp); - printf("read db/skill_tree.txt done\n"); + PRINTF("read db/skill_tree.txt done\n"); // 属性修正テーブル for (i = 0; i < 4; i++) @@ -8221,7 +8217,7 @@ int pc_readdb(void) fp = fopen_("db/attr_fix.txt", "r"); if (fp == NULL) { - printf("can't read db/attr_fix.txt\n"); + PRINTF("can't read db/attr_fix.txt\n"); return 1; } while (fgets(line, sizeof(line) - 1, fp)) @@ -8239,7 +8235,7 @@ int pc_readdb(void) } lv = atoi(split[0]); n = atoi(split[1]); -// printf("%d %d\n",lv,n); +// PRINTF("%d %d\n",lv,n); for (i = 0; i < n;) { @@ -8265,7 +8261,7 @@ int pc_readdb(void) } } fclose_(fp); - printf("read db/attr_fix.txt done\n"); + PRINTF("read db/attr_fix.txt done\n"); // サイズ補正テーブル for (i = 0; i < 3; i++) @@ -8274,7 +8270,7 @@ int pc_readdb(void) fp = fopen_("db/size_fix.txt", "r"); if (fp == NULL) { - printf("can't read db/size_fix.txt\n"); + PRINTF("can't read db/size_fix.txt\n"); return 1; } i = 0; @@ -8298,7 +8294,7 @@ int pc_readdb(void) i++; } fclose_(fp); - printf("read db/size_fix.txt done\n"); + PRINTF("read db/size_fix.txt done\n"); // 精錬データテーブル for (i = 0; i < 5; i++) @@ -8312,7 +8308,7 @@ int pc_readdb(void) fp = fopen_("db/refine_db.txt", "r"); if (fp == NULL) { - printf("can't read db/refine_db.txt\n"); + PRINTF("can't read db/refine_db.txt\n"); return 1; } i = 0; @@ -8339,7 +8335,7 @@ int pc_readdb(void) i++; } fclose_(fp); //Lupus. close this file!!! - printf("read db/refine_db.txt done\n"); + PRINTF("read db/refine_db.txt done\n"); return 0; } @@ -8374,7 +8370,7 @@ void pc_statpointdb(void) if (stp == NULL) { - printf("can't read db/statpoint.txt\n"); + PRINTF("can't read db/statpoint.txt\n"); return; } @@ -8385,7 +8381,7 @@ void pc_statpointdb(void) buf_stat = (char *) malloc(end + 1); l = fread(buf_stat, 1, end, stp); fclose_(stp); - printf("read db/statpoint.txt done (size=%d)\n", l); + PRINTF("read db/statpoint.txt done (size=%d)\n", l); for (i = 0; i < 255; i++) { diff --git a/src/map/script.cpp b/src/map/script.cpp index cb43f64..3a75728 100644 --- a/src/map/script.cpp +++ b/src/map/script.cpp @@ -10,7 +10,10 @@ #include #include +#include + #include "../common/db.hpp" +#include "../common/extract.hpp" #include "../common/lock.hpp" #include "../common/mt_rand.hpp" #include "../common/socket.hpp" @@ -86,9 +89,19 @@ struct dbt *script_get_userfunc_db(void) } static -char pos[11][100] = - { "頭", "体", "左手", "右手", "ローブ", "靴", "アクセサリー1", - "アクセサリー2", "頭2", "頭3", "装着していない" +const char *pos[11] = +{ + "Head", + "Body", + "Left hand", + "Right hand", + "Robe", + "Shoes", + "Accessory 1", + "Accessory 2", + "Head 2", + "Head 3", + "Not Equipped", }; static @@ -131,7 +144,6 @@ struct BuiltinFunction extern BuiltinFunction builtin_functions[]; -#ifdef RECENT_GCC enum class ScriptCode : uint8_t { // tyoes and specials @@ -143,7 +155,6 @@ enum class ScriptCode : uint8_t XOR, OR, AND, ADD, SUB, MUL, DIV, MOD, NEG, LNOT, NOT, R_SHIFT, L_SHIFT }; -#endif /*========================================== * 文字列のハッシュを計算 @@ -446,17 +457,17 @@ void disp_error_message(const char *mes, const char *pos_) } if (lineend == NULL || pos_ < lineend) { - printf("%s line %d : ", mes, line); + PRINTF("%s line %d : ", mes, line); for (int i = 0; (linestart[i] != '\r') && (linestart[i] != '\n') && linestart[i]; i++) { if (linestart + i != pos_) - printf("%c", linestart[i]); + PRINTF("%c", linestart[i]); else - printf("\'%c\'", linestart[i]); + PRINTF("\'%c\'", linestart[i]); } - printf("\a\n"); + PRINTF("\a\n"); if (lineend) *lineend = c; return; @@ -478,7 +489,7 @@ const char *parse_simpleexpr(const char *p) #ifdef DEBUG_FUNCIN if (battle_config.etc_log) - printf("parse_simpleexpr %s\n", p); + PRINTF("parse_simpleexpr %s\n", p); #endif if (*p == ';' || *p == ',') { @@ -577,7 +588,7 @@ const char *parse_simpleexpr(const char *p) #ifdef DEBUG_FUNCIN if (battle_config.etc_log) - printf("parse_simpleexpr end %s\n", p); + PRINTF("parse_simpleexpr end %s\n", p); #endif return p; } @@ -593,7 +604,7 @@ const char *parse_subexpr(const char *p, int limit) #ifdef DEBUG_FUNCIN if (battle_config.etc_log) - printf("parse_subexpr %s\n", p); + PRINTF("parse_subexpr %s\n", p); #endif p = skip_space(p); @@ -696,7 +707,7 @@ const char *parse_subexpr(const char *p, int limit) } #ifdef DEBUG_FUNCIN if (battle_config.etc_log) - printf("parse_subexpr end %s\n", p); + PRINTF("parse_subexpr end %s\n", p); #endif return p; /* return first untreated operator */ } @@ -710,7 +721,7 @@ const char *parse_expr(const char *p) { #ifdef DEBUG_FUNCIN if (battle_config.etc_log) - printf("parse_expr %s\n", p); + PRINTF("parse_expr %s\n", p); #endif switch (*p) { @@ -726,7 +737,7 @@ const char *parse_expr(const char *p) p = parse_subexpr(p, -1); #ifdef DEBUG_FUNCIN if (battle_config.etc_log) - printf("parse_expr end %s\n", p); + PRINTF("parse_expr end %s\n", p); #endif return p; } @@ -827,35 +838,30 @@ void add_builtin_functions(void) static void read_constdb(void) { - FILE *fp; - char line[1024], name[1024]; - int val, n, i, type; - - fp = fopen_("db/const.txt", "r"); - if (fp == NULL) + std::ifstream in("db/const.txt"); + if (!in.is_open()) { - printf("can't read db/const.txt\n"); + PRINTF("can't read db/const.txt\n"); return; } - while (fgets(line, 1020, fp)) + + std::string line; + while (std::getline(in, line)) { if (line[0] == '/' && line[1] == '/') continue; - type = 0; - if (sscanf(line, "%[A-Za-z0-9_],%d,%d", name, &val, &type) >= 2 || - sscanf(line, "%[A-Za-z0-9_] %d %d", name, &val, &type) >= 2) - { - for (i = 0; name[i]; i++) - name[i] = tolower(name[i]); - n = add_str(name); - if (type == 0) - str_data[n].type = ScriptCode::INT; - else - str_data[n].type = ScriptCode::PARAM; - str_data[n].val = val; - } + + std::string name; + int val; + int type = 0; // if not provided + if (SSCANF(line, "%m[A-Za-z0-9_] %x %x", &name, &val, &type) < 2) + continue; + for (char& c : name) + c = tolower(c); + int n = add_str(name.c_str()); + str_data[n].type = type ? ScriptCode::PARAM : ScriptCode::INT; + str_data[n].val = val; } - fclose_(fp); } /*========================================== @@ -968,12 +974,12 @@ const ScriptCode *parse_script(const char *src, int line) for (i = 0; i < script_pos; i++) { if ((i & 15) == 0) - printf("%04x : ", i); - printf("%02x ", script_buf[i]); + PRINTF("%04x : ", i); + PRINTF("%02x ", script_buf[i]); if ((i & 15) == 15) - printf("\n"); + PRINTF("\n"); } - printf("\n"); + PRINTF("\n"); #endif return script_buf; @@ -995,7 +1001,7 @@ struct map_session_data *script_rid2sd(ScriptState *st) struct map_session_data *sd = map_id2sd(st->rid); if (!sd) { - printf("script_rid2sd: fatal error ! player not attached!\n"); + PRINTF("script_rid2sd: fatal error ! player not attached!\n"); } return sd; } @@ -1017,7 +1023,7 @@ void get_val(ScriptState *st, struct script_data *data) if (prefix != '$') { if ((sd = script_rid2sd(st)) == NULL) - printf("get_val error name?:%s\n", name); + PRINTF("get_val error name?:%s\n", name); } if (postfix == '$') { @@ -1035,7 +1041,7 @@ void get_val(ScriptState *st, struct script_data *data) } else { - printf("script: get_val: illegal scope string variable.\n"); + PRINTF("script: get_val: illegal scope string variable.\n"); data->u.str = "!!ERROR!!"; } if (data->u.str == NULL) @@ -1126,7 +1132,7 @@ void set_reg(struct map_session_data *sd, int num, const char *name, struct scri } else { - printf("script: set_reg: illegal scope string variable !"); + PRINTF("script: set_reg: illegal scope string variable !"); } } else @@ -1238,7 +1244,7 @@ void push_val(struct script_stack *stack, ScriptCode type, int val) 64 * sizeof(*(stack->stack_data))); } // if(battle_config.etc_log) -// printf("push (%d,%d)-> %d\n",type,val,stack->sp); +// PRINTF("push (%d,%d)-> %d\n",type,val,stack->sp); stack->stack_data[stack->sp].type = type; stack->stack_data[stack->sp].u.num = val; stack->sp++; @@ -1261,7 +1267,7 @@ void push_str(struct script_stack *stack, ScriptCode type, const char *str) 64 * sizeof(*(stack->stack_data))); } // if(battle_config.etc_log) -// printf("push (%d,%x)-> %d\n",type,str,stack->sp); +// PRINTF("push (%d,%x)-> %d\n",type,str,stack->sp); stack->stack_data[stack->sp].type = type; stack->stack_data[stack->sp].u.str = str; stack->sp++; @@ -1336,7 +1342,7 @@ void builtin_goto(ScriptState *st) { if (st->stack->stack_data[st->start + 2].type != ScriptCode::POS) { - printf("script: goto: not label !\n"); + PRINTF("script: goto: not label !\n"); st->state = END; return; } @@ -1375,7 +1381,7 @@ void builtin_callfunc(ScriptState *st) } else { - printf("script:callfunc: function not found! [%s]\n", str); + PRINTF("script:callfunc: function not found! [%s]\n", str); st->state = END; } } @@ -1734,7 +1740,7 @@ void builtin_input(ScriptState *st) } else { - printf("builtin_input: string discarded !!\n"); + PRINTF("builtin_input: string discarded !!\n"); } } else @@ -1812,7 +1818,7 @@ void builtin_set(ScriptState *st) if (st->stack->stack_data[st->start + 2].type != ScriptCode::NAME) { - printf("script: builtin_set: not name\n"); + PRINTF("script: builtin_set: not name\n"); return; } @@ -1850,7 +1856,7 @@ void builtin_setarray(ScriptState *st) if (prefix != '$' && prefix != '@') { - printf("builtin_setarray: illegal scope !\n"); + PRINTF("builtin_setarray: illegal scope !\n"); return; } if (prefix != '$') @@ -1882,7 +1888,7 @@ void builtin_cleararray(ScriptState *st) if (prefix != '$' && prefix != '@') { - printf("builtin_cleararray: illegal scope !\n"); + PRINTF("builtin_cleararray: illegal scope !\n"); return; } if (prefix != '$') @@ -1924,7 +1930,7 @@ void builtin_getarraysize(ScriptState *st) if (prefix != '$' && prefix != '@') { - printf("builtin_copyarray: illegal scope !\n"); + PRINTF("builtin_copyarray: illegal scope !\n"); return; } @@ -1943,7 +1949,7 @@ void builtin_getelementofarray(ScriptState *st) int i = conv_num(st, &(st->stack->stack_data[st->start + 3])); if (i > 127 || i < 0) { - printf("script: getelementofarray (operator[]): param2 illegal number %d\n", + PRINTF("script: getelementofarray (operator[]): param2 illegal number %d\n", i); push_val(st->stack, ScriptCode::INT, 0); } @@ -1955,7 +1961,7 @@ void builtin_getelementofarray(ScriptState *st) } else { - printf("script: getelementofarray (operator[]): param1 not name !\n"); + PRINTF("script: getelementofarray (operator[]): param1 not name !\n"); push_val(st->stack, ScriptCode::INT, 0); } } @@ -2009,7 +2015,7 @@ void builtin_countitem(ScriptState *st) else { if (battle_config.error_log) - printf("wrong item ID : countitem (%i)\n", nameid); + PRINTF("wrong item ID : countitem (%i)\n", nameid); } push_val(st->stack, ScriptCode::INT, count); @@ -2210,7 +2216,7 @@ void builtin_delitem(ScriptState *st) if (nameid < 500 || amount <= 0) { //by Lupus. Don't run FOR if u got wrong item ID or amount<=0 - //printf("wrong item ID or amount<=0 : delitem %i,\n",nameid,amount); + //PRINTF("wrong item ID or amount<=0 : delitem %i,\n",nameid,amount); return; } sd = script_rid2sd(st); @@ -2389,7 +2395,7 @@ void builtin_getequipid(ScriptState *st) sd = script_rid2sd(st); if (sd == NULL) { - printf("getequipid: sd == NULL\n"); + PRINTF("getequipid: sd == NULL\n"); return; } num = conv_num(st, &(st->stack->stack_data[st->start + 2])); @@ -2992,10 +2998,10 @@ void builtin_announce(ScriptState *st) { struct block_list *bl = (flag & 0x08) ? map_id2bl(st->oid) : (struct block_list *) script_rid2sd(st); - clif_GMmessage(bl, str, strlen(str) + 1, flag); + clif_GMmessage(bl, str, flag); } else - intif_GMmessage(str, strlen(str) + 1, flag); + intif_GMmessage(str, flag); } /*========================================== @@ -3003,9 +3009,9 @@ void builtin_announce(ScriptState *st) *------------------------------------------ */ static -void builtin_mapannounce_sub(struct block_list *bl, const char *str, int len, int flag) +void builtin_mapannounce_sub(struct block_list *bl, const char *str, int flag) { - clif_GMmessage(bl, str, len, flag | 3); + clif_GMmessage(bl, str, flag | 3); } static @@ -3019,7 +3025,7 @@ void builtin_mapannounce(ScriptState *st) if ((m = map_mapname2mapid(mapname)) < 0) return; - map_foreachinarea(std::bind(builtin_mapannounce_sub, ph::_1, str, strlen(str) + 1, flag & 0x10), + map_foreachinarea(std::bind(builtin_mapannounce_sub, ph::_1, str, flag & 0x10), m, 0, 0, map[m].xs, map[m].ys, BL_PC); } @@ -3232,7 +3238,7 @@ void builtin_sc_end(ScriptState *st) bl = map_id2bl(((struct map_session_data *) bl)->skilltarget); skill_status_change_end(bl, type, -1); // if(battle_config.etc_log) -// printf("sc_end : %d %d\n",st->rid,type); +// PRINTF("sc_end : %d %d\n",st->rid,type); } static @@ -3257,7 +3263,7 @@ static void builtin_debugmes(ScriptState *st) { conv_str(st, &(st->stack->stack_data[st->start + 2])); - printf("script debug : %d %d : %s\n", st->rid, st->oid, + PRINTF("script debug : %d %d : %s\n", st->rid, st->oid, st->stack->stack_data[st->start + 2].u.str); } @@ -4140,7 +4146,7 @@ void builtin_npctalk(ScriptState *st) memcpy(message, nd->name, 24); strcat(message, " : "); strcat(message, str); - clif_message(&(nd->bl), message); + clif_message(&nd->bl, message); } } @@ -4454,7 +4460,7 @@ void op_2str(ScriptState *st, ScriptCode op, int sp1, int sp2) a = (strcmp(s1, s2) <= 0); break; default: - printf("illegal string operater\n"); + PRINTF("illegal string operater\n"); break; } @@ -4561,7 +4567,7 @@ void op_2(ScriptState *st, ScriptCode op) else { // si,is => error - printf("script: op_2: int&str, str&int not allow."); + PRINTF("script: op_2: int&str, str&int not allow."); push_val(st->stack, ScriptCode::INT, 0); } } @@ -4604,7 +4610,7 @@ void run_func(ScriptState *st) if (i == 0) { if (battle_config.error_log) - printf("function not found\n"); + PRINTF("function not found\n"); // st->stack->sp=0; st->state = END; return; @@ -4617,7 +4623,7 @@ void run_func(ScriptState *st) if (st->stack->stack_data[st->start].type != ScriptCode::NAME || str_data[func].type != ScriptCode::FUNC) { - printf("run_func: not function and command! \n"); + PRINTF("run_func: not function and command! \n"); // st->stack->sp=0; st->state = END; return; @@ -4625,33 +4631,33 @@ void run_func(ScriptState *st) #ifdef DEBUG_RUN if (battle_config.etc_log) { - printf("run_func : %s? (%d(%d))\n", str_buf + str_data[func].str, + PRINTF("run_func : %s? (%d(%d))\n", str_buf + str_data[func].str, func, str_data[func].type); - printf("stack dump :"); + PRINTF("stack dump :"); for (i = 0; i < end_sp; i++) { switch (st->stack->stack_data[i].type) { case ScriptCode::INT: - printf(" int(%d)", st->stack->stack_data[i].u.num); + PRINTF(" int(%d)", st->stack->stack_data[i].u.num); break; case ScriptCode::NAME: - printf(" name(%s)", + PRINTF(" name(%s)", str_buf + str_data[st->stack->stack_data[i].u.num].str); break; case ScriptCode::ARG: - printf(" arg"); + PRINTF(" arg"); break; case ScriptCode::POS: - printf(" pos(%d)", st->stack->stack_data[i].u.num); + PRINTF(" pos(%d)", st->stack->stack_data[i].u.num); break; default: - printf(" %d,%d", st->stack->stack_data[i].type, + PRINTF(" %d,%d", st->stack->stack_data[i].type, st->stack->stack_data[i].u.num); } } - printf("\n"); + PRINTF("\n"); } #endif if (str_data[func].func) @@ -4661,8 +4667,8 @@ void run_func(ScriptState *st) else { if (battle_config.error_log) - printf("run_func : %s? (%d(%d))\n", str_buf + str_data[func].str, - func, uint8_t(str_data[func].type)); + PRINTF("run_func : %s? (%d(%d))\n", str_buf + str_data[func].str, + func, str_data[func].type); push_val(st->stack, ScriptCode::INT, 0); } @@ -4677,7 +4683,7 @@ void run_func(ScriptState *st) if (st->defsp < 4 || st->stack->stack_data[st->defsp - 1].type != ScriptCode::RETINFO) { - printf("script:run_func (return) return without callfunc or callsub!\n"); + PRINTF("script:run_func (return) return without callfunc or callsub!\n"); st->state = END; return; } @@ -4717,7 +4723,7 @@ void run_script_main(const ScriptCode *script, int pos_, int, int, if (stack->sp != st->defsp) { if (battle_config.error_log) - printf("stack.sp (%d) != default (%d)\n", stack->sp, + PRINTF("stack.sp (%d) != default (%d)\n", stack->sp, st->defsp); stack->sp = st->defsp; } @@ -4747,7 +4753,7 @@ void run_script_main(const ScriptCode *script, int pos_, int, int, st->state = 0; if (gotocount > 0 && (--gotocount) <= 0) { - printf("run_script: infinity loop !\n"); + PRINTF("run_script: infinity loop !\n"); st->state = END; } } @@ -4789,13 +4795,13 @@ void run_script_main(const ScriptCode *script, int pos_, int, int, default: if (battle_config.error_log) - printf("unknown command : %d @ %d\n", uint8_t(c), pos_); + PRINTF("unknown command : %d @ %d\n", c, pos_); st->state = END; break; } if (cmdcount > 0 && (--cmdcount) <= 0) { - printf("run_script: infinity loop !\n"); + PRINTF("run_script: infinity loop !\n"); st->state = END; } } @@ -4942,43 +4948,47 @@ void mapreg_setregstr(int num, const char *str) static void script_load_mapreg(void) { - FILE *fp; - char line[1024]; + std::ifstream in(mapreg_txt); - if ((fp = fopen_(mapreg_txt, "rt")) == NULL) + if (!in.is_open()) return; - while (fgets(line, sizeof(line), fp)) - { - char buf1[256], buf2[1024], *p; - int n, v, s, i; - if (sscanf(line, "%255[^,],%d\t%n", buf1, &i, &n) != 2 && - (i = 0, sscanf(line, "%[^\t]\t%n", buf1, &n) != 1)) - continue; - if (buf1[strlen(buf1) - 1] == '$') + std::string line; + while (std::getline(in, line)) + { + std::string buf1, buf2; + int index = 0; + if (extract(line, + record<'\t'>( + record<','>(&buf1, &index), + &buf2)) + || extract(line, + record<'\t'>( + record<','>(&buf1), + &buf2))) { - if (sscanf(line + n, "%[^\n\r]", buf2) != 1) + int s = add_str(buf1.c_str()); + int key = (index << 24) | s; + if (buf1.back() == '$') + { + char *p = strdup(buf2.c_str()); + numdb_insert(mapregstr_db, key, p); + } + else { - printf("%s: %s broken data !\n", mapreg_txt, buf1); - continue; + int v; + if (!extract(buf2, &v)) + goto borken; + numdb_insert(mapreg_db, key, v); } - p = (char *) calloc(strlen(buf2) + 1, 1); - strcpy(p, buf2); - s = add_str(buf1); - numdb_insert(mapregstr_db, (i << 24) | s, p); } else { - if (sscanf(line + n, "%d", &v) != 1) - { - printf("%s: %s broken data !\n", mapreg_txt, buf1); - continue; - } - s = add_str(buf1); - numdb_insert(mapreg_db, (i << 24) | s, v); + borken: + PRINTF("%s: %s broken data !\n", mapreg_txt, buf1); + continue; } } - fclose_(fp); mapreg_dirty = 0; } @@ -4994,9 +5004,9 @@ void script_save_mapreg_intsub(db_key_t key, db_val_t data, FILE *fp) if (name[1] != '@') { if (i == 0) - fprintf(fp, "%s\t%d\n", name, (int) data); + FPRINTF(fp, "%s\t%d\n", name, (int) data); else - fprintf(fp, "%s,%d\t%d\n", name, i, (int) data); + FPRINTF(fp, "%s,%d\t%d\n", name, i, (int) data); } } @@ -5008,9 +5018,9 @@ void script_save_mapreg_strsub(db_key_t key, db_val_t data, FILE *fp) if (name[1] != '@') { if (i == 0) - fprintf(fp, "%s\t%s\n", name, (char *) data); + FPRINTF(fp, "%s\t%s\n", name, (char *) data); else - fprintf(fp, "%s,%d\t%s\n", name, i, (char *) data); + FPRINTF(fp, "%s,%d\t%s\n", name, i, (char *) data); } } @@ -5035,69 +5045,14 @@ void script_autosave_mapreg(timer_id, tick_t, custom_id_t, custom_data_t) script_save_mapreg(); } -/*========================================== - * - *------------------------------------------ - */ -static -void set_posword(char *p) +void script_config_read() { - char *np, *str[15]; - int i = 0; - for (i = 0; i < 11; i++) - { - if ((np = strchr(p, ',')) != NULL) - { - str[i] = p; - *np = 0; - p = np + 1; - } - else - { - str[i] = p; - p += strlen(p); - } - if (str[i]) - strcpy(pos[i], str[i]); - } -} - -void script_config_read(const char *cfgName) -{ - int i; - char line[1024], w1[1024], w2[1024]; - FILE *fp; - 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; - - fp = fopen_(cfgName, "r"); - if (fp == NULL) - { - printf("file not found: %s\n", cfgName); - return; - } - while (fgets(line, 1020, fp)) - { - if (line[0] == '/' && line[1] == '/') - continue; - i = sscanf(line, "%[^:]: %[^\r\n]", w1, w2); - if (i != 2) - continue; - if (strcasecmp(w1, "refine_posword") == 0) - { - set_posword(w2); - } - if (strcasecmp(w1, "import") == 0) - { - script_config_read(w2); - } - } - fclose_(fp); } /*========================================== diff --git a/src/map/script.hpp b/src/map/script.hpp index 03ff950..e09baf8 100644 --- a/src/map/script.hpp +++ b/src/map/script.hpp @@ -3,40 +3,7 @@ #include -// values are private, but gcc < 4.6 doesn't -// support forward-declared enums -enum class ScriptCode : uint8_t -#ifdef RECENT_GCC -; -#else -{ - // types and specials - NOP, POS, INT, PARAM, FUNC, STR, CONSTSTR, ARG, - NAME, EOL, RETINFO, - - // unary and binary operators - LOR, LAND, LE, LT, GE, GT, EQ, NE, - XOR, OR, AND, ADD, SUB, MUL, DIV, MOD, NEG, LNOT, - NOT, R_SHIFT, L_SHIFT, - - // really nasty workaround for gcc < 4.6 - - x20, x21, x22, x23, x24, x25, x26, x27, x28, x29, x2a, x2b, x2c, x2d, x2e, x2f, - x30, x31, x32, x33, x34, x35, x36, x37, x38, x39, x3a, x3b, x3c, x3d, x3e, x3f, - x40, x41, x42, x43, x44, x45, x46, x47, x48, x49, x4a, x4b, x4c, x4d, x4e, x4f, - x50, x51, x52, x53, x54, x55, x56, x57, x58, x59, x5a, x5b, x5c, x5d, x5e, x5f, - x60, x61, x62, x63, x64, x65, x66, x67, x68, x69, x6a, x6b, x6c, x6d, x6e, x6f, - x70, x71, x72, x73, x74, x75, x76, x77, x78, x79, x7a, x7b, x7c, x7d, x7e, x7f, - x80, x81, x82, x83, x84, x85, x86, x87, x88, x89, x8a, x8b, x8c, x8d, x8e, x8f, - x90, x91, x92, x93, x94, x95, x96, x97, x98, x99, x9a, x9b, x9c, x9d, x9e, x9f, - xa0, xa1, xa2, xa3, xa4, xa5, xa6, xa7, xa8, xa9, xaa, xab, xac, xad, xae, xaf, - xb0, xb1, xb2, xb3, xb4, xb5, xb6, xb7, xb8, xb9, xba, xbb, xbc, xbd, xbe, xbf, - xc0, xc1, xc2, xc3, xc4, xc5, xc6, xc7, xc8, xc9, xca, xcb, xcc, xcd, xce, xcf, - xd0, xd1, xd2, xd3, xd4, xd5, xd6, xd7, xd8, xd9, xda, xdb, xdc, xdd, xde, xdf, - xe0, xe1, xe2, xe3, xe4, xe5, xe6, xe7, xe8, xe9, xea, xeb, xec, xed, xee, xef, - xf0, xf1, xf2, xf3, xf4, xf5, xf6, xf7, xf8, xf9, xfa, xfb, xfc, xfd, xfe, xff, -}; -#endif +enum class ScriptCode : uint8_t; struct script_data { @@ -86,10 +53,10 @@ int run_script(const ScriptCode *, int, int, int); struct dbt *script_get_label_db(void); struct dbt *script_get_userfunc_db(void); -void script_config_read(const char *cfgName); +void script_config_read(); void do_init_script(void); void do_final_script(void); -extern char mapreg_txt[]; +extern char mapreg_txt[256]; #endif // SCRIPT_HPP diff --git a/src/map/skill-pools.cpp b/src/map/skill-pools.cpp index c20c863..c26d9cc 100644 --- a/src/map/skill-pools.cpp +++ b/src/map/skill-pools.cpp @@ -28,7 +28,7 @@ void skill_pool_register(SkillID id) { if (skill_pool_skills_size + 1 >= MAX_POOL_SKILLS) { - fprintf(stderr, + FPRINTF(stderr, "Too many pool skills! Increase MAX_POOL_SKILLS and recompile."); return; } diff --git a/src/map/skill.cpp b/src/map/skill.cpp index 3050012..77da219 100644 --- a/src/map/skill.cpp +++ b/src/map/skill.cpp @@ -1758,8 +1758,8 @@ int skill_additional_effect(struct block_list *src, struct block_list *bl, if (MRAND(10000) < eff1 * sc_def_card1 / 100) { if (battle_config.battle_log) - printf("PC %d skill_addeff: cardによる異常発動 %d %d\n", - sd->bl.id, uint16_t(si), eff1); + PRINTF("PC %d skill_addeff: cardによる異常発動 %d %d\n", + sd->bl.id, si, eff1); skill_status_change_start(bl, si, 7, 0, 0, 0, (bi == BadSC::CONFUSION) @@ -1774,8 +1774,8 @@ int skill_additional_effect(struct block_list *src, struct block_list *bl, if (MRAND(10000) < eff2 * sc_def_card2 / 100) { if (battle_config.battle_log) - printf("PC %d skill_addeff: cardによる異常発動 %d %d\n", - src->id, uint16_t(si), eff2); + PRINTF("PC %d skill_addeff: cardによる異常発動 %d %d\n", + src->id, si, eff2); skill_status_change_start(src, si, 7, 0, 0, 0, (bi == BadSC::CONFUSION) ? 10000 + 7000 @@ -5148,7 +5148,7 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, } break; default: - printf("Unknown skill used:%d\n", uint16_t(skillid)); + PRINTF("Unknown skill used:%d\n", skillid); map_freeblock_unlock(); return 1; } @@ -5308,8 +5308,8 @@ void skill_castend_id(timer_id tid, tick_t tick, custom_id_t id, custom_data_t) } if (battle_config.pc_skill_log) - printf("PC %d skill castend skill=%d\n", - sd->bl.id, uint16_t(sd->skillid)); + PRINTF("PC %d skill castend skill=%d\n", + sd->bl.id, sd->skillid); pc_stop_walking(sd, 0); switch (skill_get_nk(sd->skillid)) @@ -5556,8 +5556,8 @@ int skill_castend_map(struct map_session_data *sd, SkillID skill_num, pc_stopattack(sd); if (battle_config.pc_skill_log) - printf("PC %d skill castend skill =%d map=%s\n", - sd->bl.id, uint16_t(skill_num), mapname); + PRINTF("PC %d skill castend skill =%d map=%s\n", + sd->bl.id, skill_num, mapname); pc_stop_walking(sd, 0); if (strcmp(mapname, "cancel") == 0) @@ -6674,7 +6674,7 @@ int skill_unit_onplace(struct skill_unit *src, struct block_list *bl, /* default: if (battle_config.error_log) - printf("skill_unit_onplace: Unknown skill unit id=%d block=%d\n",sg->unit_id,bl->id); + PRINTF("skill_unit_onplace: Unknown skill unit id=%d block=%d\n",sg->unit_id,bl->id); break;*/ } if (bl->type == BL_MOB && ss != bl) /* スキル使用条件のMOBスキル */ @@ -6819,7 +6819,7 @@ int skill_unit_onout(struct skill_unit *src, struct block_list *bl, /* default: if (battle_config.error_log) - printf("skill_unit_onout: Unknown skill unit id=%d block=%d\n",sg->unit_id,bl->id); + PRINTF("skill_unit_onout: Unknown skill unit id=%d block=%d\n",sg->unit_id,bl->id); break;*/ } skill_unitgrouptickset_delete(bl, sg->group_id); @@ -6877,7 +6877,7 @@ int skill_unit_ondelete(struct skill_unit *src, struct block_list *bl, /* default: if (battle_config.error_log) - printf("skill_unit_ondelete: Unknown skill unit id=%d block=%d\n",sg->unit_id,bl->id); + PRINTF("skill_unit_ondelete: Unknown skill unit id=%d block=%d\n",sg->unit_id,bl->id); break;*/ } skill_unitgrouptickset_delete(bl, sg->group_id); @@ -7133,8 +7133,8 @@ void skill_castend_pos(timer_id tid, tick_t tick, custom_id_t id, custom_data_t) } if (battle_config.pc_skill_log) - printf("PC %d skill castend skill=%d\n", - sd->bl.id, uint16_t(sd->skillid)); + PRINTF("PC %d skill castend skill=%d\n", + sd->bl.id, sd->skillid); pc_stop_walking(sd, 0); skill_castend_pos2(&sd->bl, sd->skillx, sd->skilly, sd->skillid, @@ -7898,7 +7898,7 @@ int skill_use_id(struct map_session_data *sd, int target_id, if ((bl = map_id2bl(target_id)) == NULL) { /* if (battle_config.error_log) - printf("skill target not found %d\n",target_id); */ + PRINTF("skill target not found %d\n",target_id); */ return 0; } if (sd->bl.m != bl->m || pc_isdead(sd)) @@ -7976,7 +7976,7 @@ int skill_use_id(struct map_session_data *sd, int target_id, if (sc_data && sc_data[SC_DANCING].timer != -1) { // if(battle_config.pc_skill_log) -// printf("dancing! %d\n",skill_num); +// PRINTF("dancing! %d\n",skill_num); if (sc_data[SC_DANCING].val4 && skill_num != BD_ADAPTATION) //合奏中はアドリブ以外不可 return 0; if (skill_num != BD_ADAPTATION && skill_num != BA_MUSICALSTRIKE @@ -8176,8 +8176,8 @@ int skill_use_id(struct map_session_data *sd, int target_id, } if (battle_config.pc_skill_log) - printf("PC %d skill use target_id=%d skill=%d lv=%d cast=%d\n", - sd->bl.id, target_id, uint16_t(skill_num), skill_lv, casttime); + PRINTF("PC %d skill use target_id=%d skill=%d lv=%d cast=%d\n", + sd->bl.id, target_id, skill_num, skill_lv, casttime); // if(sd->skillitem == skill_num) // casttime = delay = 0; @@ -8301,9 +8301,9 @@ int skill_use_pos(struct map_session_data *sd, sd->state.skillcastcancel = skill_db[skill_num].castcancel; if (battle_config.pc_skill_log) - printf("PC %d skill use target_pos= (%d,%d) skill=%d lv=%d cast=%d\n", + PRINTF("PC %d skill use target_pos= (%d,%d) skill=%d lv=%d cast=%d\n", sd->bl.id, skill_x, skill_y, - uint16_t(skill_num), skill_lv, casttime); + skill_num, skill_lv, casttime); // if(sd->skillitem == skill_num) // casttime = delay = 0; @@ -8962,7 +8962,7 @@ int skill_status_change_active(struct block_list *bl, StatusChange type) if (bl->type != BL_PC && bl->type != BL_MOB) { if (battle_config.error_log) - printf("skill_status_change_active: neither MOB nor PC !\n"); + PRINTF("skill_status_change_active: neither MOB nor PC !\n"); return 0; } @@ -8987,7 +8987,7 @@ int skill_status_change_end(struct block_list *bl, StatusChange type, int tid) if (bl->type != BL_PC && bl->type != BL_MOB) { if (battle_config.error_log) - printf("skill_status_change_end: neither MOB nor PC !\n"); + PRINTF("skill_status_change_end: neither MOB nor PC !\n"); return 0; } sc_data = battle_get_sc_data(bl); @@ -9332,7 +9332,7 @@ void skill_status_change_timer(timer_id tid, tick_t tick, custom_id_t id, custom if (sc_data[type].timer != tid) { if (battle_config.error_log) - printf("skill_status_change_timer %d != %d\n", tid, + PRINTF("skill_status_change_timer %d != %d\n", tid, sc_data[type].timer); } @@ -9877,7 +9877,7 @@ int skill_status_effect(struct block_list *bl, StatusChange type, && MRAND(10000) < sd->reseff[bsc]) { if (battle_config.battle_log) - printf("PC %d skill_sc_start: cardによる異常耐性発動\n", + PRINTF("PC %d skill_sc_start: cardによる異常耐性発動\n", sd->bl.id); return 0; } @@ -9889,7 +9889,7 @@ int skill_status_effect(struct block_list *bl, StatusChange type, else { if (battle_config.error_log) - printf("skill_status_change_start: neither MOB nor PC !\n"); + PRINTF("skill_status_change_start: neither MOB nor PC !\n"); return 0; } @@ -10539,7 +10539,7 @@ int skill_status_effect(struct block_list *bl, StatusChange type, break; default: if (battle_config.error_log) - printf("UnknownStatusChange [%d]\n", uint16_t(type)); + PRINTF("UnknownStatusChange [%d]\n", type); return 0; } @@ -10971,7 +10971,7 @@ struct skill_unit_group *skill_initunitgroup(struct block_list *src, if (group == NULL) { - printf("skill_initunitgroup: error unit group !\n"); + PRINTF("skill_initunitgroup: error unit group !\n"); exit(1); } @@ -11613,7 +11613,7 @@ SP scan_stat(char *statname) if (!strcasecmp(statname, "none")) return SP::ZERO; - fprintf(stderr, "Unknown stat `%s'\n", statname); + FPRINTF(stderr, "Unknown stat `%s'\n", statname); return SP::ZERO; } @@ -11635,7 +11635,7 @@ int skill_readdb(void) fp = fopen_("db/skill_db.txt", "r"); if (fp == NULL) { - printf("can't read db/skill_db.txt\n"); + PRINTF("can't read db/skill_db.txt\n"); return 1; } while (fgets(line, 1020, fp)) @@ -11654,7 +11654,7 @@ int skill_readdb(void) } if (split[17] == NULL || j < 18) { - fprintf(stderr, "Incomplete skill db data online (%d entries)\n", + FPRINTF(stderr, "Incomplete skill db data online (%d entries)\n", j); continue; } @@ -11749,12 +11749,12 @@ int skill_readdb(void) skill_lookup_by_id(i).desc = tmp; } fclose_(fp); - printf("read db/skill_db.txt done\n"); + PRINTF("read db/skill_db.txt done\n"); fp = fopen_("db/skill_require_db.txt", "r"); if (fp == NULL) { - printf("can't read db/skill_require_db.txt\n"); + PRINTF("can't read db/skill_require_db.txt\n"); return 1; } while (fgets(line, 1020, fp)) @@ -11930,13 +11930,13 @@ int skill_readdb(void) skill_db[i].amount[9] = atoi(split[29]); } fclose_(fp); - printf("read db/skill_require_db.txt done\n"); + PRINTF("read db/skill_require_db.txt done\n"); /* ? */ fp = fopen_("db/skill_cast_db.txt", "r"); if (fp == NULL) { - printf("can't read db/skill_cast_db.txt\n"); + PRINTF("can't read db/skill_cast_db.txt\n"); return 1; } while (fgets(line, 1020, fp)) @@ -12010,12 +12010,12 @@ int skill_readdb(void) (split2[k]) ? atoi(split2[k]) : atoi(split2[0]); } fclose_(fp); - printf("read db/skill_cast_db.txt done\n"); + PRINTF("read db/skill_cast_db.txt done\n"); fp = fopen_("db/skill_castnodex_db.txt", "r"); if (fp == NULL) { - printf("can't read db/skill_castnodex_db.txt\n"); + PRINTF("can't read db/skill_castnodex_db.txt\n"); return 1; } while (fgets(line, 1020, fp)) @@ -12051,7 +12051,7 @@ int skill_readdb(void) (split2[k]) ? atoi(split2[k]) : atoi(split2[0]); } fclose_(fp); - printf("read db/skill_castnodex_db.txt done\n"); + PRINTF("read db/skill_castnodex_db.txt done\n"); return 0; } diff --git a/src/map/tmw.cpp b/src/map/tmw.cpp index 0ddec5b..c08c161 100644 --- a/src/map/tmw.cpp +++ b/src/map/tmw.cpp @@ -1,7 +1,6 @@ #include "tmw.hpp" #include -#include // exception to "no va_list" rule #include #include "../common/nullpo.hpp" @@ -99,21 +98,22 @@ int tmw_CheckChatSpam(struct map_session_data *sd, const char *message) void tmw_AutoBan(struct map_session_data *sd, const char *reason, int length) { - char anotherbuf[512]; - if (length == 0 || sd->auto_ban_info.in_progress) return; sd->auto_ban_info.in_progress = 1; - tmw_GmHackMsg("%s has been autobanned for %s spam", - sd->status.name, reason); + std::string hack_msg = STRPRINTF("[GM] %s has been autobanned for %s spam", + sd->status.name, + reason); + tmw_GmHackMsg(hack_msg); - gm_log("%s (%d,%d) Server : @autoban %s %dh (%s spam)", - map[sd->bl.m].name, sd->bl.x, sd->bl.y, + std::string fake_command = STRPRINTF("@autoban %s %dh (%s spam)", sd->status.name, length, reason); + log_atcommand(sd, fake_command); - snprintf(anotherbuf, 511, "You have been banned for %s spamming. Please do not spam.", reason); + std::string anotherbuf = STRPRINTF("You have been banned for %s spamming. Please do not spam.", + reason); clif_displaymessage(sd->fd, anotherbuf); /* type: 2 - ban(year, month, day, hour, minute, second) */ @@ -145,22 +145,11 @@ int tmw_CheckChatLameness(struct map_session_data *, const char *message) } // Sends a whisper to all GMs -void tmw_GmHackMsg(const char *fmt, ...) +void tmw_GmHackMsg(const_string line) { - char buf[512]; - va_list ap; - - va_start(ap, fmt); - vsnprintf(buf, 511, fmt, ap); - va_end(ap); - - char outbuf[512 + 5]; - strcpy(outbuf, "[GM] "); - strcat(outbuf, buf); - intif_wis_message_to_gm(wisp_server_name, - battle_config.hack_info_GM_level, outbuf, - strlen(outbuf) + 1); + battle_config.hack_info_GM_level, + line.data(), line.size() + 1); } /* Remove leading and trailing spaces from a string, modifying in place. */ diff --git a/src/map/tmw.hpp b/src/map/tmw.hpp index 879d123..a5b198c 100644 --- a/src/map/tmw.hpp +++ b/src/map/tmw.hpp @@ -4,8 +4,7 @@ #include "map.hpp" int tmw_CheckChatSpam(struct map_session_data *sd, const char *message); -__attribute__((format(printf, 1, 2))) -void tmw_GmHackMsg(const char *fmt, ...); +void tmw_GmHackMsg(const_string line); void tmw_TrimStr(char *str); #endif // TMW_HPP -- cgit v1.2.3-60-g2f50