summaryrefslogtreecommitdiff
path: root/src/char/char.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/char/char.c')
-rw-r--r--src/char/char.c118
1 files changed, 63 insertions, 55 deletions
diff --git a/src/char/char.c b/src/char/char.c
index a0d34e14e..6c2e529f8 100644
--- a/src/char/char.c
+++ b/src/char/char.c
@@ -334,16 +334,36 @@ static int char_db_setoffline(DBKey key, void* data, va_list ap) {
return 0;
}
-void set_all_offline(void) {
- online_char_db->foreach(online_char_db,char_db_setoffline,-1);
- if (login_fd <= 0 || session[login_fd]->eof)
- return;
- WFIFOHEAD(login_fd, 6);
- WFIFOW(login_fd,0) = 0x272c;
- WFIFOL(login_fd,2) = 99;
- WFIFOSET(login_fd,6);
+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);
- //printf ("set all offline\n");
+ if (server > -1 && character->server != server)
+ 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);
+ else if (!character->waiting_disconnect)
+ set_char_offline(character->char_id, character->account_id);
+ else return 0;
+ return 1;
+}
+
+void set_all_offline(int id) {
+ if (id < 0)
+ ShowNotice("Sending all users offline.\n");
+ else
+ ShowNotice("Sending users of map-server %d offline.\n", id);
+ online_char_db->foreach(online_char_db,char_db_kickoffline,id);
+
+ if (id >= 0 || login_fd <= 0 || session[login_fd]->eof)
+ return;
+ //Tell login-server to also mark all our characters as offline.
+ WFIFOHEAD(login_fd, 2);
+ WFIFOW(login_fd,0) = 0x2737;
+ WFIFOSET(login_fd,2);
}
/*---------------------------------------------------
@@ -1284,11 +1304,6 @@ static int create_online_files_sub(DBKey key, void* data, va_list va)
j = character->server;
if (server_fd[j] < 0) {
server[j].users = 0;
- if (kick_on_disconnect)
- {
- character->char_id = -1;
- character->server = -1;
- }
return -1;
}
// search position of character in char_dat and sort online characters.
@@ -1864,13 +1879,8 @@ int parse_tologin(int fd) {
exit(1);
} else {
ShowStatus("Connected to login-server (connection #%d).\n", fd);
-// Don't set them offline as there's no packet to tell the map server
-// to kick everyone out. Also, a disconnection from the login server is
-// NOT something serious to the data integrity as a char-map disconnect
-// is. [Skotlex]
-// if (kick_on_disconnect)
-// set_all_offline();
-// However, on reconnect, DO send our connected accounts to login.
+
+ //Send to login accounts currently connected.
send_accounts_tologin(-1, gettick(), 0, 0);
// if no map-server already connected, display a message...
@@ -2621,8 +2631,7 @@ int parse_frommap(int fd) {
ShowStatus("Map-server %d loading complete.\n", id);
char_log("Map-Server %d connected: %d maps, from IP %d.%d.%d.%d port %d. Map-server %d loading complete." RETCODE,
id, j, p[0], p[1], p[2], p[3], server[id].port, id);
- if (kick_on_disconnect)
- set_all_offline();
+
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]
}
@@ -3078,8 +3087,7 @@ int parse_frommap(int fd) {
// Reset all chars to offline [Wizputer]
case 0x2b18:
- ShowNotice("Map server [%d] requested to set all characters offline.\n", id);
- set_all_offline();
+ set_all_offline(id);
RFIFOSKIP(fd,2);
break;
@@ -3881,40 +3889,39 @@ int send_accounts_tologin(int tid, unsigned int tick, int id, int data) {
WFIFOL(login_fd,4) = users;
online_char_db->foreach(online_char_db, send_accounts_tologin_sub, &i);
WFIFOW(login_fd,2) = 8+ i*4;
- if (i > 0)
- WFIFOSET(login_fd,WFIFOW(login_fd,2));
+ WFIFOSET(login_fd,WFIFOW(login_fd,2));
}
return 0;
}
int check_connect_login_server(int tid, unsigned int tick, int id, int data) {
- if (login_fd <= 0 || session[login_fd] == NULL) {
- ShowInfo("Attempt to connect to login-server...\n");
- login_fd = make_connection(login_ip, login_port);
- if (login_fd == -1)
- { //Try again later... [Skotlex]
- login_fd = 0;
- return 0;
- }
- session[login_fd]->func_parse = parse_tologin;
- realloc_fifo(login_fd, FIFOSIZE_SERVERLINK, FIFOSIZE_SERVERLINK);
- WFIFOHEAD(login_fd, 86);
- WFIFOW(login_fd,0) = 0x2710;
- memcpy(WFIFOP(login_fd,2), userid, 24);
- memcpy(WFIFOP(login_fd,26), passwd, 24);
- WFIFOL(login_fd,50) = 0;
- WFIFOL(login_fd,54) = char_ip;
- WFIFOL(login_fd,58) = char_port;
- memset(WFIFOP(login_fd,60), 0, 20);
- memcpy(WFIFOP(login_fd,60), server_name, strlen(server_name) < 20 ? strlen(server_name) : 20);
- WFIFOW(login_fd,80) = 0;
- WFIFOW(login_fd,82) = char_maintenance;
-
- WFIFOW(login_fd,84) = char_new_display; //only display (New) if they want to [Kevin]
-
- WFIFOSET(login_fd,86);
+ if (login_fd > 0 && session[login_fd] != NULL)
+ return 0;
+
+ ShowInfo("Attempt to connect to login-server...\n");
+ login_fd = make_connection(login_ip, login_port);
+ if (login_fd == -1)
+ { //Try again later... [Skotlex]
+ login_fd = 0;
+ return 0;
}
- return 0;
+ session[login_fd]->func_parse = parse_tologin;
+ realloc_fifo(login_fd, FIFOSIZE_SERVERLINK, FIFOSIZE_SERVERLINK);
+ WFIFOHEAD(login_fd, 86);
+ WFIFOW(login_fd,0) = 0x2710;
+ memcpy(WFIFOP(login_fd,2), userid, 24);
+ memcpy(WFIFOP(login_fd,26), passwd, 24);
+ WFIFOL(login_fd,50) = 0;
+ WFIFOL(login_fd,54) = char_ip;
+ WFIFOL(login_fd,58) = char_port;
+ memcpy(WFIFOP(login_fd,60), server_name, 20);
+ WFIFOW(login_fd,80) = 0;
+ WFIFOW(login_fd,82) = char_maintenance;
+
+ WFIFOW(login_fd,84) = char_new_display; //only display (New) if they want to [Kevin]
+
+ WFIFOSET(login_fd,86);
+ return 1;
}
//------------------------------------------------
@@ -4031,7 +4038,7 @@ int char_config_read(const char *cfgName) {
} else if (strcmpi(w1, "passwd") == 0) {
strncpy(passwd, w2, 24);
} else if (strcmpi(w1, "server_name") == 0) {
- memcpy(server_name, w2, sizeof(server_name));
+ strncpy(server_name, w2, 20);
server_name[sizeof(server_name) - 1] = '\0';
ShowStatus("%s server has been initialized\n", w2);
} else if (strcmpi(w1, "wisp_server_name") == 0) {
@@ -4205,7 +4212,8 @@ void do_final(void) {
mmo_char_sync();
inter_save();
- set_all_offline();
+ set_all_offline(-1);
+ flush_fifos();
if(gm_account) aFree(gm_account);
if(char_dat) aFree(char_dat);