Преглед на файлове

- Removed the TURBO socket mechanism - it was in fact just using a variable to cache a few arithmetic operations (premature optimization)
- Since the fifohead mess is gone, fixed leftover bad code structuring

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

ultramage преди 18 години
родител
ревизия
9e7eb8804f
променени са 23 файла, в които са добавени 1082 реда и са изтрити 1286 реда
  1. 4 0
      Changelog-Trunk.txt
  2. 0 3
      Makefile
  3. 288 243
      src/char/char.c
  4. 274 265
      src/char_sql/char.c
  5. 0 2
      src/char_sql/char.h
  6. 0 2
      src/char_sql/int_guild.c
  7. 0 11
      src/char_sql/int_homun.c
  8. 0 10
      src/char_sql/int_party.c
  9. 0 10
      src/char_sql/int_pet.c
  10. 0 10
      src/char_sql/int_storage.c
  11. 0 2
      src/common/core.h
  12. 0 9
      src/common/socket.h
  13. 265 264
      src/login/login.c
  14. 171 159
      src/login_sql/login.c
  15. 0 6
      src/login_sql/login.h
  16. 29 46
      src/map/chrif.c
  17. 46 170
      src/map/clif.c
  18. 4 51
      src/map/intif.c
  19. 0 1
      src/map/irc.c
  20. 0 6
      src/map/log.c
  21. 0 12
      src/map/mail.c
  22. 1 3
      src/map/map.c
  23. 0 1
      src/map/pc.c

+ 4 - 0
Changelog-Trunk.txt

@@ -3,6 +3,10 @@ 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/21
+	* Since the fifohead mess is gone, fixed leftover bad code structuring
+	* Removed the TURBO socket mechanism - it was in fact just using a
+	  variable to cache a few arithmetic operations (premature optimization)
 2007/05/20
 	* Fixed Chase Walk having a deactivation cast time (should be instant)
 	* Changed status calc to allow value 0 stats; aegis allows

+ 0 - 3
Makefile

@@ -33,9 +33,6 @@ endif
 # OPT += -DPACKETVER=8
 # Makes map-wide script variables be saved to SQL instead of TXT files.
 # OPT += -DMAPREGSQL
-# Turbo is an alternate socket access implementation which should be faster.
-# DO NOT ENABLE YET as it isn't quite ready for general usage.
-# OPT += -DTURBO
 # Enable the perl regular expression support for scripts
 # OPT += -DPCRE_SUPPORT
 # OPT += -DGCOLLECT

Файловите разлики са ограничени, защото са твърде много
+ 288 - 243
src/char/char.c


Файловите разлики са ограничени, защото са твърде много
+ 274 - 265
src/char_sql/char.c


+ 0 - 2
src/char_sql/char.h

@@ -101,8 +101,6 @@ extern struct gm_account *gm_account;
 extern int guild_exp_rate;
 extern int log_inter;
 
-extern int debug_mysql_query(char *file, int line, void *mysql, const char *q);
-
 //Exported for use in the TXT-SQL converter.
 int mmo_char_tosql(int char_id, struct mmo_charstatus *p);
 void sql_config_read(const char *cfgName);

+ 0 - 2
src/char_sql/int_guild.c

@@ -49,8 +49,6 @@ int mapif_guild_info(int fd,struct guild *g);
 int guild_break_sub(int key,void *data,va_list ap);
 int inter_guild_tosql(struct guild *g,int flag);
 
-#define mysql_query(_x, _y)  debug_mysql_query(__FILE__, __LINE__, _x, _y)
-
 static int guild_save(DBKey key, void *data, va_list ap) {
 	struct guild *g = (struct guild*) data;
 	int *last_id = va_arg(ap, int *);

+ 0 - 11
src/char_sql/int_homun.c

@@ -12,17 +12,6 @@
 
 struct s_homunculus *homun_pt;
 
-#ifndef SQL_DEBUG
-
-#define mysql_query(_x, _y) mysql_real_query(_x, _y, strlen(_y)) //supports ' in names and runs faster [Kevin]
-
-#else
-
-#define mysql_query(_x, _y) debug_mysql_query(__FILE__, __LINE__, _x, _y)
-
-#endif
-
-
 int inter_homunculus_sql_init(void){
 	//memory alloc
 	homun_pt = (struct s_homunculus*)aCalloc(sizeof(struct s_homunculus), 1);

+ 0 - 10
src/char_sql/int_party.c

@@ -34,16 +34,6 @@ int mapif_parse_PartyLeave(int fd, int party_id, int account_id, int char_id);
 int party_check_exp_share(struct party_data *p);
 int mapif_party_optionchanged(int fd,struct party *p, int account_id, int flag);
 
-#ifndef SQL_DEBUG
-
-#define mysql_query(_x, _y) mysql_real_query(_x, _y, strlen(_y)) //supports ' in names and runs faster [Kevin]
-
-#else 
-
-#define mysql_query(_x, _y) debug_mysql_query(__FILE__, __LINE__, _x, _y)
-
-#endif
-
 //Updates party's level range and unsets even share if broken.
 static int int_party_check_lv(struct party_data *p) {
 	int i;

+ 0 - 10
src/char_sql/int_pet.c

@@ -15,16 +15,6 @@
 
 struct s_pet *pet_pt;
 
-#ifndef SQL_DEBUG
-
-#define mysql_query(_x, _y) mysql_real_query(_x, _y, strlen(_y)) //supports ' in names and runs faster [Kevin]
-
-#else 
-
-#define mysql_query(_x, _y) debug_mysql_query(__FILE__, __LINE__, _x, _y)
-
-#endif
-
 //---------------------------------------------------------
 int inter_pet_tosql(int pet_id, struct s_pet *p) {
 	//`pet` (`pet_id`, `class`,`name`,`account_id`,`char_id`,`level`,`egg_id`,`equip`,`intimate`,`hungry`,`rename_flag`,`incuvate`)

+ 0 - 10
src/char_sql/int_storage.c

@@ -20,16 +20,6 @@
 struct storage *storage_pt=NULL;
 struct guild_storage *guild_storage_pt=NULL;
 
-#ifndef SQL_DEBUG
-
-#define mysql_query(_x, _y) mysql_real_query(_x, _y, strlen(_y)) //supports ' in names and runs faster [Kevin]
-
-#else 
-
-#define mysql_query(_x, _y) debug_mysql_query(__FILE__, __LINE__, _x, _y)
-
-#endif
-
 #endif //TXT_SQL_CONVERT
 // storage data -> DB conversion
 int storage_tosql(int account_id,struct storage *p){

+ 0 - 2
src/common/core.h

@@ -4,8 +4,6 @@
 #ifndef	_CORE_H_
 #define	_CORE_H_
 
-//#define SQL_DEBUG //uncomment for debug_mysql_query instead of mysql_real_query
-	
 extern int arg_c;
 extern char **arg_v;
 

+ 0 - 9
src/common/socket.h

@@ -21,19 +21,10 @@
 
 
 // socket I/O macros
-#ifdef TURBO
-#define RFIFOVAR(fd) rbPtr ## fd
-#define WFIFOVAR(fd) wbPtr ## fd
-#define RFIFOHEAD(fd) uint8 *RFIFOVAR(fd) = session[fd]->rdata+session[fd]->rdata_pos
-#define WFIFOHEAD(fd, x) uint8 *WFIFOVAR(fd) = ( (fd) > 0 && session[fd] ? session[fd]->wdata+session[fd]->wdata_size : NULL )
-#define RFIFOP(fd,pos) ( &RFIFOVAR(fd) + (pos) )
-#define WFIFOP(fd,pos) ( &WFIFOVAR(fd) + (pos) )
-#else
 #define RFIFOHEAD(fd)
 #define WFIFOHEAD(fd, size) do{ if((fd) && session[fd]->wdata_size + (size) > session[fd]->max_wdata ) 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))
-#endif
 
 #define RFIFOB(fd,pos) (*(uint8*)RFIFOP(fd,pos))
 #define WFIFOB(fd,pos) (*(uint8*)WFIFOP(fd,pos))

+ 265 - 264
src/login/login.c

@@ -972,8 +972,6 @@ int charif_sendallwos(int sfd, unsigned char *buf, unsigned int len)
 	for(i = 0, c = 0; i < MAX_SERVERS; i++) {
 		if ((fd = server_fd[i]) >= 0 && fd != sfd) {
 			WFIFOHEAD(fd,len);
-			if (WFIFOSPACE(fd) < len) //Increase buffer size.
-				realloc_writefifo(fd, len);
 			memcpy(WFIFOP(fd,0), buf, len);
 			WFIFOSET(fd,len);
 			c++;
@@ -984,9 +982,9 @@ int charif_sendallwos(int sfd, unsigned char *buf, unsigned int len)
 }
 
 //-----------------------------------------------------
-// Send GM accounts to all char-server
+// Send GM accounts to one or all char-servers
 //-----------------------------------------------------
-void send_GM_accounts(void)
+void send_GM_accounts(int fd)
 {
 	unsigned int i;
 	uint8 buf[32767];
@@ -1007,7 +1005,13 @@ void send_GM_accounts(void)
 		}
 
 	WBUFW(buf,2) = len;
-	charif_sendallwos(-1, buf, len);
+	if (fd == -1) // send to all charservers
+		charif_sendallwos(-1, buf, len);
+	else { // send only to target
+		WFIFOHEAD(fd,len);
+		memcpy(WFIFOP(fd,0), buf, len);
+		WFIFOSET(fd,len);
+	}
 
 	return;
 }
@@ -1032,7 +1036,7 @@ int check_GM_file(int tid, unsigned int tick, int id, int data)
 
 	if (new_time != creation_time_GM_account_file) {
 		read_gm_account();
-		send_GM_accounts();
+		send_GM_accounts(-1);
 	}
 
 	return 0;
@@ -1366,9 +1370,6 @@ int parse_fromchar(int fd)
 	int j, id;
 	uint32 ipl = session[fd]->client_addr;
 	char ip[16];
-	RFIFOHEAD(fd);
-
-	ip2str(ipl, ip);
 
 	for(id = 0; id < MAX_SERVERS; id++)
 		if (server_fd[id] == fd)
@@ -1379,6 +1380,8 @@ int parse_fromchar(int fd)
 		return 0;
 	}
 
+	ip2str(ipl, ip);
+
 	if(session[fd]->eof) {
 		ShowStatus("Char-server '%s' has disconnected.\n", server[id].name);
 		login_log("Char-server '%s' has disconnected (ip: %s)." RETCODE, server[id].name, ip);
@@ -1403,7 +1406,7 @@ int parse_fromchar(int fd)
 			login_log("Char-server '%s': Request to re-load GM configuration file (ip: %s)." RETCODE, server[id].name, ip);
 			read_gm_account();
 			// send GM accounts to all char-servers
-			send_GM_accounts();
+			send_GM_accounts(-1);
 			RFIFOSKIP(fd,2);
 			break;
 
@@ -1424,7 +1427,6 @@ int parse_fromchar(int fd)
 					unsigned int k;
 					time_t connect_until_time = 0;
 					char email[40] = "";
-					WFIFOHEAD(fd,51);
 					auth_fifo[i].delflag = 1;
 					login_log("Char-server '%s': authentification of the account %d accepted (ip: %s)." RETCODE,
 					          server[id].name, account_id, ip);
@@ -1435,6 +1437,7 @@ int parse_fromchar(int fd)
 							break;
 						}
 					}
+					WFIFOHEAD(fd,51);
 					WFIFOW(fd,0) = 0x2713;
 					WFIFOL(fd,2) = account_id;
 					WFIFOB(fd,6) = 0;
@@ -1456,9 +1459,10 @@ int parse_fromchar(int fd)
 				// It is unnecessary to send validity date of the account
 				WFIFOSET(fd,51);
 			}
-		}
+
 			RFIFOSKIP(fd,19);
-			break;
+		}
+		break;
 
 		case 0x2714:
 			if (RFIFOREST(fd) < 6)
@@ -1471,7 +1475,7 @@ int parse_fromchar(int fd)
 			WFIFOSET(fd,2);
 
 			RFIFOSKIP(fd,6);
-			break;
+		break;
 
 		case 0x2715: // request from char server to change e-email from default "a@a.com"
 			if (RFIFOREST(fd) < 46)
@@ -1496,9 +1500,10 @@ int parse_fromchar(int fd)
 				if (i == auth_num)
 					login_log("Char-server '%s': Attempt to create an e-mail on an account with a default e-mail REFUSED - account doesn't exist or e-mail of account isn't default e-mail (account: %d, ip: %s)." RETCODE, server[id].name, acc, ip);
 			}
-		}
+
 			RFIFOSKIP(fd,46);
-			break;
+		}
+		break;
 
 		case 0x2716: // received an e-mail/limited time request, because a player comes back from a map-server to the char-server
 			if (RFIFOREST(fd) < 6)
@@ -1519,63 +1524,65 @@ int parse_fromchar(int fd)
 			if (i == auth_num)
 				login_log("Char-server '%s': e-mail of the account %d NOT found (ip: %s)." RETCODE,
 				          server[id].name, RFIFOL(fd,2), ip);
+
 			RFIFOSKIP(fd,6);
-			break;
+		break;
 
 		case 0x2720: // Request to become a GM
 			if (RFIFOREST(fd) < 4 || RFIFOREST(fd) < RFIFOW(fd,2))
 				return 0;
