diff options
author | ultramage <ultramage@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2007-05-28 19:39:24 +0000 |
---|---|---|
committer | ultramage <ultramage@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2007-05-28 19:39:24 +0000 |
commit | 437a47840140d324d8a1555144cd9628d897d70e (patch) | |
tree | 5c108204ee261be8d2484fdac7b71a5cc2399ebe /src | |
parent | cb1131db4cde40c0352e6c75069defab06128c93 (diff) | |
download | hercules-437a47840140d324d8a1555144cd9628d897d70e.tar.gz hercules-437a47840140d324d8a1555144cd9628d897d70e.tar.bz2 hercules-437a47840140d324d8a1555144cd9628d897d70e.tar.xz hercules-437a47840140d324d8a1555144cd9628d897d70e.zip |
- Fixed an infinite char-server loop on the map connection
- Cleaned up the charserver a bit
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@10641 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src')
-rw-r--r-- | src/char/char.c | 56 | ||||
-rw-r--r-- | src/char_sql/char.c | 35 | ||||
-rw-r--r-- | src/char_sql/char.h | 7 |
3 files changed, 51 insertions, 47 deletions
diff --git a/src/char/char.c b/src/char/char.c index 9d02641da..fab36332b 100644 --- a/src/char/char.c +++ b/src/char/char.c @@ -74,7 +74,7 @@ char backup_txt[1024]="save/backup.txt"; //By zanetheinsane char friends_txt[1024]="save/friends.txt"; // davidsiaw #ifndef TXT_SQL_CONVERT char backup_txt_flag = 0; // The backup_txt file was created because char deletion bug existed. Now it's finish and that take a lot of time to create a second file when there are a lot of characters. => option By [Yor] -char unknown_char_name[1024] = "Unknown"; +char unknown_char_name[1024] = "Unknown"; // Name to use when the requested name cannot be determined char char_log_filename[1024] = "log/char.log"; char db_path[1024]="db"; @@ -2658,6 +2658,21 @@ void char_update_fame_list(int type, int index, int fame) mapif_sendall(buf, 8); } +//Loads a character's name and stores it in the buffer given (must be NAME_LENGTH in size) +//Returns 1 on found, 0 on not found (buffer is filled with Unknown char name) +int char_loadName(int char_id, char* name) +{ + int j; + for( j = 0; j < char_num && char_dat[j].status.char_id != char_id; ++j ) + ;// find char + if( j < char_num ) + strncpy(name, char_dat[j].status.name, NAME_LENGTH); + else + strncpy(name, unknown_char_name, NAME_LENGTH); + + return (j < char_num) ? 1 : 0; +} + int search_mapserver(unsigned short map, uint32 ip, uint16 port); int parse_frommap(int fd) @@ -2948,20 +2963,16 @@ int parse_frommap(int fd) } break; - case 0x2b08: // char name check + case 0x2b08: // char name request if (RFIFOREST(fd) < 6) return 0; - for(i = 0; i < char_num; i++) { - if (char_dat[i].status.char_id == RFIFOL(fd,2)) - break; - } + + WFIFOHEAD(fd,30); WFIFOW(fd,0) = 0x2b09; WFIFOL(fd,2) = RFIFOL(fd,2); - if (i != char_num) - memcpy(WFIFOP(fd,6), char_dat[i].status.name, NAME_LENGTH); - else - memcpy(WFIFOP(fd,6), unknown_char_name, NAME_LENGTH); - WFIFOSET(fd,6+NAME_LENGTH); + char_loadName((int)RFIFOL(fd,2), (char*)WFIFOP(fd,6)); + WFIFOSET(fd,30); + RFIFOSKIP(fd,6); break; @@ -3111,17 +3122,20 @@ int parse_frommap(int fd) int fame = RFIFOL(fd, 6); char type = RFIFOB(fd, 10); int size; - struct fame_list *list = NULL; + struct fame_list* list; 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; break; + 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; } if( size == 0 ) - break;// No list + {// No list + RFIFOSKIP(fd,11); + break; + } for( i = 0; i < size; ++i ) { if( list[i].id != cid ) @@ -3162,17 +3176,11 @@ int parse_frommap(int fd) if( i == size && fame >= list[size - 1].fame ) {// not on list and has enough fame - size_t j; for( i = 0; fame < list[i].fame; ++i ) ;// get target position list[i].id = cid; list[i].fame = fame; - for( j = 0; j < char_num && char_dat[j].status.char_id != cid; ++j ) - ;// find char - if( j < char_num ) - strncpy(list[i].name, char_dat[j].status.name, NAME_LENGTH); - else - strncpy(list[i].name, "Unknown", NAME_LENGTH); + char_loadName(list[i].id, list[i].name); char_send_fame_list(-1); } diff --git a/src/char_sql/char.c b/src/char_sql/char.c index 6dba28992..5031a6c26 100644 --- a/src/char_sql/char.c +++ b/src/char_sql/char.c @@ -96,7 +96,7 @@ int char_new = 1; int char_new_display = 0; int name_ignoring_case = 0; // Allow or not identical name for characters but with a different case by [Yor] int char_name_option = 0; // Option to know which letters/symbols are authorised in the name of a character (0: all, 1: only those in char_name_letters, 2: all EXCEPT those in char_name_letters) by [Yor] -char unknown_char_name[NAME_LENGTH] = "Unknown"; +char unknown_char_name[NAME_LENGTH] = "Unknown"; // Name to use when the requested name cannot be determined char char_name_letters[1024] = ""; // list of letters/symbols used to authorise or not a name of a character. by [Yor] //The following are characters that are trimmed regardless because they cause confusion and problems on the servers. [Skotlex] #define TRIM_CHARS "\032\t\x0A\x0D " @@ -2296,8 +2296,6 @@ void char_update_fame_list(int type, int index, int fame) mapif_sendall(buf, 8); } -int search_mapserver(unsigned short map, uint32 ip, uint16 port); - //Loads a character's name and stores it in the buffer given (must be NAME_LENGTH in size) //Returns 1 on found, 0 on not found (buffer is filled with Unknown char name) int char_loadName(int char_id, char* name) @@ -2316,9 +2314,11 @@ int char_loadName(int char_id, char* name) else memcpy(name, unknown_char_name, NAME_LENGTH); if (sql_res) mysql_free_result(sql_res); - return sql_row?1:0; + + return (sql_row) ? 1 : 0; } +int search_mapserver(unsigned short map, uint32 ip, uint16 port); int parse_frommap(int fd) { @@ -2659,19 +2659,17 @@ int parse_frommap(int fd) } break; - case 0x2b08: // char name check + case 0x2b08: // char name request if (RFIFOREST(fd) < 6) return 0; - { - char name[NAME_LENGTH]; - char_loadName((int)RFIFOL(fd,2), name); + WFIFOHEAD(fd,30); WFIFOW(fd,0) = 0x2b09; WFIFOL(fd,2) = RFIFOL(fd,2); - memcpy(WFIFOP(fd,6), name, NAME_LENGTH); + char_loadName((int)RFIFOL(fd,2), (char*)WFIFOP(fd,6)); WFIFOSET(fd,30); + RFIFOSKIP(fd,6); - } break; case 0x2b0a: // request to become GM @@ -2823,17 +2821,20 @@ int parse_frommap(int fd) int fame = RFIFOL(fd, 6); char type = RFIFOB(fd, 10); int size; - struct fame_list *list = NULL; - + struct fame_list* list; + 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; break; + 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; } if( size == 0 ) - break;// No list + {// No list + RFIFOSKIP(fd,11); + break; + } for( i = 0; i < size; ++i ) { if( list[i].id != cid ) diff --git a/src/char_sql/char.h b/src/char_sql/char.h index b77fb596c..54f0bbd9e 100644 --- a/src/char_sql/char.h +++ b/src/char_sql/char.h @@ -43,12 +43,9 @@ enum { TABLE_STORAGE, TABLE_GUILD_STORAGE, }; -struct itemtemp{ - struct itemtmp equip[MAX_GUILD_STORAGE],notequip[MAX_GUILD_STORAGE]; -}; + int memitemdata_to_sql(struct itemtmp mapitem[], int count, int char_id,int tableswitch); -//int memitemdataNEW_to_sql(struct itemtmp mapitem[], int count, int char_id,int tableswitch); int mapif_sendall(unsigned char *buf,unsigned int len); int mapif_sendallwos(int fd,unsigned char *buf,unsigned int len); int mapif_send(int fd,unsigned char *buf,unsigned int len); @@ -57,8 +54,6 @@ 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 char_loadName(int char_id, char* name); - int request_accreg2(int account_id, int char_id); int save_accreg2(unsigned char* buf, int len); |