Skip to content

Commit 6d99570

Browse files
Merge pull request #3314 from guilherme-gm/api-autotrade
Stop sending standalone players to API server
2 parents 1cc00ed + 3913b51 commit 6d99570

12 files changed

+100
-55
lines changed

src/char/char.c

+31-23
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#include "common/apipackets.h"
5252
#include "common/cbasetypes.h"
5353
#include "common/charloginpackets.h"
54+
#include "common/mapcharpackets.h"
5455
#include "common/chunked.h"
5556
#include "common/conf.h"
5657
#include "common/console.h"
@@ -204,12 +205,16 @@ static struct DBData char_create_online_char_data(union DBKey key, va_list args)
204205
return DB->ptr2data(character);
205206
}
206207

207-
static void char_set_account_online(int account_id)
208+
static void char_set_account_online(int account_id, bool standalone)
208209
{
209-
WFIFOHEAD(chr->login_fd,6);
210-
WFIFOW(chr->login_fd,0) = 0x272b;
211-
WFIFOL(chr->login_fd,2) = account_id;
212-
WFIFOSET(chr->login_fd,6);
210+
WFIFOHEAD(chr->login_fd, sizeof(struct PACKET_CHARLOGIN_SET_ACCOUNT_ONLINE));
211+
212+
struct PACKET_CHARLOGIN_SET_ACCOUNT_ONLINE *p = WFIFOP(chr->login_fd, 0);
213+
p->packetType = HEADER_CHARLOGIN_SET_ACCOUNT_ONLINE;
214+
p->account_id = account_id;
215+
p->standalone = standalone ? 1 : 0;
216+
217+
WFIFOSET(chr->login_fd, sizeof(*p));
213218
}
214219

215220
static void char_set_account_offline(int account_id)
@@ -243,10 +248,10 @@ static void char_set_char_charselect(int account_id)
243248
}
244249

245250
if (chr->login_fd > 0 && !sockt->session[chr->login_fd]->flag.eof)
246-
chr->set_account_online(account_id);
251+
chr->set_account_online(account_id, false);
247252
}
248253

249-
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)
250255
{
251256
struct online_char_data* character;
252257
struct mmo_charstatus *cp;
@@ -280,7 +285,7 @@ static void char_set_char_online(bool is_initializing, int char_id, int account_
280285

281286
//Notify login server
282287
if (chr->login_fd > 0 && !sockt->session[chr->login_fd]->flag.eof)
283-
chr->set_account_online(account_id);
288+
chr->set_account_online(account_id, standalone);
284289
}
285290

286291
static void char_set_char_offline(int char_id, int account_id)
@@ -3275,7 +3280,7 @@ static void char_parse_frommap_save_character(int fd)
32753280
} else {
32763281
//This may be valid on char-server reconnection, when re-sending characters that already logged off.
32773282
ShowError("parse_from_map (save-char): Received data for non-existing/offline character (%d:%d).\n", aid, cid);
3278-
chr->set_char_online(false, cid, aid);
3283+
chr->set_char_online(false, cid, aid, false);
32793284
}
32803285

32813286
if (RFIFOB(fd,12)) {
@@ -3677,7 +3682,7 @@ static void char_parse_frommap_set_all_offline(int fd)
36773682

36783683
static void char_parse_frommap_set_char_online(int fd)
36793684
{
3680-
chr->set_char_online(false, RFIFOL(fd, 2), RFIFOL(fd, 6));
3685+
chr->set_char_online(false, RFIFOL(fd, 2), RFIFOL(fd, 6), false);
36813686
RFIFOSKIP(fd,10);
36823687
}
36833688

@@ -3781,13 +3786,16 @@ static void char_parse_frommap_auth_request(int fd)
37813786
struct char_auth_node* node;
37823787
struct mmo_charstatus* cd;
37833788

3784-
int account_id = RFIFOL(fd,2);
3785-
int char_id = RFIFOL(fd,6);
3786-
int login_id1 = RFIFOL(fd,10);
3787-
char sex = RFIFOB(fd,14);
3788-
uint32 ip = ntohl(RFIFOL(fd,15));
3789-
char standalone = RFIFOB(fd, 19);
3790-
RFIFOSKIP(fd,20);
3789+
const struct PACKET_MAPCHAR_AUTH_REQ *p = RFIFOP(fd, 0);
3790+
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;
3797+
3798+
RFIFOSKIP(fd, sizeof(struct PACKET_MAPCHAR_AUTH_REQ));
37913799

37923800
node = (struct char_auth_node*)idb_get(auth_db, account_id);
37933801
cd = (struct mmo_charstatus*)uidb_get(chr->char_db_,char_id);
@@ -3797,11 +3805,11 @@ static void char_parse_frommap_auth_request(int fd)
37973805
cd = (struct mmo_charstatus*)uidb_get(chr->char_db_,char_id);
37983806
}
37993807