-			  {
-				unsigned char buf[10];
-				FILE *fp;
-				int acc = RFIFOL(fd,4);
-				//printf("parse_fromchar: Request to become a GM acount from %d account.\n", acc);
-				WBUFW(buf,0) = 0x2721;
-				WBUFL(buf,2) = acc;
-				WBUFL(buf,6) = 0;
-				if (strcmp((char*)RFIFOP(fd,8), gm_pass) == 0) {
-					// only non-GM can become GM
-					if (isGM(acc) == 0) {
-						// if we autorise creation
-						if (level_new_gm > 0) {
-							// if we can open the file to add the new GM
-							if ((fp = fopen(GM_account_filename, "a")) != NULL) {
-								char tmpstr[24];
-								time_t raw_time;
-								time(&raw_time);
-								strftime(tmpstr, 23, date_format, localtime(&raw_time));
-								fprintf(fp, RETCODE "// %s: @GM command on account %d" RETCODE "%d %d" RETCODE, tmpstr, acc, acc, level_new_gm);
-								fclose(fp);
-								WBUFL(buf,6) = level_new_gm;
-								read_gm_account();
-								send_GM_accounts();
-								ShowNotice("GM Change of the account %d: level 0 -> %d.\n", acc, level_new_gm);
-								login_log("Char-server '%s': GM Change of the account %d: level 0 -> %d (ip: %s)." RETCODE,
-								          server[id].name, acc, level_new_gm, ip);
-							} else {
-								ShowError("Error of GM change (suggested account: %d, correct password, unable to add a GM account in GM accounts file)\n", acc);
-								login_log("Char-server '%s': Error of GM change (suggested account: %d, correct password, unable to add a GM account in GM accounts file, ip: %s)." RETCODE,
-								          server[id].name, acc, ip);
-							}
+		{
+			unsigned char buf[10];
+			FILE *fp;
+			int acc = RFIFOL(fd,4);
+			//printf("parse_fromchar: Request to become a GM acount from %d account.\n", acc);
+			WBUFW(buf,0) = 0x2721;
+			WBUFL(buf,2) = acc;
+			WBUFL(buf,6) = 0;
+			if (strcmp((char*)RFIFOP(fd,8), gm_pass) == 0) {
+				// only non-GM can become GM
+				if (isGM(acc) == 0) {
+					// if we autorise creation
+					if (level_new_gm > 0) {
+						// if we can open the file to add the new GM
+						if ((fp = fopen(GM_account_filename, "a")) != NULL) {
+							char tmpstr[24];
+							time_t raw_time;
+							time(&raw_time);
+							strftime(tmpstr, 23, date_format, localtime(&raw_time));
+							fprintf(fp, RETCODE "// %s: @GM command on account %d" RETCODE "%d %d" RETCODE, tmpstr, acc, acc, level_new_gm);
+							fclose(fp);
+							WBUFL(buf,6) = level_new_gm;
+							read_gm_account();
+							send_GM_accounts(-1);
+							ShowNotice("GM Change of the account %d: level 0 -> %d.\n", acc, level_new_gm);
+							login_log("Char-server '%s': GM Change of the account %d: level 0 -> %d (ip: %s)." RETCODE,
+							          server[id].name, acc, level_new_gm, ip);
 						} else {
-							ShowError("Error of GM change (suggested account: %d, correct password, but GM creation is disable (level_new_gm = 0))\n", acc);
-							login_log("Char-server '%s': Error of GM change (suggested account: %d, correct password, but GM creation is disable (level_new_gm = 0), ip: %s)." RETCODE,
+							ShowError("Error of GM change (suggested account: %d, correct password, unable to add a GM account in GM accounts file)\n", acc);
+							login_log("Char-server '%s': Error of GM change (suggested account: %d, correct password, unable to add a GM account in GM accounts file, ip: %s)." RETCODE,
 							          server[id].name, acc, ip);
 						}
 					} else {
-						ShowError("Error of GM change (suggested account: %d (already GM), correct password).\n", acc);
-						login_log("Char-server '%s': Error of GM change (suggested account: %d (already GM), correct password, ip: %s)." RETCODE,
+						ShowError("Error of GM change (suggested account: %d, correct password, but GM creation is disable (level_new_gm = 0))\n", acc);
+						login_log("Char-server '%s': Error of GM change (suggested account: %d, correct password, but GM creation is disable (level_new_gm = 0), ip: %s)." RETCODE,
 						          server[id].name, acc, ip);
 					}
 				} else {
-					ShowError("Error of GM change (suggested account: %d, invalid password).\n", acc);
-					login_log("Char-server '%s': Error of GM change (suggested account: %d, invalid password, ip: %s)." RETCODE,
+					ShowError("Error of GM change (suggested account: %d (already GM), correct password).\n", acc);
+					login_log("Char-server '%s': Error of GM change (suggested account: %d (already GM), correct password, ip: %s)." RETCODE,
 					          server[id].name, acc, ip);
 				}
-				charif_sendallwos(-1, buf, 10);
-			  }
+			} else {
+				ShowError("Error of GM change (suggested account: %d, invalid password).\n", acc);
+				login_log("Char-server '%s': Error of GM change (suggested account: %d, invalid password, ip: %s)." RETCODE,
+				          server[id].name, acc, ip);
+			}
+			charif_sendallwos(-1, buf, 10);
+
 			RFIFOSKIP(fd, RFIFOW(fd,2));
 			return 0;
+		}
 
 		// Map server send information to change an email of an account via char-server
 		case 0x2722:	// 0x2722 <account_id>.L <actual_e-mail>.40B <new_e-mail>.40B
@@ -1614,9 +1621,10 @@ int parse_fromchar(int fd)
 					login_log("Char-server '%s': Attempt to modify an e-mail on an account (@email GM command), but account doesn't exist (account: %d, ip: %s)." RETCODE,
 					          server[id].name, acc, ip);
 			}
-		  }
+
 			RFIFOSKIP(fd, 86);
-			break;
+		}
+		break;
 
 		case 0x2724: // Receiving of map-server via char-server a status change resquest
 			if (RFIFOREST(fd) < 10)
@@ -1661,104 +1669,106 @@ int parse_fromchar(int fd)
 			if (RFIFOREST(fd) < 18)
 				return 0;
 		{
-				uint32 acc = RFIFOL(fd,2);
-				for(i = 0; i < auth_num; i++) {
-					if (auth_dat[i].account_id == acc) {
-						time_t timestamp;
-						struct tm *tmtime;
-						if (auth_dat[i].ban_until_time == 0 || auth_dat[i].ban_until_time < time(NULL))
-							timestamp = time(NULL);
-						else
-							timestamp = auth_dat[i].ban_until_time;
-						tmtime = localtime(&timestamp);
-						tmtime->tm_year = tmtime->tm_year + (short)RFIFOW(fd,6);
-						tmtime->tm_mon = tmtime->tm_mon + (short)RFIFOW(fd,8);
-						tmtime->tm_mday = tmtime->tm_mday + (short)RFIFOW(fd,10);
-						tmtime->tm_hour = tmtime->tm_hour + (short)RFIFOW(fd,12);
-						tmtime->tm_min = tmtime->tm_min + (short)RFIFOW(fd,14);
-						tmtime->tm_sec = tmtime->tm_sec + (short)RFIFOW(fd,16);
-						timestamp = mktime(tmtime);
-						if (timestamp != -1) {
-							if (timestamp <= time(NULL))
-								timestamp = 0;
-							if (auth_dat[i].ban_until_time != timestamp) {
-								if (timestamp != 0) {
-									unsigned char buf[16];
-									char tmpstr[2048];
-									strftime(tmpstr, 24, date_format, localtime(&timestamp));
-									login_log("Char-server '%s': Ban request (account: %d, new final date of banishment: %d (%s), ip: %s)." RETCODE,
-									          server[id].name, acc, timestamp, (timestamp == 0 ? "no banishment" : tmpstr), ip);
-									WBUFW(buf,0) = 0x2731;
-									WBUFL(buf,2) = auth_dat[i].account_id;
-									WBUFB(buf,6) = 1; // 0: change of statut, 1: ban
-									WBUFL(buf,7) = (unsigned int)timestamp; // status or final date of a banishment
-									charif_sendallwos(-1, buf, 11);
-									for(j = 0; j < AUTH_FIFO_SIZE; j++)
-										if (auth_fifo[j].account_id == acc)
-											auth_fifo[j].login_id1++; // to avoid reconnection error when come back from map-server (char-server will ask again the authentification)
-								} else {
-									login_log("Char-server '%s': Error of ban request (account: %d, new date unbans the account, ip: %s)." RETCODE,
-									          server[id].name, acc, ip);
-								}
-								auth_dat[i].ban_until_time = timestamp;
-								// Save
-								mmo_auth_sync();
+			uint32 acc = RFIFOL(fd,2);
+			for(i = 0; i < auth_num; i++) {
+				if (auth_dat[i].account_id == acc) {
+					time_t timestamp;
+					struct tm *tmtime;
+					if (auth_dat[i].ban_until_time == 0 || auth_dat[i].ban_until_time < time(NULL))
+						timestamp = time(NULL);
+					else
+						timestamp = auth_dat[i].ban_until_time;
+					tmtime = localtime(&timestamp);
+					tmtime->tm_year = tmtime->tm_year + (short)RFIFOW(fd,6);
+					tmtime->tm_mon = tmtime->tm_mon + (short)RFIFOW(fd,8);
+					tmtime->tm_mday = tmtime->tm_mday + (short)RFIFOW(fd,10);
+					tmtime->tm_hour = tmtime->tm_hour + (short)RFIFOW(fd,12);
+					tmtime->tm_min = tmtime->tm_min + (short)RFIFOW(fd,14);
+					tmtime->tm_sec = tmtime->tm_sec + (short)RFIFOW(fd,16);
+					timestamp = mktime(tmtime);
+					if (timestamp != -1) {
+						if (timestamp <= time(NULL))
+							timestamp = 0;
+						if (auth_dat[i].ban_until_time != timestamp) {
+							if (timestamp != 0) {
+								unsigned char buf[16];
+								char tmpstr[2048];
+								strftime(tmpstr, 24, date_format, localtime(&timestamp));
+								login_log("Char-server '%s': Ban request (account: %d, new final date of banishment: %d (%s), ip: %s)." RETCODE,
+								          server[id].name, acc, timestamp, (timestamp == 0 ? "no banishment" : tmpstr), ip);
+								WBUFW(buf,0) = 0x2731;
+								WBUFL(buf,2) = auth_dat[i].account_id;
+								WBUFB(buf,6) = 1; // 0: change of statut, 1: ban
+								WBUFL(buf,7) = (unsigned int)timestamp; // status or final date of a banishment
+								charif_sendallwos(-1, buf, 11);
+								for(j = 0; j < AUTH_FIFO_SIZE; j++)
+									if (auth_fifo[j].account_id == acc)
+										auth_fifo[j].login_id1++; // to avoid reconnection error when come back from map-server (char-server will ask again the authentification)
 							} else {
-								login_log("Char-server '%s': Error of ban request (account: %d, no change for ban date, ip: %s)." RETCODE,
+								login_log("Char-server '%s': Error of ban request (account: %d, new date unbans the account, ip: %s)." RETCODE,
 								          server[id].name, acc, ip);
 							}
+							auth_dat[i].ban_until_time = timestamp;
+							// Save
+							mmo_auth_sync();
 						} else {
-							login_log("Char-server '%s': Error of ban request (account: %d, invalid date, ip: %s)." RETCODE,
+							login_log("Char-server '%s': Error of ban request (account: %d, no change for ban date, ip: %s)." RETCODE,
 							          server[id].name, acc, ip);
 						}
-						break;
+					} else {
+						login_log("Char-server '%s': Error of ban request (account: %d, invalid date, ip: %s)." RETCODE,
+						          server[id].name, acc, ip);
 					}
+					break;
 				}
-				if (i == auth_num)
-					login_log("Char-server '%s': Error of ban request (account: %d not found, ip: %s)." RETCODE,
-					          server[id].name, acc, ip);
-				RFIFOSKIP(fd,18);
-				return 0;
+			}
+			if (i == auth_num)
+				login_log("Char-server '%s': Error of ban request (account: %d not found, ip: %s)." RETCODE,
+				          server[id].name, acc, ip);
+
+			RFIFOSKIP(fd,18);
+			return 0;
 		}
 
 		case 0x2727: // Change of sex (sex is reversed)
 			if (RFIFOREST(fd) < 6)
 				return 0;
 		{
-				uint8 sex;
-				uint32 acc = RFIFOL(fd,2);
-				for(i = 0; i < auth_num; i++) {
-					if (auth_dat[i].account_id == acc) {
-						if (auth_dat[i].sex == 2)
-							login_log("Char-server '%s': Error of sex change - Server account (suggested account: %d, actual sex %d (Server), ip: %s)." RETCODE,
-							          server[id].name, acc, auth_dat[i].sex, ip);
-						else {
-							unsigned char buf[16];
-							if (auth_dat[i].sex == 0)
-								sex = 1;
-							else
-								sex = 0;
-							login_log("Char-server '%s': Sex change (account: %d, new sex %c, ip: %s)." RETCODE,
-							          server[id].name, acc, (sex == 2) ? 'S' : (sex == 1 ? 'M' : 'F'), ip);
-							for(j = 0; j < AUTH_FIFO_SIZE; j++)
-								if (auth_fifo[j].account_id == acc)
-									auth_fifo[j].login_id1++; // to avoid reconnection error when come back from map-server (char-server will ask again the authentification)
-							auth_dat[i].sex = sex;
-							WBUFW(buf,0) = 0x2723;
-							WBUFL(buf,2) = acc;
-							WBUFB(buf,6) = sex;
-							charif_sendallwos(-1, buf, 7);
-							// Save
-							mmo_auth_sync();
-						}
-						break;
+			uint8 sex;
+			uint32 acc = RFIFOL(fd,2);
+			for(i = 0; i < auth_num; i++) {
+				if (auth_dat[i].account_id == acc) {
+					if (auth_dat[i].sex == 2)
+						login_log("Char-server '%s': Error of sex change - Server account (suggested account: %d, actual sex %d (Server), ip: %s)." RETCODE,
+						          server[id].name, acc, auth_dat[i].sex, ip);
+					else {
+						unsigned char buf[16];
+						if (auth_dat[i].sex == 0)
+							sex = 1;
+						else
+							sex = 0;
+						login_log("Char-server '%s': Sex change (account: %d, new sex %c, ip: %s)." RETCODE,
+						          server[id].name, acc, (sex == 2) ? 'S' : (sex == 1 ? 'M' : 'F'), ip);
+						for(j = 0; j < AUTH_FIFO_SIZE; j++)
+							if (auth_fifo[j].account_id == acc)
+								auth_fifo[j].login_id1++; // to avoid reconnection error when come back from map-server (char-server will ask again the authentification)
+						auth_dat[i].sex = sex;
+						WBUFW(buf,0) = 0x2723;
+						WBUFL(buf,2) = acc;
+						WBUFB(buf,6) = sex;
+						charif_sendallwos(-1, buf, 7);
+						// Save
+						mmo_auth_sync();
 					}
+					break;
 				}
-				if (i == auth_num)
-					login_log("Char-server '%s': Error of sex change (account: %d not found, sex would be reversed, ip: %s)." RETCODE,
-					          server[id].name, acc, ip);
-				RFIFOSKIP(fd,6);
-				return 0;
+			}
+			if (i == auth_num)
+				login_log("Char-server '%s': Error of sex change (account: %d not found, sex would be reversed, ip: %s)." RETCODE,
+				          server[id].name, acc, ip);
+
+			RFIFOSKIP(fd,6);
+			return 0;
 		}
 
 		case 0x2728:	// We receive account_reg2 from a char-server, and we send them to other map-servers.
@@ -1803,47 +1813,49 @@ int parse_fromchar(int fd)
 					          server[id].name, acc, ip);
 				}
 			}
+
 			RFIFOSKIP(fd,RFIFOW(fd,2));
-			break;
+		break;
 
 		case 0x272a:	// Receiving of map-server via char-server a unban resquest
 			if (RFIFOREST(fd) < 6)
 				return 0;
-			{
-				uint32 acc = RFIFOL(fd,2);
-				for(i = 0; i < auth_num; i++) {
-					if (auth_dat[i].account_id == acc) {
-						if (auth_dat[i].ban_until_time != 0) {
-							auth_dat[i].ban_until_time = 0;
-							login_log("Char-server '%s': UnBan request (account: %d, ip: %s)." RETCODE,
-							          server[id].name, acc, ip);
-						} else {
-							login_log("Char-server '%s': Error of UnBan request (account: %d, no change for unban date, ip: %s)." RETCODE,
-							          server[id].name, acc, ip);
-						}
-						break;
+		{
+			uint32 acc = RFIFOL(fd,2);
+			for(i = 0; i < auth_num; i++) {
+				if (auth_dat[i].account_id == acc) {
+					if (auth_dat[i].ban_until_time != 0) {
+						auth_dat[i].ban_until_time = 0;
+						login_log("Char-server '%s': UnBan request (account: %d, ip: %s)." RETCODE,
+						          server[id].name, acc, ip);
+					} else {
+						login_log("Char-server '%s': Error of UnBan request (account: %d, no change for unban date, ip: %s)." RETCODE,
+						          server[id].name, acc, ip);
 					}
+					break;
 				}
-				if (i == auth_num)
-					login_log("Char-server '%s': Error of UnBan request (account: %d not found, ip: %s)." RETCODE,
-					          server[id].name, acc, ip);
-				RFIFOSKIP(fd,6);
 			}
+			if (i == auth_num)
+				login_log("Char-server '%s': Error of UnBan request (account: %d not found, ip: %s)." RETCODE,
+				          server[id].name, acc, ip);
+
+			RFIFOSKIP(fd,6);
 			return 0;
+		}
 
 		case 0x272b:    // Set account_id to online [Wizputer]
 			if (RFIFOREST(fd) < 6)
 				return 0;
 			add_online_user(id, RFIFOL(fd,2));
 			RFIFOSKIP(fd,6);
-			break;
+		break;
 		
 		case 0x272c:   // Set account_id to offline [Wizputer]
 			if (RFIFOREST(fd) < 6)
 				return 0;
 			remove_online_user(RFIFOL(fd,2));
 			RFIFOSKIP(fd,6);
-			break;
+		break;
 
 		case 0x272d:	// Receive list of all online accounts. [Skotlex]
 			if (RFIFOREST(fd) < 4 || RFIFOREST(fd) < RFIFOW(fd,2))
@@ -1866,36 +1878,38 @@ int parse_fromchar(int fd)
 				}
 			}
 			RFIFOSKIP(fd,RFIFOW(fd,2));
-			break;
+		break;
+
 		case 0x272e: //Request account_reg2 for a character.
 			if (RFIFOREST(fd) < 10)
 				return 0;
-			{
-				uint32 account_id = RFIFOL(fd, 2);
-				uint32 char_id = RFIFOL(fd, 6);
-				int p;
-				RFIFOSKIP(fd,10);
-				WFIFOW(fd,0) = 0x2729;
-				WFIFOL(fd,4) = account_id;
-				WFIFOL(fd,8) = char_id;
-				WFIFOB(fd,12) = 1; //Type 1 for Account2 registry
-				for(i = 0; i < auth_num && auth_dat[i].account_id != account_id; i++);
-				if (i == auth_num) {
-					//Account not found? Send at least empty data, map servers need a reply!
-					WFIFOW(fd,2) = 13;
-					WFIFOSET(fd,WFIFOW(fd,2));
-					break;
-				}
-				for(p = 13, j = 0; j < auth_dat[i].account_reg2_num; j++) {
-					if (auth_dat[i].account_reg2[j].str[0]) {
-						p+= sprintf((char*)WFIFOP(fd,p), "%s", auth_dat[i].account_reg2[j].str)+1; //We add 1 to consider the '\0' in place.
-						p+= sprintf((char*)WFIFOP(fd,p), "%s", auth_dat[i].account_reg2[j].value)+1;
-					}
-				}
-				WFIFOW(fd,2) = (uint16) p;
+		{
+			uint32 account_id = RFIFOL(fd, 2);
+			uint32 char_id = RFIFOL(fd, 6);
+			int p;
+			WFIFOW(fd,0) = 0x2729;
+			WFIFOL(fd,4) = account_id;
+			WFIFOL(fd,8) = char_id;
+			WFIFOB(fd,12) = 1; //Type 1 for Account2 registry
+			for(i = 0; i < auth_num && auth_dat[i].account_id != account_id; i++);
+			if (i == auth_num) {
+				//Account not found? Send at least empty data, map servers need a reply!
+				WFIFOW(fd,2) = 13;
 				WFIFOSET(fd,WFIFOW(fd,2));
+				break;
 			}
-			break;
+			for(p = 13, j = 0; j < auth_dat[i].account_reg2_num; j++) {
+				if (auth_dat[i].account_reg2[j].str[0]) {
+					p+= sprintf((char*)WFIFOP(fd,p), "%s", auth_dat[i].account_reg2[j].str)+1; //We add 1 to consider the '\0' in place.
+					p+= sprintf((char*)WFIFOP(fd,p), "%s", auth_dat[i].account_reg2[j].value)+1;
+				}
+			}
+			WFIFOW(fd,2) = (uint16) p;
+			WFIFOSET(fd,WFIFOW(fd,2));
+
+			RFIFOSKIP(fd,10);
+		}
+		break;
 
 		case 0x2736: // WAN IP update from char-server
 			if (RFIFOREST(fd) < 6)
@@ -1903,60 +1917,62 @@ int parse_fromchar(int fd)
 			server[id].ip = ntohl(RFIFOL(fd,2));
 			ShowInfo("Updated IP of Server #%d to %d.%d.%d.%d.\n",id, CONVIP(server[id].ip));
 			RFIFOSKIP(fd,6);
-			break;
+		break;
 
 		case 0x2737: //Request to set all offline.
 			ShowInfo("Setting accounts from char-server %d offline.\n", id);
 			online_db->foreach(online_db,online_db_setoffline,id);
 			RFIFOSKIP(fd,2);
-			break;
+		break;
 
 		default:
-			{
-				FILE *logfp;
-				char tmpstr[24];
-				time_t raw_time;
-				logfp = fopen(login_log_unknown_packets_filename, "a");
-				if (logfp) {
-					time(&raw_time);
-					strftime(tmpstr, 23, date_format, localtime(&raw_time));
-					fprintf(logfp, "%s: receiving of an unknown packet -> disconnection" RETCODE, tmpstr);
-					fprintf(logfp, "parse_fromchar: connection #%d (ip: %s), packet: 0x%x (with being read: %lu)." RETCODE, fd, ip, command, (unsigned long)RFIFOREST(fd));
-					fprintf(logfp, "Detail (in hex):" RETCODE);
-					fprintf(logfp, "---- 00-01-02-03-04-05-06-07  08-09-0A-0B-0C-0D-0E-0F" RETCODE);
-					memset(tmpstr, '\0', sizeof(tmpstr));
-					for(i = 0; i < RFIFOREST(fd); i++) {
-						if ((i & 15) == 0)
-							fprintf(logfp, "%04X ",i);
-						fprintf(logfp, "%02x ", RFIFOB(fd,i));
-						if (RFIFOB(fd,i) > 0x1f)
-							tmpstr[i % 16] = RFIFOB(fd,i);
-						else
-							tmpstr[i % 16] = '.';
-						if ((i - 7) % 16 == 0) // -8 + 1
-							fprintf(logfp, " ");
-						else if ((i + 1) % 16 == 0) {
-							fprintf(logfp, " %s" RETCODE, tmpstr);
-							memset(tmpstr, '\0', sizeof(tmpstr));
-						}
-					}
-					if (i % 16 != 0) {
-						for(j = i; j % 16 != 0; j++) {
-							fprintf(logfp, "   ");
-							if ((j - 7) % 16 == 0) // -8 + 1
-								fprintf(logfp, " ");
-						}
+		{
+			FILE* logfp;
+			char tmpstr[24];
+			time_t raw_time;
+			logfp = fopen(login_log_unknown_packets_filename, "a");
+			if (logfp) {
+				time(&raw_time);
+				strftime(tmpstr, 23, date_format, localtime(&raw_time));
+				fprintf(logfp, "%s: receiving of an unknown packet -> disconnection" RETCODE, tmpstr);
+				fprintf(logfp, "parse_fromchar: connection #%d (ip: %s), packet: 0x%x (with being read: %lu)." RETCODE, fd, ip, command, (unsigned long)RFIFOREST(fd));
+				fprintf(logfp, "Detail (in hex):" RETCODE);
+				fprintf(logfp, "---- 00-01-02-03-04-05-06-07  08-09-0A-0B-0C-0D-0E-0F" RETCODE);
+				memset(tmpstr, '\0', sizeof(tmpstr));
+				for(i = 0; i < RFIFOREST(fd); i++) {
+					if ((i & 15) == 0)
+						fprintf(logfp, "%04X ",i);
+					fprintf(logfp, "%02x ", RFIFOB(fd,i));
+					if (RFIFOB(fd,i) > 0x1f)
+						tmpstr[i % 16] = RFIFOB(fd,i);
+					else
+						tmpstr[i % 16] = '.';
+					if ((i - 7) % 16 == 0) // -8 + 1
+						fprintf(logfp, " ");
+					else if ((i + 1) % 16 == 0) {
 						fprintf(logfp, " %s" RETCODE, tmpstr);
+						memset(tmpstr, '\0', sizeof(tmpstr));
 					}
-					fprintf(logfp, RETCODE);
-					fclose(logfp);
 				}
+				if (i % 16 != 0) {
+					for(j = i; j % 16 != 0; j++) {
+						fprintf(logfp, "   ");
+						if ((j - 7) % 16 == 0) // -8 + 1
+							fprintf(logfp, " ");
+					}
+					fprintf(logfp, " %s" RETCODE, tmpstr);
+				}
+				fprintf(logfp, RETCODE);
+				fclose(logfp);
 			}
+
 			ShowError("parse_fromchar: Unknown packet 0x%x from a char-server! Disconnecting!\n", command);
 			set_eof(fd);
 			return 0;
 		}
-	}
+		} // switch
+	} // while
+
 	RFIFOSKIP(fd,RFIFOREST(fd));
 	return 0;
 }
@@ -1970,7 +1986,6 @@ int parse_admin(int fd)
 	uint32 ipl = session[fd]->client_addr;
 	char* account_name;
 	char ip[16];
-	RFIFOHEAD(fd);
 
 	ip2str(ipl, ip);
 
@@ -2411,7 +2426,7 @@ int parse_admin(int fd)
 									          auth_dat[i].userid, acc, (int)new_gm_level, ip);
 									// read and send new GM informations
 									read_gm_account();
-									send_GM_accounts();
+									send_GM_accounts(-1);
 								} else {
 									login_log("'ladmin': Attempt to modify of a GM level - impossible to write GM accounts file (account: %s (%d), received GM level: %d, ip: %s)" RETCODE,
 									          auth_dat[i].userid, acc, (int)new_gm_level, ip);
@@ -2876,7 +2891,7 @@ int parse_admin(int fd)
 			login_log("'ladmin': Request to re-load GM configuration file (ip: %s)." RETCODE, ip);
 			read_gm_account();
 			// send GM accounts to all char-servers
-			send_GM_accounts();
+			send_GM_accounts(-1);
 			RFIFOSKIP(fd,2);
 			break;
 
@@ -2926,8 +2941,6 @@ int parse_admin(int fd)
 			ShowWarning("Remote administration has been disconnected (unknown packet).\n");
 			return 0;
 		}
-		//WFIFOW(fd,0) = 0x791f;
-		//WFIFOSET(fd,2);
 	}
 	RFIFOSKIP(fd,RFIFOREST(fd));
 	return 0;
@@ -2959,17 +2972,14 @@ int parse_login(int fd)
 	unsigned int i;
 	uint32 ipl = session[fd]->client_addr;
 	char ip[16];
-	RFIFOHEAD(fd);
-
-	ip2str(ipl, ip);
-
-	memset(&account, 0, sizeof(account));
 
 	if (session[fd]->eof) {
 		do_close(fd);
 		return 0;
 	}
 
+	ip2str(ipl, ip);
+
 	while (RFIFOREST(fd) >= 2)
 	{
 		uint16 command = RFIFOW(fd,0);
@@ -2996,19 +3006,19 @@ int parse_login(int fd)
 			if (RFIFOREST(fd) < 26)
 				return 0;
 			RFIFOSKIP(fd,26);
-			break;
+		break;
 
 		case 0x0204:		// New alive packet: structure: 0x204 <encrypted.account.userid>.16B. (new ragexe from 22 june 2004)
 			if (RFIFOREST(fd) < 18)
 				return 0;
 			RFIFOSKIP(fd,18);
-			break;
+		break;
 
 		case 0x0064:		// request client login
 		case 0x0277:		// New login packet (layout is same as 0x64 but different length)
 		case 0x01dd:		// request client login (encryption mode)
 		{
-			int packet_len = RFIFOREST(fd);
+			int packet_len = RFIFOREST(fd); // assume no other packet was sent
 
 			//Perform ip-ban check
 			if (!check_ip(ipl))
@@ -3032,6 +3042,7 @@ int parse_login(int fd)
 			// S 0277 ??
 			// S 01dd <version>.l <account name>.24B <md5 binary>.16B <version2>.B
 			
+			memset(&account, 0, sizeof(account));
 			account.version = RFIFOL(fd,2);
 			if (!account.version) account.version = 1; //Force some version...
 			memcpy(account.userid,RFIFOP(fd,6),NAME_LENGTH); account.userid[23] = '\0';
@@ -3120,9 +3131,10 @@ int parse_login(int fd)
 				}
 				WFIFOSET(fd,23);
 			}
+
 			RFIFOSKIP(fd,packet_len);
-			break;
 		}
+		break;
 
 		case 0x01db:	// Sending request of the coding key
 		case 0x791a:	// Sending request of the coding key (administration packet)
@@ -3147,12 +3159,13 @@ int parse_login(int fd)
 			for(i = 0; i < ld->md5keylen; i++)
 				ld->md5key[i] = (char)(1 + rand() % 255);
 			
-			RFIFOSKIP(fd,2);
 			WFIFOHEAD(fd,4 + ld->md5keylen);
 			WFIFOW(fd,0) = 0x01dc;
 			WFIFOW(fd,2) = 4 + ld->md5keylen;
 			memcpy(WFIFOP(fd,4), ld->md5key, ld->md5keylen);
 			WFIFOSET(fd,WFIFOW(fd,2));
+
+			RFIFOSKIP(fd,2);
 		}
 		break;
 
@@ -3160,12 +3173,11 @@ int parse_login(int fd)
 			if (RFIFOREST(fd) < 86)
 				return 0;
 			{
-				uint16 len;
 				char* server_name;
 				uint32 server_ip;
 				uint16 server_port;
 
- 				WFIFOHEAD(fd,3);
+				memset(&account, 0, sizeof(account));
 				memcpy(account.userid, RFIFOP(fd,2), NAME_LENGTH); account.userid[23] = '\0'; remove_control_chars(account.userid);
 				memcpy(account.passwd, RFIFOP(fd,26), NAME_LENGTH); account.passwd[23] = '\0'; remove_control_chars(account.passwd);
 				account.passwdenc = 0;
@@ -3188,29 +3200,16 @@ int parse_login(int fd)
 					server[account.account_id].maintenance = RFIFOW(fd,82);
 					server[account.account_id].new_ = RFIFOW(fd,84);
 					server_fd[account.account_id] = fd;
+
+	 				WFIFOHEAD(fd,3);
 					WFIFOW(fd,0) = 0x2711;
 					WFIFOB(fd,2) = 0;
 					WFIFOSET(fd,3);
+
 					session[fd]->func_parse = parse_fromchar;
 					realloc_fifo(fd, FIFOSIZE_SERVERLINK, FIFOSIZE_SERVERLINK);
-
-					//TODO: why not use send_GM_accounts(fd)?
-					// send GM account to char-server
-					len = 4;
-					WFIFOW(fd,0) = 0x2732;
-					for(i = 0; i < auth_num; i++) {
-						// send only existing accounts. We can not create a GM account when server is online.
-						int GM_value;
-						if ((GM_value = isGM(auth_dat[i].account_id)) > 0) {
-							WFIFOL(fd,len) = auth_dat[i].account_id;
-							WFIFOB(fd,len+4) = (unsigned char)GM_value;
-							len += 5;
-						}
-					}
-					WFIFOW(fd,2) = len;
-					WFIFOSET(fd,len);
-					// /TODO
-
+					
+					send_GM_accounts(fd); // send GM account to char-server
 				} else {
 					if (server_fd[account.account_id] != -1) {
 						ShowNotice("Connection of the char-server '%s' REFUSED - already connected (account: %ld-%s, pass: %s, ip: %s)\n",
@@ -3228,11 +3227,11 @@ int parse_login(int fd)
 					WFIFOSET(fd,3);
 				}
 			}
+
 			RFIFOSKIP(fd,86);
 			return 0;
 
 		case 0x7530:	// Server version information request
-		{
 			login_log("Sending of the server version (ip: %s)" RETCODE, ip);
 			WFIFOHEAD(fd,10);
 			WFIFOW(fd,0) = 0x7531;
@@ -3244,9 +3243,9 @@ int parse_login(int fd)
 			WFIFOB(fd,7) = ATHENA_SERVER_LOGIN;
 			WFIFOW(fd,8) = ATHENA_MOD_VERSION;
 			WFIFOSET(fd,10);
+
 			RFIFOSKIP(fd,2);
-			break;
-		}
+		break;
 
 		case 0x7532:	// Request to end connection
 			login_log("End of connection (ip: %s)" RETCODE, ip);
@@ -3302,8 +3301,9 @@ int parse_login(int fd)
 				}
 			}
 			WFIFOSET(fd,3);
+
 			RFIFOSKIP(fd, (RFIFOW(fd,2) == 0) ? 28 : 20);
-			break;
+		break;
 
 		default:
 			if (save_unknown_packets) {
@@ -3351,6 +3351,7 @@ int parse_login(int fd)
 			return 0;
 		}
 	}
+
 	RFIFOSKIP(fd,RFIFOREST(fd));
 	return 0;
 }

+ 171 - 159
src/login_sql/login.c

@@ -225,13 +225,13 @@ void read_gm_account(void)
 }
 
 //-----------------------------------------------------
