diff options
Diffstat (limited to 'src/map')
-rw-r--r-- | src/map/atcommand.cpp | 283 | ||||
-rw-r--r-- | src/map/chat.cpp | 181 | ||||
-rw-r--r-- | src/map/chat.hpp | 12 | ||||
-rw-r--r-- | src/map/chrif.cpp | 16 | ||||
-rw-r--r-- | src/map/clif.cpp | 151 | ||||
-rw-r--r-- | src/map/intif.cpp | 16 | ||||
-rw-r--r-- | src/map/map.cpp | 61 | ||||
-rw-r--r-- | src/map/map.hpp | 20 | ||||
-rw-r--r-- | src/map/map.t.hpp | 1 | ||||
-rw-r--r-- | src/map/mob.cpp | 16 | ||||
-rw-r--r-- | src/map/npc.cpp | 3 | ||||
-rw-r--r-- | src/map/party.cpp | 19 | ||||
-rw-r--r-- | src/map/pc.cpp | 30 | ||||
-rw-r--r-- | src/map/pc.hpp | 5 | ||||
-rw-r--r-- | src/map/script.cpp | 30 | ||||
-rw-r--r-- | src/map/skill.cpp | 4 |
16 files changed, 287 insertions, 561 deletions
diff --git a/src/map/atcommand.cpp b/src/map/atcommand.cpp index 5fffaa3..e4ec17b 100644 --- a/src/map/atcommand.cpp +++ b/src/map/atcommand.cpp @@ -910,8 +910,7 @@ int atcommand_jump(const int fd, struct map_session_data *sd, int atcommand_who(const int fd, struct map_session_data *sd, const char *, const char *message) { - struct map_session_data *pl_sd; - int i, j, count; + int count; int pl_GM_level, GM_level; char match_text[100]; char player_name[24]; @@ -921,24 +920,27 @@ int atcommand_who(const int fd, struct map_session_data *sd, if (sscanf(message, "%99[^\n]", match_text) < 1) strcpy(match_text, ""); - for (j = 0; match_text[j]; j++) + for (int j = 0; match_text[j]; j++) match_text[j] = tolower(match_text[j]); count = 0; GM_level = pc_isGM(sd); - for (i = 0; i < fd_max; i++) + for (int i = 0; i < fd_max; i++) { - if (session[i] && (pl_sd = (struct map_session_data *)session[i]->session_data) - && pl_sd->state.auth) + if (!session[i]) + continue; + map_session_data *pl_sd = static_cast<map_session_data *>(session[i]->session_data.get()); + if (pl_sd && pl_sd->state.auth) { pl_GM_level = pc_isGM(pl_sd); if (! ((battle_config.hide_GM_session || bool(pl_sd->status.option & Option::HIDE)) && (pl_GM_level > GM_level))) - { // you can look only lower or same level + { + // you can look only lower or same level memcpy(player_name, pl_sd->status.name, 24); - for (j = 0; player_name[j]; j++) + for (int j = 0; player_name[j]; j++) player_name[j] = tolower(player_name[j]); if (strstr(player_name, match_text) != NULL) { @@ -981,8 +983,7 @@ int atcommand_who(const int fd, struct map_session_data *sd, int atcommand_whogroup(const int fd, struct map_session_data *sd, const char *, const char *message) { - struct map_session_data *pl_sd; - int i, j, count; + int count; int pl_GM_level, GM_level; char match_text[100]; char player_name[24]; @@ -993,27 +994,31 @@ int atcommand_whogroup(const int fd, struct map_session_data *sd, if (sscanf(message, "%99[^\n]", match_text) < 1) strcpy(match_text, ""); - for (j = 0; match_text[j]; j++) + for (int j = 0; match_text[j]; j++) match_text[j] = tolower(match_text[j]); count = 0; GM_level = pc_isGM(sd); - for (i = 0; i < fd_max; i++) + for (int i = 0; i < fd_max; i++) { - if (session[i] && (pl_sd = (struct map_session_data *)session[i]->session_data) - && pl_sd->state.auth) + if (!session[i]) + continue; + map_session_data *pl_sd = static_cast<map_session_data *>(session[i]->session_data.get()); + if (pl_sd && pl_sd->state.auth) { pl_GM_level = pc_isGM(pl_sd); if (! ((battle_config.hide_GM_session || bool(pl_sd->status.option & Option::HIDE)) && (pl_GM_level > GM_level))) - { // you can look only lower or same level + { + // you can look only lower or same level memcpy(player_name, pl_sd->status.name, 24); - for (j = 0; player_name[j]; j++) + for (int j = 0; player_name[j]; j++) player_name[j] = tolower(player_name[j]); if (strstr(player_name, match_text) != NULL) - { // search with no case sensitive + { + // search with no case sensitive p = party_search(pl_sd->status.party_id); const char *temp0 = p ? p->name : "None"; std::string output; @@ -1048,8 +1053,7 @@ int atcommand_whogroup(const int fd, struct map_session_data *sd, int atcommand_whomap(const int fd, struct map_session_data *sd, const char *, const char *message) { - struct map_session_data *pl_sd; - int i, count; + int count; int pl_GM_level, GM_level; int map_id; char map_name[100]; @@ -1069,10 +1073,12 @@ int atcommand_whomap(const int fd, struct map_session_data *sd, count = 0; GM_level = pc_isGM(sd); - for (i = 0; i < fd_max; i++) + for (int i = 0; i < fd_max; i++) { - if (session[i] && (pl_sd = (struct map_session_data *)session[i]->session_data) - && pl_sd->state.auth) + if (!session[i]) + continue; + map_session_data *pl_sd = static_cast<map_session_data *>(session[i]->session_data.get()); + if (pl_sd && pl_sd->state.auth) { pl_GM_level = pc_isGM(pl_sd); if (! @@ -1114,8 +1120,7 @@ int atcommand_whomap(const int fd, struct map_session_data *sd, int atcommand_whomapgroup(const int fd, struct map_session_data *sd, const char *, const char *message) { - struct map_session_data *pl_sd; - int i, count; + int count; int pl_GM_level, GM_level; int map_id = 0; char map_name[100]; @@ -1136,10 +1141,12 @@ int atcommand_whomapgroup(const int fd, struct map_session_data *sd, count = 0; GM_level = pc_isGM(sd); - for (i = 0; i < fd_max; i++) + for (int i = 0; i < fd_max; i++) { - if (session[i] && (pl_sd = (struct map_session_data *)session[i]->session_data) - && pl_sd->state.auth) + if (!session[i]) + continue; + map_session_data *pl_sd = static_cast<map_session_data *>(session[i]->session_data.get()); + if (pl_sd && pl_sd->state.auth) { pl_GM_level = pc_isGM(pl_sd); if (! @@ -1187,8 +1194,7 @@ int atcommand_whomapgroup(const int fd, struct map_session_data *sd, int atcommand_whogm(const int fd, struct map_session_data *sd, const char *, const char *message) { - struct map_session_data *pl_sd; - int i, j, count; + int count; int pl_GM_level, GM_level; char match_text[100]; char player_name[24]; @@ -1199,15 +1205,17 @@ int atcommand_whogm(const int fd, struct map_session_data *sd, if (sscanf(message, "%99[^\n]", match_text) < 1) strcpy(match_text, ""); - for (j = 0; match_text[j]; j++) + for (int j = 0; match_text[j]; j++) match_text[j] = tolower(match_text[j]); count = 0; GM_level = pc_isGM(sd); - for (i = 0; i < fd_max; i++) + for (int i = 0; i < fd_max; i++) { - if (session[i] && (pl_sd = (struct map_session_data *)session[i]->session_data) - && pl_sd->state.auth) + if (!session[i]) + continue; + map_session_data *pl_sd = static_cast<map_session_data *>(session[i]->session_data.get()); + if (pl_sd && pl_sd->state.auth) { pl_GM_level = pc_isGM(pl_sd); if (pl_GM_level > 0) @@ -1219,7 +1227,7 @@ int atcommand_whogm(const int fd, struct map_session_data *sd, { // you can look only lower or same level memcpy(player_name, pl_sd->status.name, 24); - for (j = 0; player_name[j]; j++) + for (int j = 0; player_name[j]; j++) player_name[j] = tolower(player_name[j]); if (strstr(player_name, match_text) != NULL) { @@ -1879,9 +1887,6 @@ int atcommand_gm(const int fd, struct map_session_data *sd, int atcommand_pvpoff(const int fd, struct map_session_data *sd, const char *, const char *) { - struct map_session_data *pl_sd; - int i; - 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."); @@ -1891,10 +1896,12 @@ int atcommand_pvpoff(const int fd, struct map_session_data *sd, if (map[sd->bl.m].flag.pvp) { map[sd->bl.m].flag.pvp = 0; - for (i = 0; i < fd_max; i++) - { //人数分ループ - if (session[i] && (pl_sd = (struct map_session_data *)session[i]->session_data) - && pl_sd->state.auth) + for (int i = 0; i < fd_max; i++) + { + if (!session[i]) + continue; + map_session_data *pl_sd = static_cast<map_session_data *>(session[i]->session_data.get()); + if (pl_sd && pl_sd->state.auth) { if (sd->bl.m == pl_sd->bl.m) { @@ -1920,9 +1927,6 @@ int atcommand_pvpoff(const int fd, struct map_session_data *sd, int atcommand_pvpon(const int fd, struct map_session_data *sd, const char *, const char *) { - struct map_session_data *pl_sd; - int i; - 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."); @@ -1932,10 +1936,12 @@ int atcommand_pvpon(const int fd, struct map_session_data *sd, if (!map[sd->bl.m].flag.pvp && !map[sd->bl.m].flag.nopvp) { map[sd->bl.m].flag.pvp = 1; - for (i = 0; i < fd_max; i++) + for (int i = 0; i < fd_max; i++) { - if (session[i] && (pl_sd = (struct map_session_data *)session[i]->session_data) - && pl_sd->state.auth) + if (!session[i]) + continue; + map_session_data *pl_sd = static_cast<map_session_data *>(session[i]->session_data.get()); + if (pl_sd && pl_sd->state.auth) { if (sd->bl.m == pl_sd->bl.m && !pl_sd->pvp_timer) { @@ -2702,15 +2708,15 @@ int atcommand_character_stats(const int fd, struct map_session_data *, int atcommand_character_stats_all(const int fd, struct map_session_data *, const char *, const char *) { - int i; int count; - struct map_session_data *pl_sd; count = 0; - for (i = 0; i < fd_max; i++) + for (int i = 0; i < fd_max; i++) { - if (session[i] && (pl_sd = (struct map_session_data *)session[i]->session_data) - && pl_sd->state.auth) + if (!session[i]) + continue; + map_session_data *pl_sd = static_cast<map_session_data *>(session[i]->session_data.get()); + if (pl_sd && pl_sd->state.auth) { std::string gmlevel; if (pc_isGM(pl_sd) > 0) @@ -3149,12 +3155,12 @@ int atcommand_character_save(const int fd, struct map_session_data *sd, int atcommand_doom(const int fd, struct map_session_data *sd, const char *, const char *) { - struct map_session_data *pl_sd; - int i; - - for (i = 0; i < fd_max; i++) + for (int i = 0; i < fd_max; i++) { - if (session[i] && (pl_sd = (struct map_session_data *)session[i]->session_data) + if (!session[i]) + continue; + map_session_data *pl_sd = static_cast<map_session_data *>(session[i]->session_data.get()); + if (pl_sd && pl_sd->state.auth && i != fd && pc_isGM(sd) >= pc_isGM(pl_sd)) { // you can doom only lower or same gm level @@ -3174,12 +3180,12 @@ int atcommand_doom(const int fd, struct map_session_data *sd, int atcommand_doommap(const int fd, struct map_session_data *sd, const char *, const char *) { - struct map_session_data *pl_sd; - int i; - - for (i = 0; i < fd_max; i++) + for (int i = 0; i < fd_max; i++) { - if (session[i] && (pl_sd = (struct map_session_data *)session[i]->session_data) + if (!session[i]) + continue; + map_session_data *pl_sd = static_cast<map_session_data *>(session[i]->session_data.get()); + if (pl_sd && pl_sd->state.auth && i != fd && sd->bl.m == pl_sd->bl.m && pc_isGM(sd) >= pc_isGM(pl_sd)) { // you can doom only lower or same gm level @@ -3218,12 +3224,12 @@ void atcommand_raise_sub(struct map_session_data *sd) int atcommand_raise(const int fd, struct map_session_data *, const char *, const char *) { - int i; - - for (i = 0; i < fd_max; i++) + for (int i = 0; i < fd_max; i++) { - if (session[i]) - atcommand_raise_sub((struct map_session_data *)session[i]->session_data); + if (!session[i]) + continue; + map_session_data *pl_sd = static_cast<map_session_data *>(session[i]->session_data.get()); + atcommand_raise_sub(pl_sd); } clif_displaymessage(fd, "Mercy has been granted."); @@ -3237,12 +3243,12 @@ int atcommand_raise(const int fd, struct map_session_data *, int atcommand_raisemap(const int fd, struct map_session_data *sd, const char *, const char *) { - struct map_session_data *pl_sd; - int i; - - for (i = 0; i < fd_max; i++) + for (int i = 0; i < fd_max; i++) { - if (session[i] && (pl_sd = (struct map_session_data *)session[i]->session_data) + if (!session[i]) + continue; + map_session_data *pl_sd = static_cast<map_session_data *>(session[i]->session_data.get()); + if (pl_sd && pl_sd->state.auth && sd->bl.m == pl_sd->bl.m) atcommand_raise_sub(pl_sd); } @@ -3475,14 +3481,15 @@ int atcommand_kick(const int fd, struct map_session_data *sd, int atcommand_kickall(const int fd, struct map_session_data *sd, const char *, const char *) { - struct map_session_data *pl_sd; - int i; - - for (i = 0; i < fd_max; i++) + for (int i = 0; i < fd_max; i++) { - if (session[i] && (pl_sd = (struct map_session_data *)session[i]->session_data) + if (!session[i]) + continue; + map_session_data *pl_sd = static_cast<map_session_data *>(session[i]->session_data.get()); + if (pl_sd && pl_sd->state.auth && pc_isGM(sd) >= pc_isGM(pl_sd)) - { // you can kick only lower or same gm level + { + // you can kick only lower or same gm level if (sd->status.account_id != pl_sd->status.account_id) clif_GM_kick(sd, pl_sd, 0); } @@ -3747,13 +3754,12 @@ int atcommand_party(const int fd, struct map_session_data *sd, int atcommand_mapexit(const int, struct map_session_data *sd, const char *, const char *) { - struct map_session_data *pl_sd; - int i; - - for (i = 0; i < fd_max; i++) + for (int i = 0; i < fd_max; i++) { - if (session[i] && (pl_sd = (struct map_session_data *)session[i]->session_data) - && pl_sd->state.auth) + if (!session[i]) + continue; + map_session_data *pl_sd = static_cast<map_session_data *>(session[i]->session_data.get()); + if (pl_sd && pl_sd->state.auth) { if (sd->status.account_id != pl_sd->status.account_id) clif_GM_kick(sd, pl_sd, 0); @@ -4248,8 +4254,6 @@ int atcommand_charzeny(const int fd, struct map_session_data *, int atcommand_recallall(const int fd, struct map_session_data *sd, const char *, const char *) { - struct map_session_data *pl_sd; - int i; int count; if (sd->bl.m >= 0 && map[sd->bl.m].flag.nowarpto @@ -4261,13 +4265,17 @@ int atcommand_recallall(const int fd, struct map_session_data *sd, } count = 0; - for (i = 0; i < fd_max; i++) + for (int i = 0; i < fd_max; i++) { - if (session[i] && (pl_sd = (struct map_session_data *)session[i]->session_data) + if (!session[i]) + continue; + map_session_data *pl_sd = static_cast<map_session_data *>(session[i]->session_data.get()); + if (pl_sd && pl_sd->state.auth && sd->status.account_id != pl_sd->status.account_id && pc_isGM(sd) >= pc_isGM(pl_sd)) - { // you can recall only lower or same level + { + // you can recall only lower or same level if (pl_sd->bl.m >= 0 && map[pl_sd->bl.m].flag.nowarp && battle_config.any_warp_GM_min_level > pc_isGM(sd)) count++; @@ -4295,8 +4303,6 @@ int atcommand_recallall(const int fd, struct map_session_data *sd, int atcommand_partyrecall(const int fd, struct map_session_data *sd, const char *, const char *message) { - int i; - struct map_session_data *pl_sd; char party_name[100]; struct party *p; int count; @@ -4322,10 +4328,12 @@ int atcommand_partyrecall(const int fd, struct map_session_data *sd, (p = party_search(atoi(message))) != NULL) { count = 0; - for (i = 0; i < fd_max; i++) + for (int i = 0; i < fd_max; i++) { - if (session[i] && (pl_sd = (struct map_session_data *)session[i]->session_data) - && pl_sd->state.auth + if (!session[i]) + continue; + map_session_data *pl_sd = static_cast<map_session_data *>(session[i]->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) { @@ -4431,18 +4439,15 @@ int atcommand_reloadgmdb(const int fd, struct map_session_data *, * 0 = no additional information * 1 = Show users in that map and their location * 2 = Shows NPCs in that map - * 3 = Shows the shops/chats in that map (not implemented) *------------------------------------------ */ int atcommand_mapinfo(const int fd, struct map_session_data *sd, const char *, const char *message) { - struct map_session_data *pl_sd; struct npc_data *nd = NULL; - struct chat_data *cd = NULL; char map_name[100]; const char *direction = NULL; - int m_id, i, chat_num, list = 0; + int m_id, list = 0; memset(map_name, '\0', sizeof(map_name)); @@ -4473,18 +4478,6 @@ int atcommand_mapinfo(const int fd, struct map_session_data *sd, clif_displaymessage(fd, output); output = STRPRINTF("NPCs In Map: %d", map[m_id].npc_num); clif_displaymessage(fd, output); - chat_num = 0; - for (i = 0; i < fd_max; i++) - { - if (session[i] && (pl_sd = (struct map_session_data *)session[i]->session_data) - && pl_sd->state.auth - && (cd = (struct chat_data *) map_id2bl(pl_sd->chatID))) - { - chat_num++; - } - } - output = STRPRINTF("Chats In Map: %d", chat_num); - clif_displaymessage(fd, output); clif_displaymessage(fd, "------ Map Flags ------"); output = STRPRINTF("Player vs Player: %s | No Party: %s", (map[m_id].flag.pvp) ? "True" : "False", @@ -4522,10 +4515,12 @@ int atcommand_mapinfo(const int fd, struct map_session_data *sd, break; case 1: clif_displaymessage(fd, "----- Players in Map -----"); - for (i = 0; i < fd_max; i++) + for (int i = 0; i < fd_max; i++) { - if (session[i] && (pl_sd = (struct map_session_data *)session[i]->session_data) - && pl_sd->state.auth + if (!session[i]) + continue; + map_session_data *pl_sd = static_cast<map_session_data *>(session[i]->session_data.get()); + if (pl_sd && pl_sd->state.auth && strcmp(pl_sd->mapname, map_name) == 0) { output = STRPRINTF( @@ -4537,7 +4532,7 @@ int atcommand_mapinfo(const int fd, struct map_session_data *sd, break; case 2: clif_displaymessage(fd, "----- NPCs in Map -----"); - for (i = 0; i < map[m_id].npc_num;) + for (int i = 0; i < map[m_id].npc_num;) { nd = map[m_id].npc[i]; switch (nd->dir) @@ -4582,32 +4577,9 @@ int atcommand_mapinfo(const int fd, struct map_session_data *sd, clif_displaymessage(fd, output); } break; - case 3: - clif_displaymessage(fd, "----- Chats in Map -----"); - for (i = 0; i < fd_max; i++) - { - if (session[i] && (pl_sd = (struct map_session_data *)session[i]->session_data) - && pl_sd->state.auth - && (cd = (struct chat_data *) map_id2bl(pl_sd->chatID)) - && strcmp(pl_sd->mapname, map_name) == 0 - && cd->usersd[0] == pl_sd) - { - output = STRPRINTF( - "Chat %d: %s | Player: %s | Location: %d %d", i, - cd->title, pl_sd->status.name, cd->bl.x, - cd->bl.y); - clif_displaymessage(fd, output); - output = STRPRINTF( - " Users: %d/%d | Password: %s | Public: %s", - cd->users, cd->limit, cd->pass, - (cd->pub) ? "Yes" : "No"); - clif_displaymessage(fd, output); - } - } - break; default: // normally impossible to arrive here clif_displaymessage(fd, - "Please, enter at least a valid list number (usage: @mapinfo <0-3> [map])."); + "Please, enter at least a valid list number (usage: @mapinfo <0-2> [map])."); return -1; } @@ -4977,8 +4949,7 @@ int atcommand_charignorelist(const int fd, struct map_session_data *, if (count > 0) for (i = 0; - i < - (int)(sizeof(pl_sd->ignore) / sizeof(pl_sd->ignore[0])); + i < (int)(sizeof(pl_sd->ignore) / sizeof(pl_sd->ignore[0])); i++) if (pl_sd->ignore[i].name[0]) clif_displaymessage(fd, pl_sd->ignore[i].name); @@ -5172,8 +5143,7 @@ int atcommand_email(const int fd, struct map_session_data *sd, int atcommand_effect(const int fd, struct map_session_data *sd, const char *, const char *message) { - struct map_session_data *pl_sd; - int type = 0, flag = 0, i; + int type = 0, flag = 0; if (!message || !*message || sscanf(message, "%d %d", &type, &flag) < 2) { @@ -5188,10 +5158,12 @@ int atcommand_effect(const int fd, struct map_session_data *sd, } else { - for (i = 0; i < fd_max; i++) + for (int i = 0; i < fd_max; i++) { - if (session[i] && (pl_sd = (struct map_session_data *)session[i]->session_data) - && pl_sd->state.auth) + if (!session[i]) + continue; + map_session_data *pl_sd = static_cast<map_session_data *>(session[i]->session_data.get()); + if (pl_sd && pl_sd->state.auth) { clif_specialeffect(&pl_sd->bl, type, flag); clif_displaymessage(pl_sd->fd, "Your Effect Has Changed."); // Your effect has changed. @@ -6529,10 +6501,8 @@ int atcommand_skill_learn(const int fd, struct map_session_data *, int atcommand_ipcheck(const int fd, struct map_session_data *, const char *, const char *message) { - struct map_session_data *pl_sd; struct sockaddr_in sai; char character[25]; - int i; socklen_t sa_len = sizeof(struct sockaddr); unsigned long ip; @@ -6544,6 +6514,7 @@ int atcommand_ipcheck(const int fd, struct map_session_data *, return -1; } + map_session_data *pl_sd; if ((pl_sd = map_nick2sd(character)) == NULL) { clif_displaymessage(fd, "Character not found."); @@ -6562,10 +6533,12 @@ int atcommand_ipcheck(const int fd, struct map_session_data *, // We now have the IP address of a character. // Loop over all logged in sessions looking for matches. - for (i = 0; i < fd_max; i++) + for (int i = 0; i < fd_max; i++) { - if (session[i] && (pl_sd = (struct map_session_data *)session[i]->session_data) - && pl_sd->state.auth) + if (!session[i]) + continue; + pl_sd = static_cast<map_session_data *>(session[i]->session_data.get()); + if (pl_sd && pl_sd->state.auth) { if (getpeername(pl_sd->fd, (struct sockaddr *)&sai, &sa_len)) continue; @@ -6589,12 +6562,12 @@ int atcommand_ipcheck(const int fd, struct map_session_data *, int atcommand_doomspot(const int fd, struct map_session_data *sd, const char *, const char *) { - struct map_session_data *pl_sd; - int i; - - for (i = 0; i < fd_max; i++) + for (int i = 0; i < fd_max; i++) { - if (session[i] && (pl_sd = (struct map_session_data *)session[i]->session_data) + if (!session[i]) + continue; + map_session_data *pl_sd = static_cast<map_session_data *>(session[i]->session_data.get()); + if (pl_sd && pl_sd->state.auth && i != fd && 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)) diff --git a/src/map/chat.cpp b/src/map/chat.cpp deleted file mode 100644 index 0d3bb95..0000000 --- a/src/map/chat.cpp +++ /dev/null @@ -1,181 +0,0 @@ -#include "chat.hpp" - -#include <cstdlib> -#include <cstring> - -#include "../common/nullpo.hpp" - -#include "map.hpp" -#include "npc.hpp" -#include "pc.hpp" - -#include "../poison.hpp" - -static -int chat_triggerevent(struct chat_data *cd); -static -int chat_npckickall(struct chat_data *cd); - -/*========================================== - * チャットルームから抜ける - *------------------------------------------ - */ -int chat_leavechat(struct map_session_data *sd) -{ - struct chat_data *cd; - int i, leavechar; - - nullpo_retr(1, sd); - - cd = (struct chat_data *) map_id2bl(sd->chatID); - if (cd == NULL) - return 1; - - for (i = 0, leavechar = -1; i < cd->users; i++) - { - if (cd->usersd[i] == sd) - { - leavechar = i; - break; - } - } - if (leavechar < 0) // そのchatに所属していないらしい (バグ時のみ) - return -1; - - cd->users--; - pc_setchatid(sd, 0); - - if (cd->users == 0 && (*cd->owner)->type == BL::PC) - { - // 全員居なくなった&PCのチャットなので消す - map_delobject(cd->bl.id, BL::CHAT); // freeまでしてくれる - } - else - { - for (i = leavechar; i < cd->users; i++) - cd->usersd[i] = cd->usersd[i + 1]; - if (leavechar == 0 && (*cd->owner)->type == BL::PC) - { - // PCのチャットなので所有者が抜けたので位置変更 - cd->bl.x = cd->usersd[0]->bl.x; - cd->bl.y = cd->usersd[0]->bl.y; - } - } - - return 0; -} - -/*========================================== - * npcチャットルーム作成 - *------------------------------------------ - */ -int chat_createnpcchat(struct npc_data *nd, int limit, int pub, int trigger, - const char *title, int titlelen, const char *ev) -{ - struct chat_data *cd; - - nullpo_retr(1, nd); - - CREATE(cd, struct chat_data, 1); - - cd->limit = cd->trigger = limit; - if (trigger > 0) - cd->trigger = trigger; - cd->pub = pub; - cd->users = 0; - memcpy(cd->pass, "", 8); - if (titlelen >= sizeof(cd->title) - 1) - titlelen = sizeof(cd->title) - 1; - memcpy(cd->title, title, titlelen); - cd->title[titlelen] = 0; - - cd->bl.m = nd->bl.m; - cd->bl.x = nd->bl.x; - cd->bl.y = nd->bl.y; - cd->bl.type = BL::CHAT; - cd->owner_ = (struct block_list *) nd; - cd->owner = &cd->owner_; - memcpy(cd->npc_event, ev, sizeof(cd->npc_event)); - - cd->bl.id = map_addobject(&cd->bl); - if (cd->bl.id == 0) - { - free(cd); - return 0; - } - nd->chat_id = cd->bl.id; - - return 0; -} - -/*========================================== - * npcチャットルーム削除 - *------------------------------------------ - */ -int chat_deletenpcchat(struct npc_data *nd) -{ - struct chat_data *cd; - - nullpo_ret(nd); - cd = (struct chat_data *) map_id2bl(nd->chat_id); - nullpo_ret(cd); - - chat_npckickall(cd); - map_delobject(cd->bl.id, BL::CHAT); // freeまでしてくれる - nd->chat_id = 0; - - return 0; -} - -/*========================================== - * 規定人数以上でイベントが定義されてるなら実行 - *------------------------------------------ - */ -int chat_triggerevent(struct chat_data *cd) -{ - nullpo_ret(cd); - - if (cd->users >= cd->trigger && cd->npc_event[0]) - npc_event_do(cd->npc_event); - return 0; -} - -/*========================================== - * イベントの有効化 - *------------------------------------------ - */ -int chat_enableevent(struct chat_data *cd) -{ - nullpo_ret(cd); - - cd->trigger &= 0x7f; - chat_triggerevent(cd); - return 0; -} - -/*========================================== - * イベントの無効化 - *------------------------------------------ - */ -int chat_disableevent(struct chat_data *cd) -{ - nullpo_ret(cd); - - cd->trigger |= 0x80; - return 0; -} - -/*========================================== - * チャットルームから全員蹴り出す - *------------------------------------------ - */ -int chat_npckickall(struct chat_data *cd) -{ - nullpo_ret(cd); - - while (cd->users > 0) - { - chat_leavechat(cd->usersd[cd->users - 1]); - } - return 0; -} diff --git a/src/map/chat.hpp b/src/map/chat.hpp deleted file mode 100644 index ead7b49..0000000 --- a/src/map/chat.hpp +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef CHAT_HPP -#define CHAT_HPP - -int chat_leavechat(struct map_session_data *); - -int chat_createnpcchat(struct npc_data *nd, int limit, int pub, int trigger, - const char *title, int titlelen, const char *ev); -int chat_deletenpcchat(struct npc_data *nd); -int chat_enableevent(struct chat_data *cd); -int chat_disableevent(struct chat_data *cd); - -#endif // CHAT_HPP diff --git a/src/map/chrif.cpp b/src/map/chrif.cpp index 6742f88..4757c0a 100644 --- a/src/map/chrif.cpp +++ b/src/map/chrif.cpp @@ -199,7 +199,7 @@ int chrif_changemapserver(struct map_session_data *sd, char *name, int x, s_ip = 0; for (i = 0; i < fd_max; i++) - if (session[i] && session[i]->session_data == sd) + if (session[i] && session[i]->session_data.get() == sd) { s_ip = session[i]->client_addr.sin_addr.s_addr; break; @@ -310,7 +310,7 @@ int chrif_authreq(struct map_session_data *sd) return -1; for (i = 0; i < fd_max; i++) - if (session[i] && session[i]->session_data == sd) + if (session[i] && session[i]->session_data.get() == sd) { WFIFOW(char_fd, 0) = 0x2afc; WFIFOL(char_fd, 2) = sd->bl.id; @@ -340,7 +340,7 @@ int chrif_charselectreq(struct map_session_data *sd) s_ip = 0; for (i = 0; i < fd_max; i++) - if (session[i] && session[i]->session_data == sd) + if (session[i] && session[i]->session_data.get() == sd) { s_ip = session[i]->client_addr.sin_addr.s_addr; break; @@ -1161,16 +1161,18 @@ void chrif_parse(int fd) static void send_users_tochar(TimerData *, tick_t) { - int users = 0, i; - struct map_session_data *sd; + int users = 0; if (char_fd <= 0 || session[char_fd] == NULL) return; WFIFOW(char_fd, 0) = 0x2aff; - for (i = 0; i < fd_max; i++) + for (int i = 0; i < fd_max; i++) { - if (session[i] && (sd = (struct map_session_data *)session[i]->session_data) && sd->state.auth && + if (!session[i]) + continue; + map_session_data *sd = static_cast<map_session_data *>(session[i]->session_data.get()); + if (sd && sd->state.auth && !((battle_config.hide_GM_session || sd->state.shroud_active || bool(sd->status.option & Option::HIDE)) && pc_isGM(sd))) diff --git a/src/map/clif.cpp b/src/map/clif.cpp index 1deb1f3..4e70418 100644 --- a/src/map/clif.cpp +++ b/src/map/clif.cpp @@ -66,11 +66,7 @@ enum class SendWho ALL_SAMEMAP, AREA, AREA_WOS, - AREA_WOC, - AREA_WOSC, AREA_CHAT_WOC, - CHAT, - CHAT_WOS, PARTY, PARTY_WOS, PARTY_SAMEMAP, @@ -164,14 +160,14 @@ int clif_getport(void) */ int clif_countusers(void) { - int users = 0, i; - struct map_session_data *sd; + int users = 0; - for (i = 0; i < fd_max; i++) + for (int i = 0; i < fd_max; i++) { - if (session[i] && (sd = (struct map_session_data *)session[i]->session_data) && sd - && sd->state.auth && !(battle_config.hide_GM_session - && pc_isGM(sd))) + if (!session[i]) + continue; + map_session_data *sd = static_cast<map_session_data *>(session[i]->session_data.get()); + if (sd && sd->state.auth && !(battle_config.hide_GM_session && pc_isGM(sd))) users++; } return users; @@ -181,15 +177,14 @@ int clif_countusers(void) * 全てのclientに対してfunc()実行 *------------------------------------------ */ -int clif_foreachclient(std::function<void(struct map_session_data *)> func) +int clif_foreachclient(std::function<void (struct map_session_data *)> func) { - int i; - struct map_session_data *sd; - - for (i = 0; i < fd_max; i++) + for (int i = 0; i < fd_max; i++) { - if (session[i] && (sd = (struct map_session_data *)session[i]->session_data) && sd - && sd->state.auth) + if (!session[i]) + continue; + map_session_data *sd = static_cast<map_session_data *>(session[i]->session_data.get()); + if (sd && sd->state.auth) func(sd); } return 0; @@ -238,17 +233,10 @@ void clif_send_sub(struct block_list *bl, const unsigned char *buf, int len, clif_emotion_towards(src_bl, bl, EMOTE_IGNORED); return; } - FALLTHROUGH; - case SendWho::AREA_WOC: - if ((sd && sd->chatID) || (bl && bl == src_bl)) + if (bl && bl == src_bl) return; break; - case SendWho::AREA_WOSC: - if ((sd) && sd->chatID - && sd->chatID == ((struct map_session_data *) src_bl)->chatID) - return; - break; } if (session[sd->fd] != NULL) @@ -280,9 +268,6 @@ void clif_send_sub(struct block_list *bl, const unsigned char *buf, int len, static int clif_send(const uint8_t *buf, int len, struct block_list *bl, SendWho type) { - int i; - struct map_session_data *sd; - struct chat_data *cd; struct party *p = NULL; int x0 = 0, x1 = 0, y0 = 0, y1 = 0; @@ -300,12 +285,10 @@ int clif_send(const uint8_t *buf, int len, struct block_list *bl, SendWho type) switch (type) { case SendWho::AREA: - case SendWho::AREA_WOC: type = SendWho::SELF; break; case SendWho::AREA_WOS: - case SendWho::AREA_WOSC: return 1; default: @@ -318,13 +301,16 @@ int clif_send(const uint8_t *buf, int len, struct block_list *bl, SendWho type) switch (type) { case SendWho::ALL_CLIENT: // 全クライアントに送信 - for (i = 0; i < fd_max; i++) + for (int i = 0; i < fd_max; i++) { - if (session[i] && (sd = (struct map_session_data *)session[i]->session_data) != NULL - && sd->state.auth) + if (!session[i]) + continue; + map_session_data *sd = static_cast<map_session_data *>(session[i]->session_data.get()); + if (sd && sd->state.auth) { if (clif_parse_func_table[RBUFW(buf, 0)].len) - { // packet must exist + { + // packet must exist memcpy(WFIFOP(i, 0), buf, len); WFIFOSET(i, len); } @@ -332,13 +318,16 @@ int clif_send(const uint8_t *buf, int len, struct block_list *bl, SendWho type) } break; case SendWho::ALL_SAMEMAP: // 同じマップの全クライアントに送信 - for (i = 0; i < fd_max; i++) + for (int i = 0; i < fd_max; i++) { - if (session[i] && (sd = (struct map_session_data *)session[i]->session_data) != NULL - && sd->state.auth && sd->bl.m == bl->m) + if (!session[i]) + continue; + map_session_data *sd = static_cast<map_session_data *>(session[i]->session_data.get()); + if (sd && sd->state.auth && sd->bl.m == bl->m) { if (clif_parse_func_table[RBUFW(buf, 0)].len) - { // packet must exist + { + // packet must exist memcpy(WFIFOP(i, 0), buf, len); WFIFOSET(i, len); } @@ -347,8 +336,6 @@ int clif_send(const uint8_t *buf, int len, struct block_list *bl, SendWho type) break; case SendWho::AREA: case SendWho::AREA_WOS: - case SendWho::AREA_WOC: - case SendWho::AREA_WOSC: map_foreachinarea(std::bind(clif_send_sub, ph::_1, buf, len, bl, type), bl->m, bl->x - AREA_SIZE, bl->y - AREA_SIZE, bl->x + AREA_SIZE, bl->y + AREA_SIZE, BL::PC); @@ -358,30 +345,6 @@ int clif_send(const uint8_t *buf, int len, struct block_list *bl, SendWho type) bl->m, bl->x - (AREA_SIZE), bl->y - (AREA_SIZE), bl->x + (AREA_SIZE), bl->y + (AREA_SIZE), BL::PC); break; - case SendWho::CHAT: - case SendWho::CHAT_WOS: - cd = (struct chat_data *) bl; - if (bl->type == BL::PC) - { - sd = (struct map_session_data *) bl; - cd = (struct chat_data *) map_id2bl(sd->chatID); - } - else if (bl->type != BL::CHAT) - break; - if (cd == NULL) - break; - for (i = 0; i < cd->users; i++) - { - if (type == SendWho::CHAT_WOS - && cd->usersd[i] == (struct map_session_data *) bl) - continue; - if (clif_parse_func_table[RBUFW(buf, 0)].len) - { // packet must exist - memcpy(WFIFOP(cd->usersd[i]->fd, 0), buf, len); - WFIFOSET(cd->usersd[i]->fd, len); - } - } - break; case SendWho::PARTY_AREA: // 同じ画面内の全パーティーメンバに送信 case SendWho::PARTY_AREA_WOS: // 自分以外の同じ画面内の全パーティーメンバに送信 @@ -396,7 +359,7 @@ int clif_send(const uint8_t *buf, int len, struct block_list *bl, SendWho type) case SendWho::PARTY_SAMEMAP_WOS: // 自分以外の同じマップの全パーティーメンバに送信 if (bl->type == BL::PC) { - sd = (struct map_session_data *) bl; + struct map_session_data *sd = (struct map_session_data *) bl; if (sd->partyspy > 0) { p = party_search(sd->partyspy); @@ -409,14 +372,14 @@ int clif_send(const uint8_t *buf, int len, struct block_list *bl, SendWho type) } if (p) { - for (i = 0; i < MAX_PARTY; i++) + for (int i = 0; i < MAX_PARTY; i++) { - if ((sd = p->member[i].sd) != NULL) + struct map_session_data *sd = p->member[i].sd; + if (sd) { if (sd->bl.id == bl->id && (type == SendWho::PARTY_WOS || type == SendWho::PARTY_SAMEMAP_WOS - || type == - SendWho::PARTY_AREA_WOS)) + || type == SendWho::PARTY_AREA_WOS)) continue; if (type != SendWho::PARTY && type != SendWho::PARTY_WOS && bl->m != sd->bl.m) // マップチェック continue; @@ -425,21 +388,25 @@ int clif_send(const uint8_t *buf, int len, struct block_list *bl, SendWho type) sd->bl.x > x1 || sd->bl.y > y1)) continue; if (clif_parse_func_table[RBUFW(buf, 0)].len) - { // packet must exist + { + // packet must exist memcpy(WFIFOP(sd->fd, 0), buf, len); WFIFOSET(sd->fd, len); } } } - for (i = 0; i < fd_max; i++) + for (int i = 0; i < fd_max; i++) { - if (session[i] && (sd = (struct map_session_data *)session[i]->session_data) != NULL - && sd->state.auth) + if (!session[i]) + continue; + map_session_data *sd = static_cast<map_session_data *>(session[i]->session_data.get()); + if (sd && sd->state.auth) { if (sd->partyspy == p->party_id) { if (clif_parse_func_table[RBUFW(buf, 0)].len) - { // packet must exist + { + // packet must exist memcpy(WFIFOP(sd->fd, 0), buf, len); WFIFOSET(sd->fd, len); } @@ -449,12 +416,15 @@ int clif_send(const uint8_t *buf, int len, struct block_list *bl, SendWho type) } break; case SendWho::SELF: - sd = (struct map_session_data *) bl; + { + map_session_data *sd = (struct map_session_data *) bl; if (clif_parse_func_table[RBUFW(buf, 0)].len) - { // packet must exist + { + // packet must exist memcpy(WFIFOP(sd->fd, 0), buf, len); WFIFOSET(sd->fd, len); } + } break; default: @@ -3676,16 +3646,15 @@ int clif_specialeffect(struct block_list *bl, int type, int flag) if (flag == 2) { - struct map_session_data *sd = NULL; - int i; - for (i = 0; i < fd_max; i++) + for (int i = 0; i < fd_max; i++) { - if (session[i] && (sd = (struct map_session_data *)session[i]->session_data) != NULL - && sd->state.auth && sd->bl.m == bl->m) + if (!session[i]) + continue; + struct map_session_data *sd = static_cast<map_session_data *>(session[i]->session_data.get()); + if (sd && sd->state.auth && sd->bl.m == bl->m) clif_specialeffect(&sd->bl, type, 1); } } - else if (flag == 1) clif_send(buf, clif_parse_func_table[0x19b].len, bl, SendWho::SELF); else if (!flag) @@ -3706,7 +3675,6 @@ int clif_specialeffect(struct block_list *bl, int type, int flag) static void clif_parse_WantToConnection(int fd, struct map_session_data *sd) { - struct map_session_data *old_sd; int account_id; // account_id in the packet if (sd) @@ -3727,7 +3695,8 @@ void clif_parse_WantToConnection(int fd, struct map_session_data *sd) WFIFOSET(fd, 4); // if same account already connected, we disconnect the 2 sessions - if ((old_sd = map_id2sd(account_id)) != NULL) + struct map_session_data *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 @@ -3736,8 +3705,8 @@ void clif_parse_WantToConnection(int fd, struct map_session_data *sd) } else { - CREATE(sd, struct map_session_data, 1); - session[fd]->session_data = sd; + sd = new map_session_data(); + session[fd]->session_data.reset(sd); sd->fd = fd; pc_setnewpc(sd, account_id, RFIFOL(fd, 6), RFIFOL(fd, 10), @@ -3888,9 +3857,6 @@ void clif_parse_WalkToXY(int fd, struct map_session_data *sd) if (sd->npc_id != 0 || sd->state.storage_open) return; - if (sd->chatID) - return; - if (sd->canmove_tick > gettick()) return; @@ -4094,8 +4060,7 @@ void clif_parse_GlobalMessage(int fd, struct map_session_data *sd) WBUFL(reinterpret_cast<uint8_t *>(buf), 4) = sd->bl.id; // evil multiuse buffer! - clif_send((const uint8_t *)buf, msg_len + 8, &sd->bl, - sd->chatID ? SendWho::CHAT_WOS : SendWho::AREA_CHAT_WOC); + clif_send((const uint8_t *)buf, msg_len + 8, &sd->bl, SendWho::AREA_CHAT_WOC); } /* Send the message back to the speaker. */ @@ -5583,7 +5548,7 @@ func_table clif_parse_func_table[0x0220] = static int clif_check_packet_flood(int fd, int cmd) { - struct map_session_data *sd = (struct map_session_data *)session[fd]->session_data; + map_session_data *sd = static_cast<map_session_data *>(session[fd]->session_data.get()); tick_t tick = gettick(); // sd will not be set if the client hasn't requested @@ -5800,7 +5765,7 @@ static void clif_parse(int fd) { int packet_len = 0, cmd = 0; - struct map_session_data *sd = (struct map_session_data *)session[fd]->session_data; + map_session_data *sd = static_cast<map_session_data *>(session[fd]->session_data.get()); if (!sd || (sd && !sd->state.auth)) { diff --git a/src/map/intif.cpp b/src/map/intif.cpp index 6c8edf5..6a9008e 100644 --- a/src/map/intif.cpp +++ b/src/map/intif.cpp @@ -332,9 +332,9 @@ int intif_parse_WisEnd(int fd) // Received wisp message from map-server via char-server for ALL gm static int mapif_parse_WisToGM(int fd) -{ // 0x3003/0x3803 <packet_len>.w <wispname>.24B <min_gm_level>.w <message>.?B - int i, min_gm_level, len; - struct map_session_data *pl_sd; +{ + // 0x3003/0x3803 <packet_len>.w <wispname>.24B <min_gm_level>.w <message>.?B + int min_gm_level, len; char Wisp_name[24]; char mbuf[255]; @@ -350,12 +350,16 @@ int mapif_parse_WisToGM(int fd) memcpy(message, RFIFOP(fd, 30), len); message[len - 1] = '\0'; // information is sended to all online GM - for (i = 0; i < fd_max; i++) - if (session[i] && (pl_sd = (struct map_session_data *)session[i]->session_data) - && pl_sd->state.auth) + for (int i = 0; i < fd_max; i++) + { + if (!session[i]) + continue; + map_session_data *pl_sd = static_cast<map_session_data *>(session[i]->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, strlen(message) + 1); + } if (message != mbuf) free(message); diff --git a/src/map/map.cpp b/src/map/map.cpp index a3f600a..30354c7 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -22,7 +22,6 @@ #include "atcommand.hpp" #include "battle.hpp" -#include "chat.hpp" #include "chrif.hpp" #include "clif.hpp" #include "grfio.hpp" @@ -92,6 +91,11 @@ char wisp_server_name[24] = "Server"; // can be modified in char-server config static int map_delmap(const char *mapname); +void SessionDeleter::operator()(SessionData *sd) +{ + delete static_cast<map_session_data *>(sd); +} + /*========================================== * 全map鯖総計での接続数設定 * (char鯖から送られてくる) @@ -511,9 +515,8 @@ void map_foreachinmovearea(std::function<void(struct block_list *)> func, continue; if ((bl) && ((dx > 0 && bl->x < x0 + dx) - || (dx < 0 && bl->x > x1 + dx) || (dy > 0 - && bl->y < - y0 + dy) + || (dx < 0 && bl->x > x1 + dx) + || (dy > 0 && bl->y < y0 + dy) || (dy < 0 && bl->y > y1 + dy)) && bl_list_count < BL_LIST_MAX) bl_list[bl_list_count++] = bl; @@ -530,9 +533,8 @@ void map_foreachinmovearea(std::function<void(struct block_list *)> func, continue; if ((bl) && ((dx > 0 && bl->x < x0 + dx) - || (dx < 0 && bl->x > x1 + dx) || (dy > 0 - && bl->y < - y0 + dy) + || (dx < 0 && bl->x > x1 + dx) + || (dy > 0 && bl->y < y0 + dy) || (dy < 0 && bl->y > y1 + dy)) && bl_list_count < BL_LIST_MAX) bl_list[bl_list_count++] = bl; @@ -939,9 +941,6 @@ void map_quit(struct map_session_data *sd) { nullpo_retv(sd); - if (sd->chatID) // チャットから出る - chat_leavechat(sd); - if (sd->trade_partner) // 取引を中断する trade_tradecancel(sd); @@ -992,6 +991,8 @@ void map_quit(struct map_session_data *sd) */ struct map_session_data *map_id2sd(int id) { + // This is bogus. + // However, there might be differences for de-auth'ed accounts. // remove search from db, because: // 1 - all players, npc, items and mob are in this db (to search, it's not speed, and search in session is more sure) // 2 - DB seems not always correct. Sometimes, when a player disconnects, its id (account value) is not removed and structure @@ -1006,12 +1007,17 @@ struct map_session_data *map_id2sd(int id) return (struct map_session_data*)bl; return NULL; */ - int i; - struct map_session_data *sd = NULL; - - for (i = 0; i < fd_max; i++) - if (session[i] && (sd = (struct map_session_data *)session[i]->session_data) && sd->bl.id == id) - return sd; + for (int i = 0; i < fd_max; i++) + { + if (!session[i]) + continue; + if (session[i]->session_data) + { + map_session_data *sd = static_cast<map_session_data *>(session[i]->session_data.get()); + if (sd->bl.id == id) + return sd; + } + } return NULL; } @@ -1037,11 +1043,14 @@ char *map_charid2nick(int id) static struct map_session_data *map_get_session(int i) { - struct map_session_data *d; - - if (i >= 0 && i < fd_max - && session[i] && (d = (struct map_session_data *)session[i]->session_data) && d->state.auth) - return d; + if (i >= 0 && i < fd_max) + { + if (!session[i]) + return nullptr; + map_session_data *d = static_cast<map_session_data *>(session[i]->session_data.get()); + if (d && d->state.auth) + return d; + } return NULL; } @@ -1049,8 +1058,7 @@ struct map_session_data *map_get_session(int i) static struct map_session_data *map_get_session_forward(int start) { - int i; - for (i = start; i < fd_max; i++) + for (int i = start; i < fd_max; i++) { struct map_session_data *d = map_get_session(i); if (d) @@ -1104,7 +1112,6 @@ struct map_session_data *map_nick2sd(const char *nick) { int i, quantity = 0, nicklen; struct map_session_data *sd = NULL; - struct map_session_data *pl_sd = NULL; if (nick == NULL) return NULL; @@ -1113,8 +1120,10 @@ struct map_session_data *map_nick2sd(const char *nick) for (i = 0; i < fd_max; i++) { - if (session[i] && (pl_sd = (struct map_session_data *)session[i]->session_data) - && pl_sd->state.auth) + if (!session[i]) + continue; + map_session_data *pl_sd = static_cast<map_session_data *>(session[i]->session_data.get()); + if (pl_sd && pl_sd->state.auth) { // Without case sensitive check (increase the number of similar character names found) if (strncasecmp(pl_sd->status.name, nick, nicklen) == 0) diff --git a/src/map/map.hpp b/src/map/map.hpp index 374282d..7233241 100644 --- a/src/map/map.hpp +++ b/src/map/map.hpp @@ -8,6 +8,7 @@ #include <functional> #include "../common/db.hpp" +#include "../common/socket.hpp" #include "../common/timer.t.hpp" #include "battle.t.hpp" @@ -78,7 +79,7 @@ struct quick_regeneration unsigned char tickdelay; // number of ticks to next update }; -struct map_session_data +struct map_session_data : SessionData { struct block_list bl; struct @@ -143,7 +144,6 @@ struct map_session_data unsigned storage:1; unsigned divorce:1; } npc_flags; - unsigned int chatID; Timer attacktimer; int attacktarget; @@ -476,22 +476,6 @@ struct flooritem_data struct item item_data; }; -struct chat_data -{ - struct block_list bl; - - char pass[8]; /* password */ - char title[61]; /* room title max 60 */ - unsigned char limit; /* join limit */ - unsigned char trigger; - unsigned char users; /* current users */ - unsigned char pub; /* room attribute */ - struct map_session_data *usersd[20]; - struct block_list *owner_; - struct block_list **owner; - char npc_event[50]; -}; - extern interval_t autosave_interval; extern int save_settings; diff --git a/src/map/map.t.hpp b/src/map/map.t.hpp index c57ea06..172572f 100644 --- a/src/map/map.t.hpp +++ b/src/map/map.t.hpp @@ -72,7 +72,6 @@ enum class BL : uint8_t NPC, MOB, ITEM, - CHAT, SPELL, }; enum class NpcSubtype : uint8_t diff --git a/src/map/mob.cpp b/src/map/mob.cpp index be9e71d..8921803 100644 --- a/src/map/mob.cpp +++ b/src/map/mob.cpp @@ -2695,12 +2695,12 @@ int mob_damage(struct block_list *src, struct mob_data *md, int damage, sd = mvp_sd; else { - struct map_session_data *tmp_sd; - int i; - for (i = 0; i < fd_max; i++) + for (int i = 0; i < fd_max; i++) { - if (session[i] && (tmp_sd = (struct map_session_data *)session[i]->session_data) - && tmp_sd->state.auth) + if (!session[i]) + continue; + map_session_data *tmp_sd = static_cast<map_session_data *>(session[i]->session_data.get()); + if (tmp_sd && tmp_sd->state.auth) { if (md->bl.m == tmp_sd->bl.m) { @@ -3060,8 +3060,7 @@ void mobskill_castend_id(TimerData *, tick_t tick, int id) range = skill_get_range(md->skillid, md->skilllv); if (range < 0) range = battle_get_range(&md->bl) - (range + 1); - if (range + battle_config.mob_skill_add_range < - distance(md->bl.x, md->bl.y, bl->x, bl->y)) + if (range + battle_config.mob_skill_add_range < distance(md->bl.x, md->bl.y, bl->x, bl->y)) return; md->skilldelay[md->skillidx] = tick; @@ -3113,8 +3112,7 @@ void mobskill_castend_pos(TimerData *, tick_t tick, int id) range = skill_get_range(md->skillid, md->skilllv); if (range < 0) range = battle_get_range(&md->bl) - (range + 1); - if (range + battle_config.mob_skill_add_range < - distance(md->bl.x, md->bl.y, md->skillx, md->skilly)) + if (range + battle_config.mob_skill_add_range < distance(md->bl.x, md->bl.y, md->skillx, md->skilly)) return; md->skilldelay[md->skillidx] = tick; diff --git a/src/map/npc.cpp b/src/map/npc.cpp index c08a0e7..440d1a1 100644 --- a/src/map/npc.cpp +++ b/src/map/npc.cpp @@ -854,8 +854,7 @@ int npc_selllist(struct map_session_data *sd, int n, return 1; nameid = sd->status.inventory[item_list[i * 2] - 2].nameid; if (nameid == 0 || - sd->status.inventory[item_list[i * 2] - 2].amount < - item_list[i * 2 + 1]) + sd->status.inventory[item_list[i * 2] - 2].amount < item_list[i * 2 + 1]) return 1; if (sd->trade_partner != 0) return 2; // cant sell while trading diff --git a/src/map/party.cpp b/src/map/party.cpp index f737601..594fdf7 100644 --- a/src/map/party.cpp +++ b/src/map/party.cpp @@ -126,14 +126,14 @@ int party_request_info(int party_id) static int party_check_member(struct party *p) { - int i; - struct map_session_data *sd; - nullpo_ret(p); - for (i = 0; i < fd_max; i++) + for (int i = 0; i < fd_max; i++) { - if (session[i] && (sd = (struct map_session_data *)session[i]->session_data) && sd->state.auth) + if (!session[i]) + continue; + map_session_data *sd = static_cast<map_session_data *>(session[i]->session_data.get()); + if (sd && sd->state.auth) { if (sd->status.party_id == p->party_id) { @@ -167,11 +167,12 @@ int party_check_member(struct party *p) // 情報所得失敗(そのIDのキャラを全部未所属にする) int party_recv_noinfo(int party_id) { - int i; - struct map_session_data *sd; - for (i = 0; i < fd_max; i++) + for (int i = 0; i < fd_max; i++) { - if (session[i] && (sd = (struct map_session_data *)session[i]->session_data) && sd->state.auth) + if (!session[i]) + continue; + map_session_data *sd = static_cast<map_session_data *>(session[i]->session_data.get()); + if (sd && sd->state.auth) { if (sd->status.party_id == party_id) sd->status.party_id = 0; diff --git a/src/map/pc.cpp b/src/map/pc.cpp index a098978..2699741 100644 --- a/src/map/pc.cpp +++ b/src/map/pc.cpp @@ -12,7 +12,6 @@ #include "atcommand.hpp" #include "battle.hpp" -#include "chat.hpp" #include "chrif.hpp" #include "clif.hpp" #include "intif.hpp" @@ -217,7 +216,7 @@ earray<EPOS, EQUIP, EQUIP::COUNT> equip_pos //= }}; static -struct gm_account *gm_account = NULL; +struct GM_Account *gm_accounts = NULL; static int GM_num = 0; @@ -242,8 +241,8 @@ int pc_isGM(struct map_session_data *sd) nullpo_ret(sd); for (i = 0; i < GM_num; i++) - if (gm_account[i].account_id == sd->status.account_id) - return gm_account[i].level; + if (gm_accounts[i].account_id == sd->status.account_id) + return gm_accounts[i].level; return 0; } @@ -271,17 +270,17 @@ int pc_set_gm_level(int account_id, int level) int i; for (i = 0; i < GM_num; i++) { - if (account_id == gm_account[i].account_id) + if (account_id == gm_accounts[i].account_id) { - gm_account[i].level = level; + gm_accounts[i].level = level; return 0; } } GM_num++; - RECREATE(gm_account, struct gm_account, GM_num); - gm_account[GM_num - 1].account_id = account_id; - gm_account[GM_num - 1].level = level; + RECREATE(gm_accounts, struct GM_Account, GM_num); + gm_accounts[GM_num - 1].account_id = account_id; + gm_accounts[GM_num - 1].level = level; return 0; } @@ -2360,8 +2359,6 @@ int pc_setpos(struct map_session_data *sd, const char *mapname_org, int x, int y nullpo_ret(sd); - if (sd->chatID) // チャットから出る - chat_leavechat(sd); if (sd->trade_partner) // 取引を中断する trade_tradecancel(sd); if (sd->state.storage_open) @@ -5399,16 +5396,15 @@ void pc_autosave(TimerData *, tick_t) int pc_read_gm_account(int fd) { int i = 0; - if (gm_account != NULL) - free(gm_account); + if (gm_accounts != NULL) + free(gm_accounts); GM_num = 0; - CREATE(gm_account, struct gm_account, (RFIFOW(fd, 2) - 4) / 5); + CREATE(gm_accounts, struct GM_Account, (RFIFOW(fd, 2) - 4) / 5); for (i = 4; i < RFIFOW(fd, 2); i = i + 5) { - gm_account[GM_num].account_id = RFIFOL(fd, i); - gm_account[GM_num].level = (int) RFIFOB(fd, i + 4); - //PRINTF("GM account: %d -> level %d\n", gm_account[GM_num].account_id, gm_account[GM_num].level); + gm_accounts[GM_num].account_id = RFIFOL(fd, i); + gm_accounts[GM_num].level = (int) RFIFOB(fd, i + 4); GM_num++; } return GM_num; diff --git a/src/map/pc.hpp b/src/map/pc.hpp index baf1487..1f2ab71 100644 --- a/src/map/pc.hpp +++ b/src/map/pc.hpp @@ -28,11 +28,6 @@ void pc_setdir(struct map_session_data *sd, DIR b) sd->dir = (b); } inline -void pc_setchatid(struct map_session_data *sd, int n) -{ - sd->chatID = n; -} -inline bool pc_isinvisible(struct map_session_data *sd) { return bool(sd->status.option & Option::HIDE); diff --git a/src/map/script.cpp b/src/map/script.cpp index b5e2aca..43bcebf 100644 --- a/src/map/script.cpp +++ b/src/map/script.cpp @@ -3551,11 +3551,8 @@ void builtin_getmapflag(ScriptState *st) static void builtin_pvpon(ScriptState *st) { - int m, i; - struct map_session_data *pl_sd = NULL; - const char *str = conv_str(st, &(st->stack->stack_data[st->start + 2])); - m = map_mapname2mapid(str); + int m = map_mapname2mapid(str); if (m >= 0 && !map[m].flag.pvp && !map[m].flag.nopvp) { map[m].flag.pvp = 1; @@ -3563,10 +3560,12 @@ void builtin_pvpon(ScriptState *st) if (battle_config.pk_mode) // disable ranking functions if pk_mode is on [Valaris] return; - for (i = 0; i < fd_max; i++) - { //人数分ループ - if (session[i] && (pl_sd = (struct map_session_data *)session[i]->session_data) - && pl_sd->state.auth) + for (int i = 0; i < fd_max; i++) + { + if (!session[i]) + continue; + map_session_data *pl_sd = static_cast<map_session_data *>(session[i]->session_data.get()); + if (pl_sd && pl_sd->state.auth) { if (m == pl_sd->bl.m && !pl_sd->pvp_timer) { @@ -3586,11 +3585,8 @@ void builtin_pvpon(ScriptState *st) static void builtin_pvpoff(ScriptState *st) { - int m, i; - struct map_session_data *pl_sd = NULL; - const char *str = conv_str(st, &(st->stack->stack_data[st->start + 2])); - m = map_mapname2mapid(str); + int m = map_mapname2mapid(str); if (m >= 0 && map[m].flag.pvp && map[m].flag.nopvp) { map[m].flag.pvp = 0; @@ -3598,10 +3594,12 @@ void builtin_pvpoff(ScriptState *st) if (battle_config.pk_mode) // disable ranking options if pk_mode is on [Valaris] return; - for (i = 0; i < fd_max; i++) - { //人数分ループ - if (session[i] && (pl_sd = (struct map_session_data *)session[i]->session_data) - && pl_sd->state.auth) + for (int i = 0; i < fd_max; i++) + { + if (!session[i]) + continue; + map_session_data *pl_sd = static_cast<map_session_data *>(session[i]->session_data.get()); + if (pl_sd && pl_sd->state.auth) { if (m == pl_sd->bl.m) { diff --git a/src/map/skill.cpp b/src/map/skill.cpp index 47a2e5c..31621c8 100644 --- a/src/map/skill.cpp +++ b/src/map/skill.cpp @@ -255,10 +255,6 @@ int skill_attack(BF attack_type, struct block_list *src, return 0; if (bl->type == BL::PC && pc_isdead((struct map_session_data *) bl)) //対象がPCですでに死んでいたら何もしない return 0; - if (src->type == BL::PC && ((struct map_session_data *) src)->chatID) //術者がPCでチャット中なら何もしない - return 0; - if (dsrc->type == BL::PC && ((struct map_session_data *) dsrc)->chatID) //術者がPCでチャット中なら何もしない - return 0; //何もしない判定ここまで |