Selaa lähdekoodia

* Added Buuyo-Tama's shortlist for send/eof sockets (defined out for now).
* Replaced toupper/tolower in ladmin by TOUPPER/TOLOWER defines.

Shortlist:
It's a list of sockets that have data to send and/or are ready for eof processing.
It aims to reduce the amount of time spent on do_sendrecv, where it was spending ~13.5% of execution time on a server with 1k users at WoE.
thanks to Buuyo-tama for the profile info and code

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@10506 54d463be-8e91-2dee-dedb-b68131a5f0ec

FlavioJS 18 vuotta sitten
vanhempi
commit
71f29c0445
11 muutettua tiedostoa jossa 254 lisäystä ja 124 poistoa
  1. 3 0
      Changelog-Trunk.txt
  2. 25 25
      src/char/char.c
  3. 20 20
      src/char_sql/char.c
  4. 108 3
      src/common/socket.c
  5. 22 0
      src/common/socket.h
  6. 22 22
      src/ladmin/ladmin.c
  7. 15 15
      src/login/login.c
  8. 13 13
      src/login_sql/login.c
  9. 9 9
      src/map/chrif.c
  10. 11 11
      src/map/clif.c
  11. 6 6
      src/map/irc.c

+ 3 - 0
Changelog-Trunk.txt

@@ -3,6 +3,9 @@ Date	Added
 AS OF SVN REV. 5091, WE ARE NOW USING TRUNK.  ALL UNTESTED BUGFIXES/FEATURES GO INTO TRUNK.
 IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK.
 
+2007/05/10
+	* Added Buuyo-Tama's shortlist for send/eof sockets (defined out for now). 
+	* Replaced toupper/tolower in ladmin by TOUPPER/TOLOWER defines. [FlavioJS]
 2007/05/07
 	* Fixed warpwaitingpc not working (bug introduced in r10471). [FlavioJS]
 	* Added a check to login_sql against too long db-stored emails [ultramage]

+ 25 - 25
src/char/char.c

@@ -1,24 +1,6 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
-#include <sys/types.h>
-
-#ifdef _WIN32
-#include <winsock2.h>
-#else
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#endif
-
-#include <time.h>
-#include <signal.h>
-#include <fcntl.h>
-#include <string.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-
 #include "../common/cbasetypes.h"
 #include "../common/strlib.h"
 #include "../common/core.h"
@@ -31,7 +13,6 @@
 #include "../common/showmsg.h"
 #include "../common/malloc.h"
 
-#include "char.h"
 #include "inter.h"
 #include "int_pet.h"
 #include "int_homun.h"
@@ -41,6 +22,25 @@
 #ifdef ENABLE_SC_SAVING
 #include "int_status.h"
 #endif
+#include "char.h"
+
+#include <sys/types.h>
+
+#ifdef WIN32
+#include <winsock2.h>
+#else
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#endif
+
+#include <time.h>
+#include <signal.h>
+#include <fcntl.h>
+#include <string.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
 
 #ifndef TXT_SQL_CONVERT
 struct mmo_map_server{
@@ -1952,7 +1952,7 @@ int parse_tologin(int fd) {
 	// only login-server can have an access to here.
 	// so, if it isn't the login-server, we disconnect the session (fd != login_fd).
 	if (fd != login_fd)
-		session[fd]->eof = 1;
+		set_eof(fd);
 	if(session[fd]->eof) {
 		if (fd == login_fd) {
 			ShowWarning("Connection to login-server lost (connection #%d).\n", fd);
@@ -2455,7 +2455,7 @@ int parse_tologin(int fd) {
 		}
 		default:
 			ShowWarning("Unknown packet 0x%04x received from login-server, disconnecting.\n", RFIFOW(fd,0));
-			session[fd]->eof = 1;
+			set_eof(fd);
 			return 0;
 		}
 	}
@@ -2664,7 +2664,7 @@ int parse_frommap(int fd)
 		if (server_fd[id] == fd)
 			break;
 	if(id==MAX_MAP_SERVERS)
-		session[fd]->eof=1;
+		set_eof(fd);
 	if(session[fd]->eof){
 		if (id < MAX_MAP_SERVERS) {
 			unsigned char buf[16384];
@@ -3241,7 +3241,7 @@ int parse_frommap(int fd)
 			}
 			// inter server処理でもない場合は切断
 			ShowError("Unknown packet 0x%04x from map server, disconnecting.\n", RFIFOW(fd,0));
-			session[fd]->eof = 1;
+			set_eof(fd);
 			return 0;
 		}
 	}
@@ -3307,7 +3307,7 @@ int parse_char(int fd)
 	sd = (struct char_session_data*)session[fd]->session_data;
 
 	if(login_fd < 0)
-		session[fd]->eof = 1;
+		set_eof(fd);
 	if(session[fd]->eof) { // disconnect any player (already connected to char-server or coming back from map-server) if login-server is diconnected.
 		if (fd == login_fd)
 			login_fd = -1;
@@ -3755,7 +3755,7 @@ int parse_char(int fd)
 		}
 		case 0x7532:	// disconnect(default also disconnect)
 		default:
-			session[fd]->eof = 1;
+			set_eof(fd);
 			return 0;
 		}
 	}

