Skip to content

Commit a3aecbd

Browse files
committed
Core/PacketIO: Ported SMSG_GOSSIP_POI, CMSG_GROUP_INVITE and SMSG_GROUP_INVITE to packet classes
1 parent fbc18ff commit a3aecbd

9 files changed

Lines changed: 178 additions & 48 deletions

File tree

src/server/game/Entities/Creature/GossipDef.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "GossipDef.h"
1919
#include "Log.h"
20+
#include "NPCPackets.h"
2021
#include "ObjectMgr.h"
2122
#include "Player.h"
2223
#include "QuestDef.h"
@@ -259,28 +260,27 @@ void PlayerMenu::SendCloseGossip()
259260

260261
void PlayerMenu::SendPointOfInterest(uint32 id) const
261262
{
262-
PointOfInterest const* poi = sObjectMgr->GetPointOfInterest(id);
263-
if (!poi)
263+
PointOfInterest const* pointOfInterest = sObjectMgr->GetPointOfInterest(id);
264+
if (!pointOfInterest)
264265
{
265266
TC_LOG_ERROR("sql.sql", "Request to send non-existing POI (Id: {}), ignored.", id);
266267
return;
267268
}
268269

269-
std::string name = poi->Name;
270+
WorldPackets::NPC::GossipPOI packet;
271+
packet.Name = pointOfInterest->Name;
272+
270273
LocaleConstant localeConstant = _session->GetSessionDbLocaleIndex();
271274
if (localeConstant != LOCALE_enUS)
272275
if (PointOfInterestLocale const* localeData = sObjectMgr->GetPointOfInterestLocale(id))
273-
ObjectMgr::GetLocaleString(localeData->Name, localeConstant, name);
276+
ObjectMgr::GetLocaleString(localeData->Name, localeConstant, packet.Name);
274277

275-
WorldPacket data(SMSG_GOSSIP_POI, 4 + 4 + 4 + 4 + 4 + 10); // guess size
276-
data << uint32(poi->Flags);
277-
data << float(poi->PositionX);
278-
data << float(poi->PositionY);
279-
data << uint32(poi->Icon);
280-
data << uint32(poi->Importance);
281-
data << name;
278+
packet.Flags = pointOfInterest->Flags;
279+
packet.Pos.Pos.Relocate(pointOfInterest->PositionX, pointOfInterest->PositionY);
280+
packet.Icon = pointOfInterest->Icon;
281+
packet.Importance = pointOfInterest->Importance;
282282

283-
_session->SendPacket(&data);
283+
_session->SendPacket(packet.Write());
284284
}
285285

286286
/*********************************************************/

src/server/game/Handlers/AuctionHouseHandler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void WorldSession::HandleAuctionHelloOpcode(WorldPacket& recvData)
5656
}
5757

