From 9544985ccbb20d7f8377c63a4e59d1ff97b844ac Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Mon, 3 Feb 2014 10:05:00 -0800 Subject: Convert fd to Session* where meaningful --- src/map/atcommand.cpp | 1106 ++++++++++++++++---------------- src/map/atcommand.hpp | 2 +- src/map/chrif.cpp | 441 ++++++------- src/map/chrif.hpp | 2 +- src/map/clif.cpp | 1646 +++++++++++++++++++++++------------------------- src/map/clif.hpp | 18 +- src/map/intif.cpp | 364 +++++------ src/map/intif.hpp | 2 +- src/map/magic-stmt.cpp | 6 +- src/map/map.cpp | 6 +- src/map/map.hpp | 4 +- src/map/party.cpp | 8 +- src/map/pc.cpp | 30 +- src/map/pc.hpp | 4 +- src/map/script.cpp | 4 +- src/map/tmw.cpp | 8 +- 16 files changed, 1823 insertions(+), 1828 deletions(-) (limited to 'src/map') diff --git a/src/map/atcommand.cpp b/src/map/atcommand.cpp index 9687968..931a4d0 100644 --- a/src/map/atcommand.cpp +++ b/src/map/atcommand.cpp @@ -58,10 +58,10 @@ struct AtCommandInfo { ZString args; int level; - ATCE (*proc)(const int fd, dumb_ptr sd, ZString message); + ATCE (*proc)(Session *s, dumb_ptr sd, ZString message); ZString help; - AtCommandInfo(ZString a, int l, ATCE (*p)(const int, dumb_ptr, ZString), ZString h) + AtCommandInfo(ZString a, int l, ATCE (*p)(Session *s, dumb_ptr, ZString), ZString h) : args(a), level(l), proc(p), help(h) {} }; @@ -78,16 +78,16 @@ AtCommandInfo *atcommand(XString cmd); // These @commands are used within other @commands. static -ATCE atcommand_character_baselevel(const int fd, dumb_ptr sd, +ATCE atcommand_character_baselevel(Session *s, dumb_ptr sd, ZString message); static -ATCE atcommand_skill_learn(const int fd, dumb_ptr, +ATCE atcommand_skill_learn(Session *s, dumb_ptr, ZString message); static -ATCE atcommand_charwarp(const int fd, dumb_ptr sd, +ATCE atcommand_charwarp(Session *s, dumb_ptr sd, ZString message); static -ATCE atcommand_charstreset(const int fd, dumb_ptr sd, +ATCE atcommand_charstreset(Session *s, dumb_ptr sd, ZString message); @@ -217,7 +217,7 @@ io::AppendFile *get_gm_log() return gm_logfile.get(); } -bool is_atcommand(const int fd, dumb_ptr sd, +bool is_atcommand(Session *s, dumb_ptr sd, ZString message, int gmlvl) { nullpo_retr(false, sd); @@ -237,14 +237,14 @@ bool is_atcommand(const int fd, dumb_ptr sd, { FString output = STRPRINTF("GM command is level 0, but this server disables level 0 commands: %s", FString(command)); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); return true; } if (!info) { FString output = STRPRINTF("GM command not found: %s", FString(command)); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); return true; // don't show in chat } @@ -253,13 +253,13 @@ bool is_atcommand(const int fd, dumb_ptr sd, FString output = STRPRINTF("GM command is level %d, but you are level %d: %s", info->level, gmlvl, FString(command)); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); return true; } { { - ATCE err = info->proc(fd, sd, arg); + ATCE err = info->proc(s, sd, arg); switch (err) { case ATCE::OKAY: @@ -268,17 +268,17 @@ bool is_atcommand(const int fd, dumb_ptr sd, log_atcommand(sd, message); break; case ATCE::USAGE: - clif_displaymessage(fd, "Command failed: usage error"); - clif_displaymessage(fd, STRPRINTF("Usage: %s %s", FString(command), info->args)); + clif_displaymessage(s, "Command failed: usage error"); + clif_displaymessage(s, STRPRINTF("Usage: %s %s", FString(command), info->args)); break; case ATCE::EXIST: - clif_displaymessage(fd, "Command failed: something does not exist (or already exists)"); + clif_displaymessage(s, "Command failed: something does not exist (or already exists)"); break; case ATCE::RANGE: - clif_displaymessage(fd, "Command failed: value out of range"); + clif_displaymessage(s, "Command failed: value out of range"); break; case ATCE::PERM: - clif_displaymessage(fd, "Command failed: permission denied"); + clif_displaymessage(s, "Command failed: permission denied"); break; default: abort(); @@ -365,7 +365,7 @@ bool atcommand_config_read(ZString cfgName) /// @ command processing functions static -void atc_do_help(const int fd, const char *cmd, const AtCommandInfo& info) +void atc_do_help(Session *s, const char *cmd, const AtCommandInfo& info) { auto msg = STRPRINTF("\u2007\u2007%d: @%s %s", info.level, cmd, info.args); // manually padding because *space* @@ -374,18 +374,18 @@ void atc_do_help(const int fd, const char *cmd, const AtCommandInfo& info) ++ll; if (info.level >= 100) ++ll; - clif_displaymessage(fd, msg.xslice_t((ll - 1) * 3)); + clif_displaymessage(s, msg.xslice_t((ll - 1) * 3)); } static -ATCE atcommand_help(const int fd, dumb_ptr, +ATCE atcommand_help(Session *s, dumb_ptr, ZString message) { if (!message) { - clif_displaymessage(fd, "There is too much help to display it all at once"); - clif_displaymessage(fd, "Try @help <@command> or @help or @help "); - clif_displaymessage(fd, "Right now the only category is 'all'"); + clif_displaymessage(s, "There is too much help to display it all at once"); + clif_displaymessage(s, "Try @help <@command> or @help or @help "); + clif_displaymessage(s, "Right now the only category is 'all'"); return ATCE::OKAY; } @@ -395,19 +395,19 @@ ATCE atcommand_help(const int fd, dumb_ptr, const AtCommandInfo *info = atcommand_info.search(cmd); if (!info) return ATCE::EXIST; - clif_displaymessage(fd, STRPRINTF("Usage: @%s %s", cmd, info->args)); - clif_displaymessage(fd, info->help); + clif_displaymessage(s, STRPRINTF("Usage: @%s %s", cmd, info->args)); + clif_displaymessage(s, info->help); return ATCE::OKAY; } if (message == "all") { - clif_displaymessage(fd, "Synopses of GM commands in category 'all':"); + clif_displaymessage(s, "Synopses of GM commands in category 'all':"); for (const auto& pair : atcommand_info) { const char *cmd = &*pair.first.begin(); const AtCommandInfo& info = pair.second; - atc_do_help(fd, cmd, info); + atc_do_help(s, cmd, info); } return ATCE::OKAY; } @@ -420,19 +420,19 @@ ATCE atcommand_help(const int fd, dumb_ptr, if (low < 0 || high > 100 || low >= high) return ATCE::RANGE; - clif_displaymessage(fd, STRPRINTF("Synopses of GM commands in level [%d, %d):", low, high)); + clif_displaymessage(s, STRPRINTF("Synopses of GM commands in level [%d, %d):", low, high)); for (const auto& pair : atcommand_info) { const char *cmd = &*pair.first.begin(); const AtCommandInfo& info = pair.second; if (low <= info.level && info.level < high) - atc_do_help(fd, cmd, info); + atc_do_help(s, cmd, info); } return ATCE::OKAY; } static -ATCE atcommand_setup(const int fd, dumb_ptr sd, +ATCE atcommand_setup(Session *s, dumb_ptr sd, ZString message) { int level = 1; @@ -444,31 +444,31 @@ ATCE atcommand_setup(const int fd, dumb_ptr sd, FString buf; buf = STRPRINTF("-255 %s", character); - atcommand_character_baselevel(fd, sd, buf); + atcommand_character_baselevel(s, sd, buf); buf = STRPRINTF("%d %s", level, character); - atcommand_character_baselevel(fd, sd, buf); + atcommand_character_baselevel(s, sd, buf); // Emote skill buf = STRPRINTF("1 1 %s", character); - atcommand_skill_learn(fd, sd, buf); + atcommand_skill_learn(s, sd, buf); // Trade skill buf = STRPRINTF("2 1 %s", character); - atcommand_skill_learn(fd, sd, buf); + atcommand_skill_learn(s, sd, buf); // Party skill STRPRINTF("2 2 %s", character); - atcommand_skill_learn(fd, sd, buf); + atcommand_skill_learn(s, sd, buf); STRPRINTF("018-1.gat 24 98 %s", character); - atcommand_charwarp(fd, sd, buf); + atcommand_charwarp(s, sd, buf); return ATCE::OKAY; } //static -ATCE atcommand_charwarp(const int fd, dumb_ptr sd, +ATCE atcommand_charwarp(Session *s, dumb_ptr sd, ZString message) { MapName map_name; @@ -495,43 +495,43 @@ ATCE atcommand_charwarp(const int fd, dumb_ptr sd, if (m != nullptr && m->flag.nowarpto && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { - clif_displaymessage(fd, + clif_displaymessage(s, "You are not authorised to warp someone to this map."); return ATCE::PERM; } if (pl_sd->bl_m && pl_sd->bl_m->flag.nowarp && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { - clif_displaymessage(fd, + clif_displaymessage(s, "You are not authorised to warp this player from its actual map."); return ATCE::PERM; } if (pc_setpos(pl_sd, map_name, x, y, BeingRemoveWhy::WARPED) == 0) { - clif_displaymessage(pl_sd->fd, "Warped."); - clif_displaymessage(fd, "Player warped (message sends to player too)."); + clif_displaymessage(pl_sd->sess, "Warped."); + clif_displaymessage(s, "Player warped (message sends to player too)."); } else { - clif_displaymessage(fd, "Map not found."); + clif_displaymessage(s, "Map not found."); return ATCE::EXIST; } } else { - clif_displaymessage(fd, "Coordinates out of range."); + clif_displaymessage(s, "Coordinates out of range."); return ATCE::RANGE; } } else { - clif_displaymessage(fd, "Your GM level don't authorise you to do this action on this player."); + clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."); return ATCE::PERM; } } else { - clif_displaymessage(fd, "Character not found."); + clif_displaymessage(s, "Character not found."); return ATCE::EXIST; } @@ -539,7 +539,7 @@ ATCE atcommand_charwarp(const int fd, dumb_ptr sd, } static -ATCE atcommand_warp(const int fd, dumb_ptr sd, +ATCE atcommand_warp(Session *s, dumb_ptr sd, ZString message) { MapName map_name; @@ -548,7 +548,7 @@ ATCE atcommand_warp(const int fd, dumb_ptr sd, if (!message || !extract(message, record<' ', 1>(&map_name, &x, &y))) { - clif_displaymessage(fd, + clif_displaymessage(s, "Please, enter a map (usage: @warp )."); return ATCE::USAGE; } @@ -564,28 +564,28 @@ ATCE atcommand_warp(const int fd, dumb_ptr sd, if (m != nullptr && m->flag.nowarpto && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { - clif_displaymessage(fd, + clif_displaymessage(s, "You are not authorised to warp you to this map."); return ATCE::PERM; } if (sd->bl_m && sd->bl_m->flag.nowarp && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { - clif_displaymessage(fd, + clif_displaymessage(s, "You are not authorised to warp you from your actual map."); return ATCE::PERM; } if (pc_setpos(sd, map_name, x, y, BeingRemoveWhy::WARPED) == 0) - clif_displaymessage(fd, "Warped."); + clif_displaymessage(s, "Warped."); else { - clif_displaymessage(fd, "Map not found."); + clif_displaymessage(s, "Map not found."); return ATCE::EXIST; } } else { - clif_displaymessage(fd, "Coordinates out of range."); + clif_displaymessage(s, "Coordinates out of range."); return ATCE::RANGE; } @@ -593,7 +593,7 @@ ATCE atcommand_warp(const int fd, dumb_ptr sd, } static -ATCE atcommand_where(const int fd, dumb_ptr sd, +ATCE atcommand_where(Session *s, dumb_ptr sd, ZString message) { CharName character; @@ -609,11 +609,11 @@ ATCE atcommand_where(const int fd, dumb_ptr sd, FString output = STRPRINTF("%s: %s (%d,%d)", pl_sd->status.name, pl_sd->mapname_, pl_sd->bl_x, pl_sd->bl_y); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); } else { - clif_displaymessage(fd, "Character not found."); + clif_displaymessage(s, "Character not found."); return ATCE::EXIST; } @@ -621,14 +621,14 @@ ATCE atcommand_where(const int fd, dumb_ptr sd, } static -ATCE atcommand_goto(const int fd, dumb_ptr sd, +ATCE atcommand_goto(Session *s, dumb_ptr sd, ZString message) { CharName character; if (!asplit(message, &character)) { - clif_displaymessage(fd, + clif_displaymessage(s, "Please, enter a player name (usage: @jumpto/@warpto/@goto )."); return ATCE::USAGE; } @@ -639,24 +639,24 @@ ATCE atcommand_goto(const int fd, dumb_ptr sd, if (pl_sd->bl_m && pl_sd->bl_m->flag.nowarpto && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { - clif_displaymessage(fd, + clif_displaymessage(s, "You are not authorised to warp you to the map of this player."); return ATCE::PERM; } if (sd->bl_m && sd->bl_m->flag.nowarp && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { - clif_displaymessage(fd, + clif_displaymessage(s, "You are not authorised to warp you from your actual map."); return ATCE::PERM; } pc_setpos(sd, pl_sd->mapname_, pl_sd->bl_x, pl_sd->bl_y, BeingRemoveWhy::WARPED); FString output = STRPRINTF("Jump to %s", character); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); } else { - clif_displaymessage(fd, "Character not found."); + clif_displaymessage(s, "Character not found."); return ATCE::EXIST; } @@ -664,7 +664,7 @@ ATCE atcommand_goto(const int fd, dumb_ptr sd, } static -ATCE atcommand_jump(const int fd, dumb_ptr sd, +ATCE atcommand_jump(Session *s, dumb_ptr sd, ZString message) { int x = 0, y = 0; @@ -680,24 +680,24 @@ ATCE atcommand_jump(const int fd, dumb_ptr sd, if (sd->bl_m && sd->bl_m->flag.nowarpto && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { - clif_displaymessage(fd, + clif_displaymessage(s, "You are not authorised to warp you to your actual map."); return ATCE::PERM; } if (sd->bl_m && sd->bl_m->flag.nowarp && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { - clif_displaymessage(fd, + clif_displaymessage(s, "You are not authorised to warp you from your actual map."); return ATCE::PERM; } pc_setpos(sd, sd->mapname_, x, y, BeingRemoveWhy::WARPED); FString output = STRPRINTF("Jump to %d %d", x, y); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); } else { - clif_displaymessage(fd, "Coordinates out of range."); + clif_displaymessage(s, "Coordinates out of range."); return ATCE::RANGE; } @@ -705,7 +705,7 @@ ATCE atcommand_jump(const int fd, dumb_ptr sd, } static -ATCE atcommand_who(const int fd, dumb_ptr sd, +ATCE atcommand_who(Session *s, dumb_ptr sd, ZString message) { int count; @@ -717,9 +717,10 @@ ATCE atcommand_who(const int fd, dumb_ptr sd, GM_level = pc_isGM(sd); for (int i = 0; i < fd_max; i++) { - if (!session[i]) + Session *s2 = session[i].get(); + if (!s2) continue; - dumb_ptr pl_sd = dumb_ptr(static_cast(session[i]->session_data.get())); + dumb_ptr pl_sd = dumb_ptr(static_cast(s2->session_data.get())); if (pl_sd && pl_sd->state.auth) { pl_GM_level = pc_isGM(pl_sd); @@ -744,7 +745,7 @@ ATCE atcommand_who(const int fd, dumb_ptr sd, "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); + clif_displaymessage(s, output); count++; } } @@ -752,20 +753,20 @@ ATCE atcommand_who(const int fd, dumb_ptr sd, } if (count == 0) - clif_displaymessage(fd, "No player found."); + clif_displaymessage(s, "No player found."); else if (count == 1) - clif_displaymessage(fd, "1 player found."); + clif_displaymessage(s, "1 player found."); else { FString output = STRPRINTF("%d players found.", count); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); } return ATCE::OKAY; } static -ATCE atcommand_whogroup(const int fd, dumb_ptr sd, +ATCE atcommand_whogroup(Session *s, dumb_ptr sd, ZString message) { int count; @@ -779,9 +780,10 @@ ATCE atcommand_whogroup(const int fd, dumb_ptr sd, GM_level = pc_isGM(sd); for (int i = 0; i < fd_max; i++) { - if (!session[i]) + Session *s2 = session[i].get(); + if (!s2) continue; - dumb_ptr pl_sd = dumb_ptr(static_cast(session[i]->session_data.get())); + dumb_ptr pl_sd = dumb_ptr(static_cast(s2->session_data.get())); if (pl_sd && pl_sd->state.auth) { pl_GM_level = pc_isGM(pl_sd); @@ -802,7 +804,7 @@ ATCE atcommand_whogroup(const int fd, dumb_ptr sd, output = STRPRINTF( "Name: %s (GM:%d) | Party: '%s'", pl_sd->status.name, pl_GM_level, temp0); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); count++; } } @@ -810,20 +812,20 @@ ATCE atcommand_whogroup(const int fd, dumb_ptr sd, } if (count == 0) - clif_displaymessage(fd, "No player found."); + clif_displaymessage(s, "No player found."); else if (count == 1) - clif_displaymessage(fd, "1 player found."); + clif_displaymessage(s, "1 player found."); else { FString output = STRPRINTF("%d players found.", count); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); } return ATCE::OKAY; } static -ATCE atcommand_whomap(const int fd, dumb_ptr sd, +ATCE atcommand_whomap(Session *s, dumb_ptr sd, ZString message) { int count; @@ -842,9 +844,10 @@ ATCE atcommand_whomap(const int fd, dumb_ptr sd, GM_level = pc_isGM(sd); for (int i = 0; i < fd_max; i++) { - if (!session[i]) + Session *s2 = session[i].get(); + if (!s2) continue; - dumb_ptr pl_sd = dumb_ptr(static_cast(session[i]->session_data.get())); + dumb_ptr pl_sd = dumb_ptr(static_cast(s2->session_data.get())); if (pl_sd && pl_sd->state.auth) { pl_GM_level = pc_isGM(pl_sd); @@ -867,7 +870,7 @@ ATCE atcommand_whomap(const int fd, dumb_ptr sd, "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); + clif_displaymessage(s, output); count++; } } @@ -876,13 +879,13 @@ ATCE atcommand_whomap(const int fd, dumb_ptr sd, FString output = STRPRINTF("%d players found in map '%s'.", count, map_id->name_); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); return ATCE::OKAY; } static -ATCE atcommand_whomapgroup(const int fd, dumb_ptr sd, +ATCE atcommand_whomapgroup(Session *s, dumb_ptr sd, ZString message) { int count; @@ -902,9 +905,10 @@ ATCE atcommand_whomapgroup(const int fd, dumb_ptr sd, GM_level = pc_isGM(sd); for (int i = 0; i < fd_max; i++) { - if (!session[i]) + Session *s2 = session[i].get(); + if (!s2) continue; - dumb_ptr pl_sd = dumb_ptr(static_cast(session[i]->session_data.get())); + dumb_ptr pl_sd = dumb_ptr(static_cast(s2->session_data.get())); if (pl_sd && pl_sd->state.auth) { pl_GM_level = pc_isGM(pl_sd); @@ -925,7 +929,7 @@ ATCE atcommand_whomapgroup(const int fd, dumb_ptr sd, else output = STRPRINTF("Name: %s | Party: '%s'", pl_sd->status.name, temp0); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); count++; } } @@ -941,13 +945,13 @@ ATCE atcommand_whomapgroup(const int fd, dumb_ptr sd, { output = STRPRINTF("%d players found in map '%s'.", count, map_id->name_); } - clif_displaymessage(fd, output); + clif_displaymessage(s, output); return ATCE::OKAY; } static -ATCE atcommand_whogm(const int fd, dumb_ptr sd, +ATCE atcommand_whogm(Session *s, dumb_ptr sd, ZString message) { int count; @@ -961,9 +965,10 @@ ATCE atcommand_whogm(const int fd, dumb_ptr sd, GM_level = pc_isGM(sd); for (int i = 0; i < fd_max; i++) { - if (!session[i]) + Session *s2 = session[i].get(); + if (!s2) continue; - dumb_ptr pl_sd = dumb_ptr(static_cast(session[i]->session_data.get())); + dumb_ptr pl_sd = dumb_ptr(static_cast(s2->session_data.get())); if (pl_sd && pl_sd->state.auth) { pl_GM_level = pc_isGM(pl_sd); @@ -984,19 +989,19 @@ ATCE atcommand_whogm(const int fd, dumb_ptr sd, "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); + clif_displaymessage(s, output); output = STRPRINTF( " BLvl: %d | Job: %s (Lvl: %d)", pl_sd->status.base_level, "Novice/Human", pl_sd->status.job_level); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); p = party_search(pl_sd->status.party_id); PartyName temp0 = p ? p->name : stringish("None"); output = STRPRINTF( " Party: '%s'", temp0); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); count++; } } @@ -1005,59 +1010,59 @@ ATCE atcommand_whogm(const int fd, dumb_ptr sd, } if (count == 0) - clif_displaymessage(fd, "No GM found."); + clif_displaymessage(s, "No GM found."); else if (count == 1) - clif_displaymessage(fd, "1 GM found."); + clif_displaymessage(s, "1 GM found."); else { FString output = STRPRINTF("%d GMs found.", count); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); } return ATCE::OKAY; } static -ATCE atcommand_save(const int fd, dumb_ptr sd, +ATCE atcommand_save(Session *s, dumb_ptr sd, ZString) { pc_setsavepoint(sd, sd->mapname_, sd->bl_x, sd->bl_y); pc_makesavestatus(sd); chrif_save(sd); - clif_displaymessage(fd, "Character data respawn point saved."); + clif_displaymessage(s, "Character data respawn point saved."); return ATCE::OKAY; } static -ATCE atcommand_load(const int fd, dumb_ptr sd, +ATCE atcommand_load(Session *s, dumb_ptr sd, ZString) { 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, + clif_displaymessage(s, "You are not authorised to warp you to your save map."); return ATCE::PERM; } if (sd->bl_m && sd->bl_m->flag.nowarp && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { - clif_displaymessage(fd, + clif_displaymessage(s, "You are not authorised to warp you from your actual map."); return ATCE::PERM; } pc_setpos(sd, sd->status.save_point.map_, sd->status.save_point.x, sd->status.save_point.y, BeingRemoveWhy::GONE); - clif_displaymessage(fd, "Warping to respawn point."); + clif_displaymessage(s, "Warping to respawn point."); return ATCE::OKAY; } static -ATCE atcommand_speed(const int fd, dumb_ptr sd, +ATCE atcommand_speed(Session *s, dumb_ptr sd, ZString message) { if (!message) @@ -1066,7 +1071,7 @@ ATCE atcommand_speed(const int fd, dumb_ptr sd, "Please, enter a speed value (usage: @speed <%d-%d>).", static_cast(MIN_WALK_SPEED.count()), static_cast(MAX_WALK_SPEED.count())); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); return ATCE::USAGE; } @@ -1077,7 +1082,7 @@ ATCE atcommand_speed(const int fd, dumb_ptr sd, //sd->walktimer = x; //この文を追加 by れ clif_updatestatus(sd, SP::SPEED); - clif_displaymessage(fd, "Speed changed."); + clif_displaymessage(s, "Speed changed."); } else { @@ -1085,7 +1090,7 @@ ATCE atcommand_speed(const int fd, dumb_ptr sd, "Please, enter a valid speed value (usage: @speed <%d-%d>).", static_cast(MIN_WALK_SPEED.count()), static_cast(MAX_WALK_SPEED.count())); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); return ATCE::RANGE; } @@ -1093,21 +1098,21 @@ ATCE atcommand_speed(const int fd, dumb_ptr sd, } static -ATCE atcommand_storage(const int fd, dumb_ptr sd, +ATCE atcommand_storage(Session *s, dumb_ptr sd, ZString) { struct storage *stor; if (sd->state.storage_open) { - clif_displaymessage(fd, "msg_table[250]"); + clif_displaymessage(s, "msg_table[250]"); return ATCE::EXIST; } if ((stor = account2storage2(sd->status.account_id)) != NULL && stor->storage_status == 1) { - clif_displaymessage(fd, "msg_table[250]"); + clif_displaymessage(s, "msg_table[250]"); return ATCE::EXIST; } @@ -1117,7 +1122,7 @@ ATCE atcommand_storage(const int fd, dumb_ptr sd, } static -ATCE atcommand_option(const int fd, dumb_ptr sd, +ATCE atcommand_option(Session *s, dumb_ptr sd, ZString message) { Opt1 param1 = Opt1::ZERO; @@ -1133,24 +1138,24 @@ ATCE atcommand_option(const int fd, dumb_ptr sd, clif_changeoption(sd); pc_calcstatus(sd, 0); - clif_displaymessage(fd, "Options changed."); + clif_displaymessage(s, "Options changed."); return ATCE::OKAY; } static -ATCE atcommand_hide(const int fd, dumb_ptr sd, +ATCE atcommand_hide(Session *s, dumb_ptr sd, ZString) { if (bool(sd->status.option & Option::HIDE)) { sd->status.option &= ~Option::HIDE; - clif_displaymessage(fd, "Invisible: Off."); + clif_displaymessage(s, "Invisible: Off."); } else { sd->status.option |= Option::HIDE; - clif_displaymessage(fd, "Invisible: On."); + clif_displaymessage(s, "Invisible: On."); } clif_changeoption(sd); @@ -1158,17 +1163,17 @@ ATCE atcommand_hide(const int fd, dumb_ptr sd, } static -ATCE atcommand_die(const int fd, dumb_ptr sd, +ATCE atcommand_die(Session *s, dumb_ptr sd, ZString) { pc_damage(NULL, sd, sd->status.hp + 1); - clif_displaymessage(fd, "A pity! You've died."); + clif_displaymessage(s, "A pity! You've died."); return ATCE::OKAY; } static -ATCE atcommand_kill(const int fd, dumb_ptr sd, +ATCE atcommand_kill(Session *s, dumb_ptr sd, ZString message) { CharName character; @@ -1183,17 +1188,17 @@ ATCE atcommand_kill(const int fd, dumb_ptr sd, { // you can kill only lower or same level pc_damage(NULL, pl_sd, pl_sd->status.hp + 1); - clif_displaymessage(fd, "Character killed."); + clif_displaymessage(s, "Character killed."); } else { - clif_displaymessage(fd, "Your GM level don't authorise you to do this action on this player."); + clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."); return ATCE::PERM; } } else { - clif_displaymessage(fd, "Character not found."); + clif_displaymessage(s, "Character not found."); return ATCE::EXIST; } @@ -1201,7 +1206,7 @@ ATCE atcommand_kill(const int fd, dumb_ptr sd, } static -ATCE atcommand_alive(const int fd, dumb_ptr sd, +ATCE atcommand_alive(Session *s, dumb_ptr sd, ZString) { sd->status.hp = sd->status.max_hp; @@ -1212,13 +1217,13 @@ ATCE atcommand_alive(const int fd, dumb_ptr sd, clif_updatestatus(sd, SP::HP); clif_updatestatus(sd, SP::SP); clif_resurrection(sd, 1); - clif_displaymessage(fd, "You've been revived! It's a miracle!"); + clif_displaymessage(s, "You've been revived! It's a miracle!"); return ATCE::OKAY; } static -ATCE atcommand_kami(const int, dumb_ptr, +ATCE atcommand_kami(Session *, dumb_ptr, ZString message) { if (!message) @@ -1230,7 +1235,7 @@ ATCE atcommand_kami(const int, dumb_ptr, } static -ATCE atcommand_heal(const int fd, dumb_ptr sd, +ATCE atcommand_heal(Session *s, dumb_ptr sd, ZString message) { int hp = 0, sp = 0; @@ -1266,13 +1271,13 @@ ATCE atcommand_heal(const int fd, dumb_ptr sd, { pc_heal(sd, hp, sp); if (hp >= 0 && sp >= 0) - clif_displaymessage(fd, "HP, SP recovered."); + clif_displaymessage(s, "HP, SP recovered."); else - clif_displaymessage(fd, "HP or/and SP modified."); + clif_displaymessage(s, "HP or/and SP modified."); } else { - clif_displaymessage(fd, "HP and SP are already with the good value."); + clif_displaymessage(s, "HP and SP are already with the good value."); return ATCE::RANGE; } @@ -1280,7 +1285,7 @@ ATCE atcommand_heal(const int fd, dumb_ptr sd, } static -ATCE atcommand_item(const int fd, dumb_ptr sd, +ATCE atcommand_item(Session *s, dumb_ptr sd, ZString message) { ItemName item_name; @@ -1290,7 +1295,7 @@ ATCE atcommand_item(const int fd, dumb_ptr sd, if (!extract(message, record<' ', 1>(&item_name, &number))) { - clif_displaymessage(fd, + clif_displaymessage(s, "Please, enter an item name/id (usage: @item [quantity])."); return ATCE::USAGE; } @@ -1323,11 +1328,11 @@ ATCE atcommand_item(const int fd, dumb_ptr sd, != PickupFail::OKAY) clif_additem(sd, 0, 0, flag); } - clif_displaymessage(fd, "Item created."); + clif_displaymessage(s, "Item created."); } else { - clif_displaymessage(fd, "Invalid item ID or name."); + clif_displaymessage(s, "Invalid item ID or name."); return ATCE::EXIST; } @@ -1335,7 +1340,7 @@ ATCE atcommand_item(const int fd, dumb_ptr sd, } static -ATCE atcommand_itemreset(const int fd, dumb_ptr sd, +ATCE atcommand_itemreset(Session *s, dumb_ptr sd, ZString) { int i; @@ -1346,13 +1351,13 @@ ATCE atcommand_itemreset(const int fd, dumb_ptr sd, && sd->status.inventory[i].equip == EPOS::ZERO) pc_delitem(sd, i, sd->status.inventory[i].amount, 0); } - clif_displaymessage(fd, "All of your items have been removed."); + clif_displaymessage(s, "All of your items have been removed."); return ATCE::OKAY; } static -ATCE atcommand_itemcheck(const int, dumb_ptr sd, +ATCE atcommand_itemcheck(Session *, dumb_ptr sd, ZString) { pc_checkitem(sd); @@ -1361,14 +1366,14 @@ ATCE atcommand_itemcheck(const int, dumb_ptr sd, } static -ATCE atcommand_baselevelup(const int fd, dumb_ptr sd, +ATCE atcommand_baselevelup(Session *s, dumb_ptr sd, ZString message) { int level, i; if (!extract(message, &level) || !level) { - clif_displaymessage(fd, + clif_displaymessage(s, "Please, enter a level adjustement (usage: @blvl )."); return ATCE::USAGE; } @@ -1377,7 +1382,7 @@ ATCE atcommand_baselevelup(const int fd, dumb_ptr sd, { if (sd->status.base_level == battle_config.maximum_level) { - clif_displaymessage(fd, "Base level can't go any higher."); + clif_displaymessage(s, "Base level can't go any higher."); return ATCE::RANGE; } if (level > battle_config.maximum_level || level > (battle_config.maximum_level - sd->status.base_level)) @@ -1392,13 +1397,13 @@ ATCE atcommand_baselevelup(const int fd, dumb_ptr sd, pc_calcstatus(sd, 0); pc_heal(sd, sd->status.max_hp, sd->status.max_sp); clif_misceffect(sd, 0); - clif_displaymessage(fd, "Base level raised."); + clif_displaymessage(s, "Base level raised."); } else { if (sd->status.base_level == 1) { - clif_displaymessage(fd, "Base level can't go any lower."); + clif_displaymessage(s, "Base level can't go any lower."); return ATCE::USAGE; } if (level < -battle_config.maximum_level || level < (1 - sd->status.base_level)) @@ -1418,7 +1423,7 @@ ATCE atcommand_baselevelup(const int fd, dumb_ptr sd, clif_updatestatus(sd, SP::BASELEVEL); clif_updatestatus(sd, SP::NEXTBASEEXP); pc_calcstatus(sd, 0); - clif_displaymessage(fd, "Base level lowered."); + clif_displaymessage(s, "Base level lowered."); } return ATCE::OKAY; @@ -1427,7 +1432,7 @@ ATCE atcommand_baselevelup(const int fd, dumb_ptr sd, // TODO: merge this with pc_setparam(SP::JOBLEVEL) // then fix the funny 50 and/or 10 limitation. static -ATCE atcommand_joblevelup(const int fd, dumb_ptr sd, +ATCE atcommand_joblevelup(Session *s, dumb_ptr sd, ZString message) { int up_level = 50, level; @@ -1441,7 +1446,7 @@ ATCE atcommand_joblevelup(const int fd, dumb_ptr sd, { if (sd->status.job_level == up_level) { - clif_displaymessage(fd, "Job level can't go any higher."); + clif_displaymessage(s, "Job level can't go any higher."); return ATCE::RANGE; } if (level > up_level || level > (up_level - sd->status.job_level)) @@ -1454,13 +1459,13 @@ ATCE atcommand_joblevelup(const int fd, dumb_ptr sd, clif_updatestatus(sd, SP::SKILLPOINT); pc_calcstatus(sd, 0); clif_misceffect(sd, 1); - clif_displaymessage(fd, "Job level raised."); + clif_displaymessage(s, "Job level raised."); } else { if (sd->status.job_level == 1) { - clif_displaymessage(fd, "Job level can't go any lower."); + clif_displaymessage(s, "Job level can't go any lower."); return ATCE::RANGE; } if (level < -up_level || level < (1 - sd->status.job_level)) @@ -1478,14 +1483,14 @@ ATCE atcommand_joblevelup(const int fd, dumb_ptr sd, } // to add: remove status points from skills pc_calcstatus(sd, 0); - clif_displaymessage(fd, "Job level lowered."); + clif_displaymessage(s, "Job level lowered."); } return ATCE::OKAY; } static -ATCE atcommand_gm(const int fd, dumb_ptr sd, +ATCE atcommand_gm(Session *s, dumb_ptr sd, ZString message) { if (!message) @@ -1494,7 +1499,7 @@ ATCE atcommand_gm(const int fd, dumb_ptr sd, if (pc_isGM(sd)) { // a GM can not use this function. only a normal player (become gm is not for gm!) - clif_displaymessage(fd, "You already have some GM powers."); + clif_displaymessage(s, "You already have some GM powers."); return ATCE::PERM; } else @@ -1504,13 +1509,13 @@ ATCE atcommand_gm(const int fd, dumb_ptr sd, } static -ATCE atcommand_pvpoff(const int fd, dumb_ptr sd, +ATCE atcommand_pvpoff(Session *s, dumb_ptr sd, ZString) { if (battle_config.pk_mode) { //disable command if server is in PK mode [Valaris] - clif_displaymessage(fd, "This option cannot be used in PK Mode."); + clif_displaymessage(s, "This option cannot be used in PK Mode."); return ATCE::EXIST; } @@ -1519,9 +1524,10 @@ ATCE atcommand_pvpoff(const int fd, dumb_ptr sd, sd->bl_m->flag.pvp = 0; for (int i = 0; i < fd_max; i++) { - if (!session[i]) + Session *s2 = session[i].get(); + if (!s2) continue; - dumb_ptr pl_sd = dumb_ptr(static_cast(session[i]->session_data.get())); + dumb_ptr pl_sd = dumb_ptr(static_cast(s2->session_data.get())); if (pl_sd && pl_sd->state.auth) { if (sd->bl_m == pl_sd->bl_m) @@ -1530,11 +1536,11 @@ ATCE atcommand_pvpoff(const int fd, dumb_ptr sd, } } } - clif_displaymessage(fd, "PvP: Off."); + clif_displaymessage(s, "PvP: Off."); } else { - clif_displaymessage(fd, "PvP is already Off."); + clif_displaymessage(s, "PvP is already Off."); return ATCE::EXIST; } @@ -1542,13 +1548,13 @@ ATCE atcommand_pvpoff(const int fd, dumb_ptr sd, } static -ATCE atcommand_pvpon(const int fd, dumb_ptr sd, +ATCE atcommand_pvpon(Session *s, dumb_ptr sd, ZString) { if (battle_config.pk_mode) { //disable command if server is in PK mode [Valaris] - clif_displaymessage(fd, "This option cannot be used in PK Mode."); + clif_displaymessage(s, "This option cannot be used in PK Mode."); return ATCE::EXIST; } @@ -1557,9 +1563,10 @@ ATCE atcommand_pvpon(const int fd, dumb_ptr sd, sd->bl_m->flag.pvp = 1; for (int i = 0; i < fd_max; i++) { - if (!session[i]) + Session *s2 = session[i].get(); + if (!s2) continue; - dumb_ptr pl_sd = dumb_ptr(static_cast(session[i]->session_data.get())); + dumb_ptr pl_sd = dumb_ptr(static_cast(s2->session_data.get())); if (pl_sd && pl_sd->state.auth) { if (sd->bl_m == pl_sd->bl_m && !pl_sd->pvp_timer) @@ -1572,11 +1579,11 @@ ATCE atcommand_pvpon(const int fd, dumb_ptr sd, } } } - clif_displaymessage(fd, "PvP: On."); + clif_displaymessage(s, "PvP: On."); } else { - clif_displaymessage(fd, "PvP is already On."); + clif_displaymessage(s, "PvP is already On."); return ATCE::EXIST; } @@ -1584,7 +1591,7 @@ ATCE atcommand_pvpon(const int fd, dumb_ptr sd, } static -ATCE atcommand_model(const int fd, dumb_ptr sd, +ATCE atcommand_model(Session *s, dumb_ptr sd, ZString message) { int hair_style = 0, hair_color = 0, cloth_color = 0; @@ -1600,7 +1607,7 @@ ATCE atcommand_model(const int fd, dumb_ptr sd, pc_changelook(sd, LOOK::HAIR, hair_style); pc_changelook(sd, LOOK::HAIR_COLOR, hair_color); pc_changelook(sd, LOOK::CLOTHES_COLOR, cloth_color); - clif_displaymessage(fd, "Appearence changed."); + clif_displaymessage(s, "Appearence changed."); } } else @@ -1610,7 +1617,7 @@ ATCE atcommand_model(const int fd, dumb_ptr sd, } static -ATCE atcommand_dye(const int fd, dumb_ptr sd, +ATCE atcommand_dye(Session *s, dumb_ptr sd, ZString message) { int cloth_color = 0; @@ -1622,7 +1629,7 @@ ATCE atcommand_dye(const int fd, dumb_ptr sd, { { pc_changelook(sd, LOOK::CLOTHES_COLOR, cloth_color); - clif_displaymessage(fd, "Appearence changed."); + clif_displaymessage(s, "Appearence changed."); } } else @@ -1632,7 +1639,7 @@ ATCE atcommand_dye(const int fd, dumb_ptr sd, } static -ATCE atcommand_hair_style(const int fd, dumb_ptr sd, +ATCE atcommand_hair_style(Session *s, dumb_ptr sd, ZString message) { int hair_style = 0; @@ -1644,7 +1651,7 @@ ATCE atcommand_hair_style(const int fd, dumb_ptr sd, { { pc_changelook(sd, LOOK::HAIR, hair_style); - clif_displaymessage(fd, "Appearence changed."); + clif_displaymessage(s, "Appearence changed."); } } else @@ -1654,7 +1661,7 @@ ATCE atcommand_hair_style(const int fd, dumb_ptr sd, } static -ATCE atcommand_hair_color(const int fd, dumb_ptr sd, +ATCE atcommand_hair_color(Session *s, dumb_ptr sd, ZString message) { int hair_color = 0; @@ -1666,7 +1673,7 @@ ATCE atcommand_hair_color(const int fd, dumb_ptr sd, { { pc_changelook(sd, LOOK::HAIR_COLOR, hair_color); - clif_displaymessage(fd, "Appearence changed."); + clif_displaymessage(s, "Appearence changed."); } } else @@ -1676,7 +1683,7 @@ ATCE atcommand_hair_color(const int fd, dumb_ptr sd, } static -ATCE atcommand_spawn(const int fd, dumb_ptr sd, +ATCE atcommand_spawn(Session *s, dumb_ptr sd, ZString message) { MobName monster; @@ -1736,16 +1743,16 @@ ATCE atcommand_spawn(const int fd, dumb_ptr sd, if (count != 0) if (number == count) - clif_displaymessage(fd, "All monster summoned!"); + clif_displaymessage(s, "All monster summoned!"); else { FString output = STRPRINTF("%d monster(s) summoned!", count); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); } else { - clif_displaymessage(fd, "Invalid monster ID or name."); + clif_displaymessage(s, "Invalid monster ID or name."); return ATCE::EXIST; } @@ -1753,7 +1760,7 @@ ATCE atcommand_spawn(const int fd, dumb_ptr sd, } static -void atcommand_killmonster_sub(const int fd, dumb_ptr sd, +void atcommand_killmonster_sub(Session *s, dumb_ptr sd, ZString message, const int drop) { map_local *map_id; @@ -1771,34 +1778,34 @@ void atcommand_killmonster_sub(const int fd, dumb_ptr sd, map_id->xs, map_id->ys, BL::MOB); - clif_displaymessage(fd, "All monsters killed!"); + clif_displaymessage(s, "All monsters killed!"); } static -ATCE atcommand_killmonster(const int fd, dumb_ptr sd, +ATCE atcommand_killmonster(Session *s, dumb_ptr sd, ZString message) { - atcommand_killmonster_sub(fd, sd, message, 1); + atcommand_killmonster_sub(s, sd, message, 1); return ATCE::OKAY; } static -void atlist_nearby_sub(dumb_ptr bl, int fd) +void atlist_nearby_sub(dumb_ptr bl, Session *s) { nullpo_retv(bl); FString buf = STRPRINTF(" - \"%s\"", bl->is_player()->status.name); - clif_displaymessage(fd, buf); + clif_displaymessage(s, buf); } static -ATCE atcommand_list_nearby(const int fd, dumb_ptr sd, +ATCE atcommand_list_nearby(Session *s, dumb_ptr sd, ZString) { - clif_displaymessage(fd, "Nearby players:"); - map_foreachinarea(std::bind(atlist_nearby_sub, ph::_1, fd), + clif_displaymessage(s, "Nearby players:"); + map_foreachinarea(std::bind(atlist_nearby_sub, ph::_1, s), sd->bl_m, sd->bl_x - 1, sd->bl_y - 1, sd->bl_x + 1, sd->bl_x + 1, @@ -1808,16 +1815,16 @@ ATCE atcommand_list_nearby(const int fd, dumb_ptr sd, } static -ATCE atcommand_killmonster2(const int fd, dumb_ptr sd, +ATCE atcommand_killmonster2(Session *s, dumb_ptr sd, ZString message) { - atcommand_killmonster_sub(fd, sd, message, 0); + atcommand_killmonster_sub(s, sd, message, 0); return ATCE::OKAY; } static -ATCE atcommand_gat(const int fd, dumb_ptr sd, +ATCE atcommand_gat(Session *s, dumb_ptr sd, ZString) { int y; @@ -1832,14 +1839,14 @@ ATCE atcommand_gat(const int fd, dumb_ptr sd, 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); + clif_displaymessage(s, output); } return ATCE::OKAY; } static -ATCE atcommand_packet(const int, dumb_ptr sd, +ATCE atcommand_packet(Session *, dumb_ptr sd, ZString message) { StatusChange type {}; @@ -1854,7 +1861,7 @@ ATCE atcommand_packet(const int, dumb_ptr sd, } static -ATCE atcommand_statuspoint(const int fd, dumb_ptr sd, +ATCE atcommand_statuspoint(Session *s, dumb_ptr sd, ZString message) { int point, new_status_point; @@ -1874,7 +1881,7 @@ ATCE atcommand_statuspoint(const int fd, dumb_ptr sd, { sd->status.status_point = new_status_point; clif_updatestatus(sd, SP::STATUSPOINT); - clif_displaymessage(fd, "Number of status points changed!"); + clif_displaymessage(s, "Number of status points changed!"); } else return ATCE::RANGE; @@ -1883,7 +1890,7 @@ ATCE atcommand_statuspoint(const int fd, dumb_ptr sd, } static -ATCE atcommand_skillpoint(const int fd, dumb_ptr sd, +ATCE atcommand_skillpoint(Session *s, dumb_ptr sd, ZString message) { int point, new_skill_point; @@ -1903,7 +1910,7 @@ ATCE atcommand_skillpoint(const int fd, dumb_ptr sd, { sd->status.skill_point = new_skill_point; clif_updatestatus(sd, SP::SKILLPOINT); - clif_displaymessage(fd, "Number of skill points changed!"); + clif_displaymessage(s, "Number of skill points changed!"); } else return ATCE::RANGE; @@ -1912,7 +1919,7 @@ ATCE atcommand_skillpoint(const int fd, dumb_ptr sd, } static -ATCE atcommand_zeny(const int fd, dumb_ptr sd, +ATCE atcommand_zeny(Session *s, dumb_ptr sd, ZString message) { int zeny, new_zeny; @@ -1932,7 +1939,7 @@ ATCE atcommand_zeny(const int fd, dumb_ptr sd, { sd->status.zeny = new_zeny; clif_updatestatus(sd, SP::ZENY); - clif_displaymessage(fd, "Number of zenys changed!"); + clif_displaymessage(s, "Number of zenys changed!"); } else return ATCE::RANGE; @@ -1941,7 +1948,7 @@ ATCE atcommand_zeny(const int fd, dumb_ptr sd, } template -ATCE atcommand_param(const int fd, dumb_ptr sd, +ATCE atcommand_param(Session *s, dumb_ptr sd, ZString message) { int value = 0, new_value; @@ -1964,7 +1971,7 @@ ATCE atcommand_param(const int fd, dumb_ptr sd, clif_updatestatus(sd, attr_to_sp(attr)); clif_updatestatus(sd, attr_to_usp(attr)); pc_calcstatus(sd, 0); - clif_displaymessage(fd, "Stat changed."); + clif_displaymessage(s, "Stat changed."); } else return ATCE::RANGE; @@ -1973,7 +1980,7 @@ ATCE atcommand_param(const int fd, dumb_ptr sd, } static -ATCE atcommand_all_stats(const int fd, dumb_ptr sd, +ATCE atcommand_all_stats(Session *s, dumb_ptr sd, ZString message) { int count, value = 0, new_value; @@ -2005,7 +2012,7 @@ ATCE atcommand_all_stats(const int fd, dumb_ptr sd, if (count > 0) // if at least 1 stat modified - clif_displaymessage(fd, "All stats changed!"); + clif_displaymessage(s, "All stats changed!"); else return ATCE::RANGE; @@ -2013,7 +2020,7 @@ ATCE atcommand_all_stats(const int fd, dumb_ptr sd, } static -ATCE atcommand_recall(const int fd, dumb_ptr sd, +ATCE atcommand_recall(Session *s, dumb_ptr sd, ZString message) { CharName character; @@ -2030,30 +2037,30 @@ ATCE atcommand_recall(const int fd, dumb_ptr sd, if (sd->bl_m && sd->bl_m->flag.nowarpto && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { - clif_displaymessage(fd, + clif_displaymessage(s, "You are not authorised to warp somenone to your actual map."); return ATCE::PERM; } if (pl_sd->bl_m && pl_sd->bl_m->flag.nowarp && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { - clif_displaymessage(fd, + clif_displaymessage(s, "You are not authorised to warp this player from its actual map."); return ATCE::PERM; } pc_setpos(pl_sd, sd->mapname_, sd->bl_x, sd->bl_y, BeingRemoveWhy::QUIT); FString output = STRPRINTF("%s recalled!", character); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); } else { - clif_displaymessage(fd, "Your GM level don't authorise you to do this action on this player."); + clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."); return ATCE::PERM; } } else { - clif_displaymessage(fd, "Character not found."); + clif_displaymessage(s, "Character not found."); return ATCE::EXIST; } @@ -2061,7 +2068,7 @@ ATCE atcommand_recall(const int fd, dumb_ptr sd, } static -ATCE atcommand_revive(const int fd, dumb_ptr sd, +ATCE atcommand_revive(Session *s, dumb_ptr sd, ZString message) { CharName character; @@ -2079,11 +2086,11 @@ ATCE atcommand_revive(const int fd, dumb_ptr sd, clif_updatestatus(pl_sd, SP::HP); clif_updatestatus(pl_sd, SP::SP); clif_resurrection(pl_sd, 1); - clif_displaymessage(fd, "Character revived."); + clif_displaymessage(s, "Character revived."); } else { - clif_displaymessage(fd, "Character not found."); + clif_displaymessage(s, "Character not found."); return ATCE::EXIST; } @@ -2091,7 +2098,7 @@ ATCE atcommand_revive(const int fd, dumb_ptr sd, } static -ATCE atcommand_character_stats(const int fd, dumb_ptr, +ATCE atcommand_character_stats(Session *s, dumb_ptr, ZString message) { CharName character; @@ -2104,37 +2111,37 @@ ATCE atcommand_character_stats(const int fd, dumb_ptr, { FString output; output = STRPRINTF("'%s' stats:", pl_sd->status.name); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); output = STRPRINTF("Base Level - %d", pl_sd->status.base_level), - clif_displaymessage(fd, output); + clif_displaymessage(s, output); output = STRPRINTF("Job - Novice/Human (level %d)", pl_sd->status.job_level); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); output = STRPRINTF("Hp - %d", pl_sd->status.hp); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); output = STRPRINTF("MaxHp - %d", pl_sd->status.max_hp); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); output = STRPRINTF("Sp - %d", pl_sd->status.sp); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); output = STRPRINTF("MaxSp - %d", pl_sd->status.max_sp); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); output = STRPRINTF("Str - %3d", pl_sd->status.attrs[ATTR::STR]); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); output = STRPRINTF("Agi - %3d", pl_sd->status.attrs[ATTR::AGI]); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); output = STRPRINTF("Vit - %3d", pl_sd->status.attrs[ATTR::VIT]); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); output = STRPRINTF("Int - %3d", pl_sd->status.attrs[ATTR::INT]); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); output = STRPRINTF("Dex - %3d", pl_sd->status.attrs[ATTR::DEX]); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); output = STRPRINTF("Luk - %3d", pl_sd->status.attrs[ATTR::LUK]); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); output = STRPRINTF("Zeny - %d", pl_sd->status.zeny); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); } else { - clif_displaymessage(fd, "Character not found."); + clif_displaymessage(s, "Character not found."); return ATCE::EXIST; } @@ -2142,7 +2149,7 @@ ATCE atcommand_character_stats(const int fd, dumb_ptr, } static -ATCE atcommand_character_stats_all(const int fd, dumb_ptr, +ATCE atcommand_character_stats_all(Session *s, dumb_ptr, ZString) { int count; @@ -2150,9 +2157,10 @@ ATCE atcommand_character_stats_all(const int fd, dumb_ptr, count = 0; for (int i = 0; i < fd_max; i++) { - if (!session[i]) + Session *s2 = session[i].get(); + if (!s2) continue; - dumb_ptr pl_sd = dumb_ptr(static_cast(session[i]->session_data.get())); + dumb_ptr pl_sd = dumb_ptr(static_cast(s2->session_data.get())); if (pl_sd && pl_sd->state.auth) { FString gmlevel; @@ -2168,7 +2176,7 @@ ATCE atcommand_character_stats_all(const int fd, dumb_ptr, 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); + clif_displaymessage(s, output); 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], @@ -2178,27 +2186,27 @@ ATCE atcommand_character_stats_all(const int fd, dumb_ptr, pl_sd->status.attrs[ATTR::LUK], pl_sd->status.zeny, gmlevel); - clif_displaymessage(fd, output); - clif_displaymessage(fd, "--------"); + clif_displaymessage(s, output); + clif_displaymessage(s, "--------"); count++; } } if (count == 0) - clif_displaymessage(fd, "No player found."); + clif_displaymessage(s, "No player found."); else if (count == 1) - clif_displaymessage(fd, "1 player found."); + clif_displaymessage(s, "1 player found."); else { FString output = STRPRINTF("%d players found.", count); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); } return ATCE::OKAY; } static -ATCE atcommand_character_option(const int fd, dumb_ptr sd, +ATCE atcommand_character_option(Session *s, dumb_ptr sd, ZString message) { Opt1 opt1; @@ -2220,17 +2228,17 @@ ATCE atcommand_character_option(const int fd, dumb_ptr sd, clif_changeoption(pl_sd); pc_calcstatus(pl_sd, 0); - clif_displaymessage(fd, "Character's options changed."); + clif_displaymessage(s, "Character's options changed."); } else { - clif_displaymessage(fd, "Your GM level don't authorise you to do this action on this player."); + clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."); return ATCE::PERM; } } else { - clif_displaymessage(fd, "Character not found."); + clif_displaymessage(s, "Character not found."); return ATCE::EXIST; } @@ -2238,7 +2246,7 @@ ATCE atcommand_character_option(const int fd, dumb_ptr sd, } static -ATCE atcommand_char_change_sex(const int fd, dumb_ptr sd, +ATCE atcommand_char_change_sex(Session *s, dumb_ptr sd, ZString message) { CharName character; @@ -2249,14 +2257,14 @@ ATCE atcommand_char_change_sex(const int fd, dumb_ptr sd, { chrif_char_ask_name(sd->status.account_id, character, 5, HumanTimeDiff()); // type: 5 - changesex - clif_displaymessage(fd, "Character name sends to char-server to ask it."); + clif_displaymessage(s, "Character name sends to char-server to ask it."); } return ATCE::OKAY; } static -ATCE atcommand_char_block(const int fd, dumb_ptr sd, +ATCE atcommand_char_block(Session *s, dumb_ptr sd, ZString message) { CharName character; @@ -2267,14 +2275,14 @@ ATCE atcommand_char_block(const int fd, dumb_ptr sd, { chrif_char_ask_name(sd->status.account_id, character, 1, HumanTimeDiff()); // type: 1 - block - clif_displaymessage(fd, "Character name sends to char-server to ask it."); + clif_displaymessage(s, "Character name sends to char-server to ask it."); } return ATCE::OKAY; } static -ATCE atcommand_char_ban(const int fd, dumb_ptr sd, +ATCE atcommand_char_ban(Session *s, dumb_ptr sd, ZString message) { HumanTimeDiff modif; @@ -2287,14 +2295,14 @@ ATCE atcommand_char_ban(const int fd, dumb_ptr sd, { chrif_char_ask_name(sd->status.account_id, character, 2, modif); // type: 2 - ban - clif_displaymessage(fd, "Character name sends to char-server to ask it."); + clif_displaymessage(s, "Character name sends to char-server to ask it."); } return ATCE::OKAY; } static -ATCE atcommand_char_unblock(const int fd, dumb_ptr sd, +ATCE atcommand_char_unblock(Session *s, dumb_ptr sd, ZString message) { CharName character; @@ -2306,14 +2314,14 @@ ATCE atcommand_char_unblock(const int fd, dumb_ptr sd, // send answer to login server via char-server chrif_char_ask_name(sd->status.account_id, character, 3, HumanTimeDiff()); // type: 3 - unblock - clif_displaymessage(fd, "Character name sends to char-server to ask it."); + clif_displaymessage(s, "Character name sends to char-server to ask it."); } return ATCE::OKAY; } static -ATCE atcommand_char_unban(const int fd, dumb_ptr sd, +ATCE atcommand_char_unban(Session *s, dumb_ptr sd, ZString message) { CharName character; @@ -2325,14 +2333,14 @@ ATCE atcommand_char_unban(const int fd, dumb_ptr sd, // send answer to login server via char-server chrif_char_ask_name(sd->status.account_id, character, 4, HumanTimeDiff()); // type: 4 - unban - clif_displaymessage(fd, "Character name sends to char-server to ask it."); + clif_displaymessage(s, "Character name sends to char-server to ask it."); } return ATCE::OKAY; } static -ATCE atcommand_character_save(const int fd, dumb_ptr sd, +ATCE atcommand_character_save(Session *s, dumb_ptr sd, ZString message) { MapName map_name; @@ -2352,7 +2360,7 @@ ATCE atcommand_character_save(const int fd, dumb_ptr sd, map_local *m = map_mapname2mapid(map_name); if (m == nullptr) { - clif_displaymessage(fd, "Map not found."); + clif_displaymessage(s, "Map not found."); return ATCE::EXIST; } else @@ -2360,23 +2368,23 @@ ATCE atcommand_character_save(const int fd, dumb_ptr sd, if (m != nullptr && m->flag.nowarpto && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { - clif_displaymessage(fd, + clif_displaymessage(s, "You are not authorised to set this map as a save map."); return ATCE::PERM; } pc_setsavepoint(pl_sd, map_name, x, y); - clif_displaymessage(fd, "Character's respawn point changed."); + clif_displaymessage(s, "Character's respawn point changed."); } } else { - clif_displaymessage(fd, "Your GM level don't authorise you to do this action on this player."); + clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."); return ATCE::PERM; } } else { - clif_displaymessage(fd, "Character not found."); + clif_displaymessage(s, "Character not found."); return ATCE::EXIST; } @@ -2384,47 +2392,49 @@ ATCE atcommand_character_save(const int fd, dumb_ptr sd, } static -ATCE atcommand_doom(const int fd, dumb_ptr sd, +ATCE atcommand_doom(Session *s, dumb_ptr sd, ZString) { for (int i = 0; i < fd_max; i++) { - if (!session[i]) + Session *s2 = session[i].get(); + if (!s2) continue; - dumb_ptr pl_sd = dumb_ptr(static_cast(session[i]->session_data.get())); + dumb_ptr pl_sd = dumb_ptr(static_cast(s2->session_data.get())); if (pl_sd - && pl_sd->state.auth && i != fd + && pl_sd->state.auth && s2 != s && pc_isGM(sd) >= pc_isGM(pl_sd)) { // you can doom only lower or same gm level pc_damage(NULL, pl_sd, pl_sd->status.hp + 1); - clif_displaymessage(pl_sd->fd, "The holy messenger has given judgement."); + clif_displaymessage(pl_sd->sess, "The holy messenger has given judgement."); } } - clif_displaymessage(fd, "Judgement was made."); + clif_displaymessage(s, "Judgement was made."); return ATCE::OKAY; } static -ATCE atcommand_doommap(const int fd, dumb_ptr sd, +ATCE atcommand_doommap(Session *s, dumb_ptr sd, ZString) { for (int i = 0; i < fd_max; i++) { - if (!session[i]) + Session *s2 = session[i].get(); + if (!s2) continue; - dumb_ptr pl_sd = dumb_ptr(static_cast(session[i]->session_data.get())); + dumb_ptr pl_sd = dumb_ptr(static_cast(s2->session_data.get())); if (pl_sd - && pl_sd->state.auth && i != fd && sd->bl_m == pl_sd->bl_m + && pl_sd->state.auth && s2 != s && sd->bl_m == pl_sd->bl_m && pc_isGM(sd) >= pc_isGM(pl_sd)) { // you can doom only lower or same gm level pc_damage(NULL, pl_sd, pl_sd->status.hp + 1); - clif_displaymessage(pl_sd->fd, "The holy messenger has given judgement."); + clif_displaymessage(pl_sd->sess, "The holy messenger has given judgement."); } } - clif_displaymessage(fd, "Judgement was made."); + clif_displaymessage(s, "Judgement was made."); return ATCE::OKAY; } @@ -2440,46 +2450,48 @@ void atcommand_raise_sub(dumb_ptr sd) clif_updatestatus(sd, SP::HP); clif_updatestatus(sd, SP::SP); clif_resurrection(sd, 1); - clif_displaymessage(sd->fd, "Mercy has been shown."); + clif_displaymessage(sd->sess, "Mercy has been shown."); } } static -ATCE atcommand_raise(const int fd, dumb_ptr, +ATCE atcommand_raise(Session *s, dumb_ptr, ZString) { for (int i = 0; i < fd_max; i++) { - if (!session[i]) + Session *s2 = session[i].get(); + if (!s2) continue; - dumb_ptr pl_sd = dumb_ptr(static_cast(session[i]->session_data.get())); + dumb_ptr pl_sd = dumb_ptr(static_cast(s2->session_data.get())); atcommand_raise_sub(pl_sd); } - clif_displaymessage(fd, "Mercy has been granted."); + clif_displaymessage(s, "Mercy has been granted."); return ATCE::OKAY; } static -ATCE atcommand_raisemap(const int fd, dumb_ptr sd, +ATCE atcommand_raisemap(Session *s, dumb_ptr sd, ZString) { for (int i = 0; i < fd_max; i++) { - if (!session[i]) + Session *s2 = session[i].get(); + if (!s2) continue; - dumb_ptr pl_sd = dumb_ptr(static_cast(session[i]->session_data.get())); + dumb_ptr pl_sd = dumb_ptr(static_cast(s2->session_data.get())); if (pl_sd && pl_sd->state.auth && sd->bl_m == pl_sd->bl_m) atcommand_raise_sub(pl_sd); } - clif_displaymessage(fd, "Mercy has been granted."); + clif_displaymessage(s, "Mercy has been granted."); return ATCE::OKAY; } //static -ATCE atcommand_character_baselevel(const int fd, dumb_ptr sd, +ATCE atcommand_character_baselevel(Session *s, dumb_ptr sd, ZString message) { CharName character; @@ -2499,7 +2511,7 @@ ATCE atcommand_character_baselevel(const int fd, dumb_ptr sd, { if (pl_sd->status.base_level == battle_config.maximum_level) { - clif_displaymessage(fd, "Character's base level can't go any higher."); + clif_displaymessage(s, "Character's base level can't go any higher."); return ATCE::RANGE; } if (level > battle_config.maximum_level || level > (battle_config.maximum_level - pl_sd->status.base_level)) @@ -2517,13 +2529,13 @@ ATCE atcommand_character_baselevel(const int fd, dumb_ptr sd, pc_calcstatus(pl_sd, 0); pc_heal(pl_sd, pl_sd->status.max_hp, pl_sd->status.max_sp); clif_misceffect(pl_sd, 0); - clif_displaymessage(fd, "Character's base level raised."); + clif_displaymessage(s, "Character's base level raised."); } else { if (pl_sd->status.base_level == 1) { - clif_displaymessage(fd, "Character's base level can't go any lower."); + clif_displaymessage(s, "Character's base level can't go any lower."); return ATCE::RANGE; } if (level < -battle_config.maximum_level || level < (1 - pl_sd->status.base_level)) @@ -2545,20 +2557,20 @@ ATCE atcommand_character_baselevel(const int fd, dumb_ptr sd, clif_updatestatus(pl_sd, SP::NEXTBASEEXP); clif_updatestatus(pl_sd, SP::BASEEXP); pc_calcstatus(pl_sd, 0); - clif_displaymessage(fd, "Character's base level lowered."); + clif_displaymessage(s, "Character's base level lowered."); } // Reset their stat points to prevent extra points from stacking - atcommand_charstreset(fd, sd, character.to__actual()); + atcommand_charstreset(s, sd, character.to__actual()); } else { - clif_displaymessage(fd, "Your GM level don't authorise you to do this action on this player."); + clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."); return ATCE::PERM; } } else { - clif_displaymessage(fd, "Character not found."); + clif_displaymessage(s, "Character not found."); return ATCE::EXIST; } @@ -2566,7 +2578,7 @@ ATCE atcommand_character_baselevel(const int fd, dumb_ptr sd, } static -ATCE atcommand_character_joblevel(const int fd, dumb_ptr sd, +ATCE atcommand_character_joblevel(Session *s, dumb_ptr sd, ZString message) { CharName character; @@ -2588,7 +2600,7 @@ ATCE atcommand_character_joblevel(const int fd, dumb_ptr sd, { if (pl_sd->status.job_level == max_level) { - clif_displaymessage(fd, "Character's job level can't go any higher."); + clif_displaymessage(s, "Character's job level can't go any higher."); return ATCE::RANGE; } if (pl_sd->status.job_level + level > max_level) @@ -2600,13 +2612,13 @@ ATCE atcommand_character_joblevel(const int fd, dumb_ptr sd, clif_updatestatus(pl_sd, SP::SKILLPOINT); pc_calcstatus(pl_sd, 0); clif_misceffect(pl_sd, 1); - clif_displaymessage(fd, "character's job level raised."); + clif_displaymessage(s, "character's job level raised."); } else { if (pl_sd->status.job_level == 1) { - clif_displaymessage(fd, "Character's job level can't go any lower."); + clif_displaymessage(s, "Character's job level can't go any lower."); return ATCE::RANGE; } if (pl_sd->status.job_level + level < 1) @@ -2623,18 +2635,18 @@ ATCE atcommand_character_joblevel(const int fd, dumb_ptr sd, } // to add: remove status points from skills pc_calcstatus(pl_sd, 0); - clif_displaymessage(fd, "Character's job level lowered."); + clif_displaymessage(s, "Character's job level lowered."); } } else { - clif_displaymessage(fd, "Your GM level don't authorise you to do this action on this player."); + clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."); return ATCE::PERM; } } else { - clif_displaymessage(fd, "Character not found."); + clif_displaymessage(s, "Character not found."); return ATCE::EXIST; } @@ -2642,7 +2654,7 @@ ATCE atcommand_character_joblevel(const int fd, dumb_ptr sd, } static -ATCE atcommand_kick(const int fd, dumb_ptr sd, +ATCE atcommand_kick(Session *s, dumb_ptr sd, ZString message) { CharName character; @@ -2658,13 +2670,13 @@ ATCE atcommand_kick(const int fd, dumb_ptr sd, clif_GM_kick(sd, pl_sd, 1); else { - clif_displaymessage(fd, "Your GM level don't authorise you to do this action on this player."); + clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."); return ATCE::PERM; } } else { - clif_displaymessage(fd, "Character not found."); + clif_displaymessage(s, "Character not found."); return ATCE::EXIST; } @@ -2672,14 +2684,15 @@ ATCE atcommand_kick(const int fd, dumb_ptr sd, } static -ATCE atcommand_kickall(const int fd, dumb_ptr sd, +ATCE atcommand_kickall(Session *s, dumb_ptr sd, ZString) { for (int i = 0; i < fd_max; i++) { - if (!session[i]) + Session *s2 = session[i].get(); + if (!s2) continue; - dumb_ptr pl_sd = dumb_ptr(static_cast(session[i]->session_data.get())); + dumb_ptr pl_sd = dumb_ptr(static_cast(s2->session_data.get())); if (pl_sd && pl_sd->state.auth && pc_isGM(sd) >= pc_isGM(pl_sd)) { @@ -2689,13 +2702,13 @@ ATCE atcommand_kickall(const int fd, dumb_ptr sd, } } - clif_displaymessage(fd, "All players have been kicked!"); + clif_displaymessage(s, "All players have been kicked!"); return ATCE::OKAY; } static -ATCE atcommand_questskill(const int fd, dumb_ptr sd, +ATCE atcommand_questskill(Session *s, dumb_ptr sd, ZString message) { SkillID skill_id; @@ -2710,23 +2723,23 @@ ATCE atcommand_questskill(const int fd, dumb_ptr sd, if (pc_checkskill(sd, skill_id) == 0) { pc_skill(sd, skill_id, 1, 0); - clif_displaymessage(fd, "You have learned the skill."); + clif_displaymessage(s, "You have learned the skill."); } else { - clif_displaymessage(fd, "You already have this quest skill."); + clif_displaymessage(s, "You already have this quest skill."); return ATCE::EXIST; } } else { - clif_displaymessage(fd, "This skill number doesn't exist or isn't a quest skill."); + clif_displaymessage(s, "This skill number doesn't exist or isn't a quest skill."); return ATCE::RANGE; } } else { - clif_displaymessage(fd, "This skill number doesn't exist."); + clif_displaymessage(s, "This skill number doesn't exist."); return ATCE::RANGE; } @@ -2734,7 +2747,7 @@ ATCE atcommand_questskill(const int fd, dumb_ptr sd, } static -ATCE atcommand_charquestskill(const int fd, dumb_ptr, +ATCE atcommand_charquestskill(Session *s, dumb_ptr, ZString message) { CharName character; @@ -2753,29 +2766,29 @@ ATCE atcommand_charquestskill(const int fd, dumb_ptr, if (pc_checkskill(pl_sd, skill_id) == 0) { pc_skill(pl_sd, skill_id, 1, 0); - clif_displaymessage(fd, "This player has learned the skill."); + clif_displaymessage(s, "This player has learned the skill."); } else { - clif_displaymessage(fd, "This player already has this quest skill."); + clif_displaymessage(s, "This player already has this quest skill."); return ATCE::EXIST; } } else { - clif_displaymessage(fd, "Character not found."); + clif_displaymessage(s, "Character not found."); return ATCE::EXIST; } } else { - clif_displaymessage(fd, "This skill number doesn't exist or isn't a quest skill."); + clif_displaymessage(s, "This skill number doesn't exist or isn't a quest skill."); return ATCE::RANGE; } } else { - clif_displaymessage(fd, "This skill number doesn't exist."); + clif_displaymessage(s, "This skill number doesn't exist."); return ATCE::RANGE; } @@ -2783,7 +2796,7 @@ ATCE atcommand_charquestskill(const int fd, dumb_ptr, } static -ATCE atcommand_lostskill(const int fd, dumb_ptr sd, +ATCE atcommand_lostskill(Session *s, dumb_ptr sd, ZString message) { SkillID skill_id; @@ -2800,23 +2813,23 @@ ATCE atcommand_lostskill(const int fd, dumb_ptr sd, sd->status.skill[skill_id].lv = 0; sd->status.skill[skill_id].flags = SkillFlags::ZERO; clif_skillinfoblock(sd); - clif_displaymessage(fd, "You have forgotten the skill."); + clif_displaymessage(s, "You have forgotten the skill."); } else { - clif_displaymessage(fd, "You don't have this quest skill."); + clif_displaymessage(s, "You don't have this quest skill."); return ATCE::EXIST; } } else { - clif_displaymessage(fd, "This skill number doesn't exist or isn't a quest skill."); + clif_displaymessage(s, "This skill number doesn't exist or isn't a quest skill."); return ATCE::RANGE; } } else { - clif_displaymessage(fd, "This skill number doesn't exist."); + clif_displaymessage(s, "This skill number doesn't exist."); return ATCE::RANGE; } @@ -2824,7 +2837,7 @@ ATCE atcommand_lostskill(const int fd, dumb_ptr sd, } static -ATCE atcommand_charlostskill(const int fd, dumb_ptr, +ATCE atcommand_charlostskill(Session *s, dumb_ptr, ZString message) { CharName character; @@ -2845,29 +2858,29 @@ ATCE atcommand_charlostskill(const int fd, dumb_ptr, pl_sd->status.skill[skill_id].lv = 0; pl_sd->status.skill[skill_id].flags = SkillFlags::ZERO; clif_skillinfoblock(pl_sd); - clif_displaymessage(fd, "This player has forgotten the skill."); + clif_displaymessage(s, "This player has forgotten the skill."); } else { - clif_displaymessage(fd, "This player doesn't have this quest skill."); + clif_displaymessage(s, "This player doesn't have this quest skill."); return ATCE::EXIST; } } else { - clif_displaymessage(fd, "Character not found."); + clif_displaymessage(s, "Character not found."); return ATCE::EXIST; } } else { - clif_displaymessage(fd, "This skill number doesn't exist or isn't a quest skill."); + clif_displaymessage(s, "This skill number doesn't exist or isn't a quest skill."); return ATCE::RANGE; } } else { - clif_displaymessage(fd, "This skill number doesn't exist."); + clif_displaymessage(s, "This skill number doesn't exist."); return ATCE::RANGE; } @@ -2875,7 +2888,7 @@ ATCE atcommand_charlostskill(const int fd, dumb_ptr, } static -ATCE atcommand_party(const int, dumb_ptr sd, +ATCE atcommand_party(Session *, dumb_ptr sd, ZString message) { PartyName party; @@ -2889,14 +2902,15 @@ ATCE atcommand_party(const int, dumb_ptr sd, } static -ATCE atcommand_mapexit(const int, dumb_ptr sd, +ATCE atcommand_mapexit(Session *, dumb_ptr sd, ZString) { for (int i = 0; i < fd_max; i++) { - if (!session[i]) + Session *s2 = session[i].get(); + if (!s2) continue; - dumb_ptr pl_sd = dumb_ptr(static_cast(session[i]->session_data.get())); + dumb_ptr pl_sd = dumb_ptr(static_cast(s2->session_data.get())); if (pl_sd && pl_sd->state.auth) { if (sd->status.account_id != pl_sd->status.account_id) @@ -2911,7 +2925,7 @@ ATCE atcommand_mapexit(const int, dumb_ptr sd, } static -ATCE atcommand_idsearch(const int fd, dumb_ptr, +ATCE atcommand_idsearch(Session *s, dumb_ptr, ZString message) { ItemName item_name; @@ -2922,7 +2936,7 @@ ATCE atcommand_idsearch(const int fd, dumb_ptr, return ATCE::USAGE; FString output = STRPRINTF("The reference result of '%s' (name: id):", item_name); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); match = 0; for (i = 0; i < 20000; i++) { @@ -2931,17 +2945,17 @@ ATCE atcommand_idsearch(const int fd, dumb_ptr, { match++; output = STRPRINTF("%s: %d", item->jname, item->nameid); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); } } output = STRPRINTF("It is %d affair above.", match); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); return ATCE::OKAY; } static -ATCE atcommand_charskreset(const int fd, dumb_ptr sd, +ATCE atcommand_charskreset(Session *s, dumb_ptr sd, ZString message) { CharName character; @@ -2958,17 +2972,17 @@ ATCE atcommand_charskreset(const int fd, dumb_ptr sd, pc_resetskill(pl_sd); FString output = STRPRINTF( "'%s' skill points reseted!", character); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); } else { - clif_displaymessage(fd, "Your GM level don't authorise you to do this action on this player."); + clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."); return ATCE::PERM; } } else { - clif_displaymessage(fd, "Character not found."); + clif_displaymessage(s, "Character not found."); return ATCE::EXIST; } @@ -2976,7 +2990,7 @@ ATCE atcommand_charskreset(const int fd, dumb_ptr sd, } //static -ATCE atcommand_charstreset(const int fd, dumb_ptr sd, +ATCE atcommand_charstreset(Session *s, dumb_ptr sd, ZString message) { CharName character; @@ -2994,17 +3008,17 @@ ATCE atcommand_charstreset(const int fd, dumb_ptr sd, FString output = STRPRINTF( "'%s' stats points reseted!", character); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); } else { - clif_displaymessage(fd, "Your GM level don't authorise you to do this action on this player."); + clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."); return ATCE::PERM; } } else { - clif_displaymessage(fd, "Character not found."); + clif_displaymessage(s, "Character not found."); return ATCE::EXIST; } @@ -3012,7 +3026,7 @@ ATCE atcommand_charstreset(const int fd, dumb_ptr sd, } static -ATCE atcommand_charreset(const int fd, dumb_ptr sd, +ATCE atcommand_charreset(Session *s, dumb_ptr sd, ZString message) { CharName character; @@ -3034,17 +3048,17 @@ ATCE atcommand_charreset(const int fd, dumb_ptr sd, // [Fate] Reset magic experience FString output = STRPRINTF( "'%s' skill and stats points reseted!", character); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); } else { - clif_displaymessage(fd, "Your GM level don't authorise you to do this action on this player."); + clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."); return ATCE::PERM; } } else { - clif_displaymessage(fd, "Character not found."); + clif_displaymessage(s, "Character not found."); return ATCE::EXIST; } @@ -3052,7 +3066,7 @@ ATCE atcommand_charreset(const int fd, dumb_ptr sd, } static -ATCE atcommand_char_wipe(const int fd, dumb_ptr sd, +ATCE atcommand_char_wipe(Session *s, dumb_ptr sd, ZString message) { CharName character; @@ -3118,17 +3132,17 @@ ATCE atcommand_char_wipe(const int fd, dumb_ptr sd, // [Fate] Reset magic experience FString output = STRPRINTF("%s: wiped.", character); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); } else { - clif_displaymessage(fd, "Your GM level don't authorise you to do this action on this player."); + clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."); return ATCE::PERM; } } else { - clif_displaymessage(fd, "Character not found."); + clif_displaymessage(s, "Character not found."); return ATCE::EXIST; } @@ -3136,7 +3150,7 @@ ATCE atcommand_char_wipe(const int fd, dumb_ptr sd, } static -ATCE atcommand_charmodel(const int fd, dumb_ptr, +ATCE atcommand_charmodel(Session *s, dumb_ptr, ZString message) { unsigned hair_style = 0, hair_color = 0, cloth_color = 0; @@ -3156,7 +3170,7 @@ ATCE atcommand_charmodel(const int fd, dumb_ptr, pc_changelook(pl_sd, LOOK::HAIR, hair_style); pc_changelook(pl_sd, LOOK::HAIR_COLOR, hair_color); pc_changelook(pl_sd, LOOK::CLOTHES_COLOR, cloth_color); - clif_displaymessage(fd, "Appearence changed."); + clif_displaymessage(s, "Appearence changed."); } } else @@ -3164,7 +3178,7 @@ ATCE atcommand_charmodel(const int fd, dumb_ptr, } else { - clif_displaymessage(fd, "Character not found."); + clif_displaymessage(s, "Character not found."); return ATCE::EXIST; } @@ -3172,7 +3186,7 @@ ATCE atcommand_charmodel(const int fd, dumb_ptr, } static -ATCE atcommand_charskpoint(const int fd, dumb_ptr, +ATCE atcommand_charskpoint(Session *s, dumb_ptr, ZString message) { CharName character; @@ -3197,14 +3211,14 @@ ATCE atcommand_charskpoint(const int fd, dumb_ptr, { pl_sd->status.skill_point = new_skill_point; clif_updatestatus(pl_sd, SP::SKILLPOINT); - clif_displaymessage(fd, "Character's number of skill points changed!"); + clif_displaymessage(s, "Character's number of skill points changed!"); } else return ATCE::RANGE; } else { - clif_displaymessage(fd, "Character not found."); + clif_displaymessage(s, "Character not found."); return ATCE::EXIST; } @@ -3212,7 +3226,7 @@ ATCE atcommand_charskpoint(const int fd, dumb_ptr, } static -ATCE atcommand_charstpoint(const int fd, dumb_ptr, +ATCE atcommand_charstpoint(Session *s, dumb_ptr, ZString message) { CharName character; @@ -3237,14 +3251,14 @@ ATCE atcommand_charstpoint(const int fd, dumb_ptr, { pl_sd->status.status_point = new_status_point; clif_updatestatus(pl_sd, SP::STATUSPOINT); - clif_displaymessage(fd, "Character's number of status points changed!"); + clif_displaymessage(s, "Character's number of status points changed!"); } else return ATCE::RANGE; } else { - clif_displaymessage(fd, "Character not found."); + clif_displaymessage(s, "Character not found."); return ATCE::EXIST; } @@ -3252,7 +3266,7 @@ ATCE atcommand_charstpoint(const int fd, dumb_ptr, } static -ATCE atcommand_charzeny(const int fd, dumb_ptr, +ATCE atcommand_charzeny(Session *s, dumb_ptr, ZString message) { CharName character; @@ -3275,14 +3289,14 @@ ATCE atcommand_charzeny(const int fd, dumb_ptr, { pl_sd->status.zeny = new_zeny; clif_updatestatus(pl_sd, SP::ZENY); - clif_displaymessage(fd, "Character's number of zenys changed!"); + clif_displaymessage(s, "Character's number of zenys changed!"); } else return ATCE::RANGE; } else { - clif_displaymessage(fd, "Character not found."); + clif_displaymessage(s, "Character not found."); return ATCE::EXIST; } @@ -3290,7 +3304,7 @@ ATCE atcommand_charzeny(const int fd, dumb_ptr, } static -ATCE atcommand_recallall(const int fd, dumb_ptr sd, +ATCE atcommand_recallall(Session *s, dumb_ptr sd, ZString) { int count; @@ -3298,7 +3312,7 @@ ATCE atcommand_recallall(const int fd, dumb_ptr sd, if (sd->bl_m && sd->bl_m->flag.nowarpto && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { - clif_displaymessage(fd, + clif_displaymessage(s, "You are not authorised to warp somenone to your actual map."); return ATCE::PERM; } @@ -3306,9 +3320,10 @@ ATCE atcommand_recallall(const int fd, dumb_ptr sd, count = 0; for (int i = 0; i < fd_max; i++) { - if (!session[i]) + Session *s2 = session[i].get(); + if (!s2) continue; - dumb_ptr pl_sd = dumb_ptr(static_cast(session[i]->session_data.get())); + dumb_ptr pl_sd = dumb_ptr(static_cast(s2->session_data.get())); if (pl_sd && pl_sd->state.auth && sd->status.account_id != pl_sd->status.account_id @@ -3323,20 +3338,20 @@ ATCE atcommand_recallall(const int fd, dumb_ptr sd, } } - clif_displaymessage(fd, "All characters recalled!"); + clif_displaymessage(s, "All characters recalled!"); if (count) { FString output = STRPRINTF( "Because you are not authorised to warp from some maps, %d player(s) have not been recalled.", count); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); } return ATCE::OKAY; } static -ATCE atcommand_partyrecall(const int fd, dumb_ptr sd, +ATCE atcommand_partyrecall(Session *s, dumb_ptr sd, ZString message) { PartyName party_name; @@ -3349,7 +3364,7 @@ ATCE atcommand_partyrecall(const int fd, dumb_ptr sd, if (sd->bl_m && sd->bl_m->flag.nowarpto && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { - clif_displaymessage(fd, + clif_displaymessage(s, "You are not authorised to warp somenone to your actual map."); return ATCE::PERM; } @@ -3361,9 +3376,10 @@ ATCE atcommand_partyrecall(const int fd, dumb_ptr sd, count = 0; for (int i = 0; i < fd_max; i++) { - if (!session[i]) + Session *s2 = session[i].get(); + if (!s2) continue; - dumb_ptr pl_sd = dumb_ptr(static_cast(session[i]->session_data.get())); + dumb_ptr pl_sd = dumb_ptr(static_cast(s2->session_data.get())); if (pl_sd && pl_sd->state.auth && sd->status.account_id != pl_sd->status.account_id && pl_sd->status.party_id == p->party_id) @@ -3376,18 +3392,18 @@ ATCE atcommand_partyrecall(const int fd, dumb_ptr sd, } } FString output = STRPRINTF("All online characters of the %s party are near you.", p->name); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); if (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); + clif_displaymessage(s, output); } } else { - clif_displaymessage(fd, "Incorrect name or ID, or no one from the party is online."); + clif_displaymessage(s, "Incorrect name or ID, or no one from the party is online."); return ATCE::EXIST; } @@ -3395,7 +3411,7 @@ ATCE atcommand_partyrecall(const int fd, dumb_ptr sd, } static -ATCE atcommand_mapinfo(const int fd, dumb_ptr sd, +ATCE atcommand_mapinfo(Session *s, dumb_ptr sd, ZString message) { dumb_ptr nd = NULL; @@ -3415,42 +3431,42 @@ ATCE atcommand_mapinfo(const int fd, dumb_ptr sd, if (m_id != nullptr) return ATCE::EXIST; - clif_displaymessage(fd, "------ Map Info ------"); + clif_displaymessage(s, "------ Map Info ------"); FString output = STRPRINTF("Map Name: %s", map_name); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); output = STRPRINTF("Players In Map: %d", m_id->users); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); output = STRPRINTF("NPCs In Map: %d", m_id->npc_num); - clif_displaymessage(fd, output); - clif_displaymessage(fd, "------ Map Flags ------"); + clif_displaymessage(s, output); + clif_displaymessage(s, "------ Map Flags ------"); output = STRPRINTF("Player vs Player: %s | No Party: %s", (m_id->flag.pvp) ? "True" : "False", (m_id->flag.pvp_noparty) ? "True" : "False"); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); output = STRPRINTF("No Dead Branch: %s", (m_id->flag.nobranch) ? "True" : "False"); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); output = STRPRINTF("No Memo: %s", (m_id->flag.nomemo) ? "True" : "False"); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); output = STRPRINTF("No Penalty: %s", (m_id->flag.nopenalty) ? "True" : "False"); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); output = STRPRINTF("No Return: %s", (m_id->flag.noreturn) ? "True" : "False"); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); output = STRPRINTF("No Save: %s", (m_id->flag.nosave) ? "True" : "False"); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); output = STRPRINTF("No Teleport: %s", (m_id->flag.noteleport) ? "True" : "False"); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); output = STRPRINTF("No Monster Teleport: %s", (m_id->flag.monster_noteleport) ? "True" : "False"); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); output = STRPRINTF("No Zeny Penalty: %s", (m_id->flag.nozenypenalty) ? "True" : "False"); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); switch (list) { @@ -3458,24 +3474,25 @@ ATCE atcommand_mapinfo(const int fd, dumb_ptr sd, // Do nothing. It's list 0, no additional display. break; case 1: - clif_displaymessage(fd, "----- Players in Map -----"); + clif_displaymessage(s, "----- Players in Map -----"); for (int i = 0; i < fd_max; i++) { - if (!session[i]) + Session *s2 = session[i].get(); + if (!s2) continue; - dumb_ptr pl_sd = dumb_ptr(static_cast(session[i]->session_data.get())); + dumb_ptr pl_sd = dumb_ptr(static_cast(s2->session_data.get())); if (pl_sd && pl_sd->state.auth && pl_sd->mapname_ == map_name) { 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); + clif_displaymessage(s, output); } } break; case 2: - clif_displaymessage(fd, "----- NPCs in Map -----"); + clif_displaymessage(s, "----- NPCs in Map -----"); for (int i = 0; i < m_id->npc_num;) { nd = m_id->npc[i]; @@ -3518,12 +3535,12 @@ ATCE atcommand_mapinfo(const int fd, dumb_ptr sd, "NPC %d: %s | Direction: %s | Sprite: %d | Location: %d %d", ++i, nd->name, direction, nd->npc_class, nd->bl_x, nd->bl_y); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); } break; default: // normally impossible to arrive here - clif_displaymessage(fd, + clif_displaymessage(s, "Please, enter at least a valid list number (usage: @mapinfo <0-2> [map])."); return ATCE::USAGE; } @@ -3532,7 +3549,7 @@ ATCE atcommand_mapinfo(const int fd, dumb_ptr sd, } static -ATCE atcommand_partyspy(const int fd, dumb_ptr sd, +ATCE atcommand_partyspy(Session *s, dumb_ptr sd, ZString message) { PartyName party_name; @@ -3549,18 +3566,18 @@ ATCE atcommand_partyspy(const int fd, dumb_ptr sd, { sd->partyspy = 0; FString output = STRPRINTF("No longer spying on the %s party.", p->name); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); } else { sd->partyspy = p->party_id; FString output = STRPRINTF("Spying on the %s party.", p->name); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); } } else { - clif_displaymessage(fd, "Incorrect name or ID, or no one from the party is online."); + clif_displaymessage(s, "Incorrect name or ID, or no one from the party is online."); return ATCE::EXIST; } @@ -3568,7 +3585,7 @@ ATCE atcommand_partyspy(const int fd, dumb_ptr sd, } static -ATCE atcommand_enablenpc(const int fd, dumb_ptr, +ATCE atcommand_enablenpc(Session *s, dumb_ptr, ZString message) { NpcName NPCname; @@ -3579,11 +3596,11 @@ ATCE atcommand_enablenpc(const int fd, dumb_ptr, if (npc_name2id(NPCname) != NULL) { npc_enable(NPCname, 1); - clif_displaymessage(fd, "Npc Enabled."); + clif_displaymessage(s, "Npc Enabled."); } else { - clif_displaymessage(fd, "This NPC doesn't exist."); + clif_displaymessage(s, "This NPC doesn't exist."); return ATCE::EXIST; } @@ -3591,7 +3608,7 @@ ATCE atcommand_enablenpc(const int fd, dumb_ptr, } static -ATCE atcommand_disablenpc(const int fd, dumb_ptr, +ATCE atcommand_disablenpc(Session *s, dumb_ptr, ZString message) { NpcName NPCname; @@ -3602,11 +3619,11 @@ ATCE atcommand_disablenpc(const int fd, dumb_ptr, if (npc_name2id(NPCname) != NULL) { npc_enable(NPCname, 0); - clif_displaymessage(fd, "Npc Disabled."); + clif_displaymessage(s, "Npc Disabled."); } else { - clif_displaymessage(fd, "This NPC doesn't exist."); + clif_displaymessage(s, "This NPC doesn't exist."); return ATCE::EXIST; } @@ -3614,19 +3631,19 @@ ATCE atcommand_disablenpc(const int fd, dumb_ptr, } static -ATCE atcommand_servertime(const int fd, dumb_ptr, +ATCE atcommand_servertime(Session *s, dumb_ptr, ZString) { timestamp_seconds_buffer tsbuf; stamp_time(tsbuf); FString temp = STRPRINTF("Server time: %s", tsbuf); - clif_displaymessage(fd, temp); + clif_displaymessage(s, temp); return ATCE::OKAY; } static -ATCE atcommand_chardelitem(const int fd, dumb_ptr sd, +ATCE atcommand_chardelitem(Session *s, dumb_ptr sd, ZString message) { CharName character; @@ -3664,35 +3681,35 @@ ATCE atcommand_chardelitem(const int fd, dumb_ptr sd, FString output = STRPRINTF( "%d item(s) removed by a GM.", count); - clif_displaymessage(pl_sd->fd, output); + clif_displaymessage(pl_sd->sess, output); if (number == count) output = STRPRINTF("%d item(s) removed from the player.", count); else output = STRPRINTF("%d item(s) removed. Player had only %d on %d items.", count, count, number); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); } else { - clif_displaymessage(fd, "Character does not have the item."); + clif_displaymessage(s, "Character does not have the item."); return ATCE::EXIST; } } else { - clif_displaymessage(fd, "Your GM level don't authorise you to do this action on this player."); + clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."); return ATCE::PERM; } } else { - clif_displaymessage(fd, "Character not found."); + clif_displaymessage(s, "Character not found."); return ATCE::EXIST; } } else { - clif_displaymessage(fd, "Invalid item ID or name."); + clif_displaymessage(s, "Invalid item ID or name."); return ATCE::RANGE; } @@ -3700,7 +3717,7 @@ ATCE atcommand_chardelitem(const int fd, dumb_ptr sd, } static -ATCE atcommand_broadcast(const int, dumb_ptr sd, +ATCE atcommand_broadcast(Session *, dumb_ptr sd, ZString message) { if (!message) @@ -3713,7 +3730,7 @@ ATCE atcommand_broadcast(const int, dumb_ptr sd, } static -ATCE atcommand_localbroadcast(const int, dumb_ptr sd, +ATCE atcommand_localbroadcast(Session *, dumb_ptr sd, ZString message) { if (!message) @@ -3727,7 +3744,7 @@ ATCE atcommand_localbroadcast(const int, dumb_ptr sd, } static -ATCE atcommand_email(const int fd, dumb_ptr sd, +ATCE atcommand_email(Session *s, dumb_ptr sd, ZString message) { AccountEmail actual_email; @@ -3738,35 +3755,35 @@ ATCE atcommand_email(const int fd, dumb_ptr sd, if (!e_mail_check(actual_email)) { - clif_displaymessage(fd, "Invalid actual email. If you have default e-mail, type a@a.com."); + clif_displaymessage(s, "Invalid actual email. If you have default e-mail, type a@a.com."); return ATCE::RANGE; } else if (!e_mail_check(new_email)) { - clif_displaymessage(fd, "Invalid new email. Please enter a real e-mail."); + clif_displaymessage(s, "Invalid new email. Please enter a real e-mail."); return ATCE::RANGE; } else if (new_email == DEFAULT_EMAIL) { - clif_displaymessage(fd, "New email must be a real e-mail."); + clif_displaymessage(s, "New email must be a real e-mail."); return ATCE::RANGE; } else if (actual_email == new_email) { - clif_displaymessage(fd, "New email must be different of the actual e-mail."); + clif_displaymessage(s, "New email must be different of the actual e-mail."); return ATCE::RANGE; } else { chrif_changeemail(sd->status.account_id, actual_email, new_email); - clif_displaymessage(fd, "Information sended to login-server via char-server."); + clif_displaymessage(s, "Information sended to login-server via char-server."); } return ATCE::OKAY; } static -ATCE atcommand_effect(const int fd, dumb_ptr sd, +ATCE atcommand_effect(Session *s, dumb_ptr sd, ZString message) { int type = 0, flag = 0; @@ -3776,19 +3793,20 @@ ATCE atcommand_effect(const int fd, dumb_ptr sd, if (flag <= 0) { clif_specialeffect(sd, type, flag); - clif_displaymessage(fd, "Your Effect Has Changed."); + clif_displaymessage(s, "Your Effect Has Changed."); } else { for (int i = 0; i < fd_max; i++) { - if (!session[i]) + Session *s2 = session[i].get(); + if (!s2) continue; - dumb_ptr pl_sd = dumb_ptr(static_cast(session[i]->session_data.get())); + dumb_ptr pl_sd = dumb_ptr(static_cast(s2->session_data.get())); if (pl_sd && pl_sd->state.auth) { clif_specialeffect(pl_sd, type, flag); - clif_displaymessage(pl_sd->fd, "Your Effect Has Changed."); + clif_displaymessage(pl_sd->sess, "Your Effect Has Changed."); } } } @@ -3797,7 +3815,7 @@ ATCE atcommand_effect(const int fd, dumb_ptr sd, } static -ATCE atcommand_character_item_list(const int fd, dumb_ptr sd, +ATCE atcommand_character_item_list(Session *s, dumb_ptr sd, ZString message) { struct item_data *item_data = NULL, *item_temp; @@ -3829,7 +3847,7 @@ ATCE atcommand_character_item_list(const int fd, dumb_ptr sd, FString output = STRPRINTF( "------ Items list of '%s' ------", pl_sd->status.name); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); } EPOS equip = pl_sd->status.inventory[i].equip; MString equipstr; @@ -3886,7 +3904,7 @@ ATCE atcommand_character_item_list(const int fd, dumb_ptr sd, item_data->name, item_data->jname, pl_sd->status.inventory[i].nameid, FString(equipstr)); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); MString voutput; counter2 = 0; @@ -3920,29 +3938,29 @@ ATCE atcommand_character_item_list(const int fd, dumb_ptr sd, // replace trailing ", " voutput.pop_back(); voutput.back() = ')'; - clif_displaymessage(fd, FString(voutput)); + clif_displaymessage(s, FString(voutput)); } } } if (count == 0) - clif_displaymessage(fd, "No item found on this player."); + clif_displaymessage(s, "No item found on this player."); else { FString output = STRPRINTF( "%d item(s) found in %d kind(s) of items.", counter, count); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); } } else { - clif_displaymessage(fd, "Your GM level don't authorise you to do this action on this player."); + clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."); return ATCE::PERM; } } else { - clif_displaymessage(fd, "Character not found."); + clif_displaymessage(s, "Character not found."); return ATCE::EXIST; } @@ -3950,7 +3968,7 @@ ATCE atcommand_character_item_list(const int fd, dumb_ptr sd, } static -ATCE atcommand_character_storage_list(const int fd, dumb_ptr sd, +ATCE atcommand_character_storage_list(Session *s, dumb_ptr sd, ZString message) { struct storage *stor; @@ -3984,7 +4002,7 @@ ATCE atcommand_character_storage_list(const int fd, dumb_ptr s FString output = STRPRINTF( "------ Storage items list of '%s' ------", pl_sd->status.name); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); } FString output; if (stor->storage_[i].refine) @@ -4000,7 +4018,7 @@ ATCE atcommand_character_storage_list(const int fd, dumb_ptr s stor->storage_[i].amount, item_data->name, item_data->jname, stor->storage_[i].nameid); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); MString voutput; counter2 = 0; @@ -4034,36 +4052,36 @@ ATCE atcommand_character_storage_list(const int fd, dumb_ptr s // replace last ", " voutput.pop_back(); voutput.back() = ')'; - clif_displaymessage(fd, FString(voutput)); + clif_displaymessage(s, FString(voutput)); } } } if (count == 0) - clif_displaymessage(fd, + clif_displaymessage(s, "No item found in the storage of this player."); else { FString output = STRPRINTF( "%d item(s) found in %d kind(s) of items.", counter, count); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); } } else { - clif_displaymessage(fd, "This player has no storage."); + clif_displaymessage(s, "This player has no storage."); return ATCE::OKAY; } } else { - clif_displaymessage(fd, "Your GM level don't authorise you to do this action on this player."); + clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."); return ATCE::PERM; } } else { - clif_displaymessage(fd, "Character not found."); + clif_displaymessage(s, "Character not found."); return ATCE::EXIST; } @@ -4071,7 +4089,7 @@ ATCE atcommand_character_storage_list(const int fd, dumb_ptr s } static -ATCE atcommand_character_cart_list(const int fd, dumb_ptr sd, +ATCE atcommand_character_cart_list(Session *s, dumb_ptr sd, ZString message) { struct item_data *item_data = NULL, *item_temp; @@ -4102,7 +4120,7 @@ ATCE atcommand_character_cart_list(const int fd, dumb_ptr sd, FString output = STRPRINTF( "------ Cart items list of '%s' ------", pl_sd->status.name); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); } FString output; @@ -4120,7 +4138,7 @@ ATCE atcommand_character_cart_list(const int fd, dumb_ptr sd, pl_sd->status.cart[i].amount, item_data->name, item_data->jname, pl_sd->status.cart[i].nameid); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); MString voutput; counter2 = 0; @@ -4152,29 +4170,29 @@ ATCE atcommand_character_cart_list(const int fd, dumb_ptr sd, { voutput.pop_back(); voutput.back() = '0'; - clif_displaymessage(fd, FString(voutput)); + clif_displaymessage(s, FString(voutput)); } } } if (count == 0) - clif_displaymessage(fd, + clif_displaymessage(s, "No item found in the cart of this player."); else { FString output = STRPRINTF("%d item(s) found in %d kind(s) of items.", counter, count); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); } } else { - clif_displaymessage(fd, "Your GM level don't authorise you to do this action on this player."); + clif_displaymessage(s, "Your GM level don't authorise you to do this action on this player."); return ATCE::PERM; } } else { - clif_displaymessage(fd, "Character not found."); + clif_displaymessage(s, "Character not found."); return ATCE::EXIST; } @@ -4182,21 +4200,21 @@ ATCE atcommand_character_cart_list(const int fd, dumb_ptr sd, } static -ATCE atcommand_killer(const int fd, dumb_ptr sd, +ATCE atcommand_killer(Session *s, dumb_ptr sd, ZString) { sd->special_state.killer = !sd->special_state.killer; if (sd->special_state.killer) - clif_displaymessage(fd, "You be a killa..."); + clif_displaymessage(s, "You be a killa..."); else - clif_displaymessage(fd, "You gonna be own3d..."); + clif_displaymessage(s, "You gonna be own3d..."); return ATCE::OKAY; } static -ATCE atcommand_charkiller(const int fd, dumb_ptr, +ATCE atcommand_charkiller(Session *s, dumb_ptr, ZString message) { CharName character; @@ -4212,34 +4230,34 @@ ATCE atcommand_charkiller(const int fd, dumb_ptr, if (pl_sd->special_state.killer) { - clif_displaymessage(fd, "The player is now a killer"); - clif_displaymessage(pl_sd->fd, "You are now a killer"); + clif_displaymessage(s, "The player is now a killer"); + clif_displaymessage(pl_sd->sess, "You are now a killer"); } else { - clif_displaymessage(fd, "The player is no longer a killer"); - clif_displaymessage(pl_sd->fd, "You are no longer a killer"); + clif_displaymessage(s, "The player is no longer a killer"); + clif_displaymessage(pl_sd->sess, "You are no longer a killer"); } return ATCE::OKAY; } static -ATCE atcommand_killable(const int fd, dumb_ptr sd, +ATCE atcommand_killable(Session *s, dumb_ptr sd, ZString) { sd->special_state.killable = !sd->special_state.killable; if (sd->special_state.killable) - clif_displaymessage(fd, "You gonna be own3d..."); + clif_displaymessage(s, "You gonna be own3d..."); else - clif_displaymessage(fd, "You be a killa..."); + clif_displaymessage(s, "You be a killa..."); return ATCE::OKAY; } static -ATCE atcommand_charkillable(const int fd, dumb_ptr, +ATCE atcommand_charkillable(Session *s, dumb_ptr, ZString message) { CharName character; @@ -4254,15 +4272,15 @@ ATCE atcommand_charkillable(const int fd, dumb_ptr, pl_sd->special_state.killable = !pl_sd->special_state.killable; if (pl_sd->special_state.killable) - clif_displaymessage(fd, "The player is now killable"); + clif_displaymessage(s, "The player is now killable"); else - clif_displaymessage(fd, "The player is no longer killable"); + clif_displaymessage(s, "The player is no longer killable"); return ATCE::OKAY; } static -ATCE atcommand_npcmove(const int, dumb_ptr, +ATCE atcommand_npcmove(Session *, dumb_ptr, ZString message) { NpcName character; @@ -4285,7 +4303,7 @@ ATCE atcommand_npcmove(const int, dumb_ptr, } static -ATCE atcommand_addwarp(const int fd, dumb_ptr sd, +ATCE atcommand_addwarp(Session *s, dumb_ptr sd, ZString message) { MapName mapname; @@ -4305,13 +4323,13 @@ ATCE atcommand_addwarp(const int fd, dumb_ptr sd, return ATCE::RANGE; FString output = STRPRINTF("New warp NPC => %s", w3); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); return ATCE::OKAY; } static -ATCE atcommand_chareffect(const int fd, dumb_ptr, +ATCE atcommand_chareffect(Session *s, dumb_ptr, ZString message) { CharName target; @@ -4325,13 +4343,13 @@ ATCE atcommand_chareffect(const int fd, dumb_ptr, return ATCE::EXIST; clif_specialeffect(pl_sd, type, 0); - clif_displaymessage(fd, "Your Effect Has Changed."); + clif_displaymessage(s, "Your Effect Has Changed."); return ATCE::OKAY; } static -ATCE atcommand_dropall(const int, dumb_ptr sd, +ATCE atcommand_dropall(Session *, dumb_ptr sd, ZString) { int i; @@ -4348,7 +4366,7 @@ ATCE atcommand_dropall(const int, dumb_ptr sd, } static -ATCE atcommand_chardropall(const int fd, dumb_ptr, +ATCE atcommand_chardropall(Session *s, dumb_ptr, ZString message) { CharName character; @@ -4368,15 +4386,15 @@ ATCE atcommand_chardropall(const int fd, dumb_ptr, } } - clif_displaymessage(pl_sd->fd, "Ever play 52 card pickup?"); - clif_displaymessage(fd, "It is done"); - //clif_displaymessage(fd, "It is offical.. your a jerk"); + clif_displaymessage(pl_sd->sess, "Ever play 52 card pickup?"); + clif_displaymessage(s, "It is done"); + //clif_displaymessage(s, "It is offical.. your a jerk"); return ATCE::OKAY; } static -ATCE atcommand_storeall(const int fd, dumb_ptr sd, +ATCE atcommand_storeall(Session *s, dumb_ptr sd, ZString) { int i; @@ -4388,11 +4406,11 @@ ATCE atcommand_storeall(const int fd, dumb_ptr sd, { case 2: //Try again - clif_displaymessage(fd, "run this command again.."); + clif_displaymessage(s, "run this command again.."); return ATCE::OKAY; case 1: //Failure - clif_displaymessage(fd, + clif_displaymessage(s, "You can't open the storage currently."); return ATCE::EXIST; } @@ -4408,12 +4426,12 @@ ATCE atcommand_storeall(const int fd, dumb_ptr sd, } storage_storageclose(sd); - clif_displaymessage(fd, "It is done"); + clif_displaymessage(s, "It is done"); return ATCE::OKAY; } static -ATCE atcommand_charstoreall(const int fd, dumb_ptr sd, +ATCE atcommand_charstoreall(Session *s, dumb_ptr sd, ZString message) { CharName character; @@ -4428,9 +4446,9 @@ ATCE atcommand_charstoreall(const int fd, dumb_ptr sd, { // TODO figure out what the hell this is talking about, // and especially why it's different from the other one. - clif_displaymessage(fd, + clif_displaymessage(s, "Had to open the characters storage window..."); - clif_displaymessage(fd, "run this command again.."); + clif_displaymessage(s, "run this command again.."); return ATCE::OKAY; } for (int i = 0; i < MAX_INVENTORY; i++) @@ -4444,19 +4462,19 @@ ATCE atcommand_charstoreall(const int fd, dumb_ptr sd, } storage_storageclose(pl_sd); - clif_displaymessage(pl_sd->fd, + clif_displaymessage(pl_sd->sess, "Everything you own has been put away for safe keeping."); - clif_displaymessage(pl_sd->fd, + clif_displaymessage(pl_sd->sess, "go to the nearest kafka to retrieve it.."); - clif_displaymessage(pl_sd->fd, " -- the management"); + clif_displaymessage(pl_sd->sess, " -- the management"); - clif_displaymessage(fd, "It is done"); + clif_displaymessage(s, "It is done"); return ATCE::OKAY; } static -ATCE atcommand_rain(const int, dumb_ptr sd, +ATCE atcommand_rain(Session *, dumb_ptr sd, ZString) { int effno = 0; @@ -4470,7 +4488,7 @@ ATCE atcommand_rain(const int, dumb_ptr sd, } static -ATCE atcommand_snow(const int, dumb_ptr sd, +ATCE atcommand_snow(Session *, dumb_ptr sd, ZString) { int effno = 0; @@ -4484,7 +4502,7 @@ ATCE atcommand_snow(const int, dumb_ptr sd, } static -ATCE atcommand_sakura(const int, dumb_ptr sd, +ATCE atcommand_sakura(Session *, dumb_ptr sd, ZString) { int effno = 0; @@ -4498,7 +4516,7 @@ ATCE atcommand_sakura(const int, dumb_ptr sd, } static -ATCE atcommand_fog(const int, dumb_ptr sd, +ATCE atcommand_fog(Session *, dumb_ptr sd, ZString) { int effno = 0; @@ -4513,7 +4531,7 @@ ATCE atcommand_fog(const int, dumb_ptr sd, } static -ATCE atcommand_leaves(const int, dumb_ptr sd, +ATCE atcommand_leaves(Session *, dumb_ptr sd, ZString) { int effno = 0; @@ -4527,7 +4545,7 @@ ATCE atcommand_leaves(const int, dumb_ptr sd, } static -ATCE atcommand_summon(const int, dumb_ptr sd, +ATCE atcommand_summon(Session *, dumb_ptr sd, ZString message) { MobName name; @@ -4565,7 +4583,7 @@ ATCE atcommand_summon(const int, dumb_ptr sd, } static -ATCE atcommand_adjcmdlvl(const int fd, dumb_ptr, +ATCE atcommand_adjcmdlvl(Session *s, dumb_ptr, ZString message) { int newlev; @@ -4573,7 +4591,7 @@ ATCE atcommand_adjcmdlvl(const int fd, dumb_ptr, if (!extract(message, record<' '>(&newlev, &cmd))) { - clif_displaymessage(fd, "usage: @adjcmdlvl ."); + clif_displaymessage(s, "usage: @adjcmdlvl ."); return ATCE::USAGE; } @@ -4582,17 +4600,17 @@ ATCE atcommand_adjcmdlvl(const int fd, dumb_ptr, if (it) { it->level = newlev; - clif_displaymessage(fd, "@command level changed."); + clif_displaymessage(s, "@command level changed."); return ATCE::OKAY; } } - clif_displaymessage(fd, "@command not found."); + clif_displaymessage(s, "@command not found."); return ATCE::EXIST; } static -ATCE atcommand_adjgmlvl(const int fd, dumb_ptr, +ATCE atcommand_adjgmlvl(Session *s, dumb_ptr, ZString message) { int newlev; @@ -4601,7 +4619,7 @@ ATCE atcommand_adjgmlvl(const int fd, dumb_ptr, if (!asplit(message, &newlev, &user) || newlev < 0 || newlev > 99) { - clif_displaymessage(fd, "usage: @adjgmlvl ."); + clif_displaymessage(s, "usage: @adjgmlvl ."); return ATCE::USAGE; } @@ -4615,7 +4633,7 @@ ATCE atcommand_adjgmlvl(const int fd, dumb_ptr, } static -ATCE atcommand_trade(const int, dumb_ptr sd, +ATCE atcommand_trade(Session *, dumb_ptr sd, ZString message) { CharName character; @@ -4660,7 +4678,7 @@ ZString magic_skill_names[magic_skills_nr] = }; static -ATCE atcommand_magic_info(const int fd, dumb_ptr, +ATCE atcommand_magic_info(Session *s, dumb_ptr, ZString message) { CharName character; @@ -4674,7 +4692,7 @@ ATCE atcommand_magic_info(const int fd, dumb_ptr, FString buf = STRPRINTF( "`%s' has the following magic skills:", character); - clif_displaymessage(fd, buf); + clif_displaymessage(s, buf); for (size_t i = 0; i < magic_skills_nr; i++) { @@ -4684,13 +4702,13 @@ ATCE atcommand_magic_info(const int fd, dumb_ptr, pl_sd->status.skill[sk].lv, magic_skill_names[i]); if (pl_sd->status.skill[sk].lv) - clif_displaymessage(fd, buf); + clif_displaymessage(s, buf); } return ATCE::OKAY; } - clif_displaymessage(fd, "Character not found."); + clif_displaymessage(s, "Character not found."); return ATCE::EXIST; } @@ -4701,7 +4719,7 @@ void set_skill(dumb_ptr sd, SkillID i, int level) } static -ATCE atcommand_set_magic(const int fd, dumb_ptr, +ATCE atcommand_set_magic(Session *s, dumb_ptr, ZString message) { CharName character; @@ -4710,7 +4728,7 @@ ATCE atcommand_set_magic(const int fd, dumb_ptr, if (!asplit(message, &magic_type, &value, &character)) { - clif_displaymessage(fd, + clif_displaymessage(s, "Usage: @setmagic , where is either `magic', one of the school names, or `all'."); return ATCE::USAGE; } @@ -4732,7 +4750,7 @@ ATCE atcommand_set_magic(const int fd, dumb_ptr, if (skill_index == SkillID::NEGATIVE) { - clif_displaymessage(fd, + clif_displaymessage(s, "Incorrect school of magic. Use `magic', `nature', `life', `war', `transmute', `ether', or `all'."); return ATCE::RANGE; } @@ -4750,12 +4768,12 @@ ATCE atcommand_set_magic(const int fd, dumb_ptr, return ATCE::OKAY; } - clif_displaymessage(fd, "Character not found."); + clif_displaymessage(s, "Character not found."); return ATCE::EXIST; } static -ATCE atcommand_log(const int, dumb_ptr, +ATCE atcommand_log(Session *, dumb_ptr, ZString) { return ATCE::OKAY; @@ -4763,7 +4781,7 @@ ATCE atcommand_log(const int, dumb_ptr, } static -ATCE atcommand_tee(const int, dumb_ptr sd, +ATCE atcommand_tee(Session *, dumb_ptr sd, ZString message) { MString data; @@ -4775,7 +4793,7 @@ ATCE atcommand_tee(const int, dumb_ptr sd, } static -ATCE atcommand_invisible(const int, dumb_ptr sd, +ATCE atcommand_invisible(Session *, dumb_ptr sd, ZString) { pc_invisibility(sd, 1); @@ -4783,7 +4801,7 @@ ATCE atcommand_invisible(const int, dumb_ptr sd, } static -ATCE atcommand_visible(const int, dumb_ptr sd, +ATCE atcommand_visible(Session *, dumb_ptr sd, ZString) { pc_invisibility(sd, 0); @@ -4791,7 +4809,7 @@ ATCE atcommand_visible(const int, dumb_ptr sd, } static -ATCE atcommand_jump_iterate(const int fd, dumb_ptr sd, +ATCE atcommand_jump_iterate(Session *s, dumb_ptr sd, dumb_ptr (*get_start)(void), dumb_ptr (*get_next)(dumb_ptr)) { @@ -4815,20 +4833,20 @@ ATCE atcommand_jump_iterate(const int fd, dumb_ptr sd, if (pl_sd->bl_m && pl_sd->bl_m->flag.nowarpto && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { - clif_displaymessage(fd, + clif_displaymessage(s, "You are not authorised to warp you to the map of this player."); return ATCE::PERM; } if (sd->bl_m && sd->bl_m->flag.nowarp && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { - clif_displaymessage(fd, + clif_displaymessage(s, "You are not authorised to warp you from your actual map."); return ATCE::PERM; } pc_setpos(sd, pl_sd->bl_m->name_, pl_sd->bl_x, pl_sd->bl_y, BeingRemoveWhy::WARPED); FString output = STRPRINTF("Jump to %s", pl_sd->status.name); - clif_displaymessage(fd, output); + clif_displaymessage(s, output); sd->followtarget = pl_sd->bl_id; @@ -4836,19 +4854,19 @@ ATCE atcommand_jump_iterate(const int fd, dumb_ptr sd, } static -ATCE atcommand_iterate_forward_over_players(const int fd, dumb_ptr sd, ZString) +ATCE atcommand_iterate_forward_over_players(Session *s, dumb_ptr sd, ZString) { - return atcommand_jump_iterate(fd, sd, map_get_first_session, map_get_next_session); + return atcommand_jump_iterate(s, sd, map_get_first_session, map_get_next_session); } static -ATCE atcommand_iterate_backwards_over_players(const int fd, dumb_ptr sd, ZString) +ATCE atcommand_iterate_backwards_over_players(Session *s, dumb_ptr sd, ZString) { - return atcommand_jump_iterate(fd, sd, map_get_last_session, map_get_prev_session); + return atcommand_jump_iterate(s, sd, map_get_last_session, map_get_prev_session); } static -ATCE atcommand_wgm(const int fd, dumb_ptr sd, +ATCE atcommand_wgm(Session *s, dumb_ptr sd, ZString message) { if (tmw_CheckChatSpam(sd, message)) @@ -4856,14 +4874,14 @@ ATCE atcommand_wgm(const int fd, dumb_ptr sd, tmw_GmHackMsg(STRPRINTF("[GM] %s: %s", sd->status.name, message)); if (!pc_isGM(sd)) - clif_displaymessage(fd, "Message sent."); + clif_displaymessage(s, "Message sent."); return ATCE::OKAY; } static -ATCE atcommand_skillpool_info(const int fd, dumb_ptr, +ATCE atcommand_skillpool_info(Session *s, dumb_ptr, ZString message) { CharName character; @@ -4881,19 +4899,19 @@ ATCE atcommand_skillpool_info(const int fd, dumb_ptr, FString buf = STRPRINTF( "Active skills %d out of %d for %s:", pool_skills_nr, skill_pool_max(pl_sd), character); - clif_displaymessage(fd, buf); + clif_displaymessage(s, buf); for (i = 0; i < pool_skills_nr; ++i) { buf = STRPRINTF(" - %s [%d]: power %d", skill_name(pool_skills[i]), pool_skills[i], skill_power(pl_sd, pool_skills[i])); - clif_displaymessage(fd, buf); + clif_displaymessage(s, buf); } buf = STRPRINTF("Learned skills out of %d for %s:", skill_pool_skills_size, character); - clif_displaymessage(fd, buf); + clif_displaymessage(s, buf); for (i = 0; i < skill_pool_skills_size; ++i) { @@ -4904,14 +4922,14 @@ ATCE atcommand_skillpool_info(const int fd, dumb_ptr, { buf = STRPRINTF(" - %s [%d]: lvl %d", name, skill_pool_skills[i], lvl); - clif_displaymessage(fd, buf); + clif_displaymessage(s, buf); } } } else { - clif_displaymessage(fd, "Character not found."); + clif_displaymessage(s, "Character not found."); return ATCE::EXIST; } @@ -4919,7 +4937,7 @@ ATCE atcommand_skillpool_info(const int fd, dumb_ptr, } static -ATCE atcommand_skillpool_focus(const int fd, dumb_ptr, +ATCE atcommand_skillpool_focus(Session *s, dumb_ptr, ZString message) { CharName character; @@ -4927,7 +4945,7 @@ ATCE atcommand_skillpool_focus(const int fd, dumb_ptr, if (!asplit(message, &skill, &character)) { - clif_displaymessage(fd, "Usage: @sp-focus "); + clif_displaymessage(s, "Usage: @sp-focus "); return ATCE::USAGE; } @@ -4935,18 +4953,18 @@ ATCE atcommand_skillpool_focus(const int fd, dumb_ptr, if (pl_sd != NULL) { if (skill_pool_activate(pl_sd, skill)) - clif_displaymessage(fd, "Activation failed."); + clif_displaymessage(s, "Activation failed."); else - clif_displaymessage(fd, "Activation successful."); + clif_displaymessage(s, "Activation successful."); } else - clif_displaymessage(fd, "Character not found."); + clif_displaymessage(s, "Character not found."); return ATCE::OKAY; } static -ATCE atcommand_skillpool_unfocus(const int fd, dumb_ptr, +ATCE atcommand_skillpool_unfocus(Session *s, dumb_ptr, ZString message) { CharName character; @@ -4959,18 +4977,18 @@ ATCE atcommand_skillpool_unfocus(const int fd, dumb_ptr, if (pl_sd != NULL) { if (skill_pool_deactivate(pl_sd, skill)) - clif_displaymessage(fd, "Deactivation failed."); + clif_displaymessage(s, "Deactivation failed."); else - clif_displaymessage(fd, "Deactivation successful."); + clif_displaymessage(s, "Deactivation successful."); } else - clif_displaymessage(fd, "Character not found."); + clif_displaymessage(s, "Character not found."); return ATCE::OKAY; } //static -ATCE atcommand_skill_learn(const int fd, dumb_ptr, +ATCE atcommand_skill_learn(Session *s, dumb_ptr, ZString message) { CharName character; @@ -4987,13 +5005,13 @@ ATCE atcommand_skill_learn(const int fd, dumb_ptr, clif_skillinfoblock(pl_sd); } else - clif_displaymessage(fd, "Character not found."); + clif_displaymessage(s, "Character not found."); return ATCE::OKAY; } static -ATCE atcommand_ipcheck(const int fd, dumb_ptr, +ATCE atcommand_ipcheck(Session *s, dumb_ptr, ZString message) { CharName character; @@ -5004,7 +5022,7 @@ ATCE atcommand_ipcheck(const int fd, dumb_ptr, dumb_ptr pl_sd = map_nick2sd(character); if (pl_sd == NULL) { - clif_displaymessage(fd, "Character not found."); + clif_displaymessage(s, "Character not found."); return ATCE::EXIST; } @@ -5015,9 +5033,10 @@ ATCE atcommand_ipcheck(const int fd, dumb_ptr, for (int i = 0; i < fd_max; i++) { - if (!session[i]) + Session *s2 = session[i].get(); + if (!s2) continue; - pl_sd = dumb_ptr(static_cast(session[i]->session_data.get())); + pl_sd = dumb_ptr(static_cast(s2->session_data.get())); if (pl_sd && pl_sd->state.auth) { // Is checking GM levels really needed here? @@ -5027,35 +5046,36 @@ ATCE atcommand_ipcheck(const int fd, dumb_ptr, "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); + clif_displaymessage(s, output); } } } - clif_displaymessage(fd, "End of list"); + clif_displaymessage(s, "End of list"); return ATCE::OKAY; } static -ATCE atcommand_doomspot(const int fd, dumb_ptr sd, +ATCE atcommand_doomspot(Session *s, dumb_ptr sd, ZString) { for (int i = 0; i < fd_max; i++) { - if (!session[i]) + Session *s2 = session[i].get(); + if (!s2) continue; - dumb_ptr pl_sd = dumb_ptr(static_cast(session[i]->session_data.get())); + dumb_ptr pl_sd = dumb_ptr(static_cast(s2->session_data.get())); if (pl_sd - && pl_sd->state.auth && i != fd && sd->bl_m == pl_sd->bl_m + && pl_sd->state.auth && s2 != s && sd->bl_m == pl_sd->bl_m && sd->bl_x == pl_sd->bl_x && sd->bl_y == pl_sd->bl_y && pc_isGM(sd) >= pc_isGM(pl_sd)) { // you can doom only lower or same gm level pc_damage(NULL, pl_sd, pl_sd->status.hp + 1); - clif_displaymessage(pl_sd->fd, "The holy messenger has given judgement."); + clif_displaymessage(pl_sd->sess, "The holy messenger has given judgement."); } } - clif_displaymessage(fd, "Judgement was made."); + clif_displaymessage(s, "Judgement was made."); return ATCE::OKAY; } diff --git a/src/map/atcommand.hpp b/src/map/atcommand.hpp index b494a25..a18b035 100644 --- a/src/map/atcommand.hpp +++ b/src/map/atcommand.hpp @@ -7,7 +7,7 @@ # include "map.hpp" -bool is_atcommand(const int fd, dumb_ptr sd, +bool is_atcommand(Session *s, dumb_ptr sd, ZString message, int gmlvl); bool atcommand_config_read(ZString cfgName); diff --git a/src/map/chrif.cpp b/src/map/chrif.cpp index 5b9f96f..959186c 100644 --- a/src/map/chrif.cpp +++ b/src/map/chrif.cpp @@ -34,7 +34,7 @@ const int packet_len_table[0x20] = -1, -1, 10, 6, 11, -1, 0, 0, // 2b10-2b17 }; -int char_fd; +Session *char_session; static IP4Address char_ip; static @@ -105,17 +105,17 @@ int chrif_save(dumb_ptr sd) { nullpo_retr(-1, sd); - if (char_fd < 0) + if (!char_session) return -1; pc_makesavestatus(sd); - WFIFOW(char_fd, 0) = 0x2b01; - WFIFOW(char_fd, 2) = sizeof(sd->status) + 12; - WFIFOL(char_fd, 4) = sd->bl_id; - WFIFOL(char_fd, 8) = sd->char_id; - WFIFO_STRUCT(char_fd, 12, sd->status); - WFIFOSET(char_fd, WFIFOW(char_fd, 2)); + WFIFOW(char_session, 0) = 0x2b01; + WFIFOW(char_session, 2) = sizeof(sd->status) + 12; + WFIFOL(char_session, 4) = sd->bl_id; + WFIFOL(char_session, 8) = sd->char_id; + WFIFO_STRUCT(char_session, 12, sd->status); + WFIFOSET(char_session, WFIFOW(char_session, 2)); //For data sync if (sd->state.storage_open) @@ -129,15 +129,15 @@ int chrif_save(dumb_ptr sd) *------------------------------------------ */ static -int chrif_connect(int fd) +int chrif_connect(Session *s) { - WFIFOW(fd, 0) = 0x2af8; - WFIFO_STRING(fd, 2, userid, 24); - WFIFO_STRING(fd, 26, passwd, 24); - WFIFOL(fd, 50) = 0; - WFIFOIP(fd, 54) = clif_getip(); - WFIFOW(fd, 58) = clif_getport(); // [Valaris] thanks to fov - WFIFOSET(fd, 60); + WFIFOW(s, 0) = 0x2af8; + WFIFO_STRING(s, 2, userid, 24); + WFIFO_STRING(s, 26, passwd, 24); + WFIFOL(s, 50) = 0; + WFIFOIP(s, 54) = clif_getip(); + WFIFOW(s, 58) = clif_getport(); // [Valaris] thanks to fov + WFIFOSET(s, 60); return 0; } @@ -147,21 +147,21 @@ int chrif_connect(int fd) *------------------------------------------ */ static -int chrif_sendmap(int fd) +int chrif_sendmap(Session *s) { int i = 0; - WFIFOW(fd, 0) = 0x2afa; + WFIFOW(s, 0) = 0x2afa; for (auto& pair : maps_db) { map_abstract *ma = pair.second.get(); if (!ma->gat) continue; - WFIFO_STRING(fd, 4 + i * 16, ma->name_, 16); + WFIFO_STRING(s, 4 + i * 16, ma->name_, 16); i++; } - WFIFOW(fd, 2) = 4 + i * 16; - WFIFOSET(fd, WFIFOW(fd, 2)); + WFIFOW(s, 2) = 4 + i * 16; + WFIFOSET(s, WFIFOW(s, 2)); return 0; } @@ -171,18 +171,18 @@ int chrif_sendmap(int fd) *------------------------------------------ */ static -int chrif_recvmap(int fd) +int chrif_recvmap(Session *s) { int i, j; if (chrif_state < 2) // まだ準備中 return -1; - IP4Address ip = RFIFOIP(fd, 4); - uint16_t port = RFIFOW(fd, 8); - for (i = 10, j = 0; i < RFIFOW(fd, 2); i += 16, j++) + IP4Address ip = RFIFOIP(s, 4); + uint16_t port = RFIFOW(s, 8); + for (i = 10, j = 0; i < RFIFOW(s, 2); i += 16, j++) { - MapName map = RFIFO_STRING<16>(fd, i); + MapName map = RFIFO_STRING<16>(s, i); map_setipport(map, ip, port); } if (battle_config.etc_log) @@ -203,26 +203,31 @@ int chrif_changemapserver(dumb_ptr sd, IP4Address s_ip; for (int i = 0; i < fd_max; i++) - if (session[i] && dumb_ptr(static_cast(session[i]->session_data.get())) == sd) + { + Session *s = session[i].get(); + if (!s) + continue; + if (dumb_ptr(static_cast(s->session_data.get())) == sd) { - assert (i == sd->fd); + assert (s == sd->sess); s_ip = session[i]->client_ip; break; } + } - WFIFOW(char_fd, 0) = 0x2b05; - WFIFOL(char_fd, 2) = sd->bl_id; - WFIFOL(char_fd, 6) = sd->login_id1; - WFIFOL(char_fd, 10) = sd->login_id2; - WFIFOL(char_fd, 14) = sd->status.char_id; - WFIFO_STRING(char_fd, 18, name, 16); - WFIFOW(char_fd, 34) = x; - WFIFOW(char_fd, 36) = y; - WFIFOIP(char_fd, 38) = ip; - WFIFOL(char_fd, 42) = port; - WFIFOB(char_fd, 44) = static_cast(sd->status.sex); - WFIFOIP(char_fd, 45) = s_ip; - WFIFOSET(char_fd, 49); + WFIFOW(char_session, 0) = 0x2b05; + WFIFOL(char_session, 2) = sd->bl_id; + WFIFOL(char_session, 6) = sd->login_id1; + WFIFOL(char_session, 10) = sd->login_id2; + WFIFOL(char_session, 14) = sd->status.char_id; + WFIFO_STRING(char_session, 18, name, 16); + WFIFOW(char_session, 34) = x; + WFIFOW(char_session, 36) = y; + WFIFOIP(char_session, 38) = ip; + WFIFOL(char_session, 42) = port; + WFIFOB(char_session, 44) = static_cast(sd->status.sex); + WFIFOIP(char_session, 45) = s_ip; + WFIFOSET(char_session, 49); return 0; } @@ -232,25 +237,25 @@ int chrif_changemapserver(dumb_ptr sd, *------------------------------------------ */ static -int chrif_changemapserverack(int fd) +int chrif_changemapserverack(Session *s) { - dumb_ptr sd = map_id2sd(RFIFOL(fd, 2)); + dumb_ptr sd = map_id2sd(RFIFOL(s, 2)); - if (sd == NULL || sd->status.char_id != RFIFOL(fd, 14)) + if (sd == NULL || sd->status.char_id != RFIFOL(s, 14)) return -1; - if (RFIFOL(fd, 6) == 1) + if (RFIFOL(s, 6) == 1) { if (battle_config.error_log) PRINTF("map server change failed.\n"); - pc_authfail(sd->fd); + pc_authfail(sd->status.account_id); return 0; } - MapName mapname = RFIFO_STRING<16>(fd, 18); - uint16_t x = RFIFOW(fd, 34); - uint16_t y = RFIFOW(fd, 36); - IP4Address ip = RFIFOIP(fd, 38); - uint16_t port = RFIFOW(fd, 42); + MapName mapname = RFIFO_STRING<16>(s, 18); + uint16_t x = RFIFOW(s, 34); + uint16_t y = RFIFOW(s, 36); + IP4Address ip = RFIFOIP(s, 38); + uint16_t port = RFIFOW(s, 42); clif_changemapserver(sd, mapname, x, y, ip, port); return 0; @@ -261,17 +266,17 @@ int chrif_changemapserverack(int fd) *------------------------------------------ */ static -int chrif_connectack(int fd) +int chrif_connectack(Session *s) { - if (RFIFOB(fd, 2)) + if (RFIFOB(s, 2)) { - PRINTF("Connected to char-server failed %d.\n", RFIFOB(fd, 2)); + PRINTF("Connected to char-server failed %d.\n", RFIFOB(s, 2)); exit(1); } - PRINTF("Connected to char-server (connection #%d).\n", fd); + PRINTF("Connected to char-server (connection #%d).\n", s); chrif_state = 1; - chrif_sendmap(fd); + chrif_sendmap(s); PRINTF("chrif: OnCharIfInit event done. (%d events)\n", npc_event_doall(stringish("OnCharIfInit"))); @@ -289,16 +294,16 @@ int chrif_connectack(int fd) *------------------------------------------ */ static -int chrif_sendmapack(int fd) +int chrif_sendmapack(Session *s) { - if (RFIFOB(fd, 2)) + if (RFIFOB(s, 2)) { PRINTF("chrif : send map list to char server failed %d\n", - RFIFOB(fd, 2)); + RFIFOB(s, 2)); exit(1); } - wisp_server_name = stringish(RFIFO_STRING<24>(fd, 3)); + wisp_server_name = stringish(RFIFO_STRING<24>(s, 3)); chrif_state = 2; @@ -313,22 +318,27 @@ int chrif_authreq(dumb_ptr sd) { nullpo_retr(-1, sd); - if (!sd || !char_fd || !sd->bl_id || !sd->login_id1) + if (!sd || !char_session || !sd->bl_id || !sd->login_id1) return -1; for (int i = 0; i < fd_max; i++) - if (session[i] && dumb_ptr(static_cast(session[i]->session_data.get())) == sd) + { + Session *s = session[i].get(); + if (!s) + continue; + if (dumb_ptr(static_cast(session[i]->session_data.get())) == sd) { - assert (i == sd->fd); - WFIFOW(char_fd, 0) = 0x2afc; - WFIFOL(char_fd, 2) = sd->bl_id; - WFIFOL(char_fd, 6) = sd->char_id; - WFIFOL(char_fd, 10) = sd->login_id1; - WFIFOL(char_fd, 14) = sd->login_id2; - WFIFOIP(char_fd, 18) = session[i]->client_ip; - WFIFOSET(char_fd, 22); + assert (s == sd->sess); + WFIFOW(char_session, 0) = 0x2afc; + WFIFOL(char_session, 2) = sd->bl_id; + WFIFOL(char_session, 6) = sd->char_id; + WFIFOL(char_session, 10) = sd->login_id1; + WFIFOL(char_session, 14) = sd->login_id2; + WFIFOIP(char_session, 18) = session[i]->client_ip; + WFIFOSET(char_session, 22); break; } + } return 0; } @@ -341,24 +351,29 @@ int chrif_charselectreq(dumb_ptr sd) { nullpo_retr(-1, sd); - if (!sd || !char_fd || !sd->bl_id || !sd->login_id1) + if (!sd || !char_session || !sd->bl_id || !sd->login_id1) return -1; IP4Address s_ip; for (int i = 0; i < fd_max; i++) - if (session[i] && dumb_ptr(static_cast(session[i]->session_data.get())) == sd) + { + Session *s = session[i].get(); + if (!s) + continue; + if (dumb_ptr(static_cast(s->session_data.get())) == sd) { - assert (i == sd->fd); - s_ip = session[i]->client_ip; + assert (s == sd->sess); + s_ip = s->client_ip; break; } + } - WFIFOW(char_fd, 0) = 0x2b02; - WFIFOL(char_fd, 2) = sd->bl_id; - WFIFOL(char_fd, 6) = sd->login_id1; - WFIFOL(char_fd, 10) = sd->login_id2; - WFIFOIP(char_fd, 14) = s_ip; - WFIFOSET(char_fd, 18); + WFIFOW(char_session, 0) = 0x2b02; + WFIFOL(char_session, 2) = sd->bl_id; + WFIFOL(char_session, 6) = sd->login_id1; + WFIFOL(char_session, 10) = sd->login_id2; + WFIFOIP(char_session, 14) = s_ip; + WFIFOSET(char_session, 18); return 0; } @@ -373,11 +388,11 @@ void chrif_changegm(int id, ZString pass) PRINTF("chrif_changegm: account: %d, password: '%s'.\n", id, pass); size_t len = pass.size() + 1; - WFIFOW(char_fd, 0) = 0x2b0a; - WFIFOW(char_fd, 2) = len + 8; - WFIFOL(char_fd, 4) = id; - WFIFO_STRING(char_fd, 8, pass, len); - WFIFOSET(char_fd, len + 8); + WFIFOW(char_session, 0) = 0x2b0a; + WFIFOW(char_session, 2) = len + 8; + WFIFOL(char_session, 4) = id; + WFIFO_STRING(char_session, 8, pass, len); + WFIFOSET(char_session, len + 8); } /*========================================== @@ -391,11 +406,11 @@ void chrif_changeemail(int id, AccountEmail actual_email, PRINTF("chrif_changeemail: account: %d, actual_email: '%s', new_email: '%s'.\n", id, actual_email, new_email); - WFIFOW(char_fd, 0) = 0x2b0c; - WFIFOL(char_fd, 2) = id; - WFIFO_STRING(char_fd, 6, actual_email, 40); - WFIFO_STRING(char_fd, 46, new_email, 40); - WFIFOSET(char_fd, 86); + WFIFOW(char_session, 0) = 0x2b0c; + WFIFOL(char_session, 2) = id; + WFIFO_STRING(char_session, 6, actual_email, 40); + WFIFO_STRING(char_session, 46, new_email, 40); + WFIFOSET(char_session, 86); } /*========================================== @@ -412,14 +427,14 @@ void chrif_changeemail(int id, AccountEmail actual_email, void chrif_char_ask_name(int id, CharName character_name, short operation_type, HumanTimeDiff modif) { - WFIFOW(char_fd, 0) = 0x2b0e; - WFIFOL(char_fd, 2) = id; // account_id of who ask (for answer) -1 if nobody - WFIFO_STRING(char_fd, 6, character_name.to__actual(), 24); - WFIFOW(char_fd, 30) = operation_type; // type of operation + WFIFOW(char_session, 0) = 0x2b0e; + WFIFOL(char_session, 2) = id; // account_id of who ask (for answer) -1 if nobody + WFIFO_STRING(char_session, 6, character_name.to__actual(), 24); + WFIFOW(char_session, 30) = operation_type; // type of operation if (operation_type == 2) - WFIFO_STRUCT(char_fd, 32, modif); + WFIFO_STRUCT(char_session, 32, modif); PRINTF("chrif : sended 0x2b0e\n"); - WFIFOSET(char_fd, 44); + WFIFOSET(char_session, 44); } /*========================================== @@ -439,24 +454,24 @@ void chrif_char_ask_name(int id, CharName character_name, short operation_type, *------------------------------------------ */ static -int chrif_char_ask_name_answer(int fd) +int chrif_char_ask_name_answer(Session *s) { - int acc = RFIFOL(fd, 2); // account_id of who has asked (-1 if nobody) - CharName player_name = stringish(RFIFO_STRING<24>(fd, 6)); + int acc = RFIFOL(s, 2); // account_id of who has asked (-1 if nobody) + CharName player_name = stringish(RFIFO_STRING<24>(s, 6)); dumb_ptr sd = map_id2sd(acc); if (acc >= 0 && sd != NULL) { FString output; - if (RFIFOW(fd, 32) == 1) // player not found + if (RFIFOW(s, 32) == 1) // player not found output = STRPRINTF("The player '%s' doesn't exist.", player_name); else { - switch (RFIFOW(fd, 30)) + switch (RFIFOW(s, 30)) { case 1: // block - switch (RFIFOW(fd, 32)) + switch (RFIFOW(s, 32)) { case 0: // login-server resquest done output = STRPRINTF( @@ -477,7 +492,7 @@ int chrif_char_ask_name_answer(int fd) } break; case 2: // ban - switch (RFIFOW(fd, 32)) + switch (RFIFOW(s, 32)) { case 0: // login-server resquest done output = STRPRINTF( @@ -498,7 +513,7 @@ int chrif_char_ask_name_answer(int fd) } break; case 3: // unblock - switch (RFIFOW(fd, 32)) + switch (RFIFOW(s, 32)) { case 0: // login-server resquest done output = STRPRINTF( @@ -519,7 +534,7 @@ int chrif_char_ask_name_answer(int fd) } break; case 4: // unban - switch (RFIFOW(fd, 32)) + switch (RFIFOW(s, 32)) { case 0: // login-server resquest done output = STRPRINTF( @@ -540,7 +555,7 @@ int chrif_char_ask_name_answer(int fd) } break; case 5: // changesex - switch (RFIFOW(fd, 32)) + switch (RFIFOW(s, 32)) { case 0: // login-server resquest done output = STRPRINTF( @@ -563,7 +578,7 @@ int chrif_char_ask_name_answer(int fd) } } if (output) - clif_displaymessage(sd->fd, output); + clif_displaymessage(sd->sess, output); } else PRINTF("chrif_char_ask_name_answer failed - player not online.\n"); @@ -576,13 +591,13 @@ int chrif_char_ask_name_answer(int fd) *------------------------------------------ */ static -void chrif_changedgm(int fd) +void chrif_changedgm(Session *s) { int acc, level; dumb_ptr sd = NULL; - acc = RFIFOL(fd, 2); - level = RFIFOL(fd, 6); + acc = RFIFOL(s, 2); + level = RFIFOL(s, 6); sd = map_id2sd(acc); @@ -592,9 +607,9 @@ void chrif_changedgm(int fd) if (sd != NULL) { if (level > 0) - clif_displaymessage(sd->fd, "GM modification success."); + clif_displaymessage(sd->sess, "GM modification success."); else - clif_displaymessage(sd->fd, "Failure of GM modification."); + clif_displaymessage(sd->sess, "Failure of GM modification."); } } @@ -603,13 +618,13 @@ void chrif_changedgm(int fd) *------------------------------------------ */ static -void chrif_changedsex(int fd) +void chrif_changedsex(Session *s) { int acc, i; dumb_ptr sd; - acc = RFIFOL(fd, 2); - SEX sex = static_cast(RFIFOB(fd, 6)); + acc = RFIFOL(s, 2); + SEX sex = static_cast(RFIFOB(s, 6)); if (battle_config.etc_log) PRINTF("chrif_changedsex %d.\n", acc); sd = map_id2sd(acc); @@ -632,9 +647,9 @@ void chrif_changedsex(int fd) chrif_save(sd); sd->login_id1++; // change identify, because if player come back in char within the 5 seconds, he can change its characters // do same modify in login-server for the account, but no in char-server (it ask again login_id1 to login, and don't remember it) - clif_displaymessage(sd->fd, + clif_displaymessage(sd->sess, "Your sex has been changed (need disconexion by the server)..."); - clif_setwaitclose(sd->fd); // forced to disconnect for the change + clif_setwaitclose(sd->sess); // forced to disconnect for the change } } else @@ -661,15 +676,15 @@ int chrif_saveaccountreg2(dumb_ptr sd) struct global_reg *reg = &sd->status.account_reg2[j]; if (reg->str && reg->value != 0) { - WFIFO_STRING(char_fd, p, reg->str, 32); - WFIFOL(char_fd, p + 32) = reg->value; + WFIFO_STRING(char_session, p, reg->str, 32); + WFIFOL(char_session, p + 32) = reg->value; p += 36; } } - WFIFOW(char_fd, 0) = 0x2b10; - WFIFOW(char_fd, 2) = p; - WFIFOL(char_fd, 4) = sd->bl_id; - WFIFOSET(char_fd, p); + WFIFOW(char_session, 0) = 0x2b10; + WFIFOW(char_session, 2) = p; + WFIFOL(char_session, 4) = sd->bl_id; + WFIFOSET(char_session, p); return 0; } @@ -679,19 +694,18 @@ int chrif_saveaccountreg2(dumb_ptr sd) *------------------------------------------ */ static -int chrif_accountreg2(int fd) +int chrif_accountreg2(Session *s) { int j, p; - dumb_ptr sd; - - if ((sd = map_id2sd(RFIFOL(fd, 4))) == NULL) + dumb_ptr sd = map_id2sd(RFIFOL(s, 4)); + if (sd == NULL) return 1; - for (p = 8, j = 0; p < RFIFOW(fd, 2) && j < ACCOUNT_REG2_NUM; + for (p = 8, j = 0; p < RFIFOW(s, 2) && j < ACCOUNT_REG2_NUM; p += 36, j++) { - sd->status.account_reg2[j].str = stringish(RFIFO_STRING<32>(fd, p)); - sd->status.account_reg2[j].value = RFIFOL(fd, p + 32); + sd->status.account_reg2[j].str = stringish(RFIFO_STRING<32>(s, p)); + sd->status.account_reg2[j].value = RFIFOL(s, p + 32); } sd->status.account_reg2_num = j; @@ -739,12 +753,12 @@ int chrif_divorce(int char_id, int partner_id) */ int chrif_send_divorce(int char_id) { - if (char_fd < 0) + if (!char_session) return -1; - WFIFOW(char_fd, 0) = 0x2b16; - WFIFOL(char_fd, 2) = char_id; - WFIFOSET(char_fd, 6); + WFIFOW(char_session, 0) = 0x2b16; + WFIFOL(char_session, 2) = char_id; + WFIFOSET(char_session, 6); return 0; } @@ -753,12 +767,12 @@ int chrif_send_divorce(int char_id) *------------------------------------------ */ static -int chrif_accountdeletion(int fd) +int chrif_accountdeletion(Session *s) { int acc; dumb_ptr sd; - acc = RFIFOL(fd, 2); + acc = RFIFOL(s, 2); if (battle_config.etc_log) PRINTF("chrif_accountdeletion %d.\n", acc); sd = map_id2sd(acc); @@ -767,9 +781,9 @@ int chrif_accountdeletion(int fd) if (sd != NULL) { sd->login_id1++; // change identify, because if player come back in char within the 5 seconds, he can change its characters - clif_displaymessage(sd->fd, + clif_displaymessage(sd->sess, "Your account has been deleted (disconnection)..."); - clif_setwaitclose(sd->fd); // forced to disconnect for the change + clif_setwaitclose(sd->sess); // forced to disconnect for the change } } else @@ -786,12 +800,12 @@ int chrif_accountdeletion(int fd) *------------------------------------------ */ static -int chrif_accountban(int fd) +int chrif_accountban(Session *s) { int acc; dumb_ptr sd; - acc = RFIFOL(fd, 2); + acc = RFIFOL(s, 2); if (battle_config.etc_log) PRINTF("chrif_accountban %d.\n", acc); sd = map_id2sd(acc); @@ -800,65 +814,65 @@ int chrif_accountban(int fd) if (sd != NULL) { sd->login_id1++; // change identify, because if player come back in char within the 5 seconds, he can change its characters - if (RFIFOB(fd, 6) == 0) + if (RFIFOB(s, 6) == 0) { // 0: change of statut, 1: ban - switch (RFIFOL(fd, 7)) + switch (RFIFOL(s, 7)) { // status or final date of a banishment case 1: // 0 = Unregistered ID - clif_displaymessage(sd->fd, + clif_displaymessage(sd->sess, "Your account has 'Unregistered'."); break; case 2: // 1 = Incorrect Password - clif_displaymessage(sd->fd, + clif_displaymessage(sd->sess, "Your account has an 'Incorrect Password'..."); break; case 3: // 2 = This ID is expired - clif_displaymessage(sd->fd, + clif_displaymessage(sd->sess, "Your account has expired."); break; case 4: // 3 = Rejected from Server - clif_displaymessage(sd->fd, + clif_displaymessage(sd->sess, "Your account has been rejected from server."); break; case 5: // 4 = You have been blocked by the GM Team - clif_displaymessage(sd->fd, + clif_displaymessage(sd->sess, "Your account has been blocked by the GM Team."); break; case 6: // 5 = Your Game's EXE file is not the latest version - clif_displaymessage(sd->fd, + clif_displaymessage(sd->sess, "Your Game's EXE file is not the latest version."); break; case 7: // 6 = Your are Prohibited to log in until %s - clif_displaymessage(sd->fd, + clif_displaymessage(sd->sess, "Your account has been prohibited to log in."); break; case 8: // 7 = Server is jammed due to over populated - clif_displaymessage(sd->fd, + clif_displaymessage(sd->sess, "Server is jammed due to over populated."); break; case 9: // 8 = No MSG (actually, all states after 9 except 99 are No MSG, use only this) - clif_displaymessage(sd->fd, + clif_displaymessage(sd->sess, "Your account has not more authorised."); break; case 100: // 99 = This ID has been totally erased - clif_displaymessage(sd->fd, + clif_displaymessage(sd->sess, "Your account has been totally erased."); break; default: - clif_displaymessage(sd->fd, + clif_displaymessage(sd->sess, "Your account has not more authorised."); break; } } - else if (RFIFOB(fd, 6) == 1) + else if (RFIFOB(s, 6) == 1) { // 0: change of statut, 1: ban - TimeT timestamp = static_cast(RFIFOL(fd, 7)); // status or final date of a banishment + TimeT timestamp = static_cast(RFIFOL(s, 7)); // status or final date of a banishment char tmpstr[] = WITH_TIMESTAMP("Your account has been banished until "); REPLACE_TIMESTAMP(tmpstr, timestamp); - clif_displaymessage(sd->fd, const_(tmpstr)); + clif_displaymessage(sd->sess, const_(tmpstr)); } - clif_setwaitclose(sd->fd); // forced to disconnect for the change + clif_setwaitclose(sd->sess); // forced to disconnect for the change } } else @@ -875,10 +889,10 @@ int chrif_accountban(int fd) *------------------------------------------ */ static -int chrif_recvgmaccounts(int fd) +int chrif_recvgmaccounts(Session *s) { PRINTF("From login-server: receiving of %d GM accounts information.\n", - pc_read_gm_account(fd)); + pc_read_gm_account(s)); return 0; } @@ -890,8 +904,8 @@ int chrif_recvgmaccounts(int fd) int chrif_reloadGMdb(void) { - WFIFOW(char_fd, 0) = 0x2af7; - WFIFOSET(char_fd, 2); + WFIFOW(char_session, 0) = 0x2af7; + WFIFOSET(char_session, 2); return 0; } @@ -983,10 +997,10 @@ void ladmin_itemfrob_c(dumb_ptr bl, int source_id, int dest_id) } static -void ladmin_itemfrob(int fd) +void ladmin_itemfrob(Session *s) { - int source_id = RFIFOL(fd, 2); - int dest_id = RFIFOL(fd, 6); + int source_id = RFIFOL(s, 2); + int dest_id = RFIFOL(s, 6); dumb_ptr bl = map_get_first_session(); // flooritems @@ -1006,27 +1020,27 @@ void ladmin_itemfrob(int fd) *------------------------------------------ */ static -void chrif_parse(int fd) +void chrif_parse(Session *s) { int packet_len, cmd; // only char-server can have an access to here. // so, if it isn't the char-server, we disconnect the session (fd != char_fd). - if (fd != char_fd || session[fd]->eof) + if (s != char_session || s->eof) { - if (fd == char_fd) + if (s == char_session) { PRINTF("Map-server can't connect to char-server (connection #%d).\n", - fd); - char_fd = -1; + s); + char_session = nullptr; } - delete_session(fd); + delete_session(s); return; } - while (RFIFOREST(fd) >= 2) + while (RFIFOREST(s) >= 2) { - cmd = RFIFOW(fd, 0); + cmd = RFIFOW(s, 0); if (cmd < 0x2af8 || cmd >= 0x2af8 + @@ -1034,98 +1048,98 @@ void chrif_parse(int fd) || packet_len_table[cmd - 0x2af8] == 0) { - int r = intif_parse(fd); // intifに渡す + int r = intif_parse(s); // intifに渡す if (r == 1) continue; // intifで処理した if (r == 2) return; // intifで処理したが、データが足りない - session[fd]->eof = 1; + s->eof = 1; return; } packet_len = packet_len_table[cmd - 0x2af8]; if (packet_len == -1) { - if (RFIFOREST(fd) < 4) + if (RFIFOREST(s) < 4) return; - packet_len = RFIFOW(fd, 2); + packet_len = RFIFOW(s, 2); } - if (RFIFOREST(fd) < packet_len) + if (RFIFOREST(s) < packet_len) return; switch (cmd) { case 0x2af9: - chrif_connectack(fd); + chrif_connectack(s); break; case 0x2afa: - ladmin_itemfrob(fd); + ladmin_itemfrob(s); break; case 0x2afb: - chrif_sendmapack(fd); + chrif_sendmapack(s); break; case 0x2afd: { - int id = RFIFOL(fd, 4); - int login_id2 = RFIFOL(fd, 8); - TimeT connect_until_time = static_cast(RFIFOL(fd, 12)); - short tmw_version = RFIFOW(fd, 16); + int id = RFIFOL(s, 4); + int login_id2 = RFIFOL(s, 8); + TimeT connect_until_time = static_cast(RFIFOL(s, 12)); + short tmw_version = RFIFOW(s, 16); struct mmo_charstatus st {}; - RFIFO_STRUCT(fd, 18, st); + RFIFO_STRUCT(s, 18, st); pc_authok(id, login_id2, connect_until_time, tmw_version, &st); } break; case 0x2afe: - pc_authfail(RFIFOL(fd, 2)); + pc_authfail(RFIFOL(s, 2)); break; case 0x2b00: - map_setusers(RFIFOL(fd, 2)); + map_setusers(RFIFOL(s, 2)); break; case 0x2b03: - clif_charselectok(RFIFOL(fd, 2)); + clif_charselectok(RFIFOL(s, 2)); break; case 0x2b04: - chrif_recvmap(fd); + chrif_recvmap(s); break; case 0x2b06: - chrif_changemapserverack(fd); + chrif_changemapserverack(s); break; case 0x2b0b: - chrif_changedgm(fd); + chrif_changedgm(s); break; case 0x2b0d: - chrif_changedsex(fd); + chrif_changedsex(s); break; case 0x2b0f: - chrif_char_ask_name_answer(fd); + chrif_char_ask_name_answer(s); break; case 0x2b11: - chrif_accountreg2(fd); + chrif_accountreg2(s); break; case 0x2b12: - chrif_divorce(RFIFOL(fd, 2), RFIFOL(fd, 6)); + chrif_divorce(RFIFOL(s, 2), RFIFOL(s, 6)); break; case 0x2b13: - chrif_accountdeletion(fd); + chrif_accountdeletion(s); break; case 0x2b14: - chrif_accountban(fd); + chrif_accountban(s); break; case 0x2b15: - chrif_recvgmaccounts(fd); + chrif_recvgmaccounts(s); break; default: if (battle_config.error_log) - PRINTF("chrif_parse : unknown packet %d %d\n", fd, - RFIFOW(fd, 0)); - session[fd]->eof = 1; + PRINTF("chrif_parse : unknown packet %d %d\n", s, + RFIFOW(s, 0)); + s->eof = 1; return; } - RFIFOSKIP(fd, packet_len); + RFIFOSKIP(s, packet_len); } } @@ -1139,10 +1153,10 @@ void send_users_tochar(TimerData *, tick_t) { int users = 0; - if (char_fd <= 0 || session[char_fd] == NULL) + if (!char_session) return; - WFIFOW(char_fd, 0) = 0x2aff; + WFIFOW(char_session, 0) = 0x2aff; for (int i = 0; i < fd_max; i++) { if (!session[i]) @@ -1153,13 +1167,13 @@ void send_users_tochar(TimerData *, tick_t) || sd->state.shroud_active || bool(sd->status.option & Option::HIDE)) && pc_isGM(sd))) { - WFIFOL(char_fd, 6 + 4 * users) = sd->status.char_id; + WFIFOL(char_session, 6 + 4 * users) = sd->status.char_id; users++; } } - WFIFOW(char_fd, 2) = 6 + 4 * users; - WFIFOW(char_fd, 4) = users; - WFIFOSET(char_fd, 6 + 4 * users); + WFIFOW(char_session, 2) = 6 + 4 * users; + WFIFOW(char_session, 4) = users; + WFIFOSET(char_session, 6 + 4 * users); } /*========================================== @@ -1170,16 +1184,17 @@ void send_users_tochar(TimerData *, tick_t) static void check_connect_char_server(TimerData *, tick_t) { - if (char_fd <= 0 || session[char_fd] == NULL) + if (!char_session) { PRINTF("Attempt to connect to char-server...\n"); chrif_state = 0; - if ((char_fd = make_connection(char_ip, char_port)) < 0) + char_session = make_connection(char_ip, char_port); + if (!char_session) return; - session[char_fd]->func_parse = chrif_parse; - realloc_fifo(char_fd, FIFOSIZE_SERVERLINK, FIFOSIZE_SERVERLINK); + char_session->func_parse = chrif_parse; + realloc_fifo(char_session, FIFOSIZE_SERVERLINK, FIFOSIZE_SERVERLINK); - chrif_connect(char_fd); + chrif_connect(char_session); } } diff --git a/src/map/chrif.hpp b/src/map/chrif.hpp index dfa2d35..734f1ac 100644 --- a/src/map/chrif.hpp +++ b/src/map/chrif.hpp @@ -37,6 +37,6 @@ int chrif_send_divorce(int char_id); void do_init_chrif(void); // only used by intif.cpp -extern int char_fd; +extern Session *char_session; #endif // CHRIF_HPP diff --git a/src/map/clif.cpp b/src/map/clif.cpp index b4ac24a..0429600 100644 --- a/src/map/clif.cpp +++ b/src/map/clif.cpp @@ -46,7 +46,7 @@ constexpr int EMOTE_IGNORED = 0x0e; // map.h must be the same length as this table. rate 0 is default // rate -1 is unlimited -typedef void (*clif_func)(int fd, dumb_ptr sd); +typedef void (*clif_func)(Session *s, dumb_ptr sd); struct func_table { interval_t rate; @@ -102,14 +102,14 @@ void WBUFPOS2(uint8_t *p, size_t pos, uint16_t x0, uint16_t y0, uint16_t x1, uin } inline -void WFIFOPOS(int fd, size_t pos, uint16_t x, uint16_t y) +void WFIFOPOS(Session *s, size_t pos, uint16_t x, uint16_t y) { - WBUFPOS(static_cast(WFIFOP(fd, pos)), 0, x, y); + WBUFPOS(static_cast(WFIFOP(s, pos)), 0, x, y); } inline -void WFIFOPOS2(int fd, size_t pos, uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) +void WFIFOPOS2(Session *s, size_t pos, uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) { - WBUFPOS2(static_cast(WFIFOP(fd, pos)), 0, x0, y0, x1, y1); + WBUFPOS2(static_cast(WFIFOP(s, pos)), 0, x0, y0, x1, y1); } static @@ -249,14 +249,14 @@ void clif_send_sub(dumb_ptr bl, const unsigned char *buf, int len, break; } - if (session[sd->fd] != NULL) + if (sd->sess != NULL) { { if (clif_parse_func_table[RBUFW(buf, 0)].len) { // packet must exist - WFIFO_BUF_CLONE(sd->fd, buf, len); - WFIFOSET(sd->fd, len); + WFIFO_BUF_CLONE(sd->sess, buf, len); + WFIFOSET(sd->sess, len); } } } @@ -304,16 +304,17 @@ int clif_send(const uint8_t *buf, int len, dumb_ptr bl, SendWho type case SendWho::ALL_CLIENT: // 全クライアントに送信 for (int i = 0; i < fd_max; i++) { - if (!session[i]) + Session *s = session[i].get(); + if (!s) continue; - dumb_ptr sd = dumb_ptr(static_cast(session[i]->session_data.get())); + dumb_ptr sd = dumb_ptr(static_cast(s->session_data.get())); if (sd && sd->state.auth) { if (clif_parse_func_table[RBUFW(buf, 0)].len) { // packet must exist - WFIFO_BUF_CLONE(i, buf, len); - WFIFOSET(i, len); + WFIFO_BUF_CLONE(s, buf, len); + WFIFOSET(s, len); } } } @@ -321,16 +322,17 @@ int clif_send(const uint8_t *buf, int len, dumb_ptr bl, SendWho type case SendWho::ALL_SAMEMAP: // 同じマップの全クライアントに送信 for (int i = 0; i < fd_max; i++) { - if (!session[i]) + Session *s = session[i].get(); + if (!s) continue; - dumb_ptr sd = dumb_ptr(static_cast(session[i]->session_data.get())); + dumb_ptr sd = dumb_ptr(static_cast(s->session_data.get())); if (sd && sd->state.auth && sd->bl_m == bl->bl_m) { if (clif_parse_func_table[RBUFW(buf, 0)].len) { // packet must exist - WFIFO_BUF_CLONE(i, buf, len); - WFIFOSET(i, len); + WFIFO_BUF_CLONE(s, buf, len); + WFIFOSET(s, len); } } } @@ -395,16 +397,17 @@ int clif_send(const uint8_t *buf, int len, dumb_ptr bl, SendWho type if (clif_parse_func_table[RBUFW(buf, 0)].len) { // packet must exist - WFIFO_BUF_CLONE(sd->fd, buf, len); - WFIFOSET(sd->fd, len); + WFIFO_BUF_CLONE(sd->sess, buf, len); + WFIFOSET(sd->sess, len); } } } for (int i = 0; i < fd_max; i++) { - if (!session[i]) + Session *s = session[i].get(); + if (!s) continue; - dumb_ptr sd = dumb_ptr(static_cast(session[i]->session_data.get())); + dumb_ptr sd = dumb_ptr(static_cast(s->session_data.get())); if (sd && sd->state.auth) { if (sd->partyspy == p->party_id) @@ -412,8 +415,8 @@ int clif_send(const uint8_t *buf, int len, dumb_ptr bl, SendWho type if (clif_parse_func_table[RBUFW(buf, 0)].len) { // packet must exist - WFIFO_BUF_CLONE(sd->fd, buf, len); - WFIFOSET(sd->fd, len); + WFIFO_BUF_CLONE(sd->sess, buf, len); + WFIFOSET(sd->sess, len); } } } @@ -426,8 +429,8 @@ int clif_send(const uint8_t *buf, int len, dumb_ptr bl, SendWho type if (clif_parse_func_table[RBUFW(buf, 0)].len) { // packet must exist - WFIFO_BUF_CLONE(sd->fd, buf, len); - WFIFOSET(sd->fd, len); + WFIFO_BUF_CLONE(sd->sess, buf, len); + WFIFOSET(sd->sess, len); } } break; @@ -450,24 +453,22 @@ int clif_send(const uint8_t *buf, int len, dumb_ptr bl, SendWho type */ int clif_authok(dumb_ptr sd) { - int fd; - nullpo_ret(sd); if (!sd) return 0; - if (!sd->fd) + if (!sd->sess) return 0; - fd = sd->fd; + Session *s = sd->sess; - WFIFOW(fd, 0) = 0x73; - WFIFOL(fd, 2) = gettick().time_since_epoch().count(); - WFIFOPOS(fd, 6, sd->bl_x, sd->bl_y); - WFIFOB(fd, 9) = 5; - WFIFOB(fd, 10) = 5; - WFIFOSET(fd, clif_parse_func_table[0x73].len); + WFIFOW(s, 0) = 0x73; + WFIFOL(s, 2) = gettick().time_since_epoch().count(); + WFIFOPOS(s, 6, sd->bl_x, sd->bl_y); + WFIFOB(s, 9) = 5; + WFIFOB(s, 10) = 5; + WFIFOSET(s, clif_parse_func_table[0x73].len); return 0; } @@ -476,16 +477,16 @@ int clif_authok(dumb_ptr sd) * *------------------------------------------ */ -int clif_authfail_fd(int fd, int type) +int clif_authfail_fd(Session *s, int type) { - if (!fd || !session[fd]) + if (!s) return 0; - WFIFOW(fd, 0) = 0x81; - WFIFOL(fd, 2) = type; - WFIFOSET(fd, clif_parse_func_table[0x81].len); + WFIFOW(s, 0) = 0x81; + WFIFOL(s, 2) = type; + WFIFOSET(s, clif_parse_func_table[0x81].len); - clif_setwaitclose(fd); + clif_setwaitclose(s); return 0; } @@ -497,18 +498,17 @@ int clif_authfail_fd(int fd, int type) int clif_charselectok(int id) { dumb_ptr sd; - int fd; if ((sd = map_id2sd(id)) == NULL) return 1; - if (!sd->fd) + if (!sd->sess) return 1; - fd = sd->fd; - WFIFOW(fd, 0) = 0xb3; - WFIFOB(fd, 2) = 1; - WFIFOSET(fd, clif_parse_func_table[0xb3].len); + Session *s = sd->sess; + WFIFOW(s, 0) = 0xb3; + WFIFOB(s, 2) = 1; + WFIFOSET(s, clif_parse_func_table[0xb3].len); return 0; } @@ -558,7 +558,7 @@ int clif_dropflooritem(dumb_ptr fitem) * *------------------------------------------ */ -int clif_clearflooritem(dumb_ptr fitem, int fd) +int clif_clearflooritem(dumb_ptr fitem, Session *s) { unsigned char buf[16]; @@ -567,14 +567,14 @@ int clif_clearflooritem(dumb_ptr fitem, int fd) WBUFW(buf, 0) = 0xa1; WBUFL(buf, 2) = fitem->bl_id; - if (fd == 0) + if (!s) { clif_send(buf, clif_parse_func_table[0xa1].len, fitem, SendWho::AREA); } else { - WFIFO_BUF_CLONE(fd, buf, 6); - WFIFOSET(fd, clif_parse_func_table[0xa1].len); + WFIFO_BUF_CLONE(s, buf, 6); + WFIFOSET(s, clif_parse_func_table[0xa1].len); } return 0; @@ -642,12 +642,12 @@ int clif_clearchar_delay(tick_t tick, * *------------------------------------------ */ -void clif_clearchar_id(int id, BeingRemoveWhy type, int fd) +void clif_clearchar_id(int id, BeingRemoveWhy type, Session *s) { - WFIFOW(fd, 0) = 0x80; - WFIFOL(fd, 2) = id; - WFIFOB(fd, 6) = static_cast(type); - WFIFOSET(fd, clif_parse_func_table[0x80].len); + WFIFOW(s, 0) = 0x80; + WFIFOL(s, 2) = id; + WFIFOB(s, 6) = static_cast(type); + WFIFOSET(s, clif_parse_func_table[0x80].len); } /*========================================== @@ -933,37 +933,36 @@ int clif_spawnnpc(dumb_ptr nd) int clif_spawn_fake_npc_for_player(dumb_ptr sd, int fake_npc_id) { - int fd; - nullpo_ret(sd); - fd = sd->fd; - if (!fd) + Session *s = sd->sess; + + if (!s) return 0; - WFIFOW(fd, 0) = 0x7c; - WFIFOL(fd, 2) = fake_npc_id; - WFIFOW(fd, 6) = 0; - WFIFOW(fd, 8) = 0; - WFIFOW(fd, 10) = 0; - WFIFOW(fd, 12) = 0; - WFIFOW(fd, 20) = 127; - WFIFOPOS(fd, 36, sd->bl_x, sd->bl_y); - WFIFOSET(fd, clif_parse_func_table[0x7c].len); - - WFIFOW(fd, 0) = 0x78; - WFIFOL(fd, 2) = fake_npc_id; - WFIFOW(fd, 6) = 0; - WFIFOW(fd, 8) = 0; - WFIFOW(fd, 10) = 0; - WFIFOW(fd, 12) = 0; - WFIFOW(fd, 14) = 127; // identifies as NPC - WFIFOW(fd, 20) = 127; - WFIFOPOS(fd, 46, sd->bl_x, sd->bl_y); - WFIFOPOS(fd, 36, sd->bl_x, sd->bl_y); - WFIFOB(fd, 49) = 5; - WFIFOB(fd, 50) = 5; - WFIFOSET(fd, clif_parse_func_table[0x78].len); + WFIFOW(s, 0) = 0x7c; + WFIFOL(s, 2) = fake_npc_id; + WFIFOW(s, 6) = 0; + WFIFOW(s, 8) = 0; + WFIFOW(s, 10) = 0; + WFIFOW(s, 12) = 0; + WFIFOW(s, 20) = 127; + WFIFOPOS(s, 36, sd->bl_x, sd->bl_y); + WFIFOSET(s, clif_parse_func_table[0x7c].len); + + WFIFOW(s, 0) = 0x78; + WFIFOL(s, 2) = fake_npc_id; + WFIFOW(s, 6) = 0; + WFIFOW(s, 8) = 0; + WFIFOW(s, 10) = 0; + WFIFOW(s, 12) = 0; + WFIFOW(s, 14) = 127; // identifies as NPC + WFIFOW(s, 20) = 127; + WFIFOPOS(s, 46, sd->bl_x, sd->bl_y); + WFIFOPOS(s, 36, sd->bl_x, sd->bl_y); + WFIFOB(s, 49) = 5; + WFIFOB(s, 50) = 5; + WFIFOSET(s, clif_parse_func_table[0x78].len); return 0; } @@ -1006,14 +1005,12 @@ int clif_spawnmob(dumb_ptr md) static int clif_servertick(dumb_ptr sd) { - int fd; - nullpo_ret(sd); - fd = sd->fd; - WFIFOW(fd, 0) = 0x7f; - WFIFOL(fd, 2) = sd->server_tick.time_since_epoch().count(); - WFIFOSET(fd, clif_parse_func_table[0x7f].len); + Session *s = sd->sess; + WFIFOW(s, 0) = 0x7f; + WFIFOL(s, 2) = sd->server_tick.time_since_epoch().count(); + WFIFOSET(s, clif_parse_func_table[0x7f].len); return 0; } @@ -1024,16 +1021,14 @@ int clif_servertick(dumb_ptr sd) */ int clif_walkok(dumb_ptr sd) { - int fd; - nullpo_ret(sd); - fd = sd->fd; - WFIFOW(fd, 0) = 0x87; - WFIFOL(fd, 2) = gettick().time_since_epoch().count(); - WFIFOPOS2(fd, 6, sd->bl_x, sd->bl_y, sd->to_x, sd->to_y); - WFIFOB(fd, 11) = 0; - WFIFOSET(fd, clif_parse_func_table[0x87].len); + Session *s = sd->sess; + WFIFOW(s, 0) = 0x87; + WFIFOL(s, 2) = gettick().time_since_epoch().count(); + WFIFOPOS2(s, 6, sd->bl_x, sd->bl_y, sd->to_x, sd->to_y); + WFIFOB(s, 11) = 0; + WFIFOSET(s, clif_parse_func_table[0x87].len); return 0; } @@ -1065,7 +1060,7 @@ int clif_movechar(dumb_ptr sd) *------------------------------------------ */ static -void clif_quitsave(int, dumb_ptr sd) +void clif_quitsave(Session *, dumb_ptr sd) { map_quit(sd); } @@ -1075,23 +1070,23 @@ void clif_quitsave(int, dumb_ptr sd) *------------------------------------------ */ static -void clif_waitclose(TimerData *, tick_t, int id) +void clif_waitclose(TimerData *, tick_t, Session *s) { // TODO: what happens if the player disconnects // and someone else connects? - if (session[id]) - session[id]->eof = 1; + if (s) + s->eof = 1; } /*========================================== * *------------------------------------------ */ -void clif_setwaitclose(int fd) +void clif_setwaitclose(Session *s) { Timer(gettick() + std::chrono::seconds(5), std::bind(clif_waitclose, ph::_1, ph::_2, - fd) + s) ).detach(); } @@ -1103,13 +1098,13 @@ void clif_changemap(dumb_ptr sd, MapName mapname, int x, int y { nullpo_retv(sd); - int fd = sd->fd; + Session *s = sd->sess; - WFIFOW(fd, 0) = 0x91; - WFIFO_STRING(fd, 2, mapname, 16); - WFIFOW(fd, 18) = x; - WFIFOW(fd, 20) = y; - WFIFOSET(fd, clif_parse_func_table[0x91].len); + WFIFOW(s, 0) = 0x91; + WFIFO_STRING(s, 2, mapname, 16); + WFIFOW(s, 18) = x; + WFIFOW(s, 20) = y; + WFIFOSET(s, clif_parse_func_table[0x91].len); } /*========================================== @@ -1121,14 +1116,14 @@ void clif_changemapserver(dumb_ptr sd, { nullpo_retv(sd); - int fd = sd->fd; - WFIFOW(fd, 0) = 0x92; - WFIFO_STRING(fd, 2, mapname, 16); - WFIFOW(fd, 18) = x; - WFIFOW(fd, 20) = y; - WFIFOIP(fd, 22) = ip; - WFIFOW(fd, 26) = port; - WFIFOSET(fd, clif_parse_func_table[0x92].len); + Session *s = sd->sess; + WFIFOW(s, 0) = 0x92; + WFIFO_STRING(s, 2, mapname, 16); + WFIFOW(s, 18) = x; + WFIFOW(s, 20) = y; + WFIFOIP(s, 22) = ip; + WFIFOW(s, 26) = port; + WFIFOSET(s, clif_parse_func_table[0x92].len); } /*========================================== @@ -1155,14 +1150,12 @@ void clif_fixpos(dumb_ptr bl) */ int clif_npcbuysell(dumb_ptr sd, int id) { - int fd; - nullpo_ret(sd); - fd = sd->fd; - WFIFOW(fd, 0) = 0xc4; - WFIFOL(fd, 2) = id; - WFIFOSET(fd, clif_parse_func_table[0xc4].len); + Session *s = sd->sess; + WFIFOW(s, 0) = 0xc4; + WFIFOL(s, 2) = id; + WFIFOSET(s, clif_parse_func_table[0xc4].len); return 0; } @@ -1174,24 +1167,24 @@ int clif_npcbuysell(dumb_ptr sd, int id) int clif_buylist(dumb_ptr sd, dumb_ptr nd) { struct item_data *id; - int fd, i, val; + int i, val; nullpo_ret(sd); nullpo_ret(nd); - fd = sd->fd; - WFIFOW(fd, 0) = 0xc6; + Session *s = sd->sess; + WFIFOW(s, 0) = 0xc6; for (i = 0; i < nd->shop_items.size(); i++) { id = itemdb_search(nd->shop_items[i].nameid); val = nd->shop_items[i].value; - WFIFOL(fd, 4 + i * 11) = val; // base price - WFIFOL(fd, 8 + i * 11) = val; // actual price - WFIFOB(fd, 12 + i * 11) = uint8_t(id->type); - WFIFOW(fd, 13 + i * 11) = nd->shop_items[i].nameid; + WFIFOL(s, 4 + i * 11) = val; // base price + WFIFOL(s, 8 + i * 11) = val; // actual price + WFIFOB(s, 12 + i * 11) = uint8_t(id->type); + WFIFOW(s, 13 + i * 11) = nd->shop_items[i].nameid; } - WFIFOW(fd, 2) = i * 11 + 4; - WFIFOSET(fd, WFIFOW(fd, 2)); + WFIFOW(s, 2) = i * 11 + 4; + WFIFOSET(s, WFIFOW(s, 2)); return 0; } @@ -1202,12 +1195,12 @@ int clif_buylist(dumb_ptr sd, dumb_ptr nd) */ int clif_selllist(dumb_ptr sd) { - int fd, i, c = 0, val; + int i, c = 0, val; nullpo_ret(sd); - fd = sd->fd; - WFIFOW(fd, 0) = 0xc7; + Session *s = sd->sess; + WFIFOW(s, 0) = 0xc7; for (i = 0; i < MAX_INVENTORY; i++) { if (sd->status.inventory[i].nameid > 0 && sd->inventory_data[i]) @@ -1215,14 +1208,14 @@ int clif_selllist(dumb_ptr sd) val = sd->inventory_data[i]->value_sell; if (val < 0) continue; - WFIFOW(fd, 4 + c * 10) = i + 2; - WFIFOL(fd, 6 + c * 10) = val; // base price - WFIFOL(fd, 10 + c * 10) = val; // actual price + WFIFOW(s, 4 + c * 10) = i + 2; + WFIFOL(s, 6 + c * 10) = val; // base price + WFIFOL(s, 10 + c * 10) = val; // actual price c++; } } - WFIFOW(fd, 2) = c * 10 + 4; - WFIFOSET(fd, WFIFOW(fd, 2)); + WFIFOW(s, 2) = c * 10 + 4; + WFIFOSET(s, WFIFOW(s, 2)); return 0; } @@ -1235,14 +1228,14 @@ void clif_scriptmes(dumb_ptr sd, int npcid, XString mes) { nullpo_retv(sd); - int fd = sd->fd; + Session *s = sd->sess; size_t len = mes.size() + 1; - WFIFOW(fd, 0) = 0xb4; - WFIFOW(fd, 2) = len + 8; - WFIFOL(fd, 4) = npcid; - WFIFO_STRING(fd, 8, mes, len); - WFIFOSET(fd, WFIFOW(fd, 2)); + WFIFOW(s, 0) = 0xb4; + WFIFOW(s, 2) = len + 8; + WFIFOL(s, 4) = npcid; + WFIFO_STRING(s, 8, mes, len); + WFIFOSET(s, WFIFOW(s, 2)); } /*========================================== @@ -1253,10 +1246,10 @@ void clif_scriptnext(dumb_ptr sd, int npcid) { nullpo_retv(sd); - int fd = sd->fd; - WFIFOW(fd, 0) = 0xb5; - WFIFOL(fd, 2) = npcid; - WFIFOSET(fd, clif_parse_func_table[0xb5].len); + Session *s = sd->sess; + WFIFOW(s, 0) = 0xb5; + WFIFOL(s, 2) = npcid; + WFIFOSET(s, clif_parse_func_table[0xb5].len); } /*========================================== @@ -1267,10 +1260,10 @@ void clif_scriptclose(dumb_ptr sd, int npcid) { nullpo_retv(sd); - int fd = sd->fd; - WFIFOW(fd, 0) = 0xb6; - WFIFOL(fd, 2) = npcid; - WFIFOSET(fd, clif_parse_func_table[0xb6].len); + Session *s = sd->sess; + WFIFOW(s, 0) = 0xb6; + WFIFOL(s, 2) = npcid; + WFIFOSET(s, clif_parse_func_table[0xb6].len); } /*========================================== @@ -1281,13 +1274,13 @@ void clif_scriptmenu(dumb_ptr sd, int npcid, XString mes) { nullpo_retv(sd); - int fd = sd->fd; + Session *s = sd->sess; size_t len = mes.size() + 1; - WFIFOW(fd, 0) = 0xb7; - WFIFOW(fd, 2) = len + 8; - WFIFOL(fd, 4) = npcid; - WFIFO_STRING(fd, 8, mes, len); - WFIFOSET(fd, WFIFOW(fd, 2)); + WFIFOW(s, 0) = 0xb7; + WFIFOW(s, 2) = len + 8; + WFIFOL(s, 4) = npcid; + WFIFO_STRING(s, 8, mes, len); + WFIFOSET(s, WFIFOW(s, 2)); } /*========================================== @@ -1298,10 +1291,10 @@ void clif_scriptinput(dumb_ptr sd, int npcid) { nullpo_retv(sd); - int fd = sd->fd; - WFIFOW(fd, 0) = 0x142; - WFIFOL(fd, 2) = npcid; - WFIFOSET(fd, clif_parse_func_table[0x142].len); + Session *s = sd->sess; + WFIFOW(s, 0) = 0x142; + WFIFOL(s, 2) = npcid; + WFIFOSET(s, clif_parse_func_table[0x142].len); } /*========================================== @@ -1312,10 +1305,10 @@ void clif_scriptinputstr(dumb_ptr sd, int npcid) { nullpo_retv(sd); - int fd = sd->fd; - WFIFOW(fd, 0) = 0x1d4; - WFIFOL(fd, 2) = npcid; - WFIFOSET(fd, clif_parse_func_table[0x1d4].len); + Session *s = sd->sess; + WFIFOW(s, 0) = 0x1d4; + WFIFOL(s, 2) = npcid; + WFIFOSET(s, clif_parse_func_table[0x1d4].len); } /*========================================== @@ -1327,15 +1320,15 @@ void clif_viewpoint(dumb_ptr sd, int npc_id, int type, { nullpo_retv(sd); - int fd = sd->fd; - WFIFOW(fd, 0) = 0x144; - WFIFOL(fd, 2) = npc_id; - WFIFOL(fd, 6) = type; - WFIFOL(fd, 10) = x; - WFIFOL(fd, 14) = y; - WFIFOB(fd, 18) = id; - WFIFOL(fd, 19) = color; - WFIFOSET(fd, clif_parse_func_table[0x144].len); + Session *s = sd->sess; + WFIFOW(s, 0) = 0x144; + WFIFOL(s, 2) = npc_id; + WFIFOL(s, 6) = type; + WFIFOL(s, 10) = x; + WFIFOL(s, 14) = y; + WFIFOB(s, 18) = id; + WFIFOL(s, 19) = color; + WFIFOSET(s, clif_parse_func_table[0x144].len); } /*========================================== @@ -1346,23 +1339,23 @@ int clif_additem(dumb_ptr sd, int n, int amount, PickupFail fa { nullpo_ret(sd); - int fd = sd->fd; + Session *s = sd->sess; if (fail != PickupFail::OKAY) { - WFIFOW(fd, 0) = 0xa0; - WFIFOW(fd, 2) = n + 2; - WFIFOW(fd, 4) = amount; - WFIFOW(fd, 6) = 0; - WFIFOB(fd, 8) = 0; - WFIFOB(fd, 9) = 0; - WFIFOB(fd, 10) = 0; - WFIFOW(fd, 11) = 0; - WFIFOW(fd, 13) = 0; - WFIFOW(fd, 15) = 0; - WFIFOW(fd, 17) = 0; - WFIFOW(fd, 19) = 0; - WFIFOB(fd, 21) = 0; - WFIFOB(fd, 22) = uint8_t(fail); + WFIFOW(s, 0) = 0xa0; + WFIFOW(s, 2) = n + 2; + WFIFOW(s, 4) = amount; + WFIFOW(s, 6) = 0; + WFIFOB(s, 8) = 0; + WFIFOB(s, 9) = 0; + WFIFOB(s, 10) = 0; + WFIFOW(s, 11) = 0; + WFIFOW(s, 13) = 0; + WFIFOW(s, 15) = 0; + WFIFOW(s, 17) = 0; + WFIFOW(s, 19) = 0; + WFIFOB(s, 21) = 0; + WFIFOB(s, 22) = uint8_t(fail); } else { @@ -1370,40 +1363,40 @@ int clif_additem(dumb_ptr sd, int n, int amount, PickupFail fa || sd->inventory_data[n] == NULL) return 1; - WFIFOW(fd, 0) = 0xa0; - WFIFOW(fd, 2) = n + 2; - WFIFOW(fd, 4) = amount; - WFIFOW(fd, 6) = sd->status.inventory[n].nameid; - WFIFOB(fd, 8) = sd->status.inventory[n].identify; + WFIFOW(s, 0) = 0xa0; + WFIFOW(s, 2) = n + 2; + WFIFOW(s, 4) = amount; + WFIFOW(s, 6) = sd->status.inventory[n].nameid; + WFIFOB(s, 8) = sd->status.inventory[n].identify; if (sd->status.inventory[n].broken == 1) - WFIFOB(fd, 9) = 1; // is weapon broken [Valaris] + WFIFOB(s, 9) = 1; // is weapon broken [Valaris] else - WFIFOB(fd, 9) = sd->status.inventory[n].attribute; - WFIFOB(fd, 10) = sd->status.inventory[n].refine; + WFIFOB(s, 9) = sd->status.inventory[n].attribute; + WFIFOB(s, 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] == static_cast(0xff00)) { - WFIFOW(fd, 11) = sd->status.inventory[n].card[0]; - WFIFOW(fd, 13) = sd->status.inventory[n].card[1]; - WFIFOW(fd, 15) = sd->status.inventory[n].card[2]; - WFIFOW(fd, 17) = sd->status.inventory[n].card[3]; + WFIFOW(s, 11) = sd->status.inventory[n].card[0]; + WFIFOW(s, 13) = sd->status.inventory[n].card[1]; + WFIFOW(s, 15) = sd->status.inventory[n].card[2]; + WFIFOW(s, 17) = sd->status.inventory[n].card[3]; } else { - WFIFOW(fd, 11) = sd->status.inventory[n].card[0]; - WFIFOW(fd, 13) = sd->status.inventory[n].card[1]; - WFIFOW(fd, 15) = sd->status.inventory[n].card[2]; - WFIFOW(fd, 17) = sd->status.inventory[n].card[3]; + WFIFOW(s, 11) = sd->status.inventory[n].card[0]; + WFIFOW(s, 13) = sd->status.inventory[n].card[1]; + WFIFOW(s, 15) = sd->status.inventory[n].card[2]; + WFIFOW(s, 17) = sd->status.inventory[n].card[3]; } - WFIFOW(fd, 19) = uint16_t(pc_equippoint(sd, n)); - WFIFOB(fd, 21) = uint8_t(sd->inventory_data[n]->type == ItemType::_7 + WFIFOW(s, 19) = uint16_t(pc_equippoint(sd, n)); + WFIFOB(s, 21) = uint8_t(sd->inventory_data[n]->type == ItemType::_7 ? ItemType::WEAPON : sd->inventory_data[n]->type); - WFIFOB(fd, 22) = uint8_t(fail); + WFIFOB(s, 22) = uint8_t(fail); } - WFIFOSET(fd, clif_parse_func_table[0xa0].len); + WFIFOSET(s, clif_parse_func_table[0xa0].len); return 0; } @@ -1415,12 +1408,12 @@ void clif_delitem(dumb_ptr sd, int n, int amount) { nullpo_retv(sd); - int fd = sd->fd; - WFIFOW(fd, 0) = 0xaf; - WFIFOW(fd, 2) = n + 2; - WFIFOW(fd, 4) = amount; + Session *s = sd->sess; + WFIFOW(s, 0) = 0xaf; + WFIFOW(s, 2) = n + 2; + WFIFOW(s, 4) = amount; - WFIFOSET(fd, clif_parse_func_table[0xaf].len); + WFIFOSET(s, clif_parse_func_table[0xaf].len); } /*========================================== @@ -1433,37 +1426,37 @@ void clif_itemlist(dumb_ptr sd) int n = 0; int arrow = -1; - int fd = sd->fd; - WFIFOW(fd, 0) = 0x1ee; + Session *s = sd->sess; + WFIFOW(s, 0) = 0x1ee; for (int i = 0; i < MAX_INVENTORY; i++) { if (sd->status.inventory[i].nameid <= 0 || sd->inventory_data[i] == NULL || itemdb_isequip2(sd->inventory_data[i])) continue; - WFIFOW(fd, n * 18 + 4) = i + 2; - WFIFOW(fd, n * 18 + 6) = sd->status.inventory[i].nameid; - WFIFOB(fd, n * 18 + 8) = uint8_t(sd->inventory_data[i]->type); - WFIFOB(fd, n * 18 + 9) = sd->status.inventory[i].identify; - WFIFOW(fd, n * 18 + 10) = sd->status.inventory[i].amount; + WFIFOW(s, n * 18 + 4) = i + 2; + WFIFOW(s, n * 18 + 6) = sd->status.inventory[i].nameid; + WFIFOB(s, n * 18 + 8) = uint8_t(sd->inventory_data[i]->type); + WFIFOB(s, n * 18 + 9) = sd->status.inventory[i].identify; + WFIFOW(s, n * 18 + 10) = sd->status.inventory[i].amount; if (sd->inventory_data[i]->equip == EPOS::ARROW) { - WFIFOW(fd, n * 18 + 12) = uint16_t(EPOS::ARROW); + WFIFOW(s, n * 18 + 12) = uint16_t(EPOS::ARROW); if (bool(sd->status.inventory[i].equip)) arrow = i; // ついでに矢装備チェック } else - WFIFOW(fd, n * 18 + 12) = uint16_t(EPOS::ZERO); - WFIFOW(fd, n * 18 + 14) = sd->status.inventory[i].card[0]; - WFIFOW(fd, n * 18 + 16) = sd->status.inventory[i].card[1]; - WFIFOW(fd, n * 18 + 18) = sd->status.inventory[i].card[2]; - WFIFOW(fd, n * 18 + 20) = sd->status.inventory[i].card[3]; + WFIFOW(s, n * 18 + 12) = uint16_t(EPOS::ZERO); + WFIFOW(s, n * 18 + 14) = sd->status.inventory[i].card[0]; + WFIFOW(s, n * 18 + 16) = sd->status.inventory[i].card[1]; + WFIFOW(s, n * 18 + 18) = sd->status.inventory[i].card[2]; + WFIFOW(s, n * 18 + 20) = sd->status.inventory[i].card[3]; n++; } if (n) { - WFIFOW(fd, 2) = 4 + n * 18; - WFIFOSET(fd, WFIFOW(fd, 2)); + WFIFOW(s, 2) = 4 + n * 18; + WFIFOSET(s, WFIFOW(s, 2)); } if (arrow >= 0) clif_arrowequip(sd, arrow); @@ -1477,8 +1470,8 @@ void clif_equiplist(dumb_ptr sd) { nullpo_retv(sd); - int fd = sd->fd; - WFIFOW(fd, 0) = 0xa4; + Session *s = sd->sess; + WFIFOW(s, 0) = 0xa4; int n = 0; for (int i = 0; i < MAX_INVENTORY; i++) { @@ -1486,42 +1479,42 @@ void clif_equiplist(dumb_ptr sd) || sd->inventory_data[i] == NULL || !itemdb_isequip2(sd->inventory_data[i])) continue; - WFIFOW(fd, n * 20 + 4) = i + 2; - WFIFOW(fd, n * 20 + 6) = sd->status.inventory[i].nameid; - WFIFOB(fd, n * 20 + 8) = uint8_t( + WFIFOW(s, n * 20 + 4) = i + 2; + WFIFOW(s, n * 20 + 6) = sd->status.inventory[i].nameid; + WFIFOB(s, n * 20 + 8) = uint8_t( sd->inventory_data[i]->type == ItemType::_7 ? ItemType::WEAPON : sd->inventory_data[i]->type); - WFIFOB(fd, n * 20 + 9) = sd->status.inventory[i].identify; - WFIFOW(fd, n * 20 + 10) = uint16_t(pc_equippoint(sd, i)); - WFIFOW(fd, n * 20 + 12) = uint16_t(sd->status.inventory[i].equip); + WFIFOB(s, n * 20 + 9) = sd->status.inventory[i].identify; + WFIFOW(s, n * 20 + 10) = uint16_t(pc_equippoint(sd, i)); + WFIFOW(s, n * 20 + 12) = uint16_t(sd->status.inventory[i].equip); if (sd->status.inventory[i].broken == 1) - WFIFOB(fd, n * 20 + 14) = 1; // is weapon broken [Valaris] + WFIFOB(s, n * 20 + 14) = 1; // is weapon broken [Valaris] else - WFIFOB(fd, n * 20 + 14) = sd->status.inventory[i].attribute; - WFIFOB(fd, n * 20 + 15) = sd->status.inventory[i].refine; + WFIFOB(s, n * 20 + 14) = sd->status.inventory[i].attribute; + WFIFOB(s, 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] == 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]; - WFIFOW(fd, n * 20 + 20) = sd->status.inventory[i].card[2]; - WFIFOW(fd, n * 20 + 22) = sd->status.inventory[i].card[3]; + WFIFOW(s, n * 20 + 16) = sd->status.inventory[i].card[0]; + WFIFOW(s, n * 20 + 18) = sd->status.inventory[i].card[1]; + WFIFOW(s, n * 20 + 20) = sd->status.inventory[i].card[2]; + WFIFOW(s, n * 20 + 22) = sd->status.inventory[i].card[3]; } else { - WFIFOW(fd, n * 20 + 16) = sd->status.inventory[i].card[0]; - WFIFOW(fd, n * 20 + 18) = sd->status.inventory[i].card[1]; - WFIFOW(fd, n * 20 + 20) = sd->status.inventory[i].card[2]; - WFIFOW(fd, n * 20 + 22) = sd->status.inventory[i].card[3]; + WFIFOW(s, n * 20 + 16) = sd->status.inventory[i].card[0]; + WFIFOW(s, n * 20 + 18) = sd->status.inventory[i].card[1]; + WFIFOW(s, n * 20 + 20) = sd->status.inventory[i].card[2]; + WFIFOW(s, n * 20 + 22) = sd->status.inventory[i].card[3]; } n++; } if (n) { - WFIFOW(fd, 2) = 4 + n * 20; - WFIFOSET(fd, WFIFOW(fd, 2)); + WFIFOW(s, 2) = 4 + n * 20; + WFIFOSET(s, WFIFOW(s, 2)); } } @@ -1534,8 +1527,8 @@ int clif_storageitemlist(dumb_ptr sd, struct storage *stor) nullpo_ret(sd); nullpo_ret(stor); - int fd = sd->fd; - WFIFOW(fd, 0) = 0x1f0; + Session *s = sd->sess; + WFIFOW(s, 0) = 0x1f0; int n = 0; for (int i = 0; i < MAX_STORAGE; i++) { @@ -1548,22 +1541,22 @@ int clif_storageitemlist(dumb_ptr sd, struct storage *stor) if (itemdb_isequip2(id)) continue; - WFIFOW(fd, n * 18 + 4) = i + 1; - WFIFOW(fd, n * 18 + 6) = stor->storage_[i].nameid; - WFIFOB(fd, n * 18 + 8) = uint8_t(id->type); - WFIFOB(fd, n * 18 + 9) = stor->storage_[i].identify; - WFIFOW(fd, n * 18 + 10) = stor->storage_[i].amount; - WFIFOW(fd, n * 18 + 12) = 0; - WFIFOW(fd, n * 18 + 14) = stor->storage_[i].card[0]; - WFIFOW(fd, n * 18 + 16) = stor->storage_[i].card[1]; - WFIFOW(fd, n * 18 + 18) = stor->storage_[i].card[2]; - WFIFOW(fd, n * 18 + 20) = stor->storage_[i].card[3]; + WFIFOW(s, n * 18 + 4) = i + 1; + WFIFOW(s, n * 18 + 6) = stor->storage_[i].nameid; + WFIFOB(s, n * 18 + 8) = uint8_t(id->type); + WFIFOB(s, n * 18 + 9) = stor->storage_[i].identify; + WFIFOW(s, n * 18 + 10) = stor->storage_[i].amount; + WFIFOW(s, n * 18 + 12) = 0; + WFIFOW(s, n * 18 + 14) = stor->storage_[i].card[0]; + WFIFOW(s, n * 18 + 16) = stor->storage_[i].card[1]; + WFIFOW(s, n * 18 + 18) = stor->storage_[i].card[2]; + WFIFOW(s, n * 18 + 20) = stor->storage_[i].card[3]; n++; } if (n) { - WFIFOW(fd, 2) = 4 + n * 18; - WFIFOSET(fd, WFIFOW(fd, 2)); + WFIFOW(s, 2) = 4 + n * 18; + WFIFOSET(s, WFIFOW(s, 2)); } return 0; } @@ -1577,8 +1570,8 @@ int clif_storageequiplist(dumb_ptr sd, struct storage *stor) nullpo_ret(sd); nullpo_ret(stor); - int fd = sd->fd; - WFIFOW(fd, 0) = 0xa6; + Session *s = sd->sess; + WFIFOW(s, 0) = 0xa6; int n = 0; for (int i = 0; i < MAX_STORAGE; i++) { @@ -1590,39 +1583,39 @@ int clif_storageequiplist(dumb_ptr sd, struct storage *stor) nullpo_ret(id); if (!itemdb_isequip2(id)) continue; - WFIFOW(fd, n * 20 + 4) = i + 1; - WFIFOW(fd, n * 20 + 6) = stor->storage_[i].nameid; - WFIFOB(fd, n * 20 + 8) = uint8_t(id->type); - WFIFOB(fd, n * 20 + 9) = stor->storage_[i].identify; - WFIFOW(fd, n * 20 + 10) = uint16_t(id->equip); - WFIFOW(fd, n * 20 + 12) = uint16_t(stor->storage_[i].equip); + WFIFOW(s, n * 20 + 4) = i + 1; + WFIFOW(s, n * 20 + 6) = stor->storage_[i].nameid; + WFIFOB(s, n * 20 + 8) = uint8_t(id->type); + WFIFOB(s, n * 20 + 9) = stor->storage_[i].identify; + WFIFOW(s, n * 20 + 10) = uint16_t(id->equip); + WFIFOW(s, n * 20 + 12) = uint16_t(stor->storage_[i].equip); if (stor->storage_[i].broken == 1) - WFIFOB(fd, n * 20 + 14) = 1; //is weapon broken [Valaris] + WFIFOB(s, n * 20 + 14) = 1; //is weapon broken [Valaris] else - WFIFOB(fd, n * 20 + 14) = stor->storage_[i].attribute; - WFIFOB(fd, n * 20 + 15) = stor->storage_[i].refine; + WFIFOB(s, n * 20 + 14) = stor->storage_[i].attribute; + WFIFOB(s, 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] == static_cast(0xff00)) { - WFIFOW(fd, n * 20 + 16) = stor->storage_[i].card[0]; - WFIFOW(fd, n * 20 + 18) = stor->storage_[i].card[1]; - WFIFOW(fd, n * 20 + 20) = stor->storage_[i].card[2]; - WFIFOW(fd, n * 20 + 22) = stor->storage_[i].card[3]; + WFIFOW(s, n * 20 + 16) = stor->storage_[i].card[0]; + WFIFOW(s, n * 20 + 18) = stor->storage_[i].card[1]; + WFIFOW(s, n * 20 + 20) = stor->storage_[i].card[2]; + WFIFOW(s, n * 20 + 22) = stor->storage_[i].card[3]; } else { - WFIFOW(fd, n * 20 + 16) = stor->storage_[i].card[0]; - WFIFOW(fd, n * 20 + 18) = stor->storage_[i].card[1]; - WFIFOW(fd, n * 20 + 20) = stor->storage_[i].card[2]; - WFIFOW(fd, n * 20 + 22) = stor->storage_[i].card[3]; + WFIFOW(s, n * 20 + 16) = stor->storage_[i].card[0]; + WFIFOW(s, n * 20 + 18) = stor->storage_[i].card[1]; + WFIFOW(s, n * 20 + 20) = stor->storage_[i].card[2]; + WFIFOW(s, n * 20 + 22) = stor->storage_[i].card[3]; } n++; } if (n) { - WFIFOW(fd, 2) = 4 + n * 20; - WFIFOSET(fd, WFIFOW(fd, 2)); + WFIFOW(s, 2) = 4 + n * 20; + WFIFOSET(s, WFIFOW(s, 2)); } return 0; } @@ -1634,117 +1627,117 @@ int clif_storageequiplist(dumb_ptr sd, struct storage *stor) */ int clif_updatestatus(dumb_ptr sd, SP type) { - int fd, len = 8; + int len = 8; nullpo_ret(sd); - fd = sd->fd; + Session *s = sd->sess; - WFIFOW(fd, 0) = 0xb0; - WFIFOW(fd, 2) = static_cast(type); + WFIFOW(s, 0) = 0xb0; + WFIFOW(s, 2) = static_cast(type); switch (type) { // 00b0 case SP::WEIGHT: pc_checkweighticon(sd); // is this because pc_checkweighticon can send other packets? - WFIFOW(fd, 0) = 0xb0; - WFIFOW(fd, 2) = static_cast(type); - WFIFOL(fd, 4) = sd->weight; + WFIFOW(s, 0) = 0xb0; + WFIFOW(s, 2) = static_cast(type); + WFIFOL(s, 4) = sd->weight; break; case SP::MAXWEIGHT: - WFIFOL(fd, 4) = sd->max_weight; + WFIFOL(s, 4) = sd->max_weight; break; case SP::SPEED: // ... - WFIFOL(fd, 4) = static_cast(sd->speed.count()); + WFIFOL(s, 4) = static_cast(sd->speed.count()); break; case SP::BASELEVEL: - WFIFOL(fd, 4) = sd->status.base_level; + WFIFOL(s, 4) = sd->status.base_level; break; case SP::JOBLEVEL: - WFIFOL(fd, 4) = 0; + WFIFOL(s, 4) = 0; break; case SP::STATUSPOINT: - WFIFOL(fd, 4) = sd->status.status_point; + WFIFOL(s, 4) = sd->status.status_point; break; case SP::SKILLPOINT: - WFIFOL(fd, 4) = sd->status.skill_point; + WFIFOL(s, 4) = sd->status.skill_point; break; case SP::HIT: - WFIFOL(fd, 4) = sd->hit; + WFIFOL(s, 4) = sd->hit; break; case SP::FLEE1: - WFIFOL(fd, 4) = sd->flee; + WFIFOL(s, 4) = sd->flee; break; case SP::FLEE2: - WFIFOL(fd, 4) = sd->flee2 / 10; + WFIFOL(s, 4) = sd->flee2 / 10; break; case SP::MAXHP: - WFIFOL(fd, 4) = sd->status.max_hp; + WFIFOL(s, 4) = sd->status.max_hp; break; case SP::MAXSP: - WFIFOL(fd, 4) = sd->status.max_sp; + WFIFOL(s, 4) = sd->status.max_sp; break; case SP::HP: - WFIFOL(fd, 4) = sd->status.hp; + WFIFOL(s, 4) = sd->status.hp; break; case SP::SP: - WFIFOL(fd, 4) = sd->status.sp; + WFIFOL(s, 4) = sd->status.sp; break; case SP::ASPD: - WFIFOL(fd, 4) = static_cast(sd->aspd.count()); + WFIFOL(s, 4) = static_cast(sd->aspd.count()); break; case SP::ATK1: - WFIFOL(fd, 4) = sd->base_atk + sd->watk; + WFIFOL(s, 4) = sd->base_atk + sd->watk; break; case SP::DEF1: - WFIFOL(fd, 4) = sd->def; + WFIFOL(s, 4) = sd->def; break; case SP::MDEF1: - WFIFOL(fd, 4) = sd->mdef; + WFIFOL(s, 4) = sd->mdef; break; case SP::ATK2: - WFIFOL(fd, 4) = sd->watk2; + WFIFOL(s, 4) = sd->watk2; break; case SP::DEF2: - WFIFOL(fd, 4) = sd->def2; + WFIFOL(s, 4) = sd->def2; break; case SP::MDEF2: - WFIFOL(fd, 4) = sd->mdef2; + WFIFOL(s, 4) = sd->mdef2; break; case SP::CRITICAL: - WFIFOL(fd, 4) = sd->critical / 10; + WFIFOL(s, 4) = sd->critical / 10; break; case SP::MATK1: - WFIFOL(fd, 4) = sd->matk1; + WFIFOL(s, 4) = sd->matk1; break; case SP::MATK2: - WFIFOL(fd, 4) = sd->matk2; + WFIFOL(s, 4) = sd->matk2; break; case SP::ZENY: trade_verifyzeny(sd); - WFIFOW(fd, 0) = 0xb1; + WFIFOW(s, 0) = 0xb1; if (sd->status.zeny < 0) sd->status.zeny = 0; - WFIFOL(fd, 4) = sd->status.zeny; + WFIFOL(s, 4) = sd->status.zeny; break; case SP::BASEEXP: - WFIFOW(fd, 0) = 0xb1; - WFIFOL(fd, 4) = sd->status.base_exp; + WFIFOW(s, 0) = 0xb1; + WFIFOL(s, 4) = sd->status.base_exp; break; case SP::JOBEXP: - WFIFOW(fd, 0) = 0xb1; - WFIFOL(fd, 4) = sd->status.job_exp; + WFIFOW(s, 0) = 0xb1; + WFIFOL(s, 4) = sd->status.job_exp; break; case SP::NEXTBASEEXP: - WFIFOW(fd, 0) = 0xb1; - WFIFOL(fd, 4) = pc_nextbaseexp(sd); + WFIFOW(s, 0) = 0xb1; + WFIFOL(s, 4) = pc_nextbaseexp(sd); break; case SP::NEXTJOBEXP: - WFIFOW(fd, 0) = 0xb1; - WFIFOL(fd, 4) = pc_nextjobexp(sd); + WFIFOW(s, 0) = 0xb1; + WFIFOL(s, 4) = pc_nextjobexp(sd); break; // 00be 終了 @@ -1754,15 +1747,15 @@ int clif_updatestatus(dumb_ptr sd, SP type) case SP::UINT: case SP::UDEX: case SP::ULUK: - WFIFOW(fd, 0) = 0xbe; - WFIFOB(fd, 4) = pc_need_status_point(sd, usp_to_sp(type)); + WFIFOW(s, 0) = 0xbe; + WFIFOB(s, 4) = pc_need_status_point(sd, usp_to_sp(type)); len = 5; break; // 013a 終了 case SP::ATTACKRANGE: - WFIFOW(fd, 0) = 0x13a; - WFIFOW(fd, 2) = (sd->attack_spell_override) + WFIFOW(s, 0) = 0x13a; + WFIFOW(s, 2) = (sd->attack_spell_override) ? sd->attack_spell_range : sd->attackrange; len = 4; break; @@ -1776,16 +1769,16 @@ int clif_updatestatus(dumb_ptr sd, SP type) case SP::LUK: { ATTR attr = sp_to_attr(type); - WFIFOW(fd, 0) = 0x141; - WFIFOL(fd, 2) = uint16_t(type); - WFIFOL(fd, 6) = sd->status.attrs[attr]; - WFIFOL(fd, 10) = sd->paramb[attr] + sd->parame[attr]; + WFIFOW(s, 0) = 0x141; + WFIFOL(s, 2) = uint16_t(type); + WFIFOL(s, 6) = sd->status.attrs[attr]; + WFIFOL(s, 10) = sd->paramb[attr] + sd->parame[attr]; len = 14; } break; case SP::GM: - WFIFOL(fd, 4) = pc_isGM(sd); + WFIFOL(s, 4) = pc_isGM(sd); break; default: @@ -1794,7 +1787,7 @@ int clif_updatestatus(dumb_ptr sd, SP type) type); return 1; } - WFIFOSET(fd, len); + WFIFOSET(s, len); return 0; } @@ -1894,40 +1887,40 @@ int clif_initialstatus(dumb_ptr sd) { nullpo_ret(sd); - int fd = sd->fd; - - WFIFOW(fd, 0) = 0xbd; - WFIFOW(fd, 2) = sd->status.status_point; - - WFIFOB(fd, 4) = min(sd->status.attrs[ATTR::STR], 255); - WFIFOB(fd, 5) = pc_need_status_point(sd, SP::STR); - WFIFOB(fd, 6) = min(sd->status.attrs[ATTR::AGI], 255); - WFIFOB(fd, 7) = pc_need_status_point(sd, SP::AGI); - WFIFOB(fd, 8) = min(sd->status.attrs[ATTR::VIT], 255); - WFIFOB(fd, 9) = pc_need_status_point(sd, SP::VIT); - WFIFOB(fd, 10) = min(sd->status.attrs[ATTR::INT], 255); - WFIFOB(fd, 11) = pc_need_status_point(sd, SP::INT); - WFIFOB(fd, 12) = min(sd->status.attrs[ATTR::DEX], 255); - WFIFOB(fd, 13) = pc_need_status_point(sd, SP::DEX); - WFIFOB(fd, 14) = min(sd->status.attrs[ATTR::LUK], 255); - WFIFOB(fd, 15) = pc_need_status_point(sd, SP::LUK); - - WFIFOW(fd, 16) = sd->base_atk + sd->watk; - WFIFOW(fd, 18) = sd->watk2; //atk bonus - WFIFOW(fd, 20) = sd->matk1; - WFIFOW(fd, 22) = sd->matk2; - WFIFOW(fd, 24) = sd->def; // def - WFIFOW(fd, 26) = sd->def2; - WFIFOW(fd, 28) = sd->mdef; // mdef - WFIFOW(fd, 30) = sd->mdef2; - WFIFOW(fd, 32) = sd->hit; - WFIFOW(fd, 34) = sd->flee; - WFIFOW(fd, 36) = sd->flee2 / 10; - WFIFOW(fd, 38) = sd->critical / 10; - WFIFOW(fd, 40) = sd->status.karma; - WFIFOW(fd, 42) = sd->status.manner; - - WFIFOSET(fd, clif_parse_func_table[0xbd].len); + Session *s = sd->sess; + + WFIFOW(s, 0) = 0xbd; + WFIFOW(s, 2) = sd->status.status_point; + + WFIFOB(s, 4) = min(sd->status.attrs[ATTR::STR], 255); + WFIFOB(s, 5) = pc_need_status_point(sd, SP::STR); + WFIFOB(s, 6) = min(sd->status.attrs[ATTR::AGI], 255); + WFIFOB(s, 7) = pc_need_status_point(sd, SP::AGI); + WFIFOB(s, 8) = min(sd->status.attrs[ATTR::VIT], 255); + WFIFOB(s, 9) = pc_need_status_point(sd, SP::VIT); + WFIFOB(s, 10) = min(sd->status.attrs[ATTR::INT], 255); + WFIFOB(s, 11) = pc_need_status_point(sd, SP::INT); + WFIFOB(s, 12) = min(sd->status.attrs[ATTR::DEX], 255); + WFIFOB(s, 13) = pc_need_status_point(sd, SP::DEX); + WFIFOB(s, 14) = min(sd->status.attrs[ATTR::LUK], 255); + WFIFOB(s, 15) = pc_need_status_point(sd, SP::LUK); + + WFIFOW(s, 16) = sd->base_atk + sd->watk; + WFIFOW(s, 18) = sd->watk2; //atk bonus + WFIFOW(s, 20) = sd->matk1; + WFIFOW(s, 22) = sd->matk2; + WFIFOW(s, 24) = sd->def; // def + WFIFOW(s, 26) = sd->def2; + WFIFOW(s, 28) = sd->mdef; // mdef + WFIFOW(s, 30) = sd->mdef2; + WFIFOW(s, 32) = sd->hit; + WFIFOW(s, 34) = sd->flee; + WFIFOW(s, 36) = sd->flee2 / 10; + WFIFOW(s, 38) = sd->critical / 10; + WFIFOW(s, 40) = sd->status.karma; + WFIFOW(s, 42) = sd->status.manner; + + WFIFOSET(s, clif_parse_func_table[0xbd].len); clif_updatestatus(sd, SP::STR); clif_updatestatus(sd, SP::AGI); @@ -1948,18 +1941,16 @@ int clif_initialstatus(dumb_ptr sd) */ int clif_arrowequip(dumb_ptr sd, int val) { - int fd; - nullpo_ret(sd); if (sd->attacktarget && sd->attacktarget > 0) // [Valaris] sd->attacktarget = 0; - fd = sd->fd; - WFIFOW(fd, 0) = 0x013c; - WFIFOW(fd, 2) = val + 2; //矢のアイテムID + Session *s = sd->sess; + WFIFOW(s, 0) = 0x013c; + WFIFOW(s, 2) = val + 2; //矢のアイテムID - WFIFOSET(fd, clif_parse_func_table[0x013c].len); + WFIFOSET(s, clif_parse_func_table[0x013c].len); return 0; } @@ -1970,15 +1961,14 @@ int clif_arrowequip(dumb_ptr sd, int val) */ int clif_arrow_fail(dumb_ptr sd, int type) { - int fd; - nullpo_ret(sd); - fd = sd->fd; - WFIFOW(fd, 0) = 0x013b; - WFIFOW(fd, 2) = type; + Session *s = sd->sess; + + WFIFOW(s, 0) = 0x013b; + WFIFOW(s, 2) = type; - WFIFOSET(fd, clif_parse_func_table[0x013b].len); + WFIFOSET(s, clif_parse_func_table[0x013b].len); return 0; } @@ -1989,16 +1979,14 @@ int clif_arrow_fail(dumb_ptr sd, int type) */ int clif_statusupack(dumb_ptr sd, SP type, int ok, int val) { - int fd; - nullpo_ret(sd); - fd = sd->fd; - WFIFOW(fd, 0) = 0xbc; - WFIFOW(fd, 2) = uint16_t(type); - WFIFOB(fd, 4) = ok; - WFIFOB(fd, 5) = val; - WFIFOSET(fd, clif_parse_func_table[0xbc].len); + Session *s = sd->sess; + WFIFOW(s, 0) = 0xbc; + WFIFOW(s, 2) = uint16_t(type); + WFIFOB(s, 4) = ok; + WFIFOB(s, 5) = val; + WFIFOSET(s, clif_parse_func_table[0xbc].len); return 0; } @@ -2009,16 +1997,14 @@ int clif_statusupack(dumb_ptr sd, SP type, int ok, int val) */ int clif_equipitemack(dumb_ptr sd, int n, EPOS pos, int ok) { - int fd; - nullpo_ret(sd); - fd = sd->fd; - WFIFOW(fd, 0) = 0xaa; - WFIFOW(fd, 2) = n + 2; - WFIFOW(fd, 4) = uint16_t(pos); - WFIFOB(fd, 6) = ok; - WFIFOSET(fd, clif_parse_func_table[0xaa].len); + Session *s = sd->sess; + WFIFOW(s, 0) = 0xaa; + WFIFOW(s, 2) = n + 2; + WFIFOW(s, 4) = uint16_t(pos); + WFIFOB(s, 6) = ok; + WFIFOSET(s, clif_parse_func_table[0xaa].len); return 0; } @@ -2029,16 +2015,14 @@ int clif_equipitemack(dumb_ptr sd, int n, EPOS pos, int ok) */ int clif_unequipitemack(dumb_ptr sd, int n, EPOS pos, int ok) { - int fd; - nullpo_ret(sd); - fd = sd->fd; - WFIFOW(fd, 0) = 0xac; - WFIFOW(fd, 2) = n + 2; - WFIFOW(fd, 4) = uint16_t(pos); - WFIFOB(fd, 6) = ok; - WFIFOSET(fd, clif_parse_func_table[0xac].len); + Session *s = sd->sess; + WFIFOW(s, 0) = 0xac; + WFIFOW(s, 2) = n + 2; + WFIFOW(s, 4) = uint16_t(pos); + WFIFOB(s, 6) = ok; + WFIFOSET(s, clif_parse_func_table[0xac].len); return 0; } @@ -2099,12 +2083,12 @@ int clif_useitemack(dumb_ptr sd, int index, int amount, if (!ok) { - int fd = sd->fd; - WFIFOW(fd, 0) = 0xa8; - WFIFOW(fd, 2) = index + 2; - WFIFOW(fd, 4) = amount; - WFIFOB(fd, 6) = ok; - WFIFOSET(fd, clif_parse_func_table[0xa8].len); + Session *s = sd->sess; + WFIFOW(s, 0) = 0xa8; + WFIFOW(s, 2) = index + 2; + WFIFOW(s, 4) = amount; + WFIFOB(s, 6) = ok; + WFIFOSET(s, clif_parse_func_table[0xa8].len); } else { @@ -2130,10 +2114,10 @@ void clif_traderequest(dumb_ptr sd, CharName name) { nullpo_retv(sd); - int fd = sd->fd; - WFIFOW(fd, 0) = 0xe5; - WFIFO_STRING(fd, 2, name.to__actual(), 24); - WFIFOSET(fd, clif_parse_func_table[0xe5].len); + Session *s = sd->sess; + WFIFOW(s, 0) = 0xe5; + WFIFO_STRING(s, 2, name.to__actual(), 24); + WFIFOSET(s, clif_parse_func_table[0xe5].len); } /*========================================== @@ -2144,10 +2128,10 @@ void clif_tradestart(dumb_ptr sd, int type) { nullpo_retv(sd); - int fd = sd->fd; - WFIFOW(fd, 0) = 0xe7; - WFIFOB(fd, 2) = type; - WFIFOSET(fd, clif_parse_func_table[0xe7].len); + Session *s = sd->sess; + WFIFOW(s, 0) = 0xe7; + WFIFOB(s, 2) = type; + WFIFOSET(s, clif_parse_func_table[0xe7].len); } /*========================================== @@ -2160,48 +2144,48 @@ void clif_tradeadditem(dumb_ptr sd, nullpo_retv(sd); nullpo_retv(tsd); - int fd = tsd->fd; - WFIFOW(fd, 0) = 0xe9; - WFIFOL(fd, 2) = amount; + Session *s = tsd->sess; + WFIFOW(s, 0) = 0xe9; + WFIFOL(s, 2) = amount; if (index == 0) { - WFIFOW(fd, 6) = 0; // type id - WFIFOB(fd, 8) = 0; //identify flag - WFIFOB(fd, 9) = 0; // attribute - WFIFOB(fd, 10) = 0; //refine - WFIFOW(fd, 11) = 0; //card (4w) - WFIFOW(fd, 13) = 0; //card (4w) - WFIFOW(fd, 15) = 0; //card (4w) - WFIFOW(fd, 17) = 0; //card (4w) + WFIFOW(s, 6) = 0; // type id + WFIFOB(s, 8) = 0; //identify flag + WFIFOB(s, 9) = 0; // attribute + WFIFOB(s, 10) = 0; //refine + WFIFOW(s, 11) = 0; //card (4w) + WFIFOW(s, 13) = 0; //card (4w) + WFIFOW(s, 15) = 0; //card (4w) + WFIFOW(s, 17) = 0; //card (4w) } else { index -= 2; - WFIFOW(fd, 6) = sd->status.inventory[index].nameid; // type id - WFIFOB(fd, 8) = sd->status.inventory[index].identify; //identify flag + WFIFOW(s, 6) = sd->status.inventory[index].nameid; // type id + WFIFOB(s, 8) = sd->status.inventory[index].identify; //identify flag if (sd->status.inventory[index].broken == 1) - WFIFOB(fd, 9) = 1; // is broke weapon [Valaris] + WFIFOB(s, 9) = 1; // is broke weapon [Valaris] else - WFIFOB(fd, 9) = sd->status.inventory[index].attribute; // attribute - WFIFOB(fd, 10) = sd->status.inventory[index].refine; //refine + WFIFOB(s, 9) = sd->status.inventory[index].attribute; // attribute + WFIFOB(s, 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] == 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) - WFIFOW(fd, 15) = sd->status.inventory[index].card[2]; //card (4w) - WFIFOW(fd, 17) = sd->status.inventory[index].card[3]; //card (4w) + WFIFOW(s, 11) = sd->status.inventory[index].card[0]; //card (4w) + WFIFOW(s, 13) = sd->status.inventory[index].card[1]; //card (4w) + WFIFOW(s, 15) = sd->status.inventory[index].card[2]; //card (4w) + WFIFOW(s, 17) = sd->status.inventory[index].card[3]; //card (4w) } else { - WFIFOW(fd, 11) = sd->status.inventory[index].card[0]; - WFIFOW(fd, 13) = sd->status.inventory[index].card[1]; - WFIFOW(fd, 15) = sd->status.inventory[index].card[2]; - WFIFOW(fd, 17) = sd->status.inventory[index].card[3]; + WFIFOW(s, 11) = sd->status.inventory[index].card[0]; + WFIFOW(s, 13) = sd->status.inventory[index].card[1]; + WFIFOW(s, 15) = sd->status.inventory[index].card[2]; + WFIFOW(s, 17) = sd->status.inventory[index].card[3]; } } - WFIFOSET(fd, clif_parse_func_table[0xe9].len); + WFIFOSET(s, clif_parse_func_table[0xe9].len); } /*========================================== @@ -2211,16 +2195,14 @@ void clif_tradeadditem(dumb_ptr sd, int clif_tradeitemok(dumb_ptr sd, int index, int amount, int fail) { - int fd; - nullpo_ret(sd); - fd = sd->fd; - WFIFOW(fd, 0) = 0x1b1; - WFIFOW(fd, 2) = index; - WFIFOW(fd, 4) = amount; - WFIFOB(fd, 6) = fail; - WFIFOSET(fd, clif_parse_func_table[0x1b1].len); + Session *s = sd->sess; + WFIFOW(s, 0) = 0x1b1; + WFIFOW(s, 2) = index; + WFIFOW(s, 4) = amount; + WFIFOB(s, 6) = fail; + WFIFOSET(s, clif_parse_func_table[0x1b1].len); return 0; } @@ -2231,14 +2213,12 @@ int clif_tradeitemok(dumb_ptr sd, int index, int amount, */ int clif_tradedeal_lock(dumb_ptr sd, int fail) { - int fd; - nullpo_ret(sd); - fd = sd->fd; - WFIFOW(fd, 0) = 0xec; - WFIFOB(fd, 2) = fail; // 0=you 1=the other person - WFIFOSET(fd, clif_parse_func_table[0xec].len); + Session *s = sd->sess; + WFIFOW(s, 0) = 0xec; + WFIFOB(s, 2) = fail; // 0=you 1=the other person + WFIFOSET(s, clif_parse_func_table[0xec].len); return 0; } @@ -2249,13 +2229,11 @@ int clif_tradedeal_lock(dumb_ptr sd, int fail) */ int clif_tradecancelled(dumb_ptr sd) { - int fd; - nullpo_ret(sd); - fd = sd->fd; - WFIFOW(fd, 0) = 0xee; - WFIFOSET(fd, clif_parse_func_table[0xee].len); + Session *s = sd->sess; + WFIFOW(s, 0) = 0xee; + WFIFOSET(s, clif_parse_func_table[0xee].len); return 0; } @@ -2266,14 +2244,12 @@ int clif_tradecancelled(dumb_ptr sd) */ int clif_tradecompleted(dumb_ptr sd, int fail) { - int fd; - nullpo_ret(sd); - fd = sd->fd; - WFIFOW(fd, 0) = 0xf0; - WFIFOB(fd, 2) = fail; - WFIFOSET(fd, clif_parse_func_table[0xf0].len); + Session *s = sd->sess; + WFIFOW(s, 0) = 0xf0; + WFIFOB(s, 2) = fail; + WFIFOSET(s, clif_parse_func_table[0xf0].len); return 0; } @@ -2285,16 +2261,14 @@ int clif_tradecompleted(dumb_ptr sd, int fail) int clif_updatestorageamount(dumb_ptr sd, struct storage *stor) { - int fd; - nullpo_ret(sd); nullpo_ret(stor); - fd = sd->fd; - WFIFOW(fd, 0) = 0xf2; // update storage amount - WFIFOW(fd, 2) = stor->storage_amount; //items - WFIFOW(fd, 4) = MAX_STORAGE; //items max - WFIFOSET(fd, clif_parse_func_table[0xf2].len); + Session *s = sd->sess; + WFIFOW(s, 0) = 0xf2; // update storage amount + WFIFOW(s, 2) = stor->storage_amount; //items + WFIFOW(s, 4) = MAX_STORAGE; //items max + WFIFOSET(s, clif_parse_func_table[0xf2].len); return 0; } @@ -2309,37 +2283,37 @@ int clif_storageitemadded(dumb_ptr sd, struct storage *stor, nullpo_ret(sd); nullpo_ret(stor); - int fd = sd->fd; - WFIFOW(fd, 0) = 0xf4; // Storage item added - WFIFOW(fd, 2) = index + 1; // index - WFIFOL(fd, 4) = amount; // amount + Session *s = sd->sess; + WFIFOW(s, 0) = 0xf4; // Storage item added + WFIFOW(s, 2) = index + 1; // index + WFIFOL(s, 4) = amount; // amount /* if ((view = itemdb_viewid(stor->storage_[index].nameid)) > 0) WFIFOW(fd,8) =view; else*/ - WFIFOW(fd, 8) = stor->storage_[index].nameid; - WFIFOB(fd, 10) = stor->storage_[index].identify; //identify flag + WFIFOW(s, 8) = stor->storage_[index].nameid; + WFIFOB(s, 10) = stor->storage_[index].identify; //identify flag if (stor->storage_[index].broken == 1) - WFIFOB(fd, 11) = 1; // is weapon broken [Valaris] + WFIFOB(s, 11) = 1; // is weapon broken [Valaris] else - WFIFOB(fd, 11) = stor->storage_[index].attribute; // attribute - WFIFOB(fd, 12) = stor->storage_[index].refine; //refine + WFIFOB(s, 11) = stor->storage_[index].attribute; // attribute + WFIFOB(s, 12) = stor->storage_[index].refine; //refine if (stor->storage_[index].card[0] == 0x00ff || stor->storage_[index].card[0] == 0x00fe || 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) - WFIFOW(fd, 17) = stor->storage_[index].card[2]; //card (4w) - WFIFOW(fd, 19) = stor->storage_[index].card[3]; //card (4w) + WFIFOW(s, 13) = stor->storage_[index].card[0]; //card (4w) + WFIFOW(s, 15) = stor->storage_[index].card[1]; //card (4w) + WFIFOW(s, 17) = stor->storage_[index].card[2]; //card (4w) + WFIFOW(s, 19) = stor->storage_[index].card[3]; //card (4w) } else { - WFIFOW(fd, 13) = stor->storage_[index].card[0]; - WFIFOW(fd, 15) = stor->storage_[index].card[1]; - WFIFOW(fd, 17) = stor->storage_[index].card[2]; - WFIFOW(fd, 19) = stor->storage_[index].card[3]; + WFIFOW(s, 13) = stor->storage_[index].card[0]; + WFIFOW(s, 15) = stor->storage_[index].card[1]; + WFIFOW(s, 17) = stor->storage_[index].card[2]; + WFIFOW(s, 19) = stor->storage_[index].card[3]; } - WFIFOSET(fd, clif_parse_func_table[0xf4].len); + WFIFOSET(s, clif_parse_func_table[0xf4].len); return 0; } @@ -2351,15 +2325,13 @@ int clif_storageitemadded(dumb_ptr sd, struct storage *stor, int clif_storageitemremoved(dumb_ptr sd, int index, int amount) { - int fd; - nullpo_ret(sd); - fd = sd->fd; - WFIFOW(fd, 0) = 0xf6; // Storage item removed - WFIFOW(fd, 2) = index + 1; - WFIFOL(fd, 4) = amount; - WFIFOSET(fd, clif_parse_func_table[0xf6].len); + Session *s = sd->sess; + WFIFOW(s, 0) = 0xf6; // Storage item removed + WFIFOW(s, 2) = index + 1; + WFIFOL(s, 4) = amount; + WFIFOSET(s, clif_parse_func_table[0xf6].len); return 0; } @@ -2370,13 +2342,11 @@ int clif_storageitemremoved(dumb_ptr sd, int index, */ int clif_storageclose(dumb_ptr sd) { - int fd; - nullpo_ret(sd); - fd = sd->fd; - WFIFOW(fd, 0) = 0xf8; // Storage Closed - WFIFOSET(fd, clif_parse_func_table[0xf8].len); + Session *s = sd->sess; + WFIFOW(s, 0) = 0xf8; // Storage Closed + WFIFOSET(s, clif_parse_func_table[0xf8].len); return 0; } @@ -2416,8 +2386,8 @@ void clif_getareachar_pc(dumb_ptr sd, { len = clif_set0078(dstsd, buf); } - WFIFO_BUF_CLONE(sd->fd, buf, len); - WFIFOSET(sd->fd, len); + WFIFO_BUF_CLONE(sd->sess, buf, len); + WFIFOSET(sd->sess, len); if (battle_config.save_clothcolor == 1 && dstsd->status.clothes_color > 0) clif_changelook(dstsd, LOOK::CLOTHES_COLOR, @@ -2442,8 +2412,8 @@ void clif_getareachar_npc(dumb_ptr sd, dumb_ptr nd) if (nd->npc_class < 0 || nd->flag & 1 || nd->npc_class == INVISIBLE_CLASS) return; - len = clif_npc0078(nd, static_cast(WFIFOP(sd->fd, 0))); - WFIFOSET(sd->fd, len); + len = clif_npc0078(nd, static_cast(WFIFOP(sd->sess, 0))); + WFIFOSET(sd->sess, len); } /*========================================== @@ -2558,13 +2528,13 @@ void clif_getareachar_mob(dumb_ptr sd, dumb_ptr md) if (md->state.state == MS::WALK) { - len = clif_mob007b(md, static_cast(WFIFOP(sd->fd, 0))); - WFIFOSET(sd->fd, len); + len = clif_mob007b(md, static_cast(WFIFOP(sd->sess, 0))); + WFIFOSET(sd->sess, len); } else { - len = clif_mob0078(md, static_cast(WFIFOP(sd->fd, 0))); - WFIFOSET(sd->fd, len); + len = clif_mob0078(md, static_cast(WFIFOP(sd->sess, 0))); + WFIFOSET(sd->sess, len); } } @@ -2579,19 +2549,19 @@ void clif_getareachar_item(dumb_ptr sd, nullpo_retv(sd); nullpo_retv(fitem); - int fd = sd->fd; + Session *s = sd->sess; //009d .l .w .B .w .w .w .B .B - WFIFOW(fd, 0) = 0x9d; - WFIFOL(fd, 2) = fitem->bl_id; - WFIFOW(fd, 6) = fitem->item_data.nameid; - WFIFOB(fd, 8) = fitem->item_data.identify; - WFIFOW(fd, 9) = fitem->bl_x; - WFIFOW(fd, 11) = fitem->bl_y; - WFIFOW(fd, 13) = fitem->item_data.amount; - WFIFOB(fd, 15) = fitem->subx; - WFIFOB(fd, 16) = fitem->suby; + WFIFOW(s, 0) = 0x9d; + WFIFOL(s, 2) = fitem->bl_id; + WFIFOW(s, 6) = fitem->item_data.nameid; + WFIFOB(s, 8) = fitem->item_data.identify; + WFIFOW(s, 9) = fitem->bl_x; + WFIFOW(s, 11) = fitem->bl_y; + WFIFOW(s, 13) = fitem->item_data.amount; + WFIFOB(s, 15) = fitem->subx; + WFIFOB(s, 16) = fitem->suby; - WFIFOSET(fd, clif_parse_func_table[0x9d].len); + WFIFOSET(s, clif_parse_func_table[0x9d].len); } /*========================================== @@ -2650,19 +2620,19 @@ void clif_pcoutsight(dumb_ptr bl, dumb_ptr sd) dstsd = bl->is_player(); if (sd != dstsd) { - clif_clearchar_id(dstsd->bl_id, BeingRemoveWhy::GONE, sd->fd); - clif_clearchar_id(sd->bl_id, BeingRemoveWhy::GONE, dstsd->fd); + clif_clearchar_id(dstsd->bl_id, BeingRemoveWhy::GONE, sd->sess); + clif_clearchar_id(sd->bl_id, BeingRemoveWhy::GONE, dstsd->sess); } break; case BL::NPC: if (bl->is_npc()->npc_class != INVISIBLE_CLASS) - clif_clearchar_id(bl->bl_id, BeingRemoveWhy::GONE, sd->fd); + clif_clearchar_id(bl->bl_id, BeingRemoveWhy::GONE, sd->sess); break; case BL::MOB: - clif_clearchar_id(bl->bl_id, BeingRemoveWhy::GONE, sd->fd); + clif_clearchar_id(bl->bl_id, BeingRemoveWhy::GONE, sd->sess); break; case BL::ITEM: - clif_clearflooritem(bl->is_item(), sd->fd); + clif_clearflooritem(bl->is_item(), sd->sess); break; } } @@ -2714,7 +2684,7 @@ void clif_moboutsight(dumb_ptr bl, dumb_ptr md) if (bl->bl_type == BL::PC) { sd = bl->is_player(); - clif_clearchar_id(md->bl_id, BeingRemoveWhy::GONE, sd->fd); + clif_clearchar_id(md->bl_id, BeingRemoveWhy::GONE, sd->sess); } } @@ -2743,34 +2713,32 @@ void clif_mobinsight(dumb_ptr bl, dumb_ptr md) int clif_skillinfo(dumb_ptr sd, SkillID skillid, int type, int range) { - int fd; - nullpo_ret(sd); - fd = sd->fd; + Session *s = sd->sess; if (!sd->status.skill[skillid].lv) return 0; - WFIFOW(fd, 0) = 0x147; - WFIFOW(fd, 2) = static_cast(skillid); + WFIFOW(s, 0) = 0x147; + WFIFOW(s, 2) = static_cast(skillid); if (type < 0) - WFIFOW(fd, 4) = skill_get_inf(skillid); + WFIFOW(s, 4) = skill_get_inf(skillid); else - WFIFOW(fd, 4) = type; - WFIFOW(fd, 6) = 0; - WFIFOW(fd, 8) = sd->status.skill[skillid].lv; - WFIFOW(fd, 10) = skill_get_sp(skillid, sd->status.skill[skillid].lv); + WFIFOW(s, 4) = type; + WFIFOW(s, 6) = 0; + WFIFOW(s, 8) = sd->status.skill[skillid].lv; + WFIFOW(s, 10) = skill_get_sp(skillid, sd->status.skill[skillid].lv); if (range < 0) { range = skill_get_range(skillid, sd->status.skill[skillid].lv); if (range < 0) range = battle_get_range(sd) - (range + 1); - WFIFOW(fd, 12) = range; + WFIFOW(s, 12) = range; } else - WFIFOW(fd, 12) = range; - WFIFO_ZERO(fd, 14, 24); - WFIFOB(fd, 38) = sd->status.skill[skillid].lv < skill_get_max_raise(skillid); - WFIFOSET(fd, clif_parse_func_table[0x147].len); + WFIFOW(s, 12) = range; + WFIFO_ZERO(s, 14, 24); + WFIFOB(s, 38) = sd->status.skill[skillid].lv < skill_get_max_raise(skillid); + WFIFOSET(s, clif_parse_func_table[0x147].len); return 0; } @@ -2781,36 +2749,35 @@ int clif_skillinfo(dumb_ptr sd, SkillID skillid, int type, */ void clif_skillinfoblock(dumb_ptr sd) { - int fd; int len = 4, range; nullpo_retv(sd); - fd = sd->fd; - WFIFOW(fd, 0) = 0x10f; + Session *s = sd->sess; + WFIFOW(s, 0) = 0x10f; for (SkillID i : erange(SkillID(), MAX_SKILL)) { if (sd->status.skill[i].lv && sd->tmw_version >= 1) { // [Fate] Version 1 and later don't crash because of bad skill IDs anymore - WFIFOW(fd, len) = static_cast(i); - WFIFOW(fd, len + 2) = skill_get_inf(i); - WFIFOW(fd, len + 4) = static_cast( + WFIFOW(s, len) = static_cast(i); + WFIFOW(s, len + 2) = skill_get_inf(i); + WFIFOW(s, len + 4) = static_cast( skill_db[i].poolflags | (sd->status.skill[i].flags & SkillFlags::POOL_ACTIVATED)); - WFIFOW(fd, len + 6) = sd->status.skill[i].lv; - WFIFOW(fd, len + 8) = skill_get_sp(i, sd->status.skill[i].lv); + WFIFOW(s, len + 6) = sd->status.skill[i].lv; + WFIFOW(s, len + 8) = skill_get_sp(i, sd->status.skill[i].lv); range = skill_get_range(i, sd->status.skill[i].lv); if (range < 0) range = battle_get_range(sd) - (range + 1); - WFIFOW(fd, len + 10) = range; - WFIFO_ZERO(fd, len + 12, 24); - WFIFOB(fd, len + 36) = sd->status.skill[i].lv < skill_get_max_raise(i); + WFIFOW(s, len + 10) = range; + WFIFO_ZERO(s, len + 12, 24); + WFIFOB(s, len + 36) = sd->status.skill[i].lv < skill_get_max_raise(i); len += 37; } } - WFIFOW(fd, 2) = len; - WFIFOSET(fd, len); + WFIFOW(s, 2) = len; + WFIFOSET(s, len); } /*========================================== @@ -2819,21 +2786,21 @@ void clif_skillinfoblock(dumb_ptr sd) */ int clif_skillup(dumb_ptr sd, SkillID skill_num) { - int range, fd; + int range; nullpo_ret(sd); - fd = sd->fd; - WFIFOW(fd, 0) = 0x10e; - WFIFOW(fd, 2) = uint16_t(skill_num); - WFIFOW(fd, 4) = sd->status.skill[skill_num].lv; - WFIFOW(fd, 6) = skill_get_sp(skill_num, sd->status.skill[skill_num].lv); + Session *s = sd->sess; + WFIFOW(s, 0) = 0x10e; + WFIFOW(s, 2) = uint16_t(skill_num); + WFIFOW(s, 4) = sd->status.skill[skill_num].lv; + WFIFOW(s, 6) = skill_get_sp(skill_num, sd->status.skill[skill_num].lv); range = skill_get_range(skill_num, sd->status.skill[skill_num].lv); if (range < 0) range = battle_get_range(sd) - (range + 1); - WFIFOW(fd, 8) = range; - WFIFOB(fd, 10) = sd->status.skill[skill_num].lv < skill_get_max_raise(skill_num); - WFIFOSET(fd, clif_parse_func_table[0x10e].len); + WFIFOW(s, 8) = range; + WFIFOB(s, 10) = sd->status.skill[skill_num].lv < skill_get_max_raise(skill_num); + WFIFOSET(s, clif_parse_func_table[0x10e].len); return 0; } @@ -2862,24 +2829,22 @@ int clif_skillcastcancel(dumb_ptr bl) int clif_skill_fail(dumb_ptr sd, SkillID skill_id, int type, int btype) { - int fd; - nullpo_ret(sd); - fd = sd->fd; + Session *s = sd->sess; if (type == 0x4 && battle_config.display_delay_skill_fail == 0) { return 0; } - WFIFOW(fd, 0) = 0x110; - WFIFOW(fd, 2) = uint16_t(skill_id); - WFIFOW(fd, 4) = btype; - WFIFOW(fd, 6) = 0; - WFIFOB(fd, 8) = 0; - WFIFOB(fd, 9) = type; - WFIFOSET(fd, clif_parse_func_table[0x110].len); + WFIFOW(s, 0) = 0x110; + WFIFOW(s, 2) = uint16_t(skill_id); + WFIFOW(s, 4) = btype; + WFIFOW(s, 6) = 0; + WFIFOB(s, 8) = 0; + WFIFOB(s, 9) = type; + WFIFOSET(s, clif_parse_func_table[0x110].len); return 0; } @@ -2938,16 +2903,16 @@ int clif_status_change(dumb_ptr bl, StatusChange type, int flag) * Send message (modified by [Yor]) *------------------------------------------ */ -void clif_displaymessage(int fd, XString mes) +void clif_displaymessage(Session *s, XString mes) { 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(s, 0) = 0x8e; size_t str_len = mes.size() + 1; // NUL (might not be NUL yet) - WFIFOW(fd, 2) = 4 + str_len; - WFIFO_STRING(fd, 4, mes, str_len); - WFIFOSET(fd, 4 + str_len); + WFIFOW(s, 2) = 4 + str_len; + WFIFO_STRING(s, 4, mes, str_len); + WFIFOSET(s, 4 + str_len); } } @@ -2993,25 +2958,25 @@ void clif_resurrection(dumb_ptr bl, int type) * Wisp/page is transmitted to the destination player *------------------------------------------ */ -void clif_wis_message(int fd, CharName nick, XString mes) // R 0097 .w .24B .?B +void clif_wis_message(Session *s, CharName nick, XString mes) // R 0097 .w .24B .?B { size_t mes_len = mes.size() + 1; - WFIFOW(fd, 0) = 0x97; - WFIFOW(fd, 2) = mes_len + 24 + 4; - WFIFO_STRING(fd, 4, nick.to__actual(), 24); - WFIFO_STRING(fd, 28, mes, mes_len); - WFIFOSET(fd, WFIFOW(fd, 2)); + WFIFOW(s, 0) = 0x97; + WFIFOW(s, 2) = mes_len + 24 + 4; + WFIFO_STRING(s, 4, nick.to__actual(), 24); + WFIFO_STRING(s, 28, mes, mes_len); + WFIFOSET(s, WFIFOW(s, 2)); } /*========================================== * The transmission result of Wisp/page is transmitted to the source player *------------------------------------------ */ -void clif_wis_end(int fd, int flag) // R 0098 .B: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target +void clif_wis_end(Session *s, int flag) // R 0098 .B: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target { - WFIFOW(fd, 0) = 0x98; - WFIFOW(fd, 2) = flag; - WFIFOSET(fd, clif_parse_func_table[0x98].len); + WFIFOW(s, 0) = 0x98; + WFIFOW(s, 2) = flag; + WFIFOSET(s, clif_parse_func_table[0x98].len); } /*========================================== @@ -3028,14 +2993,12 @@ void clif_wis_end(int fd, int flag) // R 0098 .B: 0: success to send wispe */ int clif_party_created(dumb_ptr sd, int flag) { - int fd; - nullpo_ret(sd); - fd = sd->fd; - WFIFOW(fd, 0) = 0xfa; - WFIFOB(fd, 2) = flag; - WFIFOSET(fd, clif_parse_func_table[0xfa].len); + Session *s = sd->sess; + WFIFOW(s, 0) = 0xfa; + WFIFOB(s, 2) = flag; + WFIFOSET(s, clif_parse_func_table[0xfa].len); return 0; } @@ -3043,7 +3006,7 @@ int clif_party_created(dumb_ptr sd, int flag) * パーティ情報送信 *------------------------------------------ */ -int clif_party_info(struct party *p, int fd) +int clif_party_info(struct party *p, Session *s) { unsigned char buf[1024]; int i, c; @@ -3070,11 +3033,11 @@ int clif_party_info(struct party *p, int fd) } size_t len = 28 + c * 46; WBUFW(buf, 2) = len; - if (fd >= 0) + if (s) { // If set, send only to fd. - WFIFO_BUF_CLONE(fd, buf, len); - WFIFOSET(fd, len); + WFIFO_BUF_CLONE(s, buf, len); + WFIFOSET(s, len); return 9; } // else, send it to all the party, if they exist. @@ -3093,21 +3056,20 @@ int clif_party_info(struct party *p, int fd) void clif_party_invite(dumb_ptr sd, dumb_ptr tsd) { - int fd; struct party *p; nullpo_retv(sd); nullpo_retv(tsd); - fd = tsd->fd; + Session *s = tsd->sess; if (!(p = party_search(sd->status.party_id))) return; - WFIFOW(fd, 0) = 0xfe; - WFIFOL(fd, 2) = sd->status.account_id; - WFIFO_STRING(fd, 6, p->name, 24); - WFIFOSET(fd, clif_parse_func_table[0xfe].len); + WFIFOW(s, 0) = 0xfe; + WFIFOL(s, 2) = sd->status.account_id; + WFIFO_STRING(s, 6, p->name, 24); + WFIFOSET(s, clif_parse_func_table[0xfe].len); } /*========================================== @@ -3128,11 +3090,11 @@ void clif_party_inviteack(dumb_ptr sd, CharName nick, int flag { nullpo_retv(sd); - int fd = sd->fd; - WFIFOW(fd, 0) = 0xfd; - WFIFO_STRING(fd, 2, nick.to__actual(), 24); - WFIFOB(fd, 26) = flag; - WFIFOSET(fd, clif_parse_func_table[0xfd].len); + Session *s = sd->sess; + WFIFOW(s, 0) = 0xfd; + WFIFO_STRING(s, 2, nick.to__actual(), 24); + WFIFOB(s, 26) = flag; + WFIFOSET(s, clif_parse_func_table[0xfd].len); } /*========================================== @@ -3166,8 +3128,8 @@ void clif_party_option(struct party *p, dumb_ptr sd, int flag) clif_send(buf, clif_parse_func_table[0x101].len, sd, SendWho::PARTY); else { - WFIFO_BUF_CLONE(sd->fd, buf, clif_parse_func_table[0x101].len); - WFIFOSET(sd->fd, clif_parse_func_table[0x101].len); + WFIFO_BUF_CLONE(sd->sess, buf, clif_parse_func_table[0x101].len); + WFIFOSET(sd->sess, clif_parse_func_table[0x101].len); } } @@ -3202,8 +3164,8 @@ void clif_party_leaved(struct party *p, dumb_ptr sd, } else if (sd != NULL) { - WFIFO_BUF_CLONE(sd->fd, buf, clif_parse_func_table[0x105].len); - WFIFOSET(sd->fd, clif_parse_func_table[0x105].len); + WFIFO_BUF_CLONE(sd->sess, buf, clif_parse_func_table[0x105].len); + WFIFOSET(sd->sess, clif_parse_func_table[0x105].len); } } @@ -3284,20 +3246,18 @@ int clif_party_hp(struct party *, dumb_ptr sd) */ int clif_movetoattack(dumb_ptr sd, dumb_ptr bl) { - int fd; - nullpo_ret(sd); nullpo_ret(bl); - fd = sd->fd; - WFIFOW(fd, 0) = 0x139; - WFIFOL(fd, 2) = bl->bl_id; - WFIFOW(fd, 6) = bl->bl_x; - WFIFOW(fd, 8) = bl->bl_y; - WFIFOW(fd, 10) = sd->bl_x; - WFIFOW(fd, 12) = sd->bl_y; - WFIFOW(fd, 14) = sd->attackrange; - WFIFOSET(fd, clif_parse_func_table[0x139].len); + Session *s = sd->sess; + WFIFOW(s, 0) = 0x139; + WFIFOL(s, 2) = bl->bl_id; + WFIFOW(s, 6) = bl->bl_x; + WFIFOW(s, 8) = bl->bl_y; + WFIFOW(s, 10) = sd->bl_x; + WFIFOW(s, 12) = sd->bl_y; + WFIFOW(s, 14) = sd->attackrange; + WFIFOSET(s, clif_parse_func_table[0x139].len); return 0; } @@ -3351,15 +3311,15 @@ void clif_emotion_towards(dumb_ptr bl, WBUFL(buf, 2) = bl->bl_id; WBUFB(buf, 6) = type; - WFIFO_BUF_CLONE(sd->fd, buf, len); - WFIFOSET(sd->fd, len); + WFIFO_BUF_CLONE(sd->sess, buf, len); + WFIFOSET(sd->sess, len); } /*========================================== * 座る *------------------------------------------ */ -void clif_sitting(int, dumb_ptr sd) +void clif_sitting(Session *, dumb_ptr sd) { unsigned char buf[64]; @@ -3378,19 +3338,17 @@ void clif_sitting(int, dumb_ptr sd) static int clif_GM_kickack(dumb_ptr sd, int id) { - int fd; - nullpo_ret(sd); - fd = sd->fd; - WFIFOW(fd, 0) = 0xcd; - WFIFOL(fd, 2) = id; - WFIFOSET(fd, clif_parse_func_table[0xcd].len); + Session *s = sd->sess; + WFIFOW(s, 0) = 0xcd; + WFIFOL(s, 2) = id; + WFIFOSET(s, clif_parse_func_table[0xcd].len); return 0; } static -void clif_parse_QuitGame(int fd, dumb_ptr sd); +void clif_parse_QuitGame(Session *s, dumb_ptr sd); int clif_GM_kick(dumb_ptr sd, dumb_ptr tsd, int type) @@ -3401,7 +3359,7 @@ int clif_GM_kick(dumb_ptr sd, dumb_ptr tsd, clif_GM_kickack(sd, tsd->status.account_id); tsd->opt1 = Opt1::ZERO; tsd->opt2 = Opt2::ZERO; - clif_parse_QuitGame(tsd->fd, tsd); + clif_parse_QuitGame(tsd->sess, tsd); return 0; } @@ -3448,7 +3406,7 @@ int clif_specialeffect(dumb_ptr bl, int type, int flag) *------------------------------------------ */ static -void clif_parse_WantToConnection(int fd, dumb_ptr sd) +void clif_parse_WantToConnection(Session *s, dumb_ptr sd) { int account_id; // account_id in the packet @@ -3459,34 +3417,34 @@ void clif_parse_WantToConnection(int fd, dumb_ptr sd) return; } - if (RFIFOW(fd, 0) == 0x72) + if (RFIFOW(s, 0) == 0x72) { - account_id = RFIFOL(fd, 2); + account_id = RFIFOL(s, 2); } else return; // Not the auth packet - WFIFOL(fd, 0) = account_id; - WFIFOSET(fd, 4); + WFIFOL(s, 0) = account_id; + WFIFOSET(s, 4); // if same account already connected, we disconnect the 2 sessions dumb_ptr old_sd = map_id2sd(account_id); if (old_sd) { - clif_authfail_fd(fd, 2); // same id - clif_authfail_fd(old_sd->fd, 2); // same id + clif_authfail_fd(s, 2); // same id + clif_authfail_fd(old_sd->sess, 2); // same id PRINTF("clif_parse_WantToConnection: Double connection for account %d (sessions: #%d (new) and #%d (old)).\n", - account_id, fd, old_sd->fd); + account_id, s, old_sd->sess); } else { sd.new_(); - session[fd]->session_data.reset(sd.operator->()); - sd->fd = fd; + s->session_data.reset(sd.operator->()); + sd->sess = s; - pc_setnewpc(sd, account_id, RFIFOL(fd, 6), RFIFOL(fd, 10), - tick_t(static_cast(RFIFOL(fd, 14))), - static_cast(RFIFOB(fd, 18))); + pc_setnewpc(sd, account_id, RFIFOL(s, 6), RFIFOL(s, 10), + tick_t(static_cast(RFIFOL(s, 14))), + static_cast(RFIFOB(s, 18))); map_addiddb(sd); @@ -3502,7 +3460,7 @@ void clif_parse_WantToConnection(int fd, dumb_ptr sd) *------------------------------------------ */ static -void clif_parse_LoadEndAck(int, dumb_ptr sd) +void clif_parse_LoadEndAck(Session *, dumb_ptr sd) { // struct item_data* item; int i; @@ -3608,11 +3566,11 @@ void clif_parse_LoadEndAck(int, dumb_ptr sd) *------------------------------------------ */ static -void clif_parse_TickSend(int fd, dumb_ptr sd) +void clif_parse_TickSend(Session *s, dumb_ptr sd) { nullpo_retv(sd); - sd->client_tick = tick_t(static_cast(RFIFOL(fd, 2))); + sd->client_tick = tick_t(static_cast(RFIFOL(s, 2))); sd->server_tick = gettick(); clif_servertick(sd); } @@ -3622,7 +3580,7 @@ void clif_parse_TickSend(int fd, dumb_ptr sd) *------------------------------------------ */ static -void clif_parse_WalkToXY(int fd, dumb_ptr sd) +void clif_parse_WalkToXY(Session *s, dumb_ptr sd) { int x, y; @@ -3649,8 +3607,8 @@ void clif_parse_WalkToXY(int fd, dumb_ptr sd) pc_stopattack(sd); - x = RFIFOB(fd, 2) * 4 + (RFIFOB(fd, 3) >> 6); - y = ((RFIFOB(fd, 3) & 0x3f) << 4) + (RFIFOB(fd, 4) >> 4); + x = RFIFOB(s, 2) * 4 + (RFIFOB(s, 3) >> 6); + y = ((RFIFOB(s, 3) & 0x3f) << 4) + (RFIFOB(s, 4) >> 4); pc_walktoxy(sd, x, y); } @@ -3659,18 +3617,18 @@ void clif_parse_WalkToXY(int fd, dumb_ptr sd) * *------------------------------------------ */ -void clif_parse_QuitGame(int fd, dumb_ptr sd) +void clif_parse_QuitGame(Session *s, dumb_ptr sd) { tick_t tick = gettick(); nullpo_retv(sd); - WFIFOW(fd, 0) = 0x18b; + WFIFOW(s, 0) = 0x18b; if ((!pc_isdead(sd) && (sd->opt1 != Opt1::ZERO || sd->opt2 != Opt2::ZERO)) || (tick < sd->canact_tick)) { - WFIFOW(fd, 2) = 1; - WFIFOSET(fd, clif_parse_func_table[0x18b].len); + WFIFOW(s, 2) = 1; + WFIFOSET(s, clif_parse_func_table[0x18b].len); return; } @@ -3678,14 +3636,14 @@ void clif_parse_QuitGame(int fd, dumb_ptr sd) if (!battle_config.prevent_logout || tick >= sd->canlog_tick + std::chrono::seconds(10)) { - clif_setwaitclose(fd); - WFIFOW(fd, 2) = 0; + clif_setwaitclose(s); + WFIFOW(s, 2) = 0; } else { - WFIFOW(fd, 2) = 1; + WFIFOW(s, 2) = 1; } - WFIFOSET(fd, clif_parse_func_table[0x18b].len); + WFIFOSET(s, clif_parse_func_table[0x18b].len); } @@ -3694,18 +3652,18 @@ void clif_parse_QuitGame(int fd, dumb_ptr sd) *------------------------------------------ */ static -void clif_parse_GetCharNameRequest(int fd, dumb_ptr sd) +void clif_parse_GetCharNameRequest(Session *s, dumb_ptr sd) { dumb_ptr bl; int account_id; - account_id = RFIFOL(fd, 2); + account_id = RFIFOL(s, 2); bl = map_id2bl(account_id); if (bl == NULL) return; - WFIFOW(fd, 0) = 0x95; - WFIFOL(fd, 2) = account_id; + WFIFOW(s, 0) = 0x95; + WFIFOL(s, 2) = account_id; switch (bl->bl_type) { @@ -3716,10 +3674,10 @@ void clif_parse_GetCharNameRequest(int fd, dumb_ptr sd) nullpo_retv(ssd); if (ssd->state.shroud_active) - WFIFO_STRING(fd, 6, "", 24); + WFIFO_STRING(s, 6, "", 24); else - WFIFO_STRING(fd, 6, ssd->status.name.to__actual(), 24); - WFIFOSET(fd, clif_parse_func_table[0x95].len); + WFIFO_STRING(s, 6, ssd->status.name.to__actual(), 24); + WFIFOSET(s, clif_parse_func_table[0x95].len); struct party *p = NULL; @@ -3735,28 +3693,28 @@ void clif_parse_GetCharNameRequest(int fd, dumb_ptr sd) if (send) { - WFIFOW(fd, 0) = 0x195; - WFIFOL(fd, 2) = account_id; - WFIFO_STRING(fd, 6, party_name, 24); - WFIFO_STRING(fd, 30, "", 24); - WFIFO_STRING(fd, 54, "", 24); - WFIFO_STRING(fd, 78, "", 24); // We send this value twice because the client expects it - WFIFOSET(fd, clif_parse_func_table[0x195].len); + WFIFOW(s, 0) = 0x195; + WFIFOL(s, 2) = account_id; + WFIFO_STRING(s, 6, party_name, 24); + WFIFO_STRING(s, 30, "", 24); + WFIFO_STRING(s, 54, "", 24); + WFIFO_STRING(s, 78, "", 24); // We send this value twice because the client expects it + WFIFOSET(s, clif_parse_func_table[0x195].len); } if (pc_isGM(sd) >= battle_config.hack_info_GM_level) { IP4Address ip = ssd->get_ip(); - WFIFOW(fd, 0) = 0x20C; + WFIFOW(s, 0) = 0x20C; // Mask the IP using the char-server password if (battle_config.mask_ip_gms) ip = MD5_ip(ip); - WFIFOL(fd, 2) = account_id; - WFIFOIP(fd, 6) = ip; - WFIFOSET(fd, clif_parse_func_table[0x20C].len); + WFIFOL(s, 2) = account_id; + WFIFOIP(s, 6) = ip; + WFIFOSET(s, clif_parse_func_table[0x20C].len); } } @@ -3766,8 +3724,8 @@ void clif_parse_GetCharNameRequest(int fd, dumb_ptr sd) NpcName name = bl->is_npc()->name; // [fate] elim hashed out/invisible names for the client auto it = std::find(name.begin(), name.end(), '#'); - WFIFO_STRING(fd, 6, name.xislice_h(it), 24); - WFIFOSET(fd, clif_parse_func_table[0x95].len); + WFIFO_STRING(s, 6, name.xislice_h(it), 24); + WFIFOSET(s, clif_parse_func_table[0x95].len); } break; case BL::MOB: @@ -3776,8 +3734,8 @@ void clif_parse_GetCharNameRequest(int fd, dumb_ptr sd) nullpo_retv(md); - WFIFO_STRING(fd, 6, md->name, 24); - WFIFOSET(fd, clif_parse_func_table[0x95].len); + WFIFO_STRING(s, 6, md->name, 24); + WFIFOSET(s, clif_parse_func_table[0x95].len); } break; default: @@ -3796,18 +3754,18 @@ void clif_parse_GetCharNameRequest(int fd, dumb_ptr sd) *------------------------------------------ */ static -void clif_parse_GlobalMessage(int fd, dumb_ptr sd) +void clif_parse_GlobalMessage(Session *s, dumb_ptr sd) { nullpo_retv(sd); FString mbuf = clif_validate_chat(sd, ChatType::Global); if (!mbuf) { - clif_displaymessage(fd, "Your message could not be sent."); + clif_displaymessage(s, "Your message could not be sent."); return; } - if (is_atcommand(fd, sd, mbuf, 0)) + if (is_atcommand(s, sd, mbuf, 0)) return; if (!magic_message(sd, mbuf)) @@ -3815,7 +3773,7 @@ void clif_parse_GlobalMessage(int fd, dumb_ptr sd) /* Don't send chat that results in an automatic ban. */ if (tmw_CheckChatSpam(sd, mbuf)) { - clif_displaymessage(fd, "Your message could not be sent."); + clif_displaymessage(s, "Your message could not be sent."); return; } @@ -3831,10 +3789,10 @@ void clif_parse_GlobalMessage(int fd, dumb_ptr sd) } /* Send the message back to the speaker. */ - size_t len = RFIFOW(fd, 2); - RFIFO_WFIFO_CLONE(fd, fd, len); - WFIFOW(fd, 0) = 0x8e; - WFIFOSET(fd, len); + size_t len = RFIFOW(s, 2); + RFIFO_WFIFO_CLONE(s, s, len); + WFIFOW(s, 0) = 0x8e; + WFIFOSET(s, len); } void clif_message(dumb_ptr bl, XString msg) @@ -3860,7 +3818,7 @@ void clif_message(dumb_ptr bl, XString msg) *------------------------------------------ */ static -void clif_parse_ChangeDir(int fd, dumb_ptr sd) +void clif_parse_ChangeDir(Session *s, dumb_ptr sd) { unsigned char buf[64]; @@ -3869,7 +3827,7 @@ void clif_parse_ChangeDir(int fd, dumb_ptr sd) // RFIFOW(fd, 2) and WBUFW(buf, 6) are always 0 // TODO perhaps we could use that to remove this hack? DIR dir; - uint8_t client_dir = RFIFOB(fd, 4); + uint8_t client_dir = RFIFOB(s, 4); // the client uses a diffenent direction enum ... ugh switch (client_dir) { @@ -3904,7 +3862,7 @@ void clif_parse_ChangeDir(int fd, dumb_ptr sd) *------------------------------------------ */ static -void clif_parse_Emotion(int fd, dumb_ptr sd) +void clif_parse_Emotion(Session *s, dumb_ptr sd) { unsigned char buf[64]; @@ -3913,7 +3871,7 @@ void clif_parse_Emotion(int fd, dumb_ptr sd) if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, SkillID::NV_EMOTE) >= 1) { - uint8_t emote = RFIFOB(fd, 2); + uint8_t emote = RFIFOB(s, 2); WBUFW(buf, 0) = 0xc0; WBUFL(buf, 2) = sd->bl_id; WBUFB(buf, 6) = emote; @@ -3928,11 +3886,11 @@ void clif_parse_Emotion(int fd, dumb_ptr sd) *------------------------------------------ */ static -void clif_parse_HowManyConnections(int fd, dumb_ptr) +void clif_parse_HowManyConnections(Session *s, dumb_ptr) { - WFIFOW(fd, 0) = 0xc2; - WFIFOL(fd, 2) = map_getusers(); - WFIFOSET(fd, clif_parse_func_table[0xc2].len); + WFIFOW(s, 0) = 0xc2; + WFIFOL(s, 2) = map_getusers(); + WFIFOSET(s, clif_parse_func_table[0xc2].len); } /*========================================== @@ -3940,7 +3898,7 @@ void clif_parse_HowManyConnections(int fd, dumb_ptr) *------------------------------------------ */ static -void clif_parse_ActionRequest(int fd, dumb_ptr sd) +void clif_parse_ActionRequest(Session *s, dumb_ptr sd) { unsigned char buf[64]; int action_type, target_id; @@ -3962,8 +3920,8 @@ void clif_parse_ActionRequest(int fd, dumb_ptr sd) pc_stop_walking(sd, 0); pc_stopattack(sd); - target_id = RFIFOL(fd, 2); - action_type = RFIFOB(fd, 6); + target_id = RFIFOL(s, 2); + action_type = RFIFOB(s, 6); switch (action_type) { @@ -3988,7 +3946,7 @@ void clif_parse_ActionRequest(int fd, dumb_ptr sd) case 0x02: // sitdown pc_stop_walking(sd, 1); pc_setsit(sd); - clif_sitting(fd, sd); + clif_sitting(s, sd); break; case 0x03: // standup pc_setstand(sd); @@ -4005,11 +3963,11 @@ void clif_parse_ActionRequest(int fd, dumb_ptr sd) *------------------------------------------ */ static -void clif_parse_Restart(int fd, dumb_ptr sd) +void clif_parse_Restart(Session *s, dumb_ptr sd) { nullpo_retv(sd); - switch (RFIFOB(fd, 2)) + switch (RFIFOB(s, 2)) { case 0x00: if (pc_isdead(sd)) @@ -4030,10 +3988,10 @@ void clif_parse_Restart(int fd, dumb_ptr sd) } else { - WFIFOW(fd, 0) = 0x18b; - WFIFOW(fd, 2) = 1; + WFIFOW(s, 0) = 0x18b; + WFIFOW(s, 2) = 1; - WFIFOSET(fd, clif_parse_func_table[0x018b].len); + WFIFOSET(s, clif_parse_func_table[0x018b].len); } break; } @@ -4050,7 +4008,7 @@ void clif_parse_Restart(int fd, dumb_ptr sd) *------------------------------------------ */ static -void clif_parse_Wis(int fd, dumb_ptr sd) +void clif_parse_Wis(Session *s, dumb_ptr sd) { dumb_ptr dstsd = NULL; @@ -4059,11 +4017,11 @@ void clif_parse_Wis(int fd, dumb_ptr sd) FString mbuf = clif_validate_chat(sd, ChatType::Whisper); if (!mbuf) { - clif_displaymessage(fd, "Your message could not be sent."); + clif_displaymessage(s, "Your message could not be sent."); return; } - if (is_atcommand(fd, sd, mbuf, 0)) + if (is_atcommand(s, sd, mbuf, 0)) { return; } @@ -4071,7 +4029,7 @@ void clif_parse_Wis(int fd, dumb_ptr sd) /* Don't send chat that results in an automatic ban. */ if (tmw_CheckChatSpam(sd, mbuf)) { - clif_displaymessage(fd, "Your message could not be sent."); + clif_displaymessage(s, "Your message could not be sent."); return; } @@ -4081,26 +4039,26 @@ void clif_parse_Wis(int fd, dumb_ptr sd) * conflict (for instance, "Test" versus "test"), the char-server must * settle the discrepancy. */ - CharName tname = stringish(RFIFO_STRING<24>(fd, 4)); + CharName tname = stringish(RFIFO_STRING<24>(s, 4)); if (!(dstsd = map_nick2sd(tname)) || dstsd->status.name != tname) intif_wis_message(sd, tname, mbuf); else { /* Refuse messages addressed to self. */ - if (dstsd->fd == fd) + if (dstsd->sess == s) { ZString mes = "You cannot page yourself."; - clif_wis_message(fd, wisp_server_name, mes); + clif_wis_message(s, wisp_server_name, mes); } else { { /* The player is not being ignored. */ { - clif_wis_message(dstsd->fd, sd->status.name, mbuf); + clif_wis_message(dstsd->sess, sd->status.name, mbuf); /* The whisper was sent successfully. */ - clif_wis_end(fd, 0); + clif_wis_end(s, 0); } } } @@ -4112,14 +4070,14 @@ void clif_parse_Wis(int fd, dumb_ptr sd) *------------------------------------------ */ static -void clif_parse_TakeItem(int fd, dumb_ptr sd) +void clif_parse_TakeItem(Session *s, dumb_ptr sd) { dumb_ptr fitem; int map_object_id; nullpo_retv(sd); - map_object_id = RFIFOL(fd, 2); + map_object_id = RFIFOL(s, 2); fitem = map_id_is_item(map_object_id); if (pc_isdead(sd)) @@ -4150,7 +4108,7 @@ void clif_parse_TakeItem(int fd, dumb_ptr sd) *------------------------------------------ */ static -void clif_parse_DropItem(int fd, dumb_ptr sd) +void clif_parse_DropItem(Session *s, dumb_ptr sd) { int item_index, item_amount; @@ -4163,18 +4121,18 @@ void clif_parse_DropItem(int fd, dumb_ptr sd) } if (sd->bl_m->flag.no_player_drops) { - clif_displaymessage(sd->fd, "Can't drop items here."); + clif_displaymessage(sd->sess, "Can't drop items here."); return; } if (sd->npc_id != 0 || sd->opt1 != Opt1::ZERO) { - clif_displaymessage(sd->fd, "Can't drop items right now."); + clif_displaymessage(sd->sess, "Can't drop items right now."); return; } - item_index = RFIFOW(fd, 2) - 2; - item_amount = RFIFOW(fd, 4); + item_index = RFIFOW(s, 2) - 2; + item_amount = RFIFOW(s, 4); pc_dropitem(sd, item_index, item_amount); } @@ -4184,7 +4142,7 @@ void clif_parse_DropItem(int fd, dumb_ptr sd) *------------------------------------------ */ static -void clif_parse_UseItem(int fd, dumb_ptr sd) +void clif_parse_UseItem(Session *s, dumb_ptr sd) { nullpo_retv(sd); @@ -4200,7 +4158,7 @@ void clif_parse_UseItem(int fd, dumb_ptr sd) if (sd->invincible_timer) pc_delinvincibletimer(sd); - pc_useitem(sd, RFIFOW(fd, 2) - 2); + pc_useitem(sd, RFIFOW(s, 2) - 2); } /*========================================== @@ -4208,7 +4166,7 @@ void clif_parse_UseItem(int fd, dumb_ptr sd) *------------------------------------------ */ static -void clif_parse_EquipItem(int fd, dumb_ptr sd) +void clif_parse_EquipItem(Session *s, dumb_ptr sd) { int index; @@ -4219,7 +4177,7 @@ void clif_parse_EquipItem(int fd, dumb_ptr sd) clif_clearchar(sd, BeingRemoveWhy::DEAD); return; } - index = RFIFOW(fd, 2) - 2; + index = RFIFOW(s, 2) - 2; if (sd->npc_id != 0) return; @@ -4234,7 +4192,7 @@ void clif_parse_EquipItem(int fd, dumb_ptr sd) //ペット用装備であるかないか if (sd->inventory_data[index]) { - EPOS epos = EPOS(RFIFOW(fd, 4)); + EPOS epos = EPOS(RFIFOW(s, 4)); if (sd->inventory_data[index]->type == ItemType::ARROW) // 矢を無理やり装備できるように(−−; epos = EPOS::ARROW; @@ -4249,7 +4207,7 @@ void clif_parse_EquipItem(int fd, dumb_ptr sd) *------------------------------------------ */ static -void clif_parse_UnequipItem(int fd, dumb_ptr sd) +void clif_parse_UnequipItem(Session *s, dumb_ptr sd) { int index; @@ -4260,7 +4218,7 @@ void clif_parse_UnequipItem(int fd, dumb_ptr sd) clif_clearchar(sd, BeingRemoveWhy::DEAD); return; } - index = RFIFOW(fd, 2) - 2; + index = RFIFOW(s, 2) - 2; if (sd->status.inventory[index].broken == 1 && sd->sc_data[StatusChange::SC_BROKNWEAPON].timer) skill_status_change_end(sd, StatusChange::SC_BROKNWEAPON, nullptr); if (sd->status.inventory[index].broken == 1 && sd->sc_data[StatusChange::SC_BROKNARMOR].timer) @@ -4277,7 +4235,7 @@ void clif_parse_UnequipItem(int fd, dumb_ptr sd) *------------------------------------------ */ static -void clif_parse_NpcClicked(int fd, dumb_ptr sd) +void clif_parse_NpcClicked(Session *s, dumb_ptr sd) { nullpo_retv(sd); @@ -4288,7 +4246,7 @@ void clif_parse_NpcClicked(int fd, dumb_ptr sd) } if (sd->npc_id != 0) return; - npc_click(sd, RFIFOL(fd, 2)); + npc_click(sd, RFIFOL(s, 2)); } /*========================================== @@ -4296,9 +4254,9 @@ void clif_parse_NpcClicked(int fd, dumb_ptr sd) *------------------------------------------ */ static -void clif_parse_NpcBuySellSelected(int fd, dumb_ptr sd) +void clif_parse_NpcBuySellSelected(Session *s, dumb_ptr sd) { - npc_buysellsel(sd, RFIFOL(fd, 2), RFIFOB(fd, 6)); + npc_buysellsel(sd, RFIFOL(s, 2), RFIFOB(s, 6)); } /*========================================== @@ -4306,17 +4264,17 @@ void clif_parse_NpcBuySellSelected(int fd, dumb_ptr sd) *------------------------------------------ */ static -void clif_parse_NpcBuyListSend(int fd, dumb_ptr sd) +void clif_parse_NpcBuyListSend(Session *s, dumb_ptr sd) { - int n = (RFIFOW(fd, 2) - 4) / 4; + int n = (RFIFOW(s, 2) - 4) / 4; // really an array of pairs of uint16_t - const uint16_t *item_list = static_cast(RFIFOP(fd, 4)); + const uint16_t *item_list = static_cast(RFIFOP(s, 4)); int fail = npc_buylist(sd, n, item_list); - WFIFOW(fd, 0) = 0xca; - WFIFOB(fd, 2) = fail; - WFIFOSET(fd, clif_parse_func_table[0xca].len); + WFIFOW(s, 0) = 0xca; + WFIFOB(s, 2) = fail; + WFIFOSET(s, clif_parse_func_table[0xca].len); } /*========================================== @@ -4324,17 +4282,17 @@ void clif_parse_NpcBuyListSend(int fd, dumb_ptr sd) *------------------------------------------ */ static -void clif_parse_NpcSellListSend(int fd, dumb_ptr sd) +void clif_parse_NpcSellListSend(Session *s, dumb_ptr sd) { - int n = (RFIFOW(fd, 2) - 4) / 4; + int n = (RFIFOW(s, 2) - 4) / 4; // really an array of pairs of uint16_t - const uint16_t *item_list = static_cast(RFIFOP(fd, 4)); + const uint16_t *item_list = static_cast(RFIFOP(s, 4)); int fail = npc_selllist(sd, n, item_list); - WFIFOW(fd, 0) = 0xcb; - WFIFOB(fd, 2) = fail; - WFIFOSET(fd, clif_parse_func_table[0xcb].len); + WFIFOW(s, 0) = 0xcb; + WFIFOB(s, 2) = fail; + WFIFOSET(s, clif_parse_func_table[0xcb].len); } /*========================================== @@ -4342,14 +4300,14 @@ void clif_parse_NpcSellListSend(int fd, dumb_ptr sd) *------------------------------------------ */ static -void clif_parse_TradeRequest(int, dumb_ptr sd) +void clif_parse_TradeRequest(Session *, dumb_ptr sd) { nullpo_retv(sd); if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, SkillID::NV_TRADE) >= 1) { - trade_traderequest(sd, RFIFOL(sd->fd, 2)); + trade_traderequest(sd, RFIFOL(sd->sess, 2)); } else clif_skill_fail(sd, SkillID::ONE, 0, 0); @@ -4360,11 +4318,11 @@ void clif_parse_TradeRequest(int, dumb_ptr sd) *------------------------------------------ */ static -void clif_parse_TradeAck(int, dumb_ptr sd) +void clif_parse_TradeAck(Session *, dumb_ptr sd) { nullpo_retv(sd); - trade_tradeack(sd, RFIFOB(sd->fd, 2)); + trade_tradeack(sd, RFIFOB(sd->sess, 2)); } /*========================================== @@ -4372,11 +4330,11 @@ void clif_parse_TradeAck(int, dumb_ptr sd) *------------------------------------------ */ static -void clif_parse_TradeAddItem(int, dumb_ptr sd) +void clif_parse_TradeAddItem(Session *, dumb_ptr sd) { nullpo_retv(sd); - trade_tradeadditem(sd, RFIFOW(sd->fd, 2), RFIFOL(sd->fd, 4)); + trade_tradeadditem(sd, RFIFOW(sd->sess, 2), RFIFOL(sd->sess, 4)); } /*========================================== @@ -4384,7 +4342,7 @@ void clif_parse_TradeAddItem(int, dumb_ptr sd) *------------------------------------------ */ static -void clif_parse_TradeOk(int, dumb_ptr sd) +void clif_parse_TradeOk(Session *, dumb_ptr sd) { trade_tradeok(sd); } @@ -4394,7 +4352,7 @@ void clif_parse_TradeOk(int, dumb_ptr sd) *------------------------------------------ */ static -void clif_parse_TradeCansel(int, dumb_ptr sd) +void clif_parse_TradeCansel(Session *, dumb_ptr sd) { trade_tradecancel(sd); } @@ -4404,7 +4362,7 @@ void clif_parse_TradeCansel(int, dumb_ptr sd) *------------------------------------------ */ static -void clif_parse_TradeCommit(int, dumb_ptr sd) +void clif_parse_TradeCommit(Session *, dumb_ptr sd) { trade_tradecommit(sd); } @@ -4414,7 +4372,7 @@ void clif_parse_TradeCommit(int, dumb_ptr sd) *------------------------------------------ */ static -void clif_parse_StopAttack(int, dumb_ptr sd) +void clif_parse_StopAttack(Session *, dumb_ptr sd) { pc_stopattack(sd); } @@ -4424,9 +4382,9 @@ void clif_parse_StopAttack(int, dumb_ptr sd) *------------------------------------------ */ static -void clif_parse_StatusUp(int fd, dumb_ptr sd) +void clif_parse_StatusUp(Session *s, dumb_ptr sd) { - pc_statusup(sd, SP(RFIFOW(fd, 2))); + pc_statusup(sd, SP(RFIFOW(s, 2))); } /*========================================== @@ -4434,9 +4392,9 @@ void clif_parse_StatusUp(int fd, dumb_ptr sd) *------------------------------------------ */ static -void clif_parse_SkillUp(int fd, dumb_ptr sd) +void clif_parse_SkillUp(Session *s, dumb_ptr sd) { - pc_skillup(sd, SkillID(RFIFOW(fd, 2))); + pc_skillup(sd, SkillID(RFIFOW(s, 2))); } /*========================================== @@ -4444,12 +4402,12 @@ void clif_parse_SkillUp(int fd, dumb_ptr sd) *------------------------------------------ */ static -void clif_parse_NpcSelectMenu(int fd, dumb_ptr sd) +void clif_parse_NpcSelectMenu(Session *s, dumb_ptr sd) { nullpo_retv(sd); - sd->npc_menu = RFIFOB(fd, 6); - map_scriptcont(sd, RFIFOL(fd, 2)); + sd->npc_menu = RFIFOB(s, 6); + map_scriptcont(sd, RFIFOL(s, 2)); } /*========================================== @@ -4457,9 +4415,9 @@ void clif_parse_NpcSelectMenu(int fd, dumb_ptr sd) *------------------------------------------ */ static -void clif_parse_NpcNextClicked(int fd, dumb_ptr sd) +void clif_parse_NpcNextClicked(Session *s, dumb_ptr sd) { - map_scriptcont(sd, RFIFOL(fd, 2)); + map_scriptcont(sd, RFIFOL(s, 2)); } /*========================================== @@ -4467,12 +4425,12 @@ void clif_parse_NpcNextClicked(int fd, dumb_ptr sd) *------------------------------------------ */ static -void clif_parse_NpcAmountInput(int fd, dumb_ptr sd) +void clif_parse_NpcAmountInput(Session *s, dumb_ptr sd) { nullpo_retv(sd); - sd->npc_amount = RFIFOL(fd, 6); - map_scriptcont(sd, RFIFOL(fd, 2)); + sd->npc_amount = RFIFOL(s, 6); + map_scriptcont(sd, RFIFOL(s, 2)); } /*========================================== @@ -4482,12 +4440,12 @@ void clif_parse_NpcAmountInput(int fd, dumb_ptr sd) *------------------------------------------ */ static -void clif_parse_NpcStringInput(int fd, dumb_ptr sd) +void clif_parse_NpcStringInput(Session *s, dumb_ptr sd) { int len; nullpo_retv(sd); - len = RFIFOW(fd, 2) - 8; + len = RFIFOW(s, 2) - 8; /* * If we check for equal to 0, too, we'll freeze clients that send (or @@ -4495,9 +4453,9 @@ void clif_parse_NpcStringInput(int fd, dumb_ptr sd) */ if (len < 0) return; - sd->npc_str = RFIFO_STRING(fd, 8, len); + sd->npc_str = RFIFO_STRING(s, 8, len); - map_scriptcont(sd, RFIFOL(fd, 4)); + map_scriptcont(sd, RFIFOL(s, 4)); } /*========================================== @@ -4505,9 +4463,9 @@ void clif_parse_NpcStringInput(int fd, dumb_ptr sd) *------------------------------------------ */ static -void clif_parse_NpcCloseClicked(int fd, dumb_ptr sd) +void clif_parse_NpcCloseClicked(Session *s, dumb_ptr sd) { - map_scriptcont(sd, RFIFOL(fd, 2)); + map_scriptcont(sd, RFIFOL(s, 2)); } /*========================================== @@ -4515,14 +4473,14 @@ void clif_parse_NpcCloseClicked(int fd, dumb_ptr sd) *------------------------------------------ */ static -void clif_parse_MoveToKafra(int fd, dumb_ptr sd) +void clif_parse_MoveToKafra(Session *s, dumb_ptr sd) { int item_index, item_amount; nullpo_retv(sd); - item_index = RFIFOW(fd, 2) - 2; - item_amount = RFIFOL(fd, 4); + item_index = RFIFOW(s, 2) - 2; + item_amount = RFIFOL(s, 4); if ((sd->npc_id != 0 && !sd->npc_flags.storage) || sd->trade_partner != 0 || !sd->state.storage_open) @@ -4537,14 +4495,14 @@ void clif_parse_MoveToKafra(int fd, dumb_ptr sd) *------------------------------------------ */ static -void clif_parse_MoveFromKafra(int fd, dumb_ptr sd) +void clif_parse_MoveFromKafra(Session *s, dumb_ptr sd) { int item_index, item_amount; nullpo_retv(sd); - item_index = RFIFOW(fd, 2) - 1; - item_amount = RFIFOL(fd, 4); + item_index = RFIFOW(s, 2) - 1; + item_amount = RFIFOL(s, 4); if ((sd->npc_id != 0 && !sd->npc_flags.storage) || sd->trade_partner != 0 || !sd->state.storage_open) @@ -4559,7 +4517,7 @@ void clif_parse_MoveFromKafra(int fd, dumb_ptr sd) *------------------------------------------ */ static -void clif_parse_CloseKafra(int, dumb_ptr sd) +void clif_parse_CloseKafra(Session *, dumb_ptr sd) { nullpo_retv(sd); @@ -4575,12 +4533,12 @@ void clif_parse_CloseKafra(int, dumb_ptr sd) *------------------------------------------ */ static -void clif_parse_CreateParty(int fd, dumb_ptr sd) +void clif_parse_CreateParty(Session *s, dumb_ptr sd) { if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, SkillID::NV_PARTY) >= 2) { - PartyName name = stringish(RFIFO_STRING<24>(fd, 2)); + PartyName name = stringish(RFIFO_STRING<24>(s, 2)); party_create(sd, name); } else @@ -4595,9 +4553,9 @@ void clif_parse_CreateParty(int fd, dumb_ptr sd) *------------------------------------------ */ static -void clif_parse_PartyInvite(int fd, dumb_ptr sd) +void clif_parse_PartyInvite(Session *s, dumb_ptr sd) { - party_invite(sd, RFIFOL(fd, 2)); + party_invite(sd, RFIFOL(s, 2)); } /*========================================== @@ -4608,16 +4566,16 @@ void clif_parse_PartyInvite(int fd, dumb_ptr sd) *------------------------------------------ */ static -void clif_parse_ReplyPartyInvite(int fd, dumb_ptr sd) +void clif_parse_ReplyPartyInvite(Session *s, dumb_ptr sd) { if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, SkillID::NV_PARTY) >= 1) { - party_reply_invite(sd, RFIFOL(fd, 2), RFIFOL(fd, 6)); + party_reply_invite(sd, RFIFOL(s, 2), RFIFOL(s, 6)); } else { - party_reply_invite(sd, RFIFOL(fd, 2), 0); + party_reply_invite(sd, RFIFOL(s, 2), 0); clif_skill_fail(sd, SkillID::ONE, 0, 4); } } @@ -4627,7 +4585,7 @@ void clif_parse_ReplyPartyInvite(int fd, dumb_ptr sd) *------------------------------------------ */ static -void clif_parse_LeaveParty(int, dumb_ptr sd) +void clif_parse_LeaveParty(Session *, dumb_ptr sd) { party_leave(sd); } @@ -4637,9 +4595,9 @@ void clif_parse_LeaveParty(int, dumb_ptr sd) *------------------------------------------ */ static -void clif_parse_RemovePartyMember(int fd, dumb_ptr sd) +void clif_parse_RemovePartyMember(Session *s, dumb_ptr sd) { - int account_id = RFIFOL(fd, 2); + int account_id = RFIFOL(s, 2); // unused RFIFO_STRING<24>(fd, 6); party_removemember(sd, account_id); } @@ -4649,9 +4607,9 @@ void clif_parse_RemovePartyMember(int fd, dumb_ptr sd) *------------------------------------------ */ static -void clif_parse_PartyChangeOption(int fd, dumb_ptr sd) +void clif_parse_PartyChangeOption(Session *s, dumb_ptr sd) { - party_changeoption(sd, RFIFOW(fd, 2), RFIFOW(fd, 4)); + party_changeoption(sd, RFIFOW(s, 2), RFIFOW(s, 4)); } /*========================================== @@ -4663,24 +4621,24 @@ void clif_parse_PartyChangeOption(int fd, dumb_ptr sd) *------------------------------------------ */ static -void clif_parse_PartyMessage(int fd, dumb_ptr sd) +void clif_parse_PartyMessage(Session *s, dumb_ptr sd) { nullpo_retv(sd); FString mbuf = clif_validate_chat(sd, ChatType::Party); if (!mbuf) { - clif_displaymessage(fd, "Your message could not be sent."); + clif_displaymessage(s, "Your message could not be sent."); return; } - if (is_atcommand(fd, sd, mbuf, 0)) + if (is_atcommand(s, sd, mbuf, 0)) return; /* Don't send chat that results in an automatic ban. */ if (tmw_CheckChatSpam(sd, mbuf)) { - clif_displaymessage(fd, "Your message could not be sent."); + clif_displaymessage(s, "Your message could not be sent."); return; } @@ -5237,9 +5195,9 @@ func_table clif_parse_func_table[0x0220] = // Checks for packet flooding static -int clif_check_packet_flood(int fd, int cmd) +int clif_check_packet_flood(Session *s, int cmd) { - dumb_ptr sd = dumb_ptr(static_cast(session[fd]->session_data.get())); + dumb_ptr sd = dumb_ptr(static_cast(s->session_data.get())); tick_t tick = gettick(); // sd will not be set if the client hasn't requested @@ -5264,7 +5222,7 @@ int clif_check_packet_flood(int fd, int cmd) // ActionRequest - attacks are allowed a faster rate than sit/stand if (cmd == 0x89) { - int action_type = RFIFOB(fd, 6); + int action_type = RFIFOB(s, 6); if (action_type == 0x00 || action_type == 0x07) rate = std::chrono::milliseconds(20); else @@ -5303,7 +5261,7 @@ int clif_check_packet_flood(int fd, int 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 + s->eof = 1; // Kick return 1; } sd->packet_flood_in = 0; @@ -5343,8 +5301,8 @@ FString clif_validate_chat(dumb_ptr sd, ChatType type) if (sd->auto_ban_info.in_progress) return FString(); - int fd = sd->fd; - size_t msg_len = RFIFOW(fd, 2) - 4; + Session *s = sd->sess; + size_t msg_len = RFIFOW(s, 2) - 4; size_t name_len = sd->status.name.to__actual().size(); /* * At least one character is required in all instances. @@ -5379,7 +5337,7 @@ FString clif_validate_chat(dumb_ptr sd, ChatType type) if (type == ChatType::Whisper && msg_len < min_len) { /* Disallow malformed messages. */ - clif_setwaitclose(fd); + clif_setwaitclose(s); WARN_MALFORMED_MSG(sd, "illegal target name"); return FString(); } @@ -5391,7 +5349,7 @@ FString clif_validate_chat(dumb_ptr sd, ChatType type) pstart += 24; buf_len -= 24; } - FString pbuf = RFIFO_STRING(fd, pstart, buf_len); + FString pbuf = RFIFO_STRING(s, pstart, buf_len); /* * The client attempted to exceed the maximum message length. @@ -5412,7 +5370,7 @@ FString clif_validate_chat(dumb_ptr sd, ChatType type) if (!(p.startswith(sd->status.name.to__actual()) && p.xslice_t(name_len).startswith(" : "))) { /* Disallow malformed/spoofed messages. */ - clif_setwaitclose(fd); + clif_setwaitclose(s); WARN_MALFORMED_MSG(sd, "spoofed name/invalid format"); return FString(); } @@ -5429,31 +5387,31 @@ FString clif_validate_chat(dumb_ptr sd, ChatType type) *------------------------------------------ */ static -void clif_parse(int fd) +void clif_parse(Session *s) { int packet_len = 0, cmd = 0; - dumb_ptr sd = dumb_ptr(static_cast(session[fd]->session_data.get())); + dumb_ptr sd = dumb_ptr(static_cast(s->session_data.get())); if (!sd || (sd && !sd->state.auth)) { - if (RFIFOREST(fd) < 2) + if (RFIFOREST(s) < 2) { // too small a packet disconnect - session[fd]->eof = 1; + s->eof = 1; } - if (RFIFOW(fd, 0) != 0x72 && RFIFOW(fd, 0) != 0x7530) + if (RFIFOW(s, 0) != 0x72 && RFIFOW(s, 0) != 0x7530) { // first packet must be auth or finger - session[fd]->eof = 1; + s->eof = 1; } } // 接続が切れてるので後始末 - if (!chrif_isconnect() || session[fd]->eof) + if (!chrif_isconnect() || s->eof) { // char鯖に繋がってない間は接続禁止 (!chrif_isconnect()) if (sd && sd->state.auth) { pc_logout(sd); - clif_quitsave(fd, sd); + clif_quitsave(s, sd); PRINTF("Player [%s] has logged off your server.\n", sd->status.name); // Player logout display [Valaris] } @@ -5462,15 +5420,15 @@ void clif_parse(int fd) PRINTF("Player with account [%d] has logged off your server (not auth account).\n", sd->bl_id); // Player logout display [Yor] map_deliddb(sd); // account_id has been included in the DB before auth answer } - if (fd) - delete_session(fd); + if (s) + delete_session(s); return; } - if (RFIFOREST(fd) < 2) + if (RFIFOREST(s) < 2) return; // Too small (no packet number) - cmd = RFIFOW(fd, 0); + cmd = RFIFOW(s, 0); // 管理用パケット処理 if (cmd >= 30000) @@ -5478,13 +5436,13 @@ void clif_parse(int fd) switch (cmd) { case 0x7530: // Athena情報所得 - WFIFOW(fd, 0) = 0x7531; - WFIFO_STRUCT(fd, 2, CURRENT_MAP_SERVER_VERSION); - WFIFOSET(fd, 10); - RFIFOSKIP(fd, 2); + WFIFOW(s, 0) = 0x7531; + WFIFO_STRUCT(s, 2, CURRENT_MAP_SERVER_VERSION); + WFIFOSET(s, 10); + RFIFOSKIP(s, 2); break; case 0x7532: // 接続の切断 - session[fd]->eof = 1; + s->eof = 1; break; } return; @@ -5496,19 +5454,19 @@ void clif_parse(int fd) packet_len = clif_parse_func_table[cmd].len; if (packet_len == VAR) { - if (RFIFOREST(fd) < 4) + if (RFIFOREST(s) < 4) { return; // Runt packet (variable length without a length sent) } - packet_len = RFIFOW(fd, 2); + packet_len = RFIFOW(s, 2); if (packet_len < 4 || packet_len > 32768) { - session[fd]->eof = 1; + s->eof = 1; return; // Runt packet (variable out of bounds) } } - if (RFIFOREST(fd) < packet_len) + if (RFIFOREST(s) < packet_len) { return; // Runt packet (sent legnth is too small) } @@ -5519,23 +5477,23 @@ void clif_parse(int fd) } else if (clif_parse_func_table[cmd].func) { - if (clif_check_packet_flood(fd, cmd)) + if (clif_check_packet_flood(s, cmd)) { // Flood triggered. Skip packet. - RFIFOSKIP(sd->fd, packet_len); + RFIFOSKIP(sd->sess, packet_len); return; } - clif_parse_func_table[cmd].func(fd, sd); + clif_parse_func_table[cmd].func(s, sd); } else { // 不明なパケット if (battle_config.error_log) { - if (fd) + if (s) PRINTF("\nclif_parse: session #%d, packet 0x%x, lenght %d\n", - fd, cmd, packet_len); + s, cmd, packet_len); #ifdef DUMP_UNKNOWN_PACKET { int i; @@ -5545,7 +5503,7 @@ void clif_parse(int fd) { if ((i & 15) == 0) PRINTF("\n%04X ", i); - PRINTF("%02X ", RFIFOB(fd, i)); + PRINTF("%02X ", RFIFOB(s, i)); } if (sd && sd->state.auth) { @@ -5586,7 +5544,7 @@ void clif_parse(int fd) { if ((i & 15) == 0) FPRINTF(fp, "\n\t%04X ", i); - FPRINTF(fp, "%02X ", RFIFOB(fd, i)); + FPRINTF(fp, "%02X ", RFIFOB(s, i)); } FPRINTF(fp, "\n\n"); } @@ -5594,7 +5552,7 @@ void clif_parse(int fd) #endif } } - RFIFOSKIP(fd, packet_len); + RFIFOSKIP(s, packet_len); } void do_init_clif(void) diff --git a/src/map/clif.hpp b/src/map/clif.hpp index ad51fc8..e84adf3 100644 --- a/src/map/clif.hpp +++ b/src/map/clif.hpp @@ -22,16 +22,16 @@ void clif_setport(int); IP4Address clif_getip(void); int clif_getport(void); int clif_countusers(void); -void clif_setwaitclose(int); +void clif_setwaitclose(Session *); int clif_authok(dumb_ptr); -int clif_authfail_fd(int, int); +int clif_authfail_fd(Session *, int); int clif_charselectok(int); int clif_dropflooritem(dumb_ptr); -int clif_clearflooritem(dumb_ptr, int); +int clif_clearflooritem(dumb_ptr, Session *); int clif_clearchar(dumb_ptr, BeingRemoveWhy); // area or fd int clif_clearchar_delay(tick_t, dumb_ptr, BeingRemoveWhy); -void clif_clearchar_id(int, BeingRemoveWhy, int); +void clif_clearchar_id(int, BeingRemoveWhy, Session *); int clif_spawnpc(dumb_ptr); //area int clif_spawnnpc(dumb_ptr); // area int clif_spawn_fake_npc_for_player(dumb_ptr sd, @@ -78,7 +78,7 @@ int clif_changeoption(dumb_ptr); // area int clif_useitemack(dumb_ptr, int, int, int); // self void clif_emotion(dumb_ptr bl, int type); -void clif_sitting(int fd, dumb_ptr sd); +void clif_sitting(Session *, dumb_ptr sd); // trade void clif_traderequest(dumb_ptr sd, CharName name); @@ -124,8 +124,8 @@ int clif_skill_damage(dumb_ptr src, dumb_ptr dst, int clif_status_change(dumb_ptr bl, StatusChange type, int flag); -void clif_wis_message(int fd, CharName nick, XString mes); -void clif_wis_end(int fd, int flag); +void clif_wis_message(Session *s, CharName nick, XString mes); +void clif_wis_end(Session *s, int flag); void clif_itemlist(dumb_ptr sd); void clif_equiplist(dumb_ptr sd); @@ -136,7 +136,7 @@ int clif_movetoattack(dumb_ptr sd, dumb_ptr bl); // party int clif_party_created(dumb_ptr sd, int flag); -int clif_party_info(struct party *p, int fd); +int clif_party_info(struct party *p, Session *s); void clif_party_invite(dumb_ptr sd, dumb_ptr tsd); void clif_party_inviteack(dumb_ptr sd, CharName nick, int flag); @@ -149,7 +149,7 @@ int clif_party_xy(struct party *p, dumb_ptr sd); int clif_party_hp(struct party *p, dumb_ptr sd); // atcommand -void clif_displaymessage(int fd, XString mes); +void clif_displaymessage(Session *s, XString mes); void clif_GMmessage(dumb_ptr bl, XString mes, int flag); void clif_resurrection(dumb_ptr bl, int type); diff --git a/src/map/intif.cpp b/src/map/intif.cpp index 8673aef..006be1c 100644 --- a/src/map/intif.cpp +++ b/src/map/intif.cpp @@ -43,11 +43,11 @@ const int packet_len_table[] = // Message for all GMs on all map servers void intif_GMmessage(XString mes) { - WFIFOW(char_fd, 0) = 0x3000; + WFIFOW(char_session, 0) = 0x3000; size_t len = mes.size() + 1; - WFIFOW(char_fd, 2) = 4 + len; - WFIFO_STRING(char_fd, 4, mes, len); - WFIFOSET(char_fd, WFIFOW(char_fd, 2)); + WFIFOW(char_session, 2) = 4 + len; + WFIFO_STRING(char_session, 4, mes, len); + WFIFOSET(char_session, WFIFOW(char_session, 2)); } // The transmission of Wisp/Page to inter-server (player not found on this server) @@ -56,12 +56,12 @@ void intif_wis_message(dumb_ptr sd, CharName nick, ZString mes nullpo_retv(sd); size_t mes_len = mes.size() + 1; - WFIFOW(char_fd, 0) = 0x3001; - WFIFOW(char_fd, 2) = mes_len + 52; - WFIFO_STRING(char_fd, 4, sd->status.name.to__actual(), 24); - WFIFO_STRING(char_fd, 28, nick.to__actual(), 24); - WFIFO_STRING(char_fd, 52, mes, mes_len); - WFIFOSET(char_fd, WFIFOW(char_fd, 2)); + WFIFOW(char_session, 0) = 0x3001; + WFIFOW(char_session, 2) = mes_len + 52; + WFIFO_STRING(char_session, 4, sd->status.name.to__actual(), 24); + WFIFO_STRING(char_session, 28, nick.to__actual(), 24); + WFIFO_STRING(char_session, 52, mes, mes_len); + WFIFOSET(char_session, WFIFOW(char_session, 2)); if (battle_config.etc_log) PRINTF("intif_wis_message from %s to %s)\n", @@ -72,10 +72,10 @@ void intif_wis_message(dumb_ptr sd, CharName nick, ZString mes static void intif_wis_replay(int id, int flag) { - WFIFOW(char_fd, 0) = 0x3002; - WFIFOL(char_fd, 2) = id; - WFIFOB(char_fd, 6) = flag; // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target - WFIFOSET(char_fd, 7); + WFIFOW(char_session, 0) = 0x3002; + WFIFOL(char_session, 2) = id; + WFIFOB(char_session, 6) = flag; // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target + WFIFOSET(char_session, 7); if (battle_config.etc_log) PRINTF("intif_wis_replay: id: %d, flag:%d\n", id, flag); @@ -85,12 +85,12 @@ void intif_wis_replay(int id, int flag) void intif_wis_message_to_gm(CharName Wisp_name, int min_gm_level, ZString mes) { size_t mes_len = mes.size() + 1; - WFIFOW(char_fd, 0) = 0x3003; - WFIFOW(char_fd, 2) = mes_len + 30; - WFIFO_STRING(char_fd, 4, Wisp_name.to__actual(), 24); - WFIFOW(char_fd, 28) = min_gm_level; - WFIFO_STRING(char_fd, 30, mes, mes_len); - WFIFOSET(char_fd, WFIFOW(char_fd, 2)); + WFIFOW(char_session, 0) = 0x3003; + WFIFOW(char_session, 2) = mes_len + 30; + WFIFO_STRING(char_session, 4, Wisp_name.to__actual(), 24); + WFIFOW(char_session, 28) = min_gm_level; + WFIFO_STRING(char_session, 30, mes, mes_len); + WFIFOSET(char_session, WFIFOW(char_session, 2)); if (battle_config.etc_log) PRINTF("intif_wis_message_to_gm: from: '%s', min level: %d, message: '%s'.\n", @@ -104,15 +104,15 @@ void intif_saveaccountreg(dumb_ptr sd) nullpo_retv(sd); - WFIFOW(char_fd, 0) = 0x3004; - WFIFOL(char_fd, 4) = sd->bl_id; + WFIFOW(char_session, 0) = 0x3004; + WFIFOL(char_session, 4) = sd->bl_id; for (j = 0, p = 8; j < sd->status.account_reg_num; j++, p += 36) { - WFIFO_STRING(char_fd, p, sd->status.account_reg[j].str, 32); - WFIFOL(char_fd, p + 32) = sd->status.account_reg[j].value; + WFIFO_STRING(char_session, p, sd->status.account_reg[j].str, 32); + WFIFOL(char_session, p + 32) = sd->status.account_reg[j].value; } - WFIFOW(char_fd, 2) = p; - WFIFOSET(char_fd, p); + WFIFOW(char_session, 2) = p; + WFIFOSET(char_session, p); } // アカウント変数要求 @@ -120,28 +120,28 @@ void intif_request_accountreg(dumb_ptr sd) { nullpo_retv(sd); - WFIFOW(char_fd, 0) = 0x3005; - WFIFOL(char_fd, 2) = sd->bl_id; - WFIFOSET(char_fd, 6); + WFIFOW(char_session, 0) = 0x3005; + WFIFOL(char_session, 2) = sd->bl_id; + WFIFOSET(char_session, 6); } // 倉庫データ要求 void intif_request_storage(int account_id) { - WFIFOW(char_fd, 0) = 0x3010; - WFIFOL(char_fd, 2) = account_id; - WFIFOSET(char_fd, 6); + WFIFOW(char_session, 0) = 0x3010; + WFIFOL(char_session, 2) = account_id; + WFIFOSET(char_session, 6); } // 倉庫データ送信 void intif_send_storage(struct storage *stor) { nullpo_retv(stor); - WFIFOW(char_fd, 0) = 0x3011; - WFIFOW(char_fd, 2) = sizeof(struct storage) + 8; - WFIFOL(char_fd, 4) = stor->account_id; - WFIFO_STRUCT(char_fd, 8, *stor); - WFIFOSET(char_fd, WFIFOW(char_fd, 2)); + WFIFOW(char_session, 0) = 0x3011; + WFIFOW(char_session, 2) = sizeof(struct storage) + 8; + WFIFOL(char_session, 4) = stor->account_id; + WFIFO_STRUCT(char_session, 8, *stor); + WFIFOSET(char_session, WFIFOW(char_session, 2)); } // パーティ作成要求 @@ -149,21 +149,21 @@ void intif_create_party(dumb_ptr sd, PartyName name) { nullpo_retv(sd); - WFIFOW(char_fd, 0) = 0x3020; - WFIFOL(char_fd, 2) = sd->status.account_id; - WFIFO_STRING(char_fd, 6, name, 24); - WFIFO_STRING(char_fd, 30, sd->status.name.to__actual(), 24); - WFIFO_STRING(char_fd, 54, sd->bl_m->name_, 16); - WFIFOW(char_fd, 70) = sd->status.base_level; - WFIFOSET(char_fd, 72); + WFIFOW(char_session, 0) = 0x3020; + WFIFOL(char_session, 2) = sd->status.account_id; + WFIFO_STRING(char_session, 6, name, 24); + WFIFO_STRING(char_session, 30, sd->status.name.to__actual(), 24); + WFIFO_STRING(char_session, 54, sd->bl_m->name_, 16); + WFIFOW(char_session, 70) = sd->status.base_level; + WFIFOSET(char_session, 72); } // パーティ情報要求 void intif_request_partyinfo(int party_id) { - WFIFOW(char_fd, 0) = 0x3021; - WFIFOL(char_fd, 2) = party_id; - WFIFOSET(char_fd, 6); + WFIFOW(char_session, 0) = 0x3021; + WFIFOL(char_session, 2) = party_id; + WFIFOSET(char_session, 6); } // パーティ追加要求 @@ -173,34 +173,34 @@ void intif_party_addmember(int party_id, int account_id) sd = map_id2sd(account_id); if (sd != NULL) { - WFIFOW(char_fd, 0) = 0x3022; - WFIFOL(char_fd, 2) = party_id; - WFIFOL(char_fd, 6) = account_id; - WFIFO_STRING(char_fd, 10, sd->status.name.to__actual(), 24); - WFIFO_STRING(char_fd, 34, sd->bl_m->name_, 16); - WFIFOW(char_fd, 50) = sd->status.base_level; - WFIFOSET(char_fd, 52); + WFIFOW(char_session, 0) = 0x3022; + WFIFOL(char_session, 2) = party_id; + WFIFOL(char_session, 6) = account_id; + WFIFO_STRING(char_session, 10, sd->status.name.to__actual(), 24); + WFIFO_STRING(char_session, 34, sd->bl_m->name_, 16); + WFIFOW(char_session, 50) = sd->status.base_level; + WFIFOSET(char_session, 52); } } // パーティ設定変更 void intif_party_changeoption(int party_id, int account_id, int exp, int item) { - WFIFOW(char_fd, 0) = 0x3023; - WFIFOL(char_fd, 2) = party_id; - WFIFOL(char_fd, 6) = account_id; - WFIFOW(char_fd, 10) = exp; - WFIFOW(char_fd, 12) = item; - WFIFOSET(char_fd, 14); + WFIFOW(char_session, 0) = 0x3023; + WFIFOL(char_session, 2) = party_id; + WFIFOL(char_session, 6) = account_id; + WFIFOW(char_session, 10) = exp; + WFIFOW(char_session, 12) = item; + WFIFOSET(char_session, 14); } // パーティ脱退要求 void intif_party_leave(int party_id, int account_id) { - WFIFOW(char_fd, 0) = 0x3024; - WFIFOL(char_fd, 2) = party_id; - WFIFOL(char_fd, 6) = account_id; - WFIFOSET(char_fd, 10); + WFIFOW(char_session, 0) = 0x3024; + WFIFOL(char_session, 2) = party_id; + WFIFOL(char_session, 6) = account_id; + WFIFOSET(char_session, 10); } // パーティ移動要求 @@ -208,13 +208,13 @@ void intif_party_changemap(dumb_ptr sd, int online) { if (sd != NULL) { - WFIFOW(char_fd, 0) = 0x3025; - WFIFOL(char_fd, 2) = sd->status.party_id; - WFIFOL(char_fd, 6) = sd->status.account_id; - WFIFO_STRING(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); + WFIFOW(char_session, 0) = 0x3025; + WFIFOL(char_session, 2) = sd->status.party_id; + WFIFOL(char_session, 6) = sd->status.account_id; + WFIFO_STRING(char_session, 10, sd->bl_m->name_, 16); + WFIFOB(char_session, 26) = online; + WFIFOW(char_session, 27) = sd->status.base_level; + WFIFOSET(char_session, 29); } } @@ -222,22 +222,22 @@ void intif_party_changemap(dumb_ptr sd, int online) void intif_party_message(int party_id, int account_id, XString mes) { size_t len = mes.size() + 1; - WFIFOW(char_fd, 0) = 0x3027; - WFIFOW(char_fd, 2) = len + 12; - WFIFOL(char_fd, 4) = party_id; - WFIFOL(char_fd, 8) = account_id; - WFIFO_STRING(char_fd, 12, mes, len); - WFIFOSET(char_fd, len + 12); + WFIFOW(char_session, 0) = 0x3027; + WFIFOW(char_session, 2) = len + 12; + WFIFOL(char_session, 4) = party_id; + WFIFOL(char_session, 8) = account_id; + WFIFO_STRING(char_session, 12, mes, len); + WFIFOSET(char_session, len + 12); } // パーティ競合チェック要求 void intif_party_checkconflict(int party_id, int account_id, CharName nick) { - WFIFOW(char_fd, 0) = 0x3028; - WFIFOL(char_fd, 2) = party_id; - WFIFOL(char_fd, 6) = account_id; - WFIFO_STRING(char_fd, 10, nick.to__actual(), 24); - WFIFOSET(char_fd, 34); + WFIFOW(char_session, 0) = 0x3028; + WFIFOL(char_session, 2) = party_id; + WFIFOL(char_session, 6) = account_id; + WFIFO_STRING(char_session, 10, nick.to__actual(), 24); + WFIFOSET(char_session, 34); } //----------------------------------------------------------------- @@ -245,21 +245,21 @@ void intif_party_checkconflict(int party_id, int account_id, CharName nick) // Wisp/Page reception static -int intif_parse_WisMessage(int fd) +int intif_parse_WisMessage(Session *s) { // rewritten by [Yor] dumb_ptr sd; - CharName from = stringish(RFIFO_STRING<24>(fd, 8)); - CharName to = stringish(RFIFO_STRING<24>(fd, 32)); + CharName from = stringish(RFIFO_STRING<24>(s, 8)); + CharName to = stringish(RFIFO_STRING<24>(s, 32)); - size_t len = RFIFOW(fd, 2) - 56; - FString buf = RFIFO_STRING(fd, 56, len); + size_t len = RFIFOW(s, 2) - 56; + FString buf = RFIFO_STRING(s, 56, len); if (battle_config.etc_log) { PRINTF("intif_parse_wismessage: id: %d, from: %s, to: %s\n", - RFIFOL(fd, 4), + RFIFOL(s, 4), from, to); } @@ -270,76 +270,78 @@ int intif_parse_WisMessage(int fd) { // if source player not found in ignore list { - clif_wis_message(sd->fd, from, buf); - intif_wis_replay(RFIFOL(fd, 4), 0); // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target + clif_wis_message(sd->sess, from, buf); + intif_wis_replay(RFIFOL(s, 4), 0); // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target } } } else - intif_wis_replay(RFIFOL(fd, 4), 1); // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target + intif_wis_replay(RFIFOL(s, 4), 1); // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target return 0; } // Wisp/page transmission result reception static -int intif_parse_WisEnd(int fd) +int intif_parse_WisEnd(Session *s) { dumb_ptr sd; - CharName name = stringish(RFIFO_STRING<24>(fd, 2)); - uint8_t flag = RFIFOB(fd, 26); + CharName name = stringish(RFIFO_STRING<24>(s, 2)); + uint8_t flag = RFIFOB(s, 26); if (battle_config.etc_log) // 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", name, flag); sd = map_nick2sd(name); if (sd != NULL) - clif_wis_end(sd->fd, flag); + clif_wis_end(sd->sess, flag); return 0; } // Received wisp message from map-server via char-server for ALL gm static -void mapif_parse_WisToGM(int fd) +void mapif_parse_WisToGM(Session *s) { // 0x3003/0x3803 .w .24B .w .?B int min_gm_level, len; - if (RFIFOW(fd, 2) - 30 <= 0) + if (RFIFOW(s, 2) - 30 <= 0) return; - len = RFIFOW(fd, 2) - 30; + len = RFIFOW(s, 2) - 30; - min_gm_level = RFIFOW(fd, 28); - CharName Wisp_name = stringish(RFIFO_STRING<24>(fd, 4)); - FString message = RFIFO_STRING(fd, 30, len); + min_gm_level = RFIFOW(s, 28); + CharName Wisp_name = stringish(RFIFO_STRING<24>(s, 4)); + FString message = RFIFO_STRING(s, 30, len); // information is sended to all online GM for (int i = 0; i < fd_max; i++) { - if (!session[i]) + Session *s2 = session[i].get(); + if (!s2) continue; - dumb_ptr pl_sd = dumb_ptr(static_cast(session[i]->session_data.get())); + dumb_ptr pl_sd = dumb_ptr(static_cast(s2->session_data.get())); if (pl_sd && pl_sd->state.auth) + { if (pc_isGM(pl_sd) >= min_gm_level) - clif_wis_message(i, Wisp_name, message); + clif_wis_message(s2, Wisp_name, message); + } } } // アカウント変数通知 static -int intif_parse_AccountReg(int fd) +int intif_parse_AccountReg(Session *s) { int j, p; - dumb_ptr sd; - - if ((sd = map_id2sd(RFIFOL(fd, 4))) == NULL) + dumb_ptr sd = map_id2sd(RFIFOL(s, 4)); + if (sd == NULL) return 1; - for (p = 8, j = 0; p < RFIFOW(fd, 2) && j < ACCOUNT_REG_NUM; + for (p = 8, j = 0; p < RFIFOW(s, 2) && j < ACCOUNT_REG_NUM; p += 36, j++) { - sd->status.account_reg[j].str = stringish(RFIFO_STRING<32>(fd, p)); - sd->status.account_reg[j].value = RFIFOL(fd, p + 32); + sd->status.account_reg[j].str = stringish(RFIFO_STRING<32>(s, p)); + sd->status.account_reg[j].value = RFIFOL(s, p + 32); } sd->status.account_reg_num = j; // PRINTF("intif: accountreg\n"); @@ -349,20 +351,20 @@ int intif_parse_AccountReg(int fd) // 倉庫データ受信 static -int intif_parse_LoadStorage(int fd) +int intif_parse_LoadStorage(Session *s) { struct storage *stor; dumb_ptr sd; - sd = map_id2sd(RFIFOL(fd, 4)); + sd = map_id2sd(RFIFOL(s, 4)); if (sd == NULL) { if (battle_config.error_log) PRINTF("intif_parse_LoadStorage: user not found %d\n", - RFIFOL(fd, 4)); + RFIFOL(s, 4)); return 1; } - stor = account2storage(RFIFOL(fd, 4)); + stor = account2storage(RFIFOL(s, 4)); if (stor->storage_status == 1) { // Already open.. lets ignore this update if (battle_config.error_log) @@ -378,16 +380,16 @@ int intif_parse_LoadStorage(int fd) return 1; } - if (RFIFOW(fd, 2) - 8 != sizeof(struct storage)) + if (RFIFOW(s, 2) - 8 != sizeof(struct storage)) { if (battle_config.error_log) PRINTF("intif_parse_LoadStorage: data size error %d %zu\n", - RFIFOW(fd, 2) - 8, sizeof(struct storage)); + RFIFOW(s, 2) - 8, sizeof(struct storage)); return 1; } if (battle_config.save_log) - PRINTF("intif_openstorage: %d\n", RFIFOL(fd, 4)); - RFIFO_STRUCT(fd, 8, *stor); + PRINTF("intif_openstorage: %d\n", RFIFOL(s, 4)); + RFIFO_STRUCT(s, 8, *stor); stor->dirty = 0; stor->storage_status = 1; sd->state.storage_open = 1; @@ -400,77 +402,77 @@ int intif_parse_LoadStorage(int fd) // 倉庫データ送信成功 static -void intif_parse_SaveStorage(int fd) +void intif_parse_SaveStorage(Session *s) { if (battle_config.save_log) - PRINTF("intif_savestorage: done %d %d\n", RFIFOL(fd, 2), - RFIFOB(fd, 6)); - storage_storage_saved(RFIFOL(fd, 2)); + PRINTF("intif_savestorage: done %d %d\n", RFIFOL(s, 2), + RFIFOB(s, 6)); + storage_storage_saved(RFIFOL(s, 2)); } // パーティ作成可否 static -void intif_parse_PartyCreated(int fd) +void intif_parse_PartyCreated(Session *s) { if (battle_config.etc_log) PRINTF("intif: party created\n"); - int account_id = RFIFOL(fd, 2); - int fail = RFIFOB(fd, 6); - int party_id = RFIFOL(fd, 7); - PartyName name = stringish(RFIFO_STRING<24>(fd, 11)); + int account_id = RFIFOL(s, 2); + int fail = RFIFOB(s, 6); + int party_id = RFIFOL(s, 7); + PartyName name = stringish(RFIFO_STRING<24>(s, 11)); party_created(account_id, fail, party_id, name); } // パーティ情報 static -void intif_parse_PartyInfo(int fd) +void intif_parse_PartyInfo(Session *s) { - if (RFIFOW(fd, 2) == 8) + if (RFIFOW(s, 2) == 8) { if (battle_config.error_log) - PRINTF("intif: party noinfo %d\n", RFIFOL(fd, 4)); - party_recv_noinfo(RFIFOL(fd, 4)); + PRINTF("intif: party noinfo %d\n", RFIFOL(s, 4)); + party_recv_noinfo(RFIFOL(s, 4)); return; } // PRINTF("intif: party info %d\n",RFIFOL(fd,4)); - if (RFIFOW(fd, 2) != sizeof(struct party) + 4) + if (RFIFOW(s, 2) != sizeof(struct party) + 4) { if (battle_config.error_log) PRINTF("intif: party info : data size error %d %d %zu\n", - RFIFOL(fd, 4), RFIFOW(fd, 2), + RFIFOL(s, 4), RFIFOW(s, 2), sizeof(struct party) + 4); } party p {}; - RFIFO_STRUCT(fd, 4, p); + RFIFO_STRUCT(s, 4, p); party_recv_info(&p); } // パーティ追加通知 static -void intif_parse_PartyMemberAdded(int fd) +void intif_parse_PartyMemberAdded(Session *s) { if (battle_config.etc_log) - 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)); + PRINTF("intif: party member added %d %d %d\n", RFIFOL(s, 2), + RFIFOL(s, 6), RFIFOB(s, 10)); + party_member_added(RFIFOL(s, 2), RFIFOL(s, 6), RFIFOB(s, 10)); } // パーティ設定変更通知 static -void intif_parse_PartyOptionChanged(int fd) +void intif_parse_PartyOptionChanged(Session *s) { - party_optionchanged(RFIFOL(fd, 2), RFIFOL(fd, 6), RFIFOW(fd, 10), - RFIFOW(fd, 12), RFIFOB(fd, 14)); + party_optionchanged(RFIFOL(s, 2), RFIFOL(s, 6), RFIFOW(s, 10), + RFIFOW(s, 12), RFIFOB(s, 14)); } // パーティ脱退通知 static -void intif_parse_PartyMemberLeaved(int fd) +void intif_parse_PartyMemberLeaved(Session *s) { - int party_id = RFIFOL(fd, 2); - int account_id = RFIFOL(fd, 6); - CharName name = stringish(RFIFO_STRING<24>(fd, 10)); + int party_id = RFIFOL(s, 2); + int account_id = RFIFOL(s, 6); + CharName name = stringish(RFIFO_STRING<24>(s, 10)); if (battle_config.etc_log) PRINTF("intif: party member leaved %d %d %s\n", party_id, account_id, name); @@ -479,40 +481,40 @@ void intif_parse_PartyMemberLeaved(int fd) // パーティ解散通知 static -void intif_parse_PartyBroken(int fd) +void intif_parse_PartyBroken(Session *s) { - party_broken(RFIFOL(fd, 2)); + party_broken(RFIFOL(s, 2)); } // パーティ移動通知 static -void intif_parse_PartyMove(int fd) +void intif_parse_PartyMove(Session *s) { - int party_id = RFIFOL(fd, 2); - int account_id = RFIFOL(fd, 6); - MapName map = stringish(RFIFO_STRING<16>(fd, 10)); - uint8_t online = RFIFOB(fd, 26); - uint16_t lv = RFIFOW(fd, 27); + int party_id = RFIFOL(s, 2); + int account_id = RFIFOL(s, 6); + MapName map = stringish(RFIFO_STRING<16>(s, 10)); + uint8_t online = RFIFOB(s, 26); + uint16_t lv = RFIFOW(s, 27); party_recv_movemap(party_id, account_id, map, online, lv); } // パーティメッセージ static -void intif_parse_PartyMessage(int fd) +void intif_parse_PartyMessage(Session *s) { - size_t len = RFIFOW(fd, 2) - 12; - FString buf = RFIFO_STRING(fd, 12, len); - party_recv_message(RFIFOL(fd, 4), RFIFOL(fd, 8), buf); + size_t len = RFIFOW(s, 2) - 12; + FString buf = RFIFO_STRING(s, 12, len); + party_recv_message(RFIFOL(s, 4), RFIFOL(s, 8), buf); } //----------------------------------------------------------------- // inter serverからの通信 // エラーがあれば0(false)を返すこと // パケットが処理できれば1,パケット長が足りなければ2を返すこと -int intif_parse(int fd) +int intif_parse(Session *s) { int packet_len; - int cmd = RFIFOW(fd, 0); + int cmd = RFIFOW(s, 0); // パケットのID確認 if (cmd < 0x3800 || cmd >= @@ -525,13 +527,13 @@ int intif_parse(int fd) packet_len = packet_len_table[cmd - 0x3800]; if (packet_len == -1) { - if (RFIFOREST(fd) < 4) + if (RFIFOREST(s) < 4) return 2; - packet_len = RFIFOW(fd, 2); + packet_len = RFIFOW(s, 2); } // if(battle_config.etc_log) // PRINTF("intif_parse %d %x %d %d\n",fd,cmd,packet_len,RFIFOREST(fd)); - if (RFIFOREST(fd) < packet_len) + if (RFIFOREST(s) < packet_len) { return 2; } @@ -540,59 +542,59 @@ int intif_parse(int fd) { case 0x3800: { - FString mes = RFIFO_STRING(fd, 4, packet_len - 4); + FString mes = RFIFO_STRING(s, 4, packet_len - 4); clif_GMmessage(NULL, mes, 0); } break; case 0x3801: - intif_parse_WisMessage(fd); + intif_parse_WisMessage(s); break; case 0x3802: - intif_parse_WisEnd(fd); + intif_parse_WisEnd(s); break; case 0x3803: - mapif_parse_WisToGM(fd); + mapif_parse_WisToGM(s); break; case 0x3804: - intif_parse_AccountReg(fd); + intif_parse_AccountReg(s); break; case 0x3810: - intif_parse_LoadStorage(fd); + intif_parse_LoadStorage(s); break; case 0x3811: - intif_parse_SaveStorage(fd); + intif_parse_SaveStorage(s); break; case 0x3820: - intif_parse_PartyCreated(fd); + intif_parse_PartyCreated(s); break; case 0x3821: - intif_parse_PartyInfo(fd); + intif_parse_PartyInfo(s); break; case 0x3822: - intif_parse_PartyMemberAdded(fd); + intif_parse_PartyMemberAdded(s); break; case 0x3823: - intif_parse_PartyOptionChanged(fd); + intif_parse_PartyOptionChanged(s); break; case 0x3824: - intif_parse_PartyMemberLeaved(fd); + intif_parse_PartyMemberLeaved(s); break; case 0x3825: - intif_parse_PartyMove(fd); + intif_parse_PartyMove(s); break; case 0x3826: - intif_parse_PartyBroken(fd); + intif_parse_PartyBroken(s); break; case 0x3827: - intif_parse_PartyMessage(fd); + intif_parse_PartyMessage(s); break; default: if (battle_config.error_log) - PRINTF("intif_parse : unknown packet %d %x\n", fd, - RFIFOW(fd, 0)); + PRINTF("intif_parse : unknown packet %d %x\n", s, + RFIFOW(s, 0)); return 0; } // パケット読み飛ばし - RFIFOSKIP(fd, packet_len); + RFIFOSKIP(s, packet_len); return 1; } diff --git a/src/map/intif.hpp b/src/map/intif.hpp index 244c230..0fe7182 100644 --- a/src/map/intif.hpp +++ b/src/map/intif.hpp @@ -7,7 +7,7 @@ # include "map.hpp" -int intif_parse(int fd); +int intif_parse(Session *); void intif_GMmessage(XString mes); diff --git a/src/map/magic-stmt.cpp b/src/map/magic-stmt.cpp index 682d9bc..945faa9 100644 --- a/src/map/magic-stmt.cpp +++ b/src/map/magic-stmt.cpp @@ -263,7 +263,7 @@ void magic_unshroud(dumb_ptr other_char) other_char->state.shroud_active = 0; // Now warp the caster out of and back into here to refresh everyone's display char_update(other_char); - clif_displaymessage(other_char->fd, "Your shroud has been dispelled!"); + clif_displaymessage(other_char->sess, "Your shroud has been dispelled!"); // entity_effect(other_char, MAGIC_EFFECT_REVEAL); } @@ -401,7 +401,7 @@ int op_message(dumb_ptr, const_array args) dumb_ptr subject = ARGCHAR(0); if (subject) - clif_displaymessage(subject->fd, ARGSTR(1)); + clif_displaymessage(subject->sess, ARGSTR(1)); return 0; } @@ -1458,7 +1458,7 @@ interval_t spell_run(dumb_ptr invocation_, int allow_delete) } else invocation_->script_pos = 0; - clif_clearchar_id(invocation_->bl_id, BeingRemoveWhy::DEAD, caster->fd); + clif_clearchar_id(invocation_->bl_id, BeingRemoveWhy::DEAD, caster->sess); } REFRESH_INVOCATION; // Script may have killed the caster break; diff --git a/src/map/map.cpp b/src/map/map.cpp index d2b604f..3817422 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -953,7 +953,7 @@ dumb_ptr map_get_first_session(void) dumb_ptr map_get_next_session(dumb_ptr d) { - return map_get_session_forward(d->fd + 1); + return map_get_session_forward(d->sess->fd + 1); } dumb_ptr map_get_last_session(void) @@ -963,7 +963,7 @@ dumb_ptr map_get_last_session(void) dumb_ptr map_get_prev_session(dumb_ptr d) { - return map_get_session_backward(d->fd - 1); + return map_get_session_backward(d->sess->fd - 1); } /*========================================== @@ -1612,7 +1612,7 @@ void term_func(void) } for (int i = 0; i < fd_max; i++) - delete_session(i); + delete_session(session[i].get()); map_removenpc(); diff --git a/src/map/map.hpp b/src/map/map.hpp index 0038e67..897c619 100644 --- a/src/map/map.hpp +++ b/src/map/map.hpp @@ -174,7 +174,7 @@ struct map_session_data : block_list, SessionData int weight, max_weight; int cart_weight, cart_max_weight, cart_num, cart_max_num; MapName mapname_; - int fd; // use this, you idiots! + Session *sess; // use this, you idiots! short to_x, to_y; interval_t speed; Opt1 opt1; @@ -310,7 +310,7 @@ struct map_session_data : block_list, SessionData IP4Address get_ip() { - return session[fd]->client_ip; + return sess->client_ip; } }; diff --git a/src/map/party.cpp b/src/map/party.cpp index 9d7cae2..09f103e 100644 --- a/src/map/party.cpp +++ b/src/map/party.cpp @@ -205,7 +205,7 @@ int party_recv_info(const struct party *sp) && sd->status.party_id == p->party_id) ? sd.operator->() : NULL; } - clif_party_info(p, -1); + clif_party_info(p, nullptr); for (i = 0; i < MAX_PARTY; i++) { // 設定情報の送信 @@ -231,7 +231,7 @@ int party_invite(dumb_ptr sd, int account_id) nullpo_ret(sd); - if (!tsd || !p || !tsd->fd) + if (!tsd || !p || !tsd->sess) return 0; if (!battle_config.invite_request_check) @@ -540,7 +540,7 @@ void party_recv_movemap(int party_id, int account_id, MapName mapname, party_send_xy_clear(p); // 座標再通知要請 - clif_party_info(p, -1); + clif_party_info(p, nullptr); } // パーティメンバの移動 @@ -566,7 +566,7 @@ int party_send_movemap(dumb_ptr sd) party_check_member(p); // 所属を確認する if (sd->status.party_id == p->party_id) { - clif_party_info(p, sd->fd); + clif_party_info(p, sd->sess); clif_party_option(p, sd, 0x100); sd->party_sended = 1; } diff --git a/src/map/pc.cpp b/src/map/pc.cpp index 73639dd..168d124 100644 --- a/src/map/pc.cpp +++ b/src/map/pc.cpp @@ -623,7 +623,7 @@ int pc_authok(int id, int login_id2, TimeT connect_until_time, if (sd->status.sex != sd->sex) { - clif_authfail_fd(sd->fd, 0); + clif_authfail_fd(sd->sess, 0); return 1; } @@ -690,10 +690,10 @@ int pc_authok(int id, int login_id2, TimeT connect_until_time, // This would leak information. // It's better to make it obvious that players can see you. if (false && bool(old_option & Option::INVISIBILITY)) - is_atcommand(sd->fd, sd, "@invisible", 0); + is_atcommand(sd->sess, sd, "@invisible", 0); if (bool(old_option & Option::HIDE)) - is_atcommand(sd->fd, sd, "@hide", 0); + is_atcommand(sd->sess, sd, "@hide", 0); // atcommand_hide might already send it, but also might not clif_changeoption(sd); } @@ -765,7 +765,7 @@ int pc_authok(int id, int login_id2, TimeT connect_until_time, char tmpstr[] = WITH_TIMESTAMP("Your account time limit is: "); REPLACE_TIMESTAMP(tmpstr, connect_until_time); - clif_wis_message(sd->fd, wisp_server_name, const_(tmpstr)); + clif_wis_message(sd->sess, wisp_server_name, const_(tmpstr)); } pc_calcstatus(sd, 1); @@ -783,7 +783,7 @@ void pc_show_motd(dumb_ptr sd) FString buf; while (in.getline(buf)) { - clif_displaymessage(sd->fd, buf); + clif_displaymessage(sd->sess, buf); } } } @@ -800,7 +800,7 @@ int pc_authfail(int id) if (sd == NULL) return 1; - clif_authfail_fd(sd->fd, 0); + clif_authfail_fd(sd->sess, 0); return 0; } @@ -2890,7 +2890,7 @@ int pc_attack(dumb_ptr sd, int target_id, int type) if (bl->bl_type == BL::NPC) { // monster npcs [Valaris] - npc_click(sd, RFIFOL(sd->fd, 2)); + npc_click(sd, RFIFOL(sd->sess, 2)); return 0; } @@ -3097,7 +3097,7 @@ int pc_gainexp_reason(dumb_ptr sd, int base_exp, int job_exp, FString output = STRPRINTF( "Experienced Gained Base:%d Job:%d", base_exp, job_exp); - clif_displaymessage(sd->fd, output); + clif_displaymessage(sd->sess, output); } return 0; @@ -5201,13 +5201,13 @@ void pc_autosave_sub(dumb_ptr sd) { nullpo_retv(sd); - if (save_flag == 0 && sd->fd > last_save_fd) + if (save_flag == 0 && sd->sess->fd > last_save_fd) { pc_makesavestatus(sd); chrif_save(sd); save_flag = 1; - last_save_fd = sd->fd; + last_save_fd = sd->sess->fd; } } @@ -5221,7 +5221,7 @@ void pc_autosave(TimerData *, tick_t) save_flag = 0; clif_foreachclient(pc_autosave_sub); if (save_flag == 0) - last_save_fd = 0; + last_save_fd = -1; interval_t interval = autosave_time / (clif_countusers() + 1); if (interval <= interval_t::zero()) @@ -5231,15 +5231,15 @@ void pc_autosave(TimerData *, tick_t) ).detach(); } -int pc_read_gm_account(int fd) +int pc_read_gm_account(Session *s) { gm_accountm.clear(); // (RFIFOW(fd, 2) - 4) / 5 - for (int i = 4; i < RFIFOW(fd, 2); i += 5) + for (int i = 4; i < RFIFOW(s, 2); i += 5) { - int account_id = RFIFOL(fd, i); - uint8_t level = RFIFOB(fd, i + 4); + int account_id = RFIFOL(s, i); + uint8_t level = RFIFOB(s, i + 4); gm_accountm[account_id] = level; } return gm_accountm.size(); diff --git a/src/map/pc.hpp b/src/map/pc.hpp index 54394a2..48ba8f3 100644 --- a/src/map/pc.hpp +++ b/src/map/pc.hpp @@ -54,7 +54,7 @@ int pc_setrestartvalue(dumb_ptr sd, int type); void pc_makesavestatus(dumb_ptr); int pc_setnewpc(dumb_ptr, int, int, int, tick_t, SEX); int pc_authok(int, int, TimeT, short tmw_version, const struct mmo_charstatus *); -int pc_authfail(int); +int pc_authfail(int accid); EPOS pc_equippoint(dumb_ptr sd, int n); @@ -146,7 +146,7 @@ void pc_set_gm_level(int account_id, uint8_t level); void pc_setstand(dumb_ptr sd); void pc_cleanup(dumb_ptr sd); // [Fate] Clean up after a logged-out PC -int pc_read_gm_account(int fd); +int pc_read_gm_account(Session *); int pc_setinvincibletimer(dumb_ptr sd, interval_t); int pc_delinvincibletimer(dumb_ptr sd); int pc_logout(dumb_ptr sd); // [fate] Player logs out diff --git a/src/map/script.cpp b/src/map/script.cpp index 279e541..6bd4543 100644 --- a/src/map/script.cpp +++ b/src/map/script.cpp @@ -3857,7 +3857,7 @@ void builtin_gmcommand(ScriptState *st) sd = script_rid2sd(st); dumb_string cmd = conv_str(st, &AARGO2(2)); - is_atcommand(sd->fd, sd, cmd, 99); + is_atcommand(sd->sess, sd, cmd, 99); } @@ -3914,7 +3914,7 @@ void builtin_message(ScriptState *st) dumb_ptr pl_sd = map_nick2sd(player); if (pl_sd == NULL) return; - clif_displaymessage(pl_sd->fd, msg); + clif_displaymessage(pl_sd->sess, msg); } diff --git a/src/map/tmw.cpp b/src/map/tmw.cpp index 9841a75..7e661bb 100644 --- a/src/map/tmw.cpp +++ b/src/map/tmw.cpp @@ -81,8 +81,8 @@ int tmw_CheckChatSpam(dumb_ptr sd, XString message) (sd->chat_lines_in >= battle_config.chat_spam_warn || sd->chat_total_repeats >= battle_config.chat_spam_warn)) { - clif_displaymessage(sd->fd, "WARNING: You are about to be automatically banned for spam!"); - clif_displaymessage(sd->fd, "WARNING: Please slow down, do not repeat, and do not SHOUT!"); + clif_displaymessage(sd->sess, "WARNING: You are about to be automatically banned for spam!"); + clif_displaymessage(sd->sess, "WARNING: Please slow down, do not repeat, and do not SHOUT!"); } return 0; @@ -107,12 +107,12 @@ void tmw_AutoBan(dumb_ptr sd, ZString reason, int length) FString anotherbuf = STRPRINTF("You have been banned for %s spamming. Please do not spam.", reason); - clif_displaymessage(sd->fd, anotherbuf); + clif_displaymessage(sd->sess, anotherbuf); /* type: 2 - ban(year, month, day, hour, minute, second) */ HumanTimeDiff ban_len {}; ban_len.hour = length; chrif_char_ask_name(-1, sd->status.name, 2, ban_len); - clif_setwaitclose(sd->fd); + clif_setwaitclose(sd->sess); } // Returns true if more than 50% of input message is caps or punctuation -- cgit v1.2.3-60-g2f50