+ 20 - 20
src/char_sql/char.c

@@ -1,9 +1,22 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
+#include "../common/cbasetypes.h"
+#include "../common/utils.h"
+#include "../common/strlib.h"
+#include "../common/showmsg.h"
+#include "../common/db.h"
+#include "../common/malloc.h"
+
+#include "itemdb.h"
+#include "inter.h"
+#include "int_guild.h"
+#include "int_homun.h"
+#include "char.h"
+
 #include <sys/types.h>
 
-#ifdef _WIN32
+#ifdef WIN32
 #include <winsock2.h>
 #else
 #include <sys/socket.h>
@@ -19,19 +32,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 
-#include "../common/cbasetypes.h"
-#include "../common/utils.h"
-#include "../common/strlib.h"
-#include "../common/showmsg.h"
-#include "../common/db.h"
-#include "../common/malloc.h"
-
-#include "itemdb.h"
-#include "inter.h"
-#include "int_guild.h"
-#include "int_homun.h"
-#include "char.h"
-
 #ifndef TXT_SQL_CONVERT
 static struct dbt *char_db_;
 #endif
@@ -1853,7 +1853,7 @@ int parse_tologin(int fd) {
 	// so, if it isn't the login-server, we disconnect the session.
 	//session eof check!
 	if(fd != login_fd)
-		session[fd]->eof = 1;
+		set_eof(fd);
 	if(session[fd]->eof) {
 		if (fd == login_fd) {
 			ShowWarning("Connection to login-server lost (connection #%d).\n", fd);
@@ -2261,7 +2261,7 @@ int parse_tologin(int fd) {
 		}
 		default:
 			ShowError("Unknown packet 0x%04x from login server, disconnecting.\n", RFIFOW(fd, 0));
-			session[fd]->eof = 1;
+			set_eof(fd);
 			return 0;
 		}
 	}
@@ -2453,7 +2453,7 @@ int parse_frommap(int fd)
 		if (server_fd[id] == fd)
 			break;
 	if(id == MAX_MAP_SERVERS)
-		session[fd]->eof = 1;
+		set_eof(fd);
 	if(session[fd]->eof) {
 		if (id < MAX_MAP_SERVERS) {
 			unsigned char buf[16384];
@@ -3092,7 +3092,7 @@ int parse_frommap(int fd)
 
 			// no inter server packet. no char server packet -> disconnect
 			ShowError("Unknown packet 0x%04x from map server, disconnecting.\n", RFIFOW(fd,0));
-			session[fd]->eof = 1;
+			set_eof(fd);
 			return 0;
 		}
 	}
@@ -3157,7 +3157,7 @@ int parse_char(int fd)
 	sd = (struct char_session_data*)session[fd]->session_data;
 
 	if(login_fd < 0)
-		session[fd]->eof = 1;
+		set_eof(fd);
 	if(session[fd]->eof) { // disconnect any player (already connected to char-server or coming back from map-server) if login-server is diconnected.
 		if (fd == login_fd)
 			login_fd = -1;
@@ -3582,7 +3582,7 @@ int parse_char(int fd)
 		}
 		case 0x7532:	// disconnect(default also disconnect)
 		default:
-			session[fd]->eof = 1;
+			set_eof(fd);
 			return 0;
 		}
 	}