-// Send GM accounts to all char-server
+// Send GM accounts to one or all char-servers
 //-----------------------------------------------------
 void send_GM_accounts(int fd)
 {
 	unsigned int i;
-	unsigned char buf[32767];
-	int len;
+	uint8 buf[32767];
+	uint16 len;
 
 	if(!login_config.login_gm_read)
 		return;
@@ -242,7 +242,7 @@ void send_GM_accounts(int fd)
 		// send only existing accounts. We can not create a GM account when server is online.
 		if (gm_account_db[i].level > 0) {
 			WBUFL(buf,len) = gm_account_db[i].account_id;
-			WBUFB(buf,len+4) = (unsigned char)gm_account_db[i].level;
+			WBUFB(buf,len+4) = (uint8)gm_account_db[i].level;
 			len += 5;
 			if (len >= 32000) {
 				ShowWarning("send_GM_accounts: Too many accounts! Only %d out of %d were sent.\n", i, GM_num);
@@ -251,14 +251,14 @@ void send_GM_accounts(int fd)
 		}
 
 	WBUFW(buf,2) = len;
-	if (fd == -1)
+	if (fd == -1) // send to all charservers
 		charif_sendallwos(-1, buf, len);
-	else
-	{
+	else { // send only to target
 		WFIFOHEAD(fd,len);
 		memcpy(WFIFOP(fd,0), buf, len);
 		WFIFOSET(fd,len);
 	}
+
 	return;
 }
 
@@ -455,6 +455,7 @@ int mmo_auth_new(struct mmo_account* account, char sex)
 	return 0;
 }
 
+
 //--------------------------------------------------------------------
 // Packet send to all char-servers, except one (wos: without our self)
 //--------------------------------------------------------------------
@@ -465,8 +466,6 @@ int charif_sendallwos(int sfd, unsigned char *buf, unsigned int len)
 	for(i = 0, c = 0; i < MAX_SERVERS; i++) {
 		if ((fd = server_fd[i]) > 0 && fd != sfd) {
 			WFIFOHEAD(fd,len);
-			if (WFIFOSPACE(fd) < len) //Increase buffer size.
-				realloc_writefifo(fd, len);
 			memcpy(WFIFOP(fd,0), buf, len);
 			WFIFOSET(fd,len);
 			c++;
@@ -727,9 +726,6 @@ int parse_fromchar(int fd)
 
 	uint32 ipl = session[fd]->client_addr;
 	char ip[16];
-	RFIFOHEAD(fd);
-
-	ip2str(ipl, ip);
 
 	for(id = 0; id < MAX_SERVERS; id++)
 		if (server_fd[id] == fd)
@@ -740,6 +736,8 @@ int parse_fromchar(int fd)
 		return 0;
 	}
 
+	ip2str(ipl, ip);
+
 	if(session[fd]->eof) {
 		ShowStatus("Char-server '%s' has disconnected.\n", server[id].name);
 		server_fd[id] = -1;
@@ -774,14 +772,13 @@ int parse_fromchar(int fd)
 			// send GM accounts to all char-servers
 			send_GM_accounts(-1);
 			RFIFOSKIP(fd,2);
-			break;
+		break;
 
 		case 0x2712: // request from char-server to authenticate an account
 			if (RFIFOREST(fd) < 19)
 				return 0;
 		{
 			int account_id;
-			WFIFOHEAD(fd,51);
 			account_id = RFIFOL(fd,2); // speed up
 			for(i = 0; i < AUTH_FIFO_SIZE; i++) {
 				if( auth_fifo[i].account_id == account_id &&
@@ -812,6 +809,7 @@ int parse_fromchar(int fd)
 					strncpy(email, sql_row[0], 40); email[39] = 0;
 					mysql_free_result(sql_res);
 				}
+				WFIFOHEAD(fd,51);
 				WFIFOW(fd,0) = 0x2713;
 				WFIFOL(fd,2) = account_id;
 				WFIFOB(fd,6) = 0;
@@ -819,19 +817,21 @@ int parse_fromchar(int fd)
 				WFIFOL(fd,47) = (unsigned long) connect_until_time;
 				WFIFOSET(fd,51);
 			} else {
+				WFIFOHEAD(fd,51);
 				WFIFOW(fd,0) = 0x2713;
 				WFIFOL(fd,2) = account_id;
 				WFIFOB(fd,6) = 1;
 				WFIFOSET(fd,51);
 			}
-		}
+
 			RFIFOSKIP(fd,19);
-			break;
-		
+		}
+		break;
 
 		case 0x2714:
 			if (RFIFOREST(fd) < 6)
 				return 0;
+
 			// how many users on world? (update)
 			if (server[id].users != RFIFOL(fd,2))
 			{
@@ -845,13 +845,13 @@ int parse_fromchar(int fd)
 					ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmpsql);
 				}
 			}
