From 8b5370313dcc00a45ea5c3e8b4c497bc00fd8e13 Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Tue, 11 Jun 2013 21:55:13 -0700 Subject: Allegedly remove all manual memory management --- src/map/atcommand.cpp | 447 ++---- src/map/atcommand.hpp | 2 +- src/map/battle.cpp | 19 +- src/map/battle.hpp | 1 - src/map/battle.t.hpp | 6 + src/map/chrif.cpp | 33 +- src/map/clif.cpp | 296 ++-- src/map/intif.cpp | 56 +- src/map/itemdb.cpp | 6 +- src/map/itemdb.hpp | 8 +- src/map/magic-expr-eval.hpp | 6 +- src/map/magic-expr.cpp | 327 ++-- src/map/magic-expr.hpp | 22 +- src/map/magic-interpreter-aux.hpp | 6 - src/map/magic-interpreter-base.cpp | 217 +-- src/map/magic-interpreter-lexer.lpp | 23 +- src/map/magic-interpreter-parser.ypp | 506 +++---- src/map/magic-interpreter.hpp | 321 ++-- src/map/magic-stmt.cpp | 341 ++--- src/map/magic.cpp | 79 +- src/map/magic.hpp | 10 +- src/map/map.cpp | 435 +++--- src/map/map.hpp | 137 +- src/map/mob.cpp | 342 ++--- src/map/mob.hpp | 2 +- src/map/npc.cpp | 611 +++----- src/map/npc.hpp | 11 +- src/map/party.cpp | 2 +- src/map/party.hpp | 2 +- src/map/path.cpp | 17 +- src/map/path.hpp | 8 + src/map/pc.cpp | 282 ++-- src/map/pc.hpp | 10 +- src/map/script.cpp | 2736 +++++++++++++++------------------- src/map/script.hpp | 90 +- src/map/skill.cpp | 34 +- src/map/skill.hpp | 6 +- src/map/storage.cpp | 36 +- src/map/tmw.cpp | 2 +- src/map/trade.cpp | 12 +- 40 files changed, 3233 insertions(+), 4274 deletions(-) create mode 100644 src/map/path.hpp (limited to 'src/map') diff --git a/src/map/atcommand.cpp b/src/map/atcommand.cpp index 56ff2ab..c066a46 100644 --- a/src/map/atcommand.cpp +++ b/src/map/atcommand.cpp @@ -127,10 +127,6 @@ ATCOMMAND_FUNC(enablenpc); ATCOMMAND_FUNC(disablenpc); ATCOMMAND_FUNC(servertime); // by Yor ATCOMMAND_FUNC(chardelitem); // by Yor -ATCOMMAND_FUNC(ignorelist); // by Yor -ATCOMMAND_FUNC(charignorelist); // by Yor -ATCOMMAND_FUNC(inall); // by Yor -ATCOMMAND_FUNC(exall); // by Yor ATCOMMAND_FUNC(email); // by Yor ATCOMMAND_FUNC(effect); //by Apple ATCOMMAND_FUNC(character_item_list); // by Yor @@ -293,10 +289,6 @@ AtCommandInfo atcommand_info[] = {"@servertime", 0, atcommand_servertime}, // by Yor {"@chardelitem", 60, atcommand_chardelitem}, // by Yor {"@listnearby", 40, atcommand_list_nearby}, // by Yor - {"@ignorelist", 0, atcommand_ignorelist}, // by Yor - {"@charignorelist", 20, atcommand_charignorelist}, // by Yor - {"@inall", 20, atcommand_inall}, // by Yor - {"@exall", 20, atcommand_exall}, // by Yor {"@email", 0, atcommand_email}, // by Yor {"@effect", 40, atcommand_effect}, // by Apple {"@charitemlist", 40, atcommand_character_item_list}, // by Yor @@ -372,19 +364,19 @@ void log_atcommand(dumb_ptr sd, const_string cmd) stamp_time(tmpstr); fprintf(fp, "[%s] %s(%d,%d) %s(%d) : ", tmpstr, - map[sd->bl_m].name, sd->bl_x, sd->bl_y, + 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; +std::string gm_logfile_name; /*========================================== * Log a timestamped line to GM log file *------------------------------------------ */ FILE *get_gm_log() { - if (!gm_logfile_name) + if (gm_logfile_name.empty()) return NULL; struct tm ctime = TimeT::now(); @@ -410,7 +402,7 @@ FILE *get_gm_log() if (!gm_logfile) { perror("GM log file"); - gm_logfile_name = NULL; + gm_logfile_name.clear(); } return gm_logfile; } @@ -642,7 +634,6 @@ int atcommand_charwarp(const int fd, dumb_ptr sd, char character[100]; int x = 0, y = 0; dumb_ptr pl_sd; - int m; memset(map_name, '\0', sizeof(map_name)); memset(character, '\0', sizeof(character)); @@ -669,15 +660,15 @@ int atcommand_charwarp(const int fd, dumb_ptr sd, { // you can rura+ only lower or same GM level if (x > 0 && x < 800 && y > 0 && y < 800) { - m = map_mapname2mapid(map_name); - if (m >= 0 && map[m].flag.nowarpto + map_local *m = map_mapname2mapid(map_name); + if (m != nullptr && m->flag.nowarpto && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(fd, "You are not authorised to warp someone to this map."); return -1; } - if (pl_sd->bl_m >= 0 && map[pl_sd->bl_m].flag.nowarp + if (pl_sd->bl_m != nullptr && pl_sd->bl_m->flag.nowarp && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(fd, @@ -725,7 +716,6 @@ int atcommand_warp(const int fd, dumb_ptr sd, { char map_name[100]; int x = 0, y = 0; - int m; memset(map_name, '\0', sizeof(map_name)); @@ -747,15 +737,15 @@ int atcommand_warp(const int fd, dumb_ptr sd, if (x > 0 && x < 800 && y > 0 && y < 800) { - m = map_mapname2mapid(map_name); - if (m >= 0 && map[m].flag.nowarpto + map_local *m = map_mapname2mapid(map_name); + if (m != nullptr && 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 map."); return -1; } - if (sd->bl_m >= 0 && map[sd->bl_m].flag.nowarp + if (sd->bl_m != nullptr && sd->bl_m->flag.nowarp && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(fd, @@ -834,14 +824,14 @@ int atcommand_goto(const int fd, dumb_ptr sd, if ((pl_sd = map_nick2sd(character)) != NULL) { - if (pl_sd->bl_m >= 0 && map[pl_sd->bl_m].flag.nowarpto + if (pl_sd->bl_m != nullptr && pl_sd->bl_m->flag.nowarpto && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(fd, "You are not authorised to warp you to the map of this player."); return -1; } - if (sd->bl_m >= 0 && map[sd->bl_m].flag.nowarp + if (sd->bl_m != nullptr && sd->bl_m->flag.nowarp && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(fd, @@ -877,14 +867,14 @@ int atcommand_jump(const int fd, dumb_ptr sd, y = random_::in(1, 399); if (x > 0 && x < 800 && y > 0 && y < 800) { - if (sd->bl_m >= 0 && map[sd->bl_m].flag.nowarpto + if (sd->bl_m != nullptr && sd->bl_m->flag.nowarpto && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(fd, "You are not authorised to warp you to your actual map."); return -1; } - if (sd->bl_m >= 0 && map[sd->bl_m].flag.nowarp + if (sd->bl_m != nullptr && sd->bl_m->flag.nowarp && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(fd, @@ -1056,7 +1046,7 @@ int atcommand_whomap(const int fd, dumb_ptr sd, { int count; int pl_GM_level, GM_level; - int map_id; + map_local *map_id; char map_name[100]; memset(map_name, '\0', sizeof(map_name)); @@ -1068,7 +1058,8 @@ int atcommand_whomap(const int fd, dumb_ptr sd, sscanf(message, "%99s", map_name); if (strstr(map_name, ".gat") == NULL && strstr(map_name, ".afm") == NULL && strlen(map_name) < 13) // 16 - 4 (.gat) strcat(map_name, ".gat"); - if ((map_id = map_mapname2mapid(map_name)) < 0) + map_id = map_mapname2mapid(map_name); + if (map_id == nullptr) map_id = sd->bl_m; } @@ -1108,7 +1099,7 @@ int atcommand_whomap(const int fd, dumb_ptr sd, } std::string output = STRPRINTF("%d players found in map '%s'.", - count, map[map_id].name); + count, map_id->name); clif_displaymessage(fd, output); return 0; @@ -1123,12 +1114,12 @@ int atcommand_whomapgroup(const int fd, dumb_ptr sd, { int count; int pl_GM_level, GM_level; - int map_id = 0; char map_name[100]; struct party *p; memset(map_name, '\0', sizeof(map_name)); + map_local *map_id; if (!message || !*message) map_id = sd->bl_m; else @@ -1136,7 +1127,8 @@ int atcommand_whomapgroup(const int fd, dumb_ptr sd, sscanf(message, "%99s", map_name); if (strstr(map_name, ".gat") == NULL && strstr(map_name, ".afm") == NULL && strlen(map_name) < 13) // 16 - 4 (.gat) strcat(map_name, ".gat"); - if ((map_id = map_mapname2mapid(map_name)) < 0) + map_id = map_mapname2mapid(map_name); + if (map_id == nullptr) map_id = sd->bl_m; } @@ -1176,12 +1168,12 @@ int atcommand_whomapgroup(const int fd, dumb_ptr sd, std::string output; if (count == 0) - output = STRPRINTF("No player found in map '%s'.", map[map_id].name); + output = STRPRINTF("No player found in map '%s'.", map_id->name); else if (count == 1) - output = STRPRINTF("1 player found in map '%s'.", map[map_id].name); + output = STRPRINTF("1 player found in map '%s'.", map_id->name); else { - output = STRPRINTF("%d players found in map '%s'.", count, map[map_id].name); + output = STRPRINTF("%d players found in map '%s'.", count, map_id->name); } clif_displaymessage(fd, output); @@ -1295,17 +1287,15 @@ int atcommand_save(const int fd, dumb_ptr sd, int atcommand_load(const int fd, dumb_ptr sd, const char *, const char *) { - int m; - - m = map_mapname2mapid(sd->status.save_point.map); - if (m >= 0 && map[m].flag.nowarpto + map_local *m = map_mapname2mapid(sd->status.save_point.map); + if (m != nullptr && m->flag.nowarpto && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(fd, "You are not authorised to warp you to your save map."); return -1; } - if (sd->bl_m >= 0 && map[sd->bl_m].flag.nowarp + if (sd->bl_m != nullptr && sd->bl_m->flag.nowarp && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(fd, @@ -1894,9 +1884,9 @@ int atcommand_pvpoff(const int fd, dumb_ptr sd, return -1; } - if (map[sd->bl_m].flag.pvp) + if (sd->bl_m->flag.pvp) { - map[sd->bl_m].flag.pvp = 0; + sd->bl_m->flag.pvp = 0; for (int i = 0; i < fd_max; i++) { if (!session[i]) @@ -1934,9 +1924,9 @@ int atcommand_pvpon(const int fd, dumb_ptr sd, return -1; } - if (!map[sd->bl_m].flag.pvp && !map[sd->bl_m].flag.nopvp) + if (!sd->bl_m->flag.pvp && !sd->bl_m->flag.nopvp) { - map[sd->bl_m].flag.pvp = 1; + sd->bl_m->flag.pvp = 1; for (int i = 0; i < fd_max; i++) { if (!session[i]) @@ -2210,23 +2200,27 @@ static void atcommand_killmonster_sub(const int fd, dumb_ptr sd, const char *message, const int drop) { - int map_id; char map_name[100]; memset(map_name, '\0', sizeof(map_name)); + map_local *map_id; if (!message || !*message || sscanf(message, "%99s", map_name) < 1) map_id = sd->bl_m; else { if (strstr(map_name, ".gat") == NULL && strstr(map_name, ".afm") == NULL && strlen(map_name) < 13) // 16 - 4 (.gat) strcat(map_name, ".gat"); - if ((map_id = map_mapname2mapid(map_name)) < 0) + map_id = map_mapname2mapid(map_name); + if (map_id == nullptr) map_id = sd->bl_m; } - map_foreachinarea(std::bind(atkillmonster_sub, ph::_1, drop), map_id, 0, 0, map[map_id].xs, - map[map_id].ys, BL::MOB); + map_foreachinarea(std::bind(atkillmonster_sub, ph::_1, drop), + map_id, + 0, 0, + map_id->xs, map_id->ys, + BL::MOB); clif_displaymessage(fd, "All monsters killed!"); @@ -2268,8 +2262,10 @@ int atcommand_list_nearby(const int fd, dumb_ptr sd, { clif_displaymessage(fd, "Nearby players:"); map_foreachinarea(std::bind(atlist_nearby_sub, ph::_1, fd), - sd->bl_m, sd->bl_x - 1, sd->bl_y - 1, - sd->bl_x + 1, sd->bl_x + 1, BL::PC); + sd->bl_m, + sd->bl_x - 1, sd->bl_y - 1, + sd->bl_x + 1, sd->bl_x + 1, + BL::PC); return 0; } @@ -2299,7 +2295,7 @@ int atcommand_gat(const int fd, dumb_ptr sd, { 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, + 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), @@ -2348,15 +2344,15 @@ int atcommand_statuspoint(const int fd, dumb_ptr sd, return -1; } - new_status_point = (int) sd->status.status_point + point; + new_status_point = sd->status.status_point + point; if (point > 0 && (point > 0x7FFF || new_status_point > 0x7FFF)) // fix positiv overflow new_status_point = 0x7FFF; else if (point < 0 && (point < -0x7FFF || new_status_point < 0)) // fix negativ overflow new_status_point = 0; - if (new_status_point != (int) sd->status.status_point) + if (new_status_point != sd->status.status_point) { - sd->status.status_point = (short) new_status_point; + sd->status.status_point = new_status_point; clif_updatestatus(sd, SP::STATUSPOINT); clif_displaymessage(fd, "Number of status points changed!"); } @@ -2388,15 +2384,15 @@ int atcommand_skillpoint(const int fd, dumb_ptr sd, return -1; } - new_skill_point = (int) sd->status.skill_point + point; + new_skill_point = sd->status.skill_point + point; if (point > 0 && (point > 0x7FFF || new_skill_point > 0x7FFF)) // fix positiv overflow new_skill_point = 0x7FFF; else if (point < 0 && (point < -0x7FFF || new_skill_point < 0)) // fix negativ overflow new_skill_point = 0; - if (new_skill_point != (int) sd->status.skill_point) + if (new_skill_point != sd->status.skill_point) { - sd->status.skill_point = (short) new_skill_point; + sd->status.skill_point = new_skill_point; clif_updatestatus(sd, SP::SKILLPOINT); clif_displaymessage(fd, "Number of skill points changed!"); } @@ -2473,7 +2469,7 @@ int atcommand_param(const int fd, dumb_ptr sd, return -1; } - new_value = (int) sd->status.attrs[attr] + value; + new_value = sd->status.attrs[attr] + value; if (value > 0 && (value > battle_config.max_parameter || new_value > battle_config.max_parameter)) // fix positiv overflow new_value = battle_config.max_parameter; else if (value < 0 && (value < -battle_config.max_parameter || new_value < 1)) // fix negativ overflow @@ -2569,14 +2565,14 @@ int atcommand_recall(const int fd, dumb_ptr sd, { if (pc_isGM(sd) >= pc_isGM(pl_sd)) { // you can recall only lower or same level - if (sd->bl_m >= 0 && map[sd->bl_m].flag.nowarpto + if (sd->bl_m != nullptr && sd->bl_m->flag.nowarpto && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(fd, "You are not authorised to warp somenone to your actual map."); return -1; } - if (pl_sd->bl_m >= 0 && map[pl_sd->bl_m].flag.nowarp + if (pl_sd->bl_m != nullptr && pl_sd->bl_m->flag.nowarp && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(fd, @@ -3094,7 +3090,6 @@ int atcommand_character_save(const int fd, dumb_ptr sd, char character[100]; dumb_ptr pl_sd; int x = 0, y = 0; - int m; memset(map_name, '\0', sizeof(map_name)); memset(character, '\0', sizeof(character)); @@ -3114,16 +3109,17 @@ int atcommand_character_save(const int fd, dumb_ptr sd, if ((pl_sd = map_nick2sd(character)) != NULL) { if (pc_isGM(sd) >= pc_isGM(pl_sd)) - { // you can change save point only to lower or same gm level - m = map_mapname2mapid(map_name); - if (m < 0) + { + // you can change save point only to lower or same gm level + map_local *m = map_mapname2mapid(map_name); + if (m == nullptr) { clif_displaymessage(fd, "Map not found."); return -1; } else { - if (m >= 0 && map[m].flag.nowarpto + if (m != nullptr && m->flag.nowarpto && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(fd, @@ -4113,12 +4109,12 @@ int atcommand_charskpoint(const int fd, dumb_ptr, if ((pl_sd = map_nick2sd(character)) != NULL) { - new_skill_point = (int) pl_sd->status.skill_point + point; + new_skill_point = pl_sd->status.skill_point + point; if (point > 0 && (point > 0x7FFF || new_skill_point > 0x7FFF)) // fix positiv overflow new_skill_point = 0x7FFF; else if (point < 0 && (point < -0x7FFF || new_skill_point < 0)) // fix negativ overflow new_skill_point = 0; - if (new_skill_point != (int) pl_sd->status.skill_point) + if (new_skill_point != pl_sd->status.skill_point) { pl_sd->status.skill_point = new_skill_point; clif_updatestatus(pl_sd, SP::SKILLPOINT); @@ -4167,12 +4163,12 @@ int atcommand_charstpoint(const int fd, dumb_ptr, if ((pl_sd = map_nick2sd(character)) != NULL) { - new_status_point = (int) pl_sd->status.status_point + point; + new_status_point = pl_sd->status.status_point + point; if (point > 0 && (point > 0x7FFF || new_status_point > 0x7FFF)) // fix positiv overflow new_status_point = 0x7FFF; else if (point < 0 && (point < -0x7FFF || new_status_point < 0)) // fix negativ overflow new_status_point = 0; - if (new_status_point != (int) pl_sd->status.status_point) + if (new_status_point != pl_sd->status.status_point) { pl_sd->status.status_point = new_status_point; clif_updatestatus(pl_sd, SP::STATUSPOINT); @@ -4257,7 +4253,7 @@ int atcommand_recallall(const int fd, dumb_ptr sd, { int count; - if (sd->bl_m >= 0 && map[sd->bl_m].flag.nowarpto + if (sd->bl_m != nullptr && sd->bl_m->flag.nowarpto && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(fd, @@ -4277,7 +4273,7 @@ int atcommand_recallall(const int fd, dumb_ptr sd, && pc_isGM(sd) >= pc_isGM(pl_sd)) { // you can recall only lower or same level - if (pl_sd->bl_m >= 0 && map[pl_sd->bl_m].flag.nowarp + if (pl_sd->bl_m != nullptr && pl_sd->bl_m->flag.nowarp && battle_config.any_warp_GM_min_level > pc_isGM(sd)) count++; else @@ -4317,7 +4313,7 @@ int atcommand_partyrecall(const int fd, dumb_ptr sd, return -1; } - if (sd->bl_m >= 0 && map[sd->bl_m].flag.nowarpto + if (sd->bl_m != nullptr && sd->bl_m->flag.nowarpto && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(fd, @@ -4338,7 +4334,7 @@ int atcommand_partyrecall(const int fd, dumb_ptr sd, && sd->status.account_id != pl_sd->status.account_id && pl_sd->status.party_id == p->party_id) { - if (pl_sd->bl_m >= 0 && map[pl_sd->bl_m].flag.nowarp + if (pl_sd->bl_m != nullptr && pl_sd->bl_m->flag.nowarp && battle_config.any_warp_GM_min_level > pc_isGM(sd)) count++; else @@ -4448,7 +4444,7 @@ int atcommand_mapinfo(const int fd, dumb_ptr sd, dumb_ptr nd = NULL; char map_name[100]; const char *direction = NULL; - int m_id, list = 0; + int list = 0; memset(map_name, '\0', sizeof(map_name)); @@ -4466,7 +4462,8 @@ int atcommand_mapinfo(const int fd, dumb_ptr sd, if (strstr(map_name, ".gat") == NULL && strstr(map_name, ".afm") == NULL && strlen(map_name) < 13) // 16 - 4 (.gat) strcat(map_name, ".gat"); - if ((m_id = map_mapname2mapid(map_name)) < 0) + map_local *m_id = map_mapname2mapid(map_name); + if (m_id != nullptr) { clif_displaymessage(fd, "Map not found."); return -1; @@ -4475,38 +4472,38 @@ int atcommand_mapinfo(const int fd, dumb_ptr sd, clif_displaymessage(fd, "------ Map Info ------"); std::string output = STRPRINTF("Map Name: %s", map_name); clif_displaymessage(fd, output); - output = STRPRINTF("Players In Map: %d", map[m_id].users); + output = STRPRINTF("Players In Map: %d", m_id->users); clif_displaymessage(fd, output); - output = STRPRINTF("NPCs In Map: %d", map[m_id].npc_num); + output = STRPRINTF("NPCs In Map: %d", m_id->npc_num); clif_displaymessage(fd, output); clif_displaymessage(fd, "------ Map Flags ------"); output = STRPRINTF("Player vs Player: %s | No Party: %s", - (map[m_id].flag.pvp) ? "True" : "False", - (map[m_id].flag.pvp_noparty) ? "True" : "False"); + (m_id->flag.pvp) ? "True" : "False", + (m_id->flag.pvp_noparty) ? "True" : "False"); clif_displaymessage(fd, output); output = STRPRINTF("No Dead Branch: %s", - (map[m_id].flag.nobranch) ? "True" : "False"); + (m_id->flag.nobranch) ? "True" : "False"); clif_displaymessage(fd, output); output = STRPRINTF("No Memo: %s", - (map[m_id].flag.nomemo) ? "True" : "False"); + (m_id->flag.nomemo) ? "True" : "False"); clif_displaymessage(fd, output); output = STRPRINTF("No Penalty: %s", - (map[m_id].flag.nopenalty) ? "True" : "False"); + (m_id->flag.nopenalty) ? "True" : "False"); clif_displaymessage(fd, output); output = STRPRINTF("No Return: %s", - (map[m_id].flag.noreturn) ? "True" : "False"); + (m_id->flag.noreturn) ? "True" : "False"); clif_displaymessage(fd, output); output = STRPRINTF("No Save: %s", - (map[m_id].flag.nosave) ? "True" : "False"); + (m_id->flag.nosave) ? "True" : "False"); clif_displaymessage(fd, output); output = STRPRINTF("No Teleport: %s", - (map[m_id].flag.noteleport) ? "True" : "False"); + (m_id->flag.noteleport) ? "True" : "False"); clif_displaymessage(fd, output); output = STRPRINTF("No Monster Teleport: %s", - (map[m_id].flag.monster_noteleport) ? "True" : "False"); + (m_id->flag.monster_noteleport) ? "True" : "False"); clif_displaymessage(fd, output); output = STRPRINTF("No Zeny Penalty: %s", - (map[m_id].flag.nozenypenalty) ? "True" : "False"); + (m_id->flag.nozenypenalty) ? "True" : "False"); clif_displaymessage(fd, output); switch (list) @@ -4533,9 +4530,9 @@ int atcommand_mapinfo(const int fd, dumb_ptr sd, break; case 2: clif_displaymessage(fd, "----- NPCs in Map -----"); - for (int i = 0; i < map[m_id].npc_num;) + for (int i = 0; i < m_id->npc_num;) { - nd = map[m_id].npc[i]; + nd = m_id->npc[i]; switch (nd->dir) { case DIR::S: @@ -4844,249 +4841,6 @@ int atcommand_localbroadcast(const int fd, dumb_ptr sd, return 0; } -/*========================================== - * @ignorelist by [Yor] - *------------------------------------------ - */ -int atcommand_ignorelist(const int fd, dumb_ptr sd, - const char *, const char *) -{ - int count; - int i; - - count = 0; - for (i = 0; i < (int)(sizeof(sd->ignore) / sizeof(sd->ignore[0])); i++) - if (sd->ignore[i].name[0]) - count++; - - if (sd->ignoreAll == 0) - if (count == 0) - clif_displaymessage(fd, "You accept any wisp (no wisper is refused)."); - else - { - 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 - { - std::string output = STRPRINTF( - "You refuse all wisps, AND refuse wisps from %d player (s):", - count); - clif_displaymessage(fd, output); - } - - if (count > 0) - for (i = 0; i < (int)(sizeof(sd->ignore) / sizeof(sd->ignore[0])); - i++) - if (sd->ignore[i].name[0]) - clif_displaymessage(fd, sd->ignore[i].name); - - return 0; -} - -/*========================================== - * @charignorelist by [Yor] - *------------------------------------------ - */ -int atcommand_charignorelist(const int fd, dumb_ptr, - const char *, const char *message) -{ - char character[100]; - dumb_ptr pl_sd; - int count; - int i; - - memset(character, '\0', sizeof(character)); - - if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1) - { - clif_displaymessage(fd, - "Please, enter a player name (usage: @charignorelist )."); - return -1; - } - - if ((pl_sd = map_nick2sd(character)) != NULL) - { - count = 0; - for (i = 0; - i < (int)(sizeof(pl_sd->ignore) / sizeof(pl_sd->ignore[0])); - i++) - if (pl_sd->ignore[i].name[0]) - count++; - - if (pl_sd->ignoreAll == 0) - if (count == 0) - { - std::string output = STRPRINTF( - "'%s' accept any wisp (no wisper is refused).", - pl_sd->status.name); - clif_displaymessage(fd, output); - } - else - { - 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) - { - std::string output = STRPRINTF( - "'%s' refuse all wisps (no specifical wisper is refused).", - pl_sd->status.name); - clif_displaymessage(fd, output); - } - else - { - std::string output = STRPRINTF( - "'%s' refuse all wisps, AND refuse wisps from %d player(s):", - pl_sd->status.name, count); - clif_displaymessage(fd, output); - } - - if (count > 0) - for (i = 0; - i < (int)(sizeof(pl_sd->ignore) / sizeof(pl_sd->ignore[0])); - i++) - if (pl_sd->ignore[i].name[0]) - clif_displaymessage(fd, pl_sd->ignore[i].name); - - } - else - { - clif_displaymessage(fd, "Character not found."); - return -1; - } - - return 0; -} - -/*========================================== - * @inall by [Yor] - *------------------------------------------ - */ -int atcommand_inall(const int fd, dumb_ptr sd, - const char *, const char *message) -{ - char character[100]; - dumb_ptr pl_sd; - - memset(character, '\0', sizeof(character)); - - if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1) - { - clif_displaymessage(fd, - "Please, enter a player name (usage: @inall )."); - return -1; - } - - if ((pl_sd = map_nick2sd(character)) != NULL) - { - if (pc_isGM(sd) >= pc_isGM(pl_sd)) - { // you can change wisp option only to lower or same level - if (pl_sd->ignoreAll == 0) - { - std::string output = STRPRINTF( - "'%s' already accepts all wispers.", - pl_sd->status.name); - clif_displaymessage(fd, output); - return -1; - } - else - { - pl_sd->ignoreAll = 0; - 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."); - WFIFOW(pl_sd->fd, 0) = 0x0d2; // R 00d2 .B .B: type: 0: deny, 1: allow, fail: 0: success, 1: fail - WFIFOB(pl_sd->fd, 2) = 1; - WFIFOB(pl_sd->fd, 3) = 0; // success - WFIFOSET(pl_sd->fd, 4); // packet_len_table[0x0d2] - } - } - else - { - clif_displaymessage(fd, "Your GM level don't authorise you to do this action on this player."); - return -1; - } - } - else - { - clif_displaymessage(fd, "Character not found."); - return -1; - } - - return 0; -} - -/*========================================== - * @exall by [Yor] - *------------------------------------------ - */ -int atcommand_exall(const int fd, dumb_ptr sd, - const char *, const char *message) -{ - char character[100]; - dumb_ptr pl_sd; - - memset(character, '\0', sizeof(character)); - - if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1) - { - clif_displaymessage(fd, - "Please, enter a player name (usage: @exall )."); - return -1; - } - - if ((pl_sd = map_nick2sd(character)) != NULL) - { - if (pc_isGM(sd) >= pc_isGM(pl_sd)) - { // you can change wisp option only to lower or same level - if (pl_sd->ignoreAll == 1) - { - std::string output = STRPRINTF( - "'%s' already blocks all wispers.", - pl_sd->status.name); - clif_displaymessage(fd, output); - return -1; - } - else - { - pl_sd->ignoreAll = 1; - 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."); - WFIFOW(pl_sd->fd, 0) = 0x0d2; // R 00d2 .B .B: type: 0: deny, 1: allow, fail: 0: success, 1: fail - WFIFOB(pl_sd->fd, 2) = 0; - WFIFOB(pl_sd->fd, 3) = 0; // success - WFIFOSET(pl_sd->fd, 4); // packet_len_table[0x0d2] - } - } - else - { - clif_displaymessage(fd, "Your GM level don't authorise you to do this action on this player."); - return -1; - } - } - else - { - clif_displaymessage(fd, "Character not found."); - return -1; - } - - return 0; -} - /*========================================== * @email by [Yor] *------------------------------------------ @@ -5901,10 +5655,10 @@ int atcommand_rain(const int, dumb_ptr sd, int effno = 0; effno = 161; nullpo_retr(-1, sd); - if (effno < 0 || map[sd->bl_m].flag.rain) + if (effno < 0 || sd->bl_m->flag.rain) return -1; - map[sd->bl_m].flag.rain = 1; + sd->bl_m->flag.rain = 1; clif_specialeffect(sd, effno, 2); return 0; } @@ -5919,10 +5673,10 @@ int atcommand_snow(const int, dumb_ptr sd, int effno = 0; effno = 162; nullpo_retr(-1, sd); - if (effno < 0 || map[sd->bl_m].flag.snow) + if (effno < 0 || sd->bl_m->flag.snow) return -1; - map[sd->bl_m].flag.snow = 1; + sd->bl_m->flag.snow = 1; clif_specialeffect(sd, effno, 2); return 0; } @@ -5937,10 +5691,10 @@ int atcommand_sakura(const int, dumb_ptr sd, int effno = 0; effno = 163; nullpo_retr(-1, sd); - if (effno < 0 || map[sd->bl_m].flag.sakura) + if (effno < 0 || sd->bl_m->flag.sakura) return -1; - map[sd->bl_m].flag.sakura = 1; + sd->bl_m->flag.sakura = 1; clif_specialeffect(sd, effno, 2); return 0; } @@ -5955,10 +5709,10 @@ int atcommand_fog(const int, dumb_ptr sd, int effno = 0; effno = 233; nullpo_retr(-1, sd); - if (effno < 0 || map[sd->bl_m].flag.fog) + if (effno < 0 || sd->bl_m->flag.fog) return -1; - map[sd->bl_m].flag.fog = 1; + sd->bl_m->flag.fog = 1; clif_specialeffect(sd, effno, 2); return 0; @@ -5974,10 +5728,10 @@ int atcommand_leaves(const int, dumb_ptr sd, int effno = 0; effno = 333; nullpo_retr(-1, sd); - if (effno < 0 || map[sd->bl_m].flag.leaves) + if (effno < 0 || sd->bl_m->flag.leaves) return -1; - map[sd->bl_m].flag.leaves = 1; + sd->bl_m->flag.leaves = 1; clif_specialeffect(sd, effno, 2); return 0; } @@ -6077,7 +5831,8 @@ int atcommand_adjgmlvl(const int fd, dumb_ptr, dumb_ptr pl_sd; if (!message || !*message - || sscanf(message, "%d %s", &newlev, user) != 2) + || sscanf(message, "%d %s", &newlev, user) != 2 + || newlev < 0 || newlev > 99) { clif_displaymessage(fd, "usage: @adjgmlvl ."); return -1; @@ -6301,21 +6056,21 @@ int atcommand_jump_iterate(const int fd, dumb_ptr sd, pl_sd = get_start(); } - if (pl_sd->bl_m >= 0 && map[pl_sd->bl_m].flag.nowarpto + if (pl_sd->bl_m != nullptr && pl_sd->bl_m->flag.nowarpto && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(fd, "You are not authorised to warp you to the map of this player."); return -1; } - if (sd->bl_m >= 0 && map[sd->bl_m].flag.nowarp + if (sd->bl_m != nullptr && 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; } - pc_setpos(sd, map[pl_sd->bl_m].name, pl_sd->bl_x, pl_sd->bl_y, BeingRemoveWhy::WARPED); + pc_setpos(sd, pl_sd->bl_m->name, pl_sd->bl_x, pl_sd->bl_y, BeingRemoveWhy::WARPED); std::string output = STRPRINTF("Jump to %s", pl_sd->status.name); clif_displaymessage(fd, output); @@ -6395,7 +6150,7 @@ int atcommand_skillpool_info(const int fd, dumb_ptr, for (i = 0; i < skill_pool_skills_size; ++i) { - const char *name = skill_name(skill_pool_skills[i]); + const std::string& name = skill_name(skill_pool_skills[i]); int lvl = pl_sd->status.skill[skill_pool_skills[i]].lv; if (lvl) @@ -6522,7 +6277,7 @@ int atcommand_ipcheck(const int fd, dumb_ptr, return -1; } - if (getpeername(pl_sd->fd, (struct sockaddr *)&sai, &sa_len)) + if (getpeername(pl_sd->fd, reinterpret_cast(&sai), &sa_len)) { clif_displaymessage(fd, "Guru Meditation Error: getpeername() failed"); @@ -6541,7 +6296,7 @@ int atcommand_ipcheck(const int fd, dumb_ptr, pl_sd = dumb_ptr(static_cast(session[i]->session_data.get())); if (pl_sd && pl_sd->state.auth) { - if (getpeername(pl_sd->fd, (struct sockaddr *)&sai, &sa_len)) + if (getpeername(pl_sd->fd, reinterpret_cast(&sai), &sa_len)) continue; // Is checking GM levels really needed here? diff --git a/src/map/atcommand.hpp b/src/map/atcommand.hpp index 7033972..d81f04d 100644 --- a/src/map/atcommand.hpp +++ b/src/map/atcommand.hpp @@ -13,6 +13,6 @@ int atcommand_config_read(const char *cfgName); void log_atcommand(dumb_ptr sd, const_string cmd); // only used by map.cpp -extern char *gm_logfile_name; +extern std::string gm_logfile_name; #endif // ATCOMMAND_HPP diff --git a/src/map/battle.cpp b/src/map/battle.cpp index 8e7b174..81e606f 100644 --- a/src/map/battle.cpp +++ b/src/map/battle.cpp @@ -12,6 +12,7 @@ #include "itemdb.hpp" #include "map.hpp" #include "mob.hpp" +#include "path.hpp" #include "pc.hpp" #include "skill.hpp" @@ -2039,8 +2040,8 @@ ATK battle_weapon_attack(dumb_ptr src, dumb_ptr target, && bool(sd->status.inventory[weapon_index].equip & EPOS::WEAPON)) weapon = sd->inventory_data[weapon_index]->nameid; - MAP_LOG("PC%d %d:%d,%d WPNDMG %s%d %d FOR %d WPN %d", - sd->status.char_id, src->bl_m, src->bl_x, src->bl_y, + MAP_LOG("PC%d %s:%d,%d WPNDMG %s%d %d FOR %d WPN %d", + sd->status.char_id, src->bl_m->name, src->bl_x, src->bl_y, (target->bl_type == BL::PC) ? "PC" : "MOB", (target->bl_type == BL::PC) ? target->as_player()-> status.char_id @@ -2052,8 +2053,8 @@ ATK battle_weapon_attack(dumb_ptr src, dumb_ptr target, if (target->bl_type == BL::PC) { dumb_ptr sd2 = target->as_player(); - MAP_LOG("PC%d %d:%d,%d WPNINJURY %s%d %d FOR %d", - sd2->status.char_id, target->bl_m, target->bl_x, target->bl_y, + MAP_LOG("PC%d %s:%d,%d WPNINJURY %s%d %d FOR %d", + sd2->status.char_id, target->bl_m->name, target->bl_x, target->bl_y, (src->bl_type == BL::PC) ? "PC" : "MOB", (src->bl_type == BL::PC) ? src->as_player()->status.char_id @@ -2226,12 +2227,12 @@ int battle_check_target(dumb_ptr src, dumb_ptr target, if (ss->bl_type == BL::PC && target->bl_type == BL::PC) { // 両方PVPモードなら否定(敵) - if (map[ss->bl_m].flag.pvp + if (ss->bl_m->flag.pvp || pc_iskiller(ss->as_player(), target->as_player())) { // [MouseJstr] if (battle_config.pk_mode) return 1; // prevent novice engagement in pk_mode [Valaris] - else if (map[ss->bl_m].flag.pvp_noparty && s_p > 0 && t_p > 0 + else if (ss->bl_m->flag.pvp_noparty && s_p > 0 && t_p > 0 && s_p == t_p) return 1; return 0; @@ -2313,7 +2314,7 @@ int battle_config_read(const char *cfgName) battle_config.defnotenemy = 1; battle_config.random_monster_checklv = 1; battle_config.attr_recover = 1; - battle_config.flooritem_lifetime = (int)std::chrono::duration_cast(LIFETIME_FLOORITEM).count(); + battle_config.flooritem_lifetime = std::chrono::duration_cast(LIFETIME_FLOORITEM).count(); battle_config.item_auto_get = 0; battle_config.drop_pickup_safety_zone = 20; battle_config.item_first_get_time = 3000; @@ -2341,7 +2342,6 @@ int battle_config_read(const char *cfgName) battle_config.wp_rate = 100; battle_config.pp_rate = 100; battle_config.monster_active_enable = 1; - battle_config.monster_loot_type = 0; battle_config.mob_skill_use = 1; battle_config.mob_count_rate = 100; battle_config.quest_skill_learn = 0; @@ -2524,7 +2524,6 @@ int battle_config_read(const char *cfgName) {"weapon_produce_rate", &battle_config.wp_rate}, {"potion_produce_rate", &battle_config.pp_rate}, {"monster_active_enable", &battle_config.monster_active_enable}, - {"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}, @@ -2666,7 +2665,7 @@ int battle_config_read(const char *cfgName) if (--count == 0) { if (static_cast(battle_config.flooritem_lifetime) < std::chrono::seconds(1)) - battle_config.flooritem_lifetime = (int)std::chrono::duration_cast(LIFETIME_FLOORITEM).count(); + battle_config.flooritem_lifetime = std::chrono::duration_cast(LIFETIME_FLOORITEM).count(); if (battle_config.restart_hp_rate < 0) battle_config.restart_hp_rate = 0; else if (battle_config.restart_hp_rate > 100) diff --git a/src/map/battle.hpp b/src/map/battle.hpp index 8b7c1bd..168cf60 100644 --- a/src/map/battle.hpp +++ b/src/map/battle.hpp @@ -132,7 +132,6 @@ extern struct Battle_Config int wp_rate; int pp_rate; int monster_active_enable; - int monster_loot_type; int mob_skill_use; int mob_count_rate; int quest_skill_learn; diff --git a/src/map/battle.t.hpp b/src/map/battle.t.hpp index e374298..f730cc5 100644 --- a/src/map/battle.t.hpp +++ b/src/map/battle.t.hpp @@ -25,6 +25,10 @@ ENUM_BITWISE_OPERATORS(BF) } using e::BF; +namespace e +{ +// not actually an enum, but put in the namespace to hide the operators +// from non-ADL. struct BCT { // former representation: @@ -56,6 +60,8 @@ constexpr bool operator == (BCT l, BCT r) { return l.lo == r.lo && l.mid == r.mid && l.classic == r.classic && l.level == r.level && l.unused == r.unused; } constexpr bool operator != (BCT l, BCT r) { return !(l == r); } +} // namespace e +using e::BCT; constexpr BCT BCT_NOENEMY = {0x00, 0x00, 0x0, 0x0, 0x00}; diff --git a/src/map/chrif.cpp b/src/map/chrif.cpp index aaa727e..ebed281 100644 --- a/src/map/chrif.cpp +++ b/src/map/chrif.cpp @@ -145,14 +145,17 @@ int chrif_connect(int fd) static int chrif_sendmap(int fd) { - int i; + int i = 0; WFIFOW(fd, 0) = 0x2afa; - for (i = 0; i < map_num; i++) - if (map[i].alias[0] != '\0') // [MouseJstr] map aliasing - memcpy(WFIFOP(fd, 4 + i * 16), map[i].alias, 16); - else - memcpy(WFIFOP(fd, 4 + i * 16), map[i].name, 16); + for (auto& pair : maps_db) + { + map_abstract *ma = pair.second.get(); + if (!ma->gat) + continue; + memcpy(WFIFOP(fd, 4 + i * 16), ma->name, 16); + i++; + } WFIFOW(fd, 2) = 4 + i * 16; WFIFOSET(fd, WFIFOW(fd, 2)); @@ -176,7 +179,7 @@ int chrif_recvmap(int fd) port = RFIFOW(fd, 8); for (i = 10, j = 0; i < RFIFOW(fd, 2); i += 16, j++) { - map_setipport((const char *)RFIFOP(fd, i), ip, port); + map_setipport(static_cast(RFIFOP(fd, i)), ip, port); // if (battle_config.etc_log) // PRINTF("recv map %d %s\n", j, RFIFOP(fd,i)); } @@ -241,7 +244,7 @@ int chrif_changemapserverack(int fd) pc_authfail(sd->fd); return 0; } - clif_changemapserver(sd, (const char *)RFIFOP(fd, 18), RFIFOW(fd, 34), + clif_changemapserver(sd, static_cast(RFIFOP(fd, 18)), RFIFOW(fd, 34), RFIFOW(fd, 36), in_addr{RFIFOL(fd, 38)}, RFIFOW(fd, 42)); return 0; @@ -989,9 +992,8 @@ void ladmin_itemfrob_c2(dumb_ptr bl, int source_id, int dest_id) case BL::MOB: { dumb_ptr mob = bl->as_mob(); - int i; - for (i = 0; i < mob->lootitem_count; i++) - FIX(mob->lootitem[i]); + for (struct item& itm : mob->lootitemv) + FIX(itm); break; } @@ -1017,10 +1019,11 @@ void ladmin_itemfrob(int fd) { int source_id = RFIFOL(fd, 2); int dest_id = RFIFOL(fd, 6); - dumb_ptr bl = (dumb_ptr) map_get_first_session(); + dumb_ptr bl = map_get_first_session(); // flooritems - map_foreachobject(std::bind(ladmin_itemfrob_c, ph::_1, source_id, dest_id), BL::NUL /* any object */); + map_foreachobject(std::bind(ladmin_itemfrob_c, ph::_1, source_id, dest_id), + BL::NUL /* any object */); // player characters (and, hopefully, mobs) while (bl->bl_next) @@ -1097,7 +1100,7 @@ void chrif_parse(int fd) case 0x2afd: pc_authok(RFIFOL(fd, 4), RFIFOL(fd, 8), static_cast(RFIFOL(fd, 12)), RFIFOW(fd, 16), - (const struct mmo_charstatus *) RFIFOP(fd, 18)); + static_cast(RFIFOP(fd, 18))); break; case 0x2afe: pc_authfail(RFIFOL(fd, 2)); @@ -1115,7 +1118,7 @@ void chrif_parse(int fd) chrif_changemapserverack(fd); break; case 0x2b09: - map_addchariddb(RFIFOL(fd, 2), (const char *)RFIFOP(fd, 6)); + map_addchariddb(RFIFOL(fd, 2), static_cast(RFIFOP(fd, 6))); break; case 0x2b0b: chrif_changedgm(fd); diff --git a/src/map/clif.cpp b/src/map/clif.cpp index fbba044..f20c887 100644 --- a/src/map/clif.cpp +++ b/src/map/clif.cpp @@ -203,9 +203,16 @@ static void clif_emotion_towards(dumb_ptr bl, dumb_ptr target, int type); + +enum class ChatType +{ + Party, + Whisper, + Global, +}; + static -char *clif_validate_chat(dumb_ptr sd, int type, - const char **message, size_t *message_len); +std::string clif_validate_chat(dumb_ptr sd, ChatType type); /*========================================== * clif_sendでSendWho::AREA*指定時用 @@ -337,13 +344,17 @@ int clif_send(const uint8_t *buf, int len, dumb_ptr bl, SendWho type case SendWho::AREA: case SendWho::AREA_WOS: map_foreachinarea(std::bind(clif_send_sub, ph::_1, buf, len, bl, type), - bl->bl_m, bl->bl_x - AREA_SIZE, bl->bl_y - AREA_SIZE, - bl->bl_x + AREA_SIZE, bl->bl_y + AREA_SIZE, BL::PC); + bl->bl_m, + bl->bl_x - AREA_SIZE, bl->bl_y - AREA_SIZE, + bl->bl_x + AREA_SIZE, bl->bl_y + AREA_SIZE, + BL::PC); break; case SendWho::AREA_CHAT_WOC: map_foreachinarea(std::bind(clif_send_sub, ph::_1, buf, len, bl, SendWho::AREA_CHAT_WOC), - bl->bl_m, bl->bl_x - (AREA_SIZE), bl->bl_y - (AREA_SIZE), - bl->bl_x + (AREA_SIZE), bl->bl_y + (AREA_SIZE), BL::PC); + bl->bl_m, + bl->bl_x - (AREA_SIZE), bl->bl_y - (AREA_SIZE), + bl->bl_x + (AREA_SIZE), bl->bl_y + (AREA_SIZE), + BL::PC); break; case SendWho::PARTY_AREA: // 同じ画面内の全パーティーメンバに送信 @@ -912,15 +923,15 @@ int clif_spawnpc(dumb_ptr sd) WBUFW(buf, 51) = 0; clif_send(buf, clif_parse_func_table[0x1d9].len, sd, SendWho::AREA_WOS); - if (map[sd->bl_m].flag.snow) + if (sd->bl_m->flag.snow) clif_specialeffect(sd, 162, 1); - if (map[sd->bl_m].flag.fog) + if (sd->bl_m->flag.fog) clif_specialeffect(sd, 233, 1); - if (map[sd->bl_m].flag.sakura) + if (sd->bl_m->flag.sakura) clif_specialeffect(sd, 163, 1); - if (map[sd->bl_m].flag.leaves) + if (sd->bl_m->flag.leaves) clif_specialeffect(sd, 333, 1); - if (map[sd->bl_m].flag.rain) + if (sd->bl_m->flag.rain) clif_specialeffect(sd, 161, 1); // clif_changelook_accessories(sd, NULL); @@ -1281,7 +1292,7 @@ int clif_scriptmes(dumb_ptr sd, int npcid, const char *mes) WFIFOW(fd, 0) = 0xb4; WFIFOW(fd, 2) = strlen(mes) + 9; WFIFOL(fd, 4) = npcid; - strcpy((char *)WFIFOP(fd, 8), mes); + strcpy(static_cast(WFIFOP(fd, 8)), mes); WFIFOSET(fd, WFIFOW(fd, 2)); return 0; @@ -1337,7 +1348,7 @@ int clif_scriptmenu(dumb_ptr sd, int npcid, const char *mes) WFIFOW(fd, 0) = 0xb7; WFIFOW(fd, 2) = strlen(mes) + 8; WFIFOL(fd, 4) = npcid; - strcpy((char *)WFIFOP(fd, 8), mes); + strcpy(static_cast(WFIFOP(fd, 8)), mes); WFIFOSET(fd, WFIFOW(fd, 2)); return 0; @@ -1469,7 +1480,7 @@ int clif_additem(dumb_ptr sd, int n, int amount, PickupFail fa WFIFOB(fd, 10) = sd->status.inventory[n].refine; if (sd->status.inventory[n].card[0] == 0x00ff || sd->status.inventory[n].card[0] == 0x00fe - || sd->status.inventory[n].card[0] == (short) 0xff00) + || sd->status.inventory[n].card[0] == static_cast(0xff00)) { WFIFOW(fd, 11) = sd->status.inventory[n].card[0]; WFIFOW(fd, 13) = sd->status.inventory[n].card[1]; @@ -1617,7 +1628,7 @@ int clif_equiplist(dumb_ptr sd) WFIFOB(fd, n * 20 + 15) = sd->status.inventory[i].refine; if (sd->status.inventory[i].card[0] == 0x00ff || sd->status.inventory[i].card[0] == 0x00fe - || sd->status.inventory[i].card[0] == (short) 0xff00) + || sd->status.inventory[i].card[0] == static_cast(0xff00)) { WFIFOW(fd, n * 20 + 16) = sd->status.inventory[i].card[0]; WFIFOW(fd, n * 20 + 18) = sd->status.inventory[i].card[1]; @@ -1742,7 +1753,7 @@ int clif_storageequiplist(dumb_ptr sd, struct storage *stor) WFIFOB(fd, n * 20 + 15) = stor->storage_[i].refine; if (stor->storage_[i].card[0] == 0x00ff || stor->storage_[i].card[0] == 0x00fe - || stor->storage_[i].card[0] == (short) 0xff00) + || stor->storage_[i].card[0] == static_cast(0xff00)) { WFIFOW(fd, n * 20 + 16) = stor->storage_[i].card[0]; WFIFOW(fd, n * 20 + 18) = stor->storage_[i].card[1]; @@ -2312,7 +2323,7 @@ int clif_traderequest(dumb_ptr sd, const char *name) fd = sd->fd; WFIFOW(fd, 0) = 0xe5; - strcpy((char *)WFIFOP(fd, 2), name); + strcpy(static_cast(WFIFOP(fd, 2)), name); WFIFOSET(fd, clif_parse_func_table[0xe5].len); return 0; @@ -2378,7 +2389,7 @@ int clif_tradeadditem(dumb_ptr sd, WFIFOB(fd, 10) = sd->status.inventory[index].refine; //refine if (sd->status.inventory[index].card[0] == 0x00ff || sd->status.inventory[index].card[0] == 0x00fe - || sd->status.inventory[index].card[0] == (short) 0xff00) + || sd->status.inventory[index].card[0] == static_cast(0xff00)) { WFIFOW(fd, 11) = sd->status.inventory[index].card[0]; //card (4w) WFIFOW(fd, 13) = sd->status.inventory[index].card[1]; //card (4w) @@ -2541,7 +2552,7 @@ int clif_storageitemadded(dumb_ptr sd, struct storage *stor, WFIFOB(fd, 12) = stor->storage_[index].refine; //refine if (stor->storage_[index].card[0] == 0x00ff || stor->storage_[index].card[0] == 0x00fe - || stor->storage_[index].card[0] == (short) 0xff00) + || stor->storage_[index].card[0] == static_cast(0xff00)) { WFIFOW(fd, 13) = stor->storage_[index].card[0]; //card (4w) WFIFOW(fd, 15) = stor->storage_[index].card[1]; //card (4w) @@ -3790,7 +3801,7 @@ void clif_parse_LoadEndAck(int, dumb_ptr sd) if (!battle_config.pk_mode) sd->pvp_timer.cancel(); - if (map[sd->bl_m].flag.pvp) + if (sd->bl_m->flag.pvp) { if (!battle_config.pk_mode) { @@ -3832,9 +3843,11 @@ void clif_parse_LoadEndAck(int, dumb_ptr sd) // clif_changelook_accessories(sd, NULL); - map_foreachinarea(std::bind(clif_getareachar, ph::_1, sd), sd->bl_m, sd->bl_x - AREA_SIZE, - sd->bl_y - AREA_SIZE, sd->bl_x + AREA_SIZE, - sd->bl_y + AREA_SIZE, BL::NUL); + map_foreachinarea(std::bind(clif_getareachar, ph::_1, sd), + sd->bl_m, + sd->bl_x - AREA_SIZE, sd->bl_y - AREA_SIZE, + sd->bl_x + AREA_SIZE, sd->bl_y + AREA_SIZE, + BL::NUL); } /*========================================== @@ -3998,7 +4011,7 @@ void clif_parse_GetCharNameRequest(int fd, dumb_ptr sd) case BL::NPC: memcpy(WFIFOP(fd, 6), bl->as_npc()->name, 24); { - char *start = (char *)WFIFOP(fd, 6); + char *start = static_cast(WFIFOP(fd, 6)); char *end = strchr(start, '#'); // [fate] elim hashed out/invisible names for the client if (end) while (*end) @@ -4038,52 +4051,41 @@ void clif_parse_GetCharNameRequest(int fd, dumb_ptr sd) static void clif_parse_GlobalMessage(int fd, dumb_ptr sd) { - int msg_len = RFIFOW(fd, 2) - 4; /* Header(2) + length(2). */ - size_t message_len = 0; - // sometimes uint8_t - char *buf = NULL; - const char *message = NULL; /* The message text only. */ - nullpo_retv(sd); - if (!(buf = clif_validate_chat(sd, 2, &message, &message_len))) + std::string mbuf = clif_validate_chat(sd, ChatType::Global); + if (mbuf.empty()) { clif_displaymessage(fd, "Your message could not be sent."); return; } - if (is_atcommand(fd, sd, message, 0)) //チャット禁止 - { - free(buf); + if (is_atcommand(fd, sd, mbuf.c_str(), 0)) return; - } - if (!magic_message(sd, buf, msg_len)) + if (!magic_message(sd, mbuf)) { /* Don't send chat that results in an automatic ban. */ - if (tmw_CheckChatSpam(sd, message)) + if (tmw_CheckChatSpam(sd, mbuf.c_str())) { - free(buf); clif_displaymessage(fd, "Your message could not be sent."); return; } /* It's not a spell/magic message, so send the message to others. */ - WBUFW(reinterpret_cast(buf), 0) = 0x8d; - WBUFW(reinterpret_cast(buf), 2) = msg_len + 8; /* Header(2) + length(2) + ID(4). */ - WBUFL(reinterpret_cast(buf), 4) = sd->bl_id; + uint8_t sendbuf[mbuf.size() + 8]; + WBUFW(sendbuf, 0) = 0x8d; + WBUFW(sendbuf, 2) = mbuf.size() + 8; /* Header(2) + length(2) + ID(4). */ + WBUFL(sendbuf, 4) = sd->bl_id; + memcpy(WBUFP(sendbuf, 8), mbuf.data(), mbuf.size()); - // evil multiuse buffer! - clif_send((const uint8_t *)buf, msg_len + 8, sd, SendWho::AREA_CHAT_WOC); + clif_send(sendbuf, mbuf.size() + 8, sd, SendWho::AREA_CHAT_WOC); } /* Send the message back to the speaker. */ memcpy(WFIFOP(fd, 0), RFIFOP(fd, 0), RFIFOW(fd, 2)); WFIFOW(fd, 0) = 0x8e; WFIFOSET(fd, WFIFOW(fd, 2)); - - free(buf); - return; } int clif_message(dumb_ptr bl, const char *msg) @@ -4290,29 +4292,25 @@ void clif_parse_Restart(int fd, dumb_ptr sd) static void clif_parse_Wis(int fd, dumb_ptr sd) { - size_t message_len = 0; - char *buf = NULL; - const char *message = NULL; /* The message text only. */ dumb_ptr dstsd = NULL; nullpo_retv(sd); - if (!(buf = clif_validate_chat(sd, 1, &message, &message_len))) + std::string mbuf = clif_validate_chat(sd, ChatType::Whisper); + if (mbuf.empty()) { clif_displaymessage(fd, "Your message could not be sent."); return; } - if (is_atcommand(fd, sd, message, 0)) + if (is_atcommand(fd, sd, mbuf.c_str(), 0)) { - free(buf); return; } /* Don't send chat that results in an automatic ban. */ - if (tmw_CheckChatSpam(sd, message)) + if (tmw_CheckChatSpam(sd, mbuf.c_str())) { - free(buf); clif_displaymessage(fd, "Your message could not be sent."); return; } @@ -4323,9 +4321,10 @@ void clif_parse_Wis(int fd, dumb_ptr sd) * conflict (for instance, "Test" versus "test"), the char-server must * settle the discrepancy. */ - if (!(dstsd = map_nick2sd((const char *)RFIFOP(fd, 4))) - || strcmp(dstsd->status.name, (const char *)RFIFOP(fd, 4)) != 0) - intif_wis_message(sd, (const char *)RFIFOP(fd, 4), message, RFIFOW(fd, 2) - 28); + const char *tname = static_cast(RFIFOP(fd, 4)); + if (!(dstsd = map_nick2sd(tname)) + || strcmp(dstsd->status.name, tname) != 0) + intif_wis_message(sd, tname, mbuf.c_str(), RFIFOW(fd, 2) - 28); else { /* Refuse messages addressed to self. */ @@ -4336,28 +4335,10 @@ void clif_parse_Wis(int fd, dumb_ptr sd) } else { - /* The target is ignoring all whispers. */ - if (dstsd->ignoreAll == 1) - /* Ignored by target. */ - clif_wis_end(fd, 2); - else { - int i; - size_t end = sizeof(dstsd->ignore) / sizeof(dstsd->ignore[0]); - - /* See if the source player is being ignored. */ - for (i = 0; i < end; ++i) - if (strcmp(dstsd->ignore[i].name, sd->status.name) == 0) - { - /* Ignored by target. */ - clif_wis_end(fd, 2); - break; - } - /* The player is not being ignored. */ - if (i == end) { - clif_wis_message(dstsd->fd, sd->status.name, message, + clif_wis_message(dstsd->fd, sd->status.name, mbuf.c_str(), RFIFOW(fd, 2) - 28); /* The whisper was sent successfully. */ clif_wis_end(fd, 0); @@ -4365,8 +4346,6 @@ void clif_parse_Wis(int fd, dumb_ptr sd) } } } - - free(buf); } /*========================================== @@ -4423,7 +4402,7 @@ void clif_parse_DropItem(int fd, dumb_ptr sd) clif_clearchar(sd, BeingRemoveWhy::DEAD); return; } - if (map[sd->bl_m].flag.no_player_drops) + if (sd->bl_m->flag.no_player_drops) { clif_displaymessage(sd->fd, "Can't drop items here."); return; @@ -4765,7 +4744,7 @@ void clif_parse_NpcStringInput(int fd, dumb_ptr sd) } if (len > 0) - strncpy(sd->npc_str, (const char *)RFIFOP(fd, 8), len); + strncpy(sd->npc_str, static_cast(RFIFOP(fd, 8)), len); sd->npc_str[len] = '\0'; map_scriptcont(sd, RFIFOL(fd, 4)); @@ -4851,7 +4830,7 @@ void clif_parse_CreateParty(int fd, dumb_ptr sd) if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, SkillID::NV_PARTY) >= 2) { - party_create(sd, (const char *)RFIFOP(fd, 2)); + party_create(sd, static_cast(RFIFOP(fd, 2))); } else clif_skill_fail(sd, SkillID::ONE, 0, 4); @@ -4909,7 +4888,7 @@ void clif_parse_LeaveParty(int, dumb_ptr sd) static void clif_parse_RemovePartyMember(int fd, dumb_ptr sd) { - party_removemember(sd, RFIFOL(fd, 2), (const char *)RFIFOP(fd, 6)); + party_removemember(sd, RFIFOL(fd, 2), static_cast(RFIFOP(fd, 6))); } /*========================================== @@ -4933,81 +4912,26 @@ void clif_parse_PartyChangeOption(int fd, dumb_ptr sd) static void clif_parse_PartyMessage(int fd, dumb_ptr sd) { - size_t message_len = 0; - char *buf = NULL; - const char *message = NULL; /* The message text only. */ - nullpo_retv(sd); - if (!(buf = clif_validate_chat(sd, 0, &message, &message_len))) + std::string mbuf = clif_validate_chat(sd, ChatType::Party); + if (mbuf.empty()) { clif_displaymessage(fd, "Your message could not be sent."); return; } - if (is_atcommand(fd, sd, message, 0)) //チャット禁止 - { - free(buf); + if (is_atcommand(fd, sd, mbuf.c_str(), 0)) return; - } /* Don't send chat that results in an automatic ban. */ - if (tmw_CheckChatSpam(sd, message)) + if (tmw_CheckChatSpam(sd, mbuf.c_str())) { - free(buf); clif_displaymessage(fd, "Your message could not be sent."); return; } - party_send_message(sd, message, RFIFOW(fd, 2) - 4); - free(buf); -} - -// 4144 wants this, but I don't like it ... -static -void clif_parse_PMIgnoreAll(int fd, dumb_ptr sd) -{ // Rewritten by [Yor] - //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 - WFIFOB(fd, 2) = 0; - if (sd->ignoreAll == 0) - { - sd->ignoreAll = 1; - WFIFOB(fd, 3) = 0; // success - WFIFOSET(fd, clif_parse_func_table[0x0d2].len); - } - else - { - WFIFOB(fd, 3) = 1; // fail - WFIFOSET(fd, clif_parse_func_table[0x0d2].len); - clif_wis_message(fd, wisp_server_name, - "You already block everyone.", - strlen("You already block everyone.") + 1); - } - } - else - { - WFIFOW(fd, 0) = 0x0d2; // R 00d2 .B .B: type: 0: deny, 1: allow, fail: 0: success, 1: fail - WFIFOB(fd, 2) = 1; - if (sd->ignoreAll == 1) - { - sd->ignoreAll = 0; - WFIFOB(fd, 3) = 0; // success - WFIFOSET(fd, clif_parse_func_table[0x0d2].len); - } - else - { - WFIFOB(fd, 3) = 1; // fail - WFIFOSET(fd, clif_parse_func_table[0x0d2].len); - clif_wis_message(fd, wisp_server_name, - "You already allow everyone.", - strlen("You already allow everyone.") + 1); - } - } - - return; + party_send_message(sd, mbuf.c_str(), RFIFOW(fd, 2) - 4); } func_table clif_parse_func_table[0x0220] = @@ -5220,7 +5144,7 @@ func_table clif_parse_func_table[0x0220] = {0, 6, NULL, }, // 0x00cd {0, 2, NULL, }, // 0x00ce {0, 27, NULL, }, // 0x00cf - {0, 3, clif_parse_PMIgnoreAll, }, // 0x00d0 + {0, 3, NULL, }, // 0x00d0 {0, 4, NULL, }, // 0x00d1 {0, 4, NULL, }, // 0x00d2 {0, 2, NULL, }, // 0x00d3 @@ -5653,35 +5577,22 @@ void WARN_MALFORMED_MSG(dumb_ptr sd, const char *msg) * 0 for when the sender's name is not included (party chat) * 1 for when the target's name is included (whisper chat) * 2 for when the sender's name is given ("sender : text", public/guild chat) - * @param[out] message the message text (pointing within return value, or NULL) - * @param[out] message_len the length of the actual text, excluding NUL - * @return a dynamically allocated copy of the message, or NULL upon failure + * @return a dynamically allocated copy of the message, or empty string upon failure */ static -char *clif_validate_chat(dumb_ptr sd, int type, - const char **message, size_t *message_len) +std::string clif_validate_chat(dumb_ptr sd, ChatType type) { - int fd; - unsigned int buf_len; /* Actual message length. */ - unsigned int msg_len; /* Reported message length. */ - unsigned int min_len; /* Minimum message length. */ - size_t name_len; /* Sender's name length. */ - char *buf = NULL; /* Copy of actual message data. */ - - *message = NULL; - *message_len = 0; - - nullpo_retr(NULL, sd); + nullpo_retr(std::string(), sd); /* * Don't send chat in the period between the ban and the connection's * closure. */ - if (type < 0 || type > 2 || sd->auto_ban_info.in_progress) - return NULL; + if (sd->auto_ban_info.in_progress) + return std::string(); - fd = sd->fd; - msg_len = RFIFOW(fd, 2) - 4; - name_len = strlen(sd->status.name); + int fd = sd->fd; + size_t msg_len = RFIFOW(fd, 2) - 4; + size_t name_len = strlen(sd->status.name); /* * At least one character is required in all instances. * Notes for length checks: @@ -5692,33 +5603,42 @@ char *clif_validate_chat(dumb_ptr sd, int type, * For type 2, the message must be longer than the sender's name length * plus the length of the separator (" : "). */ - min_len = (type == 1) ? 24 : (type == 2) ? name_len + 3 : 0; + size_t min_len = + (type == ChatType::Whisper) ? 24 + : (type == ChatType::Global) ? name_len + 3 + : 0; /* The player just sent the header (2) and length (2) words. */ if (!msg_len) { WARN_MALFORMED_MSG(sd, "no message sent"); - return NULL; + return std::string(); } /* The client sent (or claims to have sent) an empty message. */ if (msg_len == min_len) { WARN_MALFORMED_MSG(sd, "empty message"); - return NULL; + return std::string(); } /* The protocol specifies that the target must be 24 bytes long. */ - if (type == 1 && msg_len < min_len) + if (type == ChatType::Whisper && msg_len < min_len) { /* Disallow malformed messages. */ clif_setwaitclose(fd); WARN_MALFORMED_MSG(sd, "illegal target name"); - return NULL; + return std::string(); } - const char *p = static_cast((type != 1) ? RFIFOP(fd, 4) : RFIFOP(fd, 28)); - buf_len = (type == 1) ? msg_len - min_len: msg_len; + const char *p = static_cast(RFIFOP(fd, 4)); + size_t buf_len = msg_len; + if (type == ChatType::Whisper) + { + p += 24; + buf_len -= 24; + } + const char *pend = p + buf_len; /* * The client attempted to exceed the maximum message length. @@ -5730,43 +5650,25 @@ char *clif_validate_chat(dumb_ptr sd, int type, if (buf_len >= battle_config.chat_maxline) { WARN_MALFORMED_MSG(sd, "exceeded maximum message length"); - return NULL; + return std::string(); } - /* We're leaving an extra eight bytes for public/global chat, 1 for NUL. */ - buf_len += (type == 2) ? 8 + 1 : 1; - - buf = (char *) malloc(buf_len); - memcpy((type != 2) ? buf : buf + 8, p, - (type != 2) ? buf_len - 1 : buf_len - 8 - 1); - buf[buf_len - 1] = '\0'; - p = (type != 2) ? buf : buf + 8; - - if (type != 2) - { - *message = buf; - /* Don't count the NUL. */ - *message_len = buf_len - 1; - } - else + if (type == ChatType::Global) { - const char *pos = NULL; - if (!(pos = strstr(p, " : ")) - || strncmp(p, sd->status.name, name_len) - || pos - p != name_len) + const char *pos = strstr(p, " : "); + if (!pos || pos != p + name_len || memcmp(p, sd->status.name, name_len)) { - free(buf); /* Disallow malformed/spoofed messages. */ clif_setwaitclose(fd); WARN_MALFORMED_MSG(sd, "spoofed name/invalid format"); - return NULL; + return std::string(); } /* Step beyond the separator. */ - *message = pos + 3; - /* Don't count the sender's name, the extra eight bytes, or the NUL. */ - *message_len = buf_len - min_len - 8 - 1; + p = pos + 3; } + std::string buf(p, pend); + return buf; } diff --git a/src/map/intif.cpp b/src/map/intif.cpp index 53ff80e..1010047 100644 --- a/src/map/intif.cpp +++ b/src/map/intif.cpp @@ -88,7 +88,7 @@ int intif_wis_message_to_gm(const char *Wisp_name, int min_gm_level, const char WFIFOW(char_fd, 0) = 0x3003; WFIFOW(char_fd, 2) = mes_len + 30; memcpy(WFIFOP(char_fd, 4), Wisp_name, 24); - WFIFOW(char_fd, 28) = (short) min_gm_level; + WFIFOW(char_fd, 28) = min_gm_level; memcpy(WFIFOP(char_fd, 30), mes, mes_len); WFIFOSET(char_fd, WFIFOW(char_fd, 2)); @@ -159,7 +159,7 @@ int intif_create_party(dumb_ptr sd, const char *name) WFIFOL(char_fd, 2) = sd->status.account_id; memcpy(WFIFOP(char_fd, 6), name, 24); memcpy(WFIFOP(char_fd, 30), sd->status.name, 24); - memcpy(WFIFOP(char_fd, 54), map[sd->bl_m].name, 16); + memcpy(WFIFOP(char_fd, 54), sd->bl_m->name, 16); WFIFOW(char_fd, 70) = sd->status.base_level; WFIFOSET(char_fd, 72); // if(battle_config.etc_log) @@ -191,7 +191,7 @@ int intif_party_addmember(int party_id, int account_id) WFIFOL(char_fd, 2) = party_id; WFIFOL(char_fd, 6) = account_id; memcpy(WFIFOP(char_fd, 10), sd->status.name, 24); - memcpy(WFIFOP(char_fd, 34), map[sd->bl_m].name, 16); + memcpy(WFIFOP(char_fd, 34), sd->bl_m->name, 16); WFIFOW(char_fd, 50) = sd->status.base_level; WFIFOSET(char_fd, 52); } @@ -230,7 +230,7 @@ int intif_party_changemap(dumb_ptr sd, int online) WFIFOW(char_fd, 0) = 0x3025; WFIFOL(char_fd, 2) = sd->status.party_id; WFIFOL(char_fd, 6) = sd->status.account_id; - memcpy(WFIFOP(char_fd, 10), map[sd->bl_m].name, 16); + memcpy(WFIFOP(char_fd, 10), sd->bl_m->name, 16); WFIFOB(char_fd, 26) = online; WFIFOW(char_fd, 27) = sd->status.base_level; WFIFOSET(char_fd, 29); @@ -273,7 +273,6 @@ static int intif_parse_WisMessage(int fd) { // rewritten by [Yor] dumb_ptr sd; - int i; if (battle_config.etc_log) PRINTF("intif_parse_wismessage: id: %d, from: %s, to: %s, message: '%s'\n", @@ -281,27 +280,14 @@ int intif_parse_WisMessage(int fd) static_cast(RFIFOP(fd, 8)), static_cast(RFIFOP(fd, 32)), static_cast(RFIFOP(fd, 56))); - sd = map_nick2sd((const char *)RFIFOP(fd, 32)); // Searching destination player - if (sd != NULL && strcmp(sd->status.name, (const char *)RFIFOP(fd, 32)) == 0) - { // exactly same name (inter-server have checked the name before) - // if player ignore all - if (sd->ignoreAll == 1) - intif_wis_replay(RFIFOL(fd, 4), 2); // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target - else + sd = map_nick2sd(static_cast(RFIFOP(fd, 32))); // Searching destination player + if (sd != NULL && strcmp(sd->status.name, static_cast(RFIFOP(fd, 32))) == 0) + { + // exactly same name (inter-server have checked the name before) { - const char *wisp_source = (const char *)RFIFOP(fd, 8); // speed up - // if player ignore the source character - for (i = 0; i < (sizeof(sd->ignore) / sizeof(sd->ignore[0])); - i++) - if (strcmp(sd->ignore[i].name, wisp_source) == 0) - { - intif_wis_replay(RFIFOL(fd, 4), 2); // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target - break; - } // if source player not found in ignore list - if (i == (sizeof(sd->ignore) / sizeof(sd->ignore[0]))) { - clif_wis_message(sd->fd, (const char *)RFIFOP(fd, 8), (const char *)RFIFOP(fd, 56), + clif_wis_message(sd->fd, static_cast(RFIFOP(fd, 8)), static_cast(RFIFOP(fd, 56)), RFIFOW(fd, 2) - 56); intif_wis_replay(RFIFOL(fd, 4), 0); // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target } @@ -322,7 +308,7 @@ int intif_parse_WisEnd(int fd) // 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", static_cast(RFIFOP(fd, 2)), RFIFOB(fd, 26)); - sd = map_nick2sd((const char *)RFIFOP(fd, 2)); + sd = map_nick2sd(static_cast(RFIFOP(fd, 2))); if (sd != NULL) clif_wis_end(sd->fd, RFIFOB(fd, 26)); @@ -336,19 +322,18 @@ int mapif_parse_WisToGM(int fd) // 0x3003/0x3803 .w .24B .w .?B int min_gm_level, len; char Wisp_name[24]; - char mbuf[255]; if (RFIFOW(fd, 2) - 30 <= 0) return 0; len = RFIFOW(fd, 2) - 30; - char *message = ((len) >= 255) ? (char *) malloc(len) : mbuf; + char message[len + 1]; - min_gm_level = (int) RFIFOW(fd, 28); + min_gm_level = RFIFOW(fd, 28); memcpy(Wisp_name, RFIFOP(fd, 4), 24); Wisp_name[23] = '\0'; memcpy(message, RFIFOP(fd, 30), len); - message[len - 1] = '\0'; + message[len] = '\0'; // information is sended to all online GM for (int i = 0; i < fd_max; i++) { @@ -361,9 +346,6 @@ int mapif_parse_WisToGM(int fd) strlen(message) + 1); } - if (message != mbuf) - free(message); - return 0; } @@ -457,7 +439,7 @@ int intif_parse_PartyCreated(int fd) if (battle_config.etc_log) PRINTF("intif: party created\n"); party_created(RFIFOL(fd, 2), RFIFOB(fd, 6), RFIFOL(fd, 7), - (const char *)RFIFOP(fd, 11)); + static_cast(RFIFOP(fd, 11))); return 0; } @@ -511,8 +493,8 @@ int intif_parse_PartyMemberLeaved(int fd) { if (battle_config.etc_log) 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)); + RFIFOL(fd, 6), static_cast(RFIFOP(fd, 10))); + party_member_leaved(RFIFOL(fd, 2), RFIFOL(fd, 6), static_cast(RFIFOP(fd, 10))); return 0; } @@ -530,7 +512,7 @@ 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)); - party_recv_movemap(RFIFOL(fd, 2), RFIFOL(fd, 6), (const char *)RFIFOP(fd, 10), + party_recv_movemap(RFIFOL(fd, 2), RFIFOL(fd, 6), static_cast(RFIFOP(fd, 10)), RFIFOB(fd, 26), RFIFOW(fd, 27)); return 0; } @@ -541,7 +523,7 @@ int intif_parse_PartyMessage(int fd) { // if(battle_config.etc_log) // PRINTF("intif_parse_PartyMessage: %s\n",RFIFOP(fd,12)); - party_recv_message(RFIFOL(fd, 4), RFIFOL(fd, 8), (const char *)RFIFOP(fd, 12), + party_recv_message(RFIFOL(fd, 4), RFIFOL(fd, 8), static_cast(RFIFOP(fd, 12)), RFIFOW(fd, 2) - 12); return 0; } @@ -581,7 +563,7 @@ int intif_parse(int fd) { case 0x3800: clif_GMmessage(NULL, - const_string((const char *)RFIFOP(fd, 4), + const_string(static_cast(RFIFOP(fd, 4)), (packet_len - 4) - 1), 0); break; case 0x3801: diff --git a/src/map/itemdb.cpp b/src/map/itemdb.cpp index f60dc53..147db91 100644 --- a/src/map/itemdb.cpp +++ b/src/map/itemdb.cpp @@ -367,10 +367,8 @@ int itemdb_read_noequip(void) static void itemdb_final(struct item_data *id) { - if (id->use_script) - free(const_cast(id->use_script)); - if (id->equip_script) - free(const_cast(id->equip_script)); + id->use_script.reset(); + id->equip_script.reset(); } void itemdb_reload(void) diff --git a/src/map/itemdb.hpp b/src/map/itemdb.hpp index 279c7a8..02da73a 100644 --- a/src/map/itemdb.hpp +++ b/src/map/itemdb.hpp @@ -27,8 +27,8 @@ struct item_data int elv; int wlv; int refine; - const ScriptCode *use_script; - const ScriptCode *equip_script; + std::unique_ptr use_script; + std::unique_ptr equip_script; struct { unsigned available:1; @@ -67,9 +67,9 @@ int itemdb_weight(int n) return itemdb_search(n)->weight; } inline -const ScriptCode *itemdb_equipscript(int n) +const ScriptBuffer *itemdb_equipscript(int n) { - return itemdb_search(n)->equip_script; + return itemdb_search(n)->equip_script.get(); } inline int itemdb_wlv(int n) diff --git a/src/map/magic-expr-eval.hpp b/src/map/magic-expr-eval.hpp index bc5ce6e..9c9591b 100644 --- a/src/map/magic-expr-eval.hpp +++ b/src/map/magic-expr-eval.hpp @@ -10,13 +10,13 @@ int magic_signature_check(const char *opname, const char *funname, const char *signature, int args_nr, val_t *args, int line, int column); -void magic_area_rect(int *m, int *x, int *y, int *width, int *height, - area_t *area); +void magic_area_rect(map_local **m, int *x, int *y, int *width, int *height, + area_t& area); #define ARGINT(x) args[x].v.v_int #define ARGDIR(x) args[x].v.v_dir #define ARGSTR(x) args[x].v.v_string -#define ARGENTITY(x) dumb_ptr(args[x].v.v_entity) +#define ARGENTITY(x) args[x].v.v_entity #define ARGLOCATION(x) args[x].v.v_location #define ARGAREA(x) args[x].v.v_area #define ARGSPELL(x) args[x].v.v_spell diff --git a/src/map/magic-expr.cpp b/src/map/magic-expr.cpp index c0eaf9f..7739847 100644 --- a/src/map/magic-expr.cpp +++ b/src/map/magic-expr.cpp @@ -16,7 +16,7 @@ #include "../poison.hpp" static -void free_area(area_t *area) +void free_area(dumb_ptr area) { if (!area) return; @@ -31,13 +31,13 @@ void free_area(area_t *area) break; } - free(area); + area.delete_(); } static -area_t *dup_area(area_t *area) +dumb_ptr dup_area(dumb_ptr area) { - area_t *retval = (area_t *)malloc(sizeof(area_t)); + dumb_ptr retval = dumb_ptr::make(); *retval = *area; switch (area->ty) @@ -60,7 +60,7 @@ void magic_copy_var(val_t *dest, val_t *src) switch (dest->ty) { case TYPE::STRING: - dest->v.v_string = strdup(dest->v.v_string); + dest->v.v_string = dest->v.v_string.dup(); break; case TYPE::AREA: dest->v.v_area = dup_area(dest->v.v_area); @@ -76,7 +76,7 @@ void magic_clear_var(val_t *v) switch (v->ty) { case TYPE::STRING: - free(v->v.v_string); + v->v.v_string.delete_(); break; case TYPE::AREA: free_area(v->v.v_area); @@ -139,12 +139,12 @@ void stringify(val_t *v, int within_op) break; case TYPE::ENTITY: - buf = show_entity(dumb_ptr(v->v.v_entity)); + buf = show_entity(v->v.v_entity); break; case TYPE::LOCATION: buf = STRPRINTF("<\"%s\", %d, %d>", - map[v->v.v_location.m].name, + v->v.v_location.m->name, v->v.v_location.x, v->v.v_location.y); break; @@ -161,7 +161,7 @@ void stringify(val_t *v, int within_op) case TYPE::INVOCATION: { dumb_ptr invocation_ = within_op - ? dumb_ptr(v->v.v_invocation) + ? v->v.v_invocation : map_id2bl(v->v.v_int)->as_spell(); buf = invocation_->spell->name; } @@ -173,7 +173,7 @@ void stringify(val_t *v, int within_op) return; } - v->v.v_string = strdup(buf.c_str()); + v->v.v_string = dumb_string::copys(buf); v->ty = TYPE::STRING; } @@ -189,18 +189,17 @@ void intify(val_t *v) } static -area_t *area_new(AREA ty) +dumb_ptr area_new(AREA ty) { - area_t *retval; - CREATE(retval, area_t, 1); + auto retval = dumb_ptr::make(); retval->ty = ty; return retval; } static -area_t *area_union(area_t *area, area_t *other_area) +dumb_ptr area_union(dumb_ptr area, dumb_ptr other_area) { - area_t *retval = area_new(AREA::UNION); + dumb_ptr retval = area_new(AREA::UNION); retval->a.a_union[0] = area; retval->a.a_union[1] = other_area; retval->size = area->size + other_area->size; /* Assume no overlap */ @@ -215,7 +214,7 @@ void make_area(val_t *v) { if (v->ty == TYPE::LOCATION) { - area_t *a = (area_t *)malloc(sizeof(area_t)); + auto a = dumb_ptr::make(); v->ty = TYPE::AREA; a->ty = AREA::LOCATION; a->a.a_loc = v->v.v_location; @@ -240,7 +239,7 @@ void make_spell(val_t *v) { if (v->ty == TYPE::INVOCATION) { - dumb_ptr invoc = dumb_ptr(v->v.v_invocation); + dumb_ptr invoc = v->v.v_invocation; //invoc = (dumb_ptr) map_id2bl(v->v.v_int); if (!invoc) v->ty = TYPE::FAIL; @@ -253,7 +252,7 @@ void make_spell(val_t *v) } static -int fun_add(env_t *, int, val_t *result, val_t *args) +int fun_add(dumb_ptr, val_t *result, const_array args) { if (ARG_TYPE(0) == TYPE::INT && ARG_TYPE(1) == TYPE::INT) { @@ -277,31 +276,29 @@ int fun_add(env_t *, int, val_t *result, val_t *args) stringify(&args[0], 1); stringify(&args[1], 1); /* Yes, we could speed this up. */ - RESULTSTR = - (char *) malloc(1 + strlen(ARGSTR(0)) + strlen(ARGSTR(1))); - strcpy(RESULTSTR, ARGSTR(0)); - strcat(RESULTSTR, ARGSTR(1)); + // ugh + RESULTSTR = dumb_string::copys(ARGSTR(0).str() + ARGSTR(1).str()); result->ty = TYPE::STRING; } return 0; } static -int fun_sub(env_t *, int, val_t *result, val_t *args) +int fun_sub(dumb_ptr, val_t *result, const_array args) { RESULTINT = ARGINT(0) - ARGINT(1); return 0; } static -int fun_mul(env_t *, int, val_t *result, val_t *args) +int fun_mul(dumb_ptr, val_t *result, const_array args) { RESULTINT = ARGINT(0) * ARGINT(1); return 0; } static -int fun_div(env_t *, int, val_t *result, val_t *args) +int fun_div(dumb_ptr, val_t *result, const_array args) { if (!ARGINT(1)) return 1; /* division by zero */ @@ -310,7 +307,7 @@ int fun_div(env_t *, int, val_t *result, val_t *args) } static -int fun_mod(env_t *, int, val_t *result, val_t *args) +int fun_mod(dumb_ptr, val_t *result, const_array args) { if (!ARGINT(1)) return 1; /* division by zero */ @@ -319,41 +316,42 @@ int fun_mod(env_t *, int, val_t *result, val_t *args) } static -int fun_or(env_t *, int, val_t *result, val_t *args) +int fun_or(dumb_ptr, val_t *result, const_array args) { RESULTINT = ARGINT(0) || ARGINT(1); return 0; } static -int fun_and(env_t *, int, val_t *result, val_t *args) +int fun_and(dumb_ptr, val_t *result, const_array args) { RESULTINT = ARGINT(0) && ARGINT(1); return 0; } static -int fun_not(env_t *, int, val_t *result, val_t *args) +int fun_not(dumb_ptr, val_t *result, const_array args) { RESULTINT = !ARGINT(0); return 0; } static -int fun_neg(env_t *, int, val_t *result, val_t *args) +int fun_neg(dumb_ptr, val_t *result, const_array args) { RESULTINT = ~ARGINT(0); return 0; } static -int fun_gte(env_t *, int, val_t *result, val_t *args) +int fun_gte(dumb_ptr, val_t *result, const_array args) { if (ARG_TYPE(0) == TYPE::STRING || ARG_TYPE(1) == TYPE::STRING) { stringify(&args[0], 1); stringify(&args[1], 1); - RESULTINT = strcmp(ARGSTR(0), ARGSTR(1)) >= 0; + using namespace operators; + RESULTINT = ARGSTR(0) >= ARGSTR(1); } else { @@ -365,13 +363,14 @@ int fun_gte(env_t *, int, val_t *result, val_t *args) } static -int fun_gt(env_t *, int, val_t *result, val_t *args) +int fun_gt(dumb_ptr, val_t *result, const_array args) { if (ARG_TYPE(0) == TYPE::STRING || ARG_TYPE(1) == TYPE::STRING) { stringify(&args[0], 1); stringify(&args[1], 1); - RESULTINT = strcmp(ARGSTR(0), ARGSTR(1)) > 0; + using namespace operators; + RESULTINT = ARGSTR(0) > ARGSTR(1); } else { @@ -383,13 +382,14 @@ int fun_gt(env_t *, int, val_t *result, val_t *args) } static -int fun_eq(env_t *, int, val_t *result, val_t *args) +int fun_eq(dumb_ptr, val_t *result, const_array args) { if (ARG_TYPE(0) == TYPE::STRING || ARG_TYPE(1) == TYPE::STRING) { stringify(&args[0], 1); stringify(&args[1], 1); - RESULTINT = strcmp(ARGSTR(0), ARGSTR(1)) == 0; + using namespace operators; + RESULTINT = ARGSTR(0) == ARGSTR(1); } else if (ARG_TYPE(0) == TYPE::DIR && ARG_TYPE(1) == TYPE::DIR) RESULTINT = ARGDIR(0) == ARGDIR(1); @@ -415,56 +415,56 @@ int fun_eq(env_t *, int, val_t *result, val_t *args) } static -int fun_bitand(env_t *, int, val_t *result, val_t *args) +int fun_bitand(dumb_ptr, val_t *result, const_array args) { RESULTINT = ARGINT(0) & ARGINT(1); return 0; } static -int fun_bitor(env_t *, int, val_t *result, val_t *args) +int fun_bitor(dumb_ptr, val_t *result, const_array args) { RESULTINT = ARGINT(0) | ARGINT(1); return 0; } static -int fun_bitxor(env_t *, int, val_t *result, val_t *args) +int fun_bitxor(dumb_ptr, val_t *result, const_array args) { RESULTINT = ARGINT(0) ^ ARGINT(1); return 0; } static -int fun_bitshl(env_t *, int, val_t *result, val_t *args) +int fun_bitshl(dumb_ptr, val_t *result, const_array args) { RESULTINT = ARGINT(0) << ARGINT(1); return 0; } static -int fun_bitshr(env_t *, int, val_t *result, val_t *args) +int fun_bitshr(dumb_ptr, val_t *result, const_array args) { RESULTINT = ARGINT(0) >> ARGINT(1); return 0; } static -int fun_max(env_t *, int, val_t *result, val_t *args) +int fun_max(dumb_ptr, val_t *result, const_array args) { RESULTINT = max(ARGINT(0), ARGINT(1)); return 0; } static -int fun_min(env_t *, int, val_t *result, val_t *args) +int fun_min(dumb_ptr, val_t *result, const_array args) { RESULTINT = min(ARGINT(0), ARGINT(1)); return 0; } static -int fun_if_then_else(env_t *, int, val_t *result, val_t *args) +int fun_if_then_else(dumb_ptr, val_t *result, const_array args) { if (ARGINT(0)) magic_copy_var(result, &args[1]); @@ -473,9 +473,10 @@ int fun_if_then_else(env_t *, int, val_t *result, val_t *args) return 0; } -void magic_area_rect(int *m, int *x, int *y, int *width, int *height, - area_t *area) +void magic_area_rect(map_local **m, int *x, int *y, int *width, int *height, + area_t& area_) { + area_t *area = &area_; // diff hack switch (area->ty) { case AREA::UNION: @@ -547,7 +548,7 @@ void magic_area_rect(int *m, int *x, int *y, int *width, int *height, } } -int magic_location_in_area(int m, int x, int y, area_t *area) +int magic_location_in_area(map_local *m, int x, int y, dumb_ptr area) { switch (area->ty) { @@ -558,9 +559,9 @@ int magic_location_in_area(int m, int x, int y, area_t *area) case AREA::RECT: case AREA::BAR: { - int am; + map_local *am; int ax, ay, awidth, aheight; - magic_area_rect(&am, &ax, &ay, &awidth, &aheight, area); + magic_area_rect(&am, &ax, &ay, &awidth, &aheight, *area); return (am == m && (x >= ax) && (y >= ay) && (x < ax + awidth) && (y < ay + aheight)); @@ -572,7 +573,7 @@ int magic_location_in_area(int m, int x, int y, area_t *area) } static -int fun_is_in(env_t *, int, val_t *result, val_t *args) +int fun_is_in(dumb_ptr, val_t *result, const_array args) { RESULTINT = magic_location_in_area(ARGLOCATION(0).m, ARGLOCATION(0).x, @@ -581,7 +582,7 @@ int fun_is_in(env_t *, int, val_t *result, val_t *args) } static -int fun_skill(env_t *, int, val_t *result, val_t *args) +int fun_skill(dumb_ptr, val_t *result, const_array args) { if (ENTITY_TYPE(0) != BL::PC // don't convert to enum until after the range check @@ -599,7 +600,7 @@ int fun_skill(env_t *, int, val_t *result, val_t *args) } static -int fun_has_shroud(env_t *, int, val_t *result, val_t *args) +int fun_has_shroud(dumb_ptr, val_t *result, const_array args) { RESULTINT = (ENTITY_TYPE(0) == BL::PC && ARGPC(0)->state.shroud_active); return 0; @@ -607,7 +608,7 @@ int fun_has_shroud(env_t *, int, val_t *result, val_t *args) #define BATTLE_GETTER(name) \ static \ -int fun_get_##name(env_t *, int, val_t *result, val_t *args) \ +int fun_get_##name(dumb_ptr, val_t *result, const_array args) \ { \ RESULTINT = battle_get_##name(ARGENTITY(0)); \ return 0; \ @@ -625,7 +626,7 @@ BATTLE_GETTER(mdef) BATTLE_GETTER(def) BATTLE_GETTER(max_hp) static -int fun_get_dir(env_t *, int, val_t *result, val_t *args) +int fun_get_dir(dumb_ptr, val_t *result, const_array args) { RESULTDIR = battle_get_dir(ARGENTITY(0)); return 0; @@ -633,7 +634,7 @@ int fun_get_dir(env_t *, int, val_t *result, val_t *args) #define MMO_GETTER(name) \ static \ -int fun_get_##name(env_t *, int, val_t *result, val_t *args) \ +int fun_get_##name(dumb_ptr, val_t *result, const_array args) \ { \ if (ENTITY_TYPE(0) == BL::PC) \ RESULTINT = ARGPC(0)->status.name; \ @@ -646,21 +647,21 @@ MMO_GETTER(sp) MMO_GETTER(max_sp) static -int fun_name_of(env_t *, int, val_t *result, val_t *args) +int fun_name_of(dumb_ptr, val_t *result, const_array args) { if (ARG_TYPE(0) == TYPE::ENTITY) { - RESULTSTR = strdup(show_entity(ARGENTITY(0))); + RESULTSTR = dumb_string::copy(show_entity(ARGENTITY(0))); return 0; } else if (ARG_TYPE(0) == TYPE::SPELL) { - RESULTSTR = strdup(ARGSPELL(0)->name); + RESULTSTR = dumb_string::copys(ARGSPELL(0)->name); return 0; } else if (ARG_TYPE(0) == TYPE::INVOCATION) { - RESULTSTR = strdup(ARGINVOCATION(0)->spell->name); + RESULTSTR = dumb_string::copys(ARGINVOCATION(0)->spell->name); return 0; } return 1; @@ -668,7 +669,7 @@ int fun_name_of(env_t *, int, val_t *result, val_t *args) /* [Freeyorp] I'm putting this one in as name_of seems to have issues with summoned or spawned mobs. */ static -int fun_mob_id(env_t *, int, val_t *result, val_t *args) +int fun_mob_id(dumb_ptr, val_t *result, const_array args) { if (ENTITY_TYPE(0) != BL::MOB) return 1; @@ -693,14 +694,14 @@ void COPY_LOCATION(location_t& dest, block_list& src) } static -int fun_location(env_t *, int, val_t *result, val_t *args) +int fun_location(dumb_ptr, val_t *result, const_array args) { COPY_LOCATION(RESULTLOCATION, *(ARGENTITY(0))); return 0; } static -int fun_random(env_t *, int, val_t *result, val_t *args) +int fun_random(dumb_ptr, val_t *result, const_array args) { int delta = ARGINT(0); if (delta < 0) @@ -718,7 +719,7 @@ int fun_random(env_t *, int, val_t *result, val_t *args) } static -int fun_random_dir(env_t *, int, val_t *result, val_t *args) +int fun_random_dir(dumb_ptr, val_t *result, const_array args) { if (ARGINT(0)) RESULTDIR = random_::choice({DIR::S, DIR::SW, DIR::W, DIR::NW, DIR::N, DIR::NE, DIR::E, DIR::SE}); @@ -728,14 +729,14 @@ int fun_random_dir(env_t *, int, val_t *result, val_t *args) } static -int fun_hash_entity(env_t *, int, val_t *result, val_t *args) +int fun_hash_entity(dumb_ptr, val_t *result, const_array args) { RESULTINT = ARGENTITY(0)->bl_id; return 0; } int // ret -1: not a string, ret 1: no such item, ret 0: OK -magic_find_item(val_t *args, int index, struct item *item, int *stackable) +magic_find_item(const_array args, int index, struct item *item, int *stackable) { struct item_data *item_data; int must_add_sequentially; @@ -743,7 +744,7 @@ magic_find_item(val_t *args, int index, struct item *item, int *stackable) if (ARG_TYPE(index) == TYPE::INT) item_data = itemdb_exists(ARGINT(index)); else if (ARG_TYPE(index) == TYPE::STRING) - item_data = itemdb_searchname(ARGSTR(index)); + item_data = itemdb_searchname(ARGSTR(index).c_str()); else return -1; @@ -768,7 +769,7 @@ magic_find_item(val_t *args, int index, struct item *item, int *stackable) } static -int fun_count_item(env_t *, int, val_t *result, val_t *args) +int fun_count_item(dumb_ptr, val_t *result, const_array args) { dumb_ptr chr = (ENTITY_TYPE(0) == BL::PC) ? ARGPC(0) : NULL; int stackable; @@ -784,7 +785,7 @@ int fun_count_item(env_t *, int, val_t *result, val_t *args) } static -int fun_is_equipped(env_t *, int, val_t *result, val_t *args) +int fun_is_equipped(dumb_ptr, val_t *result, const_array args) { dumb_ptr chr = (ENTITY_TYPE(0) == BL::PC) ? ARGPC(0) : NULL; int stackable; @@ -810,33 +811,33 @@ int fun_is_equipped(env_t *, int, val_t *result, val_t *args) } static -int fun_is_married(env_t *, int, val_t *result, val_t *args) +int fun_is_married(dumb_ptr, val_t *result, const_array args) { RESULTINT = (ENTITY_TYPE(0) == BL::PC && ARGPC(0)->status.partner_id); return 0; } static -int fun_is_dead(env_t *, int, val_t *result, val_t *args) +int fun_is_dead(dumb_ptr, val_t *result, const_array args) { RESULTINT = (ENTITY_TYPE(0) == BL::PC && pc_isdead(ARGPC(0))); return 0; } static -int fun_is_pc(env_t *, int, val_t *result, val_t *args) +int fun_is_pc(dumb_ptr, val_t *result, const_array args) { RESULTINT = (ENTITY_TYPE(0) == BL::PC); return 0; } static -int fun_partner(env_t *, int, val_t *result, val_t *args) +int fun_partner(dumb_ptr, val_t *result, const_array args) { if (ENTITY_TYPE(0) == BL::PC && ARGPC(0)->status.partner_id) { RESULTENTITY = - map_nick2sd(map_charid2nick(ARGPC(0)->status.partner_id)).operator->(); + map_nick2sd(map_charid2nick(ARGPC(0)->status.partner_id)); return 0; } else @@ -844,14 +845,14 @@ int fun_partner(env_t *, int, val_t *result, val_t *args) } static -int fun_awayfrom(env_t *, int, val_t *result, val_t *args) +int fun_awayfrom(dumb_ptr, val_t *result, const_array args) { location_t *loc = &ARGLOCATION(0); int dx = dirx[ARGDIR(1)]; int dy = diry[ARGDIR(1)]; int distance = ARGINT(2); while (distance-- - && !bool(read_gat(loc->m, loc->x + dx, loc->y + dy) + && !bool(read_gatp(loc->m, loc->x + dx, loc->y + dy) & MapCell::UNWALKABLE)) { loc->x += dx; @@ -863,28 +864,28 @@ int fun_awayfrom(env_t *, int, val_t *result, val_t *args) } static -int fun_failed(env_t *, int, val_t *result, val_t *args) +int fun_failed(dumb_ptr, val_t *result, const_array args) { RESULTINT = ARG_TYPE(0) == TYPE::FAIL; return 0; } static -int fun_npc(env_t *, int, val_t *result, val_t *args) +int fun_npc(dumb_ptr, val_t *result, const_array args) { - RESULTENTITY = npc_name2id(ARGSTR(0)).operator->(); + RESULTENTITY = npc_name2id(ARGSTR(0).c_str()); return RESULTENTITY == NULL; } static -int fun_pc(env_t *, int, val_t *result, val_t *args) +int fun_pc(dumb_ptr, val_t *result, const_array args) { - RESULTENTITY = map_nick2sd(ARGSTR(0)).operator->(); + RESULTENTITY = map_nick2sd(ARGSTR(0).c_str()); return RESULTENTITY == NULL; } static -int fun_distance(env_t *, int, val_t *result, val_t *args) +int fun_distance(dumb_ptr, val_t *result, const_array args) { if (ARGLOCATION(0).m != ARGLOCATION(1).m) RESULTINT = 0x7fffffff; @@ -895,7 +896,7 @@ int fun_distance(env_t *, int, val_t *result, val_t *args) } static -int fun_rdistance(env_t *, int, val_t *result, val_t *args) +int fun_rdistance(dumb_ptr, val_t *result, const_array args) { if (ARGLOCATION(0).m != ARGLOCATION(1).m) RESULTINT = 0x7fffffff; @@ -903,15 +904,15 @@ int fun_rdistance(env_t *, int, val_t *result, val_t *args) { int dx = ARGLOCATION(0).x - ARGLOCATION(1).x; int dy = ARGLOCATION(0).y - ARGLOCATION(1).y; - RESULTINT = (int)(sqrt((dx * dx) + (dy * dy))); + RESULTINT = static_cast(sqrt((dx * dx) + (dy * dy))); } return 0; } static -int fun_anchor(env_t *env, int, val_t *result, val_t *args) +int fun_anchor(dumb_ptr env, val_t *result, const_array args) { - teleport_anchor_t *anchor = magic_find_anchor(ARGSTR(0)); + dumb_ptr anchor = magic_find_anchor(ARGSTR(0).str()); if (!anchor) return 1; @@ -929,7 +930,7 @@ int fun_anchor(env_t *env, int, val_t *result, val_t *args) } static -int fun_line_of_sight(env_t *, int, val_t *result, val_t *args) +int fun_line_of_sight(dumb_ptr, val_t *result, const_array args) { block_list e1, e2; @@ -941,7 +942,7 @@ int fun_line_of_sight(env_t *, int, val_t *result, val_t *args) return 0; } -void magic_random_location(location_t *dest, area_t *area) +void magic_random_location(location_t *dest, dumb_ptr area) { switch (area->ty) { @@ -958,8 +959,9 @@ void magic_random_location(location_t *dest, area_t *area) case AREA::RECT: case AREA::BAR: { - int m, x, y, w, h; - magic_area_rect(&m, &x, &y, &w, &h, area); + map_local *m; + int x, y, w, h; + magic_area_rect(&m, &x, &y, &w, &h, *area); if (w <= 1) w = 1; @@ -984,27 +986,27 @@ void magic_random_location(location_t *dest, area_t *area) } static -int fun_pick_location(env_t *, int, val_t *result, val_t *args) +int fun_pick_location(dumb_ptr, val_t *result, const_array args) { magic_random_location(&result->v.v_location, ARGAREA(0)); return 0; } static -int fun_read_script_int(env_t *, int, val_t *result, val_t *args) +int fun_read_script_int(dumb_ptr, val_t *result, const_array args) { dumb_ptr subject_p = ARGENTITY(0); - char *var_name = ARGSTR(1); + dumb_string var_name = ARGSTR(1); if (subject_p->bl_type != BL::PC) return 1; - RESULTINT = pc_readglobalreg(subject_p->as_player(), var_name); + RESULTINT = pc_readglobalreg(subject_p->as_player(), var_name.c_str()); return 0; } static -int fun_rbox(env_t *, int, val_t *result, val_t *args) +int fun_rbox(dumb_ptr, val_t *result, const_array args) { location_t loc = ARGLOCATION(0); int radius = ARGINT(1); @@ -1020,7 +1022,7 @@ int fun_rbox(env_t *, int, val_t *result, val_t *args) } static -int fun_running_status_update(env_t *, int, val_t *result, val_t *args) +int fun_running_status_update(dumb_ptr, val_t *result, const_array args) { if (ENTITY_TYPE(0) != BL::PC && ENTITY_TYPE(0) != BL::MOB) return 1; @@ -1031,66 +1033,67 @@ int fun_running_status_update(env_t *, int, val_t *result, val_t *args) } static -int fun_status_option(env_t *, int, val_t *result, val_t *args) +int fun_status_option(dumb_ptr, val_t *result, const_array args) { RESULTINT = (bool((ARGPC(0))->status.option & static_cast