+ 108 - 3
src/common/socket.c

@@ -78,6 +78,11 @@ size_t wfifo_size = (16*1024);
 
 struct socket_data* session[FD_SETSIZE];
 
+#ifdef SEND_SHORTLIST
+struct send_shortlist_node *send_shortlist = NULL;
+fd_set send_shortlist_fd_set;
+#endif
+
 int create_session(int fd, RecvFunc func_recv, SendFunc func_send, ParseFunc func_parse);
 
 #ifndef MINICORE
@@ -148,6 +153,11 @@ void setsocketopts(int fd)
  *--------------------------------------*/
 void set_eof(int fd)
 {
+#ifdef SEND_SHORTLIST
+	// Add this socket to the shortlist for eof handling.
+	send_shortlist_add_fd(fd);
+#endif
+
 	if (session_isActive(fd))
 		session[fd]->eof = 1;
 }
@@ -495,6 +505,10 @@ int WFIFOSET(int fd, int len)
 	// Even the inter-server buffer may need reallocating! [Skotlex]
 	realloc_writefifo(fd, newreserve);
 
+#ifdef SEND_SHORTLIST
+	send_shortlist_add_fd(fd);
+#endif
+
 	return 0;
 }
 
@@ -509,6 +523,9 @@ int do_sendrecv(int next)
 
 	//PRESEND Need to do this to ensure that the clients get something to do
 	//which hopefully will cause them to send packets. [Meruru]
+#ifdef SEND_SHORTLIST
+	send_shortlist_do_sends();
+#else
 	for (i = 1; i < fd_max; i++)
 	{
 		if(!session[i])
@@ -517,6 +534,7 @@ int do_sendrecv(int next)
 		if(session[i]->wdata_size)
 			session[i]->func_send(i);
 	}
+#endif
 
 	timeout.tv_sec  = next/1000;
 	timeout.tv_usec = next%1000*1000;
@@ -549,7 +567,7 @@ int do_sendrecv(int next)
 				{
 					ShowError("Deleting invalid session %d\n", i);
 				  	//So the code can react accordingly
-					session[i]->eof = 1;
+					set_eof(i);
 					session[i]->func_parse(i);
 					delete_session(i); //free the bad session
 					continue;
@@ -579,6 +597,9 @@ int do_sendrecv(int next)
 	}
 #endif
 
+#ifdef SEND_SHORTLIST
+	send_shortlist_do_sends();
+#else
 	for (i = 1; i < fd_max; i++)
 	{
 		if(!session[i])
@@ -592,6 +613,7 @@ int do_sendrecv(int next)
 			session[i]->func_parse(i); //This should close the session inmediately.
 		}
 	}
+#endif
 
 	return 0;
 }
@@ -606,7 +628,7 @@ int do_parsepacket(void)
 
 		if (session[i]->rdata_tick && DIFF_TICK(last_tick, session[i]->rdata_tick) > stall_time) {
 			ShowInfo ("Session #%d timed out\n", i);
-			session[i]->eof = 1;
+			set_eof(i);
 		}
 
 		session[i]->func_parse(i);
