<commit_before>#include "systems/chatsystem.h"
#include "cmapserver.h"
#include "cmapclient.h"

using namespace Systems;
using namespace RoseCommon;

ChatSystem::ChatSystem(SystemManager &manager) : System(manager) {
    manager.registerDispatcher(ePacketType::PAKCS_NORMAL_CHAT, &ChatSystem::normalChat);
    manager.registerDispatcher(ePacketType::PAKCS_WHISPER_CHAT, &ChatSystem::whisperChat);
    manager.registerDispatcher(ePacketType::PAKCS_PARTY_CHAT, &ChatSystem::partyChat);
}

void ChatSystem::update(EntityManager&, double) {}

void ChatSystem::normalChat(CMapClient *client, Entity entity, const CliNormalChat &packet) {
    logger_->trace("ChatSystem::normalChat");
    if (!client || !entity.component<BasicInfo>())
        return;
    CMapServer::SendPacket(client, CMapServer::eSendType::NEARBY, 
            *makePacket<ePacketType::PAKWC_NORMAL_CHAT>(getId(entity), packet.message()));
}

void ChatSystem::whisperChat(CMapClient *client, Entity entity, const CliWhisperChat &packet) {
    logger_->trace("ChatSystem::whisperChat");
    if (!client || !entity.component<BasicInfo>())
        return;
    auto target = manager_.getEntity(packet.targetId());
    if (!target || !getClient(target)) {
        client->Send(*makePacket<ePacketType::PAKWC_WHISPER_CHAT>("", "User cannot be found or is offline"));
        return;
    }
    if (auto socket = getClient(target))
        socket->Send(
                    *makePacket<ePacketType::PAKWC_WHISPER_CHAT>(packet.message(), getName(entity)));
}

void ChatSystem::partyChat(CMapClient *client, Entity entity, const CliPartyChat &packet) {
    logger_->trace("ChatSystem::partyChat");
    if (!client || !entity.component<BasicInfo>())
        return;
    if (!entity.component<Party>() || !entity.component<Party>()->party_) {
        logger_->warn("Client {} tried to send a party message but isn't in a party", getId(entity));
        return;
    }
    auto party = entity.component<Party>()->party_;
    for (auto it : party->members_) {
        if (auto socket = getClient(it))
            socket->Send(*makePacket<ePacketType::PAKWC_PARTY_CHAT>(getId(entity), packet.message()));
    }
}
<commit_msg>Solved bug where the whisper name and text was sent inverted to the client<commit_after>#include "systems/chatsystem.h"
#include "cmapserver.h"
#include "cmapclient.h"

using namespace Systems;
using namespace RoseCommon;

ChatSystem::ChatSystem(SystemManager &manager) : System(manager) {
    manager.registerDispatcher(ePacketType::PAKCS_NORMAL_CHAT, &ChatSystem::normalChat);
    manager.registerDispatcher(ePacketType::PAKCS_WHISPER_CHAT, &ChatSystem::whisperChat);
    manager.registerDispatcher(ePacketType::PAKCS_PARTY_CHAT, &ChatSystem::partyChat);
}

void ChatSystem::update(EntityManager&, double) {}

void ChatSystem::normalChat(CMapClient *client, Entity entity, const CliNormalChat &packet) {
    logger_->trace("ChatSystem::normalChat");
    if (!client || !entity.component<BasicInfo>())
        return;
    CMapServer::SendPacket(client, CMapServer::eSendType::NEARBY, 
            *makePacket<ePacketType::PAKWC_NORMAL_CHAT>(getId(entity), packet.message()));
}

void ChatSystem::whisperChat(CMapClient *client, Entity entity, const CliWhisperChat &packet) {
    logger_->trace("ChatSystem::whisperChat");
    if (!client || !entity.component<BasicInfo>())
        return;
    auto target = manager_.getEntity(packet.targetId());
    if (!target || !getClient(target)) {
        client->Send(*makePacket<ePacketType::PAKWC_WHISPER_CHAT>("", "User cannot be found or is offline"));
        return;
    }
    if (auto socket = getClient(target))
        socket->Send(
                    *makePacket<ePacketType::PAKWC_WHISPER_CHAT>(getName(entity), packet.message()));
}

void ChatSystem::partyChat(CMapClient *client, Entity entity, const CliPartyChat &packet) {
    logger_->trace("ChatSystem::partyChat");
    if (!client || !entity.component<BasicInfo>())
        return;
    if (!entity.component<Party>() || !entity.component<Party>()->party_) {
        logger_->warn("Client {} tried to send a party message but isn't in a party", getId(entity));
        return;
    }
    auto party = entity.component<Party>()->party_;
    for (auto it : party->members_) {
        if (auto socket = getClient(it))
            socket->Send(*makePacket<ePacketType::PAKWC_PARTY_CHAT>(getId(entity), packet.message()));
    }
}

{'fraction_non_alphanumeric': 0.14295439074200136, 'fraction_numerical': 0.0, 'mean_word_length': 4.8, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7640489', 'n_tokens_mistral': 1347, 'n_tokens_neox': 1325, 'n_words': 253}