From 83c8869a0d8764b7de4590e4cacc4b54a7d15133 Mon Sep 17 00:00:00 2001 From: "Guilherme G. Menaldo" Date: Sat, 3 Aug 2024 01:00:39 -0300 Subject: [PATCH] Convert CHARLOGIN_SET_ACCOUNT_ONLINE to struct format --- src/char/char.c | 11 +++++++---- src/common/HPMDataCheck.h | 2 +- src/common/charloginpackets.h | 6 ++++++ src/login/login.c | 13 ++++++++----- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/char/char.c b/src/char/char.c index 4cfd48075d3..9bebb8368de 100644 --- a/src/char/char.c +++ b/src/char/char.c @@ -207,10 +207,13 @@ static struct DBData char_create_online_char_data(union DBKey key, va_list args) static void char_set_account_online(int account_id) { - WFIFOHEAD(chr->login_fd,6); - WFIFOW(chr->login_fd,0) = 0x272b; - WFIFOL(chr->login_fd,2) = account_id; - WFIFOSET(chr->login_fd,6); + WFIFOHEAD(chr->login_fd, sizeof(struct PACKET_CHARLOGIN_SET_ACCOUNT_ONLINE)); + + struct PACKET_CHARLOGIN_SET_ACCOUNT_ONLINE *p = WFIFOP(chr->login_fd, 0); + p->packetType = HEADER_CHARLOGIN_SET_ACCOUNT_ONLINE; + p->account_id = account_id; + + WFIFOSET(chr->login_fd, sizeof(*p)); } static void char_set_account_offline(int account_id) diff --git a/src/common/HPMDataCheck.h b/src/common/HPMDataCheck.h index 4f9f3bb17e3..ae7e5f5601f 100644 --- a/src/common/HPMDataCheck.h +++ b/src/common/HPMDataCheck.h @@ -255,7 +255,7 @@ HPExport const struct s_HPMDataCheck HPMDataCheck[] = { #define COMMON_BASE62_H #endif // COMMON_BASE62_H #ifdef COMMON_CHARLOGINPACKETS_H - { "PACKET_CHARLOGIN_ONLINE_ACCOUNTS", sizeof(struct PACKET_CHARLOGIN_ONLINE_ACCOUNTS), SERVER_TYPE_ALL }, + { "PACKET_CHARLOGIN_SET_ACCOUNT_ONLINE", sizeof(struct PACKET_CHARLOGIN_SET_ACCOUNT_ONLINE), SERVER_TYPE_ALL }, #else #define COMMON_CHARLOGINPACKETS_H #endif // COMMON_CHARLOGINPACKETS_H diff --git a/src/common/charloginpackets.h b/src/common/charloginpackets.h index bdfda7c7d1f..92f69ee4c16 100644 --- a/src/common/charloginpackets.h +++ b/src/common/charloginpackets.h @@ -30,6 +30,12 @@ #pragma pack(push, 1) #endif // not NetBSD < 6 / Solaris +struct PACKET_CHARLOGIN_SET_ACCOUNT_ONLINE { + int16 packetType; + int account_id; +} __attribute__((packed)); +DEFINE_PACKET_ID(CHARLOGIN_SET_ACCOUNT_ONLINE, 0x272b) + struct PACKET_CHARLOGIN_ONLINE_ACCOUNTS { int16 packetType; uint16 packetLength; diff --git a/src/login/login.c b/src/login/login.c index 20ad72d7d33..fc9d1ce0454 100644 --- a/src/login/login.c +++ b/src/login/login.c @@ -663,9 +663,12 @@ static void login_fromchar_parse_unban(int fd, int id, const char *const ip) static void login_fromchar_parse_account_online(int fd, int id) { - login->add_online_user(id, RFIFOL(fd,2)); - lapiif->connect_user_char(id, RFIFOL(fd, 2)); - RFIFOSKIP(fd, 6); + const struct PACKET_CHARLOGIN_SET_ACCOUNT_ONLINE *p = RFIFOP(fd, 0); + + login->add_online_user(id, p->account_id); + lapiif->connect_user_char(id, p->account_id); + + RFIFOSKIP(fd, sizeof(*p)); } static void login_fromchar_parse_account_offline(int fd) @@ -939,8 +942,8 @@ static int login_parse_fromchar(int fd) } break; - case 0x272b: // Set account_id to online [Wizputer] - if( RFIFOREST(fd) < 6 ) + case HEADER_CHARLOGIN_SET_ACCOUNT_ONLINE: // Set account_id to online [Wizputer] + if (RFIFOREST(fd) < sizeof(struct PACKET_CHARLOGIN_SET_ACCOUNT_ONLINE)) return 0; login->fromchar_parse_account_online(fd, id); break;