@@ -616,7 +638,7 @@ int do_parsepacket(void)
 
 		/* 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 == rfifo_size && session[i]->max_rdata == rfifo_size) {
-			session[i]->eof = 1;
+			set_eof(i);
 			continue;
 		}
 		RFIFOFLUSH(i);
@@ -1134,3 +1156,86 @@ uint16 ntows(uint16 neshort)
 {
 	return ((neshort & 0xFF) << 8) | ((neshort & 0xFF00) >> 8);
 }
+
+#ifdef SEND_SHORTLIST
+// Add a fd to the shortlist so that it'll be recognized as a fd that needs
+// sending (or eof handling) done on it.
+void send_shortlist_add_fd(int fd)
+{
+	struct send_shortlist_node* new_node;
+
+	if (FD_ISSET(fd, &send_shortlist_fd_set))
+		// Refuse to add duplicate FDs to the shortlist
+		return;
+
+	new_node = aMalloc(sizeof(*new_node));
+
+	FD_SET(fd, &send_shortlist_fd_set);
+
+	// Add the new node to the beginning of the shortlist linked list.
+	new_node->fd = fd;
+	new_node->prev = NULL;
+	new_node->next = send_shortlist;
+	if (new_node->next)
+		new_node->next->prev = new_node;
+
+	send_shortlist = new_node;
+}
+
+// Do pending network sends (and eof handling) from the shortlist.
+void send_shortlist_do_sends()
+{
+	struct send_shortlist_node
+		*current_node = send_shortlist,
+		*next_node;
+
+	while (current_node)
+	{
+		int delete_current_node = 1;
+
+		next_node = current_node->next;
+
+		// If this session still exists, perform send operations on it and
+		// check for the eof state.
+		if (session[ current_node->fd ])
+		{
+			if (session[ current_node->fd ]->wdata_size)
+				session[ current_node->fd ]->func_send( current_node->fd );
+
+			// If it's been marked as eof, call the parse func on it so that
+			// the socket will be immediately closed.
+			if (session[ current_node->fd ]->eof)
+				session[ current_node->fd ]->func_parse( current_node->fd );
+
+			// If the session still exists, is not eof and has things left to
+			// be sent from it we'll keep it in the send shortlist.
+			if (session[ current_node->fd ] &&
+					!session[ current_node->fd ]->eof &&
+					session[ current_node->fd ]->wdata_size)
+				delete_current_node = 0;
+		}
+
+		// If this session has been marked for removal from the short list,
+		// we'll proceed in doing this.
+		if (delete_current_node)
+		{
+			FD_CLR(current_node->fd, &send_shortlist_fd_set);
+
+			// Remove its link entry
+			if (!current_node->prev)
+				send_shortlist = next_node;
+			else
+				current_node->prev->next = next_node;
+
+			if (current_node->next)
+				current_node->next->prev = current_node->prev;
+
+			// and free its memory
+			aFree(current_node);
+		}
+
+		// Iterate to the next node (session) in the short list
+		current_node = next_node;
+	}
+}
+#endif

+ 22 - 0
src/common/socket.h

@@ -140,4 +140,26 @@ int socket_getips(uint32* ips, int max);
 extern uint32 addr_[16];   // ip addresses of local host (host byte order)
 extern int naddr_;   // # of ip addresses
 
+void set_eof(int fd);
+
+/// Use a shortlist of sockets instead of iterating all sessions for sockets 
+/// that have data to send or need eof processing.
+///
+/// @author Buuyo-tama
+//#define SEND_SHORTLIST
+
+#ifdef SEND_SHORTLIST
+struct send_shortlist_node {
+	struct send_shortlist_node *next; // Next node in the linked list
+	struct send_shortlist_node *prev; // Previous node in the linked list
+	int fd; // FD that needs sending.
+};
+
+// Add a fd to the shortlist so that it'll be recognized as a fd that needs
+// sending done on it.
+void send_shortlist_add_fd(int fd);
+// Do pending network sends (and eof handling) from the shortlist.
+void send_shortlist_do_sends();
+#endif
+
 #endif /* _SOCKET_H_ */

+ 22 - 22
src/ladmin/ladmin.c

@@ -7,6 +7,17 @@
 // if you modify this software, modify ladmin in tool too.
 ///////////////////////////////////////////////////////////////////////////
 
