diff options
author | Ben Longbons <b.r.longbons@gmail.com> | 2013-01-09 00:18:53 -0800 |
---|---|---|
committer | Ben Longbons <b.r.longbons@gmail.com> | 2013-01-09 00:43:27 -0800 |
commit | f0a87e4f7f5377498960429e96be5dff183c8326 (patch) | |
tree | 2661728f73f3c163e971d94cd123ef6e378264aa /src/map | |
parent | f2fd4885c2a906414e0f36acf95d252e5a9d5805 (diff) | |
download | tmwa-f0a87e4f7f5377498960429e96be5dff183c8326.tar.gz tmwa-f0a87e4f7f5377498960429e96be5dff183c8326.tar.bz2 tmwa-f0a87e4f7f5377498960429e96be5dff183c8326.tar.xz tmwa-f0a87e4f7f5377498960429e96be5dff183c8326.zip |
Make incoming packets read-only
Diffstat (limited to 'src/map')
-rw-r--r-- | src/map/atcommand.cpp | 21 | ||||
-rw-r--r-- | src/map/battle.cpp | 2 | ||||
-rw-r--r-- | src/map/chrif.cpp | 4 | ||||
-rw-r--r-- | src/map/clif.cpp | 441 | ||||
-rw-r--r-- | src/map/intif.cpp | 12 | ||||
-rw-r--r-- | src/map/map.cpp | 18 | ||||
-rw-r--r-- | src/map/npc.cpp | 10 | ||||
-rw-r--r-- | src/map/npc.hpp | 4 | ||||
-rw-r--r-- | src/map/party.cpp | 13 | ||||
-rw-r--r-- | src/map/party.hpp | 2 | ||||
-rw-r--r-- | src/map/pc.cpp | 8 | ||||
-rw-r--r-- | src/map/pc.hpp | 2 | ||||
-rw-r--r-- | src/map/script.cpp | 7 |
13 files changed, 271 insertions, 273 deletions
diff --git a/src/map/atcommand.cpp b/src/map/atcommand.cpp index 46c0e9e..3216f91 100644 --- a/src/map/atcommand.cpp +++ b/src/map/atcommand.cpp @@ -37,9 +37,6 @@ #include "tmw.hpp" #include "trade.hpp" -static -char command_symbol = '@'; // first char of the commands (by [Yor]) - #define ATCOMMAND_FUNC(x) static \ int atcommand_##x(const int fd, struct map_session_data* sd, const char* command, const char* message) ATCOMMAND_FUNC(setup); @@ -682,7 +679,7 @@ bool is_atcommand(const int fd, struct map_session_data *sd, AtCommandType atcommand(const int level, const char *message, struct AtCommandInfo * info) { - char *p = (char *) message; // it's 'char' and not 'const char' to have possibility to modify the first character if necessary + const char *p = message; if (!info) return AtCommand_None; @@ -694,7 +691,7 @@ AtCommandType atcommand(const int level, const char *message, return AtCommand_None; } - if (*p == command_symbol) + if (*p == '@') { // check first char. char command[101]; int i = 0; @@ -704,10 +701,9 @@ AtCommandType atcommand(const int level, const char *message, while (atcommand_info[i].type != AtCommand_Unknown) { - if (strcasecmp(command + 1, atcommand_info[i].command + 1) == 0 + if (strcasecmp(command, atcommand_info[i].command) == 0 && level >= atcommand_info[i].level) { - p[0] = atcommand_info[i].command[0]; // set correct first symbol for after. break; } i++; @@ -798,9 +794,6 @@ int atcommand_config_read(const char *cfgName) if (strcasecmp(w1, "import") == 0) atcommand_config_read(w2); - else if (strcasecmp(w1, "command_symbol") == 0 && w2[0] > 31 && w2[0] != '/' && // symbol of standard ragnarok GM commands - w2[0] != '%') // symbol of party chat speaking - command_symbol = w2[0]; } fclose_(fp); @@ -1888,10 +1881,9 @@ int atcommand_item(const int fd, struct map_session_data *sd, item_tmp.nameid = item_id; item_tmp.identify = 1; PickupFail flag; - if ((flag = pc_additem((struct map_session_data *) sd, - &item_tmp, get_count)) + if ((flag = pc_additem(sd, &item_tmp, get_count)) != PickupFail::OKAY) - clif_additem((struct map_session_data *) sd, 0, 0, flag); + clif_additem(sd, 0, 0, flag); } clif_displaymessage(fd, "Item created."); } @@ -2476,8 +2468,7 @@ int atcommand_spawn(const int fd, struct map_session_data *sd, my = sd->bl.y + (MRAND(range) - (range / 2)); else my = y; - k = mob_once_spawn((struct map_session_data *) sd, "this", mx, - my, "", mob_id, 1, ""); + k = mob_once_spawn(sd, "this", mx, my, "", mob_id, 1, ""); } count += (k != 0) ? 1 : 0; } diff --git a/src/map/battle.cpp b/src/map/battle.cpp index 7da685f..93f6fe6 100644 --- a/src/map/battle.cpp +++ b/src/map/battle.cpp @@ -3628,7 +3628,7 @@ struct Damage battle_calc_pc_weapon_attack(struct block_list *src, && sd->inventory_data[index]->type == ItemType::WEAPON) { damage += - (int)(double)(sd->inventory_data[index]->weight * + (int)(sd->inventory_data[index]->weight * (0.8 * skill_lv * 4 / 10)); damage += sd->status.inventory[index].refine * pc_getrefinebonus(0, diff --git a/src/map/chrif.cpp b/src/map/chrif.cpp index 6ab786c..ee8113a 100644 --- a/src/map/chrif.cpp +++ b/src/map/chrif.cpp @@ -667,7 +667,7 @@ int chrif_changedsex(int fd) { if (sd->status.inventory[i].nameid && bool(sd->status.inventory[i].equip)) - pc_unequipitem((struct map_session_data *) sd, i, CalcStatus::NOW); + pc_unequipitem(sd, i, CalcStatus::NOW); } // reset skill of some job if (s_class.job == 19 || s_class.job == 4020 @@ -1129,7 +1129,7 @@ void chrif_parse(int fd) case 0x2afd: pc_authok(RFIFOL(fd, 4), RFIFOL(fd, 8), (time_t) RFIFOL(fd, 12), RFIFOW(fd, 16), - (struct mmo_charstatus *) RFIFOP(fd, 18)); + (const struct mmo_charstatus *) RFIFOP(fd, 18)); break; case 0x2afe: pc_authfail(RFIFOL(fd, 2)); diff --git a/src/map/clif.cpp b/src/map/clif.cpp index edae508..88b3839 100644 --- a/src/map/clif.cpp +++ b/src/map/clif.cpp @@ -128,11 +128,35 @@ enum class SendWho #define SELF SendWho::SELF }; -#define WBUFPOS(p,pos,x,y) { unsigned char *__p = (p); __p+= (pos); __p[0] = (x)>>2; __p[1] = ((x)<<6) | (((y)>>4)&0x3f); __p[2] = (y)<<4; } -#define WBUFPOS2(p,pos,x0,y0,x1,y1) { unsigned char *__p = (p); __p+= (pos); __p[0] = (x0)>>2; __p[1] = ((x0)<<6) | (((y0)>>4)&0x3f); __p[2] = ((y0)<<4) | (((x1)>>6)&0x0f); __p[3]= ((x1)<<2) | (((y1)>>8)&0x03); __p[4]= (y1); } +inline +void WBUFPOS(uint8_t *p, size_t pos, uint16_t x, uint16_t y) +{ + p += pos; + p[0] = x >> 2; + p[1] = (x << 6) | ((y >> 4) & 0x3f); + p[2] = y << 4; +} +inline +void WBUFPOS2(uint8_t *p, size_t pos, uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) +{ + p += pos; + p[0] = x0 >> 2; + p[1] = (x0 << 6) | ((y0 >> 4) & 0x3f); + p[2] = (y0 << 4) | ((x1 >> 6) & 0x0f); + p[3] = (x1 << 2) | ((y1 >> 8) & 0x03); + p[4] = y1; +} -#define WFIFOPOS(fd,pos,x,y) { WBUFPOS(WFIFOP(fd,pos),0,x,y); } -#define WFIFOPOS2(fd,pos,x0,y0,x1,y1) { WBUFPOS2(WFIFOP(fd,pos),0,x0,y0,x1,y1); } +inline +void WFIFOPOS(int fd, size_t pos, uint16_t x, uint16_t y) +{ + WBUFPOS(static_cast<uint8_t *>(WFIFOP(fd, pos)), 0, x, y); +} +inline +void WFIFOPOS2(int fd, size_t pos, uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) +{ + WBUFPOS2(static_cast<uint8_t *>(WFIFOP(fd, pos)), 0, x0, y0, x1, y1); +} static char map_ip_str[16]; @@ -235,7 +259,7 @@ void clif_emotion_towards(struct block_list *bl, static char *clif_validate_chat(struct map_session_data *sd, int type, - char **message, size_t *message_len); + const char **message, size_t *message_len); /*========================================== * clif_sendでAREA*指定時用 @@ -282,7 +306,7 @@ void clif_send_sub(struct block_list *bl, const unsigned char *buf, int len, { PRINTF("WARNING: Invalid use of clif_send function\n"); PRINTF(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n", - WBUFW(buf, 0)); + RBUFW(buf, 0)); PRINTF(" Please correct your code.\n"); // don't send to not move the pointer of the packet for next sessions in the loop } @@ -1603,29 +1627,25 @@ int clif_cutin(struct map_session_data *sd, const char *image, int type) */ int clif_additem(struct map_session_data *sd, int n, int amount, PickupFail fail) { - int fd, j; - unsigned char *buf; - nullpo_ret(sd); - fd = sd->fd; - buf = WFIFOP(fd, 0); + int fd = sd->fd; if (fail != PickupFail::OKAY) { - WBUFW(buf, 0) = 0xa0; - WBUFW(buf, 2) = n + 2; - WBUFW(buf, 4) = amount; - WBUFW(buf, 6) = 0; - WBUFB(buf, 8) = 0; - WBUFB(buf, 9) = 0; - WBUFB(buf, 10) = 0; - WBUFW(buf, 11) = 0; - WBUFW(buf, 13) = 0; - WBUFW(buf, 15) = 0; - WBUFW(buf, 17) = 0; - WBUFW(buf, 19) = 0; - WBUFB(buf, 21) = 0; - WBUFB(buf, 22) = uint8_t(fail); + 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); } else { @@ -1633,56 +1653,57 @@ int clif_additem(struct map_session_data *sd, int n, int amount, PickupFail fail || sd->inventory_data[n] == NULL) return 1; - WBUFW(buf, 0) = 0xa0; - WBUFW(buf, 2) = n + 2; - WBUFW(buf, 4) = amount; + WFIFOW(fd, 0) = 0xa0; + WFIFOW(fd, 2) = n + 2; + WFIFOW(fd, 4) = amount; if (sd->inventory_data[n]->view_id > 0) - WBUFW(buf, 6) = sd->inventory_data[n]->view_id; + WFIFOW(fd, 6) = sd->inventory_data[n]->view_id; else - WBUFW(buf, 6) = sd->status.inventory[n].nameid; - WBUFB(buf, 8) = sd->status.inventory[n].identify; + WFIFOW(fd, 6) = sd->status.inventory[n].nameid; + WFIFOB(fd, 8) = sd->status.inventory[n].identify; if (sd->status.inventory[n].broken == 1) - WBUFB(buf, 9) = 1; // is weapon broken [Valaris] + WFIFOB(fd, 9) = 1; // is weapon broken [Valaris] else - WBUFB(buf, 9) = sd->status.inventory[n].attribute; - WBUFB(buf, 10) = sd->status.inventory[n].refine; + WFIFOB(fd, 9) = sd->status.inventory[n].attribute; + WFIFOB(fd, 10) = sd->status.inventory[n].refine; if (sd->status.inventory[n].card[0] == 0x00ff || sd->status.inventory[n].card[0] == 0x00fe || sd->status.inventory[n].card[0] == (short) 0xff00) { - WBUFW(buf, 11) = sd->status.inventory[n].card[0]; - WBUFW(buf, 13) = sd->status.inventory[n].card[1]; - WBUFW(buf, 15) = sd->status.inventory[n].card[2]; - WBUFW(buf, 17) = sd->status.inventory[n].card[3]; + 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]; } else { + int j; if (sd->status.inventory[n].card[0] > 0 && (j = itemdb_viewid(sd->status.inventory[n].card[0])) > 0) - WBUFW(buf, 11) = j; + WFIFOW(fd, 11) = j; else - WBUFW(buf, 11) = sd->status.inventory[n].card[0]; + WFIFOW(fd, 11) = sd->status.inventory[n].card[0]; if (sd->status.inventory[n].card[1] > 0 && (j = itemdb_viewid(sd->status.inventory[n].card[1])) > 0) - WBUFW(buf, 13) = j; + WFIFOW(fd, 13) = j; else - WBUFW(buf, 13) = sd->status.inventory[n].card[1]; + WFIFOW(fd, 13) = sd->status.inventory[n].card[1]; if (sd->status.inventory[n].card[2] > 0 && (j = itemdb_viewid(sd->status.inventory[n].card[2])) > 0) - WBUFW(buf, 15) = j; + WFIFOW(fd, 15) = j; else - WBUFW(buf, 15) = sd->status.inventory[n].card[2]; + WFIFOW(fd, 15) = sd->status.inventory[n].card[2]; if (sd->status.inventory[n].card[3] > 0 && (j = itemdb_viewid(sd->status.inventory[n].card[3])) > 0) - WBUFW(buf, 17) = j; + WFIFOW(fd, 17) = j; else - WBUFW(buf, 17) = sd->status.inventory[n].card[3]; + WFIFOW(fd, 17) = sd->status.inventory[n].card[3]; } - WBUFW(buf, 19) = uint16_t(pc_equippoint(sd, n)); - WBUFB(buf, 21) = uint8_t(sd->inventory_data[n]->type == ItemType::_7 + WFIFOW(fd, 19) = uint16_t(pc_equippoint(sd, n)); + WFIFOB(fd, 21) = uint8_t(sd->inventory_data[n]->type == ItemType::_7 ? ItemType::WEAPON : sd->inventory_data[n]->type); - WBUFB(buf, 22) = uint8_t(fail); + WFIFOB(fd, 22) = uint8_t(fail); } WFIFOSET(fd, packet_len_table[0xa0]); @@ -1715,45 +1736,43 @@ int clif_delitem(struct map_session_data *sd, int n, int amount) */ int clif_itemlist(struct map_session_data *sd) { - int i, n, fd, arrow = -1; - unsigned char *buf; - nullpo_ret(sd); - fd = sd->fd; - buf = WFIFOP(fd, 0); - WBUFW(buf, 0) = 0x1ee; - for (i = 0, n = 0; i < MAX_INVENTORY; i++) + int n = 0; + int arrow = -1; + int fd = sd->fd; + WFIFOW(fd, 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; - WBUFW(buf, n * 18 + 4) = i + 2; + WFIFOW(fd, n * 18 + 4) = i + 2; if (sd->inventory_data[i]->view_id > 0) - WBUFW(buf, n * 18 + 6) = sd->inventory_data[i]->view_id; + WFIFOW(fd, n * 18 + 6) = sd->inventory_data[i]->view_id; else - WBUFW(buf, n * 18 + 6) = sd->status.inventory[i].nameid; - WBUFB(buf, n * 18 + 8) = uint8_t(sd->inventory_data[i]->type); - WBUFB(buf, n * 18 + 9) = sd->status.inventory[i].identify; - WBUFW(buf, n * 18 + 10) = sd->status.inventory[i].amount; + 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; if (sd->inventory_data[i]->equip == EPOS::ARROW) { - WBUFW(buf, n * 18 + 12) = uint16_t(EPOS::ARROW); + WFIFOW(fd, n * 18 + 12) = uint16_t(EPOS::ARROW); if (bool(sd->status.inventory[i].equip)) arrow = i; // ついでに矢装備チェック } else - WBUFW(buf, n * 18 + 12) = uint16_t(EPOS::ZERO); - WBUFW(buf, n * 18 + 14) = sd->status.inventory[i].card[0]; - WBUFW(buf, n * 18 + 16) = sd->status.inventory[i].card[1]; - WBUFW(buf, n * 18 + 18) = sd->status.inventory[i].card[2]; - WBUFW(buf, n * 18 + 20) = sd->status.inventory[i].card[3]; + 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]; n++; } if (n) { - WBUFW(buf, 2) = 4 + n * 18; + WFIFOW(fd, 2) = 4 + n * 18; WFIFOSET(fd, WFIFOW(fd, 2)); } if (arrow >= 0) @@ -1767,74 +1786,72 @@ int clif_itemlist(struct map_session_data *sd) */ int clif_equiplist(struct map_session_data *sd) { - int i, j, n, fd; - unsigned char *buf; - nullpo_ret(sd); - fd = sd->fd; - buf = WFIFOP(fd, 0); - WBUFW(buf, 0) = 0xa4; - for (i = 0, n = 0; i < MAX_INVENTORY; i++) + int fd = sd->fd; + WFIFOW(fd, 0) = 0xa4; + int n = 0; + 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; - WBUFW(buf, n * 20 + 4) = i + 2; + WFIFOW(fd, n * 20 + 4) = i + 2; if (sd->inventory_data[i]->view_id > 0) - WBUFW(buf, n * 20 + 6) = sd->inventory_data[i]->view_id; + WFIFOW(fd, n * 20 + 6) = sd->inventory_data[i]->view_id; else - WBUFW(buf, n * 20 + 6) = sd->status.inventory[i].nameid; - WBUFB(buf, n * 20 + 8) = uint8_t( + WFIFOW(fd, n * 20 + 6) = sd->status.inventory[i].nameid; + WFIFOB(fd, n * 20 + 8) = uint8_t( sd->inventory_data[i]->type == ItemType::_7 ? ItemType::WEAPON : sd->inventory_data[i]->type); - WBUFB(buf, n * 20 + 9) = sd->status.inventory[i].identify; - WBUFW(buf, n * 20 + 10) = uint16_t(pc_equippoint(sd, i)); - WBUFW(buf, n * 20 + 12) = uint16_t(sd->status.inventory[i].equip); + 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); if (sd->status.inventory[i].broken == 1) - WBUFB(buf, n * 20 + 14) = 1; // is weapon broken [Valaris] + WFIFOB(fd, n * 20 + 14) = 1; // is weapon broken [Valaris] else - WBUFB(buf, n * 20 + 14) = sd->status.inventory[i].attribute; - WBUFB(buf, n * 20 + 15) = sd->status.inventory[i].refine; + WFIFOB(fd, n * 20 + 14) = sd->status.inventory[i].attribute; + WFIFOB(fd, n * 20 + 15) = sd->status.inventory[i].refine; if (sd->status.inventory[i].card[0] == 0x00ff || sd->status.inventory[i].card[0] == 0x00fe || sd->status.inventory[i].card[0] == (short) 0xff00) { - WBUFW(buf, n * 20 + 16) = sd->status.inventory[i].card[0]; - WBUFW(buf, n * 20 + 18) = sd->status.inventory[i].card[1]; - WBUFW(buf, n * 20 + 20) = sd->status.inventory[i].card[2]; - WBUFW(buf, n * 20 + 22) = sd->status.inventory[i].card[3]; + 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]; } else { + int j; if (sd->status.inventory[i].card[0] > 0 && (j = itemdb_viewid(sd->status.inventory[i].card[0])) > 0) - WBUFW(buf, n * 20 + 16) = j; + WFIFOW(fd, n * 20 + 16) = j; else - WBUFW(buf, n * 20 + 16) = sd->status.inventory[i].card[0]; + WFIFOW(fd, n * 20 + 16) = sd->status.inventory[i].card[0]; if (sd->status.inventory[i].card[1] > 0 && (j = itemdb_viewid(sd->status.inventory[i].card[1])) > 0) - WBUFW(buf, n * 20 + 18) = j; + WFIFOW(fd, n * 20 + 18) = j; else - WBUFW(buf, n * 20 + 18) = sd->status.inventory[i].card[1]; + WFIFOW(fd, n * 20 + 18) = sd->status.inventory[i].card[1]; if (sd->status.inventory[i].card[2] > 0 && (j = itemdb_viewid(sd->status.inventory[i].card[2])) > 0) - WBUFW(buf, n * 20 + 20) = j; + WFIFOW(fd, n * 20 + 20) = j; else - WBUFW(buf, n * 20 + 20) = sd->status.inventory[i].card[2]; + WFIFOW(fd, n * 20 + 20) = sd->status.inventory[i].card[2]; if (sd->status.inventory[i].card[3] > 0 && (j = itemdb_viewid(sd->status.inventory[i].card[3])) > 0) - WBUFW(buf, n * 20 + 22) = j; + WFIFOW(fd, n * 20 + 22) = j; else - WBUFW(buf, n * 20 + 22) = sd->status.inventory[i].card[3]; + WFIFOW(fd, n * 20 + 22) = sd->status.inventory[i].card[3]; } n++; } if (n) { - WBUFW(buf, 2) = 4 + n * 20; + WFIFOW(fd, 2) = 4 + n * 20; WFIFOSET(fd, WFIFOW(fd, 2)); } return 0; @@ -1846,42 +1863,40 @@ int clif_equiplist(struct map_session_data *sd) */ int clif_storageitemlist(struct map_session_data *sd, struct storage *stor) { - struct item_data *id; - int i, n, fd; - unsigned char *buf; - nullpo_ret(sd); nullpo_ret(stor); - fd = sd->fd; - buf = WFIFOP(fd, 0); - WBUFW(buf, 0) = 0x1f0; - for (i = 0, n = 0; i < MAX_STORAGE; i++) + int fd = sd->fd; + WFIFOW(fd, 0) = 0x1f0; + int n = 0; + for (int i = 0; i < MAX_STORAGE; i++) { if (stor->storage_[i].nameid <= 0) continue; + + struct item_data *id; nullpo_ret(id = itemdb_search(stor->storage_[i].nameid)); if (itemdb_isequip2(id)) continue; - WBUFW(buf, n * 18 + 4) = i + 1; + WFIFOW(fd, n * 18 + 4) = i + 1; if (id->view_id > 0) - WBUFW(buf, n * 18 + 6) = id->view_id; + WFIFOW(fd, n * 18 + 6) = id->view_id; else - WBUFW(buf, n * 18 + 6) = stor->storage_[i].nameid; - WBUFB(buf, n * 18 + 8) = uint8_t(id->type); - WBUFB(buf, n * 18 + 9) = stor->storage_[i].identify; - WBUFW(buf, n * 18 + 10) = stor->storage_[i].amount; - WBUFW(buf, n * 18 + 12) = 0; - WBUFW(buf, n * 18 + 14) = stor->storage_[i].card[0]; - WBUFW(buf, n * 18 + 16) = stor->storage_[i].card[1]; - WBUFW(buf, n * 18 + 18) = stor->storage_[i].card[2]; - WBUFW(buf, n * 18 + 20) = stor->storage_[i].card[3]; + 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]; n++; } if (n) { - WBUFW(buf, 2) = 4 + n * 18; + WFIFOW(fd, 2) = 4 + n * 18; WFIFOSET(fd, WFIFOW(fd, 2)); } return 0; @@ -1893,74 +1908,73 @@ int clif_storageitemlist(struct map_session_data *sd, struct storage *stor) */ int clif_storageequiplist(struct map_session_data *sd, struct storage *stor) { - struct item_data *id; - int i, j, n, fd; - unsigned char *buf; - nullpo_ret(sd); nullpo_ret(stor); - fd = sd->fd; - buf = WFIFOP(fd, 0); - WBUFW(buf, 0) = 0xa6; - for (i = 0, n = 0; i < MAX_STORAGE; i++) + int fd = sd->fd; + WFIFOW(fd, 0) = 0xa6; + int n = 0; + for (int i = 0; i < MAX_STORAGE; i++) { if (stor->storage_[i].nameid <= 0) continue; + + struct item_data *id; nullpo_ret(id = itemdb_search(stor->storage_[i].nameid)); if (!itemdb_isequip2(id)) continue; - WBUFW(buf, n * 20 + 4) = i + 1; + WFIFOW(fd, n * 20 + 4) = i + 1; if (id->view_id > 0) - WBUFW(buf, n * 20 + 6) = id->view_id; + WFIFOW(fd, n * 20 + 6) = id->view_id; else - WBUFW(buf, n * 20 + 6) = stor->storage_[i].nameid; - WBUFB(buf, n * 20 + 8) = uint8_t(id->type); - WBUFB(buf, n * 20 + 9) = stor->storage_[i].identify; - WBUFW(buf, n * 20 + 10) = uint16_t(id->equip); - WBUFW(buf, n * 20 + 12) = uint16_t(stor->storage_[i].equip); + 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); if (stor->storage_[i].broken == 1) - WBUFB(buf, n * 20 + 14) = 1; //is weapon broken [Valaris] + WFIFOB(fd, n * 20 + 14) = 1; //is weapon broken [Valaris] else - WBUFB(buf, n * 20 + 14) = stor->storage_[i].attribute; - WBUFB(buf, n * 20 + 15) = stor->storage_[i].refine; + WFIFOB(fd, n * 20 + 14) = stor->storage_[i].attribute; + WFIFOB(fd, n * 20 + 15) = stor->storage_[i].refine; if (stor->storage_[i].card[0] == 0x00ff || stor->storage_[i].card[0] == 0x00fe || stor->storage_[i].card[0] == (short) 0xff00) { - WBUFW(buf, n * 20 + 16) = stor->storage_[i].card[0]; - WBUFW(buf, n * 20 + 18) = stor->storage_[i].card[1]; - WBUFW(buf, n * 20 + 20) = stor->storage_[i].card[2]; - WBUFW(buf, n * 20 + 22) = stor->storage_[i].card[3]; + 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]; } else { + int j; if (stor->storage_[i].card[0] > 0 && (j = itemdb_viewid(stor->storage_[i].card[0])) > 0) - WBUFW(buf, n * 20 + 16) = j; + WFIFOW(fd, n * 20 + 16) = j; else - WBUFW(buf, n * 20 + 16) = stor->storage_[i].card[0]; + WFIFOW(fd, n * 20 + 16) = stor->storage_[i].card[0]; if (stor->storage_[i].card[1] > 0 && (j = itemdb_viewid(stor->storage_[i].card[1])) > 0) - WBUFW(buf, n * 20 + 18) = j; + WFIFOW(fd, n * 20 + 18) = j; else - WBUFW(buf, n * 20 + 18) = stor->storage_[i].card[1]; + WFIFOW(fd, n * 20 + 18) = stor->storage_[i].card[1]; if (stor->storage_[i].card[2] > 0 && (j = itemdb_viewid(stor->storage_[i].card[2])) > 0) - WBUFW(buf, n * 20 + 20) = j; + WFIFOW(fd, n * 20 + 20) = j; else - WBUFW(buf, n * 20 + 20) = stor->storage_[i].card[2]; + WFIFOW(fd, n * 20 + 20) = stor->storage_[i].card[2]; if (stor->storage_[i].card[3] > 0 && (j = itemdb_viewid(stor->storage_[i].card[3])) > 0) - WBUFW(buf, n * 20 + 22) = j; + WFIFOW(fd, n * 20 + 22) = j; else - WBUFW(buf, n * 20 + 22) = stor->storage_[i].card[3]; + WFIFOW(fd, n * 20 + 22) = stor->storage_[i].card[3]; } n++; } if (n) { - WBUFW(buf, 2) = 4 + n * 20; + WFIFOW(fd, 2) = 4 + n * 20; WFIFOSET(fd, WFIFOW(fd, 2)); } return 0; @@ -2149,8 +2163,7 @@ int clif_changelook(struct block_list *bl, LOOK type, int val) int clif_changelook_towards(struct block_list *bl, LOOK type, int val, struct map_session_data *dstsd) { - unsigned char rbuf[32]; - unsigned char *buf = dstsd ? WFIFOP(dstsd->fd, 0) : rbuf; // pick target buffer or general-purpose one + unsigned char buf[32]; struct map_session_data *sd = NULL; nullpo_ret(bl); @@ -2240,7 +2253,7 @@ int clif_changelook_towards(struct block_list *bl, LOOK type, int val, WBUFW(buf, 7) = val; WBUFW(buf, 9) = 0; if (dstsd) - WFIFOSET(dstsd->fd, packet_len_table[0x1d7]); + clif_send(buf, packet_len_table[0x1d7], &dstsd->bl, SELF); else clif_send(buf, packet_len_table[0x1d7], bl, AREA); } @@ -2254,44 +2267,40 @@ int clif_changelook_towards(struct block_list *bl, LOOK type, int val, static int clif_initialstatus(struct map_session_data *sd) { - int fd; - unsigned char *buf; - nullpo_ret(sd); - fd = sd->fd; - buf = WFIFOP(fd, 0); - - WBUFW(buf, 0) = 0xbd; - WBUFW(buf, 2) = sd->status.status_point; - - WBUFB(buf, 4) = min(sd->status.attrs[ATTR::STR], 255); - WBUFB(buf, 5) = pc_need_status_point(sd, SP_STR); - WBUFB(buf, 6) = min(sd->status.attrs[ATTR::AGI], 255); - WBUFB(buf, 7) = pc_need_status_point(sd, SP_AGI); - WBUFB(buf, 8) = min(sd->status.attrs[ATTR::VIT], 255); - WBUFB(buf, 9) = pc_need_status_point(sd, SP_VIT); - WBUFB(buf, 10) = min(sd->status.attrs[ATTR::INT], 255); - WBUFB(buf, 11) = pc_need_status_point(sd, SP_INT); - WBUFB(buf, 12) = min(sd->status.attrs[ATTR::DEX], 255); - WBUFB(buf, 13) = pc_need_status_point(sd, SP_DEX); - WBUFB(buf, 14) = min(sd->status.attrs[ATTR::LUK], 255); - WBUFB(buf, 15) = pc_need_status_point(sd, SP_LUK); - - WBUFW(buf, 16) = sd->base_atk + sd->watk; - WBUFW(buf, 18) = sd->watk2; //atk bonus - WBUFW(buf, 20) = sd->matk1; - WBUFW(buf, 22) = sd->matk2; - WBUFW(buf, 24) = sd->def; // def - WBUFW(buf, 26) = sd->def2; - WBUFW(buf, 28) = sd->mdef; // mdef - WBUFW(buf, 30) = sd->mdef2; - WBUFW(buf, 32) = sd->hit; - WBUFW(buf, 34) = sd->flee; - WBUFW(buf, 36) = sd->flee2 / 10; - WBUFW(buf, 38) = sd->critical / 10; - WBUFW(buf, 40) = sd->status.karma; - WBUFW(buf, 42) = sd->status.manner; + 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, packet_len_table[0xbd]); @@ -2862,12 +2871,12 @@ void clif_getareachar_pc(struct map_session_data *sd, if (dstsd->walktimer != -1) { - len = clif_set007b(dstsd, WFIFOP(sd->fd, 0)); + len = clif_set007b(dstsd, static_cast<uint8_t *>(WFIFOP(sd->fd, 0))); WFIFOSET(sd->fd, len); } else { - len = clif_set0078(dstsd, WFIFOP(sd->fd, 0)); + len = clif_set0078(dstsd, static_cast<uint8_t *>(WFIFOP(sd->fd, 0))); WFIFOSET(sd->fd, len); } @@ -2894,7 +2903,7 @@ void clif_getareachar_npc(struct map_session_data *sd, struct npc_data *nd) if (nd->npc_class < 0 || nd->flag & 1 || nd->npc_class == INVISIBLE_CLASS) return; - len = clif_npc0078(nd, WFIFOP(sd->fd, 0)); + len = clif_npc0078(nd, static_cast<uint8_t *>(WFIFOP(sd->fd, 0))); WFIFOSET(sd->fd, len); } @@ -3030,12 +3039,12 @@ void clif_getareachar_mob(struct map_session_data *sd, struct mob_data *md) if (md->state.state == MS_WALK) { - len = clif_mob007b(md, WFIFOP(sd->fd, 0)); + len = clif_mob007b(md, static_cast<uint8_t *>(WFIFOP(sd->fd, 0))); WFIFOSET(sd->fd, len); } else { - len = clif_mob0078(md, WFIFOP(sd->fd, 0)); + len = clif_mob0078(md, static_cast<uint8_t *>(WFIFOP(sd->fd, 0))); WFIFOSET(sd->fd, len); } } @@ -4357,7 +4366,7 @@ void clif_parse_GlobalMessage(int fd, struct map_session_data *sd) size_t message_len = 0; // sometimes uint8_t char *buf = NULL; - char *message = NULL; /* The message text only. */ + const char *message = NULL; /* The message text only. */ nullpo_retv(sd); @@ -4386,9 +4395,9 @@ void clif_parse_GlobalMessage(int fd, struct map_session_data *sd) } /* It's not a spell/magic message, so send the message to others. */ - WBUFW(buf, 0) = 0x8d; - WBUFW(buf, 2) = msg_len + 8; /* Header(2) + length(2) + ID(4). */ - WBUFL(buf, 4) = sd->bl.id; + WBUFW(reinterpret_cast<uint8_t *>(buf), 0) = 0x8d; + WBUFW(reinterpret_cast<uint8_t *>(buf), 2) = msg_len + 8; /* Header(2) + length(2) + ID(4). */ + WBUFL(reinterpret_cast<uint8_t *>(buf), 4) = sd->bl.id; // evil multiuse buffer! clif_send((const uint8_t *)buf, msg_len + 8, &sd->bl, @@ -4622,7 +4631,7 @@ void clif_parse_Wis(int fd, struct map_session_data *sd) { size_t message_len = 0; char *buf = NULL; - char *message = NULL; /* The message text only. */ + const char *message = NULL; /* The message text only. */ struct map_session_data *dstsd = NULL; nullpo_retv(sd); @@ -4844,12 +4853,13 @@ void clif_parse_EquipItem(int fd, struct map_session_data *sd) //ペット用装備であるかないか if (sd->inventory_data[index]) { + EPOS epos = EPOS(RFIFOW(fd, 4)); if (sd->inventory_data[index]->type == ItemType::ARROW) // 矢を無理やり装備できるように(−−; - RFIFOW(fd, 4) = uint16_t(EPOS::ARROW); + epos = EPOS::ARROW; // Note: the EPOS argument to pc_equipitem is actually ignored - pc_equipitem(sd, index, EPOS(RFIFOW(fd, 4))); + pc_equipitem(sd, index, epos); } } @@ -4920,13 +4930,11 @@ void clif_parse_NpcBuySellSelected(int fd, struct map_session_data *sd) static void clif_parse_NpcBuyListSend(int fd, struct map_session_data *sd) { - int fail = 0, n; - unsigned short *item_list; + int n = (RFIFOW(fd, 2) - 4) / 4; + // really an array of pairs of uint16_t + const uint16_t *item_list = static_cast<const uint16_t *>(RFIFOP(fd, 4)); - n = (RFIFOW(fd, 2) - 4) / 4; - item_list = (unsigned short *) RFIFOP(fd, 4); - - fail = npc_buylist(sd, n, item_list); + int fail = npc_buylist(sd, n, item_list); WFIFOW(fd, 0) = 0xca; WFIFOB(fd, 2) = fail; @@ -4940,13 +4948,11 @@ void clif_parse_NpcBuyListSend(int fd, struct map_session_data *sd) static void clif_parse_NpcSellListSend(int fd, struct map_session_data *sd) { - int fail = 0, n; - unsigned short *item_list; - - n = (RFIFOW(fd, 2) - 4) / 4; - item_list = (unsigned short *) RFIFOP(fd, 4); + int n = (RFIFOW(fd, 2) - 4) / 4; + // really an array of pairs of uint16_t + const uint16_t *item_list = static_cast<const uint16_t *>(RFIFOP(fd, 4)); - fail = npc_selllist(sd, n, item_list); + int fail = npc_selllist(sd, n, item_list); WFIFOW(fd, 0) = 0xcb; WFIFOB(fd, 2) = fail; @@ -5469,7 +5475,7 @@ void clif_parse_PartyMessage(int fd, struct map_session_data *sd) { size_t message_len = 0; char *buf = NULL; - char *message = NULL; /* The message text only. */ + const char *message = NULL; /* The message text only. */ nullpo_retv(sd); @@ -6205,7 +6211,7 @@ int clif_check_packet_flood(int fd, int cmd) */ static char *clif_validate_chat(struct map_session_data *sd, int type, - char **message, size_t *message_len) + const char **message, size_t *message_len) { int fd; unsigned int buf_len; /* Actual message length. */ @@ -6213,7 +6219,6 @@ char *clif_validate_chat(struct map_session_data *sd, int type, unsigned int min_len; /* Minimum message length. */ size_t name_len; /* Sender's name length. */ char *buf = NULL; /* Copy of actual message data. */ - char *p = NULL; /* Temporary pointer to message. */ *message = NULL; *message_len = 0; @@ -6264,7 +6269,7 @@ char *clif_validate_chat(struct map_session_data *sd, int type, return NULL; } - p = (char *)((type != 1) ? RFIFOP(fd, 4) : RFIFOP(fd, 28)); + const char *p = static_cast<const char *>((type != 1) ? RFIFOP(fd, 4) : RFIFOP(fd, 28)); buf_len = (type == 1) ? msg_len - min_len: msg_len; /* @@ -6297,7 +6302,7 @@ char *clif_validate_chat(struct map_session_data *sd, int type, } else { - char *pos = NULL; + const char *pos = NULL; if (!(pos = strstr(p, " : ")) || strncmp(p, sd->status.name, name_len) || pos - p != name_len) diff --git a/src/map/intif.cpp b/src/map/intif.cpp index bb27643..9d44200 100644 --- a/src/map/intif.cpp +++ b/src/map/intif.cpp @@ -288,8 +288,10 @@ int intif_parse_WisMessage(int fd) if (battle_config.etc_log) PRINTF("intif_parse_wismessage: id: %d, from: %s, to: %s, message: '%s'\n", - RFIFOL(fd, 4), RFIFOP(fd, 8), RFIFOP(fd, 32), RFIFOP(fd, - 56)); + RFIFOL(fd, 4), + static_cast<const char *>(RFIFOP(fd, 8)), + static_cast<const char *>(RFIFOP(fd, 32)), + static_cast<const char *>(RFIFOP(fd, 56))); sd = map_nick2sd((const char *)RFIFOP(fd, 32)); // Searching destination player if (sd != NULL && strcmp(sd->status.name, (const char *)RFIFOP(fd, 32)) == 0) { // exactly same name (inter-server have checked the name before) @@ -328,7 +330,9 @@ int intif_parse_WisEnd(int fd) struct map_session_data *sd; if (battle_config.etc_log) - PRINTF("intif_parse_wisend: player: %s, flag: %d\n", RFIFOP(fd, 2), RFIFOB(fd, 26)); // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target + // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target + PRINTF("intif_parse_wisend: player: %s, flag: %d\n", + static_cast<const char *>(RFIFOP(fd, 2)), RFIFOB(fd, 26)); sd = map_nick2sd((const char *)RFIFOP(fd, 2)); if (sd != NULL) clif_wis_end(sd->fd, RFIFOB(fd, 26)); @@ -484,7 +488,7 @@ int intif_parse_PartyInfo(int fd) RFIFOL(fd, 4), RFIFOW(fd, 2), sizeof(struct party) + 4); } - party_recv_info((struct party *) RFIFOP(fd, 4)); + party_recv_info(static_cast<const struct party *>(RFIFOP(fd, 4))); return 0; } diff --git a/src/map/map.cpp b/src/map/map.cpp index 8732186..4e6cb66 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -1795,25 +1795,15 @@ void map_log(const_string line) if (!map_logfile) return; - struct timeval tv; - gettimeofday(&tv, NULL); + time_t t = time(NULL); - if ((tv.tv_sec >> LOGFILE_SECONDS_PER_CHUNK_SHIFT) != map_logfile_index) + if ((t >> LOGFILE_SECONDS_PER_CHUNK_SHIFT) != map_logfile_index) { map_close_logfile(); - map_start_logfile(tv.tv_sec); - } - - if (!line) - { - fputc('\n', map_logfile); - return; + map_start_logfile(t); } - FPRINTF(map_logfile, "%ld.%06ld ", (long) tv.tv_sec, (long) tv.tv_usec); - fwrite(line.data(), 1, line.size(), map_logfile); - if (line.back() != '\n') - fputc('\n', map_logfile); + log_with_timestamp(map_logfile, line); } /*========================================== diff --git a/src/map/npc.cpp b/src/map/npc.cpp index 0e406c2..df75216 100644 --- a/src/map/npc.cpp +++ b/src/map/npc.cpp @@ -363,7 +363,7 @@ void npc_do_ontimer_sub(db_key_t key, db_val_t data, int *c, int option) char temp[10]; char event[50]; - if (ev->nd->bl.id == (int) *c && (p = strchr(p, ':')) && p + if (ev->nd->bl.id == *c && (p = strchr(p, ':')) && p && strncasecmp("::OnTimer", p, 8) == 0) { sscanf(&p[9], "%s", temp); @@ -851,7 +851,7 @@ int npc_buysellsel(struct map_session_data *sd, int id, int type) *------------------------------------------ */ int npc_buylist(struct map_session_data *sd, int n, - unsigned short *item_list) + const uint16_t *item_list) { struct npc_data *nd; double z; @@ -969,7 +969,7 @@ int npc_buylist(struct map_session_data *sd, int n, *------------------------------------------ */ int npc_selllist(struct map_session_data *sd, int n, - unsigned short *item_list) + const uint16_t *item_list) { double z; int i, skill, itemamount = 0; @@ -1700,7 +1700,9 @@ int npc_parse_function(char *, char *, char *w3, char *, p = (char *) calloc(50, sizeof(char)); strncpy(p, w3, 49); - strdb_insert(script_get_userfunc_db(), p, script); + // db_val_t takes a void *, we do restore safely ... + ScriptCode *script_ = const_cast<ScriptCode *>(script); + strdb_insert(script_get_userfunc_db(), p, script_); // label_db=script_get_label_db(); diff --git a/src/map/npc.hpp b/src/map/npc.hpp index fba0ec0..52758d4 100644 --- a/src/map/npc.hpp +++ b/src/map/npc.hpp @@ -17,8 +17,8 @@ int npc_touch_areanpc(struct map_session_data *, int, int, int); int npc_click(struct map_session_data *, int); int npc_scriptcont(struct map_session_data *, int); int npc_buysellsel(struct map_session_data *, int, int); -int npc_buylist(struct map_session_data *, int, unsigned short *); -int npc_selllist(struct map_session_data *, int, unsigned short *); +int npc_buylist(struct map_session_data *, int, const uint16_t *); +int npc_selllist(struct map_session_data *, int, const uint16_t *); int npc_parse_warp(const char *w1, const char *w2, const char *w3, const char *w4); int npc_enable(const char *name, int flag); diff --git a/src/map/party.cpp b/src/map/party.cpp index 9b9470c..98bb2be 100644 --- a/src/map/party.cpp +++ b/src/map/party.cpp @@ -145,7 +145,10 @@ int party_check_member(struct party *p) if (strcmp(p->member[j].name, sd->status.name) == 0) f = 0; // データがある else - p->member[j].sd = NULL; // 同垢別キャラだった + { + // I can prove it was already zeroed + // p->member[j].sd = NULL; // 同垢別キャラだった + } } } if (f) @@ -178,7 +181,7 @@ int party_recv_noinfo(int party_id) } // 情報所得 -int party_recv_info(struct party *sp) +int party_recv_info(const struct party *sp) { struct party *p; int i; @@ -191,9 +194,11 @@ int party_recv_info(struct party *sp) numdb_insert(party_db, sp->party_id, p); // 最初のロードなのでユーザーのチェックを行う - party_check_member(sp); + *p = *sp; + party_check_member(p); } - memcpy(p, sp, sizeof(struct party)); + else + *p = *sp; for (i = 0; i < MAX_PARTY; i++) { // sdの設定 diff --git a/src/map/party.hpp b/src/map/party.hpp index ecb0cc4..8dfd9b5 100644 --- a/src/map/party.hpp +++ b/src/map/party.hpp @@ -23,7 +23,7 @@ int party_member_leaved(int party_id, int account_id, const char *name); int party_reply_invite(struct map_session_data *sd, int account_id, int flag); int party_recv_noinfo(int party_id); -int party_recv_info(struct party *sp); +int party_recv_info(const struct party *sp); int party_recv_movemap(int party_id, int account_id, const char *map, int online, int lv); int party_broken(int party_id); diff --git a/src/map/pc.cpp b/src/map/pc.cpp index 2c8a4e7..68dc50b 100644 --- a/src/map/pc.cpp +++ b/src/map/pc.cpp @@ -217,7 +217,7 @@ void pc_invincible_timer(timer_id tid, tick_t, custom_id_t id, custom_data_t) { struct map_session_data *sd; - if ((sd = (struct map_session_data *) map_id2sd(id)) == NULL + if ((sd = map_id2sd(id)) == NULL || sd->bl.type != BL_PC) return; @@ -259,7 +259,7 @@ void pc_spiritball_timer(timer_id tid, tick_t, custom_id_t id, custom_data_t) struct map_session_data *sd; int i; - if ((sd = (struct map_session_data *) map_id2sd(id)) == NULL + if ((sd = map_id2sd(id)) == NULL || sd->bl.type != BL_PC) return; @@ -781,7 +781,7 @@ int pc_breakarmor(struct map_session_data *sd) *------------------------------------------ */ int pc_authok(int id, int login_id2, time_t connect_until_time, - short tmw_version, struct mmo_charstatus *st) + short tmw_version, const struct mmo_charstatus *st) { struct map_session_data *sd = NULL; @@ -6883,7 +6883,7 @@ int pc_equipitem(struct map_session_data *sd, int n, EPOS) return 0; } - if (bool(pos == (EPOS::MISC2 | EPOS::CAPE))) + if (pos == (EPOS::MISC2 | EPOS::CAPE)) { // アクセサリ用例外処理 EPOS epor = EPOS::ZERO; diff --git a/src/map/pc.hpp b/src/map/pc.hpp index 97163b1..6f0c4e8 100644 --- a/src/map/pc.hpp +++ b/src/map/pc.hpp @@ -75,7 +75,7 @@ int pc_counttargeted(struct map_session_data *sd, struct block_list *src, int pc_setrestartvalue(struct map_session_data *sd, int type); int pc_makesavestatus(struct map_session_data *); int pc_setnewpc(struct map_session_data *, int, int, int, int, int, int); -int pc_authok(int, int, time_t, short tmw_version, struct mmo_charstatus *); +int pc_authok(int, int, time_t, short tmw_version, const struct mmo_charstatus *); int pc_authfail(int); EPOS pc_equippoint(struct map_session_data *sd, int n); diff --git a/src/map/script.cpp b/src/map/script.cpp index eca91e6..a82cd66 100644 --- a/src/map/script.cpp +++ b/src/map/script.cpp @@ -941,7 +941,7 @@ const ScriptCode *parse_script(const char *src, int line) exit(1); } set_label(l, script_pos); - strdb_insert(scriptlabel_db, (const char*)p, script_pos); // 外部用label db登録 + strdb_insert(scriptlabel_db, p, script_pos); // 外部用label db登録 *tmpp = c; p = tmpp + 1; continue; @@ -1373,7 +1373,8 @@ void builtin_callfunc(ScriptState *st) const ScriptCode *scr; const char *str = conv_str(st, &(st->stack->stack_data[st->start + 2])); - if ((scr = (const ScriptCode *)strdb_search(script_get_userfunc_db(), str))) + // note: strdb_search returns a void *; but ScriptCode is really const + if ((scr = static_cast<const ScriptCode *>(strdb_search(script_get_userfunc_db(), str)))) { int j = 0; #if 0 @@ -5082,7 +5083,7 @@ void mapregstr_db_final(db_key_t, db_val_t data) static void userfunc_db_final(db_key_t key, db_val_t data) { - free((char*)key.s); + free(key.ms); free(data); } |