mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-08-05 18:24:12 +00:00
Merge pull request #652 from DarkflameUniverse/blacklist-and-chat-changes
Blacklist and chat changes
This commit is contained in:
@@ -30,6 +30,9 @@
|
||||
#include "VehiclePhysicsComponent.h"
|
||||
#include "dConfig.h"
|
||||
#include "CharacterComponent.h"
|
||||
#include "Database.h"
|
||||
|
||||
|
||||
|
||||
void ClientPackets::HandleChatMessage(const SystemAddress& sysAddr, Packet* packet) {
|
||||
User* user = UserManager::Instance()->GetUser(sysAddr);
|
||||
@@ -284,6 +287,12 @@ void ClientPackets::HandleChatModerationRequest(const SystemAddress& sysAddr, Pa
|
||||
receiver.push_back(static_cast<uint8_t>(character));
|
||||
}
|
||||
|
||||
if (!receiver.empty()) {
|
||||
if (std::string(receiver.c_str(), 4) == "[GM]") { // Shift the string forward if we are speaking to a GM as the client appends "[GM]" if they are
|
||||
receiver = std::string(receiver.c_str() + 4, receiver.size() - 4);
|
||||
}
|
||||
}
|
||||
|
||||
stream.Read(messageLength);
|
||||
for (uint32_t i = 0; i < messageLength; ++i) {
|
||||
uint16_t character;
|
||||
@@ -291,16 +300,61 @@ void ClientPackets::HandleChatModerationRequest(const SystemAddress& sysAddr, Pa
|
||||
message.push_back(static_cast<uint8_t>(character));
|
||||
}
|
||||
|
||||
std::unordered_map<char, char> unacceptedItems;
|
||||
bool bAllClean = Game::chatFilter->IsSentenceOkay(message, user->GetLastUsedChar()->GetGMLevel());
|
||||
if (!bAllClean) {
|
||||
unacceptedItems.insert(std::make_pair((char)0, (char)message.length()));
|
||||
bool isBestFriend = false;
|
||||
|
||||
if (chatLevel == 1) {
|
||||
// Private chat
|
||||
LWOOBJID idOfReceiver = LWOOBJID_EMPTY;
|
||||
|
||||
{
|
||||
sql::PreparedStatement* stmt = Database::CreatePreppedStmt("SELECT name FROM charinfo WHERE name = ?");
|
||||
stmt->setString(1, receiver);
|
||||
|
||||
sql::ResultSet* res = stmt->executeQuery();
|
||||
|
||||
if (res->next()) {
|
||||
idOfReceiver = res->getInt("id");
|
||||
}
|
||||
|
||||
delete stmt;
|
||||
delete res;
|
||||
}
|
||||
|
||||
if (user->GetIsBestFriendMap().find(receiver) == user->GetIsBestFriendMap().end() && idOfReceiver != LWOOBJID_EMPTY) {
|
||||
sql::PreparedStatement* stmt = Database::CreatePreppedStmt("SELECT * FROM friends WHERE (player_id = ? AND friend_id = ?) OR (player_id = ? AND friend_id = ?) LIMIT 1;");
|
||||
stmt->setInt(1, entity->GetObjectID());
|
||||
stmt->setInt(2, idOfReceiver);
|
||||
stmt->setInt(3, idOfReceiver);
|
||||
stmt->setInt(4, entity->GetObjectID());
|
||||
|
||||
sql::ResultSet* res = stmt->executeQuery();
|
||||
|
||||
if (res->next()) {
|
||||
isBestFriend = res->getInt("best_friend") == 3;
|
||||
}
|
||||
|
||||
if (isBestFriend) {
|
||||
auto tmpBestFriendMap = user->GetIsBestFriendMap();
|
||||
tmpBestFriendMap[receiver] = true;
|
||||
user->SetIsBestFriendMap(tmpBestFriendMap);
|
||||
}
|
||||
|
||||
delete res;
|
||||
delete stmt;
|
||||
}
|
||||
else if (user->GetIsBestFriendMap().find(receiver) != user->GetIsBestFriendMap().end()) {
|
||||
isBestFriend = true;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::pair<uint8_t, uint8_t>> segments = Game::chatFilter->IsSentenceOkay(message, entity->GetGMLevel(), !(isBestFriend && chatLevel == 1));
|
||||
|
||||
bool bAllClean = segments.empty();
|
||||
|
||||
if (user->GetIsMuted()) {
|
||||
bAllClean = false;
|
||||
}
|
||||
|
||||
user->SetLastChatMessageApproved(bAllClean);
|
||||
WorldPackets::SendChatModerationResponse(sysAddr, bAllClean, requestID, receiver, unacceptedItems);
|
||||
WorldPackets::SendChatModerationResponse(sysAddr, bAllClean, requestID, receiver, segments);
|
||||
}
|
||||
|
@@ -188,25 +188,28 @@ void WorldPackets::SendCreateCharacter(const SystemAddress& sysAddr, Entity* ent
|
||||
Game::logger->Log("WorldPackets", "Sent CreateCharacter for ID: %llu\n", entity->GetObjectID());
|
||||
}
|
||||
|
||||
void WorldPackets::SendChatModerationResponse(const SystemAddress& sysAddr, bool requestAccepted, uint32_t requestID, const std::string& receiver, std::unordered_map<char, char> unacceptedItems) {
|
||||
CBITSTREAM
|
||||
PacketUtils::WriteHeader(bitStream, CLIENT, MSG_CLIENT_CHAT_MODERATION_STRING);
|
||||
void WorldPackets::SendChatModerationResponse(const SystemAddress& sysAddr, bool requestAccepted, uint32_t requestID, const std::string& receiver, std::vector<std::pair<uint8_t, uint8_t>> unacceptedItems) {
|
||||
CBITSTREAM
|
||||
PacketUtils::WriteHeader(bitStream, CLIENT, MSG_CLIENT_CHAT_MODERATION_STRING);
|
||||
|
||||
bitStream.Write(static_cast<char>(requestAccepted));
|
||||
bitStream.Write(static_cast<uint16_t>(0));
|
||||
bitStream.Write(static_cast<uint8_t>(requestID));
|
||||
bitStream.Write(static_cast<char>(0));
|
||||
bitStream.Write<uint8_t>(unacceptedItems.empty()); // Is sentence ok?
|
||||
bitStream.Write<uint16_t>(0x16); // Source ID, unknown
|
||||
|
||||
for (uint32_t i = 0; i < 33; ++i) {
|
||||
bitStream.Write(static_cast<uint16_t>(receiver[i]));
|
||||
}
|
||||
bitStream.Write(static_cast<uint8_t>(requestID)); // request ID
|
||||
bitStream.Write(static_cast<char>(0)); // chat mode
|
||||
|
||||
for (std::unordered_map<char, char>::iterator it = unacceptedItems.begin(); it != unacceptedItems.end(); ++it) {
|
||||
bitStream.Write(it->first);
|
||||
bitStream.Write(it->second);
|
||||
}
|
||||
PacketUtils::WritePacketWString(receiver, 42, &bitStream); // receiver name
|
||||
|
||||
SEND_PACKET
|
||||
for (auto it : unacceptedItems) {
|
||||
bitStream.Write<uint8_t>(it.first); // start index
|
||||
bitStream.Write<uint8_t>(it.second); // length
|
||||
}
|
||||
|
||||
for (int i = unacceptedItems.size(); 64 > i; i++) {
|
||||
bitStream.Write<uint16_t>(0);
|
||||
}
|
||||
|
||||
SEND_PACKET
|
||||
}
|
||||
|
||||
void WorldPackets::SendGMLevelChange(const SystemAddress& sysAddr, bool success, uint8_t highestLevel, uint8_t prevLevel, uint8_t newLevel) {
|
||||
|
@@ -18,7 +18,7 @@ namespace WorldPackets {
|
||||
void SendTransferToWorld(const SystemAddress& sysAddr, const std::string& serverIP, uint32_t serverPort, bool mythranShift);
|
||||
void SendServerState(const SystemAddress& sysAddr);
|
||||
void SendCreateCharacter(const SystemAddress& sysAddr, Entity* entity, const std::string& xmlData, const std::u16string& username, int32_t gm);
|
||||
void SendChatModerationResponse(const SystemAddress& sysAddr, bool requestAccepted, uint32_t requestID, const std::string& receiver, std::unordered_map<char, char> unacceptedItems);
|
||||
void SendChatModerationResponse(const SystemAddress& sysAddr, bool requestAccepted, uint32_t requestID, const std::string& receiver, std::vector<std::pair<uint8_t, uint8_t>> unacceptedItems);
|
||||
void SendGMLevelChange(const SystemAddress& sysAddr, bool success, uint8_t highestLevel, uint8_t prevLevel, uint8_t newLevel);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user