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

View File

@ -3,6 +3,11 @@
#include "dConfig.h"
#include "GameMessages.h"
#include "Entity.h"
#include "EntityManager.h"
#include "UserManager.h"
#include "User.h"
#include "Character.h"
#include "dChatFilter.h"
namespace WorldPackets {
@ -12,6 +17,18 @@ namespace WorldPackets {
}
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;
switch (languageCode) {
case eLanguageCodeID::EN_US:
@ -43,7 +60,8 @@ namespace WorldPackets {
bool GeneralChatMessage::Deserialize(RakNet::BitStream& bitStream) {
VALIDATE_READ(bitStream.Read(chatChannel));
VALIDATE_READ(bitStream.Read(unknown));
uint16_t padding;
VALIDATE_READ(bitStream.Read(padding));
uint32_t messageLength;
VALIDATE_READ(bitStream.Read(messageLength));
@ -58,6 +76,25 @@ namespace WorldPackets {
}
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) {
@ -116,7 +153,9 @@ namespace WorldPackets {
}
void PositionUpdate::Handle() {
Entity* entity = Game::entityManager->GetEntity(objectID);
if (entity) entity->ProcessPositionUpdate(positionUpdate);
}
bool StringCheck::Deserialize(RakNet::BitStream& bitStream) {

View File

@ -18,10 +18,6 @@ namespace WorldPackets {
struct UIHelpTop5: public LUBitStream {
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) {};
bool Deserialize(RakNet::BitStream& bitStream) override;
void Handle() override;
@ -29,7 +25,6 @@ namespace WorldPackets {
struct GeneralChatMessage : public LUBitStream {
uint8_t chatChannel = 0;
uint16_t unknown = 0;
std::u16string 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");
return;
}
Entity* entity = Game::entityManager->GetEntity(user->GetLastUsedChar()->GetObjectID());
if (entity) entity->ProcessPositionUpdate(positionUpdate);
positionUpdate.objectID = user->GetLastUsedChar()->GetObjectID();
break;
}
@ -1363,21 +1361,18 @@ void HandlePacket(Packet* packet) {
LOG("Unable to get user to parse chat message");
return;
}
auto* character = user->GetLastUsedChar();
if (!character) return;
auto* entity = character->GetEntity();
if (!entity) return;
if (user->GetIsMuted()) {
user->GetLastUsedChar()->SendMuteNotice();
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);
LOG("%s: %s", playerName.c_str(), sMessage.c_str());
ChatPackets::SendChatMessage(packet->systemAddress, chatMessage.chatChannel, playerName, user->GetLoggedInChar(), isMythran, chatMessage.message);
chatMessage.objectID = entity->GetObjectID();
chatMessage.Handle();
}
break;
@ -1411,8 +1406,8 @@ void HandlePacket(Packet* packet) {
if (!character) return;
auto* entity = character->GetEntity();
if (!entity) return;
help.sysAddr = packet->systemAddress;
help.player = entity;
help.objectID = entity->GetObjectID();
help.Handle();
break;