Core/PacketIO: Ported SMSG_GOSSIP_POI, CMSG_GROUP_INVITE and SMSG_GROUP_INVITE to packet classes

This commit is contained in:
Shauren
2024-07-14 17:28:48 +02:00
parent fbc18ff420
commit a3aecbdd92
9 changed files with 178 additions and 48 deletions

View File

@@ -17,6 +17,7 @@
#include "GossipDef.h"
#include "Log.h"
#include "NPCPackets.h"
#include "ObjectMgr.h"
#include "Player.h"
#include "QuestDef.h"
@@ -259,28 +260,27 @@ void PlayerMenu::SendCloseGossip()
void PlayerMenu::SendPointOfInterest(uint32 id) const
{
PointOfInterest const* poi = sObjectMgr->GetPointOfInterest(id);
if (!poi)
PointOfInterest const* pointOfInterest = sObjectMgr->GetPointOfInterest(id);
if (!pointOfInterest)
{
TC_LOG_ERROR("sql.sql", "Request to send non-existing POI (Id: {}), ignored.", id);
return;
}
std::string name = poi->Name;
WorldPackets::NPC::GossipPOI packet;
packet.Name = pointOfInterest->Name;
LocaleConstant localeConstant = _session->GetSessionDbLocaleIndex();
if (localeConstant != LOCALE_enUS)
if (PointOfInterestLocale const* localeData = sObjectMgr->GetPointOfInterestLocale(id))
ObjectMgr::GetLocaleString(localeData->Name, localeConstant, name);
ObjectMgr::GetLocaleString(localeData->Name, localeConstant, packet.Name);
WorldPacket data(SMSG_GOSSIP_POI, 4 + 4 + 4 + 4 + 4 + 10); // guess size
data << uint32(poi->Flags);
data << float(poi->PositionX);
data << float(poi->PositionY);
data << uint32(poi->Icon);
data << uint32(poi->Importance);
data << name;
packet.Flags = pointOfInterest->Flags;
packet.Pos.Pos.Relocate(pointOfInterest->PositionX, pointOfInterest->PositionY);
packet.Icon = pointOfInterest->Icon;
packet.Importance = pointOfInterest->Importance;
_session->SendPacket(&data);
_session->SendPacket(packet.Write());
}
/*********************************************************/

View File

