diff options
author | Ben Longbons <b.r.longbons@gmail.com> | 2013-06-22 22:30:13 -0700 |
---|---|---|
committer | Ben Longbons <b.r.longbons@gmail.com> | 2013-06-23 22:07:50 -0700 |
commit | dbbfda0e96037da4f208ff8f00d181a5294484ae (patch) | |
tree | 7a7b9982c6d98ddc2271aade72040ea9233a4a11 /src/map | |
parent | 83db3bbee4e19e7426a32ee89ad6c2d8e48260f2 (diff) | |
download | tmwa-dbbfda0e96037da4f208ff8f00d181a5294484ae.tar.gz tmwa-dbbfda0e96037da4f208ff8f00d181a5294484ae.tar.bz2 tmwa-dbbfda0e96037da4f208ff8f00d181a5294484ae.tar.xz tmwa-dbbfda0e96037da4f208ff8f00d181a5294484ae.zip |
add new stuff stuff (with tests!), poison memcmp and strncpy
Diffstat (limited to 'src/map')
-rw-r--r-- | src/map/atcommand.cpp | 43 | ||||
-rw-r--r-- | src/map/chrif.cpp | 41 | ||||
-rw-r--r-- | src/map/clif.cpp | 93 | ||||
-rw-r--r-- | src/map/clif.hpp | 5 | ||||
-rw-r--r-- | src/map/intif.cpp | 52 | ||||
-rw-r--r-- | src/map/magic-interpreter-base.cpp | 2 | ||||
-rw-r--r-- | src/map/magic-interpreter-lexer.lpp | 14 | ||||
-rw-r--r-- | src/map/map.hpp | 2 | ||||
-rw-r--r-- | src/map/mob.cpp | 3 | ||||
-rw-r--r-- | src/map/npc.cpp | 9 | ||||
-rw-r--r-- | src/map/party.cpp | 3 | ||||
-rw-r--r-- | src/map/pc.cpp | 25 | ||||
-rw-r--r-- | src/map/script.cpp | 4 | ||||
-rw-r--r-- | src/map/tmw.cpp | 2 |
14 files changed, 149 insertions, 149 deletions
diff --git a/src/map/atcommand.cpp b/src/map/atcommand.cpp index 8e29f86..f893c2e 100644 --- a/src/map/atcommand.cpp +++ b/src/map/atcommand.cpp @@ -4,6 +4,8 @@ #include <cstring> #include <ctime> +#include <fstream> + #include "../common/core.hpp" #include "../common/cxxstdio.hpp" #include "../common/mmo.hpp" @@ -432,14 +434,15 @@ bool is_atcommand(const int fd, dumb_ptr<map_session_data> sd, } { - char command[100] {}; const char *str = message; const char *p = message; + // split the first word while (*p && !isspace(*p)) p++; - if (p - str >= sizeof(command)) // too long - return true; - strncpy(command, str, p - str); + size_t len = p - str; + char command[len + 1]; + strzcpy(command, str, len + 1); + // skip the spaces; pass as argv while (isspace(*p)) p++; @@ -447,7 +450,8 @@ bool is_atcommand(const int fd, dumb_ptr<map_session_data> sd, if (info->proc(fd, sd, command, p) != 0) { // Command can not be executed - std::string output = STRPRINTF("%s failed.", command); + const char *command_ = command; + std::string output = STRPRINTF("%s failed.", command_); clif_displaymessage(fd, output); } else @@ -1773,33 +1777,20 @@ int atcommand_joblevelup(const int fd, dumb_ptr<map_session_data> sd, int atcommand_help(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *) { - char buf[2048] {}; - int i, gm_level; - FILE *fp; - - if ((fp = fopen_(help_txt, "r")) != NULL) + std::ifstream in(help_txt); + if (in.is_open()) { clif_displaymessage(fd, "Help commands:"); - gm_level = pc_isGM(sd); - while (fgets(buf, sizeof(buf) - 1, fp) != NULL) + int gm_level = pc_isGM(sd); + std::string line; + while (std::getline(in, line)) { - if (buf[0] == '/' && buf[1] == '/') + std::string w1, w2; + if (!split_key_value(line, &w1, &w2)) continue; - for (i = 0; buf[i] != '\0'; i++) - { - if (buf[i] == '\r' || buf[i] == '\n') - { - buf[i] = '\0'; - break; - } - } - char w1[2048], w2[2048]; - if (sscanf(buf, "%2047[^:]:%2047[^\n]", w1, w2) < 2) - clif_displaymessage(fd, buf); - else if (gm_level >= atoi(w1)) + if (gm_level >= atoi(w1.c_str())) clif_displaymessage(fd, w2); } - fclose_(fp); } else { diff --git a/src/map/chrif.cpp b/src/map/chrif.cpp index f2d5ec7..a1e0f55 100644 --- a/src/map/chrif.cpp +++ b/src/map/chrif.cpp @@ -22,7 +22,8 @@ #include "../poison.hpp" static -const int packet_len_table[0x20] = { +const int packet_len_table[0x20] = +{ 60, 3, 10, 27, 22, -1, 6, -1, // 2af8-2aff 6, -1, 18, 7, -1, 49, 44, 0, // 2b00-2b07 6, 30, -1, 10, 86, 7, 44, 34, // 2b08-2b0f @@ -179,9 +180,9 @@ int chrif_recvmap(int fd) port = RFIFOW(fd, 8); for (i = 10, j = 0; i < RFIFOW(fd, 2); i += 16, j++) { - map_setipport(static_cast<const char *>(RFIFOP(fd, i)), ip, port); -// if (battle_config.etc_log) -// PRINTF("recv map %d %s\n", j, RFIFOP(fd,i)); + char map[16]; + RFIFO_STRING(fd, i, map, 16); + map_setipport(map, ip, port); } if (battle_config.etc_log) PRINTF("recv map on %s:%d (%d maps)\n", ip2str(ip), port, j); @@ -244,8 +245,13 @@ int chrif_changemapserverack(int fd) pc_authfail(sd->fd); return 0; } - clif_changemapserver(sd, static_cast<const char *>(RFIFOP(fd, 18)), RFIFOW(fd, 34), - RFIFOW(fd, 36), in_addr{RFIFOL(fd, 38)}, RFIFOW(fd, 42)); + char mapname[16]; + RFIFO_STRING(fd, 18, mapname, 16); + uint16_t x = RFIFOW(fd, 34); + uint16_t y = RFIFOW(fd, 36); + auto ip = in_addr{RFIFOL(fd, 38)}; + uint16_t port = RFIFOW(fd, 42); + clif_changemapserver(sd, mapname, x, y, ip, port); return 0; } @@ -887,7 +893,7 @@ int chrif_accountban(int fd) TimeT timestamp = static_cast<time_t>(RFIFOL(fd, 7)); // status or final date of a banishment char tmpstr[] = WITH_TIMESTAMP("Your account has been banished until "); REPLACE_TIMESTAMP(tmpstr, timestamp); - clif_displaymessage(sd->fd, tmpstr); + clif_displaymessage(sd->fd, const_(tmpstr)); } clif_setwaitclose(sd->fd); // forced to disconnect for the change } @@ -1097,9 +1103,17 @@ void chrif_parse(int fd) chrif_sendmapack(fd); break; case 0x2afd: - pc_authok(RFIFOL(fd, 4), RFIFOL(fd, 8), - static_cast<time_t>(RFIFOL(fd, 12)), RFIFOW(fd, 16), - static_cast<const struct mmo_charstatus *>(RFIFOP(fd, 18))); + { + int id = RFIFOL(fd, 4); + int login_id2 = RFIFOL(fd, 8); + TimeT connect_until_time = static_cast<time_t>(RFIFOL(fd, 12)); + short tmw_version = RFIFOW(fd, 16); + struct mmo_charstatus st {}; + RFIFO_STRUCT(fd, 18, st); + pc_authok(id, login_id2, + connect_until_time, tmw_version, + &st); + } break; case 0x2afe: pc_authfail(RFIFOL(fd, 2)); @@ -1117,7 +1131,12 @@ void chrif_parse(int fd) chrif_changemapserverack(fd); break; case 0x2b09: - map_addchariddb(RFIFOL(fd, 2), static_cast<const char *>(RFIFOP(fd, 6))); + { + int charid = RFIFOL(fd, 2); + char name[24]; + RFIFO_STRING(fd, 6, name, 24); + map_addchariddb(charid, name); + } break; case 0x2b0b: chrif_changedgm(fd); diff --git a/src/map/clif.cpp b/src/map/clif.cpp index c37916b..fab8932 100644 --- a/src/map/clif.cpp +++ b/src/map/clif.cpp @@ -248,15 +248,6 @@ void clif_send_sub(dumb_ptr<block_list> bl, const unsigned char *buf, int len, if (session[sd->fd] != NULL) { - if (WFIFOP(sd->fd, 0) == buf) - { - PRINTF("WARNING: Invalid use of clif_send function\n"); - PRINTF(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n", - 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 - } - else { if (clif_parse_func_table[RBUFW(buf, 0)].len) { @@ -1261,15 +1252,15 @@ int clif_selllist(dumb_ptr<map_session_data> sd) */ int clif_scriptmes(dumb_ptr<map_session_data> sd, int npcid, const char *mes) { - int fd; - nullpo_ret(sd); - fd = sd->fd; + int fd = sd->fd; + + size_t len = strlen(mes) + 1; WFIFOW(fd, 0) = 0xb4; - WFIFOW(fd, 2) = strlen(mes) + 9; + WFIFOW(fd, 2) = len + 8; WFIFOL(fd, 4) = npcid; - strcpy(static_cast<char *>(WFIFOP(fd, 8)), mes); + WFIFO_STRING(fd, 8, mes, len); WFIFOSET(fd, WFIFOW(fd, 2)); return 0; @@ -1317,15 +1308,14 @@ int clif_scriptclose(dumb_ptr<map_session_data> sd, int npcid) */ int clif_scriptmenu(dumb_ptr<map_session_data> sd, int npcid, const char *mes) { - int fd; - nullpo_ret(sd); - fd = sd->fd; + int fd = sd->fd; + size_t len = strlen(mes) + 1; WFIFOW(fd, 0) = 0xb7; - WFIFOW(fd, 2) = strlen(mes) + 8; + WFIFOW(fd, 2) = len + 8; WFIFOL(fd, 4) = npcid; - strcpy(static_cast<char *>(WFIFOP(fd, 8)), mes); + WFIFO_STRING(fd, 8, mes, len); WFIFOSET(fd, WFIFOW(fd, 2)); return 0; @@ -2275,13 +2265,11 @@ int clif_useitemack(dumb_ptr<map_session_data> sd, int index, int amount, */ int clif_traderequest(dumb_ptr<map_session_data> sd, const char *name) { - int fd; - nullpo_ret(sd); - fd = sd->fd; + int fd = sd->fd; WFIFOW(fd, 0) = 0xe5; - strcpy(static_cast<char *>(WFIFOP(fd, 2)), name); + WFIFO_STRING(fd, 2, name, 24); WFIFOSET(fd, clif_parse_func_table[0xe5].len); return 0; @@ -2608,16 +2596,17 @@ void clif_getareachar_pc(dumb_ptr<map_session_data> sd, nullpo_retv(sd); nullpo_retv(dstsd); + uint8_t buf[256]; if (dstsd->walktimer) { - len = clif_set007b(dstsd, static_cast<uint8_t *>(WFIFOP(sd->fd, 0))); - WFIFOSET(sd->fd, len); + len = clif_set007b(dstsd, buf); } else { - len = clif_set0078(dstsd, static_cast<uint8_t *>(WFIFOP(sd->fd, 0))); - WFIFOSET(sd->fd, len); + len = clif_set0078(dstsd, buf); } + WFIFO_BUF_CLONE(sd->fd, buf, len); + WFIFOSET(sd->fd, len); if (battle_config.save_clothcolor == 1 && dstsd->status.clothes_color > 0) clif_changelook(dstsd, LOOK::CLOTHES_COLOR, @@ -3137,7 +3126,7 @@ int clif_status_change(dumb_ptr<block_list> bl, StatusChange type, int flag) * Send message (modified by [Yor]) *------------------------------------------ */ -void clif_displaymessage(int fd, const_string mes) +void clif_displaymessage(int fd, ZString mes) { if (mes) { @@ -3145,7 +3134,7 @@ void clif_displaymessage(int fd, const_string mes) WFIFOW(fd, 0) = 0x8e; size_t str_len = mes.size() + 1; // NUL (might not be NUL yet) WFIFOW(fd, 2) = 4 + str_len; - WFIFO_STRING(fd, 4, mes.data(), str_len); + WFIFO_STRING(fd, 4, mes.c_str(), str_len); WFIFOSET(fd, 4 + str_len); } } @@ -3154,14 +3143,14 @@ void clif_displaymessage(int fd, const_string mes) * 天の声を送信する *------------------------------------------ */ -void clif_GMmessage(dumb_ptr<block_list> bl, const_string mes, int flag) +void clif_GMmessage(dumb_ptr<block_list> bl, ZString mes, int flag) { size_t str_len = mes.size() + 1; unsigned char buf[str_len + 4]; WBUFW(buf, 0) = 0x9a; WBUFW(buf, 2) = str_len + 4; - WBUF_STRING(buf, 4, mes.data(), str_len); + WBUF_STRING(buf, 4, mes.c_str(), str_len); flag &= 0x07; clif_send(buf, WBUFW(buf, 2), bl, (flag == 1) ? SendWho::ALL_SAMEMAP : @@ -4689,16 +4678,9 @@ void clif_parse_NpcStringInput(int fd, dumb_ptr<map_session_data> sd) */ if (len < 0) return; - - if (len >= sizeof(sd->npc_str) - 1) - { - PRINTF("clif_parse_NpcStringInput(): Input string too long!\n"); - len = sizeof(sd->npc_str) - 1; - } - - if (len > 0) - strncpy(sd->npc_str, static_cast<const char *>(RFIFOP(fd, 8)), len); - sd->npc_str[len] = '\0'; + char buf[len]; + RFIFO_STRING(fd, 8, buf, len); + sd->npc_str = buf; map_scriptcont(sd, RFIFOL(fd, 4)); } @@ -4783,7 +4765,9 @@ void clif_parse_CreateParty(int fd, dumb_ptr<map_session_data> sd) if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, SkillID::NV_PARTY) >= 2) { - party_create(sd, static_cast<const char *>(RFIFOP(fd, 2))); + char name[24]; + RFIFO_STRING(fd, 2, name, 24); + party_create(sd, name); } else clif_skill_fail(sd, SkillID::ONE, 0, 4); @@ -4841,7 +4825,10 @@ void clif_parse_LeaveParty(int, dumb_ptr<map_session_data> sd) static void clif_parse_RemovePartyMember(int fd, dumb_ptr<map_session_data> sd) { - party_removemember(sd, RFIFOL(fd, 2), static_cast<const char *>(RFIFOP(fd, 6))); + int account_id = RFIFOL(fd, 2); + char name[24]; + RFIFO_STRING(fd, 6, name, 24); + party_removemember(sd, account_id, name); } /*========================================== @@ -5584,14 +5571,16 @@ std::string clif_validate_chat(dumb_ptr<map_session_data> sd, ChatType type) return std::string(); } - const char *p = static_cast<const char *>(RFIFOP(fd, 4)); + size_t pstart = 4; size_t buf_len = msg_len; if (type == ChatType::Whisper) { - p += 24; + pstart += 24; buf_len -= 24; } - const char *pend = p + buf_len; + char pbuf[buf_len + 1]; + // I had to change strzcpy for this :( + RFIFO_STRING(fd, pstart, pbuf, buf_len + 1); /* * The client attempted to exceed the maximum message length. @@ -5608,8 +5597,8 @@ std::string clif_validate_chat(dumb_ptr<map_session_data> sd, ChatType type) if (type == ChatType::Global) { - const char *pos = strstr(p, " : "); - if (!pos || pos != p + name_len || memcmp(p, sd->status.name, name_len)) + XString p = ZString(ZString::really_construct_from_a_pointer, pbuf); + if (!(p.startswith(const_(sd->status.name)) && p.xslice_t(name_len).startswith(" : "))) { /* Disallow malformed/spoofed messages. */ clif_setwaitclose(fd); @@ -5617,12 +5606,10 @@ std::string clif_validate_chat(dumb_ptr<map_session_data> sd, ChatType type) return std::string(); } /* Step beyond the separator. */ - p = pos + 3; + XString xs = p.xslice_t(name_len + 3); + return std::string(xs.begin(), xs.end()); } - - std::string buf(p, pend); - - return buf; + return pbuf; } /*========================================== diff --git a/src/map/clif.hpp b/src/map/clif.hpp index 5d48bc5..b9e2233 100644 --- a/src/map/clif.hpp +++ b/src/map/clif.hpp @@ -6,6 +6,7 @@ #include <functional> #include "../common/const_array.hpp" +#include "../common/strings.hpp" #include "../common/timer.t.hpp" #include "battle.t.hpp" @@ -146,8 +147,8 @@ int clif_party_xy(struct party *p, dumb_ptr<map_session_data> sd); int clif_party_hp(struct party *p, dumb_ptr<map_session_data> sd); // atcommand -void clif_displaymessage(int fd, const_string mes); -void clif_GMmessage(dumb_ptr<block_list> bl, const_string mes, int flag); +void clif_displaymessage(int fd, ZString mes); +void clif_GMmessage(dumb_ptr<block_list> bl, ZString mes, int flag); void clif_resurrection(dumb_ptr<block_list> bl, int type); int clif_specialeffect(dumb_ptr<block_list> bl, int type, int flag); // special effects [Valaris] diff --git a/src/map/intif.cpp b/src/map/intif.cpp index 9e9d2e1..311c661 100644 --- a/src/map/intif.cpp +++ b/src/map/intif.cpp @@ -286,13 +286,16 @@ int intif_parse_WisEnd(int fd) { dumb_ptr<map_session_data> sd; + char name[24]; + RFIFO_STRING(fd, 2, name, 24); + uint8_t flag = RFIFOB(fd, 26); if (battle_config.etc_log) // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target PRINTF("intif_parse_wisend: player: %s, flag: %d\n", - static_cast<const char *>(RFIFOP(fd, 2)), RFIFOB(fd, 26)); - sd = map_nick2sd(static_cast<const char *>(RFIFOP(fd, 2))); + name, flag); + sd = map_nick2sd(name); if (sd != NULL) - clif_wis_end(sd->fd, RFIFOB(fd, 26)); + clif_wis_end(sd->fd, flag); return 0; } @@ -414,8 +417,12 @@ void intif_parse_PartyCreated(int fd) { if (battle_config.etc_log) PRINTF("intif: party created\n"); - party_created(RFIFOL(fd, 2), RFIFOB(fd, 6), RFIFOL(fd, 7), - static_cast<const char *>(RFIFOP(fd, 11))); + int account_id = RFIFOL(fd, 2); + int fail = RFIFOB(fd, 6); + int party_id = RFIFOL(fd, 7); + char name[24]; + RFIFO_STRING(fd, 11, name, 24); + party_created(account_id, fail, party_id, name); } // パーティ情報 @@ -438,7 +445,9 @@ void intif_parse_PartyInfo(int fd) RFIFOL(fd, 4), RFIFOW(fd, 2), sizeof(struct party) + 4); } - party_recv_info(static_cast<const struct party *>(RFIFOP(fd, 4))); + party p {}; + RFIFO_STRUCT(fd, 4, p); + party_recv_info(&p); } // パーティ追加通知 @@ -463,10 +472,14 @@ void intif_parse_PartyOptionChanged(int fd) static void intif_parse_PartyMemberLeaved(int fd) { + int party_id = RFIFOL(fd, 2); + int account_id = RFIFOL(fd, 6); + char name[24]; + RFIFO_STRING(fd, 10, name, 24); if (battle_config.etc_log) - PRINTF("intif: party member leaved %d %d %s\n", RFIFOL(fd, 2), - RFIFOL(fd, 6), static_cast<const char *>(RFIFOP(fd, 10))); - party_member_leaved(RFIFOL(fd, 2), RFIFOL(fd, 6), static_cast<const char *>(RFIFOP(fd, 10))); + PRINTF("intif: party member leaved %d %d %s\n", + party_id, account_id, name); + party_member_leaved(party_id, account_id, name); } // パーティ解散通知 @@ -480,18 +493,19 @@ void intif_parse_PartyBroken(int fd) static void intif_parse_PartyMove(int fd) { -// if(battle_config.etc_log) -// PRINTF("intif: party move %d %d %s %d %d\n",RFIFOL(fd,2),RFIFOL(fd,6),RFIFOP(fd,10),RFIFOB(fd,26),RFIFOW(fd,27)); - party_recv_movemap(RFIFOL(fd, 2), RFIFOL(fd, 6), static_cast<const char *>(RFIFOP(fd, 10)), - RFIFOB(fd, 26), RFIFOW(fd, 27)); + int party_id = RFIFOL(fd, 2); + int account_id = RFIFOL(fd, 6); + char map[16]; + RFIFO_STRING(fd, 10, map, 16); + uint8_t online = RFIFOB(fd, 26); + uint16_t lv = RFIFOW(fd, 27); + party_recv_movemap(party_id, account_id, map, online, lv); } // パーティメッセージ static void intif_parse_PartyMessage(int fd) { -// if(battle_config.etc_log) -// PRINTF("intif_parse_PartyMessage: %s\n",RFIFOP(fd,12)); size_t len = RFIFOW(fd, 2) - 12; char buf[len]; RFIFO_STRING(fd, 12, buf, len); @@ -532,9 +546,11 @@ int intif_parse(int fd) switch (cmd) { case 0x3800: - clif_GMmessage(NULL, - const_string(static_cast<const char *>(RFIFOP(fd, 4)), - (packet_len - 4) - 1), 0); + { + char mes[packet_len - 4]; + RFIFO_STRING(fd, 4, mes, packet_len - 4); + clif_GMmessage(NULL, ZString(ZString::really_construct_from_a_pointer, mes), 0); + } break; case 0x3801: intif_parse_WisMessage(fd); diff --git a/src/map/magic-interpreter-base.cpp b/src/map/magic-interpreter-base.cpp index e6c1f37..3d0c853 100644 --- a/src/map/magic-interpreter-base.cpp +++ b/src/map/magic-interpreter-base.cpp @@ -137,7 +137,7 @@ void magic_free_env(dumb_ptr<env_t> env) } dumb_ptr<env_t> spell_create_env(magic_conf_t *conf, dumb_ptr<spell_t> spell, - dumb_ptr<map_session_data> caster, int spellpower, const_string param) + dumb_ptr<map_session_data> caster, int spellpower, const_string param) { dumb_ptr<env_t> env = alloc_env(conf); diff --git a/src/map/magic-interpreter-lexer.lpp b/src/map/magic-interpreter-lexer.lpp index c0a554b..a7c25e5 100644 --- a/src/map/magic-interpreter-lexer.lpp +++ b/src/map/magic-interpreter-lexer.lpp @@ -113,13 +113,13 @@ char *dst = &string[0]; while (*src && *src != '"') { - if (*src == '\\') - { - *dst++ = src[1]; - src += 2; - } - else - *dst++ = *src++; + if (*src == '\\') + { + *dst++ = src[1]; + src += 2; + } + else + *dst++ = *src++; } *dst = '\0'; /* terminate */ magic_frontend_lval.s = string; diff --git a/src/map/map.hpp b/src/map/map.hpp index 968bf43..cf52173 100644 --- a/src/map/map.hpp +++ b/src/map/map.hpp @@ -161,7 +161,7 @@ struct map_session_data : block_list, SessionData // but one should probably be replaced with a ScriptPointer ??? const ScriptBuffer *npc_script, *npc_scriptroot; std::vector<struct script_data> npc_stackbuf; - char npc_str[256]; + std::string npc_str; struct { unsigned storage:1; diff --git a/src/map/mob.cpp b/src/map/mob.cpp index ffeb619..345f5a6 100644 --- a/src/map/mob.cpp +++ b/src/map/mob.cpp @@ -2313,7 +2313,6 @@ int mob_damage(dumb_ptr<block_list> src, dumb_ptr<mob_data> md, int damage, int max_hp; tick_t tick = gettick(); dumb_ptr<map_session_data> mvp_sd = NULL, second_sd = NULL, third_sd = NULL; - double tdmg; nullpo_ret(md); //srcはNULLで呼ばれる場合もあるので、他でチェック @@ -2455,8 +2454,6 @@ int mob_damage(dumb_ptr<block_list> src, dumb_ptr<mob_data> md, int damage, // map外に消えた人は計算から除くので // overkill分は無いけどsumはmax_hpとは違う - tdmg = 0; - // snip a prelude loop, now merged std::sort(md->dmglogv.begin(), md->dmglogv.end(), diff --git a/src/map/npc.cpp b/src/map/npc.cpp index 91331cb..ab6892a 100644 --- a/src/map/npc.cpp +++ b/src/map/npc.cpp @@ -205,8 +205,7 @@ int npc_event_doall_l(const char *name, int rid, int argc, argrec_t *args) int c = 0; char buf[64] = "::"; - strncpy(buf + 2, name, sizeof(buf)-3); - buf[sizeof(buf)-1] = '\0'; + strzcpy(buf + 2, name, 62); for (auto& pair : ev_db) npc_event_doall_sub(pair.first, &pair.second, &c, buf, rid, argc, args); return c; @@ -1624,10 +1623,8 @@ dumb_ptr<npc_data> npc_spawn_text(map_local *m, int x, int y, retval->bl_type = BL::NPC; retval->npc_subtype = NpcSubtype::MESSAGE; - strncpy(retval->name, name, 23); - strncpy(retval->exname, name, 23); - retval->name[15] = 0; - retval->exname[15] = 0; + strzcpy(retval->name, name, 24); + strzcpy(retval->exname, name, 24); if (message) retval->message = message; diff --git a/src/map/party.cpp b/src/map/party.cpp index de655d7..62493c8 100644 --- a/src/map/party.cpp +++ b/src/map/party.cpp @@ -65,8 +65,7 @@ int party_create(dumb_ptr<map_session_data> sd, const char *name) char pname[24]; nullpo_ret(sd); - strncpy(pname, name, 24); - pname[23] = '\0'; + strzcpy(pname, name, 24); tmw_TrimStr(pname); /* The party name is empty/invalid. */ diff --git a/src/map/pc.cpp b/src/map/pc.cpp index be59c0b..6759deb 100644 --- a/src/map/pc.cpp +++ b/src/map/pc.cpp @@ -4,6 +4,8 @@ #include <cstdlib> #include <cstring> +#include <fstream> + #include "../common/cxxstdio.hpp" #include "../common/random.hpp" #include "../common/nullpo.hpp" @@ -732,25 +734,16 @@ int pc_authok(int id, int login_id2, TimeT connect_until_time, PRINTF("Connection accepted: Character '%s' (account: %d).\n", sd->status.name, sd->status.account_id); - // Message of the Dayの送信 + // TODO fix this to cache and use inotify { - char buf[256]; - FILE *fp; - if ((fp = fopen_(motd_txt, "r")) != NULL) + std::ifstream in(motd_txt); + if (in.is_open()) { - while (fgets(buf, sizeof(buf) - 1, fp) != NULL) + std::string buf; + while (std::getline(in, buf)) { - for (int i = 0; buf[i]; i++) - { - if (buf[i] == '\r' || buf[i] == '\n') - { - buf[i] = 0; - break; - } - } clif_displaymessage(sd->fd, buf); } - fclose_(fp); } } @@ -1447,9 +1440,9 @@ int pc_calcstatus(dumb_ptr<map_session_data> sd, int first) return 0; } - if (memcmp(&b_skill, &sd->status.skill, sizeof(sd->status.skill)) + if (b_skill != sd->status.skill || b_attackrange != sd->attackrange) - clif_skillinfoblock(sd); // スキル送信 + clif_skillinfoblock(sd); if (b_speed != sd->speed) clif_updatestatus(sd, SP::SPEED); diff --git a/src/map/script.cpp b/src/map/script.cpp index 0e95904..8ba2ebc 100644 --- a/src/map/script.cpp +++ b/src/map/script.cpp @@ -1563,7 +1563,7 @@ void builtin_input(ScriptState *st) sd->state.menu_or_input = 0; if (postfix == '$') { - set_reg(sd, type, num, dumb_string::fake(sd->npc_str)); + set_reg(sd, type, num, dumb_string::fake(sd->npc_str.c_str())); } else { @@ -2795,7 +2795,7 @@ void builtin_announce(ScriptState *st) static void builtin_mapannounce_sub(dumb_ptr<block_list> bl, dumb_string str, int flag) { - clif_GMmessage(bl, str.c_str(), flag | 3); + clif_GMmessage(bl, str, flag | 3); } static diff --git a/src/map/tmw.cpp b/src/map/tmw.cpp index 9929e59..7afe3ca 100644 --- a/src/map/tmw.cpp +++ b/src/map/tmw.cpp @@ -63,7 +63,7 @@ int tmw_CheckChatSpam(dumb_ptr<map_session_data> sd, const char *message) if (tmw_CheckChatLameness(sd, message)) sd->chat_lines_in += battle_config.chat_lame_penalty; - strncpy(sd->chat_lastmsg, message, battle_config.chat_maxline); + strzcpy(sd->chat_lastmsg, message, battle_config.chat_maxline); if (sd->chat_lines_in >= battle_config.chat_spam_flood || sd->chat_total_repeats >= battle_config.chat_spam_flood) |