-		{	// send some answer
+			// send some answer
 			WFIFOHEAD(fd,6);
 			WFIFOW(fd,0) = 0x2718;
 			WFIFOSET(fd,2);
-		}
+
 			RFIFOSKIP(fd,6);
-			break;
+		break;
 
 		case 0x2716: // received an e-mail/limited time request, because a player comes back from a map-server to the char-server
 			if (RFIFOREST(fd) < 6)
@@ -860,8 +860,7 @@ int parse_fromchar(int fd)
 			int account_id;
 			time_t connect_until_time = 0;
 			char email[40] = "";
-			WFIFOHEAD(fd,50);
-			account_id=RFIFOL(fd,2);
+			account_id = RFIFOL(fd,2);
 			sprintf(tmpsql,"SELECT `email`,`connect_until` FROM `%s` WHERE `%s`='%d'",login_db, login_db_account_id, account_id);
 			if(mysql_query(&mysql_handle, tmpsql)) {
 				ShowSQL("DB error - %s\n",mysql_error(&mysql_handle));
@@ -875,14 +874,16 @@ int parse_fromchar(int fd)
 			}
 			mysql_free_result(sql_res);
 			//printf("parse_fromchar: E-mail/limited time request from '%s' server (concerned account: %d)\n", server[id].name, RFIFOL(fd,2));
+			WFIFOHEAD(fd,50);
 			WFIFOW(fd,0) = 0x2717;
 			WFIFOL(fd,2) = RFIFOL(fd,2);
 			memcpy(WFIFOP(fd, 6), email, 40);
 			WFIFOL(fd,46) = (unsigned long) connect_until_time;
 			WFIFOSET(fd,50);
-		}
+
 			RFIFOSKIP(fd,6);
-			break;
+		}
+		break;
 
 		case 0x2720: // Request to become a GM (TXT only!)
 			if (RFIFOREST(fd) < 4 || RFIFOREST(fd) < RFIFOW(fd,2))
@@ -891,14 +892,13 @@ int parse_fromchar(int fd)
 			ShowWarning("change GM isn't supported in this login server version.\n");
 			ShowError("change GM error 0 %s\n", RFIFOP(fd, 8));
 
