Skip to content

Commit

Permalink
Stop sending standalone characters (e.g. autotraders) connection to A…
Browse files Browse the repository at this point in the history
…PI 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
  • Loading branch information
guilherme-gm committed Aug 3, 2024
1 parent 73da955 commit 9f414cf
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 36 deletions.
33 changes: 17 additions & 16 deletions src/char/char.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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));

Expand All @@ -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;
}

Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/char/char.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 6 additions & 1 deletion src/common/HPMDataCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/common/charloginpackets.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 5 additions & 1 deletion src/login/login.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
14 changes: 10 additions & 4 deletions src/plugins/HPMHooking/HPMHooking.Defs.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
24 changes: 12 additions & 12 deletions src/plugins/HPMHooking/HPMHooking_char.Hooks.inc
Original file line number Diff line number Diff line change
Expand Up @@ -719,28 +719,28 @@ 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;
return;
}
}
{
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;
Expand Down Expand Up @@ -797,28 +797,28 @@ 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;
return;
}
}
{
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;
Expand Down

0 comments on commit 9f414cf

Please sign in to comment.