summaryrefslogtreecommitdiff
path: root/src/char_sql
diff options
context:
space:
mode:
authorskotlex <skotlex@54d463be-8e91-2dee-dedb-b68131a5f0ec>2006-11-24 12:41:38 +0000
committerskotlex <skotlex@54d463be-8e91-2dee-dedb-b68131a5f0ec>2006-11-24 12:41:38 +0000
commit16d301eb02e84f03df387db15750e4cb52beaf9f (patch)
treef45264671d0eaf0af9d8d5ea00b2c74af36dffa9 /src/char_sql
parent269579a5d2ec5df0841c94158102228bc1634d97 (diff)
downloadhercules-16d301eb02e84f03df387db15750e4cb52beaf9f.tar.gz
hercules-16d301eb02e84f03df387db15750e4cb52beaf9f.tar.bz2
hercules-16d301eb02e84f03df387db15750e4cb52beaf9f.tar.xz
hercules-16d301eb02e84f03df387db15750e4cb52beaf9f.zip
- 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
Diffstat (limited to 'src/char_sql')
-rw-r--r--src/char_sql/char.c306
-rw-r--r--src/char_sql/int_guild.c5
-rw-r--r--src/char_sql/int_homun.c14
-rw-r--r--src/char_sql/int_party.c2
-rw-r--r--src/char_sql/int_pet.c16
-rw-r--r--src/char_sql/int_storage.c22
-rw-r--r--src/char_sql/inter.c47
7 files changed, 239 insertions, 173 deletions
diff --git a/src/char_sql/char.c b/src/char_sql/char.c
index b2395623b..8fb53945d 100644
--- a/src/char_sql/char.c
+++ b/src/char_sql/char.c
@@ -249,12 +249,13 @@ void set_char_online(int map_id, int char_id, int account_id) {
cp = idb_get(char_db_,char_id);
inter_guild_CharOnline(char_id, cp?cp->guild_id:-1);
}
- if (login_fd <= 0 || session[login_fd]->eof)
- return;
-
- WFIFOW(login_fd,0) = 0x272b;
- WFIFOL(login_fd,2) = account_id;
- WFIFOSET(login_fd,6);
+ if (login_fd > 0 && !session[login_fd]->eof)
+ {
+ WFIFOHEAD(login_fd,6);
+ WFIFOW(login_fd,0) = 0x272b;
+ WFIFOL(login_fd,2) = account_id;
+ WFIFOSET(login_fd,6);
+ }
}
void set_char_offline(int char_id, int account_id) {
@@ -285,12 +286,13 @@ void set_char_offline(int char_id, int account_id) {
character->waiting_disconnect = 0;
}
- if (login_fd <= 0 || session[login_fd]->eof)
- return;
-
- WFIFOW(login_fd,0) = 0x272c;
- WFIFOL(login_fd,2) = account_id;
- WFIFOSET(login_fd,6);
+ if (login_fd > 0 && !session[login_fd]->eof)
+ {
+ WFIFOHEAD(login_fd,6);
+ WFIFOW(login_fd,0) = 0x272c;
+ WFIFOL(login_fd,2) = account_id;
+ WFIFOSET(login_fd,6);
+ }
}
static int char_db_setoffline(DBKey key, void* data, va_list ap) {
@@ -1674,18 +1676,10 @@ int count_users(void) {
int mmo_char_send006b(int fd, struct char_session_data *sd) {
int i, j, found_num = 0;
struct mmo_charstatus *p = NULL;
-// hehe. commented other. anyway there's no need to use older version.
-// if use older packet version just uncomment that!
-//#ifdef NEW_006b
const int offset = 24;
-//#else
-// int offset = 4;
-//#endif
-
-// ShowDebug("mmo_char_send006b start.. (account:%d)\n",sd->account_id);
-// printf("offset -> %d...\n",offset);
-
- set_char_online(-1, 99,sd->account_id);
+ WFIFOHEAD(fd, offset +9*106);
+
+ set_char_online(-1, 99,sd->account_id);
//search char.
sprintf(tmp_sql, "SELECT `char_id` FROM `%s` WHERE `account_id` = '%d'",char_db, sd->account_id);
@@ -1705,8 +1699,6 @@ int mmo_char_send006b(int fd, struct char_session_data *sd) {
mysql_free_result(sql_res);
}
-// printf("char fetching end (total: %d)....\n", found_num);
-
for(i = found_num; i < 9; i++)
sd->found_char[i] = -1;
@@ -1776,7 +1768,7 @@ int send_accounts_tologin(int tid, unsigned int tick, int id, int data);
int parse_tologin(int fd) {
int i;
struct char_session_data *sd;
-
+ RFIFOHEAD(fd);
// only login-server can have an access to here.
// so, if it isn't the login-server, we disconnect the session.
//session eof check!
@@ -1831,6 +1823,7 @@ int parse_tologin(int fd) {
return 0;
for(i = 0; i < fd_max; i++) {
if (session[i] && (sd = (struct char_session_data*)session[i]->session_data) && sd->account_id == RFIFOL(fd,2)) {
+ WFIFOHEAD(i,3);
if (RFIFOB(fd,6) != 0) {
WFIFOW(i,0) = 0x6c;
WFIFOB(i,2) = 0x42;
@@ -2160,6 +2153,7 @@ int parse_tologin(int fd) {
for(i = 0; i < fd_max; i++) {
if (session[i] && (tsd = (struct char_session_data*)session[i]->session_data) && tsd->account_id == aid)
{
+ WFIFOHEAD(i,3);
WFIFOW(i,0) = 0x81;
WFIFOB(i,2) = 2;
WFIFOSET(i,3);
@@ -2192,6 +2186,7 @@ int parse_tologin(int fd) {
{ //Update ip.
char_ip = new_ip;
ShowInfo("Updating IP for [%s].\n",char_ip_str);
+ WFIFOHEAD(fd,6);
WFIFOW(fd,0) = 0x2736;
WFIFOL(fd,2) = char_ip;
WFIFOSET(fd,6);
@@ -2212,6 +2207,7 @@ int parse_tologin(int fd) {
int request_accreg2(int account_id, int char_id) {
if (login_fd > 0) {
+ WFIFOHEAD(login_fd, 10);
WFIFOW(login_fd, 0) = 0x272e;
WFIFOL(login_fd, 2) = account_id;
WFIFOL(login_fd, 6) = char_id;
@@ -2368,7 +2364,7 @@ int char_loadName(int char_id, char* name)
int parse_frommap(int fd) {
int i = 0, j = 0;
int id;
-// int auth_fifo_flag=0;
+ RFIFOHEAD(fd);
// Sometimes fd=0, and it will cause server crash. Don't know why. :(
if (fd <= 0) {
@@ -2411,8 +2407,6 @@ int parse_frommap(int fd) {
}
while(RFIFOREST(fd) >= 2 && !session[fd]->eof) {
- //ShowDebug("Received packet 0x%4x (%d bytes) from map-server (connection %d)\n", RFIFOW(fd, 0), RFIFOREST(fd), fd);
-
switch(RFIFOW(fd, 0)) {
// map-server alive packet
@@ -2426,6 +2420,7 @@ int parse_frommap(int fd) {
read_gm_account();
//Send to login request to reload gm accounts.
else if (login_fd > 0) { // don't send request if no login-server
+ WFIFOHEAD(login_fd, 2);
WFIFOW(login_fd,0) = 0x2709;
WFIFOSET(login_fd, 2);
}
@@ -2435,61 +2430,64 @@ int parse_frommap(int fd) {
case 0x2afa:
if (RFIFOREST(fd) < 4 || RFIFOREST(fd) < RFIFOW(fd,2))
return 0;
+ {
+ unsigned char *p = (unsigned char *)&server[id].ip;
+ unsigned char buf[16384];
+ int x;
+ WFIFOHEAD(fd,3+NAME_LENGTH);
+
memset(server[id].map, 0, sizeof(server[id].map));
j = 0;
for(i = 4; i < RFIFOW(fd,2); i += 4) {
server[id].map[j] = RFIFOW(fd,i);
-// printf("set map %d.%d : %s\n", id, j, server[id].map[j]);
j++;
}
- i = server[id].ip;
- {
- unsigned char *p = (unsigned char *)&server[id].ip;
- ShowStatus("Map-Server %d connected: %d maps, from IP %d.%d.%d.%d port %d.\n",
- id, j, p[0], p[1], p[2], p[3], server[id].port);
- ShowStatus("Map-server %d loading complete.\n", id);
-
- if (max_account_id != DEFAULT_MAX_ACCOUNT_ID || max_char_id != DEFAULT_MAX_CHAR_ID)
- mapif_send_maxid(max_account_id, max_char_id); //Send the current max ids to the server to keep in sync [Skotlex]
- }
+
+ ShowStatus("Map-Server %d connected: %d maps, from IP %d.%d.%d.%d port %d.\n",
+ id, j, p[0], p[1], p[2], p[3], server[id].port);
+ ShowStatus("Map-server %d loading complete.\n", id);
+
+ if (max_account_id != DEFAULT_MAX_ACCOUNT_ID || max_char_id != DEFAULT_MAX_CHAR_ID)
+ mapif_send_maxid(max_account_id, max_char_id); //Send the current max ids to the server to keep in sync [Skotlex]
+
WFIFOW(fd,0) = 0x2afb;
WFIFOB(fd,2) = 0;
- memcpy(WFIFOP(fd,3), wisp_server_name, NAME_LENGTH); // name for wisp to player
+ // name for wisp to player
+ memcpy(WFIFOP(fd,3), wisp_server_name, NAME_LENGTH);
WFIFOSET(fd,3+NAME_LENGTH);
+
char_send_fame_list(fd); //Send fame list.
- //WFIFOSET(fd,27);
- {
- unsigned char buf[16384];
- int x;
- if (j == 0) {
- ShowWarning("Map-Server %d have NO maps.\n", id);
+
+ if (j == 0)
+ ShowWarning("Map-Server %d have NO maps.\n", id);
+ else {
// Transmitting maps information to the other map-servers
- } else {
- WBUFW(buf,0) = 0x2b04;
- WBUFW(buf,2) = j * 4 + 10;
- WBUFL(buf,4) = server[id].ip;
- WBUFW(buf,8) = server[id].port;
- memcpy(WBUFP(buf,10), RFIFOP(fd,4), j * 4);
- mapif_sendallwos(fd, buf, WBUFW(buf,2));
- }
- // Transmitting the maps of the other map-servers to the new map-server
- for(x = 0; x < MAX_MAP_SERVERS; x++) {
- if (server_fd[x] > 0 && x != id) {
- WFIFOW(fd,0) = 0x2b04;
- WFIFOL(fd,4) = server[x].ip;
- WFIFOW(fd,8) = server[x].port;
- j = 0;
- for(i = 0; i < MAX_MAP_PER_SERVER; i++)
- if (server[x].map[i])
- WFIFOW(fd,10+(j++)*4) = server[x].map[i];
- if (j > 0) {
- WFIFOW(fd,2) = j * 4 + 10;
- WFIFOSET(fd,WFIFOW(fd,2));
- }
+ WBUFW(buf,0) = 0x2b04;
+ WBUFW(buf,2) = j * 4 + 10;
+ WBUFL(buf,4) = server[id].ip;
+ WBUFW(buf,8) = server[id].port;
+ memcpy(WBUFP(buf,10), RFIFOP(fd,4), j * 4);
+ mapif_sendallwos(fd, buf, WBUFW(buf,2));
+ }
+ // Transmitting the maps of the other map-servers to the new map-server
+ for(x = 0; x < MAX_MAP_SERVERS; x++) {
+ if (server_fd[x] > 0 && x != id) {
+ WFIFOHEAD(fd, 10 +4*MAX_MAP_PER_SERVER);
+ WFIFOW(fd,0) = 0x2b04;
+ WFIFOL(fd,4) = server[x].ip;
+ WFIFOW(fd,8) = server[x].port;
+ j = 0;
+ for(i = 0; i < MAX_MAP_PER_SERVER; i++)
+ if (server[x].map[i])
+ WFIFOW(fd,10+(j++)*4) = server[x].map[i];
+ if (j > 0) {
+ WFIFOW(fd,2) = j * 4 + 10;
+ WFIFOSET(fd,WFIFOW(fd,2));
}
}
}
RFIFOSKIP(fd,RFIFOW(fd,2));
+ }
break;
//Packet command is now used for sc_data request. [Skotlex]
case 0x2afc:
@@ -2512,10 +2510,11 @@ int parse_frommap(int fd) {
if (sql_res) {
struct status_change_data data;
int count = 0;
+ WFIFOHEAD(fd, 14+50*sizeof(struct status_change_data));
WFIFOW(fd, 0) = 0x2b1d;
WFIFOL(fd, 4) = aid;
WFIFOL(fd, 8) = cid;
- while((sql_row = mysql_fetch_row(sql_res)))
+ while((sql_row = mysql_fetch_row(sql_res)) && count < 50)
{
data.type = atoi(sql_row[0]);
data.tick = atoi(sql_row[1]);
@@ -2526,6 +2525,8 @@ int parse_frommap(int fd) {
memcpy(WFIFOP(fd, 14+count*sizeof(struct status_change_data)), &data, sizeof(struct status_change_data));
count++;
}
+ if (count >= 50)
+ ShowWarning("Too many status changes for %d:%d, some of them were not loaded.\n", aid, cid);
mysql_free_result(sql_res);
if (count > 0)
{
@@ -2610,6 +2611,7 @@ int parse_frommap(int fd) {
if (RFIFOB(fd,12))
{ //Flag? Set character offline after saving [Skotlex]
set_char_offline(cid, aid);
+ WFIFOHEAD(fd, 10);
WFIFOW(fd, 0) = 0x2b21; //Save ack only needed on final save.
WFIFOL(fd, 2) = aid;
WFIFOL(fd, 6) = cid;
@@ -2635,12 +2637,13 @@ int parse_frommap(int fd) {
auth_fifo[auth_fifo_pos].connect_until_time = 0; // unlimited/unknown time by default (not display in map-server)
auth_fifo[auth_fifo_pos].ip = RFIFOL(fd,14);
auth_fifo_pos++;
-
+ {
+ WFIFOHEAD(fd, 7);
WFIFOW(fd, 0) = 0x2b03;
WFIFOL(fd, 2) = RFIFOL(fd, 2);
WFIFOB(fd, 6) = 0;
WFIFOSET(fd, 7);
-
+ }
RFIFOSKIP(fd, 18);
break;
@@ -2653,8 +2656,6 @@ int parse_frommap(int fd) {
int map_id, map_fd = -1;
struct online_char_data* data;
struct mmo_charstatus* char_data;
-
-
name = RFIFOW(fd,18);
map_id = search_mapserver(name, RFIFOL(fd,24), RFIFOW(fd,28)); //Locate mapserver by ip and port.
if (map_id >= 0)
@@ -2670,6 +2671,8 @@ int parse_frommap(int fd) {
if (map_fd>=0 && session[map_fd] && char_data)
{ //Send the map server the auth of this player.
//Update the "last map" as this is where the player must be spawned on the new map server.
+ WFIFOHEAD(fd, 30);
+ WFIFOHEAD(map_fd, 20 + sizeof(struct mmo_charstatus));
char_data->last_point.map = RFIFOW(fd,18);
char_data->last_point.x = RFIFOW(fd,20);
char_data->last_point.y = RFIFOW(fd,22);
@@ -2692,6 +2695,7 @@ int parse_frommap(int fd) {
memcpy(WFIFOP(fd,2), RFIFOP(fd,2), 28);
WFIFOSET(fd, 30);
} else { //Reply with nak
+ WFIFOHEAD(fd, 30);
WFIFOW(fd, 0) = 0x2b06;
memcpy(WFIFOP(fd,2), RFIFOP(fd,2), 28);
WFIFOL(fd, 6) = 0; //Set login1 to 0.
@@ -2707,6 +2711,7 @@ int parse_frommap(int fd) {
return 0;
{
char name[NAME_LENGTH];
+ WFIFOHEAD(fd,30);
char_loadName((int)RFIFOL(fd,2), name);
WFIFOW(fd,0) = 0x2b09;
WFIFOL(fd,2) = RFIFOL(fd,2);
@@ -2737,6 +2742,7 @@ int parse_frommap(int fd) {
if (RFIFOREST(fd) < 86)
return 0;
if (login_fd > 0) { // 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;
WFIFOSET(login_fd, 86);
@@ -2751,6 +2757,7 @@ int parse_frommap(int fd) {
{
char character_name[NAME_LENGTH], t_name[NAME_LENGTH*2];
int acc = RFIFOL(fd,2); // account_id of who ask (-1 if nobody)
+ WFIFOHEAD(fd, 34);
memcpy(character_name, RFIFOP(fd,6), NAME_LENGTH);
character_name[NAME_LENGTH-1] = '\0';
jstrescapecpy(t_name, character_name); //Escape string for sql use... [Skotlex]
@@ -2776,6 +2783,7 @@ int parse_frommap(int fd) {
case 1: // block
if (acc == -1 || isGM(acc) >= isGM(atoi(sql_row[0]))) {
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(sql_row[0]); // account value
WFIFOL(login_fd,6) = 5; // status of the account
@@ -2788,6 +2796,7 @@ int parse_frommap(int fd) {
case 2: // ban
if (acc == -1 || isGM(acc) >= isGM(atoi(sql_row[0]))) {
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(sql_row[0]); // account value
WFIFOW(login_fd, 6) = RFIFOW(fd,32); // year
@@ -2805,6 +2814,7 @@ int parse_frommap(int fd) {
case 3: // unblock
if (acc == -1 || isGM(acc) >= isGM(atoi(sql_row[0]))) {
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(sql_row[0]); // account value
WFIFOL(login_fd,6) = 0; // status of the account
@@ -2817,6 +2827,7 @@ int parse_frommap(int fd) {
case 4: // unban
if (acc == -1 || isGM(acc) >= isGM(atoi(sql_row[0]))) {
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(sql_row[0]); // account value
WFIFOSET(login_fd, 6);
@@ -2828,6 +2839,7 @@ int parse_frommap(int fd) {
case 5: // changesex
if (acc == -1 || isGM(acc) >= isGM(atoi(sql_row[0]))) {
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(sql_row[0]); // account value
WFIFOSET(login_fd, 6);
@@ -3086,6 +3098,7 @@ int parse_char(int fd) {
struct char_session_data *sd;
unsigned char *p = (unsigned char *) &session[fd]->client_addr.sin_addr;
long subnet_map_ip;
+ RFIFOHEAD(fd);
sd = (struct char_session_data*)session[fd]->session_data;
@@ -3134,17 +3147,17 @@ int parse_char(int fd) {
if (RFIFOREST(fd) < 17)
return 0;
{
- if (sd == NULL) {
- CREATE(session[fd]->session_data, struct char_session_data, 1);
- sd = (struct char_session_data*)session[fd]->session_data;
- sd->connect_until_time = 0; // unknow or illimited (not displaying on map-server)
- } else {
+ WFIFOHEAD(fd, 4);
+
+ if (sd) {
//Received again auth packet for already authentified account?? Discard it.
//TODO: Perhaps log this as a hack attempt?
RFIFOSKIP(fd,17);
break;
}
-
+ CREATE(session[fd]->session_data, struct char_session_data, 1);
+ sd = (struct char_session_data*)session[fd]->session_data;
+ sd->connect_until_time = 0; // unknow or illimited (not displaying on map-server)
sd->account_id = RFIFOL(fd, 2);
sd->login_id1 = RFIFOL(fd, 6);
sd->login_id2 = RFIFOL(fd, 10);
@@ -3203,6 +3216,7 @@ int parse_char(int fd) {
if (max_connect_user == 0 || count_users() < max_connect_user) {
if (login_fd > 0) { // don't send request if no login-server
// request to login-server to obtain e-mail/time limit
+ WFIFOHEAD(login_fd, 6);
WFIFOW(login_fd,0) = 0x2716;
WFIFOL(login_fd,2) = sd->account_id;
WFIFOSET(login_fd,6);
@@ -3221,6 +3235,7 @@ int parse_char(int fd) {
}
if (i == AUTH_FIFO_SIZE) {
if (login_fd > 0) { // don't send request if no login-server
+ WFIFOHEAD(login_fd,19);
WFIFOW(login_fd,0) = 0x2712; // ask login-server to authentify an account
WFIFOL(login_fd,2) = sd->account_id;
WFIFOL(login_fd,6) = sd->login_id1;
@@ -3229,6 +3244,7 @@ int parse_char(int fd) {
WFIFOL(login_fd,15) = session[fd]->client_addr.sin_addr.s_addr;
WFIFOSET(login_fd,19);
} else { // if no login-server, we must refuse connection
+ WFIFOHEAD(fd,3);
WFIFOW(fd,0) = 0x6c;
WFIFOB(fd,2) = 0;
WFIFOSET(fd,3);
@@ -3311,6 +3327,7 @@ int parse_char(int fd) {
char_dat.last_point.y = 103;
} else {
ShowInfo("Connection Closed. No map server available that has a major city, and unable to find map-server for '%s'.\n", mapindex_id2name(char_dat.last_point.map));
+ WFIFOHEAD(fd,3);
WFIFOW(fd,0) = 0x81;
WFIFOB(fd,2) = 1; // 01 = Server closed
WFIFOSET(fd,3);
@@ -3319,18 +3336,21 @@ int parse_char(int fd) {
ShowWarning("Unable to find map-server for '%s', sending to major city '%s'.\n", mapindex_id2name(char_dat.last_point.map), mapindex_id2name(j));
char_dat.last_point.map = j;
}
- WFIFOW(fd, 0) =0x71;
- WFIFOL(fd, 2) =char_dat.char_id;
- memcpy(WFIFOP(fd,6), mapindex_id2name(char_dat.last_point.map), MAP_NAME_LENGTH);
-
- // Andvanced subnet check [LuzZza]
- if((subnet_map_ip = lan_subnetcheck((long *)p)))
- WFIFOL(fd,22) = subnet_map_ip;
- else
- WFIFOL(fd,22) = server[i].ip;
-
- WFIFOW(fd,26) = server[i].port;
- WFIFOSET(fd,28);
+ { //Send player to map.
+ WFIFOHEAD(fd,28);
+ WFIFOW(fd, 0) =0x71;
+ WFIFOL(fd, 2) =char_dat.char_id;
+ memcpy(WFIFOP(fd,6), mapindex_id2name(char_dat.last_point.map), MAP_NAME_LENGTH);
+
+ // Advanced subnet check [LuzZza]
+ if((subnet_map_ip = lan_subnetcheck((long *)p)))
+ WFIFOL(fd,22) = subnet_map_ip;
+ else
+ WFIFOL(fd,22) = server[i].ip;
+
+ WFIFOW(fd,26) = server[i].port;
+ WFIFOSET(fd,28);
+ }
if (auth_fifo_pos >= AUTH_FIFO_SIZE) {
auth_fifo_pos = 0;
}
@@ -3352,15 +3372,17 @@ int parse_char(int fd) {
memset(&server[i], 0, sizeof(struct mmo_map_server));
break;
}
-
- WFIFOW(map_fd,0) = 0x2afd;
- WFIFOW(map_fd,2) = 20 + sizeof(struct mmo_charstatus);
- WFIFOL(map_fd,4) = auth_fifo[auth_fifo_pos].account_id;
- WFIFOL(map_fd,8) = auth_fifo[auth_fifo_pos].login_id1;
- WFIFOL(map_fd,16) = auth_fifo[auth_fifo_pos].login_id2;
- WFIFOL(map_fd,12) = (unsigned long)auth_fifo[auth_fifo_pos].connect_until_time;
- memcpy(WFIFOP(map_fd,20), &char_dat, sizeof(struct mmo_charstatus));
- WFIFOSET(map_fd, WFIFOW(map_fd,2));
+ { //Send auth ok to map server
+ WFIFOHEAD(map_fd, 20 + sizeof(struct mmo_charstatus));
+ WFIFOW(map_fd,0) = 0x2afd;
+ WFIFOW(map_fd,2) = 20 + sizeof(struct mmo_charstatus);
+ WFIFOL(map_fd,4) = auth_fifo[auth_fifo_pos].account_id;
+ WFIFOL(map_fd,8) = auth_fifo[auth_fifo_pos].login_id1;
+ WFIFOL(map_fd,16) = auth_fifo[auth_fifo_pos].login_id2;
+ WFIFOL(map_fd,12) = (unsigned long)auth_fifo[auth_fifo_pos].connect_until_time;
+ memcpy(WFIFOP(map_fd,20), &char_dat, sizeof(struct mmo_charstatus));
+ WFIFOSET(map_fd, WFIFOW(map_fd,2));
+ }
set_char_online(i, auth_fifo[auth_fifo_pos].char_id, auth_fifo[auth_fifo_pos].account_id);
//Checks to see if the even share setting of the party must be broken.
@@ -3376,38 +3398,23 @@ int parse_char(int fd) {
else
i = make_new_char_sql(fd, RFIFOP(fd, 2));
- //if (i < 0) {
- // WFIFOW(fd, 0) = 0x6e;
- // WFIFOB(fd, 2) = 0x00;
- // WFIFOSET(fd, 3);
- // RFIFOSKIP(fd, 37);
- // break;
- //}
- //Changed that we can support 'Charname already exists' (-1) amd 'Char creation denied' (-2)
+ //'Charname already exists' (-1), 'Char creation denied' (-2)
//And 'You are underaged' (-3) (XD) [Sirius]
- if(i == -1){
- //already exists
- WFIFOW(fd, 0) = 0x6e;
- WFIFOB(fd, 2) = 0x00;
- WFIFOSET(fd, 3);
- RFIFOSKIP(fd, 37);
- break;
- }else if(i == -2){
- //denied
- WFIFOW(fd, 0) = 0x6e;
- WFIFOB(fd, 2) = 0x02;
- WFIFOSET(fd, 3);
- RFIFOSKIP(fd, 37);
- break;
- }else if(i == -3){
- //underaged XD
- WFIFOW(fd, 0) = 0x6e;
- WFIFOB(fd, 2) = 0x01;
- WFIFOSET(fd, 3);
- RFIFOSKIP(fd, 37);
- break;
+ if (i < 0)
+ {
+ WFIFOHEAD(fd, 3);
+ WFIFOW(fd, 0) = 0x6e;
+ switch (i) {
+ case -1: WFIFOB(fd, 2) = 0x00; break;
+ case -2: WFIFOB(fd, 2) = 0x02; break;
+ case -3: WFIFOB(fd, 2) = 0x01; break;
+ }
+ WFIFOSET(fd, 3);
+ RFIFOSKIP(fd, 37);
+ break;
}
-
+ { //Send data.
+ WFIFOHEAD(fd, 108);
WFIFOW(fd, 0) = 0x6d;
memset(WFIFOP(fd, 2), 0x00, 106);
@@ -3450,7 +3457,7 @@ int parse_char(int fd) {
WFIFOSET(fd, 108);
RFIFOSKIP(fd, 37);
-
+ }
//to do
for(ch = 0; ch < 9; ch++) {
if (sd->found_char[ch] == -1) {
@@ -3463,6 +3470,7 @@ int parse_char(int fd) {
FIFOSD_CHECK(46);
{
int cid = RFIFOL(fd,2);
+ WFIFOHEAD(fd, 46);
ShowInfo(CL_RED" Request Char Deletion:"CL_GREEN"%d (%d)"CL_RESET"\n", sd->account_id, cid);
memcpy(email, RFIFOP(fd,6), 40);
@@ -3556,12 +3564,21 @@ int parse_char(int fd) {
case 0x2af8: // login as map-server
if (RFIFOREST(fd) < 60)
return 0;
+ {
+ char *l_userid = RFIFOP(fd,2);
+ char *l_password = RFIFOP(fd,26);
+ WFIFOHEAD(fd, 4+5*GM_num);
+
+ l_userid[23] = '\0';
+ l_password[23] = '\0';
WFIFOW(fd, 0) = 0x2af9;
for(i = 0; i < MAX_MAP_SERVERS; i++) {
if (server_fd[i] <= 0)
break;
}
- if (i == MAX_MAP_SERVERS || strcmp((const char*)RFIFOP(fd,2), userid) || strcmp((const char*)RFIFOP(fd,26), passwd)) {
+ if (i == MAX_MAP_SERVERS ||
+ strcmp(l_userid, userid) ||
+ strcmp(l_password, passwd)) {
WFIFOB(fd,2) = 3;
WFIFOSET(fd, 3);
} else {
@@ -3589,7 +3606,7 @@ int parse_char(int fd) {
}
RFIFOSKIP(fd,60);
break;
-
+ }
case 0x187: // Alive?
if (RFIFOREST(fd) < 6) {
return 0;
@@ -3598,6 +3615,8 @@ int parse_char(int fd) {
break;
case 0x7530: // Athena info get
+ {
+ WFIFOHEAD(fd, 10);
WFIFOW(fd, 0) = 0x7531;
WFIFOB(fd, 2) = ATHENA_MAJOR_VERSION;
WFIFOB(fd, 3) = ATHENA_MINOR_VERSION;
@@ -3609,7 +3628,7 @@ int parse_char(int fd) {
WFIFOSET(fd, 10);
RFIFOSKIP(fd, 2);
return 0;
-
+ }
case 0x7532: // disconnect(default also disconnect)
default:
session[fd]->eof = 1;
@@ -3653,6 +3672,8 @@ int mapif_sendall(unsigned char *buf, unsigned int len) {
c = 0;
for(i = 0; i < MAX_MAP_SERVERS; i++) {
if ((fd = server_fd[i]) > 0) { //0 Should not be a valid server_fd [Skotlex]
+ WFIFOHEAD(fd,len);
+#if 0 //This seems to have been fixed long long ago.
if (session[fd] == NULL)
{ //Could this be the crash's source? [Skotlex]
ShowError("mapif_sendall: Attempting to write to invalid session %d! Map Server #%d disconnected.\n", fd, i);
@@ -3660,8 +3681,7 @@ int mapif_sendall(unsigned char *buf, unsigned int len) {
memset(&server[i], 0, sizeof(struct mmo_map_server));
continue;
}
- if (WFIFOSPACE(fd) < len) //Increase buffer size.
- realloc_writefifo(fd, len);
+#endif
memcpy(WFIFOP(fd,0), buf, len);
WFIFOSET(fd,len);
c++;
@@ -3678,8 +3698,7 @@ int mapif_sendallwos(int sfd, unsigned char *buf, unsigned int len) {
c = 0;
for(i=0, c=0;i<MAX_MAP_SERVERS;i++){
if ((fd = server_fd[i]) > 0 && fd != sfd) {
- if (WFIFOSPACE(fd) < len) //Increase buffer size.
- realloc_writefifo(fd, len);
+ WFIFOHEAD(fd, len);
memcpy(WFIFOP(fd,0), buf, len);
WFIFOSET(fd, len);
c++;
@@ -3695,8 +3714,7 @@ int mapif_send(int fd, unsigned char *buf, unsigned int len) {
if (fd >= 0) {
for(i = 0; i < MAX_MAP_SERVERS; i++) {
if (fd == server_fd[i]) {
- if (WFIFOSPACE(fd) < len) //Increase buffer size.
- realloc_writefifo(fd, len);
+ WFIFOHEAD(fd,len);
memcpy(WFIFOP(fd,0), buf, len);
WFIFOSET(fd,len);
return 1;
@@ -3712,6 +3730,7 @@ int send_users_tologin(int tid, unsigned int tick, int id, int data) {
if (login_fd > 0 && session[login_fd]) {
// send number of user to login server
+ WFIFOHEAD(login_fd,6);
WFIFOW(login_fd,0) = 0x2714;
WFIFOL(login_fd,2) = users;
WFIFOSET(login_fd,6);
@@ -3767,6 +3786,8 @@ int check_connect_login_server(int tid, unsigned int tick, int id, int data) {
}
session[login_fd]->func_parse = parse_tologin;
realloc_fifo(login_fd, FIFOSIZE_SERVERLINK, FIFOSIZE_SERVERLINK);
+ {
+ WFIFOHEAD(login_fd, 86);
WFIFOW(login_fd,0) = 0x2710;
memcpy(WFIFOP(login_fd,2), userid, 24);
memcpy(WFIFOP(login_fd,26), passwd, 24);
@@ -3776,10 +3797,9 @@ int check_connect_login_server(int tid, unsigned int tick, int id, int data) {
memcpy(WFIFOP(login_fd,60), server_name, 20);
WFIFOW(login_fd,80) = 0;
WFIFOW(login_fd,82) = char_maintenance;
-
WFIFOW(login_fd,84) = char_new_display; //only display (New) if they want to [Kevin]
-
WFIFOSET(login_fd,86);
+ }
return 0;
}
diff --git a/src/char_sql/int_guild.c b/src/char_sql/int_guild.c
index 1a1ce718a..81333db16 100644
--- a/src/char_sql/int_guild.c
+++ b/src/char_sql/int_guild.c
@@ -987,6 +987,7 @@ int guild_calcinfo(struct guild *g)
int mapif_guild_created(int fd,int account_id,struct guild *g)
{
+ WFIFOHEAD(fd, 10);
WFIFOW(fd,0)=0x3830;
WFIFOL(fd,2)=account_id;
if(g != NULL)
@@ -1031,6 +1032,7 @@ int mapif_guild_info(int fd,struct guild *g)
// ACK member add
int mapif_guild_memberadded(int fd,int guild_id,int account_id,int char_id,int flag)
{
+ WFIFOHEAD(fd, 15);
WFIFOW(fd,0)=0x3832;
WFIFOL(fd,2)=guild_id;
WFIFOL(fd,6)=account_id;
@@ -1232,7 +1234,7 @@ int mapif_guild_castle_datasave(int castle_id,int index,int value) // <Agit
int mapif_guild_castle_alldataload(int fd) {
struct guild_castle* gc = (struct guild_castle *)aMalloc(sizeof(struct guild_castle));
int i, len = 4;
-
+ WFIFOHEAD(fd, len + MAX_GUILDCASTLE*sizeof(struct guild_castle));
WFIFOW(fd,0) = 0x3842;
sprintf(tmp_sql,"SELECT * FROM `%s` ORDER BY `castle_id`", guild_castle_db);
if(mysql_query(&mysql_handle, tmp_sql) ) {
@@ -2060,6 +2062,7 @@ int mapif_parse_GuildCheck(int fd,int guild_id,int account_id,int char_id)
// ・エラーなら0(false)、そうでないなら1(true)をかえさなければならない
int inter_guild_parse_frommap(int fd)
{
+ RFIFOHEAD(fd);
switch(RFIFOW(fd,0)){
case 0x3030: mapif_parse_CreateGuild(fd,RFIFOL(fd,4),(char*)RFIFOP(fd,8),(struct guild_member *)RFIFOP(fd,32)); break;
case 0x3031: mapif_parse_GuildInfo(fd,RFIFOL(fd,2)); break;
diff --git a/src/char_sql/int_homun.c b/src/char_sql/int_homun.c
index b4c745046..d39114602 100644
--- a/src/char_sql/int_homun.c
+++ b/src/char_sql/int_homun.c
@@ -34,6 +34,7 @@ void inter_homunculus_sql_final(void){
int mapif_saved_homunculus(int fd, int account_id, unsigned char flag)
{
+ WFIFOHEAD(fd, 7);
WFIFOW(fd,0) = 0x3892;
WFIFOL(fd,2) = account_id;
WFIFOB(fd,6) = flag;
@@ -42,6 +43,7 @@ int mapif_saved_homunculus(int fd, int account_id, unsigned char flag)
}
int mapif_info_homunculus(int fd, int account_id, struct s_homunculus *hd)
{
+ WFIFOHEAD(fd, sizeof(struct s_homunculus)+9);
WFIFOW(fd,0) = 0x3891;
WFIFOW(fd,2) = sizeof(struct s_homunculus)+9;
WFIFOL(fd,4) = account_id;
@@ -54,6 +56,7 @@ int mapif_info_homunculus(int fd, int account_id, struct s_homunculus *hd)
int mapif_homunculus_deleted(int fd, int flag)
{
+ WFIFOHEAD(fd, 3);
WFIFOW(fd, 0) = 0x3893;
WFIFOB(fd,2) = flag; //Flag 1 = success
WFIFOSET(fd, 3);
@@ -140,6 +143,7 @@ int mapif_save_homunculus(int fd, int account_id, struct s_homunculus *hd)
// Load an homunculus
int mapif_load_homunculus(int fd){
int i;
+ RFIFOHEAD(fd);
memset(homun_pt, 0, sizeof(struct s_homunculus));
sprintf(tmp_sql,"SELECT `homun_id`,`char_id`,`class`,`name`,`level`,`exp`,`intimacy`,`hunger`, `str`, `agi`, `vit`, `int`, `dex`, `luk`, `hp`,`max_hp`,`sp`,`max_sp`,`skill_point`,`rename_flag`, `vaporize` FROM `homunculus` WHERE `homun_id`='%lu'", RFIFOL(fd,6));
@@ -214,6 +218,7 @@ int mapif_load_homunculus(int fd){
int mapif_delete_homunculus(int fd)
{
+ RFIFOHEAD(fd);
sprintf(tmp_sql, "DELETE FROM `homunculus` WHERE `homun_id` = '%lu'", RFIFOL(fd,2));
if(mysql_query(&mysql_handle, tmp_sql))
{
@@ -233,6 +238,7 @@ int mapif_delete_homunculus(int fd)
}
int mapif_rename_homun_ack(int fd, int account_id, int char_id, unsigned char flag, char *name){
+ WFIFOHEAD(fd, NAME_LENGTH+12);
WFIFOW(fd, 0) =0x3894;
WFIFOL(fd, 2) =account_id;
WFIFOL(fd, 6) =char_id;
@@ -267,18 +273,16 @@ int mapif_rename_homun(int fd, int account_id, int char_id, char *name){
int mapif_parse_CreateHomunculus(int fd)
{
+ RFIFOHEAD(fd);
memcpy(homun_pt, RFIFOP(fd,8), sizeof(struct s_homunculus));
// Save in sql db
if(mapif_save_homunculus(fd,RFIFOL(fd,4), homun_pt))
return mapif_homunculus_created(fd, RFIFOL(fd,4), homun_pt, 1); // send homun_id
- else
- return mapif_homunculus_created(fd, RFIFOL(fd,4), homun_pt, 0); // fail
+ return mapif_homunculus_created(fd, RFIFOL(fd,4), homun_pt, 0); // fail
}
-
-
-
int inter_homunculus_parse_frommap(int fd){
+ RFIFOHEAD(fd);
switch(RFIFOW(fd, 0)){
case 0x3090: mapif_parse_CreateHomunculus(fd); break;
case 0x3091: mapif_load_homunculus(fd); break;
diff --git a/src/char_sql/int_party.c b/src/char_sql/int_party.c
index 3ea997229..da5506903 100644
--- a/src/char_sql/int_party.c
+++ b/src/char_sql/int_party.c
@@ -382,6 +382,7 @@ int party_check_conflict(int party_id,int account_id,int char_id)
// パーティ作成可否
int mapif_party_created(int fd,int account_id,int char_id,struct party *p)
{
+ WFIFOHEAD(fd, 39);
WFIFOW(fd,0)=0x3820;
WFIFOL(fd,2)=account_id;
WFIFOL(fd,6)=char_id;
@@ -403,6 +404,7 @@ int mapif_party_created(int fd,int account_id,int char_id,struct party *p)
// パーティ情報見つからず
int mapif_party_noinfo(int fd,int party_id)
{
+ WFIFOHEAD(fd,8);
WFIFOW(fd,0)=0x3821;
WFIFOW(fd,2)=8;
WFIFOL(fd,4)=party_id;
diff --git a/src/char_sql/int_pet.c b/src/char_sql/int_pet.c
index 5d5dc0615..69eb4ec02 100644
--- a/src/char_sql/int_pet.c
+++ b/src/char_sql/int_pet.c
@@ -141,6 +141,7 @@ int inter_pet_delete(int pet_id){
//------------------------------------------------------
int mapif_pet_created(int fd, int account_id, struct s_pet *p)
{
+ WFIFOHEAD(fd, 11);
WFIFOW(fd, 0) =0x3880;
WFIFOL(fd, 2) =account_id;
if(p!=NULL){
@@ -157,6 +158,7 @@ int mapif_pet_created(int fd, int account_id, struct s_pet *p)
}
int mapif_pet_info(int fd, int account_id, struct s_pet *p){
+ WFIFOHEAD(fd, sizeof(struct s_pet) + 9);
WFIFOW(fd, 0) =0x3881;
WFIFOW(fd, 2) =sizeof(struct s_pet) + 9;
WFIFOL(fd, 4) =account_id;
@@ -168,6 +170,7 @@ int mapif_pet_info(int fd, int account_id, struct s_pet *p){
}
int mapif_pet_noinfo(int fd, int account_id){
+ WFIFOHEAD(fd, sizeof(struct s_pet) + 9);
WFIFOW(fd, 0) =0x3881;
WFIFOW(fd, 2) =sizeof(struct s_pet) + 9;
WFIFOL(fd, 4) =account_id;
@@ -179,6 +182,7 @@ int mapif_pet_noinfo(int fd, int account_id){
}
int mapif_save_pet_ack(int fd, int account_id, int flag){
+ WFIFOHEAD(fd, 7);
WFIFOW(fd, 0) =0x3882;
WFIFOL(fd, 2) =account_id;
WFIFOB(fd, 6) =flag;
@@ -188,6 +192,7 @@ int mapif_save_pet_ack(int fd, int account_id, int flag){
}
int mapif_delete_pet_ack(int fd, int flag){
+ WFIFOHEAD(fd, 3);
WFIFOW(fd, 0) =0x3883;
WFIFOB(fd, 2) =flag;
WFIFOSET(fd, 3);
@@ -196,6 +201,7 @@ int mapif_delete_pet_ack(int fd, int flag){
}
int mapif_rename_pet_ack(int fd, int account_id, int char_id, int flag, char *name){
+ WFIFOHEAD(fd, NAME_LENGTH+12);
WFIFOW(fd, 0) =0x3884;
WFIFOL(fd, 2) =account_id;
WFIFOL(fd, 6) =char_id;
@@ -268,7 +274,9 @@ int mapif_load_pet(int fd, int account_id, int char_id, int pet_id){
int mapif_save_pet(int fd, int account_id, struct s_pet *data) {
//here process pet save request.
- int len=RFIFOW(fd, 2);
+ int len;
+ RFIFOHEAD(fd);
+ len=RFIFOW(fd, 2);
if(sizeof(struct s_pet)!=len-8) {
ShowError("inter pet: data size error %d %d\n", sizeof(struct s_pet), len-8);
}
@@ -318,32 +326,38 @@ int mapif_rename_pet(int fd, int account_id, int char_id, char *name){
}
int mapif_parse_CreatePet(int fd){
+ RFIFOHEAD(fd);
mapif_create_pet(fd, RFIFOL(fd, 2), RFIFOL(fd, 6), RFIFOW(fd, 10), RFIFOW(fd, 12), RFIFOW(fd, 14), RFIFOW(fd, 16), RFIFOW(fd, 18),
RFIFOW(fd, 20), RFIFOB(fd, 22), RFIFOB(fd, 23), (char*)RFIFOP(fd, 24));
return 0;
}
int mapif_parse_LoadPet(int fd){
+ RFIFOHEAD(fd);
mapif_load_pet(fd, RFIFOL(fd, 2), RFIFOL(fd, 6), RFIFOL(fd, 10));
return 0;
}
int mapif_parse_SavePet(int fd){
+ RFIFOHEAD(fd);
mapif_save_pet(fd, RFIFOL(fd, 4), (struct s_pet *) RFIFOP(fd, 8));
return 0;
}
int mapif_parse_DeletePet(int fd){
+ RFIFOHEAD(fd);
mapif_delete_pet(fd, RFIFOL(fd, 2));
return 0;
}
int mapif_parse_RenamePet(int fd){
+ RFIFOHEAD(fd);
mapif_rename_pet(fd, RFIFOL(fd, 2), RFIFOL(fd, 6), RFIFOP(fd, 10));
return 0;
}
int inter_pet_parse_frommap(int fd){
+ RFIFOHEAD(fd);
switch(RFIFOW(fd, 0)){
case 0x3080: mapif_parse_CreatePet(fd); break;
case 0x3081: mapif_parse_LoadPet(fd); break;
diff --git a/src/char_sql/int_storage.c b/src/char_sql/int_storage.c
index 3ed0c2aa9..578de6bc8 100644
--- a/src/char_sql/int_storage.c
+++ b/src/char_sql/int_storage.c
@@ -223,6 +223,7 @@ int inter_guild_storage_delete(int guild_id)
// recive packet about storage data
int mapif_load_storage(int fd,int account_id){
//load from DB
+ WFIFOHEAD(fd, sizeof(struct storage)+8);
storage_fromsql(account_id, storage_pt);
WFIFOW(fd,0)=0x3810;
WFIFOW(fd,2)=sizeof(struct storage)+8;
@@ -233,6 +234,7 @@ int mapif_load_storage(int fd,int account_id){
}
// send ack to map server which is "storage data save ok."
int mapif_save_storage_ack(int fd,int account_id){
+ WFIFOHEAD(fd, 7);
WFIFOW(fd,0)=0x3811;
WFIFOL(fd,2)=account_id;
WFIFOB(fd,6)=0;
@@ -243,6 +245,7 @@ int mapif_save_storage_ack(int fd,int account_id){
int mapif_load_guild_storage(int fd,int account_id,int guild_id)
{
int guild_exist=1;
+ WFIFOHEAD(fd, sizeof(struct guild_storage)+12);
WFIFOW(fd,0)=0x3818;
#if 0 // innodb guilds should render this check unnecessary [Aru]
@@ -279,6 +282,7 @@ int mapif_load_guild_storage(int fd,int account_id,int guild_id)
}
int mapif_save_guild_storage_ack(int fd,int account_id,int guild_id,int fail)
{
+ WFIFOHEAD(fd,11);
WFIFOW(fd,0)=0x3819;
WFIFOL(fd,2)=account_id;
WFIFOL(fd,6)=guild_id;
@@ -292,14 +296,17 @@ int mapif_save_guild_storage_ack(int fd,int account_id,int guild_id,int fail)
// recive request about storage data
int mapif_parse_LoadStorage(int fd){
+ RFIFOHEAD(fd);
mapif_load_storage(fd,RFIFOL(fd,2));
return 0;
}
// storage data recive and save
int mapif_parse_SaveStorage(int fd){
- int account_id=RFIFOL(fd,4);
- int len=RFIFOW(fd,2);
-
+ int account_id;
+ int len;
+ RFIFOHEAD(fd);
+ account_id=RFIFOL(fd,4);
+ len=RFIFOW(fd,2);
if(sizeof(struct storage)!=len-8){
ShowError("inter storage: data size error %d %d\n",sizeof(struct storage),len-8);
}else{
@@ -312,6 +319,7 @@ int mapif_parse_SaveStorage(int fd){
int mapif_parse_LoadGuildStorage(int fd)
{
+ RFIFOHEAD(fd);
mapif_load_guild_storage(fd,RFIFOL(fd,2),RFIFOL(fd,6));
return 0;
}
@@ -319,8 +327,11 @@ int mapif_parse_LoadGuildStorage(int fd)
int mapif_parse_SaveGuildStorage(int fd)
{
int guild_exist=1;
- int guild_id=RFIFOL(fd,8);
- int len=RFIFOW(fd,2);
+ int guild_id;
+ int len;
+ RFIFOHEAD(fd);
+ guild_id=RFIFOL(fd,8);
+ len=RFIFOW(fd,2);
if(sizeof(struct guild_storage)!=len-12){
ShowError("inter storage: data size error %d %d\n",sizeof(struct guild_storage),len-12);
}
@@ -354,6 +365,7 @@ int mapif_parse_SaveGuildStorage(int fd)
int inter_storage_parse_frommap(int fd){
+ RFIFOHEAD(fd);
switch(RFIFOW(fd,0)){
case 0x3010: mapif_parse_LoadStorage(fd); break;
case 0x3011: mapif_parse_SaveStorage(fd); break;
diff --git a/src/char_sql/inter.c b/src/char_sql/inter.c
index 249d260a6..5ce452717 100644
--- a/src/char_sql/inter.c
+++ b/src/char_sql/inter.c
@@ -493,8 +493,9 @@ int mapif_account_reg(int fd,unsigned char *src)
int mapif_account_reg_reply(int fd,int account_id,int char_id, int type)
{
struct accreg *reg=accreg_pt;
+ WFIFOHEAD(fd, 13 + 5000);
inter_accreg_fromsql(account_id,char_id,reg,type);
-
+
WFIFOW(fd,0)=0x3804;
WFIFOL(fd,4)=account_id;
WFIFOL(fd,8)=char_id;
@@ -503,11 +504,13 @@ int mapif_account_reg_reply(int fd,int account_id,int char_id, int type)
WFIFOW(fd,2)=13;
}else{
int i,p;
- for (p=13,i = 0; i < reg->reg_num; i++) {
+ for (p=13,i = 0; i < reg->reg_num && p < 5000; i++) {
p+= sprintf(WFIFOP(fd,p), "%s", reg->reg[i].str)+1; //We add 1 to consider the '\0' in place.
p+= sprintf(WFIFOP(fd,p), "%s", reg->reg[i].value)+1;
}
WFIFOW(fd,2)=p;
+ if (p>= 5000)
+ ShowWarning("Too many acc regs for %d:%d, not all values were loaded.\n", account_id, char_id);
}
WFIFOSET(fd,WFIFOW(fd,2));
return 0;
@@ -547,14 +550,16 @@ void mapif_send_maxid(int account_id, int char_id)
//Request to kick char from a certain map server. [Skotlex]
int mapif_disconnectplayer(int fd, int account_id, int char_id, int reason)
{
- if (fd < 0)
- return -1;
-
- WFIFOW(fd,0) = 0x2b1f;
- WFIFOL(fd,2) = account_id;
- WFIFOB(fd,6) = reason;
- WFIFOSET(fd,7);
- return 0;
+ if (fd >= 0)
+ {
+ WFIFOHEAD(fd,7);
+ WFIFOW(fd,0) = 0x2b1f;
+ WFIFOL(fd,2) = account_id;
+ WFIFOB(fd,6) = reason;
+ WFIFOSET(fd,7);
+ return 0;
+ }
+ return -1;
}
//--------------------------------------------------------
@@ -595,6 +600,7 @@ int check_ttl_wisdata(void) {
// GM message sending
int mapif_parse_GMmessage(int fd)
{
+ RFIFOHEAD(fd);
mapif_GMmessage(RFIFOP(fd, 8), RFIFOW(fd, 2), RFIFOL(fd, 4), fd);
return 0;
}
@@ -605,7 +611,7 @@ int mapif_parse_WisRequest(int fd) {
struct WisData* wd;
static int wisid = 0;
char name[NAME_LENGTH], t_name[NAME_LENGTH*2]; //Needs space to allocate names with escaped chars [Skotlex]
-
+ RFIFOHEAD(fd);
if ( fd <= 0 ) {return 0;} // check if we have a valid fd
if (RFIFOW(fd,2)-52 >= sizeof(wd->msg)) {
@@ -675,9 +681,12 @@ int mapif_parse_WisRequest(int fd) {
// Wisp/page transmission result
int mapif_parse_WisReply(int fd) {
- int id = RFIFOL(fd,2), flag = RFIFOB(fd,6);
- struct WisData *wd = idb_get(wis_db, id);
-
+ int id, flag;
+ struct WisData *wd;
+ RFIFOHEAD(fd);
+ id = RFIFOL(fd,2);
+ flag = RFIFOB(fd,6);
+ wd = idb_get(wis_db, id);
if (wd == NULL)
return 0; // This wisp was probably suppress before, because it was timeout of because of target was found on another map-server
@@ -692,7 +701,7 @@ int mapif_parse_WisReply(int fd) {
// Received wisp message from map-server for ALL gm (just copy the message and resends it to ALL map-servers)
int mapif_parse_WisToGM(int fd) {
unsigned char buf[2048]; // 0x3003/0x3803 <packet_len>.w <wispname>.24B <min_gm_level>.w <message>.?B
-
+ RFIFOHEAD(fd);
ShowDebug("Sent packet back!\n");
memcpy(WBUFP(buf,0), RFIFOP(fd,0), RFIFOW(fd,2));
WBUFW(buf, 0) = 0x3803;
@@ -706,7 +715,7 @@ int mapif_parse_Registry(int fd)
{
int j,p,len, max;
struct accreg *reg=accreg_pt;
-
+ RFIFOHEAD(fd);
memset(accreg_pt,0,sizeof(struct accreg));
switch (RFIFOB(fd, 12)) {
case 3: //Character registry
@@ -754,9 +763,10 @@ int mapif_parse_RegistryRequest(int fd)
//--------------------------------------------------------
int inter_parse_frommap(int fd)
{
- int cmd=RFIFOW(fd,0);
+ int cmd;
int len=0;
-
+ RFIFOHEAD(fd);
+ cmd=RFIFOW(fd,0);
// inter鯖管轄かを調べ
if(cmd < 0x3000 || cmd >= 0x3000 + (sizeof(inter_recv_packet_length)/
sizeof(inter_recv_packet_length[0]) ) )
@@ -797,6 +807,7 @@ int inter_parse_frommap(int fd)
// RFIFO check
int inter_check_length(int fd, int length)
{
+ RFIFOHEAD(fd);
if(length==-1){ // v-len packet
if(RFIFOREST(fd)<4) // packet not yet
return 0;