Skip to content

Commit

Permalink
Add partial support for adventurer agency (incomplete)
Browse files Browse the repository at this point in the history
  • Loading branch information
4144 committed Apr 11, 2023
1 parent 32c2691 commit 9ef5e4e
Show file tree
Hide file tree
Showing 23 changed files with 334 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ Thumbs.db
/vcproj-*/char-server
/vcproj-*/login-server
/vcproj-*/map-server
/vcproj-*/api-server
/vcproj-*/mapcache
/vcproj-*/plugin-*/

Expand Down
2 changes: 2 additions & 0 deletions api-server.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@ECHO OFF
CALL serv.bat api-server.exe Api-Server
1 change: 1 addition & 0 deletions run-server.bat
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ rem Writen by Jbain
start cmd /k login-server.bat
start cmd /k char-server.bat
start cmd /k map-server.bat
start cmd /k api-server.bat
2 changes: 1 addition & 1 deletion src/api/aclif.c
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ static void aclif_check_headers(int fd, struct api_session_data *sd)

const char *size_str = strdb_get(sd->headers_db, "Content-Length");
if (size_str != NULL) {
const size_t sz = atoll(size_str);
const size_t sz = (size_t)atoll(size_str);
if (sz > MAX_BODY_SIZE) {
ShowError("Body size too big: %d\n", fd);
sockt->eof(fd);
Expand Down
58 changes: 58 additions & 0 deletions src/char/int_adventurer_agency.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
#include "char/char.h"
#include "char/int_party.h"
#include "char/inter.h"
#include "char/mapif.h"
#include "common/cbasetypes.h"
#include "common/mapcharpackets.h"
#include "common/apipackets.h"
#include "common/db.h"
#include "common/memmgr.h"
Expand All @@ -43,6 +45,60 @@
static struct inter_adventurer_agency_interface inter_adventurer_agency_s;
struct inter_adventurer_agency_interface *inter_adventurer_agency;

static int inter_adventurer_agency_parse_frommap(int fd)
{
RFIFOHEAD(fd);

switch (RFIFOW(fd, 0)) {
case 0x3084:
inter_adventurer_agency->pJoinParty(fd);
break;
default:
return 0;
}

return 1;
}

static void inter_adventurer_agency_parse_joinParty(int fd)
{
const struct PACKET_MAPCHAR_AGENCY_JOIN_PARTY_REQ *p = RFIFOP(fd, 0);
const int char_id = p->char_id;
const int party_id = p->party_id;
const int map_index = p->map_index;

struct mmo_charstatus *cp = (struct mmo_charstatus*)idb_get(chr->char_db_, char_id);
nullpo_retv(cp);
if (cp->party_id != 0) {
mapif->agency_joinPartyResult(fd, char_id, AGENCY_PLAYER_ALREADY_IN_PARTY);
return;
}

struct party_data* party = (struct party_data*)idb_get(inter_party->db, party_id);
if (party == NULL) {
mapif->agency_joinPartyResult(fd, char_id, AGENCY_PARTY_NOT_FOUND);
return;
}

struct party_member member = { 0 };
member.account_id = cp->account_id;
member.char_id = cp->char_id;
safestrncpy(member.name, cp->name, NAME_LENGTH);
member.class = cp->class;
member.map = map_index;
member.lv = cp->base_level;
member.online = 1;
member.leader = 0;

if (!inter_party->add_member(party_id, &member)) {
// for avoid another request to db, considerer only error
// from inter_party->add_member is too much members already
mapif->agency_joinPartyResult(fd, char_id, AGENCY_PARTY_NUMBER_EXCEEDED);
return;
}
mapif->agency_joinPartyResult(fd, char_id, AGENCY_JOIN_ACCEPTED);
}

static bool inter_adventurer_agency_entry_check_existing(int char_id, int party_id)
{
if (SQL_ERROR == SQL->Query(inter->sql_handle,
Expand Down Expand Up @@ -265,6 +321,8 @@ void inter_adventurer_agency_defaults(void)
{
inter_adventurer_agency = &inter_adventurer_agency_s;

inter_adventurer_agency->pJoinParty = inter_adventurer_agency_parse_joinParty;
inter_adventurer_agency->parse_frommap = inter_adventurer_agency_parse_frommap;
inter_adventurer_agency->entry_add = inter_adventurer_agency_entry_add;
inter_adventurer_agency->entry_check_existing = inter_adventurer_agency_entry_check_existing;
inter_adventurer_agency->entry_delete_existing = inter_adventurer_agency_entry_delete_existing;
Expand Down
2 changes: 2 additions & 0 deletions src/char/int_adventurer_agency.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ struct adventuter_agency_page;
* inter_adventurer_agency_interface interface
**/
struct inter_adventurer_agency_interface {
int (*parse_frommap) (int fd);
void (*pJoinParty) (int fd);
bool (*entry_add) (int char_id, const struct party_add_data *entry);
bool (*entry_check_existing) (int char_id, int party_id);
void (*entry_delete_existing) (int char_id, int party_id);
Expand Down
16 changes: 16 additions & 0 deletions src/char/inter.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include "char/char.h"
#include "char/geoip.h"
#include "char/int_adventurer_agency.h"
#include "char/int_auction.h"
#include "char/int_clan.h"
#include "char/int_elemental.h"
Expand Down Expand Up @@ -66,6 +67,20 @@ static char default_codepage[32] = ""; //Feature by irmin.

int party_share_level = 10;

// recv. packet list
static int inter_recv_packet_length[] = {
0, 0, 0, 0, -1,13,36, (2 + 4 + 4 + 4 + NAME_LENGTH), 0, 0, 0, 0, 0, 0, 0, 0, // 3000-
6,-1, 6,-1, 0, 0, 0, 0, 10,-1, 0, 0, 0, 0, 0, 0, // 3010- Account Storage, Achievements [Smokexyz]
-1,10,-1,14, 14,19, 6, 0, 14,14, 0, 0, 0, 0, 0, 0, // 3020- Party
-1, 6,-1,-1, 55,23, 6, 0, 14,-1,-1,-1, 18,19,186,-1, // 3030-
-1, 9, 0, 0, 10,10, 0, 0, 7, 6,10,10, 10,-1, 0, 0, // 3040- Clan System(3044-3045)
-1,-1,10,10, 0,-1,12, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3050- Auction System [Zephyrus], Item Bound [Mhalicot]
6,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3060- Quest system [Kevin] [Inkfish]
-1,10, 6,-1, 0, 0, 0, 0, 0, 0, 0, 0, -1,10, 6,-1, // 3070- Mercenary packets [Zephyrus], Elemental packets [pakpil]
56,14,-1, 6, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3080-
-1,10,-1, 6, 0, 20,10,20, -1,6 + NAME_LENGTH, 0, 0, 0, 0, 0, 0, // 3090- Homunculus packets [albator], RoDEX packets
};

#define MAX_JOB_NAMES 150
static char *msg_table[MAX_JOB_NAMES]; // messages 550 ~ 699 are job names

Expand Down Expand Up @@ -1043,6 +1058,7 @@ static int inter_parse_frommap(int fd)
|| inter_rodex->parse_frommap(fd)
|| inter_clan->parse_frommap(fd)
|| inter_achievement->parse_frommap(fd)
|| inter_adventurer_agency->parse_frommap(fd)
)
break;
else
Expand Down
13 changes: 13 additions & 0 deletions src/char/mapif.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "char/int_storage.h"
#include "char/inter.h"
#include "common/cbasetypes.h"
#include "common/charmappackets.h"
#include "common/memmgr.h"
#include "common/mmo.h"
#include "common/nullpo.h"
Expand Down Expand Up @@ -2297,6 +2298,17 @@ static void mapif_rodex_getitemsack(int char_id, int64 mail_id, uint8 opentype,
mapif->send(buf, 16 + sizeof(struct rodex_item) * RODEX_MAX_ITEM);
}

static void mapif_agency_joinPartyResult(int fd, int char_id, enum adventurer_agency_result result)
{
WFIFOHEAD(fd, sizeof(struct PACKET_CHARMAP_AGENCY_JOIN_PARTY));
struct PACKET_CHARMAP_AGENCY_JOIN_PARTY *p = WFIFOP(fd, 0);

p->packetType = 0x389b;
p->char_id = char_id;
p->result = result;
WFIFOSET(fd, sizeof(struct PACKET_CHARMAP_AGENCY_JOIN_PARTY));
}

void mapif_defaults(void)
{
mapif = &mapif_s;
Expand Down Expand Up @@ -2457,4 +2469,5 @@ void mapif_defaults(void)
/* Clan System */
mapif->parse_ClanMemberKick = mapif_parse_ClanMemberKick;
mapif->parse_ClanMemberCount = mapif_parse_ClanMemberCount;
mapif->agency_joinPartyResult = mapif_agency_joinPartyResult;
}
2 changes: 2 additions & 0 deletions src/char/mapif.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "common/mmo.h"

struct rodex_item;
enum adventurer_agency_result;

/**
* mapif interface
Expand Down Expand Up @@ -184,6 +185,7 @@ struct mapif_interface {
// Clan System
int (*parse_ClanMemberKick) (int fd, int clan_id, int kick_interval);
int (*parse_ClanMemberCount) (int fd, int clan_id, int kick_interval);
void (*agency_joinPartyResult) (int fd, int char_id, enum adventurer_agency_result result);
};

#ifdef HERCULES_CORE
Expand Down
3 changes: 2 additions & 1 deletion src/common/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ COMMON_H = atomic.h cbasetypes.h conf.h console.h core.h db.h des.h ers.h \
grfio.h hercules.h HPM.h HPMi.h memmgr.h memmgr_inc.h mapindex.h \
md5calc.h mmo.h mutex.h nullpo.h packets.h packets_len.h packets_struct.h random.h \
showmsg.h socket.h spinlock.h sql.h strlib.h sysinfo.h thread.h \
timer.h utils.h winapi.h api.h ../plugins/HPMHooking.h
timer.h utils.h winapi.h api.h charmappackets.h mapcharpackets.h \
../plugins/HPMHooking.h
COMMON_PH =

COMMON_SQL_OBJ = obj_sql/sql.o
Expand Down
42 changes: 42 additions & 0 deletions src/common/charmappackets.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
* Copyright (C) 2012-2020 Hercules Dev Team
* Copyright (C) 2020-2021 Andrei Karas (4144)
* Copyright (C) Athena Dev Teams
*
* Hercules is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef COMMON_CHARMAPPACKETS_H
#define COMMON_CHARMAPPACKETS_H

#include "common/hercules.h"

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

struct PACKET_CHARMAP_AGENCY_JOIN_PARTY {
int16 packetType;
int char_id;
int result;
} __attribute__((packed));

#if !defined(sun) && (!defined(__NETBSD__) || __NetBSD_Version__ >= 600000000) // NetBSD 5 and Solaris don't like pragma pack but accept the packed attribute
#pragma pack(pop)
#endif // not NetBSD < 6 / Solaris

#endif /* COMMON_CHARMAPPACKETS_H */
43 changes: 43 additions & 0 deletions src/common/mapcharpackets.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
* Copyright (C) 2012-2020 Hercules Dev Team
* Copyright (C) 2020-2021 Andrei Karas (4144)
* Copyright (C) Athena Dev Teams
*
* Hercules is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef COMMON_MAPCHARPACKETS_H
#define COMMON_MAPCHARPACKETS_H

#include "common/hercules.h"

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

struct PACKET_MAPCHAR_AGENCY_JOIN_PARTY_REQ {
int16 packetType;
int char_id;
int party_id;
int map_index;
} __attribute__((packed));

#if !defined(sun) && (!defined(__NETBSD__) || __NetBSD_Version__ >= 600000000) // NetBSD 5 and Solaris don't like pragma pack but accept the packed attribute
#pragma pack(pop)
#endif // not NetBSD < 6 / Solaris

#endif /* COMMON_MAPCHARPACKETS_H */
19 changes: 19 additions & 0 deletions src/common/mmo.h
Original file line number Diff line number Diff line change
Expand Up @@ -1351,6 +1351,25 @@ enum e_pet_intimacy_level {
PET_INTIMACY_MAX = 1000
};


// enum from packet ZC_ADVENTURER_AGENCY_JOIN_RESULT (0x0afa)
enum adventurer_agency_result {
AGENCY_JOIN_ACCEPTED = 0,
AGENCY_JOIN_REJECTED = 1,
AGENCY_PARTY_NUMBER_EXCEEDED = 2,
AGENCY_MASTER_UNABLE_ACCEPT_REQUEST = 3,
AGENCY_PARTY_JOIN_BLOCKED_BY_MAP = 4,
AGENCY_CHAR_CANT_BE_FOUND = 5,
AGENCY_CHAR_CANT_BE_FOUND2 = 6,
AGENCY_PLAYER_ALREADY_IN_PARTY = 7,
AGENCY_REQUEST_CANT_BE_RECEIVED = 8,
AGENCY_CANT_FIND_PARTY_LEADER_DELAYED = 9,
AGENCY_PARTY_NOT_FOUND = 10,
AGENCY_JOB_LEVEL_TOO_LOW = 11,
AGENCY_CHAR_IN_SAME_ACCOUNT_ALREADY_JOINED = 12,
AGENCY_UNKNOWN_ERROR = 13
};

/* packet size constant for itemlist */
#if MAX_INVENTORY > MAX_STORAGE && MAX_INVENTORY > MAX_CART
#define MAX_ITEMLIST MAX_INVENTORY
Expand Down
45 changes: 45 additions & 0 deletions src/map/clif.c
Original file line number Diff line number Diff line change
Expand Up @@ -25838,6 +25838,48 @@ static void clif_goldpc_info(struct map_session_data *sd)
#endif // 20140611
}

static void clif_parse_adventuterAgencyJoinReq(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
static void clif_parse_adventuterAgencyJoinReq(int fd, struct map_session_data *sd)
{
#if PACKETVER_MAIN_NUM >= 20171213 || PACKETVER_RE_NUM >= 20171213 || PACKETVER_ZERO_NUM >= 20171214
const struct PACKET_CZ_ADVENTURER_AGENCY_JOIN_REQ *p = RP2PTR(fd);
if (sd->status.party_id != 0) {
clif->adventurerAgencyResult(sd, AGENCY_PLAYER_ALREADY_IN_PARTY, sd->status.name, "");
return;
}
if (sd->party_invite_account != 0) {
clif->adventurerAgencyResult(sd, AGENCY_UNKNOWN_ERROR, "", "");
return;
}
struct map_session_data *tsd = map->charid2sd(p->GID);
if (tsd == NULL) {
clif->adventurerAgencyResult(sd, AGENCY_MASTER_UNABLE_ACCEPT_REQUEST, "", "");
return;
}
if (tsd->status.party_id == 0) {
clif->adventurerAgencyResult(sd, AGENCY_PARTY_NOT_FOUND, "", "");
return;
}

intif->request_agency_join_party(sd->status.char_id, tsd->status.party_id, sd->mapindex);
#endif
}

static void clif_adventurerAgencyResult(struct map_session_data *sd, enum adventurer_agency_result result, const char *player_name, const char *party_name)
{
#if PACKETVER_MAIN_NUM >= 20191218 || PACKETVER_RE_NUM >= 20191211 || PACKETVER_ZERO_NUM >= 20191224
nullpo_retv(sd);
nullpo_retv(player_name);
nullpo_retv(party_name);
struct PACKET_ZC_ADVENTURER_AGENCY_JOIN_RESULT p = {};
p.packetType = HEADER_ZC_ADVENTURER_AGENCY_JOIN_RESULT;
p.result = result;
safestrncpy(p.player_name, player_name, NAME_LENGTH);
safestrncpy(p.party_name, party_name, NAME_LENGTH);
clif->send(&p, sizeof(p), &sd->bl, SELF);
#endif
}

/*==========================================
* Main client packet processing function
*------------------------------------------*/
Expand Down Expand Up @@ -27192,4 +27234,7 @@ void clif_defaults(void)
clif->dynamicnpc_create_result = clif_dynamicnpc_create_result;

clif->goldpc_info = clif_goldpc_info;

clif->pAdventuterAgencyJoinReq = clif_parse_adventuterAgencyJoinReq;
clif->adventurerAgencyResult = clif_adventurerAgencyResult;
}
3 changes: 3 additions & 0 deletions src/map/clif.h
Original file line number Diff line number Diff line change
Expand Up @@ -1972,6 +1972,9 @@ struct clif_interface {
void (*pDynamicnpcCreateRequest) (int fd, struct map_session_data *sd);
void (*dynamicnpc_create_result) (struct map_session_data *sd, enum dynamicnpc_create_result result);
void (*goldpc_info) (struct map_session_data *sd);

void (*pAdventuterAgencyJoinReq) (int fd, struct map_session_data *sd);
void (*adventurerAgencyResult) (struct map_session_data *sd, enum adventurer_agency_result result, const char *player_name, const char *party_name);
};

#ifdef HERCULES_CORE
Expand Down
Loading

0 comments on commit 9ef5e4e

Please sign in to comment.