diff options
author | Andrei Karas <akaras@inbox.ru> | 2018-11-30 19:51:42 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2018-12-12 21:18:07 +0300 |
commit | 9a454fc1d03e7c3e1a39745742626e6f13b31378 (patch) | |
tree | 2206f32994c2e2117042699063314fb183719be1 | |
parent | 63f57fa5c3944ba7759f84361dd42391709f21c8 (diff) | |
download | hercules-9a454fc1d03e7c3e1a39745742626e6f13b31378.tar.gz hercules-9a454fc1d03e7c3e1a39745742626e6f13b31378.tar.bz2 hercules-9a454fc1d03e7c3e1a39745742626e6f13b31378.tar.xz hercules-9a454fc1d03e7c3e1a39745742626e6f13b31378.zip |
Fix issue with chars list if number of chars is 3*N chars.
Also introduced header file with HC packet structs.
-rw-r--r-- | src/char/Makefile.in | 2 | ||||
-rw-r--r-- | src/char/char.c | 53 | ||||
-rw-r--r-- | src/char/char.h | 4 | ||||
-rw-r--r-- | src/char/packets_hc_struct.h | 45 |
4 files changed, 83 insertions, 21 deletions
diff --git a/src/char/Makefile.in b/src/char/Makefile.in index 95c8df813..f159a443f 100644 --- a/src/char/Makefile.in +++ b/src/char/Makefile.in @@ -46,7 +46,7 @@ CHAR_C = char.c HPMchar.c loginif.c mapif.c geoip.c inter.c int_achievement.c in CHAR_OBJ = $(addprefix obj_sql/, $(patsubst %.c,%.o,$(CHAR_C))) CHAR_H = char.h HPMchar.h loginif.h mapif.h geoip.h inter.h int_achievement.h int_auction.h int_clan.h int_elemental.h \ int_guild.h int_homun.h int_mail.h int_mercenary.h int_party.h int_pet.h \ - int_quest.h int_rodex.h int_storage.h pincode.h + int_quest.h int_rodex.h int_storage.h pincode.h packets_hc_struct.h CHAR_PH = HAVE_MYSQL=@HAVE_MYSQL@ diff --git a/src/char/char.c b/src/char/char.c index 023ab0ade..e08933f7b 100644 --- a/src/char/char.c +++ b/src/char/char.c @@ -41,6 +41,7 @@ #include "char/inter.h" #include "char/loginif.h" #include "char/mapif.h" +#include "char/packets_hc_struct.h" #include "char/pincode.h" #include "common/HPM.h" @@ -1051,7 +1052,7 @@ static int char_mmo_gender(const struct char_session_data *sd, const struct mmo_ //===================================================================================================== // Loads the basic character rooster for the given account. Returns total buffer used. -static int char_mmo_chars_fromsql(struct char_session_data *sd, uint8 *buf) +static int char_mmo_chars_fromsql(struct char_session_data *sd, uint8 *buf, int *count) { struct SqlStmt *stmt; struct mmo_charstatus p; @@ -1060,6 +1061,9 @@ static int char_mmo_chars_fromsql(struct char_session_data *sd, uint8 *buf) time_t unban_time = 0; char sex[2]; + if (count) + *count = 0; + nullpo_ret(sd); nullpo_ret(buf); @@ -1131,7 +1135,8 @@ static int char_mmo_chars_fromsql(struct char_session_data *sd, uint8 *buf) return 0; } - for( i = 0; i < MAX_CHARS && SQL_SUCCESS == SQL->StmtNextRow(stmt); i++ ) { + int tmpCount = 0; + for (i = 0; i < MAX_CHARS && SQL_SUCCESS == SQL->StmtNextRow(stmt); i++) { if (p.slot >= MAX_CHARS) continue; p.last_point.map = mapindex->name2id(last_map); @@ -1139,11 +1144,14 @@ static int char_mmo_chars_fromsql(struct char_session_data *sd, uint8 *buf) sd->unban_time[p.slot] = unban_time; p.sex = chr->mmo_gender(sd, &p, sex[0]); j += chr->mmo_char_tobuf(WBUFP(buf, j), &p); + tmpCount ++; } - memset(sd->new_name,0,sizeof(sd->new_name)); + memset(sd->new_name, 0, sizeof(sd->new_name)); SQL->StmtFree(stmt); + if (count) + *count = tmpCount; return j; } @@ -2099,14 +2107,23 @@ static int char_mmo_char_tobuf(uint8 *buffer, struct mmo_charstatus *p) } /* Made Possible by Yommy~! <3 */ -static void char_mmo_char_send099d(int fd, struct char_session_data *sd) -{ -// support added for client between 20121010 and 20130320 -#if PACKETVER > 20120418 - WFIFOHEAD(fd,4 + (MAX_CHARS*MAX_CHAR_BUF)); - WFIFOW(fd,0) = 0x99d; - WFIFOW(fd,2) = chr->mmo_chars_fromsql(sd, WFIFOP(fd,4)) + 4; - WFIFOSET(fd,WFIFOW(fd,2)); +static void char_send_HC_ACK_CHARINFO_PER_PAGE(int fd, struct char_session_data *sd) +{ +#if PACKETVER_MAIN_NUM >= 20130522 || PACKETVER_RE_NUM >= 20130327 || defined(PACKETVER_ZERO) + WFIFOHEAD(fd, sizeof(struct PACKET_HC_ACK_CHARINFO_PER_PAGE) + (MAX_CHARS * MAX_CHAR_BUF)); + struct PACKET_HC_ACK_CHARINFO_PER_PAGE *p = WFIFOP(fd, 0); + int count = 0; + p->packetId = HEADER_HC_ACK_CHARINFO_PER_PAGE; + p->packetLen = chr->mmo_chars_fromsql(sd, WFIFOP(fd, 4), &count) + sizeof(struct PACKET_HC_ACK_CHARINFO_PER_PAGE); + WFIFOSET(fd, p->packetLen); + // send empty packet if chars count is 3*N, for trigger final code in client + if (count % 3 != 0) { + WFIFOHEAD(fd, sizeof(struct PACKET_HC_ACK_CHARINFO_PER_PAGE)); + p = WFIFOP(fd, 0); + p->packetId = HEADER_HC_ACK_CHARINFO_PER_PAGE; + p->packetLen = sizeof(struct PACKET_HC_ACK_CHARINFO_PER_PAGE); + WFIFOSET(fd, p->packetLen); + } #endif } @@ -2192,7 +2209,7 @@ static int char_mmo_char_send_characters(int fd, struct char_session_data *sd) WFIFOB(fd,6) = MAX_CHARS; // Premium slots. AKA any existent chars past sd->char_slots but within MAX_CHARS will show a 'Premium Service' in red #endif memset(WFIFOP(fd,4 + offset), 0, 20); // unknown bytes - j+=chr->mmo_chars_fromsql(sd, WFIFOP(fd,j)); + j += chr->mmo_chars_fromsql(sd, WFIFOP(fd, j), NULL); WFIFOW(fd,2) = j; // packet len WFIFOSET(fd,j); @@ -4173,10 +4190,10 @@ static void char_delete2_accept_actual_ack(int fd, int char_id, uint32 result) /// Any (0x718): An unknown error has occurred. static void char_delete2_accept_ack(int fd, int char_id, uint32 result) {// HC: <082a>.W <char id>.L <Msg:0-5>.L -#if PACKETVER >= 20130000 /* not sure the exact date -- must refresh or client gets stuck */ +#if PACKETVER_MAIN_NUM >= 20130522 || PACKETVER_RE_NUM >= 20130327 || defined(PACKETVER_ZERO) if( result == 1 ) { struct char_session_data* sd = (struct char_session_data*)sockt->session[fd]->session_data; - chr->mmo_char_send099d(fd, sd); + chr->send_HC_ACK_CHARINFO_PER_PAGE(fd, sd); } #endif chr->delete2_accept_actual_ack(fd, char_id, result); @@ -5009,7 +5026,7 @@ static void char_parse_char_pincode_first_pin(int fd, struct char_session_data * static void char_parse_char_request_chars(int fd, struct char_session_data *sd) { - chr->mmo_char_send099d(fd, sd); + chr->send_HC_ACK_CHARINFO_PER_PAGE(fd, sd); RFIFOSKIP(fd,2); } @@ -5029,8 +5046,8 @@ static void char_parse_char_move_character(int fd, struct char_session_data *sd) chr->change_character_slot_ack(fd, ret); /* for some stupid reason it requires the char data again (gravity -_-) */ if( ret ) -#if PACKETVER >= 20130000 - chr->mmo_char_send099d(fd, sd); +#if PACKETVER_MAIN_NUM >= 20130522 || PACKETVER_RE_NUM >= 20130327 || defined(PACKETVER_ZERO) + chr->send_HC_ACK_CHARINFO_PER_PAGE(fd, sd); #else chr->mmo_char_send_characters(fd, sd); #endif @@ -6427,7 +6444,7 @@ void char_defaults(void) chr->divorce_char_sql = char_divorce_char_sql; chr->count_users = char_count_users; chr->mmo_char_tobuf = char_mmo_char_tobuf; - chr->mmo_char_send099d = char_mmo_char_send099d; + chr->send_HC_ACK_CHARINFO_PER_PAGE = char_send_HC_ACK_CHARINFO_PER_PAGE; chr->mmo_char_send_ban_list = char_mmo_char_send_ban_list; chr->mmo_char_send_slots_info = char_mmo_char_send_slots_info; chr->mmo_char_send_characters = char_mmo_char_send_characters; diff --git a/src/char/char.h b/src/char/char.h index 81cab1eaf..914530537 100644 --- a/src/char/char.h +++ b/src/char/char.h @@ -142,7 +142,7 @@ struct char_interface { int (*getitemdata_from_sql) (struct item *items, int max, int guid, enum inventory_table_type table); int (*memitemdata_to_sql) (const struct item items[], int id, enum inventory_table_type table); int (*mmo_gender) (const struct char_session_data *sd, const struct mmo_charstatus *p, char sex); - int (*mmo_chars_fromsql) (struct char_session_data* sd, uint8* buf); + int (*mmo_chars_fromsql) (struct char_session_data* sd, uint8* buf, int *count); int (*mmo_char_fromsql) (int char_id, struct mmo_charstatus* p, bool load_everything); int (*mmo_char_sql_init) (void); bool (*char_slotchange) (struct char_session_data *sd, int fd, unsigned short from, unsigned short to); @@ -153,7 +153,7 @@ struct char_interface { int (*divorce_char_sql) (int partner_id1, int partner_id2); int (*count_users) (void); int (*mmo_char_tobuf) (uint8* buffer, struct mmo_charstatus* p); - void (*mmo_char_send099d) (int fd, struct char_session_data *sd); + void (*send_HC_ACK_CHARINFO_PER_PAGE) (int fd, struct char_session_data *sd); void (*mmo_char_send_ban_list) (int fd, struct char_session_data *sd); void (*mmo_char_send_slots_info) (int fd, struct char_session_data* sd); int (*mmo_char_send_characters) (int fd, struct char_session_data* sd); diff --git a/src/char/packets_hc_struct.h b/src/char/packets_hc_struct.h new file mode 100644 index 000000000..196493cac --- /dev/null +++ b/src/char/packets_hc_struct.h @@ -0,0 +1,45 @@ +/** + * This file is part of Hercules. + * http://herc.ws - http://github.com/HerculesWS/Hercules + * + * Copyright (C) 2016-2018 Hercules Dev Team + * + * Hercules is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef CHAR_PACKETS_HC_STRUCT_H +#define CHAR_PACKETS_HC_STRUCT_H + +#include "common/hercules.h" +#include "common/mmo.h" +#include "common/packetsstatic_len.h" + +/* Packets Structs */ +#if !defined(sun) && (!defined(__NETBSD__) || __NetBSD_Version__ >= 600000000) // NetBSD 5 and Solaris don't like pragma pack but accept the packed attribute +#pragma pack(push, 1) +#endif // not NetBSD < 6 / Solaris + +#if PACKETVER_MAIN_NUM >= 20130522 || PACKETVER_RE_NUM >= 20130327 || defined(PACKETVER_ZERO) +struct PACKET_HC_ACK_CHARINFO_PER_PAGE { + int16 packetId; + int16 packetLen; + // chars list[] +} __attribute__((packed)); +DEFINE_PACKET_HEADER(HC_ACK_CHARINFO_PER_PAGE, 0x099d); +#endif + +#if !defined(sun) && (!defined(__NETBSD__) || __NetBSD_Version__ >= 600000000) // NetBSD 5 and Solaris don't like pragma pack but accept the packed attribute +#pragma pack(pop) +#endif // not NetBSD < 6 / Solaris + +#endif // CHAR_PACKETS_HC_STRUCT_H |