summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/char_sql/char.c171
-rw-r--r--src/map/chrif.c80
-rw-r--r--src/map/chrif.h2
3 files changed, 107 insertions, 146 deletions
diff --git a/src/char_sql/char.c b/src/char_sql/char.c
index fc25afdc3..64e341c11 100644
--- a/src/char_sql/char.c
+++ b/src/char_sql/char.c
@@ -2508,124 +2508,99 @@ 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)
-
- 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 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
+
+ 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 )
+ {
+ result = 1; // 1-player not found
+ }
+ else
+ if( SQL_SUCCESS != Sql_NextRow(sql_handle) )
+ Sql_ShowDebug(sql_handle);
+ else
{
+ char name[NAME_LENGTH];
+ int account_id;
char* data;
- size_t len;
- // name
- Sql_GetData(sql_handle, 1, &data, &len);
- if( len >= NAME_LENGTH )
- memcpy(WFIFOP(fd,6), data, NAME_LENGTH);
+ 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
- {
- 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)) {
+ 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
- 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;
+ 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
- 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
- WFIFOW(login_fd, 6) = RFIFOW(fd,32); // year
- WFIFOW(login_fd, 8) = RFIFOW(fd,34); // month
- WFIFOW(login_fd,10) = RFIFOW(fd,36); // day
- WFIFOW(login_fd,12) = RFIFOW(fd,38); // hour
- 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;
+ WFIFOHEAD(login_fd,18);
+ WFIFOW(login_fd, 0) = 0x2725;
+ 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
+ WFIFOW(login_fd,12) = RFIFOW(fd,38); // hour
+ WFIFOW(login_fd,14) = RFIFOW(fd,40); // minute
+ WFIFOW(login_fd,16) = RFIFOW(fd,42); // second
+ WFIFOSET(login_fd,18);
+ 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
- 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;
+ 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
- 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
- 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;
+ WFIFOHEAD(login_fd,6);
+ WFIFOW(login_fd,0) = 0x272a;
+ WFIFOL(login_fd,2) = account_id;
+ WFIFOSET(login_fd,6);
+ 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
- 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;
+ WFIFOHEAD(login_fd,6);
+ WFIFOW(login_fd,0) = 0x2727;
+ WFIFOL(login_fd,2) = account_id;
+ WFIFOSET(login_fd,6);
+ 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) {
- WFIFOSET(fd, 34);
+ 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);
}
- RFIFOSKIP(fd, 44);
+ RFIFOSKIP(fd,44);
}
break;
diff --git a/src/map/chrif.c b/src/map/chrif.c
index 1f86a6b88..7c24ea25d 100644
--- a/src/map/chrif.c
+++ b/src/map/chrif.c
@@ -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,33 +589,28 @@ 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
+ WFIFOHEAD(char_fd,44);
+ WFIFOW(char_fd,0) = 0x2b0e;
+ 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;
- WFIFOW(char_fd, 36) = day;
- WFIFOW(char_fd, 38) = hour;
- WFIFOW(char_fd, 40) = minute;
- WFIFOW(char_fd, 42) = second;
+ WFIFOW(char_fd,32) = year;
+ WFIFOW(char_fd,34) = month;
+ WFIFOW(char_fd,36) = day;
+ WFIFOW(char_fd,38) = hour;
+ 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,46 +643,36 @@ 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) {
+ if( acc < 0 || sd == NULL ) {
ShowError("chrif_char_ask_name_answer failed - player not online.\n");
- return 0;
+ return;
}
- switch(type)
- {
- case 1: action = "block"; break;
- case 2: action = "ban"; break;
- case 3: action = "unblock"; break;
- case 4: action = "unban"; break;
- case 5: action = "change the sex of"; break;
+ switch( type ) {
+ case 1 : action = "block"; break;
+ case 2 : action = "ban"; break;
+ case 3 : action = "unblock"; break;
+ case 4 : action = "unban"; break;
+ case 5 : action = "change the sex of"; break;
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;
diff --git a/src/map/chrif.h b/src/map/chrif.h
index 179772257..ad39c966a 100644
--- a/src/map/chrif.h
+++ b/src/map/chrif.h
@@ -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);