diff --git a/dChatServer/ChatPacketHandler.cpp b/dChatServer/ChatPacketHandler.cpp index 6e146745..f23c45e8 100644 --- a/dChatServer/ChatPacketHandler.cpp +++ b/dChatServer/ChatPacketHandler.cpp @@ -14,7 +14,6 @@ #include "eObjectBits.h" #include "eConnectionType.h" #include "eChatMessageType.h" -#include "eChatInternalMessageType.h" #include "eClientMessageType.h" #include "eGameMessageType.h" #include "StringifiedEnum.h" @@ -805,7 +804,7 @@ void ChatPacketHandler::SendTeamInviteConfirm(const PlayerData& receiver, bool b 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) { CBITSTREAM; BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, eChatMessageType::WORLD_ROUTE_PACKET); bitStream.Write(receiver.playerID); @@ -816,16 +815,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 def9c9b9..2cf5ea2f 100644 --- a/dChatServer/ChatPacketHandler.h +++ b/dChatServer/ChatPacketHandler.h @@ -67,7 +67,7 @@ namespace ChatPacketHandler { 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 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/ChatServer.cpp b/dChatServer/ChatServer.cpp index 87ea3cbe..db12e7d2 100644 --- a/dChatServer/ChatServer.cpp +++ b/dChatServer/ChatServer.cpp @@ -17,7 +17,6 @@ #include "PlayerContainer.h" #include "ChatPacketHandler.h" #include "eChatMessageType.h" -#include "eChatInternalMessageType.h" #include "eWorldMessageType.h" #include "ChatIgnoreList.h" #include "StringifiedEnum.h" @@ -190,42 +189,28 @@ void HandlePacket(Packet* packet) { if (packet->data[0] == ID_NEW_INCOMING_CONNECTION) { LOG("A server is connecting, awaiting user list."); } - if (packet->length < 4) return; // Nothing left to process. Need 4 bytes to continue. + CINSTREAM; + inStream.SetReadOffset(BYTES_TO_BITS(1)); - if (static_cast(packet->data[1]) == eConnectionType::CHAT_INTERNAL) { - switch (static_cast(packet->data[3])) { - case eChatInternalMessageType::PLAYER_ADDED_NOTIFICATION: - Game::playerContainer.InsertPlayer(packet); - break; + eConnectionType connection; + eChatMessageType chatMessageID; - case eChatInternalMessageType::PLAYER_REMOVED_NOTIFICATION: - Game::playerContainer.RemovePlayer(packet); - break; + inStream.Read(connection); + inStream.Read(chatMessageID); + inStream.SetReadOffset(BYTES_TO_BITS(HEADER_SIZE)); - case eChatInternalMessageType::MUTE_UPDATE: + switch (chatMessageID) { + case eChatMessageType::GM_MUTE: + // verif internal Game::playerContainer.MuteUpdate(packet); break; - case eChatInternalMessageType::CREATE_TEAM: + case eChatMessageType::CREATE_TEAM: + // verif internal Game::playerContainer.CreateTeamServer(packet); break; - case eChatInternalMessageType::ANNOUNCEMENT: { - //we just forward this packet to every connected server - CINSTREAM; - Game::server->Send(&inStream, packet->systemAddress, true); //send to everyone except origin - break; - } - - default: - LOG("Unknown CHAT_INTERNAL id: %i", int(packet->data[3])); - } - } - - if (static_cast(packet->data[1]) == eConnectionType::CHAT) { - eChatMessageType chat_message_type = static_cast(packet->data[3]); - switch (chat_message_type) { case eChatMessageType::GET_FRIENDS_LIST: ChatPacketHandler::HandleFriendlistRequest(packet); break; @@ -296,15 +281,32 @@ void HandlePacket(Packet* packet) { ChatPacketHandler::HandleTeamLootOption(packet); break; case eChatMessageType::GMLEVEL_UPDATE: + // verify internal ChatPacketHandler::HandleGMLevelUpdate(packet); break; case eChatMessageType::WHO: + // verify internal ChatPacketHandler::HandleWho(packet); break; case eChatMessageType::SHOW_ALL: + // verify internal ChatPacketHandler::HandleShowAll(packet); break; case eChatMessageType::LOGIN_SESSION_NOTIFY: + // verify internal + Game::playerContainer.InsertPlayer(packet); + break; + case eChatMessageType::GM_ANNOUNCE:{ + // verify internal + //we just forward this packet to every connected server + CINSTREAM; + Game::server->Send(&inStream, packet->systemAddress, true); //send to everyone except origin + } + break; + case eChatMessageType::UNEXPECTED_DISCONNECT: + // verify internal + Game::playerContainer.RemovePlayer(packet); + break; case eChatMessageType::USER_CHANNEL_CHAT_MESSAGE: case eChatMessageType::WORLD_DISCONNECT_REQUEST: case eChatMessageType::WORLD_PROXIMITY_RESPONSE: @@ -331,7 +333,6 @@ void HandlePacket(Packet* packet) { case eChatMessageType::CSR_REQUEST: case eChatMessageType::CSR_REPLY: case eChatMessageType::GM_KICK: - case eChatMessageType::GM_ANNOUNCE: case eChatMessageType::WORLD_ROUTE_PACKET: case eChatMessageType::GET_ZONE_POPULATIONS: case eChatMessageType::REQUEST_MINIMUM_CHAT_MODE: @@ -343,7 +344,6 @@ void HandlePacket(Packet* packet) { case eChatMessageType::WORLD_PLAYERS_PET_MODERATED_ACKNOWLEDGE: case eChatMessageType::ACHIEVEMENT_NOTIFY: case eChatMessageType::GM_CLOSE_PRIVATE_CHAT_WINDOW: - case eChatMessageType::UNEXPECTED_DISCONNECT: case eChatMessageType::PLAYER_READY: case eChatMessageType::GET_DONATION_TOTAL: case eChatMessageType::UPDATE_DONATION: diff --git a/dChatServer/PlayerContainer.cpp b/dChatServer/PlayerContainer.cpp index fe0eb789..83a198b1 100644 --- a/dChatServer/PlayerContainer.cpp +++ b/dChatServer/PlayerContainer.cpp @@ -9,7 +9,6 @@ #include "BitStreamUtils.h" #include "Database.h" #include "eConnectionType.h" -#include "eChatInternalMessageType.h" #include "eGameMasterLevel.h" #include "ChatPackets.h" #include "dConfig.h" @@ -154,7 +153,7 @@ void PlayerContainer::CreateTeamServer(Packet* packet) { void PlayerContainer::BroadcastMuteUpdate(LWOOBJID player, time_t time) { CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::MUTE_UPDATE); + BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatMessageType::GM_MUTE); bitStream.Write(player); bitStream.Write(time); @@ -337,22 +336,18 @@ void PlayerContainer::DisbandTeam(TeamData* team) { void PlayerContainer::TeamStatusUpdate(TeamData* team) { const auto index = std::find(mTeams.begin(), mTeams.end(), team); - if (index == mTeams.end()) return; - const auto& leader = GetPlayerData(team->leaderID); - - if (!leader) return; - - const auto leaderName = GeneralUtils::UTF8ToUTF16(leader.playerName); - for (const auto memberId : team->memberIDs) { - const auto& otherMember = GetPlayerData(memberId); - - if (!otherMember) continue; - + const auto& member = GetPlayerData(memberId); + if (!member) { + RemoveMember(team, memberId, false, false, false, true); + } + } + for (const auto memberId : team->memberIDs) { + const auto& member = GetPlayerData(memberId); if (!team->local) { - ChatPacketHandler::SendTeamStatus(otherMember, team->leaderID, leader.zoneID, team->lootFlag, 0, leaderName); + ChatPacketHandler::SendTeamStatus(member, team); } } @@ -361,7 +356,7 @@ void PlayerContainer::TeamStatusUpdate(TeamData* team) { void PlayerContainer::UpdateTeamsOnWorld(TeamData* team, bool deleteTeam) { CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::TEAM_UPDATE); + BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatMessageType::TEAM_GET_STATUS); bitStream.Write(team->teamID); bitStream.Write(deleteTeam); diff --git a/dCommon/dEnums/eChatInternalMessageType.h b/dCommon/dEnums/eChatInternalMessageType.h deleted file mode 100644 index d3b7020b..00000000 --- a/dCommon/dEnums/eChatInternalMessageType.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef __ECHATINTERNALMESSAGETYPE__H__ -#define __ECHATINTERNALMESSAGETYPE__H__ - -#include - -enum eChatInternalMessageType : uint32_t { - PLAYER_ADDED_NOTIFICATION = 0, - PLAYER_REMOVED_NOTIFICATION, - ADD_FRIEND, - ADD_BEST_FRIEND, - ADD_TO_TEAM, - ADD_BLOCK, - REMOVE_FRIEND, - REMOVE_BLOCK, - REMOVE_FROM_TEAM, - DELETE_TEAM, - REPORT, - PRIVATE_CHAT, - PRIVATE_CHAT_RESPONSE, - ANNOUNCEMENT, - MAIL_COUNT_UPDATE, - MAIL_SEND_NOTIFY, - REQUEST_USER_LIST, - FRIEND_LIST, - ROUTE_TO_PLAYER, - TEAM_UPDATE, - MUTE_UPDATE, - CREATE_TEAM, -}; - -#endif //!__ECHATINTERNALMESSAGETYPE__H__ diff --git a/dCommon/dEnums/eChatMessageType.h b/dCommon/dEnums/eChatMessageType.h index 52895ba3..30250272 100644 --- a/dCommon/dEnums/eChatMessageType.h +++ b/dCommon/dEnums/eChatMessageType.h @@ -72,7 +72,8 @@ enum class eChatMessageType :uint32_t { UPDATE_DONATION, PRG_CSR_COMMAND, HEARTBEAT_REQUEST_FROM_WORLD, - UPDATE_FREE_TRIAL_STATUS + UPDATE_FREE_TRIAL_STATUS, + // CUSTOM DLU MESSAGE ID FOR INTERNAL USE }; #endif //!__ECHATMESSAGETYPE__H__ diff --git a/dGame/Entity.cpp b/dGame/Entity.cpp index 8b72a80c..3c76a97c 100644 --- a/dGame/Entity.cpp +++ b/dGame/Entity.cpp @@ -867,7 +867,7 @@ void Entity::SetGMLevel(eGameMasterLevel value) { // Update the chat server of our GM Level { CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, eChatMessageType::GMLEVEL_UPDATE); + BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatMessageType::GMLEVEL_UPDATE); bitStream.Write(m_ObjectID); bitStream.Write(m_GMLevel); diff --git a/dGame/UserManager.cpp b/dGame/UserManager.cpp index fc582108..97ceced1 100644 --- a/dGame/UserManager.cpp +++ b/dGame/UserManager.cpp @@ -26,7 +26,7 @@ #include "eCharacterCreationResponse.h" #include "eRenameResponse.h" #include "eConnectionType.h" -#include "eChatInternalMessageType.h" +#include "eChatMessageType.h" #include "BitStreamUtils.h" #include "CheatDetection.h" @@ -413,7 +413,7 @@ void UserManager::DeleteCharacter(const SystemAddress& sysAddr, Packet* packet) Database::Get()->DeleteCharacter(charID); CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::PLAYER_REMOVED_NOTIFICATION); + BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatMessageType::UNEXPECTED_DISCONNECT); bitStream.Write(objectID); Game::chatServer->Send(&bitStream, SYSTEM_PRIORITY, RELIABLE, 0, Game::chatSysAddr, false); diff --git a/dGame/dComponents/ActivityComponent.cpp b/dGame/dComponents/ActivityComponent.cpp index aa6a4604..e0cd7895 100644 --- a/dGame/dComponents/ActivityComponent.cpp +++ b/dGame/dComponents/ActivityComponent.cpp @@ -22,7 +22,6 @@ #include "eMissionTaskType.h" #include "eMatchUpdate.h" #include "eConnectionType.h" -#include "eChatInternalMessageType.h" #include "CDCurrencyTableTable.h" #include "CDActivityRewardsTable.h" @@ -501,7 +500,7 @@ void ActivityInstance::StartZone() { // only make a team if we have more than one participant if (participants.size() > 1) { CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::CREATE_TEAM); + BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatMessageType::CREATE_TEAM); bitStream.Write(leader->GetObjectID()); bitStream.Write(m_Participants.size()); diff --git a/dGame/dUtilities/SlashCommandHandler.cpp b/dGame/dUtilities/SlashCommandHandler.cpp index 5e045653..7c1a4867 100644 --- a/dGame/dUtilities/SlashCommandHandler.cpp +++ b/dGame/dUtilities/SlashCommandHandler.cpp @@ -80,7 +80,6 @@ #include "RenderComponent.h" #include "eControlScheme.h" #include "eConnectionType.h" -#include "eChatInternalMessageType.h" #include "eChatMessageType.h" #include "eMasterMessageType.h" #include "PlayerManager.h" @@ -1079,7 +1078,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit //Notify chat about it CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::MUTE_UPDATE); + BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatMessageType::GM_MUTE); bitStream.Write(characterId); bitStream.Write(expire); @@ -2115,7 +2114,7 @@ void SlashCommandHandler::SendAnnouncement(const std::string& title, const std:: //Notify chat about it CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ANNOUNCEMENT); + BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatMessageType::GM_ANNOUNCE); bitStream.Write(title.size()); for (auto character : title) { diff --git a/dWorldServer/WorldServer.cpp b/dWorldServer/WorldServer.cpp index 42d135e1..2ebb64ec 100644 --- a/dWorldServer/WorldServer.cpp +++ b/dWorldServer/WorldServer.cpp @@ -67,7 +67,6 @@ #include "eObjectBits.h" #include "eConnectionType.h" #include "eServerMessageType.h" -#include "eChatInternalMessageType.h" #include "eChatMessageType.h" #include "eWorldMessageType.h" #include "eMasterMessageType.h" @@ -545,8 +544,8 @@ void HandlePacketChat(Packet* packet) { if (packet->data[0] == ID_USER_PACKET_ENUM) { if (static_cast(packet->data[1]) == eConnectionType::CHAT_INTERNAL) { - switch (static_cast(packet->data[3])) { - case eChatInternalMessageType::ANNOUNCEMENT: { + switch (static_cast(packet->data[3])) { + case eChatMessageType::GM_ANNOUNCE: { CINSTREAM_SKIP_HEADER; std::string title; @@ -579,7 +578,7 @@ void HandlePacketChat(Packet* packet) { break; } - case eChatInternalMessageType::MUTE_UPDATE: { + case eChatMessageType::GM_MUTE: { CINSTREAM_SKIP_HEADER; LWOOBJID playerId; time_t expire = 0; @@ -597,7 +596,7 @@ void HandlePacketChat(Packet* packet) { break; } - case eChatInternalMessageType::TEAM_UPDATE: { + case eChatMessageType::TEAM_GET_STATUS: { CINSTREAM_SKIP_HEADER; LWOOBJID teamID = 0; @@ -822,7 +821,7 @@ void HandlePacket(Packet* packet) { { CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::PLAYER_REMOVED_NOTIFICATION); + BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatMessageType::PLAYER_REMOVED_NOTIFICATION); bitStream.Write(user->GetLoggedInChar()); Game::chatServer->Send(&bitStream, SYSTEM_PRIORITY, RELIABLE, 0, Game::chatSysAddr, false); } @@ -973,7 +972,7 @@ void HandlePacket(Packet* packet) { // This means we swapped characters and we need to remove the previous player from the container. if (static_cast(lastCharacter) != playerID) { CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::PLAYER_REMOVED_NOTIFICATION); + BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatMessageType::PLAYER_REMOVED_NOTIFICATION); bitStream.Write(lastCharacter); Game::chatServer->Send(&bitStream, SYSTEM_PRIORITY, RELIABLE, 0, Game::chatSysAddr, false); } @@ -1118,7 +1117,7 @@ void HandlePacket(Packet* packet) { //RakNet::RakString playerName(player->GetCharacter()->GetName().c_str()); CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::PLAYER_ADDED_NOTIFICATION); + BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatMessageType::PLAYER_ADDED_NOTIFICATION); bitStream.Write(player->GetObjectID()); bitStream.Write(playerName.size()); for (size_t i = 0; i < playerName.size(); i++) {