5858
//this void causes that auction window is opened
59-
void WorldSession::SendAuctionHello(ObjectGuid guid, Creature* unit)
59+
void WorldSession::SendAuctionHello(ObjectGuid guid, Unit const* unit)
6060
{
6161
if (GetPlayer()->GetLevel() < sWorld->getIntConfig(CONFIG_AUCTION_LEVEL_REQ))
6262
{

src/server/game/Handlers/GroupHandler.cpp

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "MiscPackets.h"
2626
#include "ObjectAccessor.h"
2727
#include "ObjectMgr.h"
28+
#include "PartyPackets.h"
2829
#include "Pet.h"
2930
#include "Player.h"
3031
#include "SocialMgr.h"
@@ -58,74 +59,70 @@ void WorldSession::SendPartyResult(PartyOperation operation, const std::string&
5859
SendPacket(&data);
5960
}
6061

61-
void WorldSession::HandleGroupInviteOpcode(WorldPacket& recvData)
62+
void WorldSession::HandleGroupInviteOpcode(WorldPackets::Party::PartyInviteClient& packet)
6263
{
6364
TC_LOG_DEBUG("network", "WORLD: Received CMSG_GROUP_INVITE");
6465

65-
std::string membername;
66-
recvData >> membername;
67-
recvData.read_skip<uint32>();
68-
6966
// attempt add selected player
7067

7168
// cheating
72-
if (!normalizePlayerName(membername))
69+
if (!normalizePlayerName(packet.TargetName))
7370
{
74-
SendPartyResult(PARTY_OP_INVITE, membername, ERR_BAD_PLAYER_NAME_S);
71+
SendPartyResult(PARTY_OP_INVITE, packet.TargetName, ERR_BAD_PLAYER_NAME_S);
7572
return;
7673
}
7774

7875
Player* invitingPlayer = GetPlayer();
79-
Player* invitedPlayer = ObjectAccessor::FindPlayerByName(membername);
76+
Player* invitedPlayer = ObjectAccessor::FindPlayerByName(packet.TargetName);
8077

8178
// no player
8279
if (!invitedPlayer)
8380
{
84-
SendPartyResult(PARTY_OP_INVITE, membername, ERR_BAD_PLAYER_NAME_S);
81+
SendPartyResult(PARTY_OP_INVITE, packet.TargetName, ERR_BAD_PLAYER_NAME_S);
8582
return;
8683
}
8784

8885
// player trying to invite himself (most likely cheating)
8986
if (invitedPlayer == invitingPlayer)
9087
{
91-
SendPartyResult(PARTY_OP_INVITE, membername, ERR_BAD_PLAYER_NAME_S);
88+
SendPartyResult(PARTY_OP_INVITE, packet.TargetName, ERR_BAD_PLAYER_NAME_S);
9289
return;
9390
}
9491

9592
// restrict invite to GMs
9693
if (!sWorld->getBoolConfig(CONFIG_ALLOW_GM_GROUP) && !invitingPlayer->IsGameMaster() && invitedPlayer->IsGameMaster())
9794
{
98-
SendPartyResult(PARTY_OP_INVITE, membername, ERR_BAD_PLAYER_NAME_S);
95+
SendPartyResult(PARTY_OP_INVITE, packet.TargetName, ERR_BAD_PLAYER_NAME_S);
9996
return;
10097
}
10198

10299
// can't group with
103100
if (!invitingPlayer->IsGameMaster() && !sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GROUP) && invitingPlayer->GetTeam() != invitedPlayer->GetTeam())
104101
{
105-
SendPartyResult(PARTY_OP_INVITE, membername, ERR_PLAYER_WRONG_FACTION);
102+
SendPartyResult(PARTY_OP_INVITE, packet.TargetName, ERR_PLAYER_WRONG_FACTION);
106103
return;
107104
}
108105
if (invitingPlayer->GetInstanceId() != 0 && invitedPlayer->GetInstanceId() != 0 && invitingPlayer->GetInstanceId() != invitedPlayer->GetInstanceId() && invitingPlayer->GetMapId() == invitedPlayer->GetMapId())
109106
{
110-
SendPartyResult(PARTY_OP_INVITE, membername, ERR_TARGET_NOT_IN_INSTANCE_S);
107+
SendPartyResult(PARTY_OP_INVITE, packet.TargetName, ERR_TARGET_NOT_IN_INSTANCE_S);
111108
return;
112109
}
113110
// just ignore us
114111
if (invitedPlayer->GetInstanceId() != 0 && invitedPlayer->GetDungeonDifficulty() != invitingPlayer->GetDungeonDifficulty())
115112
{
116-
SendPartyResult(PARTY_OP_INVITE, membername, ERR_IGNORING_YOU_S);
113+
SendPartyResult(PARTY_OP_INVITE, packet.TargetName, ERR_IGNORING_YOU_S);
117114
return;
118115
}
119116

120117
if (invitedPlayer->GetSocial()->HasIgnore(invitingPlayer->GetGUID()))
121118
{
122-
SendPartyResult(PARTY_OP_INVITE, membername, ERR_IGNORING_YOU_S);
119+
SendPartyResult(PARTY_OP_INVITE, packet.TargetName, ERR_IGNORING_YOU_S);
123120
return;
124121
}
125122

126123
if (!invitedPlayer->GetSocial()->HasFriend(invitingPlayer->GetGUID()) && invitingPlayer->GetLevel() < sWorld->getIntConfig(CONFIG_PARTY_LEVEL_REQ))
127124
{
128-
SendPartyResult(PARTY_OP_INVITE, membername, ERR_INVITE_RESTRICTED);
125+
SendPartyResult(PARTY_OP_INVITE, packet.TargetName, ERR_INVITE_RESTRICTED);
129126
return;
130127
}
131128

@@ -141,18 +138,14 @@ void WorldSession::HandleGroupInviteOpcode(WorldPacket& recvData)
141138
// player already in another group or invited
142139
if (group2 || invitedPlayer->GetGroupInvite())
143140
{
144-
SendPartyResult(PARTY_OP_INVITE, membername, ERR_ALREADY_IN_GROUP_S);
141+
SendPartyResult(PARTY_OP_INVITE, packet.TargetName, ERR_ALREADY_IN_GROUP_S);
145142

146143
if (group2)
147144
{
148145
// tell the player that they were invited but it failed as they were already in a group
149-
WorldPacket data(SMSG_GROUP_INVITE, 10); // guess size
150-
data << uint8(0); // invited/already in group flag
151-
data << invitingPlayer->GetName(); // max len 48
152-
data << uint32(0); // unk
153-
data << uint8(0); // count
154-
data << uint32(0); // unk
155-
invitedPlayer->SendDirectMessage(&data);
146+
WorldPackets::Party::PartyInvite partyInvite;
147+
partyInvite.Initialize(invitingPlayer, packet.ProposedRoles, false);
148+
invitedPlayer->SendDirectMessage(partyInvite.Write());
156149
}
157150

158151
return;
@@ -203,16 +196,11 @@ void WorldSession::HandleGroupInviteOpcode(WorldPacket& recvData)
203196
}
204197
}
205198

206-
// ok, we do it
207-
WorldPacket data(SMSG_GROUP_INVITE, 10); // guess size
208-
data << uint8(1); // invited/already in group flag
209-
data << invitingPlayer->GetName(); // max len 48
210-
data << uint32(0); // unk
211-
data << uint8(0); // count
212-
data << uint32(0); // unk
213-
invitedPlayer->SendDirectMessage(&data);
199+
WorldPackets::Party::PartyInvite partyInvite;
200+
partyInvite.Initialize(invitingPlayer, packet.ProposedRoles, true);
201+
invitedPlayer->SendDirectMessage(partyInvite.Write());
214202

215-
SendPartyResult(PARTY_OP_INVITE, membername, ERR_PARTY_RESULT_OK);
203+
SendPartyResult(PARTY_OP_INVITE, packet.TargetName, ERR_PARTY_RESULT_OK);
216204
}
217205

