Removed some redundant code from the sql charserver.

Fixed a sql-charserver @block crash (missing Sql_NextRow() call).
Probably fixed 'random junk' being displayed in @changesex reply text.

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@11324 54d463be-8e91-2dee-dedb-b68131a5f0ec
This commit is contained in:
ultramage 2007-09-28 14:37:31 +00:00
parent d7a44b3d83
commit caaa7bde2f
4 changed files with 110 additions and 149 deletions

View File

@ -105,7 +105,7 @@
85: Invalid time for ban command.
86: Sorry, but a player name have at least 4 characters.
87: Sorry, but a player name has 23 characters maximum.
88: Character name sent to char-server to ask it.
88: Sending request to login server...
89: Sorry, it's already the night. Impossible to execute the command.
90: Sorry, it's already the day. Impossible to execute the command.
91: Character's base level can't go any higher.

View File

@ -2508,62 +2508,55 @@ int parse_frommap(int fd)
RFIFOSKIP(fd, 86);
break;
case 0x2b0e: // Request from map-server to change an account's status (all operations are transmitted to login-server)
case 0x2b0e: // Request from map-server to change an account's status (will just be forwarded to login server)
if (RFIFOREST(fd) < 44)
return 0;
{
char character_name[NAME_LENGTH];
char esc_name[NAME_LENGTH*2+1];// escaped character name
int acc = RFIFOL(fd,2); // account_id of who ask (-1 if nobody)
int acc = 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
memcpy(character_name, RFIFOP(fd,6), NAME_LENGTH);
character_name[NAME_LENGTH-1] = '\0';
Sql_EscapeStringLen(sql_handle, esc_name, character_name, strnlen(character_name, NAME_LENGTH));
// prepare answer
WFIFOHEAD(fd,34);
WFIFOW(fd,0) = 0x2b0f; // answer
WFIFOL(fd,2) = acc; // who want do operation
WFIFOW(fd,30) = RFIFOW(fd, 30); // type of operation: 1-block, 2-ban, 3-unblock, 4-unban
int result = 0; // 0-login-server request done, 1-player not found, 2-gm level too low, 3-login-server offline
char esc_name[NAME_LENGTH*2+1];
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'", char_db, esc_name) )
Sql_ShowDebug(sql_handle);
if( Sql_NumRows(sql_handle) > 0 )
else
if( Sql_NumRows(sql_handle) == 0 )
{
char* data;
size_t len;
// name
Sql_GetData(sql_handle, 1, &data, &len);
if( len >= NAME_LENGTH )
memcpy(WFIFOP(fd,6), data, NAME_LENGTH);
result = 1; // 1-player not found
}
else
if( SQL_SUCCESS != Sql_NextRow(sql_handle) )
Sql_ShowDebug(sql_handle);
else
{
memcpy(WFIFOP(fd,6), data, len);
memset(WFIFOP(fd,6+len), 0, NAME_LENGTH - len);
}
// account_id
Sql_GetData(sql_handle, 0, &data, NULL);
WFIFOW(fd,32) = 0; // answer: 0-login-server request done, 1-player not found, 2-gm level too low, 3-login-server offline
switch(RFIFOW(fd, 30)) {
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));
if( login_fd <= 0 )
result = 3; // 3-login-server offline
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(atoi(data))) {
if (login_fd > 0) { // don't send request if no login-server
WFIFOHEAD(login_fd,10);
WFIFOW(login_fd,0) = 0x2724;
WFIFOL(login_fd,2) = atoi(data); // account value
WFIFOL(login_fd,6) = 5; // status of the account
WFIFOL(login_fd,2) = account_id;
WFIFOL(login_fd,6) = 5; // new account status
WFIFOSET(login_fd,10);
} else
WFIFOW(fd,32) = 3; // answer: 0-login-server request done, 1-player not found, 2-gm level too low, 3-login-server offline
} else
WFIFOW(fd,32) = 2; // answer: 0-login-server request done, 1-player not found, 2-gm level too low, 3-login-server offline
break;
case 2: // ban
if (acc == -1 || isGM(acc) >= isGM(atoi(data))) {
if (login_fd > 0) { // don't send request if no login-server
WFIFOHEAD(login_fd,18);
WFIFOW(login_fd, 0) = 0x2725;
WFIFOL(login_fd, 2) = atoi(data); // account value
WFIFOL(login_fd, 2) = account_id;
WFIFOW(login_fd, 6) = RFIFOW(fd,32); // year
WFIFOW(login_fd, 8) = RFIFOW(fd,34); // month
WFIFOW(login_fd,10) = RFIFOW(fd,36); // day
@ -2571,57 +2564,39 @@ int parse_frommap(int fd)
WFIFOW(login_fd,14) = RFIFOW(fd,40); // minute
WFIFOW(login_fd,16) = RFIFOW(fd,42); // second
WFIFOSET(login_fd,18);
} else
WFIFOW(fd,32) = 3; // answer: 0-login-server request done, 1-player not found, 2-gm level too low, 3-login-server offline
} else
WFIFOW(fd,32) = 2; // answer: 0-login-server request done, 1-player not found, 2-gm level too low, 3-login-server offline
break;
case 3: // unblock
if (acc == -1 || isGM(acc) >= isGM(atoi(data))) {
if (login_fd > 0) { // don't send request if no login-server
WFIFOHEAD(login_fd,10);
WFIFOW(login_fd,0) = 0x2724;
WFIFOL(login_fd,2) = atoi(data); // account value
WFIFOL(login_fd,6) = 0; // status of the account
WFIFOL(login_fd,2) = account_id;
WFIFOL(login_fd,6) = 0; // new account status
WFIFOSET(login_fd,10);
} else
WFIFOW(fd,32) = 3; // answer: 0-login-server request done, 1-player not found, 2-gm level too low, 3-login-server offline
} else
WFIFOW(fd,32) = 2; // answer: 0-login-server request done, 1-player not found, 2-gm level too low, 3-login-server offline
break;
case 4: // unban
if (acc == -1 || isGM(acc) >= isGM(atoi(data))) {
if (login_fd > 0) { // don't send request if no login-server
WFIFOHEAD(login_fd,6);
WFIFOW(login_fd,0) = 0x272a;
WFIFOL(login_fd,2) = atoi(data); // account value
WFIFOL(login_fd,2) = account_id;
WFIFOSET(login_fd,6);
} else
WFIFOW(fd,32) = 3; // answer: 0-login-server request done, 1-player not found, 2-gm level too low, 3-login-server offline
} else
WFIFOW(fd,32) = 2; // answer: 0-login-server request done, 1-player not found, 2-gm level too low, 3-login-server offline
break;
case 5: // changesex
if (acc == -1 || isGM(acc) >= isGM(atoi(data))) {
if (login_fd > 0) { // don't send request if no login-server
WFIFOHEAD(login_fd,6);
WFIFOW(login_fd,0) = 0x2727;
WFIFOL(login_fd,2) = atoi(data); // account value
WFIFOL(login_fd,2) = account_id;
WFIFOSET(login_fd,6);
} else
WFIFOW(fd,32) = 3; // answer: 0-login-server request done, 1-player not found, 2-gm level too low, 3-login-server offline
} else
WFIFOW(fd,32) = 2; // answer: 0-login-server request done, 1-player not found, 2-gm level too low, 3-login-server offline
break;
}
} else {
// character name not found
memcpy(WFIFOP(fd,6), character_name, NAME_LENGTH);
WFIFOW(fd,32) = 1; // answer: 0-login-server request done, 1-player not found, 2-gm level too low, 3-login-server offline
}
Sql_FreeResult(sql_handle);
// send answer if a player ask, not if the server ask
if( acc != -1 ) {
WFIFOHEAD(fd,34);
WFIFOW(fd, 0) = 0x2b0f;
WFIFOL(fd, 2) = acc;
safestrncpy((char*)WFIFOP(fd,6), name, NAME_LENGTH);
WFIFOW(fd,30) = type;
WFIFOW(fd,32) = result;
WFIFOSET(fd,34);
}

