summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/char/char.c82
-rw-r--r--src/char/inter.c8
-rw-r--r--src/char/loginif.c7
-rw-r--r--src/common/socket.c93
-rw-r--r--src/common/socket.h42
-rw-r--r--src/login/login.c51
-rw-r--r--src/login/loginlog_sql.c4
-rw-r--r--src/map/atcommand.c4
-rw-r--r--src/map/channel.c2
-rw-r--r--src/map/chrif.c36
-rw-r--r--src/map/clif.c47
-rw-r--r--src/map/irc-bot.c10
-rw-r--r--src/map/map.c4
-rw-r--r--src/map/pc.c4
-rw-r--r--src/map/script.c2
-rw-r--r--src/map/trade.c4
16 files changed, 190 insertions, 210 deletions
diff --git a/src/char/char.c b/src/char/char.c
index e70a4b762..52c560373 100644
--- a/src/char/char.c
+++ b/src/char/char.c
@@ -2208,7 +2208,7 @@ void char_disconnect_player(int account_id)
// disconnect player if online on char-server
ARR_FIND( 0, sockt->fd_max, i, session[i] && (sd = (struct char_session_data*)session[i]->session_data) && sd->account_id == account_id );
if( i < sockt->fd_max )
- set_eof(i);
+ sockt->eof(i);
}
void char_authfail_fd(int fd, int type)
@@ -2280,7 +2280,7 @@ int char_parse_fromlogin_connection_state(int fd)
ShowError("The server communication passwords (default s1/p1) are probably invalid.\n");
ShowError("Also, please make sure your login db has the correct communication username/passwords and the gender of the account is S.\n");
ShowError("The communication passwords are set in /conf/map-server.conf and /conf/char-server.conf\n");
- set_eof(fd);
+ sockt->eof(fd);
return 1;
} else {
ShowStatus("Connected to login-server (connection #%d).\n", fd);
@@ -2315,7 +2315,7 @@ void char_parse_fromlogin_auth_state(int fd)
unsigned int expiration_time = RFIFOL(fd, 29);
RFIFOSKIP(fd,33);
- if( session_isActive(request_id) && (sd=(struct char_session_data*)session[request_id]->session_data) &&
+ if (sockt->session_is_active(request_id) && (sd=(struct char_session_data*)session[request_id]->session_data) &&
!sd->auth && sd->account_id == account_id && sd->login_id1 == login_id1 && sd->login_id2 == login_id2 && sd->sex == sex )
{
int client_fd = request_id;
@@ -2536,7 +2536,7 @@ void char_parse_fromlogin_kick(int fd)
if( i < sockt->fd_max )
{
chr->authfail_fd(i, 2);
- set_eof(i);
+ sockt->eof(i);
}
else // still moving to the map-server
chr->set_char_offline(-1, aid);
@@ -2561,11 +2561,11 @@ void char_parse_fromlogin_update_ip(int fd)
WBUFW(buf,0) = 0x2b1e;
mapif->sendall(buf, 2);
- new_ip = host2ip(login_ip_str);
+ new_ip = sockt->host2ip(login_ip_str);
if (new_ip && new_ip != login_ip)
login_ip = new_ip; //Update login ip, too.
- new_ip = host2ip(char_ip_str);
+ new_ip = sockt->host2ip(char_ip_str);
if (new_ip && new_ip != chr->ip) {
//Update ip.
chr->ip = new_ip;
@@ -2596,18 +2596,18 @@ int char_parse_fromlogin(int fd) {
// only process data from the login-server
if( fd != chr->login_fd ) {
ShowDebug("chr->parse_fromlogin: Disconnecting invalid session #%d (is not the login-server)\n", fd);
- do_close(fd);
+ sockt->close(fd);
return 0;
}
if( session[fd]->flag.eof ) {
- do_close(fd);
+ sockt->close(fd);
chr->login_fd = -1;
loginif->on_disconnect();
return 0;
} else if ( session[fd]->flag.ping ) {/* we've reached stall time */
if( DIFF_TICK(sockt->last_tick, session[fd]->rdata_tick) > (sockt->stall_time * 2) ) {/* we can't wait any longer */
- set_eof(fd);
+ sockt->eof(fd);
return 0;
} else if( session[fd]->flag.ping != 2 ) { /* we haven't sent ping out yet */
chr->ping_login_server(fd);
@@ -2713,7 +2713,7 @@ int char_parse_fromlogin(int fd) {
default:
ShowError("Unknown packet 0x%04x received from login-server, disconnecting.\n", command);
- set_eof(fd);
+ sockt->eof(fd);
return 0;
}
}
@@ -2940,7 +2940,7 @@ void mapif_server_destroy(int id)
{
if( chr->server[id].fd == -1 )
{
- do_close(chr->server[id].fd);
+ sockt->close(chr->server[id].fd);
chr->server[id].fd = -1;
}
}
@@ -3296,7 +3296,7 @@ void char_parse_frommap_change_map_server(int fd)
char_data = (struct mmo_charstatus*)uidb_get(chr->char_db_,RFIFOL(fd,14));
}
- if (runflag == CHARSERVER_ST_RUNNING && session_isActive(map_fd) && char_data) {
+ if (runflag == CHARSERVER_ST_RUNNING && sockt->session_is_active(map_fd) && char_data) {
//Send the map server the auth of this player.
struct online_char_data* data;
struct char_auth_node* node;
@@ -3824,14 +3824,14 @@ void char_parse_frommap_request_stats_report(int fd)
opt.silent = 1;
opt.setTimeo = 1;
- if( (sfd = make_connection(host2ip("stats.herc.ws"),(uint16)25427,&opt) ) == -1 ) {
+ if ((sfd = sockt->make_connection(sockt->host2ip("stats.herc.ws"),(uint16)25427,&opt) ) == -1) {
RFIFOSKIP(fd, RFIFOW(fd,2) );/* skip this packet */
RFIFOFLUSH(fd);
return;/* connection not possible, we drop the report */
}
session[sfd]->flag.server = 1;/* to ensure we won't drop our own packet */
- realloc_fifo(sfd, FIFOSIZE_SERVERLINK, FIFOSIZE_SERVERLINK);
+ sockt->realloc_fifo(sfd, FIFOSIZE_SERVERLINK, FIFOSIZE_SERVERLINK);
WFIFOHEAD(sfd, RFIFOW(fd,2) );
@@ -3840,7 +3840,7 @@ void char_parse_frommap_request_stats_report(int fd)
WFIFOSET(sfd, RFIFOW(fd,2) );
do {
- flush_fifo(sfd);
+ sockt->flush(sfd);
#ifdef WIN32
Sleep(1);
#else
@@ -3848,7 +3848,7 @@ void char_parse_frommap_request_stats_report(int fd)
#endif
} while( !session[sfd]->flag.eof && session[sfd]->wdata_size );
- do_close(sfd);
+ sockt->close(sfd);
RFIFOSKIP(fd, RFIFOW(fd,2) );/* skip this packet */
RFIFOFLUSH(fd);
@@ -3894,11 +3894,11 @@ int char_parse_frommap(int fd)
ARR_FIND( 0, ARRAYLENGTH(chr->server), id, chr->server[id].fd == fd );
if( id == ARRAYLENGTH(chr->server) ) {// not a map server
ShowDebug("chr->parse_frommap: Disconnecting invalid session #%d (is not a map-server)\n", fd);
- do_close(fd);
+ sockt->close(fd);
return 0;
}
if( session[fd]->flag.eof ) {
- do_close(fd);
+ sockt->close(fd);
chr->server[id].fd = -1;
mapif->on_disconnect(id);
return 0;
@@ -4113,7 +4113,7 @@ int char_parse_frommap(int fd)
// no inter server packet. no char server packet -> disconnect
ShowError("Unknown packet 0x%04x from map server, disconnecting.\n", RFIFOW(fd,0));
- set_eof(fd);
+ sockt->eof(fd);
return 0;
}
} // switch
@@ -4497,7 +4497,7 @@ void char_send_map_info(int fd, int i, uint32 subnet_map_ip, struct mmo_charstat
WFIFOL(fd,2) = cd->char_id;
mapindex->getmapname_ext(mapindex_id2name(cd->last_point.map), (char*)WFIFOP(fd,6));
WFIFOL(fd,22) = htonl((subnet_map_ip) ? subnet_map_ip : chr->server[i].ip);
- WFIFOW(fd,26) = ntows(htons(chr->server[i].port)); // [!] LE byte order here [!]
+ WFIFOW(fd,26) = sockt->ntows(htons(chr->server[i].port)); // [!] LE byte order here [!]
WFIFOSET(fd,28);
}
@@ -4977,7 +4977,7 @@ void char_parse_char_login_map_server(int fd, uint32 ipl)
chr->server[i].users = 0;
session[fd]->func_parse = chr->parse_frommap;
session[fd]->flag.server = 1;
- realloc_fifo(fd, FIFOSIZE_SERVERLINK, FIFOSIZE_SERVERLINK);
+ sockt->realloc_fifo(fd, FIFOSIZE_SERVERLINK, FIFOSIZE_SERVERLINK);
chr->mapif_init(fd);
}
sockt->datasync(fd, true);
@@ -5052,8 +5052,8 @@ void char_parse_char_move_character(int fd, struct char_session_data* sd)
int char_parse_char_unknown_packet(int fd, uint32 ipl)
{
- ShowError("chr->parse_char: Received unknown packet "CL_WHITE"0x%x"CL_RESET" from ip '"CL_WHITE"%s"CL_RESET"'! Disconnecting!\n", RFIFOW(fd,0), ip2str(ipl, NULL));
- set_eof(fd);
+ ShowError("chr->parse_char: Received unknown packet "CL_WHITE"0x%x"CL_RESET" from ip '"CL_WHITE"%s"CL_RESET"'! Disconnecting!\n", RFIFOW(fd,0), sockt->ip2str(ipl, NULL));
+ sockt->eof(fd);
return 1;
}
@@ -5067,7 +5067,7 @@ int char_parse_char(int fd)
// disconnect any player if no login-server.
if(chr->login_fd < 0)
- set_eof(fd);
+ sockt->eof(fd);
if(session[fd]->flag.eof)
{
@@ -5079,7 +5079,7 @@ int char_parse_char(int fd)
if( data == NULL || data->server == -1) //If it is not in any server, send it offline. [Skotlex]
chr->set_char_offline(-1,sd->account_id);
}
- do_close(fd);
+ sockt->close(fd);
return 0;
}
@@ -5393,14 +5393,14 @@ int char_check_connect_login_server(int tid, int64 tick, int id, intptr_t data)
ShowInfo("Attempt to connect to login-server...\n");
- if ( (chr->login_fd = make_connection(login_ip, login_port, NULL)) == -1) { //Try again later. [Skotlex]
+ if ((chr->login_fd = sockt->make_connection(login_ip, login_port, NULL)) == -1) { //Try again later. [Skotlex]
chr->login_fd = 0;
return 0;
}
session[chr->login_fd]->func_parse = chr->parse_fromlogin;
session[chr->login_fd]->flag.server = 1;
- realloc_fifo(chr->login_fd, FIFOSIZE_SERVERLINK, FIFOSIZE_SERVERLINK);
+ sockt->realloc_fifo(chr->login_fd, FIFOSIZE_SERVERLINK, FIFOSIZE_SERVERLINK);
loginif->connect_to_server();
@@ -5593,27 +5593,27 @@ int char_config_read(const char* cfgName)
safestrncpy(wisp_server_name, w2, sizeof(wisp_server_name));
}
} else if (strcmpi(w1, "login_ip") == 0) {
- login_ip = host2ip(w2);
+ login_ip = sockt->host2ip(w2);
if (login_ip) {
char ip_str[16];
safestrncpy(login_ip_str, w2, sizeof(login_ip_str));
- ShowStatus("Login server IP address : %s -> %s\n", w2, ip2str(login_ip, ip_str));
+ ShowStatus("Login server IP address : %s -> %s\n", w2, sockt->ip2str(login_ip, ip_str));
}
} else if (strcmpi(w1, "login_port") == 0) {
login_port = atoi(w2);
} else if (strcmpi(w1, "char_ip") == 0) {
- chr->ip = host2ip(w2);
+ chr->ip = sockt->host2ip(w2);
if (chr->ip) {
char ip_str[16];
safestrncpy(char_ip_str, w2, sizeof(char_ip_str));
- ShowStatus("Character server IP address : %s -> %s\n", w2, ip2str(chr->ip, ip_str));
+ ShowStatus("Character server IP address : %s -> %s\n", w2, sockt->ip2str(chr->ip, ip_str));
}
} else if (strcmpi(w1, "bind_ip") == 0) {
- bind_ip = host2ip(w2);
+ bind_ip = sockt->host2ip(w2);
if (bind_ip) {
char ip_str[16];
safestrncpy(bind_ip_str, w2, sizeof(bind_ip_str));
- ShowStatus("Character server binding IP address : %s -> %s\n", w2, ip2str(bind_ip, ip_str));
+ ShowStatus("Character server binding IP address : %s -> %s\n", w2, sockt->ip2str(bind_ip, ip_str));
}
} else if (strcmpi(w1, "char_port") == 0) {
chr->port = atoi(w2);
@@ -5739,7 +5739,7 @@ int do_final(void) {
inter->final();
- flush_fifos();
+ sockt->flush_fifos();
do_final_mapif();
loginif->final();
@@ -5752,7 +5752,7 @@ int do_final(void) {
auth_db->destroy(auth_db, NULL);
if( chr->char_fd != -1 ) {
- do_close(chr->char_fd);
+ sockt->close(chr->char_fd);
chr->char_fd = -1;
}
@@ -5800,7 +5800,7 @@ void do_shutdown(void)
for( id = 0; id < ARRAYLENGTH(chr->server); ++id )
mapif->server_reset(id);
loginif->check_shutdown();
- flush_fifos();
+ sockt->flush_fifos();
runflag = CORE_ST_STOP;
}
}
@@ -5919,7 +5919,7 @@ int do_init(int argc, char **argv) {
if ((sockt->naddr_ != 0) && (!login_ip || !chr->ip)) {
char ip_str[16];
- ip2str(sockt->addr_[0], ip_str);
+ sockt->ip2str(sockt->addr_[0], ip_str);
if (sockt->naddr_ > 1)
ShowStatus("Multiple interfaces detected.. using %s as our IP address\n", ip_str);
@@ -5927,11 +5927,11 @@ int do_init(int argc, char **argv) {
ShowStatus("Defaulting to %s as our IP address\n", ip_str);
if (!login_ip) {
safestrncpy(login_ip_str, ip_str, sizeof(login_ip_str));
- login_ip = str2ip(login_ip_str);
+ login_ip = sockt->str2ip(login_ip_str);
}
if (!chr->ip) {
safestrncpy(char_ip_str, ip_str, sizeof(char_ip_str));
- chr->ip = str2ip(char_ip_str);
+ chr->ip = sockt->str2ip(char_ip_str);
}
}
@@ -5962,9 +5962,9 @@ int do_init(int argc, char **argv) {
if( SQL_ERROR == SQL->Query(inter->sql_handle, "DELETE FROM `%s` WHERE `guild_id` = '0' AND `account_id` = '0' AND `char_id` = '0'", guild_member_db) )
Sql_ShowDebug(inter->sql_handle);
- set_defaultparse(chr->parse_char);
+ sockt->set_defaultparse(chr->parse_char);
- if( (chr->char_fd = make_listen_bind(bind_ip,chr->port)) == -1 ) {
+ if ((chr->char_fd = sockt->make_listen_bind(bind_ip,chr->port)) == -1) {
ShowFatalError("Failed to bind to port '"CL_WHITE"%d"CL_RESET"'\n",chr->port);
exit(EXIT_FAILURE);
}
diff --git a/src/char/inter.c b/src/char/inter.c
index dbb782093..eceb649f3 100644
--- a/src/char/inter.c
+++ b/src/char/inter.c
@@ -492,7 +492,7 @@ void mapif_parse_accinfo2(bool success, int map_fd, int u_fd, int u_aid, int acc
nullpo_retv(last_ip);
nullpo_retv(lastlogin);
nullpo_retv(birthdate);
- if (map_fd <= 0 || !session_isActive(map_fd))
+ if (map_fd <= 0 || !sockt->session_is_active(map_fd))
return; // check if we have a valid fd
if (!success) {
@@ -511,7 +511,7 @@ void mapif_parse_accinfo2(bool success, int map_fd, int u_fd, int u_aid, int acc
}
inter->msg_to_fd(map_fd, u_fd, u_aid, "Account e-mail: %s | Birthdate: %s", email, birthdate);
- inter->msg_to_fd(map_fd, u_fd, u_aid, "Last IP: %s (%s)", last_ip, geoip->getcountry(str2ip(last_ip)));
+ inter->msg_to_fd(map_fd, u_fd, u_aid, "Last IP: %s (%s)", last_ip, geoip->getcountry(sockt->str2ip(last_ip)));
inter->msg_to_fd(map_fd, u_fd, u_aid, "This user has logged %d times, the last time were at %s", logincount, lastlogin);
inter->msg_to_fd(map_fd, u_fd, u_aid, "-- Character Details --");
@@ -557,7 +557,7 @@ void inter_savereg(int account_id, int char_id, const char *key, unsigned int in
nullpo_retv(key);
/* to login server we go! */
if( key[0] == '#' && key[1] == '#' ) {/* global account reg */
- if( session_isValid(chr->login_fd) )
+ if (sockt->session_is_valid(chr->login_fd))
chr->global_accreg_to_login_add(key,index,val,is_string);
else {
ShowError("Login server unavailable, cant perform update on '%s' variable for AID:%d CID:%d\n",key,account_id,char_id);
@@ -1170,7 +1170,7 @@ int mapif_parse_Registry(int fd)
if( count ) {
int cursor = 14, i;
char key[32], sval[254];
- bool isLoginActive = session_isActive(chr->login_fd);
+ bool isLoginActive = sockt->session_is_active(chr->login_fd);
if( isLoginActive )
chr->global_accreg_to_login_start(account_id,char_id);
diff --git a/src/char/loginif.c b/src/char/loginif.c
index 881c8f2ac..4eac78774 100644
--- a/src/char/loginif.c
+++ b/src/char/loginif.c
@@ -28,7 +28,7 @@ void loginif_reset(void)
// TODO kick everyone out and reset everything or wait for connect and try to reacquire locks [FlavioJS]
for( id = 0; id < ARRAYLENGTH(chr->server); ++id )
mapif->server_reset(id);
- flush_fifos();
+ sockt->flush_fifos();
exit(EXIT_FAILURE);
}
@@ -80,9 +80,8 @@ void do_init_loginif(void)
void do_final_loginif(void)
{
- if( chr->login_fd != -1 )
- {
- do_close(chr->login_fd);
+ if (chr->login_fd != -1) {
+ sockt->close(chr->login_fd);
chr->login_fd = -1;
}
}
diff --git a/src/common/socket.c b/src/common/socket.c
index 830877044..0b69743ab 100644
--- a/src/common/socket.c
+++ b/src/common/socket.c
@@ -5,9 +5,7 @@
#define HERCULES_CORE
#include "config/core.h" // SHOW_SERVER_STATS
-#define H_SOCKET_C
#include "socket.h"
-#undef H_SOCKET_C
#include "common/HPM.h"
#include "common/cbasetypes.h"
@@ -359,8 +357,7 @@ void setsocketopts(int fd, struct hSockOpt *opt) {
*--------------------------------------*/
void set_eof(int fd)
{
- if( sockt->session_isActive(fd) )
- {
+ if (sockt->session_is_active(fd)) {
#ifdef SEND_SHORTLIST
// Add this socket to the shortlist for eof handling.
send_shortlist_add_fd(fd);
@@ -373,7 +370,7 @@ int recv_to_fifo(int fd)
{
ssize_t len;
- if( !sockt->session_isActive(fd) )
+ if (!sockt->session_is_active(fd))
return -1;
len = sRecv(fd, (char *) session[fd]->rdata + session[fd]->rdata_size, (int)RFIFOSPACE(fd), 0);
@@ -382,14 +379,14 @@ int recv_to_fifo(int fd)
{//An exception has occurred
if( sErrno != S_EWOULDBLOCK ) {
//ShowDebug("recv_to_fifo: %s, closing connection #%d\n", error_msg(), fd);
- set_eof(fd);
+ sockt->eof(fd);
}
return 0;
}
if( len == 0 )
{//Normal connection end.
- set_eof(fd);
+ sockt->eof(fd);
return 0;
}
@@ -410,7 +407,7 @@ int send_from_fifo(int fd)
{
ssize_t len;
- if( !sockt->session_isValid(fd) )
+ if (!sockt->session_is_valid(fd))
return -1;
if( session[fd]->wdata_size == 0 )
@@ -426,7 +423,7 @@ int send_from_fifo(int fd)
socket_data_qo -= session[fd]->wdata_size;
#endif
session[fd]->wdata_size = 0; //Clear the send queue as we can't send anymore. [Skotlex]
- set_eof(fd);
+ sockt->eof(fd);
}
return 0;
}
@@ -463,7 +460,7 @@ void flush_fifos(void)
{
int i;
for(i = 1; i < sockt->fd_max; i++)
- sockt->flush_fifo(i);
+ sockt->flush(i);
}
/*======================================
@@ -493,7 +490,7 @@ int connect_client(int listen_fd) {
}
setsocketopts(fd,NULL);
- set_nonblocking(fd, 1);
+ sockt->set_nonblocking(fd, 1);
#ifndef MINICORE
if( ip_rules && !connect_check(ntohl(client_address.sin_addr.s_addr)) ) {
@@ -535,7 +532,7 @@ int make_listen_bind(uint32 ip, uint16 port)
}
setsocketopts(fd,NULL);
- set_nonblocking(fd, 1);
+ sockt->set_nonblocking(fd, 1);
server_address.sin_family = AF_INET;
server_address.sin_addr.s_addr = htonl(ip);
@@ -601,7 +598,7 @@ int make_connection(uint32 ip, uint16 port, struct hSockOpt *opt) {
return -1;
}
//Now the socket can be made non-blocking. [Skotlex]
- set_nonblocking(fd, 1);
+ sockt->set_nonblocking(fd, 1);
if (sockt->fd_max <= fd) sockt->fd_max = fd + 1;
sFD_SET(fd,&readfds);
@@ -631,7 +628,7 @@ static int create_session(int fd, RecvFunc func_recv, SendFunc func_send, ParseF
static void delete_session(int fd)
{
- if( sockt->session_isValid(fd) ) {
+ if (sockt->session_is_valid(fd)) {
#ifdef SHOW_SERVER_STATS
socket_data_qi -= session[fd]->rdata_size - session[fd]->rdata_pos;
socket_data_qo -= session[fd]->wdata_size;
@@ -657,7 +654,7 @@ static void delete_session(int fd)
int realloc_fifo(int fd, unsigned int rfifo_size, unsigned int wfifo_size)
{
- if( !sockt->session_isValid(fd) )
+ if (!sockt->session_is_valid(fd))
return 0;
if( session[fd]->max_rdata != rfifo_size && session[fd]->rdata_size < rfifo_size) {
@@ -676,7 +673,7 @@ int realloc_writefifo(int fd, size_t addition)
{
size_t newsize;
- if( !sockt->session_isValid(fd) ) // might not happen
+ if (!sockt->session_is_valid(fd)) // might not happen
return 0;
if (session[fd]->wdata_size + addition > session[fd]->max_wdata) {
@@ -700,11 +697,11 @@ int realloc_writefifo(int fd, size_t addition)
}
/// advance the RFIFO cursor (marking 'len' bytes as processed)
-int RFIFOSKIP(int fd, size_t len)
+int rfifoskip(int fd, size_t len)
{
struct socket_data *s;
- if ( !sockt->session_isActive(fd) )
+ if (!sockt->session_is_active(fd))
return 0;
s = session[fd];
@@ -722,12 +719,12 @@ int RFIFOSKIP(int fd, size_t len)
}
/// advance the WFIFO cursor (marking 'len' bytes for sending)
-int WFIFOSET(int fd, size_t len)
+int wfifoset(int fd, size_t len)
{
size_t newreserve;
struct socket_data* s = session[fd];
- if( !sockt->session_isValid(fd) || s->wdata == NULL )
+ if (!sockt->session_is_valid(fd) || s->wdata == NULL)
return 0;
// we have written len bytes to the buffer already before calling WFIFOSET
@@ -771,14 +768,14 @@ int WFIFOSET(int fd, size_t len)
#endif
//If the interserver has 200% of its normal size full, flush the data.
if( s->flag.server && s->wdata_size >= 2*FIFOSIZE_SERVERLINK )
- flush_fifo(fd);
+ sockt->flush(fd);
// always keep a WFIFO_SIZE reserve in the buffer
// For inter-server connections, let the reserve be 1/4th of the link size.
newreserve = s->flag.server ? FIFOSIZE_SERVERLINK / 4 : WFIFO_SIZE;
// readjust the buffer to include the chosen reserve
- realloc_writefifo(fd, newreserve);
+ sockt->realloc_writefifo(fd, newreserve);
#ifdef SEND_SHORTLIST
send_shortlist_add_fd(fd);
@@ -878,12 +875,12 @@ int do_sockets(int next)
session[i]->flag.ping = 1;
} else {
ShowInfo("Session #%d timed out\n", i);
- set_eof(i);
+ sockt->eof(i);
}
}
#ifdef __clang_analyzer__
- // Let Clang's static analyzer know this never happens (it thinks it might because of a NULL check in session_isValid)
+ // Let Clang's static analyzer know this never happens (it thinks it might because of a NULL check in session_is_valid)
if (!session[i]) continue;
#endif // __clang_analyzer__
session[i]->func_parse(i);
@@ -894,7 +891,7 @@ int do_sockets(int next)
RFIFOFLUSH(i);
// after parse, check client's RFIFO size to know if there is an invalid packet (too big and not parsed)
if (session[i]->rdata_size == session[i]->max_rdata) {
- set_eof(i);
+ sockt->eof(i);
continue;
}
}
@@ -1247,12 +1244,12 @@ void socket_final(void)
}
/// Closes a socket.
-void do_close(int fd)
+void socket_close(int fd)
{
if( fd <= 0 ||fd >= FD_SETSIZE )
return;// invalid
- flush_fifo(fd); // Try to send what's left (although it might not succeed since it's a nonblocking socket)
+ sockt->flush(fd); // Try to send what's left (although it might not succeed since it's a nonblocking socket)
sFD_CLR(fd, &readfds);// this needs to be done before closing the socket
sShutdown(fd, SHUT_RDWR); // Disallow further reads/writes
sClose(fd); // We don't really care if these closing functions return an error, we are just shutting down and not reusing this socket.
@@ -1393,7 +1390,7 @@ void socket_init(void)
#endif
// Get initial local ips
- sockt->naddr_ = socket_getips(sockt->addr_,16);
+ sockt->naddr_ = sockt->getips(sockt->addr_,16);
sFD_ZERO(&readfds);
#if defined(SEND_SHORTLIST)
@@ -1424,14 +1421,14 @@ void socket_init(void)
HPM->share(session,"session");
}
-bool session_isValid(int fd)
+bool session_is_valid(int fd)
{
return ( fd > 0 && fd < FD_SETSIZE && session[fd] != NULL );
}
-bool session_isActive(int fd)
+bool session_is_active(int fd)
{
- return ( sockt->session_isValid(fd) && !session[fd]->flag.eof );
+ return ( sockt->session_is_valid(fd) && !session[fd]->flag.eof );
}
// Resolves hostname into a numeric ip.
@@ -1441,9 +1438,15 @@ uint32 host2ip(const char* hostname)
return (h != NULL) ? ntohl(*(uint32*)h->h_addr) : 0;
}
-// Converts a numeric ip into a dot-formatted string.
-// Result is placed either into a user-provided buffer or a static system buffer.
-const char* ip2str(uint32 ip, char ip_str[16])
+/**
+ * Converts a numeric ip into a dot-formatted string.
+ *
+ * @param ip Numeric IP to convert.
+ * @param ip_str Output buffer, optional (if provided, must have size greater or equal to 16).
+ *
+ * @return A pointer to the output string.
+ */
+const char *ip2str(uint32 ip, char *ip_str)
{
struct in_addr addr;
addr.s_addr = htonl(ip);
@@ -1518,7 +1521,7 @@ void socket_datasync(int fd, bool send) {
WFIFOW(fd, 2) = 8;
WFIFOL(fd, 4) = 0;
WFIFOSET(fd, 8);
- flush_fifo(fd);
+ sockt->flush(fd);
/* shut down */
ShowFatalError("Servers are out of sync! recompile from scratch (%d)\n",i);
exit(EXIT_FAILURE);
@@ -1535,7 +1538,7 @@ void send_shortlist_add_fd(int fd)
int i;
int bit;
- if( !sockt->session_isValid(fd) )
+ if (!sockt->session_is_valid(fd))
return;// out of range
i = fd/32;
@@ -1696,8 +1699,8 @@ int socket_net_config_read_sub(config_setting_t *t, struct s_subnet **list, int
}
RECREATE(*list, struct s_subnet, *count + 1);
l = *list;
- l[*count].ip = str2ip(ipbuf);
- l[*count].mask = str2ip(maskbuf);
+ l[*count].ip = sockt->str2ip(ipbuf);
+ l[*count].mask = sockt->str2ip(maskbuf);
++*count;
}
return *count;
@@ -1792,14 +1795,14 @@ void socket_defaults(void) {
sockt->make_connection = make_connection;
sockt->realloc_fifo = realloc_fifo;
sockt->realloc_writefifo = realloc_writefifo;
- sockt->WFIFOSET = WFIFOSET;
- sockt->RFIFOSKIP = RFIFOSKIP;
- sockt->close = do_close;
+ sockt->wfifoset = wfifoset;
+ sockt->rfifoskip = rfifoskip;
+ sockt->close = socket_close;
/* */
- sockt->session_isValid = session_isValid;
- sockt->session_isActive = session_isActive;
+ sockt->session_is_valid = session_is_valid;
+ sockt->session_is_active = session_is_active;
/* */
- sockt->flush_fifo = flush_fifo;
+ sockt->flush = flush_fifo;
sockt->flush_fifos = flush_fifos;
sockt->set_nonblocking = set_nonblocking;
sockt->set_defaultparse = set_defaultparse;
@@ -1808,7 +1811,7 @@ void socket_defaults(void) {
sockt->str2ip = str2ip;
sockt->ntows = ntows;
sockt->getips = socket_getips;
- sockt->set_eof = set_eof;
+ sockt->eof = set_eof;
sockt->lan_subnet_check = socket_lan_subnet_check;
sockt->allowed_ip_check = socket_allowed_ip_check;
diff --git a/src/common/socket.h b/src/common/socket.h
index 26b674d43..e7046b0d1 100644
--- a/src/common/socket.h
+++ b/src/common/socket.h
@@ -23,7 +23,7 @@ struct HPluginData;
// socket I/O macros
#define RFIFOHEAD(fd)
-#define WFIFOHEAD(fd, size) do{ if((fd) && session[fd]->wdata_size + (size) > session[fd]->max_wdata ) realloc_writefifo((fd), (size)); }while(0)
+#define WFIFOHEAD(fd, size) do{ if((fd) && session[fd]->wdata_size + (size) > session[fd]->max_wdata ) sockt->realloc_writefifo((fd), (size)); }while(0)
#define RFIFOP(fd,pos) (session[fd]->rdata + session[fd]->rdata_pos + (pos))
#define WFIFOP(fd,pos) (session[fd]->wdata + session[fd]->wdata_size + (pos))
@@ -50,6 +50,9 @@ struct HPluginData;
} \
} while(0)
+#define WFIFOSET(fd, len) (sockt->wfifoset(fd, len))
+#define RFIFOSKIP(fd, len) (sockt->rfifoskip(fd, len))
+
/* [Ind/Hercules] */
#define RFIFO2PTR(fd) (void*)(session[fd]->rdata + session[fd]->rdata_pos)
@@ -159,27 +162,27 @@ struct socket_interface {
int (*make_connection) (uint32 ip, uint16 port, struct hSockOpt *opt);
int (*realloc_fifo) (int fd, unsigned int rfifo_size, unsigned int wfifo_size);
int (*realloc_writefifo) (int fd, size_t addition);
- int (*WFIFOSET) (int fd, size_t len);
- int (*RFIFOSKIP) (int fd, size_t len);
+ int (*wfifoset) (int fd, size_t len);
+ int (*rfifoskip) (int fd, size_t len);
void (*close) (int fd);
/* */
- bool (*session_isValid) (int fd);
- bool (*session_isActive) (int fd);
+ bool (*session_is_valid) (int fd);
+ bool (*session_is_active) (int fd);
/* */
- void (*flush_fifo) (int fd);
+ void (*flush) (int fd);
void (*flush_fifos) (void);
void (*set_nonblocking) (int fd, unsigned long yes);
void (*set_defaultparse) (ParseFunc defaultparse);
/* hostname/ip conversion functions */
uint32 (*host2ip) (const char* hostname);
- const char * (*ip2str) (uint32 ip, char ip_str[16]);
+ const char * (*ip2str) (uint32 ip, char *ip_str);
uint32 (*str2ip) (const char* ip_str);
/* */
uint16 (*ntows) (uint16 netshort);
/* */
int (*getips) (uint32* ips, int max);
/* */
- void (*set_eof) (int fd);
+ void (*eof) (int fd);
uint32 (*lan_subnet_check) (uint32 ip, struct s_subnet *info);
bool (*allowed_ip_check) (uint32 ip);
@@ -194,27 +197,4 @@ struct socket_interface *sockt;
void socket_defaults(void);
#endif // HERCULES_CORE
-/* the purpose of these macros is simply to not make calling them be an annoyance */
-#ifndef H_SOCKET_C
- #define make_listen_bind(ip, port) ( sockt->make_listen_bind(ip, port) )
- #define make_connection(ip, port, opt) ( sockt->make_connection(ip, port, opt) )
- #define realloc_fifo(fd, rfifo_size, wfifo_size) ( sockt->realloc_fifo(fd, rfifo_size, wfifo_size) )
- #define realloc_writefifo(fd, addition) ( sockt->realloc_writefifo(fd, addition) )
- #define WFIFOSET(fd, len) ( sockt->WFIFOSET(fd, len) )
- #define RFIFOSKIP(fd, len) ( sockt->RFIFOSKIP(fd, len) )
- #define do_close(fd) ( sockt->close(fd) )
- #define session_isValid(fd) ( sockt->session_isValid(fd) )
- #define session_isActive(fd) ( sockt->session_isActive(fd) )
- #define flush_fifo(fd) ( sockt->flush_fifo(fd) )
- #define flush_fifos() ( sockt->flush_fifos() )
- #define set_nonblocking(fd, yes) ( sockt->set_nonblocking(fd, yes) )
- #define set_defaultparse(defaultparse) ( sockt->set_defaultparse(defaultparse) )
- #define host2ip(hostname) ( sockt->host2ip(hostname) )
- #define ip2str(ip, ip_str) ( sockt->ip2str(ip, ip_str) )
- #define str2ip(ip_str) ( sockt->str2ip(ip_str) )
- #define ntows(netshort) ( sockt->ntows(netshort) )
- #define getips(ips, max) ( sockt->getips(ips, max) )
- #define set_eof(fd) ( sockt->set_eof(fd) )
-#endif /* H_SOCKET_C */
-
#endif /* COMMON_SOCKET_H */
diff --git a/src/login/login.c b/src/login/login.c
index 141ab5e2b..3109e80fd 100644
--- a/src/login/login.c
+++ b/src/login/login.c
@@ -144,8 +144,7 @@ int charif_sendallwos(int sfd, uint8* buf, size_t len)
for( i = 0, c = 0; i < ARRAYLENGTH(server); ++i )
{
int fd = server[i].fd;
- if( session_isValid(fd) && fd != sfd )
- {
+ if (sockt->session_is_valid(fd) && fd != sfd) {
WFIFOHEAD(fd,len);
memcpy(WFIFOP(fd,0), buf, len);
WFIFOSET(fd,len);
@@ -172,7 +171,7 @@ void chrif_server_destroy(int id)
Assert_retv(id >= 0 && id < MAX_SERVERS);
if (server[id].fd != -1)
{
- do_close(server[id].fd);
+ sockt->close(server[id].fd);
server[id].fd = -1;
}
}
@@ -703,7 +702,7 @@ bool login_fromchar_parse_wrong_pincode(int fd)
return true;
}
- login_log(host2ip(acc.last_ip), acc.userid, 100, "PIN Code check failed"); // FIXME: Do we really want to log this with the same code as successful logins?
+ login_log(sockt->host2ip(acc.last_ip), acc.userid, 100, "PIN Code check failed"); // FIXME: Do we really want to log this with the same code as successful logins?
}
login->remove_online_user(acc.account_id);
@@ -776,21 +775,21 @@ int login_parse_fromchar(int fd)
if( id == ARRAYLENGTH(server) )
{// not a char server
ShowDebug("login_parse_fromchar: Disconnecting invalid session #%d (is not a char-server)\n", fd);
- set_eof(fd);
- do_close(fd);
+ sockt->eof(fd);
+ sockt->close(fd);
return 0;
}
if( session[fd]->flag.eof )
{
- do_close(fd);
+ sockt->close(fd);
server[id].fd = -1;
chrif_on_disconnect(id);
return 0;
}
ipl = server[id].ip;
- ip2str(ipl, ip);
+ sockt->ip2str(ipl, ip);
while( RFIFOREST(fd) >= 2 ) {
uint16 command = RFIFOW(fd,0);
@@ -954,7 +953,7 @@ int login_parse_fromchar(int fd)
break;
default:
ShowError("login_parse_fromchar: Unknown packet 0x%x from a char-server! Disconnecting!\n", command);
- set_eof(fd);
+ sockt->eof(fd);
return 0;
} // switch
} // while
@@ -1034,7 +1033,7 @@ int login_mmo_auth(struct login_session_data* sd, bool isServer) {
char ip[16];
nullpo_ret(sd);
- ip2str(session[sd->fd]->client_addr, ip);
+ sockt->ip2str(session[sd->fd]->client_addr, ip);
// DNS Blacklist check
if( login_config.use_dnsbl ) {
@@ -1047,7 +1046,7 @@ int login_mmo_auth(struct login_session_data* sd, bool isServer) {
for( dnsbl_serv = strtok(login_config.dnsbl_servs,","); dnsbl_serv != NULL; dnsbl_serv = strtok(NULL,",") ) {
sprintf(ip_dnsbl, "%s.%s", r_ip, trim(dnsbl_serv));
- if( host2ip(ip_dnsbl) ) {
+ if (sockt->host2ip(ip_dnsbl)) {
ShowInfo("DNSBL: (%s) Blacklisted. User Kicked.\n", r_ip);
return 3;
}
@@ -1211,7 +1210,7 @@ void login_auth_ok(struct login_session_data* sd)
server_num = 0;
for( i = 0; i < ARRAYLENGTH(server); ++i )
- if( session_isActive(server[i].fd) )
+ if (sockt->session_is_active(server[i].fd))
server_num++;
if( server_num == 0 )
@@ -1263,12 +1262,12 @@ void login_auth_ok(struct login_session_data* sd)
for (i = 0, n = 0; i < ARRAYLENGTH(server); ++i) {
uint32 subnet_char_ip;
- if( !session_isValid(server[i].fd) )
+ if (!sockt->session_is_valid(server[i].fd))
continue;
subnet_char_ip = login->lan_subnet_check(ip);
WFIFOL(fd,47+n*32) = htonl((subnet_char_ip) ? subnet_char_ip : server[i].ip);
- WFIFOW(fd,47+n*32+4) = ntows(htons(server[i].port)); // [!] LE byte order here [!]
+ WFIFOW(fd,47+n*32+4) = sockt->ntows(htons(server[i].port)); // [!] LE byte order here [!]
memcpy(WFIFOP(fd,47+n*32+6), server[i].name, 20);
WFIFOW(fd,47+n*32+26) = server[i].users;
@@ -1542,7 +1541,7 @@ void login_parse_request_connection(int fd, struct login_session_data* sd, const
sd->sex == 'S' &&
sd->account_id >= 0 &&
sd->account_id < ARRAYLENGTH(server) &&
- !session_isValid(server[sd->account_id].fd) &&
+ !sockt->session_is_valid(server[sd->account_id].fd) &&
sockt->allowed_ip_check(ipl))
{
ShowStatus("Connection of the char-server '%s' accepted.\n", server_name);
@@ -1556,7 +1555,7 @@ void login_parse_request_connection(int fd, struct login_session_data* sd, const
session[fd]->func_parse = login->parse_fromchar;
session[fd]->flag.server = 1;
- realloc_fifo(fd, FIFOSIZE_SERVERLINK, FIFOSIZE_SERVERLINK);
+ sockt->realloc_fifo(fd, FIFOSIZE_SERVERLINK, FIFOSIZE_SERVERLINK);
// send connection success
login->char_server_connection_status(fd, sd, 0);
@@ -1578,12 +1577,12 @@ int login_parse_login(int fd)
char ip[16];
uint32 ipl = session[fd]->client_addr;
- ip2str(ipl, ip);
+ sockt->ip2str(ipl, ip);
if( session[fd]->flag.eof )
{
ShowInfo("Closed connection from '"CL_WHITE"%s"CL_RESET"'.\n", ip);
- do_close(fd);
+ sockt->close(fd);
return 0;
}
@@ -1595,7 +1594,7 @@ int login_parse_login(int fd)
ShowStatus("Connection refused: IP isn't authorized (deny/allow, ip: %s).\n", ip);
login_log(ipl, "unknown", -3, "ip banned");
login->login_error(fd, 3); // 3 = Rejected from Server
- set_eof(fd);
+ sockt->eof(fd);
return 0;
}
@@ -1675,7 +1674,7 @@ int login_parse_login(int fd)
default:
ShowNotice("Abnormal end of connection (ip: %s): Unknown packet 0x%x\n", ip, command);
- set_eof(fd);
+ sockt->eof(fd);
return 0;
}
}
@@ -1744,10 +1743,10 @@ int login_config_read(const char* cfgName)
ShowInfo("Console Silent Setting: %d\n", atoi(w2));
}
else if( !strcmpi(w1, "bind_ip") ) {
- login_config.login_ip = host2ip(w2);
+ login_config.login_ip = sockt->host2ip(w2);
if( login_config.login_ip ) {
char ip_str[16];
- ShowStatus("Login server binding IP address : %s -> %s\n", w2, ip2str(login_config.login_ip, ip_str));
+ ShowStatus("Login server binding IP address : %s -> %s\n", w2, sockt->ip2str(login_config.login_ip, ip_str));
}
}
else if( !strcmpi(w1, "login_port") ) {
@@ -1874,7 +1873,7 @@ int do_final(void) {
if( login->fd != -1 )
{
- do_close(login->fd);
+ sockt->close(login->fd);
login->fd = -1;
}
@@ -1913,7 +1912,7 @@ void do_shutdown_login(void)
// TODO proper shutdown procedure; kick all characters, wait for acks, ... [FlavioJS]
for( id = 0; id < ARRAYLENGTH(server); ++id )
chrif_server_reset(id);
- flush_fifos();
+ sockt->flush_fifos();
runflag = CORE_ST_STOP;
}
}
@@ -2007,7 +2006,7 @@ int do_init(int argc, char** argv)
login->auth_db = idb_alloc(DB_OPT_RELEASE_DATA);
// set default parser as login_parse_login function
- set_defaultparse(login->parse_login);
+ sockt->set_defaultparse(login->parse_login);
// every 10 minutes cleanup online account db.
timer->add_func_list(login->online_data_cleanup, "login->online_data_cleanup");
@@ -2028,7 +2027,7 @@ int do_init(int argc, char** argv)
HPM->event(HPET_INIT);
// server port open & binding
- if( (login->fd = make_listen_bind(login_config.login_ip,login_config.login_port)) == -1 ) {
+ if ((login->fd = sockt->make_listen_bind(login_config.login_ip,login_config.login_port)) == -1) {
ShowFatalError("Failed to bind to port '"CL_WHITE"%d"CL_RESET"'\n",login_config.login_port);
exit(EXIT_FAILURE);
}
diff --git a/src/login/loginlog_sql.c b/src/login/loginlog_sql.c
index da698e187..d26d910de 100644
--- a/src/login/loginlog_sql.c
+++ b/src/login/loginlog_sql.c
@@ -44,7 +44,7 @@ unsigned long loginlog_failedattempts(uint32 ip, unsigned int minutes)
return 0;
if( SQL_ERROR == SQL->Query(sql_handle, "SELECT count(*) FROM `%s` WHERE `ip` = '%s' AND `rcode` = '1' AND `time` > NOW() - INTERVAL %d MINUTE",
- log_login_db, ip2str(ip,NULL), minutes) )// how many times failed account? in one ip.
+ log_login_db, sockt->ip2str(ip,NULL), minutes) )// how many times failed account? in one ip.
Sql_ShowDebug(sql_handle);
if( SQL_SUCCESS == SQL->NextRow(sql_handle) )
@@ -78,7 +78,7 @@ void login_log(uint32 ip, const char* username, int rcode, const char* message)
retcode = SQL->Query(sql_handle,
"INSERT INTO `%s`(`time`,`ip`,`user`,`rcode`,`log`) VALUES (NOW(), '%s', '%s', '%d', '%s')",
- log_login_db, ip2str(ip,NULL), esc_username, rcode, esc_message);
+ log_login_db, sockt->ip2str(ip,NULL), esc_username, rcode, esc_message);
if( retcode != SQL_SUCCESS )
Sql_ShowDebug(sql_handle);
diff --git a/src/map/atcommand.c b/src/map/atcommand.c
index fb0b89381..b84546054 100644
--- a/src/map/atcommand.c
+++ b/src/map/atcommand.c
@@ -83,7 +83,7 @@ const char* atcommand_msgsd(struct map_session_data *sd, int msg_number) {
}
const char* atcommand_msgfd(int fd, int msg_number) {
- struct map_session_data *sd = session_isValid(fd) ? session[fd]->session_data : NULL;
+ struct map_session_data *sd = sockt->session_is_valid(fd) ? session[fd]->session_data : NULL;
if( !(msg_number >= 0 && msg_number < MAX_MSG) )
return "??";
if( !sd || sd->lang_id >= atcommand->max_message_table || !atcommand->msg_table[sd->lang_id][msg_number] )
@@ -3676,7 +3676,7 @@ ACMD(reloadscript) {
}
mapit->free(iter);
- flush_fifos();
+ sockt->flush_fifos();
map->reloadnpc(true); // reload config files seeking for npcs
script->reload();
npc->reload();
diff --git a/src/map/channel.c b/src/map/channel.c
index 69f7ab872..ab6694345 100644
--- a/src/map/channel.c
+++ b/src/map/channel.c
@@ -301,7 +301,7 @@ void channel_join_sub(struct channel_data *chan, struct map_session_data *sd, bo
/* someone is cheating, we kindly disconnect the bastard */
if (sd->channel_count > 200) {
- set_eof(sd->fd);
+ sockt->eof(sd->fd);
}
}
diff --git a/src/map/chrif.c b/src/map/chrif.c
index 5bd1e436f..f9b6af7f7 100644
--- a/src/map/chrif.c
+++ b/src/map/chrif.c
@@ -219,14 +219,14 @@ void chrif_checkdefaultlogin(void) {
bool chrif_setip(const char* ip) {
char ip_str[16];
- if ( !( chrif->ip = host2ip(ip) ) ) {
+ if (!(chrif->ip = sockt->host2ip(ip))) {
ShowWarning("Failed to Resolve Char Server Address! (%s)\n", ip);
return false;
}
safestrncpy(chrif->ip_str, ip, sizeof(chrif->ip_str));
- ShowInfo("Char Server IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(chrif->ip, ip_str));
+ ShowInfo("Char Server IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, sockt->ip2str(chrif->ip, ip_str));
return true;
}
@@ -542,7 +542,7 @@ void chrif_authreq(struct map_session_data *sd, bool hstandalone) {
struct auth_node *node= chrif->search(sd->bl.id);
if( node != NULL || !chrif->isconnected() ) {
- set_eof(sd->fd);
+ sockt->eof(sd->fd);
return;
}
@@ -980,7 +980,7 @@ void chrif_idbanned(int fd) {
clif->message(sd->fd, tmpstr);
}
- set_eof(sd->fd); // forced to disconnect for the change
+ sockt->eof(sd->fd); // forced to disconnect for the change
map->quit(sd); // Remove leftovers (e.g. autotrading) [Paradox924X]
}
@@ -1232,9 +1232,9 @@ bool chrif_char_offline_nsd(int account_id, int char_id) {
bool chrif_flush(void) {
chrif_check(false);
- set_nonblocking(chrif->fd, 0);
- flush_fifos();
- set_nonblocking(chrif->fd, 1);
+ sockt->set_nonblocking(chrif->fd, 0);
+ sockt->flush_fifos();
+ sockt->set_nonblocking(chrif->fd, 1);
return true;
}
@@ -1286,7 +1286,7 @@ void chrif_update_ip(int fd) {
WFIFOHEAD(fd,6);
- new_ip = host2ip(chrif->ip_str);
+ new_ip = sockt->host2ip(chrif->ip_str);
if (new_ip && new_ip != chrif->ip)
chrif->ip = new_ip; //Update chrif->ip
@@ -1315,7 +1315,7 @@ void chrif_skillid2idx(int fd) {
if( fd == 0 ) fd = chrif->fd;
- if( !session_isValid(fd) )
+ if (!sockt->session_is_valid(fd))
return;
WFIFOHEAD(fd,4 + (MAX_SKILL * 4));
@@ -1340,18 +1340,18 @@ int chrif_parse(int fd) {
// only process data from the char-server
if ( fd != chrif->fd ) {
ShowDebug("chrif_parse: Disconnecting invalid session #%d (is not the char-server)\n", fd);
- do_close(fd);
+ sockt->close(fd);
return 0;
}
if ( session[fd]->flag.eof ) {
- do_close(fd);
+ sockt->close(fd);
chrif->fd = -1;
chrif->on_disconnect();
return 0;
} else if ( session[fd]->flag.ping ) {/* we've reached stall time */
if( DIFF_TICK(sockt->last_tick, session[fd]->rdata_tick) > (sockt->stall_time * 2) ) {/* we can't wait any longer */
- set_eof(fd);
+ sockt->eof(fd);
return 0;
} else if( session[fd]->flag.ping != 2 ) { /* we haven't sent ping out yet */
chrif->keepalive(fd);
@@ -1377,7 +1377,7 @@ int chrif_parse(int fd) {
if (r == 2) return 0; // Didn't have enough data (len==-1)
ShowWarning("chrif_parse: session #%d, intif->parse failed (unrecognized command 0x%.4x).\n", fd, cmd);
- set_eof(fd);
+ sockt->eof(fd);
return 0;
}
@@ -1418,7 +1418,7 @@ int chrif_parse(int fd) {
case 0x2b27: chrif->authfail(fd); break;
default:
ShowError("chrif_parse : unknown packet (session #%d): 0x%x. Disconnecting.\n", fd, cmd);
- set_eof(fd);
+ sockt->eof(fd);
return 0;
}
if ( fd == chrif->fd ) //There's the slight chance we lost the connection during parse, in which case this would segfault if not checked [Skotlex]
@@ -1483,12 +1483,12 @@ int check_connect_char_server(int tid, int64 tick, int id, intptr_t data) {
chrif->state = 0;
- if ( ( chrif->fd = make_connection(chrif->ip, chrif->port,NULL) ) == -1) //Attempt to connect later. [Skotlex]
+ if ((chrif->fd = sockt->make_connection(chrif->ip, chrif->port,NULL)) == -1) //Attempt to connect later. [Skotlex]
return 0;
session[chrif->fd]->func_parse = chrif->parse;
session[chrif->fd]->flag.server = 1;
- realloc_fifo(chrif->fd, FIFOSIZE_SERVERLINK, FIFOSIZE_SERVERLINK);
+ sockt->realloc_fifo(chrif->fd, FIFOSIZE_SERVERLINK, FIFOSIZE_SERVERLINK);
chrif->connect(chrif->fd);
chrif->connected = (chrif->state == 2);
@@ -1529,7 +1529,7 @@ void chrif_send_report(char* buf, int len) {
WFIFOSET(chrif->fd,len + 2);
- flush_fifo(chrif->fd); /* ensure it's sent now. */
+ sockt->flush(chrif->fd); /* ensure it's sent now. */
}
#endif
}
@@ -1601,7 +1601,7 @@ int auth_db_final(DBKey key, DBData *data, va_list ap) {
void do_final_chrif(void)
{
if( chrif->fd != -1 ) {
- do_close(chrif->fd);
+ sockt->close(chrif->fd);
chrif->fd = -1;
}
diff --git a/src/map/clif.c b/src/map/clif.c
index d00cac0ee..66f245980 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -193,22 +193,22 @@ static inline unsigned int mes_len_check(char* mes, unsigned int len, unsigned i
*------------------------------------------*/
bool clif_setip(const char* ip) {
char ip_str[16];
- clif->map_ip = host2ip(ip);
+ clif->map_ip = sockt->host2ip(ip);
if ( !clif->map_ip ) {
ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
return false;
}
safestrncpy(clif->map_ip_str, ip, sizeof(clif->map_ip_str));
- ShowInfo("Map Server IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(clif->map_ip, ip_str));
+ ShowInfo("Map Server IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, sockt->ip2str(clif->map_ip, ip_str));
return true;
}
bool clif_setbindip(const char* ip) {
- clif->bind_ip = host2ip(ip);
+ clif->bind_ip = sockt->host2ip(ip);
if ( clif->bind_ip ) {
char ip_str[16];
- ShowInfo("Map Server Bind IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(clif->bind_ip, ip_str));
+ ShowInfo("Map Server Bind IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, sockt->ip2str(clif->bind_ip, ip_str));
return true;
}
ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
@@ -242,10 +242,9 @@ uint16 clif_getport(void)
/*==========================================
* Updates server ip resolution and returns it
*------------------------------------------*/
-uint32 clif_refresh_ip(void) {
- uint32 new_ip;
-
- new_ip = host2ip(clif->map_ip_str);
+uint32 clif_refresh_ip(void)
+{
+ uint32 new_ip = sockt->host2ip(clif->map_ip_str);
if ( new_ip && new_ip != clif->map_ip ) {
clif->map_ip = new_ip;
ShowInfo("Updating IP resolution of [%s].\n", clif->map_ip_str);
@@ -698,7 +697,7 @@ void clif_authfail_fd(int fd, int type)
WFIFOW(fd,0) = 0x81;
WFIFOB(fd,2) = type;
WFIFOSET(fd,packet_len(0x81));
- set_eof(fd);
+ sockt->eof(fd);
}
@@ -1746,7 +1745,7 @@ void clif_changemapserver(struct map_session_data* sd, unsigned short map_index,
WFIFOW(fd,18) = x;
WFIFOW(fd,20) = y;
WFIFOL(fd,22) = htonl(ip);
- WFIFOW(fd,26) = ntows(htons(port)); // [!] LE byte order here [!]
+ WFIFOW(fd,26) = sockt->ntows(htons(port)); // [!] LE byte order here [!]
WFIFOSET(fd,packet_len(0x92));
}
@@ -2238,7 +2237,7 @@ void clif_additem(struct map_session_data *sd, int n, int amount, int fail) {
struct packet_additem p;
nullpo_retv(sd);
- if( !session_isActive(sd->fd) ) //Sasuke-
+ if (!sockt->session_is_active(sd->fd)) //Sasuke-
return;
if( fail )
@@ -2697,7 +2696,7 @@ void clif_updatestatus(struct map_session_data *sd,int type)
fd=sd->fd;
- if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
+ if (!sockt->session_is_active(fd)) // Invalid pointer fix, by sasuke [Kevin]
return;
WFIFOHEAD(fd, 14);
@@ -3605,7 +3604,7 @@ void clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
nullpo_retv(cd);
fd = sd->fd;
- if (!session_isActive(fd))
+ if (!sockt->session_is_active(fd))
return;
t = (int)(cd->owner->type == BL_NPC);
WFIFOHEAD(fd, 8 + (28*(cd->users+t)));
@@ -5683,7 +5682,7 @@ void clif_wis_message(int fd, const char* nick, const char* mes, size_t mes_len)
/// 2 = ignored by target
/// 3 = everyone ignored by target
void clif_wis_end(int fd, int flag) {
- struct map_session_data *sd = session_isValid(fd) ? session[fd]->session_data : NULL;
+ struct map_session_data *sd = sockt->session_is_valid(fd) ? session[fd]->session_data : NULL;
struct packet_wis_end p;
if( !sd )
@@ -7450,7 +7449,7 @@ void clif_guild_notice(struct map_session_data* sd, struct guild* g)
fd = sd->fd;
- if ( !session_isActive(fd) )
+ if (!sockt->session_is_active(fd))
return;
if(g->mes1[0] == '\0' && g->mes2[0] == '\0')
@@ -8806,7 +8805,7 @@ bool clif_process_message(struct map_session_data *sd, int format, char **name_,
{
//Hacked message, or infamous "client desynchronize" issue where they pick one char while loading another.
ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
- set_eof(fd); // Just kick them out to correct it.
+ sockt->eof(fd); // Just kick them out to correct it.
return false;
}
@@ -8956,7 +8955,7 @@ void clif_parse_WantToConnection(int fd, struct map_session_data* sd) {
WFIFOW(fd,0) = 0x6a;
WFIFOB(fd,2) = 3; // Rejected by server
WFIFOSET(fd,packet_len(0x6a));
- set_eof(fd);
+ sockt->eof(fd);
return;
}
@@ -9528,7 +9527,7 @@ void clif_parse_QuitGame(int fd, struct map_session_data *sd)
if( !sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] && !sd->sc.data[SC_CHASEWALK] && !sd->sc.data[SC_CLOAKINGEXCEED] && !sd->sc.data[SC__INVISIBILITY] &&
(!battle_config.prevent_logout || DIFF_TICK(timer->gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
{
- set_eof(fd);
+ sockt->eof(fd);
clif->disconnect_ack(sd, 0);
} else {
@@ -18317,9 +18316,9 @@ int clif_parse(int fd) {
map->quit(sd);
}
} else {
- ShowInfo("Closed connection from '"CL_WHITE"%s"CL_RESET"'.\n", ip2str(session[fd]->client_addr, NULL));
+ ShowInfo("Closed connection from '"CL_WHITE"%s"CL_RESET"'.\n", sockt->ip2str(session[fd]->client_addr, NULL));
}
- do_close(fd);
+ sockt->close(fd);
return 0;
}
@@ -18348,7 +18347,7 @@ int clif_parse(int fd) {
#ifdef DUMP_INVALID_PACKET
ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
#endif
- set_eof(fd);
+ sockt->eof(fd);
return 0;
}
@@ -18364,7 +18363,7 @@ int clif_parse(int fd) {
#ifdef DUMP_INVALID_PACKET
ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
#endif
- set_eof(fd);
+ sockt->eof(fd);
return 0;
}
@@ -18506,8 +18505,8 @@ int do_init_clif(bool minimal)
packetdb_loaddb();
- set_defaultparse(clif->parse);
- if( make_listen_bind(clif->bind_ip,clif->map_port) == -1 ) {
+ sockt->set_defaultparse(clif->parse);
+ if (sockt->make_listen_bind(clif->bind_ip,clif->map_port) == -1) {
ShowFatalError("Failed to bind to port '"CL_WHITE"%d"CL_RESET"'\n",clif->map_port);
exit(EXIT_FAILURE);
}
diff --git a/src/map/irc-bot.c b/src/map/irc-bot.c
index b0f687c0d..451d224fd 100644
--- a/src/map/irc-bot.c
+++ b/src/map/irc-bot.c
@@ -41,7 +41,7 @@ int irc_connect_timer(int tid, int64 tick, int id, intptr_t data) {
ircbot->last_try = timer->gettick();
- if ((ircbot->fd = make_connection(ircbot->ip, channel->config->irc_server_port, &opt)) > 0) {
+ if ((ircbot->fd = sockt->make_connection(ircbot->ip, channel->config->irc_server_port, &opt)) > 0) {
session[ircbot->fd]->func_parse = ircbot->parse;
session[ircbot->fd]->flag.server = 1;
timer->add(timer->gettick() + 3000, ircbot->identify_timer, 0, 0);
@@ -115,12 +115,12 @@ int irc_parse(int fd) {
char *parse_string = NULL, *str_safe = NULL;
if (session[fd]->flag.eof) {
- do_close(fd);
+ sockt->close(fd);
ircbot->fd = 0;
ircbot->isOn = false;
ircbot->isIn = false;
ircbot->fails = 0;
- ircbot->ip = host2ip(channel->config->irc_server);
+ ircbot->ip = sockt->host2ip(channel->config->irc_server);
timer->add(timer->gettick() + 120000, ircbot->connect_timer, 0, 0);
return 0;
}
@@ -415,7 +415,7 @@ void irc_bot_init(bool minimal) {
if (!channel->config->irc)
return;
- if (!(ircbot->ip = host2ip(channel->config->irc_server))) {
+ if (!(ircbot->ip = sockt->host2ip(channel->config->irc_server))) {
ShowError("Unable to resolve '%s' (irc server), disabling irc channel...\n", channel->config->irc_server);
channel->config->irc = false;
return;
@@ -454,7 +454,7 @@ void irc_bot_final(void) {
return;
if( ircbot->isOn ) {
ircbot->send("QUIT :Hercules is shutting down");
- do_close(ircbot->fd);
+ sockt->close(ircbot->fd);
}
for( i = 0; i < ircbot->funcs.size; i++ ) {
diff --git a/src/map/map.c b/src/map/map.c
index e43d4d7f6..d8ea311f9 100644
--- a/src/map/map.c
+++ b/src/map/map.c
@@ -5552,7 +5552,7 @@ void do_shutdown(void)
for( sd = (TBL_PC*)mapit->first(iter); mapit->exists(iter); sd = (TBL_PC*)mapit->next(iter) )
clif->GM_kick(NULL, sd);
mapit->free(iter);
- flush_fifos();
+ sockt->flush_fifos();
}
chrif->check_shutdown();
}
@@ -5923,7 +5923,7 @@ int do_init(int argc, char *argv[])
if (!map->ip_set || !map->char_ip_set) {
char ip_str[16];
- ip2str(sockt->addr_[0], ip_str);
+ sockt->ip2str(sockt->addr_[0], ip_str);
ShowWarning("Not all IP addresses in /conf/map-server.conf configured, auto-detecting...\n");
diff --git a/src/map/pc.c b/src/map/pc.c
index ad32217b8..04d597d81 100644
--- a/src/map/pc.c
+++ b/src/map/pc.c
@@ -9014,7 +9014,7 @@ int pc_readregistry(struct map_session_data *sd, int64 reg) {
ShowError("pc_readregistry: Trying to read reg %s before it's been loaded!\n", script->get_str(script_getvarid(reg)));
//This really shouldn't happen, so it's possible the data was lost somewhere, we should request it again.
//intif->request_registry(sd,type==3?4:type);
- set_eof(sd->fd);
+ sockt->eof(sd->fd);
return 0;
}
@@ -9035,7 +9035,7 @@ char* pc_readregistry_str(struct map_session_data *sd, int64 reg) {
ShowError("pc_readregistry_str: Trying to read reg %s before it's been loaded!\n", script->get_str(script_getvarid(reg)));
//This really shouldn't happen, so it's possible the data was lost somewhere, we should request it again.
//intif->request_registry(sd,type==3?4:type);
- set_eof(sd->fd);
+ sockt->eof(sd->fd);
return NULL;
}
diff --git a/src/map/script.c b/src/map/script.c
index 23c6af0f8..837f83668 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -18280,7 +18280,7 @@ BUILDIN(getcharip) {
/* set ip, ip_addr and convert to ip and push str */
ip = session[sd->fd]->client_addr;
- ip_addr = ip2str(ip, NULL);
+ ip_addr = sockt->ip2str(ip, NULL);
script_pushstrcopy(st, ip_addr);
}
diff --git a/src/map/trade.c b/src/map/trade.c
index 4dd6ffafa..2f6e2a648 100644
--- a/src/map/trade.c
+++ b/src/map/trade.c
@@ -209,13 +209,13 @@ int impossible_trade_check(struct map_session_data *sd)
// if we block people
if (battle_config.ban_hack_trade < 0) {
chrif->char_ask_name(-1, sd->status.name, CHAR_ASK_NAME_BLOCK, 0, 0, 0, 0, 0, 0);
- set_eof(sd->fd); // forced to disconnect because of the hack
+ sockt->eof(sd->fd); // forced to disconnect because of the hack
// message about the ban
safestrncpy(message_to_gm, msg_txt(540), sizeof(message_to_gm)); // This player has been definitively blocked.
// if we ban people
} else if (battle_config.ban_hack_trade > 0) {
chrif->char_ask_name(-1, sd->status.name, CHAR_ASK_NAME_BAN, 0, 0, 0, 0, battle_config.ban_hack_trade, 0); // type: 2 - ban (year, month, day, hour, minute, second)
- set_eof(sd->fd); // forced to disconnect because of the hack
+ sockt->eof(sd->fd); // forced to disconnect because of the hack
// message about the ban
sprintf(message_to_gm, msg_txt(507), battle_config.ban_hack_trade); // This player has been banned for %d minute(s).
} else