218206
void WorldSession::HandleGroupAcceptOpcode(WorldPacket& recvData)

src/server/game/Server/Packets/AllPackets.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "MailPackets.h"
3030
#include "MiscPackets.h"
3131
#include "NPCPackets.h"
32+
#include "PartyPackets.h"
3233
#include "PetPackets.h"
3334
#include "QueryPackets.h"
3435
#include "QuestPackets.h"

src/server/game/Server/Packets/NPCPackets.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,17 @@ WorldPacket const* WorldPackets::NPC::TrainerList::Write()
4545
return &_worldPacket;
4646
}
4747

48+
WorldPacket const* WorldPackets::NPC::GossipPOI::Write()
49+
{
50+
_worldPacket << int32(Flags);
51+
_worldPacket << Pos;
52+
_worldPacket << int32(Icon);
53+
_worldPacket << int32(Importance);
54+
_worldPacket << Name;
55+
56+
return &_worldPacket;
57+
}
58+
4859
void WorldPackets::NPC::TrainerBuySpell::Read()
4960
{
5061
_worldPacket >> TrainerGUID;

src/server/game/Server/Packets/NPCPackets.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include "Packet.h"
2222
#include "ObjectGuid.h"
23+
#include "Position.h"
2324
#include <array>
2425

2526
namespace WorldPackets
@@ -67,6 +68,20 @@ namespace WorldPackets
6768
std::string Greeting;
6869
};
6970

