Skip to content

Commit

Permalink
Add common packets struct file for inter server packets
Browse files Browse the repository at this point in the history
  • Loading branch information
Asheraf committed Feb 27, 2022
1 parent afb19fb commit cbfced4
Show file tree
Hide file tree
Showing 19 changed files with 113 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/char/int_pet.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ static int inter_pet_parse_frommap(int fd)
{
RFIFOHEAD(fd);
switch(RFIFOW(fd, 0)){
case 0x3080: mapif->parse_CreatePet(fd); break;
case HEADER_INTER_CREATE_PET: mapif->parse_CreatePet(fd); break;
case 0x3081: mapif->parse_LoadPet(fd); break;
case 0x3082: mapif->parse_SavePet(fd); break;
case 0x3083: mapif->parse_DeletePet(fd); break;
Expand Down
3 changes: 2 additions & 1 deletion src/char/inter.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ static int inter_recv_packet_length[] = {
-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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3080-
sizeof(struct PACKET_INTER_CREATE_PET), // 3080
14,-1, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3081-
-1,10,-1, 6, 0, 20,10,20, -1,6 + NAME_LENGTH, 0, 0, 0, 0, 0, 0, // 3090- Homunculus packets [albator], RoDEX packets
};

Expand Down
1 change: 1 addition & 0 deletions src/char/inter.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include "common/hercules.h"
#include "common/db.h"
#include "common/packets_struct.h"

#include <stdarg.h>

Expand Down
32 changes: 15 additions & 17 deletions src/char/mapif.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "common/memmgr.h"
#include "common/mmo.h"
#include "common/nullpo.h"
#include "common/packets_struct.h"
#include "common/random.h"
#include "common/showmsg.h"
#include "common/socket.h"
Expand Down Expand Up @@ -1472,27 +1473,24 @@ static int mapif_delete_pet(int fd, int pet_id)

static int mapif_parse_CreatePet(int fd)
{
int account_id;
struct s_pet *pet;
const struct PACKET_INTER_CREATE_PET *p = RP2PTR(fd);

RFIFOHEAD(fd);
account_id = RFIFOL(fd, 2);
pet = inter_pet->create(account_id,
RFIFOL(fd, 6),
RFIFOL(fd, 10),
RFIFOL(fd, 14),
RFIFOL(fd, 18),
RFIFOL(fd, 22),
RFIFOW(fd, 26),
RFIFOW(fd, 28),
RFIFOB(fd, 30),
RFIFOB(fd, 31),
RFIFOP(fd, 32));
struct s_pet *pet = inter_pet->create(p->account_id,
p->char_id,
p->pet_class,
p->pet_lv,
p->pet_egg_id,
p->pet_equip,
p->intimate,
p->hungry,
p->rename_flag,
p->incubate,
p->pet_name);

if (pet != NULL)
mapif->pet_created(fd, account_id, pet);
mapif->pet_created(fd, p->account_id, pet);
else
mapif->pet_created(fd, account_id, NULL);
mapif->pet_created(fd, p->account_id, NULL);

return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/common/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ COMMON_OBJ = $(addprefix obj_all/, $(COMMON_SHARED_OBJ) \
COMMON_C += console.c core.c memmgr.c socket.c
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 random.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 ../plugins/HPMHooking.h
COMMON_PH =
Expand Down
53 changes: 53 additions & 0 deletions src/common/packets_struct.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
* Copyright (C) 2022 Hercules Dev Team
*
* 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_PACKETS_STRUCT_H
#define COMMON_PACKETS_STRUCT_H

#include "common/cbasetypes.h"
#include "common/mmo.h"
#include "common/packetsstatic_len.h"

#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_INTER_CREATE_PET {
int16 packet_id;
int account_id;
int char_id;
int pet_class;
int pet_lv;
int pet_egg_id;
int pet_equip;
int16 intimate;
int16 hungry;
char rename_flag;
char incubate;
char pet_name[NAME_LENGTH];
};
DEFINE_PACKET_ID(INTER_CREATE_PET, 0x3080);

#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_PACKETS_STRUCT_H */
30 changes: 16 additions & 14 deletions src/map/intif.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

#include "common/memmgr.h"
#include "common/nullpo.h"
#include "common/packets_struct.h"
#include "common/showmsg.h"
#include "common/socket.h"
#include "common/strlib.h"
Expand Down Expand Up @@ -77,21 +78,22 @@ static int intif_create_pet(int account_id, int char_id, int pet_class, int pet_
if (intif->CheckForCharServer())
return 0;
nullpo_ret(pet_name);
WFIFOHEAD(inter_fd, 32 + NAME_LENGTH);
WFIFOW(inter_fd, 0) = 0x3080;
WFIFOL(inter_fd, 2) = account_id;
WFIFOL(inter_fd, 6) = char_id;
WFIFOL(inter_fd, 10) = pet_class;
WFIFOL(inter_fd, 14) = pet_lv;
WFIFOL(inter_fd, 18) = pet_egg_id;
WFIFOL(inter_fd, 22) = pet_equip;
WFIFOW(inter_fd, 26) = intimate;
WFIFOW(inter_fd, 28) = hungry;
WFIFOB(inter_fd, 30) = rename_flag;
WFIFOB(inter_fd, 31) = incubate;
memcpy(WFIFOP(inter_fd, 32), pet_name, NAME_LENGTH);
WFIFOSET(inter_fd, 32 + NAME_LENGTH);

WFIFOHEAD(inter_fd, sizeof(struct PACKET_INTER_CREATE_PET));
struct PACKET_INTER_CREATE_PET *p = WFIFOP(inter_fd, 0);
p->packet_id = HEADER_INTER_CREATE_PET;
p->account_id = account_id;
p->char_id = char_id;
p->pet_class = pet_class;
p->pet_lv = pet_lv;
p->pet_egg_id = pet_egg_id;
p->pet_equip = pet_equip;
p->intimate = intimate;
p->hungry = hungry;
p->rename_flag = rename_flag;
p->incubate = incubate;
safestrncpy(p->pet_name, pet_name, NAME_LENGTH);
WFIFOSET(inter_fd, sizeof(struct PACKET_INTER_CREATE_PET));
return 0;
}

Expand Down
1 change: 1 addition & 0 deletions vcproj-15/char-server.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@
<ClInclude Include="..\src\common\mmo.h" />
<ClInclude Include="..\src\common\mutex.h" />
<ClInclude Include="..\src\common\nullpo.h" />
<ClInclude Include="..\src\common\packets_struct.h" />
<ClInclude Include="..\src\common\random.h" />
<ClInclude Include="..\src\common\showmsg.h" />
<ClInclude Include="..\src\common\socket.h" />
Expand Down
3 changes: 3 additions & 0 deletions vcproj-15/char-server.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,9 @@
<ClInclude Include="..\src\char\int_rodex.h">
<Filter>char</Filter>
</ClInclude>
<ClInclude Include="..\src\common\packets_struct.h">
<Filter>common</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="common">
Expand Down
1 change: 1 addition & 0 deletions vcproj-15/map-server.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
<ClInclude Include="..\src\common\mmo.h" />
<ClInclude Include="..\src\common\mutex.h" />
<ClInclude Include="..\src\common\nullpo.h" />
<ClInclude Include="..\src\common\packets_struct.h" />
<ClInclude Include="..\src\common\random.h" />
<ClInclude Include="..\src\common\showmsg.h" />
<ClInclude Include="..\src\common\socket.h" />
Expand Down
3 changes: 3 additions & 0 deletions vcproj-15/map-server.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,9 @@
<ClInclude Include="..\src\map\refine.h">
<Filter>map</Filter>
</ClInclude>
<ClInclude Include="..\src\common\packets_struct.h">
<Filter>common</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="common">
Expand Down
1 change: 1 addition & 0 deletions vcproj-16/char-server.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@
<ClInclude Include="..\src\common\mmo.h" />
<ClInclude Include="..\src\common\mutex.h" />
<ClInclude Include="..\src\common\nullpo.h" />
<ClInclude Include="..\src\common\packets_struct.h" />
<ClInclude Include="..\src\common\random.h" />
<ClInclude Include="..\src\common\showmsg.h" />
<ClInclude Include="..\src\common\socket.h" />
Expand Down
3 changes: 3 additions & 0 deletions vcproj-16/char-server.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,9 @@
<ClInclude Include="..\src\char\int_rodex.h">
<Filter>char</Filter>
</ClInclude>
<ClInclude Include="..\src\common\packets_struct.h">
<Filter>common</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="common">
Expand Down
1 change: 1 addition & 0 deletions vcproj-16/map-server.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
<ClInclude Include="..\src\common\mmo.h" />
<ClInclude Include="..\src\common\mutex.h" />
<ClInclude Include="..\src\common\nullpo.h" />
<ClInclude Include="..\src\common\packets_struct.h" />
<ClInclude Include="..\src\common\random.h" />
<ClInclude Include="..\src\common\showmsg.h" />
<ClInclude Include="..\src\common\socket.h" />
Expand Down
3 changes: 3 additions & 0 deletions vcproj-16/map-server.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,9 @@
<ClInclude Include="..\src\map\grader.h">
<Filter>map</Filter>
</ClInclude>
<ClInclude Include="..\src\common\packets_struct.h">
<Filter>common</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="common">
Expand Down
1 change: 1 addition & 0 deletions vcproj-17/char-server.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@
<ClInclude Include="..\src\common\mmo.h" />
<ClInclude Include="..\src\common\mutex.h" />
<ClInclude Include="..\src\common\nullpo.h" />
<ClInclude Include="..\src\common\packets_struct.h" />
<ClInclude Include="..\src\common\random.h" />
<ClInclude Include="..\src\common\showmsg.h" />
<ClInclude Include="..\src\common\socket.h" />
Expand Down
3 changes: 3 additions & 0 deletions vcproj-17/char-server.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,9 @@
<ClInclude Include="..\src\char\int_rodex.h">
<Filter>char</Filter>
</ClInclude>
<ClInclude Include="..\src\common\packets_struct.h">
<Filter>common</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="common">
Expand Down
1 change: 1 addition & 0 deletions vcproj-17/map-server.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
<ClInclude Include="..\src\common\mmo.h" />
<ClInclude Include="..\src\common\mutex.h" />
<ClInclude Include="..\src\common\nullpo.h" />
<ClInclude Include="..\src\common\packets_struct.h" />
<ClInclude Include="..\src\common\random.h" />
<ClInclude Include="..\src\common\showmsg.h" />
<ClInclude Include="..\src\common\socket.h" />
Expand Down
3 changes: 3 additions & 0 deletions vcproj-17/map-server.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,9 @@
<ClInclude Include="..\src\map\refine.h">
<Filter>map</Filter>
</ClInclude>
<ClInclude Include="..\src\common\packets_struct.h">
<Filter>common</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="common">
Expand Down

0 comments on commit cbfced4

Please sign in to comment.