Ver Fonte

Cleaning few thing while bored in class...

-TODO harmonize while(next) packet parsing
lighta há 11 anos atrás
pai
commit
06f8917d75
9 ficheiros alterados com 804 adições e 1474 exclusões
  1. 1 1
      src/char/Makefile.in
  2. 3 1056
      src/char/char.c
  3. 2 6
      src/char/char.h
  4. 212 207
      src/char/char_clif.c
  5. 1 0
      src/char/char_clif.h
  6. 103 15
      src/char/char_logif.c
  7. 10 0
      src/char/char_logif.h
  8. 465 189
      src/char/char_mapif.c
  9. 7 0
      src/char/char_mapif.h

+ 1 - 1
src/char/Makefile.in

@@ -15,7 +15,7 @@ LIBCONFIG_INCLUDE = -I../../3rdparty/libconfig
 COMMON_SQL_OBJ = ../common/obj_sql/sql.o
 COMMON_H = ../common/sql.h
 
-CHAR_OBJ = $(shell ls *.c | sed -e "s/.c/.o/g")
+CHAR_OBJ = $(shell ls *.c | sed -e "s/\.c/\.o/g")
 #CHAR_OBJ = char.o char_clif.o char_logif.o char_mapif.o char_cnslif.o \
 	inter.o int_party.o int_guild.o int_storage.o int_pet.o int_homun.o int_mail.o int_auction.o int_quest.o int_mercenary.o int_elemental.o
 CHAR_SQL_OBJ = $(CHAR_OBJ:%=obj_sql/%)

Diff do ficheiro suprimidas por serem muito extensas
+ 3 - 1056
src/char/char.c


+ 2 - 6
src/char/char.h

@@ -241,17 +241,13 @@ int char_married(int pl1,int pl2);
 int char_child(int parent_id, int child_id);
 int char_family(int pl1,int pl2,int pl3);
 
-int request_accreg2(int account_id, int char_id);
-int save_accreg2(unsigned char* buf, int len);
+int char_request_accreg2(int account_id, int char_id);
+int char_save_accreg2(unsigned char* buf, int len);
 
 //extern bool char_gm_read;
 int char_loadName(int char_id, char* name);
 int char_check_char_name(char * name, char * esc_name);
 
-//Bonus Script
-void bonus_script_get(int fd);///Get bonus_script data
-void bonus_script_save(int fd); ///Save bonus_script data
-
 void char_pincode_decrypt( uint32 userSeed, char* pin );
 int char_pincode_compare( int fd, struct char_session_data* sd, char* pin );
 void char_auth_ok(int fd, struct char_session_data *sd);

+ 212 - 207
src/char/char_clif.c