-			RFIFOSKIP(fd, RFIFOW(fd, 2));
-		{
 			WFIFOHEAD(fd,10);
 			WFIFOW(fd,0) = 0x2721;
 			WFIFOL(fd,2) = RFIFOL(fd,4); // oldacc;
 			WFIFOL(fd,6) = 0; // newacc;
 			WFIFOSET(fd,10);
-		}
+
+			RFIFOSKIP(fd, RFIFOW(fd, 2));
 			return 0;
 
 		// Map server send information to change an email of an account via char-server
@@ -944,9 +944,10 @@ int parse_fromchar(int fd)
 				}
 
 			}
+
 			RFIFOSKIP(fd, 86);
-			break;
 		}
+		break;
 
 		case 0x2724: // Receiving of map-server via char-server a status change resquest
 			if (RFIFOREST(fd) < 10)
@@ -978,9 +979,10 @@ int parse_fromchar(int fd)
 				ShowSQL("DB error - %s\n",mysql_error(&mysql_handle));
 				ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmpsql);
 			}
+
 			RFIFOSKIP(fd,10);
-			break;
 		}
+		break;
 
 		case 0x2725: // Receiving of map-server via char-server a ban resquest
 			if (RFIFOREST(fd) < 18)
@@ -1033,9 +1035,10 @@ int parse_fromchar(int fd)
 					}
 				}
 			}
+
 			RFIFOSKIP(fd,18);
-			break;
 		}
+		break;
 
 		case 0x2727: // Change of sex (sex is reversed)
 			if (RFIFOREST(fd) < 6)
@@ -1043,7 +1046,7 @@ int parse_fromchar(int fd)
 		{
 			int acc,sex;
 			unsigned char buf[16];
-			acc=RFIFOL(fd,2);
+			acc = RFIFOL(fd,2);
 			sprintf(tmpsql,"SELECT `sex` FROM `%s` WHERE `%s` = '%d'",login_db,login_db_account_id,acc);
 
 			if(mysql_query(&mysql_handle, tmpsql)) {
@@ -1076,9 +1079,10 @@ int parse_fromchar(int fd)
 			WBUFL(buf,2) = acc;
 			WBUFB(buf,6) = sex;
 			charif_sendallwos(-1, buf, 7);
+
 			RFIFOSKIP(fd,6);
-			break;
 		}
+		break;
 
 		case 0x2728:	// save account_reg2
 			if (RFIFOREST(fd) < 4 || RFIFOREST(fd) < RFIFOW(fd,2))
@@ -1090,7 +1094,7 @@ int parse_fromchar(int fd)
 				char temp_str2[512];
 				char value[256];
 				unsigned char *buf;
-				acc=RFIFOL(fd,4);
+				acc = RFIFOL(fd,4);
 				buf = (unsigned char*)aCalloc(RFIFOW(fd,2)+1, sizeof(unsigned char));
 				//Delete all global account variables....
 				sprintf(tmpsql,"DELETE FROM `%s` WHERE `type`='1' AND `account_id`='%d';",reg_db,acc);
@@ -1121,46 +1125,47 @@ int parse_fromchar(int fd)
 				if (buf) aFree(buf);
 			}
 			RFIFOSKIP(fd,RFIFOW(fd,2));
-			break;
+		break;
 
 		case 0x272a:	// Receiving of map-server via char-server a unban resquest
 			if (RFIFOREST(fd) < 6)
 				return 0;
-			{
-				int acc;
-				acc = RFIFOL(fd,2);
-				sprintf(tmpsql,"SELECT `ban_until` FROM `%s` WHERE `%s` = '%d'",login_db,login_db_account_id,acc);
+		{
+			int acc;
+			acc = RFIFOL(fd,2);
+			sprintf(tmpsql,"SELECT `ban_until` FROM `%s` WHERE `%s` = '%d'",login_db,login_db_account_id,acc);
+			if(mysql_query(&mysql_handle, tmpsql)) {
+				ShowSQL("DB error - %s\n",mysql_error(&mysql_handle));
+				ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmpsql);
+			}
+			sql_res = mysql_store_result(&mysql_handle) ;
+			if (sql_res && mysql_num_rows(sql_res) > 0) { //Found a match
+				sprintf(tmpsql,"UPDATE `%s` SET `ban_until` = '0' WHERE `%s` = '%d'", login_db,login_db_account_id,acc);
+				//query
 				if(mysql_query(&mysql_handle, tmpsql)) {
 					ShowSQL("DB error - %s\n",mysql_error(&mysql_handle));
 					ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmpsql);
 				}
-				sql_res = mysql_store_result(&mysql_handle) ;
-				if (sql_res && mysql_num_rows(sql_res) > 0) { //Found a match
-					sprintf(tmpsql,"UPDATE `%s` SET `ban_until` = '0' WHERE `%s` = '%d'", login_db,login_db_account_id,acc);
-					//query
-					if(mysql_query(&mysql_handle, tmpsql)) {
-						ShowSQL("DB error - %s\n",mysql_error(&mysql_handle));
-						ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmpsql);
-					}
-				}
-				if (sql_res) mysql_free_result(sql_res);
-				RFIFOSKIP(fd,6);
 			}
+			if (sql_res) mysql_free_result(sql_res);
+
+			RFIFOSKIP(fd,6);
 			return 0;
+		}
 
 		case 0x272b:    // Set account_id to online [Wizputer]
 			if (RFIFOREST(fd) < 6)
 				return 0;
 			add_online_user(id, RFIFOL(fd,2));
 			RFIFOSKIP(fd,6);
-			break;
+		break;
 
 		case 0x272c:   // Set account_id to offline [Wizputer]
 			if (RFIFOREST(fd) < 6)
 				return 0;
 			remove_online_user(RFIFOL(fd,2));
 			RFIFOSKIP(fd,6);
-			break;
+		break;
 
 		case 0x272d:	// Receive list of all online accounts. [Skotlex]
 			if (RFIFOREST(fd) < 4 || RFIFOREST(fd) < RFIFOW(fd,2))
@@ -1182,43 +1187,46 @@ int parse_fromchar(int fd)
 				}
 			}
 			RFIFOSKIP(fd,RFIFOW(fd,2));
-			break;
+
+		break;
 		case 0x272e: //Request account_reg2 for a character.
 			if (RFIFOREST(fd) < 10)
 				return 0;
-			{
-				int account_id = RFIFOL(fd, 2);
-				int char_id = RFIFOL(fd, 6);
-				int p;
-				WFIFOHEAD(fd,10000);
-				RFIFOSKIP(fd,10);
-				sprintf(tmpsql, "SELECT `str`,`value` FROM `%s` WHERE `type`='1' AND `account_id`='%d'",reg_db, account_id);
-				if (mysql_query(&mysql_handle, tmpsql)) {
-					ShowSQL("DB error - %s\n",mysql_error(&mysql_handle));
-					ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmpsql);
-					break;
-				}
-				sql_res = mysql_store_result(&mysql_handle) ;
-				if (!sql_res) {
-					break;
-				}
-				WFIFOW(fd,0) = 0x2729;
-				WFIFOL(fd,4) = account_id;
-				WFIFOL(fd,8) = char_id;
-				WFIFOB(fd,12) = 1; //Type 1 for Account2 registry
-				for(p = 13; (sql_row = mysql_fetch_row(sql_res)) && p < 9000;){
-					if (sql_row[0][0]) {
-						p+= sprintf(WFIFOP(fd,p), "%s", sql_row[0])+1; //We add 1 to consider the '\0' in place.
-						p+= sprintf(WFIFOP(fd,p), "%s", sql_row[1])+1;
-					}
+		{
+			int account_id = RFIFOL(fd, 2);
+			int char_id = RFIFOL(fd, 6);
+			int p;
+			sprintf(tmpsql, "SELECT `str`,`value` FROM `%s` WHERE `type`='1' AND `account_id`='%d'",reg_db, account_id);
+			if (mysql_query(&mysql_handle, tmpsql)) {
+				ShowSQL("DB error - %s\n",mysql_error(&mysql_handle));
+				ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmpsql);
+				break;
+			}
+			sql_res = mysql_store_result(&mysql_handle) ;
+			if (!sql_res) {
+				break;
+			}
+			WFIFOHEAD(fd,10000);
+			WFIFOW(fd,0) = 0x2729;
+			WFIFOL(fd,4) = account_id;
+			WFIFOL(fd,8) = char_id;
+			WFIFOB(fd,12) = 1; //Type 1 for Account2 registry
+			p = 13;
+			while ((sql_row = mysql_fetch_row(sql_res)) && p < 9000) {
+				if (sql_row[0][0]) {
+					p+= sprintf(WFIFOP(fd,p), "%s", sql_row[0])+1; //We add 1 to consider the '\0' in place.
+					p+= sprintf(WFIFOP(fd,p), "%s", sql_row[1])+1;
 				}
-				if (p >= 9000)
-					ShowWarning("Too many account2 registries for AID %d. Some registries were not sent.\n", account_id);
-				WFIFOW(fd,2) = p;
-				WFIFOSET(fd,WFIFOW(fd,2));
-				mysql_free_result(sql_res);
 			}
-			break;
+			mysql_free_result(sql_res);
+			if (p >= 9000)
+				ShowWarning("Too many account2 registries for AID %d. Some registries were not sent.\n", account_id);
+			WFIFOW(fd,2) = p;
+			WFIFOSET(fd,WFIFOW(fd,2));
+
+			RFIFOSKIP(fd,10);
+		}
+		break;
 
 		case 0x2736: // WAN IP update from char-server
 			if (RFIFOREST(fd) < 6)
@@ -1226,20 +1234,20 @@ int parse_fromchar(int fd)
 			server[id].ip = ntohl(RFIFOL(fd,2));
 			ShowInfo("Updated IP of Server #%d to %d.%d.%d.%d.\n",id, CONVIP(server[id].ip));
 			RFIFOSKIP(fd,6);
-			break;
+		break;
 
 		case 0x2737: //Request to set all offline.
 			ShowInfo("Setting accounts from char-server %d offline.\n", id);
 			online_db->foreach(online_db,online_db_setoffline,id);
 			RFIFOSKIP(fd,2);
-			break;
+		break;
 
 		default:
 			ShowError("parse_fromchar: Unknown packet 0x%x from a char-server! Disconnecting!\n", RFIFOW(fd,0));
 			set_eof(fd);
 			return 0;
-		}
-	}
+		} // switch
+	} // while
 
 	RFIFOSKIP(fd,RFIFOREST(fd));
 	return 0;
@@ -1311,12 +1319,9 @@ int parse_login(int fd)
 	int result, i;
 	uint32 ipl = session[fd]->client_addr;
 	char ip[16];
-	RFIFOHEAD(fd);
 
 	ip2str(ipl, ip);
 
