summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Changelog-Trunk.txt8
-rw-r--r--conf/Changelog.txt2
-rw-r--r--conf/atcommand_athena.conf3
-rw-r--r--src/char/char.c127
-rw-r--r--src/char_sql/char.c112
-rw-r--r--src/login/login.c18
-rw-r--r--src/login_sql/login.c20
-rw-r--r--src/map/atcommand.c20
-rw-r--r--src/map/chrif.c110
-rw-r--r--src/map/chrif.h2
-rw-r--r--src/map/map.c11
11 files changed, 264 insertions, 169 deletions
diff --git a/Changelog-Trunk.txt b/Changelog-Trunk.txt
index 5b7e17434..ac449cd23 100644
--- a/Changelog-Trunk.txt
+++ b/Changelog-Trunk.txt
@@ -4,6 +4,14 @@ AS OF SVN REV. 5091, WE ARE NOW USING TRUNK. ALL UNTESTED BUGFIXES/FEATURES GO
IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK.
2007/11/09
+ * Re-worked the login-char-map packet spam mechanism
+ - mapserver no longer sends entire user list to charserver every
+ 10 seconds; similar change done to the char-login connection
+ - user count updates are only sent when the value actually changes
+ instead of servers polling each other every few seconds
+ - the servers now prevent interserver connection timeout explicitly by
+ sending ping/ack packet pairs instead of relying on the usercount
+ polling to do so; keepalive is sent every 'stall_time'-2 seconds
* Fixed socket.c checking time() incorrectly (bugreport:394) [ultramage]
* Added a database iterator to db.c/db.h. [FlavioJS]
2007/11/08
diff --git a/conf/Changelog.txt b/conf/Changelog.txt
index b9da37380..ae89cac7e 100644
--- a/conf/Changelog.txt
+++ b/conf/Changelog.txt
@@ -1,5 +1,7 @@
Date Added
+2007/11/08
+ * Removed the unneccessary @refreshonline command
2007/10/29
* Removed petid command (not needed because commands understand names)
* Removed *id2 commands (messy, useless and redundant)
diff --git a/conf/atcommand_athena.conf b/conf/atcommand_athena.conf
index 92ecf2bf5..622ee3be6 100644
--- a/conf/atcommand_athena.conf
+++ b/conf/atcommand_athena.conf
@@ -702,9 +702,6 @@ reloadgmdb: 99
// Change a battle_config flag without rebooting server
setbattleflag: 99
-// Refresh only status of players - SQL Only
-refreshonline: 99
-
// Re-load gm command config (admin command)
reloadatcommand: 99
diff --git a/src/char/char.c b/src/char/char.c
index 0e7d5782d..f7881a33b 100644
--- a/src/char/char.c
+++ b/src/char/char.c
@@ -172,8 +172,6 @@ struct online_char_data {
// Holds all online characters.
static DBMap* online_char_db; // int account_id -> struct online_char_data*
-time_t update_online; // to update online files when we receiving information from a server (not less than 8 seconds)
-
int console = 0;
//------------------------------
@@ -344,6 +342,9 @@ void set_char_online(int map_id, int char_id, int account_id)
character->char_id = (char_id==99)?-1:char_id;
character->server = (char_id==99)?-1:map_id;
+ if( character->server > -1 )
+ server[character->server].users++;
+
if(character->waiting_disconnect != -1) {
delete_timer(character->waiting_disconnect, chardb_waiting_disconnect);
character->waiting_disconnect = -1;
@@ -363,6 +364,9 @@ void set_char_offline(int char_id, int account_id)
if ((character = idb_get(online_char_db, account_id)) != NULL)
{ //We don't free yet to avoid aCalloc/aFree spamming during char change. [Skotlex]
+ if( character->server > -1 )
+ server[character->server].users--;
+
character->char_id = -1;
character->server = -1;
if(character->waiting_disconnect != -1){
@@ -2305,7 +2309,6 @@ int parse_fromlogin(int fd)
}
ShowStatus("From login-server: receiving information of %d GM accounts.\n", GM_num);
char_log("From login-server: receiving information of %d GM accounts.\n", GM_num);
- create_online_files(); // update online players files (perhaps some online players change of GM level)
// send new gm acccounts level to map-servers
memcpy(buf, RFIFOP(fd,0), RFIFOW(fd,2));
WBUFW(buf,0) = 0x2b15;
@@ -2639,10 +2642,6 @@ int parse_frommap(int fd)
switch(RFIFOW(fd,0))
{
- case 0x2718: // map-server alive packet
- RFIFOSKIP(fd,2);
- break;
-
case 0x2af7: // request from map-server to reload GM accounts. Transmission to login-server
if (login_fd > 0) { // don't send request if no login-server
WFIFOHEAD(login_fd,2);
@@ -2672,10 +2671,11 @@ int parse_frommap(int fd)
if (max_account_id != DEFAULT_MAX_ACCOUNT_ID || max_char_id != DEFAULT_MAX_CHAR_ID)
mapif_send_maxid(max_account_id, max_char_id); //Send the current max ids to the server to keep in sync [Skotlex]
+ // send name for wisp to player
WFIFOHEAD(fd, 3 + NAME_LENGTH);
WFIFOW(fd,0) = 0x2afb;
WFIFOB(fd,2) = 0;
- memcpy(WFIFOP(fd,3), wisp_server_name, NAME_LENGTH); // name for wisp to player
+ memcpy(WFIFOP(fd,3), wisp_server_name, NAME_LENGTH);
WFIFOSET(fd,3+NAME_LENGTH);
char_send_fame_list(fd); //Send fame list.
@@ -2774,11 +2774,6 @@ int parse_frommap(int fd)
character->char_id = cid;
character->server = id;
}
- if (update_online < time(NULL)) { // Time is done
- update_online = time(NULL) + 8;
- create_online_files(); // only every 8 sec. (normally, 1 server send users every 5 sec.) Don't update every time, because that takes time, but only every 2 connection.
- // it set to 8 sec because is more than 5 (sec) and if we have more than 1 map-server, informations can be received in shifted.
- }
//If any chars remain in -2, they will be cleaned in the cleanup timer.
RFIFOSKIP(fd,6+i*8);
break;
@@ -3033,8 +3028,6 @@ int parse_frommap(int fd)
}
break;
-// case 0x2b0f: Not used anymore, available for future use
-
case 0x2b10: // Update and send fame ranking list
if (RFIFOREST(fd) < 11)
return 0;
@@ -3147,6 +3140,13 @@ int parse_frommap(int fd)
}
break;
+ case 0x2b23: // map-server alive packet
+ WFIFOHEAD(fd,2);
+ WFIFOW(fd,0) = 0x2b24;
+ WFIFOSET(fd,2);
+ RFIFOSKIP(fd,2);
+ break;
+
case 0x2736: // ip address update
if (RFIFOREST(fd) < 6) return 0;
server[id].ip = ntohl(RFIFOL(fd, 2));
@@ -3783,22 +3783,33 @@ int mapif_send(int fd, unsigned char *buf, unsigned int len)
return 0;
}
-int send_users_tologin(int tid, unsigned int tick, int id, int data)
+int broadcast_user_count(int tid, unsigned int tick, int id, int data)
{
+ uint8 buf[6];
int users = count_users();
- unsigned char buf[16];
- if (login_fd > 0 && session[login_fd]) {
+ // only send an update when needed
+ static prev_users = 0;
+ if( prev_users == users )
+ return 0;
+ prev_users = users;
+
+ if( login_fd > 0 && session[login_fd] )
+ {
// send number of user to login server
WFIFOHEAD(login_fd,6);
WFIFOW(login_fd,0) = 0x2714;
WFIFOL(login_fd,2) = users;
WFIFOSET(login_fd,6);
}
+
// send number of players to all map-servers
WBUFW(buf,0) = 0x2b00;
WBUFL(buf,2) = users;
- mapif_sendall(buf, 6);
+ mapif_sendall(buf,6);
+
+ // refresh online files (txt and html)
+ create_online_files();
return 0;
}
@@ -3868,6 +3879,18 @@ int check_connect_login_server(int tid, unsigned int tick, int id, int data)
return 1;
}
+// sends a ping packet to login server (will receive pong 0x2718)
+int ping_login_server(int tid, unsigned int tick, int id, int data)
+{
+ if (login_fd > 0 && session[login_fd] != NULL)
+ {
+ WFIFOHEAD(login_fd,2);
+ WFIFOW(login_fd,0) = 0x2719;
+ WFIFOSET(login_fd,2);
+ }
+ return 0;
+}
+
//------------------------------------------------
//Invoked 15 seconds after mapif_disconnectplayer in case the map server doesn't
//replies/disconnect the player we tried to kick. [Skotlex]
@@ -3883,6 +3906,23 @@ static int chardb_waiting_disconnect(int tid, unsigned int tick, int id, int dat
return 0;
}
+static int online_data_cleanup_sub(DBKey key, void *data, va_list ap)
+{
+ struct online_char_data *character= (struct online_char_data*)data;
+ if (character->server == -2) //Unknown server.. set them offline
+ set_char_offline(character->char_id, character->account_id);
+ if (character->server < 0)
+ //Free data from players that have not been online for a while.
+ db_remove(online_char_db, key);
+ return 0;
+}
+
+static int online_data_cleanup(int tid, unsigned int tick, int id, int data)
+{
+ online_char_db->foreach(online_char_db, online_data_cleanup_sub);
+ return 0;
+}
+
//----------------------------------
// Reading Lan Support configuration
// Rewrote: Anvanced subnet check [LuzZza]
@@ -3931,10 +3971,10 @@ int char_lan_config_read(const char *lancfgName)
subnet_count++;
}
-
- ShowStatus("Read information about %d subnetworks.\n", subnet_count);
}
+ ShowStatus("Read information about %d subnetworks.\n", subnet_count);
+
fclose(fp);
return 0;
}
@@ -4181,23 +4221,6 @@ void set_server_type(void)
SERVER_TYPE = ATHENA_SERVER_CHAR;
}
-static int online_data_cleanup_sub(DBKey key, void *data, va_list ap)
-{
- struct online_char_data *character= (struct online_char_data*)data;
- if (character->server == -2) //Unknown server.. set them offline
- set_char_offline(character->char_id, character->account_id);
- if (character->server < 0)
- //Free data from players that have not been online for a while.
- db_remove(online_char_db, key);
- return 0;
-}
-
-static int online_data_cleanup(int tid, unsigned int tick, int id, int data)
-{
- online_char_db->foreach(online_char_db, online_data_cleanup_sub);
- return 0;
-}
-
int do_init(int argc, char **argv)
{
int i;
@@ -4258,18 +4281,32 @@ int do_init(int argc, char **argv)
}
}
+ // establish char-login connection if not present
add_timer_func_list(check_connect_login_server, "check_connect_login_server");
- add_timer_func_list(send_users_tologin, "send_users_tologin");
+ add_timer_interval(gettick() + 1000, check_connect_login_server, 0, 0, 10 * 1000);
+
+ // keep the char-login connection alive
+ add_timer_func_list(ping_login_server, "ping_login_server");
+ add_timer_interval(gettick() + 1000, ping_login_server, 0, 0, ((int)stall_time-2) * 1000);
+
+ // periodically update the overall user count on all mapservers + login server
+ add_timer_func_list(broadcast_user_count, "broadcast_user_count");
+ add_timer_interval(gettick() + 1000, broadcast_user_count, 0, 0, 5 * 1000);
+
+ // send a list of all online account IDs to login server
add_timer_func_list(send_accounts_tologin, "send_accounts_tologin");
+ add_timer_interval(gettick() + 1000, send_accounts_tologin, 0, 0, 3600 * 1000); //Sync online accounts every hour
+
+ // ???
add_timer_func_list(chardb_waiting_disconnect, "chardb_waiting_disconnect");
+
+ // ???
add_timer_func_list(online_data_cleanup, "online_data_cleanup");
+ add_timer_interval(gettick() + 1000, online_data_cleanup, 0, 0, 600 * 1000);
+
+ // periodic flush of all saved data to disk
add_timer_func_list(mmo_char_sync_timer, "mmo_char_sync_timer");
-
- add_timer_interval(gettick() + 1000, check_connect_login_server, 0, 0, 10*1000);
- add_timer_interval(gettick() + 1000, send_users_tologin, 0, 0, 5*1000);
- add_timer_interval(gettick() + 3600*1000, send_accounts_tologin, 0, 0, 3600*1000); //Sync online accounts every hour
- add_timer_interval(gettick() + 600*1000, online_data_cleanup, 0, 0, 600*1000);
- add_timer_interval(gettick() + autosave_interval, mmo_char_sync_timer, 0, 0, autosave_interval);
+ add_timer_interval(gettick() + 1000, mmo_char_sync_timer, 0, 0, autosave_interval);
if( console )
{
diff --git a/src/char_sql/char.c b/src/char_sql/char.c
index 89f31e2c1..e48ecc9e4 100644
--- a/src/char_sql/char.c
+++ b/src/char_sql/char.c
@@ -246,6 +246,9 @@ void set_char_online(int map_id, int char_id, int account_id)
character->char_id = (char_id==99)?-1:char_id;
character->server = (char_id==99)?-1:map_id;
+ if( character->server > -1 )
+ server[character->server].users++;
+
if(character->waiting_disconnect != -1) {
delete_timer(character->waiting_disconnect, chardb_waiting_disconnect);
character->waiting_disconnect = -1;
@@ -289,6 +292,9 @@ void set_char_offline(int char_id, int account_id)
if ((character = idb_get(online_char_db, account_id)) != NULL)
{ //We don't free yet to avoid aCalloc/aFree spamming during char change. [Skotlex]
+ if( character->server > -1 )
+ server[character->server].users--;
+
character->char_id = -1;
character->server = -1;
if(character->waiting_disconnect != -1){
@@ -2098,10 +2104,6 @@ int parse_frommap(int fd)
switch(RFIFOW(fd, 0))
{
- case 0x2718: // map-server alive packet
- RFIFOSKIP(fd,2);
- break;
-
case 0x2af7: // request from map-server to reload GM accounts. Transmission to login-server
if(char_gm_read) //Re-read gm accounts.
read_gm_account();
@@ -2132,10 +2134,11 @@ int parse_frommap(int fd)
if (max_account_id != DEFAULT_MAX_ACCOUNT_ID || max_char_id != DEFAULT_MAX_CHAR_ID)
mapif_send_maxid(max_account_id, max_char_id); //Send the current max ids to the server to keep in sync [Skotlex]
+ // send name for wisp to player
WFIFOHEAD(fd, 3 + NAME_LENGTH);
WFIFOW(fd,0) = 0x2afb;
WFIFOB(fd,2) = 0;
- memcpy(WFIFOP(fd,3), wisp_server_name, NAME_LENGTH); // name for wisp to player
+ memcpy(WFIFOP(fd,3), wisp_server_name, NAME_LENGTH);
WFIFOSET(fd,3+NAME_LENGTH);
char_send_fame_list(fd); //Send fame list.
@@ -2519,8 +2522,6 @@ int parse_frommap(int fd)
}
break;
-// case 0x2b0f: Not used anymore, available for future use
-
case 0x2b10: // Update and send fame ranking list
if (RFIFOREST(fd) < 11)
return 0;
@@ -2657,6 +2658,13 @@ int parse_frommap(int fd)
}
break;
+ case 0x2b23: // map-server alive packet
+ WFIFOHEAD(fd,2);
+ WFIFOW(fd,0) = 0x2b24;
+ WFIFOSET(fd,2);
+ RFIFOSKIP(fd,2);
+ break;
+
case 0x2736: // ip address update
if (RFIFOREST(fd) < 6) return 0;
server[id].ip = ntohl(RFIFOL(fd, 2));
@@ -3266,22 +3274,30 @@ int mapif_send(int fd, unsigned char *buf, unsigned int len)
return 0;
}
-int send_users_tologin(int tid, unsigned int tick, int id, int data)
+int broadcast_user_count(int tid, unsigned int tick, int id, int data)
{
+ uint8 buf[6];
int users = count_users();
- unsigned char buf[16];
- if (login_fd > 0 && session[login_fd]) {
+ // only send an update when needed
+ static prev_users = 0;
+ if( prev_users == users )
+ return 0;
+ prev_users = users;
+
+ if( login_fd > 0 && session[login_fd] )
+ {
// send number of user to login server
WFIFOHEAD(login_fd,6);
WFIFOW(login_fd,0) = 0x2714;
WFIFOL(login_fd,2) = users;
WFIFOSET(login_fd,6);
}
+
// send number of players to all map-servers
WBUFW(buf,0) = 0x2b00;
WBUFL(buf,2) = users;
- mapif_sendall(buf, 6);
+ mapif_sendall(buf,6);
return 0;
}
@@ -3351,6 +3367,18 @@ int check_connect_login_server(int tid, unsigned int tick, int id, int data)
return 1;
}
+// sends a ping packet to login server (will receive pong 0x2718)
+int ping_login_server(int tid, unsigned int tick, int id, int data)
+{
+ if (login_fd > 0 && session[login_fd] != NULL)
+ {
+ WFIFOHEAD(login_fd,2);
+ WFIFOW(login_fd,0) = 0x2719;
+ WFIFOSET(login_fd,2);
+ }
+ return 0;
+}
+
//------------------------------------------------
//Invoked 15 seconds after mapif_disconnectplayer in case the map server doesn't
//replies/disconnect the player we tried to kick. [Skotlex]
@@ -3366,6 +3394,23 @@ static int chardb_waiting_disconnect(int tid, unsigned int tick, int id, int dat
return 0;
}
+static int online_data_cleanup_sub(DBKey key, void *data, va_list ap)
+{
+ struct online_char_data *character= (struct online_char_data*)data;
+ if (character->server == -2) //Unknown server.. set them offline
+ set_char_offline(character->char_id, character->account_id);
+ if (character->server < 0)
+ //Free data from players that have not been online for a while.
+ db_remove(online_char_db, key);
+ return 0;
+}
+
+static int online_data_cleanup(int tid, unsigned int tick, int id, int data)
+{
+ online_char_db->foreach(online_char_db, online_data_cleanup_sub);
+ return 0;
+}
+
//----------------------------------
// Reading Lan Support configuration
// Rewrote: Anvanced subnet check [LuzZza]
@@ -3414,10 +3459,10 @@ int char_lan_config_read(const char *lancfgName)
subnet_count++;
}
-
- ShowStatus("Read information about %d subnetworks.\n", subnet_count);
}
+ ShowStatus("Read information about %d subnetworks.\n", subnet_count);
+
fclose(fp);
return 0;
}
@@ -3726,23 +3771,6 @@ void set_server_type(void)
SERVER_TYPE = ATHENA_SERVER_CHAR;
}
-static int online_data_cleanup_sub(DBKey key, void *data, va_list ap)
-{
- struct online_char_data *character= (struct online_char_data*)data;
- if (character->server == -2) //Unknown server.. set them offline
- set_char_offline(character->char_id, character->account_id);
- if (character->server < 0)
- //Free data from players that have not been online for a while.
- db_remove(online_char_db, key);
- return 0;
-}
-
-static int online_data_cleanup(int tid, unsigned int tick, int id, int data)
-{
- online_char_db->foreach(online_char_db, online_data_cleanup_sub);
- return 0;
-}
-
int do_init(int argc, char **argv)
{
int i;
@@ -3800,16 +3828,28 @@ int do_init(int argc, char **argv)
}
}
+ // establish char-login connection if not present
add_timer_func_list(check_connect_login_server, "check_connect_login_server");
- add_timer_func_list(send_users_tologin, "send_users_tologin");
+ add_timer_interval(gettick() + 1000, check_connect_login_server, 0, 0, 10 * 1000);
+
+ // keep the char-login connection alive
+ add_timer_func_list(ping_login_server, "ping_login_server");
+ add_timer_interval(gettick() + 1000, ping_login_server, 0, 0, ((int)stall_time-2) * 1000);
+
+ // periodically update the overall user count on all mapservers + login server
+ add_timer_func_list(broadcast_user_count, "broadcast_user_count");
+ add_timer_interval(gettick() + 1000, broadcast_user_count, 0, 0, 5 * 1000);
+
+ // send a list of all online account IDs to login server
add_timer_func_list(send_accounts_tologin, "send_accounts_tologin");
+ add_timer_interval(gettick() + 1000, send_accounts_tologin, 0, 0, 3600 * 1000); //Sync online accounts every hour.
+
+ // ???
add_timer_func_list(chardb_waiting_disconnect, "chardb_waiting_disconnect");
- add_timer_func_list(online_data_cleanup, "online_data_cleanup");
- add_timer_interval(gettick() + 1000, check_connect_login_server, 0, 0, 10*1000);
- add_timer_interval(gettick() + 1000, send_users_tologin, 0, 0, 5*1000);
- add_timer_interval(gettick() + 3600*1000, send_accounts_tologin, 0, 0, 3600*1000); //Sync online accounts every hour.
- add_timer_interval(gettick() + 600*1000, online_data_cleanup, 0, 0, 600*1000);
+ // ???
+ add_timer_func_list(online_data_cleanup, "online_data_cleanup");
+ add_timer_interval(gettick() + 1000, online_data_cleanup, 0, 0, 600 * 1000);
if( console )
{
diff --git a/src/login/login.c b/src/login/login.c
index 2b1650e2c..91a2f1996 100644
--- a/src/login/login.c
+++ b/src/login/login.c
@@ -1441,10 +1441,6 @@ int parse_fromchar(int fd)
return 0;
//printf("parse_fromchar: Receiving of the users number of the server '%s': %d\n", server[id].name, RFIFOL(fd,2));
server[id].users = RFIFOL(fd,2);
- // send some answer
- WFIFOHEAD(fd,2);
- WFIFOW(fd,0) = 0x2718;
- WFIFOSET(fd,2);
RFIFOSKIP(fd,6);
break;
@@ -1500,6 +1496,17 @@ int parse_fromchar(int fd)
RFIFOSKIP(fd,6);
break;
+ case 0x2719: // ping request from charserver
+ if( RFIFOREST(fd) < 2 )
+ return 0;
+
+ WFIFOHEAD(fd,2);
+ WFIFOW(fd,0) = 0x2718;
+ WFIFOSET(fd,2);
+
+ RFIFOSKIP(fd,2);
+ break;
+
case 0x2720: // Request to become a GM
if (RFIFOREST(fd) < 4 || RFIFOREST(fd) < RFIFOW(fd,2))
return 0;
@@ -3419,9 +3426,10 @@ int login_lan_config_read(const char *lancfgName)
subnet_count++;
}
- ShowStatus("Read information about %d subnetworks.\n", subnet_count);
}
+ ShowStatus("Read information about %d subnetworks.\n", subnet_count);
+
fclose(fp);
return 0;
}
diff --git a/src/login_sql/login.c b/src/login_sql/login.c
index 7139c0b2c..f72590bac 100644
--- a/src/login_sql/login.c
+++ b/src/login_sql/login.c
@@ -764,11 +764,6 @@ int parse_fromchar(int fd)
if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `sstatus` SET `user` = '%d' WHERE `index` = '%d'", server[id].users, id) )
Sql_ShowDebug(sql_handle);
}
- // send some answer
- WFIFOHEAD(fd,2);
- WFIFOW(fd,0) = 0x2718;
- WFIFOSET(fd,2);
-
RFIFOSKIP(fd,6);
break;
@@ -817,6 +812,17 @@ int parse_fromchar(int fd)
}
break;
+ case 0x2719: // ping request from charserver
+ if( RFIFOREST(fd) < 2 )
+ return 0;
+
+ WFIFOHEAD(fd,2);
+ WFIFOW(fd,0) = 0x2718;
+ WFIFOSET(fd,2);
+
+ RFIFOSKIP(fd,2);
+ break;
+
case 0x2720: // Request to become a GM (TXT only!)
if (RFIFOREST(fd) < 4 || RFIFOREST(fd) < RFIFOW(fd,2))
return 0;
@@ -1691,10 +1697,10 @@ int login_lan_config_read(const char *lancfgName)
subnet_count++;
}
-
- ShowStatus("Read information about %d subnetworks.\n", subnet_count);
}
+ ShowStatus("Read information about %d subnetworks.\n", subnet_count);
+
fclose(fp);
return 0;
}
diff --git a/src/map/atcommand.c b/src/map/atcommand.c
index 7a590c2d2..32a07e132 100644
--- a/src/map/atcommand.c
+++ b/src/map/atcommand.c
@@ -6818,32 +6818,19 @@ int atcommand_misceffect(const int fd, struct map_session_data* sd, const char*
return 0;
}
-#ifndef TXT_ONLY /* Begin SQL-Only commands */
-
/*==========================================
* MAIL SYSTEM
*------------------------------------------*/
int atcommand_mail(const int fd, struct map_session_data* sd, const char* command, const char* message)
{
nullpo_retr(0,sd);
-
+#ifndef TXT_ONLY
mail_openmail(sd);
+#endif
return 0;
}
/*==========================================
- * Refresh online command for SQL [Valaris]
- * Will refresh and check online column of players and set correctly.
- *------------------------------------------*/
-int atcommand_refreshonline(const int fd, struct map_session_data* sd, const char* command, const char* message)
-{
- send_users_tochar(-1, gettick(), 0, 0);
- return 0;
-}
-
-#endif /* end sql only */
-
-/*==========================================
* Show Monster DB Info v 1.0
* originally by [Lupus] eAthena
*------------------------------------------*/
@@ -8394,10 +8381,7 @@ AtCommandInfo atcommand_info[] = {
{ "homshuffle", 60, atcommand_homshuffle },
{ "showmobs", 10, atcommand_showmobs },
{ "feelreset", 10, atcommand_feelreset },
-#ifndef TXT_ONLY
{ "mail", 1, atcommand_mail },
- { "refreshonline", 99, atcommand_refreshonline },
-#endif
};
diff --git a/src/map/chrif.c b/src/map/chrif.c
index 6369a6745..52fcc5ca3 100644
--- a/src/map/chrif.c
+++ b/src/map/chrif.c
@@ -31,56 +31,58 @@ static const int packet_len_table[0x3d] = { // U - used, F - free
60, 3,-1,27,10,-1, 6,-1, // 2af8-2aff: U->2af8, U->2af9, U->2afa, U->2afb, U->2afc, U->2afd, U->2afe, U->2aff
6,-1,18, 7,-1,35,30,10, // 2b00-2b07: U->2b00, U->2b01, U->2b02, U->2b03, U->2b04, U->2b05, U->2b06, U->2b07
6,30,-1,10,86, 7,44,34, // 2b08-2b0f: U->2b08, U->2b09, U->2b0a, U->2b0b, U->2b0c, U->2b0d, U->2b0e, U->2b0f
- 11,-1,10, 6,11,-1, 0,10, // 2b10-2b17: U->2b10, U->2b11, U->2b12, U->2b13, U->2b14, U->2b15, U->2b16, U->2b17
- -1,-1,-1,-1,-1,-1, 2, 7, // 2b18-2b1f: U->2b18, U->2b19, U->2b1a, U->2b1b, U->2b1c, U->2b1d, U->2b1e, U->2b1f
- -1,10, 8,-1,-1,-1,-1,-1, // 2b20-2b27: U->2b20, U->2b21, U->2b22, U->2b23, F->2b24, F->2b25, F->2b26, F->2b27
+ 11, 9,10, 6,11,-1,266,10, // 2b10-2b17: U->2b10, U->2b11, U->2b12, U->2b13, U->2b14, U->2b15, U->2b16, U->2b17
+ 2,10, 2,-1,-1,-1, 2, 7, // 2b18-2b1f: U->2b18, U->2b19, U->2b1a, U->2b1b, U->2b1c, U->2b1d, U->2b1e, U->2b1f
+ -1,10, 8, 2, 2,-1,-1,-1, // 2b20-2b27: U->2b20, U->2b21, U->2b22, U->2b23, U->2b24, F->2b25, F->2b26, F->2b27
};
//Used Packets:
//2af8: Outgoing, chrif_connect -> 'connect to charserver / auth @ charserver'
-//2af9: Incomming, chrif_connectack -> 'answer of the 2af8 login(ok / fail)'
+//2af9: Incoming, chrif_connectack -> 'answer of the 2af8 login(ok / fail)'
//2afa: Outgoing, chrif_sendmap -> 'sending our maps'
-//2afb: Incomming, chrif_sendmapack -> 'Maps received successfully / or not ..'
+//2afb: Incoming, chrif_sendmapack -> 'Maps received successfully / or not ..'
//2afc: Outgoing, chrif_scdata_request -> request sc_data for pc_authok'ed char. <- new command reuses previous one.
-//2afd: Incomming, chrif_authok -> 'character selected, add to auth db'
+//2afd: Incoming, chrif_authok -> 'character selected, add to auth db'
//2afe: Outgoing, send_usercount_tochar -> 'sends player count of this map server to charserver'
//2aff: Outgoing, send_users_tochar -> 'sends all actual connected character ids to charserver'
-//2b00: Incomming, map_setusers -> 'set the actual usercount? PACKET.2B COUNT.L.. ?' (not sure)
+//2b00: Incoming, map_setusers -> 'set the actual usercount? PACKET.2B COUNT.L.. ?' (not sure)
//2b01: Outgoing, chrif_save -> 'charsave of char XY account XY (complete struct)'
//2b02: Outgoing, chrif_charselectreq -> 'player returns from ingame to charserver to select another char.., this packets includes sessid etc' ? (not 100% sure)
-//2b03: Incomming, clif_charselectok -> '' (i think its the packet after enterworld?) (not sure)
-//2b04: Incomming, chrif_recvmap -> 'getting maps from charserver of other mapserver's'
+//2b03: Incoming, clif_charselectok -> '' (i think its the packet after enterworld?) (not sure)
+//2b04: Incoming, chrif_recvmap -> 'getting maps from charserver of other mapserver's'
//2b05: Outgoing, chrif_changemapserver -> 'Tell the charserver the mapchange / quest for ok...'
-//2b06: Incomming, chrif_changemapserverack -> 'awnser of 2b05, ok/fail, data: dunno^^'
+//2b06: Incoming, chrif_changemapserverack -> 'awnser of 2b05, ok/fail, data: dunno^^'
//2b07: Incoming, clif_updatemaxid -> Received when updating the max account/char known
//2b08: Outgoing, chrif_searchcharid -> '...'
-//2b09: Incomming, map_addchariddb -> 'Adds a name to the nick db'
+//2b09: Incoming, map_addchariddb -> 'Adds a name to the nick db'
//2b0a: Outgoing, chrif_changegm -> 'level change of acc/char XY'
-//2b0b: Incomming, chrif_changedgm -> 'answer of 2b0a..'
+//2b0b: Incoming, chrif_changedgm -> 'answer of 2b0a..'
//2b0c: Outgoing, chrif_changeemail -> 'change mail address ...'
-//2b0d: Incomming, chrif_changedsex -> 'Change sex of acc XY'
+//2b0d: Incoming, chrif_changedsex -> 'Change sex of acc XY'
//2b0e: Outgoing, chrif_char_ask_name -> 'Do some operations (change sex, ban / unban etc)'
-//2b0f: Incomming, chrif_char_ask_name_answer -> 'answer of the 2b0e'
+//2b0f: Incoming, chrif_char_ask_name_answer -> 'answer of the 2b0e'
//2b10: Outgoing, chrif_updatefamelist -> 'Update the fame ranking lists and send them'
//2b11: Outgoing, chrif_changesex -> 'change sex of acc X'
-//2b12: Incomming, chrif_divorce -> 'divorce a wedding of charid X and partner id X'
-//2b13: Incomming, chrif_accountdeletion -> 'Delete acc XX, if the player is on, kick ....'
-//2b14: Incomming, chrif_accountban -> 'not sure: kick the player with message XY'
-//2b15: Incomming, chrif_recvgmaccounts -> 'receive gm accs from charserver (seems to be incomplete !)'
+//2b12: Incoming, chrif_divorce -> 'divorce a wedding of charid X and partner id X'
+//2b13: Incoming, chrif_accountdeletion -> 'Delete acc XX, if the player is on, kick ....'
+//2b14: Incoming, chrif_accountban -> 'not sure: kick the player with message XY'
+//2b15: Incoming, chrif_recvgmaccounts -> 'receive gm accs from charserver (seems to be incomplete !)'
//2b16: Outgoing, chrif_ragsrvinfo -> 'sends motd / rates ....'
//2b17: Outgoing, chrif_char_offline -> 'tell the charserver that the char is now offline'
//2b18: Outgoing, chrif_char_reset_offline -> 'set all players OFF!'
//2b19: Outgoing, chrif_char_online -> 'tell the charserver that the char .. is online'
//2b1a: Outgoing, chrif_buildfamelist -> 'Build the fame ranking lists and send them'
-//2b1b: Incomming, chrif_recvfamelist -> 'Receive fame ranking lists'
+//2b1b: Incoming, chrif_recvfamelist -> 'Receive fame ranking lists'
//2b1c: Outgoing, chrif_save_scdata -> 'Send sc_data of player for saving.'
-//2b1d: Incomming, chrif_load_scdata -> 'received sc_data of player for loading.'
+//2b1d: Incoming, chrif_load_scdata -> 'received sc_data of player for loading.'
//2b1e: Incoming, chrif_update_ip -> 'Reqest forwarded from char-server for interserver IP sync.' [Lance]
-//2b1f: Incomming, chrif_disconnectplayer -> 'disconnects a player (aid X) with the message XY ... 0x81 ..' [Sirius]
-//2b20: Incomming, chrif_removemap -> 'remove maps of a server (sample: its going offline)' [Sirius]
-//2b21: Incomming, chrif_save_ack. Returned after a character has been "final saved" on the char-server. [Skotlex]
-//2b22: Incomming, chrif_updatefamelist_ack. Updated one position in the fame list.
-//2b24-2b27: FREE
+//2b1f: Incoming, chrif_disconnectplayer -> 'disconnects a player (aid X) with the message XY ... 0x81 ..' [Sirius]
+//2b20: Incoming, chrif_removemap -> 'remove maps of a server (sample: its going offline)' [Sirius]
+//2b21: Incoming, chrif_save_ack. Returned after a character has been "final saved" on the char-server. [Skotlex]
+//2b22: Incoming, chrif_updatefamelist_ack. Updated one position in the fame list.
+//2b23: Outgoing, chrif_keepalive. charserver ping.
+//2b24: Incoming, chrif_keepalive_ack. charserver ping reply.
+//2b25-2b27: FREE
int chrif_connected = 0;
int char_fd = 0; //Using 0 instead of -1 is safer against crashes. [Skotlex]
@@ -376,7 +378,7 @@ int chrif_sendmapack(int fd)
chrif_state = 2;
//If there are players online, send them to the char-server. [Skotlex]
- send_users_tochar(-1, gettick(), 0, 0);
+ send_users_tochar();
//Re-save any storages that were modified in the disconnection time. [Skotlex]
do_reconnect_map();
@@ -995,6 +997,8 @@ int chrif_recvfamelist(int fd)
return 0;
}
+/// fame ranking update confirmation
+/// R 2b22 <table>.B <index>.B <value>.L
int chrif_updatefamelist_ack(int fd)
{
struct fame_list* list;
@@ -1096,6 +1100,7 @@ int chrif_load_scdata(int fd)
/*==========================================
* Send rates and motd to char server [Wizputer]
+ * S 2b16 <base rate>.w <job rate>.w <drop rate>.w <motd len>.w <motd>.256B
*------------------------------------------*/
int chrif_ragsrvinfo(int base_rate, int job_rate, int drop_rate)
{
@@ -1110,6 +1115,7 @@ int chrif_load_scdata(int fd)
WFIFOW(char_fd,2) = base_rate;
WFIFOW(char_fd,4) = job_rate;
WFIFOW(char_fd,6) = drop_rate;
+ WFIFOW(char_fd,8) = sizeof(buf) + 10;
if ((fp = fopen(motd_txt, "r")) != NULL) {
if (fgets(buf, sizeof(buf), fp) != NULL)
@@ -1120,13 +1126,11 @@ int chrif_load_scdata(int fd)
break;
}
}
- WFIFOW(char_fd,8) = sizeof(buf) + 10;
memcpy(WFIFOP(char_fd,10), buf, sizeof(buf));
}
fclose(fp);
} else {
memset(buf, 0, sizeof(buf)); //No data found, send empty packets?
- WFIFOW(char_fd,8) = sizeof(buf) + 10;
memcpy(WFIFOP(char_fd,10), buf, sizeof(buf));
}
WFIFOSET(char_fd,WFIFOW(char_fd,8));
@@ -1226,6 +1230,18 @@ void chrif_update_ip(int fd)
WFIFOSET(fd,6);
}
+// pings the charserver
+void chrif_keepalive(int fd)
+{
+ WFIFOHEAD(fd,2);
+ WFIFOW(fd,0) = 0x2b23;
+ WFIFOSET(fd,2);
+}
+
+void chrif_keepalive_ack(int fd)
+{
+}
+
/*==========================================
*
*------------------------------------------*/
@@ -1283,7 +1299,7 @@ int chrif_parse(int fd)
case 0x2af9: chrif_connectack(fd); break;
case 0x2afb: chrif_sendmapack(fd); break;
case 0x2afd: chrif_authok(fd); break;
- case 0x2b00: map_setusers(fd); break;
+ case 0x2b00: map_setusers(RFIFOL(fd,2)); chrif_keepalive(fd); break;
case 0x2b03: clif_charselectok(RFIFOL(fd,2)); break;
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;
@@ -1303,6 +1319,7 @@ int chrif_parse(int fd)
case 0x2b20: chrif_removemap(fd); break;
case 0x2b21: chrif_save_ack(fd); break;
case 0x2b22: chrif_updatefamelist_ack(fd); break;
+ case 0x2b24: chrif_keepalive_ack(fd); break;
default:
if (battle_config.error_log)
ShowError("chrif_parse : unknown packet (session #%d): 0x%x. Disconnecting.\n", fd, cmd);
@@ -1316,19 +1333,22 @@ int chrif_parse(int fd)
return 0;
}
+int ping_char_server(int tid, unsigned int tick, int id, int data)
+{
+ chrif_check(-1);
+ chrif_keepalive(char_fd);
+ return 0;
+}
+
+// unused
int send_usercount_tochar(int tid, unsigned int tick, int id, int data)
{
int count;
- static int last_count = 0;
chrif_check(-1);
map_getallusers(&count);
- if (count == last_count) //No need to waste packets.
- return 0;
- last_count = count;
-
WFIFOHEAD(char_fd,4);
WFIFOW(char_fd,0) = 0x2afe;
WFIFOW(char_fd,2) = count;
@@ -1340,7 +1360,7 @@ int send_usercount_tochar(int tid, unsigned int tick, int id, int data)
* timer関数
* 今このmap鯖に繋がっているクライアント人数をchar鯖へ送る
*------------------------------------------*/
-int send_users_tochar(int tid, unsigned int tick, int id, int data)
+int send_users_tochar(void)
{
int count, users=0, i;
struct map_session_data **all_sd;
@@ -1430,22 +1450,20 @@ int do_final_chrif(void)
*------------------------------------------*/
int do_init_chrif(void)
{
+ auth_db = idb_alloc(DB_OPT_RELEASE_DATA);
+
add_timer_func_list(check_connect_char_server, "check_connect_char_server");
- add_timer_func_list(send_usercount_tochar, "send_usercount_tochar");
- add_timer_func_list(send_users_tochar, "send_users_tochar");
+ add_timer_func_list(ping_char_server, "ping_char_server");
add_timer_func_list(auth_db_cleanup, "auth_db_cleanup");
+ // establish map-char connection if not present
add_timer_interval(gettick() + 1000, check_connect_char_server, 0, 0, 10 * 1000);
-#ifdef TXT_ONLY
- //Txt needs this more frequently because it is used for the online.html file.
- add_timer_interval(gettick() + 1000, send_users_tochar, 0, 0, UPDATE_INTERVAL);
-#else
- add_timer_interval(gettick() + 1000, send_users_tochar, 0, 0, CHECK_INTERVAL);
- add_timer_interval(gettick() + 1000, send_usercount_tochar, 0, 0, UPDATE_INTERVAL);
-#endif
- add_timer_interval(gettick() + 1000, auth_db_cleanup, 0, 0, 30 * 1000);
- auth_db = idb_alloc(DB_OPT_RELEASE_DATA);
+ // keep the map-char connection alive
+ add_timer_interval(gettick() + 1000, ping_char_server, 0, 0, ((int)stall_time-2) * 1000);
+
+ // wipe stale data for timed-out client connection requests
+ add_timer_interval(gettick() + 1000, auth_db_cleanup, 0, 0, 30 * 1000);
return 0;
}
diff --git a/src/map/chrif.h b/src/map/chrif.h
index 71f402233..1ae274f57 100644
--- a/src/map/chrif.h
+++ b/src/map/chrif.h
@@ -44,7 +44,7 @@ int chrif_save_scdata(struct map_session_data *sd);
int chrif_ragsrvinfo(int base_rate,int job_rate, int drop_rate);
int chrif_char_offline(struct map_session_data *sd);
int chrif_char_reset_offline(void);
-int send_users_tochar(int tid, unsigned int tick, int id, int data);
+int send_users_tochar(void);
int chrif_char_online(struct map_session_data *sd);
int chrif_changesex(int id, int sex);
int chrif_chardisconnect(struct map_session_data *sd);
diff --git a/src/map/map.c b/src/map/map.c
index 52153c55d..495676082 100644
--- a/src/map/map.c
+++ b/src/map/map.c
@@ -159,16 +159,11 @@ int enable_spy = 0; //To enable/disable @spy commands, which consume too much cp
int enable_grf = 0; //To enable/disable reading maps from GRF files, bypassing mapcache [blackhole89]
/*==========================================
- * 全map鯖?計での接??設定
- * (char鯖から送られてくる)
+ * server player count (of all mapservers)
*------------------------------------------*/
-void map_setusers(int fd)
+void map_setusers(int users)
{
- map_users = RFIFOL(fd,2);
- // send some answer
- WFIFOHEAD(fd, 2);
- WFIFOW(fd,0) = 0x2718;
- WFIFOSET(fd,2);
+ map_users = users;
}
/*==========================================