Skip to content

Commit 9f414cf

Browse files
committed
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
1 parent 73da955 commit 9f414cf

File tree

7 files changed

+53
-36
lines changed

7 files changed

+53
-36
lines changed

src/char/char.c

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -205,13 +205,14 @@ static struct DBData char_create_online_char_data(union DBKey key, va_list args)
205205
return DB->ptr2data(character);
206206
}
207207

208-
static void char_set_account_online(int account_id)
208+
static void char_set_account_online(int account_id, bool standalone)
209209
{
210210
WFIFOHEAD(chr->login_fd, sizeof(struct PACKET_CHARLOGIN_SET_ACCOUNT_ONLINE));
211211

212212
struct PACKET_CHARLOGIN_SET_ACCOUNT_ONLINE *p = WFIFOP(chr->login_fd, 0);
213213
p->packetType = HEADER_CHARLOGIN_SET_ACCOUNT_ONLINE;
214214
p->account_id = account_id;
215+
p->standalone = standalone ? 1 : 0;
215216

216217
WFIFOSET(chr->login_fd, sizeof(*p));
217218
}
@@ -247,10 +248,10 @@ static void char_set_char_charselect(int account_id)
247248
}
248249

249250
if (chr->login_fd > 0 && !sockt->session[chr->login_fd]->flag.eof)
250-
chr->set_account_online(account_id);
251+
chr->set_account_online(account_id, false);
251252
}
252253

253-
static void char_set_char_online(bool is_initializing, int char_id, int account_id)
254+
static void char_set_char_online(bool is_initializing, int char_id, int account_id, bool standalone)
254255
{
255256
struct online_char_data* character;
256257
struct mmo_charstatus *cp;
@@ -284,7 +285,7 @@ static void char_set_char_online(bool is_initializing, int char_id, int account_
284285

285286
//Notify login server
286287
if (chr->login_fd > 0 && !sockt->session[chr->login_fd]->flag.eof)
287-
chr->set_account_online(account_id);
288+
chr->set_account_online(account_id, standalone);
288289
}
289290

290291
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)
32793280
} else {
32803281
//This may be valid on char-server reconnection, when re-sending characters that already logged off.
32813282
ShowError("parse_from_map (save-char): Received data for non-existing/offline character (%d:%d).\n", aid, cid);
3282-
chr->set_char_online(false, cid, aid);
3283+
chr->set_char_online(false, cid, aid, false);
32833284
}
32843285

32853286
if (RFIFOB(fd,12)) {
@@ -3681,7 +3682,7 @@ static void char_parse_frommap_set_all_offline(int fd)
36813682

36823683
static void char_parse_frommap_set_char_online(int fd)
36833684
{
3684-
chr->set_char_online(false, RFIFOL(fd, 2), RFIFOL(fd, 6));
3685+
chr->set_char_online(false, RFIFOL(fd, 2), RFIFOL(fd, 6), false);
36853686
RFIFOSKIP(fd,10);
36863687
}
36873688

@@ -3787,12 +3788,12 @@ static void char_parse_frommap_auth_request(int fd)
37873788

37883789
const struct PACKET_MAPCHAR_AUTH_REQ *p = RFIFOP(fd, 0);
37893790

3790-
int account_id = p->account_id;
3791-
int char_id = p->char_id;
3792-
int login_id1 = p->login_id1;
3793-
char sex = p->sex;
3794-
uint32 ip = ntohl(p->client_addr);
3795-
char standalone = p->standalone;
3791+
int account_id = p->account_id;
3792+
int char_id = p->char_id;
3793+
int login_id1 = p->login_id1;
3794+
char sex = p->sex;
3795+
uint32 ip = ntohl(p->client_addr);
3796+
uint8 standalone = p->standalone;
37963797

37973798
RFIFOSKIP(fd, sizeof(struct PACKET_MAPCHAR_AUTH_REQ));
37983799

@@ -3804,11 +3805,11 @@ static void char_parse_frommap_auth_request(int fd)
38043805
cd = (struct mmo_charstatus*)uidb_get(chr->char_db_,char_id);
38053806
}
38063807