-	memset(&account, 0, sizeof(account));
-
 	if (session[fd]->eof) {
 		do_close(fd);
 		return 0;
@@ -1332,13 +1337,13 @@ int parse_login(int fd)
 			if (RFIFOREST(fd) < 26)
 				return 0;
 			RFIFOSKIP(fd,26);
-			break;
+		break;
 
 		case 0x0204:		// New alive packet: structure: 0x204 <encrypted.account.userid>.16B. (new ragexe from 22 june 2004)
 			if (RFIFOREST(fd) < 18)
 				return 0;
 			RFIFOSKIP(fd,18);
-			break;
+		break;
 
 		case 0x0064:		// request client login
 		case 0x0277:		// New login packet (layout is same as 0x64 but different length)
@@ -1367,6 +1372,7 @@ int parse_login(int fd)
 			// S 0277 ??
 			// S 01dd <version>.l <account name>.24B <md5 binary>.16B <version2>.B
 
+			memset(&account, 0, sizeof(account));
 			account.version = RFIFOL(fd,2);
 			if (!account.version) account.version = 1; //Force some version...
 			memcpy(account.userid,RFIFOP(fd,6),NAME_LENGTH); account.userid[23] = '\0';
@@ -1382,7 +1388,6 @@ int parse_login(int fd)
 					WFIFOB(fd,2) = 1; // 01 = Server closed
 					WFIFOSET(fd,3);
 				} else {
-					WFIFOHEAD(fd,47+32*MAX_SERVERS);
 					if (login_config.log_login) {
 						sprintf(tmpsql,"INSERT DELAYED INTO `%s`(`time`,`ip`,`user`,`rcode`,`log`) VALUES (NOW(), '%u', '%s','100', 'login ok')", loginlog_db, ipl, t_uid);
 						//query
@@ -1397,6 +1402,7 @@ int parse_login(int fd)
 						ShowStatus("Connection of the account '%s' accepted.\n", account.userid);
 
 					server_num = 0;
+					WFIFOHEAD(fd,47+32*MAX_SERVERS);
 					for(i = 0; i < MAX_SERVERS; i++) {
 						if (server_fd[i] >= 0) {
 							// Advanced subnet check [LuzZza]
@@ -1436,7 +1442,6 @@ int parse_login(int fd)
 					}
 				}
 			} else { // auth failed
-				WFIFOHEAD(fd,23);
 				if (login_config.log_login)
 				{
 					const char* error;
@@ -1519,6 +1524,7 @@ int parse_login(int fd)
 				sql_row = sql_res?mysql_fetch_row(sql_res):NULL;
 
 				//cannot connect login failed
+				WFIFOHEAD(fd,23);
 				memset(WFIFOP(fd,0), '\0', 23);
 				WFIFOW(fd,0) = 0x6a;
 				WFIFOB(fd,2) = (uint8)result;
@@ -1532,9 +1538,10 @@ int parse_login(int fd)
 
 				if (sql_res) mysql_free_result(sql_res);
 			}
+
 			RFIFOSKIP(fd,packet_len);
-			break;
 		}
+		break;
 
 		case 0x01db:	// Sending request of the coding key
 		{
@@ -1554,87 +1561,91 @@ int parse_login(int fd)
 			for(i = 0; i < ld->md5keylen; i++)
 				ld->md5key[i] = (char)(1 + rand() % 255);
 
-			RFIFOSKIP(fd,2);
 			WFIFOHEAD(fd,4 + ld->md5keylen);
 			WFIFOW(fd,0) = 0x01dc;
 			WFIFOW(fd,2) = 4 + ld->md5keylen;
 			memcpy(WFIFOP(fd,4), ld->md5key, ld->md5keylen);
 			WFIFOSET(fd,WFIFOW(fd,2));
+
+			RFIFOSKIP(fd,2);
 		}
 		break;
 
 		case 0x2710:	// Connection request of a char-server
 			if (RFIFOREST(fd) < 86)
 				return 0;
+		{
+			char* server_name;
+			uint32 server_ip;
+			uint16 server_port;
+
+			memset(&account, 0, sizeof(account));
+			memcpy(account.userid,RFIFOP(fd,2),NAME_LENGTH); account.userid[23] = '\0';
+			memcpy(account.passwd,RFIFOP(fd,26),NAME_LENGTH); account.passwd[23] = '\0';
+			account.passwdenc = 0;
+			server_name = (char*)RFIFOP(fd,60); server_name[20] = '\0';
+			server_ip = ntohl(RFIFOL(fd,54));
+			server_port = ntohs(RFIFOW(fd,58));
+			ShowInfo("Connection request of the char-server '%s' @ %d.%d.%d.%d:%d (ip: %s)\n",
+				server_name, CONVIP(server_ip), server_port, ip);
+			jstrescapecpy(t_uid, server_name);
+			if (login_config.log_login)
 			{
-				char* server_name;
-				uint32 server_ip;
-				uint16 server_port;
-
-				WFIFOHEAD(fd,3);
-				memcpy(account.userid,RFIFOP(fd,2),NAME_LENGTH); account.userid[23] = '\0';
-				memcpy(account.passwd,RFIFOP(fd,26),NAME_LENGTH); account.passwd[23] = '\0';
-				account.passwdenc = 0;
-				server_name = (char*)RFIFOP(fd,60); server_name[20] = '\0';
-				server_ip = ntohl(RFIFOL(fd,54));
-				server_port = ntohs(RFIFOW(fd,58));
-				ShowInfo("Connection request of the char-server '%s' @ %d.%d.%d.%d:%d (ip: %s)\n",
-					server_name, CONVIP(server_ip), server_port, ip);
-				jstrescapecpy(t_uid, server_name);
-				if (login_config.log_login)
-				{
-					char t_login[50];
-					jstrescapecpy(t_login,account.userid);
-					sprintf(tmpsql,"INSERT DELAYED INTO `%s`(`time`,`ip`,`user`,`rcode`,`log`) VALUES (NOW(), '%u', '%s@%s','100', 'charserver - %s@%u.%u.%u.%u:%d')",
-						loginlog_db, ipl, t_login, t_uid, t_uid, CONVIP(server_ip), server_port);
+				char t_login[50];
+				jstrescapecpy(t_login,account.userid);
+				sprintf(tmpsql,"INSERT DELAYED INTO `%s`(`time`,`ip`,`user`,`rcode`,`log`) VALUES (NOW(), '%u', '%s@%s','100', 'charserver - %s@%u.%u.%u.%u:%d')",
+					loginlog_db, ipl, t_login, t_uid, t_uid, CONVIP(server_ip), server_port);
 
-					//query
-					if(mysql_query(&mysql_handle, tmpsql)) {
-						ShowSQL("DB error - %s\n",mysql_error(&mysql_handle));
-						ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmpsql);
-					}
+				//query
+				if(mysql_query(&mysql_handle, tmpsql)) {
+					ShowSQL("DB error - %s\n",mysql_error(&mysql_handle));
+					ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmpsql);
 				}
+			}
 
-				result = mmo_auth(&account, fd);
-				if (result == -1 && account.sex == 2 && account.account_id < MAX_SERVERS && server_fd[account.account_id] == -1) {
-					ShowStatus("Connection of the char-server '%s' accepted.\n", server_name);
-					memset(&server[account.account_id], 0, sizeof(struct mmo_char_server));
-					server[account.account_id].ip = ntohl(RFIFOL(fd,54));
-					server[account.account_id].port = ntohs(RFIFOW(fd,58));
-					memcpy(server[account.account_id].name, server_name, 20);
-					server[account.account_id].users = 0;
-					server[account.account_id].maintenance = RFIFOW(fd,82);
-					server[account.account_id].new_ = RFIFOW(fd,84);
-					server_fd[account.account_id] = fd;
-					sprintf(tmpsql,"DELETE FROM `sstatus` WHERE `index`='%d'", account.account_id);
-					//query
-					if(mysql_query(&mysql_handle, tmpsql)) {
-						ShowSQL("DB error - %s\n",mysql_error(&mysql_handle));
-						ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmpsql);
-					}
-
-					sprintf(tmpsql,"INSERT INTO `sstatus`(`index`,`name`,`user`) VALUES ( '%d', '%s', '%d')",
-						account.account_id, t_uid,0);
-					//query
-					if(mysql_query(&mysql_handle, tmpsql)) {
-						ShowSQL("DB error - %s\n",mysql_error(&mysql_handle));
-						ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmpsql);
-					}
-					WFIFOW(fd,0) = 0x2711;
-					WFIFOB(fd,2) = 0;
-					WFIFOSET(fd,3);
-					session[fd]->func_parse = parse_fromchar;
-					realloc_fifo(fd, FIFOSIZE_SERVERLINK, FIFOSIZE_SERVERLINK);
-					// send GM account to char-server
-					send_GM_accounts(fd);
-				} else {
-					WFIFOW(fd,0) = 0x2711;
-					WFIFOB(fd,2) = 3;
-					WFIFOSET(fd,3);
+			result = mmo_auth(&account, fd);
+			if (result == -1 && account.sex == 2 && account.account_id < MAX_SERVERS && server_fd[account.account_id] == -1) {
+				ShowStatus("Connection of the char-server '%s' accepted.\n", server_name);
+				memset(&server[account.account_id], 0, sizeof(struct mmo_char_server));
+				server[account.account_id].ip = ntohl(RFIFOL(fd,54));
+				server[account.account_id].port = ntohs(RFIFOW(fd,58));
+				memcpy(server[account.account_id].name, server_name, 20);
+				server[account.account_id].users = 0;
+				server[account.account_id].maintenance = RFIFOW(fd,82);
+				server[account.account_id].new_ = RFIFOW(fd,84);
+				server_fd[account.account_id] = fd;
+				sprintf(tmpsql,"DELETE FROM `sstatus` WHERE `index`='%d'", account.account_id);
+				//query
+				if(mysql_query(&mysql_handle, tmpsql)) {
+					ShowSQL("DB error - %s\n",mysql_error(&mysql_handle));
+					ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmpsql);
+				}
+				
+				sprintf(tmpsql,"INSERT INTO `sstatus`(`index`,`name`,`user`) VALUES ( '%d', '%s', '%d')",
+					account.account_id, t_uid,0);
+				//query
+				if(mysql_query(&mysql_handle, tmpsql)) {
+					ShowSQL("DB error - %s\n",mysql_error(&mysql_handle));
+					ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmpsql);
 				}
+				WFIFOHEAD(fd,3);
+				WFIFOW(fd,0) = 0x2711;
+				WFIFOB(fd,2) = 0;
+				WFIFOSET(fd,3);
+				session[fd]->func_parse = parse_fromchar;
+				realloc_fifo(fd, FIFOSIZE_SERVERLINK, FIFOSIZE_SERVERLINK);
+				
+				send_GM_accounts(fd); // send GM account to char-server
+			} else {
+				WFIFOHEAD(fd,3);
+				WFIFOW(fd,0) = 0x2711;
+				WFIFOB(fd,2) = 3;
+				WFIFOSET(fd,3);
 			}
+
 			RFIFOSKIP(fd,86);
 			return 0;
+		}
 
 		case 0x7530:	// Server version information request
 		{
@@ -1649,14 +1660,15 @@ int parse_login(int fd)
 			WFIFOB(fd,7) = ATHENA_SERVER_LOGIN;
 			WFIFOW(fd,8) = ATHENA_MOD_VERSION;
 			WFIFOSET(fd,10);
+
 			RFIFOSKIP(fd,2);
-			break;
 		}
+		break;
 
 		case 0x7532:	// Request to end connection
 			ShowStatus ("End of connection (ip: %s)" RETCODE, ip);
 			set_eof(fd);
-			break;
+		break;
 
 		default:
 			ShowStatus ("Abnormal end of connection (ip: %s): Unknown packet 0x%x " RETCODE, ip, RFIFOW(fd,0));

+ 0 - 6
src/login_sql/login.h

@@ -13,12 +13,6 @@
 // supported encryption types: 1- passwordencrypt, 2- passwordencrypt2, 3- both
 #define PASSWORDENC 3
 