+#include "../common/cbasetypes.h"
+#include "../common/core.h"
+#include "../common/strlib.h"
+#include "../common/socket.h"
+#include "../common/timer.h"
+#include "../common/version.h"
+#include "../common/mmo.h"
+#include "../common/md5calc.h"
+#include "../common/showmsg.h"
+#include "ladmin.h"
+
 #include <sys/types.h>
 #include <time.h>
 #ifdef WIN32
@@ -36,17 +47,6 @@ void Gettimeofday(struct timeval *timenow)
 #include <fcntl.h>
 #include <string.h> // str*
 #include <stdarg.h> // valist
-#include <ctype.h> // tolower
-
-#include "../common/core.h"
-#include "../common/strlib.h"
-#include "../common/socket.h"
-#include "../common/timer.h"
-#include "../common/version.h"
-#include "../common/mmo.h"
-#include "../common/md5calc.h"
-#include "../common/showmsg.h"
-#include "ladmin.h"
 
 
 //-------------------------------INSTRUCTIONS------------------------------
@@ -579,7 +579,7 @@ void display_help(char* param, int language) {
 
 	// lowercase for command
 	for (i = 0; command[i]; i++)
-		command[i] = tolower(command[i]);
+		command[i] = TOLOWER(command[i]);
 
 	// Analyse of the command
 	check_command(command); // give complete name to the command
@@ -1146,7 +1146,7 @@ int addaccount(char* param, int emailflag) {
 		}
 	}*/
 
