From 9f414cf60e08d8c79b131418dc9249c2dbe16f58 Mon Sep 17 00:00:00 2001 From: "Guilherme G. Menaldo" Date: Sat, 3 Aug 2024 01:21:09 -0300 Subject: [PATCH] Stop sending standalone characters (e.g. autotraders) connection to API server API server won't have those user accounts and error out, since they won't use the API server anyway, we don't have to send them there --- src/char/char.c | 33 ++++++++++--------- src/char/char.h | 4 +-- src/common/HPMDataCheck.h | 7 +++- src/common/charloginpackets.h | 1 + src/login/login.c | 6 +++- src/plugins/HPMHooking/HPMHooking.Defs.inc | 14 +++++--- .../HPMHooking/HPMHooking_char.Hooks.inc | 24 +++++++------- 7 files changed, 53 insertions(+), 36 deletions(-) diff --git a/src/char/char.c b/src/char/char.c index 534b34962b2..fd4103f4db6 100644 --- a/src/char/char.c +++ b/src/char/char.c @@ -205,13 +205,14 @@ static struct DBData char_create_online_char_data(union DBKey key, va_list args) return DB->ptr2data(character); } -static void char_set_account_online(int account_id) +static void char_set_account_online(int account_id, bool standalone) { 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; + p->standalone = standalone ? 1 : 0; WFIFOSET(chr->login_fd, sizeof(*p)); } @@ -247,10 +248,10 @@ static void char_set_char_charselect(int account_id) } if (chr->login_fd > 0 && !sockt->session[chr->login_fd]->flag.eof) - chr->set_account_online(account_id); + chr->set_account_online(account_id, false); } -static void char_set_char_online(bool is_initializing, int char_id, int account_id) +static void char_set_char_online(bool is_initializing, int char_id, int account_id, bool standalone) { struct online_char_data* character; struct mmo_charstatus *cp; @@ -284,7 +285,7 @@ static void char_set_char_online(bool is_initializing, int char_id, int account_ //Notify login server if (chr->login_fd > 0 && !sockt->session[chr->login_fd]->flag.eof) - chr->set_account_online(account_id); + chr->set_account_online(account_id, standalone); } static void char_set_char_offline(int char_id, int account_id) @@ -3279,7 +3280,7 @@ static void char_parse_frommap_save_character(int fd) } else { //This may be valid on char-server reconnection, when re-sending characters that already logged off. ShowError("parse_from_map (save-char): Received data for non-existing/offline character (%d:%d).\n", aid, cid); - chr->set_char_online(false, cid, aid); + chr->set_char_online(false, cid, aid, false); } if (RFIFOB(fd,12)) { @@ -3681,7 +3682,7 @@ static void char_parse_frommap_set_all_offline(int fd) static void char_parse_frommap_set_char_online(int fd) { - chr->set_char_online(false, RFIFOL(fd, 2), RFIFOL(fd, 6)); + chr->set_char_online(false, RFIFOL(fd, 2), RFIFOL(fd, 6), false); RFIFOSKIP(fd,10); } @@ -3787,12 +3788,12 @@ static void char_parse_frommap_auth_request(int fd) const struct PACKET_MAPCHAR_AUTH_REQ *p = RFIFOP(fd, 0); - int account_id = p->account_id; - int char_id = p->char_id; - int login_id1 = p->login_id1; - char sex = p->sex; - uint32 ip = ntohl(p->client_addr); - char standalone = p->standalone; + int account_id = p->account_id; + int char_id = p->char_id; + int login_id1 = p->login_id1; + char sex = p->sex; + uint32 ip = ntohl(p->client_addr); + uint8 standalone = p->standalone; RFIFOSKIP(fd, sizeof(struct PACKET_MAPCHAR_AUTH_REQ)); @@ -3804,11 +3805,11 @@ static void char_parse_frommap_auth_request(int fd) cd = (struct mmo_charstatus*)uidb_get(chr->char_db_,char_id); } - if( core->runflag == CHARSERVER_ST_RUNNING && cd && standalone ) { + if (core->runflag == CHARSERVER_ST_RUNNING && cd != NULL && standalone != 0) { cd->sex = sex; chr->map_auth_ok(fd, account_id, NULL, cd); - chr->set_char_online(false, char_id, account_id); + chr->set_char_online(false, char_id, account_id, true); return; } @@ -3827,7 +3828,7 @@ static void char_parse_frommap_auth_request(int fd) chr->map_auth_ok(fd, account_id, node, cd); // only use the auth once and mark user online idb_remove(auth_db, account_id); - chr->set_char_online(false, char_id, account_id); + chr->set_char_online(false, char_id, account_id, (standalone != 0)); } else {// auth failed @@ -4583,7 +4584,7 @@ static void char_parse_char_select(int fd, struct char_session_data *sd, uint32 } /* set char as online prior to loading its data so 3rd party applications will realize the sql data is not reliable */ - chr->set_char_online(true, char_id, sd->account_id); + chr->set_char_online(true, char_id, sd->account_id, false); loginif->set_char_online(char_id, sd->account_id); if (!chr->mmo_char_fromsql(char_id, &char_dat, true)) { /* failed? set it back offline */ chr->set_char_offline(char_id, sd->account_id); diff --git a/src/char/char.h b/src/char/char.h index bb697bb609a..325b964840e 100644 --- a/src/char/char.h +++ b/src/char/char.h @@ -140,10 +140,10 @@ struct char_interface { int (*waiting_disconnect) (int tid, int64 tick, int id, intptr_t data); int (*delete_char_sql) (int char_id); struct DBData (*create_online_char_data) (union DBKey key, va_list args); - void (*set_account_online) (int account_id); + void (*set_account_online) (int account_id, bool standalone); void (*set_account_offline) (int account_id); void (*set_char_charselect) (int account_id); - void (*set_char_online) (bool is_initializing, int char_id, int account_id); + void (*set_char_online) (bool is_initializing, int char_id, int account_id, bool standalone); void (*set_char_offline) (int char_id, int account_id); int (*db_setoffline) (union DBKey key, struct DBData *data, va_list ap); int (*db_kickoffline) (union DBKey key, struct DBData *data, va_list ap); diff --git a/src/common/HPMDataCheck.h b/src/common/HPMDataCheck.h index a8d6f53aca3..ae7e5f5601f 100644 --- a/src/common/HPMDataCheck.h +++ b/src/common/HPMDataCheck.h @@ -254,6 +254,11 @@ HPExport const struct s_HPMDataCheck HPMDataCheck[] = { #else #define COMMON_BASE62_H #endif // COMMON_BASE62_H + #ifdef COMMON_CHARLOGINPACKETS_H + { "PACKET_CHARLOGIN_SET_ACCOUNT_ONLINE", sizeof(struct PACKET_CHARLOGIN_SET_ACCOUNT_ONLINE), SERVER_TYPE_ALL }, + #else + #define COMMON_CHARLOGINPACKETS_H + #endif // COMMON_CHARLOGINPACKETS_H #ifdef COMMON_CHARMAPPACKETS_H { "PACKET_CHARMAP_AGENCY_JOIN_PARTY", sizeof(struct PACKET_CHARMAP_AGENCY_JOIN_PARTY), SERVER_TYPE_ALL }, { "PACKET_CHARMAP_GUILD_EMBLEM", sizeof(struct PACKET_CHARMAP_GUILD_EMBLEM), SERVER_TYPE_ALL }, @@ -321,7 +326,7 @@ HPExport const struct s_HPMDataCheck HPMDataCheck[] = { #define COMMON_HPMI_H #endif // COMMON_HPMI_H #ifdef COMMON_MAPCHARPACKETS_H - { "PACKET_MAPCHAR_AGENCY_JOIN_PARTY_REQ", sizeof(struct PACKET_MAPCHAR_AGENCY_JOIN_PARTY_REQ), SERVER_TYPE_ALL }, + { "PACKET_MAPCHAR_AUTH_REQ", sizeof(struct PACKET_MAPCHAR_AUTH_REQ), SERVER_TYPE_ALL }, { "PACKET_MAPCHAR_GUILD_EMBLEM", sizeof(struct PACKET_MAPCHAR_GUILD_EMBLEM), SERVER_TYPE_ALL }, #else #define COMMON_MAPCHARPACKETS_H diff --git a/src/common/charloginpackets.h b/src/common/charloginpackets.h index 92f69ee4c16..00a25f391b5 100644 --- a/src/common/charloginpackets.h +++ b/src/common/charloginpackets.h @@ -33,6 +33,7 @@ struct PACKET_CHARLOGIN_SET_ACCOUNT_ONLINE { int16 packetType; int account_id; + uint8 standalone; // 0 - real player (false) / 1 - standalone/server generated (true) } __attribute__((packed)); DEFINE_PACKET_ID(CHARLOGIN_SET_ACCOUNT_ONLINE, 0x272b) diff --git a/src/login/login.c b/src/login/login.c index fc9d1ce0454..206d01b07ac 100644 --- a/src/login/login.c +++ b/src/login/login.c @@ -666,7 +666,11 @@ static void login_fromchar_parse_account_online(int fd, int id) 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); + + // "standalone" players (such as autotraders) does not exists in API server, so we should not send data about them + // or we will get errors from API server + if (p->standalone == 0) + lapiif->connect_user_char(id, p->account_id); RFIFOSKIP(fd, sizeof(*p)); } diff --git a/src/plugins/HPMHooking/HPMHooking.Defs.inc b/src/plugins/HPMHooking/HPMHooking.Defs.inc index 5245c3d6c95..d61e0fc3c46 100644 --- a/src/plugins/HPMHooking/HPMHooking.Defs.inc +++ b/src/plugins/HPMHooking/HPMHooking.Defs.inc @@ -744,14 +744,14 @@ typedef int (*HPMHOOK_pre_chr_delete_char_sql) (int *char_id); typedef int (*HPMHOOK_post_chr_delete_char_sql) (int retVal___, int char_id); typedef struct DBData (*HPMHOOK_pre_chr_create_online_char_data) (union DBKey *key, va_list args); typedef struct DBData (*HPMHOOK_post_chr_create_online_char_data) (struct DBData retVal___, union DBKey key, va_list args); -typedef void (*HPMHOOK_pre_chr_set_account_online) (int *account_id); -typedef void (*HPMHOOK_post_chr_set_account_online) (int account_id); +typedef void (*HPMHOOK_pre_chr_set_account_online) (int *account_id, bool *standalone); +typedef void (*HPMHOOK_post_chr_set_account_online) (int account_id, bool standalone); typedef void (*HPMHOOK_pre_chr_set_account_offline) (int *account_id); typedef void (*HPMHOOK_post_chr_set_account_offline) (int account_id); typedef void (*HPMHOOK_pre_chr_set_char_charselect) (int *account_id); typedef void (*HPMHOOK_post_chr_set_char_charselect) (int account_id); -typedef void (*HPMHOOK_pre_chr_set_char_online) (bool *is_initializing, int *char_id, int *account_id); -typedef void (*HPMHOOK_post_chr_set_char_online) (bool is_initializing, int char_id, int account_id); +typedef void (*HPMHOOK_pre_chr_set_char_online) (bool *is_initializing, int *char_id, int *account_id, bool *standalone); +typedef void (*HPMHOOK_post_chr_set_char_online) (bool is_initializing, int char_id, int account_id, bool standalone); typedef void (*HPMHOOK_pre_chr_set_char_offline) (int *char_id, int *account_id); typedef void (*HPMHOOK_post_chr_set_char_offline) (int char_id, int account_id); typedef int (*HPMHOOK_pre_chr_db_setoffline) (union DBKey *key, struct DBData **data, va_list ap); @@ -7546,6 +7546,12 @@ typedef bool (*HPMHOOK_pre_pc_auto_exp_insurance) (struct map_session_data **sd) typedef bool (*HPMHOOK_post_pc_auto_exp_insurance) (bool retVal___, struct map_session_data *sd); typedef void (*HPMHOOK_pre_pc_crimson_marker_clear) (struct map_session_data **sd); typedef void (*HPMHOOK_post_pc_crimson_marker_clear) (struct map_session_data *sd); +typedef bool (*HPMHOOK_pre_pc_is_own_skill) (struct map_session_data **sd, uint16 *skill_id); +typedef bool (*HPMHOOK_post_pc_is_own_skill) (bool retVal___, struct map_session_data *sd, uint16 skill_id); +typedef void (*HPMHOOK_pre_pc_clear_existing_cloneskill) (struct map_session_data **sd, bool *clear_vars); +typedef void (*HPMHOOK_post_pc_clear_existing_cloneskill) (struct map_session_data *sd, bool clear_vars); +typedef void (*HPMHOOK_pre_pc_clear_existing_reproduceskill) (struct map_session_data **sd, bool *clear_vars); +typedef void (*HPMHOOK_post_pc_clear_existing_reproduceskill) (struct map_session_data *sd, bool clear_vars); #endif // MAP_PC_H #ifdef MAP_NPC_H /* libpcre */ typedef pcre* (*HPMHOOK_pre_libpcre_compile) (const char **pattern, int *options, const char ***errptr, int **erroffset, const unsigned char **tableptr); diff --git a/src/plugins/HPMHooking/HPMHooking_char.Hooks.inc b/src/plugins/HPMHooking/HPMHooking_char.Hooks.inc index bf085d7fd66..b4b3b34645b 100644 --- a/src/plugins/HPMHooking/HPMHooking_char.Hooks.inc +++ b/src/plugins/HPMHooking/HPMHooking_char.Hooks.inc @@ -719,14 +719,14 @@ struct DBData HP_chr_create_online_char_data(union DBKey key, va_list args) { } return retVal___; } -void HP_chr_set_account_online(int account_id) { +void HP_chr_set_account_online(int account_id, bool standalone) { int hIndex = 0; if (HPMHooks.count.HP_chr_set_account_online_pre > 0) { - void (*preHookFunc) (int *account_id); + void (*preHookFunc) (int *account_id, bool *standalone); *HPMforce_return = false; for (hIndex = 0; hIndex < HPMHooks.count.HP_chr_set_account_online_pre; hIndex++) { preHookFunc = HPMHooks.list.HP_chr_set_account_online_pre[hIndex].func; - preHookFunc(&account_id); + preHookFunc(&account_id, &standalone); } if (*HPMforce_return) { *HPMforce_return = false; @@ -734,13 +734,13 @@ void HP_chr_set_account_online(int account_id) { } } { - HPMHooks.source.chr.set_account_online(account_id); + HPMHooks.source.chr.set_account_online(account_id, standalone); } if (HPMHooks.count.HP_chr_set_account_online_post > 0) { - void (*postHookFunc) (int account_id); + void (*postHookFunc) (int account_id, bool standalone); for (hIndex = 0; hIndex < HPMHooks.count.HP_chr_set_account_online_post; hIndex++) { postHookFunc = HPMHooks.list.HP_chr_set_account_online_post[hIndex].func; - postHookFunc(account_id); + postHookFunc(account_id, standalone); } } return; @@ -797,14 +797,14 @@ void HP_chr_set_char_charselect(int account_id) { } return; } -void HP_chr_set_char_online(bool is_initializing, int char_id, int account_id) { +void HP_chr_set_char_online(bool is_initializing, int char_id, int account_id, bool standalone) { int hIndex = 0; if (HPMHooks.count.HP_chr_set_char_online_pre > 0) { - void (*preHookFunc) (bool *is_initializing, int *char_id, int *account_id); + void (*preHookFunc) (bool *is_initializing, int *char_id, int *account_id, bool *standalone); *HPMforce_return = false; for (hIndex = 0; hIndex < HPMHooks.count.HP_chr_set_char_online_pre; hIndex++) { preHookFunc = HPMHooks.list.HP_chr_set_char_online_pre[hIndex].func; - preHookFunc(&is_initializing, &char_id, &account_id); + preHookFunc(&is_initializing, &char_id, &account_id, &standalone); } if (*HPMforce_return) { *HPMforce_return = false; @@ -812,13 +812,13 @@ void HP_chr_set_char_online(bool is_initializing, int char_id, int account_id) { } } { - HPMHooks.source.chr.set_char_online(is_initializing, char_id, account_id); + HPMHooks.source.chr.set_char_online(is_initializing, char_id, account_id, standalone); } if (HPMHooks.count.HP_chr_set_char_online_post > 0) { - void (*postHookFunc) (bool is_initializing, int char_id, int account_id); + void (*postHookFunc) (bool is_initializing, int char_id, int account_id, bool standalone); for (hIndex = 0; hIndex < HPMHooks.count.HP_chr_set_char_online_post; hIndex++) { postHookFunc = HPMHooks.list.HP_chr_set_char_online_post[hIndex].func; - postHookFunc(is_initializing, char_id, account_id); + postHookFunc(is_initializing, char_id, account_id, standalone); } } return;