-#ifndef SQL_DEBUG
-	#define mysql_query(_x, _y) mysql_query(_x, _y)
-#else 
-	#define mysql_query(_x, _y) debug_mysql_query(__FILE__, __LINE__, _x, _y)
-#endif
-
 struct mmo_account {
 	int version;
 	char userid[NAME_LENGTH];

+ 29 - 46
src/map/chrif.c

@@ -207,7 +207,7 @@ int chrif_save(struct map_session_data *sd, int flag)
 int chrif_connect(int fd)
 {
 	ShowStatus("Logging in to char server...\n", char_fd);
-	WFIFOHEAD(fd, 60);
+	WFIFOHEAD(fd,60);
 	WFIFOW(fd,0) = 0x2af8;
 	memcpy(WFIFOP(fd,2), userid, NAME_LENGTH);
 	memcpy(WFIFOP(fd,26), passwd, NAME_LENGTH);
@@ -240,7 +240,6 @@ int chrif_recvmap(int fd)
 	int i, j;
 	uint32 ip;
 	uint16 port;
-	RFIFOHEAD(fd);
 	ip = ntohl(RFIFOL(fd,4));
 	port = ntohs(RFIFOW(fd,8));
 	for(i = 10, j = 0; i < RFIFOW(fd,2); i += 4, j++) {
@@ -259,7 +258,6 @@ int chrif_removemap(int fd)
 	int i, j;
 	uint32 ip;
 	uint16 port;
-	RFIFOHEAD(fd);
 
 	ip = RFIFOL(fd, 4);
 	port = RFIFOW(fd, 8);
@@ -278,7 +276,6 @@ int chrif_removemap(int fd)
 int chrif_save_ack(int fd)
 {
 	struct map_session_data *sd;
-	RFIFOHEAD(fd);
 	sd = map_id2sd(RFIFOL(fd,2));
 
 	if (sd && sd->status.char_id == RFIFOL(fd,6))
@@ -306,7 +303,7 @@ int chrif_changemapserver(struct map_session_data *sd, short map, int x, int y,
 	else //Not connected? Can't retrieve IP
 		s_ip = 0;
 
-	WFIFOHEAD(char_fd, 35);
+	WFIFOHEAD(char_fd,35);
 	WFIFOW(char_fd, 0) = 0x2b05;
 	WFIFOL(char_fd, 2) = sd->bl.id;
 	WFIFOL(char_fd, 6) = sd->login_id1;
@@ -329,7 +326,6 @@ int chrif_changemapserverack(int fd)
 {
 	struct map_session_data *sd;
 	char mapname[MAP_NAME_LENGTH_EXT];
-	RFIFOHEAD(fd);
 	sd = map_id2sd(RFIFOL(fd,2));
 
 	if (sd == NULL || sd->status.char_id != RFIFOL(fd,14))
@@ -355,7 +351,6 @@ int chrif_changemapserverack(int fd)
  *------------------------------------------*/
 int chrif_connectack(int fd)
 {
-	RFIFOHEAD(fd);
 	if (RFIFOB(fd,2)) {
 		ShowFatalError("Connection to char-server failed %d.\n", RFIFOB(fd,2));
 		exit(1);
@@ -381,7 +376,6 @@ int chrif_connectack(int fd)
  *------------------------------------------*/
 int chrif_sendmapack(int fd)
 {
-	RFIFOHEAD(fd);
 	if (RFIFOB(fd,2)) {
 		ShowFatalError("chrif : send map list to char server failed %d\n", RFIFOB(fd,2));
 		exit(1);
@@ -408,10 +402,10 @@ int chrif_scdata_request(int account_id, int char_id)
 #ifdef ENABLE_SC_SAVING
 	chrif_check(-1);
 
-	WFIFOHEAD(char_fd, 10);
-	WFIFOW(char_fd, 0) = 0x2afc;
-	WFIFOL(char_fd, 2) = account_id;
-	WFIFOL(char_fd, 6) = char_id;
+	WFIFOHEAD(char_fd,10);
+	WFIFOW(char_fd,0) = 0x2afc;
+	WFIFOL(char_fd,2) = account_id;
+	WFIFOL(char_fd,6) = char_id;
 	WFIFOSET(char_fd,10);
 #endif
 	return 0;
@@ -455,7 +449,6 @@ void chrif_authok(int fd)
 {
 	struct auth_node *auth_data;
 	TBL_PC* sd;
-	RFIFOHEAD(fd);
 	//Check if we don't already have player data in our server
 	//(prevents data that is to be saved from being overwritten by
 	//this received status data if this auth is later successful) [Skotlex]
@@ -535,7 +528,7 @@ int chrif_charselectreq(struct map_session_data* sd, uint32 s_ip)
 		return -1;
 	chrif_check(-1);
 
-	WFIFOHEAD(char_fd, 18);
+	WFIFOHEAD(char_fd,18);
 	WFIFOW(char_fd, 0) = 0x2b02;
 	WFIFOL(char_fd, 2) = sd->bl.id;
 	WFIFOL(char_fd, 6) = sd->login_id1;
@@ -555,7 +548,7 @@ int chrif_searchcharid(int char_id)
 		return -1;
 	chrif_check(-1);
 
-	WFIFOHEAD(char_fd, 6);
+	WFIFOHEAD(char_fd,6);
 	WFIFOW(char_fd,0) = 0x2b08;
 	WFIFOL(char_fd,2) = char_id;
 	WFIFOSET(char_fd,6);
@@ -593,7 +586,7 @@ int chrif_changeemail(int id, const char *actual_email, const char *new_email)
 
 	chrif_check(-1);
 
-        WFIFOHEAD(char_fd, 86);
+	WFIFOHEAD(char_fd,86);
 	WFIFOW(char_fd,0) = 0x2b0c;
 	WFIFOL(char_fd,2) = id;
 	memcpy(WFIFOP(char_fd,6), actual_email, 40);
@@ -643,7 +636,7 @@ int chrif_changesex(int id, int sex)
 {
 	chrif_check(-1);
 
-        WFIFOHEAD(char_fd, 9);
+	WFIFOHEAD(char_fd,9);
 	WFIFOW(char_fd,0) = 0x2b11;
 	WFIFOW(char_fd,2) = 9;
 	WFIFOL(char_fd,4) = id;
@@ -673,7 +666,6 @@ int chrif_char_ask_name_answer(int fd)
 	struct map_session_data *sd;
 	char output[256];
 	char player_name[NAME_LENGTH];
-	RFIFOHEAD(fd);
 
 	acc = RFIFOL(fd,2); // account_id of who has asked (-1 if nobody)
 	memcpy(player_name, RFIFOP(fd,6), NAME_LENGTH-1);
@@ -774,7 +766,6 @@ int chrif_changedgm(int fd)
 {
 	int acc, level;
 	struct map_session_data *sd = NULL;
-	RFIFOHEAD(fd);
 
 	acc = RFIFOL(fd,2);
 	level = RFIFOL(fd,6);
@@ -800,7 +791,6 @@ int chrif_changedsex(int fd)
 {
 	int acc, sex, i;
 	struct map_session_data *sd;
-	RFIFOHEAD(fd);
 
 	acc = RFIFOL(fd,2);
 	sex = RFIFOL(fd,6);
@@ -896,7 +886,6 @@ int chrif_accountdeletion(int fd)
 {
 	int acc;
 	struct map_session_data *sd;
-	RFIFOHEAD(fd);
 
 	acc = RFIFOL(fd,2);
 	if (battle_config.etc_log)
@@ -923,7 +912,6 @@ int chrif_accountban(int fd)
 {
 	int acc;
 	struct map_session_data *sd;
-	RFIFOHEAD(fd);
 
 	acc = RFIFOL(fd,2);
 	if (battle_config.etc_log)
@@ -991,7 +979,6 @@ int chrif_accountban(int fd)
 int chrif_disconnectplayer(int fd)
 {
 	struct map_session_data *sd;
-	RFIFOHEAD(fd);
 
 	sd = map_id2sd(RFIFOL(fd, 2));
 
@@ -1040,9 +1027,9 @@ int chrif_reloadGMdb(void)
 {
 	chrif_check(-1);
 
-	WFIFOHEAD(char_fd, 2);
+	WFIFOHEAD(char_fd,2);
 	WFIFOW(char_fd,0) = 0x2af7;
-	WFIFOSET(char_fd, 2);
+	WFIFOSET(char_fd,2);
 
 	return 0;
 }
@@ -1080,12 +1067,12 @@ int chrif_updatefamelist(struct map_session_data *sd)
 	}
 
 	WFIFOHEAD(char_fd, 12);
-	WFIFOW(char_fd, 0) = 0x2b10;
-	WFIFOL(char_fd, 2) = sd->status.char_id;
-	WFIFOL(char_fd, 6) = sd->status.fame;
-	WFIFOB(char_fd, 10) = type;
-	WFIFOB(char_fd, 11) = pc_famerank(sd->status.char_id, sd->class_&MAPID_UPPERMASK);
-	WFIFOSET(char_fd, 12);
+	WFIFOW(char_fd,0) = 0x2b10;
+	WFIFOL(char_fd,2) = sd->status.char_id;
+	WFIFOL(char_fd,6) = sd->status.fame;
+	WFIFOB(char_fd,10) = type;
+	WFIFOB(char_fd,11) = pc_famerank(sd->status.char_id, sd->class_&MAPID_UPPERMASK);
+	WFIFOSET(char_fd,12);
 
 	return 0;
 }
@@ -1094,9 +1081,9 @@ int chrif_buildfamelist(void)
 {
 	chrif_check(-1);
 
-	WFIFOHEAD(char_fd, 2);
-	WFIFOW(char_fd, 0) = 0x2b1a;
-	WFIFOSET(char_fd, 2);
+	WFIFOHEAD(char_fd,2);
+	WFIFOW(char_fd,0) = 0x2b1a;
+	WFIFOSET(char_fd,2);
 
 	return 0;
 }
@@ -1105,7 +1092,6 @@ int chrif_recvfamelist(int fd)
 {
 	int num, size;
 	int total = 0, len = 8;
-	RFIFOHEAD(fd);
 
 	memset (smith_fame_list, 0, sizeof(smith_fame_list));
 	memset (chemist_fame_list, 0, sizeof(chemist_fame_list));
@@ -1141,7 +1127,6 @@ int chrif_updatefamelist_ack(int fd)
 {
 	struct fame_list *list;
 	char index;
-	RFIFOHEAD(fd);
 	switch (RFIFOB(fd, 2))
 	{
 		case 1:
@@ -1213,7 +1198,6 @@ int chrif_load_scdata(int fd)
 	struct map_session_data *sd;
 	struct status_change_data *data;
 	int aid, cid, i, count;
-	RFIFOHEAD(fd);
 
 	aid = RFIFOL(fd,4); //Player Account ID
 	cid = RFIFOL(fd,8); //Player Char ID
@@ -1290,7 +1274,7 @@ int chrif_char_offline(struct map_session_data *sd)
 {
 	chrif_check(-1);
 
-	WFIFOHEAD(char_fd, 10);
+	WFIFOHEAD(char_fd,10);
 	WFIFOW(char_fd,0) = 0x2b17;
 	WFIFOL(char_fd,2) = sd->status.char_id;
 	WFIFOL(char_fd,6) = sd->status.account_id;
@@ -1320,7 +1304,7 @@ int chrif_char_reset_offline(void)
 {
 	chrif_check(-1);
 
-	WFIFOHEAD(char_fd, 2);
+	WFIFOHEAD(char_fd,2);
 	WFIFOW(char_fd,0) = 0x2b18;
 	WFIFOSET(char_fd,2);
 
@@ -1335,7 +1319,7 @@ int chrif_char_online(struct map_session_data *sd)
 {
 	chrif_check(-1);
 
-        WFIFOHEAD(char_fd, 10);
+	WFIFOHEAD(char_fd,10);
 	WFIFOW(char_fd,0) = 0x2b19;
 	WFIFOL(char_fd,2) = sd->status.char_id;
 	WFIFOL(char_fd,6) = sd->status.account_id;
@@ -1363,16 +1347,16 @@ int chrif_disconnect(int fd)
 void chrif_update_ip(int fd)
 {
 	uint32 new_ip;
-	WFIFOHEAD(fd, 6);
+	WFIFOHEAD(fd,6);
 	new_ip = host2ip(char_ip_str);
 	if (new_ip && new_ip != char_ip)
 		char_ip = new_ip; //Update char_ip
 
 	new_ip = clif_refresh_ip();
 	if (!new_ip) return; //No change
-	WFIFOW(fd, 0) = 0x2736;
-	WFIFOL(fd, 2) = htonl(new_ip);
-	WFIFOSET(fd, 6);
+	WFIFOW(fd,0) = 0x2736;
+	WFIFOL(fd,2) = htonl(new_ip);
+	WFIFOSET(fd,6);
 }
 
 /*==========================================
@@ -1395,7 +1379,6 @@ int chrif_parse(int fd)
 	}
 
 	while (RFIFOREST(fd) >= 2) { //Infinite loop on broken pipe fix. [Skotlex]
-		RFIFOHEAD(fd);
 		cmd = RFIFOW(fd,0);
 		if (cmd < 0x2af8 || cmd >= 0x2af8 + (sizeof(packet_len_table) / sizeof(packet_len_table[0])) ||
 		    packet_len_table[cmd-0x2af8] == 0) {
@@ -1469,7 +1452,7 @@ int send_usercount_tochar(int tid, unsigned int tick, int id, int data)
 		return 0;
 	last_count = count;
 
-	WFIFOHEAD(char_fd, 4);
+	WFIFOHEAD(char_fd,4);
 	WFIFOW(char_fd,0) = 0x2afe;
 	WFIFOW(char_fd,2) = count;
 	WFIFOSET(char_fd,4);

Файловите разлики са ограничени, защото са твърде много
+ 46 - 170
src/map/clif.c


+ 4 - 51
src/map/intif.c

@@ -413,7 +413,6 @@ int intif_party_addmember(int party_id,struct party_member *member)
 {
 	if (CheckForCharServer())
 		return 0;
-
 	WFIFOHEAD(inter_fd,42);
 	WFIFOW(inter_fd,0)=0x3022;
 	WFIFOW(inter_fd,2)=8+sizeof(struct party_member);
@@ -849,7 +848,7 @@ int intif_parse_WisMessage(int fd)
 	char *wisp_source;
 	char name[NAME_LENGTH];
 	int id, i;
-	RFIFOHEAD(fd);
+
 	id=RFIFOL(fd,4);
 
 	memcpy(name, RFIFOP(fd,32), NAME_LENGTH);
@@ -885,7 +884,6 @@ int intif_parse_WisMessage(int fd)
 int intif_parse_WisEnd(int fd)
 {
 	struct map_session_data* sd;
-	RFIFOHEAD(fd);
 
 	if (battle_config.etc_log)
 		ShowInfo("intif_parse_wisend: player: %s, flag: %d\n", RFIFOP(fd,2), RFIFOB(fd,26)); // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target
@@ -918,7 +916,6 @@ int mapif_parse_WisToGM(int fd)
 	char Wisp_name[NAME_LENGTH];
 	char mbuf[255];
 	char *message;
-	RFIFOHEAD(fd);
 
 	mes_len =  RFIFOW(fd,2) - 30;
 	message = (char *) (mes_len >= 255 ? (char *) aMallocA(mes_len) : mbuf);
@@ -943,7 +940,6 @@ int intif_parse_Registers(int fd)
 	struct map_session_data *sd;
 	struct global_reg *reg;
 	int *qty;
-	RFIFOHEAD(fd);
 
 	if( (sd=map_id2sd(RFIFOL(fd,4)))==NULL)
 		return 1;
@@ -994,7 +990,6 @@ int intif_parse_LoadStorage(int fd)
 {
 	struct storage *stor;
 	struct map_session_data *sd;
-	RFIFOHEAD(fd);
 
 	sd=map_id2sd( RFIFOL(fd,4) );
 	if(sd==NULL){
@@ -1038,7 +1033,6 @@ int intif_parse_LoadStorage(int fd)
 // 倉庫データ送信成功
 int intif_parse_SaveStorage(int fd)
 {
-	RFIFOHEAD(fd);
 	if(battle_config.save_log)
 		ShowInfo("intif_savestorage: done %d %d\n",RFIFOL(fd,2),RFIFOB(fd,6) );
 	storage_storage_saved(RFIFOL(fd,2));
@@ -1050,7 +1044,7 @@ int intif_parse_LoadGuildStorage(int fd)
 	struct guild_storage *gstor;
 	struct map_session_data *sd;
 	int guild_id;
-	RFIFOHEAD(fd);
+	
 	guild_id = RFIFOL(fd,8);
 	if(guild_id <= 0)
 		return 1;
@@ -1093,7 +1087,6 @@ int intif_parse_LoadGuildStorage(int fd)
 }
 int intif_parse_SaveGuildStorage(int fd)
 {
-	RFIFOHEAD(fd);
 	if(battle_config.save_log) {
 		ShowInfo("intif_save_guild_storage: done %d %d %d\n",RFIFOL(fd,2),RFIFOL(fd,6),RFIFOB(fd,10) );
 	}
@@ -1104,7 +1097,6 @@ int intif_parse_SaveGuildStorage(int fd)
 // パーティ作成可否
 int intif_parse_PartyCreated(int fd)
 {
-	RFIFOHEAD(fd);
 	if(battle_config.etc_log)
 		ShowInfo("intif: party created by account %d\n\n", RFIFOL(fd,2));
 	party_created(RFIFOL(fd,2), RFIFOL(fd,6),RFIFOB(fd,10),RFIFOL(fd,11), (char *)RFIFOP(fd,15));
@@ -1113,7 +1105,6 @@ int intif_parse_PartyCreated(int fd)
 // パーティ情報
 int intif_parse_PartyInfo(int fd)
 {
-	RFIFOHEAD(fd);
 	if( RFIFOW(fd,2)==8){
 		if(battle_config.error_log)
 			ShowWarning("intif: party noinfo %d\n",RFIFOL(fd,4));
@@ -1132,7 +1123,6 @@ int intif_parse_PartyInfo(int fd)
 // パーティ追加通知
 int intif_parse_PartyMemberAdded(int fd)
 {
-	RFIFOHEAD(fd);
 	if(battle_config.etc_log)
 		ShowInfo("intif: party member added Party (%d), Account(%d), Char(%d)\n",RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10));
 	party_member_added(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10), RFIFOB(fd, 14));
@@ -1141,14 +1131,12 @@ int intif_parse_PartyMemberAdded(int fd)
 // パーティ設定変更通知
 int intif_parse_PartyOptionChanged(int fd)
 {
-	RFIFOHEAD(fd);
 	party_optionchanged(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOW(fd,10),RFIFOW(fd,12),RFIFOB(fd,14));
 	return 0;
 }
 // パーティ脱退通知
 int intif_parse_PartyMemberLeaved(int fd)
 {
-	RFIFOHEAD(fd);
 	if(battle_config.etc_log)
 		ShowInfo("intif: party member leaved: Party(%d), Account(%d), Char(%d)\n",RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10));
 	party_member_leaved(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10));
@@ -1157,23 +1145,18 @@ int intif_parse_PartyMemberLeaved(int fd)
 // パーティ解散通知
 int intif_parse_PartyBroken(int fd)
 {
-	RFIFOHEAD(fd);
 	party_broken(RFIFOL(fd,2));
 	return 0;
 }
 // パーティ移動通知
 int intif_parse_PartyMove(int fd)
 {
-	RFIFOHEAD(fd);
 	party_recv_movemap(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),RFIFOW(fd,14),RFIFOB(fd,16),RFIFOW(fd,17));
 	return 0;
 }
 // パーティメッセージ
 int intif_parse_PartyMessage(int fd)
 {
-	RFIFOHEAD(fd);
-//	if(battle_config.etc_log)
-//		printf("intif_parse_PartyMessage: %s\n",RFIFOP(fd,12));
 	party_recv_message(RFIFOL(fd,4),RFIFOL(fd,8),(char *) RFIFOP(fd,12),RFIFOW(fd,2)-12);
 	return 0;
 }
@@ -1181,15 +1164,13 @@ int intif_parse_PartyMessage(int fd)
 // ギルド作成可否
 int intif_parse_GuildCreated(int fd)
 {
-	RFIFOHEAD(fd);
 	guild_created(RFIFOL(fd,2),RFIFOL(fd,6));
 	return 0;
 }
 // ギルド情報
 int intif_parse_GuildInfo(int fd)
 {
-	RFIFOHEAD(fd);
-	if( RFIFOW(fd,2)==8){
+	if(RFIFOW(fd,2) == 8) {
 		if(battle_config.error_log)
 			ShowWarning("intif: guild noinfo %d\n",RFIFOL(fd,4));
 		guild_recv_noinfo(RFIFOL(fd,4));
@@ -1208,7 +1189,6 @@ int intif_parse_GuildInfo(int fd)
 // ギルドメンバ追加通知
 int intif_parse_GuildMemberAdded(int fd)
 {
-	RFIFOHEAD(fd);
 	if(battle_config.etc_log)
 		ShowInfo("intif: guild member added %d %d %d %d\n",RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),RFIFOB(fd,14));
 	guild_member_added(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),RFIFOB(fd,14));
@@ -1217,23 +1197,19 @@ int intif_parse_GuildMemberAdded(int fd)
 // ギルドメンバ脱退/追放通知
 int intif_parse_GuildMemberLeaved(int fd)
 {
-	RFIFOHEAD(fd);
-	guild_member_leaved(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),RFIFOB(fd,14),
-		(char *) RFIFOP(fd,55), (char *) RFIFOP(fd,15));
+	guild_member_leaved(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),RFIFOB(fd,14),(char *)RFIFOP(fd,55),(char *)RFIFOP(fd,15));
 	return 0;
 }
 
 // ギルドメンバオンライン状態/Lv変更通知
 int intif_parse_GuildMemberInfoShort(int fd)
 {
-	RFIFOHEAD(fd);
 	guild_recv_memberinfoshort(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),RFIFOB(fd,14),RFIFOW(fd,15),RFIFOW(fd,17));
 	return 0;
 }
 // ギルド解散通知
 int intif_parse_GuildBroken(int fd)
 {
-	RFIFOHEAD(fd);
 	guild_broken(RFIFOL(fd,2),RFIFOB(fd,6));
 	return 0;
 }
@@ -1246,7 +1222,6 @@ int intif_parse_GuildBasicInfoChanged(int fd)
 	void *data;
 	struct guild *g;
 	short dw;
-	RFIFOHEAD(fd);
 	type=RFIFOW(fd,8);
 	guild_id=RFIFOL(fd,4);
 	data=RFIFOP(fd,10);
@@ -1268,7 +1243,6 @@ int intif_parse_GuildMemberInfoChanged(int fd)
 	int type, guild_id, account_id, char_id, idx, dd;
 	void* data;
 	struct guild *g;
-	RFIFOHEAD(fd);
 	type=RFIFOW(fd,16);
 	guild_id=RFIFOL(fd,4);
 	account_id=RFIFOL(fd,8);
@@ -1311,7 +1285,6 @@ int intif_parse_GuildMemberInfoChanged(int fd)
 // ギルド役職変更通知
 int intif_parse_GuildPosition(int fd)
 {
-	RFIFOHEAD(fd);
 	if( RFIFOW(fd,2)!=sizeof(struct guild_position)+12 ){
 		if(battle_config.error_log)
 			ShowError("intif: guild info : data size error\n %d %d %d",RFIFOL(fd,4),RFIFOW(fd,2),sizeof(struct guild_position)+12);
@@ -1322,14 +1295,12 @@ int intif_parse_GuildPosition(int fd)
 // ギルドスキル割り振り通知
 int intif_parse_GuildSkillUp(int fd)
 {
-	RFIFOHEAD(fd);
 	guild_skillupack(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10));
 	return 0;
 }
 // ギルド同盟/敵対通知
 int intif_parse_GuildAlliance(int fd)
 {
-	RFIFOHEAD(fd);
 	guild_allianceack(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),RFIFOL(fd,14),
 		RFIFOB(fd,18),(char *) RFIFOP(fd,19),(char *) RFIFOP(fd,43));
 	return 0;
@@ -1337,56 +1308,47 @@ int intif_parse_GuildAlliance(int fd)
 // ギルド告知変更通知
 int intif_parse_GuildNotice(int fd)
 {
-	RFIFOHEAD(fd);
 	guild_notice_changed(RFIFOL(fd,2),(char *) RFIFOP(fd,6),(char *) RFIFOP(fd,66));
 	return 0;
 }
 // ギルドエンブレム変更通知
 int intif_parse_GuildEmblem(int fd)
 {
-	RFIFOHEAD(fd);
 	guild_emblem_changed(RFIFOW(fd,2)-12,RFIFOL(fd,4),RFIFOL(fd,8), (char *)RFIFOP(fd,12));
 	return 0;
 }
 // ギルド会話受信
 int intif_parse_GuildMessage(int fd)
 {
-	RFIFOHEAD(fd);
 	guild_recv_message(RFIFOL(fd,4),RFIFOL(fd,8),(char *) RFIFOP(fd,12),RFIFOW(fd,2)-12);
 	return 0;
 }
 // ギルド城データ要求返信
 int intif_parse_GuildCastleDataLoad(int fd)
 {
-	RFIFOHEAD(fd);
 	return guild_castledataloadack(RFIFOW(fd,2),RFIFOB(fd,4),RFIFOL(fd,5));
 }
 // ギルド城データ変更通知
 int intif_parse_GuildCastleDataSave(int fd)
 {
-	RFIFOHEAD(fd);
 	return guild_castledatasaveack(RFIFOW(fd,2),RFIFOB(fd,4),RFIFOL(fd,5));
 }
 
 // ギルド城データ一括受信(初期化時)
 int intif_parse_GuildCastleAllDataLoad(int fd)
 {
-	RFIFOHEAD(fd);
 	return guild_castlealldataload(RFIFOW(fd,2),(struct guild_castle *)RFIFOP(fd,4));
 }
 
 int intif_parse_GuildMasterChanged(int fd)
 {
-	RFIFOHEAD(fd);
 	return guild_gm_changed(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10));
 }
 
 // pet
 int intif_parse_CreatePet(int fd)
 {
-	RFIFOHEAD(fd);
 	pet_get_egg(RFIFOL(fd,2),RFIFOL(fd,7),RFIFOB(fd,6));
-
 	return 0;
 }
 
@@ -1394,7 +1356,6 @@ int intif_parse_RecvPetData(int fd)
 {
 	struct s_pet p;
 	int len;
-	RFIFOHEAD(fd);
 	len=RFIFOW(fd,2);
 	if(sizeof(struct s_pet)!=len-9) {
 		if(battle_config.etc_log)
@@ -1409,7 +1370,6 @@ int intif_parse_RecvPetData(int fd)
 }
 int intif_parse_SavePetOk(int fd)
 {
-	RFIFOHEAD(fd);
 	if(RFIFOB(fd,6) == 1) {
 		if(battle_config.error_log)
 			ShowError("pet data save failure\n");
@@ -1420,7 +1380,6 @@ int intif_parse_SavePetOk(int fd)
 
 int intif_parse_DeletePetOk(int fd)
 {
-	RFIFOHEAD(fd);
 	if(RFIFOB(fd,2) == 1) {
 		if(battle_config.error_log)
 			ShowError("pet data delete failure\n");
@@ -1432,7 +1391,6 @@ int intif_parse_DeletePetOk(int fd)
 int intif_parse_ChangeNameOk(int fd)
 {
 	struct map_session_data *sd = NULL;
-	RFIFOHEAD(fd);
 	if((sd=map_id2sd(RFIFOL(fd,2)))==NULL ||
 		sd->status.char_id != RFIFOL(fd,6))
 		return 0;
@@ -1456,7 +1414,6 @@ int intif_parse_ChangeNameOk(int fd)
 int intif_parse_CreateHomunculus(int fd)
 {
 	int len;
-	RFIFOHEAD(fd);
 	len=RFIFOW(fd,2)-9;
 	if(sizeof(struct s_homunculus)!=len) {
 		if(battle_config.etc_log)
@@ -1471,7 +1428,6 @@ int intif_parse_RecvHomunculusData(int fd)
 {
 	int len;
 
-	RFIFOHEAD(fd);
 	len=RFIFOW(fd,2)-9;
 
 	if(sizeof(struct s_homunculus)!=len) {
@@ -1485,7 +1441,6 @@ int intif_parse_RecvHomunculusData(int fd)
 
 int intif_parse_SaveHomunculusOk(int fd)
 {
-	RFIFOHEAD(fd);
 	if(RFIFOB(fd,6) != 1) {
 		if(battle_config.error_log)
 			ShowError("homunculus data save failure for account %d\n", RFIFOL(fd,2));
@@ -1495,7 +1450,6 @@ int intif_parse_SaveHomunculusOk(int fd)
 
 int intif_parse_DeleteHomunculusOk(int fd)
 {
-	RFIFOHEAD(fd);
 	if(RFIFOB(fd,2) != 1) {
 		if(battle_config.error_log)
 			ShowError("Homunculus data delete failure\n");
@@ -1510,7 +1464,6 @@ int intif_parse_DeleteHomunculusOk(int fd)
 int intif_parse(int fd)
 {
 	int packet_len, cmd;
-	RFIFOHEAD(fd);
 	cmd = RFIFOW(fd,0);
 	// パケットのID確認
 	if(cmd<0x3800 || cmd>=0x3800+(sizeof(packet_len_table)/sizeof(packet_len_table[0])) ||

+ 0 - 1
src/map/irc.c

@@ -147,7 +147,6 @@ int irc_parse(int fd)
 	}
 	if(RFIFOREST(fd) > 0){
 		char *incoming_string=aMalloc(RFIFOREST(fd)*sizeof(char));
-		RFIFOHEAD(fd);
 		memcpy(incoming_string,RFIFOP(fd,0),RFIFOREST(fd));
 		send_to_parser(fd,incoming_string,"\n");
 		RFIFOSKIP(fd,RFIFOREST(fd));

+ 0 - 6
src/map/log.c

@@ -14,12 +14,6 @@
 #include "log.h"
 #include "battle.h"
 
-#ifndef SQL_DEBUG
-	#define mysql_query(_x, _y) mysql_real_query(_x, _y, strlen(_y)) //supports ' in names and runs faster [Kevin]
-#else 
-	#define mysql_query(_x, _y) debug_mysql_query(__FILE__, __LINE__, _x, _y)
-#endif
-
 struct Log_Config log_config;
 
 char timestring[255];

+ 0 - 12
src/map/mail.c

@@ -24,18 +24,6 @@
 #include "pc.h"
 #include "mail.h"
 
-#ifndef TXT_ONLY
-	#ifndef SQL_DEBUG
-
-		#define mysql_query(_x, _y) mysql_real_query(_x, _y, strlen(_y))
-
-	#else 
-
-		#define mysql_query(_x, _y) debug_mysql_query(__FILE__, __LINE__, _x, _y)
-
-	#endif
-#endif
-
 int MAIL_CHECK_TIME = 120000;
 int mail_timer;
 //extern char *msg_table[1000]; // Server messages (0-499 reserved for GM commands, 500-999 reserved for others)

+ 1 - 3
src/map/map.c

@@ -179,11 +179,9 @@ int enable_grf = 0;	//To enable/disable reading maps from GRF files, bypassing m
  *------------------------------------------*/
 void map_setusers(int fd)
 {
-	RFIFOHEAD(fd);
-	WFIFOHEAD(fd, 2);
-
 	map_users = RFIFOL(fd,2);
 	// send some answer
+	WFIFOHEAD(fd, 2);
 	WFIFOW(fd,0) = 0x2718;
 	WFIFOSET(fd,2);
 }

+ 0 - 1
src/map/pc.c

@@ -7012,7 +7012,6 @@ int pc_autosave(int tid,unsigned int tick,int id,int data)
 int pc_read_gm_account(int fd)
 {
 	int i = 0;
-	RFIFOHEAD(fd);
 	if (gm_account != NULL)
 		aFree(gm_account);
 	GM_num = 0;

Някои файлове не бяха показани, защото твърде много файлове са промени