From 14f84fc044754d22740905b7fa90022b4a04b0d8 Mon Sep 17 00:00:00 2001 From: shennetsind Date: Sat, 18 Jan 2014 19:30:11 -0200 Subject: Socket interfaced We designed this one with having as little changes required elsewhere in mind, thus the way most socket-related things are called has not changed. Plugins may now take a greater advantage of the socket features. Signed-off-by: shennetsind --- src/char/char.c | 24 ++++----- src/common/HPM.c | 6 +-- src/common/core.c | 9 ++-- src/common/socket.c | 135 +++++++++++++++++++++++++++++++++---------------- src/common/socket.h | 142 ++++++++++++++++++++++++++++++---------------------- src/common/strlib.h | 1 + src/common/timer.c | 2 +- src/common/timer.h | 2 +- src/map/atcommand.c | 2 +- src/map/chrif.c | 10 ++-- src/map/chrif.h | 2 +- src/map/clif.c | 32 ++++++------ src/map/map.c | 10 ++-- src/map/mob.c | 2 +- src/map/pc.c | 2 +- src/map/pc.h | 2 +- src/map/script.c | 2 +- src/map/unit.c | 2 +- 18 files changed, 227 insertions(+), 160 deletions(-) diff --git a/src/char/char.c b/src/char/char.c index a6588dc09..efe02031f 100644 --- a/src/char/char.c +++ b/src/char/char.c @@ -2109,8 +2109,8 @@ void disconnect_player(int account_id) struct char_session_data* sd; // disconnect player if online on char-server - ARR_FIND( 0, fd_max, i, session[i] && (sd = (struct char_session_data*)session[i]->session_data) && sd->account_id == account_id ); - if( i < fd_max ) + 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); } @@ -2228,7 +2228,7 @@ int parse_fromlogin(int fd) { loginif_on_disconnect(); return 0; } else if ( session[fd]->flag.ping ) {/* we've reached stall time */ - if( DIFF_TICK(last_tick, session[fd]->rdata_tick) > (stall_time * 2) ) {/* we can't wait any longer */ + if( DIFF_TICK(sockt->last_tick, session[fd]->rdata_tick) > (sockt->stall_time * 2) ) {/* we can't wait any longer */ set_eof(fd); return 0; } else if( session[fd]->flag.ping != 2 ) { /* we haven't sent ping out yet */ @@ -2334,8 +2334,8 @@ int parse_fromlogin(int fd) { return 0; // find the authenticated session with this account id - ARR_FIND( 0, fd_max, i, session[i] && (sd = (struct char_session_data*)session[i]->session_data) && sd->auth && sd->account_id == RFIFOL(fd,2) ); - if( i < fd_max ) { + ARR_FIND( 0, sockt->fd_max, i, session[i] && (sd = (struct char_session_data*)session[i]->session_data) && sd->auth && sd->account_id == RFIFOL(fd,2) ); + if( i < sockt->fd_max ) { memcpy(sd->email, RFIFOP(fd,6), 40); sd->expiration_time = (time_t)RFIFOL(fd,46); sd->group_id = RFIFOB(fd,50); @@ -2512,8 +2512,8 @@ int parse_fromlogin(int fd) { {// Manual kick from char server. struct char_session_data *tsd; int i; - ARR_FIND( 0, fd_max, i, session[i] && (tsd = (struct char_session_data*)session[i]->session_data) && tsd->account_id == aid ); - if( i < fd_max ) + ARR_FIND( 0, sockt->fd_max, i, session[i] && (tsd = (struct char_session_data*)session[i]->session_data) && tsd->account_id == aid ); + if( i < sockt->fd_max ) { WFIFOHEAD(i,3); WFIFOW(i,0) = 0x81; @@ -2885,7 +2885,7 @@ int parse_frommap(int fd) case 0x2b0a: if( RFIFOREST(fd) < RFIFOW(fd, 2) ) return 0; - socket_datasync(fd, false); + sockt->datasync(fd, false); RFIFOSKIP(fd,RFIFOW(fd,2)); break; @@ -4609,7 +4609,7 @@ int parse_char(int fd) realloc_fifo(fd, FIFOSIZE_SERVERLINK, FIFOSIZE_SERVERLINK); char_mapif_init(fd); } - socket_datasync(fd, true); + sockt->datasync(fd, true); RFIFOSKIP(fd,60); } @@ -5304,11 +5304,11 @@ int do_init(int argc, char **argv) { mmo_char_sql_init(); char_read_fame_list(); //Read fame lists. - if ((naddr_ != 0) && (!login_ip || !char_ip)) { + if ((sockt->naddr_ != 0) && (!login_ip || !char_ip)) { char ip_str[16]; - ip2str(addr_[0], ip_str); + ip2str(sockt->addr_[0], ip_str); - if (naddr_ > 1) + if (sockt->naddr_ > 1) ShowStatus("Multiple interfaces detected.. using %s as our IP address\n", ip_str); else ShowStatus("Defaulting to %s as our IP address\n", ip_str); diff --git a/src/common/HPM.c b/src/common/HPM.c index e31437b72..cb70ddcd7 100644 --- a/src/common/HPM.c +++ b/src/common/HPM.c @@ -675,11 +675,7 @@ void hplugins_share_defaults(void) { HPM->share(DB, "DB"); HPM->share(HPMiMalloc, "iMalloc"); /* socket */ - HPM->share(RFIFOSKIP,"RFIFOSKIP"); - HPM->share(WFIFOSET,"WFIFOSET"); - HPM->share(do_close,"do_close"); - HPM->share(make_connection,"make_connection"); - //session,fd_max and addr_ are shared from within socket.c + HPM->share(sockt,"sockt"); /* strlib */ HPM->share(strlib,"strlib"); HPM->share(sv,"sv"); diff --git a/src/common/core.c b/src/common/core.c index 5c1e58801..86634ec4b 100644 --- a/src/common/core.c +++ b/src/common/core.c @@ -287,6 +287,7 @@ void core_defaults(void) { sql_defaults(); timer_defaults(); db_defaults(); + socket_defaults(); #endif } /*====================================== @@ -350,14 +351,14 @@ int main (int argc, char **argv) { HPM->init(); #endif - socket_init(); + sockt->init(); do_init(argc,argv); {// Main runtime cycle int next; while (runflag != CORE_ST_STOP) { - next = timer->do_timer(timer->gettick_nocache()); - do_sockets(next); + next = timer->perform(timer->gettick_nocache()); + sockt->perform(next); } } @@ -368,7 +369,7 @@ int main (int argc, char **argv) { HPM->final(); #endif timer->final(); - socket_final(); + sockt->final(); DB->final(); rathread_final(); #endif diff --git a/src/common/socket.c b/src/common/socket.c index 95333cdce..9a61b0827 100644 --- a/src/common/socket.c +++ b/src/common/socket.c @@ -10,6 +10,9 @@ #include "../common/strlib.h" #include "../config/core.h" #include "../common/HPM.h" + +#define _H_SOCKET_C_ + #include "socket.h" #include @@ -43,6 +46,19 @@ #endif #endif +/** + * Socket Interface Source + **/ +struct socket_interface sockt_s; + +#ifdef SEND_SHORTLIST + // Add a fd to the shortlist so that it'll be recognized as a fd that needs + // sending done on it. + void send_shortlist_add_fd(int fd); + // Do pending network sends (and eof handling) from the shortlist. + void send_shortlist_do_sends(); +#endif + ///////////////////////////////////////////////////////////////////// #if defined(WIN32) ///////////////////////////////////////////////////////////////////// @@ -212,12 +228,6 @@ char* sErr(int code) #endif fd_set readfds; -int fd_max; -time_t last_tick; -time_t stall_time = 60; - -uint32 addr_[16]; // ip addresses of local host (host byte order) -int naddr_ = 0; // # of ip addresses // Maximum packet size in bytes, which the client is able to handle. // Larger packets cause a buffer overflow and stack corruption. @@ -328,7 +338,7 @@ void setsocketopts(int fd, struct hSockOpt *opt) { *--------------------------------------*/ void set_eof(int fd) { - if( session_isActive(fd) ) + if( sockt->session_isActive(fd) ) { #ifdef SEND_SHORTLIST // Add this socket to the shortlist for eof handling. @@ -342,7 +352,7 @@ int recv_to_fifo(int fd) { ssize_t len; - if( !session_isActive(fd) ) + if( !sockt->session_isActive(fd) ) return -1; len = sRecv(fd, (char *) session[fd]->rdata + session[fd]->rdata_size, (int)RFIFOSPACE(fd), 0); @@ -363,7 +373,7 @@ int recv_to_fifo(int fd) } session[fd]->rdata_size += len; - session[fd]->rdata_tick = last_tick; + session[fd]->rdata_tick = sockt->last_tick; #ifdef SHOW_SERVER_STATS socket_data_i += len; socket_data_qi += len; @@ -379,7 +389,7 @@ int send_from_fifo(int fd) { ssize_t len; - if( !session_isValid(fd) ) + if( !sockt->session_isValid(fd) ) return -1; if( session[fd]->wdata_size == 0 ) @@ -431,8 +441,8 @@ void flush_fifo(int fd) void flush_fifos(void) { int i; - for(i = 1; i < fd_max; i++) - flush_fifo(i); + for(i = 1; i < sockt->fd_max; i++) + sockt->flush_fifo(i); } /*====================================== @@ -466,12 +476,12 @@ int connect_client(int listen_fd) { #ifndef MINICORE if( ip_rules && !connect_check(ntohl(client_address.sin_addr.s_addr)) ) { - do_close(fd); + sockt->close(fd); return -1; } #endif - if( fd_max <= fd ) fd_max = fd + 1; + if( sockt->fd_max <= fd ) sockt->fd_max = fd + 1; sFD_SET(fd,&readfds); create_session(fd, recv_to_fifo, send_from_fifo, default_func_parse); @@ -521,7 +531,7 @@ int make_listen_bind(uint32 ip, uint16 port) exit(EXIT_FAILURE); } - if(fd_max <= fd) fd_max = fd + 1; + if(sockt->fd_max <= fd) sockt->fd_max = fd + 1; sFD_SET(fd, &readfds); create_session(fd, connect_client, null_send, null_parse); @@ -566,13 +576,13 @@ int make_connection(uint32 ip, uint16 port, struct hSockOpt *opt) { if( result == SOCKET_ERROR ) { if( !( opt && opt->silent ) ) ShowError("make_connection: connect failed (socket #%d, %s)!\n", fd, error_msg()); - do_close(fd); + sockt->close(fd); return -1; } //Now the socket can be made non-blocking. [Skotlex] set_nonblocking(fd, 1); - if (fd_max <= fd) fd_max = fd + 1; + if (sockt->fd_max <= fd) sockt->fd_max = fd + 1; sFD_SET(fd,&readfds); create_session(fd, recv_to_fifo, send_from_fifo, default_func_parse); @@ -591,7 +601,7 @@ static int create_session(int fd, RecvFunc func_recv, SendFunc func_send, ParseF session[fd]->func_recv = func_recv; session[fd]->func_send = func_send; session[fd]->func_parse = func_parse; - session[fd]->rdata_tick = last_tick; + session[fd]->rdata_tick = sockt->last_tick; session[fd]->session_data = NULL; session[fd]->hdata = NULL; session[fd]->hdatac = 0; @@ -600,7 +610,7 @@ static int create_session(int fd, RecvFunc func_recv, SendFunc func_send, ParseF static void delete_session(int fd) { - if( session_isValid(fd) ) { + if( sockt->session_isValid(fd) ) { unsigned int i; #ifdef SHOW_SERVER_STATS socket_data_qi -= session[fd]->rdata_size - session[fd]->rdata_pos; @@ -625,7 +635,7 @@ static void delete_session(int fd) int realloc_fifo(int fd, unsigned int rfifo_size, unsigned int wfifo_size) { - if( !session_isValid(fd) ) + if( !sockt->session_isValid(fd) ) return 0; if( session[fd]->max_rdata != rfifo_size && session[fd]->rdata_size < rfifo_size) { @@ -644,7 +654,7 @@ int realloc_writefifo(int fd, size_t addition) { size_t newsize; - if( !session_isValid(fd) ) // might not happen + if( !sockt->session_isValid(fd) ) // might not happen return 0; if( session[fd]->wdata_size + addition > session[fd]->max_wdata ) @@ -672,7 +682,7 @@ int RFIFOSKIP(int fd, size_t len) { struct socket_data *s; - if ( !session_isActive(fd) ) + if ( !sockt->session_isActive(fd) ) return 0; s = session[fd]; @@ -695,7 +705,7 @@ int WFIFOSET(int fd, size_t len) size_t newreserve; struct socket_data* s = session[fd]; - if( !session_isValid(fd) || s->wdata == NULL ) + if( !sockt->session_isValid(fd) || s->wdata == NULL ) return 0; // we have written len bytes to the buffer already before calling WFIFOSET @@ -771,7 +781,7 @@ int do_sockets(int next) #ifdef SEND_SHORTLIST send_shortlist_do_sends(); #else - for (i = 1; i < fd_max; i++) + for (i = 1; i < sockt->fd_max; i++) { if(!session[i]) continue; @@ -786,7 +796,7 @@ int do_sockets(int next) timeout.tv_usec = next%1000*1000; memcpy(&rfd, &readfds, sizeof(rfd)); - ret = sSelect(fd_max, &rfd, NULL, NULL, &timeout); + ret = sSelect(sockt->fd_max, &rfd, NULL, NULL, &timeout); if( ret == SOCKET_ERROR ) { @@ -798,7 +808,7 @@ int do_sockets(int next) return 0; // interrupted by a signal, just loop and try again } - last_tick = time(NULL); + sockt->last_tick = time(NULL); #if defined(WIN32) // on windows, enumerating all members of the fd_set is way faster if we access the internals @@ -810,7 +820,7 @@ int do_sockets(int next) } #else // otherwise assume that the fd_set is a bit-array and enumerate it in a standard way - for( i = 1; ret && i < fd_max; ++i ) + for( i = 1; ret && i < sockt->fd_max; ++i ) { if(sFD_ISSET(i,&rfd) && session[i]) { @@ -824,7 +834,7 @@ int do_sockets(int next) #ifdef SEND_SHORTLIST send_shortlist_do_sends(); #else - for (i = 1; i < fd_max; i++) + for (i = 1; i < sockt->fd_max; i++) { if(!session[i]) continue; @@ -840,12 +850,12 @@ int do_sockets(int next) #endif // parse input data on each socket - for(i = 1; i < fd_max; i++) + for(i = 1; i < sockt->fd_max; i++) { if(!session[i]) continue; - if (session[i]->rdata_tick && DIFF_TICK(last_tick, session[i]->rdata_tick) > stall_time) { + if (session[i]->rdata_tick && DIFF_TICK(sockt->last_tick, session[i]->rdata_tick) > sockt->stall_time) { if( session[i]->flag.server ) {/* server is special */ if( session[i]->flag.ping != 2 )/* only update if necessary otherwise it'd resend the ping unnecessarily */ session[i]->flag.ping = 1; @@ -873,7 +883,7 @@ int do_sockets(int next) } #ifdef SHOW_SERVER_STATS - if (last_tick != socket_data_last_tick) + if (sockt->last_tick != socket_data_last_tick) { char buf[1024]; @@ -883,7 +893,7 @@ int do_sockets(int next) #else ShowMessage("\033[s\033[1;1H\033[2K%s\033[u", buf); #endif - socket_data_last_tick = last_tick; + socket_data_last_tick = sockt->last_tick; socket_data_i = socket_data_ci = 0; socket_data_o = socket_data_co = 0; } @@ -1148,9 +1158,9 @@ int socket_config_read(const char* cfgName) continue; if (!strcmpi(w1, "stall_time")) { - stall_time = atoi(w2); - if( stall_time < 3 ) - stall_time = 3;/* a minimum is required to refrain it from killing itself */ + sockt->stall_time = atoi(w2); + if( sockt->stall_time < 3 ) + sockt->stall_time = 3;/* a minimum is required to refrain it from killing itself */ } #ifndef MINICORE else if (!strcmpi(w1, "enable_ip_rules")) { @@ -1218,9 +1228,9 @@ void socket_final(void) aFree(access_deny); #endif - for( i = 1; i < fd_max; i++ ) + for( i = 1; i < sockt->fd_max; i++ ) if(session[i]) - do_close(i); + sockt->close(i); // session[0] のダミーデータを削除 aFree(session[0]->rdata); @@ -1382,7 +1392,7 @@ void socket_init(void) #endif // Get initial local ips - naddr_ = socket_getips(addr_,16); + sockt->naddr_ = socket_getips(sockt->addr_,16); sFD_ZERO(&readfds); #if defined(SEND_SHORTLIST) @@ -1394,7 +1404,7 @@ void socket_init(void) socket_config_read(SOCKET_CONF_FILENAME); // initialise last send-receive tick - last_tick = time(NULL); + sockt->last_tick = time(NULL); // session[0] is now currently used for disconnected sessions of the map server, and as such, // should hold enough buffer (it is a vacuum so to speak) as it is never flushed. [Skotlex] @@ -1411,8 +1421,6 @@ void socket_init(void) /* Hercules Plugin Manager */ HPM->share(session,"session"); - HPM->share(&fd_max,"fd_max"); - HPM->share(addr_,"addr"); } bool session_isValid(int fd) @@ -1422,7 +1430,7 @@ bool session_isValid(int fd) bool session_isActive(int fd) { - return ( session_isValid(fd) && !session[fd]->flag.eof ); + return ( sockt->session_isValid(fd) && !session[fd]->flag.eof ); } // Resolves hostname into a numeric ip. @@ -1526,7 +1534,7 @@ void send_shortlist_add_fd(int fd) int i; int bit; - if( !session_isValid(fd) ) + if( !sockt->session_isValid(fd) ) return;// out of range i = fd/32; @@ -1595,3 +1603,44 @@ void send_shortlist_do_sends() } } #endif + +void socket_defaults(void) { + sockt = &sockt_s; + + sockt->fd_max = 0; + /* */ + sockt->stall_time = 60; + sockt->last_tick = 0; + /* */ + memset(&sockt->addr_, 0, sizeof(sockt->addr_)); + sockt->naddr_ = 0; + /* */ + sockt->init = socket_init; + sockt->final = socket_final; + /* */ + sockt->perform = do_sockets; + /* */ + sockt->datasync = socket_datasync; + /* */ + sockt->make_listen_bind = make_listen_bind; + 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->session_isValid = session_isValid; + sockt->session_isActive = session_isActive; + /* */ + sockt->flush_fifo = flush_fifo; + sockt->flush_fifos = flush_fifos; + sockt->set_nonblocking = set_nonblocking; + sockt->set_defaultparse = set_defaultparse; + sockt->host2ip = host2ip; + sockt->ip2str = ip2str; + sockt->str2ip = str2ip; + sockt->ntows = ntows; + sockt->getips = socket_getips; + sockt->set_eof = set_eof; +} diff --git a/src/common/socket.h b/src/common/socket.h index 02817f653..6879d2e90 100644 --- a/src/common/socket.h +++ b/src/common/socket.h @@ -107,73 +107,93 @@ struct hSockOpt { unsigned int setTimeo : 1; }; -// Data prototype declaration - -struct socket_data **session; - -extern int fd_max; - -extern time_t last_tick; -extern time_t stall_time; - -////////////////////////////////// -// some checking on sockets -extern bool session_isValid(int fd); -extern bool session_isActive(int fd); -////////////////////////////////// - -// Function prototype declaration - -int make_listen_bind(uint32 ip, uint16 port); -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 do_sockets(int next); -void do_close(int fd); -void socket_init(void); -void socket_final(void); - -extern void flush_fifo(int fd); -extern void flush_fifos(void); -extern void set_nonblocking(int fd, unsigned long yes); - -void set_defaultparse(ParseFunc defaultparse); +/// Use a shortlist of sockets instead of iterating all sessions for sockets +/// that have data to send or need eof handling. +/// Adapted to use a static array instead of a linked list. +/// +/// @author Buuyo-tama +#define SEND_SHORTLIST -// hostname/ip conversion functions -uint32 host2ip(const char* hostname); -const char* ip2str(uint32 ip, char ip_str[16]); -uint32 str2ip(const char* ip_str); // Note: purposely returns four comma-separated arguments #define CONVIP(ip) ((ip)>>24)&0xFF,((ip)>>16)&0xFF,((ip)>>8)&0xFF,((ip)>>0)&0xFF #define MAKEIP(a,b,c,d) ((uint32)( ( ( (a)&0xFF ) << 24 ) | ( ( (b)&0xFF ) << 16 ) | ( ( (c)&0xFF ) << 8 ) | ( ( (d)&0xFF ) << 0 ) )) -uint16 ntows(uint16 netshort); - -int socket_getips(uint32* ips, int max); - -extern uint32 addr_[16]; // ip addresses of local host (host byte order) -extern int naddr_; // # of ip addresses -void set_eof(int fd); - -/* [Ind/Hercules] - socket_datasync */ -void socket_datasync(int fd, bool send); +/** + * This stays out of the interface. + **/ +struct socket_data **session; -/// Use a shortlist of sockets instead of iterating all sessions for sockets -/// that have data to send or need eof handling. -/// Adapted to use a static array instead of a linked list. -/// -/// @author Buuyo-tama -#define SEND_SHORTLIST +/** + * Socket.c interface, mostly for reading however. + **/ +struct socket_interface { + int fd_max; + /* */ + time_t stall_time; + time_t last_tick; + /* */ + uint32 addr_[16]; // ip addresses of local host (host byte order) + int naddr_; // # of ip addresses + /* */ + void (*init) (void); + void (*final) (void); + /* */ + int (*perform) (int next); + /* [Ind/Hercules] - socket_datasync */ + void (*datasync) (int fd, bool send); + /* */ + int (*make_listen_bind) (uint32 ip, uint16 port); + 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); + void (*close) (int fd); + /* */ + bool (*session_isValid) (int fd); + bool (*session_isActive) (int fd); + /* */ + void (*flush_fifo) (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]); + uint32 (*str2ip) (const char* ip_str); + /* */ + uint16 (*ntows) (uint16 netshort); + /* */ + int (*getips) (uint32* ips, int max); + /* */ + void (*set_eof) (int fd); +}; -#ifdef SEND_SHORTLIST -// Add a fd to the shortlist so that it'll be recognized as a fd that needs -// sending done on it. -void send_shortlist_add_fd(int fd); -// Do pending network sends (and eof handling) from the shortlist. -void send_shortlist_do_sends(); -#endif +struct socket_interface *sockt; + +void socket_defaults(void); + +/* 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 /* _SOCKET_H_ */ diff --git a/src/common/strlib.h b/src/common/strlib.h index d1aea8cac..5336260f6 100644 --- a/src/common/strlib.h +++ b/src/common/strlib.h @@ -190,4 +190,5 @@ void strlib_defaults(void); #define strline(str,pos) (strlib->strline((str),(pos))) #define bin2hex(output,input,count) (strlib->bin2hex((output),(input),(count))) #endif /* STRLIB_C */ + #endif /* _STRLIB_H_ */ diff --git a/src/common/timer.c b/src/common/timer.c index 7f9e20dad..526854582 100644 --- a/src/common/timer.c +++ b/src/common/timer.c @@ -468,7 +468,7 @@ void timer_defaults(void) { timer->addtick = timer_addtick; timer->settick = timer_settick; timer->get_uptime = timer_get_uptime; - timer->do_timer = do_timer; + timer->perform = do_timer; timer->init = timer_init; timer->final = timer_final; } diff --git a/src/common/timer.h b/src/common/timer.h index 9aa29861e..af1a2b036 100644 --- a/src/common/timer.h +++ b/src/common/timer.h @@ -56,7 +56,7 @@ struct timer_interface { unsigned long (*get_uptime) (void); - int (*do_timer) (int64 tick); + int (*perform) (int64 tick); void (*init) (void); void (*final) (void); }; diff --git a/src/map/atcommand.c b/src/map/atcommand.c index 3cdfb0e29..0cb552bd0 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -9847,7 +9847,7 @@ bool is_atcommand(const int fd, struct map_session_data* sd, const char* message } if( battle_config.idletime_criteria & BCIDLE_ATCOMMAND ) - sd->idletime = last_tick; + sd->idletime = sockt->last_tick; //Clearing these to be used once more. memset(command, '\0', sizeof(command)); diff --git a/src/map/chrif.c b/src/map/chrif.c index 0a3fb0ad2..3dc35fc68 100644 --- a/src/map/chrif.c +++ b/src/map/chrif.c @@ -426,7 +426,7 @@ void chrif_connectack(int fd) { guild->castle_map_init(); } - socket_datasync(fd, true); + sockt->datasync(fd, true); chrif->skillid2idx(fd); } @@ -1251,7 +1251,7 @@ bool chrif_char_offline_nsd(int account_id, int char_id) { /*========================================= * Tell char-server to reset all chars offline [Wizputer] *-----------------------------------------*/ -bool chrif_flush_fifo(void) { +bool chrif_flush(void) { chrif_check(false); set_nonblocking(chrif->fd, 0); @@ -1372,7 +1372,7 @@ int chrif_parse(int fd) { chrif->on_disconnect(); return 0; } else if ( session[fd]->flag.ping ) {/* we've reached stall time */ - if( DIFF_TICK(last_tick, session[fd]->rdata_tick) > (stall_time * 2) ) {/* we can't wait any longer */ + if( DIFF_TICK(sockt->last_tick, session[fd]->rdata_tick) > (sockt->stall_time * 2) ) {/* we can't wait any longer */ set_eof(fd); return 0; } else if( session[fd]->flag.ping != 2 ) { /* we haven't sent ping out yet */ @@ -1423,7 +1423,7 @@ int chrif_parse(int fd) { case 0x2b04: chrif->recvmap(fd); break; case 0x2b06: chrif->changemapserverack(RFIFOL(fd,2), RFIFOL(fd,6), RFIFOL(fd,10), RFIFOL(fd,14), RFIFOW(fd,18), RFIFOW(fd,20), RFIFOW(fd,22), RFIFOL(fd,24), RFIFOW(fd,28)); break; case 0x2b09: map->addnickdb(RFIFOL(fd,2), (char*)RFIFOP(fd,6)); break; - case 0x2b0a: socket_datasync(fd, false); break; + case 0x2b0a: sockt->datasync(fd, false); break; case 0x2b0d: chrif->changedsex(fd); break; case 0x2b0f: chrif->char_ask_name_answer(RFIFOL(fd,2), (char*)RFIFOP(fd,6), RFIFOW(fd,30), RFIFOW(fd,32)); break; case 0x2b12: chrif->divorceack(RFIFOL(fd,2), RFIFOL(fd,6)); break; @@ -1692,7 +1692,7 @@ void chrif_defaults(void) { chrif->removefriend = chrif_removefriend; chrif->send_report = chrif_send_report; - chrif->flush_fifo = chrif_flush_fifo; + chrif->flush = chrif_flush; chrif->skillid2idx = chrif_skillid2idx; chrif->sd_to_auth = chrif_sd_to_auth; diff --git a/src/map/chrif.h b/src/map/chrif.h index 7e7aa43cd..163fdf670 100644 --- a/src/map/chrif.h +++ b/src/map/chrif.h @@ -104,7 +104,7 @@ struct chrif_interface { bool (*removefriend) (int char_id, int friend_id); void (*send_report) (char* buf, int len); - bool (*flush_fifo) (void); + bool (*flush) (void); void (*skillid2idx) (int fd); bool (*sd_to_auth) (TBL_PC* sd, enum sd_state state); diff --git a/src/map/clif.c b/src/map/clif.c index af328e7a7..975a5aa01 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -9708,7 +9708,7 @@ void clif_parse_WalkToXY(int fd, struct map_session_data *sd) //Set last idle time... [Skotlex] if( battle_config.idletime_criteria & BCIDLE_WALK ) - sd->idletime = last_tick; + sd->idletime = sockt->last_tick; unit->walktoxy(&sd->bl, x, y, 4); } @@ -9859,7 +9859,7 @@ void clif_parse_GlobalMessage(int fd, struct map_session_data* sd) } if( battle_config.idletime_criteria & BCIDLE_CHAT ) - sd->idletime = last_tick; + sd->idletime = sockt->last_tick; if( sd->gcbind ) { clif->chsys_send(sd->gcbind,sd,message); @@ -10024,7 +10024,7 @@ void clif_parse_Emotion(int fd, struct map_session_data *sd) sd->emotionlasttime = time(NULL); if( battle_config.idletime_criteria & BCIDLE_EMOTION ) - sd->idletime = last_tick; + sd->idletime = sockt->last_tick; if(battle_config.client_reshuffle_dice && emoticon>=E_DICE1 && emoticon<=E_DICE6) {// re-roll dice emoticon = rnd()%6+E_DICE1; @@ -10099,7 +10099,7 @@ void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, pc->delinvincibletimer(sd); if( battle_config.idletime_criteria & BCIDLE_ATTACK ) - sd->idletime = last_tick; + sd->idletime = sockt->last_tick; unit->attack(&sd->bl, target_id, action_type != 0); break; case 0x02: // sitdown @@ -10124,7 +10124,7 @@ void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, break; if( battle_config.idletime_criteria & BCIDLE_SIT ) - sd->idletime = last_tick; + sd->idletime = sockt->last_tick; pc_setsit(sd); skill->sit(sd,1); @@ -10138,7 +10138,7 @@ void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, } if( battle_config.idletime_criteria & BCIDLE_SIT ) - sd->idletime = last_tick; + sd->idletime = sockt->last_tick; pc->setstand(sd); skill->sit(sd,0); @@ -10332,7 +10332,7 @@ void clif_parse_WisMessage(int fd, struct map_session_data* sd) } if( battle_config.idletime_criteria & BCIDLE_CHAT ) - sd->idletime = last_tick; + sd->idletime = sockt->last_tick; // Chat logging type 'W' / Whisper logs->chat(LOG_CHAT_WHISPER, 0, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, target, message); @@ -10552,7 +10552,7 @@ void clif_parse_DropItem(int fd, struct map_session_data *sd) break; if( battle_config.idletime_criteria & BCIDLE_DROPITEM ) - sd->idletime = last_tick; + sd->idletime = sockt->last_tick; return; } @@ -10580,7 +10580,7 @@ void clif_parse_UseItem(int fd, struct map_session_data *sd) //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex] if( battle_config.idletime_criteria & BCIDLE_USEITEM ) - sd->idletime = last_tick; + sd->idletime = sockt->last_tick; n = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2; if(n <0 || n >= MAX_INVENTORY) @@ -10627,7 +10627,7 @@ void clif_parse_EquipItem(int fd,struct map_session_data *sd) { } if( battle_config.idletime_criteria & BCIDLE_USEITEM ) - sd->idletime = last_tick; + sd->idletime = sockt->last_tick; //Client doesn't send the position for ammo. if(sd->inventory_data[p->index]->type == IT_AMMO) @@ -10747,7 +10747,7 @@ void clif_parse_UnequipItem(int fd,struct map_session_data *sd) index = RFIFOW(fd,2)-2; if( battle_config.idletime_criteria & BCIDLE_USEITEM ) - sd->idletime = last_tick; + sd->idletime = sockt->last_tick; pc->unequipitem(sd,index,1); } @@ -11297,7 +11297,7 @@ void clif_parse_UseSkillToId(int fd, struct map_session_data *sd) // Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex] if( battle_config.idletime_criteria & BCIDLE_USESKILLTOID ) - sd->idletime = last_tick; + sd->idletime = sockt->last_tick; if( sd->npc_id || sd->state.workinprogress&1 ){ #ifdef RENEWAL @@ -11398,7 +11398,7 @@ void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, uint16 ski //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex] if( battle_config.idletime_criteria & BCIDLE_USESKILLTOPOS ) - sd->idletime = last_tick; + sd->idletime = sockt->last_tick; if( skill->not_ok(skill_id, sd) ) return; @@ -12154,7 +12154,7 @@ void clif_parse_PartyMessage(int fd, struct map_session_data* sd) } if( battle_config.idletime_criteria & BCIDLE_CHAT ) - sd->idletime = last_tick; + sd->idletime = sockt->last_tick; party->send_message(sd, text, textlen); } @@ -13214,7 +13214,7 @@ void clif_parse_GuildMessage(int fd, struct map_session_data* sd) } if( battle_config.idletime_criteria & BCIDLE_CHAT ) - sd->idletime = last_tick; + sd->idletime = sockt->last_tick; if( sd->bg_id ) bg->send_message(sd, text, textlen); @@ -16203,7 +16203,7 @@ void clif_parse_BattleChat(int fd, struct map_session_data* sd) } if( battle_config.idletime_criteria & BCIDLE_CHAT ) - sd->idletime = last_tick; + sd->idletime = sockt->last_tick; bg->send_message(sd, text, textlen); } diff --git a/src/map/map.c b/src/map/map.c index 052d589b4..8301caa5b 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -5113,7 +5113,7 @@ void do_final(void) map->id_db->foreach(map->id_db,map->cleanup_db_sub); chrif->char_reset_offline(); - chrif->flush_fifo(); + chrif->flush(); atcommand->final(); battle->final(); @@ -5200,7 +5200,7 @@ void do_abort(void) } ShowError("Server received crash signal! Attempting to save all online characters!\n"); map->foreachpc(map->abort_sub); - chrif->flush_fifo(); + chrif->flush(); } /*====================================================== @@ -5524,13 +5524,13 @@ int do_init(int argc, char *argv[]) if (!map->ip_set || !map->char_ip_set) { char ip_str[16]; - ip2str(addr_[0], ip_str); + ip2str(sockt->addr_[0], ip_str); ShowWarning("Not all IP addresses in /conf/map-server.conf configured, autodetecting...\n"); - if (naddr_ == 0) + if (sockt->naddr_ == 0) ShowError("Unable to determine your IP address...\n"); - else if (naddr_ > 1) + else if (sockt->naddr_ > 1) ShowNotice("Multiple interfaces detected...\n"); ShowInfo("Defaulting to %s as our IP address\n", ip_str); diff --git a/src/map/mob.c b/src/map/mob.c index 6a8aa5f03..dab7b99ac 100644 --- a/src/map/mob.c +++ b/src/map/mob.c @@ -1825,7 +1825,7 @@ void mob_item_drop(struct mob_data *md, struct item_drop_list *dlist, struct ite if( sd && (drop_rate <= sd->state.autoloot || pc->isautolooting(sd, ditem->item_data.nameid)) - && (battle_config.idle_no_autoloot == 0 || DIFF_TICK(last_tick, sd->idletime) < battle_config.idle_no_autoloot) + && (battle_config.idle_no_autoloot == 0 || DIFF_TICK(sockt->last_tick, sd->idletime) < battle_config.idle_no_autoloot) && (battle_config.homunculus_autoloot?1:!flag) #ifdef AUTOLOOT_DISTANCE && sd->bl.m == md->bl.m diff --git a/src/map/pc.c b/src/map/pc.c index f96b70cdb..b6c354189 100644 --- a/src/map/pc.c +++ b/src/map/pc.c @@ -1035,7 +1035,7 @@ bool pc_authok(struct map_session_data *sd, int login_id2, time_t expiration_tim sd->cansendmail_tick = tick; sd->hchsysch_tick = tick; - sd->idletime = last_tick; + sd->idletime = sockt->last_tick; for(i = 0; i < MAX_SPIRITBALL; i++) sd->spirit_timer[i] = INVALID_TIMER; diff --git a/src/map/pc.h b/src/map/pc.h index f64b20945..487266646 100644 --- a/src/map/pc.h +++ b/src/map/pc.h @@ -585,7 +585,7 @@ enum equip_pos { #define pc_setsit(sd) ( (sd)->state.dead_sit = (sd)->vd.dead_sit = 2 ) #define pc_isdead(sd) ( (sd)->state.dead_sit == 1 ) #define pc_issit(sd) ( (sd)->vd.dead_sit == 2 ) -#define pc_isidle(sd) ( (sd)->chatID || (sd)->state.vending || (sd)->state.buyingstore || DIFF_TICK(last_tick, (sd)->idletime) >= battle_config.idle_no_share ) +#define pc_isidle(sd) ( (sd)->chatID || (sd)->state.vending || (sd)->state.buyingstore || DIFF_TICK(sockt->last_tick, (sd)->idletime) >= battle_config.idle_no_share ) #define pc_istrading(sd) ( (sd)->npc_id || (sd)->state.vending || (sd)->state.buyingstore || (sd)->state.trading ) #define pc_cant_act(sd) ( (sd)->npc_id || (sd)->state.vending || (sd)->state.buyingstore || (sd)->chatID || ((sd)->sc.opt1 && (sd)->sc.opt1 != OPT1_BURNING) || (sd)->state.trading || (sd)->state.storage_flag || (sd)->state.prevend ) diff --git a/src/map/script.c b/src/map/script.c index 75469a345..8e8f89727 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -15044,7 +15044,7 @@ BUILDIN(checkidle) { sd = script->rid2sd(st); if (sd) - script_pushint(st, DIFF_TICK32(last_tick, sd->idletime)); // TODO: change this to int64 when we'll support 64 bit script values + script_pushint(st, DIFF_TICK32(sockt->last_tick, sd->idletime)); // TODO: change this to int64 when we'll support 64 bit script values else script_pushint(st, 0); diff --git a/src/map/unit.c b/src/map/unit.c index d801a72f0..af52e6dfb 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -1918,7 +1918,7 @@ int unit_attack_timer_sub(struct block_list* src, int tid, int64 tick) { if(ud->state.attack_continue) { if( src->type == BL_PC && battle_config.idletime_criteria & BCIDLE_ATTACK ) - ((TBL_PC*)src)->idletime = last_tick; + ((TBL_PC*)src)->idletime = sockt->last_tick; ud->attacktimer = timer->add(ud->attackabletime,unit->attack_timer,src->id,0); } -- cgit v1.2.3-70-g09d2