3807-
if( core->runflag == CHARSERVER_ST_RUNNING && cd && standalone ) {
3808+
if (core->runflag == CHARSERVER_ST_RUNNING && cd != NULL && standalone != 0) {
38083809
cd->sex = sex;
38093810

38103811
chr->map_auth_ok(fd, account_id, NULL, cd);
3811-
chr->set_char_online(false, char_id, account_id);
3812+
chr->set_char_online(false, char_id, account_id, true);
38123813
return;
38133814
}
38143815

@@ -3827,7 +3828,7 @@ static void char_parse_frommap_auth_request(int fd)
38273828
chr->map_auth_ok(fd, account_id, node, cd);
38283829
// only use the auth once and mark user online
38293830
idb_remove(auth_db, account_id);
3830-
chr->set_char_online(false, char_id, account_id);
3831+
chr->set_char_online(false, char_id, account_id, (standalone != 0));
38313832
}
38323833
else
38333834
{// auth failed
@@ -4583,7 +4584,7 @@ static void char_parse_char_select(int fd, struct char_session_data *sd, uint32
45834584
}
45844585

45854586
/* set char as online prior to loading its data so 3rd party applications will realize the sql data is not reliable */
4586-
chr->set_char_online(true, char_id, sd->account_id);
4587+
chr->set_char_online(true, char_id, sd->account_id, false);
45874588
loginif->set_char_online(char_id, sd->account_id);
45884589
if (!chr->mmo_char_fromsql(char_id, &char_dat, true)) { /* failed? set it back offline */
45894590
chr->set_char_offline(char_id, sd->account_id);

src/char/char.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,10 @@ struct char_interface {
140140
int (*waiting_disconnect) (int tid, int64 tick, int id, intptr_t data);
141141
int (*delete_char_sql) (int char_id);
142142
struct DBData (*create_online_char_data) (union DBKey key, va_list args);
143-
void (*set_account_online) (int account_id);
143+
void (*set_account_online) (int account_id, bool standalone);
144144
void (*set_account_offline) (int account_id);
145145
void (*set_char_charselect) (int account_id);
146-
void (*set_char_online) (bool is_initializing, int char_id, int account_id);
146+
void (*set_char_online) (bool is_initializing, int char_id, int account_id, bool standalone);
147147
void (*set_char_offline) (int char_id, int account_id);
148148
int (*db_setoffline) (union DBKey key, struct DBData *data, va_list ap);
149149
int (*db_kickoffline) (union DBKey key, struct DBData *data, va_list ap);

src/common/HPMDataCheck.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,11 @@ HPExport const struct s_HPMDataCheck HPMDataCheck[] = {
254254
#else
255255
#define COMMON_BASE62_H
256256
#endif // COMMON_BASE62_H
257+
#ifdef COMMON_CHARLOGINPACKETS_H
258+
{ "PACKET_CHARLOGIN_SET_ACCOUNT_ONLINE", sizeof(struct PACKET_CHARLOGIN_SET_ACCOUNT_ONLINE), SERVER_TYPE_ALL },
259+
#else
260+
#define COMMON_CHARLOGINPACKETS_H
261+
#endif // COMMON_CHARLOGINPACKETS_H
257262
#ifdef COMMON_CHARMAPPACKETS_H
258263
{ "PACKET_CHARMAP_AGENCY_JOIN_PARTY", sizeof(struct PACKET_CHARMAP_AGENCY_JOIN_PARTY), SERVER_TYPE_ALL },
259264
{ "PACKET_CHARMAP_GUILD_EMBLEM", sizeof(struct PACKET_CHARMAP_GUILD_EMBLEM), SERVER_TYPE_ALL },
@@ -321,7 +326,7 @@ HPExport const struct s_HPMDataCheck HPMDataCheck[] = {
321326
#define COMMON_HPMI_H
322327
#endif // COMMON_HPMI_H
323328
#ifdef COMMON_MAPCHARPACKETS_H
324-
{ "PACKET_MAPCHAR_AGENCY_JOIN_PARTY_REQ", sizeof(struct PACKET_MAPCHAR_AGENCY_JOIN_PARTY_REQ), SERVER_TYPE_ALL },
329+
{ "PACKET_MAPCHAR_AUTH_REQ", sizeof(struct PACKET_MAPCHAR_AUTH_REQ), SERVER_TYPE_ALL },
325330
{ "PACKET_MAPCHAR_GUILD_EMBLEM", sizeof(struct PACKET_MAPCHAR_GUILD_EMBLEM), SERVER_TYPE_ALL },
326331
#else
327332
#define COMMON_MAPCHARPACKETS_H

src/common/charloginpackets.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
struct PACKET_CHARLOGIN_SET_ACCOUNT_ONLINE {
3434
int16 packetType;
3535
int account_id;
36+
uint8 standalone; // 0 - real player (false) / 1 - standalone/server generated (true)
3637
} __attribute__((packed));
3738
DEFINE_PACKET_ID(CHARLOGIN_SET_ACCOUNT_ONLINE, 0x272b)
3839

src/login/login.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,11 @@ static void login_fromchar_parse_account_online(int fd, int id)
666666
const struct PACKET_CHARLOGIN_SET_ACCOUNT_ONLINE *p = RFIFOP(fd, 0);
667667

668668
login->add_online_user(id, p->account_id);
669-
lapiif->connect_user_char(id, p->account_id);
669+
670+
// "standalone" players (such as autotraders) does not exists in API server, so we should not send data about them
671+
// or we will get errors from API server
672+
if (p->standalone == 0)
673+
lapiif->connect_user_char(id, p->account_id);
670674

671675
RFIFOSKIP(fd, sizeof(*p));
672676
}

src/plugins/HPMHooking/HPMHooking.Defs.inc

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -744,14 +744,14 @@ typedef int (*HPMHOOK_pre_chr_delete_char_sql) (int *char_id);
744744
typedef int (*HPMHOOK_post_chr_delete_char_sql) (int retVal___, int char_id);
745745
typedef struct DBData (*HPMHOOK_pre_chr_create_online_char_data) (union DBKey *key, va_list args);
746746
typedef struct DBData (*HPMHOOK_post_chr_create_online_char_data) (struct DBData retVal___, union DBKey key, va_list args);
747-
typedef void (*HPMHOOK_pre_chr_set_account_online) (int *account_id);
748-
typedef void (*HPMHOOK_post_chr_set_account_online) (int account_id);
747+
typedef void (*HPMHOOK_pre_chr_set_account_online) (int *account_id, bool *standalone);
748+
typedef void (*HPMHOOK_post_chr_set_account_online) (int account_id, bool standalone);
749749
typedef void (*HPMHOOK_pre_chr_set_account_offline) (int *account_id);
750750
typedef void (*HPMHOOK_post_chr_set_account_offline) (int account_id);
751751
typedef void (*HPMHOOK_pre_chr_set_char_charselect) (int *account_id);
752752
typedef void (*HPMHOOK_post_chr_set_char_charselect) (int account_id);
753-
typedef void (*HPMHOOK_pre_chr_set_char_online) (bool *is_initializing, int *char_id, int *account_id);
754-
typedef void (*HPMHOOK_post_chr_set_char_online) (bool is_initializing, int char_id, int account_id);
753+
typedef void (*HPMHOOK_pre_chr_set_char_online) (bool *is_initializing, int *char_id, int *account_id, bool *standalone);
754+
typedef void (*HPMHOOK_post_chr_set_char_online) (bool is_initializing, int char_id, int account_id, bool standalone);
755755
typedef void (*HPMHOOK_pre_chr_set_char_offline) (int *char_id, int *account_id);
756756
typedef void (*HPMHOOK_post_chr_set_char_offline) (int char_id, int account_id);
757757
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)
75467546
typedef bool (*HPMHOOK_post_pc_auto_exp_insurance) (bool retVal___, struct map_session_data *sd);
75477547
typedef void (*HPMHOOK_pre_pc_crimson_marker_clear) (struct map_session_data **sd);
75487548
typedef void (*HPMHOOK_post_pc_crimson_marker_clear) (struct map_session_data *sd);
7549+
typedef bool (*HPMHOOK_pre_pc_is_own_skill) (struct map_session_data **sd, uint16 *skill_id);
7550+
typedef bool (*HPMHOOK_post_pc_is_own_skill) (bool retVal___, struct map_session_data *sd, uint16 skill_id);
7551+
typedef void (*HPMHOOK_pre_pc_clear_existing_cloneskill) (struct map_session_data **sd, bool *clear_vars);
7552+
typedef void (*HPMHOOK_post_pc_clear_existing_cloneskill) (struct map_session_data *sd, bool clear_vars);
7553+
typedef void (*HPMHOOK_pre_pc_clear_existing_reproduceskill) (struct map_session_data **sd, bool *clear_vars);
7554+
typedef void (*HPMHOOK_post_pc_clear_existing_reproduceskill) (struct map_session_data *sd, bool clear_vars);
75497555
#endif // MAP_PC_H
75507556
#ifdef MAP_NPC_H /* libpcre */
75517557
typedef pcre* (*HPMHOOK_pre_libpcre_compile) (const char **pattern, int *options, const char ***errptr, int **erroffset, const unsigned char **tableptr);

src/plugins/HPMHooking/HPMHooking_char.Hooks.inc

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -719,28 +719,28 @@ struct DBData HP_chr_create_online_char_data(union DBKey key, va_list args) {
719719
}
720720
return retVal___;
721721
}
722-
void HP_chr_set_account_online(int account_id) {
722+
void HP_chr_set_account_online(int account_id, bool standalone) {
723723
int hIndex = 0;
724724
if (HPMHooks.count.HP_chr_set_account_online_pre > 0) {
725-
void (*preHookFunc) (int *account_id);
725+
void (*preHookFunc) (int *account_id, bool *standalone);
726726
*HPMforce_return = false;
727727
for (hIndex = 0; hIndex < HPMHooks.count.HP_chr_set_account_online_pre; hIndex++) {
728728
preHookFunc = HPMHooks.list.HP_chr_set_account_online_pre[hIndex].func;
729-
preHookFunc(&account_id);
729+
preHookFunc(&account_id, &standalone);
730730
}
731731
if (*HPMforce_return) {
732732
*HPMforce_return = false;
733733
return;
734734
}
735735
}
736736
{
737-
HPMHooks.source.chr.set_account_online(account_id);
737+
HPMHooks.source.chr.set_account_online(account_id, standalone);
738738
}
739739
if (HPMHooks.count.HP_chr_set_account_online_post > 0) {
740-
void (*postHookFunc) (int account_id);
740+
void (*postHookFunc) (int account_id, bool standalone);
741741
for (hIndex = 0; hIndex < HPMHooks.count.HP_chr_set_account_online_post; hIndex++) {
742742
postHookFunc = HPMHooks.list.HP_chr_set_account_online_post[hIndex].func;
743-
postHookFunc(account_id);
743+
postHookFunc(account_id, standalone);
744744
}
745745
}
746746
return;
@@ -797,28 +797,28 @@ void HP_chr_set_char_charselect(int account_id) {
797797
}
798798
return;
799799
}
800-
void HP_chr_set_char_online(bool is_initializing, int char_id, int account_id) {
800+
void HP_chr_set_char_online(bool is_initializing, int char_id, int account_id, bool standalone) {
801801
int hIndex = 0;
802802
if (HPMHooks.count.HP_chr_set_char_online_pre > 0) {
803-
void (*preHookFunc) (bool *is_initializing, int *char_id, int *account_id);
803+
void (*preHookFunc) (bool *is_initializing, int *char_id, int *account_id, bool *standalone);
804804
*HPMforce_return = false;
805805
for (hIndex = 0; hIndex < HPMHooks.count.HP_chr_set_char_online_pre; hIndex++) {
806806
preHookFunc = HPMHooks.list.HP_chr_set_char_online_pre[hIndex].func;
807-
preHookFunc(&is_initializing, &char_id, &account_id);
807+
preHookFunc(&is_initializing, &char_id, &account_id, &standalone);
808808
}
809809
if (*HPMforce_return) {
810810
*HPMforce_return = false;
811811
return;
812812
}
813813
}
814814
{
815-
HPMHooks.source.chr.set_char_online(is_initializing, char_id, account_id);
815+
HPMHooks.source.chr.set_char_online(is_initializing, char_id, account_id, standalone);
816816
}
817817
if (HPMHooks.count.HP_chr_set_char_online_post > 0) {
818-
void (*postHookFunc) (bool is_initializing, int char_id, int account_id);
818+
void (*postHookFunc) (bool is_initializing, int char_id, int account_id, bool standalone);
819819
for (hIndex = 0; hIndex < HPMHooks.count.HP_chr_set_char_online_post; hIndex++) {
820820
postHookFunc = HPMHooks.list.HP_chr_set_char_online_post[hIndex].func;
821-
postHookFunc(is_initializing, char_id, account_id);
821+
postHookFunc(is_initializing, char_id, account_id, standalone);
822822
}
823823
}
824824
return;

0 commit comments

Comments
 (0)