@@ -56,7 +56,7 @@ void WorldSession::HandleAuctionHelloOpcode(WorldPacket& recvData)
}
//this void causes that auction window is opened
void WorldSession::SendAuctionHello(ObjectGuid guid, Creature* unit)
void WorldSession::SendAuctionHello(ObjectGuid guid, Unit const* unit)
{
if (GetPlayer()->GetLevel() < sWorld->getIntConfig(CONFIG_AUCTION_LEVEL_REQ))
{

View File

@@ -25,6 +25,7 @@
#include "MiscPackets.h"
#include "ObjectAccessor.h"
#include "ObjectMgr.h"
#include "PartyPackets.h"
#include "Pet.h"
#include "Player.h"
#include "SocialMgr.h"
@@ -58,74 +59,70 @@ void WorldSession::SendPartyResult(PartyOperation operation, const std::string&
SendPacket(&data);
}
void WorldSession::HandleGroupInviteOpcode(WorldPacket& recvData)
void WorldSession::HandleGroupInviteOpcode(WorldPackets::Party::PartyInviteClient& packet)
{
TC_LOG_DEBUG("network", "WORLD: Received CMSG_GROUP_INVITE");
std::string membername;
recvData >> membername;
recvData.read_skip<uint32>();
// attempt add selected player
// cheating
if (!normalizePlayerName(membername))
if (!normalizePlayerName(packet.TargetName))
{
SendPartyResult(PARTY_OP_INVITE, membername, ERR_BAD_PLAYER_NAME_S);
SendPartyResult(PARTY_OP_INVITE, packet.TargetName, ERR_BAD_PLAYER_NAME_S);
return;
}
Player* invitingPlayer = GetPlayer();
Player* invitedPlayer = ObjectAccessor::FindPlayerByName(membername);
Player* invitedPlayer = ObjectAccessor::FindPlayerByName(packet.TargetName);
// no player
if (!invitedPlayer)
{
SendPartyResult(PARTY_OP_INVITE, membername, ERR_BAD_PLAYER_NAME_S);
SendPartyResult(PARTY_OP_INVITE, packet.TargetName, ERR_BAD_PLAYER_NAME_S);
return;
}
// player trying to invite himself (most likely cheating)
if (invitedPlayer == invitingPlayer)
{
SendPartyResult(PARTY_OP_INVITE, membername, ERR_BAD_PLAYER_NAME_S);
SendPartyResult(PARTY_OP_INVITE, packet.TargetName, ERR_BAD_PLAYER_NAME_S);
return;
}
// restrict invite to GMs
if (!sWorld->getBoolConfig(CONFIG_ALLOW_GM_GROUP) && !invitingPlayer->IsGameMaster() && invitedPlayer->IsGameMaster())
{
SendPartyResult(PARTY_OP_INVITE, membername, ERR_BAD_PLAYER_NAME_S);
SendPartyResult(PARTY_OP_INVITE, packet.TargetName, ERR_BAD_PLAYER_NAME_S);
return;
}
// can't group with
if (!invitingPlayer->IsGameMaster() && !sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GROUP) && invitingPlayer->GetTeam() != invitedPlayer->GetTeam())
{
SendPartyResult(PARTY_OP_INVITE, membername, ERR_PLAYER_WRONG_FACTION);
SendPartyResult(PARTY_OP_INVITE, packet.TargetName, ERR_PLAYER_WRONG_FACTION);
return;
}
if (invitingPlayer->GetInstanceId() != 0 && invitedPlayer->GetInstanceId() != 0 && invitingPlayer->GetInstanceId() != invitedPlayer->GetInstanceId() && invitingPlayer->GetMapId() == invitedPlayer->GetMapId())
{
SendPartyResult(PARTY_OP_INVITE, membername, ERR_TARGET_NOT_IN_INSTANCE_S);
SendPartyResult(PARTY_OP_INVITE, packet.TargetName, ERR_TARGET_NOT_IN_INSTANCE_S);
return;
}
// just ignore us
if (invitedPlayer->GetInstanceId() != 0 && invitedPlayer->GetDungeonDifficulty() != invitingPlayer->GetDungeonDifficulty())
{
SendPartyResult(PARTY_OP_INVITE, membername, ERR_IGNORING_YOU_S);
SendPartyResult(PARTY_OP_INVITE, packet.TargetName, ERR_IGNORING_YOU_S);
return;
}
if (invitedPlayer->GetSocial()->HasIgnore(invitingPlayer->GetGUID()))
{
SendPartyResult(PARTY_OP_INVITE, membername, ERR_IGNORING_YOU_S);
SendPartyResult(PARTY_OP_INVITE, packet.TargetName, ERR_IGNORING_YOU_S);
return;
}
if (!invitedPlayer->GetSocial()->HasFriend(invitingPlayer->GetGUID()) && invitingPlayer->GetLevel() < sWorld->getIntConfig(CONFIG_PARTY_LEVEL_REQ))
{
SendPartyResult(PARTY_OP_INVITE, membername, ERR_INVITE_RESTRICTED);
SendPartyResult(PARTY_OP_INVITE, packet.TargetName, ERR_INVITE_RESTRICTED);
return;
}
@@ -141,18 +138,14 @@ void WorldSession::HandleGroupInviteOpcode(WorldPacket& recvData)
// player already in another group or invited
if (group2 || invitedPlayer->GetGroupInvite())
{
SendPartyResult(PARTY_OP_INVITE, membername, ERR_ALREADY_IN_GROUP_S);
SendPartyResult(PARTY_OP_INVITE, packet.TargetName, ERR_ALREADY_IN_GROUP_S);
if (group2)
{
// tell the player that they were invited but it failed as they were already in a group
WorldPacket data(SMSG_GROUP_INVITE, 10); // guess size
data << uint8(0); // invited/already in group flag
data << invitingPlayer->GetName(); // max len 48
data << uint32(0); // unk
data << uint8(0); // count
data << uint32(0); // unk
invitedPlayer->SendDirectMessage(&data);
WorldPackets::Party::PartyInvite partyInvite;
partyInvite.Initialize(invitingPlayer, packet.ProposedRoles, false);
invitedPlayer->SendDirectMessage(partyInvite.Write());
}
return;
@@ -203,16 +196,11 @@ void WorldSession::HandleGroupInviteOpcode(WorldPacket& recvData)
}
}
// ok, we do it
WorldPacket data(SMSG_GROUP_INVITE, 10); // guess size
data << uint8(1); // invited/already in group flag
data << invitingPlayer->GetName(); // max len 48
data << uint32(0); // unk
data << uint8(0); // count
data << uint32(0); // unk
invitedPlayer->SendDirectMessage(&data);
WorldPackets::Party::PartyInvite partyInvite;
partyInvite.Initialize(invitingPlayer, packet.ProposedRoles, true);
invitedPlayer->SendDirectMessage(partyInvite.Write());
SendPartyResult(PARTY_OP_INVITE, membername, ERR_PARTY_RESULT_OK);
SendPartyResult(PARTY_OP_INVITE, packet.TargetName, ERR_PARTY_RESULT_OK);
}
void WorldSession::HandleGroupAcceptOpcode(WorldPacket& recvData)

View File

@@ -29,6 +29,7 @@
#include "MailPackets.h"
#include "MiscPackets.h"
#include "NPCPackets.h"
#include "PartyPackets.h"
#include "PetPackets.h"
#include "QueryPackets.h"
#include "QuestPackets.h"

