From 20408d8dfea510bb8a3e94bf8d0f825616940341 Mon Sep 17 00:00:00 2001 From: Aaron Kimbrell Date: Sun, 31 Mar 2024 22:27:50 -0500 Subject: [PATCH 1/6] chore: remove chat_internal and processes everything over chat connection (#1508) * WIP * get rid of redundent case and some formatting issues * move some things around for cleaner diffs * remove dead code that does nothing and add connection check * fix whitespace * address feedback --- dChatServer/ChatIgnoreList.cpp | 4 +- dChatServer/ChatPacketHandler.cpp | 27 ++- dChatServer/ChatServer.cpp | 79 ++++----- dChatServer/PlayerContainer.cpp | 6 +- dCommon/dEnums/eChatInternalMessageType.h | 31 ---- dCommon/dEnums/eChatMessageType.h | 4 +- dCommon/dEnums/eConnectionType.h | 3 +- dGame/UserManager.cpp | 4 +- dGame/dComponents/ActivityComponent.cpp | 4 +- dGame/dUtilities/SlashCommandHandler.cpp | 6 +- dWorldServer/WorldServer.cpp | 190 +++++++++++----------- 11 files changed, 151 insertions(+), 207 deletions(-) delete mode 100644 dCommon/dEnums/eChatInternalMessageType.h diff --git a/dChatServer/ChatIgnoreList.cpp b/dChatServer/ChatIgnoreList.cpp index f0c55eb0..6dfbd7fc 100644 --- a/dChatServer/ChatIgnoreList.cpp +++ b/dChatServer/ChatIgnoreList.cpp @@ -1,6 +1,6 @@ #include "ChatIgnoreList.h" #include "PlayerContainer.h" -#include "eChatInternalMessageType.h" +#include "eChatMessageType.h" #include "BitStreamUtils.h" #include "Game.h" #include "Logger.h" @@ -13,7 +13,7 @@ // The only thing not auto-handled is instance activities force joining the team on the server. void WriteOutgoingReplyHeader(RakNet::BitStream& bitStream, const LWOOBJID& receivingPlayer, const ChatIgnoreList::Response type) { - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER); + BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, eChatMessageType::WORLD_ROUTE_PACKET); bitStream.Write(receivingPlayer); //portion that will get routed: diff --git a/dChatServer/ChatPacketHandler.cpp b/dChatServer/ChatPacketHandler.cpp index 5e2e58d7..d37777b6 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" @@ -60,7 +59,7 @@ void ChatPacketHandler::HandleFriendlistRequest(Packet* packet) { //Now, we need to send the friendlist to the server they came from: CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER); + BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, eChatMessageType::WORLD_ROUTE_PACKET); bitStream.Write(playerID); //portion that will get routed: @@ -454,7 +453,7 @@ void ChatPacketHandler::HandlePrivateChatMessage(Packet* packet) { void ChatPacketHandler::SendPrivateChatMessage(const PlayerData& sender, const PlayerData& receiver, const PlayerData& routeTo, const LUWString& message, const eChatChannel channel, const eChatMessageResponseCode responseCode) { CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER); + BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, eChatMessageType::WORLD_ROUTE_PACKET); bitStream.Write(routeTo.playerID); BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, eChatMessageType::PRIVATE_CHAT_MESSAGE); @@ -696,7 +695,7 @@ void ChatPacketHandler::HandleTeamStatusRequest(Packet* packet) { void ChatPacketHandler::SendTeamInvite(const PlayerData& receiver, const PlayerData& sender) { 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: @@ -711,7 +710,7 @@ void ChatPacketHandler::SendTeamInvite(const PlayerData& receiver, const PlayerD void ChatPacketHandler::SendTeamInviteConfirm(const PlayerData& receiver, bool bLeaderIsFreeTrial, LWOOBJID i64LeaderID, LWOZONEID i64LeaderZoneID, uint8_t ucLootFlag, uint8_t ucNumOfOtherPlayers, uint8_t ucResponseCode, std::u16string wsLeaderName) { 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: @@ -738,7 +737,7 @@ void ChatPacketHandler::SendTeamInviteConfirm(const PlayerData& receiver, bool b void ChatPacketHandler::SendTeamStatus(const PlayerData& receiver, LWOOBJID i64LeaderID, LWOZONEID i64LeaderZoneID, uint8_t ucLootFlag, uint8_t ucNumOfOtherPlayers, std::u16string wsLeaderName) { 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: @@ -763,7 +762,7 @@ void ChatPacketHandler::SendTeamStatus(const PlayerData& receiver, LWOOBJID i64L void ChatPacketHandler::SendTeamSetLeader(const PlayerData& receiver, LWOOBJID i64PlayerID) { 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: @@ -780,7 +779,7 @@ void ChatPacketHandler::SendTeamSetLeader(const PlayerData& receiver, LWOOBJID i void ChatPacketHandler::SendTeamAddPlayer(const PlayerData& receiver, bool bIsFreeTrial, bool bLocal, bool bNoLootOnDeath, LWOOBJID i64PlayerID, std::u16string wsPlayerName, LWOZONEID zoneID) { 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: @@ -809,7 +808,7 @@ void ChatPacketHandler::SendTeamAddPlayer(const PlayerData& receiver, bool bIsFr void ChatPacketHandler::SendTeamRemovePlayer(const PlayerData& receiver, bool bDisband, bool bIsKicked, bool bIsLeaving, bool bLocal, LWOOBJID i64LeaderID, LWOOBJID i64PlayerID, std::u16string wsPlayerName) { 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: @@ -835,7 +834,7 @@ void ChatPacketHandler::SendTeamRemovePlayer(const PlayerData& receiver, bool bD void ChatPacketHandler::SendTeamSetOffWorldFlag(const PlayerData& receiver, LWOOBJID i64PlayerID, LWOZONEID zoneID) { 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: @@ -869,7 +868,7 @@ void ChatPacketHandler::SendFriendUpdate(const PlayerData& friendData, const Pla [bool] - is FTP*/ CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER); + BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, eChatMessageType::WORLD_ROUTE_PACKET); bitStream.Write(friendData.playerID); //portion that will get routed: @@ -906,7 +905,7 @@ void ChatPacketHandler::SendFriendRequest(const PlayerData& receiver, const Play } 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: @@ -920,7 +919,7 @@ void ChatPacketHandler::SendFriendRequest(const PlayerData& receiver, const Play void ChatPacketHandler::SendFriendResponse(const PlayerData& receiver, const PlayerData& sender, eAddFriendResponseType responseCode, uint8_t isBestFriendsAlready, uint8_t isBestFriendRequest) { 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: @@ -943,7 +942,7 @@ void ChatPacketHandler::SendFriendResponse(const PlayerData& receiver, const Pla void ChatPacketHandler::SendRemoveFriend(const PlayerData& receiver, std::string& personToRemove, bool isSuccessful) { 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: diff --git a/dChatServer/ChatServer.cpp b/dChatServer/ChatServer.cpp index 84104726..cc938c3c 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" @@ -182,47 +181,29 @@ int main(int argc, char** argv) { void HandlePacket(Packet* packet) { if (packet->data[0] == ID_DISCONNECTION_NOTIFICATION || packet->data[0] == ID_CONNECTION_LOST) { LOG("A server has disconnected, erasing their connected players from the list."); - } - - if (packet->data[0] == ID_NEW_INCOMING_CONNECTION) { + } else if (packet->data[0] == ID_NEW_INCOMING_CONNECTION) { LOG("A server is connecting, awaiting user list."); - } + } else if (packet->length < 4 || packet->data[0] != ID_USER_PACKET_ENUM) return; // Nothing left to process or not the right packet type - 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; - - case eChatInternalMessageType::MUTE_UPDATE: + inStream.Read(connection); + if (connection != eConnectionType::CHAT) return; + inStream.Read(chatMessageID); + + switch (chatMessageID) { + case eChatMessageType::GM_MUTE: Game::playerContainer.MuteUpdate(packet); break; - case eChatInternalMessageType::CREATE_TEAM: + case eChatMessageType::CREATE_TEAM: 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,6 +277,19 @@ void HandlePacket(Packet* packet) { ChatPacketHandler::HandleGMLevelUpdate(packet); break; case eChatMessageType::LOGIN_SESSION_NOTIFY: + Game::playerContainer.InsertPlayer(packet); + break; + case eChatMessageType::GM_ANNOUNCE:{ + // we just forward this packet to every connected server + inStream.ResetReadPointer(); + Game::server->Send(inStream, packet->systemAddress, true); // send to everyone except origin + } + break; + case eChatMessageType::UNEXPECTED_DISCONNECT: + Game::playerContainer.RemovePlayer(packet); + break; + case eChatMessageType::WHO: + case eChatMessageType::SHOW_ALL: case eChatMessageType::USER_CHANNEL_CHAT_MESSAGE: case eChatMessageType::WORLD_DISCONNECT_REQUEST: case eChatMessageType::WORLD_PROXIMITY_RESPONSE: @@ -308,7 +302,6 @@ void HandlePacket(Packet* packet) { case eChatMessageType::GUILD_KICK: case eChatMessageType::GUILD_GET_STATUS: case eChatMessageType::GUILD_GET_ALL: - case eChatMessageType::SHOW_ALL: case eChatMessageType::BLUEPRINT_MODERATED: case eChatMessageType::BLUEPRINT_MODEL_READY: case eChatMessageType::PROPERTY_READY_FOR_APPROVAL: @@ -323,7 +316,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: @@ -332,33 +324,18 @@ void HandlePacket(Packet* packet) { case eChatMessageType::UGCMANIFEST_REPORT_DONE_FILE: case eChatMessageType::UGCMANIFEST_REPORT_DONE_BLUEPRINT: case eChatMessageType::UGCC_REQUEST: - case eChatMessageType::WHO: 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: case eChatMessageType::PRG_CSR_COMMAND: case eChatMessageType::HEARTBEAT_REQUEST_FROM_WORLD: case eChatMessageType::UPDATE_FREE_TRIAL_STATUS: - LOG("Unhandled CHAT Message id: %s (%i)", StringifiedEnum::ToString(chat_message_type).data(), chat_message_type); + LOG("Unhandled CHAT Message id: %s (%i)", StringifiedEnum::ToString(chatMessageID).data(), chatMessageID); break; default: - LOG("Unknown CHAT Message id: %i", chat_message_type); - } - } - - if (static_cast(packet->data[1]) == eConnectionType::WORLD) { - switch (static_cast(packet->data[3])) { - case eWorldMessageType::ROUTE_PACKET: { - LOG("Routing packet from world"); - break; - } - - default: - LOG("Unknown World id: %i", int(packet->data[3])); - } + LOG("Unknown CHAT Message id: %i", chatMessageID); } } diff --git a/dChatServer/PlayerContainer.cpp b/dChatServer/PlayerContainer.cpp index 7feff763..57b3f233 100644 --- a/dChatServer/PlayerContainer.cpp +++ b/dChatServer/PlayerContainer.cpp @@ -9,9 +9,9 @@ #include "BitStreamUtils.h" #include "Database.h" #include "eConnectionType.h" -#include "eChatInternalMessageType.h" #include "ChatPackets.h" #include "dConfig.h" +#include "eChatMessageType.h" void PlayerContainer::Initialize() { m_MaxNumberOfBestFriends = @@ -145,7 +145,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, eChatMessageType::GM_MUTE); bitStream.Write(player); bitStream.Write(time); @@ -352,7 +352,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, 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..38cd86de 100644 --- a/dCommon/dEnums/eChatMessageType.h +++ b/dCommon/dEnums/eChatMessageType.h @@ -72,7 +72,9 @@ 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 + CREATE_TEAM, }; #endif //!__ECHATMESSAGETYPE__H__ diff --git a/dCommon/dEnums/eConnectionType.h b/dCommon/dEnums/eConnectionType.h index ce1ff90c..406110a9 100644 --- a/dCommon/dEnums/eConnectionType.h +++ b/dCommon/dEnums/eConnectionType.h @@ -5,8 +5,7 @@ enum class eConnectionType : uint16_t { SERVER = 0, AUTH, CHAT, - CHAT_INTERNAL, - WORLD, + WORLD = 4, CLIENT, MASTER }; diff --git a/dGame/UserManager.cpp b/dGame/UserManager.cpp index 0fde2eb6..b94e9de5 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" @@ -422,7 +422,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, 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 ce82abe0..1b2fc338 100644 --- a/dGame/dComponents/ActivityComponent.cpp +++ b/dGame/dComponents/ActivityComponent.cpp @@ -21,7 +21,7 @@ #include "eMissionTaskType.h" #include "eMatchUpdate.h" #include "eConnectionType.h" -#include "eChatInternalMessageType.h" +#include "eChatMessageType.h" #include "CDCurrencyTableTable.h" #include "CDActivityRewardsTable.h" @@ -501,7 +501,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, 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 d0620121..0b26e85a 100644 --- a/dGame/dUtilities/SlashCommandHandler.cpp +++ b/dGame/dUtilities/SlashCommandHandler.cpp @@ -79,7 +79,7 @@ #include "RenderComponent.h" #include "eControlScheme.h" #include "eConnectionType.h" -#include "eChatInternalMessageType.h" +#include "eChatMessageType.h" #include "eMasterMessageType.h" #include "PlayerManager.h" @@ -1063,7 +1063,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, eChatMessageType::GM_MUTE); bitStream.Write(characterId); bitStream.Write(expire); @@ -2078,7 +2078,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, eChatMessageType::GM_ANNOUNCE); bitStream.Write(title.size()); for (auto character : title) { diff --git a/dWorldServer/WorldServer.cpp b/dWorldServer/WorldServer.cpp index 5f7a8b3e..1c85ef22 100644 --- a/dWorldServer/WorldServer.cpp +++ b/dWorldServer/WorldServer.cpp @@ -66,7 +66,7 @@ #include "eObjectBits.h" #include "eConnectionType.h" #include "eServerMessageType.h" -#include "eChatInternalMessageType.h" +#include "eChatMessageType.h" #include "eWorldMessageType.h" #include "eMasterMessageType.h" #include "eGameMessageType.h" @@ -541,118 +541,116 @@ 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::ROUTE_TO_PLAYER: { - CINSTREAM_SKIP_HEADER; - LWOOBJID playerID; - inStream.Read(playerID); + if (static_cast(packet->data[1]) == eConnectionType::CHAT) { + switch (static_cast(packet->data[3])) { + case eChatMessageType::WORLD_ROUTE_PACKET: { + CINSTREAM_SKIP_HEADER; + LWOOBJID playerID; + inStream.Read(playerID); - auto player = Game::entityManager->GetEntity(playerID); - if (!player) return; + auto player = Game::entityManager->GetEntity(playerID); + if (!player) return; - auto sysAddr = player->GetSystemAddress(); + auto sysAddr = player->GetSystemAddress(); - //Write our stream outwards: - CBITSTREAM; - for (BitSize_t i = 0; i < inStream.GetNumberOfBytesUsed(); i++) { - bitStream.Write(packet->data[i + 16]); //16 bytes == header + playerID to skip + //Write our stream outwards: + CBITSTREAM; + for (BitSize_t i = 0; i < inStream.GetNumberOfBytesUsed(); i++) { + bitStream.Write(packet->data[i + 16]); //16 bytes == header + playerID to skip + } + + SEND_PACKET; //send routed packet to player + break; } - SEND_PACKET; //send routed packet to player + case eChatMessageType::GM_ANNOUNCE: { + CINSTREAM_SKIP_HEADER; - break; - } + std::string title; + std::string msg; - case eChatInternalMessageType::ANNOUNCEMENT: { - CINSTREAM_SKIP_HEADER; + uint32_t len; + inStream.Read(len); + for (uint32_t i = 0; len > i; i++) { + char character; + inStream.Read(character); + title += character; + } - std::string title; - std::string msg; + len = 0; + inStream.Read(len); + for (uint32_t i = 0; len > i; i++) { + char character; + inStream.Read(character); + msg += character; + } - uint32_t len; - inStream.Read(len); - for (uint32_t i = 0; len > i; i++) { - char character; - inStream.Read(character); - title += character; - } + //Send to our clients: + AMFArrayValue args; - len = 0; - inStream.Read(len); - for (uint32_t i = 0; len > i; i++) { - char character; - inStream.Read(character); - msg += character; - } + args.Insert("title", title); + args.Insert("message", msg); - //Send to our clients: - AMFArrayValue args; - - args.Insert("title", title); - args.Insert("message", msg); - - GameMessages::SendUIMessageServerToAllClients("ToggleAnnounce", args); - - break; - } - - case eChatInternalMessageType::MUTE_UPDATE: { - CINSTREAM_SKIP_HEADER; - LWOOBJID playerId; - time_t expire = 0; - inStream.Read(playerId); - inStream.Read(expire); - - auto* entity = Game::entityManager->GetEntity(playerId); - auto* character = entity != nullptr ? entity->GetCharacter() : nullptr; - auto* user = character != nullptr ? character->GetParentUser() : nullptr; - if (user) { - user->SetMuteExpire(expire); - - entity->GetCharacter()->SendMuteNotice(); - } - - break; - } - - case eChatInternalMessageType::TEAM_UPDATE: { - CINSTREAM_SKIP_HEADER; - - LWOOBJID teamID = 0; - char lootOption = 0; - char memberCount = 0; - std::vector members; - - inStream.Read(teamID); - bool deleteTeam = inStream.ReadBit(); - - if (deleteTeam) { - TeamManager::Instance()->DeleteTeam(teamID); - - LOG("Deleting team (%llu)", teamID); + GameMessages::SendUIMessageServerToAllClients("ToggleAnnounce", args); break; } - inStream.Read(lootOption); - inStream.Read(memberCount); - LOG("Updating team (%llu), (%i), (%i)", teamID, lootOption, memberCount); - for (char i = 0; i < memberCount; i++) { - LWOOBJID member = LWOOBJID_EMPTY; - inStream.Read(member); - members.push_back(member); + case eChatMessageType::GM_MUTE: { + CINSTREAM_SKIP_HEADER; + LWOOBJID playerId; + time_t expire = 0; + inStream.Read(playerId); + inStream.Read(expire); - LOG("Updating team member (%llu)", member); + auto* entity = Game::entityManager->GetEntity(playerId); + auto* character = entity != nullptr ? entity->GetCharacter() : nullptr; + auto* user = character != nullptr ? character->GetParentUser() : nullptr; + if (user) { + user->SetMuteExpire(expire); + + entity->GetCharacter()->SendMuteNotice(); + } + + break; } - TeamManager::Instance()->UpdateTeam(teamID, lootOption, members); + case eChatMessageType::TEAM_GET_STATUS: { + CINSTREAM_SKIP_HEADER; - break; - } + LWOOBJID teamID = 0; + char lootOption = 0; + char memberCount = 0; + std::vector members; - default: - LOG("Received an unknown chat internal: %i", int(packet->data[3])); + inStream.Read(teamID); + bool deleteTeam = inStream.ReadBit(); + + if (deleteTeam) { + TeamManager::Instance()->DeleteTeam(teamID); + + LOG("Deleting team (%llu)", teamID); + + break; + } + + inStream.Read(lootOption); + inStream.Read(memberCount); + LOG("Updating team (%llu), (%i), (%i)", teamID, lootOption, memberCount); + for (char i = 0; i < memberCount; i++) { + LWOOBJID member = LWOOBJID_EMPTY; + inStream.Read(member); + members.push_back(member); + + LOG("Updating team member (%llu)", member); + } + + TeamManager::Instance()->UpdateTeam(teamID, lootOption, members); + + break; + } + default: + LOG("Received an unknown chat: %i", int(packet->data[3])); } } } @@ -817,7 +815,7 @@ void HandlePacket(Packet* packet) { { CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::PLAYER_REMOVED_NOTIFICATION); + BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, eChatMessageType::UNEXPECTED_DISCONNECT); bitStream.Write(user->GetLoggedInChar()); Game::chatServer->Send(&bitStream, SYSTEM_PRIORITY, RELIABLE, 0, Game::chatSysAddr, false); } @@ -986,7 +984,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, eChatMessageType::UNEXPECTED_DISCONNECT); bitStream.Write(lastCharacter); Game::chatServer->Send(&bitStream, SYSTEM_PRIORITY, RELIABLE, 0, Game::chatSysAddr, false); } @@ -1132,7 +1130,7 @@ void HandlePacket(Packet* packet) { const auto& playerName = character->GetName(); CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::PLAYER_ADDED_NOTIFICATION); + BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, eChatMessageType::LOGIN_SESSION_NOTIFY); bitStream.Write(player->GetObjectID()); bitStream.Write(playerName.size()); for (size_t i = 0; i < playerName.size(); i++) { From 24de0e5fdb8ddd634a61de8de166de174db49734 Mon Sep 17 00:00:00 2001 From: David Markowitz <39972741+EmosewaMC@users.noreply.github.com> Date: Wed, 3 Apr 2024 17:06:29 -0700 Subject: [PATCH 2/6] Update GeneralUtils.cpp (#1528) same check as the header --- dCommon/GeneralUtils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dCommon/GeneralUtils.cpp b/dCommon/GeneralUtils.cpp index 27ebfb2c..159cc127 100644 --- a/dCommon/GeneralUtils.cpp +++ b/dCommon/GeneralUtils.cpp @@ -320,7 +320,7 @@ std::vector GeneralUtils::GetSqlFileNamesFromFolder(const std::stri return sortedFiles; } -#ifdef DARKFLAME_PLATFORM_MACOS +#if !(__GNUC__ >= 11 || _MSC_VER >= 1924) // MacOS floating-point parse function specializations namespace GeneralUtils::details { From b340d7c8f9b7bf0f43913b5b766db97968ca6227 Mon Sep 17 00:00:00 2001 From: David Markowitz <39972741+EmosewaMC@users.noreply.github.com> Date: Thu, 4 Apr 2024 22:51:40 -0700 Subject: [PATCH 3/6] replace white and blacklist (#1530) --- CMakeLists.txt | 2 +- dChatFilter/dChatFilter.cpp | 30 +++++------ dChatFilter/dChatFilter.h | 8 +-- dCommon/dEnums/eWorldMessageType.h | 4 +- dGame/UserManager.cpp | 2 +- .../PropertyManagementComponent.cpp | 47 ++++++------------ dGame/dGameMessages/GameMessages.cpp | 16 ++---- resources/{blacklist.dcf => blocklist.dcf} | Bin 8 files changed, 43 insertions(+), 66 deletions(-) rename resources/{blacklist.dcf => blocklist.dcf} (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index ae6455b0..00b9383f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -103,7 +103,7 @@ make_directory(${CMAKE_BINARY_DIR}/resServer) make_directory(${CMAKE_BINARY_DIR}/logs) # Copy resource files on first build -set(RESOURCE_FILES "sharedconfig.ini" "authconfig.ini" "chatconfig.ini" "worldconfig.ini" "masterconfig.ini" "blacklist.dcf") +set(RESOURCE_FILES "sharedconfig.ini" "authconfig.ini" "chatconfig.ini" "worldconfig.ini" "masterconfig.ini" "blocklist.dcf") message(STATUS "Checking resource file integrity") include(Utils) diff --git a/dChatFilter/dChatFilter.cpp b/dChatFilter/dChatFilter.cpp index 6e81db3b..844e3411 100644 --- a/dChatFilter/dChatFilter.cpp +++ b/dChatFilter/dChatFilter.cpp @@ -27,8 +27,8 @@ dChatFilter::dChatFilter(const std::string& filepath, bool dontGenerateDCF) { ExportWordlistToDCF(filepath + ".dcf", true); } - if (BinaryIO::DoesFileExist("blacklist.dcf")) { - ReadWordlistDCF("blacklist.dcf", false); + if (BinaryIO::DoesFileExist("blocklist.dcf")) { + ReadWordlistDCF("blocklist.dcf", false); } //Read player names that are ok as well: @@ -44,20 +44,20 @@ dChatFilter::~dChatFilter() { m_DeniedWords.clear(); } -void dChatFilter::ReadWordlistPlaintext(const std::string& filepath, bool whiteList) { +void dChatFilter::ReadWordlistPlaintext(const std::string& filepath, bool allowList) { std::ifstream file(filepath); if (file) { std::string line; while (std::getline(file, line)) { line.erase(std::remove(line.begin(), line.end(), '\r'), line.end()); std::transform(line.begin(), line.end(), line.begin(), ::tolower); //Transform to lowercase - if (whiteList) m_ApprovedWords.push_back(CalculateHash(line)); + if (allowList) m_ApprovedWords.push_back(CalculateHash(line)); else m_DeniedWords.push_back(CalculateHash(line)); } } } -bool dChatFilter::ReadWordlistDCF(const std::string& filepath, bool whiteList) { +bool dChatFilter::ReadWordlistDCF(const std::string& filepath, bool allowList) { std::ifstream file(filepath, std::ios::binary); if (file) { fileHeader hdr; @@ -70,13 +70,13 @@ bool dChatFilter::ReadWordlistDCF(const std::string& filepath, bool whiteList) { if (hdr.formatVersion == formatVersion) { size_t wordsToRead = 0; BinaryIO::BinaryRead(file, wordsToRead); - if (whiteList) m_ApprovedWords.reserve(wordsToRead); + if (allowList) m_ApprovedWords.reserve(wordsToRead); else m_DeniedWords.reserve(wordsToRead); size_t word = 0; for (size_t i = 0; i < wordsToRead; ++i) { BinaryIO::BinaryRead(file, word); - if (whiteList) m_ApprovedWords.push_back(word); + if (allowList) m_ApprovedWords.push_back(word); else m_DeniedWords.push_back(word); } @@ -90,14 +90,14 @@ bool dChatFilter::ReadWordlistDCF(const std::string& filepath, bool whiteList) { return false; } -void dChatFilter::ExportWordlistToDCF(const std::string& filepath, bool whiteList) { +void dChatFilter::ExportWordlistToDCF(const std::string& filepath, bool allowList) { std::ofstream file(filepath, std::ios::binary | std::ios_base::out); if (file) { BinaryIO::BinaryWrite(file, uint32_t(dChatFilterDCF::header)); BinaryIO::BinaryWrite(file, uint32_t(dChatFilterDCF::formatVersion)); - BinaryIO::BinaryWrite(file, size_t(whiteList ? m_ApprovedWords.size() : m_DeniedWords.size())); + BinaryIO::BinaryWrite(file, size_t(allowList ? m_ApprovedWords.size() : m_DeniedWords.size())); - for (size_t word : whiteList ? m_ApprovedWords : m_DeniedWords) { + for (size_t word : allowList ? m_ApprovedWords : m_DeniedWords) { BinaryIO::BinaryWrite(file, word); } @@ -105,10 +105,10 @@ void dChatFilter::ExportWordlistToDCF(const std::string& filepath, bool whiteLis } } -std::vector> dChatFilter::IsSentenceOkay(const std::string& message, eGameMasterLevel gmLevel, bool whiteList) { +std::vector> dChatFilter::IsSentenceOkay(const std::string& message, eGameMasterLevel gmLevel, bool allowList) { if (gmLevel > eGameMasterLevel::FORUM_MODERATOR) return { }; //If anything but a forum mod, return true. if (message.empty()) return { }; - if (!whiteList && m_DeniedWords.empty()) return { { 0, message.length() } }; + if (!allowList && m_DeniedWords.empty()) return { { 0, message.length() } }; std::stringstream sMessage(message); std::string segment; @@ -126,16 +126,16 @@ std::vector> dChatFilter::IsSentenceOkay(const std:: size_t hash = CalculateHash(segment); - if (std::find(m_UserUnapprovedWordCache.begin(), m_UserUnapprovedWordCache.end(), hash) != m_UserUnapprovedWordCache.end() && whiteList) { + if (std::find(m_UserUnapprovedWordCache.begin(), m_UserUnapprovedWordCache.end(), hash) != m_UserUnapprovedWordCache.end() && allowList) { listOfBadSegments.emplace_back(position, originalSegment.length()); } - if (std::find(m_ApprovedWords.begin(), m_ApprovedWords.end(), hash) == m_ApprovedWords.end() && whiteList) { + if (std::find(m_ApprovedWords.begin(), m_ApprovedWords.end(), hash) == m_ApprovedWords.end() && allowList) { m_UserUnapprovedWordCache.push_back(hash); listOfBadSegments.emplace_back(position, originalSegment.length()); } - if (std::find(m_DeniedWords.begin(), m_DeniedWords.end(), hash) != m_DeniedWords.end() && !whiteList) { + if (std::find(m_DeniedWords.begin(), m_DeniedWords.end(), hash) != m_DeniedWords.end() && !allowList) { m_UserUnapprovedWordCache.push_back(hash); listOfBadSegments.emplace_back(position, originalSegment.length()); } diff --git a/dChatFilter/dChatFilter.h b/dChatFilter/dChatFilter.h index d00525ce..0f1e49ba 100644 --- a/dChatFilter/dChatFilter.h +++ b/dChatFilter/dChatFilter.h @@ -21,10 +21,10 @@ public: dChatFilter(const std::string& filepath, bool dontGenerateDCF); ~dChatFilter(); - void ReadWordlistPlaintext(const std::string& filepath, bool whiteList); - bool ReadWordlistDCF(const std::string& filepath, bool whiteList); - void ExportWordlistToDCF(const std::string& filepath, bool whiteList); - std::vector> IsSentenceOkay(const std::string& message, eGameMasterLevel gmLevel, bool whiteList = true); + void ReadWordlistPlaintext(const std::string& filepath, bool allowList); + bool ReadWordlistDCF(const std::string& filepath, bool allowList); + void ExportWordlistToDCF(const std::string& filepath, bool allowList); + std::vector> IsSentenceOkay(const std::string& message, eGameMasterLevel gmLevel, bool allowList = true); private: bool m_DontGenerateDCF; diff --git a/dCommon/dEnums/eWorldMessageType.h b/dCommon/dEnums/eWorldMessageType.h index bfaa110b..92081055 100644 --- a/dCommon/dEnums/eWorldMessageType.h +++ b/dCommon/dEnums/eWorldMessageType.h @@ -29,8 +29,8 @@ enum class eWorldMessageType : uint32_t { ROUTE_PACKET, // Social? POSITION_UPDATE, MAIL, - WORD_CHECK, // Whitelist word check - STRING_CHECK, // Whitelist string check + WORD_CHECK, // AllowList word check + STRING_CHECK, // AllowList string check GET_PLAYERS_IN_ZONE, REQUEST_UGC_MANIFEST_INFO, BLUEPRINT_GET_ALL_DATA_REQUEST, diff --git a/dGame/UserManager.cpp b/dGame/UserManager.cpp index b94e9de5..da7e9e23 100644 --- a/dGame/UserManager.cpp +++ b/dGame/UserManager.cpp @@ -83,7 +83,7 @@ void UserManager::Initialize() { auto chatListStream = Game::assetManager->GetFile("chatplus_en_us.txt"); if (!chatListStream) { LOG("Failed to load %s", (Game::assetManager->GetResPath() / "chatplus_en_us.txt").string().c_str()); - throw std::runtime_error("Aborting initialization due to missing chat whitelist file."); + throw std::runtime_error("Aborting initialization due to missing chat allowlist file."); } while (std::getline(chatListStream, line, '\n')) { diff --git a/dGame/dComponents/PropertyManagementComponent.cpp b/dGame/dComponents/PropertyManagementComponent.cpp index 2acc6a5d..95a6f3e0 100644 --- a/dGame/dComponents/PropertyManagementComponent.cpp +++ b/dGame/dComponents/PropertyManagementComponent.cpp @@ -352,16 +352,11 @@ void PropertyManagementComponent::UpdateModelPosition(const LWOOBJID id, const N auto* spawner = Game::zoneManager->GetSpawner(spawnerId); - auto ldfModelBehavior = new LDFData(u"modelBehaviors", 0); - auto userModelID = new LDFData(u"userModelID", info.spawnerID); - auto modelType = new LDFData(u"modelType", 2); - auto propertyObjectID = new LDFData(u"propertyObjectID", true); - auto componentWhitelist = new LDFData(u"componentWhitelist", 1); - info.nodes[0]->config.push_back(componentWhitelist); - info.nodes[0]->config.push_back(ldfModelBehavior); - info.nodes[0]->config.push_back(modelType); - info.nodes[0]->config.push_back(propertyObjectID); - info.nodes[0]->config.push_back(userModelID); + info.nodes[0]->config.push_back(new LDFData(u"modelBehaviors", 0)); + info.nodes[0]->config.push_back(new LDFData(u"userModelID", info.spawnerID)); + info.nodes[0]->config.push_back(new LDFData(u"modelType", 2)); + info.nodes[0]->config.push_back(new LDFData(u"propertyObjectID", true)); + info.nodes[0]->config.push_back(new LDFData(u"componentWhitelist", 1)); auto* model = spawner->Spawn(); @@ -585,29 +580,17 @@ void PropertyManagementComponent::Load() { GeneralUtils::SetBit(blueprintID, eObjectBits::CHARACTER); GeneralUtils::SetBit(blueprintID, eObjectBits::PERSISTENT); - LDFBaseData* ldfBlueprintID = new LDFData(u"blueprintid", blueprintID); - LDFBaseData* componentWhitelist = new LDFData(u"componentWhitelist", 1); - LDFBaseData* modelType = new LDFData(u"modelType", 2); - LDFBaseData* propertyObjectID = new LDFData(u"propertyObjectID", true); - LDFBaseData* userModelID = new LDFData(u"userModelID", databaseModel.id); - - settings.push_back(ldfBlueprintID); - settings.push_back(componentWhitelist); - settings.push_back(modelType); - settings.push_back(propertyObjectID); - settings.push_back(userModelID); + settings.push_back(new LDFData(u"blueprintid", blueprintID)); + settings.push_back(new LDFData(u"componentWhitelist", 1)); + settings.push_back(new LDFData(u"modelType", 2)); + settings.push_back(new LDFData(u"propertyObjectID", true)); + settings.push_back(new LDFData(u"userModelID", databaseModel.id)); } else { - auto modelType = new LDFData(u"modelType", 2); - auto userModelID = new LDFData(u"userModelID", databaseModel.id); - auto ldfModelBehavior = new LDFData(u"modelBehaviors", 0); - auto propertyObjectID = new LDFData(u"propertyObjectID", true); - auto componentWhitelist = new LDFData(u"componentWhitelist", 1); - - settings.push_back(componentWhitelist); - settings.push_back(ldfModelBehavior); - settings.push_back(modelType); - settings.push_back(propertyObjectID); - settings.push_back(userModelID); + settings.push_back(new LDFData(u"modelType", 2)); + settings.push_back(new LDFData(u"userModelID", databaseModel.id)); + settings.push_back(new LDFData(u"modelBehaviors", 0)); + settings.push_back(new LDFData(u"propertyObjectID", true)); + settings.push_back(new LDFData(u"componentWhitelist", 1)); } node->config = settings; diff --git a/dGame/dGameMessages/GameMessages.cpp b/dGame/dGameMessages/GameMessages.cpp index c144675b..291dc151 100644 --- a/dGame/dGameMessages/GameMessages.cpp +++ b/dGame/dGameMessages/GameMessages.cpp @@ -2663,17 +2663,11 @@ void GameMessages::HandleBBBSaveRequest(RakNet::BitStream& inStream, Entity* ent info.spawnerID = entity->GetObjectID(); info.spawnerNodeID = 0; - LDFBaseData* ldfBlueprintID = new LDFData(u"blueprintid", blueprintID); - LDFBaseData* componentWhitelist = new LDFData(u"componentWhitelist", 1); - LDFBaseData* modelType = new LDFData(u"modelType", 2); - LDFBaseData* propertyObjectID = new LDFData(u"propertyObjectID", true); - LDFBaseData* userModelID = new LDFData(u"userModelID", newIDL); - - info.settings.push_back(ldfBlueprintID); - info.settings.push_back(componentWhitelist); - info.settings.push_back(modelType); - info.settings.push_back(propertyObjectID); - info.settings.push_back(userModelID); + info.settings.push_back(new LDFData(u"blueprintid", blueprintID)); + info.settings.push_back(new LDFData(u"componentWhitelist", 1)); + info.settings.push_back(new LDFData(u"modelType", 2)); + info.settings.push_back(new LDFData(u"propertyObjectID", true)); + info.settings.push_back(new LDFData(u"userModelID", newIDL)); Entity* newEntity = Game::entityManager->CreateEntity(info, nullptr); if (newEntity) { diff --git a/resources/blacklist.dcf b/resources/blocklist.dcf similarity index 100% rename from resources/blacklist.dcf rename to resources/blocklist.dcf From 06e7d57e0d9c9929175956a03c2b16b12162e873 Mon Sep 17 00:00:00 2001 From: jadebenn Date: Fri, 5 Apr 2024 00:52:26 -0500 Subject: [PATCH 4/6] chore: Remove dpEntity pointers from collision checking (#1529) * chore: Remove dpEntity pointers from collision checking * Update fn documentation in ProximityMonitorComponent.h * use more idiomatic method to calculate vector index * feedback * missed a ranges::find replacement * adjust for feedback. last changes tonight. * okay, also remove unneeded include. then sleep. * for real tho * update to use unordered_set instead of set --- dGame/dComponents/BaseCombatAIComponent.cpp | 8 +++--- dGame/dComponents/PhantomPhysicsComponent.cpp | 18 ++++++------- .../dComponents/ProximityMonitorComponent.cpp | 26 +++++++++---------- dGame/dComponents/ProximityMonitorComponent.h | 8 +++--- dPhysics/dpEntity.cpp | 17 ++++++------ dPhysics/dpEntity.h | 15 ++++++----- dScripts/02_server/Map/AM/WanderingVendor.cpp | 2 +- dScripts/ai/AG/AgBusDoor.cpp | 8 +++--- 8 files changed, 51 insertions(+), 51 deletions(-) diff --git a/dGame/dComponents/BaseCombatAIComponent.cpp b/dGame/dComponents/BaseCombatAIComponent.cpp index 2bd2b6f1..0c2a796c 100644 --- a/dGame/dComponents/BaseCombatAIComponent.cpp +++ b/dGame/dComponents/BaseCombatAIComponent.cpp @@ -150,13 +150,13 @@ void BaseCombatAIComponent::Update(const float deltaTime) { m_dpEntityEnemy->SetPosition(m_Parent->GetPosition()); //Process enter events - for (auto en : m_dpEntity->GetNewObjects()) { - m_Parent->OnCollisionPhantom(en->GetObjectID()); + for (const auto id : m_dpEntity->GetNewObjects()) { + m_Parent->OnCollisionPhantom(id); } //Process exit events - for (auto en : m_dpEntity->GetRemovedObjects()) { - m_Parent->OnCollisionLeavePhantom(en->GetObjectID()); + for (const auto id : m_dpEntity->GetRemovedObjects()) { + m_Parent->OnCollisionLeavePhantom(id); } // Check if we should stop the tether effect diff --git a/dGame/dComponents/PhantomPhysicsComponent.cpp b/dGame/dComponents/PhantomPhysicsComponent.cpp index 276184b1..ba0c2495 100644 --- a/dGame/dComponents/PhantomPhysicsComponent.cpp +++ b/dGame/dComponents/PhantomPhysicsComponent.cpp @@ -187,7 +187,7 @@ PhantomPhysicsComponent::PhantomPhysicsComponent(Entity* parent) : PhysicsCompon //add fallback cube: m_dpEntity = new dpEntity(m_Parent->GetObjectID(), 2.0f, 2.0f, 2.0f); } - + m_dpEntity->SetScale(m_Scale); m_dpEntity->SetRotation(m_Rotation); m_dpEntity->SetPosition(m_Position); @@ -323,14 +323,13 @@ void PhantomPhysicsComponent::Update(float deltaTime) { if (!m_dpEntity) return; //Process enter events - for (auto en : m_dpEntity->GetNewObjects()) { - if (!en) continue; - ApplyCollisionEffect(en->GetObjectID(), m_EffectType, m_DirectionalMultiplier); - m_Parent->OnCollisionPhantom(en->GetObjectID()); + for (const auto id : m_dpEntity->GetNewObjects()) { + ApplyCollisionEffect(id, m_EffectType, m_DirectionalMultiplier); + m_Parent->OnCollisionPhantom(id); //If we are a respawn volume, inform the client: if (m_IsRespawnVolume) { - auto entity = Game::entityManager->GetEntity(en->GetObjectID()); + auto* const entity = Game::entityManager->GetEntity(id); if (entity) { GameMessages::SendPlayerReachedRespawnCheckpoint(entity, m_RespawnPos, m_RespawnRot); @@ -341,10 +340,9 @@ void PhantomPhysicsComponent::Update(float deltaTime) { } //Process exit events - for (auto en : m_dpEntity->GetRemovedObjects()) { - if (!en) continue; - ApplyCollisionEffect(en->GetObjectID(), m_EffectType, 1.0f); - m_Parent->OnCollisionLeavePhantom(en->GetObjectID()); + for (const auto id : m_dpEntity->GetRemovedObjects()) { + ApplyCollisionEffect(id, m_EffectType, 1.0f); + m_Parent->OnCollisionLeavePhantom(id); } } diff --git a/dGame/dComponents/ProximityMonitorComponent.cpp b/dGame/dComponents/ProximityMonitorComponent.cpp index 9ab3f1db..3338dd43 100644 --- a/dGame/dComponents/ProximityMonitorComponent.cpp +++ b/dGame/dComponents/ProximityMonitorComponent.cpp @@ -5,7 +5,7 @@ #include "EntityManager.h" #include "SimplePhysicsComponent.h" -const std::map ProximityMonitorComponent::m_EmptyObjectMap = {}; +const std::unordered_set ProximityMonitorComponent::m_EmptyObjectSet = {}; ProximityMonitorComponent::ProximityMonitorComponent(Entity* parent, int radiusSmall, int radiusLarge) : Component(parent) { if (radiusSmall != -1 && radiusLarge != -1) { @@ -38,26 +38,26 @@ void ProximityMonitorComponent::SetProximityRadius(dpEntity* entity, const std:: m_ProximitiesData.insert(std::make_pair(name, entity)); } -const std::map& ProximityMonitorComponent::GetProximityObjects(const std::string& name) { - const auto& iter = m_ProximitiesData.find(name); +const std::unordered_set& ProximityMonitorComponent::GetProximityObjects(const std::string& name) { + const auto iter = m_ProximitiesData.find(name); - if (iter == m_ProximitiesData.end()) { - return m_EmptyObjectMap; + if (iter == m_ProximitiesData.cend()) { + return m_EmptyObjectSet; } return iter->second->GetCurrentlyCollidingObjects(); } bool ProximityMonitorComponent::IsInProximity(const std::string& name, LWOOBJID objectID) { - const auto& iter = m_ProximitiesData.find(name); + const auto iter = m_ProximitiesData.find(name); - if (iter == m_ProximitiesData.end()) { + if (iter == m_ProximitiesData.cend()) { return false; } - const auto& collitions = iter->second->GetCurrentlyCollidingObjects(); + const auto& collisions = iter->second->GetCurrentlyCollidingObjects(); - return collitions.find(objectID) != collitions.end(); + return collisions.contains(objectID); } void ProximityMonitorComponent::Update(float deltaTime) { @@ -66,13 +66,13 @@ void ProximityMonitorComponent::Update(float deltaTime) { prox.second->SetPosition(m_Parent->GetPosition()); //Process enter events - for (auto* en : prox.second->GetNewObjects()) { - m_Parent->OnCollisionProximity(en->GetObjectID(), prox.first, "ENTER"); + for (const auto id : prox.second->GetNewObjects()) { + m_Parent->OnCollisionProximity(id, prox.first, "ENTER"); } //Process exit events - for (auto* en : prox.second->GetRemovedObjects()) { - m_Parent->OnCollisionProximity(en->GetObjectID(), prox.first, "LEAVE"); + for (const auto id : prox.second->GetRemovedObjects()) { + m_Parent->OnCollisionProximity(id, prox.first, "LEAVE"); } } } diff --git a/dGame/dComponents/ProximityMonitorComponent.h b/dGame/dComponents/ProximityMonitorComponent.h index 512b2848..e80f1b5b 100644 --- a/dGame/dComponents/ProximityMonitorComponent.h +++ b/dGame/dComponents/ProximityMonitorComponent.h @@ -6,6 +6,8 @@ #ifndef PROXIMITYMONITORCOMPONENT_H #define PROXIMITYMONITORCOMPONENT_H +#include + #include "BitStream.h" #include "Entity.h" #include "dpWorld.h" @@ -42,9 +44,9 @@ public: /** * Returns the last of entities that are used to check proximity, given a name * @param name the proximity name to retrieve physics objects for - * @return a map of physics entities for this name, indexed by object ID + * @return a set of physics entity object IDs for this name */ - const std::map& GetProximityObjects(const std::string& name); + const std::unordered_set& GetProximityObjects(const std::string& name); /** * Checks if the passed object is in proximity of the named proximity sensor @@ -70,7 +72,7 @@ private: /** * Default value for the proximity data */ - static const std::map m_EmptyObjectMap; + static const std::unordered_set m_EmptyObjectSet; }; #endif // PROXIMITYMONITORCOMPONENT_H diff --git a/dPhysics/dpEntity.cpp b/dPhysics/dpEntity.cpp index cbe3f5e8..6fc40452 100644 --- a/dPhysics/dpEntity.cpp +++ b/dPhysics/dpEntity.cpp @@ -3,8 +3,6 @@ #include "dpShapeBox.h" #include "dpGrid.h" -#include - dpEntity::dpEntity(const LWOOBJID& objectID, dpShapeType shapeType, bool isStatic) { m_ObjectID = objectID; m_IsStatic = isStatic; @@ -76,16 +74,17 @@ void dpEntity::CheckCollision(dpEntity* other) { return; } - bool wasFound = m_CurrentlyCollidingObjects.contains(other->GetObjectID()); - - bool isColliding = m_CollisionShape->IsColliding(other->GetShape()); + const auto objId = other->GetObjectID(); + const auto objItr = m_CurrentlyCollidingObjects.find(objId); + const bool wasFound = objItr != m_CurrentlyCollidingObjects.cend(); + const bool isColliding = m_CollisionShape->IsColliding(other->GetShape()); if (isColliding && !wasFound) { - m_CurrentlyCollidingObjects.emplace(other->GetObjectID(), other); - m_NewObjects.push_back(other); + m_CurrentlyCollidingObjects.emplace(objId); + m_NewObjects.push_back(objId); } else if (!isColliding && wasFound) { - m_CurrentlyCollidingObjects.erase(other->GetObjectID()); - m_RemovedObjects.push_back(other); + m_CurrentlyCollidingObjects.erase(objItr); + m_RemovedObjects.push_back(objId); } } diff --git a/dPhysics/dpEntity.h b/dPhysics/dpEntity.h index ea7a49b2..3dea1b61 100644 --- a/dPhysics/dpEntity.h +++ b/dPhysics/dpEntity.h @@ -2,7 +2,8 @@ #include "NiPoint3.h" #include "NiQuaternion.h" #include -#include +#include +#include #include "dCommonVars.h" #include "dpCommon.h" @@ -49,9 +50,9 @@ public: bool GetSleeping() const { return m_Sleeping; } void SetSleeping(bool value) { m_Sleeping = value; } - const std::vector& GetNewObjects() const { return m_NewObjects; } - const std::vector& GetRemovedObjects() const { return m_RemovedObjects; } - const std::map& GetCurrentlyCollidingObjects() const { return m_CurrentlyCollidingObjects; } + const std::span GetNewObjects() const { return m_NewObjects; } + const std::span GetRemovedObjects() const { return m_RemovedObjects; } + const std::unordered_set& GetCurrentlyCollidingObjects() const { return m_CurrentlyCollidingObjects; } void PreUpdate() { m_NewObjects.clear(); m_RemovedObjects.clear(); } @@ -80,7 +81,7 @@ private: bool m_IsGargantuan = false; - std::vector m_NewObjects; - std::vector m_RemovedObjects; - std::map m_CurrentlyCollidingObjects; + std::vector m_NewObjects; + std::vector m_RemovedObjects; + std::unordered_set m_CurrentlyCollidingObjects; }; diff --git a/dScripts/02_server/Map/AM/WanderingVendor.cpp b/dScripts/02_server/Map/AM/WanderingVendor.cpp index 742741d3..d6bb3247 100644 --- a/dScripts/02_server/Map/AM/WanderingVendor.cpp +++ b/dScripts/02_server/Map/AM/WanderingVendor.cpp @@ -21,7 +21,7 @@ void WanderingVendor::OnProximityUpdate(Entity* self, Entity* entering, std::str const auto proxObjs = proximityMonitorComponent->GetProximityObjects("playermonitor"); bool foundPlayer = false; - for (const auto id : proxObjs | std::views::keys) { + for (const auto id : proxObjs) { auto* entity = Game::entityManager->GetEntity(id); if (entity && entity->IsPlayer()) { foundPlayer = true; diff --git a/dScripts/ai/AG/AgBusDoor.cpp b/dScripts/ai/AG/AgBusDoor.cpp index fd6c272e..a4106aaf 100644 --- a/dScripts/ai/AG/AgBusDoor.cpp +++ b/dScripts/ai/AG/AgBusDoor.cpp @@ -23,13 +23,13 @@ void AgBusDoor::OnProximityUpdate(Entity* self, Entity* entering, std::string na m_Counter = 0; m_OuterCounter = 0; - for (const auto& pair : proximityMonitorComponent->GetProximityObjects("busDoor")) { - auto* entity = Game::entityManager->GetEntity(pair.first); + for (const auto id : proximityMonitorComponent->GetProximityObjects("busDoor")) { + const auto* const entity = Game::entityManager->GetEntity(id); if (entity != nullptr && entity->IsPlayer()) m_Counter++; } - for (const auto& pair : proximityMonitorComponent->GetProximityObjects("busDoorOuter")) { - auto* entity = Game::entityManager->GetEntity(pair.first); + for (const auto id : proximityMonitorComponent->GetProximityObjects("busDoorOuter")) { + const auto* const entity = Game::entityManager->GetEntity(id); if (entity != nullptr && entity->IsPlayer()) m_OuterCounter++; } From bcfaa6c7fed659597afda8ab52dc0c8d058fc2a6 Mon Sep 17 00:00:00 2001 From: jadebenn Date: Fri, 5 Apr 2024 03:14:52 -0500 Subject: [PATCH 5/6] const return oversight (#1532) --- dPhysics/dpEntity.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dPhysics/dpEntity.h b/dPhysics/dpEntity.h index 3dea1b61..cc47d718 100644 --- a/dPhysics/dpEntity.h +++ b/dPhysics/dpEntity.h @@ -50,8 +50,8 @@ public: bool GetSleeping() const { return m_Sleeping; } void SetSleeping(bool value) { m_Sleeping = value; } - const std::span GetNewObjects() const { return m_NewObjects; } - const std::span GetRemovedObjects() const { return m_RemovedObjects; } + std::span GetNewObjects() const { return m_NewObjects; } + std::span GetRemovedObjects() const { return m_RemovedObjects; } const std::unordered_set& GetCurrentlyCollidingObjects() const { return m_CurrentlyCollidingObjects; } void PreUpdate() { m_NewObjects.clear(); m_RemovedObjects.clear(); } From 18c27b14c879a1ae6366c37b069c0cdfe5abe94b Mon Sep 17 00:00:00 2001 From: jadebenn Date: Fri, 5 Apr 2024 12:56:23 -0500 Subject: [PATCH 6/6] disable non conforming volatile behavior on MSVC (#1534) --- CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 00b9383f..aa517182 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,7 +73,8 @@ if(UNIX) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -O2 -fPIC") elseif(MSVC) # Skip warning for invalid conversion from size_t to uint32_t for all targets below for now - add_compile_options("/wd4267" "/utf-8") + # Also disable non-portable MSVC volatile behavior + add_compile_options("/wd4267" "/utf-8" "/volatile:iso") elseif(WIN32) add_compile_definitions(_CRT_SECURE_NO_WARNINGS) endif()