move the handlers over

This commit is contained in:
Aronwk 2025-05-16 20:59:37 -05:00
parent 5628664060
commit c8a3a2c6de
4 changed files with 52 additions and 21 deletions

View File

@ -5,6 +5,7 @@
#include "BitStream.h" #include "BitStream.h"
#include "MessageIdentifiers.h" #include "MessageIdentifiers.h"
#include "eConnectionType.h" #include "eConnectionType.h"
#include "dCommonVars.h"
#include <string> #include <string>
#include <algorithm> #include <algorithm>
@ -49,6 +50,7 @@ struct LUWString {
struct LUBitStream { struct LUBitStream {
eConnectionType connectionType = eConnectionType::UNKNOWN; eConnectionType connectionType = eConnectionType::UNKNOWN;
uint32_t internalPacketID = 0xFFFFFFFF; uint32_t internalPacketID = 0xFFFFFFFF;
LWOOBJID objectID = LWOOBJID_EMPTY;
LUBitStream() = default; LUBitStream() = default;

View File

@ -3,6 +3,11 @@
#include "dConfig.h" #include "dConfig.h"
#include "GameMessages.h" #include "GameMessages.h"
#include "Entity.h" #include "Entity.h"
#include "EntityManager.h"
#include "UserManager.h"
#include "User.h"
#include "Character.h"
#include "dChatFilter.h"
namespace WorldPackets { namespace WorldPackets {
@ -12,6 +17,18 @@ namespace WorldPackets {
} }
void UIHelpTop5::Handle() { void UIHelpTop5::Handle() {
Entity* player = Game::entityManager->GetEntity(objectID);
if (!player) {
LOG("Unable to get player for UIHelpTop5");
return;
}
auto sysAddr = player->GetSystemAddress();
if (sysAddr == UNASSIGNED_SYSTEM_ADDRESS) {
LOG("Unable to get system address for player for UIHelpTop5");
return;
}
AMFArrayValue data; AMFArrayValue data;
switch (languageCode) { switch (languageCode) {
case eLanguageCodeID::EN_US: case eLanguageCodeID::EN_US:
@ -43,7 +60,8 @@ namespace WorldPackets {
bool GeneralChatMessage::Deserialize(RakNet::BitStream& bitStream) { bool GeneralChatMessage::Deserialize(RakNet::BitStream& bitStream) {
VALIDATE_READ(bitStream.Read(chatChannel)); VALIDATE_READ(bitStream.Read(chatChannel));
VALIDATE_READ(bitStream.Read(unknown)); uint16_t padding;
VALIDATE_READ(bitStream.Read(padding));
uint32_t messageLength; uint32_t messageLength;
VALIDATE_READ(bitStream.Read(messageLength)); VALIDATE_READ(bitStream.Read(messageLength));
@ -58,6 +76,25 @@ namespace WorldPackets {
} }
void GeneralChatMessage::Handle() { void GeneralChatMessage::Handle() {
Entity* player = Game::entityManager->GetEntity(objectID);
if (!player) return;
auto sysAddr = player->GetSystemAddress();
User* user = UserManager::Instance()->GetUser(sysAddr);
if (!user) {
LOG("Unable to get user to parse chat message");
return;
}
std::string playerName = user->GetLastUsedChar()->GetName();
bool isMythran = user->GetLastUsedChar()->GetGMLevel() > eGameMasterLevel::CIVILIAN;
bool isOk = Game::chatFilter->IsSentenceOkay(GeneralUtils::UTF16ToWTF8(message), user->GetLastUsedChar()->GetGMLevel()).empty();
LOG_DEBUG("Msg: %s was approved previously? %i", GeneralUtils::UTF16ToWTF8(message).c_str(), user->GetLastChatMessageApproved());
if (!isOk) return;
if (!isOk && !isMythran) return;
std::string sMessage = GeneralUtils::UTF16ToWTF8(message);
LOG("%s: %s", playerName.c_str(), sMessage.c_str());
ChatPackets::SendChatMessage(sysAddr, chatChannel, playerName, user->GetLoggedInChar(), isMythran, message);
} }
bool PositionUpdate::Deserialize(RakNet::BitStream& bitStream) { bool PositionUpdate::Deserialize(RakNet::BitStream& bitStream) {
@ -116,6 +153,8 @@ namespace WorldPackets {
} }
void PositionUpdate::Handle() { void PositionUpdate::Handle() {
Entity* entity = Game::entityManager->GetEntity(objectID);
if (entity) entity->ProcessPositionUpdate(positionUpdate);
} }

View File

@ -18,10 +18,6 @@ namespace WorldPackets {
struct UIHelpTop5: public LUBitStream { struct UIHelpTop5: public LUBitStream {
eLanguageCodeID languageCode = eLanguageCodeID::EN_US; eLanguageCodeID languageCode = eLanguageCodeID::EN_US;
// should these be moved up to the base class?
SystemAddress sysAddr = UNASSIGNED_SYSTEM_ADDRESS;
Entity* player = nullptr;
UIHelpTop5() : LUBitStream(eConnectionType::WORLD, MessageType::World::UI_HELP_TOP_5) {}; UIHelpTop5() : LUBitStream(eConnectionType::WORLD, MessageType::World::UI_HELP_TOP_5) {};
bool Deserialize(RakNet::BitStream& bitStream) override; bool Deserialize(RakNet::BitStream& bitStream) override;
void Handle() override; void Handle() override;
@ -29,7 +25,6 @@ namespace WorldPackets {
struct GeneralChatMessage : public LUBitStream { struct GeneralChatMessage : public LUBitStream {
uint8_t chatChannel = 0; uint8_t chatChannel = 0;
uint16_t unknown = 0;
std::u16string message; std::u16string message;
GeneralChatMessage() : LUBitStream(eConnectionType::WORLD, MessageType::World::GENERAL_CHAT_MESSAGE) {}; GeneralChatMessage() : LUBitStream(eConnectionType::WORLD, MessageType::World::GENERAL_CHAT_MESSAGE) {};

View File

@ -1229,9 +1229,7 @@ void HandlePacket(Packet* packet) {
LOG("Unable to get user to parse position update"); LOG("Unable to get user to parse position update");
return; return;
} }
positionUpdate.objectID = user->GetLastUsedChar()->GetObjectID();
Entity* entity = Game::entityManager->GetEntity(user->GetLastUsedChar()->GetObjectID());
if (entity) entity->ProcessPositionUpdate(positionUpdate);
break; break;
} }
@ -1363,21 +1361,18 @@ void HandlePacket(Packet* packet) {
LOG("Unable to get user to parse chat message"); LOG("Unable to get user to parse chat message");
return; return;
} }
auto* character = user->GetLastUsedChar();
if (!character) return;
auto* entity = character->GetEntity();
if (!entity) return;
if (user->GetIsMuted()) { if (user->GetIsMuted()) {
user->GetLastUsedChar()->SendMuteNotice(); user->GetLastUsedChar()->SendMuteNotice();
return; return;
} }
std::string playerName = user->GetLastUsedChar()->GetName();
bool isMythran = user->GetLastUsedChar()->GetGMLevel() > eGameMasterLevel::CIVILIAN;
bool isOk = Game::chatFilter->IsSentenceOkay(GeneralUtils::UTF16ToWTF8(chatMessage.message), user->GetLastUsedChar()->GetGMLevel()).empty();
LOG_DEBUG("Msg: %s was approved previously? %i", GeneralUtils::UTF16ToWTF8(chatMessage.message).c_str(), user->GetLastChatMessageApproved());
if (!isOk) return;
if (!isOk && !isMythran) return;
std::string sMessage = GeneralUtils::UTF16ToWTF8(chatMessage.message); chatMessage.objectID = entity->GetObjectID();
LOG("%s: %s", playerName.c_str(), sMessage.c_str()); chatMessage.Handle();
ChatPackets::SendChatMessage(packet->systemAddress, chatMessage.chatChannel, playerName, user->GetLoggedInChar(), isMythran, chatMessage.message);
} }
break; break;
@ -1411,8 +1406,8 @@ void HandlePacket(Packet* packet) {
if (!character) return; if (!character) return;
auto* entity = character->GetEntity(); auto* entity = character->GetEntity();
if (!entity) return; if (!entity) return;
help.sysAddr = packet->systemAddress;
help.player = entity; help.objectID = entity->GetObjectID();
help.Handle(); help.Handle();
break; break;