From 16d301eb02e84f03df387db15750e4cb52beaf9f Mon Sep 17 00:00:00 2001 From: skotlex Date: Fri, 24 Nov 2006 12:41:38 +0000 Subject: - Added all the missing FIFOHEADs in the login/sql servers (required for TURBO support) - Fixed the fact that the TURBO code breaks when you attempt to handle more than one connection at a time within the same function. However this broke map-server compilation, therefore, don't use TURBO yet! It needs more fixing (and I need more time to fix it) - While at it, cleaned a few packet implementations in the char/login servers which were not only ugly, but had some really stupid flaws within (stuff like escaping a string, and then using the non-escaped variable to insert to SQL? T_T) And will someone explain me why the TXT servers are coded much more cleanly, and without such horribly broken code as I find in the SQL ones? T_T; git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@9307 54d463be-8e91-2dee-dedb-b68131a5f0ec --- src/login_sql/login.c | 72 +++++++++++++++++++++++++++++++++++---------------- 1 file changed, 50 insertions(+), 22 deletions(-) (limited to 'src/login_sql') diff --git a/src/login_sql/login.c b/src/login_sql/login.c index 8133849d7..a0b3770ed 100644 --- a/src/login_sql/login.c +++ b/src/login_sql/login.c @@ -268,8 +268,9 @@ void send_GM_accounts(int fd) { charif_sendallwos(-1, buf, len); else { + WFIFOHEAD(fd, len); memcpy(WFIFOP(fd,0), buf, len); - WFIFOSET(fd,len); + WFIFOSET(fd, len); } return; } @@ -548,6 +549,7 @@ int charif_sendallwos(int sfd, unsigned char *buf, unsigned int len) { c = 0; for(i = 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); @@ -898,6 +900,7 @@ int parse_fromchar(int fd){ unsigned char *p = (unsigned char *) &session[fd]->client_addr.sin_addr.s_addr; unsigned long ipl = session[fd]->client_addr.sin_addr.s_addr; char ip[16]; + RFIFOHEAD(fd); sprintf(ip, "%d.%d.%d.%d", p[0], p[1], p[2], p[3]); @@ -949,6 +952,7 @@ int parse_fromchar(int fd){ return 0; { int account_id; + WFIFOHEAD(fd,51); account_id = RFIFOL(fd,2); // speed up for(i=0;i= 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); @@ -1499,6 +1510,7 @@ int parse_login(int fd) { unsigned char *p = (unsigned char *) &session[fd]->client_addr.sin_addr.s_addr; unsigned long ipl = session[fd]->client_addr.sin_addr.s_addr; char ip[16]; + RFIFOHEAD(fd); sprintf(ip, "%d.%d.%d.%d", p[0], p[1], p[2], p[3]); @@ -1579,11 +1591,12 @@ int parse_login(int fd) { // int gm_level = isGM(account.account_id); // removed by [zzo] if (min_level_to_connect > account.level) { + WFIFOHEAD(fd,3); WFIFOW(fd,0) = 0x81; WFIFOB(fd,2) = 1; // 01 = Server closed WFIFOSET(fd,3); } else { - + WFIFOHEAD(fd,47+32*MAX_SERVERS); if (p[0] != 127 && log_login) { sprintf(tmpsql,"INSERT DELAYED INTO `%s`(`time`,`ip`,`user`,`rcode`,`log`) VALUES (NOW(), '%u', '%s','100', 'login ok')", loginlog_db, (unsigned int)ntohl(ipl), t_uid); //query @@ -1641,6 +1654,7 @@ int parse_login(int fd) { } else { char tmp_sql[512]; char error[64]; + WFIFOHEAD(fd,23); if (log_login) { sprintf(tmp_sql,"INSERT DELAYED INTO `%s`(`time`,`ip`,`user`,`rcode`,`log`) VALUES (NOW(), '%u', '%s', '%d','login failed : %%s')", loginlog_db, (unsigned int)ntohl(ipl), t_uid, result); @@ -1817,12 +1831,16 @@ int parse_login(int fd) { session[fd]->eof = 1; return 0; } - ShowDebug("Request Password key -%s\n",md5key); - RFIFOSKIP(fd,2); + { + WFIFOHEAD(fd,4+md5keylen); WFIFOW(fd,0)=0x01dc; WFIFOW(fd,2)=4+md5keylen; memcpy(WFIFOP(fd,4),md5key,md5keylen); WFIFOSET(fd,WFIFOW(fd,2)); + + ShowDebug("Request Password key -%s\n",md5key); + RFIFOSKIP(fd,2); + } break; case 0x2710: // request Char-server connection @@ -1830,9 +1848,27 @@ int parse_login(int fd) { return 0; { unsigned char* server_name; + 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 = RFIFOP(fd,60); + server_name[20] = '\0'; + ShowInfo("server connection request %s @ %d.%d.%d.%d:%d (%d.%d.%d.%d)\n", + server_name, RFIFOB(fd, 54), RFIFOB(fd, 55), RFIFOB(fd, 56), RFIFOB(fd, 57), RFIFOW(fd, 58), + p[0], p[1], p[2], p[3]); + jstrescapecpy(t_uid,server_name); if (log_login) { - sprintf(tmpsql,"INSERT DELAYED INTO `%s`(`time`,`ip`,`user`,`rcode`,`log`) VALUES (NOW(), '%u', '%s@%s','100', 'charserver - %s@%d.%d.%d.%d:%d')", loginlog_db, (unsigned int)ntohl(ipl), RFIFOP(fd, 2),RFIFOP(fd, 60),RFIFOP(fd, 60), RFIFOB(fd, 54), RFIFOB(fd, 55), RFIFOB(fd, 56), RFIFOB(fd, 57), RFIFOW(fd, 58)); + 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@%d.%d.%d.%d:%d')", + loginlog_db, (unsigned int)ntohl(ipl), + t_login, t_uid, t_uid, + RFIFOB(fd, 54), RFIFOB(fd, 55), RFIFOB(fd, 56), RFIFOB(fd, 57), + RFIFOW(fd, 58)); //query if(mysql_query(&mysql_handle, tmpsql)) { @@ -1840,15 +1876,6 @@ int parse_login(int fd) { ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmpsql); } } - ShowInfo("server connection request %s @ %d.%d.%d.%d:%d (%d.%d.%d.%d)\n", - RFIFOP(fd, 60), RFIFOB(fd, 54), RFIFOB(fd, 55), RFIFOB(fd, 56), RFIFOB(fd, 57), RFIFOW(fd, 58), - p[0], p[1], p[2], p[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 = RFIFOP(fd,60); result = mmo_auth(&account, fd); //printf("Result: %d - Sex: %d - Account ID: %d\n",result,account.sex,(int) account.account_id); @@ -1857,7 +1884,7 @@ int parse_login(int fd) { memset(&server[account.account_id], 0, sizeof(struct mmo_char_server)); server[account.account_id].ip=RFIFOL(fd,54); server[account.account_id].port=RFIFOW(fd,58); - memcpy(server[account.account_id].name,RFIFOP(fd,60),20); + 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); @@ -1869,9 +1896,8 @@ int parse_login(int fd) { ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmpsql); } - jstrescapecpy(t_uid,server[account.account_id].name); sprintf(tmpsql,"INSERT INTO `sstatus`(`index`,`name`,`user`) VALUES ( '%ld', '%s', '%d')", - account.account_id, server[account.account_id].name,0); + account.account_id, t_uid,0); //query if(mysql_query(&mysql_handle, tmpsql)) { ShowSQL("DB error - %s\n",mysql_error(&mysql_handle)); @@ -1894,6 +1920,8 @@ int parse_login(int fd) { return 0; case 0x7530: // request Athena information + { + WFIFOHEAD(fd,10); WFIFOW(fd,0)=0x7531; WFIFOB(fd,2)=ATHENA_MAJOR_VERSION; WFIFOB(fd,3)=ATHENA_MINOR_VERSION; @@ -1906,7 +1934,7 @@ int parse_login(int fd) { RFIFOSKIP(fd,2); ShowInfo ("Athena version check...\n"); break; - + } case 0x7532: ShowStatus ("End of connection (ip: %s)" RETCODE, ip); session[fd]->eof = 1; -- cgit v1.2.3-70-g09d2