Core/PacketIO: Update opcodes for 11.0.5

This commit is contained in:
Shauren
2024-10-30 14:40:36 +01:00
parent b0352ef78e
commit ac7a95b45c
12 changed files with 2196 additions and 2147 deletions

View File

@@ -27327,7 +27327,7 @@ bool Player::IsAreaThatActivatesPvpTalents(uint32 areaID) const
return false;
}
void Player::UpdateFallInformationIfNeed(MovementInfo const& minfo, uint16 opcode)
void Player::UpdateFallInformationIfNeed(MovementInfo const& minfo, uint32 opcode)
{
if (m_lastFallTime >= minfo.jump.fallTime || m_lastFallZ <= minfo.pos.GetPositionZ() || opcode == CMSG_MOVE_FALL_LAND)
SetFallInformation(minfo.jump.fallTime, minfo.pos.GetPositionZ());

View File

@@ -2564,7 +2564,7 @@ class TC_GAME_API Player final : public Unit, public GridObject<Player>
/*********************************************************/
/*** VARIOUS SYSTEMS ***/
/*********************************************************/
void UpdateFallInformationIfNeed(MovementInfo const& minfo, uint16 opcode);
void UpdateFallInformationIfNeed(MovementInfo const& minfo, uint32 opcode);
// only changed for direct client control (possess, vehicle etc.), not stuff you control using pet commands
WorldObject* m_seer;
void SetFallInformation(uint32 time, float z);

View File

@@ -574,7 +574,7 @@ void WorldSession::HandleAuctionReplicateItems(WorldPackets::AuctionHouse::Aucti
SendPacket(response.Write());
}
void WorldSession::HandleAuctionRequestFavoriteList(WorldPackets::AuctionHouse::AuctionRequestFavoriteList& /*requestFavoriteList*/)
void WorldSession::SendAuctionFavoriteList()
{
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHARACTER_FAVORITE_AUCTIONS);
stmt->setUInt64(0, _player->GetGUID().GetCounter());

View File

@@ -1206,6 +1206,8 @@ void WorldSession::HandlePlayerLogin(LoginQueryHolder const& holder)
pCurrChar->SetGuildLevel(0);
}
SendAuctionFavoriteList();
pCurrChar->GetSession()->GetBattlePetMgr()->SendJournalLockStatus();
pCurrChar->SendInitialPacketsBeforeAddToMap();

View File

