summaryrefslogtreecommitdiff
path: root/src/map
diff options
context:
space:
mode:
authorBen Longbons <b.r.longbons@gmail.com>2013-06-18 20:03:57 -0700
committerBen Longbons <b.r.longbons@gmail.com>2013-06-18 20:11:16 -0700
commit83db3bbee4e19e7426a32ee89ad6c2d8e48260f2 (patch)
treea6fb6f6b6acaa09d5a43cd669f87c2f7f519a521 /src/map
parent8b5370313dcc00a45ea5c3e8b4c497bc00fd8e13 (diff)
downloadtmwa-83db3bbee4e19e7426a32ee89ad6c2d8e48260f2.tar.gz
tmwa-83db3bbee4e19e7426a32ee89ad6c2d8e48260f2.tar.bz2
tmwa-83db3bbee4e19e7426a32ee89ad6c2d8e48260f2.tar.xz
tmwa-83db3bbee4e19e7426a32ee89ad6c2d8e48260f2.zip
Also poison memcpy, memmove, and memset
Diffstat (limited to 'src/map')
-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
29 files changed, 709 insertions, 1131 deletions
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