diff options
author | Haru <haru@dotalux.com> | 2015-08-09 02:17:43 +0200 |
---|---|---|
committer | Haru <haru@dotalux.com> | 2015-08-15 00:51:41 +0200 |
commit | f8edb93a6a26cd81eeaad0eac23e33da7740c8b4 (patch) | |
tree | e1d6ef1a867613be7d8d0384c93c9767867a91a3 /src | |
parent | b0210e25675b0b3e950a0ee13ae8652360d84386 (diff) | |
download | hercules-f8edb93a6a26cd81eeaad0eac23e33da7740c8b4.tar.gz hercules-f8edb93a6a26cd81eeaad0eac23e33da7740c8b4.tar.bz2 hercules-f8edb93a6a26cd81eeaad0eac23e33da7740c8b4.tar.xz hercules-f8edb93a6a26cd81eeaad0eac23e33da7740c8b4.zip |
Moved session array into the socket interface
Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/char/char.c | 66 | ||||
-rw-r--r-- | src/common/socket.c | 199 | ||||
-rw-r--r-- | src/common/socket.h | 36 | ||||
-rw-r--r-- | src/login/login.c | 26 | ||||
-rw-r--r-- | src/map/atcommand.c | 2 | ||||
-rw-r--r-- | src/map/chrif.c | 32 | ||||
-rw-r--r-- | src/map/clif.c | 22 | ||||
-rw-r--r-- | src/map/intif.c | 6 | ||||
-rw-r--r-- | src/map/irc-bot.c | 6 | ||||
-rw-r--r-- | src/map/pc.c | 4 | ||||
-rw-r--r-- | src/map/script.c | 6 | ||||
-rw-r--r-- | src/plugins/sample.c | 19 |
12 files changed, 210 insertions, 214 deletions
diff --git a/src/char/char.c b/src/char/char.c index 6cfcdb331..3e24ceae0 100644 --- a/src/char/char.c +++ b/src/char/char.c @@ -206,7 +206,7 @@ void char_set_char_charselect(int account_id) character->waiting_disconnect = INVALID_TIMER; } - if (chr->login_fd > 0 && !session[chr->login_fd]->flag.eof) + if (chr->login_fd > 0 && !sockt->session[chr->login_fd]->flag.eof) chr->set_account_online(account_id); } @@ -246,7 +246,7 @@ void char_set_char_online(int map_id, int char_id, int account_id) inter_guild->CharOnline(char_id, cp?cp->guild_id:-1); //Notify login server - if (chr->login_fd > 0 && !session[chr->login_fd]->flag.eof) + if (chr->login_fd > 0 && !sockt->session[chr->login_fd]->flag.eof) chr->set_account_online(account_id); } @@ -292,7 +292,7 @@ void char_set_char_offline(int char_id, int account_id) } //Remove char if 1- Set all offline, or 2- character is no longer connected to char-server. - if (chr->login_fd > 0 && !session[chr->login_fd]->flag.eof && (char_id == -1 || character == NULL || character->fd == -1)) + if (chr->login_fd > 0 && !sockt->session[chr->login_fd]->flag.eof && (char_id == -1 || character == NULL || character->fd == -1)) chr->set_account_offline(account_id); } @@ -355,7 +355,7 @@ void char_set_all_offline(int id) ShowNotice("Sending users of map-server %d offline.\n",id); chr->online_char_db->foreach(chr->online_char_db,chr->db_kickoffline,id); - if (id >= 0 || chr->login_fd <= 0 || session[chr->login_fd]->flag.eof) + if (id >= 0 || chr->login_fd <= 0 || sockt->session[chr->login_fd]->flag.eof) return; chr->set_login_all_offline(); } @@ -2206,7 +2206,7 @@ void char_disconnect_player(int account_id) struct char_session_data* sd; // 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 ); + ARR_FIND( 0, sockt->fd_max, i, sockt->session[i] && (sd = (struct char_session_data*)sockt->session[i]->session_data) && sd->account_id == account_id ); if( i < sockt->fd_max ) sockt->eof(i); } @@ -2315,7 +2315,7 @@ void char_parse_fromlogin_auth_state(int fd) unsigned int expiration_time = RFIFOL(fd, 29); RFIFOSKIP(fd,33); - if (sockt->session_is_active(request_id) && (sd=(struct char_session_data*)session[request_id]->session_data) && + if (sockt->session_is_active(request_id) && (sd=(struct char_session_data*)sockt->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; @@ -2344,10 +2344,10 @@ void char_parse_fromlogin_auth_state(int fd) void char_parse_fromlogin_account_data(int fd) { - struct char_session_data* sd = (struct char_session_data*)session[fd]->session_data; + struct char_session_data* sd = (struct char_session_data*)sockt->session[fd]->session_data; int i; // find the authenticated session with this account id - 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) ); + ARR_FIND( 0, sockt->fd_max, i, sockt->session[i] && (sd = (struct char_session_data*)sockt->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); @@ -2388,8 +2388,8 @@ void char_parse_fromlogin_account_data(int fd) void char_parse_fromlogin_login_pong(int fd) { RFIFOSKIP(fd,2); - if (session[fd]) - session[fd]->flag.ping = 0; + if (sockt->session[fd]) + sockt->session[fd]->flag.ping = 0; } void char_changesex(int account_id, int sex) @@ -2532,7 +2532,7 @@ void char_parse_fromlogin_kick(int fd) {// Manual kick from char server. struct char_session_data *tsd; int i; - ARR_FIND( 0, sockt->fd_max, i, session[i] && (tsd = (struct char_session_data*)session[i]->session_data) && tsd->account_id == aid ); + ARR_FIND( 0, sockt->fd_max, i, sockt->session[i] && (tsd = (struct char_session_data*)sockt->session[i]->session_data) && tsd->account_id == aid ); if( i < sockt->fd_max ) { chr->authfail_fd(i, 2); @@ -2600,18 +2600,18 @@ int char_parse_fromlogin(int fd) { return 0; } - if( session[fd]->flag.eof ) { + if( sockt->session[fd]->flag.eof ) { 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 */ + } else if ( sockt->session[fd]->flag.ping ) {/* we've reached stall time */ + if( DIFF_TICK(sockt->last_tick, sockt->session[fd]->rdata_tick) > (sockt->stall_time * 2) ) {/* we can't wait any longer */ sockt->eof(fd); return 0; - } else if( session[fd]->flag.ping != 2 ) { /* we haven't sent ping out yet */ + } else if( sockt->session[fd]->flag.ping != 2 ) { /* we haven't sent ping out yet */ chr->ping_login_server(fd); - session[fd]->flag.ping = 2; + sockt->session[fd]->flag.ping = 2; } } @@ -3830,7 +3830,7 @@ void char_parse_frommap_request_stats_report(int fd) return;/* connection not possible, we drop the report */ } - session[sfd]->flag.server = 1;/* to ensure we won't drop our own packet */ + sockt->session[sfd]->flag.server = 1;/* to ensure we won't drop our own packet */ sockt->realloc_fifo(sfd, FIFOSIZE_SERVERLINK, FIFOSIZE_SERVERLINK); WFIFOHEAD(sfd, RFIFOW(fd,2) ); @@ -3846,7 +3846,7 @@ void char_parse_frommap_request_stats_report(int fd) #else sleep(1); #endif - } while( !session[sfd]->flag.eof && session[sfd]->wdata_size ); + } while( !sockt->session[sfd]->flag.eof && sockt->session[sfd]->wdata_size ); sockt->close(sfd); @@ -3897,7 +3897,7 @@ int char_parse_frommap(int fd) sockt->close(fd); return 0; } - if( session[fd]->flag.eof ) { + if( sockt->session[fd]->flag.eof ) { sockt->close(fd); chr->server[id].fd = -1; mapif->on_disconnect(id); @@ -4226,7 +4226,7 @@ void char_delete2_accept_ack(int fd, int char_id, uint32 result) {// HC: <082a>.W <char id>.L <Msg:0-5>.L #if PACKETVER >= 20130000 /* not sure the exact date -- must refresh or client gets stuck */ if( result == 1 ) { - struct char_session_data* sd = (struct char_session_data*)session[fd]->session_data; + struct char_session_data* sd = (struct char_session_data*)sockt->session[fd]->session_data; chr->mmo_char_send099d(fd, sd); } #endif @@ -4442,8 +4442,8 @@ void char_parse_char_connect(int fd, struct char_session_data* sd, uint32 ipl) return; } - CREATE(session[fd]->session_data, struct char_session_data, 1); - sd = (struct char_session_data*)session[fd]->session_data; + CREATE(sockt->session[fd]->session_data, struct char_session_data, 1); + sd = (struct char_session_data*)sockt->session[fd]->session_data; sd->account_id = account_id; sd->login_id1 = login_id1; sd->login_id2 = login_id2; @@ -4647,7 +4647,7 @@ void char_parse_char_select(int fd, struct char_session_data* sd, uint32 ipl) //Send NEW auth packet [Kevin] //FIXME: is this case even possible? [ultramage] - if ((map_fd = chr->server[i].fd) < 1 || session[map_fd] == NULL) + if ((map_fd = chr->server[i].fd) < 1 || sockt->session[map_fd] == NULL) { ShowError("chr->parse_char: Attempting to write to invalid session %d! Map Server #%d disconnected.\n", map_fd, i); chr->server[i].fd = -1; @@ -4975,8 +4975,8 @@ void char_parse_char_login_map_server(int fd, uint32 ipl) chr->server[i].ip = ntohl(RFIFOL(fd,54)); chr->server[i].port = ntohs(RFIFOW(fd,58)); chr->server[i].users = 0; - session[fd]->func_parse = chr->parse_frommap; - session[fd]->flag.server = 1; + sockt->session[fd]->func_parse = chr->parse_frommap; + sockt->session[fd]->flag.server = 1; sockt->realloc_fifo(fd, FIFOSIZE_SERVERLINK, FIFOSIZE_SERVERLINK); chr->mapif_init(fd); } @@ -5061,15 +5061,15 @@ int char_parse_char(int fd) { unsigned short cmd; struct char_session_data* sd; - uint32 ipl = session[fd]->client_addr; + uint32 ipl = sockt->session[fd]->client_addr; - sd = (struct char_session_data*)session[fd]->session_data; + sd = (struct char_session_data*)sockt->session[fd]->session_data; // disconnect any player if no login-server. if(chr->login_fd < 0) sockt->eof(fd); - if(session[fd]->flag.eof) + if(sockt->session[fd]->flag.eof) { if( sd != NULL && sd->auth ) { // already authed client @@ -5340,7 +5340,7 @@ int char_broadcast_user_count(int tid, int64 tick, int id, intptr_t data) { return 0; prev_users = users; - if( chr->login_fd > 0 && session[chr->login_fd] ) + if( chr->login_fd > 0 && sockt->session[chr->login_fd] ) { // send number of user to login server loginif->send_users_count(users); @@ -5371,7 +5371,7 @@ static int char_send_accounts_tologin_sub(DBKey key, DBData *data, va_list ap) } int char_send_accounts_tologin(int tid, int64 tick, int id, intptr_t data) { - if (chr->login_fd > 0 && session[chr->login_fd]) + if (chr->login_fd > 0 && sockt->session[chr->login_fd]) { // send account list to login server int users = chr->online_char_db->size(chr->online_char_db); @@ -5388,7 +5388,7 @@ int char_send_accounts_tologin(int tid, int64 tick, int id, intptr_t data) { } int char_check_connect_login_server(int tid, int64 tick, int id, intptr_t data) { - if (chr->login_fd > 0 && session[chr->login_fd] != NULL) + if (chr->login_fd > 0 && sockt->session[chr->login_fd] != NULL) return 0; ShowInfo("Attempt to connect to login-server...\n"); @@ -5398,8 +5398,8 @@ int char_check_connect_login_server(int tid, int64 tick, int id, intptr_t data) return 0; } - session[chr->login_fd]->func_parse = chr->parse_fromlogin; - session[chr->login_fd]->flag.server = 1; + sockt->session[chr->login_fd]->func_parse = chr->parse_fromlogin; + sockt->session[chr->login_fd]->flag.server = 1; sockt->realloc_fifo(chr->login_fd, FIFOSIZE_SERVERLINK, FIFOSIZE_SERVERLINK); loginif->connect_to_server(); diff --git a/src/common/socket.c b/src/common/socket.c index 0b69743ab..098fdf236 100644 --- a/src/common/socket.c +++ b/src/common/socket.c @@ -362,7 +362,7 @@ void set_eof(int fd) // Add this socket to the shortlist for eof handling. send_shortlist_add_fd(fd); #endif - session[fd]->flag.eof = 1; + sockt->session[fd]->flag.eof = 1; } } @@ -373,7 +373,7 @@ int recv_to_fifo(int fd) if (!sockt->session_is_active(fd)) return -1; - len = sRecv(fd, (char *) session[fd]->rdata + session[fd]->rdata_size, (int)RFIFOSPACE(fd), 0); + len = sRecv(fd, (char *) sockt->session[fd]->rdata + sockt->session[fd]->rdata_size, (int)RFIFOSPACE(fd), 0); if( len == SOCKET_ERROR ) {//An exception has occurred @@ -390,12 +390,12 @@ int recv_to_fifo(int fd) return 0; } - session[fd]->rdata_size += len; - session[fd]->rdata_tick = sockt->last_tick; + sockt->session[fd]->rdata_size += len; + sockt->session[fd]->rdata_tick = sockt->last_tick; #ifdef SHOW_SERVER_STATS socket_data_i += len; socket_data_qi += len; - if (!session[fd]->flag.server) + if (!sockt->session[fd]->flag.server) { socket_data_ci += len; } @@ -410,19 +410,19 @@ int send_from_fifo(int fd) if (!sockt->session_is_valid(fd)) return -1; - if( session[fd]->wdata_size == 0 ) + if( sockt->session[fd]->wdata_size == 0 ) return 0; // nothing to send - len = sSend(fd, (const char *) session[fd]->wdata, (int)session[fd]->wdata_size, MSG_NOSIGNAL); + len = sSend(fd, (const char *) sockt->session[fd]->wdata, (int)sockt->session[fd]->wdata_size, MSG_NOSIGNAL); if( len == SOCKET_ERROR ) {//An exception has occurred if( sErrno != S_EWOULDBLOCK ) { //ShowDebug("send_from_fifo: %s, ending connection #%d\n", error_msg(), fd); #ifdef SHOW_SERVER_STATS - socket_data_qo -= session[fd]->wdata_size; + socket_data_qo -= sockt->session[fd]->wdata_size; #endif - session[fd]->wdata_size = 0; //Clear the send queue as we can't send anymore. [Skotlex] + sockt->session[fd]->wdata_size = 0; //Clear the send queue as we can't send anymore. [Skotlex] sockt->eof(fd); } return 0; @@ -432,14 +432,14 @@ int send_from_fifo(int fd) { // some data could not be transferred? // shift unsent data to the beginning of the queue - if( (size_t)len < session[fd]->wdata_size ) - memmove(session[fd]->wdata, session[fd]->wdata + len, session[fd]->wdata_size - len); + if( (size_t)len < sockt->session[fd]->wdata_size ) + memmove(sockt->session[fd]->wdata, sockt->session[fd]->wdata + len, sockt->session[fd]->wdata_size - len); - session[fd]->wdata_size -= len; + sockt->session[fd]->wdata_size -= len; #ifdef SHOW_SERVER_STATS socket_data_o += len; socket_data_qo -= len; - if (!session[fd]->flag.server) + if (!sockt->session[fd]->flag.server) { socket_data_co += len; } @@ -452,8 +452,8 @@ int send_from_fifo(int fd) /// Best effort - there's no warranty that the data will be sent. void flush_fifo(int fd) { - if(session[fd] != NULL) - session[fd]->func_send(fd); + if(sockt->session[fd] != NULL) + sockt->session[fd]->func_send(fd); } void flush_fifos(void) @@ -503,7 +503,7 @@ int connect_client(int listen_fd) { sFD_SET(fd,&readfds); create_session(fd, recv_to_fifo, send_from_fifo, default_func_parse); - session[fd]->client_addr = ntohl(client_address.sin_addr.s_addr); + sockt->session[fd]->client_addr = ntohl(client_address.sin_addr.s_addr); return fd; } @@ -553,8 +553,8 @@ int make_listen_bind(uint32 ip, uint16 port) sFD_SET(fd, &readfds); create_session(fd, connect_client, null_send, null_parse); - session[fd]->client_addr = 0; // just listens - session[fd]->rdata_tick = 0; // disable timeouts on this socket + sockt->session[fd]->client_addr = 0; // just listens + sockt->session[fd]->rdata_tick = 0; // disable timeouts on this socket return fd; } @@ -604,25 +604,25 @@ int make_connection(uint32 ip, uint16 port, struct hSockOpt *opt) { sFD_SET(fd,&readfds); create_session(fd, recv_to_fifo, send_from_fifo, default_func_parse); - session[fd]->client_addr = ntohl(remote_address.sin_addr.s_addr); + sockt->session[fd]->client_addr = ntohl(remote_address.sin_addr.s_addr); return fd; } static int create_session(int fd, RecvFunc func_recv, SendFunc func_send, ParseFunc func_parse) { - CREATE(session[fd], struct socket_data, 1); - CREATE(session[fd]->rdata, unsigned char, RFIFO_SIZE); - CREATE(session[fd]->wdata, unsigned char, WFIFO_SIZE); - session[fd]->max_rdata = RFIFO_SIZE; - session[fd]->max_wdata = WFIFO_SIZE; - session[fd]->func_recv = func_recv; - session[fd]->func_send = func_send; - session[fd]->func_parse = func_parse; - session[fd]->rdata_tick = sockt->last_tick; - session[fd]->session_data = NULL; - session[fd]->hdata = NULL; - session[fd]->hdatac = 0; + CREATE(sockt->session[fd], struct socket_data, 1); + CREATE(sockt->session[fd]->rdata, unsigned char, RFIFO_SIZE); + CREATE(sockt->session[fd]->wdata, unsigned char, WFIFO_SIZE); + sockt->session[fd]->max_rdata = RFIFO_SIZE; + sockt->session[fd]->max_wdata = WFIFO_SIZE; + sockt->session[fd]->func_recv = func_recv; + sockt->session[fd]->func_send = func_send; + sockt->session[fd]->func_parse = func_parse; + sockt->session[fd]->rdata_tick = sockt->last_tick; + sockt->session[fd]->session_data = NULL; + sockt->session[fd]->hdata = NULL; + sockt->session[fd]->hdatac = 0; return 0; } @@ -630,25 +630,25 @@ static void delete_session(int 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; + socket_data_qi -= sockt->session[fd]->rdata_size - sockt->session[fd]->rdata_pos; + socket_data_qo -= sockt->session[fd]->wdata_size; #endif - aFree(session[fd]->rdata); - aFree(session[fd]->wdata); - if( session[fd]->session_data ) - aFree(session[fd]->session_data); - if (session[fd]->hdata) { + aFree(sockt->session[fd]->rdata); + aFree(sockt->session[fd]->wdata); + if( sockt->session[fd]->session_data ) + aFree(sockt->session[fd]->session_data); + if (sockt->session[fd]->hdata) { unsigned int i; - for(i = 0; i < session[fd]->hdatac; i++) { - if( session[fd]->hdata[i]->flag.free ) { - aFree(session[fd]->hdata[i]->data); + for(i = 0; i < sockt->session[fd]->hdatac; i++) { + if( sockt->session[fd]->hdata[i]->flag.free ) { + aFree(sockt->session[fd]->hdata[i]->data); } - aFree(session[fd]->hdata[i]); + aFree(sockt->session[fd]->hdata[i]); } - aFree(session[fd]->hdata); + aFree(sockt->session[fd]->hdata); } - aFree(session[fd]); - session[fd] = NULL; + aFree(sockt->session[fd]); + sockt->session[fd] = NULL; } } @@ -657,14 +657,14 @@ int realloc_fifo(int fd, unsigned int rfifo_size, unsigned int wfifo_size) if (!sockt->session_is_valid(fd)) return 0; - if( session[fd]->max_rdata != rfifo_size && session[fd]->rdata_size < rfifo_size) { - RECREATE(session[fd]->rdata, unsigned char, rfifo_size); - session[fd]->max_rdata = rfifo_size; + if( sockt->session[fd]->max_rdata != rfifo_size && sockt->session[fd]->rdata_size < rfifo_size) { + RECREATE(sockt->session[fd]->rdata, unsigned char, rfifo_size); + sockt->session[fd]->max_rdata = rfifo_size; } - if( session[fd]->max_wdata != wfifo_size && session[fd]->wdata_size < wfifo_size) { - RECREATE(session[fd]->wdata, unsigned char, wfifo_size); - session[fd]->max_wdata = wfifo_size; + if( sockt->session[fd]->max_wdata != wfifo_size && sockt->session[fd]->wdata_size < wfifo_size) { + RECREATE(sockt->session[fd]->wdata, unsigned char, wfifo_size); + sockt->session[fd]->max_wdata = wfifo_size; } return 0; } @@ -676,22 +676,22 @@ int realloc_writefifo(int fd, size_t addition) if (!sockt->session_is_valid(fd)) // might not happen return 0; - if (session[fd]->wdata_size + addition > session[fd]->max_wdata) { + if (sockt->session[fd]->wdata_size + addition > sockt->session[fd]->max_wdata) { // grow rule; grow in multiples of WFIFO_SIZE newsize = WFIFO_SIZE; - while( session[fd]->wdata_size + addition > newsize ) newsize += WFIFO_SIZE; - } else if (session[fd]->max_wdata >= (size_t)2*(session[fd]->flag.server?FIFOSIZE_SERVERLINK:WFIFO_SIZE) - && (session[fd]->wdata_size+addition)*4 < session[fd]->max_wdata + while( sockt->session[fd]->wdata_size + addition > newsize ) newsize += WFIFO_SIZE; + } else if (sockt->session[fd]->max_wdata >= (size_t)2*(sockt->session[fd]->flag.server?FIFOSIZE_SERVERLINK:WFIFO_SIZE) + && (sockt->session[fd]->wdata_size+addition)*4 < sockt->session[fd]->max_wdata ) { // shrink rule, shrink by 2 when only a quarter of the fifo is used, don't shrink below nominal size. - newsize = session[fd]->max_wdata / 2; + newsize = sockt->session[fd]->max_wdata / 2; } else { // no change return 0; } - RECREATE(session[fd]->wdata, unsigned char, newsize); - session[fd]->max_wdata = newsize; + RECREATE(sockt->session[fd]->wdata, unsigned char, newsize); + sockt->session[fd]->max_wdata = newsize; return 0; } @@ -704,7 +704,7 @@ int rfifoskip(int fd, size_t len) if (!sockt->session_is_active(fd)) return 0; - s = session[fd]; + s = sockt->session[fd]; if (s->rdata_size < s->rdata_pos + len) { ShowError("RFIFOSKIP: skipped past end of read buffer! Adjusting from %"PRIuS" to %"PRIuS" (session #%d)\n", len, RFIFOREST(fd), fd); @@ -722,7 +722,7 @@ int rfifoskip(int fd, size_t len) int wfifoset(int fd, size_t len) { size_t newreserve; - struct socket_data* s = session[fd]; + struct socket_data* s = sockt->session[fd]; if (!sockt->session_is_valid(fd) || s->wdata == NULL) return 0; @@ -797,11 +797,11 @@ int do_sockets(int next) #else for (i = 1; i < sockt->fd_max; i++) { - if(!session[i]) + if(!sockt->session[fd] continue; - if(session[i]->wdata_size) - session[i]->func_send(i); + if(sockt->session[fd]>wdata_size) + sockt->session[fd]>func_send(i); } #endif @@ -829,16 +829,16 @@ int do_sockets(int next) for( i = 0; i < (int)rfd.fd_count; ++i ) { int fd = sock2fd(rfd.fd_array[i]); - if( session[fd] ) - session[fd]->func_recv(fd); + if( sockt->session[fd] ) + sockt->session[fd]->func_recv(fd); } #else // otherwise assume that the fd_set is a bit-array and enumerate it in a standard way for( i = 1; ret && i < sockt->fd_max; ++i ) { - if(sFD_ISSET(i,&rfd) && session[i]) + if(sFD_ISSET(i,&rfd) && sockt->session[i]) { - session[i]->func_recv(i); + sockt->session[i]->func_recv(i); --ret; } } @@ -850,15 +850,15 @@ int do_sockets(int next) #else for (i = 1; i < sockt->fd_max; i++) { - if(!session[i]) + if(!sockt->session[i]) continue; - if(session[i]->wdata_size) - session[i]->func_send(i); + if(sockt->session[i]->wdata_size) + sockt->session[i]->func_send(i); - if (session[i]->flag.eof) { //func_send can't free a session, this is safe. + if (sockt->session[i]->flag.eof) { //func_send can't free a session, this is safe. //Finally, even if there is no data to parse, connections signaled eof should be closed, so we call parse_func [Skotlex] - session[i]->func_parse(i); //This should close the session immediately. + sockt->session[i]->func_parse(i); //This should close the session immediately. } } #endif @@ -866,13 +866,13 @@ int do_sockets(int next) // parse input data on each socket for(i = 1; i < sockt->fd_max; i++) { - if(!session[i]) + if(!sockt->session[i]) continue; - 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; + if (sockt->session[i]->rdata_tick && DIFF_TICK(sockt->last_tick, sockt->session[i]->rdata_tick) > sockt->stall_time) { + if( sockt->session[i]->flag.server ) {/* server is special */ + if( sockt->session[i]->flag.ping != 2 )/* only update if necessary otherwise it'd resend the ping unnecessarily */ + sockt->session[i]->flag.ping = 1; } else { ShowInfo("Session #%d timed out\n", i); sockt->eof(i); @@ -881,16 +881,16 @@ int do_sockets(int next) #ifdef __clang_analyzer__ // 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; + if (!sockt->session[i]) continue; #endif // __clang_analyzer__ - session[i]->func_parse(i); + sockt->session[i]->func_parse(i); - if(!session[i]) + if(!sockt->session[i]) continue; 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) { + if (sockt->session[i]->rdata_size == sockt->session[i]->max_rdata) { sockt->eof(i); continue; } @@ -1217,15 +1217,15 @@ void socket_final(void) #endif for( i = 1; i < sockt->fd_max; i++ ) - if(session[i]) + if(sockt->session[i]) sockt->close(i); - // session[0] - aFree(session[0]->rdata); - aFree(session[0]->wdata); - aFree(session[0]); + // sockt->session[0] + aFree(sockt->session[0]->rdata); + aFree(sockt->session[0]->wdata); + aFree(sockt->session[0]); - aFree(session); + aFree(sockt->session); if (sockt->lan_subnet) aFree(sockt->lan_subnet); @@ -1253,7 +1253,7 @@ void socket_close(int fd) 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. - if (session[fd]) delete_session(fd); + if (sockt->session[fd]) delete_session(fd); } /// Retrieve local ips in host byte order. @@ -1397,14 +1397,14 @@ void socket_init(void) memset(send_shortlist_set, 0, sizeof(send_shortlist_set)); #endif - CREATE(session, struct socket_data *, FD_SETSIZE); + CREATE(sockt->session, struct socket_data *, FD_SETSIZE); socket_config_read(SOCKET_CONF_FILENAME); // initialize last send-receive tick sockt->last_tick = time(NULL); - // session[0] is now currently used for disconnected sessions of the map server, and as such, + // sockt->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] create_session(0, null_recv, null_send, null_parse); @@ -1416,19 +1416,16 @@ void socket_init(void) #endif ShowInfo("Server supports up to '"CL_WHITE"%"PRId64""CL_RESET"' concurrent connections.\n", rlim_cur); - - /* Hercules Plugin Manager */ - HPM->share(session,"session"); } bool session_is_valid(int fd) { - return ( fd > 0 && fd < FD_SETSIZE && session[fd] != NULL ); + return ( fd > 0 && fd < FD_SETSIZE && sockt->session[fd] != NULL ); } bool session_is_active(int fd) { - return ( sockt->session_is_valid(fd) && !session[fd]->flag.eof ); + return ( sockt->session_is_valid(fd) && !sockt->session[fd]->flag.eof ); } // Resolves hostname into a numeric ip. @@ -1588,20 +1585,20 @@ void send_shortlist_do_sends() send_shortlist_set[idx]&=~(1<<bit);// unset fd // If this session still exists, perform send operations on it and // check for the eof state. - if( session[fd] ) + if( sockt->session[fd] ) { // Send data - if( session[fd]->wdata_size ) - session[fd]->func_send(fd); + if( sockt->session[fd]->wdata_size ) + sockt->session[fd]->func_send(fd); // If it's been marked as eof, call the parse func on it so that // the socket will be immediately closed. - if( session[fd]->flag.eof ) - session[fd]->func_parse(fd); + if( sockt->session[fd]->flag.eof ) + sockt->session[fd]->func_parse(fd); // If the session still exists, is not eof and has things left to // be sent from it we'll re-add it to the shortlist. - if( session[fd] && !session[fd]->flag.eof && session[fd]->wdata_size ) + if( sockt->session[fd] && !sockt->session[fd]->flag.eof && sockt->session[fd]->wdata_size ) send_shortlist_add_fd(fd); } } diff --git a/src/common/socket.h b/src/common/socket.h index e7046b0d1..18bf25178 100644 --- a/src/common/socket.h +++ b/src/common/socket.h @@ -23,9 +23,14 @@ 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 ) 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)) +#define WFIFOHEAD(fd, size) \ + do{ \ + if ((fd) && sockt->session[fd]->wdata_size + (size) > sockt->session[fd]->max_wdata) \ + sockt->realloc_writefifo((fd), (size)); \ + } while(0) + +#define RFIFOP(fd,pos) (sockt->session[fd]->rdata + sockt->session[fd]->rdata_pos + (pos)) +#define WFIFOP(fd,pos) (sockt->session[fd]->wdata + sockt->session[fd]->wdata_size + (pos)) #define RFIFOB(fd,pos) (*(uint8*)RFIFOP((fd),(pos))) #define WFIFOB(fd,pos) (*(uint8*)WFIFOP((fd),(pos))) @@ -35,18 +40,18 @@ struct HPluginData; #define WFIFOL(fd,pos) (*(uint32*)WFIFOP((fd),(pos))) #define RFIFOQ(fd,pos) (*(uint64*)RFIFOP((fd),(pos))) #define WFIFOQ(fd,pos) (*(uint64*)WFIFOP((fd),(pos))) -#define RFIFOSPACE(fd) (session[fd]->max_rdata - session[fd]->rdata_size) -#define WFIFOSPACE(fd) (session[fd]->max_wdata - session[fd]->wdata_size) +#define RFIFOSPACE(fd) (sockt->session[fd]->max_rdata - sockt->session[fd]->rdata_size) +#define WFIFOSPACE(fd) (sockt->session[fd]->max_wdata - sockt->session[fd]->wdata_size) -#define RFIFOREST(fd) (session[fd]->flag.eof ? 0 : session[fd]->rdata_size - session[fd]->rdata_pos) +#define RFIFOREST(fd) (sockt->session[fd]->flag.eof ? 0 : sockt->session[fd]->rdata_size - sockt->session[fd]->rdata_pos) #define RFIFOFLUSH(fd) \ do { \ - if(session[fd]->rdata_size == session[fd]->rdata_pos){ \ - session[fd]->rdata_size = session[fd]->rdata_pos = 0; \ + if(sockt->session[fd]->rdata_size == sockt->session[fd]->rdata_pos){ \ + sockt->session[fd]->rdata_size = sockt->session[fd]->rdata_pos = 0; \ } else { \ - session[fd]->rdata_size -= session[fd]->rdata_pos; \ - memmove(session[fd]->rdata, session[fd]->rdata+session[fd]->rdata_pos, session[fd]->rdata_size); \ - session[fd]->rdata_pos = 0; \ + sockt->session[fd]->rdata_size -= sockt->session[fd]->rdata_pos; \ + memmove(sockt->session[fd]->rdata, sockt->session[fd]->rdata+sockt->session[fd]->rdata_pos, sockt->session[fd]->rdata_size); \ + sockt->session[fd]->rdata_pos = 0; \ } \ } while(0) @@ -54,7 +59,7 @@ struct HPluginData; #define RFIFOSKIP(fd, len) (sockt->rfifoskip(fd, len)) /* [Ind/Hercules] */ -#define RFIFO2PTR(fd) (void*)(session[fd]->rdata + session[fd]->rdata_pos) +#define RFIFO2PTR(fd) (void*)(sockt->session[fd]->rdata + sockt->session[fd]->rdata_pos) // buffer I/O macros #define RBUFP(p,pos) (((uint8*)(p)) + (pos)) @@ -127,11 +132,6 @@ struct s_subnet { #define MAKEIP(a,b,c,d) ((uint32)( ( ( (a)&0xFF ) << 24 ) | ( ( (b)&0xFF ) << 16 ) | ( ( (c)&0xFF ) << 8 ) | ( ( (d)&0xFF ) << 0 ) )) /** - * This stays out of the interface. - **/ -struct socket_data **session; - -/** * Socket.c interface, mostly for reading however. **/ struct socket_interface { @@ -143,6 +143,8 @@ struct socket_interface { uint32 addr_[16]; // ip addresses of local host (host byte order) int naddr_; // # of ip addresses + struct socket_data **session; + struct s_subnet *lan_subnet; ///< LAN subnets array int lan_subnet_count; ///< LAN subnets count struct s_subnet *trusted_ip; ///< Trusted IP ranges array diff --git a/src/login/login.c b/src/login/login.c index d17e5d2df..2b429bad0 100644 --- a/src/login/login.c +++ b/src/login/login.c @@ -780,7 +780,7 @@ int login_parse_fromchar(int fd) return 0; } - if( session[fd]->flag.eof ) + if( sockt->session[fd]->flag.eof ) { sockt->close(fd); server[id].fd = -1; @@ -1033,14 +1033,14 @@ int login_mmo_auth(struct login_session_data* sd, bool isServer) { char ip[16]; nullpo_ret(sd); - sockt->ip2str(session[sd->fd]->client_addr, ip); + sockt->ip2str(sockt->session[sd->fd]->client_addr, ip); // DNS Blacklist check if( login_config.use_dnsbl ) { char r_ip[16]; char ip_dnsbl[256]; char* dnsbl_serv; - uint8* sin_addr = (uint8*)&session[sd->fd]->client_addr; + uint8* sin_addr = (uint8*)&sockt->session[sd->fd]->client_addr; sprintf(r_ip, "%u.%u.%u.%u", sin_addr[0], sin_addr[1], sin_addr[2], sin_addr[3]); @@ -1190,7 +1190,7 @@ void login_auth_ok(struct login_session_data* sd) nullpo_retv(sd); fd = sd->fd; - ip = session[fd]->client_addr; + ip = sockt->session[fd]->client_addr; if( runflag != LOGINSERVER_ST_RUNNING ) { // players can only login while running @@ -1312,7 +1312,7 @@ void login_auth_failed(struct login_session_data* sd, int result) nullpo_retv(sd); fd = sd->fd; - ip = session[fd]->client_addr; + ip = sockt->session[fd]->client_addr; if (login_config.log_login) { const char* error; @@ -1533,7 +1533,7 @@ void login_parse_request_connection(int fd, struct login_session_data* sd, const ShowInfo("Connection request of the char-server '%s' @ %u.%u.%u.%u:%u (account: '%s', pass: '%s', ip: '%s')\n", server_name, CONVIP(server_ip), server_port, sd->userid, sd->passwd, ip); sprintf(message, "charserver - %s@%u.%u.%u.%u:%u", server_name, CONVIP(server_ip), server_port); - login_log(session[fd]->client_addr, sd->userid, 100, message); + login_log(sockt->session[fd]->client_addr, sd->userid, 100, message); result = login->mmo_auth(sd, true); if (runflag == LOGINSERVER_ST_RUNNING && @@ -1553,8 +1553,8 @@ void login_parse_request_connection(int fd, struct login_session_data* sd, const server[sd->account_id].type = type; server[sd->account_id].new_ = new_; - session[fd]->func_parse = login->parse_fromchar; - session[fd]->flag.server = 1; + sockt->session[fd]->func_parse = login->parse_fromchar; + sockt->session[fd]->flag.server = 1; sockt->realloc_fifo(fd, FIFOSIZE_SERVERLINK, FIFOSIZE_SERVERLINK); // send connection success @@ -1572,14 +1572,14 @@ void login_parse_request_connection(int fd, struct login_session_data* sd, const //---------------------------------------------------------------------------------------- int login_parse_login(int fd) { - struct login_session_data* sd = (struct login_session_data*)session[fd]->session_data; + struct login_session_data* sd = (struct login_session_data*)sockt->session[fd]->session_data; int result; char ip[16]; - uint32 ipl = session[fd]->client_addr; + uint32 ipl = sockt->session[fd]->client_addr; sockt->ip2str(ipl, ip); - if( session[fd]->flag.eof ) + if( sockt->session[fd]->flag.eof ) { ShowInfo("Closed connection from '"CL_WHITE"%s"CL_RESET"'.\n", ip); sockt->close(fd); @@ -1599,8 +1599,8 @@ int login_parse_login(int fd) } // create a session for this new connection - CREATE(session[fd]->session_data, struct login_session_data, 1); - sd = (struct login_session_data*)session[fd]->session_data; + CREATE(sockt->session[fd]->session_data, struct login_session_data, 1); + sd = (struct login_session_data*)sockt->session[fd]->session_data; sd->fd = fd; } diff --git a/src/map/atcommand.c b/src/map/atcommand.c index b84546054..6c5a6282e 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 = sockt->session_is_valid(fd) ? session[fd]->session_data : NULL; + struct map_session_data *sd = sockt->session_is_valid(fd) ? sockt->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] ) diff --git a/src/map/chrif.c b/src/map/chrif.c index f9b6af7f7..62df026da 100644 --- a/src/map/chrif.c +++ b/src/map/chrif.c @@ -124,8 +124,8 @@ bool chrif_auth_delete(int account_id, int char_id, enum sd_state state) { if ( (node = chrif->auth_check(account_id, char_id, state) ) ) { int fd = node->sd ? node->sd->fd : node->fd; - if ( session[fd] && session[fd]->session_data == node->sd ) - session[fd]->session_data = NULL; + if ( sockt->session[fd] && sockt->session[fd]->session_data == node->sd ) + sockt->session[fd]->session_data = NULL; if ( node->sd ) { if( node->sd->regs.vars ) @@ -177,8 +177,8 @@ bool chrif_auth_logout(TBL_PC* sd, enum sd_state state) { if(sd->fd && state == ST_LOGOUT) { //Disassociate player, and free it after saving ack returns. [Skotlex] //fd info must not be lost for ST_MAPCHANGE as a final packet needs to be sent to the player. - if ( session[sd->fd] ) - session[sd->fd]->session_data = NULL; + if ( sockt->session[sd->fd] ) + sockt->session[sd->fd]->session_data = NULL; sd->fd = 0; } @@ -238,7 +238,7 @@ void chrif_setport(uint16 port) { // says whether the char-server is connected or not int chrif_isconnected(void) { - return (chrif->fd > 0 && session[chrif->fd] != NULL && chrif->state == 2); + return (chrif->fd > 0 && sockt->session[chrif->fd] != NULL && chrif->state == 2); } /*========================================== @@ -384,7 +384,7 @@ bool chrif_changemapserver(struct map_session_data* sd, uint32 ip, uint16 port) WFIFOL(chrif->fd,24) = htonl(ip); WFIFOW(chrif->fd,28) = htons(port); WFIFOB(chrif->fd,30) = sd->status.sex; - WFIFOL(chrif->fd,31) = htonl(session[sd->fd]->client_addr); + WFIFOL(chrif->fd,31) = htonl(sockt->session[sd->fd]->client_addr); WFIFOL(chrif->fd,35) = sd->group_id; WFIFOSET(chrif->fd,39); @@ -552,7 +552,7 @@ void chrif_authreq(struct map_session_data *sd, bool hstandalone) { WFIFOL(chrif->fd,6) = sd->status.char_id; WFIFOL(chrif->fd,10) = sd->login_id1; WFIFOB(chrif->fd,14) = sd->status.sex; - WFIFOL(chrif->fd,15) = htonl(session[sd->fd]->client_addr); + WFIFOL(chrif->fd,15) = htonl(sockt->session[sd->fd]->client_addr); WFIFOB(chrif->fd,19) = hstandalone ? 1 : 0; WFIFOSET(chrif->fd,20); chrif->sd_to_auth(sd, ST_LOGIN); @@ -1308,7 +1308,7 @@ void chrif_keepalive(int fd) { WFIFOSET(fd,2); } void chrif_keepalive_ack(int fd) { - session[fd]->flag.ping = 0;/* reset ping state, we received a packet */ + sockt->session[fd]->flag.ping = 0;/* reset ping state, we received a packet */ } void chrif_skillid2idx(int fd) { int i, count = 0; @@ -1344,18 +1344,18 @@ int chrif_parse(int fd) { return 0; } - if ( session[fd]->flag.eof ) { + if ( sockt->session[fd]->flag.eof ) { 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 */ + } else if ( sockt->session[fd]->flag.ping ) {/* we've reached stall time */ + if( DIFF_TICK(sockt->last_tick, sockt->session[fd]->rdata_tick) > (sockt->stall_time * 2) ) {/* we can't wait any longer */ sockt->eof(fd); return 0; - } else if( session[fd]->flag.ping != 2 ) { /* we haven't sent ping out yet */ + } else if( sockt->session[fd]->flag.ping != 2 ) { /* we haven't sent ping out yet */ chrif->keepalive(fd); - session[fd]->flag.ping = 2; + sockt->session[fd]->flag.ping = 2; } } @@ -1475,7 +1475,7 @@ bool send_users_tochar(void) { *------------------------------------------*/ int check_connect_char_server(int tid, int64 tick, int id, intptr_t data) { static int displayed = 0; - if ( chrif->fd <= 0 || session[chrif->fd] == NULL ) { + if ( chrif->fd <= 0 || sockt->session[chrif->fd] == NULL ) { if ( !displayed ) { ShowStatus("Attempting to connect to Char Server. Please wait.\n"); displayed = 1; @@ -1486,8 +1486,8 @@ int check_connect_char_server(int tid, int64 tick, int id, intptr_t data) { 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; + sockt->session[chrif->fd]->func_parse = chrif->parse; + sockt->session[chrif->fd]->flag.server = 1; sockt->realloc_fifo(chrif->fd, FIFOSIZE_SERVERLINK, FIFOSIZE_SERVERLINK); chrif->connect(chrif->fd); diff --git a/src/map/clif.c b/src/map/clif.c index db5259d81..0784326c9 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -291,7 +291,7 @@ int clif_send_sub(struct block_list *bl, va_list ap) { nullpo_ret(sd = (struct map_session_data *)bl); fd = sd->fd; - if (!fd || session[fd] == NULL) //Don't send to disconnected clients. + if (!fd || sockt->session[fd] == NULL) //Don't send to disconnected clients. return 0; buf = va_arg(ap,void*); @@ -427,7 +427,7 @@ bool clif_send(const void* buf, int len, struct block_list* bl, enum send_target for(i = 0; i < cd->users; i++) { if (type == CHAT_WOS && cd->usersd[i] == sd) continue; - if ((fd=cd->usersd[i]->fd) >0 && session[fd]) { // Added check to see if session exists [PoW] + if ((fd=cd->usersd[i]->fd) >0 && sockt->session[fd]) { // Added check to see if session exists [PoW] WFIFOHEAD(fd,len); memcpy(WFIFOP(fd,0), buf, len); WFIFOSET(fd,len); @@ -690,7 +690,7 @@ void clif_authrefuse(int fd, uint8 error_code) // TODO: type enum void clif_authfail_fd(int fd, int type) { - if (!fd || !session[fd] || session[fd]->func_parse != clif->parse) //clif_authfail should only be invoked on players! + if (!fd || !sockt->session[fd] || sockt->session[fd]->func_parse != clif->parse) //clif_authfail should only be invoked on players! return; WFIFOHEAD(fd, packet_len(0x81)); @@ -1710,7 +1710,7 @@ void clif_quitsave(int fd,struct map_session_data *sd) { else if (sd->fd) { //Disassociate session from player (session is deleted after this function was called) //And set a timer to make him quit later. - session[sd->fd]->session_data = NULL; + sockt->session[sd->fd]->session_data = NULL; sd->fd = 0; timer->add(timer->gettick() + 10000, clif->delayquit, sd->bl.id, 0); } @@ -5682,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 = sockt->session_is_valid(fd) ? session[fd]->session_data : NULL; + struct map_session_data *sd = sockt->session_is_valid(fd) ? sockt->session[fd]->session_data : NULL; struct packet_wis_end p; if( !sd ) @@ -8975,7 +8975,7 @@ void clif_parse_WantToConnection(int fd, struct map_session_data* sd) { * clif->cryptKey[1] ) + clif->cryptKey[2]) & 0xFFFFFFFF; sd->parse_cmd_func = clif->parse_cmd; - session[fd]->session_data = sd; + sockt->session[fd]->session_data = sd; pc->setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd); @@ -9980,7 +9980,7 @@ void clif_parse_Restart(int fd, struct map_session_data *sd) { && (!battle_config.prevent_logout || DIFF_TICK(timer->gettick(), sd->canlog_tick) > battle_config.prevent_logout) ) { //Send to char-server for character selection. - chrif->charselectreq(sd, session[fd]->client_addr); + chrif->charselectreq(sd, sockt->session[fd]->client_addr); } else { clif->disconnect_ack(sd, 1); } @@ -18296,13 +18296,13 @@ int clif_parse(int fd) { unsigned short (*parse_cmd_func)(int fd, struct map_session_data *sd); // begin main client packet processing loop - sd = (TBL_PC *)session[fd]->session_data; + sd = (TBL_PC *)sockt->session[fd]->session_data; - if (session[fd]->flag.eof) { + if (sockt->session[fd]->flag.eof) { if (sd) { if (sd->state.autotrade) { //Disassociate character from the socket connection. - session[fd]->session_data = NULL; + sockt->session[fd]->session_data = NULL; sd->fd = 0; ShowInfo("Character '"CL_WHITE"%s"CL_RESET"' logged off (using @autotrade).\n", sd->status.name); } else @@ -18316,7 +18316,7 @@ int clif_parse(int fd) { map->quit(sd); } } else { - ShowInfo("Closed connection from '"CL_WHITE"%s"CL_RESET"'.\n", sockt->ip2str(session[fd]->client_addr, NULL)); + ShowInfo("Closed connection from '"CL_WHITE"%s"CL_RESET"'.\n", sockt->ip2str(sockt->session[fd]->client_addr, NULL)); } sockt->close(fd); return 0; diff --git a/src/map/intif.c b/src/map/intif.c index 26fd1949c..a2e19f9e9 100644 --- a/src/map/intif.c +++ b/src/map/intif.c @@ -45,7 +45,7 @@ struct intif_interface intif_s; int CheckForCharServer(void) { - return ((chrif->fd <= 0) || session[chrif->fd] == NULL || session[chrif->fd]->wdata == NULL); + return ((chrif->fd <= 0) || sockt->session[chrif->fd] == NULL || sockt->session[chrif->fd]->wdata == NULL); } // pet @@ -2145,9 +2145,9 @@ void intif_request_accinfo( int u_fd, int aid, int group_lv, char* query ) { void intif_parse_MessageToFD(int fd) { int u_fd = RFIFOL(fd,4); - if( session[u_fd] && session[u_fd]->session_data ) { + if( sockt->session[u_fd] && sockt->session[u_fd]->session_data ) { int aid = RFIFOL(fd,8); - struct map_session_data * sd = session[u_fd]->session_data; + struct map_session_data * sd = sockt->session[u_fd]->session_data; /* matching e.g. previous fd owner didn't dc during request or is still the same */ if( sd && sd->bl.id == aid ) { char msg[512]; diff --git a/src/map/irc-bot.c b/src/map/irc-bot.c index 451d224fd..34069f74f 100644 --- a/src/map/irc-bot.c +++ b/src/map/irc-bot.c @@ -42,8 +42,8 @@ int irc_connect_timer(int tid, int64 tick, int id, intptr_t data) { ircbot->last_try = timer->gettick(); 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; + sockt->session[ircbot->fd]->func_parse = ircbot->parse; + sockt->session[ircbot->fd]->flag.server = 1; timer->add(timer->gettick() + 3000, ircbot->identify_timer, 0, 0); ircbot->isOn = true; } @@ -114,7 +114,7 @@ struct irc_func* irc_func_search(char* function_name) { int irc_parse(int fd) { char *parse_string = NULL, *str_safe = NULL; - if (session[fd]->flag.eof) { + if (sockt->session[fd]->flag.eof) { sockt->close(fd); ircbot->fd = 0; ircbot->isOn = false; diff --git a/src/map/pc.c b/src/map/pc.c index 327b7428f..d7b7a9f48 100644 --- a/src/map/pc.c +++ b/src/map/pc.c @@ -45,7 +45,7 @@ #include "common/nullpo.h" #include "common/random.h" #include "common/showmsg.h" -#include "common/socket.h" // session[] +#include "common/socket.h" #include "common/strlib.h" // safestrncpy() #include "common/sysinfo.h" #include "common/timer.h" @@ -1007,7 +1007,7 @@ int pc_isequip(struct map_session_data *sd,int n) bool pc_authok(struct map_session_data *sd, int login_id2, time_t expiration_time, int group_id, struct mmo_charstatus *st, bool changing_mapservers) { int i; int64 tick = timer->gettick(); - uint32 ip = session[sd->fd]->client_addr; + uint32 ip = sockt->session[sd->fd]->client_addr; sd->login_id2 = login_id2; diff --git a/src/map/script.c b/src/map/script.c index 837f83668..4fb196255 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -18265,21 +18265,21 @@ BUILDIN(getcharip) { } /* check for sd and IP */ - if (!sd || !session[sd->fd]->client_addr) + if (!sd || !sockt->session[sd->fd]->client_addr) { script_pushconststr(st, ""); return true; } /* return the client ip_addr converted for output */ - if (sd && sd->fd && session[sd->fd]) + if (sd && sd->fd && sockt->session[sd->fd]) { /* initiliaze */ const char *ip_addr = NULL; uint32 ip; /* set ip, ip_addr and convert to ip and push str */ - ip = session[sd->fd]->client_addr; + ip = sockt->session[sd->fd]->client_addr; ip_addr = sockt->ip2str(ip, NULL); script_pushstrcopy(st, ip_addr); } diff --git a/src/plugins/sample.c b/src/plugins/sample.c index b034775b0..d11c082b4 100644 --- a/src/plugins/sample.c +++ b/src/plugins/sample.c @@ -44,15 +44,15 @@ struct sample_data_struct { /* cmd 0xf3 - it is a client-server existent id, for clif_parse_GlobalMessage */ /* in this sample we do nothing and simply redirect */ void sample_packet0f3(int fd) { - struct map_session_data *sd = session[fd]->session_data; + struct map_session_data *sd = sockt->session[fd]->session_data; struct sample_data_struct *data; if( !sd ) return;/* socket didn't fully log-in? this packet shouldn't do anything then! */ ShowInfo("sample_packet0f3: Hello World! received 0xf3 for '%s', redirecting!\n",sd->status.name); - /* sample usage of appending data to a socket_data (session[]) entry */ - if( !(data = getFromSession(session[fd],0)) ) { + /* sample usage of appending data to a socket_data (sockt->session[]) entry */ + if( !(data = getFromSession(sockt->session[fd],0)) ) { CREATE(data,struct sample_data_struct,1); data->lastMSGPosition.map = sd->status.last_point.map; @@ -60,13 +60,13 @@ void sample_packet0f3(int fd) { data->lastMSGPosition.y = sd->status.last_point.y; data->someNumber = rand()%777; - ShowInfo("Created Appended session[] data, %d %d %d %d\n",data->lastMSGPosition.map,data->lastMSGPosition.x,data->lastMSGPosition.y,data->someNumber); - addToSession(session[fd],data,0,true); + ShowInfo("Created Appended sockt->session[] data, %d %d %d %d\n",data->lastMSGPosition.map,data->lastMSGPosition.x,data->lastMSGPosition.y,data->someNumber); + addToSession(sockt->session[fd],data,0,true); } else { - ShowInfo("Existent Appended session[] data, %d %d %d %d\n",data->lastMSGPosition.map,data->lastMSGPosition.x,data->lastMSGPosition.y,data->someNumber); + ShowInfo("Existent Appended sockt->session[] data, %d %d %d %d\n",data->lastMSGPosition.map,data->lastMSGPosition.x,data->lastMSGPosition.y,data->someNumber); if( rand()%4 == 2 ) { - ShowInfo("Removing Appended session[] data\n"); - removeFromSession(session[fd],0); + ShowInfo("Removing Appended sockt->session[] data\n"); + removeFromSession(sockt->session[fd],0); } } @@ -133,9 +133,6 @@ HPExport void plugin_init (void) { pc = GET_SYMBOL("pc"); strlib = GET_SYMBOL("strlib"); - /* session[] */ - session = GET_SYMBOL("session"); - ShowInfo ("Server type is "); switch (*server_type) { |