View File

@ -7,6 +7,7 @@
#include "../common/timer.h"
#include "../common/nullpo.h"
#include "../common/showmsg.h"
#include "../common/strlib.h"
#include "map.h"
#include "battle.h"
@ -588,24 +589,20 @@ int chrif_changeemail(int id, const char *actual_email, const char *new_email)
}
/*==========================================
* Send message to char-server with a character name to do some operations (by Yor)
* Used to ask Char-server about a character name to have the account number to modify account file in login-server.
* S 2b0e <accid>.l <name>.24B <type>.w { <year>.w <month>.w <day>.w <hour>.w <minute>.w <second>.w }
* Send an account modification request to the login server (via char server).
* type of operation:
* 1: block
* 2: ban
* 3: unblock
* 4: unban
* 5: changesex
* 1: block, 2: ban, 3: unblock, 4: unban, 5: changesex
*------------------------------------------*/
int chrif_char_ask_name(int id, char * character_name, short operation_type, int year, int month, int day, int hour, int minute, int second)
int chrif_char_ask_name(int acc, const char* character_name, unsigned short operation_type, int year, int month, int day, int hour, int minute, int second)
{
chrif_check(-1);
WFIFOHEAD(char_fd,44);
WFIFOW(char_fd,0) = 0x2b0e;
WFIFOL(char_fd, 2) = id; // account_id of who ask (for answer) -1 if nobody
memcpy(WFIFOP(char_fd,6), character_name, NAME_LENGTH);
WFIFOW(char_fd, 30) = operation_type; // type of operation
WFIFOL(char_fd,2) = acc;
safestrncpy((char*)WFIFOP(char_fd,6), character_name, NAME_LENGTH);
WFIFOW(char_fd,30) = operation_type;
if (operation_type == 2) {
WFIFOW(char_fd,32) = year;
WFIFOW(char_fd,34) = month;
@ -614,7 +611,6 @@ int chrif_char_ask_name(int id, char * character_name, short operation_type, int
WFIFOW(char_fd,40) = minute;
WFIFOW(char_fd,42) = second;
}
// ShowInfo("chrif : sent 0x2b0e\n");
WFIFOSET(char_fd,44);
return 0;
@ -638,7 +634,7 @@ int chrif_changesex(int id, int sex)
/*==========================================
* R 2b0f <accid>.l <name>.24B <type>.w <answer>.w
* Reply to chrif_char_ask_name() (request to do some character operation)
* Processing a reply to chrif_char_ask_name() (request to modify an account).
* type of operation:
* 1: block, 2: ban, 3: unblock, 4: unban, 5: changesex
* type of answer:
@ -647,27 +643,19 @@ int chrif_changesex(int id, int sex)
* 2: gm level too low
* 3: login-server offline
*------------------------------------------*/
int chrif_char_ask_name_answer(int fd)
static void chrif_char_ask_name_answer(int acc, const char* player_name, uint16 type, uint16 answer)
{
struct map_session_data* sd;
char* action;
const char* action;
char output[256];
int acc = RFIFOL(fd,2); // account_id of who has asked (-1 if nobody)
char* player_name = (char*)RFIFOP(fd,6);
uint16 type;
uint16 answer;
type = RFIFOW(fd,30);
answer = RFIFOW(fd,32);
sd = map_id2sd(acc);
if( acc < 0 || sd == NULL ) {
ShowError("chrif_char_ask_name_answer failed - player not online.\n");
return 0;
return;
}
switch(type)
{
switch( type ) {
case 1 : action = "block"; break;
case 2 : action = "ban"; break;
case 3 : action = "unblock"; break;
@ -676,17 +664,15 @@ int chrif_char_ask_name_answer(int fd)
default: action = "???"; break;
}
switch(answer)
{
case 0: sprintf(output, "Login-server has been asked to %s the player '%20s'.", action, player_name); break;
case 1: sprintf(output, "The player '%20s' doesn't exist.", player_name); break;
case 2: sprintf(output, "Your GM level don't authorise you to %s the player '%20s'.", action, player_name); break;
case 3: sprintf(output, "Login-server is offline. Impossible to %s the player '%20s'.", action, player_name); break;
switch( answer ) {
case 0 : sprintf(output, "Login-server has been asked to %s the player '%.*s'.", action, NAME_LENGTH, player_name); break;
case 1 : sprintf(output, "The player '%.*s' doesn't exist.", NAME_LENGTH, player_name); break;
case 2 : sprintf(output, "Your GM level don't authorise you to %s the player '%.*s'.", action, NAME_LENGTH, player_name); break;
case 3 : sprintf(output, "Login-server is offline. Impossible to %s the player '%.*s'.", action, NAME_LENGTH, player_name); break;
default: output[0] = '\0'; break;
}
clif_displaymessage(sd->fd, output);
return 0;
}
/*==========================================
@ -1305,7 +1291,7 @@ int chrif_parse(int fd)
case 0x2b09: map_addnickdb(RFIFOL(fd,2), (char*)RFIFOP(fd,6)); break;
case 0x2b0b: chrif_changedgm(fd); break;
case 0x2b0d: chrif_changedsex(fd); break;
case 0x2b0f: chrif_char_ask_name_answer(fd); break;
case 0x2b0f: chrif_char_ask_name_answer(RFIFOL(fd,2), (char*)RFIFOP(fd,6), RFIFOW(fd,30), RFIFOW(fd,32)); break;
case 0x2b12: chrif_divorce(RFIFOL(fd,2), RFIFOL(fd,6)); break;
case 0x2b13: chrif_accountdeletion(fd); break;
case 0x2b14: chrif_accountban(fd); break;

View File

@ -34,7 +34,7 @@ int chrif_changemapserver(struct map_session_data* sd, short map, int x, int y,
int chrif_searchcharid(int char_id);
int chrif_changegm(int id,const char *pass,int len);
int chrif_changeemail(int id, const char *actual_email, const char *new_email);
int chrif_char_ask_name(int id, char * character_name, short operation_type, int year, int month, int day, int hour, int minute, int second);
int chrif_char_ask_name(int acc, const char* character_name, unsigned short operation_type, int year, int month, int day, int hour, int minute, int second);
int chrif_reloadGMdb(void);
int chrif_updatefamelist(struct map_session_data *sd);
int chrif_buildfamelist(void);