From 938bcd258d6e52792b57b382c329b77d766e99b6 Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Sun, 24 Mar 2024 22:29:57 -0500 Subject: [PATCH] fix: use team data in packets where applicaable --- dChatServer/ChatPacketHandler.cpp | 63 ++++++++++++++++++++----------- dChatServer/ChatPacketHandler.h | 5 ++- dChatServer/PlayerContainer.cpp | 4 +- 3 files changed, 46 insertions(+), 26 deletions(-) diff --git a/dChatServer/ChatPacketHandler.cpp b/dChatServer/ChatPacketHandler.cpp index 5e2e58d7..71873921 100644 --- a/dChatServer/ChatPacketHandler.cpp +++ b/dChatServer/ChatPacketHandler.cpp @@ -709,7 +709,9 @@ void ChatPacketHandler::SendTeamInvite(const PlayerData& receiver, const PlayerD SEND_PACKET; } -void ChatPacketHandler::SendTeamInviteConfirm(const PlayerData& receiver, bool bLeaderIsFreeTrial, LWOOBJID i64LeaderID, LWOZONEID i64LeaderZoneID, uint8_t ucLootFlag, uint8_t ucNumOfOtherPlayers, uint8_t ucResponseCode, std::u16string wsLeaderName) { +void ChatPacketHandler::SendTeamInviteConfirm(const PlayerData& receiver, TeamData* team, uint8_t responseCode) { + if(!team) return; + CBITSTREAM; BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER); bitStream.Write(receiver.playerID); @@ -720,25 +722,35 @@ void ChatPacketHandler::SendTeamInviteConfirm(const PlayerData& receiver, bool b bitStream.Write(receiver.playerID); bitStream.Write(eGameMessageType::TEAM_INVITE_CONFIRM); - bitStream.Write(bLeaderIsFreeTrial); - bitStream.Write(i64LeaderID); - bitStream.Write(i64LeaderZoneID); - bitStream.Write(0); // BinaryBuffe, no clue what's in here - bitStream.Write(ucLootFlag); - bitStream.Write(ucNumOfOtherPlayers); - bitStream.Write(ucResponseCode); - bitStream.Write(wsLeaderName.size()); - for (const auto character : wsLeaderName) { - bitStream.Write(character); + bitStream.Write(false); // bLeaderIsFreeTrial + bitStream.Write(team->leaderID); + const auto& leader = Game::playerContainer.GetPlayerData(team->leaderID); + + bitStream.Write(leader.zoneID); + bitStream.Write((team->memberIDs.size() - 1) * ((sizeof(int16_t) * 33) + sizeof(LWOOBJID) + sizeof(LWOZONEID))); + for (const auto memberid: team->memberIDs){ + if (memberid == team->leaderID) continue; + const auto& member = Game::playerContainer.GetPlayerData(memberid); + bitStream.Write(LUWString(member.playerName)); + bitStream.Write(memberid); + bitStream.Write(member.zoneID); } + bitStream.Write(team->lootFlag); + bitStream.Write(team->memberIDs.size()); + bitStream.Write(0); // ucResponseCode + const std::u16string wsLeaderName = GeneralUtils::UTF8ToUTF16(leader.playerName); + bitStream.Write(wsLeaderName.size()); + bitStream.Write(wsLeaderName); SystemAddress sysAddr = receiver.sysAddr; SEND_PACKET; } -void ChatPacketHandler::SendTeamStatus(const PlayerData& receiver, LWOOBJID i64LeaderID, LWOZONEID i64LeaderZoneID, uint8_t ucLootFlag, uint8_t ucNumOfOtherPlayers, std::u16string wsLeaderName) { +void ChatPacketHandler::SendTeamStatus(const PlayerData& receiver, TeamData* team) { + if(!team) return; + CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER); + BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, eChatMessageType::WORLD_ROUTE_PACKET); bitStream.Write(receiver.playerID); //portion that will get routed: @@ -747,16 +759,23 @@ void ChatPacketHandler::SendTeamStatus(const PlayerData& receiver, LWOOBJID i64L bitStream.Write(receiver.playerID); bitStream.Write(eGameMessageType::TEAM_GET_STATUS_RESPONSE); - bitStream.Write(i64LeaderID); - bitStream.Write(i64LeaderZoneID); - bitStream.Write(0); // BinaryBuffe, no clue what's in here - bitStream.Write(ucLootFlag); - bitStream.Write(ucNumOfOtherPlayers); - bitStream.Write(wsLeaderName.size()); - for (const auto character : wsLeaderName) { - bitStream.Write(character); - } + bitStream.Write(team->leaderID); + const auto& leader = Game::playerContainer.GetPlayerData(team->leaderID); + bitStream.Write(leader.zoneID); + bitStream.Write((team->memberIDs.size() - 1) * ((sizeof(int16_t) * 33) + sizeof(LWOOBJID) + sizeof(LWOZONEID))); + for (const auto memberid: team->memberIDs){ + if (memberid == team->leaderID) continue; + const auto& member = Game::playerContainer.GetPlayerData(memberid); + bitStream.Write(LUWString(member.playerName)); + bitStream.Write(memberid); + bitStream.Write(member.zoneID); + } + bitStream.Write(team->lootFlag); + bitStream.Write(team->memberIDs.size()); + const std::u16string wsLeaderName = GeneralUtils::UTF8ToUTF16(leader.playerName); + bitStream.Write(wsLeaderName.size()); + bitStream.Write(wsLeaderName); SystemAddress sysAddr = receiver.sysAddr; SEND_PACKET; } diff --git a/dChatServer/ChatPacketHandler.h b/dChatServer/ChatPacketHandler.h index 847fc899..41c1d8ca 100644 --- a/dChatServer/ChatPacketHandler.h +++ b/dChatServer/ChatPacketHandler.h @@ -4,6 +4,7 @@ #include "BitStream.h" struct PlayerData; +struct TeamData; enum class eAddFriendResponseType : uint8_t; @@ -64,8 +65,8 @@ namespace ChatPacketHandler { void HandleTeamStatusRequest(Packet* packet); void SendTeamInvite(const PlayerData& receiver, const PlayerData& sender); - void SendTeamInviteConfirm(const PlayerData& receiver, bool bLeaderIsFreeTrial, LWOOBJID i64LeaderID, LWOZONEID i64LeaderZoneID, uint8_t ucLootFlag, uint8_t ucNumOfOtherPlayers, uint8_t ucResponseCode, std::u16string wsLeaderName); - void SendTeamStatus(const PlayerData& receiver, LWOOBJID i64LeaderID, LWOZONEID i64LeaderZoneID, uint8_t ucLootFlag, uint8_t ucNumOfOtherPlayers, std::u16string wsLeaderName); + void SendTeamInviteConfirm(const PlayerData& receiver, TeamData* team, uint8_t responseCode); + void SendTeamStatus(const PlayerData& receiver, TeamData* team); void SendTeamSetLeader(const PlayerData& receiver, LWOOBJID i64PlayerID); void SendTeamAddPlayer(const PlayerData& receiver, bool bIsFreeTrial, bool bLocal, bool bNoLootOnDeath, LWOOBJID i64PlayerID, std::u16string wsPlayerName, LWOZONEID zoneID); void SendTeamRemovePlayer(const PlayerData& receiver, bool bDisband, bool bIsKicked, bool bIsLeaving, bool bLocal, LWOOBJID i64LeaderID, LWOOBJID i64PlayerID, std::u16string wsPlayerName); diff --git a/dChatServer/PlayerContainer.cpp b/dChatServer/PlayerContainer.cpp index 4e4d1be5..b5ce667f 100644 --- a/dChatServer/PlayerContainer.cpp +++ b/dChatServer/PlayerContainer.cpp @@ -228,7 +228,7 @@ void PlayerContainer::AddMember(TeamData* team, LWOOBJID playerID) { const auto leaderName = GeneralUtils::UTF8ToUTF16(leader.playerName); const auto memberName = GeneralUtils::UTF8ToUTF16(member.playerName); - ChatPacketHandler::SendTeamInviteConfirm(member, false, leader.playerID, leader.zoneID, team->lootFlag, 0, 0, leaderName); + ChatPacketHandler::SendTeamInviteConfirm(member, team, 0); if (!team->local) { ChatPacketHandler::SendTeamSetLeader(member, leader.playerID); @@ -343,7 +343,7 @@ void PlayerContainer::TeamStatusUpdate(TeamData* team) { if (!otherMember) continue; if (!team->local) { - ChatPacketHandler::SendTeamStatus(otherMember, team->leaderID, leader.zoneID, team->lootFlag, 0, leaderName); + ChatPacketHandler::SendTeamStatus(otherMember, team); } }