View File

@@ -45,6 +45,17 @@ WorldPacket const* WorldPackets::NPC::TrainerList::Write()
return &_worldPacket;
}
WorldPacket const* WorldPackets::NPC::GossipPOI::Write()
{
_worldPacket << int32(Flags);
_worldPacket << Pos;
_worldPacket << int32(Icon);
_worldPacket << int32(Importance);
_worldPacket << Name;
return &_worldPacket;
}
void WorldPackets::NPC::TrainerBuySpell::Read()
{
_worldPacket >> TrainerGUID;

View File

@@ -20,6 +20,7 @@
#include "Packet.h"
#include "ObjectGuid.h"
#include "Position.h"
#include <array>
namespace WorldPackets
@@ -67,6 +68,20 @@ namespace WorldPackets
std::string Greeting;
};
class GossipPOI final : public ServerPacket
{
public:
GossipPOI() : ServerPacket(SMSG_GOSSIP_POI, 4 + 4 + 4 + 4 + 4 + 32) { }
WorldPacket const* Write() override;
uint32 Flags = 0;
TaggedPosition<Position::XY> Pos;
int32 Icon = 0;
int32 Importance = 0;
std::string Name;
};
class TrainerBuySpell final : public ClientPacket
{
public:

View File

@@ -0,0 +1,48 @@
/*
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
*
* This program 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 2 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/>.
*/
#include "PartyPackets.h"
#include "Player.h"
void WorldPackets::Party::PartyInviteClient::Read()
{
_worldPacket >> TargetName;
_worldPacket >> ProposedRoles;
}
WorldPacket const* WorldPackets::Party::PartyInvite::Write()
{
_worldPacket << uint8(CanAccept);
_worldPacket << InviterName;
_worldPacket << uint32(ProposedRoles);
_worldPacket << uint8(LfgSlots.size());
if (!LfgSlots.empty())
_worldPacket.append(LfgSlots.data(), LfgSlots.size());
_worldPacket << uint32(LfgCompletedMask);
return &_worldPacket;
}
void WorldPackets::Party::PartyInvite::Initialize(Player const* inviter, uint32 proposedRoles, bool canAccept)
{
CanAccept = canAccept;
InviterName = inviter->GetName();
ProposedRoles = proposedRoles;
}

View File

@@ -0,0 +1,62 @@
/*
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
*
* This program 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 2 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 PartyPackets_h__
#define PartyPackets_h__
#include "Packet.h"
class Player;
namespace WorldPackets
{
namespace Party
{
class PartyInviteClient final : public ClientPacket
{
public:
PartyInviteClient(WorldPacket&& packet) : ClientPacket(CMSG_GROUP_INVITE, std::move(packet)) { }
void Read() override;
uint32 ProposedRoles = 0;
std::string TargetName;
};
class PartyInvite final : public ServerPacket
{
public:
PartyInvite() : ServerPacket(SMSG_GROUP_INVITE, 55) { }
WorldPacket const* Write() override;
void Initialize(Player const* inviter, uint32 proposedRoles, bool canAccept);
bool CanAccept = false;
// Inviter
std::string InviterName;
// Lfg
uint32 ProposedRoles = 0;
uint32 LfgCompletedMask = 0;
std::vector<uint32> LfgSlots;
};
}
}
#endif // PartyPackets_h__

View File

@@ -207,6 +207,11 @@ namespace WorldPackets
class TrainerBuySpell;
}
namespace Party
{
class PartyInviteClient;
}
namespace Pet
{
class DismissCritter;
@@ -577,7 +582,7 @@ class TC_GAME_API WorldSession
void AddInstanceEnterTime(uint32 instanceId, SystemTimePoint enterTime);
void UpdateInstanceEnterTimes();
//auction
void SendAuctionHello(ObjectGuid guid, Creature* unit);
void SendAuctionHello(ObjectGuid guid, Unit const* unit);
void SendAuctionCommandResult(uint32 auctionItemId, AuctionAction command, AuctionError errorCode, InventoryResult bagResult = InventoryResult(0));
void SendAuctionBidderNotification(uint32 location, uint32 auctionId, ObjectGuid bidder, uint32 bidSum, uint32 diff, uint32 item_template);
void SendAuctionOwnerNotification(AuctionEntry* auction);
@@ -774,7 +779,7 @@ class TC_GAME_API WorldSession
void HandleBattlefieldStatusOpcode(WorldPacket& recvData);
void HandleGroupInviteOpcode(WorldPacket& recvPacket);
void HandleGroupInviteOpcode(WorldPackets::Party::PartyInviteClient& packet);
void HandleGroupAcceptOpcode(WorldPacket& recvPacket);
void HandleGroupDeclineOpcode(WorldPacket& recvPacket);
void HandleGroupUninviteOpcode(WorldPacket& recvPacket);