-	sex[0] = toupper(sex[0]);
+	sex[0] = TOUPPER(sex[0]);
 	if (strchr("MF", sex[0]) == NULL) {
 		if (defaultlanguage == 'F') {
 			ShowMessage("Sexe incorrect [%s]. Entrez M ou F svp.\n", sex);
@@ -1251,7 +1251,7 @@ int banaddaccount(char* param) {
 
 	// lowercase for modif
 	for (i = 0; modif[i]; i++)
-		modif[i] = tolower(modif[i]);
+		modif[i] = TOLOWER(modif[i]);
 	p_modif = modif;
 	while (strlen(p_modif) > 0) {
 		value = atoi(p_modif);
@@ -2074,7 +2074,7 @@ int changelanguage(char* language) {
 		return 136;
 	}
 
-	language[0] = toupper(language[0]);
+	language[0] = TOUPPER(language[0]);
 	if (language[0] == 'F' || language[0] == 'E') {
 		defaultlanguage = language[0];
 		if (defaultlanguage == 'F') {
@@ -2115,7 +2115,7 @@ int listaccount(char* param, int type) {
 		// get all accounts = use default
 	} else if (list_type == 2) { // if search
 		for (i = 0; param[i]; i++)
-			param[i] = tolower(param[i]);
+			param[i] = TOLOWER(param[i]);
 		// get all accounts = use default
 	} else if (list_type == 3) { // if listban
 		// get all accounts = use default
@@ -2355,7 +2355,7 @@ int changesex(char* param) {
 		return 102;
 	}
 
-	sex[0] = toupper(sex[0]);
+	sex[0] = TOUPPER(sex[0]);
 	if (strchr("MF", sex[0]) == NULL) {
 		if (defaultlanguage == 'F') {
 			ShowMessage("Sexe incorrect [%s]. Entrez M ou F svp.\n", sex);
@@ -2607,7 +2607,7 @@ int timeaddaccount(char* param) {
 
 	// lowercase for modif
 	for (i = 0; modif[i]; i++)
-		modif[i] = tolower(modif[i]);
+		modif[i] = TOLOWER(modif[i]);
 	p_modif = modif;
 	while (strlen(p_modif) > 0) {
 		value = atoi(p_modif);
@@ -3081,7 +3081,7 @@ int prompt(void) {
 
 		// lowercase for command line
 		for (i = 0; command[i]; i++)
-			command[i] = tolower(command[i]);
+			command[i] = TOLOWER(command[i]);
 
 		if (command[0] == '?' || strlen(command) == 0) {
 			if (defaultlanguage == 'F') {
@@ -3250,7 +3250,7 @@ int parse_fromlogin(int fd)
 					ShowMessage(" - unauthorised IP.\n");
 					ladmin_log("Error at login: incorrect password, administration system not activated, or unauthorised IP." RETCODE);
 				}
-				session[fd]->eof = 1;
+				set_eof(fd);
 				//bytes_to_read = 1; // not stop at prompt
 				return 0;
 			} else {
@@ -3361,7 +3361,7 @@ int parse_fromlogin(int fd)
 					userid[sizeof(userid)-1] = '\0';
 					memset(lower_userid, '\0', sizeof(lower_userid));
 					for (j = 0; userid[j]; j++)
-						lower_userid[j] = tolower(userid[j]);
+						lower_userid[j] = TOLOWER(userid[j]);
 					list_first = RFIFOL(fd,i) + 1;
 					// here are checks...
 					if (list_type == 0 ||
@@ -4148,7 +4148,7 @@ int parse_fromlogin(int fd)
 		default:
 			ShowMessage("Remote administration has been disconnected (unknown packet).\n");
 			ladmin_log("'End of connection, unknown packet." RETCODE);
-			session[fd]->eof = 1;
+			set_eof(fd);
 			return 0;
 		}
 	}

+ 15 - 15
src/login/login.c

@@ -1,13 +1,6 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/stat.h> // for stat/lstat/fstat
-#include <signal.h>
-#include <fcntl.h>
-#include <string.h>
-
 #include "../common/cbasetypes.h"
 #include "../common/core.h"
 #include "../common/socket.h"
@@ -22,6 +15,13 @@
 #include "../common/md5calc.h"
 #include "login.h"
 
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/stat.h> // for stat/lstat/fstat
+#include <signal.h>
+#include <fcntl.h>
+#include <string.h>
+
 uint32 account_id_count = START_ACCOUNT_NUM;
 bool new_account_flag = true;
 uint32 login_ip = INADDR_ANY;
@@ -1367,7 +1367,7 @@ int parse_fromchar(int fd)
 		if (server_fd[id] == fd)
 			break;
 	if (id == MAX_SERVERS) { // not a char server
-		session[fd]->eof = 1;
+		set_eof(fd);
 		do_close(fd);
 		return 0;
 	}
@@ -1946,7 +1946,7 @@ int parse_fromchar(int fd)
 				}
 			}
 			ShowError("parse_fromchar: Unknown packet 0x%x from a char-server! Disconnecting!\n", command);
-			session[fd]->eof = 1;
+			set_eof(fd);
 			return 0;
 		}
 	}
@@ -2001,7 +2001,7 @@ int parse_admin(int fd)
 		case 0x7532:	// Request of end of connection
 			login_log("'ladmin': End of connection (ip: %s)" RETCODE, ip);
 			RFIFOSKIP(fd,2);
-			session[fd]->eof = 1;
+			set_eof(fd);
 			break;
 
 		case 0x7920:	// Request of an accounts list
@@ -2915,7 +2915,7 @@ int parse_admin(int fd)
 				}
 			}
 			login_log("'ladmin': End of connection, unknown packet (ip: %s)" RETCODE, ip);
-			session[fd]->eof = 1;
+			set_eof(fd);
 			ShowWarning("Remote administration has been disconnected (unknown packet).\n");
 			return 0;
 		}
@@ -3012,7 +3012,7 @@ int parse_login(int fd)
 				WFIFOB(fd,2) = 3; // 3 = Rejected from Server
 				WFIFOSET(fd,23);
 				RFIFOSKIP(fd,packet_len);
-				session[fd]->eof = 1;
+				set_eof(fd);
 				break;
 			}
 
@@ -3123,7 +3123,7 @@ int parse_login(int fd)
 			struct login_session_data* ld;
 			if (session[fd]->session_data) {
 				ShowWarning("login: abnormal request of MD5 key (already opened session).\n");
-				session[fd]->eof = 1;
+				set_eof(fd);
 				return 0;
 			}
 
@@ -3243,7 +3243,7 @@ int parse_login(int fd)
 
 		case 0x7532:	// Request to end connection
 			login_log("End of connection (ip: %s)" RETCODE, ip);
-			session[fd]->eof = 1;
+			set_eof(fd);
 			return 0;
 
 		case 0x7918:	// Request for administation login
@@ -3340,7 +3340,7 @@ int parse_login(int fd)
 				}
 			}
 			login_log("Abnormal end of connection (ip: %s): Unknown packet 0x%x " RETCODE, ip, command);
-			session[fd]->eof = 1;
+			set_eof(fd);
 			return 0;
 		}
 	}