71+
class GossipPOI final : public ServerPacket
72+
{
73+
public:
74+
GossipPOI() : ServerPacket(SMSG_GOSSIP_POI, 4 + 4 + 4 + 4 + 4 + 32) { }
75+
76+
WorldPacket const* Write() override;
77+
78+
uint32 Flags = 0;
79+
TaggedPosition<Position::XY> Pos;
80+
int32 Icon = 0;
81+
int32 Importance = 0;
82+
std::string Name;
83+
};
84+
7085
class TrainerBuySpell final : public ClientPacket
7186
{
7287
public:
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3+
*
4+
* This program is free software; you can redistribute it and/or modify it
5+
* under the terms of the GNU General Public License as published by the
6+
* Free Software Foundation; either version 2 of the License, or (at your
7+
* option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12+
* more details.
13+
*
14+
* You should have received a copy of the GNU General Public License along
15+
* with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
#include "PartyPackets.h"
19+
#include "Player.h"
20+
21+
void WorldPackets::Party::PartyInviteClient::Read()
22+
{
23+
_worldPacket >> TargetName;
24+
_worldPacket >> ProposedRoles;
25+
}
26+
27+
WorldPacket const* WorldPackets::Party::PartyInvite::Write()
28+
{
29+
_worldPacket << uint8(CanAccept);
30+
_worldPacket << InviterName;
31+
_worldPacket << uint32(ProposedRoles);
32+
_worldPacket << uint8(LfgSlots.size());
33+
if (!LfgSlots.empty())
34+
_worldPacket.append(LfgSlots.data(), LfgSlots.size());
35+
36+
_worldPacket << uint32(LfgCompletedMask);
37+
38+
return &_worldPacket;
39+
}
40+
41+
void WorldPackets::Party::PartyInvite::Initialize(Player const* inviter, uint32 proposedRoles, bool canAccept)
42+
{
43+
CanAccept = canAccept;
44+
45+
InviterName = inviter->GetName();
46+
47+
ProposedRoles = proposedRoles;
48+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3+
*
4+
* This program is free software; you can redistribute it and/or modify it
5+
* under the terms of the GNU General Public License as published by the
6+
* Free Software Foundation; either version 2 of the License, or (at your
7+
* option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12+
* more details.
13+
*
14+
* You should have received a copy of the GNU General Public License along
15+
* with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
#ifndef PartyPackets_h__
19+
#define PartyPackets_h__
20+
21+
#include "Packet.h"
22+
23+
class Player;
24+
25+
namespace WorldPackets
26+
{
27+
namespace Party
28+
{
29+
class PartyInviteClient final : public ClientPacket
30+
{
31+
public:
32+
PartyInviteClient(WorldPacket&& packet) : ClientPacket(CMSG_GROUP_INVITE, std::move(packet)) { }
33+
34+
void Read() override;
35+
36+
uint32 ProposedRoles = 0;
37+
std::string TargetName;
38+
};
39+
40+
class PartyInvite final : public ServerPacket
41+
{
42+
public:
43+
PartyInvite() : ServerPacket(SMSG_GROUP_INVITE, 55) { }
44+
45+
WorldPacket const* Write() override;
46+
47+
void Initialize(Player const* inviter, uint32 proposedRoles, bool canAccept);
48+
49+
bool CanAccept = false;
50+
51+
// Inviter
52+
std::string InviterName;
53+
54+
// Lfg
55+
uint32 ProposedRoles = 0;
56+
uint32 LfgCompletedMask = 0;
57+
std::vector<uint32> LfgSlots;
58+
};
59+
}
60+
}
61+
62+
#endif // PartyPackets_h__

src/server/game/Server/WorldSession.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,11 @@ namespace WorldPackets
207207
class TrainerBuySpell;
208208
}
209209

210+
namespace Party
211+
{
212+
class PartyInviteClient;
213+
}
214+
210215
namespace Pet
211216
{
212217
class DismissCritter;
@@ -577,7 +582,7 @@ class TC_GAME_API WorldSession
577582
void AddInstanceEnterTime(uint32 instanceId, SystemTimePoint enterTime);
578583
void UpdateInstanceEnterTimes();
579584
//auction
580-
void SendAuctionHello(ObjectGuid guid, Creature* unit);
585+
void SendAuctionHello(ObjectGuid guid, Unit const* unit);
581586
void SendAuctionCommandResult(uint32 auctionItemId, AuctionAction command, AuctionError errorCode, InventoryResult bagResult = InventoryResult(0));
582587
void SendAuctionBidderNotification(uint32 location, uint32 auctionId, ObjectGuid bidder, uint32 bidSum, uint32 diff, uint32 item_template);
583588
void SendAuctionOwnerNotification(AuctionEntry* auction);
@@ -774,7 +779,7 @@ class TC_GAME_API WorldSession
774779

775780
void HandleBattlefieldStatusOpcode(WorldPacket& recvData);
776781

777-
void HandleGroupInviteOpcode(WorldPacket& recvPacket);
782+
void HandleGroupInviteOpcode(WorldPackets::Party::PartyInviteClient& packet);
778783
void HandleGroupAcceptOpcode(WorldPacket& recvPacket);
779784
void HandleGroupDeclineOpcode(WorldPacket& recvPacket);
780785
void HandleGroupUninviteOpcode(WorldPacket& recvPacket);

0 commit comments

Comments
 (0)