summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Longbons <b.r.longbons@gmail.com>2013-09-08 19:43:28 -0700
committerBen Longbons <b.r.longbons@gmail.com>2013-09-09 19:29:31 -0700
commita5861a4c81bb616b7fba2028cf9ee31f890357c5 (patch)
tree0a7aedad97d70b6194eb57a7de39857d015685a3
parent367e76ba89bde0e3fb6c4ae0e64cd3927e0db2f2 (diff)
downloadtmwa-a5861a4c81bb616b7fba2028cf9ee31f890357c5.tar.gz
tmwa-a5861a4c81bb616b7fba2028cf9ee31f890357c5.tar.bz2
tmwa-a5861a4c81bb616b7fba2028cf9ee31f890357c5.tar.xz
tmwa-a5861a4c81bb616b7fba2028cf9ee31f890357c5.zip
Use IP4 classes and rename conf variables
-rw-r--r--src/char/char.cpp267
-rw-r--r--src/char/char.hpp3
-rw-r--r--src/char/inter.cpp6
-rw-r--r--src/char/inter.hpp1
-rw-r--r--src/common/ip.hpp13
-rw-r--r--src/common/md5calc.cpp21
-rw-r--r--src/common/md5calc.hpp5
-rw-r--r--src/common/socket.cpp6
-rw-r--r--src/common/socket.hpp30
-rw-r--r--src/common/utils.cpp20
-rw-r--r--src/common/utils.hpp4
-rw-r--r--src/ladmin/ladmin.cpp45
-rw-r--r--src/login/login.cpp393
-rw-r--r--src/map/atcommand.cpp41
-rw-r--r--src/map/atcommand.hpp2
-rw-r--r--src/map/battle.cpp162
-rw-r--r--src/map/battle.hpp107
-rw-r--r--src/map/chrif.cpp79
-rw-r--r--src/map/chrif.hpp6
-rw-r--r--src/map/clif.cpp27
-rw-r--r--src/map/clif.hpp7
-rw-r--r--src/map/map.cpp50
-rw-r--r--src/map/map.hpp17
-rw-r--r--src/map/mob.cpp12
-rw-r--r--src/map/pc.cpp22
-rw-r--r--src/map/script.cpp8
-rw-r--r--src/map/skill.cpp2
27 files changed, 466 insertions, 890 deletions
diff --git a/src/char/char.cpp b/src/char/char.cpp
index ab68322..5f63c2a 100644
--- a/src/char/char.cpp
+++ b/src/char/char.cpp
@@ -41,7 +41,7 @@ int server_freezeflag[MAX_MAP_SERVERS]; // Map-server anti-freeze system. Cou
static
int anti_freeze_enable = 0;
static
-std::chrono::seconds ANTI_FREEZE_INTERVAL = std::chrono::seconds(6);
+std::chrono::seconds anti_freeze_interval = std::chrono::seconds(6);
constexpr
std::chrono::milliseconds DEFAULT_AUTOSAVE_INTERVAL =
@@ -59,22 +59,14 @@ ServerName server_name;
static
CharName wisp_server_name = stringish<CharName>("Server");
static
-IP_String login_ip_str;
-static
-int login_ip;
+IP4Address login_ip;
static
int login_port = 6900;
static
-IP_String char_ip_str;
-static
-int char_ip;
+IP4Address char_ip;
static
int char_port = 6121;
static
-int char_maintenance;
-static
-int char_new;
-static
FString char_txt;
static
CharName unknown_char_name = stringish<CharName>("Unknown");
@@ -82,11 +74,9 @@ static
FString char_log_filename = "log/char.log";
//Added for lan support
static
-IP_String lan_map_ip;
+IP4Address lan_map_ip;
static
-uint8_t subneti[4];
-static
-uint8_t subnetmaski[4];
+IP4Mask lan_subnet;
static
int char_name_option = 0; // Option to know which letters/symbols are authorised in the name of a character (0: all, 1: only those in char_name_letters, 2: all EXCEPT those in char_name_letters) by [Yor]
static
@@ -110,7 +100,7 @@ struct AuthFifoEntry
int account_id;
int char_id;
int login_id1, login_id2;
- int ip;
+ IP4Address ip;
int delflag;
int sex;
unsigned short packet_tmw_version;
@@ -131,13 +121,7 @@ std::vector<mmo_charstatus> char_data;
static
int max_connect_user = 0;
static
-std::chrono::milliseconds autosave_interval = DEFAULT_AUTOSAVE_INTERVAL;
-static
-int start_zeny = 500;
-static
-int start_weapon = 1201;
-static
-int start_armor = 1202;
+std::chrono::milliseconds autosave_time = DEFAULT_AUTOSAVE_INTERVAL;
// Initial position (it's possible to set it in conf file)
static
@@ -666,10 +650,7 @@ mmo_charstatus *make_new_char(int fd, CharName name, const uint8_t (&stats)[6],
return nullptr;
}
- char ip[16];
- uint8_t *sin_addr = reinterpret_cast<uint8_t *>(&session[fd]->client_addr.sin_addr);
- sprintf(ip, "%d.%d.%d.%d", sin_addr[0], sin_addr[1], sin_addr[2],
- sin_addr[3]);
+ IP4Address ip = session[fd]->client_ip;
CHAR_LOG("Creation of New Character: (connection #%d, account: %d) slot %d, character Name: %s, stats: %d+%d+%d+%d+%d+%d=%d, hair: %d, hair color: %d. [%s]\n",
fd, sd->account_id, slot, name,
@@ -688,7 +669,7 @@ mmo_charstatus *make_new_char(int fd, CharName name, const uint8_t (&stats)[6],
cd.job_level = 1;
cd.base_exp = 0;
cd.job_exp = 0;
- cd.zeny = start_zeny;
+ cd.zeny = 0;
cd.attrs[ATTR::STR] = stats[0];
cd.attrs[ATTR::AGI] = stats[1];
cd.attrs[ATTR::VIT] = stats[2];
@@ -1562,12 +1543,11 @@ void parse_frommap(int fd)
j++;
}
{
- uint8_t *p = reinterpret_cast<uint8_t *>(&server[id].ip);
- PRINTF("Map-Server %d connected: %d maps, from IP %d.%d.%d.%d port %d.\n",
- id, j, p[0], p[1], p[2], p[3], server[id].port);
+ PRINTF("Map-Server %d connected: %d maps, from IP %s port %d.\n",
+ id, j, server[id].ip, server[id].port);
PRINTF("Map-server %d loading complete.\n", id);
- CHAR_LOG("Map-Server %d connected: %d maps, from IP %d.%d.%d.%d port %d. Map-server %d loading complete.\n",
- id, j, p[0], p[1], p[2], p[3],
+ CHAR_LOG("Map-Server %d connected: %d maps, from IP %s port %d. Map-server %d loading complete.\n",
+ id, j, server[id].ip,
server[id].port, id);
}
WFIFOW(fd, 0) = 0x2afb;
@@ -1587,7 +1567,7 @@ void parse_frommap(int fd)
{
WBUFW(buf, 0) = 0x2b04;
WBUFW(buf, 2) = j * 16 + 10;
- WBUFL(buf, 4) = server[id].ip;
+ WBUFIP(buf, 4) = server[id].ip;
WBUFW(buf, 8) = server[id].port;
// server[id].maps[i] = RFIFO_STRING(fd, 4 + i * 16)
for (int i = 0; i < j; ++i)
@@ -1600,7 +1580,7 @@ void parse_frommap(int fd)
if (server_fd[x] >= 0 && x != id)
{
WFIFOW(fd, 0) = 0x2b04;
- WFIFOL(fd, 4) = server[x].ip;
+ WFIFOIP(fd, 4) = server[x].ip;
WFIFOW(fd, 8) = server[x].port;
j = 0;
for (int i = 0; i < MAX_MAP_PER_SERVER; i++)
@@ -1630,7 +1610,7 @@ void parse_frommap(int fd)
afi.login_id1 == RFIFOL(fd, 10) &&
// here, it's the only area where it's possible that we doesn't know login_id2 (map-server asks just after 0x72 packet, that doesn't given the value)
(afi.login_id2 == RFIFOL(fd, 14) || RFIFOL(fd, 14) == 0) && // relate to the versions higher than 18
- (!check_ip_flag || afi.ip == RFIFOL(fd, 18))
+ (!check_ip_flag || afi.ip == RFIFOIP(fd, 18))
&& !afi.delflag)
{
mmo_charstatus *cd = nullptr;
@@ -1732,7 +1712,7 @@ void parse_frommap(int fd)
auth_fifo_iter->login_id2 = RFIFOL(fd, 10);
auth_fifo_iter->delflag = 2;
auth_fifo_iter->connect_until_time = TimeT(); // unlimited/unknown time by default (not display in map-server)
- auth_fifo_iter->ip = RFIFOL(fd, 14);
+ auth_fifo_iter->ip = RFIFOIP(fd, 14);
auth_fifo_iter++;
WFIFOW(fd, 0) = 0x2b03;
WFIFOL(fd, 2) = RFIFOL(fd, 2);
@@ -1758,7 +1738,7 @@ void parse_frommap(int fd)
auth_fifo_iter->delflag = 0;
auth_fifo_iter->sex = RFIFOB(fd, 44);
auth_fifo_iter->connect_until_time = TimeT(); // unlimited/unknown time by default (not display in map-server)
- auth_fifo_iter->ip = RFIFOL(fd, 45);
+ auth_fifo_iter->ip = RFIFOIP(fd, 45);
// default, if not found in the loop
WFIFOW(fd, 6) = 1;
@@ -1774,28 +1754,6 @@ void parse_frommap(int fd)
RFIFOSKIP(fd, 49);
break;
- // キャラ名検索
- case 0x2b08:
- if (RFIFOREST(fd) < 6)
- return;
- {
- CharName name = unknown_char_name;
- for (const mmo_charstatus& cd : char_data)
- {
- if (cd.char_id == RFIFOL(fd, 2))
- {
- name = cd.name;
- break;
- }
- }
- WFIFOW(fd, 0) = 0x2b09;
- WFIFOL(fd, 2) = RFIFOL(fd, 2);
- WFIFO_STRING(fd, 6, name.to__actual(), 24);
- WFIFOSET(fd, 30);
- }
- RFIFOSKIP(fd, 6);
- break;
-
// it is a request to become GM
case 0x2b0a:
if (RFIFOREST(fd) < 4 || RFIFOREST(fd) < RFIFOW(fd, 2))
@@ -2038,33 +1996,18 @@ int search_mapserver(XString map)
// Test to know if an IP come from LAN or WAN. by [Yor]
//-----------------------------------------------------
static
-int lan_ip_check(unsigned char *p)
+int lan_ip_check(IP4Address addr)
{
- int i;
- int lancheck = 1;
+ bool lancheck = lan_subnet.covers(addr);
-// PRINTF("lan_ip_check: to compare: %d.%d.%d.%d, network: %d.%d.%d.%d/%d.%d.%d.%d\n",
-// p[0], p[1], p[2], p[3],
-// subneti[0], subneti[1], subneti[2], subneti[3],
-// subnetmaski[0], subnetmaski[1], subnetmaski[2], subnetmaski[3]);
- for (i = 0; i < 4; i++)
- {
- if ((subneti[i] & subnetmaski[i]) != (p[i] & subnetmaski[i]))
- {
- lancheck = 0;
- break;
- }
- }
PRINTF("LAN test (result): %s source\033[0m.\n",
(lancheck) ? "\033[1;36mLAN" : "\033[1;32mWAN");
return lancheck;
}
static
-void handle_x0066(int fd, struct char_session_data *sd, uint8_t rfifob_2, uint8_t *p)
+void handle_x0066(int fd, struct char_session_data *sd, uint8_t rfifob_2, IP4Address ip)
{
- IP_String ip = ip2str(session[fd]->client_addr.sin_addr);
-
{
mmo_charstatus *cd = nullptr;
for (mmo_charstatus& cdi : char_data)
@@ -2115,10 +2058,10 @@ void handle_x0066(int fd, struct char_session_data *sd, uint8_t rfifob_2, uint8_
cd->name,
sd->account_id, cd->char_num, ip);
PRINTF("--Send IP of map-server. ");
- if (lan_ip_check(p))
- WFIFOL(fd, 22) = inet_addr(lan_map_ip.c_str());
+ if (lan_ip_check(ip))
+ WFIFOIP(fd, 22) = lan_map_ip;
else
- WFIFOL(fd, 22) = server[i].ip;
+ WFIFOIP(fd, 22) = server[i].ip;
WFIFOW(fd, 26) = server[i].port;
WFIFOSET(fd, 28);
if (auth_fifo_iter == auth_fifo.end())
@@ -2130,7 +2073,7 @@ void handle_x0066(int fd, struct char_session_data *sd, uint8_t rfifob_2, uint8_
auth_fifo_iter->delflag = 0;
auth_fifo_iter->sex = sd->sex;
auth_fifo_iter->connect_until_time = sd->connect_until_time;
- auth_fifo_iter->ip = session[fd]->client_addr.sin_addr.s_addr;
+ auth_fifo_iter->ip = session[fd]->client_ip;
auth_fifo_iter->packet_tmw_version = sd->packet_tmw_version;
auth_fifo_iter++;
}
@@ -2140,7 +2083,7 @@ void handle_x0066(int fd, struct char_session_data *sd, uint8_t rfifob_2, uint8_
static
void parse_char(int fd)
{
- uint8_t *p = reinterpret_cast<uint8_t *>(&session[fd]->client_addr.sin_addr);
+ IP4Address ip = session[fd]->client_ip;
if (login_fd < 0 || session[fd]->eof)
{ // disconnect any player (already connected to char-server or coming back from map-server) if login-server is diconnected.
@@ -2213,7 +2156,7 @@ void parse_char(int fd)
&& afi.login_id1 == sd->login_id1
&& afi.login_id2 == sd->login_id2
&& (!check_ip_flag
- || afi.ip == session[fd]->client_addr.sin_addr.s_addr)
+ || afi.ip == session[fd]->client_ip)
&& afi.delflag == 2)
{
afi.delflag = 1;
@@ -2253,8 +2196,7 @@ void parse_char(int fd)
WFIFOL(login_fd, 6) = sd->login_id1;
WFIFOL(login_fd, 10) = sd->login_id2; // relate to the versions higher than 18
WFIFOB(login_fd, 14) = sd->sex;
- WFIFOL(login_fd, 15) =
- session[fd]->client_addr.sin_addr.s_addr;
+ WFIFOIP(login_fd, 15) = session[fd]->client_ip;
WFIFOSET(login_fd, 19);
}
else
@@ -2272,7 +2214,7 @@ void parse_char(int fd)
case 0x66: // キャラ選択
if (!sd || RFIFOREST(fd) < 3)
return;
- handle_x0066(fd, sd, RFIFOB(fd, 2), p);
+ handle_x0066(fd, sd, RFIFOB(fd, 2), ip);
RFIFOSKIP(fd, 3);
break;
@@ -2417,7 +2359,7 @@ void parse_char(int fd)
if (anti_freeze_enable)
server_freezeflag[i] = 5; // Map anti-freeze system. Counter. 5 ok, 4...0 freezed
// ignore RFIFOL(fd, 50)
- server[i].ip = RFIFOL(fd, 54);
+ server[i].ip = RFIFOIP(fd, 54);
server[i].port = RFIFOW(fd, 58);
server[i].users = 0;
for (MapName& mapi : server[i].maps)
@@ -2558,12 +2500,12 @@ void check_connect_login_server(TimerData *, tick_t)
WFIFO_STRING(login_fd, 2, userid, 24);
WFIFO_STRING(login_fd, 26, passwd, 24);
WFIFOL(login_fd, 50) = 0;
- WFIFOL(login_fd, 54) = char_ip;
+ WFIFOIP(login_fd, 54) = char_ip;
WFIFOL(login_fd, 58) = char_port;
WFIFO_STRING(login_fd, 60, server_name, 20);
WFIFOW(login_fd, 80) = 0;
- WFIFOW(login_fd, 82) = char_maintenance;
- WFIFOW(login_fd, 84) = char_new;
+ WFIFOW(login_fd, 82) = 0; //char_maintenance;
+ WFIFOW(login_fd, 84) = 0; //char_new;
WFIFOSET(login_fd, 86);
}
}
@@ -2577,13 +2519,8 @@ int lan_config_read(ZString lancfgName)
struct hostent *h = NULL;
// set default configuration
- lan_map_ip = stringish<IP_String>("127.0.0.1");
- subneti[0] = 127;
- subneti[1] = 0;
- subneti[2] = 0;
- subneti[3] = 1;
- for (int j = 0; j < 4; j++)
- subnetmaski[j] = 255;
+ lan_map_ip = IP4_LOCALHOST;
+ lan_subnet = IP4Mask(IP4_LOCALHOST, IP4_BROADCAST);
std::ifstream in(lancfgName.c_str());
@@ -2609,56 +2546,30 @@ int lan_config_read(ZString lancfgName)
h = gethostbyname(w2.c_str());
if (h != NULL)
{
- SNPRINTF(lan_map_ip, 16, "%d.%d.%d.%d",
- static_cast<uint8_t>(h->h_addr[0]),
- static_cast<uint8_t>(h->h_addr[1]),
- static_cast<uint8_t>(h->h_addr[2]),
- static_cast<uint8_t>(h->h_addr[3]));
+ lan_map_ip = IP4Address({
+ static_cast<uint8_t>(h->h_addr[0]),
+ static_cast<uint8_t>(h->h_addr[1]),
+ static_cast<uint8_t>(h->h_addr[2]),
+ static_cast<uint8_t>(h->h_addr[3]),
+ });
}
else
{
- lan_map_ip = stringish<IP_String>(w2);
+ PRINTF("Bad IP value: %s\n", line);
+ abort();
}
PRINTF("LAN IP of map-server: %s.\n", lan_map_ip);
}
- else if (w1 == "subnet")
- {
- // Read Subnetwork
- for (int j = 0; j < 4; j++)
- subneti[j] = 0;
- h = gethostbyname(w2.c_str());
- if (h != NULL)
- {
- for (int j = 0; j < 4; j++)
- subneti[j] = h->h_addr[j];
- }
- else
- {
- SSCANF(w2, "%hhu.%hhu.%hhu.%hhu", &subneti[0], &subneti[1],
- &subneti[2], &subneti[3]);
- }
- PRINTF("Sub-network of the map-server: %d.%d.%d.%d.\n",
- subneti[0], subneti[1], subneti[2], subneti[3]);
- }
- else if (w1 == "subnetmask")
+ else if (w1 == "subnet" /*backward compatibility*/
+ || w1 == "lan_subnet")
{
- // Read Subnetwork Mask
- for (int j = 0; j < 4; j++)
- subnetmaski[j] = 255;
- h = gethostbyname(w2.c_str());
- if (h != NULL)
+ if (!extract(w2, &lan_subnet))
{
- for (int j = 0; j < 4; j++)
- subnetmaski[j] = h->h_addr[j];
+ PRINTF("Bad IP mask: %s\n", line);
+ abort();
}
- else
- {
- SSCANF(w2, "%hhu.%hhu.%hhu.%hhu", &subnetmaski[0], &subnetmaski[1],
- &subnetmaski[2], &subnetmaski[3]);
- }
- PRINTF("Sub-network mask of the map-server: %d.%d.%d.%d.\n",
- subnetmaski[0], subnetmaski[1], subnetmaski[2],
- subnetmaski[3]);
+ PRINTF("Sub-network of the map-server: %s.\n",
+ lan_subnet);
}
else
{
@@ -2669,10 +2580,8 @@ int lan_config_read(ZString lancfgName)
// sub-network check of the map-server
{
- unsigned char p[4];
- SSCANF(lan_map_ip, "%hhu.%hhu.%hhu.%hhu", &p[0], &p[1], &p[2], &p[3]);
PRINTF("LAN test of LAN IP of the map-server: ");
- if (lan_ip_check(p) == 0)
+ if (!lan_ip_check(lan_map_ip))
{
PRINTF("\033[1;31m***ERROR: LAN IP of the map-server doesn't belong to the specified Sub-network.\033[0m\n");
}
@@ -2723,16 +2632,20 @@ int char_config_read(ZString cfgName)
h = gethostbyname(w2.c_str());
if (h != NULL)
{
- SNPRINTF(login_ip_str, 16, "%d.%d.%d.%d",
+ login_ip = IP4Address({
static_cast<uint8_t>(h->h_addr[0]),
static_cast<uint8_t>(h->h_addr[1]),
static_cast<uint8_t>(h->h_addr[2]),
- static_cast<uint8_t>(h->h_addr[3]));
+ static_cast<uint8_t>(h->h_addr[3]),
+ });
PRINTF("Login server IP address : %s -> %s\n",
- w2, login_ip_str);
+ w2, login_ip);
}
else
- login_ip_str = stringish<IP_String>(w2);
+ {
+ PRINTF("Bad IP value: %s\n", line);
+ abort();
+ }
}
else if (w1 == "login_port")
{
@@ -2743,29 +2656,25 @@ int char_config_read(ZString cfgName)
h = gethostbyname(w2.c_str());
if (h != NULL)
{
- SNPRINTF(char_ip_str, 16, "%d.%d.%d.%d",
+ char_ip = IP4Address({
static_cast<uint8_t>(h->h_addr[0]),
static_cast<uint8_t>(h->h_addr[1]),
static_cast<uint8_t>(h->h_addr[2]),
- static_cast<uint8_t>(h->h_addr[3]));
+ static_cast<uint8_t>(h->h_addr[3]),
+ });
PRINTF("Character server IP address : %s -> %s\n",
- w2, char_ip_str);
+ w2, char_ip);
}
else
- char_ip_str = stringish<IP_String>(w2);
+ {
+ PRINTF("Bad IP value: %s\n", line);
+ abort();
+ }
}
else if (w1 == "char_port")
{
char_port = atoi(w2.c_str());
}
- else if (w1 == "char_maintenance")
- {
- char_maintenance = atoi(w2.c_str());
- }
- else if (w1 == "char_new")
- {
- char_new = atoi(w2.c_str());
- }
else if (w1 == "char_txt")
{
char_txt = w2;
@@ -2782,32 +2691,14 @@ int char_config_read(ZString cfgName)
}
else if (w1 == "autosave_time")
{
- autosave_interval = std::chrono::seconds(atoi(w2.c_str()));
- if (autosave_interval <= std::chrono::seconds::zero())
- autosave_interval = DEFAULT_AUTOSAVE_INTERVAL;
+ autosave_time = std::chrono::seconds(atoi(w2.c_str()));
+ if (autosave_time <= std::chrono::seconds::zero())
+ autosave_time = DEFAULT_AUTOSAVE_INTERVAL;
}
else if (w1 == "start_point")
{
extract(w2, &start_point);
}
- else if (w1 == "start_zeny")
- {
- start_zeny = atoi(w2.c_str());
- if (start_zeny < 0)
- start_zeny = 0;
- }
- else if (w1 == "start_weapon")
- {
- start_weapon = atoi(w2.c_str());
- if (start_weapon < 0)
- start_weapon = 0;
- }
- else if (w1 == "start_armor")
- {
- start_armor = atoi(w2.c_str());
- if (start_armor < 0)
- start_armor = 0;
- }
else if (w1 == "unknown_char_name")
{
unknown_char_name = stringish<CharName>(w2);
@@ -2822,8 +2713,11 @@ int char_config_read(ZString cfgName)
}
else if (w1 == "char_name_letters")
{
- for (uint8_t c : w2)
- char_name_letters[c] = true;
+ if (!w2)
+ char_name_letters.reset();
+ else
+ for (uint8_t c : w2)
+ char_name_letters[c] = true;
}
else if (w1 == "online_txt_filename")
{
@@ -2855,7 +2749,7 @@ int char_config_read(ZString cfgName)
}
else if (w1 == "anti_freeze_interval")
{
- ANTI_FREEZE_INTERVAL = std::max(
+ anti_freeze_interval = std::max(
std::chrono::seconds(atoi(w2.c_str())),
std::chrono::seconds(5));
}
@@ -2909,9 +2803,6 @@ int do_init(int argc, ZString *argv)
else
lan_config_read(LOGIN_LAN_CONF_NAME);
- login_ip = inet_addr(login_ip_str.c_str());
- char_ip = inet_addr(char_ip_str.c_str());
-
for (i = 0; i < MAX_MAP_SERVERS; i++)
{
server[i] = mmo_map_server{};
@@ -2941,16 +2832,16 @@ int do_init(int argc, ZString *argv)
send_users_tologin,
std::chrono::seconds(5)
).detach();
- Timer(gettick() + autosave_interval,
+ Timer(gettick() + autosave_time,
mmo_char_sync_timer,
- autosave_interval
+ autosave_time
).detach();
if (anti_freeze_enable > 0)
{
Timer(gettick() + std::chrono::seconds(1),
map_anti_freeze_system,
- ANTI_FREEZE_INTERVAL
+ anti_freeze_interval
).detach();
}
diff --git a/src/char/char.hpp b/src/char/char.hpp
index 8e37c64..abd5381 100644
--- a/src/char/char.hpp
+++ b/src/char/char.hpp
@@ -2,6 +2,7 @@
#define CHAR_HPP
#include "../common/const_array.hpp"
+#include "../common/ip.hpp"
#include "../common/mmo.hpp"
constexpr int MAX_MAP_SERVERS = 30;
@@ -12,7 +13,7 @@ constexpr int MAX_MAP_SERVERS = 30;
struct mmo_map_server
{
- long ip;
+ IP4Address ip;
short port;
int users;
MapName maps[MAX_MAP_PER_SERVER];
diff --git a/src/char/inter.cpp b/src/char/inter.cpp
index 3cb51e7..81c4a9d 100644
--- a/src/char/inter.cpp
+++ b/src/char/inter.cpp
@@ -26,8 +26,6 @@
// that is the waiting time of answers of all map-servers
constexpr std::chrono::minutes WISDATA_TTL = std::chrono::minutes(1);
-FString inter_log_filename = "log/inter.log";
-
static
FString accreg_txt = "save/accreg.txt";
@@ -203,10 +201,6 @@ int inter_config_read(ZString cfgName)
if (party_share_level < 0)
party_share_level = 0;
}
- else if (w1 == "inter_log_filename")
- {
- inter_log_filename = w2;
- }
else if (w1 == "import")
{
inter_config_read(w2);
diff --git a/src/char/inter.hpp b/src/char/inter.hpp
index ce8447d..447ab53 100644
--- a/src/char/inter.hpp
+++ b/src/char/inter.hpp
@@ -12,6 +12,5 @@ int inter_check_length(int fd, int length);
#define inter_cfgName "conf/inter_athena.conf"
extern int party_share_level;
-extern FString inter_log_filename;
#endif // INTER_HPP
diff --git a/src/common/ip.hpp b/src/common/ip.hpp
index e67056c..aceb765 100644
--- a/src/common/ip.hpp
+++ b/src/common/ip.hpp
@@ -21,6 +21,8 @@
#include "sanity.hpp"
+#include <netinet/in.h>
+
#include "extract.hpp"
#include "strings.hpp"
@@ -53,6 +55,17 @@ public:
IP4Address(const uint8_t (&a)[4])
: _addr{a[0], a[1], a[2], a[3]}
{}
+ explicit
+ IP4Address(struct in_addr addr)
+ {
+ static_assert(sizeof(addr) == sizeof(_addr), "4 bytes");
+ *this = IP4Address(reinterpret_cast<const uint8_t (&)[4]>(addr));
+ }
+ explicit
+ operator struct in_addr() const
+ {
+ return reinterpret_cast<const struct in_addr&>(_addr);
+ }
constexpr friend
IP4Address operator & (IP4Address l, IP4Address r)
diff --git a/src/common/md5calc.cpp b/src/common/md5calc.cpp
index ae134b7..1c48a24 100644
--- a/src/common/md5calc.cpp
+++ b/src/common/md5calc.cpp
@@ -327,26 +327,21 @@ bool pass_ok(AccountPass password, AccountCrypt crypted)
// [M|h]ashes up an IP address and a secret key
// to return a hopefully unique masked IP.
-struct in_addr MD5_ip(struct in_addr ip)
+IP4Address MD5_ip(IP4Address ip)
{
static SaltString secret = make_salt();
- union
- {
- uint8_t bytes[4];
- struct in_addr ip;
- } conv;
// MD5sum a secret + the IP address
VString<31> ipbuf;
- SNPRINTF(ipbuf, 32, "%u%s", ip.s_addr, secret);
+ SNPRINTF(ipbuf, 32, "%s %s", ip, secret);
md5_binary obuf;
MD5_to_bin(MD5_from_string(ipbuf), obuf);
// Fold the md5sum to 32 bits, pack the bytes to an in_addr
- conv.bytes[0] = obuf[0] ^ obuf[1] ^ obuf[8] ^ obuf[9];
- conv.bytes[1] = obuf[2] ^ obuf[3] ^ obuf[10] ^ obuf[11];
- conv.bytes[2] = obuf[4] ^ obuf[5] ^ obuf[12] ^ obuf[13];
- conv.bytes[3] = obuf[6] ^ obuf[7] ^ obuf[14] ^ obuf[15];
-
- return conv.ip;
+ return IP4Address({
+ static_cast<uint8_t>(obuf[0] ^ obuf[1] ^ obuf[8] ^ obuf[9]),
+ static_cast<uint8_t>(obuf[2] ^ obuf[3] ^ obuf[10] ^ obuf[11]),
+ static_cast<uint8_t>(obuf[4] ^ obuf[5] ^ obuf[12] ^ obuf[13]),
+ static_cast<uint8_t>(obuf[6] ^ obuf[7] ^ obuf[14] ^ obuf[15]),
+ });
}
diff --git a/src/common/md5calc.hpp b/src/common/md5calc.hpp
index 98f44d6..70a996e 100644
--- a/src/common/md5calc.hpp
+++ b/src/common/md5calc.hpp
@@ -11,6 +11,7 @@
#include <array>
+#include "ip.hpp"
#include "mmo.hpp"
#include "strings.hpp"
@@ -53,7 +54,7 @@ SaltString make_salt(void);
/// check plaintext password against saved saltcrypt
bool pass_ok(AccountPass password, AccountCrypt crypted);
-/// This returns an in_addr because it is configurable whether it gets called at all
-struct in_addr MD5_ip(struct in_addr ip);
+/// This returns an IP4Address because it is configurable whether it gets called at all
+IP4Address MD5_ip(IP4Address ip);
#endif // MD5CALC_HPP
diff --git a/src/common/socket.cpp b/src/common/socket.cpp
index 4655d1d..c7e6ed2 100644
--- a/src/common/socket.cpp
+++ b/src/common/socket.cpp
@@ -174,7 +174,7 @@ void connect_client(int listen_fd)
session[fd]->func_recv = recv_to_fifo;
session[fd]->func_send = send_from_fifo;
session[fd]->func_parse = default_func_parse;
- session[fd]->client_addr = client_address;
+ session[fd]->client_ip = IP4Address(client_address.sin_addr);
session[fd]->created = TimeT::now();
session[fd]->connected = 0;
}
@@ -240,7 +240,7 @@ int make_listen_port(uint16_t port)
return fd;
}
-int make_connection(uint32_t ip, uint16_t port)
+int make_connection(IP4Address ip, uint16_t port)
{
struct sockaddr_in server_address;
int fd = socket(AF_INET, SOCK_STREAM, 0);
@@ -264,7 +264,7 @@ int make_connection(uint32_t ip, uint16_t port)
setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof yes);
server_address.sin_family = AF_INET;
- server_address.sin_addr.s_addr = ip;
+ server_address.sin_addr = in_addr(ip);
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wold-style-cast"
#if __GNUC__ > 4 || __GNUC_MINOR__ >= 8
diff --git a/src/common/socket.hpp b/src/common/socket.hpp
index dd1c872..91a8c49 100644
--- a/src/common/socket.hpp
+++ b/src/common/socket.hpp
@@ -10,6 +10,7 @@
# include <array>
# include "dumb_ptr.hpp"
+# include "ip.hpp"
# include "utils.hpp"
# include "timer.t.hpp"
@@ -43,7 +44,7 @@ struct socket_data
/// Note that there is no need for a wdata_pos
size_t rdata_pos;
- struct sockaddr_in client_addr;
+ IP4Address client_ip;
/// Send or recieve
/// Only called when select() indicates the socket is ready
@@ -78,7 +79,7 @@ extern int fd_max;
int make_listen_port(uint16_t port);
/// Connect to an address, return a connected socket or -1
// FIXME - this is IPv4 only!
-int make_connection(uint32_t ip, uint16_t port);
+int make_connection(IP4Address ip, uint16_t port);
/// free() the structure and close() the fd
void delete_session(int);
/// Make a the internal queues bigger
@@ -143,6 +144,13 @@ void RFIFO_STRUCT(int fd, size_t pos, T& structure)
{
really_memcpy(pod_addressof_m(structure), static_cast<const uint8_t *>(RFIFOP(fd, pos)), sizeof(T));
}
+inline
+IP4Address RFIFOIP(int fd, size_t pos)
+{
+ IP4Address o;
+ RFIFO_STRUCT(fd, pos, o);
+ return o;
+}
template<uint8_t len>
inline
VString<len-1> RFIFO_STRING(int fd, size_t pos)
@@ -195,6 +203,13 @@ void RBUF_STRUCT(const uint8_t *p, size_t pos, T& structure)
{
really_memcpy(pod_addressof_m(structure), p + pos, sizeof(T));
}
+inline
+IP4Address RBUFIP(const uint8_t *p, size_t pos)
+{
+ IP4Address o;
+ RBUF_STRUCT(p, pos, o);
+ return o;
+}
template<uint8_t len>
inline
VString<len-1> RBUF_STRING(const uint8_t *p, size_t pos)
@@ -248,6 +263,12 @@ void WFIFO_STRUCT(int fd, size_t pos, T& structure)
really_memcpy(static_cast<uint8_t *>(WFIFOP(fd, pos)), pod_addressof_c(structure), sizeof(T));
}
inline
+IP4Address& WFIFOIP(int fd, size_t pos)
+{
+ static_assert(is_trivially_copyable<IP4Address>::value, "That was the whole point");
+ return *static_cast<IP4Address *>(WFIFOP(fd, pos));
+}
+inline
void WFIFO_STRING(int fd, size_t pos, XString s, size_t len)
{
char *const begin = static_cast<char *>(WFIFOP(fd, pos));
@@ -298,6 +319,11 @@ void WBUF_STRUCT(uint8_t *p, size_t pos, T& structure)
really_memcpy(p + pos, pod_addressof_c(structure), sizeof(T));
}
inline
+IP4Address& WBUFIP(uint8_t *p, size_t pos)
+{
+ return *static_cast<IP4Address *>(WBUFP(p, pos));
+}
+inline
void WBUF_STRING(uint8_t *p, size_t pos, XString s, size_t len)
{
char *const begin = static_cast<char *>(WBUFP(p, pos));
diff --git a/src/common/utils.cpp b/src/common/utils.cpp
index c9c22b9..9ab470b 100644
--- a/src/common/utils.cpp
+++ b/src/common/utils.cpp
@@ -44,11 +44,11 @@ bool e_mail_check(XString email)
//-------------------------------------------------
int config_switch (ZString str)
{
- if (str == "on" || str == "yes"
+ if (str == "true" || str == "on" || str == "yes"
|| str == "oui" || str == "ja"
|| str == "si")
return 1;
- if (str == "off" || str == "no"
+ if (str == "false" || str == "off" || str == "no"
|| str == "non" || str == "nein")
return 0;
@@ -59,22 +59,6 @@ int config_switch (ZString str)
abort();
}
-IP_String ip2str(struct in_addr ip)
-{
- const uint8_t *p = reinterpret_cast<const uint8_t *>(&ip);
-
- IP_String out;
- SNPRINTF(out, 16, "%d.%d.%d.%d", p[0], p[1], p[2], p[3]);
- return out;
-}
-VString<16> ip2str_extradot(struct in_addr ip)
-{
- const uint8_t *p = reinterpret_cast<const uint8_t *>(&ip);
- VString<16> out;
- SNPRINTF(out, 17, "%d.%d.%d.%d.", p[0], p[1], p[2], p[3]);
- return out;
-}
-
bool split_key_value(const FString& line, SString *w1, TString *w2)
{
FString::iterator begin = line.begin(), end = line.end();
diff --git a/src/common/utils.hpp b/src/common/utils.hpp
index 196bb3e..4f6190a 100644
--- a/src/common/utils.hpp
+++ b/src/common/utils.hpp
@@ -13,8 +13,6 @@
#include "strings.hpp"
#include "utils2.hpp"
-struct IP_String : VString<15> {};
-
template<class T>
struct is_trivially_copyable
: std::integral_constant<bool,
@@ -26,8 +24,6 @@ struct is_trivially_copyable
bool e_mail_check(XString email);
int config_switch (ZString str);
-IP_String ip2str(struct in_addr ip);
-VString<15 + 1> ip2str_extradot(struct in_addr ip);
bool split_key_value(const FString& line, SString *w1, TString *w2);
diff --git a/src/ladmin/ladmin.cpp b/src/ladmin/ladmin.cpp
index 12d9390..e0860b2 100644
--- a/src/ladmin/ladmin.cpp
+++ b/src/ladmin/ladmin.cpp
@@ -36,11 +36,11 @@ int eathena_interactive_session;
// (see login_athena.conf, 'admin_state' parameter)
//-------------------------------------------------------------------------
static
-IP_String loginserverip = stringish<IP_String>("127.0.0.1"); // IP of login-server
+IP4Address login_ip = IP4_LOCALHOST; // IP of login-server
static
-int loginserverport = 6900; // Port of login-server
+int login_port = 6900; // Port of login-server
static
-AccountPass loginserveradminpassword = stringish<AccountPass>("admin"); // Administration password
+AccountPass admin_pass = stringish<AccountPass>("admin"); // Administration password
static
FString ladmin_log_filename = "log/ladmin.log";
//-------------------------------------------------------------------------
@@ -226,8 +226,6 @@ FString ladmin_log_filename = "log/ladmin.log";
static
int login_fd;
static
-int login_ip;
-static
int bytes_to_read = 0; // flag to know if we waiting bytes from login-server
static
TString parameters; // needs to be global since it's passed to the parse function
@@ -1903,9 +1901,9 @@ void parse_fromlogin(int fd)
if (session[fd]->eof)
{
PRINTF("Impossible to have a connection with the login-server [%s:%d] !\n",
- loginserverip, loginserverport);
+ login_ip, login_port);
LADMIN_LOG("Impossible to have a connection with the login-server [%s:%d] !\n",
- loginserverip, loginserverport);
+ login_ip, login_port);
delete_session(fd);
exit(0);
}
@@ -1945,8 +1943,8 @@ void parse_fromlogin(int fd)
if (RFIFOREST(fd) < 10)
return;
{
- Iprintf(" Login-Server [%s:%d]\n", loginserverip,
- loginserverport);
+ Iprintf(" Login-Server [%s:%d]\n",
+ login_ip, login_port);
Version version;
RFIFO_STRUCT(login_fd, 2, version);
Iprintf(" tmwA version %hhu.%hhu.%hhu (dev? %hhu) (flags %hhx) (which %hhx) (vend %hu)\n",
@@ -2608,7 +2606,7 @@ void parse_fromlogin(int fd)
int state = RFIFOL(fd, 36);
timestamp_seconds_buffer error_message = stringish<timestamp_seconds_buffer>(RFIFO_STRING<20>(fd, 40));
timestamp_milliseconds_buffer lastlogin = stringish<timestamp_milliseconds_buffer>(RFIFO_STRING<24>(fd, 60));
- IP_String last_ip = stringish<IP_String>(RFIFO_STRING<16>(fd, 84));
+ VString<15> last_ip_ = RFIFO_STRING<16>(fd, 84);
AccountEmail email = stringish<AccountEmail>(RFIFO_STRING<40>(fd, 100));
TimeT connect_until_time = static_cast<time_t>(RFIFOL(fd, 140));
TimeT ban_until_time = static_cast<time_t>(RFIFOL(fd, 144));
@@ -2703,7 +2701,7 @@ void parse_fromlogin(int fd)
PRINTF(" Count: %d connection.\n",
connections);
PRINTF(" Last connection at: %s (ip: %s)\n",
- lastlogin, last_ip);
+ lastlogin, last_ip_);
if (!connect_until_time)
{
PRINTF(" Validity limit: unlimited.\n");
@@ -2743,13 +2741,13 @@ int Connect_login_server(void)
Iprintf("Attempt to connect to login-server...\n");
LADMIN_LOG("Attempt to connect to login-server...\n");
- if ((login_fd = make_connection(login_ip, loginserverport)) < 0)
+ if ((login_fd = make_connection(login_ip, login_port)) < 0)
return 0;
{
WFIFOW(login_fd, 0) = 0x7918; // Request for administation login
WFIFOW(login_fd, 2) = 0; // no encrypted
- WFIFO_STRING(login_fd, 4, loginserveradminpassword, 24);
+ WFIFO_STRING(login_fd, 4, admin_pass, 24);
WFIFOSET(login_fd, 28);
bytes_to_read = 1;
@@ -2788,28 +2786,23 @@ int ladmin_config_read(ZString cfgName)
struct hostent *h = gethostbyname(w2.c_str());
if (h != NULL)
{
- Iprintf("Login server IP address: %s -> %d.%d.%d.%d\n",
- w2,
+ Iprintf("Login server IP address: %s -> %s\n",
+ w2, login_ip);
+ login_ip = IP4Address({
static_cast<uint8_t>(h->h_addr[0]),
static_cast<uint8_t>(h->h_addr[1]),
static_cast<uint8_t>(h->h_addr[2]),
- static_cast<uint8_t>(h->h_addr[3]));
- SNPRINTF(loginserverip, 16, "%d.%d.%d.%d",
- static_cast<uint8_t>(h->h_addr[0]),
- static_cast<uint8_t>(h->h_addr[1]),
- static_cast<uint8_t>(h->h_addr[2]),
- static_cast<uint8_t>(h->h_addr[3]));
+ static_cast<uint8_t>(h->h_addr[3]),
+ });
}
- else
- loginserverip = stringish<IP_String>(w2);
}
else if (w1 == "login_port")
{
- loginserverport = atoi(w2.c_str());
+ login_port = atoi(w2.c_str());
}
else if (w1 == "admin_pass")
{
- loginserveradminpassword = stringish<AccountPass>(w2);
+ admin_pass = stringish<AccountPass>(w2);
}
else if (w1 == "ladmin_log_filename")
{
@@ -2825,8 +2818,6 @@ int ladmin_config_read(ZString cfgName)
}
}
- login_ip = inet_addr(loginserverip.c_str());
-
Iprintf("---End reading of Ladmin configuration file.\n");
return 0;
diff --git a/src/login/login.cpp b/src/login/login.cpp
index b0b3137..8d79158 100644
--- a/src/login/login.cpp
+++ b/src/login/login.cpp
@@ -56,11 +56,9 @@ struct mmo_account
struct mmo_char_server
{
ServerName name;
- long ip;
- short port;
- int users;
- int maintenance;
- int is_new;
+ IP4Address ip;
+ uint16_t port;
+ uint16_t users;
};
static
@@ -68,15 +66,13 @@ int account_id_count = START_ACCOUNT_NUM;
static
int server_num;
static
-int new_account_flag = 0;
+int new_account = 0;
static
int login_port = 6900;
static
-IP_String lan_char_ip;
+IP4Address lan_char_ip;
static
-uint8_t subneti[4];
-static
-uint8_t subnetmaski[4];
+IP4Mask lan_subnet;
static
FString update_host;
static
@@ -85,7 +81,7 @@ ServerName main_server;
static
FString account_filename = "save/account.txt";
static
-FString GM_account_filename = "conf/GM_account.txt";
+FString gm_account_filename = "conf/GM_account.txt";
static
FString login_log_filename = "log/login.log";
static
@@ -113,7 +109,7 @@ int server_freezeflag[MAX_SERVERS]; // Char-server anti-freeze system. Counte
static
int anti_freeze_enable = 0;
static
-std::chrono::seconds ANTI_FREEZE_INTERVAL = std::chrono::seconds(15);
+std::chrono::seconds anti_freeze_interval = std::chrono::seconds(15);
static
int login_fd;
@@ -122,16 +118,13 @@ enum class ACO
{
DENY_ALLOW,
ALLOW_DENY,
- MUTUAL_FAILTURE,
+ MUTUAL_FAILURE,
};
-// TODO: port the new code for this
-struct AccessEntry : VString<127> {};
-
static
ACO access_order = ACO::DENY_ALLOW;
static
-std::vector<AccessEntry>
+std::vector<IP4Mask>
access_allow, access_deny, access_ladmin;
static
@@ -155,7 +148,8 @@ constexpr int AUTH_FIFO_SIZE = 256;
struct
{
int account_id, login_id1, login_id2;
- int ip, sex, delflag;
+ IP4Address ip;
+ int sex, delflag;
} auth_fifo[AUTH_FIFO_SIZE];
static
int auth_fifo_pos = 0;
@@ -172,7 +166,7 @@ struct AuthData
timestamp_seconds_buffer error_message; // Message of error code #6 = Your are Prohibited to log in until %s (packet 0x006a)
TimeT ban_until_time; // # of seconds 1/1/1970 (timestamp): ban time limit of the account (0 = no ban)
TimeT connect_until_time; // # of seconds 1/1/1970 (timestamp): Validity limit of the account (0 = unlimited)
- IP_String last_ip; // save of last IP of connection
+ IP4Address last_ip; // save of last IP of connection
VString<254> memo; // a memo field
int account_reg2_num;
struct global_reg account_reg2[ACCOUNT_REG2_NUM];
@@ -250,15 +244,15 @@ int read_gm_account(void)
gm_account_db.clear();
- creation_time_GM_account_file = file_modified(GM_account_filename);
+ creation_time_GM_account_file = file_modified(gm_account_filename);
- if ((fp = fopen(GM_account_filename.c_str(), "r")) == NULL)
+ if ((fp = fopen(gm_account_filename.c_str(), "r")) == NULL)
{
PRINTF("read_gm_account: GM accounts file [%s] not found.\n",
- GM_account_filename);
+ gm_account_filename);
PRINTF(" Actually, there is no GM accounts on the server.\n");
LOGIN_LOG("read_gm_account: GM accounts file [%s] not found.\n",
- GM_account_filename);
+ gm_account_filename);
LOGIN_LOG(" Actually, there is no GM accounts on the server.\n");
return 1;
}
@@ -272,16 +266,16 @@ int read_gm_account(void)
if (sscanf(line, "%d %hhu", &p.account_id, &p.level) != 2
&& sscanf(line, "%d: %hhu", &p.account_id, &p.level) != 2)
PRINTF("read_gm_account: file [%s], invalid 'id_acount level' format.\n",
- GM_account_filename);
+ gm_account_filename);
else if (p.level <= 0)
PRINTF("read_gm_account: file [%s] %dth account (invalid level [0 or negative]: %d).\n",
- GM_account_filename, c + 1, p.level);
+ gm_account_filename, c + 1, p.level);
else
{
if (p.level > 99)
{
PRINTF("read_gm_account: file [%s] %dth account (invalid level, but corrected: %d->99).\n",
- GM_account_filename, c + 1, p.level);
+ gm_account_filename, c + 1, p.level);
p.level = 99;
}
if ((GM_level = isGM(p.account_id)) > 0)
@@ -312,57 +306,18 @@ int read_gm_account(void)
fclose(fp);
PRINTF("read_gm_account: file '%s' readed (%d GM accounts found).\n",
- GM_account_filename, c);
+ gm_account_filename, c);
LOGIN_LOG("read_gm_account: file '%s' readed (%d GM accounts found).\n",
- GM_account_filename, c);
+ gm_account_filename, c);
return 0;
}
-//--------------------------------------------------------------
-// Test of the IP mask
-// (ip: IP to be tested, str: mask x.x.x.x/# or x.x.x.x/y.y.y.y)
-//--------------------------------------------------------------
-static
-int check_ipmask(struct in_addr ip, ZString str)
-{
- unsigned int mask = 0, ip2;
- uint8_t *p = reinterpret_cast<uint8_t *>(&ip2),
- *p2 = reinterpret_cast<uint8_t *>(&mask);
- int i = 0;
- unsigned int m;
-
- if (SSCANF(str, "%hhu.%hhu.%hhu.%hhu/%n",
- &p[0], &p[1], &p[2], &p[3], &i) != 4
- || i == 0)
- return 0;
-
- if (SSCANF(str.oslice_t(i), "%hhu.%hhu.%hhu.%hhu",
- &p2[0], &p2[1], &p2[2], &p2[3]) == 4)
- {
- mask = ntohl(mask);
- }
- else if (SSCANF(str.oslice_t(i), "%u", &m) == 1 && m <= 32)
- {
- for (i = 0; i < m && i < 32; i++)
- mask = (mask >> 1) | 0x80000000;
- }
- else
- {
- PRINTF("check_ipmask: invalid mask [%s].\n", str);
- return 0;
- }
-
-// PRINTF("Tested IP: %08x, network: %08x, network mask: %08x\n",
-// (unsigned int)ntohl(ip), (unsigned int)ntohl(ip2), (unsigned int)mask);
- return ((ntohl(ip.s_addr) & mask) == (ntohl(ip2) & mask));
-}
-
//---------------------
// Access control by IP
//---------------------
static
-bool check_ip(struct in_addr ip)
+bool check_ip(IP4Address ip)
{
enum class ACF
{
@@ -376,33 +331,26 @@ bool check_ip(struct in_addr ip)
return 1;
// When there is no restriction, all IP are authorised.
-// + 012.345.: front match form, or
-// all: all IP are matched, or
-// 012.345.678.901/24: network form (mask with # of bits), or
-// 012.345.678.901/255.255.255.0: network form (mask with ip mask)
-// + Note about the DNS resolution (like www.ne.jp, etc.):
-// There is no guarantee to have an answer.
-// If we have an answer, there is no guarantee to have a 100% correct value.
-// And, the waiting time (to check) can be long (over 1 minute to a timeout). That can block the software.
-// So, DNS notation isn't authorised for ip checking.
- VString<16> buf = ip2str_extradot(ip);
-
- for (const AccessEntry& ae : access_allow)
+ if (std::find_if(access_allow.begin(), access_allow.end(),
+ [&ip](IP4Mask m)
+ {
+ return m.covers(ip);
+ }) != access_allow.end())
{
-#warning "TODO use an IPAddress4 and IPMask4 class"
- if (buf.startswith(ae) || check_ipmask(ip, ae))
{
flag = ACF::ALLOW;
if (access_order == ACO::ALLOW_DENY)
// With 'allow, deny' (deny if not allow), allow has priority
return 1;
- break;
}
}
- for (const AccessEntry& ae : access_deny)
+ if (std::find_if(access_deny.begin(), access_deny.end(),
+ [&ip](IP4Mask m)
+ {
+ return m.covers(ip);
+ }) != access_deny.end())
{
- if (buf.startswith(ae) || check_ipmask(ip, ae))
{
flag = ACF::DENY;
return 0;
@@ -421,30 +369,17 @@ bool check_ip(struct in_addr ip)
// Access control by IP for ladmin
//--------------------------------
static
-bool check_ladminip(struct in_addr ip)
+bool check_ladminip(IP4Address ip)
{
if (access_ladmin.empty())
// When there is no restriction, all IP are authorised.
return true;
-// + 012.345.: front match form, or
-// all: all IP are matched, or
-// 012.345.678.901/24: network form (mask with # of bits), or
-// 012.345.678.901/255.255.255.0: network form (mask with ip mask)
-// + Note about the DNS resolution (like www.ne.jp, etc.):
-// There is no guarantee to have an answer.
-// If we have an answer, there is no guarantee to have a 100% correct value.
-// And, the waiting time (to check) can be long (over 1 minute to a timeout). That can block the software.
-// So, DNS notation isn't authorised for ip checking.
- VString<16> buf = ip2str_extradot(ip);
-
- for (const AccessEntry& ae : access_ladmin)
- {
- if (buf.startswith(ae) || check_ipmask(ip, ae))
- return true;
- }
-
- return false;
+ return std::find_if(access_ladmin.begin(), access_ladmin.end(),
+ [&ip](IP4Mask m)
+ {
+ return m.covers(ip);
+ }) != access_ladmin.end();
}
//-----------------------------------------------
@@ -513,6 +448,7 @@ bool extract(XString line, AuthData *ad)
{
std::vector<struct global_reg> vars;
VString<1> sex;
+ VString<15> ip;
if (!extract(line,
record<'\t'>(
&ad->account_id,
@@ -525,11 +461,14 @@ bool extract(XString line, AuthData *ad)
&ad->email,
&ad->error_message,
&ad->connect_until_time,
- &ad->last_ip,
+ &ip,
&ad->memo,
&ad->ban_until_time,
vrec<' '>(&vars))))
return false;
+ ad->last_ip = IP4Address();
+ if (ip != "-" && !extract(ip, &ad->last_ip))
+ return false;
if (ad->account_id > END_ACCOUNT_NUM)
return false;
for (const AuthData& adi : auth_data)
@@ -767,7 +706,7 @@ void check_GM_file(TimerData *, tick_t)
return;
// get last modify time/date
- tick_t new_time = file_modified(GM_account_filename);
+ tick_t new_time = file_modified(gm_account_filename);
if (new_time != creation_time_GM_account_file)
{
@@ -814,7 +753,7 @@ int mmo_auth_new(struct mmo_account *account, char sex, AccountEmail email)
ad.connect_until_time = timestamp;
}
- ad.last_ip = stringish<IP_String>("-");
+ ad.last_ip = IP4Address();
ad.memo = "!";
ad.account_reg2_num = 0;
auth_data.push_back(ad);
@@ -830,12 +769,12 @@ int mmo_auth(struct mmo_account *account, int fd)
{
char new_account_sex = '\0';
- IP_String ip = ip2str(session[fd]->client_addr.sin_addr);
+ IP4Address ip = session[fd]->client_ip;
// Account creation with _M/_F
if (account->passwdenc == 0
&& (account->userid.endswith("_F") || account->userid.endswith("_M"))
- && new_account_flag == 1 && account_id_count <= END_ACCOUNT_NUM
+ && new_account == 1 && account_id_count <= END_ACCOUNT_NUM
&& (account->userid.size() - 2) >= 4 && account->passwd.size() >= 4)
{
new_account_sex = account->userid.back();
@@ -983,7 +922,7 @@ void char_anti_freeze_system(TimerData *, tick_t)
static
void parse_fromchar(int fd)
{
- IP_String ip = ip2str(session[fd]->client_addr.sin_addr);
+ IP4Address ip = session[fd]->client_ip;
int id;
for (id = 0; id < MAX_SERVERS; id++)
@@ -1034,7 +973,7 @@ void parse_fromchar(int fd)
auth_fifo[i].login_id2 == RFIFOL(fd, 10) && // relate to the versions higher than 18
auth_fifo[i].sex == RFIFOB(fd, 14) &&
(!check_ip_flag
- || auth_fifo[i].ip == RFIFOL(fd, 15))
+ || auth_fifo[i].ip == RFIFOIP(fd, 15))
&& !auth_fifo[i].delflag)
{
int p;
@@ -1179,7 +1118,7 @@ void parse_fromchar(int fd)
if (level_new_gm > 0)
{
// if we can open the file to add the new GM
- if ((fp = fopen(GM_account_filename.c_str(), "a")) != NULL)
+ if ((fp = fopen(gm_account_filename.c_str(), "a")) != NULL)
{
timestamp_seconds_buffer tmpstr;
stamp_time(tmpstr);
@@ -1632,7 +1571,7 @@ void parse_fromchar(int fd)
static
void parse_admin(int fd)
{
- IP_String ip = ip2str(session[fd]->client_addr.sin_addr);
+ IP4Address ip = session[fd]->client_ip;
if (session[fd]->eof)
{
@@ -1911,12 +1850,12 @@ void parse_admin(int fd)
{
if (server_fd[i] >= 0)
{
- WFIFOL(fd, 4 + server_num * 32) = server[i].ip;
+ WFIFOIP(fd, 4 + server_num * 32) = server[i].ip;
WFIFOW(fd, 4 + server_num * 32 + 4) = server[i].port;
WFIFO_STRING(fd, 4 + server_num * 32 + 6, server[i].name, 20);
WFIFOW(fd, 4 + server_num * 32 + 26) = server[i].users;
- WFIFOW(fd, 4 + server_num * 32 + 28) = server[i].maintenance;
- WFIFOW(fd, 4 + server_num * 32 + 30) = server[i].is_new;
+ WFIFOW(fd, 4 + server_num * 32 + 28) = 0; //maintenance;
+ WFIFOW(fd, 4 + server_num * 32 + 30) = 0; //is_new;
server_num++;
}
}
@@ -2057,9 +1996,9 @@ void parse_admin(int fd)
char line[512];
int GM_account, GM_level;
int modify_flag;
- if ((fp2 = lock_fopen(GM_account_filename, &lock)) != NULL)
+ if ((fp2 = lock_fopen(gm_account_filename, &lock)) != NULL)
{
- if ((fp = fopen(GM_account_filename.c_str(), "r")) != NULL)
+ if ((fp = fopen(gm_account_filename.c_str(), "r")) != NULL)
{
timestamp_seconds_buffer tmpstr;
stamp_time(tmpstr);
@@ -2129,7 +2068,7 @@ void parse_admin(int fd)
ad->userid, acc,
new_gm_level, ip);
}
- lock_fclose(fp2, GM_account_filename, &lock);
+ lock_fclose(fp2, gm_account_filename, &lock);
WFIFOL(fd, 2) = acc;
LOGIN_LOG("'ladmin': Modification of a GM level (account: %s (%d), new GM level: %d, ip: %s)\n",
ad->userid, acc,
@@ -2540,7 +2479,7 @@ void parse_admin(int fd)
else
{
TimeT now = TimeT::now();
- TimeT timestamp;
+ TimeT timestamp = ad->connect_until_time;
if (!timestamp || timestamp < now)
timestamp = now;
struct tm tmtime = timestamp;
@@ -2627,7 +2566,7 @@ void parse_admin(int fd)
WFIFOL(fd, 36) = ad->state;
WFIFO_STRING(fd, 40, ad->error_message, 20);
WFIFO_STRING(fd, 60, ad->lastlogin, 24);
- WFIFO_STRING(fd, 84, ad->last_ip, 16);
+ WFIFO_STRING(fd, 84, convert_for_printf(ad->last_ip), 16);
WFIFO_STRING(fd, 100, ad->email, 40);
WFIFOL(fd, 140) = static_cast<time_t>(ad->connect_until_time);
WFIFOL(fd, 144) = static_cast<time_t>(ad->ban_until_time);
@@ -2670,7 +2609,7 @@ void parse_admin(int fd)
WFIFOL(fd, 36) = ad.state;
WFIFO_STRING(fd, 40, ad.error_message, 20);
WFIFO_STRING(fd, 60, ad.lastlogin, 24);
- WFIFO_STRING(fd, 84, ad.last_ip, 16);
+ WFIFO_STRING(fd, 84, convert_for_printf(ad.last_ip), 16);
WFIFO_STRING(fd, 100, ad.email, 40);
WFIFOL(fd, 140) = static_cast<time_t>(ad.connect_until_time);
WFIFOL(fd, 144) = static_cast<time_t>(ad.ban_until_time);
@@ -2765,25 +2704,11 @@ void parse_admin(int fd)
//--------------------------------------------
// Test to know if an IP come from LAN or WAN.
//--------------------------------------------
-// TODO fix to not take a ptr-to-uint8_t
static
-int lan_ip_check(unsigned char *p)
+bool lan_ip_check(IP4Address p)
{
- int i;
- int lancheck = 1;
+ bool lancheck = lan_subnet.covers(p);
-// PRINTF("lan_ip_check: to compare: %d.%d.%d.%d, network: %d.%d.%d.%d/%d.%d.%d.%d\n",
-// p[0], p[1], p[2], p[3],
-// subneti[0], subneti[1], subneti[2], subneti[3],
-// subnetmaski[0], subnetmaski[1], subnetmaski[2], subnetmaski[3]);
- for (i = 0; i < 4; i++)
- {
- if ((subneti[i] & subnetmaski[i]) != (p[i] & subnetmaski[i]))
- {
- lancheck = 0;
- break;
- }
- }
PRINTF("LAN test (result): %s source\033[0m.\n",
(lancheck) ? "\033[1;36mLAN" : "\033[1;32mWAN");
return lancheck;
@@ -2797,9 +2722,8 @@ void parse_login(int fd)
{
struct mmo_account account;
int result, j;
- uint8_t *p = reinterpret_cast<uint8_t *>(&session[fd]->client_addr.sin_addr);
- IP_String ip = ip2str(session[fd]->client_addr.sin_addr);
+ IP4Address ip = session[fd]->client_ip;
if (session[fd]->eof)
{
@@ -2861,7 +2785,7 @@ void parse_login(int fd)
LOGIN_LOG("Request for connection (non encryption mode) of %s (ip: %s).\n",
account.userid, ip);
- if (!check_ip(session[fd]->client_addr.sin_addr))
+ if (!check_ip(ip))
{
LOGIN_LOG("Connection refused: IP isn't authorised (deny/allow, ip: %s).\n",
ip);
@@ -2934,15 +2858,15 @@ void parse_login(int fd)
{
if (server_fd[i] >= 0)
{
- if (lan_ip_check(p))
- WFIFOL(fd, 47 + server_num * 32) = inet_addr(lan_char_ip.c_str());
+ if (lan_ip_check(ip))
+ WFIFOIP(fd, 47 + server_num * 32) = lan_char_ip;
else
- WFIFOL(fd, 47 + server_num * 32) = server[i].ip;
+ WFIFOIP(fd, 47 + server_num * 32) = server[i].ip;
WFIFOW(fd, 47 + server_num * 32 + 4) = server[i].port;
WFIFO_STRING(fd, 47 + server_num * 32 + 6, server[i].name, 20);
WFIFOW(fd, 47 + server_num * 32 + 26) = server[i].users;
- WFIFOW(fd, 47 + server_num * 32 + 28) = server[i].maintenance;
- WFIFOW(fd, 47 + server_num * 32 + 30) = server[i].is_new;
+ WFIFOW(fd, 47 + server_num * 32 + 28) = 0; //maintenance;
+ WFIFOW(fd, 47 + server_num * 32 + 30) = 0; //is_new;
server_num++;
}
}
@@ -2969,7 +2893,7 @@ void parse_login(int fd)
auth_fifo[auth_fifo_pos].sex = account.sex;
auth_fifo[auth_fifo_pos].delflag = 0;
auth_fifo[auth_fifo_pos].ip =
- session[fd]->client_addr.sin_addr.s_addr;
+ session[fd]->client_ip;
auth_fifo_pos++;
// if no char-server, don't send void list of servers, just disconnect the player with proper message
}
@@ -3021,10 +2945,8 @@ void parse_login(int fd)
account.passwd = stringish<AccountPass>(RFIFO_STRING<24>(fd, 26).to_print());
account.passwdenc = 0;
ServerName server_name = stringish<ServerName>(RFIFO_STRING<20>(fd, 60).to_print());
- LOGIN_LOG("Connection request of the char-server '%s' @ %d.%d.%d.%d:%d (ip: %s)\n",
- server_name, RFIFOB(fd, 54), RFIFOB(fd, 55),
- RFIFOB(fd, 56), RFIFOB(fd, 57), RFIFOW(fd, 58),
- ip);
+ LOGIN_LOG("Connection request of the char-server '%s' @ %s:%d (ip: %s)\n",
+ server_name, RFIFOIP(fd, 54), RFIFOW(fd, 58), ip);
result = mmo_auth(&account, fd);
if (result == -1 && account.sex == 2)
@@ -3059,12 +2981,12 @@ void parse_login(int fd)
PRINTF("Connection of the char-server '%s' accepted.\n",
server_name);
server[account.account_id] = mmo_char_server{};
- server[account.account_id].ip = RFIFOL(fd, 54);
+ server[account.account_id].ip = RFIFOIP(fd, 54);
server[account.account_id].port = RFIFOW(fd, 58);
server[account.account_id].name = server_name;
server[account.account_id].users = 0;
- server[account.account_id].maintenance = RFIFOW(fd, 82);
- server[account.account_id].is_new = RFIFOW(fd, 84);
+ //maintenance = RFIFOW(fd, 82);
+ //is_new = RFIFOW(fd, 84);
server_fd[account.account_id] = fd;
if (anti_freeze_enable)
server_freezeflag[account.account_id] = 5; // Char-server anti-freeze system. Counter. 5 ok, 4...0 freezed
@@ -3106,7 +3028,7 @@ void parse_login(int fd)
WFIFOW(fd, 0) = 0x7531;
{
Version version = CURRENT_LOGIN_SERVER_VERSION;
- version.flags = new_account_flag ? 1 : 0;
+ version.flags = new_account ? 1 : 0;
WFIFO_STRUCT(fd, 2, version);
WFIFOSET(fd, 10);
}
@@ -3124,7 +3046,7 @@ void parse_login(int fd)
return;
WFIFOW(fd, 0) = 0x7919;
WFIFOB(fd, 2) = 1;
- if (!check_ladminip(session[fd]->client_addr.sin_addr))
+ if (!check_ladminip(session[fd]->client_ip))
{
LOGIN_LOG("'ladmin'-login: Connection in administration mode refused: IP isn't authorised (ladmin_allow, ip: %s).\n",
ip);
@@ -3235,13 +3157,8 @@ int login_lan_config_read(ZString lancfgName)
struct hostent *h = NULL;
// set default configuration
- lan_char_ip = stringish<IP_String>("127.0.0.1");
- subneti[0] = 127;
- subneti[1] = 0;
- subneti[2] = 0;
- subneti[3] = 1;
- for (int j = 0; j < 4; j++)
- subnetmaski[j] = 255;
+ lan_char_ip = IP4_LOCALHOST;
+ lan_subnet = IP4Mask(IP4_LOCALHOST, IP4_BROADCAST);
std::ifstream in(lancfgName.c_str());
@@ -3268,55 +3185,30 @@ int login_lan_config_read(ZString lancfgName)
h = gethostbyname(w2.c_str());
if (h != NULL)
{
- SNPRINTF(lan_char_ip, 16, "%d.%d.%d.%d",
- static_cast<uint8_t>(h->h_addr[0]),
- static_cast<uint8_t>(h->h_addr[1]),
- static_cast<uint8_t>(h->h_addr[2]),
- static_cast<uint8_t>(h->h_addr[3]));
+ lan_char_ip = IP4Address({
+ static_cast<uint8_t>(h->h_addr[0]),
+ static_cast<uint8_t>(h->h_addr[1]),
+ static_cast<uint8_t>(h->h_addr[2]),
+ static_cast<uint8_t>(h->h_addr[3]),
+ });
}
else
{
- lan_char_ip = stringish<IP_String>(w2);
+ PRINTF("Bad IP value: %s\n", line);
+ abort();
}
PRINTF("LAN IP of char-server: %s.\n", lan_char_ip);
}
- else if (w1 == "subnet")
+ else if (w1 == "subnet" /*backward compatibility*/
+ || w1 == "lan_subnet")
{
- // Read Subnetwork
- for (int j = 0; j < 4; j++)
- subneti[j] = 0;
- h = gethostbyname(w2.c_str());
- if (h != NULL)
- {
- for (int j = 0; j < 4; j++)
- subneti[j] = h->h_addr[j];
- }
- else
+ if (!extract(w2, &lan_subnet))
{
- SSCANF(w2, "%hhu.%hhu.%hhu.%hhu", &subneti[0], &subneti[1],
- &subneti[2], &subneti[3]);
+ PRINTF("Bad IP mask: %s\n", line);
+ abort();
}
- PRINTF("Sub-network of the char-server: %d.%d.%d.%d.\n",
- subneti[0], subneti[1], subneti[2], subneti[3]);
- }
- else if (w1 == "subnetmask")
- { // Read Subnetwork Mask
- for (int j = 0; j < 4; j++)
- subnetmaski[j] = 255;
- h = gethostbyname(w2.c_str());
- if (h != NULL)
- {
- for (int j = 0; j < 4; j++)
- subnetmaski[j] = h->h_addr[j];
- }
- else
- {
- SSCANF(w2, "%hhu.%hhu.%hhu.%hhu", &subnetmaski[0], &subnetmaski[1],
- &subnetmaski[2], &subnetmaski[3]);
- }
- PRINTF("Sub-network mask of the char-server: %d.%d.%d.%d.\n",
- subnetmaski[0], subnetmaski[1], subnetmaski[2],
- subnetmaski[3]);
+ PRINTF("Sub-network of the char-server: %s.\n",
+ lan_subnet);
}
else
{
@@ -3328,17 +3220,13 @@ int login_lan_config_read(ZString lancfgName)
// log the LAN configuration
LOGIN_LOG("The LAN configuration of the server is set:\n");
LOGIN_LOG("- with LAN IP of char-server: %s.\n", lan_char_ip);
- LOGIN_LOG("- with the sub-network of the char-server: %d.%d.%d.%d/%d.%d.%d.%d.\n",
- subneti[0], subneti[1], subneti[2], subneti[3],
- subnetmaski[0], subnetmaski[1], subnetmaski[2], subnetmaski[3]);
+ LOGIN_LOG("- with the sub-network of the char-server: %s.\n",
+ lan_subnet);
// sub-network check of the char-server
{
- unsigned char p[4];
- SSCANF(lan_char_ip, "%hhu.%hhu.%hhu.%hhu",
- &p[0], &p[1], &p[2], &p[3]);
PRINTF("LAN test of LAN IP of the char-server: ");
- if (lan_ip_check(p) == 0)
+ if (!lan_ip_check(lan_char_ip))
{
PRINTF("\033[1;31m***ERROR: LAN IP of the char-server doesn't belong to the specified Sub-network\033[0m\n");
LOGIN_LOG("***ERROR: LAN IP of the char-server doesn't belong to the specified Sub-network.\n");
@@ -3389,19 +3277,25 @@ int login_config_read(ZString cfgName)
}
else
{
+ // a.b.c.d/0.0.0.0 (canonically, 0.0.0.0/0) covers all
if (w2 == "all")
{
// reset all previous values
access_ladmin.clear();
// set to all
- access_ladmin.push_back(AccessEntry());
+ access_ladmin.push_back(IP4Mask());
}
else if (w2
- && !(access_ladmin.size() == 1
- && access_ladmin.front() == AccessEntry()))
+ && !(access_ladmin.size() == 1
+ && access_ladmin.front().mask() == IP4Address()))
{
// don't add IP if already 'all'
- AccessEntry n = stringish<AccessEntry>(w2);
+ IP4Mask n;
+ if (!extract(w2, &n))
+ {
+ PRINTF("Bad IP mask: %s\n", line);
+ abort();
+ }
access_ladmin.push_back(n);
}
}
@@ -3416,7 +3310,7 @@ int login_config_read(ZString cfgName)
}
else if (w1 == "new_account")
{
- new_account_flag = config_switch(w2);
+ new_account = config_switch(w2);
}
else if (w1 == "login_port")
{
@@ -3428,7 +3322,7 @@ int login_config_read(ZString cfgName)
}
else if (w1 == "gm_account_filename")
{
- GM_account_filename = w2;
+ gm_account_filename = w2;
}
else if (w1 == "gm_account_filename_check_timer")
{
@@ -3481,7 +3375,7 @@ int login_config_read(ZString cfgName)
else if (w2 == "allow,deny" || w2 == "allow, deny")
access_order = ACO::ALLOW_DENY;
else if (w2 == "mutual-failture" || w2 == "mutual-failure")
- access_order = ACO::MUTUAL_FAILTURE;
+ access_order = ACO::MUTUAL_FAILURE;
else
PRINTF("Bad order: %s\n", w2);
}
@@ -3498,14 +3392,19 @@ int login_config_read(ZString cfgName)
// reset all previous values
access_allow.clear();
// set to all
- access_allow.push_back(AccessEntry());
+ access_allow.push_back(IP4Mask());
}
else if (w2
- && !(access_allow.size() == 1
- && access_allow.front() == AccessEntry()))
+ && !(access_allow.size() == 1
+ && access_allow.front().mask() == IP4Address()))
{
// don't add IP if already 'all'
- AccessEntry n = stringish<AccessEntry>(w2);
+ IP4Mask n;
+ if (!extract(w2, &n))
+ {
+ PRINTF("Bad IP mask: %s\n", line);
+ abort();
+ }
access_allow.push_back(n);
}
}
@@ -3523,14 +3422,19 @@ int login_config_read(ZString cfgName)
// reset all previous values
access_deny.clear();
// set to all
- access_deny.push_back(AccessEntry());
+ access_deny.push_back(IP4Mask());
}
else if (w2
- && !(access_deny.size() == 1
- && access_deny.front() == AccessEntry()))
+ && !(access_deny.size() == 1
+ && access_deny.front().mask() == IP4Address()))
{
// don't add IP if already 'all'
- AccessEntry n = stringish<AccessEntry>(w2);
+ IP4Mask n;
+ if (!extract(w2, &n))
+ {
+ PRINTF("Bad IP mask: %s\n", line);
+ abort();
+ }
access_deny.push_back(n);
}
}
@@ -3541,7 +3445,7 @@ int login_config_read(ZString cfgName)
}
else if (w1 == "anti_freeze_interval")
{
- ANTI_FREEZE_INTERVAL = std::max(
+ anti_freeze_interval = std::max(
std::chrono::seconds(atoi(w2.c_str())),
std::chrono::seconds(5));
}
@@ -3611,10 +3515,10 @@ void display_conf_warnings(void)
level_new_gm = 60;
}
- if (new_account_flag != 0 && new_account_flag != 1)
+ if (new_account != 0 && new_account != 1)
{
PRINTF("***WARNING: Invalid value for new_account parameter -> set to 0 (no new account).\n");
- new_account_flag = 0;
+ new_account = 0;
}
if (login_port < 1024 || login_port > 65535)
@@ -3701,7 +3605,7 @@ void display_conf_warnings(void)
if (access_order == ACO::DENY_ALLOW)
{
- if (access_deny.size() == 1 && access_deny.front() == AccessEntry())
+ if (access_deny.size() == 1 && access_deny.front().mask() == IP4Address())
{
PRINTF("***WARNING: The IP security order is 'deny,allow' (allow if not deny).\n");
PRINTF(" And you refuse ALL IP.\n");
@@ -3716,14 +3620,15 @@ void display_conf_warnings(void)
}
}
else
- { // ACO_MUTUAL_FAILTURE
+ {
+ // ACO::MUTUAL_FAILURE
if (access_allow.empty())
{
PRINTF("***WARNING: The IP security order is 'mutual-failture'\n");
PRINTF(" (allow if in the allow list and not in the deny list).\n");
PRINTF(" But, NO IP IS AUTHORISED!\n");
}
- else if (access_deny.size() == 1 && access_deny.front() == AccessEntry())
+ else if (access_deny.size() == 1 && access_deny.front().mask() == IP4Address())
{
PRINTF("***WARNING: The IP security order is mutual-failture\n");
PRINTF(" (allow if in the allow list and not in the deny list).\n");
@@ -3755,14 +3660,14 @@ void save_config_in_log(void)
LOGIN_LOG("- with a remote administration with the password of %zu character(s).\n",
admin_pass.size());
if (access_ladmin.empty()
- || (access_ladmin.size() == 1 && access_ladmin.front() == AccessEntry()))
+ || (access_ladmin.size() == 1 && access_ladmin.front().mask() == IP4Address()))
{
LOGIN_LOG("- to accept any IP for remote administration\n");
}
else
{
LOGIN_LOG("- to accept following IP for remote administration:\n");
- for (const AccessEntry& ae : access_ladmin)
+ for (const IP4Mask& ae : access_ladmin)
LOGIN_LOG(" %s\n", ae);
}
@@ -3779,7 +3684,7 @@ void save_config_in_log(void)
LOGIN_LOG("- to create GM with level '%d' when @gm is used.\n",
level_new_gm);
- if (new_account_flag == 1)
+ if (new_account == 1)
LOGIN_LOG("- to ALLOW new users (with _F/_M).\n");
else
LOGIN_LOG("- to NOT ALLOW new users (with _F/_M).\n");
@@ -3787,7 +3692,7 @@ void save_config_in_log(void)
LOGIN_LOG("- with the accounts file name: '%s'.\n",
account_filename);
LOGIN_LOG("- with the GM accounts file name: '%s'.\n",
- GM_account_filename);
+ gm_account_filename);
if (gm_account_filename_check_timer == interval_t::zero())
LOGIN_LOG("- to NOT check GM accounts file modifications.\n");
else
@@ -3847,14 +3752,14 @@ void save_config_in_log(void)
{
LOGIN_LOG("- with the IP security order: 'deny,allow' (allow if not deny). You refuse no IP.\n");
}
- else if (access_deny.size() == 1 && access_deny.front() == AccessEntry())
+ else if (access_deny.size() == 1 && access_deny.front().mask() == IP4Address())
{
LOGIN_LOG("- with the IP security order: 'deny,allow' (allow if not deny). You refuse ALL IP.\n");
}
else
{
LOGIN_LOG("- with the IP security order: 'deny,allow' (allow if not deny). Refused IP are:\n");
- for (const AccessEntry& ae : access_deny)
+ for (IP4Mask ae : access_deny)
LOGIN_LOG(" %s\n", ae);
}
}
@@ -3864,14 +3769,14 @@ void save_config_in_log(void)
{
LOGIN_LOG("- with the IP security order: 'allow,deny' (deny if not allow). But, NO IP IS AUTHORISED!\n");
}
- else if (access_allow.size() == 1 && access_allow.front() == AccessEntry())
+ else if (access_allow.size() == 1 && access_allow.front().mask() == IP4Address())
{
LOGIN_LOG("- with the IP security order: 'allow,deny' (deny if not allow). You authorise ALL IP.\n");
}
else
{
LOGIN_LOG("- with the IP security order: 'allow,deny' (deny if not allow). Authorised IP are:\n");
- for (const AccessEntry& ae : access_allow)
+ for (IP4Mask ae : access_allow)
LOGIN_LOG(" %s\n", ae);
}
}
@@ -3882,24 +3787,24 @@ void save_config_in_log(void)
{
LOGIN_LOG(" But, NO IP IS AUTHORISED!\n");
}
- else if (access_deny.size() == 1 && access_deny.front() == AccessEntry())
+ else if (access_deny.size() == 1 && access_deny.front().mask() == IP4Address())
{
LOGIN_LOG(" But, you refuse ALL IP!\n");
}
else
{
- if (access_allow.size() == 1 && access_allow.front() == AccessEntry())
+ if (access_allow.size() == 1 && access_allow.front().mask() == IP4Address())
{
LOGIN_LOG(" You authorise ALL IP.\n");
}
else
{
LOGIN_LOG(" Authorised IP are:\n");
- for (const AccessEntry& ae : access_allow)
+ for (IP4Mask ae : access_allow)
LOGIN_LOG(" %s\n", ae);
}
LOGIN_LOG(" Refused IP are:\n");
- for (const AccessEntry& ae : access_deny)
+ for (IP4Mask ae : access_deny)
LOGIN_LOG(" %s\n", ae);
}
}
@@ -3964,7 +3869,7 @@ int do_init(int argc, ZString *argv)
{
Timer(gettick() + std::chrono::seconds(1),
char_anti_freeze_system,
- ANTI_FREEZE_INTERVAL
+ anti_freeze_interval
).detach();
}
diff --git a/src/map/atcommand.cpp b/src/map/atcommand.cpp
index 4b52d93..4b41c7b 100644
--- a/src/map/atcommand.cpp
+++ b/src/map/atcommand.cpp
@@ -418,14 +418,14 @@ void log_atcommand(dumb_ptr<map_session_data> sd, ZString cmd)
cmd);
}
-FString gm_logfile_name;
+FString gm_log;
/*==========================================
* Log a timestamped line to GM log file
*------------------------------------------
*/
FILE *get_gm_log()
{
- if (!gm_logfile_name)
+ if (!gm_log)
return NULL;
struct tm ctime = TimeT::now();
@@ -441,7 +441,7 @@ FILE *get_gm_log()
last_logfile_nr = logfile_nr;
FString fullname = STRPRINTF("%s.%04d-%02d",
- gm_logfile_name, year, month);
+ gm_log, year, month);
if (gm_logfile)
fclose(gm_logfile);
@@ -451,7 +451,7 @@ FILE *get_gm_log()
if (!gm_logfile)
{
perror("GM log file");
- gm_logfile_name = FString();
+ gm_log = FString();
}
return gm_logfile;
}
@@ -511,7 +511,7 @@ AtCommandInfo *atcommand(const int level, ZString message)
{
ZString p = message;
- if (battle_config.atc_gmonly != 0 && !level) // level = pc_isGM(sd)
+ if (battle_config.atcommand_gm_only != 0 && !level) // level = pc_isGM(sd)
return nullptr;
if (!p)
{
@@ -1466,8 +1466,8 @@ int atcommand_alive(const int fd, dumb_ptr<map_session_data> sd,
sd->status.hp = sd->status.max_hp;
sd->status.sp = sd->status.max_sp;
pc_setstand(sd);
- if (static_cast<interval_t>(battle_config.pc_invincible_time) > interval_t::zero())
- pc_setinvincibletimer(sd, static_cast<interval_t>(battle_config.pc_invincible_time));
+ if (static_cast<interval_t>(battle_config.player_invincible_time) > interval_t::zero())
+ pc_setinvincibletimer(sd, static_cast<interval_t>(battle_config.player_invincible_time));
clif_updatestatus(sd, SP::HP);
clif_updatestatus(sd, SP::SP);
clif_resurrection(sd, 1);
@@ -2081,9 +2081,9 @@ int atcommand_spawn(const int fd, dumb_ptr<map_session_data> sd,
number = 1;
// If value of atcommand_spawn_quantity_limit directive is greater than or equal to 1 and quantity of monsters is greater than value of the directive
- if (battle_config.atc_spawn_quantity_limit >= 1
- && number > battle_config.atc_spawn_quantity_limit)
- number = battle_config.atc_spawn_quantity_limit;
+ if (battle_config.atcommand_spawn_quantity_limit >= 1
+ && number > battle_config.atcommand_spawn_quantity_limit)
+ number = battle_config.atcommand_spawn_quantity_limit;
if (battle_config.etc_log)
PRINTF("@spawn monster='%s' id=%d count=%d (%d,%d)\n",
@@ -2546,8 +2546,8 @@ int atcommand_revive(const int fd, dumb_ptr<map_session_data> sd,
{
pl_sd->status.hp = pl_sd->status.max_hp;
pc_setstand(pl_sd);
- if (static_cast<interval_t>(battle_config.pc_invincible_time) > interval_t::zero())
- pc_setinvincibletimer(sd, static_cast<interval_t>(battle_config.pc_invincible_time));
+ if (static_cast<interval_t>(battle_config.player_invincible_time) > interval_t::zero())
+ pc_setinvincibletimer(sd, static_cast<interval_t>(battle_config.player_invincible_time));
clif_updatestatus(pl_sd, SP::HP);
clif_updatestatus(pl_sd, SP::SP);
clif_resurrection(pl_sd, 1);
@@ -5917,10 +5917,7 @@ int atcommand_skill_learn(const int fd, dumb_ptr<map_session_data>,
int atcommand_ipcheck(const int fd, dumb_ptr<map_session_data>,
ZString message)
{
- struct sockaddr_in sai;
CharName character;
- socklen_t sa_len = sizeof(struct sockaddr);
- unsigned long ip;
if (!asplit(message, &character))
{
@@ -5935,14 +5932,7 @@ int atcommand_ipcheck(const int fd, dumb_ptr<map_session_data>,
return -1;
}
- if (getpeername(pl_sd->fd, reinterpret_cast<struct sockaddr *>(&sai), &sa_len))
- {
- clif_displaymessage(fd,
- "Guru Meditation Error: getpeername() failed");
- return -1;
- }
-
- ip = sai.sin_addr.s_addr;
+ IP4Address ip = pl_sd->get_ip();
// We now have the IP address of a character.
// Loop over all logged in sessions looking for matches.
@@ -5954,11 +5944,8 @@ int atcommand_ipcheck(const 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 (getpeername(pl_sd->fd, reinterpret_cast<struct sockaddr *>(&sai), &sa_len))
- continue;
-
// Is checking GM levels really needed here?
- if (ip == sai.sin_addr.s_addr)
+ if (ip == pl_sd->get_ip())
{
FString output = STRPRINTF(
"Name: %s | Location: %s %d %d",
diff --git a/src/map/atcommand.hpp b/src/map/atcommand.hpp
index e07a264..280372e 100644
--- a/src/map/atcommand.hpp
+++ b/src/map/atcommand.hpp
@@ -13,6 +13,6 @@ int atcommand_config_read(ZString cfgName);
void log_atcommand(dumb_ptr<map_session_data> sd, ZString cmd);
// only used by map.cpp
-extern FString gm_logfile_name;
+extern FString gm_log;
#endif // ATCOMMAND_HPP
diff --git a/src/map/battle.cpp b/src/map/battle.cpp
index 4045348..02ea370 100644
--- a/src/map/battle.cpp
+++ b/src/map/battle.cpp
@@ -2302,18 +2302,12 @@ int battle_config_read(ZString cfgName)
battle_config.enemy_critical_rate = 100;
battle_config.enemy_str = 1;
battle_config.enemy_perfect_flee = 0;
- battle_config.cast_rate = 100;
+ battle_config.casting_rate = 100;
battle_config.delay_rate = 100;
battle_config.delay_dependon_dex = 0;
- battle_config.sdelay_attack_enable = 0;
- battle_config.left_cardfix_to_right = 0;
- battle_config.pc_skill_add_range = 0;
- battle_config.skill_out_range_consume = 1;
- battle_config.mob_skill_add_range = 0;
- battle_config.pc_damage_delay = 1;
- battle_config.defnotenemy = 1;
- battle_config.random_monster_checklv = 1;
- battle_config.attr_recover = 1;
+ battle_config.skill_delay_attack_enable = 0;
+ battle_config.monster_skill_add_range = 0;
+ battle_config.player_damage_delay = 1;
battle_config.flooritem_lifetime = std::chrono::duration_cast<std::chrono::milliseconds>(LIFETIME_FLOORITEM).count();
battle_config.item_auto_get = 0;
battle_config.drop_pickup_safety_zone = 20;
@@ -2323,43 +2317,26 @@ int battle_config_read(ZString cfgName)
battle_config.base_exp_rate = 100;
battle_config.job_exp_rate = 100;
- battle_config.gtb_pvp_only = 0;
battle_config.death_penalty_type = 0;
battle_config.death_penalty_base = 0;
battle_config.death_penalty_job = 0;
- battle_config.zeny_penalty = 0;
battle_config.restart_hp_rate = 0;
battle_config.restart_sp_rate = 0;
battle_config.monster_hp_rate = 100;
battle_config.monster_max_aspd = 199;
- battle_config.atc_gmonly = 0;
- battle_config.gm_allskill = 0;
- battle_config.gm_allequip = 0;
- battle_config.gm_skilluncond = 0;
- battle_config.skillfree = 0;
- battle_config.skillup_limit = 0;
- battle_config.wp_rate = 100;
- battle_config.pp_rate = 100;
+ battle_config.atcommand_gm_only = 0;
+ battle_config.gm_all_equipment = 0;
battle_config.monster_active_enable = 1;
battle_config.mob_skill_use = 1;
battle_config.mob_count_rate = 100;
- battle_config.quest_skill_learn = 0;
- battle_config.quest_skill_reset = 1;
battle_config.basic_skill_check = 1;
- battle_config.pc_invincible_time = 5000;
+ battle_config.player_invincible_time = 5000;
battle_config.skill_min_damage = 0;
- battle_config.finger_offensive_type = 0;
- battle_config.heal_exp = 0;
- battle_config.resurrection_exp = 0;
- battle_config.shop_exp = 0;
- battle_config.combo_delay_rate = 100;
- battle_config.wedding_modifydisplay = 0;
battle_config.natural_healhp_interval = 6000;
battle_config.natural_healsp_interval = 8000;
battle_config.natural_heal_skill_interval = 10000;
battle_config.natural_heal_weight_rate = 50;
battle_config.itemheal_regeneration_factor = 1;
- battle_config.item_name_override_grffile = 1;
battle_config.arrow_decrement = 1;
battle_config.max_aspd = 199;
battle_config.max_hp = 32500;
@@ -2367,16 +2344,13 @@ int battle_config_read(ZString cfgName)
battle_config.max_lv = 99; // [MouseJstr]
battle_config.max_parameter = 99;
battle_config.max_cart_weight = 8000;
- battle_config.pc_skill_log = 0;
- battle_config.mob_skill_log = 0;
+ battle_config.monster_skill_log = 0;
battle_config.battle_log = 0;
battle_config.save_log = 0;
battle_config.error_log = 1;
battle_config.etc_log = 1;
battle_config.save_clothcolor = 0;
battle_config.undead_detect_type = 0;
- battle_config.pc_auto_counter_type = 1;
- battle_config.monster_auto_counter_type = 1;
battle_config.agi_penaly_type = 0;
battle_config.agi_penaly_count = 3;
battle_config.agi_penaly_num = 0;
@@ -2385,53 +2359,22 @@ int battle_config_read(ZString cfgName)
battle_config.vit_penaly_count = 3;
battle_config.vit_penaly_num = 0;
battle_config.vit_penaly_count_lv = static_cast<int>(ATK::DEF); // FIXME
- battle_config.pc_skill_reiteration = 0;
- battle_config.monster_skill_reiteration = 0;
- battle_config.pc_skill_nofootset = 0;
- battle_config.monster_skill_nofootset = 0;
- battle_config.pc_cloak_check_type = 0;
- battle_config.monster_cloak_check_type = 0;
battle_config.mob_changetarget_byskill = 0;
- battle_config.pc_attack_direction_change = 1;
+ battle_config.player_attack_direction_change = 1;
battle_config.monster_attack_direction_change = 1;
- battle_config.pc_undead_nofreeze = 0;
- battle_config.pc_land_skill_limit = 1;
- battle_config.monster_land_skill_limit = 1;
- battle_config.party_skill_penaly = 1;
- battle_config.monster_class_change_full_recover = 0;
- battle_config.produce_item_name_input = 1;
- battle_config.produce_potion_name_input = 1;
- battle_config.making_arrow_name_input = 1;
- battle_config.holywater_name_input = 1;
battle_config.display_delay_skill_fail = 1;
- battle_config.chat_warpportal = 0;
- battle_config.mob_warpportal = 0;
battle_config.dead_branch_active = 0;
battle_config.show_steal_in_same_party = 0;
- battle_config.enable_upper_class = 0;
- battle_config.pc_attack_attr_none = 0;
- battle_config.mob_attack_attr_none = 1;
- battle_config.mob_ghostring_fix = 0;
- battle_config.gx_allhit = 0;
- battle_config.gx_cardfix = 0;
- battle_config.gx_dupele = 1;
- battle_config.gx_disptype = 1;
- battle_config.player_skill_partner_check = 1;
battle_config.hide_GM_session = 0;
- battle_config.unit_movement_type = 0;
battle_config.invite_request_check = 1;
- battle_config.skill_removetrap_type = 0;
battle_config.disp_experience = 0;
battle_config.prevent_logout = 1; // Added by RoVeRT
battle_config.maximum_level = 255; // Added by Valaris
battle_config.drops_by_luk = 0; // [Valaris]
battle_config.pk_mode = 0; // [Valaris]
battle_config.multi_level_up = 0; // [Valaris]
- battle_config.backstab_bow_penalty = 0; // Akaru
- battle_config.show_mob_hp = 0; // [Valaris]
battle_config.hack_info_GM_level = 60; // added by [Yor] (default: 60, GM level)
battle_config.any_warp_GM_min_level = 20; // added by [Yor]
- battle_config.packet_ver_flag = 63; // added by [Yor]
battle_config.min_hair_style = 0;
battle_config.max_hair_style = 20;
battle_config.min_hair_color = 0;
@@ -2469,9 +2412,7 @@ int battle_config_read(ZString cfgName)
FString line;
while (io::getline(in, line))
{
-#define BATTLE_CONFIG_VAR2(name, varname) {{name}, &battle_config.varname}
-#define BATTLE_CONFIG_VAR(name) BATTLE_CONFIG_VAR2(#name, name)
- // s/{"\([a-zA-Z_0-9]*\)", &battle_config.\1}/BATTLE_CONFIG_VAR(\1)/
+#define BATTLE_CONFIG_VAR(name) {{#name}, &battle_config.name}
const struct
{
ZString str;
@@ -2483,18 +2424,12 @@ int battle_config_read(ZString cfgName)
BATTLE_CONFIG_VAR(enemy_critical_rate),
BATTLE_CONFIG_VAR(enemy_str),
BATTLE_CONFIG_VAR(enemy_perfect_flee),
- BATTLE_CONFIG_VAR2("casting_rate", cast_rate),
+ BATTLE_CONFIG_VAR(casting_rate),
BATTLE_CONFIG_VAR(delay_rate),
BATTLE_CONFIG_VAR(delay_dependon_dex),
- BATTLE_CONFIG_VAR2("skill_delay_attack_enable", sdelay_attack_enable),
- BATTLE_CONFIG_VAR(left_cardfix_to_right),
- BATTLE_CONFIG_VAR2("player_skill_add_range", pc_skill_add_range),
- BATTLE_CONFIG_VAR(skill_out_range_consume),
- BATTLE_CONFIG_VAR2("monster_skill_add_range", mob_skill_add_range),
- BATTLE_CONFIG_VAR2("player_damage_delay", pc_damage_delay),
- BATTLE_CONFIG_VAR2("defunit_not_enemy", defnotenemy),
- BATTLE_CONFIG_VAR(random_monster_checklv),
- BATTLE_CONFIG_VAR2("attribute_recover", attr_recover),
+ BATTLE_CONFIG_VAR(skill_delay_attack_enable),
+ BATTLE_CONFIG_VAR(monster_skill_add_range),
+ BATTLE_CONFIG_VAR(player_damage_delay),
BATTLE_CONFIG_VAR(flooritem_lifetime),
BATTLE_CONFIG_VAR(item_auto_get),
BATTLE_CONFIG_VAR(drop_pickup_safety_zone),
@@ -2503,45 +2438,27 @@ int battle_config_read(ZString cfgName)
BATTLE_CONFIG_VAR(item_third_get_time),
BATTLE_CONFIG_VAR(base_exp_rate),
BATTLE_CONFIG_VAR(job_exp_rate),
- BATTLE_CONFIG_VAR(gtb_pvp_only),
BATTLE_CONFIG_VAR(death_penalty_type),
BATTLE_CONFIG_VAR(death_penalty_base),
BATTLE_CONFIG_VAR(death_penalty_job),
- BATTLE_CONFIG_VAR(zeny_penalty),
BATTLE_CONFIG_VAR(restart_hp_rate),
BATTLE_CONFIG_VAR(restart_sp_rate),
BATTLE_CONFIG_VAR(monster_hp_rate),
BATTLE_CONFIG_VAR(monster_max_aspd),
- BATTLE_CONFIG_VAR2("atcommand_gm_only", atc_gmonly),
- BATTLE_CONFIG_VAR2("atcommand_spawn_quantity_limit", atc_spawn_quantity_limit),
- BATTLE_CONFIG_VAR2("gm_all_skill", gm_allskill),
- BATTLE_CONFIG_VAR2("gm_all_skill_add_abra", gm_allskill_addabra),
- BATTLE_CONFIG_VAR2("gm_all_equipment", gm_allequip),
- BATTLE_CONFIG_VAR2("gm_skill_unconditional", gm_skilluncond),
- BATTLE_CONFIG_VAR2("player_skillfree", skillfree),
- BATTLE_CONFIG_VAR2("player_skillup_limit", skillup_limit),
- BATTLE_CONFIG_VAR2("weapon_produce_rate", wp_rate),
- BATTLE_CONFIG_VAR2("potion_produce_rate", pp_rate),
+ BATTLE_CONFIG_VAR(atcommand_gm_only),
+ BATTLE_CONFIG_VAR(atcommand_spawn_quantity_limit),
+ BATTLE_CONFIG_VAR(gm_all_equipment),
BATTLE_CONFIG_VAR(monster_active_enable),
BATTLE_CONFIG_VAR(mob_skill_use),
BATTLE_CONFIG_VAR(mob_count_rate),
- BATTLE_CONFIG_VAR(quest_skill_learn),
- BATTLE_CONFIG_VAR(quest_skill_reset),
BATTLE_CONFIG_VAR(basic_skill_check),
- BATTLE_CONFIG_VAR2("player_invincible_time", pc_invincible_time),
+ BATTLE_CONFIG_VAR(player_invincible_time),
BATTLE_CONFIG_VAR(skill_min_damage),
- BATTLE_CONFIG_VAR(finger_offensive_type),
- BATTLE_CONFIG_VAR(heal_exp),
- BATTLE_CONFIG_VAR(resurrection_exp),
- BATTLE_CONFIG_VAR(shop_exp),
- BATTLE_CONFIG_VAR(combo_delay_rate),
- BATTLE_CONFIG_VAR(wedding_modifydisplay),
BATTLE_CONFIG_VAR(natural_healhp_interval),
BATTLE_CONFIG_VAR(natural_healsp_interval),
BATTLE_CONFIG_VAR(natural_heal_skill_interval),
BATTLE_CONFIG_VAR(natural_heal_weight_rate),
BATTLE_CONFIG_VAR(itemheal_regeneration_factor),
- BATTLE_CONFIG_VAR(item_name_override_grffile),
BATTLE_CONFIG_VAR(arrow_decrement),
BATTLE_CONFIG_VAR(max_aspd),
BATTLE_CONFIG_VAR(max_hp),
@@ -2549,16 +2466,13 @@ int battle_config_read(ZString cfgName)
BATTLE_CONFIG_VAR(max_lv),
BATTLE_CONFIG_VAR(max_parameter),
BATTLE_CONFIG_VAR(max_cart_weight),
- BATTLE_CONFIG_VAR2("player_skill_log", pc_skill_log),
- BATTLE_CONFIG_VAR2("monster_skill_log", mob_skill_log),
+ BATTLE_CONFIG_VAR(monster_skill_log),
BATTLE_CONFIG_VAR(battle_log),
BATTLE_CONFIG_VAR(save_log),
BATTLE_CONFIG_VAR(error_log),
BATTLE_CONFIG_VAR(etc_log),
BATTLE_CONFIG_VAR(save_clothcolor),
BATTLE_CONFIG_VAR(undead_detect_type),
- BATTLE_CONFIG_VAR2("player_auto_counter_type", pc_auto_counter_type),
- BATTLE_CONFIG_VAR(monster_auto_counter_type),
BATTLE_CONFIG_VAR(agi_penaly_type),
BATTLE_CONFIG_VAR(agi_penaly_count),
BATTLE_CONFIG_VAR(agi_penaly_num),
@@ -2567,43 +2481,15 @@ int battle_config_read(ZString cfgName)
BATTLE_CONFIG_VAR(vit_penaly_count),
BATTLE_CONFIG_VAR(vit_penaly_num),
BATTLE_CONFIG_VAR(vit_penaly_count_lv),
- BATTLE_CONFIG_VAR2("player_skill_reiteration", pc_skill_reiteration),
- BATTLE_CONFIG_VAR(monster_skill_reiteration),
- BATTLE_CONFIG_VAR2("player_skill_nofootset", pc_skill_nofootset),
- BATTLE_CONFIG_VAR(monster_skill_nofootset),
- BATTLE_CONFIG_VAR2("player_cloak_check_type", pc_cloak_check_type),
- BATTLE_CONFIG_VAR(monster_cloak_check_type),
BATTLE_CONFIG_VAR(mob_changetarget_byskill),
- BATTLE_CONFIG_VAR2("player_attack_direction_change", pc_attack_direction_change),
+ BATTLE_CONFIG_VAR(player_attack_direction_change),
BATTLE_CONFIG_VAR(monster_attack_direction_change),
- BATTLE_CONFIG_VAR2("player_land_skill_limit", pc_land_skill_limit),
- BATTLE_CONFIG_VAR(monster_land_skill_limit),
- BATTLE_CONFIG_VAR(party_skill_penaly),
- BATTLE_CONFIG_VAR(monster_class_change_full_recover),
- BATTLE_CONFIG_VAR(produce_item_name_input),
- BATTLE_CONFIG_VAR(produce_potion_name_input),
- BATTLE_CONFIG_VAR(making_arrow_name_input),
- BATTLE_CONFIG_VAR(holywater_name_input),
BATTLE_CONFIG_VAR(display_delay_skill_fail),
- BATTLE_CONFIG_VAR(chat_warpportal),
- BATTLE_CONFIG_VAR(mob_warpportal),
BATTLE_CONFIG_VAR(dead_branch_active),
BATTLE_CONFIG_VAR(show_steal_in_same_party),
- BATTLE_CONFIG_VAR(enable_upper_class),
- BATTLE_CONFIG_VAR(mob_attack_attr_none),
- BATTLE_CONFIG_VAR(mob_ghostring_fix),
- BATTLE_CONFIG_VAR(pc_attack_attr_none),
- BATTLE_CONFIG_VAR(gx_allhit),
- BATTLE_CONFIG_VAR(gx_cardfix),
- BATTLE_CONFIG_VAR(gx_dupele),
- BATTLE_CONFIG_VAR(gx_disptype),
- BATTLE_CONFIG_VAR(player_skill_partner_check),
BATTLE_CONFIG_VAR(hide_GM_session),
- BATTLE_CONFIG_VAR(unit_movement_type),
BATTLE_CONFIG_VAR(invite_request_check),
- BATTLE_CONFIG_VAR(skill_removetrap_type),
BATTLE_CONFIG_VAR(disp_experience),
- BATTLE_CONFIG_VAR(riding_weight),
BATTLE_CONFIG_VAR(prevent_logout), // Added by RoVeRT
BATTLE_CONFIG_VAR(alchemist_summon_reward), // [Valaris]
BATTLE_CONFIG_VAR(maximum_level), // [Valaris]
@@ -2611,11 +2497,8 @@ int battle_config_read(ZString cfgName)
BATTLE_CONFIG_VAR(monsters_ignore_gm), // [Valaris]
BATTLE_CONFIG_VAR(pk_mode), // [Valaris]
BATTLE_CONFIG_VAR(multi_level_up), // [Valaris]
- BATTLE_CONFIG_VAR(backstab_bow_penalty),
- BATTLE_CONFIG_VAR(show_mob_hp), // [Valaris]
BATTLE_CONFIG_VAR(hack_info_GM_level), // added by [Yor]
BATTLE_CONFIG_VAR(any_warp_GM_min_level), // added by [Yor]
- BATTLE_CONFIG_VAR(packet_ver_flag), // added by [Yor]
BATTLE_CONFIG_VAR(min_hair_style), // added by [MouseJstr]
BATTLE_CONFIG_VAR(max_hair_style), // added by [MouseJstr]
BATTLE_CONFIG_VAR(min_hair_color), // added by [MouseJstr]
@@ -2771,11 +2654,6 @@ int battle_config_read(ZString cfgName)
battle_config.mask_ip_gms = 0;
else if (battle_config.mask_ip_gms > 1)
battle_config.mask_ip_gms = 1;
-
- // at least 1 client must be accepted
- if ((battle_config.packet_ver_flag & 63) == 0) // added by [Yor]
- battle_config.packet_ver_flag = 63; // accept all clients
-
}
return 0;
diff --git a/src/map/battle.hpp b/src/map/battle.hpp
index 6ed32fd..c933e28 100644
--- a/src/map/battle.hpp
+++ b/src/map/battle.hpp
@@ -96,16 +96,10 @@ extern struct Battle_Config
int enemy_critical_rate;
int enemy_str;
int enemy_perfect_flee;
- int cast_rate, delay_rate, delay_dependon_dex;
- int sdelay_attack_enable;
- int left_cardfix_to_right;
- int pc_skill_add_range;
- int skill_out_range_consume;
- int mob_skill_add_range;
- int pc_damage_delay;
- int defnotenemy;
- int random_monster_checklv;
- int attr_recover;
+ int casting_rate, delay_rate, delay_dependon_dex;
+ int skill_delay_attack_enable;
+ int monster_skill_add_range;
+ int player_damage_delay;
int flooritem_lifetime;
int item_auto_get;
int item_first_get_time;
@@ -114,41 +108,23 @@ extern struct Battle_Config
int base_exp_rate, job_exp_rate;
int death_penalty_type;
int death_penalty_base, death_penalty_job;
- int gtb_pvp_only; // [MouseJstr]
- int zeny_penalty;
int restart_hp_rate;
int restart_sp_rate;
int monster_hp_rate;
int monster_max_aspd;
- int atc_gmonly;
- int atc_spawn_quantity_limit;
- int gm_allskill;
- int gm_allskill_addabra;
- int gm_allequip;
- int gm_skilluncond;
- int skillfree;
- int skillup_limit;
- int wp_rate;
- int pp_rate;
+ int atcommand_gm_only;
+ int atcommand_spawn_quantity_limit;
+ int gm_all_equipment;
int monster_active_enable;
int mob_skill_use;
int mob_count_rate;
- int quest_skill_learn;
- int quest_skill_reset;
int basic_skill_check;
- int pc_invincible_time;
+ int player_invincible_time;
int skill_min_damage;
- int finger_offensive_type;
- int heal_exp;
- int resurrection_exp;
- int shop_exp;
- int combo_delay_rate;
- int wedding_modifydisplay;
int natural_healhp_interval;
int natural_healsp_interval;
int natural_heal_skill_interval;
int natural_heal_weight_rate;
- int item_name_override_grffile;
int arrow_decrement;
int max_aspd;
int max_hp;
@@ -156,89 +132,54 @@ extern struct Battle_Config
int max_lv;
int max_parameter;
int max_cart_weight;
- int pc_skill_log;
- int mob_skill_log;
+ int monster_skill_log;
int battle_log;
int save_log;
int error_log;
int etc_log;
int save_clothcolor;
int undead_detect_type;
- int pc_auto_counter_type;
- int monster_auto_counter_type;
int agi_penaly_type;
int agi_penaly_count;
int agi_penaly_num;
int vit_penaly_type;
int vit_penaly_count;
int vit_penaly_num;
- int pc_skill_reiteration;
- int monster_skill_reiteration;
- int pc_skill_nofootset;
- int monster_skill_nofootset;
- int pc_cloak_check_type;
- int monster_cloak_check_type;
int mob_changetarget_byskill;
- int pc_attack_direction_change;
+ int player_attack_direction_change;
int monster_attack_direction_change;
- int pc_undead_nofreeze;
- int pc_land_skill_limit;
- int monster_land_skill_limit;
- int party_skill_penaly;
- int monster_class_change_full_recover;
- int produce_item_name_input;
- int produce_potion_name_input;
- int making_arrow_name_input;
- int holywater_name_input;
int display_delay_skill_fail;
- int chat_warpportal;
- int mob_warpportal;
int dead_branch_active;
int show_steal_in_same_party;
- int enable_upper_class;
- int mob_attack_attr_none;
- int mob_ghostring_fix;
- int pc_attack_attr_none;
- int prevent_logout; // Added by RoVeRT
+ int prevent_logout;
- int alchemist_summon_reward; // [Valaris]
+ int alchemist_summon_reward;
int maximum_level;
int drops_by_luk;
int monsters_ignore_gm;
int multi_level_up;
int pk_mode;
- int show_mob_hp; // end additions [Valaris]
int agi_penaly_count_lv;
int vit_penaly_count_lv;
- int gx_allhit;
- int gx_cardfix;
- int gx_dupele;
- int gx_disptype;
- int player_skill_partner_check;
int hide_GM_session;
- int unit_movement_type;
int invite_request_check;
- int skill_removetrap_type;
int disp_experience;
- int riding_weight;
- int backstab_bow_penalty;
- int hack_info_GM_level; // added by [Yor]
- int any_warp_GM_min_level; // added by [Yor]
- int packet_ver_flag; // added by [Yor]
+ int hack_info_GM_level;
+ int any_warp_GM_min_level;
- int min_hair_style; // added by [MouseJstr]
- int max_hair_style; // added by [MouseJstr]
- int min_hair_color; // added by [MouseJstr]
- int max_hair_color; // added by [MouseJstr]
- int min_cloth_color; // added by [MouseJstr]
- int max_cloth_color; // added by [MouseJstr]
+ int min_hair_style;
+ int max_hair_style;
+ int min_hair_color;
+ int max_hair_color;
+ int min_cloth_color;
+ int max_cloth_color;
- int castrate_dex_scale; // added by [MouseJstr]
- int area_size; // added by [MouseJstr]
+ int castrate_dex_scale;
+ int area_size;
int chat_lame_penalty;
int chat_spam_threshold;
@@ -253,8 +194,8 @@ extern struct Battle_Config
int mask_ip_gms;
- int drop_pickup_safety_zone; // [Fate] Max. distance to an object dropped by a kill by self in which dropsteal protection works
- int itemheal_regeneration_factor; // [Fate] itemheal speed factor
+ int drop_pickup_safety_zone;
+ int itemheal_regeneration_factor;
int mob_splash_radius;
} battle_config;
diff --git a/src/map/chrif.cpp b/src/map/chrif.cpp
index 33a9879..c9020a3 100644
--- a/src/map/chrif.cpp
+++ b/src/map/chrif.cpp
@@ -32,9 +32,7 @@ const int packet_len_table[0x20] =
int char_fd;
static
-IP_String char_ip_str;
-static
-int char_ip;
+IP4Address char_ip;
static
int char_port = 6121;
static
@@ -72,10 +70,9 @@ AccountPass chrif_getpasswd(void)
*
*------------------------------------------
*/
-void chrif_setip(IP_String ip)
+void chrif_setip(IP4Address ip)
{
- char_ip_str = ip;
- char_ip = inet_addr(char_ip_str.c_str());
+ char_ip = ip;
}
/*==========================================
@@ -134,7 +131,7 @@ int chrif_connect(int fd)
WFIFO_STRING(fd, 2, userid, 24);
WFIFO_STRING(fd, 26, passwd, 24);
WFIFOL(fd, 50) = 0;
- WFIFOL(fd, 54) = clif_getip().s_addr;
+ WFIFOIP(fd, 54) = clif_getip();
WFIFOW(fd, 58) = clif_getport(); // [Valaris] thanks to fov
WFIFOSET(fd, 60);
@@ -172,21 +169,21 @@ int chrif_sendmap(int fd)
static
int chrif_recvmap(int fd)
{
- int i, j, port;
+ int i, j;
if (chrif_state < 2) // まだ準備中
return -1;
- struct in_addr ip;
- ip.s_addr = RFIFOL(fd, 4);
- port = RFIFOW(fd, 8);
+ IP4Address ip = RFIFOIP(fd, 4);
+ uint16_t port = RFIFOW(fd, 8);
for (i = 10, j = 0; i < RFIFOW(fd, 2); i += 16, j++)
{
MapName map = RFIFO_STRING<16>(fd, i);
map_setipport(map, ip, port);
}
if (battle_config.etc_log)
- PRINTF("recv map on %s:%d (%d maps)\n", ip2str(ip), port, j);
+ PRINTF("recv map on %s:%d (%d maps)\n",
+ ip, port, j);
return 0;
}
@@ -196,17 +193,16 @@ int chrif_recvmap(int fd)
*------------------------------------------
*/
int chrif_changemapserver(dumb_ptr<map_session_data> sd,
- MapName name, int x, int y, struct in_addr ip, short port)
+ MapName name, int x, int y, IP4Address ip, short port)
{
- int i, s_ip;
-
nullpo_retr(-1, sd);
- s_ip = 0;
- for (i = 0; i < fd_max; i++)
+ IP4Address s_ip;
+ for (int i = 0; i < fd_max; i++)
if (session[i] && dumb_ptr<map_session_data>(static_cast<map_session_data *>(session[i]->session_data.get())) == sd)
{
- s_ip = session[i]->client_addr.sin_addr.s_addr;
+ assert (i == sd->fd);
+ s_ip = session[i]->client_ip;
break;
}
@@ -218,10 +214,10 @@ int chrif_changemapserver(dumb_ptr<map_session_data> sd,
WFIFO_STRING(char_fd, 18, name, 16);
WFIFOW(char_fd, 34) = x;
WFIFOW(char_fd, 36) = y;
- WFIFOL(char_fd, 38) = ip.s_addr;
+ WFIFOIP(char_fd, 38) = ip;
WFIFOL(char_fd, 42) = port;
WFIFOB(char_fd, 44) = sd->status.sex;
- WFIFOL(char_fd, 45) = s_ip;
+ WFIFOIP(char_fd, 45) = s_ip;
WFIFOSET(char_fd, 49);
return 0;
@@ -249,7 +245,7 @@ int chrif_changemapserverack(int fd)
MapName mapname = RFIFO_STRING<16>(fd, 18);
uint16_t x = RFIFOW(fd, 34);
uint16_t y = RFIFOW(fd, 36);
- auto ip = in_addr{RFIFOL(fd, 38)};
+ IP4Address ip = RFIFOIP(fd, 38);
uint16_t port = RFIFOW(fd, 42);
clif_changemapserver(sd, mapname, x, y, ip, port);
@@ -311,22 +307,21 @@ int chrif_sendmapack(int fd)
*/
int chrif_authreq(dumb_ptr<map_session_data> sd)
{
- int i;
-
nullpo_retr(-1, sd);
if (!sd || !char_fd || !sd->bl_id || !sd->login_id1)
return -1;
- for (i = 0; i < fd_max; i++)
+ for (int i = 0; i < fd_max; i++)
if (session[i] && dumb_ptr<map_session_data>(static_cast<map_session_data *>(session[i]->session_data.get())) == sd)
{
+ assert (i == sd->fd);
WFIFOW(char_fd, 0) = 0x2afc;
WFIFOL(char_fd, 2) = sd->bl_id;
WFIFOL(char_fd, 6) = sd->char_id;
WFIFOL(char_fd, 10) = sd->login_id1;
WFIFOL(char_fd, 14) = sd->login_id2;
- WFIFOL(char_fd, 18) = session[i]->client_addr.sin_addr.s_addr;
+ WFIFOIP(char_fd, 18) = session[i]->client_ip;
WFIFOSET(char_fd, 22);
break;
}
@@ -340,18 +335,17 @@ int chrif_authreq(dumb_ptr<map_session_data> sd)
*/
int chrif_charselectreq(dumb_ptr<map_session_data> sd)
{
- int i, s_ip;
-
nullpo_retr(-1, sd);
if (!sd || !char_fd || !sd->bl_id || !sd->login_id1)
return -1;
- s_ip = 0;
- for (i = 0; i < fd_max; i++)
+ IP4Address s_ip;
+ for (int i = 0; i < fd_max; i++)
if (session[i] && dumb_ptr<map_session_data>(static_cast<map_session_data *>(session[i]->session_data.get())) == sd)
{
- s_ip = session[i]->client_addr.sin_addr.s_addr;
+ assert (i == sd->fd);
+ s_ip = session[i]->client_ip;
break;
}
@@ -359,29 +353,13 @@ int chrif_charselectreq(dumb_ptr<map_session_data> sd)
WFIFOL(char_fd, 2) = sd->bl_id;
WFIFOL(char_fd, 6) = sd->login_id1;
WFIFOL(char_fd, 10) = sd->login_id2;
- WFIFOL(char_fd, 14) = s_ip;
+ WFIFOIP(char_fd, 14) = s_ip;
WFIFOSET(char_fd, 18);
return 0;
}
/*==========================================
- * キャラ名問い合わせ
- *------------------------------------------
- */
-int chrif_searchcharid(int char_id)
-{
- if (!char_id)
- return -1;
-
- WFIFOW(char_fd, 0) = 0x2b08;
- WFIFOL(char_fd, 2) = char_id;
- WFIFOSET(char_fd, 6);
-
- return 0;
-}
-
-/*==========================================
* GMに変化要求
*------------------------------------------
*/
@@ -1108,13 +1086,6 @@ void chrif_parse(int fd)
case 0x2b06:
chrif_changemapserverack(fd);
break;
- case 0x2b09:
- {
- int charid = RFIFOL(fd, 2);
- CharName name = stringish<CharName>(RFIFO_STRING<24>(fd, 6));
- map_addchariddb(charid, name);
- }
- break;
case 0x2b0b:
chrif_changedgm(fd);
break;
diff --git a/src/map/chrif.hpp b/src/map/chrif.hpp
index 97760c3..dfcc12b 100644
--- a/src/map/chrif.hpp
+++ b/src/map/chrif.hpp
@@ -3,6 +3,7 @@
#include "../common/dumb_ptr.hpp"
#include "../common/human_time_diff.hpp"
+#include "../common/ip.hpp"
#include "map.hpp"
@@ -10,7 +11,7 @@ void chrif_setuserid(AccountName);
void chrif_setpasswd(AccountPass);
AccountPass chrif_getpasswd(void);
-void chrif_setip(IP_String);
+void chrif_setip(IP4Address);
void chrif_setport(int);
int chrif_isconnect(void);
@@ -21,9 +22,8 @@ int chrif_charselectreq(dumb_ptr<map_session_data>);
int chrif_changemapserver(dumb_ptr<map_session_data> sd,
MapName name, int x, int y,
- struct in_addr ip, short port);
+ IP4Address ip, short port);
-int chrif_searchcharid(int char_id);
void chrif_changegm(int id, ZString pass);
void chrif_changeemail(int id, AccountEmail actual_email, AccountEmail new_email);
void chrif_char_ask_name(int id, CharName character_name, short operation_type,
diff --git a/src/map/clif.cpp b/src/map/clif.cpp
index fa208be..e068249 100644
--- a/src/map/clif.cpp
+++ b/src/map/clif.cpp
@@ -107,9 +107,7 @@ void WFIFOPOS2(int fd, size_t pos, uint16_t x0, uint16_t y0, uint16_t x1, uint16
}
static
-IP_String map_ip_str;
-static
-struct in_addr map_ip;
+IP4Address map_ip;
static
int map_port = 5121;
@@ -121,10 +119,9 @@ int clif_changelook_towards(dumb_ptr<block_list> bl, LOOK type, int val,
* map鯖のip設定
*------------------------------------------
*/
-void clif_setip(IP_String ip)
+void clif_setip(IP4Address ip)
{
- map_ip_str = ip;
- map_ip.s_addr = inet_addr(map_ip_str.c_str());
+ map_ip = ip;
}
/*==========================================
@@ -140,7 +137,7 @@ void clif_setport(int port)
* map鯖のip読み出し
*------------------------------------------
*/
-struct in_addr clif_getip(void)
+IP4Address clif_getip(void)
{
return map_ip;
}
@@ -1114,7 +1111,7 @@ void clif_changemap(dumb_ptr<map_session_data> sd, MapName mapname, int x, int y
*------------------------------------------
*/
void clif_changemapserver(dumb_ptr<map_session_data> sd,
- MapName mapname, int x, int y, struct in_addr ip, int port)
+ MapName mapname, int x, int y, IP4Address ip, int port)
{
nullpo_retv(sd);
@@ -1123,7 +1120,7 @@ void clif_changemapserver(dumb_ptr<map_session_data> sd,
WFIFO_STRING(fd, 2, mapname, 16);
WFIFOW(fd, 18) = x;
WFIFOW(fd, 20) = y;
- WFIFOL(fd, 22) = ip.s_addr;
+ WFIFOIP(fd, 22) = ip;
WFIFOW(fd, 26) = port;
WFIFOSET(fd, clif_parse_func_table[0x92].len);
}
@@ -3526,9 +3523,9 @@ void clif_parse_LoadEndAck(int, dumb_ptr<map_session_data> sd)
// 119
// 78
- if (battle_config.pc_invincible_time > 0)
+ if (battle_config.player_invincible_time > 0)
{
- pc_setinvincibletimer(sd, static_cast<interval_t>(battle_config.pc_invincible_time));
+ pc_setinvincibletimer(sd, static_cast<interval_t>(battle_config.player_invincible_time));
}
map_addblock(sd); // ブロック登録
@@ -3735,15 +3732,15 @@ void clif_parse_GetCharNameRequest(int fd, dumb_ptr<map_session_data> sd)
if (pc_isGM(sd) >= battle_config.hack_info_GM_level)
{
- struct in_addr ip = ssd->ip;
+ IP4Address ip = ssd->get_ip();
WFIFOW(fd, 0) = 0x20C;
// Mask the IP using the char-server password
if (battle_config.mask_ip_gms)
- ip = MD5_ip(ssd->ip);
+ ip = MD5_ip(ip);
WFIFOL(fd, 2) = account_id;
- WFIFOL(fd, 6) = ip.s_addr;
+ WFIFOIP(fd, 6) = ip;
WFIFOSET(fd, clif_parse_func_table[0x20C].len);
}
@@ -3944,7 +3941,7 @@ void clif_parse_ActionRequest(int fd, dumb_ptr<map_session_data> sd)
case 0x07: // continuous attack
if (bool(sd->status.option & Option::HIDE))
return;
- if (!battle_config.sdelay_attack_enable)
+ if (!battle_config.skill_delay_attack_enable)
{
if (tick < sd->canact_tick)
{
diff --git a/src/map/clif.hpp b/src/map/clif.hpp
index 20f9912..fa68e23 100644
--- a/src/map/clif.hpp
+++ b/src/map/clif.hpp
@@ -6,6 +6,7 @@
#include <functional>
#include "../common/const_array.hpp"
+#include "../common/ip.hpp"
#include "../common/strings.hpp"
#include "../common/timer.t.hpp"
@@ -14,10 +15,10 @@
#include "pc.t.hpp"
#include "skill.t.hpp"
-void clif_setip(IP_String);
+void clif_setip(IP4Address);
void clif_setport(int);
-struct in_addr clif_getip(void);
+IP4Address clif_getip(void);
int clif_getport(void);
int clif_countusers(void);
void clif_setwaitclose(int);
@@ -39,7 +40,7 @@ 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
void clif_changemap(dumb_ptr<map_session_data>, MapName, int, int); //self
-void clif_changemapserver(dumb_ptr<map_session_data>, MapName, int, int, struct in_addr, int); //self
+void clif_changemapserver(dumb_ptr<map_session_data>, MapName, int, int, IP4Address, 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);
diff --git a/src/map/map.cpp b/src/map/map.cpp
index f2eefe5..25b70dc 100644
--- a/src/map/map.cpp
+++ b/src/map/map.cpp
@@ -64,7 +64,7 @@ dumb_ptr<block_list> object[MAX_FLOORITEM];
static
int first_free_object_id = 0, last_object_id = 0;
-interval_t autosave_interval = DEFAULT_AUTOSAVE_INTERVAL;
+interval_t autosave_time = DEFAULT_AUTOSAVE_INTERVAL;
int save_settings = 0xFFFF;
FString motd_txt = "conf/motd.txt";
@@ -1078,7 +1078,7 @@ map_local *map_mapname2mapid(MapName name)
* 他鯖map名からip,port変換
*------------------------------------------
*/
-int map_mapname2ipport(MapName name, struct in_addr *ip, int *port)
+int map_mapname2ipport(MapName name, IP4Address *ip, int *port)
{
map_abstract *md = maps_db.get(name);
if (md == NULL || md->gat)
@@ -1187,7 +1187,7 @@ void map_setcell(map_local *m, int x, int y, MapCell t)
* 他鯖管理のマップをdbに追加
*------------------------------------------
*/
-int map_setipport(MapName name, struct in_addr ip, int port)
+int map_setipport(MapName name, IP4Address ip, int port)
{
map_abstract *md = maps_db.get(name);
if (md == NULL)
@@ -1205,10 +1205,10 @@ int map_setipport(MapName name, struct in_addr ip, int port)
if (md->gat)
{
// local -> check data
- if (ip.s_addr != clif_getip().s_addr || port != clif_getport())
+ if (ip != clif_getip() || port != clif_getport())
{
- PRINTF("from char server : %s -> %s:%d\n", name, ip2str(ip),
- port);
+ PRINTF("from char server : %s -> %s:%d\n",
+ name, ip, port);
return 1;
}
}
@@ -1450,19 +1450,23 @@ int map_config_read(ZString cfgName)
else if (w1 == "char_ip")
{
h = gethostbyname(w2.c_str());
- IP_String w2ip;
+ IP4Address w2ip;
if (h != NULL)
{
- SNPRINTF(w2ip, 16, "%d.%d.%d.%d",
+ w2ip = IP4Address({
static_cast<uint8_t>(h->h_addr[0]),
static_cast<uint8_t>(h->h_addr[1]),
static_cast<uint8_t>(h->h_addr[2]),
- static_cast<uint8_t>(h->h_addr[3]));
+ static_cast<uint8_t>(h->h_addr[3]),
+ });
PRINTF("Character server IP address : %s -> %s\n",
w2, w2ip);
}
else
- w2ip = stringish<IP_String>(w2);
+ {
+ PRINTF("Bad IP value: %s\n", line);
+ abort();
+ }
chrif_setip(w2ip);
}
else if (w1 == "char_port")
@@ -1472,19 +1476,23 @@ int map_config_read(ZString cfgName)
else if (w1 == "map_ip")
{
h = gethostbyname(w2.c_str());
- IP_String w2ip;
+ IP4Address w2ip;
if (h != NULL)
{
- SNPRINTF(w2ip, 16, "%d.%d.%d.%d",
- static_cast<uint8_t>(h->h_addr[0]),
- static_cast<uint8_t>(h->h_addr[1]),
- static_cast<uint8_t>(h->h_addr[2]),
- static_cast<uint8_t>(h->h_addr[3]));
+ w2ip = IP4Address({
+ static_cast<uint8_t>(h->h_addr[0]),
+ static_cast<uint8_t>(h->h_addr[1]),
+ static_cast<uint8_t>(h->h_addr[2]),
+ static_cast<uint8_t>(h->h_addr[3]),
+ });
PRINTF("Map server IP address : %s -> %s\n",
w2, w2ip);
}
else
- w2ip = stringish<IP_String>(w2);
+ {
+ PRINTF("Bad IP value: %s\n", line);
+ abort();
+ }
clif_setip(w2ip);
}
else if (w1 == "map_port")
@@ -1511,9 +1519,9 @@ int map_config_read(ZString cfgName)
}
else if (w1 == "autosave_time")
{
- autosave_interval = std::chrono::seconds(atoi(w2.c_str()));
- if (autosave_interval <= interval_t::zero())
- autosave_interval = DEFAULT_AUTOSAVE_INTERVAL;
+ autosave_time = std::chrono::seconds(atoi(w2.c_str()));
+ if (autosave_time <= interval_t::zero())
+ autosave_time = DEFAULT_AUTOSAVE_INTERVAL;
}
else if (w1 == "motd_txt")
{
@@ -1529,7 +1537,7 @@ int map_config_read(ZString cfgName)
}
else if (w1 == "gm_log")
{
- gm_logfile_name = std::move(w2);
+ gm_log = std::move(w2);
}
else if (w1 == "log_file")
{
diff --git a/src/map/map.hpp b/src/map/map.hpp
index d98900d..4d5ac9d 100644
--- a/src/map/map.hpp
+++ b/src/map/map.hpp
@@ -165,7 +165,7 @@ struct map_session_data : block_list, SessionData
int weight, max_weight;
int cart_weight, cart_max_weight, cart_num, cart_max_num;
MapName mapname_;
- int fd, new_fd;
+ int fd; // use this, you idiots!
short to_x, to_y;
interval_t speed;
Opt1 opt1;
@@ -299,7 +299,10 @@ struct map_session_data : block_list, SessionData
TimeT packet_flood_reset_due;
int packet_flood_in;
- struct in_addr ip;
+ IP4Address get_ip()
+ {
+ return session[fd]->client_ip;
+ }
};
struct npc_timerevent_list
@@ -539,8 +542,8 @@ struct map_local : map_abstract
struct map_remote : map_abstract
{
- struct in_addr ip;
- unsigned int port;
+ IP4Address ip;
+ uint16_t port;
};
inline
@@ -558,7 +561,7 @@ struct flooritem_data : block_list
struct item item_data;
};
-extern interval_t autosave_interval;
+extern interval_t autosave_time;
extern int save_settings;
extern FString motd_txt;
@@ -708,8 +711,8 @@ dumb_ptr<invocation> map_id_is_spell(int id)
map_local *map_mapname2mapid(MapName);
-int map_mapname2ipport(MapName, struct in_addr *, int *);
-int map_setipport(MapName name, struct in_addr ip, int port);
+int map_mapname2ipport(MapName, IP4Address *, int *);
+int map_setipport(MapName name, IP4Address ip, int port);
void map_addiddb(dumb_ptr<block_list>);
void map_deliddb(dumb_ptr<block_list> bl);
void map_addnickdb(dumb_ptr<map_session_data>);
diff --git a/src/map/mob.cpp b/src/map/mob.cpp
index cd548a4..b8158af 100644
--- a/src/map/mob.cpp
+++ b/src/map/mob.cpp
@@ -3001,12 +3001,12 @@ void mobskill_castend_id(TimerData *, tick_t tick, int id)
range = skill_get_range(md->skillid, md->skilllv);
if (range < 0)
range = battle_get_range(md) - (range + 1);
- if (range + battle_config.mob_skill_add_range < distance(md->bl_x, md->bl_y, bl->bl_x, bl->bl_y))
+ if (range + battle_config.monster_skill_add_range < distance(md->bl_x, md->bl_y, bl->bl_x, bl->bl_y))
return;
md->skilldelayup[md->skillidx - &mob_db[md->mob_class].skills.front()] = tick;
- if (battle_config.mob_skill_log == 1)
+ if (battle_config.monster_skill_log == 1)
PRINTF("MOB skill castend skill=%d, mob_class = %d\n",
md->skillid, md->mob_class);
mob_stop_walking(md, 0);
@@ -3053,11 +3053,11 @@ void mobskill_castend_pos(TimerData *, tick_t tick, int id)
range = skill_get_range(md->skillid, md->skilllv);
if (range < 0)
range = battle_get_range(md) - (range + 1);
- if (range + battle_config.mob_skill_add_range < distance(md->bl_x, md->bl_y, md->skillx, md->skilly))
+ if (range + battle_config.monster_skill_add_range < distance(md->bl_x, md->bl_y, md->skillx, md->skilly))
return;
md->skilldelayup[md->skillidx - &mob_db[md->mob_class].skills.front()] = tick;
- if (battle_config.mob_skill_log == 1)
+ if (battle_config.monster_skill_log == 1)
PRINTF("MOB skill castend skill=%d, mob_class = %d\n",
md->skillid, md->mob_class);
mob_stop_walking(md, 0);
@@ -3107,7 +3107,7 @@ int mobskill_use_id(dumb_ptr<mob_data> md, dumb_ptr<block_list> target,
md->state.skillcastcancel = ms->cancel;
md->skilldelayup[ms - &mob_db[md->mob_class].skills.front()] = gettick();
- if (battle_config.mob_skill_log == 1)
+ if (battle_config.monster_skill_log == 1)
PRINTF("MOB skill use target_id=%d skill=%d lv=%d cast=%d, mob_class = %d\n",
target->bl_id, skill_id, skill_lv,
static_cast<uint32_t>(casttime.count()), md->mob_class);
@@ -3178,7 +3178,7 @@ int mobskill_use_pos(dumb_ptr<mob_data> md,
md->skilldelayup[ms - &mob_db[md->mob_class].skills.front()] = gettick();
md->state.skillcastcancel = ms->cancel;
- if (battle_config.mob_skill_log == 1)
+ if (battle_config.monster_skill_log == 1)
PRINTF("MOB skill use target_pos= (%d,%d) skill=%d lv=%d cast=%d, mob_class = %d\n",
skill_x, skill_y, skill_id, skill_lv,
static_cast<uint32_t>(casttime.count()), md->mob_class);
diff --git a/src/map/pc.cpp b/src/map/pc.cpp
index 7b0af59..5fdb390 100644
--- a/src/map/pc.cpp
+++ b/src/map/pc.cpp
@@ -583,8 +583,8 @@ int pc_isequip(dumb_ptr<map_session_data> sd, int n)
item = sd->inventory_data[n];
sc_data = battle_get_sc_data(sd);
- if (battle_config.gm_allequip > 0
- && pc_isGM(sd) >= battle_config.gm_allequip)
+ if (battle_config.gm_all_equipment > 0
+ && pc_isGM(sd) >= battle_config.gm_all_equipment)
return 1;
if (item == NULL)
@@ -609,8 +609,6 @@ int pc_authok(int id, int login_id2, TimeT connect_until_time,
struct party *p;
tick_t tick = gettick();
- struct sockaddr_in sai;
- socklen_t sa_len = sizeof(struct sockaddr);
sd = map_id2sd(id);
if (sd == NULL)
@@ -759,10 +757,6 @@ int pc_authok(int id, int login_id2, TimeT connect_until_time,
sd->packet_flood_reset_due = TimeT();
sd->packet_flood_in = 0;
- // Obtain IP address (if they are still connected)
- if (!getpeername(sd->fd, reinterpret_cast<struct sockaddr *>(&sai), &sa_len))
- sd->ip = sai.sin_addr;
-
// message of the limited time of the account
if (connect_until_time)
{
@@ -2308,7 +2302,7 @@ int pc_setpos(dumb_ptr<map_session_data> sd,
{
if (sd->mapname_)
{
- struct in_addr ip;
+ IP4Address ip;
int port;
if (map_mapname2ipport(mapname_, &ip, &port) == 0)
{
@@ -2638,7 +2632,7 @@ int pc_stop_walking(dumb_ptr<map_session_data> sd, int type)
sd->to_y = sd->bl_y;
if (type & 0x01)
clif_fixpos(sd);
- if (type & 0x02 && battle_config.pc_damage_delay)
+ if (type & 0x02 && battle_config.player_damage_delay)
{
tick_t tick = gettick();
interval_t delay = battle_get_dmotion(sd);
@@ -2794,7 +2788,7 @@ void pc_attack_timer(TimerData *, tick_t tick, int id)
if (opt != NULL && bool(*opt & Option::REAL_ANY_HIDE))
return;
- if (!battle_config.sdelay_attack_enable)
+ if (!battle_config.skill_delay_attack_enable)
{
if (tick < sd->canact_tick)
{
@@ -2837,7 +2831,7 @@ void pc_attack_timer(TimerData *, tick_t tick, int id)
}
else
{
- if (battle_config.pc_attack_direction_change)
+ if (battle_config.player_attack_direction_change)
sd->dir = sd->head_dir = map_calc_dir(sd, bl->bl_x, bl->bl_y); // 向き設定
if (sd->walktimer)
@@ -5207,7 +5201,7 @@ void pc_autosave(TimerData *, tick_t)
if (save_flag == 0)
last_save_fd = 0;
- interval_t interval = autosave_interval / (clif_countusers() + 1);
+ interval_t interval = autosave_time / (clif_countusers() + 1);
if (interval <= interval_t::zero())
interval = std::chrono::milliseconds(1);
Timer(gettick() + interval,
@@ -5265,7 +5259,7 @@ int do_init_pc(void)
pc_natural_heal,
NATURAL_HEAL_INTERVAL
).detach();
- Timer(gettick() + autosave_interval,
+ Timer(gettick() + autosave_time,
pc_autosave
).detach();
diff --git a/src/map/script.cpp b/src/map/script.cpp
index 5e96a9f..f7eecca 100644
--- a/src/map/script.cpp
+++ b/src/map/script.cpp
@@ -66,7 +66,7 @@ Map<ScriptLabel, int> scriptlabel_db;
UPMap<FString, const ScriptBuffer> userfunc_db;
static
-const char *pos[11] =
+const char *pos_str[11] =
{
"Head",
"Body",
@@ -2227,13 +2227,13 @@ void builtin_getequipname(ScriptState *st)
{
item = sd->inventory_data[i];
if (item)
- buf = STRPRINTF("%s-[%s]", pos[num - 1], item->jname);
+ buf = STRPRINTF("%s-[%s]", pos_str[num - 1], item->jname);
else
- buf = STRPRINTF("%s-[%s]", pos[num - 1], pos[10]);
+ buf = STRPRINTF("%s-[%s]", pos_str[num - 1], pos_str[10]);
}
else
{
- buf = STRPRINTF("%s-[%s]", pos[num - 1], pos[10]);
+ buf = STRPRINTF("%s-[%s]", pos_str[num - 1], pos_str[10]);
}
push_str(st->stack, ByteCode::STR, dumb_string::copys(buf));
diff --git a/src/map/skill.cpp b/src/map/skill.cpp
index 7489731..f868b41 100644
--- a/src/map/skill.cpp
+++ b/src/map/skill.cpp
@@ -582,7 +582,7 @@ interval_t skill_castfix(dumb_ptr<block_list> bl, interval_t interval)
interval * castrate * (battle_config.castrate_dex_scale -
dex) / (battle_config.castrate_dex_scale *
100);
- interval = interval * battle_config.cast_rate / 100;
+ interval = interval * battle_config.casting_rate / 100;
}
return std::max(interval, interval_t::zero());