+ 13 - 13
src/login_sql/login.c

@@ -1,13 +1,6 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/stat.h> // for stat/lstat/fstat
-#include <signal.h>
-#include <fcntl.h>
-#include <string.h>
-
 #include "../common/cbasetypes.h"
 #include "../common/core.h"
 #include "../common/socket.h"
@@ -21,6 +14,13 @@
 #include "../common/md5calc.h"
 #include "login.h"
 
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/stat.h> // for stat/lstat/fstat
+#include <signal.h>
+#include <fcntl.h>
+#include <string.h>
+
 //add include for DBMS(mysql)
 #ifdef WIN32
 #include <winsock2.h>
@@ -735,7 +735,7 @@ int parse_fromchar(int fd)
 		if (server_fd[id] == fd)
 			break;
 	if (id == MAX_SERVERS) { // not a char server
-		session[fd]->eof = 1;
+		set_eof(fd);
 		do_close(fd);
 		return 0;
 	}
@@ -1236,7 +1236,7 @@ int parse_fromchar(int fd)
 
 		default:
 			ShowError("parse_fromchar: Unknown packet 0x%x from a char-server! Disconnecting!\n", RFIFOW(fd,0));
-			session[fd]->eof = 1;
+			set_eof(fd);
 			return 0;
 		}
 	}
@@ -1354,7 +1354,7 @@ int parse_login(int fd)
 				WFIFOB(fd,2) = 3; // 3 = Rejected from Server
 				WFIFOSET(fd,23);
 				RFIFOSKIP(fd,packet_len);
-				session[fd]->eof = 1;
+				set_eof(fd);
 				break;
 			}
 
@@ -1541,7 +1541,7 @@ int parse_login(int fd)
 			struct login_session_data* ld;
 			if (session[fd]->session_data) {
 				ShowWarning("login: abnormal request of MD5 key (already opened session).\n");
-				session[fd]->eof = 1;
+				set_eof(fd);
 				return 0;
 			}
 
@@ -1655,12 +1655,12 @@ int parse_login(int fd)
 
 		case 0x7532:	// Request to end connection
 			ShowStatus ("End of connection (ip: %s)" RETCODE, ip);
-			session[fd]->eof = 1;
+			set_eof(fd);
 			break;
 
 		default:
 			ShowStatus ("Abnormal end of connection (ip: %s): Unknown packet 0x%x " RETCODE, ip, RFIFOW(fd,0));
-			session[fd]->eof = 1;
+			set_eof(fd);
 			return 0;
 		}
 	}

+ 9 - 9
src/map/chrif.c

@@ -1,12 +1,6 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <time.h>
-
 #include "../common/cbasetypes.h"
 #include "../common/malloc.h"
 #include "../common/socket.h"
@@ -16,13 +10,19 @@
 
 #include "map.h"
 #include "battle.h"
-#include "chrif.h"
 #include "clif.h"
 #include "intif.h"
 #include "npc.h"
 #include "pc.h"
 #include "status.h"
 #include "mercenary.h"
+#include "chrif.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <time.h>
 
 struct dbt *auth_db;
 
@@ -1424,7 +1424,7 @@ int chrif_parse(int fd)
 			if (r == 1) continue;	// intifで処理した
 			if (r == 2) return 0;	// intifで処理したが、データが足りない
 
-			session[fd]->eof = 1;
+			set_eof(fd);
 			ShowWarning("chrif_parse: session #%d, intif_parse failed -> disconnected.\n", fd);
 			return 0;
 		}
