summaryrefslogtreecommitdiff
path: root/src/char_sql/char.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/char_sql/char.c')
-rw-r--r--src/char_sql/char.c56
1 files changed, 25 insertions, 31 deletions
diff --git a/src/char_sql/char.c b/src/char_sql/char.c
index b44717d65..e18475c36 100644
--- a/src/char_sql/char.c
+++ b/src/char_sql/char.c
@@ -77,12 +77,12 @@ char login_db_level[32] = "level";
int lowest_gm_level = 1;
struct mmo_map_server {
+ int fd;
uint32 ip;
uint16 port;
int users;
unsigned short map[MAX_MAP_PER_SERVER];
} server[MAX_MAP_SERVERS];
-int server_fd[MAX_MAP_SERVERS];
int login_fd, char_fd;
char userid[24];
@@ -239,7 +239,7 @@ void set_char_online(int map_id, int char_id, int account_id)
if (char_id != 99)
ShowNotice("set_char_online: Character %d:%d marked in map server %d, but map server %d claims to have (%d:%d) online!\n",
character->account_id, character->char_id, character->server, map_id, account_id, char_id);
- mapif_disconnectplayer(server_fd[character->server], character->account_id, character->char_id, 2);
+ mapif_disconnectplayer(server[character->server].fd, character->account_id, character->char_id, 2);
}
character->char_id = (char_id==99)?-1:char_id;
@@ -329,15 +329,14 @@ static int char_db_setoffline(DBKey key, void* data, va_list ap)
static int char_db_kickoffline(DBKey key, void* data, va_list ap)
{
struct online_char_data* character = (struct online_char_data*)data;
- int server = va_arg(ap, int);
+ int server_id = va_arg(ap, int);
- if (server > -1 && character->server != server)
+ if (server_id > -1 && character->server != server_id)
return 0;
//Kick out any connected characters, and set them offline as appropiate.
if (character->server > -1)
- mapif_disconnectplayer(server_fd[character->server],
- character->account_id, character->char_id, 1);
+ mapif_disconnectplayer(server[character->server].fd, character->account_id, character->char_id, 1);
else if (character->waiting_disconnect == -1)
set_char_offline(character->char_id, character->account_id);
else return 0;
@@ -1423,7 +1422,7 @@ int count_users(void)
if (login_fd > 0 && session[login_fd]){
users = 0;
for(i = 0; i < MAX_MAP_SERVERS; i++) {
- if (server_fd[i] > 0) {
+ if (server[i].fd > 0) {
users += server[i].users;
}
}
@@ -1584,7 +1583,7 @@ static void char_auth_ok(int fd, struct char_session_data *sd)
{ // check if character is not online already. [Skotlex]
if (character->server > -1)
{ //Character already online. KICK KICK KICK
- mapif_disconnectplayer(server_fd[character->server], character->account_id, character->char_id, 2);
+ mapif_disconnectplayer(server[character->server].fd, character->account_id, character->char_id, 2);
if (character->waiting_disconnect == -1)
character->waiting_disconnect = add_timer(gettick()+20000, chardb_waiting_disconnect, character->account_id, 0);
WFIFOW(fd,0) = 0x81;
@@ -1660,7 +1659,7 @@ int parse_fromlogin(int fd)
send_accounts_tologin(-1, gettick(), 0, 0);
// if no map-server already connected, display a message...
- ARR_FIND( 0, MAX_MAP_SERVERS, i, server_fd[i] > 0 && server[i].map[0] );
+ ARR_FIND( 0, MAX_MAP_SERVERS, i, server[i].fd > 0 && server[i].map[0] );
if( i == MAX_MAP_SERVERS )
ShowStatus("Awaiting maps from map-server.\n");
}
@@ -1892,7 +1891,7 @@ int parse_fromlogin(int fd)
{ //Kick out this player.
if( character->server != -1 )
{ //Kick it from the map server it is on.
- mapif_disconnectplayer(server_fd[character->server], character->account_id, character->char_id, 2);
+ mapif_disconnectplayer(server[character->server].fd, character->account_id, character->char_id, 2);
if (character->waiting_disconnect == -1)
character->waiting_disconnect = add_timer(gettick()+15000, chardb_waiting_disconnect, character->account_id, 0);
}
@@ -2124,9 +2123,7 @@ int parse_frommap(int fd)
return 0;
}
- for(id = 0; id < MAX_MAP_SERVERS; id++)
- if (server_fd[id] == fd)
- break;
+ ARR_FIND( 0, MAX_MAP_SERVERS, id, server[id].fd == fd );
if(id == MAX_MAP_SERVERS)
set_eof(fd);
if(session[fd]->eof) {
@@ -2146,9 +2143,9 @@ int parse_frommap(int fd)
mapif_sendallwos(fd, buf, WBUFW(buf,2));
}
memset(&server[id], 0, sizeof(struct mmo_map_server));
- if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `ragsrvinfo` WHERE `index`='%d'", server_fd[id]) )
+ if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `ragsrvinfo` WHERE `index`='%d'", server[id].fd) )
Sql_ShowDebug(sql_handle);
- server_fd[id] = -1;
+ server[id].fd = -1;
online_char_db->foreach(online_char_db,char_db_setoffline,id); //Tag relevant chars as 'in disconnected' server.
}
do_close(fd);
@@ -2215,7 +2212,7 @@ int parse_frommap(int fd)
}
// Transmitting the maps of the other map-servers to the new map-server
for(x = 0; x < MAX_MAP_SERVERS; x++) {
- if (server_fd[x] > 0 && x != id) {
+ if (server[x].fd > 0 && x != id) {
WFIFOHEAD(fd,10 +4*MAX_MAP_PER_SERVER);
WFIFOW(fd,0) = 0x2b04;
WFIFOL(fd,4) = htonl(server[x].ip);
@@ -2315,7 +2312,7 @@ int parse_frommap(int fd)
{
ShowNotice("Set map user: Character (%d:%d) marked on map server %d, but map server %d claims to have (%d:%d) online!\n",
character->account_id, character->char_id, character->server, id, aid, cid);
- mapif_disconnectplayer(server_fd[character->server], character->account_id, character->char_id, 2);
+ mapif_disconnectplayer(server[character->server].fd, character->account_id, character->char_id, 2);
}
character->server = id;
character->char_id = cid;
@@ -2397,7 +2394,7 @@ int parse_frommap(int fd)
map_id = search_mapserver(RFIFOW(fd,18), ntohl(RFIFOL(fd,24)), ntohs(RFIFOW(fd,28))); //Locate mapserver by ip and port.
if (map_id >= 0)
- map_fd = server_fd[map_id];
+ map_fd = server[map_id].fd;
//Char should just had been saved before this packet, so this should be safe. [Skotlex]
char_data = uidb_get(char_db_,RFIFOL(fd,14));
if (char_data == NULL)
@@ -2754,7 +2751,7 @@ int search_mapserver(unsigned short map, uint32 ip, uint16 port)
for(i = 0; i < MAX_MAP_SERVERS; i++)
{
- if (server_fd[i] > 0
+ if (server[i].fd > 0
&& (ip == (uint32)-1 || server[i].ip == ip)
&& (port == (uint16)-1 || server[i].port == port))
{
@@ -2930,7 +2927,7 @@ int parse_char(int fd)
if (i < 0) {
unsigned short j;
//First check that there's actually a map server online.
- ARR_FIND( 0, MAX_MAP_SERVERS, j, server_fd[j] >= 0 && server[j].map[0] );
+ ARR_FIND( 0, MAX_MAP_SERVERS, j, server[j].fd >= 0 && server[j].map[0] );
if (j == MAX_MAP_SERVERS) {
ShowInfo("Connection Closed. No map servers available.\n");
WFIFOHEAD(fd,3);
@@ -2994,10 +2991,10 @@ int parse_char(int fd)
auth_fifo[auth_fifo_pos].ip = session[fd]->client_addr;
//Send NEW auth packet [Kevin]
- if ((map_fd = server_fd[i]) < 1 || session[map_fd] == NULL)
+ if ((map_fd = server[i].fd) < 1 || session[map_fd] == NULL)
{
ShowError("parse_char: Attempting to write to invalid session %d! Map Server #%d disconnected.\n", map_fd, i);
- server_fd[i] = -1;
+ server[i].fd = -1;
memset(&server[i], 0, sizeof(struct mmo_map_server));
//Send server closed.
WFIFOHEAD(fd,3);
@@ -3174,10 +3171,7 @@ int parse_char(int fd)
char* l_pass = RFIFOP(fd,26);
l_user[23] = '\0';
l_pass[23] = '\0';
- for(i = 0; i < MAX_MAP_SERVERS; i++) {
- if (server_fd[i] <= 0)
- break;
- }
+ ARR_FIND( 0, MAX_MAP_SERVERS, i, server[i].fd <= 0 );
if (i == MAX_MAP_SERVERS || strcmp(l_user, userid) || strcmp(l_pass, passwd)) {
WFIFOHEAD(fd,3);
WFIFOW(fd,0) = 0x2af9;
@@ -3189,7 +3183,7 @@ int parse_char(int fd)
WFIFOB(fd,2) = 0;
WFIFOSET(fd,3);
- server_fd[i] = fd;
+ server[i].fd = fd;
server[i].ip = ntohl(RFIFOL(fd,54));
server[i].port = ntohs(RFIFOW(fd,58));
server[i].users = 0;
@@ -3284,7 +3278,7 @@ int mapif_sendall(unsigned char *buf, unsigned int len)
c = 0;
for(i = 0; i < MAX_MAP_SERVERS; i++) {
int fd;
- if ((fd = server_fd[i]) > 0) {
+ if ((fd = server[i].fd) > 0) {
WFIFOHEAD(fd,len);
memcpy(WFIFOP(fd,0), buf, len);
WFIFOSET(fd,len);
@@ -3302,7 +3296,7 @@ int mapif_sendallwos(int sfd, unsigned char *buf, unsigned int len)
c = 0;
for(i = 0; i < MAX_MAP_SERVERS; i++) {
int fd;
- if ((fd = server_fd[i]) > 0 && fd != sfd) {
+ if ((fd = server[i].fd) > 0 && fd != sfd) {
WFIFOHEAD(fd,len);
memcpy(WFIFOP(fd,0), buf, len);
WFIFOSET(fd,len);
@@ -3318,7 +3312,7 @@ int mapif_send(int fd, unsigned char *buf, unsigned int len)
int i;
if (fd >= 0) {
- ARR_FIND( 0, MAX_MAP_SERVERS, i, fd == server_fd[i] );
+ ARR_FIND( 0, MAX_MAP_SERVERS, i, fd == server[i].fd );
if( i < MAX_MAP_SERVERS )
{
WFIFOHEAD(fd,len);
@@ -3835,7 +3829,7 @@ int do_init(int argc, char **argv)
for(i = 0; i < MAX_MAP_SERVERS; i++) {
memset(&server[i], 0, sizeof(struct mmo_map_server));
- server_fd[i] = -1;
+ server[i].fd = -1;
}
//Read map indexes