summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/char/char.cpp196
-rw-r--r--src/char/char.hpp2
-rw-r--r--src/char/int_party.cpp103
-rw-r--r--src/char/int_storage.cpp16
-rw-r--r--src/char/inter.cpp145
-rw-r--r--src/common/const_array.hpp2
-rw-r--r--src/common/md5calc.cpp108
-rw-r--r--src/common/mmo.hpp2
-rw-r--r--src/common/socket.cpp4
-rw-r--r--src/common/socket.hpp79
-rw-r--r--src/common/utils.hpp39
-rw-r--r--src/ladmin/ladmin.cpp262
-rw-r--r--src/login/login.cpp298
-rw-r--r--src/map/atcommand.cpp316
-rw-r--r--src/map/battle.cpp9
-rw-r--r--src/map/battle.hpp1
-rw-r--r--src/map/chrif.cpp27
-rw-r--r--src/map/clif.cpp291
-rw-r--r--src/map/clif.hpp25
-rw-r--r--src/map/intif.cpp202
-rw-r--r--src/map/intif.hpp32
-rw-r--r--src/map/itemdb.cpp17
-rw-r--r--src/map/magic-expr.cpp16
-rw-r--r--src/map/magic-interpreter-parser.ypp2
-rw-r--r--src/map/magic-interpreter.hpp28
-rw-r--r--src/map/magic-stmt.cpp5
-rw-r--r--src/map/map.cpp17
-rw-r--r--src/map/map.hpp30
-rw-r--r--src/map/mob.cpp323
-rw-r--r--src/map/mob.hpp7
-rw-r--r--src/map/npc.cpp76
-rw-r--r--src/map/party.cpp50
-rw-r--r--src/map/party.hpp12
-rw-r--r--src/map/path.cpp3
-rw-r--r--src/map/pc.cpp144
-rw-r--r--src/map/pc.hpp4
-rw-r--r--src/map/script.cpp20
-rw-r--r--src/map/skill.cpp127
-rw-r--r--src/map/skill.hpp13
-rw-r--r--src/map/storage.cpp4
-rw-r--r--src/map/tmw.cpp37
-rw-r--r--src/map/tmw.hpp2
-rw-r--r--src/poison.hpp2
43 files changed, 1330 insertions, 1768 deletions
diff --git a/src/char/char.cpp b/src/char/char.cpp
index 496f5fd..02d89af 100644
--- a/src/char/char.cpp
+++ b/src/char/char.cpp
@@ -230,9 +230,9 @@ __inline__ static
std::string mmo_char_tostr(struct mmo_charstatus *p)
{
// on multi-map server, sometimes it's posssible that last_point become void. (reason???) We check that to not lost character at restart.
- if (p->last_point.map[0] == '\0')
+ if (p->last_point.map_[0] == '\0')
{
- memcpy(p->last_point.map, "001-1.gat", 10);
+ strzcpy(p->last_point.map_, "001-1.gat", 16);
p->last_point.x = 273;
p->last_point.y = 354;
}
@@ -265,13 +265,13 @@ std::string mmo_char_tostr(struct mmo_charstatus *p)
p->party_id, 0/*guild_id*/, 0/*pet_id*/,
p->hair, p->hair_color, p->clothes_color,
p->weapon, p->shield, p->head_top, p->head_mid, p->head_bottom,
- p->last_point.map, p->last_point.x, p->last_point.y,
- p->save_point.map, p->save_point.x, p->save_point.y, p->partner_id);
+ p->last_point.map_, p->last_point.x, p->last_point.y,
+ p->save_point.map_, p->save_point.x, p->save_point.y, p->partner_id);
for (int i = 0; i < 10; i++)
- if (p->memo_point[i].map[0])
+ if (p->memo_point[i].map_[0])
{
str_p += STRPRINTF("%s,%d,%d ",
- p->memo_point[i].map, p->memo_point[i].x, p->memo_point[i].y);
+ p->memo_point[i].map_, p->memo_point[i].x, p->memo_point[i].y);
}
str_p += '\t';
@@ -335,7 +335,7 @@ std::string mmo_char_tostr(struct mmo_charstatus *p)
static
bool extract(const_string str, struct point *p)
{
- return extract(str, record<','>(&p->map, &p->x, &p->y));
+ return extract(str, record<','>(&p->map_, &p->x, &p->y));
}
struct skill_loader
@@ -364,7 +364,7 @@ static
bool extract(const_string str, struct mmo_charstatus *p)
{
// initilialise character
- memset(p, '\0', sizeof(struct mmo_charstatus));
+ *p = mmo_charstatus{};
uint32_t unused_guild_id, unused_pet_id;
std::vector<struct point> memos;
@@ -389,7 +389,7 @@ bool extract(const_string str, struct mmo_charstatus *p)
// somebody was silly and stuck partner id as a field
// of this, instead of adding a new \t
// or putting it elsewhere, like by pet/guild
- record<','>(&p->save_point.map, &p->save_point.x, &p->save_point.y, &p->partner_id),
+ record<','>(&p->save_point.map_, &p->save_point.x, &p->save_point.y, &p->partner_id),
vrec<' '>(&memos),
vrec<' '>(&inventory),
vrec<' '>(&cart),
@@ -768,8 +768,8 @@ mmo_charstatus *make_new_char(int fd, const uint8_t *dat)
cd.head_top = 0;
cd.head_mid = 0;
cd.head_bottom = 0;
- memcpy(&cd.last_point, &start_point, sizeof(start_point));
- memcpy(&cd.save_point, &start_point, sizeof(start_point));
+ cd.last_point = start_point;
+ cd.save_point = start_point;
char_data.push_back(std::move(cd));
online_chars.push_back(-1);
@@ -950,7 +950,7 @@ int mmo_char_send006b(int fd, struct char_session_data *sd)
}
const int offset = 24;
- memset(WFIFOP(fd, 0), 0, offset + found_num * 106);
+ WFIFO_ZERO(fd, 0, offset + found_num * 106);
WFIFOW(fd, 0) = 0x6b;
WFIFOW(fd, 2) = offset + found_num * 106;
@@ -994,7 +994,7 @@ int mmo_char_send006b(int fd, struct char_session_data *sd)
WFIFOW(fd, j + 72) = find_equip_view(p, EPOS::MISC2);
// WFIFOW(fd,j+72) = p->clothes_color;
- memcpy(WFIFOP(fd, j + 74), p->name, 24);
+ WFIFO_STRING(fd, j + 74, p->name, 24);
WFIFOB(fd, j + 98) = min(p->attrs[ATTR::STR], 255);
WFIFOB(fd, j + 99) = min(p->attrs[ATTR::AGI], 255);
@@ -1018,8 +1018,11 @@ int set_account_reg2(int acc, int num, struct global_reg *reg)
{
if (cd.account_id == acc)
{
- memcpy(cd.account_reg2, reg, sizeof(cd.account_reg2));
+ for (int i = 0; i < num; ++i)
+ cd.account_reg2[i] = reg[i];
cd.account_reg2_num = num;
+ for (int i = num; i < ACCOUNT_REG2_NUM; ++i)
+ cd.account_reg2[i] = global_reg{};
c++;
}
}
@@ -1168,7 +1171,7 @@ void parse_tologin(int fd)
// if no map-server already connected, display a message...
int i;
for (i = 0; i < MAX_MAP_SERVERS; i++)
- if (server_fd[i] >= 0 && server[i].map[0][0]) // if map-server online and at least 1 map
+ if (server_fd[i] >= 0 && server[i].maps[0][0]) // if map-server online and at least 1 map
break;
if (i == MAX_MAP_SERVERS)
PRINTF("Awaiting maps from map-server.\n");
@@ -1200,7 +1203,7 @@ void parse_tologin(int fd)
// PRINTF("max_connect_user (unlimited) -> accepted.\n");
// else
// PRINTF("count_users(): %d < max_connect_user (%d) -> accepted.\n", count_users(), max_connect_user);
- memcpy(sd->email, RFIFOP(fd, 7), 40);
+ RFIFO_STRING(fd, 7, sd->email, 40);
if (e_mail_check(sd->email) == 0)
strzcpy(sd->email, "a@a.com", 40); // default e-mail
sd->connect_until_time = static_cast<time_t>(RFIFOL(fd, 47));
@@ -1234,7 +1237,7 @@ void parse_tologin(int fd)
{
if (sd->account_id == RFIFOL(fd, 2))
{
- memcpy(sd->email, RFIFOP(fd, 6), 40);
+ RFIFO_STRING(fd, 6, sd->email, 40);
if (e_mail_check(sd->email) == 0)
strzcpy(sd->email, "a@a.com", 40); // default e-mail
sd->connect_until_time = static_cast<time_t>(RFIFOL(fd, 46));
@@ -1316,16 +1319,12 @@ void parse_tologin(int fd)
CHAR_LOG("'ladmin': Receiving a message for broadcast, but no map-server is online.\n");
else
{
- uint8_t buf[128];
- char message[RFIFOL(fd, 4) + 1]; // +1 to add a null terminated if not exist in the packet
- int lp;
- char *p;
- memset(message, '\0', sizeof(message));
- memcpy(message, RFIFOP(fd, 8), RFIFOL(fd, 4));
- message[sizeof(message) - 1] = '\0';
+ size_t len = RFIFOL(fd, 4);
+ char message[len];
+ RFIFO_STRING(fd, 8, message, len);
remove_control_chars(message);
// remove all first spaces
- p = message;
+ char *p = message;
while (p[0] == ' ')
p++;
// if message is only composed of spaces
@@ -1334,25 +1333,16 @@ void parse_tologin(int fd)
// else send message to all map-servers
else
{
- if (RFIFOW(fd, 2) == 0)
{
const char *message_ptr = message;
CHAR_LOG("'ladmin': Receiving a message for broadcast (message (in yellow): %s)\n",
message_ptr);
- lp = 4;
- }
- else
- {
- const char *message_ptr = message;
- CHAR_LOG("'ladmin': Receiving a message for broadcast (message (in blue): %s)\n",
- message_ptr);
- lp = 8;
}
// send broadcast to all map-servers
+ uint8_t buf[4 + len];
WBUFW(buf, 0) = 0x3800;
- WBUFW(buf, 2) = lp + sizeof(message);
- WBUFL(buf, 4) = 0x65756c62; // only write if in blue (lp = 8)
- memcpy(WBUFP(buf, lp), message, sizeof(message));
+ WBUFW(buf, 2) = 4 + sizeof(message);
+ WBUF_STRING(buf, 4, message, sizeof(message));
mapif_sendall(buf, WBUFW(buf, 2));
}
}
@@ -1366,24 +1356,25 @@ void parse_tologin(int fd)
return;
{
struct global_reg reg[ACCOUNT_REG2_NUM];
- unsigned char buf[4096];
int j, p, acc;
acc = RFIFOL(fd, 4);
for (p = 8, j = 0;
p < RFIFOW(fd, 2) && j < ACCOUNT_REG2_NUM;
p += 36, j++)
{
- memcpy(reg[j].str, RFIFOP(fd, p), 32);
+ RFIFO_STRING(fd, p, reg[j].str, 32);
reg[j].value = RFIFOL(fd, p + 32);
}
set_account_reg2(acc, j, reg);
- // 同垢ログインを禁止していれば送る必要は無い
- memcpy(buf, RFIFOP(fd, 0), RFIFOW(fd, 2));
+
+ size_t len = RFIFOW(fd, 2);
+ uint8_t buf[len];
+ RFIFO_BUF_CLONE(fd, buf, len);
WBUFW(buf, 0) = 0x2b11;
- mapif_sendall(buf, WBUFW(buf, 2));
- RFIFOSKIP(fd, RFIFOW(fd, 2));
+ mapif_sendall(buf, len);
// PRINTF("char: save_account_reg_reply\n");
}
+ RFIFOSKIP(fd, RFIFOW(fd, 2));
break;
case 0x7924:
@@ -1496,10 +1487,11 @@ void parse_tologin(int fd)
if (RFIFOREST(fd) < 4 || RFIFOREST(fd) < RFIFOW(fd, 2))
return;
{
- uint8_t buf[32000];
+ size_t len = RFIFOW(fd, 2);
+ uint8_t buf[len];
gm_accounts.clear();
- gm_accounts.resize((RFIFOW(fd, 2) - 4) / 5);
- for (int i = 4; i < RFIFOW(fd, 2); i = i + 5)
+ gm_accounts.reserve((len - 4) / 5);
+ for (int i = 4; i < len; i += 5)
{
gm_accounts.push_back({static_cast<int>(RFIFOL(fd, i)), RFIFOB(fd, i + 4)});
}
@@ -1509,9 +1501,9 @@ void parse_tologin(int fd)
gm_accounts.size());
create_online_files(); // update online players files (perhaps some online players change of GM level)
// send new gm acccounts level to map-servers
- memcpy(buf, RFIFOP(fd, 0), RFIFOW(fd, 2));
+ RFIFO_BUF_CLONE(fd, buf, len);
WBUFW(buf, 0) = 0x2b15;
- mapif_sendall(buf, RFIFOW(fd, 2));
+ mapif_sendall(buf, len);
}
RFIFOSKIP(fd, RFIFOW(fd, 2));
break;
@@ -1590,7 +1582,7 @@ void parse_frommap(int fd)
{
PRINTF("Map-server %d (session #%d) has disconnected.\n", id,
fd);
- memset(&server[id], 0, sizeof(struct mmo_map_server));
+ server[id] = mmo_map_server{};
server_fd[id] = -1;
for (int& oci : online_chars)
if (oci == fd)
@@ -1623,11 +1615,12 @@ void parse_frommap(int fd)
if (RFIFOREST(fd) < 4 || RFIFOREST(fd) < RFIFOW(fd, 2))
return;
{
- memset(server[id].map, 0, sizeof(server[id].map));
+ for (char (&foo)[16] : server[id].maps)
+ strzcpy(foo, "", 16);
int j = 0;
for (int i = 4; i < RFIFOW(fd, 2); i += 16)
{
- memcpy(server[id].map[j], RFIFOP(fd, i), 16);
+ RFIFO_STRING(fd, i, server[id].maps[j], 16);
// PRINTF("set map %d.%d : %s\n", id, j, server[id].map[j]);
j++;
}
@@ -1642,7 +1635,7 @@ void parse_frommap(int fd)
}
WFIFOW(fd, 0) = 0x2afb;
WFIFOB(fd, 2) = 0;
- memcpy(WFIFOP(fd, 3), wisp_server_name, 24); // name for wisp to player
+ WFIFO_STRING(fd, 3, wisp_server_name, 24);
WFIFOSET(fd, 27);
{
unsigned char buf[16384];
@@ -1659,7 +1652,9 @@ void parse_frommap(int fd)
WBUFW(buf, 2) = j * 16 + 10;
WBUFL(buf, 4) = server[id].ip;
WBUFW(buf, 8) = server[id].port;
- memcpy(WBUFP(buf, 10), RFIFOP(fd, 4), j * 16);
+ // server[id].maps[i] = RFIFO_STRING(fd, 4 + i * 16)
+ for (int i = 0; i < j; ++i)
+ WBUF_STRING(buf, 10, server[id].maps[i], 16);
mapif_sendallwos(fd, buf, WBUFW(buf, 2));
}
// Transmitting the maps of the other map-servers to the new map-server
@@ -1672,9 +1667,8 @@ void parse_frommap(int fd)
WFIFOW(fd, 8) = server[x].port;
j = 0;
for (int i = 0; i < MAX_MAP_PER_SERVER; i++)
- if (server[x].map[i][0])
- memcpy(WFIFOP(fd, 10 + (j++) * 16),
- server[x].map[i], 16);
+ if (server[x].maps[i][0])
+ WFIFO_STRING(fd, 10 + (j++) * 16, server[x].maps[i], 16);
if (j > 0)
{
WFIFOW(fd, 2) = j * 16 + 10;
@@ -1714,7 +1708,7 @@ void parse_frommap(int fd)
assert (cd && "uh-oh - deleted while in queue?");
afi.delflag = 1;
WFIFOW(fd, 0) = 0x2afd;
- WFIFOW(fd, 2) = 18 + sizeof(struct mmo_charstatus);
+ WFIFOW(fd, 2) = 18 + sizeof(*cd);
WFIFOL(fd, 4) = RFIFOL(fd, 2);
WFIFOL(fd, 8) = afi.login_id2;
WFIFOL(fd, 12) = static_cast<time_t>(afi.connect_until_time);
@@ -1723,9 +1717,7 @@ void parse_frommap(int fd)
FPRINTF(stderr,
"From queue index %zd: recalling packet version %d\n",
(&afi - &auth_fifo.front()), afi.packet_tmw_version);
- memcpy(WFIFOP(fd, 18),
- cd,
- sizeof(struct mmo_charstatus));
+ WFIFO_STRUCT(fd, 18, *cd);
WFIFOSET(fd, WFIFOW(fd, 2));
//PRINTF("auth_fifo search success (auth #%d, account %d, character: %d).\n", i, RFIFOL(fd,2), RFIFOL(fd,6));
goto x2afc_out;
@@ -1784,7 +1776,7 @@ void parse_frommap(int fd)
if (cd.account_id == RFIFOL(fd, 4) &&
cd.char_id == RFIFOL(fd, 8))
{
- memcpy(&cd, RFIFOP(fd, 12), sizeof(struct mmo_charstatus));
+ RFIFO_STRUCT(fd, 12, cd);
break;
}
}
@@ -1818,8 +1810,10 @@ void parse_frommap(int fd)
return;
if (auth_fifo_iter == auth_fifo.end())
auth_fifo_iter = auth_fifo.begin();
+
+ RFIFO_WFIFO_CLONE(fd, fd, 44);
+ // overwrite
WFIFOW(fd, 0) = 0x2b06;
- memcpy(WFIFOP(fd, 2), RFIFOP(fd, 2), 42);
auth_fifo_iter->account_id = RFIFOL(fd, 2);
auth_fifo_iter->char_id = RFIFOL(fd, 14);
auth_fifo_iter->login_id1 = RFIFOL(fd, 6);
@@ -1859,7 +1853,7 @@ void parse_frommap(int fd)
}
WFIFOW(fd, 0) = 0x2b09;
WFIFOL(fd, 2) = RFIFOL(fd, 2);
- memcpy(WFIFOP(fd, 6), *name, 24);
+ WFIFO_STRING(fd, 6, *name, 24);
WFIFOSET(fd, 30);
}
RFIFOSKIP(fd, 6);
@@ -1872,10 +1866,10 @@ void parse_frommap(int fd)
// PRINTF("parse_frommap: change gm -> login, account: %d, pass: '%s'.\n", RFIFOL(fd,4), RFIFOP(fd,8));
if (login_fd > 0)
{ // don't send request if no login-server
+ size_t len = RFIFOW(fd, 2);
+ RFIFO_WFIFO_CLONE(fd, login_fd, len);
WFIFOW(login_fd, 0) = 0x2720;
- memcpy(WFIFOP(login_fd, 2), RFIFOP(fd, 2),
- RFIFOW(fd, 2) - 2);
- WFIFOSET(login_fd, RFIFOW(fd, 2));
+ WFIFOSET(login_fd, len);
}
else
{
@@ -1893,7 +1887,7 @@ void parse_frommap(int fd)
return;
if (login_fd > 0)
{ // don't send request if no login-server
- memcpy(WFIFOP(login_fd, 0), RFIFOP(fd, 0), 86); // 0x2722 <account_id>.L <actual_e-mail>.40B <new_e-mail>.40B
+ RFIFO_WFIFO_CLONE(fd, login_fd, 86); // 0x2722 <account_id>.L <actual_e-mail>.40B <new_e-mail>.40B
WFIFOW(login_fd, 0) = 0x2722;
WFIFOSET(login_fd, 86);
}
@@ -1916,7 +1910,7 @@ void parse_frommap(int fd)
const mmo_charstatus *cd = search_character(character_name);
if (cd)
{
- memcpy(WFIFOP(fd, 6), cd->name, 24); // put correct name if found
+ WFIFO_STRING(fd, 6, cd->name, 24); // put correct name if found
WFIFOW(fd, 32) = 0; // answer: 0-login-server resquest done, 1-player not found, 2-gm level too low, 3-login-server offline
switch (RFIFOW(fd, 30))
{
@@ -2019,7 +2013,7 @@ void parse_frommap(int fd)
else
{
// character name not found
- memcpy(WFIFOP(fd, 6), character_name, 24);
+ WFIFO_STRING(fd, 6, character_name, 24);
WFIFOW(fd, 32) = 1; // answer: 0-login-server resquest done, 1-player not found, 2-gm level too low, 3-login-server offline
}
// send answer if a player ask, not if the server ask
@@ -2045,15 +2039,14 @@ void parse_frommap(int fd)
p < RFIFOW(fd, 2) && j < ACCOUNT_REG2_NUM;
p += 36, j++)
{
- memcpy(reg[j].str, RFIFOP(fd, p), 32);
+ RFIFO_STRING(fd, p, reg[j].str, 32);
reg[j].value = RFIFOL(fd, p + 32);
}
set_account_reg2(acc, j, reg);
// loginサーバーへ送る
if (login_fd > 0)
{ // don't send request if no login-server
- memcpy(WFIFOP(login_fd, 0), RFIFOP(fd, 0),
- RFIFOW(fd, 2));
+ RFIFO_WFIFO_CLONE(fd, login_fd, RFIFOW(fd, 2));
WFIFOW(login_fd, 0) = 0x2728;
WFIFOSET(login_fd, WFIFOW(login_fd, 2));
}
@@ -2116,9 +2109,9 @@ int search_mapserver(const char *map)
temp_map_len = strlen(temp_map);
for (i = 0; i < MAX_MAP_SERVERS; i++)
if (server_fd[i] >= 0)
- for (j = 0; server[i].map[j][0]; j++)
+ for (j = 0; server[i].maps[j][0]; j++)
//PRINTF("%s : %s = %d\n", server[i].map[j], map, strncmp(server[i].map[j], temp_map, temp_map_len));
- if (strncmp(server[i].map[j], temp_map, temp_map_len) == 0)
+ if (strncmp(server[i].maps[j], temp_map, temp_map_len) == 0)
{
// PRINTF("found -> server #%d.\n", i);
return i;
@@ -2175,7 +2168,7 @@ void handle_x0066(int fd, struct char_session_data *sd, uint8_t rfifob_2, uint8_
sd->account_id, rfifob_2,
cd->name, ip);
// searching map server
- int i = search_mapserver(cd->last_point.map);
+ int i = search_mapserver(cd->last_point.map_);
// if map is not found, we check major cities
if (i < 0)
{
@@ -2184,13 +2177,12 @@ void handle_x0066(int fd, struct char_session_data *sd, uint8_t rfifob_2, uint8_
i = 0;
for (j = 0; j < MAX_MAP_SERVERS; j++)
if (server_fd[j] >= 0
- && server[j].map[0][0])
+ && server[j].maps[0][0])
{ // change save point to one of map found on the server (the first)
i = j;
- memcpy(cd->last_point.map,
- server[j].map[0], 16);
+ strzcpy(cd->last_point.map_, server[j].maps[0], 16);
PRINTF("Map-server #%d found with a map: '%s'.\n",
- j, server[j].map[0]);
+ j, server[j].maps[0]);
// coordonates are unknown
break;
}
@@ -2205,9 +2197,7 @@ void handle_x0066(int fd, struct char_session_data *sd, uint8_t rfifob_2, uint8_
}
WFIFOW(fd, 0) = 0x71;
WFIFOL(fd, 2) = cd->char_id;
- memcpy(WFIFOP(fd, 6),
- cd->last_point.map,
- 16);
+ WFIFO_STRING(fd, 6, cd->last_point.map_, 16);
PRINTF("Character selection '%s' (account: %d, slot: %d) [%s]\n",
cd->name,
sd->account_id, cd->char_num, ip);
@@ -2269,8 +2259,12 @@ void parse_char(int fd)
{
WFIFOW(login_fd, 0) = 0x2740;
WFIFOL(login_fd, 2) = sd->account_id;
- memcpy(WFIFOP(login_fd, 6), RFIFOP(fd, 2), 24);
- memcpy(WFIFOP(login_fd, 30), RFIFOP(fd, 26), 24);
+ char old_pass[24];
+ RFIFO_STRING(fd, 2, old_pass, 24);
+ WFIFO_STRING(login_fd, 6, old_pass, 24);
+ char new_pass[24];
+ RFIFO_STRING(fd, 26, new_pass, 24);
+ WFIFO_STRING(login_fd, 30, new_pass, 24);
WFIFOSET(login_fd, 54);
}
RFIFOSKIP(fd, 50);
@@ -2291,7 +2285,7 @@ void parse_char(int fd)
{
session[fd]->session_data = make_unique<char_session_data, SessionDeleter>();
sd = static_cast<char_session_data *>(session[fd]->session_data.get());
- memcpy(sd->email, "no mail", 40); // put here a mail without '@' to refuse deletion if we don't receive the e-mail
+ strzcpy(sd->email, "no mail", 40); // put here a mail without '@' to refuse deletion if we don't receive the e-mail
sd->connect_until_time = TimeT(); // unknow or illimited (not displaying on map-server)
}
sd->account_id = RFIFOL(fd, 2);
@@ -2387,7 +2381,7 @@ void parse_char(int fd)
}
WFIFOW(fd, 0) = 0x6d;
- memset(WFIFOP(fd, 2), 0, 106);
+ WFIFO_ZERO(fd, 2, 106);
WFIFOL(fd, 2) = cd->char_id;
WFIFOL(fd, 2 + 4) = cd->base_exp;
@@ -2415,7 +2409,7 @@ void parse_char(int fd)
WFIFOW(fd, 2 + 68) = cd->head_mid;
WFIFOW(fd, 2 + 70) = cd->hair_color;
- memcpy(WFIFOP(fd, 2 + 74), cd->name, 24);
+ WFIFO_STRING(fd, 2 + 74, cd->name, 24);
WFIFOB(fd, 2 + 98) = min(cd->attrs[ATTR::STR], 255);
WFIFOB(fd, 2 + 99) = min(cd->attrs[ATTR::AGI], 255);
@@ -2433,7 +2427,7 @@ void parse_char(int fd)
case 0x68: // delete char //Yor's Fix
if (!sd || RFIFOREST(fd) < 46)
return;
- memcpy(email, RFIFOP(fd, 6), 40);
+ RFIFO_STRING(fd, 6, email, 40);
if (e_mail_check(email) == 0)
strzcpy(email, "a@a.com", 40); // default e-mail
@@ -2504,7 +2498,8 @@ void parse_char(int fd)
server[i].ip = RFIFOL(fd, 54);
server[i].port = RFIFOW(fd, 58);
server[i].users = 0;
- memset(server[i].map, 0, sizeof(server[i].map));
+ for (char (&mapi)[16] : server[i].maps)
+ strzcpy(mapi, "", 16);
WFIFOSET(fd, 3);
RFIFOSKIP(fd, 60);
realloc_fifo(fd, FIFOSIZE_SERVERLINK,
@@ -2566,7 +2561,7 @@ int mapif_sendall(const uint8_t *buf, unsigned int len)
int fd;
if ((fd = server_fd[i]) >= 0)
{
- memcpy(WFIFOP(fd, 0), buf, len);
+ WFIFO_BUF_CLONE(fd, buf, len);
WFIFOSET(fd, len);
c++;
}
@@ -2585,7 +2580,7 @@ int mapif_sendallwos(int sfd, const uint8_t *buf, unsigned int len)
int fd;
if ((fd = server_fd[i]) >= 0 && fd != sfd)
{
- memcpy(WFIFOP(fd, 0), buf, len);
+ WFIFO_BUF_CLONE(fd, buf, len);
WFIFOSET(fd, len);
c++;
}
@@ -2604,7 +2599,7 @@ int mapif_send(int fd, const uint8_t *buf, unsigned int len)
{
if (fd == server_fd[i])
{
- memcpy(WFIFOP(fd, 0), buf, len);
+ WFIFO_BUF_CLONE(fd, buf, len);
WFIFOSET(fd, len);
return 1;
}
@@ -2643,18 +2638,13 @@ void check_connect_login_server(TimerData *, tick_t)
session[login_fd]->func_parse = parse_tologin;
realloc_fifo(login_fd, FIFOSIZE_SERVERLINK, FIFOSIZE_SERVERLINK);
WFIFOW(login_fd, 0) = 0x2710;
- memset(WFIFOP(login_fd, 2), 0, 24);
- memcpy(WFIFOP(login_fd, 2), userid,
- strlen(userid) < 24 ? strlen(userid) : 24);
- memset(WFIFOP(login_fd, 26), 0, 24);
- memcpy(WFIFOP(login_fd, 26), passwd,
- strlen(passwd) < 24 ? strlen(passwd) : 24);
+ WFIFO_ZERO(login_fd, 2, 24);
+ WFIFO_STRING(login_fd, 2, userid, 24);
+ WFIFO_STRING(login_fd, 26, passwd, 24);
WFIFOL(login_fd, 50) = 0;
WFIFOL(login_fd, 54) = char_ip;
WFIFOL(login_fd, 58) = char_port;
- memset(WFIFOP(login_fd, 60), 0, 20);
- memcpy(WFIFOP(login_fd, 60), server_name,
- strlen(server_name) < 20 ? strlen(server_name) : 20);
+ WFIFO_STRING(login_fd, 60, server_name, 20);
WFIFOW(login_fd, 80) = 0;
WFIFOW(login_fd, 82) = char_maintenance;
WFIFOW(login_fd, 84) = char_new;
@@ -2892,7 +2882,7 @@ int char_config_read(const char *cfgName)
continue;
if (strstr(map, ".gat") != NULL)
{ // Verify at least if '.gat' is in the map name
- memcpy(start_point.map, map, 16);
+ strzcpy(start_point.map_, map, 16);
start_point.x = x;
start_point.y = y;
}
@@ -3017,7 +3007,7 @@ int do_init(int argc, char **argv)
for (i = 0; i < MAX_MAP_SERVERS; i++)
{
- memset(&server[i], 0, sizeof(struct mmo_map_server));
+ server[i] = mmo_map_server{};
server_fd[i] = -1;
}
diff --git a/src/char/char.hpp b/src/char/char.hpp
index a08e28c..5e16a6a 100644
--- a/src/char/char.hpp
+++ b/src/char/char.hpp
@@ -15,7 +15,7 @@ struct mmo_map_server
long ip;
short port;
int users;
- char map[MAX_MAP_PER_SERVER][16];
+ char maps[MAX_MAP_PER_SERVER][16];
};
const mmo_charstatus *search_character(const char *character_name);
diff --git a/src/char/int_party.cpp b/src/char/int_party.cpp
index 7e6f8b6..688c05a 100644
--- a/src/char/int_party.cpp
+++ b/src/char/int_party.cpp
@@ -22,7 +22,7 @@ static
int party_newid = 100;
static
-int mapif_party_broken(int party_id, int flag);
+void mapif_party_broken(int party_id, int flag);
static
int party_check_empty(struct party *p);
static
@@ -56,7 +56,7 @@ std::string inter_party_tostr(struct party *p)
static
int inter_party_fromstr(char *str, struct party *p)
{
- memset(p, 0, sizeof(struct party));
+ *p = party();
if (sscanf(str,
"%d\t"
@@ -249,13 +249,11 @@ void party_check_conflict_sub(struct party *p,
// キャラの競合がないかチェック
static
-int party_check_conflict(int party_id, int account_id, const char *nick)
+void party_check_conflict(int party_id, int account_id, const char *nick)
{
for (auto& pair : party_db)
party_check_conflict_sub(&pair.second,
party_id, account_id, nick);
-
- return 0;
}
//-------------------------------------------------------------------
@@ -263,7 +261,7 @@ int party_check_conflict(int party_id, int account_id, const char *nick)
// パーティ作成可否
static
-int mapif_party_created(int fd, int account_id, struct party *p)
+void mapif_party_created(int fd, int account_id, struct party *p)
{
WFIFOW(fd, 0) = 0x3820;
WFIFOL(fd, 2) = account_id;
@@ -271,67 +269,59 @@ int mapif_party_created(int fd, int account_id, struct party *p)
{
WFIFOB(fd, 6) = 0;
WFIFOL(fd, 7) = p->party_id;
- memcpy(WFIFOP(fd, 11), p->name, 24);
+ WFIFO_STRING(fd, 11, p->name, 24);
PRINTF("int_party: created! %d %s\n", p->party_id, p->name);
}
else
{
WFIFOB(fd, 6) = 1;
WFIFOL(fd, 7) = 0;
- memcpy(WFIFOP(fd, 11), "error", 24);
+ WFIFO_STRING(fd, 11, "error", 24);
}
WFIFOSET(fd, 35);
-
- return 0;
}
// パーティ情報見つからず
static
-int mapif_party_noinfo(int fd, int party_id)
+void mapif_party_noinfo(int fd, int party_id)
{
WFIFOW(fd, 0) = 0x3821;
WFIFOW(fd, 2) = 8;
WFIFOL(fd, 4) = party_id;
WFIFOSET(fd, 8);
PRINTF("int_party: info not found %d\n", party_id);
-
- return 0;
}
// パーティ情報まとめ送り
static
-int mapif_party_info(int fd, struct party *p)
+void mapif_party_info(int fd, struct party *p)
{
unsigned char buf[4 + sizeof(struct party)];
WBUFW(buf, 0) = 0x3821;
- memcpy(buf + 4, p, sizeof(struct party));
+ WBUF_STRUCT(buf, 4, *p);
WBUFW(buf, 2) = 4 + sizeof(struct party);
if (fd < 0)
mapif_sendall(buf, WBUFW(buf, 2));
else
mapif_send(fd, buf, WBUFW(buf, 2));
// PRINTF("int_party: info %d %s\n", p->party_id, p->name);
-
- return 0;
}
// パーティメンバ追加可否
static
-int mapif_party_memberadded(int fd, int party_id, int account_id, int flag)
+void mapif_party_memberadded(int fd, int party_id, int account_id, int flag)
{
WFIFOW(fd, 0) = 0x3822;
WFIFOL(fd, 2) = party_id;
WFIFOL(fd, 6) = account_id;
WFIFOB(fd, 10) = flag;
WFIFOSET(fd, 11);
-
- return 0;
}
// パーティ設定変更通知
static
-int mapif_party_optionchanged(int fd, struct party *p, int account_id,
+void mapif_party_optionchanged(int fd, struct party *p, int account_id,
int flag)
{
unsigned char buf[15];
@@ -348,45 +338,39 @@ int mapif_party_optionchanged(int fd, struct party *p, int account_id,
mapif_send(fd, buf, 15);
PRINTF("int_party: option changed %d %d %d %d %d\n", p->party_id,
account_id, p->exp, p->item, flag);
-
- return 0;
}
// パーティ脱退通知
static
-int mapif_party_leaved(int party_id, int account_id, char *name)
+void mapif_party_leaved(int party_id, int account_id, char *name)
{
unsigned char buf[34];
WBUFW(buf, 0) = 0x3824;
WBUFL(buf, 2) = party_id;
WBUFL(buf, 6) = account_id;
- memcpy(WBUFP(buf, 10), name, 24);
+ WBUF_STRING(buf, 10, name, 24);
mapif_sendall(buf, 34);
PRINTF("int_party: party leaved %d %d %s\n", party_id, account_id, name);
-
- return 0;
}
// パーティマップ更新通知
static
-int mapif_party_membermoved(struct party *p, int idx)
+void mapif_party_membermoved(struct party *p, int idx)
{
unsigned char buf[29];
WBUFW(buf, 0) = 0x3825;
WBUFL(buf, 2) = p->party_id;
WBUFL(buf, 6) = p->member[idx].account_id;
- memcpy(WBUFP(buf, 10), p->member[idx].map, 16);
+ WBUF_STRING(buf, 10, p->member[idx].map, 16);
WBUFB(buf, 26) = p->member[idx].online;
WBUFW(buf, 27) = p->member[idx].lv;
mapif_sendall(buf, 29);
-
- return 0;
}
// パーティ解散通知
-int mapif_party_broken(int party_id, int flag)
+void mapif_party_broken(int party_id, int flag)
{
unsigned char buf[7];
WBUFW(buf, 0) = 0x3826;
@@ -394,13 +378,11 @@ int mapif_party_broken(int party_id, int flag)
WBUFB(buf, 6) = flag;
mapif_sendall(buf, 7);
PRINTF("int_party: broken %d\n", party_id);
-
- return 0;
}
// パーティ内発言
static
-int mapif_party_message(int party_id, int account_id, const char *mes, int len)
+void mapif_party_message(int party_id, int account_id, const char *mes, int len)
{
unsigned char buf[len + 12];
@@ -408,10 +390,8 @@ int mapif_party_message(int party_id, int account_id, const char *mes, int len)
WBUFW(buf, 2) = len + 12;
WBUFL(buf, 4) = party_id;
WBUFL(buf, 8) = account_id;
- memcpy(WBUFP(buf, 12), mes, len);
+ WBUF_STRING(buf, 12, mes, len);
mapif_sendall(buf, len + 12);
-
- return 0;
}
//-------------------------------------------------------------------
@@ -419,7 +399,7 @@ int mapif_party_message(int party_id, int account_id, const char *mes, int len)
// パーティ
static
-int mapif_parse_CreateParty(int fd, int account_id, const char *name, const char *nick,
+void mapif_parse_CreateParty(int fd, int account_id, const char *name, const char *nick,
const char *map, int lv)
{
int i;
@@ -430,7 +410,7 @@ int mapif_parse_CreateParty(int fd, int account_id, const char *name, const char
{
PRINTF("int_party: illegal party name [%s]\n", name);
mapif_party_created(fd, account_id, NULL);
- return 0;
+ return;
}
}
@@ -438,16 +418,16 @@ int mapif_parse_CreateParty(int fd, int account_id, const char *name, const char
{
PRINTF("int_party: same name party exists [%s]\n", name);
mapif_party_created(fd, account_id, NULL);
- return 0;
+ return;
}
struct party p {};
p.party_id = party_newid++;
- memcpy(p.name, name, 24);
+ strzcpy(p.name, name, 24);
p.exp = 0;
p.item = 0;
p.member[0].account_id = account_id;
- memcpy(p.member[0].name, nick, 24);
- memcpy(p.member[0].map, map, 16);
+ strzcpy(p.member[0].name, nick, 24);
+ strzcpy(p.member[0].map, map, 16);
p.member[0].leader = 1;
p.member[0].online = 1;
p.member[0].lv = lv;
@@ -456,33 +436,29 @@ int mapif_parse_CreateParty(int fd, int account_id, const char *name, const char
mapif_party_created(fd, account_id, &p);
mapif_party_info(fd, &p);
-
- return 0;
}
// パーティ情報要求
static
-int mapif_parse_PartyInfo(int fd, int party_id)
+void mapif_parse_PartyInfo(int fd, int party_id)
{
struct party *p = party_db.search(party_id);
if (p != NULL)
mapif_party_info(fd, p);
else
mapif_party_noinfo(fd, party_id);
-
- return 0;
}
// パーティ追加要求
static
-int mapif_parse_PartyAddMember(int fd, int party_id, int account_id,
+void mapif_parse_PartyAddMember(int fd, int party_id, int account_id,
const char *nick, const char *map, int lv)
{
struct party *p = party_db.search(party_id);
if (p == NULL)
{
mapif_party_memberadded(fd, party_id, account_id, 1);
- return 0;
+ return;
}
for (int i = 0; i < MAX_PARTY; i++)
@@ -492,8 +468,8 @@ int mapif_parse_PartyAddMember(int fd, int party_id, int account_id,
int flag = 0;
p->member[i].account_id = account_id;
- memcpy(p->member[i].name, nick, 24);
- memcpy(p->member[i].map, map, 16);
+ strzcpy(p->member[i].name, nick, 24);
+ strzcpy(p->member[i].map, map, 16);
p->member[i].leader = 0;
p->member[i].online = 1;
p->member[i].lv = lv;
@@ -507,22 +483,20 @@ int mapif_parse_PartyAddMember(int fd, int party_id, int account_id,
}
if (flag)
mapif_party_optionchanged(fd, p, 0, 0);
- return 0;
+ return;
}
}
mapif_party_memberadded(fd, party_id, account_id, 1);
-
- return 0;
}
// パーティー設定変更要求
static
-int mapif_parse_PartyChangeOption(int fd, int party_id, int account_id,
+void mapif_parse_PartyChangeOption(int fd, int party_id, int account_id,
int exp, int item)
{
struct party *p = party_db.search(party_id);
if (p == NULL)
- return 0;
+ return;
p->exp = exp;
int flag = 0;
@@ -535,7 +509,6 @@ int mapif_parse_PartyChangeOption(int fd, int party_id, int account_id,
p->item = item;
mapif_party_optionchanged(fd, p, account_id, flag);
- return 0;
}
// パーティ脱退要求
@@ -550,7 +523,7 @@ void mapif_parse_PartyLeave(int, int party_id, int account_id)
continue;
mapif_party_leaved(party_id, account_id, p->member[i].name);
- memset(&p->member[i], 0, sizeof(struct party_member));
+ p->member[i] = party_member{};
if (party_check_empty(p) == 0)
mapif_party_info(-1, p); // まだ人がいるのでデータ送信
return;
@@ -572,7 +545,7 @@ void mapif_parse_PartyChangeMap(int fd, int party_id, int account_id,
continue;
int flag = 0;
- memcpy(p->member[i].map, map, 16);
+ strzcpy(p->member[i].map, map, 16);
p->member[i].online = online;
p->member[i].lv = lv;
mapif_party_membermoved(p, i);
@@ -602,17 +575,17 @@ void mapif_parse_BreakParty(int fd, int party_id)
// パーティメッセージ送信
static
-int mapif_parse_PartyMessage(int, int party_id, int account_id, const char *mes,
+void mapif_parse_PartyMessage(int, int party_id, int account_id, const char *mes,
int len)
{
- return mapif_party_message(party_id, account_id, mes, len);
+ mapif_party_message(party_id, account_id, mes, len);
}
// パーティチェック要求
static
-int mapif_parse_PartyCheck(int, int party_id, int account_id, const char *nick)
+void mapif_parse_PartyCheck(int, int party_id, int account_id, const char *nick)
{
- return party_check_conflict(party_id, account_id, nick);
+ party_check_conflict(party_id, account_id, nick);
}
// map server からの通信
diff --git a/src/char/int_storage.cpp b/src/char/int_storage.cpp
index ba55538..4067490 100644
--- a/src/char/int_storage.cpp
+++ b/src/char/int_storage.cpp
@@ -163,26 +163,24 @@ void inter_storage_delete(int account_id)
// 倉庫データの送信
static
-int mapif_load_storage(int fd, int account_id)
+void mapif_load_storage(int fd, int account_id)
{
struct storage *s = account2storage(account_id);
WFIFOW(fd, 0) = 0x3810;
WFIFOW(fd, 2) = sizeof(struct storage) + 8;
WFIFOL(fd, 4) = account_id;
- memcpy(WFIFOP(fd, 8), s, sizeof(struct storage));
+ WFIFO_STRUCT(fd, 8, *s);
WFIFOSET(fd, WFIFOW(fd, 2));
- return 0;
}
// 倉庫データ保存完了送信
static
-int mapif_save_storage_ack(int fd, int account_id)
+void mapif_save_storage_ack(int fd, int account_id)
{
WFIFOW(fd, 0) = 0x3811;
WFIFOL(fd, 2) = account_id;
WFIFOB(fd, 6) = 0;
WFIFOSET(fd, 7);
- return 0;
}
//---------------------------------------------------------
@@ -190,15 +188,14 @@ int mapif_save_storage_ack(int fd, int account_id)
// 倉庫データ要求受信
static
-int mapif_parse_LoadStorage(int fd)
+void mapif_parse_LoadStorage(int fd)
{
mapif_load_storage(fd, RFIFOL(fd, 2));
- return 0;
}
// 倉庫データ受信&保存
static
-int mapif_parse_SaveStorage(int fd)
+void mapif_parse_SaveStorage(int fd)
{
struct storage *s;
int account_id = RFIFOL(fd, 4);
@@ -211,10 +208,9 @@ int mapif_parse_SaveStorage(int fd)
else
{
s = account2storage(account_id);
- memcpy(s, RFIFOP(fd, 8), sizeof(struct storage));
+ RFIFO_STRUCT(fd, 8, *s);
mapif_save_storage_ack(fd, account_id);
}
- return 0;
}
// map server からの通信
diff --git a/src/char/inter.cpp b/src/char/inter.cpp
index 04523f7..fab50d2 100644
--- a/src/char/inter.cpp
+++ b/src/char/inter.cpp
@@ -24,8 +24,6 @@
// Existence time of Wisp/page data (60 seconds)
// that is the waiting time of answers of all map-servers
constexpr std::chrono::minutes WISDATA_TTL = std::chrono::minutes(1);
-// Number of elements of Wisp/page data deletion list
-constexpr int WISDELLIST_MAX = 256;
char inter_log_filename[1024] = "log/inter.log";
@@ -44,7 +42,8 @@ int party_share_level = 10;
// 受信パケット長リスト
static
-int inter_recv_packet_length[] = {
+int inter_recv_packet_length[] =
+{
-1, -1, 7, -1, -1, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
6, -1, 0, 0, 0, 0, 0, 0, 10, -1, 0, 0, 0, 0, 0, 0,
72, 6, 52, 14, 10, 29, 6, -1, 34, 0, 0, 0, 0, 0, 0, 0,
@@ -60,13 +59,13 @@ struct WisData
{
int id, fd, count;
tick_t tick;
- unsigned char src[24], dst[24];
+ char src[24], dst[24];
std::string msg;
};
static
Map<int, struct WisData> wis_db;
static
-int wis_dellist[WISDELLIST_MAX], wis_delnum;
+std::vector<int> wis_dellistv;
//--------------------------------------------------------
@@ -245,63 +244,60 @@ int inter_init(const char *file)
// GMメッセージ送信
static
-void mapif_GMmessage(const uint8_t *mes, int len)
+void mapif_GMmessage(const char *mes)
{
- unsigned char buf[len];
+ size_t str_len = strlen(mes) + 1;
+ size_t msg_len = str_len + 4;
+ uint8_t buf[msg_len];
WBUFW(buf, 0) = 0x3800;
- WBUFW(buf, 2) = len;
- memcpy(WBUFP(buf, 4), mes, len - 4);
- mapif_sendall(buf, len);
+ WBUFW(buf, 2) = msg_len;
+ WBUF_STRING(buf, 4, mes, str_len);
+ mapif_sendall(buf, msg_len);
}
// Wisp/page transmission to all map-server
static
-int mapif_wis_message(struct WisData *wd)
+void mapif_wis_message(struct WisData *wd)
{
- unsigned char buf[56 + wd->msg.size()];
+ size_t str_size = wd->msg.size() + 1;
+ uint8_t buf[56 + str_size];
WBUFW(buf, 0) = 0x3801;
- WBUFW(buf, 2) = 56 + wd->msg.size();
+ WBUFW(buf, 2) = 56 + str_size;
WBUFL(buf, 4) = wd->id;
- memcpy(WBUFP(buf, 8), wd->src, 24);
- memcpy(WBUFP(buf, 32), wd->dst, 24);
- memcpy(WBUFP(buf, 56), wd->msg.data(), wd->msg.size());
+ WBUF_STRING(buf, 8, wd->src, 24);
+ WBUF_STRING(buf, 32, wd->dst, 24);
+ WBUF_STRING(buf, 56, wd->msg.c_str(), str_size);
wd->count = mapif_sendall(buf, WBUFW(buf, 2));
-
- return 0;
}
// Wisp/page transmission result to map-server
static
-int mapif_wis_end(struct WisData *wd, int flag)
+void mapif_wis_end(struct WisData *wd, int flag)
{
- unsigned char buf[27];
+ uint8_t buf[27];
WBUFW(buf, 0) = 0x3802;
- memcpy(WBUFP(buf, 2), wd->src, 24);
+ WBUF_STRING(buf, 2, wd->src, 24);
WBUFB(buf, 26) = flag; // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target
mapif_send(wd->fd, buf, 27);
-
- return 0;
}
// アカウント変数送信
static
-int mapif_account_reg(int fd, const uint8_t *src)
+void mapif_account_reg(int fd)
{
- unsigned char buf[RBUFW(src, 2)];
-
- memcpy(WBUFP(buf, 0), src, RBUFW(src, 2));
+ size_t len = RFIFOW(fd, 2);
+ uint8_t buf[len];
+ RFIFO_BUF_CLONE(fd, buf, len);
WBUFW(buf, 0) = 0x3804;
mapif_sendallwos(fd, buf, WBUFW(buf, 2));
-
- return 0;
}
// アカウント変数要求返信
static
-int mapif_account_reg_reply(int fd, int account_id)
+void mapif_account_reg_reply(int fd, int account_id)
{
struct accreg *reg = accreg_db.search(account_id);
@@ -316,14 +312,12 @@ int mapif_account_reg_reply(int fd, int account_id)
int j, p;
for (j = 0, p = 8; j < reg->reg_num; j++, p += 36)
{
- memcpy(WFIFOP(fd, p), reg->reg[j].str, 32);
+ WFIFO_STRING(fd, p, reg->reg[j].str, 32);
WFIFOL(fd, p + 32) = reg->reg[j].value;
}
WFIFOW(fd, 2) = p;
}
WFIFOSET(fd, WFIFOW(fd, 2));
-
- return 0;
}
//--------------------------------------------------------
@@ -332,25 +326,23 @@ int mapif_account_reg_reply(int fd, int account_id)
static
void check_ttl_wisdata_sub(struct WisData *wd, tick_t tick)
{
- if (tick > wd->tick + WISDATA_TTL
- && wis_delnum < WISDELLIST_MAX)
- wis_dellist[wis_delnum++] = wd->id;
+ if (tick > wd->tick + WISDATA_TTL)
+ wis_dellistv.push_back(wd->id);
}
static
-int check_ttl_wisdata(void)
+void check_ttl_wisdata(void)
{
tick_t tick = gettick();
- int i;
- do
+ // this code looks silly now, but let's wait a bit to refactor properly
{
- wis_delnum = 0;
+ wis_dellistv.clear();
for (auto& pair : wis_db)
check_ttl_wisdata_sub(&pair.second, tick);
- for (i = 0; i < wis_delnum; i++)
+ for (int it : wis_dellistv)
{
- struct WisData *wd = wis_db.search(wis_dellist[i]);
+ struct WisData *wd = wis_db.search(it);
assert (wd);
PRINTF("inter: wis data id=%d time out : from %s to %s\n",
wd->id, wd->src, wd->dst);
@@ -359,9 +351,6 @@ int check_ttl_wisdata(void)
wis_db.erase(wd->id);
}
}
- while (wis_delnum >= WISDELLIST_MAX);
-
- return 0;
}
//--------------------------------------------------------
@@ -369,32 +358,40 @@ int check_ttl_wisdata(void)
// GMメッセージ送信
static
-int mapif_parse_GMmessage(int fd)
+void mapif_parse_GMmessage(int fd)
{
- mapif_GMmessage(static_cast<const uint8_t *>(RFIFOP(fd, 4)), RFIFOW(fd, 2));
+ size_t msg_len = RFIFOW(fd, 2);
+ size_t str_len = msg_len - 4;
+ char buf[str_len];
+ RFIFO_STRING(fd, 4, buf, str_len);
- return 0;
+ mapif_GMmessage(buf);
}
// Wisp/page request to send
static
-int mapif_parse_WisRequest(int fd)
+void mapif_parse_WisRequest(int fd)
{
static int wisid = 0;
if (RFIFOW(fd, 2) - 52 <= 0)
{ // normaly, impossible, but who knows...
PRINTF("inter: Wis message doesn't exist.\n");
- return 0;
+ return;
}
+ char from[24];
+ char to[24];
+ RFIFO_STRING(fd, 4, from, 24);
+ RFIFO_STRING(fd, 28, to, 24);
+
// search if character exists before to ask all map-servers
- const mmo_charstatus *mcs = search_character(static_cast<const char *>(RFIFOP(fd, 28)));
+ const mmo_charstatus *mcs = search_character(to);
if (!mcs)
{
- unsigned char buf[27];
+ uint8_t buf[27];
WBUFW(buf, 0) = 0x3802;
- memcpy(WBUFP(buf, 2), RFIFOP(fd, 4), 24);
+ WBUF_STRING(buf, 2, from, 24);
WBUFB(buf, 26) = 1; // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target
mapif_send(fd, buf, 27);
// Character exists. So, ask all map-servers
@@ -402,13 +399,13 @@ int mapif_parse_WisRequest(int fd)
else
{
// to be sure of the correct name, rewrite it
- strzcpy(static_cast<char *>(const_cast<void *>(RFIFOP(fd, 28))), mcs->name, 24);
+ strzcpy(to, mcs->name, 24);
// if source is destination, don't ask other servers.
- if (strcmp(static_cast<const char *>(RFIFOP(fd, 4)), static_cast<const char *>(RFIFOP(fd, 28))) == 0)
+ if (strcmp(from, to) == 0)
{
- unsigned char buf[27];
+ uint8_t buf[27];
WBUFW(buf, 0) = 0x3802;
- memcpy(WBUFP(buf, 2), RFIFOP(fd, 4), 24);
+ WBUF_STRING(buf, 2, from, 24);
WBUFB(buf, 26) = 1; // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target
mapif_send(fd, buf, 27);
}
@@ -422,16 +419,16 @@ int mapif_parse_WisRequest(int fd)
wd.id = ++wisid;
wd.fd = fd;
size_t len = RFIFOW(fd, 2) - 52;
- memcpy(wd.src, RFIFOP(fd, 4), 24);
- memcpy(wd.dst, RFIFOP(fd, 28), 24);
- wd.msg = std::string(static_cast<const char *>(RFIFOP(fd, 52)), len);
+ RFIFO_STRING(fd, 4, wd.src, 24);
+ RFIFO_STRING(fd, 28, wd.dst, 24);
+ char tmpbuf[len];
+ RFIFO_STRING(fd, 52, tmpbuf, len);
+ wd.msg = std::string(tmpbuf);
wd.tick = gettick();
wis_db.insert(wd.id, wd);
mapif_wis_message(&wd);
}
}
-
- return 0;
}
// Wisp/page transmission result
@@ -455,20 +452,20 @@ int mapif_parse_WisReply(int fd)
// Received wisp message from map-server for ALL gm (just copy the message and resends it to ALL map-servers)
static
-int mapif_parse_WisToGM(int fd)
+void mapif_parse_WisToGM(int fd)
{
- unsigned char buf[RFIFOW(fd, 2)]; // 0x3003/0x3803 <packet_len>.w <wispname>.24B <min_gm_level>.w <message>.?B
+ size_t len = RFIFOW(fd, 2);
+ uint8_t buf[len];
+ // 0x3003/0x3803 <packet_len>.w <wispname>.24B <min_gm_level>.w <message>.?B
- memcpy(WBUFP(buf, 0), RFIFOP(fd, 0), RFIFOW(fd, 2));
+ RFIFO_BUF_CLONE(fd, buf, len);
WBUFW(buf, 0) = 0x3803;
- mapif_sendall(buf, RFIFOW(fd, 2));
-
- return 0;
+ mapif_sendall(buf, len);
}
// アカウント変数保存要求
static
-int mapif_parse_AccReg(int fd)
+void mapif_parse_AccReg(int fd)
{
int j, p;
struct accreg *reg = accreg_db.search(RFIFOL(fd, 4));
@@ -483,22 +480,20 @@ int mapif_parse_AccReg(int fd)
for (j = 0, p = 8; j < ACCOUNT_REG_NUM && p < RFIFOW(fd, 2);
j++, p += 36)
{
- memcpy(reg->reg[j].str, RFIFOP(fd, p), 32);
+ RFIFO_STRING(fd, p, reg->reg[j].str, 32);
reg->reg[j].value = RFIFOL(fd, p + 32);
}
reg->reg_num = j;
// 他のMAPサーバーに送信
- mapif_account_reg(fd, static_cast<const uint8_t *>(RFIFOP(fd, 0)));
-
- return 0;
+ mapif_account_reg(fd);
}
// アカウント変数送信要求
static
-int mapif_parse_AccRegRequest(int fd)
+void mapif_parse_AccRegRequest(int fd)
{
- return mapif_account_reg_reply(fd, RFIFOL(fd, 2));
+ mapif_account_reg_reply(fd, RFIFOL(fd, 2));
}
//--------------------------------------------------------
diff --git a/src/common/const_array.hpp b/src/common/const_array.hpp
index 06045dc..a3a6d58 100644
--- a/src/common/const_array.hpp
+++ b/src/common/const_array.hpp
@@ -126,6 +126,8 @@ public:
};
// subclass just provides a simpler name and some conversions
+// Important note: it must be safe to dereference end, though
+// the value is unspecified.
class const_string : public const_array<char>
{
public:
diff --git a/src/common/md5calc.cpp b/src/common/md5calc.cpp
index 36f220d..f773c9f 100644
--- a/src/common/md5calc.cpp
+++ b/src/common/md5calc.cpp
@@ -3,6 +3,7 @@
#include <cstring>
#include "random.hpp"
+#include "utils.hpp"
#include "../poison.hpp"
@@ -43,7 +44,7 @@ const uint32_t T[64] =
static
uint32_t rotate_left(uint32_t val, unsigned shift)
{
- return val << shift | val >> (32-shift);
+ return val << shift | val >> (32 - shift);
}
static
@@ -117,45 +118,45 @@ void MD5_init(MD5_state* state)
void MD5_do_block(MD5_state* state, MD5_block block)
{
#define X block.data
-#define a state->val[(16-i)%4]
-#define b state->val[(17-i)%4]
-#define c state->val[(18-i)%4]
-#define d state->val[(19-i)%4]
+#define a state->val[(16 - i) % 4]
+#define b state->val[(17 - i) % 4]
+#define c state->val[(18 - i) % 4]
+#define d state->val[(19 - i) % 4]
// save the values
const MD5_state saved = *state;
// round 1
- for (int i=0; i<16; i++)
+ for (int i = 0; i < 16; i++)
{
#define k MD5_round1[i].k
#define s MD5_round1[i].s
- a = b + rotate_left(a + F(b,c,d) + X[k] + T[i+0x0], s);
+ a = b + rotate_left(a + F(b, c, d) + X[k] + T[i + 0x0], s);
#undef k
#undef s
}
// round 2
- for (int i=0; i<16; i++)
+ for (int i = 0; i < 16; i++)
{
#define k MD5_round2[i].k
#define s MD5_round2[i].s
- a = b + rotate_left(a + G(b,c,d) + X[k] + T[i+0x10], s);
+ a = b + rotate_left(a + G(b, c, d) + X[k] + T[i + 0x10], s);
#undef k
#undef s
}
// round 3
- for (int i=0; i<16; i++)
+ for (int i = 0; i < 16; i++)
{
#define k MD5_round3[i].k
#define s MD5_round3[i].s
- a = b + rotate_left(a + H(b,c,d) + X[k] + T[i+0x20], s);
+ a = b + rotate_left(a + H(b, c, d) + X[k] + T[i + 0x20], s);
#undef k
#undef s
}
// round 4
- for (int i=0; i<16; i++)
+ for (int i = 0; i < 16; i++)
{
#define k MD5_round4[i].k
#define s MD5_round4[i].s
- a = b + rotate_left(a + I(b,c,d) + X[k] + T[i+0x30], s);
+ a = b + rotate_left(a + I(b, c, d) + X[k] + T[i + 0x30], s);
#undef k
#undef s
}
@@ -172,8 +173,8 @@ void MD5_do_block(MD5_state* state, MD5_block block)
void MD5_to_bin(MD5_state state, uint8_t out[0x10])
{
- for (int i=0; i<0x10; i++)
- out[i] = state.val[i/4] >> 8*(i%4);
+ for (int i = 0; i < 0x10; i++)
+ out[i] = state.val[i / 4] >> 8 * (i % 4);
}
static
@@ -183,9 +184,9 @@ void MD5_to_str(MD5_state state, char out[0x21])
{
uint8_t bin[16];
MD5_to_bin(state, bin);
- for (int i=0; i<0x10; i++)
- out[2*i] = hex[bin[i] >> 4],
- out[2*i+1] = hex[bin[i] & 0xf];
+ for (int i = 0; i < 0x10; i++)
+ out[2 * i] = hex[bin[i] >> 4],
+ out[2 * i + 1] = hex[bin[i] & 0xf];
out[0x20] = '\0';
}
@@ -197,31 +198,31 @@ MD5_state MD5_from_string(const char* msg, const size_t msglen)
size_t rem = msglen;
while (rem >= 64)
{
- for (int i=0; i<0x10; i++)
- X[i] = msg[4*i+0] | msg[4*i+1]<<8 | msg[4*i+2]<<16 | msg[4*i+3]<<24;
+ for (int i = 0; i < 0x10; i++)
+ X[i] = msg[4 * i + 0] | msg[4 * i + 1] << 8 | msg[4 * i + 2] << 16 | msg[4 * i + 3] << 24;
MD5_do_block(&state, block);
msg += 64;
rem -= 64;
}
// now pad 1-512 bits + the 64-bit length - may be two blocks
uint8_t buf[0x40] = {};
- memcpy(buf, msg, rem);
+ really_memcpy(buf, reinterpret_cast<const uint8_t *>(msg), rem);
buf[rem] = 0x80; // a single one bit
if (64 - rem > 8)
{
- for (int i=0; i<8; i++)
- buf[0x38+i] = (static_cast<uint64_t>(msglen)*8) >> (i*8);
+ for (int i = 0; i < 8; i++)
+ buf[0x38 + i] = (static_cast<uint64_t>(msglen) * 8) >> (i * 8);
}
- for (int i=0; i<0x10; i++)
- X[i] = buf[4*i+0] | buf[4*i+1]<<8 | buf[4*i+2]<<16 | buf[4*i+3]<<24;
+ for (int i = 0; i < 0x10; i++)
+ X[i] = buf[4 * i + 0] | buf[4 * i + 1] << 8 | buf[4 * i + 2] << 16 | buf[4 * i + 3] << 24;
MD5_do_block(&state, block);
if (64 - rem <= 8)
{
- memset(buf,'\0', 0x38);
- for (int i=0; i<8; i++)
- buf[0x38+i] = (static_cast<uint64_t>(msglen)*8) >> (i*8);
- for (int i=0; i<0x10; i++)
- X[i] = buf[4*i+0] | buf[4*i+1]<<8 | buf[4*i+2]<<16 | buf[4*i+3]<<24;
+ really_memset0(buf, 0x38);
+ for (int i = 0; i < 8; i++)
+ buf[0x38 + i] = (static_cast<uint64_t>(msglen) * 8) >> (i * 8);
+ for (int i = 0; i < 0x10; i++)
+ X[i] = buf[4 * i + 0] | buf[4 * i + 1] << 8 | buf[4 * i + 2] << 16 | buf[4 * i + 3] << 24;
MD5_do_block(&state, block);
}
return state;
@@ -233,7 +234,8 @@ MD5_state MD5_from_cstring(const char* msg)
return MD5_from_string(msg, strlen(msg));
}
-MD5_state MD5_from_FILE(FILE* in) {
+MD5_state MD5_from_FILE(FILE* in)
+{
uint64_t total_len = 0;
uint8_t buf[0x40];
@@ -249,33 +251,33 @@ MD5_state MD5_from_FILE(FILE* in) {
size_t rv = fread(buf + block_len, 1, 0x40 - block_len, in);
if (!rv)
break;
- total_len += 8*rv; // in bits
+ total_len += 8 * rv; // in bits
block_len += rv;
if (block_len != 0x40)
continue;
- for (int i=0; i<0x10; i++)
- X[i] = buf[4*i+0] | buf[4*i+1]<<8 | buf[4*i+2]<<16 | buf[4*i+3]<<24;
+ for (int i = 0; i < 0x10; i++)
+ X[i] = buf[4 * i + 0] | buf[4 * i + 1] << 8 | buf[4 * i + 2] << 16 | buf[4 * i + 3] << 24;
MD5_do_block(&state, block);
block_len = 0;
}
// no more input, just pad and append the length
buf[block_len] = 0x80;
- memset(buf + block_len + 1, '\0', 0x40 - block_len - 1);
+ really_memset0(buf + block_len + 1, 0x40 - block_len - 1);
if (block_len < 0x38)
{
- for (int i=0; i<8; i++)
- buf[0x38+i] = total_len >> i*8;
+ for (int i = 0; i < 8; i++)
+ buf[0x38 + i] = total_len >> i * 8;
}
- for (int i=0; i<0x10; i++)
- X[i] = buf[4*i+0] | buf[4*i+1]<<8 | buf[4*i+2]<<16 | buf[4*i+3]<<24;
+ for (int i = 0; i < 0x10; i++)
+ X[i] = buf[4 * i + 0] | buf[4 * i + 1] << 8 | buf[4 * i + 2] << 16 | buf[4 * i + 3] << 24;
MD5_do_block(&state, block);
if (0x38 <= block_len)
{
- memset(buf, '\0', 0x38);
- for (int i=0; i<8; i++)
- buf[0x38+i] = total_len >> i*8;
- for (int i=0; i<0x10; i++)
- X[i] = buf[4*i+0] | buf[4*i+1]<<8 | buf[4*i+2]<<16 | buf[4*i+3]<<24;
+ really_memset0(buf, 0x38);
+ for (int i = 0; i < 8; i++)
+ buf[0x38 + i] = total_len >> i * 8;
+ for (int i = 0; i < 0x10; i++)
+ X[i] = buf[4 * i + 0] | buf[4 * i + 1] << 8 | buf[4 * i + 2] << 16 | buf[4 * i + 3] << 24;
MD5_do_block(&state, block);
}
return state;
@@ -291,19 +293,20 @@ const char *MD5_saltcrypt(const char *key, const char *salt)
// hash the key then the salt
// buf ends up as a 64-char NUL-terminated string
MD5_to_str(MD5_from_cstring(key), buf);
- MD5_to_str(MD5_from_cstring(salt), buf+32);
+ MD5_to_str(MD5_from_cstring(salt), buf + 32);
// Hash the buffer back into sbuf - this is stupid
// (luckily, putting the result into itself is safe)
- MD5_to_str(MD5_from_cstring(buf), buf+32);
+ MD5_to_str(MD5_from_cstring(buf), buf + 32);
static char obuf[33];
// This truncates the string, but we have to keep it like that for compatibility
- snprintf(obuf, 32, "!%s$%s", salt, buf+32);
+ snprintf(obuf, 32, "!%s$%s", salt, buf + 32);
return obuf;
}
-const char *make_salt(void) {
+const char *make_salt(void)
+{
static char salt[6];
for (int i = 0; i < 5; i++)
// 126 would probably actually be okay
@@ -311,7 +314,8 @@ const char *make_salt(void) {
return salt;
}
-bool pass_ok(const char *password, const char *crypted) {
+bool pass_ok(const char *password, const char *crypted)
+{
char buf[40];
strncpy(buf, crypted, 40);
char *salt = buf + 1;
@@ -324,15 +328,15 @@ bool pass_ok(const char *password, const char *crypted) {
// to return a hopefully unique masked IP.
struct in_addr MD5_ip(char *secret, struct in_addr ip)
{
- char ipbuf[32];
uint8_t obuf[16];
- union {
+ union
+ {
uint8_t bytes[4];
struct in_addr ip;
} conv;
// MD5sum a secret + the IP address
- memset(&ipbuf, 0, sizeof(ipbuf));
+ char ipbuf[32] {};
snprintf(ipbuf, sizeof(ipbuf), "%u%s", ip.s_addr, secret);
/// TODO stop it from being a cstring
MD5_to_bin(MD5_from_cstring(ipbuf), obuf);
diff --git a/src/common/mmo.hpp b/src/common/mmo.hpp
index a04fd34..14b8bac 100644
--- a/src/common/mmo.hpp
+++ b/src/common/mmo.hpp
@@ -78,7 +78,7 @@ struct item
struct point
{
- char map[24];
+ char map_[16];
short x, y;
};
diff --git a/src/common/socket.cpp b/src/common/socket.cpp
index 0ee8712..c509825 100644
--- a/src/common/socket.cpp
+++ b/src/common/socket.cpp
@@ -38,7 +38,7 @@ std::array<std::unique_ptr<struct socket_data>, FD_SETSIZE> session;
inline
void RFIFOFLUSH(int fd)
{
- memmove(&session[fd]->rdata[0], RFIFOP(fd, 0), RFIFOREST(fd));
+ really_memmove(&session[fd]->rdata[0], static_cast<const uint8_t *>(RFIFOP(fd, 0)), RFIFOREST(fd));
session[fd]->rdata_size = RFIFOREST(fd);
session[fd]->rdata_pos = 0;
}
@@ -97,7 +97,7 @@ void send_from_fifo(int fd)
session[fd]->wdata_size -= len;
if (session[fd]->wdata_size)
{
- memmove(&session[fd]->wdata[0], &session[fd]->wdata[len],
+ really_memmove(&session[fd]->wdata[0], &session[fd]->wdata[len],
session[fd]->wdata_size);
}
session[fd]->connected = 1;
diff --git a/src/common/socket.hpp b/src/common/socket.hpp
index d526379..ef7b193 100644
--- a/src/common/socket.hpp
+++ b/src/common/socket.hpp
@@ -102,6 +102,13 @@ FILE *fopen_(const char *path, const char *mode);
bool free_fds(void);
+template<class T>
+uint8_t *pod_addressof(T& structure)
+{
+ static_assert(is_trivially_copyable<T>::value, "Can only byte-copy POD-ish structs");
+ return &reinterpret_cast<uint8_t&>(structure);
+}
+
/// Check how much can be read
@@ -131,6 +138,21 @@ uint32_t RFIFOL(int fd, size_t pos)
{
return *static_cast<const uint32_t *>(RFIFOP(fd, pos));
}
+template<class T>
+void RFIFO_STRUCT(int fd, size_t pos, T& structure)
+{
+ really_memcpy(pod_addressof(structure), static_cast<const uint8_t *>(RFIFOP(fd, pos)), sizeof(T));
+}
+inline
+void RFIFO_STRING(int fd, size_t pos, char *out, size_t len)
+{
+ strzcpy(out, static_cast<const char *>(RFIFOP(fd, pos)), len);
+}
+inline
+void RFIFO_BUF_CLONE(int fd, uint8_t *buf, size_t len)
+{
+ really_memcpy(buf, static_cast<const uint8_t *>(RFIFOP(fd, 0)), len);
+}
/// Done reading
void RFIFOSKIP(int fd, size_t len);
@@ -156,6 +178,16 @@ uint32_t RBUFL(const uint8_t *p, size_t pos)
{
return *static_cast<const uint32_t *>(RBUFP(p, pos));
}
+template<class T>
+void RBUF_STRUCT(const uint8_t *p, size_t pos, T& structure)
+{
+ really_memcpy(pod_addressof(structure), p + pos, sizeof(T));
+}
+inline
+void RBUF_STRING(const uint8_t *p, size_t pos, char *out, size_t len)
+{
+ strzcpy(out, static_cast<const char *>(RBUFP(p, pos)), len);
+}
/// Unused - check how much data can be written
@@ -185,6 +217,29 @@ uint32_t& WFIFOL(int fd, size_t pos)
{
return *static_cast<uint32_t *>(WFIFOP(fd, pos));
}
+template<class T>
+void WFIFO_STRUCT(int fd, size_t pos, T& structure)
+{
+ really_memcpy(static_cast<uint8_t *>(WFIFOP(fd, pos)), pod_addressof(structure), sizeof(T));
+}
+inline
+void WFIFO_STRING(int fd, size_t pos, const char *s, size_t len)
+{
+ strzcpy(static_cast<char *>(WFIFOP(fd, pos)), s, len);
+}
+inline
+void WFIFO_ZERO(int fd, size_t pos, size_t len)
+{
+ uint8_t *b = static_cast<uint8_t *>(WFIFOP(fd, pos));
+ uint8_t *e = b + len;
+ std::fill(b, e, '\0');
+}
+inline
+void WFIFO_BUF_CLONE(int fd, const uint8_t *buf, size_t len)
+{
+ really_memcpy(static_cast<uint8_t *>(WFIFOP(fd, 0)), buf, len);
+}
+
/// Finish writing
void WFIFOSET(int fd, size_t len);
@@ -209,5 +264,29 @@ uint32_t& WBUFL(uint8_t *p, size_t pos)
{
return *static_cast<uint32_t *>(WBUFP(p, pos));
}
+template<class T>
+void WBUF_STRUCT(uint8_t *p, size_t pos, T& structure)
+{
+ really_memcpy(p + pos, pod_addressof(structure), sizeof(T));
+}
+inline
+void WBUF_STRING(uint8_t *p, size_t pos, const char *s, size_t len)
+{
+ strzcpy(static_cast<char *>(WBUFP(p, pos)), s, len);
+}
+inline
+void WBUF_ZERO(uint8_t *p, size_t pos, size_t len)
+{
+ uint8_t *b = static_cast<uint8_t *>(WBUFP(p, pos));
+ uint8_t *e = b + len;
+ std::fill(b, e, '\0');
+}
+
+inline
+void RFIFO_WFIFO_CLONE(int rfd, int wfd, size_t len)
+{
+ really_memcpy(static_cast<uint8_t *>(WFIFOP(wfd, 0)),
+ static_cast<const uint8_t *>(RFIFOP(rfd, 0)), len);
+}
#endif // SOCKET_HPP
diff --git a/src/common/utils.hpp b/src/common/utils.hpp
index caa39ed..cd45aa1 100644
--- a/src/common/utils.hpp
+++ b/src/common/utils.hpp
@@ -7,11 +7,21 @@
#include <cstring>
#include <string>
+#include <type_traits>
#include "const_array.hpp"
#include "operators.hpp"
#include "utils2.hpp"
+template<class T>
+struct is_trivially_copyable
+: std::integral_constant<bool,
+ // come back when GCC actually implements the public traits properly
+ __has_trivial_copy(T)
+ && __has_trivial_assign(T)
+ && __has_trivial_destructor(T)>
+{};
+
int remove_control_chars(char *str);
int e_mail_check(const char *email);
int config_switch (const char *str);
@@ -25,10 +35,37 @@ void strzcpy(char *dest, const char *src, size_t n)
if (n)
{
strncpy(dest, src, n);
- dest[n-1] = '\0';
+ dest[n - 1] = '\0';
}
}
+inline
+void really_memcpy(uint8_t *dest, const uint8_t *src, size_t n)
+{
+ memcpy(dest, src, n);
+}
+
+inline
+void really_memmove(uint8_t *dest, const uint8_t *src, size_t n)
+{
+ memmove(dest, src, n);
+}
+
+inline
+void really_memset0(uint8_t *dest, size_t n)
+{
+ memset(dest, '\0', n);
+}
+template<class T>
+void really_memzero_this(T *v)
+{
+ static_assert(is_trivially_copyable<T>::value, "only for mostly-pod types");
+ static_assert(std::is_class<T>::value || std::is_union<T>::value, "Only for user-defined structures (for now)");
+ memset(v, '\0', sizeof(*v));
+}
+template<class T, size_t n>
+void really_memzero_this(T (&)[n]) = delete;
+
// Exists in place of time_t, to give it a predictable printf-format.
// (on x86 and amd64, time_t == long, but not on x32)
static_assert(sizeof(long long) >= sizeof(time_t), "long long >= time_t");
diff --git a/src/ladmin/ladmin.cpp b/src/ladmin/ladmin.cpp
index f5940dd..c5a98fd 100644
--- a/src/ladmin/ladmin.cpp
+++ b/src/ladmin/ladmin.cpp
@@ -323,14 +323,13 @@ int verify_accountname(const char *account_name)
static
int typepasswd(char *password)
{
- char password1[1023], password2[1023];
+ char password1[1023] {};
+ char password2[1023] {};
int letter;
int i;
LADMIN_LOG("No password was given. Request to obtain a password.\n");
- memset(password1, '\0', sizeof(password1));
- memset(password2, '\0', sizeof(password2));
PRINTF("\033[1;36m Type the password > \033[0;32;42m");
i = 0;
while ((letter = getchar()) != '\n')
@@ -524,11 +523,9 @@ int check_command(char *command)
static
void display_help(const char *param)
{
- char command[1023];
+ char command[1023] {};
int i;
- memset(command, '\0', sizeof(command));
-
if (sscanf(param, "%s ", command) < 1 || strlen(command) == 0)
strcpy(command, ""); // any value that is not a command
@@ -867,13 +864,10 @@ void display_help(const char *param)
static
int addaccount(const char *param, int emailflag)
{
- char name[1023], sex[1023], email[1023], password[1023];
-// int i;
-
- memset(name, '\0', sizeof(name));
- memset(sex, '\0', sizeof(sex));
- memset(email, '\0', sizeof(email));
- memset(password, '\0', sizeof(password));
+ char name[1023] {};
+ char sex[1023] {};
+ char email[1023] {};
+ char password[1023] {};
if (emailflag == 0)
{ // add command
@@ -951,10 +945,10 @@ int addaccount(const char *param, int emailflag)
LADMIN_LOG("Request to login-server to create an account.\n");
WFIFOW(login_fd, 0) = 0x7930;
- memcpy(WFIFOP(login_fd, 2), name, 24);
- memcpy(WFIFOP(login_fd, 26), password, 24);
+ WFIFO_STRING(login_fd, 2, name, 24);
+ WFIFO_STRING(login_fd, 26, password, 24);
WFIFOB(login_fd, 50) = sex[0];
- memcpy(WFIFOP(login_fd, 51), email, 40);
+ WFIFO_STRING(login_fd, 51, email, 40);
WFIFOSET(login_fd, 91);
bytes_to_read = 1;
@@ -967,13 +961,12 @@ int addaccount(const char *param, int emailflag)
static
int banaddaccount(const char *param)
{
- char name[1023], modif[1023];
+ char name[1023] {};
+ char modif[1023] {};
int year, month, day, hour, minute, second;
const char *p_modif;
int value, i;
- memset(name, '\0', sizeof(name));
- memset(modif, '\0', sizeof(modif));
year = month = day = hour = minute = second = 0;
if (sscanf(param, "\"%[^\"]\" %[^\r\n]", name, modif) < 2 &&
@@ -1114,7 +1107,7 @@ int banaddaccount(const char *param)
LADMIN_LOG("Request to login-server to modify a ban date/time.\n");
WFIFOW(login_fd, 0) = 0x794c;
- memcpy(WFIFOP(login_fd, 2), name, 24);
+ WFIFO_STRING(login_fd, 2, name, 24);
WFIFOW(login_fd, 26) = year;
WFIFOW(login_fd, 28) = month;
WFIFOW(login_fd, 30) = day;
@@ -1232,7 +1225,7 @@ int bansetaccountsub(const char *name, const char *date, const char *time_)
LADMIN_LOG("Request to login-server to set a ban.\n");
WFIFOW(login_fd, 0) = 0x794a;
- memcpy(WFIFOP(login_fd, 2), name, 24);
+ WFIFO_STRING(login_fd, 2, name, 24);
WFIFOL(login_fd, 26) = static_cast<time_t>(ban_until_time);
WFIFOSET(login_fd, 30);
bytes_to_read = 1;
@@ -1246,11 +1239,9 @@ int bansetaccountsub(const char *name, const char *date, const char *time_)
static
int banaccount(const char *param)
{
- char name[1023], date[1023], time_[1023];
-
- memset(name, '\0', sizeof(name));
- memset(date, '\0', sizeof(date));
- memset(time_, '\0', sizeof(time_));
+ char name[1023] {};
+ char date[1023] {};
+ char time_[1023] {};
if (sscanf(param, "%s %s \"%[^\"]\"", date, time_, name) < 3 &&
sscanf(param, "%s %s '%[^']'", date, time_, name) < 3 &&
@@ -1275,11 +1266,9 @@ int banaccount(const char *param)
static
int bansetaccount(const char *param)
{
- char name[1023], date[1023], time_[1023];
-
- memset(name, '\0', sizeof(name));
- memset(date, '\0', sizeof(date));
- memset(time_, '\0', sizeof(time_));
+ char name[1023] {};
+ char date[1023] {};
+ char time_[1023] {};
if (sscanf(param, "\"%[^\"]\" %s %[^\r\n]", name, date, time_) < 2 && // if date = 0, time_ can be void
sscanf(param, "'%[^']' %s %[^\r\n]", name, date, time_) < 2 && // if date = 0, time_ can be void
@@ -1307,9 +1296,7 @@ int bansetaccount(const char *param)
static
int unbanaccount(const char *param)
{
- char name[1023];
-
- memset(name, '\0', sizeof(name));
+ char name[1023] {};
if (strlen(param) == 0 ||
(sscanf(param, "\"%[^\"]\"", name) < 1 &&
@@ -1336,10 +1323,8 @@ int unbanaccount(const char *param)
static
int checkaccount(const char *param)
{
- char name[1023], password[1023];
-
- memset(name, '\0', sizeof(name));
- memset(password, '\0', sizeof(password));
+ char name[1023] {};
+ char password[1023] {};
if (sscanf(param, "\"%[^\"]\" %[^\r\n]", name, password) < 1 && // password can be void
sscanf(param, "'%[^']' %[^\r\n]", name, password) < 1 && // password can be void
@@ -1367,8 +1352,8 @@ int checkaccount(const char *param)
LADMIN_LOG("Request to login-server to check a password.\n");
WFIFOW(login_fd, 0) = 0x793a;
- memcpy(WFIFOP(login_fd, 2), name, 24);
- memcpy(WFIFOP(login_fd, 26), password, 24);
+ WFIFO_STRING(login_fd, 2, name, 24);
+ WFIFO_STRING(login_fd, 26, password, 24);
WFIFOSET(login_fd, 50);
bytes_to_read = 1;
@@ -1381,13 +1366,10 @@ int checkaccount(const char *param)
static
int delaccount(const char *param)
{
- char name[1023];
+ char name[1023] {};
char letter;
- char confirm[1023];
int i;
- memset(name, '\0', sizeof(name));
-
if (strlen(param) == 0 ||
(sscanf(param, "\"%[^\"]\"", name) < 1 &&
sscanf(param, "'%[^']'", name) < 1 &&
@@ -1404,13 +1386,13 @@ int delaccount(const char *param)
return 102;
}
- memset(confirm, '\0', sizeof(confirm));
+ char confirm[1023] {};
while (confirm[0] != 'n'
&& confirm[0] != 'y')
{
- PRINTF("\033[1;36m ** Are you really sure to DELETE account [$userid]? (y/n) > \033[0m");
+ PRINTF("\033[1;36m ** Are you really sure to DELETE account [%s]? (y/n) > \033[0m", name);
fflush(stdout);
- memset(confirm, '\0', sizeof(confirm));
+ strzcpy(confirm, "", sizeof(confirm));
i = 0;
while ((letter = getchar()) != '\n')
confirm[i++] = letter;
@@ -1426,7 +1408,7 @@ int delaccount(const char *param)
LADMIN_LOG("Request to login-server to delete an acount.\n");
WFIFOW(login_fd, 0) = 0x7932;
- memcpy(WFIFOP(login_fd, 2), name, 24);
+ WFIFO_STRING(login_fd, 2, name, 24);
WFIFOSET(login_fd, 26);
bytes_to_read = 1;
@@ -1439,10 +1421,8 @@ int delaccount(const char *param)
static
int changeemail(const char *param)
{
- char name[1023], email[1023];
-
- memset(name, '\0', sizeof(name));
- memset(email, '\0', sizeof(email));
+ char name[1023] {};
+ char email[1023] {};
if (sscanf(param, "\"%[^\"]\" %[^\r\n]", name, email) < 2 &&
sscanf(param, "'%[^']' %[^\r\n]", name, email) < 2 &&
@@ -1487,8 +1467,8 @@ int changeemail(const char *param)
LADMIN_LOG("Request to login-server to change an email.\n");
WFIFOW(login_fd, 0) = 0x7940;
- memcpy(WFIFOP(login_fd, 2), name, 24);
- memcpy(WFIFOP(login_fd, 26), email, 40);
+ WFIFO_STRING(login_fd, 2, name, 24);
+ WFIFO_STRING(login_fd, 26, email, 40);
WFIFOSET(login_fd, 66);
bytes_to_read = 1;
@@ -1516,11 +1496,8 @@ int getlogincount(void)
static
int changegmlevel(const char *param)
{
- char name[1023];
- int GM_level;
-
- memset(name, '\0', sizeof(name));
- GM_level = 0;
+ char name[1023] {};
+ int GM_level = 0;
if (sscanf(param, "\"%[^\"]\" %d", name, &GM_level) < 1 &&
sscanf(param, "'%[^']' %d", name, &GM_level) < 1 &&
@@ -1549,7 +1526,7 @@ int changegmlevel(const char *param)
LADMIN_LOG("Request to login-server to change a GM level.\n");
WFIFOW(login_fd, 0) = 0x793e;
- memcpy(WFIFOP(login_fd, 2), name, 24);
+ WFIFO_STRING(login_fd, 2, name, 24);
WFIFOB(login_fd, 26) = GM_level;
WFIFOSET(login_fd, 27);
bytes_to_read = 1;
@@ -1563,9 +1540,7 @@ int changegmlevel(const char *param)
static
int idaccount(const char *param)
{
- char name[1023];
-
- memset(name, '\0', sizeof(name));
+ char name[1023] {};
if (strlen(param) == 0 ||
(sscanf(param, "\"%[^\"]\"", name) < 1 &&
@@ -1586,7 +1561,7 @@ int idaccount(const char *param)
LADMIN_LOG("Request to login-server to know an account id.\n");
WFIFOW(login_fd, 0) = 0x7944;
- memcpy(WFIFOP(login_fd, 2), name, 24);
+ WFIFO_STRING(login_fd, 2, name, 24);
WFIFOSET(login_fd, 26);
bytes_to_read = 1;
@@ -1639,9 +1614,10 @@ int sendbroadcast(short type, const char *message)
WFIFOW(login_fd, 0) = 0x794e;
WFIFOW(login_fd, 2) = type;
- WFIFOL(login_fd, 4) = strlen(message) + 1;
- memcpy(WFIFOP(login_fd, 8), message, strlen(message) + 1);
- WFIFOSET(login_fd, 8 + strlen(message) + 1);
+ size_t len = strlen(message) + 1;
+ WFIFOL(login_fd, 4) = len;
+ WFIFO_STRING(login_fd, 8, message, len);
+ WFIFOSET(login_fd, 8 + len);
bytes_to_read = 1;
return 0;
@@ -1747,10 +1723,8 @@ int itemfrob(const char *param)
static
int changememo(const char *param)
{
- char name[1023], memo[1023];
-
- memset(name, '\0', sizeof(name));
- memset(memo, '\0', sizeof(memo));
+ char name[1023] {};
+ char memo[1023] {};
if (sscanf(param, "\"%[^\"]\" %[^\r\n]", name, memo) < 1 && // memo can be void
sscanf(param, "'%[^']' %[^\r\n]", name, memo) < 1 && // memo can be void
@@ -1767,23 +1741,24 @@ int changememo(const char *param)
return 102;
}
- if (strlen(memo) > 254)
+ size_t len = strlen(memo);
+ size_t len1 = len + 1;
+ if (len > 254)
{
- PRINTF("Memo is too long (%zu characters).\n", strlen(memo));
+ PRINTF("Memo is too long (%zu characters).\n", len);
PRINTF("Please input a memo of 254 bytes at the maximum.\n");
LADMIN_LOG("Email is too long (%zu characters). Please input a memo of 254 bytes at the maximum.\n",
- strlen(memo));
+ len);
return 102;
}
LADMIN_LOG("Request to login-server to change a memo.\n");
WFIFOW(login_fd, 0) = 0x7942;
- memcpy(WFIFOP(login_fd, 2), name, 24);
- WFIFOW(login_fd, 26) = strlen(memo);
- if (strlen(memo) > 0)
- memcpy(WFIFOP(login_fd, 28), memo, strlen(memo));
- WFIFOSET(login_fd, 28 + strlen(memo));
+ WFIFO_STRING(login_fd, 2, name, 24);
+ WFIFOW(login_fd, 26) = len1;
+ WFIFO_STRING(login_fd, 28, memo, len);
+ WFIFOSET(login_fd, 28 + len1);
bytes_to_read = 1;
return 0;
@@ -1819,10 +1794,8 @@ int nameaccount(int id)
static
int changepasswd(const char *param)
{
- char name[1023], password[1023];
-
- memset(name, '\0', sizeof(name));
- memset(password, '\0', sizeof(password));
+ char name[1023] {};
+ char password[1023] {};
if (sscanf(param, "\"%[^\"]\" %[^\r\n]", name, password) < 1 &&
sscanf(param, "'%[^']' %[^\r\n]", name, password) < 1 &&
@@ -1850,8 +1823,8 @@ int changepasswd(const char *param)
LADMIN_LOG("Request to login-server to change a password.\n");
WFIFOW(login_fd, 0) = 0x7934;
- memcpy(WFIFOP(login_fd, 2), name, 24);
- memcpy(WFIFOP(login_fd, 26), password, 24);
+ WFIFO_STRING(login_fd, 2, name, 24);
+ WFIFO_STRING(login_fd, 26, password, 24);
WFIFOSET(login_fd, 50);
bytes_to_read = 1;
@@ -1883,10 +1856,8 @@ int reloadGM(char *params)
static
int changesex(const char *param)
{
- char name[1023], sex[1023];
-
- memset(name, '\0', sizeof(name));
- memset(sex, '\0', sizeof(sex));
+ char name[1023] {};
+ char sex[1023] {};
if (sscanf(param, "\"%[^\"]\" %[^\r\n]", name, sex) < 2 &&
sscanf(param, "'%[^']' %[^\r\n]", name, sex) < 2 &&
@@ -1915,7 +1886,7 @@ int changesex(const char *param)
LADMIN_LOG("Request to login-server to change a sex.\n");
WFIFOW(login_fd, 0) = 0x793c;
- memcpy(WFIFOP(login_fd, 2), name, 24);
+ WFIFO_STRING(login_fd, 2, name, 24);
WFIFOB(login_fd, 26) = sex[0];
WFIFOSET(login_fd, 27);
bytes_to_read = 1;
@@ -1930,10 +1901,7 @@ int changesex(const char *param)
static
int changestatesub(const char *name, int state, const char *error_message7)
{
- char error_message[1023]; // need to use, because we can modify error_message7
-
- memset(error_message, '\0', sizeof(error_message));
- strncpy(error_message, error_message7, sizeof(error_message) - 1);
+ const char *error_message = error_message7;
if ((state < 0 || state > 9) && state != 100)
{ // Valid values: 0: ok, or value of the 0x006a packet + 1
@@ -1959,7 +1927,7 @@ int changestatesub(const char *name, int state, const char *error_message7)
if (state != 7)
{
- strcpy(error_message, "-");
+ error_message = "-";
}
else
{
@@ -1980,9 +1948,9 @@ int changestatesub(const char *name, int state, const char *error_message7)
LADMIN_LOG("Request to login-server to change a state.\n");
WFIFOW(login_fd, 0) = 0x7936;
- memcpy(WFIFOP(login_fd, 2), name, 24);
+ WFIFO_STRING(login_fd, 2, name, 24);
WFIFOL(login_fd, 26) = state;
- memcpy(WFIFOP(login_fd, 30), error_message, 20);
+ WFIFO_STRING(login_fd, 30, error_message, 20);
WFIFOSET(login_fd, 50);
bytes_to_read = 1;
@@ -1995,16 +1963,12 @@ int changestatesub(const char *name, int state, const char *error_message7)
static
int changestate(const char *param)
{
- char name[1023], error_message[1023];
+ char name[1023] {};
+ char error_message[1023] {};
int state;
- memset(name, '\0', sizeof(name));
- memset(error_message, '\0', sizeof(error_message));
-
- if (sscanf(param, "\"%[^\"]\" %d %[^\r\n]", name, &state, error_message)
- < 2
- && sscanf(param, "'%[^']' %d %[^\r\n]", name, &state,
- error_message) < 2
+ if (sscanf(param, "\"%[^\"]\" %d %[^\r\n]", name, &state, error_message) < 2
+ && sscanf(param, "'%[^']' %d %[^\r\n]", name, &state, error_message) < 2
&& sscanf(param, "%s %d %[^\r\n]", name, &state, error_message) < 2)
{
PRINTF("Please input an account name and a state.\n");
@@ -2025,9 +1989,7 @@ int changestate(const char *param)
static
int unblockaccount(const char *param)
{
- char name[1023];
-
- memset(name, '\0', sizeof(name));
+ char name[1023] {};
if (strlen(param) == 0 ||
(sscanf(param, "\"%[^\"]\"", name) < 1 &&
@@ -2052,9 +2014,7 @@ int unblockaccount(const char *param)
static
int blockaccount(const char *param)
{
- char name[1023];
-
- memset(name, '\0', sizeof(name));
+ char name[1023] {};
if (strlen(param) == 0 ||
(sscanf(param, "\"%[^\"]\"", name) < 1 &&
@@ -2079,13 +2039,12 @@ int blockaccount(const char *param)
static
int timeaddaccount(const char *param)
{
- char name[1023], modif[1023];
+ char name[1023] {};
+ char modif[1023] {};
int year, month, day, hour, minute, second;
const char *p_modif;
int value, i;
- memset(name, '\0', sizeof(name));
- memset(modif, '\0', sizeof(modif));
year = month = day = hour = minute = second = 0;
if (sscanf(param, "\"%[^\"]\" %[^\r\n]", name, modif) < 2 &&
@@ -2226,7 +2185,7 @@ int timeaddaccount(const char *param)
LADMIN_LOG("Request to login-server to modify a time limit.\n");
WFIFOW(login_fd, 0) = 0x7950;
- memcpy(WFIFOP(login_fd, 2), name, 24);
+ WFIFO_STRING(login_fd, 2, name, 24);
WFIFOW(login_fd, 26) = year;
WFIFOW(login_fd, 28) = month;
WFIFOW(login_fd, 30) = day;
@@ -2245,12 +2204,11 @@ int timeaddaccount(const char *param)
static
int timesetaccount(const char *param)
{
- char name[1023], date[1023], time_[1023];
+ char name[1023] {};
+ char date[1023] {};
+ char time_[1023] {};
int year, month, day, hour, minute, second;
- memset(name, '\0', sizeof(name));
- memset(date, '\0', sizeof(date));
- memset(time_, '\0', sizeof(time_));
year = month = day = hour = minute = second = 0;
// # of seconds 1/1/1970 (timestamp): Validity limit of the account (0 = unlimited)
@@ -2361,7 +2319,7 @@ int timesetaccount(const char *param)
LADMIN_LOG("Request to login-server to set a time limit.\n");
WFIFOW(login_fd, 0) = 0x7948;
- memcpy(WFIFOP(login_fd, 2), name, 24);
+ WFIFO_STRING(login_fd, 2, name, 24);
WFIFOL(login_fd, 26) = static_cast<time_t>(connect_until_time);
WFIFOSET(login_fd, 30);
bytes_to_read = 1;
@@ -2375,9 +2333,7 @@ int timesetaccount(const char *param)
static
int whoaccount(const char *param)
{
- char name[1023];
-
- memset(name, '\0', sizeof(name));
+ char name[1023] {};
if (strlen(param) == 0 ||
(sscanf(param, "\"%[^\"]\"", name) < 1 &&
@@ -2397,7 +2353,7 @@ int whoaccount(const char *param)
LADMIN_LOG("Request to login-server to obtain information about an account (by its name).\n");
WFIFOW(login_fd, 0) = 0x7952;
- memcpy(WFIFOP(login_fd, 2), name, 24);
+ WFIFO_STRING(login_fd, 2, name, 24);
WFIFOSET(login_fd, 26);
bytes_to_read = 1;
@@ -2448,7 +2404,7 @@ int prompt(void)
fflush(stdout);
// get command and parameter
- memset(buf, '\0', sizeof(buf));
+ strzcpy(buf, "", sizeof(buf));
fflush(stdin);
if (!fgets(buf, 1023, stdin))
exit(0);
@@ -2510,10 +2466,9 @@ int prompt(void)
i--;
}
- char command[1024];
+ char command[1024] {};
// extract command name and parameters
- memset(command, '\0', sizeof(command));
- memset(parameters, '\0', sizeof(parameters));
+ strzcpy(parameters, "", sizeof(parameters));
sscanf(buf, "%1023s %[^\n]", command, parameters);
command[1023] = '\0';
parameters[1023] = '\0';
@@ -2752,24 +2707,24 @@ void parse_fromlogin(int fd)
return;
{
char md5str[64] = "";
- uint8_t md5bin[32], md5key[RFIFOW(fd, 2) - 4 + 1];
- memcpy(md5key, RFIFOP(fd, 4), RFIFOW(fd, 2) - 4);
- md5key[sizeof(md5key) - 1] = '0';
+ size_t key_len = RFIFOW(fd, 2) - 4;
+ uint8_t md5bin[32];
+ char md5key[key_len];
+ RFIFO_STRING(fd, 4, md5key, key_len);
if (passenc == 1)
{
- strncpy(md5str, static_cast<const char *>(RFIFOP(fd, 4)), RFIFOW(fd, 2) - 4);
+ strcpy(md5str, md5key);
strcat(md5str, loginserveradminpassword);
}
else if (passenc == 2)
{
- strncpy(md5str, loginserveradminpassword,
- sizeof(loginserveradminpassword));
- strcat(md5str, static_cast<const char *>(RFIFOP(fd, 4)));
+ strcpy(md5str, loginserveradminpassword);
+ strcat(md5str, md5key);
}
MD5_to_bin(MD5_from_cstring(md5str), md5bin);
WFIFOW(login_fd, 0) = 0x7918; // Request for administation login (encrypted password)
WFIFOW(login_fd, 2) = passenc; // Encrypted type
- memcpy(WFIFOP(login_fd, 4), md5bin, 16);
+ really_memcpy(static_cast<uint8_t *>(WFIFOP(login_fd, 4)), md5bin, 16);
WFIFOSET(login_fd, 20);
Iprintf("Receiving of the MD5 key.\n");
LADMIN_LOG("Receiving of the MD5 key.\n");
@@ -2840,10 +2795,8 @@ void parse_fromlogin(int fd)
{
int j;
char userid[24];
- char lower_userid[24];
- memcpy(userid, RFIFOP(fd, i + 5), sizeof(userid));
- userid[sizeof(userid) - 1] = '\0';
- memset(lower_userid, '\0', sizeof(lower_userid));
+ char lower_userid[24] {};
+ RFIFO_STRING(fd, i + 5, userid, 24);
for (j = 0; userid[j]; j++)
lower_userid[j] = tolower(userid[j]);
list_first = RFIFOL(fd, i) + 1;
@@ -3051,8 +3004,6 @@ void parse_fromlogin(int fd)
return;
{
// Get length of the received packet
- int i;
- char name[20];
LADMIN_LOG(" Receiving of the number of online players.\n");
// Read information of the servers
if (RFIFOW(fd, 2) < 5)
@@ -3063,10 +3014,10 @@ void parse_fromlogin(int fd)
{
PRINTF(" Number of online players (server: number).\n");
// Displaying of result
- for (i = 4; i < RFIFOW(fd, 2); i += 32)
+ for (int i = 4; i < RFIFOW(fd, 2); i += 32)
{
- memcpy(name, RFIFOP(fd, i + 6), sizeof(name));
- name[sizeof(name) - 1] = '\0';
+ char name[20];
+ RFIFO_STRING(fd, i + 6, name, 20);
PRINTF(" %-20s : %5d\n", name,
RFIFOW(fd, i + 26));
}
@@ -3401,21 +3352,14 @@ void parse_fromlogin(int fd)
last_ip[16], email[40], memo[255];
TimeT ban_until_time; // # of seconds 1/1/1970 (timestamp): ban time limit of the account (0 = no ban)
TimeT connect_until_time; // # of seconds 1/1/1970 (timestamp): Validity limit of the account (0 = unlimited)
- memcpy(userid, RFIFOP(fd, 7), sizeof(userid));
- userid[sizeof(userid) - 1] = '\0';
- memcpy(error_message, RFIFOP(fd, 40),
- sizeof(error_message));
- error_message[sizeof(error_message) - 1] = '\0';
- memcpy(lastlogin, RFIFOP(fd, 60), sizeof(lastlogin));
- lastlogin[sizeof(lastlogin) - 1] = '\0';
- memcpy(last_ip, RFIFOP(fd, 84), sizeof(last_ip));
- last_ip[sizeof(last_ip) - 1] = '\0';
- memcpy(email, RFIFOP(fd, 100), sizeof(email));
- email[sizeof(email) - 1] = '\0';
+ RFIFO_STRING(fd, 7, userid, 24);
+ RFIFO_STRING(fd, 40, error_message, 20);
+ RFIFO_STRING(fd, 60, lastlogin, 24);
+ RFIFO_STRING(fd, 84, last_ip, 16);
+ RFIFO_STRING(fd, 100, email, 40);
connect_until_time = static_cast<time_t>(RFIFOL(fd, 140));
ban_until_time = static_cast<time_t>(RFIFOL(fd, 144));
- memset(memo, '\0', sizeof(memo));
- strncpy(memo, static_cast<const char *>(RFIFOP(fd, 150)), RFIFOW(fd, 148));
+ RFIFO_STRING(fd, 150, memo, RFIFOW(fd, 148));
if (RFIFOL(fd, 2) == -1)
{
PRINTF("Unabled to find the account [%s]. Account doesn't exist.\n",
@@ -3553,7 +3497,7 @@ int Connect_login_server(void)
{
WFIFOW(login_fd, 0) = 0x7918; // Request for administation login
WFIFOW(login_fd, 2) = 0; // no encrypted
- memcpy(WFIFOP(login_fd, 4), loginserveradminpassword, 24);
+ WFIFO_STRING(login_fd, 4, loginserveradminpassword, 24);
WFIFOSET(login_fd, 28);
bytes_to_read = 1;
diff --git a/src/login/login.cpp b/src/login/login.cpp
index baa1097..df271ef 100644
--- a/src/login/login.cpp
+++ b/src/login/login.cpp
@@ -750,7 +750,7 @@ void charif_sendallwos(int sfd, const uint8_t *buf, size_t len)
int fd = server_fd[i];
if (fd >= 0 && fd != sfd)
{
- memcpy(WFIFOP(fd, 0), buf, len);
+ WFIFO_BUF_CLONE(fd, buf, len);
WFIFOSET(fd, len);
}
}
@@ -1042,7 +1042,7 @@ void parse_fromchar(int fd)
LOGIN_LOG("Char-server '%s' has disconnected (ip: %s).\n",
server[id].name, ip);
server_fd[id] = -1;
- memset(&server[id], 0, sizeof(struct mmo_char_server));
+ server[id] = mmo_char_server{};
}
delete_session(fd);
return;
@@ -1097,7 +1097,7 @@ void parse_fromchar(int fd)
j < ad.account_reg2_num;
p += 36, j++)
{
- memcpy(WFIFOP(fd, p), ad.account_reg2[j].str, 32);
+ WFIFO_STRING(fd, p, ad.account_reg2[j].str, 32);
WFIFOL(fd, p + 32) = ad.account_reg2[j].value;
}
WFIFOW(fd, 2) = p;
@@ -1106,7 +1106,7 @@ void parse_fromchar(int fd)
WFIFOW(fd, 0) = 0x2713;
WFIFOL(fd, 2) = acc;
WFIFOB(fd, 6) = 0;
- memcpy(WFIFOP(fd, 7), ad.email, 40);
+ WFIFO_STRING(fd, 7, ad.email, 40);
WFIFOL(fd, 47) = static_cast<time_t>(ad.connect_until_time);
WFIFOSET(fd, 51);
break;
@@ -1149,8 +1149,7 @@ void parse_fromchar(int fd)
if (RFIFOREST(fd) < 46)
return;
acc = RFIFOL(fd, 2); // speed up
- memcpy(email, RFIFOP(fd, 6), 40);
- email[39] = '\0';
+ RFIFO_STRING(fd, 6, email, 40);
remove_control_chars(email);
//PRINTF("parse_fromchar: an e-mail creation of an account with a default e-mail: server '%s', account: %d, e-mail: '%s'.\n", server[id].name, acc, RFIFOP(fd,6));
if (e_mail_check(email) == 0)
@@ -1164,7 +1163,7 @@ void parse_fromchar(int fd)
&& (strcmp(ad.email, "a@a.com") == 0
|| ad.email[0] == '\0'))
{
- memcpy(ad.email, email, 40);
+ strzcpy(ad.email, email, 40);
LOGIN_LOG("Char-server '%s': Create an e-mail on an account with a default e-mail (account: %d, new e-mail: %s, ip: %s).\n",
server[id].name, acc, email, ip);
goto x2715_out;
@@ -1191,7 +1190,7 @@ void parse_fromchar(int fd)
server[id].name, RFIFOL(fd, 2), ip);
WFIFOW(fd, 0) = 0x2717;
WFIFOL(fd, 2) = RFIFOL(fd, 2);
- memcpy(WFIFOP(fd, 6), ad.email, 40);
+ WFIFO_STRING(fd, 6, ad.email, 40);
WFIFOL(fd, 46) = static_cast<time_t>(ad.connect_until_time);
WFIFOSET(fd, 50);
goto x2716_end;
@@ -1288,11 +1287,9 @@ void parse_fromchar(int fd)
int acc;
char actual_email[40], new_email[40];
acc = RFIFOL(fd, 2);
- memcpy(actual_email, RFIFOP(fd, 6), 40);
- actual_email[39] = '\0';
+ RFIFO_STRING(fd, 6, actual_email, 40);
remove_control_chars(actual_email);
- memcpy(new_email, RFIFOP(fd, 46), 40);
- new_email[39] = '\0';
+ RFIFO_STRING(fd, 46, new_email, 40);
remove_control_chars(new_email);
if (e_mail_check(actual_email) == 0)
LOGIN_LOG("Char-server '%s': Attempt to modify an e-mail on an account (@email GM command), but actual email is invalid (account: %d, ip: %s)\n",
@@ -1311,7 +1308,7 @@ void parse_fromchar(int fd)
{
if (strcasecmp(ad.email, actual_email) == 0)
{
- memcpy(ad.email, new_email, 40);
+ strzcpy(ad.email, new_email, 40);
LOGIN_LOG("Char-server '%s': Modify an e-mail on an account (@email GM command) (account: %d (%s), new e-mail: %s, ip: %s).\n",
server[id].name, acc,
ad.userid, new_email, ip);
@@ -1512,25 +1509,22 @@ void parse_fromchar(int fd)
{
if (ad.account_id == acc)
{
- unsigned char buf[RFIFOW(fd, 2) + 1];
LOGIN_LOG("Char-server '%s': receiving (from the char-server) of account_reg2 (account: %d, ip: %s).\n",
server[id].name, acc, ip);
+ size_t len = RFIFOW(fd, 2);
int j;
for (p = 8, j = 0;
- p < RFIFOW(fd, 2) && j < ACCOUNT_REG2_NUM;
+ p < len && j < ACCOUNT_REG2_NUM;
p += 36, j++)
{
- memcpy(ad.account_reg2[j].str,
- RFIFOP(fd, p), 32);
- ad.account_reg2[j].str[31] = '\0';
- remove_control_chars(ad.account_reg2
- [j].str);
- ad.account_reg2[j].value =
- RFIFOL(fd, p + 32);
+ RFIFO_STRING(fd, p, ad.account_reg2[j].str, 32);
+ remove_control_chars(ad.account_reg2[j].str);
+ ad.account_reg2[j].value = RFIFOL(fd, p + 32);
}
ad.account_reg2_num = j;
// Sending information towards the other char-servers.
- memcpy(WBUFP(buf, 0), RFIFOP(fd, 0), RFIFOW(fd, 2));
+ uint8_t buf[len];
+ RFIFO_BUF_CLONE(fd, buf, len);
WBUFW(buf, 0) = 0x2729;
charif_sendallwos(fd, buf, WBUFW(buf, 2));
// PRINTF("parse_fromchar: receiving (from the char-server) of account_reg2 (account id: %d).\n", acc);
@@ -1582,11 +1576,9 @@ void parse_fromchar(int fd)
int acc;
char actual_pass[24], new_pass[24];
acc = RFIFOL(fd, 2);
- memcpy(actual_pass, RFIFOP(fd, 6), 24);
- actual_pass[23] = '\0';
+ RFIFO_STRING(fd, 6, actual_pass, 24);
remove_control_chars(actual_pass);
- memcpy(new_pass, RFIFOP(fd, 30), 24);
- new_pass[23] = '\0';
+ RFIFO_STRING(fd, 30, new_pass, 24);
remove_control_chars(new_pass);
int status = 0;
@@ -1634,18 +1626,18 @@ void parse_fromchar(int fd)
logfp = fopen_(login_log_unknown_packets_filename, "a");
if (logfp)
{
- timestamp_milliseconds_buffer tmpstr;
- stamp_time(tmpstr);
+ timestamp_milliseconds_buffer timestr;
+ stamp_time(timestr);
FPRINTF(logfp,
"%s: receiving of an unknown packet -> disconnection\n",
- tmpstr);
+ timestr);
FPRINTF(logfp,
"parse_fromchar: connection #%d (ip: %s), packet: 0x%x (with being read: %zu).\n",
fd, ip, RFIFOW(fd, 0), RFIFOREST(fd));
FPRINTF(logfp, "Detail (in hex):\n");
FPRINTF(logfp,
"---- 00-01-02-03-04-05-06-07 08-09-0A-0B-0C-0D-0E-0F\n");
- memset(tmpstr, '\0', sizeof(tmpstr));
+ char tmpstr[16 + 1] {};
int i;
for (i = 0; i < RFIFOREST(fd); i++)
{
@@ -1661,7 +1653,7 @@ void parse_fromchar(int fd)
else if ((i + 1) % 16 == 0)
{
FPRINTF(logfp, " %s\n", tmpstr);
- memset(tmpstr, '\0', sizeof(tmpstr));
+ strzcpy(tmpstr, "", 16 + 1);
}
}
if (i % 16 != 0)
@@ -1762,7 +1754,7 @@ void parse_admin(int fd)
{
WFIFOL(fd, len) = account_id;
WFIFOB(fd, len + 4) = isGM(account_id);
- memcpy(WFIFOP(fd, len + 5), ad.userid, 24);
+ WFIFO_STRING(fd, len + 5, ad.userid, 24);
WFIFOB(fd, len + 29) = ad.sex;
WFIFOL(fd, len + 30) = ad.logincount;
if (ad.state == 0 && ad.ban_until_time) // if no state and banished
@@ -1782,7 +1774,7 @@ void parse_admin(int fd)
if (RFIFOREST(fd) < 10)
return;
uint8_t buf[10];
- memcpy(buf, RFIFOP(fd, 0), 10);
+ RFIFO_BUF_CLONE(fd, buf, 10);
// forward package to char servers
charif_sendallwos(-1, buf, 10);
RFIFOSKIP(fd, 10);
@@ -1796,13 +1788,13 @@ void parse_admin(int fd)
return;
{
struct mmo_account ma;
- strzcpy(ma.userid, static_cast<const char *>(RFIFOP(fd, 2)), 24);
- strzcpy(ma.passwd, static_cast<const char *>(RFIFOP(fd, 26)), 24);
- memcpy(ma.lastlogin, "-", 2);
+ RFIFO_STRING(fd, 2, ma.userid, 24);
+ RFIFO_STRING(fd, 26, ma.passwd, 24);
+ strzcpy(ma.lastlogin, "-", 24);
ma.sex = RFIFOB(fd, 50);
WFIFOW(fd, 0) = 0x7931;
WFIFOL(fd, 2) = -1;
- memcpy(WFIFOP(fd, 6), ma.userid, 24);
+ WFIFO_STRING(fd, 6, ma.userid, 24);
if (strlen(ma.userid) < 4 || strlen(ma.passwd) < 4)
{
LOGIN_LOG("'ladmin': Attempt to create an invalid account (account or pass is too short, ip: %s)\n",
@@ -1868,7 +1860,7 @@ void parse_admin(int fd)
WBUFL(buf, 2) = ad->account_id;
charif_sendallwos(-1, buf, 6);
// send answer
- memcpy(WFIFOP(fd, 6), ad->userid, 24);
+ WFIFO_STRING(fd, 6, ad->userid, 24);
WFIFOL(fd, 2) = ad->account_id;
// save deleted account in log file
LOGIN_LOG("'ladmin': Account deletion (account: %s, id: %d, ip: %s) - saved in next line:\n",
@@ -1880,12 +1872,12 @@ void parse_admin(int fd)
LOGIN_LOG("%s\n", buf);
}
// delete account
- memset(ad->userid, '\0', sizeof(ad->userid));
+ strzcpy(ad->userid, "", 24);
ad->account_id = -1;
}
else
{
- memcpy(WFIFOP(fd, 6), account_name, 24);
+ WFIFO_STRING(fd, 6, account_name, 24);
LOGIN_LOG("'ladmin': Attempt to delete an unknown account (account: %s, ip: %s)\n",
account_name, ip);
}
@@ -1905,7 +1897,7 @@ void parse_admin(int fd)
AuthData *ad = search_account(account_name);
if (ad)
{
- memcpy(WFIFOP(fd, 6), ad->userid, 24);
+ WFIFO_STRING(fd, 6, ad->userid, 24);
strzcpy(ad->pass, MD5_saltcrypt(static_cast<const char *>(RFIFOP(fd, 26)), make_salt()), 40);
WFIFOL(fd, 2) = ad->account_id;
LOGIN_LOG("'ladmin': Modification of a password (account: %s, new password: %s, ip: %s)\n",
@@ -1913,7 +1905,7 @@ void parse_admin(int fd)
}
else
{
- memcpy(WFIFOP(fd, 6), account_name, 24);
+ WFIFO_STRING(fd, 6, account_name, 24);
LOGIN_LOG("'ladmin': Attempt to modify the password of an unknown account (account: %s, ip: %s)\n",
account_name, ip);
}
@@ -1942,7 +1934,7 @@ void parse_admin(int fd)
AuthData *ad = search_account(account_name);
if (ad)
{
- memcpy(WFIFOP(fd, 6), ad->userid, 24);
+ WFIFO_STRING(fd, 6, ad->userid, 24);
WFIFOL(fd, 2) = ad->account_id;
if (ad->state == statut
&& strcmp(ad->error_message, error_message) == 0)
@@ -1976,7 +1968,7 @@ void parse_admin(int fd)
}
else
{
- memcpy(WFIFOP(fd, 6), account_name, 24);
+ WFIFO_STRING(fd, 6, account_name, 24);
LOGIN_LOG("'ladmin': Attempt to modify the state of an unknown account (account: %s, received state: %d, ip: %s)\n",
account_name, statut, ip);
}
@@ -1995,12 +1987,9 @@ void parse_admin(int fd)
{
WFIFOL(fd, 4 + server_num * 32) = server[i].ip;
WFIFOW(fd, 4 + server_num * 32 + 4) = server[i].port;
- memcpy(WFIFOP(fd, 4 + server_num * 32 + 6),
- server[i].name, 20);
- WFIFOW(fd, 4 + server_num * 32 + 26) =
- server[i].users;
- WFIFOW(fd, 4 + server_num * 32 + 28) =
- server[i].maintenance;
+ WFIFO_STRING(fd, 4 + server_num * 32 + 6, server[i].name, 20);
+ WFIFOW(fd, 4 + server_num * 32 + 26) = server[i].users;
+ WFIFOW(fd, 4 + server_num * 32 + 28) = server[i].maintenance;
WFIFOW(fd, 4 + server_num * 32 + 30) = server[i].is_new;
server_num++;
}
@@ -2022,7 +2011,7 @@ void parse_admin(int fd)
const AuthData *ad = search_account(account_name);
if (ad)
{
- memcpy(WFIFOP(fd, 6), ad->userid, 24);
+ WFIFO_STRING(fd, 6, ad->userid, 24);
char pass[24];
strzcpy(pass, static_cast<const char *>(RFIFOP(fd, 26)), 24);
if (pass_ok(pass, ad->pass))
@@ -2041,7 +2030,7 @@ void parse_admin(int fd)
}
else
{
- memcpy(WFIFOP(fd, 6), account_name, 24);
+ WFIFO_STRING(fd, 6, account_name, 24);
LOGIN_LOG("'ladmin': Attempt to check the password of an unknown account (account: %s, ip: %s)\n",
account_name, ip);
}
@@ -2057,7 +2046,7 @@ void parse_admin(int fd)
WFIFOL(fd, 2) = -1;
strzcpy(account_name, static_cast<const char *>(RFIFOP(fd, 2)), 24);
remove_control_chars(account_name);
- memcpy(WFIFOP(fd, 6), account_name, 24);
+ WFIFO_STRING(fd, 6, account_name, 24);
{
char sex;
sex = RFIFOB(fd, 26);
@@ -2075,7 +2064,7 @@ void parse_admin(int fd)
AuthData *ad = search_account(account_name);
if (ad)
{
- memcpy(WFIFOP(fd, 6), ad->userid, 24);
+ WFIFO_STRING(fd, 6, ad->userid, 24);
if (ad->sex !=
((sex == 'S' || sex == 's') ? 2
: (sex == 'M' || sex == 'm')))
@@ -2120,7 +2109,7 @@ void parse_admin(int fd)
WFIFOL(fd, 2) = -1;
strzcpy(account_name, static_cast<const char *>(RFIFOP(fd, 2)), 24);
remove_control_chars(account_name);
- memcpy(WFIFOP(fd, 6), account_name, 24);
+ WFIFO_STRING(fd, 6, account_name, 24);
{
char new_gm_level;
new_gm_level = RFIFOB(fd, 26);
@@ -2135,7 +2124,7 @@ void parse_admin(int fd)
if (ad)
{
int acc = ad->account_id;
- memcpy(WFIFOP(fd, 6), ad->userid, 24);
+ WFIFO_STRING(fd, 6, ad->userid, 24);
if (isGM(acc) != new_gm_level)
{
// modification of the file
@@ -2266,7 +2255,7 @@ void parse_admin(int fd)
WFIFOL(fd, 2) = -1;
strzcpy(account_name, static_cast<const char *>(RFIFOP(fd, 2)), 24);
remove_control_chars(account_name);
- memcpy(WFIFOP(fd, 6), account_name, 24);
+ WFIFO_STRING(fd, 6, account_name, 24);
{
char email[40];
strzcpy(email, static_cast<const char *>(RFIFOP(fd, 26)), 40);
@@ -2281,8 +2270,8 @@ void parse_admin(int fd)
AuthData *ad = search_account(account_name);
if (ad)
{
- memcpy(WFIFOP(fd, 6), ad->userid, 24);
- memcpy(ad->email, email, 40);
+ WFIFO_STRING(fd, 6, ad->userid, 24);
+ strzcpy(ad->email, email, 40);
WFIFOL(fd, 2) = ad->account_id;
LOGIN_LOG("'ladmin': Modification of an email (account: %s, new e-mail: %s, ip: %s)\n",
ad->userid, email, ip);
@@ -2310,22 +2299,19 @@ void parse_admin(int fd)
AuthData *ad = search_account(account_name);
if (ad)
{
- int size_of_memo = sizeof(ad->memo);
- memcpy(WFIFOP(fd, 6), ad->userid, 24);
- memset(ad->memo, '\0', size_of_memo);
+ size_t size_of_memo = sizeof(ad->memo);
+ WFIFO_STRING(fd, 6, ad->userid, 24);
+ strzcpy(ad->memo, "", size_of_memo);
if (RFIFOW(fd, 26) == 0)
{
- strncpy(ad->memo, "!", size_of_memo);
- }
- else if (RFIFOW(fd, 26) > size_of_memo - 1)
- {
- memcpy(ad->memo, RFIFOP(fd, 28),
- size_of_memo - 1);
+ strzcpy(ad->memo, "!", size_of_memo);
}
else
{
- memcpy(ad->memo, RFIFOP(fd, 28),
- RFIFOW(fd, 26));
+ size_t len = RFIFOW(fd, 26);
+ if (len > size_of_memo)
+ len = size_of_memo;
+ RFIFO_STRING(fd, 28, ad->memo, len);
}
ad->memo[size_of_memo - 1] = '\0';
remove_control_chars(ad->memo);
@@ -2335,7 +2321,7 @@ void parse_admin(int fd)
}
else
{
- memcpy(WFIFOP(fd, 6), account_name, 24);
+ WFIFO_STRING(fd, 6, account_name, 24);
LOGIN_LOG("'ladmin': Attempt to modify the memo field of an unknown account (account: %s, ip: %s)\n",
account_name, ip);
}
@@ -2355,7 +2341,7 @@ void parse_admin(int fd)
const AuthData *ad = search_account(account_name);
if (ad)
{
- memcpy(WFIFOP(fd, 6), ad->userid, 24);
+ WFIFO_STRING(fd, 6, ad->userid, 24);
WFIFOL(fd, 2) = ad->account_id;
LOGIN_LOG("'ladmin': Request (by the name) of an account id (account: %s, id: %d, ip: %s)\n",
ad->userid, ad->account_id,
@@ -2363,7 +2349,7 @@ void parse_admin(int fd)
}
else
{
- memcpy(WFIFOP(fd, 6), account_name, 24);
+ WFIFO_STRING(fd, 6, account_name, 24);
LOGIN_LOG("'ladmin': ID request (by the name) of an unknown account (account: %s, ip: %s)\n",
account_name, ip);
}
@@ -2377,7 +2363,7 @@ void parse_admin(int fd)
return;
WFIFOW(fd, 0) = 0x7947;
WFIFOL(fd, 2) = RFIFOL(fd, 2);
- memset(WFIFOP(fd, 6), '\0', 24);
+ WFIFO_ZERO(fd, 6, 24);
for (const AuthData& ad : auth_data)
{
if (ad.account_id == RFIFOL(fd, 2))
@@ -2411,7 +2397,7 @@ void parse_admin(int fd)
AuthData *ad = search_account(account_name);
if (ad)
{
- memcpy(WFIFOP(fd, 6), ad->userid, 24);
+ WFIFO_STRING(fd, 6, ad->userid, 24);
LOGIN_LOG("'ladmin': Change of a validity limit (account: %s, new validity: %lld (%s), ip: %s)\n",
ad->userid,
timestamp,
@@ -2422,7 +2408,7 @@ void parse_admin(int fd)
}
else
{
- memcpy(WFIFOP(fd, 6), account_name, 24);
+ WFIFO_STRING(fd, 6, account_name, 24);
LOGIN_LOG("'ladmin': Attempt to change the validity limit of an unknown account (account: %s, received validity: %lld (%s), ip: %s)\n",
account_name,
timestamp,
@@ -2452,7 +2438,7 @@ void parse_admin(int fd)
AuthData *ad = search_account(account_name);
if (ad)
{
- memcpy(WFIFOP(fd, 6), ad->userid, 24);
+ WFIFO_STRING(fd, 6, ad->userid, 24);
WFIFOL(fd, 2) = ad->account_id;
LOGIN_LOG("'ladmin': Change of the final date of a banishment (account: %s, new final date of banishment: %lld (%s), ip: %s)\n",
ad->userid, timestamp,
@@ -2478,7 +2464,7 @@ void parse_admin(int fd)
}
else
{
- memcpy(WFIFOP(fd, 6), account_name, 24);
+ WFIFO_STRING(fd, 6, account_name, 24);
LOGIN_LOG("'ladmin': Attempt to change the final date of a banishment of an unknown account (account: %s, received final date of banishment: %lld (%s), ip: %s)\n",
account_name, timestamp,
tmpstr,
@@ -2502,7 +2488,7 @@ void parse_admin(int fd)
if (ad)
{
WFIFOL(fd, 2) = ad->account_id;
- memcpy(WFIFOP(fd, 6), ad->userid, 24);
+ WFIFO_STRING(fd, 6, ad->userid, 24);
TimeT timestamp;
TimeT now = TimeT::now();
if (!ad->ban_until_time
@@ -2569,7 +2555,7 @@ void parse_admin(int fd)
}
else
{
- memcpy(WFIFOP(fd, 6), account_name, 24);
+ WFIFO_STRING(fd, 6, account_name, 24);
LOGIN_LOG("'ladmin': Attempt to adjust the final date of a banishment of an unknown account (account: %s, ip: %s)\n",
account_name, ip);
WFIFOL(fd, 30) = 0;
@@ -2601,24 +2587,21 @@ void parse_admin(int fd)
goto x794e_have_no_server;
{
x794e_have_server:
- uint8_t buf[32000];
- char message[32000];
+ // overwrite the -1
WFIFOW(fd, 2) = 0;
- memset(message, '\0', sizeof(message));
- memcpy(message, RFIFOP(fd, 8), RFIFOL(fd, 4));
- message[sizeof(message) - 1] = '\0';
+
+ size_t len = RFIFOL(fd, 4);
+ char message[len];
+ RFIFO_STRING(fd, 8, message, len);
remove_control_chars(message);
- if (RFIFOW(fd, 2) == 0)
- LOGIN_LOG("'ladmin': Receiving a message for broadcast (message (in yellow): %s, ip: %s)\n",
- message, ip);
- else
- LOGIN_LOG("'ladmin': Receiving a message for broadcast (message (in blue): %s, ip: %s)\n",
- message, ip);
+ const char *message_ptr = message;
+ LOGIN_LOG("'ladmin': Receiving a message for broadcast (message: %s, ip: %s)\n",
+ message_ptr, ip);
// send same message to all char-servers (no answer)
- memcpy(WBUFP(buf, 0), RFIFOP(fd, 0),
- 8 + RFIFOL(fd, 4));
+ uint8_t buf[len + 8];
+ RFIFO_BUF_CLONE(fd, buf, 8 + len);
WBUFW(buf, 0) = 0x2726;
- charif_sendallwos(-1, buf, 8 + RFIFOL(fd, 4));
+ charif_sendallwos(-1, buf, 8 + len);
}
}
x794e_have_no_server:
@@ -2638,7 +2621,7 @@ void parse_admin(int fd)
if (ad)
{
WFIFOL(fd, 2) = ad->account_id;
- memcpy(WFIFOP(fd, 6), ad->userid, 24);
+ WFIFO_STRING(fd, 6, ad->userid, 24);
if (add_to_unlimited_account == 0 && !ad->connect_until_time)
{
LOGIN_LOG("'ladmin': Attempt to adjust the validity limit of an unlimited account (account: %s, ip: %s)\n",
@@ -2705,7 +2688,7 @@ void parse_admin(int fd)
}
else
{
- memcpy(WFIFOP(fd, 6), account_name, 24);
+ WFIFO_STRING(fd, 6, account_name, 24);
LOGIN_LOG("'ladmin': Attempt to adjust the validity limit of an unknown account (account: %s, ip: %s)\n",
account_name, ip);
WFIFOL(fd, 30) = 0;
@@ -2728,30 +2711,27 @@ void parse_admin(int fd)
{
WFIFOL(fd, 2) = ad->account_id;
WFIFOB(fd, 6) = isGM(ad->account_id);
- memcpy(WFIFOP(fd, 7), ad->userid, 24);
+ WFIFO_STRING(fd, 7, ad->userid, 24);
WFIFOB(fd, 31) = ad->sex;
WFIFOL(fd, 32) = ad->logincount;
WFIFOL(fd, 36) = ad->state;
- memcpy(WFIFOP(fd, 40), ad->error_message, 20);
- memcpy(WFIFOP(fd, 60), ad->lastlogin, 24);
- memcpy(WFIFOP(fd, 84), ad->last_ip, 16);
- memcpy(WFIFOP(fd, 100), ad->email, 40);
+ WFIFO_STRING(fd, 40, ad->error_message, 20);
+ WFIFO_STRING(fd, 60, ad->lastlogin, 24);
+ WFIFO_STRING(fd, 84, ad->last_ip, 16);
+ WFIFO_STRING(fd, 100, ad->email, 40);
WFIFOL(fd, 140) = static_cast<time_t>(ad->connect_until_time);
WFIFOL(fd, 144) = static_cast<time_t>(ad->ban_until_time);
- WFIFOW(fd, 148) = strlen(ad->memo);
- if (ad->memo[0])
- {
- memcpy(WFIFOP(fd, 150), ad->memo,
- strlen(ad->memo));
- }
+ size_t len = strlen(ad->memo) + 1;
+ WFIFOW(fd, 148) = len;
+ WFIFO_STRING(fd, 150, ad->memo, len);
LOGIN_LOG("'ladmin': Sending information of an account (request by the name; account: %s, id: %d, ip: %s)\n",
ad->userid, ad->account_id,
ip);
- WFIFOSET(fd, 150 + strlen(ad->memo));
+ WFIFOSET(fd, 150 + len);
}
else
{
- memcpy(WFIFOP(fd, 7), account_name, 24);
+ WFIFO_STRING(fd, 7, account_name, 24);
WFIFOW(fd, 148) = 0;
LOGIN_LOG("'ladmin': Attempt to obtain information (by the name) of an unknown account (account: %s, ip: %s)\n",
account_name, ip);
@@ -2766,7 +2746,7 @@ void parse_admin(int fd)
return;
WFIFOW(fd, 0) = 0x7953;
WFIFOL(fd, 2) = RFIFOL(fd, 2);
- memset(WFIFOP(fd, 7), '\0', 24);
+ WFIFO_ZERO(fd, 7, 24);
for (const AuthData& ad : auth_data)
{
if (ad.account_id == RFIFOL(fd, 2))
@@ -2774,23 +2754,20 @@ void parse_admin(int fd)
LOGIN_LOG("'ladmin': Sending information of an account (request by the id; account: %s, id: %d, ip: %s)\n",
ad.userid, RFIFOL(fd, 2), ip);
WFIFOB(fd, 6) = isGM(ad.account_id);
- memcpy(WFIFOP(fd, 7), ad.userid, 24);
+ WFIFO_STRING(fd, 7, ad.userid, 24);
WFIFOB(fd, 31) = ad.sex;
WFIFOL(fd, 32) = ad.logincount;
WFIFOL(fd, 36) = ad.state;
- memcpy(WFIFOP(fd, 40), ad.error_message, 20);
- memcpy(WFIFOP(fd, 60), ad.lastlogin, 24);
- memcpy(WFIFOP(fd, 84), ad.last_ip, 16);
- memcpy(WFIFOP(fd, 100), ad.email, 40);
+ WFIFO_STRING(fd, 40, ad.error_message, 20);
+ WFIFO_STRING(fd, 60, ad.lastlogin, 24);
+ WFIFO_STRING(fd, 84, ad.last_ip, 16);
+ WFIFO_STRING(fd, 100, ad.email, 40);
WFIFOL(fd, 140) = static_cast<time_t>(ad.connect_until_time);
WFIFOL(fd, 144) = static_cast<time_t>(ad.ban_until_time);
- WFIFOW(fd, 148) = strlen(ad.memo);
- if (ad.memo[0])
- {
- memcpy(WFIFOP(fd, 150), ad.memo,
- strlen(ad.memo));
- }
- WFIFOSET(fd, 150 + strlen(ad.memo));
+ size_t len = strlen(ad.memo) + 1;
+ WFIFOW(fd, 148) = len;
+ WFIFO_STRING(fd, 150, ad.memo, len);
+ WFIFOSET(fd, 150 + len);
goto x7954_out;
}
}
@@ -2820,17 +2797,18 @@ void parse_admin(int fd)
logfp = fopen_(login_log_unknown_packets_filename, "a");
if (logfp)
{
- timestamp_milliseconds_buffer tmpstr;
+ timestamp_milliseconds_buffer timestr;
+ stamp_time(timestr);
FPRINTF(logfp,
"%s: receiving of an unknown packet -> disconnection\n",
- tmpstr);
+ timestr);
FPRINTF(logfp,
"parse_admin: connection #%d (ip: %s), packet: 0x%x (with being read: %zu).\n",
fd, ip, RFIFOW(fd, 0), RFIFOREST(fd));
FPRINTF(logfp, "Detail (in hex):\n");
FPRINTF(logfp,
"---- 00-01-02-03-04-05-06-07 08-09-0A-0B-0C-0D-0E-0F\n");
- memset(tmpstr, '\0', sizeof(tmpstr));
+ char tmpstr[16 + 1] {};
int i;
for (i = 0; i < RFIFOREST(fd); i++)
{
@@ -2846,7 +2824,7 @@ void parse_admin(int fd)
else if ((i + 1) % 16 == 0)
{
FPRINTF(logfp, " %s\n", tmpstr);
- memset(tmpstr, '\0', sizeof(tmpstr));
+ strzcpy(tmpstr, "", 16 + 1);
}
}
if (i % 16 != 0)
@@ -2911,7 +2889,6 @@ void parse_login(int fd)
struct mmo_account account;
int result, j;
uint8_t *p = reinterpret_cast<uint8_t *>(&session[fd]->client_addr.sin_addr);
- int host_len;
const char *ip = ip2str(session[fd]->client_addr.sin_addr);
@@ -2977,7 +2954,7 @@ void parse_login(int fd)
ip);
WFIFOW(fd, 0) = 0x6a;
WFIFOB(fd, 2) = 0x03;
- memset(WFIFOP(fd, 3), '\0', 20);
+ WFIFO_ZERO(fd, 3, 20);
WFIFOSET(fd, 23);
RFIFOSKIP(fd, 55);
break;
@@ -3027,13 +3004,13 @@ void parse_login(int fd)
*/
// if (version_2 & VERSION_2_UPDATEHOST)
{
- host_len = strlen(update_host);
+ size_t host_len = strlen(update_host);
if (host_len > 0)
{
+ host_len++;
WFIFOW(fd, 0) = 0x63;
WFIFOW(fd, 2) = 4 + host_len;
- memcpy(WFIFOP(fd, 4), update_host,
- host_len);
+ WFIFO_STRING(fd, 4, update_host, host_len);
WFIFOSET(fd, 4 + host_len);
}
}
@@ -3046,21 +3023,14 @@ void parse_login(int fd)
if (server_fd[i] >= 0)
{
if (lan_ip_check(p))
- WFIFOL(fd, 47 + server_num * 32) =
- inet_addr(lan_char_ip);
+ WFIFOL(fd, 47 + server_num * 32) = inet_addr(lan_char_ip);
else
- WFIFOL(fd, 47 + server_num * 32) =
- server[i].ip;
- WFIFOW(fd, 47 + server_num * 32 + 4) =
- server[i].port;
- memcpy(WFIFOP(fd, 47 + server_num * 32 + 6),
- server[i].name, 20);
- WFIFOW(fd, 47 + server_num * 32 + 26) =
- server[i].users;
- WFIFOW(fd, 47 + server_num * 32 + 28) =
- server[i].maintenance;
- WFIFOW(fd, 47 + server_num * 32 + 30) =
- server[i].is_new;
+ WFIFOL(fd, 47 + server_num * 32) = server[i].ip;
+ WFIFOW(fd, 47 + server_num * 32 + 4) = server[i].port;
+ WFIFO_STRING(fd, 47 + server_num * 32 + 6, server[i].name, 20);
+ WFIFOW(fd, 47 + server_num * 32 + 26) = server[i].users;
+ WFIFOW(fd, 47 + server_num * 32 + 28) = server[i].maintenance;
+ WFIFOW(fd, 47 + server_num * 32 + 30) = server[i].is_new;
server_num++;
}
}
@@ -3073,7 +3043,7 @@ void parse_login(int fd)
WFIFOL(fd, 8) = account.account_id;
WFIFOL(fd, 12) = account.login_id2;
WFIFOL(fd, 16) = 0; // in old version, that was for ip (not more used)
- memcpy(WFIFOP(fd, 20), account.lastlogin, 24); // in old version, that was for name (not more used)
+ WFIFO_STRING(fd, 20, account.lastlogin, 24); // in old version, that was for name (not more used)
WFIFOB(fd, 46) = account.sex;
WFIFOSET(fd, 47 + 32 * server_num);
if (auth_fifo_pos >= AUTH_FIFO_SIZE)
@@ -3103,7 +3073,7 @@ void parse_login(int fd)
}
else
{
- memset(WFIFOP(fd, 0), '\0', 23);
+ WFIFO_ZERO(fd, 0, 23);
WFIFOW(fd, 0) = 0x6a;
WFIFOB(fd, 2) = result;
if (result == 6)
@@ -3117,12 +3087,11 @@ void parse_login(int fd)
// if account is banned, we send ban timestamp
timestamp_seconds_buffer tmpstr;
stamp_time(tmpstr, &ad->ban_until_time);
- memcpy(WFIFOP(fd, 3), tmpstr, 20);
+ WFIFO_STRING(fd, 3, tmpstr, 20);
}
else
{ // we send error message
- memcpy(WFIFOP(fd, 3),
- ad->error_message, 20);
+ WFIFO_STRING(fd, 3, ad->error_message, 20);
}
}
}
@@ -3154,7 +3123,7 @@ void parse_login(int fd)
}
// TODO fix or get rid of this
// Creation of the coding key
- memset(ld->md5key, '\0', sizeof(ld->md5key));
+ strzcpy(ld->md5key, "", sizeof(ld->md5key));
ld->md5keylen = random_::in(12, 15);
for (int i = 0; i < ld->md5keylen; i++)
ld->md5key[i] = random_::in(1, 255);
@@ -3162,7 +3131,7 @@ void parse_login(int fd)
RFIFOSKIP(fd, 2);
WFIFOW(fd, 0) = 0x01dc;
WFIFOW(fd, 2) = 4 + ld->md5keylen;
- memcpy(WFIFOP(fd, 4), ld->md5key, ld->md5keylen);
+ WFIFO_STRING(fd, 4, ld->md5key, ld->md5keylen + 1);
WFIFOSET(fd, WFIFOW(fd, 2));
session[fd]->session_data = std::move(ld);
}
@@ -3218,15 +3187,12 @@ void parse_login(int fd)
account.passwd, ip);
PRINTF("Connection of the char-server '%s' accepted.\n",
server_name);
- memset(&server[account.account_id], 0,
- sizeof(struct mmo_char_server));
+ server[account.account_id] = mmo_char_server{};
server[account.account_id].ip = RFIFOL(fd, 54);
server[account.account_id].port = RFIFOW(fd, 58);
- memcpy(server[account.account_id].name, server_name,
- 20);
+ strzcpy(server[account.account_id].name, server_name, 20);
server[account.account_id].users = 0;
- server[account.account_id].maintenance =
- RFIFOW(fd, 82);
+ server[account.account_id].maintenance = RFIFOW(fd, 82);
server[account.account_id].is_new = RFIFOW(fd, 84);
server_fd[account.account_id] = fd;
if (anti_freeze_enable)
@@ -3235,8 +3201,7 @@ void parse_login(int fd)
WFIFOB(fd, 2) = 0;
WFIFOSET(fd, 3);
session[fd]->func_parse = parse_fromchar;
- realloc_fifo(fd, FIFOSIZE_SERVERLINK,
- FIFOSIZE_SERVERLINK);
+ realloc_fifo(fd, FIFOSIZE_SERVERLINK, FIFOSIZE_SERVERLINK);
// send GM account to char-server
len = 4;
WFIFOW(fd, 0) = 0x2732;
@@ -3368,11 +3333,11 @@ void parse_login(int fd)
logfp = fopen_(login_log_unknown_packets_filename, "a");
if (logfp)
{
- timestamp_milliseconds_buffer tmpstr;
- stamp_time(tmpstr);
+ timestamp_milliseconds_buffer timestr;
+ stamp_time(timestr);
FPRINTF(logfp,
"%s: receiving of an unknown packet -> disconnection\n",
- tmpstr);
+ timestr);
FPRINTF(logfp,
"parse_login: connection #%d (ip: %s), packet: 0x%x (with being read: %zu).\n",
fd, ip, RFIFOW(fd, 0),
@@ -3380,7 +3345,8 @@ void parse_login(int fd)
FPRINTF(logfp, "Detail (in hex):\n");
FPRINTF(logfp,
"---- 00-01-02-03-04-05-06-07 08-09-0A-0B-0C-0D-0E-0F\n");
- memset(tmpstr, '\0', sizeof(tmpstr));
+
+ char tmpstr[16 + 1] {};
int i;
for (i = 0; i < RFIFOREST(fd); i++)
@@ -3397,7 +3363,7 @@ void parse_login(int fd)
else if ((i + 1) % 16 == 0)
{
FPRINTF(logfp, " %s\n", tmpstr);
- memset(tmpstr, '\0', sizeof(tmpstr));
+ strzcpy(tmpstr, "", 16 + 1);
}
}
if (i % 16 != 0)
diff --git a/src/map/atcommand.cpp b/src/map/atcommand.cpp
index c066a46..8e29f86 100644
--- a/src/map/atcommand.cpp
+++ b/src/map/atcommand.cpp
@@ -364,7 +364,7 @@ void log_atcommand(dumb_ptr<map_session_data> sd, const_string cmd)
stamp_time(tmpstr);
fprintf(fp, "[%s] %s(%d,%d) %s(%d) : ",
tmpstr,
- sd->bl_m->name, sd->bl_x, sd->bl_y,
+ sd->bl_m->name_, sd->bl_x, sd->bl_y,
sd->status.name, sd->status.account_id);
fwrite(cmd.data(), 1, cmd.size(), fp);
}
@@ -432,10 +432,9 @@ bool is_atcommand(const int fd, dumb_ptr<map_session_data> sd,
}
{
- char command[100];
+ char command[100] {};
const char *str = message;
const char *p = message;
- memset(command, '\0', sizeof(command));
while (*p && !isspace(*p))
p++;
if (p - str >= sizeof(command)) // too long
@@ -584,11 +583,9 @@ int atcommand_config_read(const char *cfgName)
int atcommand_setup(const int fd, dumb_ptr<map_session_data> sd,
const char *, const char *message)
{
- char character[100];
+ char character[100] {};
int level = 1;
- memset(character, '\0', sizeof(character));
-
if (!message || !*message
|| sscanf(message, "%d %99[^\n]", &level, character) < 2)
{
@@ -630,14 +627,11 @@ int atcommand_setup(const int fd, dumb_ptr<map_session_data> sd,
int atcommand_charwarp(const int fd, dumb_ptr<map_session_data> sd,
const char *, const char *message)
{
- char map_name[100];
- char character[100];
+ char map_name[100] {};
+ char character[100] {};
int x = 0, y = 0;
dumb_ptr<map_session_data> pl_sd;
- memset(map_name, '\0', sizeof(map_name));
- memset(character, '\0', sizeof(character));
-
if (!message || !*message
|| sscanf(message, "%99s %d %d %99[^\n]", map_name, &x, &y,
character) < 4)
@@ -714,11 +708,9 @@ int atcommand_charwarp(const int fd, dumb_ptr<map_session_data> sd,
int atcommand_warp(const int fd, dumb_ptr<map_session_data> sd,
const char *, const char *message)
{
- char map_name[100];
+ char map_name[100] {};
int x = 0, y = 0;
- memset(map_name, '\0', sizeof(map_name));
-
if (!message || !*message
|| sscanf(message, "%99s %d %d", map_name, &x, &y) < 1)
{
@@ -776,11 +768,9 @@ int atcommand_warp(const int fd, dumb_ptr<map_session_data> sd,
int atcommand_where(const int fd, dumb_ptr<map_session_data> sd,
const char *, const char *message)
{
- char character[100];
+ char character[100] {};
dumb_ptr<map_session_data> pl_sd;
- memset(character, '\0', sizeof(character));
-
if (sscanf(message, "%99[^\n]", character) < 1)
strcpy(character, sd->status.name);
@@ -791,7 +781,7 @@ int atcommand_where(const int fd, dumb_ptr<map_session_data> sd,
{ // you can look only lower or same level
std::string output = STRPRINTF("%s: %s (%d,%d)",
pl_sd->status.name,
- pl_sd->mapname, pl_sd->bl_x, pl_sd->bl_y);
+ pl_sd->mapname_, pl_sd->bl_x, pl_sd->bl_y);
clif_displaymessage(fd, output);
}
else
@@ -810,11 +800,9 @@ int atcommand_where(const int fd, dumb_ptr<map_session_data> sd,
int atcommand_goto(const int fd, dumb_ptr<map_session_data> sd,
const char *, const char *message)
{
- char character[100];
+ char character[100] {};
dumb_ptr<map_session_data> pl_sd;
- memset(character, '\0', sizeof(character));
-
if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1)
{
clif_displaymessage(fd,
@@ -838,7 +826,7 @@ int atcommand_goto(const int fd, dumb_ptr<map_session_data> sd,
"You are not authorised to warp you from your actual map.");
return -1;
}
- pc_setpos(sd, pl_sd->mapname, pl_sd->bl_x, pl_sd->bl_y, BeingRemoveWhy::WARPED);
+ pc_setpos(sd, pl_sd->mapname_, pl_sd->bl_x, pl_sd->bl_y, BeingRemoveWhy::WARPED);
std::string output = STRPRINTF("Jump to %s", character);
clif_displaymessage(fd, output);
}
@@ -881,7 +869,7 @@ int atcommand_jump(const int fd, dumb_ptr<map_session_data> sd,
"You are not authorised to warp you from your actual map.");
return -1;
}
- pc_setpos(sd, sd->mapname, x, y, BeingRemoveWhy::WARPED);
+ pc_setpos(sd, sd->mapname_, x, y, BeingRemoveWhy::WARPED);
std::string output = STRPRINTF("Jump to %d %d", x, y);
clif_displaymessage(fd, output);
}
@@ -903,11 +891,8 @@ int atcommand_who(const int fd, dumb_ptr<map_session_data> sd,
{
int count;
int pl_GM_level, GM_level;
- char match_text[100];
- char player_name[24];
-
- memset(match_text, '\0', sizeof(match_text));
- memset(player_name, '\0', sizeof(player_name));
+ char match_text[100] {};
+ char player_name[24] {};
if (sscanf(message, "%99[^\n]", match_text) < 1)
strcpy(match_text, "");
@@ -930,7 +915,7 @@ int atcommand_who(const int fd, dumb_ptr<map_session_data> sd,
&& (pl_GM_level > GM_level)))
{
// you can look only lower or same level
- memcpy(player_name, pl_sd->status.name, 24);
+ strzcpy(player_name, pl_sd->status.name, 24);
for (int j = 0; player_name[j]; j++)
player_name[j] = tolower(player_name[j]);
if (strstr(player_name, match_text) != NULL)
@@ -941,11 +926,11 @@ int atcommand_who(const int fd, dumb_ptr<map_session_data> sd,
output = STRPRINTF(
"Name: %s (GM:%d) | Location: %s %d %d",
pl_sd->status.name, pl_GM_level,
- pl_sd->mapname, pl_sd->bl_x, pl_sd->bl_y);
+ pl_sd->mapname_, pl_sd->bl_x, pl_sd->bl_y);
else
output = STRPRINTF(
"Name: %s | Location: %s %d %d",
- pl_sd->status.name, pl_sd->mapname,
+ pl_sd->status.name, pl_sd->mapname_,
pl_sd->bl_x, pl_sd->bl_y);
clif_displaymessage(fd, output);
count++;
@@ -976,13 +961,10 @@ int atcommand_whogroup(const int fd, dumb_ptr<map_session_data> sd,
{
int count;
int pl_GM_level, GM_level;
- char match_text[100];
- char player_name[24];
+ char match_text[100] {};
+ char player_name[24] {};
struct party *p;
- memset(match_text, '\0', sizeof(match_text));
- memset(player_name, '\0', sizeof(player_name));
-
if (sscanf(message, "%99[^\n]", match_text) < 1)
strcpy(match_text, "");
for (int j = 0; match_text[j]; j++)
@@ -1004,7 +986,7 @@ int atcommand_whogroup(const int fd, dumb_ptr<map_session_data> sd,
&& (pl_GM_level > GM_level)))
{
// you can look only lower or same level
- memcpy(player_name, pl_sd->status.name, 24);
+ strzcpy(player_name, pl_sd->status.name, 24);
for (int j = 0; player_name[j]; j++)
player_name[j] = tolower(player_name[j]);
if (strstr(player_name, match_text) != NULL)
@@ -1047,9 +1029,7 @@ int atcommand_whomap(const int fd, dumb_ptr<map_session_data> sd,
int count;
int pl_GM_level, GM_level;
map_local *map_id;
- char map_name[100];
-
- memset(map_name, '\0', sizeof(map_name));
+ char map_name[100] {};
if (!message || !*message)
map_id = sd->bl_m;
@@ -1085,11 +1065,11 @@ int atcommand_whomap(const int fd, dumb_ptr<map_session_data> sd,
output = STRPRINTF(
"Name: %s (GM:%d) | Location: %s %d %d",
pl_sd->status.name, pl_GM_level,
- pl_sd->mapname, pl_sd->bl_x, pl_sd->bl_y);
+ pl_sd->mapname_, pl_sd->bl_x, pl_sd->bl_y);
else
output = STRPRINTF(
"Name: %s | Location: %s %d %d",
- pl_sd->status.name, pl_sd->mapname,
+ pl_sd->status.name, pl_sd->mapname_,
pl_sd->bl_x, pl_sd->bl_y);
clif_displaymessage(fd, output);
count++;
@@ -1099,7 +1079,7 @@ int atcommand_whomap(const int fd, dumb_ptr<map_session_data> sd,
}
std::string output = STRPRINTF("%d players found in map '%s'.",
- count, map_id->name);
+ count, map_id->name_);
clif_displaymessage(fd, output);
return 0;
@@ -1114,11 +1094,9 @@ int atcommand_whomapgroup(const int fd, dumb_ptr<map_session_data> sd,
{
int count;
int pl_GM_level, GM_level;
- char map_name[100];
+ char map_name[100] {};
struct party *p;
- memset(map_name, '\0', sizeof(map_name));
-
map_local *map_id;
if (!message || !*message)
map_id = sd->bl_m;
@@ -1168,12 +1146,12 @@ int atcommand_whomapgroup(const int fd, dumb_ptr<map_session_data> sd,
std::string output;
if (count == 0)
- output = STRPRINTF("No player found in map '%s'.", map_id->name);
+ output = STRPRINTF("No player found in map '%s'.", map_id->name_);
else if (count == 1)
- output = STRPRINTF("1 player found in map '%s'.", map_id->name);
+ output = STRPRINTF("1 player found in map '%s'.", map_id->name_);
else
{
- output = STRPRINTF("%d players found in map '%s'.", count, map_id->name);
+ output = STRPRINTF("%d players found in map '%s'.", count, map_id->name_);
}
clif_displaymessage(fd, output);
@@ -1189,13 +1167,10 @@ int atcommand_whogm(const int fd, dumb_ptr<map_session_data> sd,
{
int count;
int pl_GM_level, GM_level;
- char match_text[100];
- char player_name[24];
+ char match_text[100] {};
+ char player_name[24] {};
struct party *p;
- memset(match_text, '\0', sizeof(match_text));
- memset(player_name, '\0', sizeof(player_name));
-
if (sscanf(message, "%99[^\n]", match_text) < 1)
strcpy(match_text, "");
for (int j = 0; match_text[j]; j++)
@@ -1219,7 +1194,7 @@ int atcommand_whogm(const int fd, dumb_ptr<map_session_data> sd,
&& (pl_GM_level > GM_level)))
{
// you can look only lower or same level
- memcpy(player_name, pl_sd->status.name, 24);
+ strzcpy(player_name, pl_sd->status.name, 24);
for (int j = 0; player_name[j]; j++)
player_name[j] = tolower(player_name[j]);
if (strstr(player_name, match_text) != NULL)
@@ -1229,7 +1204,7 @@ int atcommand_whogm(const int fd, dumb_ptr<map_session_data> sd,
output = STRPRINTF(
"Name: %s (GM:%d) | Location: %s %d %d",
pl_sd->status.name, pl_GM_level,
- pl_sd->mapname, pl_sd->bl_x, pl_sd->bl_y);
+ pl_sd->mapname_, pl_sd->bl_x, pl_sd->bl_y);
clif_displaymessage(fd, output);
output = STRPRINTF(
" BLvl: %d | Job: %s (Lvl: %d)",
@@ -1272,7 +1247,7 @@ int atcommand_save(const int fd, dumb_ptr<map_session_data> sd,
{
nullpo_retr(-1, sd);
- pc_setsavepoint(sd, sd->mapname, sd->bl_x, sd->bl_y);
+ pc_setsavepoint(sd, sd->mapname_, sd->bl_x, sd->bl_y);
pc_makesavestatus(sd);
chrif_save(sd);
clif_displaymessage(fd, "Character data respawn point saved.");
@@ -1287,7 +1262,7 @@ int atcommand_save(const int fd, dumb_ptr<map_session_data> sd,
int atcommand_load(const int fd, dumb_ptr<map_session_data> sd,
const char *, const char *)
{
- map_local *m = map_mapname2mapid(sd->status.save_point.map);
+ map_local *m = map_mapname2mapid(sd->status.save_point.map_);
if (m != nullptr && m->flag.nowarpto
&& battle_config.any_warp_GM_min_level > pc_isGM(sd))
{
@@ -1303,7 +1278,7 @@ int atcommand_load(const int fd, dumb_ptr<map_session_data> sd,
return -1;
}
- pc_setpos(sd, sd->status.save_point.map, sd->status.save_point.x,
+ pc_setpos(sd, sd->status.save_point.map_, sd->status.save_point.x,
sd->status.save_point.y, BeingRemoveWhy::GONE);
clif_displaymessage(fd, "Warping to respawn point.");
@@ -1453,11 +1428,9 @@ int atcommand_die(const int fd, dumb_ptr<map_session_data> sd,
int atcommand_kill(const int fd, dumb_ptr<map_session_data> sd,
const char *, const char *message)
{
- char character[100];
+ char character[100] {};
dumb_ptr<map_session_data> pl_sd;
- memset(character, '\0', sizeof(character));
-
if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1)
{
clif_displaymessage(fd,
@@ -1521,7 +1494,7 @@ int atcommand_kami(const int fd, dumb_ptr<map_session_data>,
return -1;
}
- intif_GMmessage(message, 0);
+ intif_GMmessage(message);
return 0;
}
@@ -1581,14 +1554,11 @@ int atcommand_heal(const int fd, dumb_ptr<map_session_data> sd,
int atcommand_item(const int fd, dumb_ptr<map_session_data> sd,
const char *, const char *message)
{
- char item_name[100];
+ char item_name[100] {};
int number = 0, item_id;
- struct item item_tmp;
struct item_data *item_data;
int get_count, i;
- memset(item_name, '\0', sizeof(item_name));
-
if (!message || !*message
|| sscanf(message, "%99s %d", item_name, &number) < 1)
{
@@ -1617,7 +1587,7 @@ int atcommand_item(const int fd, dumb_ptr<map_session_data> sd,
}
for (i = 0; i < number; i += get_count)
{
- memset(&item_tmp, 0, sizeof(item_tmp));
+ struct item item_tmp {};
item_tmp.nameid = item_id;
item_tmp.identify = 1;
PickupFail flag;
@@ -1803,12 +1773,10 @@ 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], w1[2048], w2[2048];
+ char buf[2048] {};
int i, gm_level;
FILE *fp;
- memset(buf, '\0', sizeof(buf));
-
if ((fp = fopen_(help_txt, "r")) != NULL)
{
clif_displaymessage(fd, "Help commands:");
@@ -1825,6 +1793,7 @@ int atcommand_help(const int fd, dumb_ptr<map_session_data> sd,
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))
@@ -1848,9 +1817,7 @@ int atcommand_help(const int fd, dumb_ptr<map_session_data> sd,
int atcommand_gm(const int fd, dumb_ptr<map_session_data> sd,
const char *, const char *message)
{
- char password[100];
-
- memset(password, '\0', sizeof(password));
+ char password[100] {};
if (!message || !*message || sscanf(message, "%99[^\n]", password) < 1)
{
@@ -2106,7 +2073,7 @@ int atcommand_hair_color(const int fd, dumb_ptr<map_session_data> sd,
int atcommand_spawn(const int fd, dumb_ptr<map_session_data> sd,
const char *command, const char *message)
{
- char monster[100];
+ char monster[100] {};
int mob_id;
int number = 0;
int x = 0, y = 0;
@@ -2114,8 +2081,6 @@ int atcommand_spawn(const int fd, dumb_ptr<map_session_data> sd,
int i, j, k;
int mx, my, range;
- memset(monster, '\0', sizeof(monster));
-
if (!message || !*message
|| sscanf(message, "%99s %d %d %d", monster, &number, &x, &y) < 1)
{
@@ -2200,9 +2165,7 @@ static
void atcommand_killmonster_sub(const int fd, dumb_ptr<map_session_data> sd,
const char *message, const int drop)
{
- char map_name[100];
-
- memset(map_name, '\0', sizeof(map_name));
+ char map_name[100] {};
map_local *map_id;
if (!message || !*message || sscanf(message, "%99s", map_name) < 1)
@@ -2295,7 +2258,7 @@ int atcommand_gat(const int fd, dumb_ptr<map_session_data> sd,
{
std::string output = STRPRINTF(
"%s (x= %d, y= %d) %02X %02X %02X %02X %02X",
- sd->bl_m->name, sd->bl_x - 2, sd->bl_y + y,
+ sd->bl_m->name_, sd->bl_x - 2, sd->bl_y + y,
map_getcell(sd->bl_m, sd->bl_x - 2, sd->bl_y + y),
map_getcell(sd->bl_m, sd->bl_x - 1, sd->bl_y + y),
map_getcell(sd->bl_m, sd->bl_x, sd->bl_y + y),
@@ -2549,11 +2512,9 @@ int atcommand_all_stats(const int fd, dumb_ptr<map_session_data> sd,
int atcommand_recall(const int fd, dumb_ptr<map_session_data> sd,
const char *, const char *message)
{
- char character[100];
+ char character[100] {};
dumb_ptr<map_session_data> pl_sd;
- memset(character, '\0', sizeof(character));
-
if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1)
{
clif_displaymessage(fd,
@@ -2579,7 +2540,7 @@ int atcommand_recall(const int fd, dumb_ptr<map_session_data> sd,
"You are not authorised to warp this player from its actual map.");
return -1;
}
- pc_setpos(pl_sd, sd->mapname, sd->bl_x, sd->bl_y, BeingRemoveWhy::QUIT);
+ pc_setpos(pl_sd, sd->mapname_, sd->bl_x, sd->bl_y, BeingRemoveWhy::QUIT);
std::string output = STRPRINTF("%s recalled!", character);
clif_displaymessage(fd, output);
}
@@ -2605,11 +2566,9 @@ int atcommand_recall(const int fd, dumb_ptr<map_session_data> sd,
int atcommand_revive(const int fd, dumb_ptr<map_session_data> sd,
const char *, const char *message)
{
- char character[100];
+ char character[100] {};
dumb_ptr<map_session_data> pl_sd;
- memset(character, '\0', sizeof(character));
-
if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1)
{
clif_displaymessage(fd,
@@ -2644,11 +2603,9 @@ int atcommand_revive(const int fd, dumb_ptr<map_session_data> sd,
int atcommand_character_stats(const int fd, dumb_ptr<map_session_data>,
const char *, const char *message)
{
- char character[100];
+ char character[100] {};
dumb_ptr<map_session_data> pl_sd;
- memset(character, '\0', sizeof(character));
-
if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1)
{
clif_displaymessage(fd,
@@ -2764,12 +2721,10 @@ int atcommand_character_stats_all(const int fd, dumb_ptr<map_session_data>,
int atcommand_character_option(const int fd, dumb_ptr<map_session_data> sd,
const char *, const char *message)
{
- char character[100];
+ char character[100] {};
int opt1_ = 0, opt2_ = 0, opt3_ = 0;
dumb_ptr<map_session_data> pl_sd;
- memset(character, '\0', sizeof(character));
-
if (!message || !*message
|| sscanf(message, "%d %d %d %99[^\n]", &opt1_, &opt2_, &opt3_,
character) < 4 || opt1_ < 0 || opt2_ < 0 || opt3_ < 0)
@@ -2818,9 +2773,7 @@ int atcommand_character_option(const int fd, dumb_ptr<map_session_data> sd,
int atcommand_char_change_sex(const int fd, dumb_ptr<map_session_data> sd,
const char *, const char *message)
{
- char character[100];
-
- memset(character, '\0', sizeof(character));
+ char character[100] {};
if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1)
{
@@ -2857,9 +2810,7 @@ int atcommand_char_change_sex(const int fd, dumb_ptr<map_session_data> sd,
int atcommand_char_block(const int fd, dumb_ptr<map_session_data> sd,
const char *, const char *message)
{
- char character[100];
-
- memset(character, '\0', sizeof(character));
+ char character[100] {};
if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1)
{
@@ -2907,13 +2858,11 @@ int atcommand_char_block(const int fd, dumb_ptr<map_session_data> sd,
int atcommand_char_ban(const int fd, dumb_ptr<map_session_data> sd,
const char *, const char *message)
{
- char modif[100], character[100];
+ char modif[100] {};
+ char character[100] {};
char *modif_p;
int year, month, day, hour, minute, second, value;
- memset(modif, '\0', sizeof(modif));
- memset(character, '\0', sizeof(character));
-
if (!message || !*message
|| sscanf(message, "%s %99[^\n]", modif, character) < 2)
{
@@ -3008,9 +2957,7 @@ int atcommand_char_ban(const int fd, dumb_ptr<map_session_data> sd,
int atcommand_char_unblock(const int fd, dumb_ptr<map_session_data> sd,
const char *, const char *message)
{
- char character[100];
-
- memset(character, '\0', sizeof(character));
+ char character[100] {};
if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1)
{
@@ -3047,9 +2994,7 @@ int atcommand_char_unblock(const int fd, dumb_ptr<map_session_data> sd,
int atcommand_char_unban(const int fd, dumb_ptr<map_session_data> sd,
const char *, const char *message)
{
- char character[100];
-
- memset(character, '\0', sizeof(character));
+ char character[100] {};
if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1)
{
@@ -3086,14 +3031,11 @@ int atcommand_char_unban(const int fd, dumb_ptr<map_session_data> sd,
int atcommand_character_save(const int fd, dumb_ptr<map_session_data> sd,
const char *, const char *message)
{
- char map_name[100];
- char character[100];
+ char map_name[100] {};
+ char character[100] {};
dumb_ptr<map_session_data> pl_sd;
int x = 0, y = 0;
- memset(map_name, '\0', sizeof(map_name));
- memset(character, '\0', sizeof(character));
-
if (!message || !*message
|| sscanf(message, "%99s %d %d %99[^\n]", map_name, &x, &y,
character) < 4 || x < 0 || y < 0)
@@ -3262,11 +3204,9 @@ int atcommand_character_baselevel(const int fd, dumb_ptr<map_session_data> sd,
const char *, const char *message)
{
dumb_ptr<map_session_data> pl_sd;
- char character[100];
+ char character[100] {};
int level = 0, i;
- memset(character, '\0', sizeof(character));
-
if (!message || !*message
|| sscanf(message, "%d %99[^\n]", &level, character) < 2
|| level == 0)
@@ -3356,11 +3296,9 @@ int atcommand_character_joblevel(const int fd, dumb_ptr<map_session_data> sd,
const char *, const char *message)
{
dumb_ptr<map_session_data> pl_sd;
- char character[100];
+ char character[100] {};
int max_level = 50, level = 0;
- memset(character, '\0', sizeof(character));
-
if (!message || !*message
|| sscanf(message, "%d %99[^\n]", &level, character) < 2
|| level == 0)
@@ -3441,9 +3379,7 @@ int atcommand_kick(const int fd, dumb_ptr<map_session_data> sd,
const char *, const char *message)
{
dumb_ptr<map_session_data> pl_sd;
- char character[100];
-
- memset(character, '\0', sizeof(character));
+ char character[100] {};
if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1)
{
@@ -3552,12 +3488,10 @@ int atcommand_questskill(const int fd, dumb_ptr<map_session_data> sd,
int atcommand_charquestskill(const int fd, dumb_ptr<map_session_data>,
const char *, const char *message)
{
- char character[100];
+ char character[100] {};
dumb_ptr<map_session_data> pl_sd;
int skill_id_ = 0;
- memset(character, '\0', sizeof(character));
-
if (!message || !*message
|| sscanf(message, "%d %99[^\n]", &skill_id_, character) < 2
|| skill_id_ < 0)
@@ -3664,12 +3598,10 @@ int atcommand_lostskill(const int fd, dumb_ptr<map_session_data> sd,
int atcommand_charlostskill(const int fd, dumb_ptr<map_session_data>,
const char *, const char *message)
{
- char character[100];
+ char character[100] {};
dumb_ptr<map_session_data> pl_sd;
int skill_id_ = 0;
- memset(character, '\0', sizeof(character));
-
if (!message || !*message
|| sscanf(message, "%d %99[^\n]", &skill_id_, character) < 2
|| skill_id_ < 0)
@@ -3728,9 +3660,7 @@ int atcommand_charlostskill(const int fd, dumb_ptr<map_session_data>,
int atcommand_party(const int fd, dumb_ptr<map_session_data> sd,
const char *, const char *message)
{
- char party[100];
-
- memset(party, '\0', sizeof(party));
+ char party[100] {};
if (!message || !*message || sscanf(message, "%99[^\n]", party) < 1)
{
@@ -3776,12 +3706,10 @@ int atcommand_mapexit(const int, dumb_ptr<map_session_data> sd,
int atcommand_idsearch(const int fd, dumb_ptr<map_session_data>,
const char *, const char *message)
{
- char item_name[100];
+ char item_name[100] {};
int i, match;
struct item_data *item;
- memset(item_name, '\0', sizeof(item_name));
-
if (!message || !*message || sscanf(message, "%99s", item_name) < 0)
{
clif_displaymessage(fd,
@@ -3815,11 +3743,9 @@ int atcommand_idsearch(const int fd, dumb_ptr<map_session_data>,
int atcommand_charskreset(const int fd, dumb_ptr<map_session_data> sd,
const char *, const char *message)
{
- char character[100];
+ char character[100] {};
dumb_ptr<map_session_data> pl_sd;
- memset(character, '\0', sizeof(character));
-
if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1)
{
clif_displaymessage(fd,
@@ -3858,11 +3784,9 @@ int atcommand_charskreset(const int fd, dumb_ptr<map_session_data> sd,
int atcommand_charstreset(const int fd, dumb_ptr<map_session_data> sd,
const char *, const char *message)
{
- char character[100];
+ char character[100] {};
dumb_ptr<map_session_data> pl_sd;
- memset(character, '\0', sizeof(character));
-
if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1)
{
clif_displaymessage(fd,
@@ -3902,11 +3826,9 @@ int atcommand_charstreset(const int fd, dumb_ptr<map_session_data> sd,
int atcommand_charreset(const int fd, dumb_ptr<map_session_data> sd,
const char *, const char *message)
{
- char character[100];
+ char character[100] {};
dumb_ptr<map_session_data> pl_sd;
- memset(character, '\0', sizeof(character));
-
if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1)
{
clif_displaymessage(fd,
@@ -3948,11 +3870,9 @@ int atcommand_charreset(const int fd, dumb_ptr<map_session_data> sd,
int atcommand_char_wipe(const int fd, dumb_ptr<map_session_data> sd,
const char *, const char *message)
{
- char character[100];
+ char character[100] {};
dumb_ptr<map_session_data> pl_sd;
- memset(character, '\0', sizeof(character));
-
if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1)
{
clif_displaymessage(fd,
@@ -4038,9 +3958,7 @@ int atcommand_charmodel(const int fd, dumb_ptr<map_session_data>,
{
int hair_style = 0, hair_color = 0, cloth_color = 0;
dumb_ptr<map_session_data> pl_sd;
- char character[100];
-
- memset(character, '\0', sizeof(character));
+ char character[100] {};
if (!message || !*message
|| sscanf(message, "%d %d %d %99[^\n]", &hair_style, &hair_color,
@@ -4092,12 +4010,10 @@ int atcommand_charskpoint(const int fd, dumb_ptr<map_session_data>,
const char *, const char *message)
{
dumb_ptr<map_session_data> pl_sd;
- char character[100];
+ char character[100] {};
int new_skill_point;
int point = 0;
- memset(character, '\0', sizeof(character));
-
if (!message || !*message
|| sscanf(message, "%d %99[^\n]", &point, character) < 2
|| point == 0)
@@ -4146,12 +4062,10 @@ int atcommand_charstpoint(const int fd, dumb_ptr<map_session_data>,
const char *, const char *message)
{
dumb_ptr<map_session_data> pl_sd;
- char character[100];
+ char character[100] {};
int new_status_point;
int point = 0;
- memset(character, '\0', sizeof(character));
-
if (!message || !*message
|| sscanf(message, "%d %99[^\n]", &point, character) < 2
|| point == 0)
@@ -4200,11 +4114,9 @@ int atcommand_charzeny(const int fd, dumb_ptr<map_session_data>,
const char *, const char *message)
{
dumb_ptr<map_session_data> pl_sd;
- char character[100];
+ char character[100] {};
int zeny = 0, new_zeny;
- memset(character, '\0', sizeof(character));
-
if (!message || !*message
|| sscanf(message, "%d %99[^\n]", &zeny, character) < 2 || zeny == 0)
{
@@ -4277,7 +4189,7 @@ int atcommand_recallall(const int fd, dumb_ptr<map_session_data> sd,
&& battle_config.any_warp_GM_min_level > pc_isGM(sd))
count++;
else
- pc_setpos(pl_sd, sd->mapname, sd->bl_x, sd->bl_y, BeingRemoveWhy::QUIT);
+ pc_setpos(pl_sd, sd->mapname_, sd->bl_x, sd->bl_y, BeingRemoveWhy::QUIT);
}
}
@@ -4300,12 +4212,10 @@ int atcommand_recallall(const int fd, dumb_ptr<map_session_data> sd,
int atcommand_partyrecall(const int fd, dumb_ptr<map_session_data> sd,
const char *, const char *message)
{
- char party_name[100];
+ char party_name[100] {};
struct party *p;
int count;
- memset(party_name, '\0', sizeof(party_name));
-
if (!message || !*message || sscanf(message, "%99[^\n]", party_name) < 1)
{
clif_displaymessage(fd,
@@ -4338,7 +4248,7 @@ int atcommand_partyrecall(const int fd, dumb_ptr<map_session_data> sd,
&& battle_config.any_warp_GM_min_level > pc_isGM(sd))
count++;
else
- pc_setpos(pl_sd, sd->mapname, sd->bl_x, sd->bl_y, BeingRemoveWhy::QUIT);
+ pc_setpos(pl_sd, sd->mapname_, sd->bl_x, sd->bl_y, BeingRemoveWhy::QUIT);
}
}
std::string output = STRPRINTF("All online characters of the %s party are near you.", p->name);
@@ -4442,12 +4352,10 @@ int atcommand_mapinfo(const int fd, dumb_ptr<map_session_data> sd,
const char *, const char *message)
{
dumb_ptr<npc_data> nd = NULL;
- char map_name[100];
+ char map_name[100] {};
const char *direction = NULL;
int list = 0;
- memset(map_name, '\0', sizeof(map_name));
-
sscanf(message, "%d %99[^\n]", &list, map_name);
if (list < 0 || list > 3)
@@ -4458,7 +4366,7 @@ int atcommand_mapinfo(const int fd, dumb_ptr<map_session_data> sd,
}
if (map_name[0] == '\0')
- strcpy(map_name, sd->mapname);
+ strcpy(map_name, sd->mapname_);
if (strstr(map_name, ".gat") == NULL && strstr(map_name, ".afm") == NULL && strlen(map_name) < 13) // 16 - 4 (.gat)
strcat(map_name, ".gat");
@@ -4519,7 +4427,7 @@ int atcommand_mapinfo(const int fd, dumb_ptr<map_session_data> sd,
continue;
dumb_ptr<map_session_data> pl_sd = dumb_ptr<map_session_data>(static_cast<map_session_data *>(session[i]->session_data.get()));
if (pl_sd && pl_sd->state.auth
- && strcmp(pl_sd->mapname, map_name) == 0)
+ && strcmp(pl_sd->mapname_, map_name) == 0)
{
output = STRPRINTF(
"Player '%s' (session #%d) | Location: %d,%d",
@@ -4591,11 +4499,9 @@ int atcommand_mapinfo(const int fd, dumb_ptr<map_session_data> sd,
int atcommand_partyspy(const int fd, dumb_ptr<map_session_data> sd,
const char *, const char *message)
{
- char party_name[100];
+ char party_name[100] {};
struct party *p;
- memset(party_name, '\0', sizeof(party_name));
-
if (!message || !*message || sscanf(message, "%99[^\n]", party_name) < 1)
{
clif_displaymessage(fd,
@@ -4635,9 +4541,7 @@ int atcommand_partyspy(const int fd, dumb_ptr<map_session_data> sd,
int atcommand_enablenpc(const int fd, dumb_ptr<map_session_data>,
const char *, const char *message)
{
- char NPCname[100];
-
- memset(NPCname, '\0', sizeof(NPCname));
+ char NPCname[100] {};
if (!message || !*message || sscanf(message, "%99[^\n]", NPCname) < 1)
{
@@ -4667,9 +4571,7 @@ int atcommand_enablenpc(const int fd, dumb_ptr<map_session_data>,
int atcommand_disablenpc(const int fd, dumb_ptr<map_session_data>,
const char *, const char *message)
{
- char NPCname[100];
-
- memset(NPCname, '\0', sizeof(NPCname));
+ char NPCname[100] {};
if (!message || !*message || sscanf(message, "%99[^\n]", NPCname) < 1)
{
@@ -4724,14 +4626,11 @@ int atcommand_chardelitem(const int fd, dumb_ptr<map_session_data> sd,
const char *, const char *message)
{
dumb_ptr<map_session_data> pl_sd;
- char character[100];
- char item_name[100];
+ char character[100] {};
+ char item_name[100] {};
int i, number = 0, item_id, item_position, count;
struct item_data *item_data;
- memset(character, '\0', sizeof(character));
- memset(item_name, '\0', sizeof(item_name));
-
if (!message || !*message
|| sscanf(message, "%s %d %99[^\n]", item_name, &number,
character) < 3 || number < 1)
@@ -4815,7 +4714,7 @@ int atcommand_broadcast(const int fd, dumb_ptr<map_session_data> sd,
}
std::string output = STRPRINTF("%s : %s", sd->status.name, message);
- intif_GMmessage(output, 0);
+ intif_GMmessage(output);
return 0;
}
@@ -4848,11 +4747,8 @@ int atcommand_localbroadcast(const int fd, dumb_ptr<map_session_data> sd,
int atcommand_email(const int fd, dumb_ptr<map_session_data> sd,
const char *, const char *message)
{
- char actual_email[100];
- char new_email[100];
-
- memset(actual_email, '\0', sizeof(actual_email));
- memset(new_email, '\0', sizeof(new_email));
+ char actual_email[100] {};
+ char new_email[100] {};
if (!message || !*message
|| sscanf(message, "%99s %99s", actual_email, new_email) < 2)
@@ -4939,10 +4835,8 @@ int atcommand_character_item_list(const int fd, dumb_ptr<map_session_data> sd,
dumb_ptr<map_session_data> pl_sd;
struct item_data *item_data, *item_temp;
int i, j, count, counter, counter2;
- char character[100], equipstr[100];
-
- memset(character, '\0', sizeof(character));
- memset(equipstr, '\0', sizeof(equipstr));
+ char character[100] {};
+ char equipstr[100];
if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1)
{
@@ -5009,7 +4903,7 @@ int atcommand_character_item_list(const int fd, dumb_ptr<map_session_data> sd,
equipstr[strlen(equipstr) - 2] = '\0';
}
else
- memset(equipstr, '\0', sizeof(equipstr));
+ strzcpy(equipstr, "", sizeof(equipstr));
std::string output;
if (sd->status.inventory[i].refine)
@@ -5102,9 +4996,7 @@ int atcommand_character_storage_list(const int fd, dumb_ptr<map_session_data> sd
dumb_ptr<map_session_data> pl_sd;
struct item_data *item_data, *item_temp;
int i, j, count, counter, counter2;
- char character[100];
-
- memset(character, '\0', sizeof(character));
+ char character[100] {};
if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1)
{
@@ -5233,9 +5125,7 @@ int atcommand_character_cart_list(const int fd, dumb_ptr<map_session_data> sd,
dumb_ptr<map_session_data> pl_sd;
struct item_data *item_data, *item_temp;
int i, j, count, counter, counter2;
- char character[100];
-
- memset(character, '\0', sizeof(character));
+ char character[100] {};
if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1)
{
@@ -5416,7 +5306,7 @@ int atcommand_charkillable(const int fd, dumb_ptr<map_session_data>,
int atcommand_npcmove(const int, dumb_ptr<map_session_data> sd,
const char *, const char *message)
{
- char character[100];
+ char character[100] {};
int x = 0, y = 0;
dumb_ptr<npc_data> nd = 0;
@@ -5426,8 +5316,6 @@ int atcommand_npcmove(const int, dumb_ptr<map_session_data> sd,
if (!message || !*message)
return -1;
- memset(character, '\0', sizeof character);
-
if (sscanf(message, "%d %d %99[^\n]", &x, &y, character) < 3)
return -1;
@@ -5461,7 +5349,7 @@ int atcommand_addwarp(const int fd, dumb_ptr<map_session_data> sd,
if (sscanf(message, "%29s %d %d[^\n]", mapname, &x, &y) < 3)
return -1;
- std::string w1 = STRPRINTF("%s,%d,%d", sd->mapname, sd->bl_x, sd->bl_y);
+ std::string w1 = STRPRINTF("%s,%d,%d", sd->mapname_, sd->bl_x, sd->bl_y);
std::string w3 = STRPRINTF("%s%d%d%d%d", mapname, sd->bl_x, sd->bl_y, x, y);
std::string w4 = STRPRINTF("1,1,%s.gat,%d,%d", mapname, x, y);
@@ -5900,11 +5788,9 @@ const char *magic_skill_names[magic_skills_nr] =
int atcommand_magic_info(const int fd, dumb_ptr<map_session_data>,
const char *, const char *message)
{
- char character[100];
+ char character[100] {};
dumb_ptr<map_session_data> pl_sd;
- memset(character, '\0', sizeof(character));
-
if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1)
{
clif_displaymessage(fd, "Usage: @magicinfo <char_name>");
@@ -5946,13 +5832,11 @@ void set_skill(dumb_ptr<map_session_data> sd, SkillID i, int level)
int atcommand_set_magic(const int fd, dumb_ptr<map_session_data>,
const char *, const char *message)
{
- char character[100];
+ char character[100] {};
char magic_type[20];
int value;
dumb_ptr<map_session_data> pl_sd;
- memset(character, '\0', sizeof(character));
-
if (!message || !*message
|| sscanf(message, "%19s %i %99[^\n]", magic_type, &value,
character) < 1)
@@ -6070,7 +5954,7 @@ int atcommand_jump_iterate(const int fd, dumb_ptr<map_session_data> sd,
"You are not authorised to warp you from your actual map.");
return -1;
}
- pc_setpos(sd, pl_sd->bl_m->name, pl_sd->bl_x, pl_sd->bl_y, BeingRemoveWhy::WARPED);
+ pc_setpos(sd, pl_sd->bl_m->name_, pl_sd->bl_x, pl_sd->bl_y, BeingRemoveWhy::WARPED);
std::string output = STRPRINTF("Jump to %s", pl_sd->status.name);
clif_displaymessage(fd, output);
@@ -6105,7 +5989,7 @@ int atcommand_wgm(const int fd, dumb_ptr<map_session_data> sd,
if (tmw_CheckChatSpam(sd, message))
return 0;
- tmw_GmHackMsg(static_cast<const std::string&>(STRPRINTF("[GM] %s: %s", sd->status.name, message)));
+ tmw_GmHackMsg(STRPRINTF("[GM] %s: %s", sd->status.name, message).c_str());
if (!pc_isGM(sd))
clif_displaymessage(fd, "Message sent.");
@@ -6258,12 +6142,10 @@ int atcommand_ipcheck(const int fd, dumb_ptr<map_session_data>,
const char *, const char *message)
{
struct sockaddr_in sai;
- char character[25];
+ char character[25] {};
socklen_t sa_len = sizeof(struct sockaddr);
unsigned long ip;
- memset(character, '\0', sizeof(character));
-
if (sscanf(message, "%24[^\n]", character) < 1)
{
clif_displaymessage(fd, "Usage: @ipcheck <char name>");
@@ -6304,7 +6186,7 @@ int atcommand_ipcheck(const int fd, dumb_ptr<map_session_data>,
{
std::string output = STRPRINTF(
"Name: %s | Location: %s %d %d",
- pl_sd->status.name, pl_sd->mapname,
+ pl_sd->status.name, pl_sd->mapname_,
pl_sd->bl_x, pl_sd->bl_y);
clif_displaymessage(fd, output);
}
diff --git a/src/map/battle.cpp b/src/map/battle.cpp
index 81e606f..93ccef8 100644
--- a/src/map/battle.cpp
+++ b/src/map/battle.cpp
@@ -1926,8 +1926,7 @@ struct Damage battle_calc_attack(BF attack_type,
dumb_ptr<block_list> target, SkillID skill_num,
int skill_lv, int flag)
{
- struct Damage d;
- memset(&d, 0, sizeof(d));
+ struct Damage d {};
switch (attack_type)
{
@@ -2041,7 +2040,7 @@ ATK battle_weapon_attack(dumb_ptr<block_list> src, dumb_ptr<block_list> target,
weapon = sd->inventory_data[weapon_index]->nameid;
MAP_LOG("PC%d %s:%d,%d WPNDMG %s%d %d FOR %d WPN %d",
- sd->status.char_id, src->bl_m->name, src->bl_x, src->bl_y,
+ sd->status.char_id, src->bl_m->name_, src->bl_x, src->bl_y,
(target->bl_type == BL::PC) ? "PC" : "MOB",
(target->bl_type == BL::PC)
? target->as_player()-> status.char_id
@@ -2054,7 +2053,7 @@ ATK battle_weapon_attack(dumb_ptr<block_list> src, dumb_ptr<block_list> target,
{
dumb_ptr<map_session_data> sd2 = target->as_player();
MAP_LOG("PC%d %s:%d,%d WPNINJURY %s%d %d FOR %d",
- sd2->status.char_id, target->bl_m->name, target->bl_x, target->bl_y,
+ sd2->status.char_id, target->bl_m->name_, target->bl_x, target->bl_y,
(src->bl_type == BL::PC) ? "PC" : "MOB",
(src->bl_type == BL::PC)
? src->as_player()->status.char_id
@@ -2323,7 +2322,6 @@ int battle_config_read(const char *cfgName)
battle_config.base_exp_rate = 100;
battle_config.job_exp_rate = 100;
- battle_config.pvp_exp = 1;
battle_config.gtb_pvp_only = 0;
battle_config.death_penalty_type = 0;
battle_config.death_penalty_base = 0;
@@ -2503,7 +2501,6 @@ int battle_config_read(const char *cfgName)
{"item_third_get_time", &battle_config.item_third_get_time},
{"base_exp_rate", &battle_config.base_exp_rate},
{"job_exp_rate", &battle_config.job_exp_rate},
- {"pvp_exp", &battle_config.pvp_exp},
{"gtb_pvp_only", &battle_config.gtb_pvp_only},
{"death_penalty_type", &battle_config.death_penalty_type},
{"death_penalty_base", &battle_config.death_penalty_base},
diff --git a/src/map/battle.hpp b/src/map/battle.hpp
index 168cf60..4e410ef 100644
--- a/src/map/battle.hpp
+++ b/src/map/battle.hpp
@@ -114,7 +114,6 @@ extern struct Battle_Config
int base_exp_rate, job_exp_rate;
int death_penalty_type;
int death_penalty_base, death_penalty_job;
- int pvp_exp; // [MouseJstr]
int gtb_pvp_only; // [MouseJstr]
int zeny_penalty;
int restart_hp_rate;
diff --git a/src/map/chrif.cpp b/src/map/chrif.cpp
index ebed281..f2d5ec7 100644
--- a/src/map/chrif.cpp
+++ b/src/map/chrif.cpp
@@ -110,7 +110,7 @@ int chrif_save(dumb_ptr<map_session_data> sd)
WFIFOW(char_fd, 2) = sizeof(sd->status) + 12;
WFIFOL(char_fd, 4) = sd->bl_id;
WFIFOL(char_fd, 8) = sd->char_id;
- memcpy(WFIFOP(char_fd, 12), &sd->status, sizeof(sd->status));
+ WFIFO_STRUCT(char_fd, 12, sd->status);
WFIFOSET(char_fd, WFIFOW(char_fd, 2));
//For data sync
@@ -128,8 +128,8 @@ static
int chrif_connect(int fd)
{
WFIFOW(fd, 0) = 0x2af8;
- memcpy(WFIFOP(fd, 2), userid, 24);
- memcpy(WFIFOP(fd, 26), passwd, 24);
+ WFIFO_STRING(fd, 2, userid, 24);
+ WFIFO_STRING(fd, 26, passwd, 24);
WFIFOL(fd, 50) = 0;
WFIFOL(fd, 54) = clif_getip().s_addr;
WFIFOW(fd, 58) = clif_getport(); // [Valaris] thanks to fov
@@ -153,7 +153,7 @@ int chrif_sendmap(int fd)
map_abstract *ma = pair.second.get();
if (!ma->gat)
continue;
- memcpy(WFIFOP(fd, 4 + i * 16), ma->name, 16);
+ WFIFO_STRING(fd, 4 + i * 16, ma->name_, 16);
i++;
}
WFIFOW(fd, 2) = 4 + i * 16;
@@ -213,7 +213,7 @@ int chrif_changemapserver(dumb_ptr<map_session_data> sd, char *name, int x,
WFIFOL(char_fd, 6) = sd->login_id1;
WFIFOL(char_fd, 10) = sd->login_id2;
WFIFOL(char_fd, 14) = sd->status.char_id;
- memcpy(WFIFOP(char_fd, 18), name, 16);
+ WFIFO_STRING(char_fd, 18, name, 16);
WFIFOW(char_fd, 34) = x;
WFIFOW(char_fd, 36) = y;
WFIFOL(char_fd, 38) = ip.s_addr;
@@ -292,7 +292,7 @@ int chrif_sendmapack(int fd)
exit(1);
}
- memcpy(wisp_server_name, RFIFOP(fd, 3), 24);
+ RFIFO_STRING(fd, 3, wisp_server_name, 24);
chrif_state = 2;
@@ -387,7 +387,7 @@ int chrif_changegm(int id, const char *pass, int len)
WFIFOW(char_fd, 0) = 0x2b0a;
WFIFOW(char_fd, 2) = len + 8;
WFIFOL(char_fd, 4) = id;
- memcpy(WFIFOP(char_fd, 8), pass, len);
+ WFIFO_STRING(char_fd, 8, pass, len);
WFIFOSET(char_fd, len + 8);
return 0;
@@ -406,8 +406,8 @@ int chrif_changeemail(int id, const char *actual_email,
WFIFOW(char_fd, 0) = 0x2b0c;
WFIFOL(char_fd, 2) = id;
- memcpy(WFIFOP(char_fd, 6), actual_email, 40);
- memcpy(WFIFOP(char_fd, 46), new_email, 40);
+ WFIFO_STRING(char_fd, 6, actual_email, 40);
+ WFIFO_STRING(char_fd, 46, new_email, 40);
WFIFOSET(char_fd, 86);
return 0;
@@ -430,7 +430,7 @@ int chrif_char_ask_name(int id, char *character_name, short operation_type,
{
WFIFOW(char_fd, 0) = 0x2b0e;
WFIFOL(char_fd, 2) = id; // account_id of who ask (for answer) -1 if nobody
- memcpy(WFIFOP(char_fd, 6), character_name, 24);
+ WFIFO_STRING(char_fd, 6, character_name, 24);
WFIFOW(char_fd, 30) = operation_type; // type of operation
if (operation_type == 2)
{
@@ -471,8 +471,7 @@ int chrif_char_ask_name_answer(int fd)
char player_name[24];
acc = RFIFOL(fd, 2); // account_id of who has asked (-1 if nobody)
- memcpy(player_name, RFIFOP(fd, 6), sizeof(player_name));
- player_name[sizeof(player_name) - 1] = '\0';
+ RFIFO_STRING(fd, 6, player_name, 24);
sd = map_id2sd(acc);
if (acc >= 0 && sd != NULL)
@@ -692,7 +691,7 @@ int chrif_saveaccountreg2(dumb_ptr<map_session_data> sd)
struct global_reg *reg = &sd->status.account_reg2[j];
if (reg->str[0] && reg->value != 0)
{
- memcpy(WFIFOP(char_fd, p), reg->str, 32);
+ WFIFO_STRING(char_fd, p, reg->str, 32);
WFIFOL(char_fd, p + 32) = reg->value;
p += 36;
}
@@ -721,7 +720,7 @@ int chrif_accountreg2(int fd)
for (p = 8, j = 0; p < RFIFOW(fd, 2) && j < ACCOUNT_REG2_NUM;
p += 36, j++)
{
- memcpy(sd->status.account_reg2[j].str, RFIFOP(fd, p), 32);
+ RFIFO_STRING(fd, p, sd->status.account_reg2[j].str, 32);
sd->status.account_reg2[j].value = RFIFOL(fd, p + 32);
}
sd->status.account_reg2_num = j;
diff --git a/src/map/clif.cpp b/src/map/clif.cpp
index f20c887..c37916b 100644
--- a/src/map/clif.cpp
+++ b/src/map/clif.cpp
@@ -123,7 +123,7 @@ int clif_changelook_towards(dumb_ptr<block_list> bl, LOOK type, int val,
*/
void clif_setip(const char *ip)
{
- memcpy(map_ip_str, ip, 16);
+ strzcpy(map_ip_str, ip, 16);
map_ip.s_addr = inet_addr(map_ip_str);
}
@@ -261,7 +261,7 @@ void clif_send_sub(dumb_ptr<block_list> bl, const unsigned char *buf, int len,
if (clif_parse_func_table[RBUFW(buf, 0)].len)
{
// packet must exist
- memcpy(WFIFOP(sd->fd, 0), buf, len);
+ WFIFO_BUF_CLONE(sd->fd, buf, len);
WFIFOSET(sd->fd, len);
}
}
@@ -318,7 +318,7 @@ int clif_send(const uint8_t *buf, int len, dumb_ptr<block_list> bl, SendWho type
if (clif_parse_func_table[RBUFW(buf, 0)].len)
{
// packet must exist
- memcpy(WFIFOP(i, 0), buf, len);
+ WFIFO_BUF_CLONE(i, buf, len);
WFIFOSET(i, len);
}
}
@@ -335,7 +335,7 @@ int clif_send(const uint8_t *buf, int len, dumb_ptr<block_list> bl, SendWho type
if (clif_parse_func_table[RBUFW(buf, 0)].len)
{
// packet must exist
- memcpy(WFIFOP(i, 0), buf, len);
+ WFIFO_BUF_CLONE(i, buf, len);
WFIFOSET(i, len);
}
}
@@ -401,7 +401,7 @@ int clif_send(const uint8_t *buf, int len, dumb_ptr<block_list> bl, SendWho type
if (clif_parse_func_table[RBUFW(buf, 0)].len)
{
// packet must exist
- memcpy(WFIFOP(sd->fd, 0), buf, len);
+ WFIFO_BUF_CLONE(sd->fd, buf, len);
WFIFOSET(sd->fd, len);
}
}
@@ -418,7 +418,7 @@ int clif_send(const uint8_t *buf, int len, dumb_ptr<block_list> bl, SendWho type
if (clif_parse_func_table[RBUFW(buf, 0)].len)
{
// packet must exist
- memcpy(WFIFOP(sd->fd, 0), buf, len);
+ WFIFO_BUF_CLONE(sd->fd, buf, len);
WFIFOSET(sd->fd, len);
}
}
@@ -432,7 +432,7 @@ int clif_send(const uint8_t *buf, int len, dumb_ptr<block_list> bl, SendWho type
if (clif_parse_func_table[RBUFW(buf, 0)].len)
{
// packet must exist
- memcpy(WFIFOP(sd->fd, 0), buf, len);
+ WFIFO_BUF_CLONE(sd->fd, buf, len);
WFIFOSET(sd->fd, len);
}
}
@@ -584,7 +584,7 @@ int clif_clearflooritem(dumb_ptr<flooritem_data> fitem, int fd)
}
else
{
- memcpy(WFIFOP(fd, 0), buf, 6);
+ WFIFO_BUF_CLONE(fd, buf, 6);
WFIFOSET(fd, clif_parse_func_table[0xa1].len);
}
@@ -653,17 +653,12 @@ int clif_clearchar_delay(tick_t tick,
*
*------------------------------------------
*/
-int clif_clearchar_id(int id, BeingRemoveWhy type, int fd)
+void clif_clearchar_id(int id, BeingRemoveWhy type, int fd)
{
- unsigned char buf[16];
-
- WBUFW(buf, 0) = 0x80;
- WBUFL(buf, 2) = id;
- WBUFB(buf, 6) = static_cast<uint8_t>(type);
- memcpy(WFIFOP(fd, 0), buf, 7);
+ WFIFOW(fd, 0) = 0x80;
+ WFIFOL(fd, 2) = id;
+ WFIFOB(fd, 6) = static_cast<uint8_t>(type);
WFIFOSET(fd, clif_parse_func_table[0x80].len);
-
- return 0;
}
/*==========================================
@@ -800,9 +795,7 @@ int clif_set007b(dumb_ptr<map_session_data> sd, unsigned char *buf)
static
int clif_mob0078(dumb_ptr<mob_data> md, unsigned char *buf)
{
- int level;
-
- memset(buf, 0, clif_parse_func_table[0x78].len);
+ really_memset0(buf, clif_parse_func_table[0x78].len);
nullpo_ret(md);
@@ -820,10 +813,8 @@ int clif_mob0078(dumb_ptr<mob_data> md, unsigned char *buf)
WBUFB(buf, 48) |= dir;
WBUFB(buf, 49) = 5;
WBUFB(buf, 50) = 5;
- WBUFW(buf, 52) =
- ((level =
- battle_get_lv(md)) >
- battle_config.max_lv) ? battle_config.max_lv : level;
+ int level = battle_get_lv(md);
+ WBUFW(buf, 52) = (level > battle_config.max_lv) ? battle_config.max_lv : level;
return clif_parse_func_table[0x78].len;
}
@@ -835,9 +826,7 @@ int clif_mob0078(dumb_ptr<mob_data> md, unsigned char *buf)
static
int clif_mob007b(dumb_ptr<mob_data> md, unsigned char *buf)
{
- int level;
-
- memset(buf, 0, clif_parse_func_table[0x7b].len);
+ really_memset0(buf, clif_parse_func_table[0x7b].len);
nullpo_ret(md);
@@ -854,10 +843,8 @@ int clif_mob007b(dumb_ptr<mob_data> md, unsigned char *buf)
WBUFPOS2(buf, 50, md->bl_x, md->bl_y, md->to_x, md->to_y);
WBUFB(buf, 56) = 5;
WBUFB(buf, 57) = 5;
- WBUFW(buf, 58) =
- ((level =
- battle_get_lv(md)) >
- battle_config.max_lv) ? battle_config.max_lv : level;
+ int level = battle_get_lv(md);
+ WBUFW(buf, 58) = (level > battle_config.max_lv) ? battle_config.max_lv : level;
return clif_parse_func_table[0x7b].len;
}
@@ -871,7 +858,7 @@ int clif_npc0078(dumb_ptr<npc_data> nd, unsigned char *buf)
{
nullpo_ret(nd);
- memset(buf, 0, clif_parse_func_table[0x78].len);
+ really_memset0(buf, clif_parse_func_table[0x78].len);
WBUFW(buf, 0) = 0x78;
WBUFL(buf, 2) = nd->bl_id;
@@ -953,7 +940,7 @@ int clif_spawnnpc(dumb_ptr<npc_data> nd)
if (nd->npc_class < 0 || nd->flag & 1 || nd->npc_class == INVISIBLE_CLASS)
return 0;
- memset(buf, 0, clif_parse_func_table[0x7c].len);
+ really_memset0(buf, clif_parse_func_table[0x7c].len);
WBUFW(buf, 0) = 0x7c;
WBUFL(buf, 2) = nd->bl_id;
@@ -1018,7 +1005,7 @@ int clif_spawnmob(dumb_ptr<mob_data> md)
nullpo_ret(md);
{
- memset(buf, 0, clif_parse_func_table[0x7c].len);
+ really_memset0(buf, clif_parse_func_table[0x7c].len);
WBUFW(buf, 0) = 0x7c;
WBUFL(buf, 2) = md->bl_id;
@@ -1137,55 +1124,47 @@ void clif_setwaitclose(int fd)
*
*------------------------------------------
*/
-int clif_changemap(dumb_ptr<map_session_data> sd, const char *mapname, int x, int y)
+void clif_changemap(dumb_ptr<map_session_data> sd, const char *mapname, int x, int y)
{
- int fd;
-
- nullpo_ret(sd);
+ nullpo_retv(sd);
- fd = sd->fd;
+ int fd = sd->fd;
WFIFOW(fd, 0) = 0x91;
- memcpy(WFIFOP(fd, 2), mapname, 16);
+ WFIFO_STRING(fd, 2, mapname, 16);
WFIFOW(fd, 18) = x;
WFIFOW(fd, 20) = y;
WFIFOSET(fd, clif_parse_func_table[0x91].len);
-
- return 0;
}
/*==========================================
*
*------------------------------------------
*/
-int clif_changemapserver(dumb_ptr<map_session_data> sd, const char *mapname, int x,
+void clif_changemapserver(dumb_ptr<map_session_data> sd, const char *mapname, int x,
int y, struct in_addr ip, int port)
{
- int fd;
-
- nullpo_ret(sd);
+ nullpo_retv(sd);
- fd = sd->fd;
+ int fd = sd->fd;
WFIFOW(fd, 0) = 0x92;
- memcpy(WFIFOP(fd, 2), mapname, 16);
+ WFIFO_STRING(fd, 2, mapname, 16);
WFIFOW(fd, 18) = x;
WFIFOW(fd, 20) = y;
WFIFOL(fd, 22) = ip.s_addr;
WFIFOW(fd, 26) = port;
WFIFOSET(fd, clif_parse_func_table[0x92].len);
-
- return 0;
}
/*==========================================
*
*------------------------------------------
*/
-int clif_fixpos(dumb_ptr<block_list> bl)
+void clif_fixpos(dumb_ptr<block_list> bl)
{
uint8_t buf[16];
- nullpo_ret(bl);
+ nullpo_retv(bl);
WBUFW(buf, 0) = 0x88;
WBUFL(buf, 2) = bl->bl_id;
@@ -1193,8 +1172,6 @@ int clif_fixpos(dumb_ptr<block_list> bl)
WBUFW(buf, 8) = bl->bl_y;
clif_send(buf, clif_parse_func_table[0x88].len, bl, SendWho::AREA);
-
- return 0;
}
/*==========================================
@@ -1418,25 +1395,6 @@ int clif_viewpoint(dumb_ptr<map_session_data> sd, int npc_id, int type, int x,
*
*------------------------------------------
*/
-int clif_cutin(dumb_ptr<map_session_data> sd, const char *image, int type)
-{
- int fd;
-
- nullpo_ret(sd);
-
- fd = sd->fd;
- WFIFOW(fd, 0) = 0x1b3;
- memcpy(WFIFOP(fd, 2), image, 64);
- WFIFOB(fd, 66) = type;
- WFIFOSET(fd, clif_parse_func_table[0x1b3].len);
-
- return 0;
-}
-
-/*==========================================
- *
- *------------------------------------------
- */
int clif_additem(dumb_ptr<map_session_data> sd, int n, int amount, PickupFail fail)
{
nullpo_ret(sd);
@@ -3009,7 +2967,7 @@ int clif_skillinfo(dumb_ptr<map_session_data> sd, SkillID skillid, int type,
}
else
WFIFOW(fd, 12) = range;
- memset(WFIFOP(fd, 14), 0, 24);
+ WFIFO_ZERO(fd, 14, 24);
WFIFOB(fd, 38) = sd->status.skill[skillid].lv < skill_get_max_raise(skillid);
WFIFOSET(fd, clif_parse_func_table[0x147].len);
@@ -3020,12 +2978,12 @@ int clif_skillinfo(dumb_ptr<map_session_data> sd, SkillID skillid, int type,
* スキルリストを送信する
*------------------------------------------
*/
-int clif_skillinfoblock(dumb_ptr<map_session_data> sd)
+void clif_skillinfoblock(dumb_ptr<map_session_data> sd)
{
int fd;
int len = 4, range;
- nullpo_ret(sd);
+ nullpo_retv(sd);
fd = sd->fd;
WFIFOW(fd, 0) = 0x10f;
@@ -3045,15 +3003,13 @@ int clif_skillinfoblock(dumb_ptr<map_session_data> sd)
if (range < 0)
range = battle_get_range(sd) - (range + 1);
WFIFOW(fd, len + 10) = range;
- memset(WFIFOP(fd, len + 12), 0, 24);
+ WFIFO_ZERO(fd, len + 12, 24);
WFIFOB(fd, len + 36) = sd->status.skill[i].lv < skill_get_max_raise(i);
len += 37;
}
}
WFIFOW(fd, 2) = len;
WFIFOSET(fd, len);
-
- return 0;
}
/*==========================================
@@ -3187,10 +3143,10 @@ void clif_displaymessage(int fd, const_string mes)
{
// don't send a void message (it's not displaying on the client chat). @help can send void line.
WFIFOW(fd, 0) = 0x8e;
- WFIFOW(fd, 2) = 5 + mes.size(); // 4 + len + NULL teminate
- memcpy(WFIFOP(fd, 4), mes.data(), mes.size());
- WFIFOB(fd, 4 + mes.size()) = '\0';
- WFIFOSET(fd, 5 + mes.size());
+ 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);
+ WFIFOSET(fd, 4 + str_len);
}
}
@@ -3200,14 +3156,12 @@ void clif_displaymessage(int fd, const_string mes)
*/
void clif_GMmessage(dumb_ptr<block_list> bl, const_string mes, int flag)
{
- unsigned char buf[mes.size() + 16];
- int lp = (flag & 0x10) ? 8 : 4;
+ size_t str_len = mes.size() + 1;
+ unsigned char buf[str_len + 4];
WBUFW(buf, 0) = 0x9a;
- WBUFW(buf, 2) = mes.size() + 1 + lp;
- WBUFL(buf, 4) = 0x65756c62;
- memcpy(WBUFP(buf, lp), mes.data(), mes.size());
- WBUFB(buf, lp + mes.size()) = '\0';
+ WBUFW(buf, 2) = str_len + 4;
+ WBUF_STRING(buf, 4, mes.data(), str_len);
flag &= 0x07;
clif_send(buf, WBUFW(buf, 2), bl,
(flag == 1) ? SendWho::ALL_SAMEMAP :
@@ -3220,45 +3174,43 @@ void clif_GMmessage(dumb_ptr<block_list> bl, const_string mes, int flag)
* 復活する
*------------------------------------------
*/
-int clif_resurrection(dumb_ptr<block_list> bl, int type)
+void clif_resurrection(dumb_ptr<block_list> bl, int type)
{
- unsigned char buf[16];
+ uint8_t buf[16];
- nullpo_ret(bl);
+ nullpo_retv(bl);
WBUFW(buf, 0) = 0x148;
WBUFL(buf, 2) = bl->bl_id;
WBUFW(buf, 6) = type;
- clif_send(buf, clif_parse_func_table[0x148].len, bl, type == 1 ? SendWho::AREA : SendWho::AREA_WOS);
-
- return 0;
+ clif_send(buf, clif_parse_func_table[0x148].len, bl,
+ type == 1 ? SendWho::AREA : SendWho::AREA_WOS);
}
/*==========================================
* Wisp/page is transmitted to the destination player
*------------------------------------------
*/
-int clif_wis_message(int fd, const char *nick, const char *mes, int mes_len) // R 0097 <len>.w <nick>.24B <message>.?B
+void clif_wis_message(int fd, const char *nick, const char *mes) // R 0097 <len>.w <nick>.24B <message>.?B
{
+ size_t mes_len = strlen(mes) + 1;
WFIFOW(fd, 0) = 0x97;
WFIFOW(fd, 2) = mes_len + 24 + 4;
- memcpy(WFIFOP(fd, 4), nick, 24);
- memcpy(WFIFOP(fd, 28), mes, mes_len);
+ WFIFO_STRING(fd, 4, nick, 24);
+ WFIFO_STRING(fd, 28, mes, mes_len);
WFIFOSET(fd, WFIFOW(fd, 2));
- return 0;
}
/*==========================================
* The transmission result of Wisp/page is transmitted to the source player
*------------------------------------------
*/
-int clif_wis_end(int fd, int flag) // R 0098 <type>.B: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target
+void clif_wis_end(int fd, int flag) // R 0098 <type>.B: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target
{
WFIFOW(fd, 0) = 0x98;
WFIFOW(fd, 2) = flag;
WFIFOSET(fd, clif_parse_func_table[0x98].len);
- return 0;
}
/*==========================================
@@ -3299,7 +3251,7 @@ int clif_party_info(struct party *p, int fd)
nullpo_ret(p);
WBUFW(buf, 0) = 0xfb;
- memcpy(WBUFP(buf, 4), p->name, 24);
+ WBUF_STRING(buf, 4, p->name, 24);
for (i = c = 0; i < MAX_PARTY; i++)
{
struct party_member *m = &p->member[i];
@@ -3308,22 +3260,25 @@ int clif_party_info(struct party *p, int fd)
if (sd == NULL)
sd = dumb_ptr<map_session_data>(m->sd);
WBUFL(buf, 28 + c * 46) = m->account_id;
- memcpy(WBUFP(buf, 28 + c * 46 + 4), m->name, 24);
- memcpy(WBUFP(buf, 28 + c * 46 + 28), m->map, 16);
+ WBUF_STRING(buf, 28 + c * 46 + 4, m->name, 24);
+ WBUF_STRING(buf, 28 + c * 46 + 28, m->map, 16);
WBUFB(buf, 28 + c * 46 + 44) = (m->leader) ? 0 : 1;
WBUFB(buf, 28 + c * 46 + 45) = (m->online) ? 0 : 1;
c++;
}
}
- WBUFW(buf, 2) = 28 + c * 46;
+ size_t len = 28 + c * 46;
+ WBUFW(buf, 2) = len;
if (fd >= 0)
- { // fdが設定されてるならそれに送る
- memcpy(WFIFOP(fd, 0), buf, WBUFW(buf, 2));
- WFIFOSET(fd, WFIFOW(fd, 2));
+ {
+ // If set, send only to fd.
+ WFIFO_BUF_CLONE(fd, buf, len);
+ WFIFOSET(fd, len);
return 9;
}
+ // else, send it to all the party, if they exist.
if (sd != NULL)
- clif_send(buf, WBUFW(buf, 2), sd, SendWho::PARTY);
+ clif_send(buf, len, sd, SendWho::PARTY);
return 0;
}
@@ -3334,25 +3289,24 @@ int clif_party_info(struct party *p, int fd)
* (R 00fe <sender_ID>.l <party_name>.24B)
*------------------------------------------
*/
-int clif_party_invite(dumb_ptr<map_session_data> sd,
+void clif_party_invite(dumb_ptr<map_session_data> sd,
dumb_ptr<map_session_data> tsd)
{
int fd;
struct party *p;
- nullpo_ret(sd);
- nullpo_ret(tsd);
+ nullpo_retv(sd);
+ nullpo_retv(tsd);
fd = tsd->fd;
if (!(p = party_search(sd->status.party_id)))
- return 0;
+ return;
WFIFOW(fd, 0) = 0xfe;
WFIFOL(fd, 2) = sd->status.account_id;
- memcpy(WFIFOP(fd, 6), p->name, 24);
+ WFIFO_STRING(fd, 6, p->name, 24);
WFIFOSET(fd, clif_parse_func_table[0xfe].len);
- return 0;
}
/*==========================================
@@ -3377,7 +3331,7 @@ int clif_party_inviteack(dumb_ptr<map_session_data> sd, const char *nick, int fl
fd = sd->fd;
WFIFOW(fd, 0) = 0xfd;
- memcpy(WFIFOP(fd, 2), nick, 24);
+ WFIFO_STRING(fd, 2, nick, 24);
WFIFOB(fd, 26) = flag;
WFIFOSET(fd, clif_parse_func_table[0xfd].len);
return 0;
@@ -3390,11 +3344,11 @@ int clif_party_inviteack(dumb_ptr<map_session_data> sd, const char *nick, int fl
* 0x100=一人にのみ送信
*------------------------------------------
*/
-int clif_party_option(struct party *p, dumb_ptr<map_session_data> sd, int flag)
+void clif_party_option(struct party *p, dumb_ptr<map_session_data> sd, int flag)
{
unsigned char buf[16];
- nullpo_ret(p);
+ nullpo_retv(p);
// if(battle_config.etc_log)
// PRINTF("clif_party_option: %d %d %d\n",p->exp,p->item,flag);
@@ -3406,7 +3360,7 @@ int clif_party_option(struct party *p, dumb_ptr<map_session_data> sd, int flag)
break;
}
if (sd == NULL)
- return 0;
+ return;
WBUFW(buf, 0) = 0x101;
WBUFW(buf, 2) = ((flag & 0x01) ? 2 : p->exp);
WBUFW(buf, 4) = ((flag & 0x10) ? 2 : p->item);
@@ -3414,10 +3368,9 @@ int clif_party_option(struct party *p, dumb_ptr<map_session_data> sd, int flag)
clif_send(buf, clif_parse_func_table[0x101].len, sd, SendWho::PARTY);
else
{
- memcpy(WFIFOP(sd->fd, 0), buf, clif_parse_func_table[0x101].len);
+ WFIFO_BUF_CLONE(sd->fd, buf, clif_parse_func_table[0x101].len);
WFIFOSET(sd->fd, clif_parse_func_table[0x101].len);
}
- return 0;
}
/*==========================================
@@ -3434,7 +3387,7 @@ int clif_party_leaved(struct party *p, dumb_ptr<map_session_data> sd,
WBUFW(buf, 0) = 0x105;
WBUFL(buf, 2) = account_id;
- memcpy(WBUFP(buf, 6), name, 24);
+ WBUF_STRING(buf, 6, name, 24);
WBUFB(buf, 30) = flag & 0x0f;
if ((flag & 0xf0) == 0)
@@ -3451,7 +3404,7 @@ int clif_party_leaved(struct party *p, dumb_ptr<map_session_data> sd,
}
else if (sd != NULL)
{
- memcpy(WFIFOP(sd->fd, 0), buf, clif_parse_func_table[0x105].len);
+ WFIFO_BUF_CLONE(sd->fd, buf, clif_parse_func_table[0x105].len);
WFIFOSET(sd->fd, clif_parse_func_table[0x105].len);
}
return 0;
@@ -3461,13 +3414,13 @@ int clif_party_leaved(struct party *p, dumb_ptr<map_session_data> sd,
* パーティメッセージ送信
*------------------------------------------
*/
-int clif_party_message(struct party *p, int account_id, const char *mes, int len)
+void clif_party_message(struct party *p, int account_id, const char *mes)
{
// always set, but clang is not smart enough
dumb_ptr<map_session_data> sd = nullptr;
int i;
- nullpo_ret(p);
+ nullpo_retv(p);
for (i = 0; i < MAX_PARTY; i++)
{
@@ -3477,14 +3430,14 @@ int clif_party_message(struct party *p, int account_id, const char *mes, int len
}
if (sd != NULL)
{
- unsigned char buf[1024];
+ size_t len = strlen(mes) + 1;
+ unsigned char buf[len + 8];
WBUFW(buf, 0) = 0x109;
WBUFW(buf, 2) = len + 8;
WBUFL(buf, 4) = account_id;
- memcpy(WBUFP(buf, 8), mes, len);
+ WBUF_STRING(buf, 8, mes, len);
clif_send(buf, len + 8, sd, SendWho::PARTY);
}
- return 0;
}
/*==========================================
@@ -3601,7 +3554,7 @@ void clif_emotion_towards(dumb_ptr<block_list> bl,
WBUFL(buf, 2) = bl->bl_id;
WBUFB(buf, 6) = type;
- memcpy(WFIFOP(sd->fd, 0), buf, len);
+ WFIFO_BUF_CLONE(sd->fd, buf, len);
WFIFOSET(sd->fd, len);
}
@@ -3663,7 +3616,7 @@ int clif_specialeffect(dumb_ptr<block_list> bl, int type, int flag)
nullpo_ret(bl);
- memset(buf, 0, clif_parse_func_table[0x19b].len);
+ WBUF_ZERO(buf, 0, clif_parse_func_table[0x19b].len);
WBUFW(buf, 0) = 0x19b;
WBUFL(buf, 2) = bl->bl_id;
@@ -3963,9 +3916,9 @@ void clif_parse_GetCharNameRequest(int fd, dumb_ptr<map_session_data> sd)
nullpo_retv(ssd);
if (ssd->state.shroud_active)
- memset(WFIFOP(fd, 6), 0, 24);
+ WFIFO_STRING(fd, 6, "", 24);
else
- memcpy(WFIFOP(fd, 6), ssd->status.name, 24);
+ WFIFO_STRING(fd, 6, ssd->status.name, 24);
WFIFOSET(fd, clif_parse_func_table[0x95].len);
struct party *p = NULL;
@@ -3984,10 +3937,10 @@ void clif_parse_GetCharNameRequest(int fd, dumb_ptr<map_session_data> sd)
{
WFIFOW(fd, 0) = 0x195;
WFIFOL(fd, 2) = account_id;
- memcpy(WFIFOP(fd, 6), party_name, 24);
- memcpy(WFIFOP(fd, 30), "", 24);
- memcpy(WFIFOP(fd, 54), "", 24);
- memcpy(WFIFOP(fd, 78), "", 24); // We send this value twice because the client expects it
+ WFIFO_STRING(fd, 6, party_name, 24);
+ WFIFO_STRING(fd, 30, "", 24);
+ WFIFO_STRING(fd, 54, "", 24);
+ WFIFO_STRING(fd, 78, "", 24); // We send this value twice because the client expects it
WFIFOSET(fd, clif_parse_func_table[0x195].len);
}
@@ -4009,19 +3962,21 @@ void clif_parse_GetCharNameRequest(int fd, dumb_ptr<map_session_data> sd)
}
break;
case BL::NPC:
- memcpy(WFIFOP(fd, 6), bl->as_npc()->name, 24);
+ {
+ char name[24];
+ strzcpy(name, bl->as_npc()->name, 24);
+ // [fate] elim hashed out/invisible names for the client
+ *strchrnul(name, '#') = '\0';
+ for (char& c : name)
{
- char *start = static_cast<char *>(WFIFOP(fd, 6));
- char *end = strchr(start, '#'); // [fate] elim hashed out/invisible names for the client
- if (end)
- while (*end)
- *end++ = 0;
-
// [fate] Elim preceding underscores for (hackish) name position fine-tuning
- while (*start == '_')
- *start++ = ' ';
+ if (c != '_')
+ break;
+ c = ' ';
}
+ WFIFO_STRING(fd, 6, name, 24);
WFIFOSET(fd, clif_parse_func_table[0x95].len);
+ }
break;
case BL::MOB:
{
@@ -4029,7 +3984,7 @@ void clif_parse_GetCharNameRequest(int fd, dumb_ptr<map_session_data> sd)
nullpo_retv(md);
- memcpy(WFIFOP(fd, 6), md->name, 24);
+ WFIFO_STRING(fd, 6, md->name, 24);
WFIFOSET(fd, clif_parse_func_table[0x95].len);
}
break;
@@ -4073,39 +4028,39 @@ void clif_parse_GlobalMessage(int fd, dumb_ptr<map_session_data> sd)
}
/* It's not a spell/magic message, so send the message to others. */
- uint8_t sendbuf[mbuf.size() + 8];
+ size_t mbuf_size = mbuf.size() + 1;
+ uint8_t sendbuf[mbuf_size + 8];
WBUFW(sendbuf, 0) = 0x8d;
- WBUFW(sendbuf, 2) = mbuf.size() + 8; /* Header(2) + length(2) + ID(4). */
+ WBUFW(sendbuf, 2) = mbuf_size + 8; /* Header(2) + length(2) + ID(4). */
WBUFL(sendbuf, 4) = sd->bl_id;
- memcpy(WBUFP(sendbuf, 8), mbuf.data(), mbuf.size());
+ WBUF_STRING(sendbuf, 8, mbuf.c_str(), mbuf_size);
- clif_send(sendbuf, mbuf.size() + 8, sd, SendWho::AREA_CHAT_WOC);
+ clif_send(sendbuf, mbuf_size + 8, sd, SendWho::AREA_CHAT_WOC);
}
/* Send the message back to the speaker. */
- memcpy(WFIFOP(fd, 0), RFIFOP(fd, 0), RFIFOW(fd, 2));
+ size_t len = RFIFOW(fd, 2);
+ RFIFO_WFIFO_CLONE(fd, fd, len);
WFIFOW(fd, 0) = 0x8e;
- WFIFOSET(fd, WFIFOW(fd, 2));
+ WFIFOSET(fd, len);
}
-int clif_message(dumb_ptr<block_list> bl, const char *msg)
+void clif_message(dumb_ptr<block_list> bl, const char *msg)
{
- unsigned short msg_len = strlen(msg) + 1;
- unsigned char buf[512];
+ size_t msg_len = strlen(msg) + 1;
+ uint8_t buf[512];
if (msg_len + 16 > 512)
- return 0;
+ return;
- nullpo_ret(bl);
+ nullpo_retv(bl);
WBUFW(buf, 0) = 0x8d;
WBUFW(buf, 2) = msg_len + 8;
WBUFL(buf, 4) = bl->bl_id;
- memcpy(WBUFP(buf, 8), msg, msg_len);
+ WBUF_STRING(buf, 8, msg, msg_len);
clif_send(buf, WBUFW(buf, 2), bl, SendWho::AREA);
-
- return 0;
}
/*==========================================
@@ -4225,12 +4180,10 @@ void clif_parse_ActionRequest(int fd, dumb_ptr<map_session_data> sd)
break;
case 0x02: // sitdown
pc_stop_walking(sd, 1);
- skill_gangsterparadise(sd, 1); // ギャングスターパラダイス設定
pc_setsit(sd);
clif_sitting(fd, sd);
break;
case 0x03: // standup
- skill_gangsterparadise(sd, 0); // ギャングスターパラダイス解除
pc_setstand(sd);
WBUFW(buf, 0) = 0x8a;
WBUFL(buf, 2) = sd->bl_id;
@@ -4256,7 +4209,7 @@ void clif_parse_Restart(int fd, dumb_ptr<map_session_data> sd)
{
pc_setstand(sd);
pc_setrestartvalue(sd, 3);
- pc_setpos(sd, sd->status.save_point.map,
+ pc_setpos(sd, sd->status.save_point.map_,
sd->status.save_point.x, sd->status.save_point.y,
BeingRemoveWhy::QUIT);
}
@@ -4321,25 +4274,25 @@ void clif_parse_Wis(int fd, dumb_ptr<map_session_data> sd)
* conflict (for instance, "Test" versus "test"), the char-server must
* settle the discrepancy.
*/
- const char *tname = static_cast<const char *>(RFIFOP(fd, 4));
+ char tname[24];
+ RFIFO_STRING(fd, 4, tname, 24);
if (!(dstsd = map_nick2sd(tname))
|| strcmp(dstsd->status.name, tname) != 0)
- intif_wis_message(sd, tname, mbuf.c_str(), RFIFOW(fd, 2) - 28);
+ intif_wis_message(sd, tname, mbuf.c_str());
else
{
/* Refuse messages addressed to self. */
if (dstsd->fd == fd)
{
const char *mes = "You cannot page yourself.";
- clif_wis_message(fd, wisp_server_name, mes, strlen(mes) + 1);
+ clif_wis_message(fd, wisp_server_name, mes);
}
else
{
{
/* The player is not being ignored. */
{
- clif_wis_message(dstsd->fd, sd->status.name, mbuf.c_str(),
- RFIFOW(fd, 2) - 28);
+ clif_wis_message(dstsd->fd, sd->status.name, mbuf.c_str());
/* The whisper was sent successfully. */
clif_wis_end(fd, 0);
}
@@ -4931,7 +4884,7 @@ void clif_parse_PartyMessage(int fd, dumb_ptr<map_session_data> sd)
return;
}
- party_send_message(sd, mbuf.c_str(), RFIFOW(fd, 2) - 4);
+ party_send_message(sd, mbuf.c_str());
}
func_table clif_parse_func_table[0x0220] =
diff --git a/src/map/clif.hpp b/src/map/clif.hpp
index 5240fa1..5d48bc5 100644
--- a/src/map/clif.hpp
+++ b/src/map/clif.hpp
@@ -28,7 +28,7 @@ int clif_dropflooritem(dumb_ptr<flooritem_data>);
int clif_clearflooritem(dumb_ptr<flooritem_data>, int);
int clif_clearchar(dumb_ptr<block_list>, BeingRemoveWhy); // area or fd
int clif_clearchar_delay(tick_t, dumb_ptr<block_list>, BeingRemoveWhy);
-int clif_clearchar_id(int, BeingRemoveWhy, int);
+void clif_clearchar_id(int, BeingRemoveWhy, int);
int clif_spawnpc(dumb_ptr<map_session_data>); //area
int clif_spawnnpc(dumb_ptr<npc_data>); // area
int clif_spawn_fake_npc_for_player(dumb_ptr<map_session_data> sd,
@@ -37,9 +37,9 @@ int clif_spawnmob(dumb_ptr<mob_data>); // area
int clif_walkok(dumb_ptr<map_session_data>); // self
int clif_movechar(dumb_ptr<map_session_data>); // area
int clif_movemob(dumb_ptr<mob_data>); //area
-int clif_changemap(dumb_ptr<map_session_data>, const char *, int, int); //self
-int clif_changemapserver(dumb_ptr<map_session_data>, const char *, int, int, struct in_addr, int); //self
-int clif_fixpos(dumb_ptr<block_list>); // area
+void clif_changemap(dumb_ptr<map_session_data>, const char *, int, int); //self
+void clif_changemapserver(dumb_ptr<map_session_data>, const char *, int, int, struct in_addr, int); //self
+void clif_fixpos(dumb_ptr<block_list>); // area
int clif_fixmobpos(dumb_ptr<mob_data> md);
int clif_fixpcpos(dumb_ptr<map_session_data> sd);
int clif_npcbuysell(dumb_ptr<map_session_data>, int); //self
@@ -51,7 +51,6 @@ int clif_scriptclose(dumb_ptr<map_session_data>, int); //self
int clif_scriptmenu(dumb_ptr<map_session_data>, int, const char *); //self
int clif_scriptinput(dumb_ptr<map_session_data>, int); //self
int clif_scriptinputstr(dumb_ptr<map_session_data> sd, int npcid); // self
-int clif_cutin(dumb_ptr<map_session_data>, const char *, int); //self
int clif_viewpoint(dumb_ptr<map_session_data>, int, int, int, int, int, int); //self
int clif_additem(dumb_ptr<map_session_data>, int, int, PickupFail); //self
int clif_delitem(dumb_ptr<map_session_data>, int, int); //self
@@ -109,7 +108,7 @@ void clif_moboutsight(dumb_ptr<block_list>, dumb_ptr<mob_data>);
int clif_skillinfo(dumb_ptr<map_session_data> sd, SkillID skillid, int type,
int range);
-int clif_skillinfoblock(dumb_ptr<map_session_data> sd);
+void clif_skillinfoblock(dumb_ptr<map_session_data> sd);
int clif_skillup(dumb_ptr<map_session_data> sd, SkillID skill_num);
int clif_skillcastcancel(dumb_ptr<block_list> bl);
@@ -122,8 +121,8 @@ int clif_skill_damage(dumb_ptr<block_list> src, dumb_ptr<block_list> dst,
int clif_status_change(dumb_ptr<block_list> bl,
StatusChange type, int flag);
-int clif_wis_message(int fd, const char *nick, const char *mes, int mes_len);
-int clif_wis_end(int fd, int flag);
+void clif_wis_message(int fd, const char *nick, const char *mes);
+void clif_wis_end(int fd, int flag);
int clif_itemlist(dumb_ptr<map_session_data> sd);
int clif_equiplist(dumb_ptr<map_session_data> sd);
@@ -135,24 +134,24 @@ int clif_movetoattack(dumb_ptr<map_session_data> sd, dumb_ptr<block_list> bl);
// party
int clif_party_created(dumb_ptr<map_session_data> sd, int flag);
int clif_party_info(struct party *p, int fd);
-int clif_party_invite(dumb_ptr<map_session_data> sd,
+void clif_party_invite(dumb_ptr<map_session_data> sd,
dumb_ptr<map_session_data> tsd);
int clif_party_inviteack(dumb_ptr<map_session_data> sd, const char *nick, int flag);
-int clif_party_option(struct party *p, dumb_ptr<map_session_data> sd,
+void clif_party_option(struct party *p, dumb_ptr<map_session_data> sd,
int flag);
int clif_party_leaved(struct party *p, dumb_ptr<map_session_data> sd,
int account_id, const char *name, int flag);
-int clif_party_message(struct party *p, int account_id, const char *mes, int len);
+void clif_party_message(struct party *p, int account_id, const char *mes);
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);
-int clif_resurrection(dumb_ptr<block_list> bl, int type);
+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]
-int clif_message(dumb_ptr<block_list> bl, const char *msg); // messages (from mobs/npcs) [Valaris]
+void clif_message(dumb_ptr<block_list> bl, const char *msg); // messages (from mobs/npcs) [Valaris]
int clif_GM_kick(dumb_ptr<map_session_data> sd, dumb_ptr<map_session_data> tsd,
int type);
diff --git a/src/map/intif.cpp b/src/map/intif.cpp
index 1010047..9e9d2e1 100644
--- a/src/map/intif.cpp
+++ b/src/map/intif.cpp
@@ -18,7 +18,8 @@
#include "../poison.hpp"
static
-const int packet_len_table[] = {
+const int packet_len_table[] =
+{
-1, -1, 27, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-1, 7, 0, 0, 0, 0, 0, 0, -1, 11, 0, 0, 0, 0, 0, 0,
35, -1, 11, 15, 34, 29, 7, -1, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -35,40 +36,36 @@ const int packet_len_table[] = {
// inter serverへの送信
// Message for all GMs on all map servers
-void intif_GMmessage(const_string mes, int flag)
+void intif_GMmessage(const_string mes)
{
- int lp = (flag & 0x10) ? 8 : 4;
WFIFOW(char_fd, 0) = 0x3000;
- WFIFOW(char_fd, 2) = lp + mes.size() + 1;
- WFIFOL(char_fd, 4) = 0x65756c62;
- memcpy(WFIFOP(char_fd, lp), mes.data(), mes.size());
- WFIFOB(char_fd, lp + mes.size()) = '\0';
+ size_t len = mes.size() + 1;
+ WFIFOW(char_fd, 2) = 4 + len;
+ WFIFO_STRING(char_fd, 4, mes.data(), len);
WFIFOSET(char_fd, WFIFOW(char_fd, 2));
}
// The transmission of Wisp/Page to inter-server (player not found on this server)
-int intif_wis_message(dumb_ptr<map_session_data> sd, const char *nick, const char *mes,
- int mes_len)
+void intif_wis_message(dumb_ptr<map_session_data> sd, const char *nick, const char *mes)
{
- nullpo_ret(sd);
+ nullpo_retv(sd);
+ size_t mes_len = strlen(mes) + 1;
WFIFOW(char_fd, 0) = 0x3001;
WFIFOW(char_fd, 2) = mes_len + 52;
- memcpy(WFIFOP(char_fd, 4), sd->status.name, 24);
- memcpy(WFIFOP(char_fd, 28), nick, 24);
- memcpy(WFIFOP(char_fd, 52), mes, mes_len);
+ WFIFO_STRING(char_fd, 4, sd->status.name, 24);
+ WFIFO_STRING(char_fd, 28, nick, 24);
+ WFIFO_STRING(char_fd, 52, mes, mes_len);
WFIFOSET(char_fd, WFIFOW(char_fd, 2));
if (battle_config.etc_log)
PRINTF("intif_wis_message from %s to %s (message: '%s')\n",
sd->status.name, nick, mes);
-
- return 0;
}
// The reply of Wisp/page
static
-int intif_wis_replay(int id, int flag)
+void intif_wis_replay(int id, int flag)
{
WFIFOW(char_fd, 0) = 0x3002;
WFIFOL(char_fd, 2) = id;
@@ -77,129 +74,112 @@ int intif_wis_replay(int id, int flag)
if (battle_config.etc_log)
PRINTF("intif_wis_replay: id: %d, flag:%d\n", id, flag);
-
- return 0;
}
// The transmission of GM only Wisp/Page from server to inter-server
-int intif_wis_message_to_gm(const char *Wisp_name, int min_gm_level, const char *mes,
- int mes_len)
+void intif_wis_message_to_gm(const char *Wisp_name, int min_gm_level, const char *mes)
{
+ size_t mes_len = strlen(mes) + 1;
WFIFOW(char_fd, 0) = 0x3003;
WFIFOW(char_fd, 2) = mes_len + 30;
- memcpy(WFIFOP(char_fd, 4), Wisp_name, 24);
+ WFIFO_STRING(char_fd, 4, Wisp_name, 24);
WFIFOW(char_fd, 28) = min_gm_level;
- memcpy(WFIFOP(char_fd, 30), mes, mes_len);
+ WFIFO_STRING(char_fd, 30, mes, mes_len);
WFIFOSET(char_fd, WFIFOW(char_fd, 2));
if (battle_config.etc_log)
PRINTF("intif_wis_message_to_gm: from: '%s', min level: %d, message: '%s'.\n",
Wisp_name, min_gm_level, mes);
-
- return 0;
}
// アカウント変数送信
-int intif_saveaccountreg(dumb_ptr<map_session_data> sd)
+void intif_saveaccountreg(dumb_ptr<map_session_data> sd)
{
int j, p;
- nullpo_ret(sd);
+ nullpo_retv(sd);
WFIFOW(char_fd, 0) = 0x3004;
WFIFOL(char_fd, 4) = sd->bl_id;
for (j = 0, p = 8; j < sd->status.account_reg_num; j++, p += 36)
{
- memcpy(WFIFOP(char_fd, p), sd->status.account_reg[j].str, 32);
+ WFIFO_STRING(char_fd, p, sd->status.account_reg[j].str, 32);
WFIFOL(char_fd, p + 32) = sd->status.account_reg[j].value;
}
WFIFOW(char_fd, 2) = p;
WFIFOSET(char_fd, p);
- return 0;
}
// アカウント変数要求
-int intif_request_accountreg(dumb_ptr<map_session_data> sd)
+void intif_request_accountreg(dumb_ptr<map_session_data> sd)
{
- nullpo_ret(sd);
+ nullpo_retv(sd);
WFIFOW(char_fd, 0) = 0x3005;
WFIFOL(char_fd, 2) = sd->bl_id;
WFIFOSET(char_fd, 6);
- return 0;
}
// 倉庫データ要求
-int intif_request_storage(int account_id)
+void intif_request_storage(int account_id)
{
WFIFOW(char_fd, 0) = 0x3010;
WFIFOL(char_fd, 2) = account_id;
WFIFOSET(char_fd, 6);
- return 0;
}
// 倉庫データ送信
-int intif_send_storage(struct storage *stor)
+void intif_send_storage(struct storage *stor)
{
- nullpo_ret(stor);
+ nullpo_retv(stor);
WFIFOW(char_fd, 0) = 0x3011;
WFIFOW(char_fd, 2) = sizeof(struct storage) + 8;
WFIFOL(char_fd, 4) = stor->account_id;
- memcpy(WFIFOP(char_fd, 8), stor, sizeof(struct storage));
+ WFIFO_STRUCT(char_fd, 8, *stor);
WFIFOSET(char_fd, WFIFOW(char_fd, 2));
- return 0;
}
// パーティ作成要求
-int intif_create_party(dumb_ptr<map_session_data> sd, const char *name)
+void intif_create_party(dumb_ptr<map_session_data> sd, const char *name)
{
- nullpo_ret(sd);
+ nullpo_retv(sd);
WFIFOW(char_fd, 0) = 0x3020;
WFIFOL(char_fd, 2) = sd->status.account_id;
- memcpy(WFIFOP(char_fd, 6), name, 24);
- memcpy(WFIFOP(char_fd, 30), sd->status.name, 24);
- memcpy(WFIFOP(char_fd, 54), sd->bl_m->name, 16);
+ WFIFO_STRING(char_fd, 6, name, 24);
+ WFIFO_STRING(char_fd, 30, sd->status.name, 24);
+ WFIFO_STRING(char_fd, 54, sd->bl_m->name_, 16);
WFIFOW(char_fd, 70) = sd->status.base_level;
WFIFOSET(char_fd, 72);
-// if(battle_config.etc_log)
-// PRINTF("intif: create party\n");
- return 0;
}
// パーティ情報要求
-int intif_request_partyinfo(int party_id)
+void intif_request_partyinfo(int party_id)
{
WFIFOW(char_fd, 0) = 0x3021;
WFIFOL(char_fd, 2) = party_id;
WFIFOSET(char_fd, 6);
-// if(battle_config.etc_log)
-// PRINTF("intif: request party info\n");
- return 0;
}
// パーティ追加要求
-int intif_party_addmember(int party_id, int account_id)
+void intif_party_addmember(int party_id, int account_id)
{
dumb_ptr<map_session_data> sd;
sd = map_id2sd(account_id);
-// if(battle_config.etc_log)
-// PRINTF("intif: party add member %d %d\n",party_id,account_id);
if (sd != NULL)
{
WFIFOW(char_fd, 0) = 0x3022;
WFIFOL(char_fd, 2) = party_id;
WFIFOL(char_fd, 6) = account_id;
- memcpy(WFIFOP(char_fd, 10), sd->status.name, 24);
- memcpy(WFIFOP(char_fd, 34), sd->bl_m->name, 16);
+ WFIFO_STRING(char_fd, 10, sd->status.name, 24);
+ WFIFO_STRING(char_fd, 34, sd->bl_m->name_, 16);
WFIFOW(char_fd, 50) = sd->status.base_level;
WFIFOSET(char_fd, 52);
}
- return 0;
}
// パーティ設定変更
-int intif_party_changeoption(int party_id, int account_id, int exp, int item)
+void intif_party_changeoption(int party_id, int account_id, int exp, int item)
{
WFIFOW(char_fd, 0) = 0x3023;
WFIFOL(char_fd, 2) = party_id;
@@ -207,62 +187,52 @@ int intif_party_changeoption(int party_id, int account_id, int exp, int item)
WFIFOW(char_fd, 10) = exp;
WFIFOW(char_fd, 12) = item;
WFIFOSET(char_fd, 14);
- return 0;
}
// パーティ脱退要求
-int intif_party_leave(int party_id, int account_id)
+void intif_party_leave(int party_id, int account_id)
{
-// if(battle_config.etc_log)
-// PRINTF("intif: party leave %d %d\n",party_id,account_id);
WFIFOW(char_fd, 0) = 0x3024;
WFIFOL(char_fd, 2) = party_id;
WFIFOL(char_fd, 6) = account_id;
WFIFOSET(char_fd, 10);
- return 0;
}
// パーティ移動要求
-int intif_party_changemap(dumb_ptr<map_session_data> sd, int online)
+void intif_party_changemap(dumb_ptr<map_session_data> sd, int online)
{
if (sd != NULL)
{
WFIFOW(char_fd, 0) = 0x3025;
WFIFOL(char_fd, 2) = sd->status.party_id;
WFIFOL(char_fd, 6) = sd->status.account_id;
- memcpy(WFIFOP(char_fd, 10), sd->bl_m->name, 16);
+ WFIFO_STRING(char_fd, 10, sd->bl_m->name_, 16);
WFIFOB(char_fd, 26) = online;
WFIFOW(char_fd, 27) = sd->status.base_level;
WFIFOSET(char_fd, 29);
}
-// if(battle_config.etc_log)
-// PRINTF("party: change map\n");
- return 0;
}
// パーティ会話送信
-int intif_party_message(int party_id, int account_id, const char *mes, int len)
+void intif_party_message(int party_id, int account_id, const char *mes)
{
-// if(battle_config.etc_log)
-// PRINTF("intif_party_message: %s\n",mes);
+ size_t len = strlen(mes) + 1;
WFIFOW(char_fd, 0) = 0x3027;
WFIFOW(char_fd, 2) = len + 12;
WFIFOL(char_fd, 4) = party_id;
WFIFOL(char_fd, 8) = account_id;
- memcpy(WFIFOP(char_fd, 12), mes, len);
+ WFIFO_STRING(char_fd, 12, mes, len);
WFIFOSET(char_fd, len + 12);
- return 0;
}
// パーティ競合チェック要求
-int intif_party_checkconflict(int party_id, int account_id, const char *nick)
+void intif_party_checkconflict(int party_id, int account_id, const char *nick)
{
WFIFOW(char_fd, 0) = 0x3028;
WFIFOL(char_fd, 2) = party_id;
WFIFOL(char_fd, 6) = account_id;
- memcpy(WFIFOP(char_fd, 10), nick, 24);
+ WFIFO_STRING(char_fd, 10, nick, 24);
WFIFOSET(char_fd, 34);
- return 0;
}
//-----------------------------------------------------------------
@@ -271,24 +241,36 @@ int intif_party_checkconflict(int party_id, int account_id, const char *nick)
// Wisp/Page reception
static
int intif_parse_WisMessage(int fd)
-{ // rewritten by [Yor]
+{
+ // rewritten by [Yor]
dumb_ptr<map_session_data> sd;
+ char from[24];
+ RFIFO_STRING(fd, 8, from, 24);
+ char to[24];
+ RFIFO_STRING(fd, 32, to, 24);
+
+ size_t len = RFIFOW(fd, 2) - 56;
+ char buf[len];
+ RFIFO_STRING(fd, 56, buf, len);
+
if (battle_config.etc_log)
+ {
+ const char *mes = buf;
PRINTF("intif_parse_wismessage: id: %d, from: %s, to: %s, message: '%s'\n",
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(static_cast<const char *>(RFIFOP(fd, 32))); // Searching destination player
- if (sd != NULL && strcmp(sd->status.name, static_cast<const char *>(RFIFOP(fd, 32))) == 0)
+ from,
+ to,
+ mes);
+ }
+ sd = map_nick2sd(to); // Searching destination player
+ if (sd != NULL && strcmp(sd->status.name, to) == 0)
{
// exactly same name (inter-server have checked the name before)
{
// if source player not found in ignore list
{
- clif_wis_message(sd->fd, static_cast<const char *>(RFIFOP(fd, 8)), static_cast<const char *>(RFIFOP(fd, 56)),
- RFIFOW(fd, 2) - 56);
+ clif_wis_message(sd->fd, from, buf);
intif_wis_replay(RFIFOL(fd, 4), 0); // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target
}
}
@@ -317,23 +299,21 @@ 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)
+void mapif_parse_WisToGM(int fd)
{
// 0x3003/0x3803 <packet_len>.w <wispname>.24B <min_gm_level>.w <message>.?B
int min_gm_level, len;
char Wisp_name[24];
if (RFIFOW(fd, 2) - 30 <= 0)
- return 0;
+ return;
len = RFIFOW(fd, 2) - 30;
- char message[len + 1];
+ char message[len];
min_gm_level = RFIFOW(fd, 28);
- memcpy(Wisp_name, RFIFOP(fd, 4), 24);
- Wisp_name[23] = '\0';
- memcpy(message, RFIFOP(fd, 30), len);
- message[len] = '\0';
+ RFIFO_STRING(fd, 4, Wisp_name, 24);
+ RFIFO_STRING(fd, 30, message, len);
// information is sended to all online GM
for (int i = 0; i < fd_max; i++)
{
@@ -342,11 +322,8 @@ int mapif_parse_WisToGM(int fd)
dumb_ptr<map_session_data> pl_sd = dumb_ptr<map_session_data>(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);
+ clif_wis_message(i, Wisp_name, message);
}
-
- return 0;
}
// アカウント変数通知
@@ -361,7 +338,7 @@ int intif_parse_AccountReg(int fd)
for (p = 8, j = 0; p < RFIFOW(fd, 2) && j < ACCOUNT_REG_NUM;
p += 36, j++)
{
- memcpy(sd->status.account_reg[j].str, RFIFOP(fd, p), 32);
+ RFIFO_STRING(fd, p, sd->status.account_reg[j].str, 32);
sd->status.account_reg[j].value = RFIFOL(fd, p + 32);
}
sd->status.account_reg_num = j;
@@ -410,7 +387,7 @@ int intif_parse_LoadStorage(int fd)
}
if (battle_config.save_log)
PRINTF("intif_openstorage: %d\n", RFIFOL(fd, 4));
- memcpy(stor, RFIFOP(fd, 8), sizeof(struct storage));
+ RFIFO_STRUCT(fd, 8, *stor);
stor->dirty = 0;
stor->storage_status = 1;
sd->state.storage_open = 1;
@@ -423,36 +400,34 @@ int intif_parse_LoadStorage(int fd)
// 倉庫データ送信成功
static
-int intif_parse_SaveStorage(int fd)
+void intif_parse_SaveStorage(int fd)
{
if (battle_config.save_log)
PRINTF("intif_savestorage: done %d %d\n", RFIFOL(fd, 2),
RFIFOB(fd, 6));
storage_storage_saved(RFIFOL(fd, 2));
- return 0;
}
// パーティ作成可否
static
-int intif_parse_PartyCreated(int fd)
+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)));
- return 0;
}
// パーティ情報
static
-int intif_parse_PartyInfo(int fd)
+void intif_parse_PartyInfo(int fd)
{
if (RFIFOW(fd, 2) == 8)
{
if (battle_config.error_log)
PRINTF("intif: party noinfo %d\n", RFIFOL(fd, 4));
party_recv_noinfo(RFIFOL(fd, 4));
- return 0;
+ return;
}
// PRINTF("intif: party info %d\n",RFIFOL(fd,4));
@@ -464,68 +439,63 @@ int intif_parse_PartyInfo(int fd)
sizeof(struct party) + 4);
}
party_recv_info(static_cast<const struct party *>(RFIFOP(fd, 4)));
- return 0;
}
// パーティ追加通知
static
-int intif_parse_PartyMemberAdded(int fd)
+void intif_parse_PartyMemberAdded(int fd)
{
if (battle_config.etc_log)
PRINTF("intif: party member added %d %d %d\n", RFIFOL(fd, 2),
RFIFOL(fd, 6), RFIFOB(fd, 10));
party_member_added(RFIFOL(fd, 2), RFIFOL(fd, 6), RFIFOB(fd, 10));
- return 0;
}
// パーティ設定変更通知
static
-int intif_parse_PartyOptionChanged(int fd)
+void intif_parse_PartyOptionChanged(int fd)
{
party_optionchanged(RFIFOL(fd, 2), RFIFOL(fd, 6), RFIFOW(fd, 10),
RFIFOW(fd, 12), RFIFOB(fd, 14));
- return 0;
}
// パーティ脱退通知
static
-int intif_parse_PartyMemberLeaved(int fd)
+void intif_parse_PartyMemberLeaved(int fd)
{
if (battle_config.etc_log)
PRINTF("intif: party member leaved %d %d %s\n", RFIFOL(fd, 2),
RFIFOL(fd, 6), static_cast<const char *>(RFIFOP(fd, 10)));
party_member_leaved(RFIFOL(fd, 2), RFIFOL(fd, 6), static_cast<const char *>(RFIFOP(fd, 10)));
- return 0;
}
// パーティ解散通知
static
-int intif_parse_PartyBroken(int fd)
+void intif_parse_PartyBroken(int fd)
{
party_broken(RFIFOL(fd, 2));
- return 0;
}
// パーティ移動通知
static
-int intif_parse_PartyMove(int fd)
+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));
- return 0;
}
// パーティメッセージ
static
-int intif_parse_PartyMessage(int fd)
+void intif_parse_PartyMessage(int fd)
{
// if(battle_config.etc_log)
// PRINTF("intif_parse_PartyMessage: %s\n",RFIFOP(fd,12));
- party_recv_message(RFIFOL(fd, 4), RFIFOL(fd, 8), static_cast<const char *>(RFIFOP(fd, 12)),
- RFIFOW(fd, 2) - 12);
- return 0;
+ size_t len = RFIFOW(fd, 2) - 12;
+ char buf[len];
+ RFIFO_STRING(fd, 12, buf, len);
+ party_recv_message(RFIFOL(fd, 4), RFIFOL(fd, 8), buf);
}
//-----------------------------------------------------------------
diff --git a/src/map/intif.hpp b/src/map/intif.hpp
index 766af59..73a06e5 100644
--- a/src/map/intif.hpp
+++ b/src/map/intif.hpp
@@ -7,27 +7,25 @@
int intif_parse(int fd);
-void intif_GMmessage(const_string mes, int flag);
+void intif_GMmessage(const_string mes);
-int intif_wis_message(dumb_ptr<map_session_data> sd, const char *nick, const char *mes,
- int mes_len);
-int intif_wis_message_to_gm(const char *Wisp_name, int min_gm_level, const char *mes,
- int mes_len);
+void intif_wis_message(dumb_ptr<map_session_data> sd, const char *nick, const char *mes);
+void intif_wis_message_to_gm(const char *Wisp_name, int min_gm_level, const char *mes);
-int intif_saveaccountreg(dumb_ptr<map_session_data> sd);
-int intif_request_accountreg(dumb_ptr<map_session_data> sd);
+void intif_saveaccountreg(dumb_ptr<map_session_data> sd);
+void intif_request_accountreg(dumb_ptr<map_session_data> sd);
-int intif_request_storage(int account_id);
-int intif_send_storage(struct storage *stor);
+void intif_request_storage(int account_id);
+void intif_send_storage(struct storage *stor);
-int intif_create_party(dumb_ptr<map_session_data> sd, const char *name);
-int intif_request_partyinfo(int party_id);
-int intif_party_addmember(int party_id, int account_id);
-int intif_party_changeoption(int party_id, int account_id, int exp,
+void intif_create_party(dumb_ptr<map_session_data> sd, const char *name);
+void intif_request_partyinfo(int party_id);
+void intif_party_addmember(int party_id, int account_id);
+void intif_party_changeoption(int party_id, int account_id, int exp,
int item);
-int intif_party_leave(int party_id, int accound_id);
-int intif_party_changemap(dumb_ptr<map_session_data> sd, int online);
-int intif_party_message(int party_id, int account_id, const char *mes, int len);
-int intif_party_checkconflict(int party_id, int account_id, const char *nick);
+void intif_party_leave(int party_id, int accound_id);
+void intif_party_changemap(dumb_ptr<map_session_data> sd, int online);
+void intif_party_message(int party_id, int account_id, const char *mes);
+void intif_party_checkconflict(int party_id, int account_id, const char *nick);
#endif // INTIF_HPP
diff --git a/src/map/itemdb.cpp b/src/map/itemdb.cpp
index 147db91..329bab8 100644
--- a/src/map/itemdb.cpp
+++ b/src/map/itemdb.cpp
@@ -161,7 +161,6 @@ int itemdb_readdb(void)
char line[1024];
int ln = 0, lines = 0;
int nameid, j;
- char *str[32], *p, *np;
struct item_data *id;
int i = 0;
const char *filename[] = { "db/item_db.txt", "db/item_db2.txt" };
@@ -184,7 +183,9 @@ int itemdb_readdb(void)
lines++;
if (line[0] == '/' && line[1] == '/')
continue;
- memset(str, 0, sizeof(str));
+ char *str[32] {};
+ char *p;
+ char *np;
for (j = 0, np = p = line; j < 17 && p; j++)
{
while (*p == '\t' || *p == ' ')
@@ -207,8 +208,8 @@ int itemdb_readdb(void)
//ID,Name,Jname,Type,Price,Sell,Weight,ATK,DEF,Range,Slot,Job,Gender,Loc,wLV,eLV,View
id = itemdb_search(nameid);
- memcpy(id->name, str[1], 24);
- memcpy(id->jname, str[2], 24);
+ strzcpy(id->name, str[1], 24);
+ strzcpy(id->jname, str[2], 24);
id->type = ItemType(atoi(str[3]));
id->value_buy = atoi(str[4]);
id->value_sell = atoi(str[5]);
@@ -269,7 +270,6 @@ int itemdb_read_itemavail(void)
char line[1024];
int ln = 0;
int nameid, j, k;
- char *str[10], *p;
if ((fp = fopen_("db/item_avail.txt", "r")) == NULL)
{
@@ -282,7 +282,8 @@ int itemdb_read_itemavail(void)
struct item_data *id;
if (line[0] == '/' && line[1] == '/')
continue;
- memset(str, 0, sizeof(str));
+ char *str[10] {};
+ char *p;
for (j = 0, p = line; j < 2 && p; j++)
{
str[j] = p;
@@ -323,7 +324,6 @@ int itemdb_read_noequip(void)
char line[1024];
int ln = 0;
int nameid, j;
- char *str[32], *p;
struct item_data *id;
if ((fp = fopen_("db/item_noequip.txt", "r")) == NULL)
@@ -335,7 +335,8 @@ int itemdb_read_noequip(void)
{
if (line[0] == '/' && line[1] == '/')
continue;
- memset(str, 0, sizeof(str));
+ char *str[32] {};
+ char *p;
for (j = 0, p = line; j < 2 && p; j++)
{
str[j] = p;
diff --git a/src/map/magic-expr.cpp b/src/map/magic-expr.cpp
index 7739847..4946de8 100644
--- a/src/map/magic-expr.cpp
+++ b/src/map/magic-expr.cpp
@@ -144,7 +144,7 @@ void stringify(val_t *v, int within_op)
case TYPE::LOCATION:
buf = STRPRINTF("<\"%s\", %d, %d>",
- v->v.v_location.m->name,
+ v->v.v_location.m->name_,
v->v.v_location.x,
v->v.v_location.y);
break;
@@ -736,7 +736,7 @@ int fun_hash_entity(dumb_ptr<env_t>, val_t *result, const_array<val_t> args)
}
int // ret -1: not a string, ret 1: no such item, ret 0: OK
-magic_find_item(const_array<val_t> args, int index, struct item *item, int *stackable)
+magic_find_item(const_array<val_t> args, int index, struct item *item_, int *stackable)
{
struct item_data *item_data;
int must_add_sequentially;
@@ -761,9 +761,9 @@ magic_find_item(const_array<val_t> args, int index, struct item *item, int *stac
if (stackable)
*stackable = !must_add_sequentially;
- memset(item, 0, sizeof(struct item));
- item->nameid = item_data->nameid;
- item->identify = 1;
+ *item_ = item();
+ item_->nameid = item_data->nameid;
+ item_->identify = 1;
return 0;
}
@@ -1064,7 +1064,7 @@ static
int fun_is_exterior(dumb_ptr<env_t>, val_t *result, const_array<val_t> args)
{
#warning "Evil assumptions!"
- RESULTINT = ARGLOCATION(0).m->name[4] == '1';
+ RESULTINT = ARGLOCATION(0).m->name_[4] == '1';
return 0;
}
@@ -1127,7 +1127,7 @@ static
int fun_map_level(dumb_ptr<env_t>, val_t *result, const_array<val_t> args)
{
#warning "Evil assumptions!"
- RESULTINT = ARGLOCATION(0).m->name[4] - '0';
+ RESULTINT = ARGLOCATION(0).m->name_[4] - '0';
return 0;
}
@@ -1135,7 +1135,7 @@ static
int fun_map_nr(dumb_ptr<env_t>, val_t *result, const_array<val_t> args)
{
#warning "Evil assumptions!"
- const char *mapname = ARGLOCATION(0).m->name;
+ const char *mapname = ARGLOCATION(0).m->name_;
RESULTINT = ((mapname[0] - '0') * 100)
+ ((mapname[1] - '0') * 10) + ((mapname[2] - '0'));
diff --git a/src/map/magic-interpreter-parser.ypp b/src/map/magic-interpreter-parser.ypp
index 2cec1f2..c5a7dd8 100644
--- a/src/map/magic-interpreter-parser.ypp
+++ b/src/map/magic-interpreter-parser.ypp
@@ -120,7 +120,7 @@ val_t *find_constant(const std::string& name);
dumb_ptr<proc_t> proc;
// evil hackery
- YYSTYPE() { memset(this, '\0', sizeof(*this)); }
+ YYSTYPE() { really_memzero_this(this); }
~YYSTYPE() = default;
YYSTYPE(const YYSTYPE& rhs) = default;
YYSTYPE& operator = (const YYSTYPE& rhs) = default;
diff --git a/src/map/magic-interpreter.hpp b/src/map/magic-interpreter.hpp
index f233f37..9b60d998 100644
--- a/src/map/magic-interpreter.hpp
+++ b/src/map/magic-interpreter.hpp
@@ -41,7 +41,7 @@ struct area_t
} a_rect;
dumb_ptr<area_t> a_union[2];
- au() { memset(this, '\0', sizeof(*this)); }
+ au() { really_memzero_this(this); }
~au() = default;
au(const au&) = default;
au& operator = (const au&) = default;
@@ -52,7 +52,7 @@ struct area_t
struct val_t
{
- union v
+ union vu
{
int v_int;
DIR v_dir;
@@ -65,10 +65,10 @@ struct val_t
dumb_ptr<invocation> v_invocation;
dumb_ptr<spell_t> v_spell;
- v() { memset(this, '\0', sizeof(*this)); }
- ~v() = default;
- v(const v&) = default;
- v& operator = (const v&) = default;
+ vu() { really_memzero_this(this); }
+ ~vu() = default;
+ vu(const vu&) = default;
+ vu& operator = (const vu&) = default;
} v;
TYPE ty;
};
@@ -101,7 +101,7 @@ struct e_area_t
} a_rect;
dumb_ptr<e_area_t> a_union[2];
- a0() { memset(this, '\0', sizeof(*this)); }
+ a0() { really_memzero_this(this); }
~a0() = default;
a0(const a0&) = default;
a0& operator = (const a0&) = default;
@@ -129,7 +129,7 @@ struct expr_t
int id;
} e_field;
- eu() { memset(this, '\0', sizeof(*this)); }
+ eu() { really_memzero_this(this); }
~eu() = default;
eu(const eu&) = default;
eu& operator = (const eu&) = default;
@@ -181,7 +181,7 @@ struct effect_t
dumb_ptr<effect_t> body;
} e_call;
- e0() { memset(this, '\0', sizeof(*this)); }
+ e0() { really_memzero_this(this); }
~e0() = default;
e0(const e0&) = default;
e0& operator = (const e0&) = default;
@@ -218,7 +218,7 @@ struct spellguard_t
dumb_ptr<component_t> s_catalysts;
dumb_ptr<spellguard_t> s_alt; /* either `next' or `s.s_alt' */
effect_set_t s_effect;
- su() { memset(this, '\0', sizeof(*this)); }
+ su() { really_memzero_this(this); }
~su() = default;
su(const su&) = default;
su& operator = (const su&) = default;
@@ -340,10 +340,10 @@ struct cont_activation_record_t
dumb_ptr<val_t[]> old_actualpa;
} c_proc;
- cu() { memset(this, '\0', sizeof(*this)); }
- ~cu() {}
- cu(const cu&) = delete;
- cu& operator = (const cu&) = delete;
+ cu() { really_memzero_this(this); }
+ ~cu() = default;
+ cu(const cu&) = default;
+ cu& operator = (const cu&) = default;
} c;
CONT_STACK ty;
};
diff --git a/src/map/magic-stmt.cpp b/src/map/magic-stmt.cpp
index f24167c..5d732c8 100644
--- a/src/map/magic-stmt.cpp
+++ b/src/map/magic-stmt.cpp
@@ -437,7 +437,6 @@ void entity_warp(dumb_ptr<block_list> target, map_local *destm, int destx, int d
case BL::PC:
{
dumb_ptr<map_session_data> character = target->as_player();
- char *map_name;
clif_clearchar(character, BeingRemoveWhy::WARPED);
map_delblock(character);
character->bl_x = destx;
@@ -447,7 +446,7 @@ void entity_warp(dumb_ptr<block_list> target, map_local *destm, int destx, int d
pc_touch_all_relevant_npcs(character);
// Note that touching NPCs may have triggered warping and thereby updated x and y:
- map_name = character->bl_m->name;
+ const char *map_name = character->bl_m->name_;
// Warp part #1: update relevant data, interrupt trading etc.:
pc_setpos(character, map_name, character->bl_x, character->bl_y, BeingRemoveWhy::GONE);
@@ -689,7 +688,7 @@ int op_spawn(dumb_ptr<env_t>, const_array<val_t> args)
int mob_id;
dumb_ptr<mob_data> mob;
- mob_id = mob_once_spawn(owner, loc.m->name, loc.x, loc.y, "--ja--", // Is that needed?
+ mob_id = mob_once_spawn(owner, loc.m->name_, loc.x, loc.y, "--ja--", // Is that needed?
monster_id, 1, "");
mob = map_id_as_mob(mob_id);
diff --git a/src/map/map.cpp b/src/map/map.cpp
index 414fcd7..fc80199 100644
--- a/src/map/map.cpp
+++ b/src/map/map.cpp
@@ -700,7 +700,7 @@ int map_addflooritem_any(struct item *item_data, int amount,
fitem->third_get_id = owners[2]->bl_id;
fitem->third_get_tick = tick + owner_protection[2];
- memcpy(&fitem->item_data, item_data, sizeof(*item_data));
+ fitem->item_data = *item_data;
fitem->item_data.amount = amount;
// TODO - talk to 4144 about maybe removing this.
// It has no effect on the server itself, it is visual only.
@@ -749,7 +749,7 @@ void map_addchariddb(int charid, const char *name)
if (p == NULL)
p = charid_db.init(charid);
- memcpy(p->nick, name, 24);
+ strzcpy(p->nick, name, 24);
p->req_id = 0;
}
@@ -813,7 +813,6 @@ void map_quit(dumb_ptr<map_session_data> sd)
pc_stop_walking(sd, 0);
pc_stopattack(sd);
pc_delinvincibletimer(sd);
- skill_gangsterparadise(sd, 0);
pc_calcstatus(sd, 4);
@@ -1030,7 +1029,7 @@ int map_addnpc(map_local *m, dumb_ptr<npc_data> nd)
if (i == MAX_NPC_PER_MAP)
{
if (battle_config.error_log)
- PRINTF("too many NPCs in one map %s\n", m->name);
+ PRINTF("too many NPCs in one map %s\n", m->name_);
return -1;
}
if (i == m->npc_num)
@@ -1209,11 +1208,11 @@ int map_setipport(const char *name, struct in_addr ip, int port)
{
// not exist -> add new data
auto mdos = make_unique<map_remote>();
- memcpy(mdos->name, name, 24);
+ strzcpy(mdos->name_, name, 16);
mdos->gat = NULL;
mdos->ip = ip;
mdos->port = port;
- maps_db.put(mdos->name, std::move(mdos));
+ maps_db.put(mdos->name_, std::move(mdos));
}
else
{
@@ -1263,7 +1262,7 @@ bool map_readmap(map_local *m, size_t num, const std::string& fn)
m->npc_num = 0;
m->users = 0;
- memset(&m->flag, 0, sizeof(m->flag));
+ really_memzero_this(&m->flag);
if (battle_config.pk_mode)
m->flag.pvp = 1; // make all maps pvp for pk_mode [Valaris]
MapCell *gat_m = reinterpret_cast<MapCell *>(&gat_v[4]);
@@ -1288,7 +1287,7 @@ int map_readallmap(void)
for (auto& mit : maps_db)
{
- assert (strstr(mit.second->name, ".gat") != NULL);
+ assert (strstr(mit.second->name_, ".gat") != NULL);
{
{
map_local *ml = static_cast<map_local *>(mit.second.get());
@@ -1329,7 +1328,7 @@ void map_addmap(const std::string& mapname)
}
auto newmap = make_unique<map_local>();
- strzcpy(newmap->name, mapname.c_str(), sizeof(newmap->name));
+ strzcpy(newmap->name_, mapname.c_str(), 16);
}
/*==========================================
diff --git a/src/map/map.hpp b/src/map/map.hpp
index c004315..968bf43 100644
--- a/src/map/map.hpp
+++ b/src/map/map.hpp
@@ -6,6 +6,7 @@
#include <netinet/in.h>
#include <functional>
+#include <list>
#include "../common/db.hpp"
#include "../common/matrix.hpp"
@@ -22,10 +23,7 @@ constexpr int MAX_NPC_PER_MAP = 512;
constexpr int BLOCK_SIZE = 8;
#define AREA_SIZE battle_config.area_size
constexpr std::chrono::seconds LIFETIME_FLOORITEM = std::chrono::minutes(1);
-constexpr int DAMAGELOG_SIZE = 30;
constexpr int MAX_SKILL_LEVEL = 100;
-constexpr int MAX_MOBSKILL = 32;
-constexpr int MAX_EVENTQUEUE = 2;
constexpr int MAX_EVENTTIMER = 32;
constexpr interval_t NATURAL_HEAL_INTERVAL = std::chrono::milliseconds(500);
constexpr int MAX_FLOORITEM = 500000;
@@ -143,7 +141,7 @@ struct map_session_data : block_list, SessionData
earray<short, EQUIP, EQUIP::COUNT> equip_index;
int weight, max_weight;
int cart_weight, cart_max_weight, cart_num, cart_max_num;
- char mapname[24];
+ char mapname_[16];
int fd, new_fd;
short to_x, to_y;
interval_t speed;
@@ -240,7 +238,6 @@ struct map_session_data : block_list, SessionData
earray<struct status_change, StatusChange, StatusChange::MAX_STATUSCHANGE> sc_data;
short sc_count;
- struct square dev;
int trade_partner;
int deal_item_index[10];
@@ -261,7 +258,7 @@ struct map_session_data : block_list, SessionData
Timer pvp_timer;
int pvp_lastusers;
- char eventqueue[MAX_EVENTQUEUE][50];
+ std::list<std::string> eventqueuel;
Timer eventtimer[MAX_EVENTTIMER];
struct
@@ -316,7 +313,7 @@ struct npc_data : block_list
Option option;
short flag;
- char eventqueue[MAX_EVENTQUEUE][50];
+ std::list<std::string> eventqueuel;
Timer eventtimer[MAX_EVENTTIMER];
short arenaflag;
@@ -421,11 +418,13 @@ struct mob_data : block_list
tick_t last_deadtime, last_spawntime, last_thinktime;
tick_t canmove_tick;
short move_fail_count;
- struct
+ struct DmgLogEntry
{
int id;
int dmg;
- } dmglog[DAMAGELOG_SIZE];
+ };
+ // logically a map ...
+ std::vector<DmgLogEntry> dmglogv;
std::vector<struct item> lootitemv;
earray<struct status_change, StatusChange, StatusChange::MAX_STATUSCHANGE> sc_data;
@@ -441,8 +440,9 @@ struct mob_data : block_list
int skilltarget;
short skillx, skilly;
SkillID skillid;
- short skilllv, skillidx;
- tick_t skilldelay[MAX_MOBSKILL];
+ short skilllv;
+ struct mob_skill *skillidx;
+ std::unique_ptr<tick_t[]> skilldelayup; // [MAX_MOBSKILL];
LevelElement def_ele;
int master_id, master_dist;
int exclusion_src, exclusion_party;
@@ -459,13 +459,11 @@ struct BlockLists
struct map_abstract
{
- // shouldn't this be 16?
- // but beware of hard-coded memcpys
- char name[24];
+ char name_[16];
// gat is NULL for map_remote and non-NULL or map_local
std::unique_ptr<MapCell[]> gat;
- virtual ~map_abstract() {};
+ virtual ~map_abstract() {}
};
extern
UPMap<std::string, map_abstract> maps_db;
@@ -593,7 +591,7 @@ void map_log(const_string line);
#define MAP_LOG_PC(sd, fmt, ...) \
MAP_LOG("PC%d %s:%d,%d " fmt, \
- sd->status.char_id, sd->bl_m->name, sd->bl_x, sd->bl_y, ## __VA_ARGS__)
+ sd->status.char_id, sd->bl_m->name_, sd->bl_x, sd->bl_y, ## __VA_ARGS__)
// 床アイテム関連
void map_clearflooritem_timer(TimerData *, tick_t, int);
diff --git a/src/map/mob.cpp b/src/map/mob.cpp
index e4520d0..ffeb619 100644
--- a/src/map/mob.cpp
+++ b/src/map/mob.cpp
@@ -33,7 +33,7 @@ constexpr random_::Fraction MOB_LAZYMOVEPERC {50, 1000};
// Warp probability in the negligent mode MOB (rate of 1000 minute)
constexpr random_::Fraction MOB_LAZYWARPPERC {20, 1000};
-struct mob_db mob_db[2001];
+struct mob_db_ mob_db[2001];
/*==========================================
* Local prototype declaration (only required thing)
@@ -47,7 +47,7 @@ static
void mob_timer(TimerData *, tick_t, int, unsigned char);
static
int mobskill_use_id(dumb_ptr<mob_data> md, dumb_ptr<block_list> target,
- int skill_idx);
+ mob_skill& skill_idx);
/*==========================================
* Mob is searched with a name.
@@ -60,9 +60,7 @@ int mobdb_searchname(const char *str)
for (i = 0; i < sizeof(mob_db) / sizeof(mob_db[0]); i++)
{
if (strcasecmp(mob_db[i].name, str) == 0
- || strcmp(mob_db[i].jname, str) == 0
- || memcmp(mob_db[i].name, str, 24) == 0
- || memcmp(mob_db[i].jname, str, 24) == 0)
+ || strcmp(mob_db[i].jname, str) == 0)
return i;
}
@@ -90,16 +88,16 @@ void mob_init(dumb_ptr<mob_data> md);
*------------------------------------------
*/
static
-int mob_spawn_dataset(dumb_ptr<mob_data> md, const char *mobname, int mob_class)
+void mob_spawn_dataset(dumb_ptr<mob_data> md, const char *mobname, int mob_class)
{
- nullpo_ret(md);
+ nullpo_retv(md);
if (strcmp(mobname, "--en--") == 0)
- memcpy(md->name, mob_db[mob_class].name, 24);
+ strzcpy(md->name, mob_db[mob_class].name, 24);
else if (strcmp(mobname, "--ja--") == 0)
- memcpy(md->name, mob_db[mob_class].jname, 24);
+ strzcpy(md->name, mob_db[mob_class].jname, 24);
else
- memcpy(md->name, mobname, 24);
+ strzcpy(md->name, mobname, 24);
md->bl_prev = NULL;
md->bl_next = NULL;
@@ -107,14 +105,12 @@ int mob_spawn_dataset(dumb_ptr<mob_data> md, const char *mobname, int mob_class)
md->mob_class = mob_class;
md->bl_id = npc_get_new_npc_id();
- memset(&md->state, 0, sizeof(md->state));
+ really_memzero_this(&md->state);
// md->timer = nullptr;
md->target_id = 0;
md->attacked_id = 0;
mob_init(md);
-
- return 0;
}
// Mutation values indicate how `valuable' a change to each stat is, XP wise.
@@ -268,7 +264,7 @@ void mob_mutate(dumb_ptr<mob_data> md, mob_stat stat, int intensity)
// This calculates the exp of a given mob
static
-int mob_gen_exp(struct mob_db *mob)
+int mob_gen_exp(mob_db_ *mob)
{
if (mob->max_hp <= 1)
return 1;
@@ -414,7 +410,7 @@ int mob_once_spawn(dumb_ptr<map_session_data> sd, const char *mapname,
md->spawn.delay1 = static_cast<interval_t>(-1); // Only once is a flag.
md->spawn.delay2 = static_cast<interval_t>(-1); // Only once is a flag.
- memcpy(md->npc_event, event, sizeof(md->npc_event));
+ strzcpy(md->npc_event, event, 50);
md->bl_type = BL::MOB;
map_addiddb(md);
@@ -947,7 +943,7 @@ int mob_walktoxy_sub(dumb_ptr<mob_data> md)
if (path_search(&wpd, md->bl_m, md->bl_x, md->bl_y, md->to_x, md->to_y,
md->state.walk_easy))
return 1;
- memcpy(&md->walkpath, &wpd, sizeof(wpd));
+ md->walkpath = wpd;
md->state.change_walk_target = 0;
mob_changestate(md, MS::WALK, 0);
@@ -1110,7 +1106,7 @@ int mob_spawn(int id)
map_addblock(md);
- memset(&md->state, 0, sizeof(md->state));
+ really_memzero_this(&md->state);
md->attacked_id = 0;
md->target_id = 0;
md->move_fail_count = 0;
@@ -1133,12 +1129,13 @@ int mob_spawn(int id)
// md->deletetimer = nullptr;
// md->skilltimer = nullptr;
- for (int i = 0; i < MAX_MOBSKILL; i++)
- md->skilldelay[i] = tick - std::chrono::hours(10);
+ md->skilldelayup = make_unique<tick_t[]>(mob_db[md->mob_class].skills.size());
+ for (size_t i = 0; i < mob_db[md->mob_class].skills.size(); i++)
+ md->skilldelayup[i] = tick - std::chrono::hours(10);
md->skillid = SkillID();
md->skilllv = 0;
- memset(md->dmglog, 0, sizeof(md->dmglog));
+ md->dmglogv.clear();
md->lootitemv.clear();
for (StatusChange i : erange(StatusChange(), StatusChange::MAX_STATUSCHANGE))
@@ -2312,15 +2309,8 @@ double damage_bonus_factor[DAMAGE_BONUS_COUNT + 1] =
int mob_damage(dumb_ptr<block_list> src, dumb_ptr<mob_data> md, int damage,
int type)
{
- int count, minpos, mindmg;
- dumb_ptr<map_session_data> sd = NULL, tmpsd[DAMAGELOG_SIZE];
- struct
- {
- struct party *p;
- int id, base_exp, job_exp;
- } pt[DAMAGELOG_SIZE];
- int pnum = 0;
- int mvp_damage, max_hp;
+ dumb_ptr<map_session_data> sd = NULL;
+ int max_hp;
tick_t tick = gettick();
dumb_ptr<map_session_data> mvp_sd = NULL, second_sd = NULL, third_sd = NULL;
double tdmg;
@@ -2384,30 +2374,22 @@ int mob_damage(dumb_ptr<block_list> src, dumb_ptr<mob_data> md, int damage,
{
if (sd != NULL)
{
- int i;
- for (i = 0, minpos = 0, mindmg = 0x7fffffff; i < DAMAGELOG_SIZE;
- i++)
+ for (mob_data::DmgLogEntry& dle : md->dmglogv)
{
- if (md->dmglog[i].id == sd->bl_id)
- break;
- if (md->dmglog[i].id == 0)
- {
- minpos = i;
- mindmg = 0;
- }
- else if (md->dmglog[i].dmg < mindmg)
+ if (dle.id == sd->bl_id)
{
- minpos = i;
- mindmg = md->dmglog[i].dmg;
+ dle.dmg += damage;
+ goto damage_logged_pc;
}
}
- if (i < DAMAGELOG_SIZE)
- md->dmglog[i].dmg += damage;
- else
+ //else
{
- md->dmglog[minpos].id = sd->bl_id;
- md->dmglog[minpos].dmg = damage;
+ mob_data::DmgLogEntry app;
+ app.id = sd->bl_id;
+ app.dmg = damage;
+ md->dmglogv.push_back(app);
}
+ damage_logged_pc:
if (md->attacked_id <= 0 && md->state.special_mob_ai == 0)
md->attacked_id = sd->bl_id;
@@ -2426,35 +2408,27 @@ int mob_damage(dumb_ptr<block_list> src, dumb_ptr<mob_data> md, int damage,
}
nullpo_ret(md2);
- int i;
- for (i = 0, minpos = 0, mindmg = 0x7fffffff; i < DAMAGELOG_SIZE;
- i++)
+ for (mob_data::DmgLogEntry& dle : md->dmglogv)
{
- if (md->dmglog[i].id == md2->master_id)
- break;
- if (md->dmglog[i].id == 0)
+ if (dle.id == md2->master_id)
{
- minpos = i;
- mindmg = 0;
- }
- else if (md->dmglog[i].dmg < mindmg)
- {
- minpos = i;
- mindmg = md->dmglog[i].dmg;
+ dle.dmg += damage;
+ goto damage_logged_slave;
}
}
- if (i < DAMAGELOG_SIZE)
- md->dmglog[i].dmg += damage;
- else
+ //else
{
- md->dmglog[minpos].id = md2->master_id;
- md->dmglog[minpos].dmg = damage;
+ mob_data::DmgLogEntry app;
+ app.id = md2->master_id;
+ app.dmg = damage;
+ md->dmglogv.push_back(app);
if (md->attacked_id <= 0 && md->state.special_mob_ai == 0)
md->attacked_id = md2->master_id;
}
+ damage_logged_slave:
+ ;
}
-
}
md->hp -= damage;
@@ -2473,9 +2447,6 @@ int mob_damage(dumb_ptr<block_list> src, dumb_ptr<mob_data> md, int damage,
mob_changestate(md, MS::DEAD, 0);
mobskill_use(md, tick, MobSkillCondition::ANY);
- memset(tmpsd, 0, sizeof(tmpsd));
- memset(pt, 0, sizeof(pt));
-
max_hp = battle_get_max_hp(md);
if (src && src->bl_type == BL::MOB)
@@ -2485,46 +2456,53 @@ int mob_damage(dumb_ptr<block_list> src, dumb_ptr<mob_data> md, int damage,
// overkill分は無いけどsumはmax_hpとは違う
tdmg = 0;
- count = 0;
- mvp_damage = 0;
- for (int i = 0; i < DAMAGELOG_SIZE; i++)
- {
- if (md->dmglog[i].id == 0)
- continue;
- tmpsd[i] = map_id2sd(md->dmglog[i].id);
- if (tmpsd[i] == NULL)
- continue;
- count++;
- if (tmpsd[i]->bl_m != md->bl_m || pc_isdead(tmpsd[i]))
- continue;
- tdmg += md->dmglog[i].dmg;
- if (mvp_damage < md->dmglog[i].dmg)
- {
- third_sd = second_sd;
- second_sd = mvp_sd;
- mvp_sd = tmpsd[i];
- mvp_damage = md->dmglog[i].dmg;
- }
- }
+ // snip a prelude loop, now merged
+
+ std::sort(md->dmglogv.begin(), md->dmglogv.end(),
+ [](const mob_data::DmgLogEntry& l, const mob_data::DmgLogEntry& r) -> bool
+ {
+ // reversed
+ return l.dmg > r.dmg;
+ }
+ );
- // [MouseJstr]
- if ((md->bl_m->flag.pvp == 0) || (battle_config.pvp_exp == 1))
{
- // 経験値の分配
- for (int i = 0; i < DAMAGELOG_SIZE; i++)
+ struct DmgLogParty
{
+ struct party *p;
+ int base_exp, job_exp;
+ };
+ std::vector<DmgLogParty> ptv;
- int pid, base_exp, job_exp, flag = 1;
+ for (mob_data::DmgLogEntry& dle : md->dmglogv)
+ {
+ dumb_ptr<map_session_data> tmpsdi = map_id2sd(dle.id);
+ if (tmpsdi == NULL)
+ continue;
+ if (tmpsdi->bl_m != md->bl_m || pc_isdead(tmpsdi))
+ continue;
+
+ // this way is actually fair, unlike the old way
+ if (!mvp_sd)
+ mvp_sd = tmpsdi;
+ else if (!second_sd)
+ second_sd = tmpsdi;
+ else if (!third_sd)
+ third_sd = tmpsdi;
+
+ int base_exp, job_exp, flag = 1;
double per;
struct party *p;
- if (tmpsd[i] == NULL || tmpsd[i]->bl_m != md->bl_m)
- continue;
+
// [Fate] The above is the old formula. We do a more involved computation below.
// [o11c] Look in git history for old code, you idiot!
// 256 = 100% of the score
- per = static_cast<double>(md->dmglog[i].dmg) * 256 / static_cast<double>(max_hp);
- per *= damage_bonus_factor[count > DAMAGE_BONUS_COUNT ? DAMAGE_BONUS_COUNT : count]; // Bonus for party attack
+ per = static_cast<double>(dle.dmg) * 256 / static_cast<double>(max_hp);
+ size_t count = md->dmglogv.size();
+ if (count > DAMAGE_BONUS_COUNT)
+ count = DAMAGE_BONUS_COUNT;
+ per *= damage_bonus_factor[count]; // Bonus for party attack
if (per > 512)
per = 512; // [Fate] Retained from before. The maximum a single individual can get is double the original value.
if (per < 1)
@@ -2555,39 +2533,42 @@ int mob_damage(dumb_ptr<block_list> src, dumb_ptr<mob_data> md, int damage,
&& battle_config.alchemist_summon_reward != 1)
job_exp = 0; // Added [Valaris]
- if ((pid = tmpsd[i]->status.party_id) > 0)
- { // パーティに入っている
- int j = 0;
- for (j = 0; j < pnum; j++) // 公平パーティリストにいるかどうか
- if (pt[j].id == pid)
- break;
- if (j == pnum)
- { // いないときは公平かどうか確認
- if ((p = party_search(pid)) != NULL && p->exp != 0)
+ int pid = tmpsdi->status.party_id;
+ if (pid > 0)
+ {
+ std::vector<DmgLogParty>::iterator it = std::find_if(ptv.begin(), ptv.end(),
+ [pid](const DmgLogParty& dlp)
+ {
+ return dlp.p->party_id == pid;
+ }
+ );
+ if (it == ptv.end())
+ {
+ p = party_search(pid);
+ if (p != NULL && p->exp != 0)
{
- pt[pnum].id = pid;
- pt[pnum].p = p;
- pt[pnum].base_exp = base_exp;
- pt[pnum].job_exp = job_exp;
- pnum++;
+ DmgLogParty pn {};
+ pn.p = p;
+ pn.base_exp = base_exp;
+ pn.job_exp = job_exp;
+ ptv.push_back(pn);
flag = 0;
}
}
else
- { // いるときは公平
- pt[j].base_exp += base_exp;
- pt[j].job_exp += job_exp;
+ {
+ it->base_exp += base_exp;
+ it->job_exp += job_exp;
flag = 0;
}
}
- if (flag) // 各自所得
- pc_gainexp_reason(tmpsd[i], base_exp, job_exp,
+ if (flag)
+ // not sharing
+ pc_gainexp_reason(tmpsdi, base_exp, job_exp,
PC_GAINEXP_REASON::KILLING);
}
- // 公平分配
- for (int i = 0; i < pnum; i++)
- party_exp_share(pt[i].p, md->bl_m, pt[i].base_exp,
- pt[i].job_exp);
+ for (DmgLogParty& pti : ptv)
+ party_exp_share(pti.p, md->bl_m, pti.base_exp, pti.job_exp);
// item drop
if (!(type & 1))
@@ -2915,7 +2896,7 @@ int mob_summonslave(dumb_ptr<mob_data> md2, int *value, int amount, int flag)
md->spawn.delay1 = static_cast<interval_t>(-1); // 一度のみフラグ
md->spawn.delay2 = static_cast<interval_t>(-1); // 一度のみフラグ
- memset(md->npc_event, 0, sizeof(md->npc_event));
+ strzcpy(md->npc_event, "", 50);
md->bl_type = BL::MOB;
map_addiddb(md);
mob_spawn(md->bl_id);
@@ -3023,7 +3004,7 @@ void mobskill_castend_id(TimerData *, tick_t tick, int id)
if (range + battle_config.mob_skill_add_range < distance(md->bl_x, md->bl_y, bl->bl_x, bl->bl_y))
return;
- md->skilldelay[md->skillidx] = tick;
+ md->skilldelayup[md->skillidx - &mob_db[md->mob_class].skills.front()] = tick;
if (battle_config.mob_skill_log == 1)
PRINTF("MOB skill castend skill=%d, mob_class = %d\n",
@@ -3074,7 +3055,7 @@ void mobskill_castend_pos(TimerData *, tick_t tick, int id)
range = battle_get_range(md) - (range + 1);
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;
+ md->skilldelayup[md->skillidx - &mob_db[md->mob_class].skills.front()] = tick;
if (battle_config.mob_skill_log == 1)
PRINTF("MOB skill castend skill=%d, mob_class = %d\n",
@@ -3087,7 +3068,7 @@ void mobskill_castend_pos(TimerData *, tick_t tick, int id)
*------------------------------------------
*/
int mobskill_use_id(dumb_ptr<mob_data> md, dumb_ptr<block_list> target,
- int skill_idx)
+ mob_skill& skill_idx)
{
int range;
struct mob_skill *ms;
@@ -3095,8 +3076,7 @@ int mobskill_use_id(dumb_ptr<mob_data> md, dumb_ptr<block_list> target,
int skill_lv;
nullpo_ret(md);
- ms = &mob_db[md->mob_class].skill[skill_idx];
- nullpo_ret(ms);
+ ms = &skill_idx;
if (target == NULL && (target = map_id2bl(md->target_id)) == NULL)
return 0;
@@ -3125,7 +3105,7 @@ int mobskill_use_id(dumb_ptr<mob_data> md, dumb_ptr<block_list> target,
interval_t casttime = skill_castfix(md, ms->casttime);
md->state.skillcastcancel = ms->cancel;
- md->skilldelay[skill_idx] = gettick();
+ md->skilldelayup[ms - &mob_db[md->mob_class].skills.front()] = gettick();
if (battle_config.mob_skill_log == 1)
PRINTF("MOB skill use target_id=%d skill=%d lv=%d cast=%d, mob_class = %d\n",
@@ -3140,7 +3120,7 @@ int mobskill_use_id(dumb_ptr<mob_data> md, dumb_ptr<block_list> target,
md->skilly = 0;
md->skillid = skill_id;
md->skilllv = skill_lv;
- md->skillidx = skill_idx;
+ md->skillidx = &skill_idx;
if (casttime > interval_t::zero())
{
@@ -3163,7 +3143,7 @@ int mobskill_use_id(dumb_ptr<mob_data> md, dumb_ptr<block_list> target,
*/
static
int mobskill_use_pos(dumb_ptr<mob_data> md,
- int skill_x, int skill_y, int skill_idx)
+ int skill_x, int skill_y, mob_skill& skill_idx)
{
int range;
struct mob_skill *ms;
@@ -3171,8 +3151,7 @@ int mobskill_use_pos(dumb_ptr<mob_data> md,
int skill_lv;
nullpo_ret(md);
- ms = &mob_db[md->mob_class].skill[skill_idx];
- nullpo_ret(ms);
+ ms = &skill_idx;
if (md->bl_prev == NULL)
return 0;
@@ -3196,7 +3175,7 @@ int mobskill_use_pos(dumb_ptr<mob_data> md,
// delay=skill_delayfix(sd, skill_get_delay( skill_id,skill_lv) );
interval_t casttime = skill_castfix(md, ms->casttime);
- md->skilldelay[skill_idx] = gettick();
+ md->skilldelayup[ms - &mob_db[md->mob_class].skills.front()] = gettick();
md->state.skillcastcancel = ms->cancel;
if (battle_config.mob_skill_log == 1)
@@ -3213,7 +3192,7 @@ int mobskill_use_pos(dumb_ptr<mob_data> md,
md->skilltarget = 0;
md->skillid = skill_id;
md->skilllv = skill_lv;
- md->skillidx = skill_idx;
+ md->skillidx = &skill_idx;
if (casttime > interval_t::zero())
{
md->skilltimer = Timer(gettick() + casttime,
@@ -3236,13 +3215,10 @@ int mobskill_use_pos(dumb_ptr<mob_data> md,
int mobskill_use(dumb_ptr<mob_data> md, tick_t tick,
MobSkillCondition event)
{
- struct mob_skill *ms;
-// dumb_ptr<block_list> target=NULL;
int max_hp;
nullpo_ret(md);
- ms = mob_db[md->mob_class].skill;
- nullpo_ret(ms);
+ std::vector<mob_skill>& ms = mob_db[md->mob_class].skills;
max_hp = battle_get_max_hp(md);
@@ -3252,53 +3228,54 @@ int mobskill_use(dumb_ptr<mob_data> md, tick_t tick,
if (md->state.special_mob_ai)
return 0;
- for (int ii = 0; ii < mob_db[md->mob_class].maxskill; ii++)
+ for (mob_skill& msii : ms)
{
+ tick_t& sdii = md->skilldelayup[&msii - &ms.front()];
int flag = 0;
// ディレイ中
- if (tick < md->skilldelay[ii] + ms[ii].delay)
+ if (tick < sdii + msii.delay)
continue;
// 状態判定
- if (ms[ii].state != MobSkillState::ANY && ms[ii].state != md->state.skillstate)
+ if (msii.state != MobSkillState::ANY && msii.state != md->state.skillstate)
continue;
// Note: these *may* both be MobSkillCondition::ANY
- flag = (event == ms[ii].cond1);
+ flag = (event == msii.cond1);
if (!flag)
{
- switch (ms[ii].cond1)
+ switch (msii.cond1)
{
case MobSkillCondition::MSC_ALWAYS:
flag = 1;
break;
case MobSkillCondition::MSC_MYHPLTMAXRATE: // HP< maxhp%
- flag = (md->hp < max_hp * ms[ii].cond2i / 100);
+ flag = (md->hp < max_hp * msii.cond2i / 100);
break;
case MobSkillCondition::MSC_NOTINTOWN: // Only outside of towns.
flag = !md->bl_m->flag.town;
break;
case MobSkillCondition::MSC_SLAVELT: // slave < num
- flag = (mob_countslave(md) < ms[ii].cond2i);
+ flag = (mob_countslave(md) < msii.cond2i);
break;
case MobSkillCondition::MSC_SLAVELE: // slave <= num
- flag = (mob_countslave(md) <= ms[ii].cond2i);
+ flag = (mob_countslave(md) <= msii.cond2i);
break;
}
}
// 確率判定
- if (flag && random_::chance({ms[ii].permillage, 10000}))
+ if (flag && random_::chance({msii.permillage, 10000}))
{
- if (skill_get_inf(ms[ii].skill_id) & 2)
+ if (skill_get_inf(msii.skill_id) & 2)
{
// 場所指定
dumb_ptr<block_list> bl = NULL;
int x = 0, y = 0;
{
- if (ms[ii].target == MobSkillTarget::MST_TARGET)
+ if (msii.target == MobSkillTarget::MST_TARGET)
bl = map_id2bl(md->target_id);
else
bl = md;
@@ -3311,23 +3288,23 @@ int mobskill_use(dumb_ptr<mob_data> md, tick_t tick,
}
if (x <= 0 || y <= 0)
continue;
- if (!mobskill_use_pos(md, x, y, ii))
+ if (!mobskill_use_pos(md, x, y, msii))
return 0;
}
else
{
{
dumb_ptr<block_list> bl = NULL;
- if (ms[ii].target == MobSkillTarget::MST_TARGET)
+ if (msii.target == MobSkillTarget::MST_TARGET)
bl = map_id2bl(md->target_id);
else
bl = md;
- if (bl && !mobskill_use_id(md, bl, ii))
+ if (bl && !mobskill_use_id(md, bl, msii))
return 0;
}
}
- if (ms[ii].emotion >= 0)
- clif_emotion(md, ms[ii].emotion);
+ if (msii.emotion >= 0)
+ clif_emotion(md, msii.emotion);
return 1;
}
}
@@ -3414,7 +3391,8 @@ int mob_readdb(void)
char line[1024];
const char *filename[] = { "db/mob_db.txt", "db/mob_db2.txt" };
- memset(mob_db, 0, sizeof(mob_db));
+ for (mob_db_& e : mob_db)
+ e = mob_db_{};
for (int j = 0; j < 2; j++)
{
@@ -3453,8 +3431,8 @@ int mob_readdb(void)
if (mob_class <= 1000 || mob_class > 2000)
continue;
- memcpy(mob_db[mob_class].name, str[1], 24);
- memcpy(mob_db[mob_class].jname, str[2], 24);
+ strzcpy(mob_db[mob_class].name, str[1], 24);
+ strzcpy(mob_db[mob_class].jname, str[2], 24);
mob_db[mob_class].lv = atoi(str[3]);
mob_db[mob_class].max_hp = atoi(str[4]);
mob_db[mob_class].max_sp = atoi(str[5]);
@@ -3516,7 +3494,7 @@ int mob_readdb(void)
mob_db[mob_class].mutations_nr = atoi(str[55]);
mob_db[mob_class].mutation_power = atoi(str[56]);
- mob_db[mob_class].maxskill = 0;
+ mob_db[mob_class].skills.clear();
mob_db[mob_class].sex = 0;
mob_db[mob_class].hair = 0;
@@ -3546,7 +3524,6 @@ int mob_readskilldb(void)
{
FILE *fp;
char line[1024];
- int i;
const struct
{
@@ -3596,20 +3573,20 @@ int mob_readskilldb(void)
}
while (fgets(line, 1020, fp))
{
- char *sp[20], *p;
int mob_id;
- // always initialized, but clang is not smart enough yet
- struct mob_skill *ms = nullptr;
int j = 0;
if (line[0] == '/' && line[1] == '/')
continue;
- memset(sp, 0, sizeof(sp));
+ char *sp[20] {};
+ char *p;
+ int i;
for (i = 0, p = line; i < 18 && p; i++)
{
sp[i] = p;
- if ((p = strchr(p, ',')) != NULL)
+ p = strchr(p, ',');
+ if (p != NULL)
*p++ = 0;
}
if ((mob_id = atoi(sp[0])) <= 0)
@@ -3617,21 +3594,12 @@ int mob_readskilldb(void)
if (strcmp(sp[1], "clear") == 0)
{
- memset(mob_db[mob_id].skill, 0,
- sizeof(mob_db[mob_id].skill));
- mob_db[mob_id].maxskill = 0;
+ mob_db[mob_id].skills.clear();
continue;
}
- for (i = 0; i < MAX_MOBSKILL; i++)
- if ((ms = &mob_db[mob_id].skill[i])->skill_id == SkillID::ZERO)
- break;
- if (i == MAX_MOBSKILL)
- {
- PRINTF("mob_skill: readdb: too many skill ! [%s] in %d[%s]\n",
- sp[1], mob_id, mob_db[mob_id].jname);
- continue;
- }
+ mob_db[mob_id].skills.push_back(mob_skill{});
+ struct mob_skill *ms = &mob_db[mob_id].skills.back();
ms->state = static_cast<MobSkillState>(atoi(sp[2]));
for (j = 0; j < sizeof(state) / sizeof(state[0]); j++)
@@ -3670,7 +3638,6 @@ int mob_readskilldb(void)
ms->emotion = atoi(sp[17]);
else
ms->emotion = -1;
- mob_db[mob_id].maxskill = i + 1;
}
fclose_(fp);
PRINTF("read %s done\n", filename[x]);
diff --git a/src/map/mob.hpp b/src/map/mob.hpp
index 1c7cfab..66dbc53 100644
--- a/src/map/mob.hpp
+++ b/src/map/mob.hpp
@@ -26,7 +26,7 @@ struct mob_skill
short emotion;
};
-struct mob_db
+struct mob_db_
{
char name[24], jname[24];
int lv;
@@ -51,10 +51,9 @@ struct mob_db
int sex;
short hair, hair_color, weapon, shield, head_top, head_mid, head_buttom, option, clothes_color; // [Valaris]
int equip; // [Valaris]
- int maxskill;
- struct mob_skill skill[MAX_MOBSKILL];
+ std::vector<struct mob_skill> skills;
};
-extern struct mob_db mob_db[];
+extern struct mob_db_ mob_db[];
int mobdb_searchname(const char *str);
int mobdb_checkid(const int id);
diff --git a/src/map/npc.cpp b/src/map/npc.cpp
index b46f3f5..91331cb 100644
--- a/src/map/npc.cpp
+++ b/src/map/npc.cpp
@@ -47,8 +47,10 @@ Map<std::string, struct event_data> ev_db;
static
DMap<std::string, dumb_ptr<npc_data>> npcname_db;
+// used for clock-based event triggers
+// only tm_min, tm_hour, and tm_mday are used
static
-struct tm ev_tm_b; // 時計イベント用
+struct tm ev_tm_b;
/*==========================================
* NPCの無効化/有効化
@@ -72,7 +74,7 @@ void npc_enable_sub(dumb_ptr<block_list> bl, dumb_ptr<npc_data> nd)
if (nd->flag & 1)
return;
- memcpy(aname, nd->name, sizeof(nd->name));
+ strzcpy(aname, nd->name, sizeof(nd->name));
if (sd->areanpc_id == nd->bl_id)
return;
sd->areanpc_id = nd->bl_id;
@@ -134,18 +136,15 @@ int npc_event_dequeue(dumb_ptr<map_session_data> sd)
sd->npc_id = 0;
- if (sd->eventqueue[0][0]) // キューのイベント処理
+ if (!sd->eventqueuel.empty())
{
- if (!pc_addeventtimer(sd, std::chrono::milliseconds(100), sd->eventqueue[0]))
+ if (!pc_addeventtimer(sd, std::chrono::milliseconds(100), sd->eventqueuel.front().c_str()))
{
PRINTF("npc_event_dequeue(): Event timer is full.\n");
return 0;
}
- if (MAX_EVENTQUEUE > 1)
- memmove(sd->eventqueue[0], sd->eventqueue[1],
- (MAX_EVENTQUEUE - 1) * sizeof(sd->eventqueue[0]));
- sd->eventqueue[MAX_EVENTQUEUE - 1][0] = '\0';
+ sd->eventqueuel.pop_front();
return 1;
}
@@ -471,24 +470,7 @@ int npc_event(dumb_ptr<map_session_data> sd, const char *eventname,
if (sd->npc_id != 0)
{
-// if (battle_config.error_log)
-// PRINTF("npc_event: npc_id != 0\n");
- int i;
- for (i = 0; i < MAX_EVENTQUEUE; i++)
- if (!sd->eventqueue[i][0])
- break;
- if (i == MAX_EVENTQUEUE)
- {
- if (battle_config.error_log)
- PRINTF("npc_event: event queue is full !\n");
- }
- else
- {
-// if (battle_config.etc_log)
-// PRINTF("npc_event: enqueue\n");
- strncpy(sd->eventqueue[i], eventname, 50);
- sd->eventqueue[i][49] = '\0';
- }
+ sd->eventqueuel.push_back(eventname);
return 1;
}
if (nd->flag & 1)
@@ -595,7 +577,7 @@ int npc_touch_areanpc(dumb_ptr<map_session_data> sd, map_local *m, int x, int y)
case NpcSubtype::SCRIPT:
{
char aname[50] {};
- memcpy(aname, m->npc[i]->name, sizeof(m->npc[i]->name));
+ strzcpy(aname, m->npc[i]->name, 24);
if (sd->areanpc_id == m->npc[i]->bl_id)
return 1;
@@ -825,8 +807,7 @@ int npc_buylist(dumb_ptr<map_session_data> sd, int n,
if ((item_data = itemdb_exists(item_list[i * 2 + 1])) != NULL)
{
int amount = item_list[i * 2];
- struct item item_tmp;
- memset(&item_tmp, 0, sizeof(item_tmp));
+ struct item item_tmp {};
item_tmp.nameid = item_data->nameid;
item_tmp.identify = 1; // npc販売アイテムは鑑定済み
@@ -978,8 +959,8 @@ int npc_parse_warp(const char *w1, const char *, const char *w3, const char *w4)
nd->bl_y = y;
nd->dir = DIR::S;
nd->flag = 0;
- memcpy(nd->name, w3, 24);
- memcpy(nd->exname, w3, 24);
+ strzcpy(nd->name, w3, 24);
+ strzcpy(nd->exname, w3, 24);
if (!battle_config.warp_point_debug)
nd->npc_class = WARP_CLASS;
@@ -990,7 +971,7 @@ int npc_parse_warp(const char *w1, const char *, const char *w3, const char *w4)
nd->opt1 = Opt1::ZERO;
nd->opt2 = Opt2::ZERO;
nd->opt3 = Opt3::ZERO;
- memcpy(nd->warp.name, to_mapname, 16);
+ strzcpy(nd->warp.name, to_mapname, 16);
xs += 2;
ys += 2;
nd->warp.x = to_x;
@@ -1101,7 +1082,7 @@ int npc_parse_shop(char *w1, char *, char *w3, char *w4)
nd->bl_id = npc_get_new_npc_id();
nd->dir = dir;
nd->flag = 0;
- memcpy(nd->name, w3, 24);
+ strzcpy(nd->name, w3, 24);
nd->npc_class = atoi(w4);
nd->speed = std::chrono::milliseconds(200);
nd->option = Option::ZERO;
@@ -1274,13 +1255,13 @@ int npc_parse_script(char *w1, char *w2, char *w3, char *w4,
if (p)
{
*p = 0;
- memcpy(nd->name, w3, 24);
- memcpy(nd->exname, p + 2, 24);
+ strzcpy(nd->name, w3, 24);
+ strzcpy(nd->exname, p + 2, 24);
}
else
{
- memcpy(nd->name, w3, 24);
- memcpy(nd->exname, w3, 24);
+ strzcpy(nd->name, w3, 24);
+ strzcpy(nd->exname, w3, 24);
}
nd->bl_prev = nd->bl_next = NULL;
@@ -1462,11 +1443,11 @@ int npc_parse_mob(const char *w1, const char *, const char *w3, const char *w4)
md->bl_x = x;
md->bl_y = y;
if (strcmp(w3, "--en--") == 0)
- memcpy(md->name, mob_db[mob_class].name, 24);
+ strzcpy(md->name, mob_db[mob_class].name, 24);
else if (strcmp(w3, "--ja--") == 0)
- memcpy(md->name, mob_db[mob_class].jname, 24);
+ strzcpy(md->name, mob_db[mob_class].jname, 24);
else
- memcpy(md->name, w3, 24);
+ strzcpy(md->name, w3, 24);
md->n = i;
md->mob_class = mob_class;
@@ -1479,7 +1460,7 @@ int npc_parse_mob(const char *w1, const char *, const char *w3, const char *w4)
md->spawn.delay1 = delay1;
md->spawn.delay2 = delay2;
- memset(&md->state, 0, sizeof(md->state));
+ really_memzero_this(&md->state);
// md->timer = nullptr;
md->target_id = 0;
md->attacked_id = 0;
@@ -1487,9 +1468,9 @@ int npc_parse_mob(const char *w1, const char *, const char *w3, const char *w4)
md->lootitemv.clear();
if (strlen(eventname) >= 4)
- memcpy(md->npc_event, eventname, 24);
+ strzcpy(md->npc_event, eventname, 24);
else
- memset(md->npc_event, 0, 24);
+ strzcpy(md->npc_event, "", 24);
md->bl_type = BL::MOB;
map_addiddb(md);
@@ -1526,13 +1507,13 @@ int npc_parse_mapflag(char *w1, char *, char *w3, char *w4)
{
if (strcmp(w4, "SavePoint") == 0)
{
- memcpy(m->save.map, "SavePoint", 16);
+ strzcpy(m->save.map_, "SavePoint", 16);
m->save.x = -1;
m->save.y = -1;
}
else if (sscanf(w4, "%[^,],%d,%d", savemap, &savex, &savey) == 3)
{
- memcpy(m->save.map, savemap, 16);
+ strzcpy(m->save.map_, savemap, 16);
m->save.x = savex;
m->save.y = savey;
}
@@ -1714,7 +1695,10 @@ void npc_free(dumb_ptr<npc_data> nd)
*/
int do_init_npc(void)
{
- memset(&ev_tm_b, -1, sizeof(ev_tm_b));
+ // other fields unused
+ ev_tm_b.tm_min = -1;
+ ev_tm_b.tm_hour = -1;
+ ev_tm_b.tm_mday = -1;
for (; !npc_srcs.empty(); npc_srcs.pop_front())
{
diff --git a/src/map/party.cpp b/src/map/party.cpp
index 451dcfa..de655d7 100644
--- a/src/map/party.cpp
+++ b/src/map/party.cpp
@@ -24,7 +24,7 @@ static
Map<int, struct party> party_db;
static
-int party_check_conflict(dumb_ptr<map_session_data> sd);
+void party_check_conflict(dumb_ptr<map_session_data> sd);
static
void party_send_xyhp_timer(TimerData *tid, tick_t tick);
@@ -83,12 +83,12 @@ int party_create(dumb_ptr<map_session_data> sd, const char *name)
}
/* Relay the result of a party creation request. */
-int party_created(int account_id, int fail, int party_id, const char *name)
+void party_created(int account_id, int fail, int party_id, const char *name)
{
dumb_ptr<map_session_data> sd;
sd = map_id2sd(account_id);
- nullpo_ret(sd);
+ nullpo_retv(sd);
/* The party name is valid and not already taken. */
if (!fail)
@@ -104,7 +104,7 @@ int party_created(int account_id, int fail, int party_id, const char *name)
p = party_db.init(party_id);
p->party_id = party_id;
- memcpy(p->name, name, 24);
+ strzcpy(p->name, name, 24);
/* The party was created successfully. */
clif_party_created(sd, 0);
@@ -112,14 +112,12 @@ int party_created(int account_id, int fail, int party_id, const char *name)
else
clif_party_created(sd, 1);
-
- return 0;
}
// 情報要求
-int party_request_info(int party_id)
+void party_request_info(int party_id)
{
- return intif_request_partyinfo(party_id);
+ intif_request_partyinfo(party_id);
}
// 所属キャラの確認
@@ -502,24 +500,24 @@ int party_optionchanged(int party_id, int account_id, int exp, int item,
}
// パーティメンバの移動通知
-int party_recv_movemap(int party_id, int account_id, const char *mapname, int online,
+void party_recv_movemap(int party_id, int account_id, const char *mapname, int online,
int lv)
{
struct party *p;
int i;
if ((p = party_search(party_id)) == NULL)
- return 0;
+ return;
for (i = 0; i < MAX_PARTY; i++)
{
struct party_member *m = &p->member[i];
if (m == NULL)
{
PRINTF("party_recv_movemap nullpo?\n");
- return 0;
+ return;
}
if (m->account_id == account_id)
{
- memcpy(m->map, mapname, 16);
+ strzcpy(m->map, mapname, 16);
m->online = online;
m->lv = lv;
break;
@@ -530,7 +528,7 @@ int party_recv_movemap(int party_id, int account_id, const char *mapname, int on
if (battle_config.error_log)
PRINTF("party: not found member %d on %d[%s]", account_id,
party_id, p->name);
- return 0;
+ return;
}
for (i = 0; i < MAX_PARTY; i++)
@@ -543,7 +541,6 @@ int party_recv_movemap(int party_id, int account_id, const char *mapname, int on
party_send_xy_clear(p); // 座標再通知要請
clif_party_info(p, -1);
- return 0;
}
// パーティメンバの移動
@@ -601,33 +598,29 @@ int party_send_logout(dumb_ptr<map_session_data> sd)
}
// パーティメッセージ送信
-int party_send_message(dumb_ptr<map_session_data> sd, const char *mes, int len)
+void party_send_message(dumb_ptr<map_session_data> sd, const char *mes)
{
if (sd->status.party_id == 0)
- return 0;
- intif_party_message(sd->status.party_id, sd->status.account_id, mes,
- len);
- return 0;
+ return;
+ intif_party_message(sd->status.party_id, sd->status.account_id, mes);
}
// パーティメッセージ受信
-int party_recv_message(int party_id, int account_id, const char *mes, int len)
+void party_recv_message(int party_id, int account_id, const char *mes)
{
struct party *p;
if ((p = party_search(party_id)) == NULL)
- return 0;
- clif_party_message(p, account_id, mes, len);
- return 0;
+ return;
+ clif_party_message(p, account_id, mes);
}
// パーティ競合確認
-int party_check_conflict(dumb_ptr<map_session_data> sd)
+void party_check_conflict(dumb_ptr<map_session_data> sd)
{
- nullpo_ret(sd);
+ nullpo_retv(sd);
intif_party_checkconflict(sd->status.party_id, sd->status.account_id,
sd->status.name);
- return 0;
}
// 位置やHP通知用
@@ -669,11 +662,11 @@ void party_send_xyhp_timer(TimerData *, tick_t)
}
// 位置通知クリア
-int party_send_xy_clear(struct party *p)
+void party_send_xy_clear(struct party *p)
{
int i;
- nullpo_ret(p);
+ nullpo_retv(p);
for (i = 0; i < MAX_PARTY; i++)
{
@@ -685,7 +678,6 @@ int party_send_xy_clear(struct party *p)
sd->party_hp = -1;
}
}
- return 0;
}
// HP通知の必要性検査用(map_foreachinmoveareaから呼ばれる)
diff --git a/src/map/party.hpp b/src/map/party.hpp
index 4037a04..c27cc08 100644
--- a/src/map/party.hpp
+++ b/src/map/party.hpp
@@ -14,8 +14,8 @@ struct party *party_search(int party_id);
struct party *party_searchname(const char *str);
int party_create(dumb_ptr<map_session_data> sd, const char *name);
-int party_created(int account_id, int fail, int party_id, const char *name);
-int party_request_info(int party_id);
+void party_created(int account_id, int fail, int party_id, const char *name);
+void party_request_info(int party_id);
int party_invite(dumb_ptr<map_session_data> sd, int account_id);
int party_member_added(int party_id, int account_id, int flag);
int party_leave(dumb_ptr<map_session_data> sd);
@@ -26,7 +26,7 @@ int party_reply_invite(dumb_ptr<map_session_data> sd, int account_id,
int flag);
int party_recv_noinfo(int party_id);
int party_recv_info(const struct party *sp);
-int party_recv_movemap(int party_id, int account_id, const char *map,
+void party_recv_movemap(int party_id, int account_id, const char *map,
int online, int lv);
int party_broken(int party_id);
int party_optionchanged(int party_id, int account_id, int exp, int item,
@@ -36,10 +36,10 @@ int party_changeoption(dumb_ptr<map_session_data> sd, int exp, int item);
int party_send_movemap(dumb_ptr<map_session_data> sd);
int party_send_logout(dumb_ptr<map_session_data> sd);
-int party_send_message(dumb_ptr<map_session_data> sd, const char *mes, int len);
-int party_recv_message(int party_id, int account_id, const char *mes, int len);
+void party_send_message(dumb_ptr<map_session_data> sd, const char *mes);
+void party_recv_message(int party_id, int account_id, const char *mes);
-int party_send_xy_clear(struct party *p);
+void party_send_xy_clear(struct party *p);
void party_send_hp_check(dumb_ptr<block_list> bl, int party_id, int *flag);
int party_exp_share(struct party *p, map_local *map, int base_exp, int job_exp);
diff --git a/src/map/path.cpp b/src/map/path.cpp
index b938e3b..879bba3 100644
--- a/src/map/path.cpp
+++ b/src/map/path.cpp
@@ -223,7 +223,6 @@ int can_move(struct map_local *m, int x0, int y0, int x1, int y1)
int path_search(struct walkpath_data *wpd, map_local *m, int x0, int y0, int x1, int y1, int flag)
{
int heap[MAX_HEAP + 1];
- struct tmp_path tp[MAX_WALKPATH * MAX_WALKPATH];
int i, rp, x, y;
int dx, dy;
@@ -277,7 +276,7 @@ int path_search(struct walkpath_data *wpd, map_local *m, int x0, int y0, int x1,
if (flag & 1)
return -1;
- memset(tp, 0, sizeof(tp));
+ struct tmp_path tp[MAX_WALKPATH * MAX_WALKPATH] {};
i = calc_index(x0, y0);
tp[i].x = x0;
diff --git a/src/map/pc.cpp b/src/map/pc.cpp
index f2dcab2..be59c0b 100644
--- a/src/map/pc.cpp
+++ b/src/map/pc.cpp
@@ -394,9 +394,9 @@ int pc_walktoxy_sub(dumb_ptr<map_session_data>);
* saveに必要なステータス修正を行なう
*------------------------------------------
*/
-int pc_makesavestatus(dumb_ptr<map_session_data> sd)
+void pc_makesavestatus(dumb_ptr<map_session_data> sd)
{
- nullpo_ret(sd);
+ nullpo_retv(sd);
// 服の色は色々弊害が多いので保存対象にはしない
if (!battle_config.save_clothcolor)
@@ -406,12 +406,11 @@ int pc_makesavestatus(dumb_ptr<map_session_data> sd)
if (pc_isdead(sd))
{
pc_setrestartvalue(sd, 0);
- memcpy(&sd->status.last_point, &sd->status.save_point,
- sizeof(sd->status.last_point));
+ sd->status.last_point = sd->status.save_point;
}
else
{
- memcpy(sd->status.last_point.map, sd->mapname, 24);
+ strzcpy(sd->status.last_point.map_, sd->mapname_, 16);
sd->status.last_point.x = sd->bl_x;
sd->status.last_point.y = sd->bl_y;
}
@@ -420,15 +419,11 @@ int pc_makesavestatus(dumb_ptr<map_session_data> sd)
if (sd->bl_m->flag.nosave)
{
map_local *m = sd->bl_m;
- if (strcmp(m->save.map, "SavePoint") == 0)
- memcpy(&sd->status.last_point, &sd->status.save_point,
- sizeof(sd->status.last_point));
+ if (strcmp(m->save.map_, "SavePoint") == 0)
+ sd->status.last_point = sd->status.save_point;
else
- memcpy(&sd->status.last_point, &m->save,
- sizeof(sd->status.last_point));
+ sd->status.last_point = m->save;
}
-
- return 0;
}
/*==========================================
@@ -624,7 +619,7 @@ int pc_authok(int id, int login_id2, TimeT connect_until_time,
sd->login_id2 = login_id2;
sd->tmw_version = tmw_version;
- memcpy(&sd->status, st, sizeof(*st));
+ sd->status = *st;
if (sd->status.sex != sd->sex)
{
@@ -636,7 +631,7 @@ int pc_authok(int id, int login_id2, TimeT connect_until_time,
MAP_LOG_XP(sd, "LOGIN");
MAP_LOG_MAGIC(sd, "LOGIN");
- memset(&sd->state, 0, sizeof(sd->state));
+ really_memzero_this(&sd->state);
// 基本的な初期化
sd->state.connect_new = 1;
sd->bl_prev = sd->bl_next = NULL;
@@ -674,13 +669,6 @@ int pc_authok(int id, int login_id2, TimeT connect_until_time,
// -o11c
sd->cast_tick = tick; // + pc_readglobalreg (sd, "MAGIC_CAST_TICK");
- memset(&sd->dev, 0, sizeof(struct square));
- for (int i = 0; i < 5; i++)
- {
- sd->dev.val1[i] = 0;
- sd->dev.val2[i] = 0;
- }
-
// アカウント変数の送信要求
intif_request_accountreg(sd);
@@ -705,15 +693,10 @@ int pc_authok(int id, int login_id2, TimeT connect_until_time,
sd->party_hp = -1;
// イベント関係の初期化
- memset(sd->eventqueue, 0, sizeof(sd->eventqueue));
- for (int i = 0; i < MAX_EVENTTIMER; i++)
- {
- // sd->eventtimer[i] = nullptr;
- }
-
+ sd->eventqueuel.clear();
// 位置の設定
- pc_setpos(sd, sd->status.last_point.map, sd->status.last_point.x,
+ pc_setpos(sd, sd->status.last_point.map_, sd->status.last_point.x,
sd->status.last_point.y, BeingRemoveWhy::GONE);
// パーティ、ギルドデータの要求
@@ -779,7 +762,8 @@ int pc_authok(int id, int login_id2, TimeT connect_until_time,
sd->chat_repeat_reset_due = TimeT();
sd->chat_lastmsg[0] = '\0';
- memset(sd->flood_rates, 0, sizeof(sd->flood_rates));
+ for (tick_t& t : sd->flood_rates)
+ t = tick_t();
sd->packet_flood_reset_due = TimeT();
sd->packet_flood_in = 0;
@@ -794,7 +778,7 @@ int pc_authok(int id, int login_id2, TimeT connect_until_time,
char tmpstr[] = WITH_TIMESTAMP("Your account time limit is: ");
REPLACE_TIMESTAMP(tmpstr, connect_until_time);
- clif_wis_message(sd->fd, wisp_server_name, tmpstr, sizeof(tmpstr));
+ clif_wis_message(sd->fd, wisp_server_name, tmpstr);
}
pc_calcstatus(sd, 1);
@@ -992,7 +976,7 @@ int pc_calcstatus(dumb_ptr<map_session_data> sd, int first)
sd->arrow_range = 0;
sd->nhealhp = sd->nhealsp = sd->nshealhp = sd->nshealsp = sd->nsshealhp =
sd->nsshealsp = 0;
- memset(&sd->special_state, 0, sizeof(sd->special_state));
+ really_memzero_this(&sd->special_state);
sd->watk_ = 0; //二刀流用(仮)
sd->watk_2 = 0;
@@ -2053,8 +2037,7 @@ PickupFail pc_additem(dumb_ptr<map_session_data> sd, struct item *item_data,
i = pc_search_inventory(sd, 0);
if (i >= 0)
{
- memcpy(&sd->status.inventory[i], item_data,
- sizeof(sd->status.inventory[0]));
+ sd->status.inventory[i] = *item_data;
if (bool(item_data->equip))
sd->status.inventory[i].equip = EPOS::ZERO;
@@ -2094,8 +2077,7 @@ int pc_delitem(dumb_ptr<map_session_data> sd, int n, int amount, int type)
{
if (bool(sd->status.inventory[n].equip))
pc_unequipitem(sd, n, CalcStatus::NOW);
- memset(&sd->status.inventory[n], 0,
- sizeof(sd->status.inventory[0]));
+ sd->status.inventory[n] = item{};
sd->inventory_data[n] = NULL;
}
if (!(type & 1))
@@ -2312,7 +2294,7 @@ int pc_cart_delitem(dumb_ptr<map_session_data> sd, int n, int amount, int)
sd->cart_weight -= itemdb_weight(sd->status.cart[n].nameid) * amount;
if (sd->status.cart[n].amount <= 0)
{
- memset(&sd->status.cart[n], 0, sizeof(sd->status.cart[0]));
+ sd->status.cart[n] = item{};
sd->cart_num--;
}
@@ -2329,7 +2311,7 @@ int pc_cart_delitem(dumb_ptr<map_session_data> sd, int n, int amount, int)
int pc_setpos(dumb_ptr<map_session_data> sd, const char *mapname_org, int x, int y,
BeingRemoveWhy clrtype)
{
- char mapname[24];
+ char mapname_[16];
nullpo_ret(sd);
@@ -2348,30 +2330,27 @@ int pc_setpos(dumb_ptr<map_session_data> sd, const char *mapname_org, int x, int
if (pc_issit(sd))
{
// pc_setstand (sd); // [fate] Nothing wrong with warping while sitting
- skill_gangsterparadise(sd, 0);
}
- memcpy(mapname, mapname_org, 24);
- mapname[16] = 0;
- if (strstr(mapname, ".gat") == NULL && strlen(mapname) < 16)
+ strzcpy(mapname_, mapname_org, 16);
+ if (strstr(mapname_, ".gat") == NULL && strlen(mapname_) < 16 - 4)
{
- strcat(mapname, ".gat");
+ strcat(mapname_, ".gat");
}
- map_local *m = map_mapname2mapid(mapname);
+ map_local *m = map_mapname2mapid(mapname_);
if (!m)
{
- if (sd->mapname[0])
+ if (sd->mapname_[0])
{
struct in_addr ip;
int port;
- if (map_mapname2ipport(mapname, &ip, &port) == 0)
+ if (map_mapname2ipport(mapname_, &ip, &port) == 0)
{
skill_stop_dancing(sd, 1);
clif_clearchar(sd, clrtype);
- skill_gangsterparadise(sd, 0);
map_delblock(sd);
- memcpy(sd->mapname, mapname, 24);
+ strzcpy(sd->mapname_, mapname_, 16);
sd->bl_x = x;
sd->bl_y = y;
sd->state.waitingdisconnect = 1;
@@ -2382,7 +2361,7 @@ int pc_setpos(dumb_ptr<map_session_data> sd, const char *mapname_org, int x, int
else if (sd->state.storage_open)
storage_storage_quit(sd);
- chrif_changemapserver(sd, mapname, x, y, ip, port);
+ chrif_changemapserver(sd, mapname_, x, y, ip, port);
return 0;
}
}
@@ -2411,15 +2390,14 @@ int pc_setpos(dumb_ptr<map_session_data> sd, const char *mapname_org, int x, int
while (bool(read_gatp(m, x, y) & MapCell::UNWALKABLE));
}
- if (sd->mapname[0] && sd->bl_prev != NULL)
+ if (sd->mapname_[0] && sd->bl_prev != NULL)
{
clif_clearchar(sd, clrtype);
- skill_gangsterparadise(sd, 0);
map_delblock(sd);
- clif_changemap(sd, m->name, x, y); // [MouseJstr]
+ clif_changemap(sd, m->name_, x, y); // [MouseJstr]
}
- memcpy(sd->mapname, mapname, 24);
+ strzcpy(sd->mapname_, mapname_, 16);
sd->bl_m = m;
sd->to_x = x;
sd->to_y = y;
@@ -2459,7 +2437,7 @@ int pc_randomwarp(dumb_ptr<map_session_data> sd, BeingRemoveWhy type)
&& (i++) < 1000);
if (i < 1000)
- pc_setpos(sd, m->name, x, y, type);
+ pc_setpos(sd, m->name_, x, y, type);
return 0;
}
@@ -2603,14 +2581,6 @@ void pc_walk(TimerData *, tick_t tick, int id, unsigned char data)
}
}
- // ディボーション検査
- for (int i = 0; i < 5; i++)
- if (sd->dev.val1[i])
- {
- skill_devotion3(sd, sd->dev.val1[i]);
- break;
- }
-
if (bool(map_getcell(sd->bl_m, x, y) & MapCell::NPC_NEAR))
npc_touch_areanpc(sd, sd->bl_m, x, y);
else
@@ -2642,7 +2612,7 @@ int pc_walktoxy_sub(dumb_ptr<map_session_data> sd)
if (path_search(&wpd, sd->bl_m, sd->bl_x, sd->bl_y, sd->to_x, sd->to_y, 0))
return 1;
- memcpy(&sd->walkpath, &wpd, sizeof(wpd));
+ sd->walkpath = wpd;
clif_walkok(sd);
sd->state.change_walk_target = 0;
@@ -3089,9 +3059,6 @@ int pc_gainexp_reason(dumb_ptr<map_session_data> sd, int base_exp, int job_exp,
if (sd->bl_prev == NULL || pc_isdead(sd))
return 0;
- if ((battle_config.pvp_exp == 0) && sd->bl_m->flag.pvp) // [MouseJstr]
- return 0; // no exp on pvp maps
-
earray<const char *, PC_GAINEXP_REASON, PC_GAINEXP_REASON::COUNT> reasons //=
{{
"KILLXP",
@@ -3482,8 +3449,6 @@ int pc_resetskill(dumb_ptr<map_session_data> sd)
int pc_damage(dumb_ptr<block_list> src, dumb_ptr<map_session_data> sd,
int damage)
{
- int i = 0;
-
nullpo_ret(sd);
// 既に死んでいたら無効
@@ -3493,7 +3458,6 @@ int pc_damage(dumb_ptr<block_list> src, dumb_ptr<map_session_data> sd,
if (pc_issit(sd))
{
pc_setstand(sd);
- skill_gangsterparadise(sd, 0);
}
if (src)
@@ -3559,14 +3523,9 @@ int pc_damage(dumb_ptr<block_list> src, dumb_ptr<map_session_data> sd,
sd->cast_tick = gettick();
magic_stop_completely(sd);
- for (i = 0; i < 5; i++)
- if (sd->dev.val1[i])
- {
- sd->dev.val1[i] = sd->dev.val2[i] = 0;
- }
-
if (battle_config.death_penalty_type > 0 && sd->status.base_level >= 20)
- { // changed penalty options, added death by player if pk_mode [Valaris]
+ {
+ // changed penalty options, added death by player if pk_mode [Valaris]
if (!sd->bl_m->flag.nopenalty)
{
if (battle_config.death_penalty_type == 1
@@ -3638,7 +3597,7 @@ int pc_damage(dumb_ptr<block_list> src, dumb_ptr<map_session_data> sd,
sd->pvp_point = 0;
pc_setstand(sd);
pc_setrestartvalue(sd, 3);
- pc_setpos(sd, sd->status.save_point.map, sd->status.save_point.x,
+ pc_setpos(sd, sd->status.save_point.map_, sd->status.save_point.x,
sd->status.save_point.y, BeingRemoveWhy::GONE);
}
}
@@ -4753,15 +4712,13 @@ int pc_checkitem(dumb_ptr<map_session_data> sd)
}
if (i > j)
{
- memcpy(&sd->status.inventory[j], &sd->status.inventory[i],
- sizeof(struct item));
+ sd->status.inventory[j] = sd->status.inventory[i];
sd->inventory_data[j] = sd->inventory_data[i];
}
j++;
}
- if (j < MAX_INVENTORY)
- memset(&sd->status.inventory[j], 0,
- sizeof(struct item) * (MAX_INVENTORY - j));
+ while (j < MAX_INVENTORY)
+ sd->status.inventory[j++] = item{};
for (k = j; k < MAX_INVENTORY; k++)
sd->inventory_data[k] = NULL;
@@ -4780,14 +4737,12 @@ int pc_checkitem(dumb_ptr<map_session_data> sd)
}
if (i > j)
{
- memcpy(&sd->status.cart[j], &sd->status.cart[i],
- sizeof(struct item));
+ sd->status.cart[j] = sd->status.cart[i];
}
j++;
}
- if (j < MAX_CART)
- memset(&sd->status.cart[j], 0,
- sizeof(struct item) * (MAX_CART - j));
+ while (j < MAX_CART)
+ sd->status.cart[j++] = item{};
// 装 備位置チェック
@@ -5280,16 +5235,13 @@ void pc_natural_heal(TimerData *, tick_t tick)
* セーブポイントの保存
*------------------------------------------
*/
-int pc_setsavepoint(dumb_ptr<map_session_data> sd, const char *mapname, int x, int y)
+void pc_setsavepoint(dumb_ptr<map_session_data> sd, const char *mapname, int x, int y)
{
- nullpo_ret(sd);
+ nullpo_retv(sd);
- strncpy(sd->status.save_point.map, mapname, 23);
- sd->status.save_point.map[23] = '\0';
+ strzcpy(sd->status.save_point.map_, mapname, 16);
sd->status.save_point.x = x;
sd->status.save_point.y = y;
-
- return 0;
}
/*==========================================
@@ -5355,12 +5307,13 @@ void pc_setstand(dumb_ptr<map_session_data> sd)
}
static
-int pc_calc_sigma(void)
+void pc_calc_sigma(void)
{
int j, k;
{
- memset(hp_sigma_val_0, 0, sizeof(hp_sigma_val_0));
+ for (int& it : hp_sigma_val_0)
+ it = 0;
for (k = 0, j = 2; j <= MAX_LEVEL; j++)
{
k += hp_coefficient_0 * j + 50;
@@ -5368,7 +5321,6 @@ int pc_calc_sigma(void)
hp_sigma_val_0[j - 1] = k;
}
}
- return 0;
}
/*==========================================
@@ -5407,7 +5359,7 @@ void pc_invisibility(dumb_ptr<map_session_data> sd, int enabled)
{
sd->status.option &= ~Option::INVISIBILITY;
clif_status_change(sd, StatusChange::CLIF_OPTION_SC_INVISIBILITY, 0);
- pc_setpos(sd, sd->bl_m->name, sd->bl_x, sd->bl_y, BeingRemoveWhy::WARPED);
+ pc_setpos(sd, sd->bl_m->name_, sd->bl_x, sd->bl_y, BeingRemoveWhy::WARPED);
}
}
diff --git a/src/map/pc.hpp b/src/map/pc.hpp
index c319543..761ab8c 100644
--- a/src/map/pc.hpp
+++ b/src/map/pc.hpp
@@ -49,7 +49,7 @@ void pc_invisibility(dumb_ptr<map_session_data> sd, int enabled); // [Fate]
int pc_counttargeted(dumb_ptr<map_session_data> sd, dumb_ptr<block_list> src,
ATK target_lv);
int pc_setrestartvalue(dumb_ptr<map_session_data> sd, int type);
-int pc_makesavestatus(dumb_ptr<map_session_data>);
+void pc_makesavestatus(dumb_ptr<map_session_data>);
int pc_setnewpc(dumb_ptr<map_session_data>, int, int, int, tick_t, int);
int pc_authok(int, int, TimeT, short tmw_version, const struct mmo_charstatus *);
int pc_authfail(int);
@@ -63,7 +63,7 @@ int pc_walktoxy(dumb_ptr<map_session_data>, int, int);
int pc_stop_walking(dumb_ptr<map_session_data>, int);
int pc_movepos(dumb_ptr<map_session_data>, int, int);
int pc_setpos(dumb_ptr<map_session_data>, const char *, int, int, BeingRemoveWhy);
-int pc_setsavepoint(dumb_ptr<map_session_data>, const char *, int, int);
+void pc_setsavepoint(dumb_ptr<map_session_data>, const char *, int, int);
int pc_randomwarp(dumb_ptr<map_session_data> sd, BeingRemoveWhy type);
ADDITEM pc_checkadditem(dumb_ptr<map_session_data>, int, int);
diff --git a/src/map/script.cpp b/src/map/script.cpp
index 7281784..0e95904 100644
--- a/src/map/script.cpp
+++ b/src/map/script.cpp
@@ -1417,7 +1417,7 @@ void builtin_isat(ScriptState *st)
using namespace operators;
push_val(st->stack, ByteCode::INT,
(x == sd->bl_x) && (y == sd->bl_y)
- && (str == sd->bl_m->name));
+ && (str == sd->bl_m->name_));
}
/*==========================================
@@ -1441,7 +1441,7 @@ void builtin_warp(ScriptState *st)
if (sd->bl_m->flag.noreturn) // 蝶禁止
return;
- pc_setpos(sd, sd->status.save_point.map,
+ pc_setpos(sd, sd->status.save_point.map_,
sd->status.save_point.x, sd->status.save_point.y, BeingRemoveWhy::WARPED);
}
else if (str == "Save")
@@ -1449,7 +1449,7 @@ void builtin_warp(ScriptState *st)
if (sd->bl_m->flag.noreturn) // 蝶禁止
return;
- pc_setpos(sd, sd->status.save_point.map,
+ pc_setpos(sd, sd->status.save_point.map_,
sd->status.save_point.x, sd->status.save_point.y, BeingRemoveWhy::WARPED);
}
else
@@ -1892,7 +1892,6 @@ static
void builtin_getitem(ScriptState *st)
{
int nameid, amount;
- struct item item_tmp;
dumb_ptr<map_session_data> sd;
struct script_data *data;
@@ -1919,7 +1918,7 @@ void builtin_getitem(ScriptState *st)
if (nameid > 0)
{
- memset(&item_tmp, 0, sizeof(item_tmp));
+ struct item item_tmp {};
item_tmp.nameid = nameid;
item_tmp.identify = 1;
if (HARGO2(5)) //アイテムを指定したIDに渡す
@@ -1947,7 +1946,6 @@ void builtin_makeitem(ScriptState *st)
{
int nameid, amount, flag = 0;
int x, y;
- struct item item_tmp;
dumb_ptr<map_session_data> sd;
struct script_data *data;
@@ -1980,7 +1978,7 @@ void builtin_makeitem(ScriptState *st)
if (nameid > 0)
{
- memset(&item_tmp, 0, sizeof(item_tmp));
+ struct item item_tmp {};
item_tmp.nameid = nameid;
if (!flag)
item_tmp.identify = 1;
@@ -2787,7 +2785,7 @@ void builtin_announce(ScriptState *st)
clif_GMmessage(bl, str, flag);
}
else
- intif_GMmessage(str, flag);
+ intif_GMmessage(str);
}
/*==========================================
@@ -3989,7 +3987,7 @@ void builtin_getsavepoint(ScriptState *st)
{
case 0:
{
- dumb_string mapname = dumb_string::copy(sd->status.save_point.map);
+ dumb_string mapname = dumb_string::copy(sd->status.save_point.map_);
push_str(st->stack, ByteCode::STR, mapname);
}
break;
@@ -4059,7 +4057,7 @@ void builtin_isin(ScriptState *st)
push_val(st->stack, ByteCode::INT,
(sd->bl_x >= x1 && sd->bl_x <= x2)
&& (sd->bl_y >= y1 && sd->bl_y <= y2)
- && (str == sd->bl_m->name));
+ && (str == sd->bl_m->name_));
}
// Trigger the shop on a (hopefully) nearby shop NPC
@@ -4147,7 +4145,7 @@ void builtin_getmap(ScriptState *st)
dumb_ptr<map_session_data> sd = script_rid2sd(st);
// A map_data lives essentially forever.
- push_str(st->stack, ByteCode::CONSTSTR, dumb_string::fake(sd->bl_m->name));
+ push_str(st->stack, ByteCode::CONSTSTR, dumb_string::fake(sd->bl_m->name_));
}
//
diff --git a/src/map/skill.cpp b/src/map/skill.cpp
index 4e195be..8fd7802 100644
--- a/src/map/skill.cpp
+++ b/src/map/skill.cpp
@@ -52,16 +52,14 @@ struct skill_name_db skill_names[] =
{SkillID::ZERO, nullptr, nullptr}
};
-earray<struct skill_db, SkillID, SkillID::MAX_SKILL_DB> skill_db;
+earray<skill_db_, SkillID, SkillID::MAX_SKILL_DB> skill_db;
static
int skill_attack(BF attack_type, dumb_ptr<block_list> src,
dumb_ptr<block_list> dsrc, dumb_ptr<block_list> bl,
SkillID skillid, int skilllv, tick_t tick, BCT flag);
-static
-void skill_devotion_end(dumb_ptr<map_session_data> md,
- dumb_ptr<map_session_data> sd, int target);
+
static
void skill_status_change_timer(TimerData *tid, tick_t tick,
int id, StatusChange type);
@@ -93,7 +91,7 @@ int skill_get_max_raise(SkillID id)
int skill_get_range(SkillID id, int lv)
{
- return (lv <= 0) ? 0 : skill_db[id].range[lv - 1];
+ return (lv <= 0) ? 0 : skill_db[id].range_k;
}
int skill_get_sp(SkillID id, int lv)
@@ -103,7 +101,7 @@ int skill_get_sp(SkillID id, int lv)
int skill_get_num(SkillID id, int lv)
{
- return (lv <= 0) ? 0 : skill_db[id].num[lv - 1];
+ return (lv <= 0) ? 0 : skill_db[id].num_k;
}
int skill_get_cast(SkillID id, int lv)
@@ -132,16 +130,6 @@ int skill_get_castnodex(SkillID id, int lv)
return (lv <= 0) ? 0 : skill_db[id].castnodex[lv - 1];
}
-static
-int distance(int x0, int y0, int x1, int y1)
-{
- int dx, dy;
-
- dx = abs(x0 - x1);
- dy = abs(y0 - y1);
- return dx > dy ? dx : dy;
-}
-
/*==========================================
* スキル追加効果
*------------------------------------------
@@ -528,7 +516,7 @@ int skill_castend_nodamage_id(dumb_ptr<block_list> src, dumb_ptr<block_list> bl,
if (md && !md->master_id)
{
mob_summonslave(md,
- mob_db[md->mob_class].skill[md->skillidx].val,
+ md->skillidx->val,
skilllv,
1);
}
@@ -537,7 +525,7 @@ int skill_castend_nodamage_id(dumb_ptr<block_list> src, dumb_ptr<block_list> bl,
case SkillID::NPC_EMOTION:
if (md)
clif_emotion(md,
- mob_db[md->mob_class].skill[md->skillidx].val[0]);
+ md->skillidx->val[0]);
break;
}
@@ -653,73 +641,6 @@ int skill_castcancel(dumb_ptr<block_list> bl, int)
return 1;
}
-/*==========================================
- * ディボーション 有効確認
- *------------------------------------------
- */
-void skill_devotion(dumb_ptr<map_session_data> md, int)
-{
- // 総確認
- int n;
-
- nullpo_retv(md);
-
- for (n = 0; n < 5; n++)
- {
- if (md->dev.val1[n])
- {
- dumb_ptr<map_session_data> sd = map_id2sd(md->dev.val1[n]);
- // 相手が見つからない // 相手をディボしてるのが自分じゃない // 距離が離れてる
- if (sd == NULL
- || (md->bl_id != 0/* was something else - TODO remove this */)
- || skill_devotion3(md, md->dev.val1[n]))
- {
- skill_devotion_end(md, sd, n);
- }
- }
- }
-}
-
-int skill_devotion3(dumb_ptr<block_list> bl, int target)
-{
- // クルセが歩いた時の距離チェック
- dumb_ptr<map_session_data> md;
- dumb_ptr<map_session_data> sd;
- int n, r = 0;
-
- nullpo_retr(1, bl);
-
- md = bl->as_player();
- sd = map_id2sd(target);
- if (sd == NULL)
- return 1;
- else
- r = distance(bl->bl_x, bl->bl_y, sd->bl_x, sd->bl_y);
-
- if ( + 6 < r)
- { // 許容範囲を超えてた
- for (n = 0; n < 5; n++)
- if (md->dev.val1[n] == target)
- md->dev.val2[n] = 0; // 離れた時は、糸を切るだけ
- return 1;
- }
- return 0;
-}
-
-void skill_devotion_end(dumb_ptr<map_session_data> md,
- dumb_ptr<map_session_data>, int target)
-{
- // クルセと被ディボキャラのリセット
- nullpo_retv(md);
-
- md->dev.val1[target] = md->dev.val2[target] = 0;
-}
-
-int skill_gangsterparadise(dumb_ptr<map_session_data>, int)
-{
- return 0;
-}
-
/*----------------------------------------------------------------------------
* ステータス異常
*----------------------------------------------------------------------------
@@ -1253,12 +1174,14 @@ SP scan_stat(char *statname)
static
int skill_readdb(void)
{
- int j, k;
+ int j;
FILE *fp;
char line[1024], *p;
/* The main skill database */
- memset(&skill_db, 0, sizeof(skill_db));
+ for (skill_db_& skdb : skill_db)
+ skdb = skill_db_{};
+
fp = fopen_("db/skill_db.txt", "r");
if (fp == NULL)
{
@@ -1267,7 +1190,7 @@ int skill_readdb(void)
}
while (fgets(line, 1020, fp))
{
- char *split[50], *split2[MAX_SKILL_LEVEL];
+ char *split[50];
if (line[0] == '/' && line[1] == '/')
continue;
for (j = 0, p = line; j < 18 && p; j++)
@@ -1290,17 +1213,9 @@ int skill_readdb(void)
if (/*i < SkillID() ||*/ i > SkillID::MAX_SKILL_DB)
continue;
- memset(split2, 0, sizeof(split2));
- for (j = 0, p = split[1]; j < MAX_SKILL_LEVEL && p; j++)
- {
- split2[j] = p;
- p = strchr(p, ':');
- if (p)
- *p++ = 0;
- }
- for (k = 0; k < MAX_SKILL_LEVEL; k++)
- skill_db[i].range[k] =
- (split2[k]) ? atoi(split2[k]) : atoi(split2[0]);
+ char *split2_0;
+ split2_0 = split[1];
+ skill_db[i].range_k = atoi(split2_0);
skill_db[i].hit = atoi(split[2]);
skill_db[i].inf = atoi(split[3]);
skill_db[i].pl = atoi(split[4]);
@@ -1308,17 +1223,8 @@ int skill_readdb(void)
skill_db[i].max_raise = atoi(split[6]);
skill_db[i].max = atoi(split[7]);
- memset(split2, 0, sizeof(split2));
- for (j = 0, p = split[8]; j < MAX_SKILL_LEVEL && p; j++)
- {
- split2[j] = p;
- p = strchr(p, ':');
- if (p)
- *p++ = 0;
- }
- for (k = 0; k < MAX_SKILL_LEVEL; k++)
- skill_db[i].num[k] =
- (split2[k]) ? atoi(split2[k]) : atoi(split2[0]);
+ split2_0 = split[8];
+ skill_db[i].num_k = atoi(split2_0);
if (strcasecmp(split[9], "yes") == 0)
skill_db[i].castcancel = 1;
@@ -1328,7 +1234,6 @@ int skill_readdb(void)
skill_db[i].inf2 = atoi(split[11]);
skill_db[i].maxcount = atoi(split[12]);
// split[13] was one of: BF::WEAPON, BF::MAGIC, BF::MISC, BF::ZERO
- memset(split2, 0, sizeof(split2));
// split[14] was colon-separated blow counts.
if (!strcasecmp(split[15], "passive"))
diff --git a/src/map/skill.hpp b/src/map/skill.hpp
index 42caf0b..2823943 100644
--- a/src/map/skill.hpp
+++ b/src/map/skill.hpp
@@ -10,13 +10,13 @@ constexpr int MAX_SKILL_ARROW_DB = 150;
constexpr int MAX_SKILL_ABRA_DB = 350;
// スキルデータベース
-struct skill_db
+struct skill_db_
{
- int range[MAX_SKILL_LEVEL], hit, inf, pl, nk, max;
+ int range_k, hit, inf, pl, nk, max;
SP stat;
SkillFlags poolflags;
int max_raise; // `max' is the global max, `max_raise' is the maximum attainable via skill-ups
- int num[MAX_SKILL_LEVEL];
+ int num_k;
int cast[MAX_SKILL_LEVEL], delay[MAX_SKILL_LEVEL];
int upkeep_time[MAX_SKILL_LEVEL], upkeep_time2[MAX_SKILL_LEVEL];
int castcancel, cast_def_rate;
@@ -28,7 +28,8 @@ struct skill_db
int itemid[10], amount[10];
int castnodex[MAX_SKILL_LEVEL];
};
-extern earray<struct skill_db, SkillID, SkillID::MAX_SKILL_DB> skill_db;
+extern
+earray<skill_db_, SkillID, SkillID::MAX_SKILL_DB> skill_db;
struct skill_name_db
{
@@ -74,10 +75,6 @@ void skill_stop_dancing(dumb_ptr<block_list> src, int flag);
// 詠唱キャンセル
int skill_castcancel(dumb_ptr<block_list> bl, int type);
-int skill_gangsterparadise(dumb_ptr<map_session_data> sd, int type);
-void skill_devotion(dumb_ptr<map_session_data> md, int target);
-int skill_devotion3(dumb_ptr<block_list> bl, int target);
-
// ステータス異常
int skill_status_effect(dumb_ptr<block_list> bl, StatusChange type,
int val1,
diff --git a/src/map/storage.cpp b/src/map/storage.cpp
index 5145b80..54bc792 100644
--- a/src/map/storage.cpp
+++ b/src/map/storage.cpp
@@ -119,7 +119,7 @@ int storage_additem(dumb_ptr<map_session_data> sd, struct storage *stor,
if (i >= MAX_STORAGE)
return 1;
- memcpy(&stor->storage_[i], item_data, sizeof(stor->storage_[0]));
+ stor->storage_[i] = *item_data;
stor->storage_[i].amount = amount;
stor->storage_amount++;
clif_storageitemadded(sd, stor, i, amount);
@@ -143,7 +143,7 @@ int storage_delitem(dumb_ptr<map_session_data> sd, struct storage *stor,
stor->storage_[n].amount -= amount;
if (stor->storage_[n].amount == 0)
{
- memset(&stor->storage_[n], 0, sizeof(stor->storage_[0]));
+ stor->storage_[n] = item{};
stor->storage_amount--;
clif_updatestorageamount(sd, stor);
}
diff --git a/src/map/tmw.cpp b/src/map/tmw.cpp
index 955ea74..9929e59 100644
--- a/src/map/tmw.cpp
+++ b/src/map/tmw.cpp
@@ -96,7 +96,7 @@ void tmw_AutoBan(dumb_ptr<map_session_data> sd, const char *reason, int length)
std::string hack_msg = STRPRINTF("[GM] %s has been autobanned for %s spam",
sd->status.name,
reason);
- tmw_GmHackMsg(hack_msg);
+ tmw_GmHackMsg(hack_msg.c_str());
std::string fake_command = STRPRINTF("@autoban %s %dh (%s spam)",
sd->status.name, length, reason);
@@ -135,33 +135,24 @@ int tmw_CheckChatLameness(dumb_ptr<map_session_data>, const char *message)
}
// Sends a whisper to all GMs
-void tmw_GmHackMsg(const_string line)
+void tmw_GmHackMsg(const char *line)
{
intif_wis_message_to_gm(wisp_server_name,
battle_config.hack_info_GM_level,
- line.data(), line.size() + 1);
+ line);
}
/* Remove leading and trailing spaces from a string, modifying in place. */
-void tmw_TrimStr(char *str)
+void tmw_TrimStr(char *const ob)
{
- char *l;
- char *a;
- char *e;
-
- if (!*str)
- return;
-
- e = str + strlen(str) - 1;
-
- /* Skip all leading spaces. */
- for (l = str; *l && isspace(*l); ++l)
- ;
-
- /* Find the end of the string, or the start of trailing spaces. */
- for (a = e; *a && a > l && isspace(*a); --a)
- ;
-
- memmove(str, l, a - l + 1);
- str[a - l + 1] = '\0';
+ char *const oe = ob + strlen(ob);
+ char *nb = ob;
+ while (*nb && isspace(*nb))
+ nb++;
+ char *ne = oe;
+ while (ne != nb && isspace(ne[-1]))
+ ne--;
+ // not like memcpy - allowed to overlap one way
+ char *zb = std::copy(nb, ne, ob);
+ std::fill(zb, oe, '\0');
}
diff --git a/src/map/tmw.hpp b/src/map/tmw.hpp
index 26446b9..5551504 100644
--- a/src/map/tmw.hpp
+++ b/src/map/tmw.hpp
@@ -7,7 +7,7 @@
#include "map.hpp"
int tmw_CheckChatSpam(dumb_ptr<map_session_data> sd, const char *message);
-void tmw_GmHackMsg(const_string line);
+void tmw_GmHackMsg(const char *line);
void tmw_TrimStr(char *str);
#endif // TMW_HPP
diff --git a/src/poison.hpp b/src/poison.hpp
index 46e6d65..2a82a72 100644
--- a/src/poison.hpp
+++ b/src/poison.hpp
@@ -71,8 +71,6 @@
#pragma GCC poison wcsdup
-#if 0
#pragma GCC poison memcpy
#pragma GCC poison memmove
#pragma GCC poison memset
-#endif