@@ -1465,7 +1465,7 @@ int chrif_parse(int fd)
 		default:
 			if (battle_config.error_log)
 				ShowError("chrif_parse : unknown packet (session #%d): 0x%x. Disconnecting.\n", fd, cmd);
-			session[fd]->eof = 1;
+			set_eof(fd);
 			return 0;
 		}
 		if (fd == char_fd) //There's the slight chance we lost the connection during parse, in which case this would segfault if not checked [Skotlex]

+ 11 - 11
src/map/clif.c

@@ -4,12 +4,6 @@
 #define DUMP_UNKNOWN_PACKET	0
 #define DUMP_ALL_PACKETS	0
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdarg.h>
-#include <time.h>
-
 #include "../common/cbasetypes.h"
 #include "../common/socket.h"
 #include "../common/timer.h"
@@ -21,7 +15,6 @@
 
 #include "map.h"
 #include "chrif.h"
-#include "clif.h"
 #include "pc.h"
 #include "status.h"
 #include "npc.h"
@@ -44,6 +37,13 @@
 #include "mercenary.h"	//[orn]
 #include "log.h"
 #include "irc.h"
+#include "clif.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+#include <time.h>
 
 struct Clif_Config {
 	int packet_db_ver;	//Preferred packet version.
@@ -1622,7 +1622,7 @@ void clif_quitsave(int fd,struct map_session_data *sd)
  */
 static int clif_waitclose(int tid, unsigned int tick, int id, int data) {
 	if (session[id] && session[id]->func_parse == clif_parse) //Avoid disconnecting non-players, as pointed out by End of Exam [Skotlex]
-		session[id]->eof = 1;
+		set_eof(id);
 
 	return 0;
 }
@@ -11873,7 +11873,7 @@ int clif_parse(int fd)
 		packet_ver = sd->packet_ver;
 		if (packet_ver < 0 || packet_ver > MAX_PACKET_VER) {	// This should never happen unless we have some corrupted memory issues :X [Skotlex]
 			ShowWarning("clif_parse: Disconnecting session #%d (AID:%d/CID:%d) for having invalid packet_ver=%d.", fd, sd->status.account_id, sd->status.char_id, packet_ver);
-			session[fd]->eof = 1;
+			set_eof(fd);
 			return 0;
 		}
 	} else {
@@ -11909,7 +11909,7 @@ int clif_parse(int fd)
 	// ゲーム用以外パケットか、認証を終える前に0072以外が来たら、切断する
 	if (cmd > MAX_PACKET_DB || packet_db[packet_ver][cmd].len == 0) {	// if packet is not inside these values: session is incorrect?? or auth packet is unknown
 		ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
-		session[fd]->eof = 1;
+		set_eof(fd);
 		return 0;
 	}
 
@@ -11922,7 +11922,7 @@ int clif_parse(int fd)
 		packet_len = RFIFOW(fd,2);
 		if (packet_len < 4 || packet_len > 32768) {
 			ShowWarning("clif_parse: Packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
-			session[fd]->eof =1;
+			set_eof(fd);
 			return 0;
 		}
 	}

+ 6 - 6
src/map/irc.c

@@ -1,10 +1,6 @@
 // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
 // For more information, see LICENCE in the main folder
 
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-
 #include "../common/core.h"
 #include "../common/socket.h"
 #include "../common/malloc.h"
@@ -18,8 +14,12 @@
 
 #include "map.h"
 #include "pc.h"
-#include "irc.h"
 #include "intif.h" //For GM Broadcast [Zido]
+#include "irc.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
 
 short use_irc=0;
 
@@ -252,7 +252,7 @@ void irc_parse_sub(int fd, char *incoming_string)
 	        	sprintf(send_string, "QUIT");
 			irc_send(send_string);
 			if(session[fd])
-				session[fd]->eof=1;
+				set_eof(fd);
 		}
 	}
 	else if (irc_si->state == 2){