3800-
if( core->runflag == CHARSERVER_ST_RUNNING && cd && standalone ) {
3808+
if (core->runflag == CHARSERVER_ST_RUNNING && cd != NULL && standalone != 0) {
38013809
cd->sex = sex;
38023810

38033811
chr->map_auth_ok(fd, account_id, NULL, cd);
3804-
chr->set_char_online(false, char_id, account_id);
3812+
chr->set_char_online(false, char_id, account_id, true);
38053813
return;
38063814
}
38073815

@@ -3820,7 +3828,7 @@ static void char_parse_frommap_auth_request(int fd)
38203828
chr->map_auth_ok(fd, account_id, node, cd);
38213829
// only use the auth once and mark user online
38223830
idb_remove(auth_db, account_id);
3823-
chr->set_char_online(false, char_id, account_id);
3831+
chr->set_char_online(false, char_id, account_id, (standalone != 0));
38243832
}
38253833
else
38263834
{// auth failed
@@ -4040,8 +4048,8 @@ static int char_parse_frommap(int fd)
40404048
chr->parse_frommap_ping(fd);
40414049
break;
40424050

4043-
case 0x2b26: // auth request from map-server
4044-
if (RFIFOREST(fd) < 20)
4051+
case HEADER_MAPCHAR_AUTH_REQ: // auth request from map-server
4052+
if (RFIFOREST(fd) < sizeof(struct PACKET_MAPCHAR_AUTH_REQ))
40454053
return 0;
40464054

40474055
{
@@ -4576,7 +4584,7 @@ static void char_parse_char_select(int fd, struct char_session_data *sd, uint32
45764584
}
45774585

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

src/char/char.h

+2-2
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/char/packets_hc_struct.h

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "common/hercules.h"
2424
#include "common/mmo.h"
2525
#include "common/packetsstatic_len.h"
26+
#include "common/packetsmacro.h"
2627

2728
/* Packets Structs */
2829
#if !defined(sun) && (!defined(__NETBSD__) || __NetBSD_Version__ >= 600000000) // NetBSD 5 and Solaris don't like pragma pack but accept the packed attribute

src/common/HPMDataCheck.h

+4
Original file line numberDiff line numberDiff line change
@@ -256,13 +256,16 @@ HPExport const struct s_HPMDataCheck HPMDataCheck[] = {
256256
#endif // COMMON_BASE62_H
257257
#ifdef COMMON_CHARLOGINPACKETS_H
258258
{ "PACKET_CHARLOGIN_ONLINE_ACCOUNTS", sizeof(struct PACKET_CHARLOGIN_ONLINE_ACCOUNTS), SERVER_TYPE_ALL },
259+
{ "PACKET_CHARLOGIN_SET_ACCOUNT_ONLINE", sizeof(struct PACKET_CHARLOGIN_SET_ACCOUNT_ONLINE), SERVER_TYPE_ALL },
259260
#else
260261
#define COMMON_CHARLOGINPACKETS_H
261262
#endif // COMMON_CHARLOGINPACKETS_H
262263
#ifdef COMMON_CHARMAPPACKETS_H
263264
{ "PACKET_CHARMAP_AGENCY_JOIN_PARTY", sizeof(struct PACKET_CHARMAP_AGENCY_JOIN_PARTY), SERVER_TYPE_ALL },
264265
{ "PACKET_CHARMAP_GUILD_EMBLEM", sizeof(struct PACKET_CHARMAP_GUILD_EMBLEM), SERVER_TYPE_ALL },
265266
{ "PACKET_CHARMAP_GUILD_INFO", sizeof(struct PACKET_CHARMAP_GUILD_INFO), SERVER_TYPE_ALL },
267+
{ "PACKET_CHARMAP_GUILD_INFO_EMBLEM", sizeof(struct PACKET_CHARMAP_GUILD_INFO_EMBLEM), SERVER_TYPE_ALL },
268+
{ "PACKET_CHARMAP_GUILD_INFO_EMPTY", sizeof(struct PACKET_CHARMAP_GUILD_INFO_EMPTY), SERVER_TYPE_ALL },
266269
#else
267270
#define COMMON_CHARMAPPACKETS_H
268271
#endif // COMMON_CHARMAPPACKETS_H
@@ -327,6 +330,7 @@ HPExport const struct s_HPMDataCheck HPMDataCheck[] = {
327330
#endif // COMMON_HPMI_H
328331
#ifdef COMMON_MAPCHARPACKETS_H
329332
{ "PACKET_MAPCHAR_AGENCY_JOIN_PARTY_REQ", sizeof(struct PACKET_MAPCHAR_AGENCY_JOIN_PARTY_REQ), SERVER_TYPE_ALL },
333+
{ "PACKET_MAPCHAR_AUTH_REQ", sizeof(struct PACKET_MAPCHAR_AUTH_REQ), SERVER_TYPE_ALL },
330334
{ "PACKET_MAPCHAR_GUILD_EMBLEM", sizeof(struct PACKET_MAPCHAR_GUILD_EMBLEM), SERVER_TYPE_ALL },
331335
#else
332336
#define COMMON_MAPCHARPACKETS_H

src/common/charloginpackets.h

+8
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,20 @@
2424
// Packets sent by Char-Server to Login-Server
2525

2626
#include "common/hercules.h"
27+
#include "common/packetsmacro.h"
2728

2829
/* Packets Structs */
2930
#if !defined(sun) && (!defined(__NETBSD__) || __NetBSD_Version__ >= 600000000) // NetBSD 5 and Solaris don't like pragma pack but accept the packed attribute
3031
#pragma pack(push, 1)
3132
#endif // not NetBSD < 6 / Solaris
3233

34+
struct PACKET_CHARLOGIN_SET_ACCOUNT_ONLINE {
35+
int16 packetType;
36+
int account_id;
37+
uint8 standalone; // 0 - real player (false) / 1 - standalone/server generated (true)
38+
} __attribute__((packed));
39+
DEFINE_PACKET_ID(CHARLOGIN_SET_ACCOUNT_ONLINE, 0x272b)
40+
3341
struct PACKET_CHARLOGIN_ONLINE_ACCOUNTS {
3442
int16 packetType;
3543
uint16 packetLength;

src/common/charmappackets.h

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#define COMMON_CHARMAPPACKETS_H
2424

2525
#include "common/hercules.h"
26+
#include "common/packetsmacro.h"
2627

2728
/* Packets Structs */
2829
#if !defined(sun) && (!defined(__NETBSD__) || __NetBSD_Version__ >= 600000000) // NetBSD 5 and Solaris don't like pragma pack but accept the packed attribute

src/common/mapcharpackets.h

+12
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,24 @@
2323
#define COMMON_MAPCHARPACKETS_H
2424

2525
#include "common/hercules.h"
26+
#include "common/packetsmacro.h"
2627

2728
/* Packets Structs */
2829
#if !defined(sun) && (!defined(__NETBSD__) || __NetBSD_Version__ >= 600000000) // NetBSD 5 and Solaris don't like pragma pack but accept the packed attribute
2930
#pragma pack(push, 1)
3031
#endif // not NetBSD < 6 / Solaris
3132

33+
struct PACKET_MAPCHAR_AUTH_REQ {
34+
int16 packetType;
35+
int account_id;
36+
int char_id;
37+
int login_id1;
38+
uint8 sex;
39+
int client_addr;
40+
uint8 standalone; // 0 - real player (false) / 1 - standalone/server generated (true)
41+
} __attribute__((packed));
42+
DEFINE_PACKET_ID(MAPCHAR_AUTH_REQ, 0x2b26)
43+
3244
struct PACKET_MAPCHAR_AGENCY_JOIN_PARTY_REQ {
3345
int16 packetType;
3446
int char_id;

src/login/login.c

+12-5
Original file line numberDiff line numberDiff line change
@@ -663,9 +663,16 @@ static void login_fromchar_parse_unban(int fd, int id, const char *const ip)
663663

664664
static void login_fromchar_parse_account_online(int fd, int id)
665665
{
666-
login->add_online_user(id, RFIFOL(fd,2));
667-
lapiif->connect_user_char(id, RFIFOL(fd, 2));
668-
RFIFOSKIP(fd, 6);
666+
const struct PACKET_CHARLOGIN_SET_ACCOUNT_ONLINE *p = RFIFOP(fd, 0);
667+
668+
login->add_online_user(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);
674+
675+
RFIFOSKIP(fd, sizeof(*p));
669676
}
670677

671678
static void login_fromchar_parse_account_offline(int fd)
@@ -939,8 +946,8 @@ static int login_parse_fromchar(int fd)
939946
}
940947
break;
941948

942-
case 0x272b: // Set account_id to online [Wizputer]
943-
if( RFIFOREST(fd) < 6 )
949+
case HEADER_CHARLOGIN_SET_ACCOUNT_ONLINE: // Set account_id to online [Wizputer]
950+
if (RFIFOREST(fd) < sizeof(struct PACKET_CHARLOGIN_SET_ACCOUNT_ONLINE))
944951
return 0;
945952
login->fromchar_parse_account_online(fd, id);
946953
break;

src/map/chrif.c

+12-9
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include "common/HPM.h"
4343
#include "common/cbasetypes.h"
4444
#include "common/ers.h"
45+
#include "common/mapcharpackets.h"
4546
#include "common/memmgr.h"
4647
#include "common/msgtable.h"
4748
#include "common/nullpo.h"
@@ -470,15 +471,17 @@ static void chrif_authreq(struct map_session_data *sd, bool hstandalone)
470471
return;
471472
}
472473

473-
WFIFOHEAD(chrif->fd,20);
474-
WFIFOW(chrif->fd,0) = 0x2b26;
475-
WFIFOL(chrif->fd,2) = sd->status.account_id;
476-
WFIFOL(chrif->fd,6) = sd->status.char_id;
477-
WFIFOL(chrif->fd,10) = sd->login_id1;
478-
WFIFOB(chrif->fd,14) = sd->status.sex;
479-
WFIFOL(chrif->fd,15) = htonl(sockt->session[sd->fd]->client_addr);
480-
WFIFOB(chrif->fd,19) = hstandalone ? 1 : 0;
481-
WFIFOSET(chrif->fd,20);
474+
WFIFOHEAD(chrif->fd, sizeof(struct PACKET_MAPCHAR_AUTH_REQ));
475+
struct PACKET_MAPCHAR_AUTH_REQ *p = WFIFOP(chrif->fd, 0);
476+
p->packetType = HEADER_MAPCHAR_AUTH_REQ;
477+
p->account_id = sd->status.account_id;
478+
p->char_id = sd->status.char_id;
479+
p->login_id1 = sd->login_id1;
480+
p->sex = sd->status.sex;
481+
p->client_addr = htonl(sockt->session[sd->fd]->client_addr);
482+
p->standalone = hstandalone ? 1 : 0;
483+
WFIFOSET(chrif->fd, sizeof(struct PACKET_MAPCHAR_AUTH_REQ));
484+
482485
chrif->sd_to_auth(sd, ST_LOGIN);
483486
}
484487

src/map/packets_struct.h

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "common/cbasetypes.h"
2727
#include "common/mmo.h"
2828
#include "common/packetsstatic_len.h"
29+
#include "common/packetsmacro.h"
2930

3031
// Packet DB
3132
#define MAX_PACKET_POS 20

src/plugins/HPMHooking/HPMHooking.Defs.inc

+4-4
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);

src/plugins/HPMHooking/HPMHooking_char.Hooks.inc

+12-12
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)