@@ -309,14 +309,6 @@ namespace WorldPackets
Optional<Addon::AddOnInfo> TaintedBy;
};
class AuctionRequestFavoriteList final : public ClientPacket
{
public:
AuctionRequestFavoriteList(WorldPacket&& packet) : ClientPacket(CMSG_AUCTION_REQUEST_FAVORITE_LIST, std::move(packet)) { }
void Read() override { }
};
class AuctionSellCommodity final : public ClientPacket
{
public:

View File

@@ -57,15 +57,16 @@ bool OpcodeTable::ValidateClientOpcode(OpcodeClient opcode, char const* name) co
return false;
}
if (opcode < MIN_CMSG_OPCODE_NUMBER || opcode > MAX_CMSG_OPCODE_NUMBER)
std::ptrdiff_t index = GetOpcodeArrayIndex(opcode);
if (index < 0 || index >= std::ptrdiff_t(NUM_CMSG_OPCODES))
{
TC_LOG_ERROR("network", "Tried to set handler for an invalid opcode {}", opcode);
return false;
}
if ((*this)[opcode] != nullptr)
if (_internalTableClient[index] != nullptr)
{
TC_LOG_ERROR("network", "Tried to override client handler of {} with {} (opcode {})", (*this)[opcode]->Name, name, opcode);
TC_LOG_ERROR("network", "Tried to override client handler of {} with {} (opcode {})", _internalTableClient[index]->Name, name, opcode);
return false;
}
@@ -77,7 +78,7 @@ void OpcodeTable::ValidateAndSetClientOpcode(OpcodeClient opcode, char const* na
if (!ValidateClientOpcode(opcode, name))
return;
_internalTableClient[opcode - MIN_CMSG_OPCODE_NUMBER].reset(new ClientOpcodeHandler{
_internalTableClient[GetOpcodeArrayIndex(opcode)].reset(new ClientOpcodeHandler{
.Name = name,
.Status = status,
.Call = call,
@@ -93,7 +94,8 @@ bool OpcodeTable::ValidateServerOpcode(OpcodeServer opcode, char const* name, Co
return false;
}
if (opcode < MIN_SMSG_OPCODE_NUMBER || opcode > MAX_SMSG_OPCODE_NUMBER)
std::ptrdiff_t index = GetOpcodeArrayIndex(opcode);
if (index < 0 || index >= std::ptrdiff_t(NUM_SMSG_OPCODES))
{
TC_LOG_ERROR("network", "Tried to set handler for an invalid opcode {}", opcode);
return false;
@@ -111,9 +113,9 @@ bool OpcodeTable::ValidateServerOpcode(OpcodeServer opcode, char const* name, Co
return false;
}
if ((*this)[opcode] != nullptr)
if (_internalTableServer[index] != nullptr)
{
TC_LOG_ERROR("network", "Tried to override server handler of {} with {} (opcode {})", (*this)[opcode]->Name, name, opcode);
TC_LOG_ERROR("network", "Tried to override server handler of {} with {} (opcode {})", _internalTableServer[index]->Name, name, opcode);
return false;
}
@@ -125,7 +127,7 @@ void OpcodeTable::ValidateAndSetServerOpcode(OpcodeServer opcode, char const* na
if (!ValidateServerOpcode(opcode, name, conIdx))
return;
_internalTableServer[opcode - MIN_SMSG_OPCODE_NUMBER].reset(new ServerOpcodeHandler{ .Name = name, .Status = status, .ConnectionIndex = conIdx });
_internalTableServer[GetOpcodeArrayIndex(opcode)].reset(new ServerOpcodeHandler{ .Name = name, .Status = status, .ConnectionIndex = conIdx });
}
/// Correspondence between opcodes and their names
@@ -184,7 +186,6 @@ void OpcodeTable::InitializeClientOpcodes()
DEFINE_HANDLER(CMSG_AUCTION_PLACE_BID, STATUS_LOGGEDIN, PROCESS_THREADUNSAFE, &WorldSession::HandleAuctionPlaceBid);
DEFINE_HANDLER(CMSG_AUCTION_REMOVE_ITEM, STATUS_LOGGEDIN, PROCESS_THREADUNSAFE, &WorldSession::HandleAuctionRemoveItem);
DEFINE_HANDLER(CMSG_AUCTION_REPLICATE_ITEMS, STATUS_LOGGEDIN, PROCESS_THREADUNSAFE, &WorldSession::HandleAuctionReplicateItems);
DEFINE_HANDLER(CMSG_AUCTION_REQUEST_FAVORITE_LIST, STATUS_LOGGEDIN, PROCESS_THREADUNSAFE, &WorldSession::HandleAuctionRequestFavoriteList);
DEFINE_HANDLER(CMSG_AUCTION_SELL_COMMODITY, STATUS_LOGGEDIN, PROCESS_THREADUNSAFE, &WorldSession::HandleAuctionSellCommodity);
DEFINE_HANDLER(CMSG_AUCTION_SELL_ITEM, STATUS_LOGGEDIN, PROCESS_THREADUNSAFE, &WorldSession::HandleAuctionSellItem);
DEFINE_HANDLER(CMSG_AUCTION_SET_FAVORITE_ITEM, STATUS_LOGGEDIN, PROCESS_THREADUNSAFE, &WorldSession::HandleAuctionSetFavoriteItem);
@@ -1980,7 +1981,6 @@ void OpcodeTable::InitializeServerOpcodes()
DEFINE_SERVER_OPCODE_HANDLER(SMSG_RECRAFT_ITEM_RESULT, STATUS_UNHANDLED, CONNECTION_TYPE_REALM);
DEFINE_SERVER_OPCODE_HANDLER(SMSG_RECRUIT_A_FRIEND_FAILURE, STATUS_NEVER, CONNECTION_TYPE_REALM);
DEFINE_SERVER_OPCODE_HANDLER(SMSG_REFRESH_COMPONENT, STATUS_UNHANDLED, CONNECTION_TYPE_REALM);
DEFINE_SERVER_OPCODE_HANDLER(SMSG_REFRESH_SPELL_HISTORY, STATUS_UNHANDLED, CONNECTION_TYPE_REALM);
DEFINE_SERVER_OPCODE_HANDLER(SMSG_REGIONWIDE_CHARACTER_MAIL_DATA, STATUS_UNHANDLED, CONNECTION_TYPE_REALM);
DEFINE_SERVER_OPCODE_HANDLER(SMSG_REGIONWIDE_CHARACTER_RESTRICTIONS_DATA, STATUS_UNHANDLED, CONNECTION_TYPE_REALM);
DEFINE_SERVER_OPCODE_HANDLER(SMSG_REMOVE_ITEM_PASSIVE, STATUS_NEVER, CONNECTION_TYPE_INSTANCE);
@@ -2240,15 +2240,16 @@ void OpcodeTable::InitializeServerOpcodes()
#undef DEFINE_SERVER_OPCODE_HANDLER
}
template<std::size_t MIN_OPCODE, std::size_t MAX_OPCODE, typename T>
inline std::string GetOpcodeNameForLoggingImpl(T id)
template<typename OpcodeDefinition, std::size_t N, typename T>
inline std::string GetOpcodeNameForLoggingImpl(std::array<OpcodeDefinition, N> const& definitions, T id)
{
uint32 opcode = uint32(id);
char const* name = nullptr;
if (opcode >= MIN_OPCODE && opcode <= MAX_OPCODE)
std::ptrdiff_t index = GetOpcodeArrayIndex(id);
if (index >= 0 && index < std::ssize(definitions))
{
if (auto const* handler = opcodeTable[id])
if (auto const* handler = definitions[index].get())
name = handler->Name;
else
name = "UNKNOWN OPCODE";
@@ -2256,15 +2257,15 @@ inline std::string GetOpcodeNameForLoggingImpl(T id)
else
name = "INVALID OPCODE";
return Trinity::StringFormat("[{0} 0x{1:04X} ({1})]", name, opcode);
return Trinity::StringFormat("[{0} 0x{1:06X} ({1})]", name, opcode);
}
std::string GetOpcodeNameForLogging(OpcodeClient opcode)
{
return GetOpcodeNameForLoggingImpl<MIN_CMSG_OPCODE_NUMBER, MAX_CMSG_OPCODE_NUMBER>(opcode);
return GetOpcodeNameForLoggingImpl(opcodeTable._internalTableClient, opcode);
}
std::string GetOpcodeNameForLogging(OpcodeServer opcode)
{
return GetOpcodeNameForLoggingImpl<MIN_SMSG_OPCODE_NUMBER, MAX_SMSG_OPCODE_NUMBER>(opcode);
return GetOpcodeNameForLoggingImpl(opcodeTable._internalTableServer, opcode);
}

File diff suppressed because it is too large Load Diff

View File

@@ -137,7 +137,7 @@ void PacketLog::LogPacket(WorldPacket const& packet, Direction direction, boost:
header.OptionalData.SocketPort = port;
std::size_t size = packet.size();
if (direction == CLIENT_TO_SERVER)
size -= 2;
size -= 4;
header.Length = size + sizeof(header.Opcode);
header.Opcode = packet.GetOpcode();
@@ -147,7 +147,7 @@ void PacketLog::LogPacket(WorldPacket const& packet, Direction direction, boost:
{
uint8 const* data = packet.contents();
if (direction == CLIENT_TO_SERVER)
data += 2;
data += 4;
fwrite(data, 1, size, _file);
}

View File

@@ -212,7 +212,7 @@ std::string WorldSession::GetPlayerInfo() const
/// Send a packet to the client
void WorldSession::SendPacket(WorldPacket const* packet, bool forced /*= false*/)
{
if (packet->GetOpcode() < MIN_SMSG_OPCODE_NUMBER || packet->GetOpcode() > MAX_SMSG_OPCODE_NUMBER)
if (!opcodeTable.IsValid(static_cast<OpcodeServer>(packet->GetOpcode())))
{
char const* specialName = packet->GetOpcode() == UNKNOWN_OPCODE ? "UNKNOWN_OPCODE" : "INVALID_OPCODE";
TC_LOG_ERROR("network.opcode", "Prevented sending of {} (0x{:04X}) to {}", specialName, packet->GetOpcode(), GetPlayerInfo());
@@ -1297,7 +1297,7 @@ bool WorldSession::DosProtection::EvaluateOpcode(WorldPacket& p, time_t time) co
}
}
uint32 WorldSession::DosProtection::GetMaxPacketCounterAllowed(uint16 opcode) const
uint32 WorldSession::DosProtection::GetMaxPacketCounterAllowed(uint32 opcode) const
{
uint32 maxPacketCounterAllowed;
switch (opcode)

View File

@@ -145,7 +145,6 @@ namespace WorldPackets
class AuctionPlaceBid;
class AuctionRemoveItem;
class AuctionReplicateItems;
class AuctionRequestFavoriteList;
class AuctionSellCommodity;
class AuctionSellItem;
class AuctionSetFavoriteItem;
@@ -1470,7 +1469,7 @@ class TC_GAME_API WorldSession
void HandleAuctionPlaceBid(WorldPackets::AuctionHouse::AuctionPlaceBid& placeBid);
void HandleAuctionRemoveItem(WorldPackets::AuctionHouse::AuctionRemoveItem& removeItem);
void HandleAuctionReplicateItems(WorldPackets::AuctionHouse::AuctionReplicateItems& replicateItems);
void HandleAuctionRequestFavoriteList(WorldPackets::AuctionHouse::AuctionRequestFavoriteList& requestFavoriteList);
void SendAuctionFavoriteList();
void HandleAuctionSellCommodity(WorldPackets::AuctionHouse::AuctionSellCommodity& sellCommodity);
void HandleAuctionSellItem(WorldPackets::AuctionHouse::AuctionSellItem& sellItem);
void HandleAuctionSetFavoriteItem(WorldPackets::AuctionHouse::AuctionSetFavoriteItem& setFavoriteItem);
@@ -1909,13 +1908,13 @@ class TC_GAME_API WorldSession
POLICY_BAN,
};
uint32 GetMaxPacketCounterAllowed(uint16 opcode) const;
uint32 GetMaxPacketCounterAllowed(uint32 opcode) const;
WorldSession* Session;
private:
Policy _policy;
typedef std::unordered_map<uint16, PacketCounter> PacketThrottlingMap;
typedef std::unordered_map<uint32, PacketCounter> PacketThrottlingMap;
// mark this member as "mutable" so it can be modified even in const functions
mutable PacketThrottlingMap _PacketThrottlingMap;

View File

@@ -331,7 +331,7 @@ bool WorldSocket::ReadHeaderHandler()
ASSERT(_headerBuffer.GetActiveSize() == sizeof(IncomingPacketHeader), "Header size " SZFMTD " different than expected " SZFMTD, _headerBuffer.GetActiveSize(), sizeof(IncomingPacketHeader));
IncomingPacketHeader* header = reinterpret_cast<IncomingPacketHeader*>(_headerBuffer.GetReadPointer());
uint16 encryptedOpcode = header->EncryptedOpcode;
uint32 encryptedOpcode = header->EncryptedOpcode;
if (!header->IsValidSize())
{
@@ -364,7 +364,7 @@ WorldSocket::ReadDataHandlerResult WorldSocket::ReadDataHandler()
WorldPacket packet(std::move(_packetBuffer), GetConnectionType());
OpcodeClient opcode = packet.read<OpcodeClient>();
if (opcode < MIN_CMSG_OPCODE_NUMBER || opcode > MAX_CMSG_OPCODE_NUMBER)
if (!opcodeTable.IsValid(opcode))
{
TC_LOG_ERROR("network", "WorldSocket::ReadHeaderHandler(): client {} sent wrong opcode (opcode: {})",
GetRemoteIpAddress().to_string(), uint32(opcode));
@@ -538,7 +538,7 @@ void WorldSocket::SendPacket(WorldPacket const& packet)
void WorldSocket::WritePacketToBuffer(EncryptablePacket const& packet, MessageBuffer& buffer)
{
uint16 opcode = packet.GetOpcode();
uint32 opcode = packet.GetOpcode();
uint32 packetSize = packet.size();
// Reserve space for buffer
@@ -550,8 +550,8 @@ void WorldSocket::WritePacketToBuffer(EncryptablePacket const& packet, MessageBu
if (packetSize > MinSizeForCompression && packet.NeedsEncryption())
{
CompressedWorldPacket cmp;
cmp.UncompressedSize = packetSize + 2;
cmp.UncompressedAdler = adler32(adler32(0x9827D8F1, (Bytef*)&opcode, 2), packet.contents(), packetSize);
cmp.UncompressedSize = packetSize + sizeof(opcode);
cmp.UncompressedAdler = adler32(adler32(0x9827D8F1, (Bytef*)&opcode, sizeof(opcode)), packet.contents(), packetSize);
// Reserve space for compression info - uncompressed size and checksums
uint8* compressionInfo = buffer.GetWritePointer();
@@ -571,7 +571,7 @@ void WorldSocket::WritePacketToBuffer(EncryptablePacket const& packet, MessageBu
buffer.Write(packet.contents(), packet.size());
memcpy(dataPos, &opcode, sizeof(opcode));
packetSize += 2 /*opcode*/;
packetSize += sizeof(opcode);
PacketHeader header;
header.Size = packetSize;
@@ -583,12 +583,12 @@ void WorldSocket::WritePacketToBuffer(EncryptablePacket const& packet, MessageBu
uint32 WorldSocket::CompressPacket(uint8* buffer, WorldPacket const& packet)
{
uint32 opcode = packet.GetOpcode();
uint32 bufferSize = deflateBound(_compressionStream, packet.size() + sizeof(uint16));
uint32 bufferSize = deflateBound(_compressionStream, packet.size() + sizeof(opcode));
_compressionStream->next_out = buffer;
_compressionStream->avail_out = bufferSize;
_compressionStream->next_in = (Bytef*)&opcode;
_compressionStream->avail_in = sizeof(uint16);
_compressionStream->avail_in = sizeof(opcode);
int32 z_res = deflate(_compressionStream, Z_NO_FLUSH);
if (z_res != Z_OK)

View File

@@ -40,7 +40,7 @@ class EncryptablePacket;
class WorldPacket;
class WorldSession;
enum ConnectionType : int8;
enum OpcodeClient : uint16;
enum OpcodeClient : uint32;
class EncryptablePacket : public WorldPacket
{
@@ -82,7 +82,7 @@ struct PacketHeader
struct IncomingPacketHeader : PacketHeader
{
uint16 EncryptedOpcode;
uint32 EncryptedOpcode;
};
#pragma pack(pop)