@@ -163,29 +163,30 @@ int chclif_parse_pincode_check( int fd, struct char_session_data* sd ){
  * Client request to change pincode
  */
 int chclif_parse_pincode_change( int fd, struct char_session_data* sd ){
-	char oldpin[PINCODE_LENGTH+1];
-	char newpin[PINCODE_LENGTH+1];
-
 	if( RFIFOREST(fd) < 14 )
 		return 0;
 	if( charserv_config.pincode_config.pincode_enabled==0 || RFIFOL(fd,2) != sd->account_id )
 		return 0;
-
-	memset(oldpin,0,PINCODE_LENGTH+1);
-	memset(newpin,0,PINCODE_LENGTH+1);
-	strncpy(oldpin, (char*)RFIFOP(fd,6), PINCODE_LENGTH);
-	strncpy(newpin, (char*)RFIFOP(fd,10), PINCODE_LENGTH);
-	RFIFOSKIP(fd,14);
-
-	char_pincode_decrypt(sd->pincode_seed,oldpin);
-	if( !char_pincode_compare( fd, sd, oldpin ) )
-		return 0;
-	char_pincode_decrypt(sd->pincode_seed,newpin);
-
-	chlogif_pincode_notifyLoginPinUpdate( sd->account_id, newpin );
-	strncpy(sd->pincode, newpin, sizeof(newpin));
-
-	chclif_pincode_sendstate( fd, sd, PINCODE_PASSED );
+        else {
+            char oldpin[PINCODE_LENGTH+1];
+            char newpin[PINCODE_LENGTH+1];
+        
+            memset(oldpin,0,PINCODE_LENGTH+1);
+            memset(newpin,0,PINCODE_LENGTH+1);
+            strncpy(oldpin, (char*)RFIFOP(fd,6), PINCODE_LENGTH);
+            strncpy(newpin, (char*)RFIFOP(fd,10), PINCODE_LENGTH);
+            RFIFOSKIP(fd,14);
+
+            char_pincode_decrypt(sd->pincode_seed,oldpin);
+            if( !char_pincode_compare( fd, sd, oldpin ) )
+                    return 0;
+            char_pincode_decrypt(sd->pincode_seed,newpin);
+
+            chlogif_pincode_notifyLoginPinUpdate( sd->account_id, newpin );
+            strncpy(sd->pincode, newpin, sizeof(newpin));
+
+            chclif_pincode_sendstate( fd, sd, PINCODE_PASSED );
+        }
 	return 1;
 }
 
@@ -193,24 +194,24 @@ int chclif_parse_pincode_change( int fd, struct char_session_data* sd ){
  * activate PIN system and set first PIN
  */
 int chclif_parse_pincode_setnew( int fd, struct char_session_data* sd ){
-	char newpin[PINCODE_LENGTH+1];
-
-	memset(newpin,0,PINCODE_LENGTH+1);
-
 	if( RFIFOREST(fd) < 10 )
 		return 0;
 
 	if( charserv_config.pincode_config.pincode_enabled==0 || RFIFOL(fd,2) != sd->account_id )
 		return 0;
-	strncpy( newpin, (char*)RFIFOP(fd,6), PINCODE_LENGTH );
-	RFIFOSKIP(fd,10);
+        else {
+            char newpin[PINCODE_LENGTH+1];
+            memset(newpin,0,PINCODE_LENGTH+1);
+            strncpy( newpin, (char*)RFIFOP(fd,6), PINCODE_LENGTH );
+            RFIFOSKIP(fd,10);
 
-	char_pincode_decrypt( sd->pincode_seed, newpin );
+            char_pincode_decrypt( sd->pincode_seed, newpin );
 
-	chlogif_pincode_notifyLoginPinUpdate( sd->account_id, newpin );
-	strncpy( sd->pincode, newpin, strlen( newpin ) );
+            chlogif_pincode_notifyLoginPinUpdate( sd->account_id, newpin );
+            strncpy( sd->pincode, newpin, strlen( newpin ) );
 
-	chclif_pincode_sendstate( fd, sd, PINCODE_PASSED );
+            chclif_pincode_sendstate( fd, sd, PINCODE_PASSED );
+        }
 	return 1;
 }
 
@@ -364,12 +365,12 @@ void chclif_char_delete2_cancel_ack(int fd, int char_id, uint32 result) {
 
 // CH: <0827>.W <char id>.L
 int chclif_parse_char_delete2_req(int fd, struct char_session_data* sd) {
-	int char_id, i;
+    FIFOSD_CHECK(6)
+    {
+        int char_id, i;
 	char* data;
 	time_t delete_date;
-
-	FIFOSD_CHECK(6)
-
+        
 	char_id = RFIFOL(fd,2);
 	RFIFOSKIP(fd,6);
 
@@ -410,7 +411,6 @@ int chclif_parse_char_delete2_req(int fd, struct char_session_data* sd) {
 		return;
 	}
 */
-
 	// success
 	delete_date = time(NULL)+(charserv_config.char_config.char_del_delay);
 
@@ -422,19 +422,19 @@ int chclif_parse_char_delete2_req(int fd, struct char_session_data* sd) {
 	}
 
 	chclif_char_delete2_ack(fd, char_id, 1, delete_date);
-	return 1;
+    }
+    return 1;
 }
 
 // CH: <0829>.W <char id>.L <birth date:YYMMDD>.6B
 int chclif_parse_char_delete2_accept(int fd, struct char_session_data* sd) {
-	char birthdate[8+1];
+    FIFOSD_CHECK(12)
+    {
+        char birthdate[8+1];
 	int char_id, i, k;
 	unsigned int base_level;
 	char* data;
 	time_t delete_date;
-
-	FIFOSD_CHECK(12)
-
 	char_id = RFIFOL(fd,2);
 
 	ShowInfo(CL_RED"Request Char Deletion: "CL_GREEN"%d (%d)"CL_RESET"\n", sd->account_id, char_id);
@@ -502,7 +502,8 @@ int chclif_parse_char_delete2_accept(int fd, struct char_session_data* sd) {
 	sd->found_char[MAX_CHARS-1] = -1;
 
 	chclif_char_delete2_accept_ack(fd, char_id, 1);
-	return 1;
+    }
+    return 1;
 }
 
 // CH: <082b>.W <char id>.L
@@ -601,7 +602,7 @@ int chclif_parse_reqtoconnect(int fd, struct char_session_data* sd,uint32 ipl){
 			//TODO: Perhaps log this as a hack attempt?
 			//TODO: and perhaps send back a reply?
 			ShowInfo("Already registered break\n");
-			return 0;
+			return 0; // @CHEKME this was break
 		}
 
 		CREATE(session[fd]->session_data, struct char_session_data, 1);
@@ -634,11 +635,8 @@ int chclif_parse_reqtoconnect(int fd, struct char_session_data* sd,uint32 ipl){
 			node->login_id2  == login_id2 /*&&
 			node->ip         == ipl*/ )
 		{// authentication found (coming from map server)
-			DBMap *online_char_db = char_get_onlinedb();
-			struct online_char_data* ol_cd = (struct online_char_data*)idb_get(online_char_db, account_id);
-			if(ol_cd) sd->version = ol_cd->version;
-			ShowInfo("char_parse_reqtoconnect: authentication found (coming from map server), sd->v=%d online_chd=%d\n",sd->version,ol_cd);
-			idb_remove(auth_db, account_id);
+                        sd->version = node->version;
+                        idb_remove(auth_db, account_id);
 			char_auth_ok(fd, sd);
 		}
 		else
@@ -705,6 +703,15 @@ int chclif_parse_charselect(int fd, struct char_session_data* sd,uint32 ipl){
 		char_id = atoi(data);
 		Sql_FreeResult(sql_handle);
 
+                /* client doesn't let it get to this point if you're banned, so its a forged packet */
+                if( sd->found_char[slot] == char_id && sd->unban_time[slot] > time(NULL) ) {
+                        WFIFOHEAD(fd,3);
+                        WFIFOW(fd,0) = 0x6c;
+                        WFIFOB(fd,2) = 0; // rejected from server
+                        WFIFOSET(fd,3);
+                        return 0;
+                }
+                
 		/* set char as online prior to loading its data so 3rd party applications will realise the sql data is not reliable */
 		char_set_char_online(-2,char_id,sd->account_id);
 		if( !char_mmo_char_fromsql(char_id, &char_dat, true) ) { /* failed? set it back offline */
@@ -787,7 +794,7 @@ int chclif_parse_charselect(int fd, struct char_session_data* sd,uint32 ipl){
 		WFIFOW(fd,0) = 0x71;
 		WFIFOL(fd,2) = cd->char_id;
 		mapindex_getmapname_ext(mapindex_id2name(cd->last_point.map), (char*)WFIFOP(fd,6));
-		subnet_map_ip = lan_subnetcheck(ipl); // Advanced subnet check [LuzZza]
+		subnet_map_ip = char_lan_subnetcheck(ipl); // Advanced subnet check [LuzZza]
 		WFIFOL(fd,22) = htonl((subnet_map_ip) ? subnet_map_ip : map_server[i].ip);
 		WFIFOW(fd,26) = ntows(htons(map_server[i].port)); // [!] LE byte order here [!]
 		WFIFOSET(fd,28);
@@ -867,66 +874,64 @@ int chclif_parse_createnewchar(int fd, struct char_session_data* sd,int cmd){
 }
 
 int chclif_parse_delchar(int fd,struct char_session_data* sd, int cmd){
-	char email[40];
-	int i, ch;
-
-	if (cmd == 0x68) FIFOSD_CHECK(46)
-	else if (cmd == 0x1fb) FIFOSD_CHECK(56)
-	else return 0;
-
-	{
-		int cid = RFIFOL(fd,2);
-
-		ShowInfo(CL_RED"Request Char Deletion: "CL_GREEN"%d (%d)"CL_RESET"\n", sd->account_id, cid);
-		memcpy(email, RFIFOP(fd,6), 40);
-		RFIFOSKIP(fd,( cmd == 0x68) ? 46 : 56);
-
-		// Check if e-mail is correct
-		if(strcmpi(email, sd->email) && //email does not matches and
-		(
-			strcmp("a@a.com", sd->email) || //it is not default email, or
-			(strcmp("a@a.com", email) && strcmp("", email)) //email sent does not matches default
-		)) {	//Fail
-			WFIFOHEAD(fd,3);
-			WFIFOW(fd,0) = 0x70;
-			WFIFOB(fd,2) = 0; // 00 = Incorrect Email address
-			WFIFOSET(fd,3);
-			return 0;
-		}
-
-		// check if this char exists
-		ARR_FIND( 0, MAX_CHARS, i, sd->found_char[i] == cid );
-		if( i == MAX_CHARS )
-		{ // Such a character does not exist in the account
-			WFIFOHEAD(fd,3);
-			WFIFOW(fd,0) = 0x70;
-			WFIFOB(fd,2) = 0;
-			WFIFOSET(fd,3);
-			return 0;
-		}
-
-		// remove char from list and compact it
-		for(ch = i; ch < MAX_CHARS-1; ch++)
-			sd->found_char[ch] = sd->found_char[ch+1];
-		sd->found_char[MAX_CHARS-1] = -1;
-
-		/* Delete character */
-		if(char_delete_char_sql(cid)<0){
-			//can't delete the char
-			//either SQL error or can't delete by some CONFIG conditions
-			//del fail
-			WFIFOHEAD(fd,3);
-			WFIFOW(fd, 0) = 0x70;
-			WFIFOB(fd, 2) = 0;
-			WFIFOSET(fd, 3);
-			return 0;
-		}
-		/* Char successfully deleted.*/
-		WFIFOHEAD(fd,2);
-		WFIFOW(fd,0) = 0x6f;
-		WFIFOSET(fd,2);
-	}
-	return 1;
+    if (cmd == 0x68) FIFOSD_CHECK(46)
+    else if (cmd == 0x1fb) FIFOSD_CHECK(56)
+    else return 0;
+    {
+        char email[40];
+        int i, ch;
+        int cid = RFIFOL(fd,2);
+
+        ShowInfo(CL_RED"Request Char Deletion: "CL_GREEN"%d (%d)"CL_RESET"\n", sd->account_id, cid);
+        memcpy(email, RFIFOP(fd,6), 40);
+        RFIFOSKIP(fd,( cmd == 0x68) ? 46 : 56);
+
+        // Check if e-mail is correct
+        if(strcmpi(email, sd->email) && //email does not matches and
+        (
+                strcmp("a@a.com", sd->email) || //it is not default email, or
+                (strcmp("a@a.com", email) && strcmp("", email)) //email sent does not matches default
+        )) {	//Fail
+                WFIFOHEAD(fd,3);
+                WFIFOW(fd,0) = 0x70;
+                WFIFOB(fd,2) = 0; // 00 = Incorrect Email address
+                WFIFOSET(fd,3);
+                return 0;
+        }
+
+        // check if this char exists
+        ARR_FIND( 0, MAX_CHARS, i, sd->found_char[i] == cid );
+        if( i == MAX_CHARS )
+        { // Such a character does not exist in the account
+                WFIFOHEAD(fd,3);
+                WFIFOW(fd,0) = 0x70;
+                WFIFOB(fd,2) = 0;
+                WFIFOSET(fd,3);
+                return 0;
+        }
+
+        // remove char from list and compact it
+        for(ch = i; ch < MAX_CHARS-1; ch++)
+                sd->found_char[ch] = sd->found_char[ch+1];
+        sd->found_char[MAX_CHARS-1] = -1;
+
+        /* Delete character */
+        if(char_delete_char_sql(cid)<0){
+                //can't delete the char
+                //either SQL error or can't delete by some CONFIG conditions
+                //del fail
+                WFIFOHEAD(fd,3);
+                WFIFOW(fd, 0) = 0x70;
+                WFIFOB(fd, 2) = 0;
+                WFIFOSET(fd, 3);
+                return 0;
+        }
+        /* Char successfully deleted.*/
+        WFIFOHEAD(fd,2);
+        WFIFOW(fd,0) = 0x6f;
+        WFIFOSET(fd,2);
+    }
+    return 1;
 }
 
 // R 0187 <account ID>.l
@@ -941,97 +946,96 @@ int chclif_parse_keepalive(int fd){
 // R 08fc <char ID>.l <new name>.24B
 // R 028d <account ID>.l <char ID>.l <new name>.24B
 int chclif_parse_reqrename(int fd, struct char_session_data* sd, int cmd){
-	if(cmd == 0x8fc) FIFOSD_CHECK(30)
-	if(cmd == 0x28d) FIFOSD_CHECK(34)
-	else return 0;
-
-	{
-		int i, cid=0;
-		char name[NAME_LENGTH];
-		char esc_name[NAME_LENGTH*2+1];
-		safestrncpy(name, (char *)RFIFOP(fd,10), NAME_LENGTH);
-
-		if(cmd == 0x8fc){
-			cid =RFIFOL(fd,2);
-			RFIFOSKIP(fd,30);
-		}
-		else if(cmd == 0x28d) {
-			int aid = RFIFOL(fd,2);
-			cid =RFIFOL(fd,6);
-			if( aid != sd->account_id )
-				return 0;
-			RFIFOSKIP(fd,34);
-		}
-
-		ARR_FIND( 0, MAX_CHARS, i, sd->found_char[i] == cid );
-		if( i == MAX_CHARS )
-			return 0;
-
-		normalize_name(name,TRIM_CHARS);
-		Sql_EscapeStringLen(sql_handle, esc_name, name, strnlen(name, NAME_LENGTH));
-		if( !char_check_char_name(name,esc_name) )
-		{
-			i = 1;
-			safestrncpy(sd->new_name, name, NAME_LENGTH);
-		}
-		else
-			i = 0;
-
-		WFIFOHEAD(fd, 4);
-		WFIFOW(fd,0) = 0x28e;
-		WFIFOW(fd,2) = i;
-		WFIFOSET(fd,4);
-	}
-	return 1;
+    int i, cid=0;
+    char name[NAME_LENGTH];
+    char esc_name[NAME_LENGTH*2+1];
+
+    if(cmd == 0x8fc){
+            FIFOSD_CHECK(30)
+            cid =RFIFOL(fd,2);
+            safestrncpy(name, (char *)RFIFOP(fd,6), NAME_LENGTH);
+            RFIFOSKIP(fd,30);
+    }
+    else if(cmd == 0x28d) {
+            FIFOSD_CHECK(34)
+            int aid = RFIFOL(fd,2);
+            cid =RFIFOL(fd,6);
+            safestrncpy(name, (char *)RFIFOP(fd,10), NAME_LENGTH);
+            RFIFOSKIP(fd,34);
+            if( aid != sd->account_id )
+                    return 0;
+    }
+
+    ARR_FIND( 0, MAX_CHARS, i, sd->found_char[i] == cid );
+    if( i == MAX_CHARS )
+            return 0;
+
+    normalize_name(name,TRIM_CHARS);
+    Sql_EscapeStringLen(sql_handle, esc_name, name, strnlen(name, NAME_LENGTH));
+    if( !char_check_char_name(name,esc_name) )
+    {
+            i = 1;
+            safestrncpy(sd->new_name, name, NAME_LENGTH);
+    }
+    else
+            i = 0;
+
+    WFIFOHEAD(fd, 4);
+    WFIFOW(fd,0) = 0x28e;
+    WFIFOW(fd,2) = i;
+    WFIFOSET(fd,4);
+    return 1;
 }
 
 // 0x28f <char_id>.L
 int chclif_parse_ackrename(int fd, struct char_session_data* sd){
-	// 0: Successful
-	// 1: This character's name has already been changed. You cannot change a character's name more than once.
-	// 2: User information is not correct.
-	// 3: You have failed to change this character's name.
-	// 4: Another user is using this character name, so please select another one.
-	FIFOSD_CHECK(6)
-
-	{
-		int i;
-		int cid = RFIFOL(fd,2);
-		RFIFOSKIP(fd,6);
-
-		ARR_FIND( 0, MAX_CHARS, i, sd->found_char[i] == cid );
-		if( i == MAX_CHARS )
-			return 0;
-		i = char_rename_char_sql(sd, cid);
+    // 0: Successful
+    // 1: This character's name has already been changed. You cannot change a character's name more than once.
+    // 2: User information is not correct.
+    // 3: You have failed to change this character's name.
+    // 4: Another user is using this character name, so please select another one.
+    FIFOSD_CHECK(6)
+    {
+        int i;
+        int cid = RFIFOL(fd,2);
+        RFIFOSKIP(fd,6);
+
+        ARR_FIND( 0, MAX_CHARS, i, sd->found_char[i] == cid );
+        if( i == MAX_CHARS )
+                return 0;
+        i = char_rename_char_sql(sd, cid);
+
+        WFIFOHEAD(fd, 4);
+        WFIFOW(fd,0) = 0x290;
+        WFIFOW(fd,2) = i;
+        WFIFOSET(fd,4);
+    }
+    return 1;
+}
 
-		WFIFOHEAD(fd, 4);
-		WFIFOW(fd,0) = 0x290;
-		WFIFOW(fd,2) = i;
-		WFIFOSET(fd,4);
-	}
-	return 1;
+int chclif_ack_captcha(int fd){
+    WFIFOHEAD(fd,5);
+    WFIFOW(fd,0) = 0x7e9;
+    WFIFOW(fd,2) = 5;
+    WFIFOB(fd,4) = 1;
+    WFIFOSET(fd,5);
+    return 1;
 }
 
 // R 07e5 <?>.w <aid>.l
 int chclif_parse_reqcaptcha(int fd){
-	WFIFOHEAD(fd,5);
-	WFIFOW(fd,0) = 0x7e9;
-	WFIFOW(fd,2) = 5;
-	WFIFOB(fd,4) = 1;
-	WFIFOSET(fd,5);
-	RFIFOSKIP(fd,8);
-	return 1;
+    //FIFOSD_CHECK(8)
+    RFIFOSKIP(fd,8);
+    chclif_ack_captcha(fd); 
+    return 1;
 }
 
 // R 07e7 <len>.w <aid>.l <code>.b10 <?>.b14
 int chclif_parse_chkcaptcha(int fd){
-	WFIFOHEAD(fd,5);
-	WFIFOW(fd,0) = 0x7e9;
-	WFIFOW(fd,2) = 5;
-	WFIFOB(fd,4) = 1;
-	WFIFOSET(fd,5);
-	RFIFOSKIP(fd,32);
-	return 1;
+    //FIFOSD_CHECK(32)
+    RFIFOSKIP(fd,32);
+    chclif_ack_captcha(fd);
+    return 1;
 }
 
 /**
@@ -1043,6 +1047,7 @@ int chclif_parse(int fd) {
 	unsigned short cmd;
 	struct char_session_data* sd = (struct char_session_data*)session[fd]->session_data;
 	uint32 ipl = session[fd]->client_addr;
+        int next=0;
 
 	// disconnect any player if no login-server.
 	if(login_fd < 0)
@@ -1066,43 +1071,43 @@ int chclif_parse(int fd) {
 	while( RFIFOREST(fd) >= 2 )
 	{
 		cmd = RFIFOW(fd,0);
+                if(next==-1) return 0; // avoid processing of followup packets (prev was probably incomplete)
 		switch( cmd )
 		{
-
-		case 0x65: chclif_parse_reqtoconnect(fd,sd,ipl); break;
+		case 0x65: next=chclif_parse_reqtoconnect(fd,sd,ipl); break;
 		// char select
-		case 0x66: chclif_parse_charselect(fd,sd,ipl); break;
+		case 0x66: next=chclif_parse_charselect(fd,sd,ipl); break;
 		// createnewchar
-		case 0x970: chclif_parse_createnewchar(fd,sd,cmd); break;
-		case 0x67: chclif_parse_createnewchar(fd,sd,cmd); break;
+		case 0x970: next=chclif_parse_createnewchar(fd,sd,cmd); break;
+		case 0x67: next=chclif_parse_createnewchar(fd,sd,cmd); break;
 		// delete char
-		case 0x68: chclif_parse_delchar(fd,sd,cmd); break; //
-		case 0x1fb: chclif_parse_delchar(fd,sd,cmd); break; // 2004-04-19aSakexe+ langtype 12 char deletion packet
+		case 0x68: next=chclif_parse_delchar(fd,sd,cmd); break; //
+		case 0x1fb: next=chclif_parse_delchar(fd,sd,cmd); break; // 2004-04-19aSakexe+ langtype 12 char deletion packet
 		// client keep-alive packet (every 12 seconds)
-		case 0x187: chclif_parse_keepalive(fd); break;
+		case 0x187: next=chclif_parse_keepalive(fd); break;
 		// char rename
-		case 0x8fc: chclif_parse_reqrename(fd,sd,cmd); break; //request <date/version?>
-		case 0x28d: chclif_parse_reqrename(fd,sd,cmd); break; //request <date/version?>
-		case 0x28f: chclif_parse_ackrename(fd,sd); break; //Confirm change name.
+		case 0x8fc: next=chclif_parse_reqrename(fd,sd,cmd); break; //request <date/version?>
+		case 0x28d: next=chclif_parse_reqrename(fd,sd,cmd); break; //request <date/version?>
+		case 0x28f: next=chclif_parse_ackrename(fd,sd); break; //Confirm change name.
 		// captcha
-		case 0x7e5: chclif_parse_reqcaptcha(fd); break; // captcha code request (not implemented)
-		case 0x7e7: chclif_parse_chkcaptcha(fd); break; // captcha code check (not implemented)
+		case 0x7e5: next=chclif_parse_reqcaptcha(fd); break; // captcha code request (not implemented)
+		case 0x7e7: next=chclif_parse_chkcaptcha(fd); break; // captcha code check (not implemented)
 		// deletion timer request
-		case 0x827: chclif_parse_char_delete2_req(fd, sd); break;
+		case 0x827: next=chclif_parse_char_delete2_req(fd, sd); break;
 		// deletion accept request
-		case 0x829: chclif_parse_char_delete2_accept(fd, sd); break;
+		case 0x829: next=chclif_parse_char_delete2_accept(fd, sd); break;
 		// deletion cancel request
-		case 0x82b: chclif_parse_char_delete2_cancel(fd, sd); break;
+		case 0x82b: next=chclif_parse_char_delete2_cancel(fd, sd); break;
 		// login as map-server
 		case 0x2af8: chclif_parse_maplogin(fd); return 0; // avoid processing of followup packets here
 		//pincode
-		case 0x8b8: chclif_parse_pincode_check( fd, sd ); break; // checks the entered pin
-		case 0x8c5: chclif_parse_reqpincode_window(fd,sd); break; // request for PIN window
-		case 0x8be: chclif_parse_pincode_change( fd, sd ); break; // pincode change request
-		case 0x8ba: chclif_parse_pincode_setnew( fd, sd ); break; // activate PIN system and set first PIN
+		case 0x8b8: next=chclif_parse_pincode_check( fd, sd ); break; // checks the entered pin
+		case 0x8c5: next=chclif_parse_reqpincode_window(fd,sd); break; // request for PIN window
+		case 0x8be: next=chclif_parse_pincode_change( fd, sd ); break; // pincode change request
+		case 0x8ba: next=chclif_parse_pincode_setnew( fd, sd ); break; // activate PIN system and set first PIN
 		// character movement request
-		case 0x8d4: chclif_parse_moveCharSlot(fd,sd); break;
-		case 0x9a1: chclif_parse_req_charlist(fd,sd); break;
+		case 0x8d4: next=chclif_parse_moveCharSlot(fd,sd); break;
+		case 0x9a1: next=chclif_parse_req_charlist(fd,sd); break;
 		// unknown packet received
 		default:
 			ShowError("parse_char: Received unknown packet "CL_WHITE"0x%x"CL_RESET" from ip '"CL_WHITE"%s"CL_RESET"'! Disconnecting!\n", RFIFOW(fd,0), ip2str(ipl, NULL));

+ 1 - 0
src/char/char_clif.h

@@ -46,6 +46,7 @@ int chclif_parse_delchar(int fd,struct char_session_data* sd, int cmd);
 int chclif_parse_keepalive(int fd);
 int chclif_parse_reqrename(int fd, struct char_session_data* sd, int cmd);
 int chclif_parse_ackrename(int fd, struct char_session_data* sd);
+int chclif_ack_captcha(int fd);
 int chclif_parse_reqcaptcha(int fd);
 int chclif_parse_chkcaptcha(int fd);
 

+ 103 - 15
src/char/char_logif.c

@@ -22,7 +22,6 @@
 void chlogif_on_ready(void);
 void chlogif_on_disconnect(void);
 
-
 int chlogif_pincode_notifyLoginPinError( int account_id ){
 	if (login_fd > 0 && session[login_fd] && !session[login_fd]->flag.eof){
 		WFIFOHEAD(login_fd,6);
@@ -183,7 +182,7 @@ void chlogif_send_setallaccoffline(int fd){
 }
 
 int chlogif_send_setaccoffline(int fd, int aid){
-	if (loginif_isconnected()){
+	if (chlogif_isconnected()){
 		WFIFOHEAD(fd,6);
 		WFIFOW(fd,0) = 0x272c;
 		WFIFOL(fd,2) = aid;
@@ -492,9 +491,94 @@ int chlogif_parse_updip(int fd, struct char_session_data* sd){
 	return 1;
 }
 
+/**
+ * Send to login-serv the request of banking operation from map
+ * HA 0x2740<aid>L <type>B <data>L
+ * @param account_id
+ * @param type : 0 = select, 1 = update
+ * @param data
+ * @return
+ */
+int chlogif_BankingReq(int32 account_id, int8 type, int32 data){
+	loginif_check(-1);
+
+	WFIFOHEAD(login_fd,11);
+	WFIFOW(login_fd,0) = 0x2740;
+	WFIFOL(login_fd,2) = account_id;
+	WFIFOB(login_fd,6) = type;
+	WFIFOL(login_fd,7) = data;
+	WFIFOSET(login_fd,11);
+	return 0;
+}
+
+/*
+ * Received the banking data from login and transmit it to all map-serv
+ * AH 0x2741<aid>L <bank_vault>L <not_fw>B
+ * HZ 0x2b29 <aid>L <bank_vault>L
+ */
+int chlogif_parse_BankingAck(int fd){
+	if (RFIFOREST(fd) < 11)
+            return -1;
+	else {
+		uint32 aid = RFIFOL(fd,2);
+		int32 bank_vault = RFIFOL(fd,6);
+		char not_fw = RFIFOB(fd,10);
+		RFIFOSKIP(fd,11);
+
+		if(not_fw==0) chmapif_BankingAck(aid, bank_vault);
+	}
+	return 1;
+}
+
+/*
+ * AH 0x2743
+ * We received the info from login-serv, transmit it to map
+ */
+int chlogif_parse_vipack(int fd) {
+#ifdef VIP_ENABLE
+	if (RFIFOREST(fd) < 20)
+		return -1;
+	else {
+		uint32 aid = RFIFOL(fd,2); //aid
+		uint32 vip_time = RFIFOL(fd,6); //vip_time
+		uint8 isvip = RFIFOB(fd,10); //isvip
+		uint32 groupid = RFIFOL(fd,11); //new group id
+		uint8 isgm = RFIFOB(fd,15); //isgm
+		int mapfd = RFIFOL(fd,16); //link to mapserv for ack
+		RFIFOSKIP(fd,20);
+		mapif_vipack(mapfd,aid,vip_time,isvip,isgm,groupid);
+	}
+#endif
+	return 1;
+}
+
+/**
+ * HZ 0x2b2b
+ * Request vip data from loginserv
+ * @param aid : account_id to request the vip data
+ * @param type : &2 define new duration, &1 load info
+ * @param add_vip_time : tick to add to vip timestamp
+ * @param mapfd: link to mapserv for ack
+ * @return 0 if success
+ */
+int chlogif_reqvipdata(uint32 aid, uint8 type, int32 timediff, int mapfd) {
+	loginif_check(-1);
+#ifdef VIP_ENABLE
+	WFIFOHEAD(login_fd,15);
+	WFIFOW(login_fd,0) = 0x2742;
+	WFIFOL(login_fd,2) = aid; //aid
+	WFIFOB(login_fd,6) = type; //type
+	WFIFOL(login_fd,7) = timediff; //req_inc_duration
+	WFIFOL(login_fd,11) = mapfd; //req_inc_duration
+	WFIFOSET(login_fd,15);
+#endif
+	return 0;
+}
+
+
 int chlogif_parse(int fd) {
 	struct char_session_data* sd = NULL;
-
+        int next=0;
 	// only process data from the login-server
 	if( fd != login_fd ) {
 		ShowDebug("parse_fromlogin: Disconnecting invalid session #%d (is not the login-server)\n", fd);
@@ -524,30 +608,30 @@ int chlogif_parse(int fd) {
 
 	while(RFIFOREST(fd) >= 2) {
 		uint16 command = RFIFOW(fd,0);
+                if(next==-1) return 0; //do not parse next data
 
 		switch( command )
 		{
-                case 0x2741: loginif_parse_BankingAck(fd); break;
-		case 0x2743: loginif_parse_vipack(fd); break;
-                
+                case 0x2741: next=chlogif_parse_BankingAck(fd); break;
+		case 0x2743: next=chlogif_parse_vipack(fd); break;
 		// acknowledgement of connect-to-loginserver request
-		case 0x2711: chlogif_parse_ackconnect(fd,sd); break;
+		case 0x2711: next=chlogif_parse_ackconnect(fd,sd); break;
 		// acknowledgement of account authentication request
-		case 0x2713: chlogif_parse_ackaccreq(fd, sd); break;
+		case 0x2713: next=chlogif_parse_ackaccreq(fd, sd); break;
 		// account data
-		case 0x2717: chlogif_parse_reqaccdata(fd, sd); break;
+		case 0x2717: next=chlogif_parse_reqaccdata(fd, sd); break;
 		// login-server alive packet
-		case 0x2718: chlogif_parse_keepalive(fd, sd); break;
+		case 0x2718: next=chlogif_parse_keepalive(fd, sd); break;
 		// changesex reply
-		case 0x2723: chlogif_parse_ackchangesex(fd, sd); break;
+		case 0x2723: next=chlogif_parse_ackchangesex(fd, sd); break;
 		// reply to an account_reg2 registry request
-		case 0x2729: chlogif_parse_ackacc2req(fd, sd); break;
+		case 0x2729: next=chlogif_parse_ackacc2req(fd, sd); break;
 		// State change of account/ban notification (from login-server)
-		case 0x2731: chlogif_parse_accbannotification(fd, sd); break;
+		case 0x2731: next=chlogif_parse_accbannotification(fd, sd); break;
 		// Login server request to kick a character out. [Skotlex]
-		case 0x2734: chlogif_parse_askkick(fd,sd); break;
+		case 0x2734: next=chlogif_parse_askkick(fd,sd); break;
 		// ip address update signal from login server
-		case 0x2735: chlogif_parse_updip(fd,sd); break;
+		case 0x2735: next=chlogif_parse_updip(fd,sd); break;
 		default:
 			ShowError("Unknown packet 0x%04x received from login-server, disconnecting.\n", command);
 			set_eof(fd);
@@ -592,6 +676,10 @@ int chlogif_check_connect_logserver(int tid, unsigned int tick, int id, intptr_t
 
 
 
+int chlogif_isconnected(){
+	return (login_fd > 0 && session[login_fd] && !session[login_fd]->flag.eof);
+}
+
 void do_init_chlogif(void) {
 	// establish char-login connection if not present
 	add_timer_func_list(chlogif_check_connect_logserver, "check_connect_login_server");

+ 10 - 0
src/char/char_logif.h

@@ -35,7 +35,14 @@ int chlogif_parse_accbannotification(int fd, struct char_session_data* sd);
 int chlogif_parse_askkick(int fd, struct char_session_data* sd);
 int chlogif_parse_updip(int fd, struct char_session_data* sd);
 
+int chlogif_BankingReq(int32 account_id, int8 type, int32 data);
+int chlogif_parse_BankingAck(int fd);
+int chlogif_parse_vipack(int fd);
+int chlogif_reqvipdata(uint32 aid, uint8 type, int32 timediff, int mapfd);
+
 int chlogif_parse(int fd);
+
+int chlogif_isconnected();
 int chlogif_check_connect_logserver(int tid, unsigned int tick, int id, intptr_t data);
 void do_init_chlogif(void);
 void chlogif_reset(void);
@@ -44,6 +51,9 @@ void chlogif_on_disconnect(void);
 void chlogif_on_ready(void);
 void do_final_chlogif(void);
 
+
+#define loginif_check(a) { if(!chlogif_isconnected()) return a; }
+
 #ifdef	__cplusplus
 }
 #endif

+ 465 - 189
src/char/char_mapif.c

@@ -14,6 +14,7 @@
 #include "../common/strlib.h"
 #include "inter.h"
 #include "char.h"
+#include "char_logif.h"
 #include "char_mapif.h"
 
 #include <stdio.h>
@@ -172,7 +173,7 @@ void chmapif_sendall_playercount(int users){
 int chmapif_parse_getmapname(int fd, int id){
 	int j = 0, i = 0;
 	if (RFIFOREST(fd) < 4 || RFIFOREST(fd) < RFIFOW(fd,2))
-		return 0;
+		return -1;
 
 	//Retain what map-index that map-serv contains
 	memset(map_server[id].map, 0, sizeof(map_server[id].map));
@@ -195,11 +196,11 @@ int chmapif_parse_getmapname(int fd, int id){
 	chmapif_send_fame_list(fd); //Send fame list.
 
 	{
-		unsigned char buf[16384];
 		int x;
 		if (j == 0) {
 			ShowWarning("Map-server %d has NO maps.\n", id);
 		} else {
+                        unsigned char buf[16384];
 			// Transmitting maps information to the other map-servers
 			WBUFW(buf,0) = 0x2b04;
 			WBUFW(buf,2) = j * 4 + 10;
@@ -238,7 +239,7 @@ int chmapif_parse_getmapname(int fd, int id){
  */
 int chmapif_parse_askscdata(int fd){
 	if (RFIFOREST(fd) < 10)
-		return 0;
+		return -1;
 	{
 #ifdef ENABLE_SC_SAVING
 		int aid, cid;
@@ -277,10 +278,6 @@ int chmapif_parse_askscdata(int fd){
 				WFIFOW(fd,2) = 14 + count*sizeof(struct status_change_data);
 				WFIFOW(fd,12) = count;
 				WFIFOSET(fd,WFIFOW(fd,2));
-
-				//Clear the data once loaded.
-				if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `account_id` = '%d' AND `char_id`='%d'", schema_config.scdata_db, aid, cid) )
-					Sql_ShowDebug(sql_handle);
 			}
 		}
 		Sql_FreeResult(sql_handle);
@@ -298,7 +295,7 @@ int chmapif_parse_askscdata(int fd){
  */
 int chmapif_parse_getusercount(int fd, int id){
 	if (RFIFOREST(fd) < 4)
-		return 0;
+		return -1;
 	if (RFIFOW(fd,2) != map_server[id].users) {
 		map_server[id].users = RFIFOW(fd,2);
 		ShowInfo("User Count: %d (Server: %d)\n", map_server[id].users, id);
@@ -316,7 +313,7 @@ int chmapif_parse_getusercount(int fd, int id){
 int chmapif_parse_regmapuser(int fd, int id){
 	int i;
 	if (RFIFOREST(fd) < 6 || RFIFOREST(fd) < RFIFOW(fd,2))
-		return 0;
+		return -1;
 	{
 		//TODO: When data mismatches memory, update guild/party online/offline states.
 		int aid, cid;
@@ -353,7 +350,7 @@ int chmapif_parse_regmapuser(int fd, int id){
  */
 int chmapif_parse_reqsavechar(int fd, int id){
 	if (RFIFOREST(fd) < 4 || RFIFOREST(fd) < RFIFOW(fd,2))
-			return 0;
+            return -1;
 	{
 		int aid = RFIFOL(fd,4), cid = RFIFOL(fd,8), size = RFIFOW(fd,2);
 		struct online_char_data* character;
@@ -399,7 +396,7 @@ int chmapif_parse_reqsavechar(int fd, int id){
  */
 int chmapif_parse_authok(int fd){
 	if( RFIFOREST(fd) < 19 )
-		return 0;
+		return -1;
 	else{
 		int account_id = RFIFOL(fd,2);
 		uint32 login_id1 = RFIFOL(fd,6);
@@ -427,6 +424,7 @@ int chmapif_parse_authok(int fd){
 			node->login_id2 = login_id2;
 			//node->sex = 0;
 			node->ip = ntohl(ip);
+                        node->version = version; //upd version for mapserv
 			//node->expiration_time = 0; // unlimited/unknown time by default (not display in map-server)
 			//node->gmlevel = 0;
 			idb_put(auth_db, account_id, node);
@@ -437,7 +435,6 @@ int chmapif_parse_authok(int fd){
 				struct online_char_data* character = (struct online_char_data*)idb_get(online_char_db, account_id);
 				if( character != NULL ){
 					character->pincode_success = true;
-					character->version = version;
 				}
 			}
 
@@ -454,7 +451,7 @@ int chmapif_parse_authok(int fd){
 //Request to save skill cooldown data
 int chmapif_parse_req_saveskillcooldown(int fd){
 	if( RFIFOREST(fd) < 4 || RFIFOREST(fd) < RFIFOW(fd,2) )
-				return 0;
+            return -1;
 	else {
 		int count, aid, cid;
 		aid = RFIFOL(fd,4);
@@ -487,7 +484,7 @@ int chmapif_parse_req_saveskillcooldown(int fd){
 //Request skillcooldown data 0x2b0a
 int chmapif_parse_req_skillcooldown(int fd){
 	if (RFIFOREST(fd) < 10)
-		return 0;
+		return -1;
 	else {
 		int aid, cid;
 		aid = RFIFOL(fd,2);
@@ -539,7 +536,7 @@ int chmapif_parse_req_skillcooldown(int fd){
  */
 int chmapif_parse_reqchangemapserv(int fd){
 	if (RFIFOREST(fd) < 39)
-		return 0;
+		return -1;
 	{
 		int map_id, map_fd = -1;
 		struct mmo_charstatus* char_data;
@@ -616,7 +613,7 @@ int chmapif_parse_reqchangemapserv(int fd){
  */
 int chmapif_parse_askrmfriend(int fd){
 	if (RFIFOREST(fd) < 10)
-		return 0;
+		return -1;
 	{
 		int char_id, friend_id;
 		char_id = RFIFOL(fd,2);
@@ -639,7 +636,7 @@ int chmapif_parse_askrmfriend(int fd){
  */
 int chmapif_parse_reqcharname(int fd){
 	if (RFIFOREST(fd) < 6)
-		return 0;
+		return -1;
 
 	WFIFOHEAD(fd,30);
 	WFIFOW(fd,0) = 0x2b09;
@@ -659,8 +656,8 @@ int chmapif_parse_reqcharname(int fd){
  */
 int chmapif_parse_reqnewemail(int fd){
 	if (RFIFOREST(fd) < 86)
-		return 0;
-	if (login_fd > 0) { // don't send request if no login-server
+		return -1;
+	if (chlogif_isconnected()) { // don't send request if no login-server
 		WFIFOHEAD(login_fd,86);
 		memcpy(WFIFOP(login_fd,0), RFIFOP(fd,0),86); // 0x2722 <account_id>.L <actual_e-mail>.40B <new_e-mail>.40B
 		WFIFOW(login_fd,0) = 0x2722;
@@ -677,101 +674,98 @@ int chmapif_parse_reqnewemail(int fd){
  */
 int chmapif_parse_fwlog_changestatus(int fd){
 	if (RFIFOREST(fd) < 44)
-		return 0;
-	{
-		int result = 0; // 0-login-server request done, 1-player not found, 2-gm level too low, 3-login-server offline
+		return -1;
+	else {
+		int result = 0; // 0-login-server request done, 1-player not found, 2-gm level too low, 3-login-server offline, 4-current group level > VIP group level
 		char esc_name[NAME_LENGTH*2+1];
+		char answer = true;
 
-		int acc = RFIFOL(fd,2); // account_id of who ask (-1 if server itself made this request)
+		int aid = RFIFOL(fd,2); // account_id of who ask (-1 if server itself made this request)
 		const char* name = (char*)RFIFOP(fd,6); // name of the target character
-		int type = RFIFOW(fd,30); // type of operation: 1-block, 2-ban, 3-unblock, 4-unban
-		short year = RFIFOW(fd,32);
-		short month = RFIFOW(fd,34);
-		short day = RFIFOW(fd,36);
-		short hour = RFIFOW(fd,38);
-		short minute = RFIFOW(fd,40);
-		short second = RFIFOW(fd,42);
+		int operation = RFIFOW(fd,30); // type of operation: 1-block, 2-ban, 3-unblock, 4-unban, 5-changesex, 6-vip, 7-bank
+		int32 timediff = RFIFOL(fd,32);
+		int val1 = RFIFOL(fd,36);
+		int val2 = RFIFOL(fd,40);
 		RFIFOSKIP(fd,44);
 
 		Sql_EscapeStringLen(sql_handle, esc_name, name, strnlen(name, NAME_LENGTH));
-		if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `account_id`,`name` FROM `%s` WHERE `name` = '%s'", schema_config.char_db, esc_name) )
+		if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `account_id`,`name`,`char_id`,`unban_time` FROM `%s` WHERE `name` = '%s'", schema_config.char_db, esc_name) )
 			Sql_ShowDebug(sql_handle);
-		else
-		if( Sql_NumRows(sql_handle) == 0 )
-		{
+		else if( Sql_NumRows(sql_handle) == 0 ) {
 			result = 1; // 1-player not found
 		}
-		else
-		if( SQL_SUCCESS != Sql_NextRow(sql_handle) )
+		else if( SQL_SUCCESS != Sql_NextRow(sql_handle) ) {
 			Sql_ShowDebug(sql_handle);
-			//FIXME: set proper result value?
-		else
-		{
+			result = 1;
+		} else {
 			char name[NAME_LENGTH];
 			int account_id;
 			char* data;
 
 			Sql_GetData(sql_handle, 0, &data, NULL); account_id = atoi(data);
 			Sql_GetData(sql_handle, 1, &data, NULL); safestrncpy(name, data, sizeof(name));
+			Sql_FreeResult(sql_handle);
 
-			if( login_fd <= 0 )
+			if(!chlogif_isconnected())
 				result = 3; // 3-login-server offline
 			//FIXME: need to move this check to login server [ultramage]
-//				else
-//				if( acc != -1 && isGM(acc) < isGM(account_id) )
-//					result = 2; // 2-gm level too low
-			else
-			switch( type ) {
-			case 1: // block
+			//	if( acc != -1 && isGM(acc) < isGM(account_id) )
+			//		result = 2; // 2-gm level too low
+			else {
+				switch( operation ) {
+				case 1: // block
 					WFIFOHEAD(login_fd,10);
 					WFIFOW(login_fd,0) = 0x2724;
 					WFIFOL(login_fd,2) = account_id;
 					WFIFOL(login_fd,6) = 5; // new account status
 					WFIFOSET(login_fd,10);
-			break;
-			case 2: // ban
-					WFIFOHEAD(login_fd,18);
+				break;
+				case 2: // ban
+					WFIFOHEAD(login_fd,10);
 					WFIFOW(login_fd, 0) = 0x2725;
 					WFIFOL(login_fd, 2) = account_id;
-					WFIFOW(login_fd, 6) = year;
-					WFIFOW(login_fd, 8) = month;
-					WFIFOW(login_fd,10) = day;
-					WFIFOW(login_fd,12) = hour;
-					WFIFOW(login_fd,14) = minute;
-					WFIFOW(login_fd,16) = second;
-					WFIFOSET(login_fd,18);
-			break;
-			case 3: // unblock
+					WFIFOL(login_fd, 6) = timediff;
+					WFIFOSET(login_fd,10);
+				break;
+				case 3: // unblock
 					WFIFOHEAD(login_fd,10);
 					WFIFOW(login_fd,0) = 0x2724;
 					WFIFOL(login_fd,2) = account_id;
 					WFIFOL(login_fd,6) = 0; // new account status
 					WFIFOSET(login_fd,10);
-			break;
-			case 4: // unban
+				break;
+				case 4: // unban
 					WFIFOHEAD(login_fd,6);
 					WFIFOW(login_fd,0) = 0x272a;
 					WFIFOL(login_fd,2) = account_id;
 					WFIFOSET(login_fd,6);
-			break;
-			case 5: // changesex
+				break;
+				case 5: // changesex
+					answer = false;
 					WFIFOHEAD(login_fd,6);
 					WFIFOW(login_fd,0) = 0x2727;
 					WFIFOL(login_fd,2) = account_id;
 					WFIFOSET(login_fd,6);
-			break;
-			}
+				break;
+				case 6:
+					answer = (val1&4); // vip_req val1=type, &1 login send return, &2 update timestamp, &4 map send answer
+					chlogif_reqvipdata(account_id, val1, timediff, fd);
+					break;
+				case 7:
+					answer = (val1&1); //val&1 request answer, val1&2 save data
+					chlogif_BankingReq(aid, val1, val2);
+					break;
+				} //end switch operation
+			} //login is connected
 		}
 
-		Sql_FreeResult(sql_handle);
-
-		// send answer if a player ask, not if the server ask
-		if( acc != -1 && type != 5) { // Don't send answer for changesex
+		// send answer if a player asks, not if the server asks
+		if( aid != -1 && answer) { // Don't send answer for changesex
 			WFIFOHEAD(fd,34);
 			WFIFOW(fd, 0) = 0x2b0f;
-			WFIFOL(fd, 2) = acc;
+			WFIFOL(fd, 2) = aid;
 			safestrncpy((char*)WFIFOP(fd,6), name, NAME_LENGTH);
-			WFIFOW(fd,30) = type;
+			WFIFOW(fd,30) = operation;
 			WFIFOW(fd,32) = result;
 			WFIFOSET(fd,34);
 		}
@@ -785,9 +779,9 @@ int chmapif_parse_fwlog_changestatus(int fd){
  * @param fd: wich fd to parse from
  * @return : 0 not enough data received, 1 success
  */
-int chmapif_parse_updfamelist(int fd){
+int chmapif_parse_req_alter_acc(int fd){
 	if (RFIFOREST(fd) < 11)
-		return 0;
+		return -1;
 	{
 		int cid = RFIFOL(fd, 2);
 		int fame = RFIFOL(fd, 6);
@@ -860,7 +854,7 @@ void chmapif_send_ackdivorce(int partner_id1, int partner_id2){
  */
 int chmapif_parse_reqdivorce(int fd){
 	if( RFIFOREST(fd) < 10 )
-		return 0;
+		return -1;
 	char_divorce_char_sql(RFIFOL(fd,2), RFIFOL(fd,6));
 	RFIFOSKIP(fd,10);
 	return 1;
@@ -874,7 +868,7 @@ int chmapif_parse_reqdivorce(int fd){
  */
 int chmapif_parse_updmapinfo(int fd){
 	if( RFIFOREST(fd) < 14 )
-		return 0;
+		return -1;
 	{
 		char esc_server_name[sizeof(charserv_config.server_name)*2+1];
 		Sql_EscapeString(sql_handle, esc_server_name, charserv_config.server_name);
@@ -894,7 +888,7 @@ int chmapif_parse_updmapinfo(int fd){
  */
 int chmapif_parse_setcharoffline(int fd){
 	if (RFIFOREST(fd) < 6)
-		return 0;
+		return -1;
 	char_set_char_offline(RFIFOL(fd,2),RFIFOL(fd,6));
 	RFIFOSKIP(fd,10);
 	return 1;
@@ -923,7 +917,7 @@ int chmapif_parse_setalloffline(int fd, int id){
  */
 int chmapif_parse_setcharonline(int fd, int id){
 	if (RFIFOREST(fd) < 10)
-		return 0;
+		return -1;
 	char_set_char_online(id, RFIFOL(fd,2),RFIFOL(fd,6));
 	RFIFOSKIP(fd,10);
 	return 1;
@@ -938,7 +932,7 @@ int chmapif_parse_setcharonline(int fd, int id){
  */
 int chmapif_parse_reqfamelist(int fd){
 	if (RFIFOREST(fd) < 2)
-		return 0;
+		return -1;
 	char_read_fame_list();
 	chmapif_send_fame_list(-1);
 	RFIFOSKIP(fd,2);
@@ -953,7 +947,7 @@ int chmapif_parse_reqfamelist(int fd){
  */
 int chmapif_parse_save_scdata(int fd){
 	if (RFIFOREST(fd) < 4 || RFIFOREST(fd) < RFIFOW(fd,2))
-		return 0;
+		return -1;
 	{
 #ifdef ENABLE_SC_SAVING
 		int count, aid, cid;
@@ -962,7 +956,11 @@ int chmapif_parse_save_scdata(int fd){
 		cid = RFIFOL(fd, 8);
 		count = RFIFOW(fd, 12);
 
-		if( count > 0 )
+                // Whatever comes from the mapserver, now is the time to drop previous entries
+                if( Sql_Query( sql_handle, "DELETE FROM `%s` where `account_id` = %d and `char_id` = %d;", schema_config.scdata_db, aid, cid ) != SQL_SUCCESS ){
+                        Sql_ShowDebug( sql_handle );
+                }
+		else if( count > 0 )
 		{
 			struct status_change_data data;
 			StringBuf buf;
@@ -1007,75 +1005,94 @@ int chmapif_parse_keepalive(int fd){
  * @return : 0 not enough data received, 1 success
  */
 int chmapif_parse_reqauth(int fd, int id){
-	if (RFIFOREST(fd) < 19)
-		return 0;
-
-	{
-		int account_id;
-		int char_id;
-		int login_id1;
-		char sex;
-		uint32 ip;
-		struct auth_node* node;
-		struct mmo_charstatus* cd;
-		struct mmo_charstatus char_dat;
-		DBMap*  auth_db = char_get_authdb();
-		DBMap* char_db_ = char_get_chardb();
-
-		account_id = RFIFOL(fd,2);
-		char_id    = RFIFOL(fd,6);
-		login_id1  = RFIFOL(fd,10);
-		sex        = RFIFOB(fd,14);
-		ip         = ntohl(RFIFOL(fd,15));
-		RFIFOSKIP(fd,19);
-
-		node = (struct auth_node*)idb_get(auth_db, account_id);
-		cd = (struct mmo_charstatus*)uidb_get(char_db_,char_id);
-		if( cd == NULL )
-		{	//Really shouldn't happen.
-			char_mmo_char_fromsql(char_id, &char_dat, true);
-			cd = (struct mmo_charstatus*)uidb_get(char_db_,char_id);
-		}
-		if( runflag == CHARSERVER_ST_RUNNING &&
-			cd != NULL &&
-			node != NULL &&
-			node->account_id == account_id &&
-			node->char_id == char_id &&
-			node->login_id1 == login_id1 &&
-			node->sex == sex /*&&
-			node->ip == ip*/ )
-		{// auth ok
-			cd->sex = sex;
-
-			WFIFOHEAD(fd,25 + sizeof(struct mmo_charstatus));
-			WFIFOW(fd,0) = 0x2afd;
-			WFIFOW(fd,2) = 25 + sizeof(struct mmo_charstatus);
-			WFIFOL(fd,4) = account_id;
-			WFIFOL(fd,8) = node->login_id1;
-			WFIFOL(fd,12) = node->login_id2;
-			WFIFOL(fd,16) = (uint32)node->expiration_time; // FIXME: will wrap to negative after "19-Jan-2038, 03:14:07 AM GMT"
-			WFIFOL(fd,20) = node->group_id;
-			WFIFOB(fd,24) = node->changing_mapservers;
-			memcpy(WFIFOP(fd,25), cd, sizeof(struct mmo_charstatus));
-			WFIFOSET(fd, WFIFOW(fd,2));
-
-			// only use the auth once and mark user online
-			idb_remove(auth_db, account_id);
-			char_set_char_online(id, char_id, account_id);
-		}
-		else
-		{// auth failed
-			WFIFOHEAD(fd,19);
-			WFIFOW(fd,0) = 0x2b27;
-			WFIFOL(fd,2) = account_id;
-			WFIFOL(fd,6) = char_id;
-			WFIFOL(fd,10) = login_id1;
-			WFIFOB(fd,14) = sex;
-			WFIFOL(fd,15) = htonl(ip);
-			WFIFOSET(fd,19);
-		}
-	}
-	return 1;
+    if (RFIFOREST(fd) < 20)
+            return -1;
+
+    {
+        int account_id;
+        int char_id;
+        int login_id1;
+        char sex;
+        uint32 ip;
+        struct auth_node* node;
+        struct mmo_charstatus* cd;
+        struct mmo_charstatus char_dat;
+        bool autotrade;
+
+        DBMap*  auth_db = char_get_authdb();
+        DBMap* char_db_ = char_get_chardb();
+
+        account_id = RFIFOL(fd,2);
+        char_id    = RFIFOL(fd,6);
+        login_id1  = RFIFOL(fd,10);
+        sex        = RFIFOB(fd,14);
+        ip         = ntohl(RFIFOL(fd,15));
+        autotrade = RFIFOB(fd,19);
+        RFIFOSKIP(fd,20);
+
+        node = (struct auth_node*)idb_get(auth_db, account_id);
+        cd = (struct mmo_charstatus*)uidb_get(char_db_,char_id);
+        if( cd == NULL )
+        {	//Really shouldn't happen.
+                char_mmo_char_fromsql(char_id, &char_dat, true);
+                cd = (struct mmo_charstatus*)uidb_get(char_db_,char_id);
+        }
+        if( runflag == CHARSERVER_ST_RUNNING && autotrade && cd ){
+            uint32 mmo_charstatus_len = sizeof(struct mmo_charstatus) + 25;
+            cd->sex = sex;
+
+            WFIFOHEAD(fd,mmo_charstatus_len);
+            WFIFOW(fd,0) = 0x2afd;
+            WFIFOW(fd,2) = mmo_charstatus_len;
+            WFIFOL(fd,4) = account_id;
+            WFIFOL(fd,8) = 0;
+            WFIFOL(fd,12) = 0;
+            WFIFOL(fd,16) = 0;
+            WFIFOL(fd,20) = 0;
+            WFIFOB(fd,24) = 0;
+            memcpy(WFIFOP(fd,25), cd, sizeof(struct mmo_charstatus));
+            WFIFOSET(fd, WFIFOW(fd,2));
+
+            char_set_char_online(id, char_id, account_id);
+        } else if( runflag == CHARSERVER_ST_RUNNING &&
+            cd != NULL &&
+            node != NULL &&
+            node->account_id == account_id &&
+            node->char_id == char_id &&
+            node->login_id1 == login_id1 &&
+            node->sex == sex /*&&
+            node->ip == ip*/ )
+        {// auth ok
+            uint32 mmo_charstatus_len = sizeof(struct mmo_charstatus) + 25;
+            cd->sex = sex;
+
+            WFIFOHEAD(fd,mmo_charstatus_len);
+            WFIFOW(fd,0) = 0x2afd;
+            WFIFOW(fd,2) = mmo_charstatus_len;
+            WFIFOL(fd,4) = account_id;
+            WFIFOL(fd,8) = node->login_id1;
+            WFIFOL(fd,12) = node->login_id2;
+            WFIFOL(fd,16) = (uint32)node->expiration_time; // FIXME: will wrap to negative after "19-Jan-2038, 03:14:07 AM GMT"
+            WFIFOL(fd,20) = node->group_id;
+            WFIFOB(fd,24) = node->changing_mapservers;
+            memcpy(WFIFOP(fd,25), cd, sizeof(struct mmo_charstatus));
+            WFIFOSET(fd, WFIFOW(fd,2));
+
+            // only use the auth once and mark user online
+            idb_remove(auth_db, account_id);
+            char_set_char_online(id, char_id, account_id);
+        } else {// auth failed
+                WFIFOHEAD(fd,19);
+                WFIFOW(fd,0) = 0x2b27;
+                WFIFOL(fd,2) = account_id;
+                WFIFOL(fd,6) = char_id;
+                WFIFOL(fd,10) = login_id1;
+                WFIFOB(fd,14) = sex;
+                WFIFOL(fd,15) = htonl(ip);
+                WFIFOSET(fd,19);
+        }
+    }
+    return 1;
 }
 
 /**
@@ -1084,7 +1101,8 @@ int chmapif_parse_reqauth(int fd, int id){
  * @return : 0 not enough data received, 1 success
  */
 int chmapif_parse_updmapip(int fd, int id){
-	if (RFIFOREST(fd) < 6) return 0;
+	if (RFIFOREST(fd) < 6) 
+            return -1;
 	map_server[id].ip = ntohl(RFIFOL(fd, 2));
 	ShowInfo("Updated IP address of map-server #%d to %d.%d.%d.%d.\n", id, CONVIP(map_server[id].ip));
 	RFIFOSKIP(fd,6);
@@ -1098,7 +1116,7 @@ int chmapif_parse_updmapip(int fd, int id){
  */
 int chmapif_parse_fw_configstats(int fd){
 	if( RFIFOREST(fd) < RFIFOW(fd,4) )
-		return 0;/* packet wasn't fully received yet (still fragmented) */
+		return -1;/* packet wasn't fully received yet (still fragmented) */
 	else {
 		int sfd;/* stat server fd */
 		RFIFOSKIP(fd, 2);/* we skip first 2 bytes which are the 0x3008, so we end up with a buffer equal to the one we send */
@@ -1119,7 +1137,258 @@ int chmapif_parse_fw_configstats(int fd){
 	return 1;
 }
 
+int chmapif_parse_updfamelist(int fd){
+    if (RFIFOREST(fd) < 11)
+        return -1;
+    {
+            int cid = RFIFOL(fd, 2);
+            int fame = RFIFOL(fd, 6);
+            char type = RFIFOB(fd, 10);
+            int size;
+            struct fame_list* list;
+            int player_pos;
+            int fame_pos;
+
+            switch(type)
+            {
+                    case 1:  size = fame_list_size_smith;   list = smith_fame_list;   break;
+                    case 2:  size = fame_list_size_chemist; list = chemist_fame_list; break;
+                    case 3:  size = fame_list_size_taekwon; list = taekwon_fame_list; break;
+                    default: size = 0;                      list = NULL;              break;
+            }
+
+            ARR_FIND(0, size, player_pos, list[player_pos].id == cid);// position of the player
+            ARR_FIND(0, size, fame_pos, list[fame_pos].fame <= fame);// where the player should be
+
+            if( player_pos == size && fame_pos == size )
+                    ;// not on list and not enough fame to get on it
+            else if( fame_pos == player_pos )
+            {// same position
+                    list[player_pos].fame = fame;
+                    chmapif_update_fame_list(type, player_pos, fame);
+            }
+            else
+            {// move in the list
+                    if( player_pos == size )
+                    {// new ranker - not in the list
+                            ARR_MOVE(size - 1, fame_pos, list, struct fame_list);
+                            list[fame_pos].id = cid;
+                            list[fame_pos].fame = fame;
+                            char_loadName(cid, list[fame_pos].name);
+                    }
+                    else
+                    {// already in the list
+                            if( fame_pos == size )
+                                    --fame_pos;// move to the end of the list
+                            ARR_MOVE(player_pos, fame_pos, list, struct fame_list);
+                            list[fame_pos].fame = fame;
+                    }
+                    chmapif_send_fame_list(-1);
+            }
+
+            RFIFOSKIP(fd,11);
+    }
+    return 1;
+}
+
+//HZ 0x2b29 <aid>L <bank_vault>L
+int chmapif_BankingAck(int32 account_id, int32 bank_vault){
+	unsigned char buf[11];
+	WBUFW(buf,0) = 0x2b29;
+	WBUFL(buf,2) = account_id;
+	WBUFL(buf,6) = bank_vault;
+	chmapif_sendall(buf, 10); //inform all maps-attached
+	return 1;
+}
+
+
+/*
+ * HZ 0x2b2b
+ * Transmist vip data to mapserv
+ */
+int chmapif_vipack(int mapfd, uint32 aid, uint32 vip_time, uint8 isvip, uint8 isgm, uint32 groupid) {
+#ifdef VIP_ENABLE
+	uint8 buf[16];
+	WBUFW(buf,0) = 0x2b2b;
+	WBUFL(buf,2) = aid;
+	WBUFL(buf,6) = vip_time;
+	WBUFB(buf,10) = isvip;
+	WBUFB(buf,11) = isgm;
+	WBUFL(buf,12) = groupid;
+	chmapif_send(mapfd,buf,16);  // inform the mapserv back
+#endif
+	return 0;
+}
+
+int chmapif_parse_reqcharban(int fd){
+	if (RFIFOREST(fd) < 10+NAME_LENGTH)
+		return -1;
+	else {
+		//int aid = RFIFOL(fd,2); aid of player who as requested the ban
+		int timediff = RFIFOL(fd,6);
+		const char* name = (char*)RFIFOP(fd,10); // name of the target character
+		RFIFOSKIP(fd,10+NAME_LENGTH);
+
+		if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `account_id`,`char_id`,`unban_time` FROM `%s` WHERE `name` = '%s'", schema_config.char_db, name) )
+			Sql_ShowDebug(sql_handle);
+		else if( Sql_NumRows(sql_handle) == 0 ){
+			return -1; // 1-player not found
+		}
+		else if( SQL_SUCCESS != Sql_NextRow(sql_handle) ){
+			Sql_ShowDebug(sql_handle);
+			Sql_FreeResult(sql_handle);
+			return -1;
+		} else {
+			int t_cid=0,t_aid=0;
+			char* data;
+			time_t unban_time;
+			time_t now = time(NULL);
+			SqlStmt* stmt = SqlStmt_Malloc(sql_handle);
+
+			Sql_GetData(sql_handle, 0, &data, NULL); t_aid = atoi(data);
+			Sql_GetData(sql_handle, 1, &data, NULL); t_cid = atoi(data);
+			Sql_GetData(sql_handle, 2, &data, NULL); unban_time = atol(data);
+			Sql_FreeResult(sql_handle);
+
+			if(timediff<0 && unban_time==0) return 0; //attemp to reduce time of a non banned account ?!?
+			else if(unban_time<now) unban_time=now; //new entry
+			unban_time += timediff; //alterate the time
+			if( unban_time < now ) unban_time=0; //we have totally reduce the time
+
+			if( SQL_SUCCESS != SqlStmt_Prepare(stmt,
+					  "UPDATE `%s` SET `unban_time` = ? WHERE `char_id` = ? LIMIT 1",
+					  schema_config.char_db)
+				|| SQL_SUCCESS != SqlStmt_BindParam(stmt,  0, SQLDT_LONG,   (void*)&unban_time,   sizeof(unban_time))
+				|| SQL_SUCCESS != SqlStmt_BindParam(stmt,  1, SQLDT_INT,    (void*)&t_cid,     sizeof(t_cid))
+				|| SQL_SUCCESS != SqlStmt_Execute(stmt)
+
+				) {
+				SqlStmt_ShowDebug(stmt);
+				SqlStmt_Free(stmt);
+				return -1;
+			}
+			SqlStmt_Free(stmt);
+
+			// condition applies; send to all map-servers to disconnect the player
+			if( unban_time > now ) {
+					unsigned char buf[11];
+					WBUFW(buf,0) = 0x2b14;
+					WBUFL(buf,2) = t_cid;
+					WBUFB(buf,6) = 2;
+					WBUFL(buf,7) = (unsigned int)unban_time;
+					chmapif_sendall(buf, 11);
+					// disconnect player if online on char-server
+					char_disconnect_player(t_aid);
+			}
+		}
+	}
+	return 0;
+}
+
+int chmapif_parse_reqcharunban(int fd){
+	if (RFIFOREST(fd) < 6)
+            return -1;
+	else {
+		int cid = RFIFOL(fd,2);
+		RFIFOSKIP(fd,6);
+
+		if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `unban_time` = '0' WHERE `char_id` = '%d' LIMIT 1", schema_config.char_db, cid) ) {
+			Sql_ShowDebug(sql_handle);
+			return -1;
+		}
+	}
+	return 0;
+}
 
+/** [Cydh]
+* Get bonus_script data(s) from table to load
+* @param fd
+*/
+int chmapif_bonus_script_get(int fd) {
+	if (RFIFOREST(fd) < 6)
+            return -1;
+	else {
+		int cid;
+		cid = RFIFOL(fd,2);
+		RFIFOSKIP(fd,6);
+
+		if (SQL_ERROR == Sql_Query(sql_handle,"SELECT `script`, `tick`, `flag`, `type`, `icon` FROM `%s` WHERE `char_id`='%d'",
+			schema_config.bonus_script_db,cid))
+		{
+			Sql_ShowDebug(sql_handle);
+			return 0;
+		}
+		if (Sql_NumRows(sql_handle) > 0) {
+			struct bonus_script_data bsdata;
+			int count;
+			char *data;
+
+			WFIFOHEAD(fd,10+50*sizeof(struct bonus_script_data));
+			WFIFOW(fd,0) = 0x2b2f;
+			WFIFOL(fd,4) = cid;
+			for (count = 0; count < 20 && SQL_SUCCESS == Sql_NextRow(sql_handle); ++count) {
+				Sql_GetData(sql_handle,0,&data,NULL); memcpy(bsdata.script,data,strlen(data)+1);
+				Sql_GetData(sql_handle,1,&data,NULL); bsdata.tick = atoi(data);
+				Sql_GetData(sql_handle,2,&data,NULL); bsdata.flag = atoi(data);
+				Sql_GetData(sql_handle,3,&data,NULL); bsdata.type = atoi(data);
+				Sql_GetData(sql_handle,4,&data,NULL); bsdata.icon = atoi(data);
+				memcpy(WFIFOP(fd,10+count*sizeof(struct bonus_script_data)),&bsdata,sizeof(struct bonus_script_data));
+			}
+			if (count >= 20)
+				ShowWarning("Too many bonus_script for %d, some of them were not loaded.\n",cid);
+			if (count > 0) {
+				WFIFOW(fd,2) = 10 + count*sizeof(struct bonus_script_data);
+				WFIFOW(fd,8) = count;
+				WFIFOSET(fd,WFIFOW(fd,2));
+
+				//Clear the data once loaded.
+				if (SQL_ERROR == Sql_Query(sql_handle,"DELETE FROM `%s` WHERE `char_id`='%d'",schema_config.bonus_script_db,cid))
+					Sql_ShowDebug(sql_handle);
+				ShowInfo("Loaded %d bonus_script for char_id: %d\n",count,cid);
+			}
+		}
+		Sql_FreeResult(sql_handle);
+	}
+        return 1;
+}
+
+/** [Cydh]
+* Save bonus_script data(s) to the table
+* @param fd
+*/
+int chmapif_bonus_script_save(int fd) {
+	if (RFIFOREST(fd) < 4 || RFIFOREST(fd) < RFIFOW(fd,2))
+            return -1;
+	else {
+		int count, cid;
+
+		cid = RFIFOL(fd,4);
+		count = RFIFOW(fd,8);
+
+		if (count > 0) {
+			struct bonus_script_data bs;
+			StringBuf buf;
+			int i;
+			char esc_script[MAX_BONUS_SCRIPT_LENGTH] = "";
+
+			StringBuf_Init(&buf);
+			StringBuf_Printf(&buf,"INSERT INTO `%s` (`char_id`, `script`, `tick`, `flag`, `type`, `icon`) VALUES ",schema_config.bonus_script_db);
+			for (i = 0; i < count; ++i) {
+				memcpy(&bs,RFIFOP(fd,10+i*sizeof(struct bonus_script_data)),sizeof(struct bonus_script_data));
+				Sql_EscapeString(sql_handle,esc_script,bs.script);
+				if (i > 0)
+					StringBuf_AppendStr(&buf,", ");
+				StringBuf_Printf(&buf,"('%d','%s','%d','%d','%d','%d')",cid,esc_script,bs.tick,bs.flag,bs.type,bs.icon);
+			}
+			if (SQL_ERROR == Sql_QueryStr(sql_handle,StringBuf_Value(&buf)))
+				Sql_ShowDebug(sql_handle);
+			StringBuf_Destroy(&buf);
+			ShowInfo("Saved %d bonus_script for char_id: %d\n",count,cid);
+		}
+		RFIFOSKIP(fd,RFIFOW(fd,2));
+	}
+        return 1;
+}
 
 /**
  * Entry point from map-server to char-server.
@@ -1130,6 +1399,7 @@ int chmapif_parse_fw_configstats(int fd){
  */
 int chmapif_parse(int fd){
 	int id; //mapserv id
+        int next=0;
 	ARR_FIND( 0, ARRAYLENGTH(map_server), id, map_server[id].fd == fd );
 	if( id == ARRAYLENGTH(map_server) )
 	{// not a map server
@@ -1146,45 +1416,51 @@ int chmapif_parse(int fd){
 	}
 
 	while(RFIFOREST(fd) >= 2){
-		switch(RFIFOW(fd,0)){
-		case 0x2afa: chmapif_parse_getmapname(fd,id); break;
-		case 0x2afc: chmapif_parse_askscdata(fd); break;
-		case 0x2afe: chmapif_parse_getusercount(fd,id); break; //get nb user
-		case 0x2aff: chmapif_parse_regmapuser(fd,id); break; //register users
-		case 0x2b01: chmapif_parse_reqsavechar(fd,id); break;
-		case 0x2b02: chmapif_parse_authok(fd); break;
-		case 0x2b05: chmapif_parse_reqchangemapserv(fd); break;
-		case 0x2b07: chmapif_parse_askrmfriend(fd); break;
-		case 0x2b08: chmapif_parse_reqcharname(fd); break;
-		case 0x2b0a: chmapif_parse_req_skillcooldown(fd); break;
-		case 0x2b0c: chmapif_parse_reqnewemail(fd); break;
-		case 0x2b0e: chmapif_parse_fwlog_changestatus(fd); break;
-		case 0x2b10: chmapif_parse_updfamelist(fd); break;
-		case 0x2b11: chmapif_parse_reqdivorce(fd); break;
-		case 0x2b15: chmapif_parse_req_saveskillcooldown(fd); break;
-		case 0x2b16: chmapif_parse_updmapinfo(fd); break;
-		case 0x2b17: chmapif_parse_setcharoffline(fd); break;
-		case 0x2b18: chmapif_parse_setalloffline(fd,id); break;
-		case 0x2b19: chmapif_parse_setcharonline(fd,id); break;
-		case 0x2b1a: chmapif_parse_reqfamelist(fd); break;
-		case 0x2b1c: chmapif_parse_save_scdata(fd); break;
-		case 0x2b23: chmapif_parse_keepalive(fd); break;
-		case 0x2b26: chmapif_parse_reqauth(fd,id); break;
-		case 0x2736: chmapif_parse_updmapip(fd,id); break;
-		case 0x3008: chmapif_parse_fw_configstats(fd); break;
-		
-		default:
-		{
-			// inter server - packet
-			int r = inter_parse_frommap(fd);
-			if (r == 1) break;		// processed
-			if (r == 2) return 0;	// need more packet
-			// no inter server packet. no char server packet -> disconnect
-			ShowError("Unknown packet 0x%04x from map server, disconnecting.\n", RFIFOW(fd,0));
-			set_eof(fd);
-			return 0;
-		}
-		} // switch
+            if(next==-1) return 0; //avoid processing rest of packet
+            
+            switch(RFIFOW(fd,0)){
+            case 0x2736: next=chmapif_parse_updmapip(fd,id); break;
+            case 0x2afa: next=chmapif_parse_getmapname(fd,id); break;
+            case 0x2afc: next=chmapif_parse_askscdata(fd); break;
+            case 0x2afe: next=chmapif_parse_getusercount(fd,id); break; //get nb user
+            case 0x2aff: next=chmapif_parse_regmapuser(fd,id); break; //register users
+            case 0x2b01: next=chmapif_parse_reqsavechar(fd,id); break;
+            case 0x2b02: next=chmapif_parse_authok(fd); break;
+            case 0x2b05: next=chmapif_parse_reqchangemapserv(fd); break;
+            case 0x2b07: next=chmapif_parse_askrmfriend(fd); break;
+            case 0x2b08: next=chmapif_parse_reqcharname(fd); break;
+            case 0x2b0a: next=chmapif_parse_req_skillcooldown(fd); break;
+            case 0x2b0c: next=chmapif_parse_reqnewemail(fd); break;
+            case 0x2b0e: next=chmapif_parse_req_alter_acc(fd); break;
+            case 0x2b10: next=chmapif_parse_updfamelist(fd); break;
+            case 0x2b11: next=chmapif_parse_reqdivorce(fd); break;
+            case 0x2b15: next=chmapif_parse_req_saveskillcooldown(fd); break;
+            case 0x2b16: next=chmapif_parse_updmapinfo(fd); break;
+            case 0x2b17: next=chmapif_parse_setcharoffline(fd); break;
+            case 0x2b18: next=chmapif_parse_setalloffline(fd,id); break;
+            case 0x2b19: next=chmapif_parse_setcharonline(fd,id); break;
+            case 0x2b1a: next=chmapif_parse_reqfamelist(fd); break;
+            case 0x2b1c: next=chmapif_parse_save_scdata(fd); break;
+            case 0x2b23: next=chmapif_parse_keepalive(fd); break;
+            case 0x2b26: next=chmapif_parse_reqauth(fd,id); break;
+            case 0x2b28: chmapif_parse_reqcharban(fd); break; //charban
+            case 0x2b2a: chmapif_parse_reqcharunban(fd); break; //charunban
+            //case 0x2b2c: /*free*/; break;
+            case 0x2b2d: chmapif_bonus_script_get(fd); break; //Load data
+            case 0x2b2e: chmapif_bonus_script_save(fd); break;//Save data
+            case 0x3008: next=chmapif_parse_fw_configstats(fd); break;
+            default:
+            {
+                    // inter server - packet
+                    int r = inter_parse_frommap(fd);
+                    if (r == 1) break;		// processed
+                    if (r == 2) return 0;	// need more packet
+                    // no inter server packet. no char server packet -> disconnect
+                    ShowError("Unknown packet 0x%04x from map server, disconnecting.\n", RFIFOW(fd,0));
+                    set_eof(fd);
+                    return 0;
+            }
+            } // switch
 	} // while
 
 	return 1;

+ 7 - 0
src/char/char_mapif.h

@@ -48,6 +48,13 @@ int chmapif_parse_reqauth(int fd, int id);
 int chmapif_parse_updmapip(int fd, int id);
 int chmapif_parse_fw_configstats(int fd);
 
+int chmapif_BankingAck(int32 account_id, int32 bank_vault);
+int chmapif_vipack(int mapfd, uint32 aid, uint32 vip_time, uint8 isvip, uint8 isgm, uint32 groupid);
+int chmapif_parse_reqcharban(int fd);
+int chmapif_parse_reqcharunban(int fd);
+int chmapif_bonus_script_get(int fd);
+int chmapif_bonus_script_save(int fd);
+
 int chmapif_parse(int fd);
 int chmapif_init(int fd);
 void chmapif_server_init(int id);

Alguns ficheiros não foram mostrados porque muitos ficheiros mudaram neste diff