From 33b7eb4df9dd7df83f00cf4d6891723beb9c5a28 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/charloginpackets.h | 6 ++++++ src/login/login.c | 13 ++++++++----- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/char/char.c b/src/char/char.c index 78af999b6c7..534b34962b2 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/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;