Compare commits

...

10 Commits

Author SHA1 Message Date
49dab14911 whitespace 2025-05-19 00:00:49 -05:00
74601c6887 address feedbacl 2025-05-19 00:00:01 -05:00
4627168871 fixes 2025-05-18 23:36:05 -05:00
80a4f77441 oopsie, send it 2025-05-18 21:41:59 -05:00
d6c07c85c6 clone id and redo the ldf data to be simplier 2025-05-18 21:38:58 -05:00
b98470331d Everything done, now to test 2025-05-16 22:11:16 -05:00
c8a3a2c6de move the handlers over 2025-05-16 20:59:37 -05:00
5628664060 things switched, just gotta move the handle's 2025-05-16 18:17:28 -05:00
47015fda08 nl@eof 2025-05-16 00:17:34 -05:00
3e8a417f62 Welp, ended up doing client as well since world and client are in the wroing places. 2025-05-16 00:10:00 -05:00
25 changed files with 747 additions and 574 deletions

View File

@@ -20,6 +20,7 @@
#include "eGameMasterLevel.h" #include "eGameMasterLevel.h"
#include "ChatPackets.h" #include "ChatPackets.h"
#include "TeamContainer.h" #include "TeamContainer.h"
#include "eChatChannel.h"
void ChatPacketHandler::HandleFriendlistRequest(Packet* packet) { void ChatPacketHandler::HandleFriendlistRequest(Packet* packet) {
//Get from the packet which player we want to do something with: //Get from the packet which player we want to do something with:

View File

@@ -6,33 +6,7 @@
struct PlayerData; struct PlayerData;
enum class eAddFriendResponseType : uint8_t; enum class eAddFriendResponseType : uint8_t;
enum class eChatChannel : uint8_t;
enum class eChatChannel : uint8_t {
SYSTEMNOTIFY = 0,
SYSTEMWARNING,
SYSTEMERROR,
BROADCAST,
LOCAL,
LOCALNOANIM,
EMOTE,
PRIVATE_CHAT,
TEAM,
TEAMLOCAL,
GUILD,
GUILDNOTIFY,
PROPERTY,
ADMIN,
COMBATDAMAGE,
COMBATHEALING,
COMBATLOOT,
COMBATEXP,
COMBATDEATH,
GENERAL,
TRADE,
LFG,
USER
};
enum class eChatMessageResponseCode : uint8_t { enum class eChatMessageResponseCode : uint8_t {
SENT = 0, SENT = 0,

View File

@@ -1,36 +0,0 @@
#ifndef __POSITIONUPDATE__H__
#define __POSITIONUPDATE__H__
#include "NiPoint3.h"
#include "NiQuaternion.h"
struct RemoteInputInfo {
bool operator==(const RemoteInputInfo& other) {
return m_RemoteInputX == other.m_RemoteInputX && m_RemoteInputY == other.m_RemoteInputY && m_IsPowersliding == other.m_IsPowersliding && m_IsModified == other.m_IsModified;
}
float m_RemoteInputX = 0;
float m_RemoteInputY = 0;
bool m_IsPowersliding = false;
bool m_IsModified = false;
};
struct LocalSpaceInfo {
LWOOBJID objectId = LWOOBJID_EMPTY;
NiPoint3 position = NiPoint3Constant::ZERO;
NiPoint3 linearVelocity = NiPoint3Constant::ZERO;
};
struct PositionUpdate {
NiPoint3 position = NiPoint3Constant::ZERO;
NiQuaternion rotation = NiQuaternionConstant::IDENTITY;
bool onGround = false;
bool onRail = false;
NiPoint3 velocity = NiPoint3Constant::ZERO;
NiPoint3 angularVelocity = NiPoint3Constant::ZERO;
LocalSpaceInfo localSpaceInfo;
RemoteInputInfo remoteInputInfo;
};
#endif //!__POSITIONUPDATE__H__

View File

@@ -7,6 +7,7 @@
#include <cstdint> #include <cstdint>
#include <set> #include <set>
#include <string> #include <string>
#include "dTypeDefs.h"
#include "BitStream.h" #include "BitStream.h"
#include "BitStreamUtils.h" #include "BitStreamUtils.h"
#include "MessageType/Client.h" #include "MessageType/Client.h"
@@ -38,29 +39,6 @@ constexpr uint32_t lowFrameDelta = FRAMES_TO_MS(lowFramerate);
#define SEND_PACKET Game::server->Send(bitStream, sysAddr, false); #define SEND_PACKET Game::server->Send(bitStream, sysAddr, false);
#define SEND_PACKET_BROADCAST Game::server->Send(bitStream, UNASSIGNED_SYSTEM_ADDRESS, true); #define SEND_PACKET_BROADCAST Game::server->Send(bitStream, UNASSIGNED_SYSTEM_ADDRESS, true);
//=========== TYPEDEFS ==========
using LOT = int32_t; //!< A LOT
using LWOOBJID = int64_t; //!< An object ID (should be unsigned actually but ok)
using TSkillID = int32_t; //!< A skill ID
using LWOCLONEID = uint32_t; //!< Used for Clone IDs
using LWOMAPID = uint16_t; //!< Used for Map IDs
using LWOINSTANCEID = uint16_t; //!< Used for Instance IDs
using PROPERTYCLONELIST = uint32_t; //!< Used for Property Clone IDs
using StripId = uint32_t;
constexpr LWOOBJID LWOOBJID_EMPTY = 0; //!< An empty object ID
constexpr LOT LOT_NULL = -1; //!< A null LOT
constexpr int32_t LOOTTYPE_NONE = 0; //!< No loot type available
constexpr float SECONDARY_PRIORITY = 1.0f; //!< Secondary Priority
constexpr uint32_t INVENTORY_MAX = 9999999; //!< The Maximum Inventory Size
constexpr LWOCLONEID LWOCLONEID_INVALID = -1; //!< Invalid LWOCLONEID
constexpr LWOINSTANCEID LWOINSTANCEID_INVALID = -1; //!< Invalid LWOINSTANCEID
constexpr LWOMAPID LWOMAPID_INVALID = -1; //!< Invalid LWOMAPID
constexpr uint64_t LWOZONEID_INVALID = 0; //!< Invalid LWOZONEID
constexpr float PI = 3.14159f;
//============ STRUCTS ============== //============ STRUCTS ==============
struct LWOSCENEID { struct LWOSCENEID {

View File

@@ -0,0 +1,36 @@
#pragma once
#ifndef __ECHATCHANNEL__H__
#define __ECHATCHANNEL__H__
#include <cstdint>
enum class eChatChannel : uint8_t {
SYSTEMNOTIFY = 0,
SYSTEMWARNING,
SYSTEMERROR,
BROADCAST,
LOCAL,
LOCALNOANIM,
EMOTE,
PRIVATE_CHAT,
TEAM,
TEAMLOCAL,
GUILD,
GUILDNOTIFY,
PROPERTY,
ADMIN,
COMBATDAMAGE,
COMBATHEALING,
COMBATLOOT,
COMBATEXP,
COMBATDEATH,
GENERAL,
TRADE,
LFG,
USER
};
#endif //!__ECHATCHANNEL__H__

View File

@@ -0,0 +1,10 @@
#ifndef __ECHATMODE__H__
#define __ECHATMODE__H__
#include <cstdint>
enum class eChatMode : uint8_t {
RESTRICTED = 0,
UNRESTRICTED = 1
};
#endif //!__ECHATMODE__H__

29
dCommon/dTypeDefs.h Normal file
View File

@@ -0,0 +1,29 @@
#pragma once
#ifndef __DTYPEDEFS__H__
#define __DTYPEDEFS__H__
#include <cstdint>
using LOT = int32_t; //!< A LOT
using LWOOBJID = int64_t; //!< An object ID (should be unsigned actually but ok)
using TSkillID = int32_t; //!< A skill ID
using LWOCLONEID = uint32_t; //!< Used for Clone IDs
using LWOMAPID = uint16_t; //!< Used for Map IDs
using LWOINSTANCEID = uint16_t; //!< Used for Instance IDs
using PROPERTYCLONELIST = uint32_t; //!< Used for Property Clone IDs
using StripId = uint32_t;
constexpr LWOOBJID LWOOBJID_EMPTY = 0; //!< An empty object ID
constexpr LOT LOT_NULL = -1; //!< A null LOT
constexpr int32_t LOOTTYPE_NONE = 0; //!< No loot type available
constexpr float SECONDARY_PRIORITY = 1.0f; //!< Secondary Priority
constexpr uint32_t INVENTORY_MAX = 9999999; //!< The Maximum Inventory Size
constexpr LWOCLONEID LWOCLONEID_INVALID = -1; //!< Invalid LWOCLONEID
constexpr LWOINSTANCEID LWOINSTANCEID_INVALID = -1; //!< Invalid LWOINSTANCEID
constexpr LWOMAPID LWOMAPID_INVALID = -1; //!< Invalid LWOMAPID
constexpr uint64_t LWOZONEID_INVALID = 0; //!< Invalid LWOZONEID
constexpr float PI = 3.14159f;
#endif // __DTYPEDEFS__H__

View File

@@ -23,9 +23,9 @@
#include "eMissionTaskType.h" #include "eMissionTaskType.h"
#include "eTriggerEventType.h" #include "eTriggerEventType.h"
#include "eObjectBits.h" #include "eObjectBits.h"
#include "PositionUpdate.h"
#include "MessageType/Chat.h" #include "MessageType/Chat.h"
#include "PlayerManager.h" #include "PlayerManager.h"
#include "WorldPackets.h"
//Component includes: //Component includes:
#include "Component.h" #include "Component.h"
@@ -99,7 +99,7 @@
#include <ranges> #include <ranges>
Observable<Entity*, const PositionUpdate&> Entity::OnPlayerPositionUpdate; Observable<Entity*, const WorldPackets::PositionUpdate&> Entity::OnPlayerPositionUpdate;
Entity::Entity(const LWOOBJID& objectID, EntityInfo info, User* parentUser, Entity* parentEntity) { Entity::Entity(const LWOOBJID& objectID, EntityInfo info, User* parentUser, Entity* parentEntity) {
m_ObjectID = objectID; m_ObjectID = objectID;
@@ -2112,7 +2112,7 @@ uint8_t Entity::GetCollectibleID() const {
return collectible ? collectible->GetCollectibleId() : 0; return collectible ? collectible->GetCollectibleId() : 0;
} }
void Entity::ProcessPositionUpdate(PositionUpdate& update) { void Entity::ProcessPositionUpdate(WorldPackets::PositionUpdate& update) {
if (!IsPlayer()) return; if (!IsPlayer()) return;
auto* controllablePhysicsComponent = GetComponent<ControllablePhysicsComponent>(); auto* controllablePhysicsComponent = GetComponent<ControllablePhysicsComponent>();
if (!controllablePhysicsComponent) return; if (!controllablePhysicsComponent) return;

View File

@@ -20,6 +20,9 @@ namespace GameMessages {
struct ChildLoaded; struct ChildLoaded;
struct PlayerResurrectionFinished; struct PlayerResurrectionFinished;
}; };
namespace WorldPackets {
struct PositionUpdate;
};
namespace MessageType { namespace MessageType {
enum class Game : uint16_t; enum class Game : uint16_t;
@@ -316,7 +319,7 @@ public:
Entity* GetScheduledKiller() { return m_ScheduleKiller; } Entity* GetScheduledKiller() { return m_ScheduleKiller; }
void ProcessPositionUpdate(PositionUpdate& update); void ProcessPositionUpdate(WorldPackets::PositionUpdate& update);
// Scale will only be communicated to the client when the construction packet is sent // Scale will only be communicated to the client when the construction packet is sent
void SetScale(const float scale) { m_Scale = scale; }; void SetScale(const float scale) { m_Scale = scale; };
@@ -328,7 +331,7 @@ public:
/** /**
* @brief The observable for player entity position updates. * @brief The observable for player entity position updates.
*/ */
static Observable<Entity*, const PositionUpdate&> OnPlayerPositionUpdate; static Observable<Entity*, const WorldPackets::PositionUpdate&> OnPlayerPositionUpdate;
protected: protected:
LWOOBJID m_ObjectID; LWOOBJID m_ObjectID;

View File

@@ -8,7 +8,7 @@
#include "Game.h" #include "Game.h"
#include "Logger.h" #include "Logger.h"
#include "User.h" #include "User.h"
#include "WorldPackets.h" #include "ClientPackets.h"
#include "Character.h" #include "Character.h"
#include "BitStream.h" #include "BitStream.h"
#include "ObjectIDManager.h" #include "ObjectIDManager.h"
@@ -308,13 +308,17 @@ void UserManager::CreateCharacter(const SystemAddress& sysAddr, Packet* packet)
if (!name.empty() && Database::Get()->IsNameInUse(name)) { if (!name.empty() && Database::Get()->IsNameInUse(name)) {
LOG("AccountID: %i chose unavailable name: %s", u->GetAccountID(), name.c_str()); LOG("AccountID: %i chose unavailable name: %s", u->GetAccountID(), name.c_str());
WorldPackets::SendCharacterCreationResponse(sysAddr, eCharacterCreationResponse::CUSTOM_NAME_IN_USE); ClientPackets::CharacterCreationResponse response;
response.response = eCharacterCreationResponse::CUSTOM_NAME_IN_USE;
response.Send(sysAddr);
return; return;
} }
if (Database::Get()->IsNameInUse(predefinedName)) { if (Database::Get()->IsNameInUse(predefinedName)) {
LOG("AccountID: %i chose unavailable predefined name: %s", u->GetAccountID(), predefinedName.c_str()); LOG("AccountID: %i chose unavailable predefined name: %s", u->GetAccountID(), predefinedName.c_str());
WorldPackets::SendCharacterCreationResponse(sysAddr, eCharacterCreationResponse::PREDEFINED_NAME_IN_USE); ClientPackets::CharacterCreationResponse response;
response.response = eCharacterCreationResponse::PREDEFINED_NAME_IN_USE;
response.Send(sysAddr);
return; return;
} }
@@ -328,7 +332,8 @@ void UserManager::CreateCharacter(const SystemAddress& sysAddr, Packet* packet)
ObjectIDManager::RequestPersistentID([=, this](uint32_t objectID) { ObjectIDManager::RequestPersistentID([=, this](uint32_t objectID) {
if (Database::Get()->GetCharacterInfo(objectID)) { if (Database::Get()->GetCharacterInfo(objectID)) {
LOG("Character object id unavailable, check object_id_tracker!"); LOG("Character object id unavailable, check object_id_tracker!");
WorldPackets::SendCharacterCreationResponse(sysAddr, eCharacterCreationResponse::OBJECT_ID_UNAVAILABLE); ClientPackets::CharacterCreationResponse response;
response.response = eCharacterCreationResponse::OBJECT_ID_UNAVAILABLE;
return; return;
} }
@@ -394,7 +399,9 @@ void UserManager::CreateCharacter(const SystemAddress& sysAddr, Packet* packet)
//Now finally insert our character xml: //Now finally insert our character xml:
Database::Get()->InsertCharacterXml(objectID, xml.str()); Database::Get()->InsertCharacterXml(objectID, xml.str());
WorldPackets::SendCharacterCreationResponse(sysAddr, eCharacterCreationResponse::SUCCESS); ClientPackets::CharacterCreationResponse response;
response.response = eCharacterCreationResponse::SUCCESS;
response.Send(sysAddr);
UserManager::RequestCharacterList(sysAddr); UserManager::RequestCharacterList(sysAddr);
}); });
} }
@@ -420,9 +427,11 @@ void UserManager::DeleteCharacter(const SystemAddress& sysAddr, Packet* packet)
"User %i tried to delete a character that it does not own!", "User %i tried to delete a character that it does not own!",
u->GetAccountID()); u->GetAccountID());
ClientPackets::CharacterDeleteResponse response;
if (!hasCharacter) { if (!hasCharacter) {
WorldPackets::SendCharacterDeleteResponse(sysAddr, false); response.success = false;
} else { } else {
response.success = true;
LOG("Deleting character %i", charID); LOG("Deleting character %i", charID);
Database::Get()->DeleteCharacter(charID); Database::Get()->DeleteCharacter(charID);
@@ -430,9 +439,9 @@ void UserManager::DeleteCharacter(const SystemAddress& sysAddr, Packet* packet)
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, MessageType::Chat::UNEXPECTED_DISCONNECT); BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, MessageType::Chat::UNEXPECTED_DISCONNECT);
bitStream.Write(objectID); bitStream.Write(objectID);
Game::chatServer->Send(&bitStream, SYSTEM_PRIORITY, RELIABLE, 0, Game::chatSysAddr, false); Game::chatServer->Send(&bitStream, SYSTEM_PRIORITY, RELIABLE, 0, Game::chatSysAddr, false);
WorldPackets::SendCharacterDeleteResponse(sysAddr, true);
} }
response.Send(sysAddr);
} }
void UserManager::RenameCharacter(const SystemAddress& sysAddr, Packet* packet) { void UserManager::RenameCharacter(const SystemAddress& sysAddr, Packet* packet) {
@@ -473,32 +482,34 @@ void UserManager::RenameCharacter(const SystemAddress& sysAddr, Packet* packet)
return false; return false;
}); });
ClientPackets::CharacterRenameResponse response;
if (!ownsCharacter || !character) { if (!ownsCharacter || !character) {
WorldPackets::SendCharacterRenameResponse(sysAddr, eRenameResponse::UNKNOWN_ERROR); response.response = eRenameResponse::UNKNOWN_ERROR;
} else if (ownsCharacter && character) { } else if (ownsCharacter && character) {
if (newName == character->GetName()) { if (newName == character->GetName()) {
WorldPackets::SendCharacterRenameResponse(sysAddr, eRenameResponse::NAME_UNAVAILABLE); response.response = eRenameResponse::NAME_UNAVAILABLE;
return;
}
if (!Database::Get()->GetCharacterInfo(newName)) { } else if (!Database::Get()->GetCharacterInfo(newName)) {
if (IsNamePreapproved(newName)) { if (IsNamePreapproved(newName)) {
Database::Get()->SetCharacterName(charID, newName); Database::Get()->SetCharacterName(charID, newName);
LOG("Character %s now known as %s", character->GetName().c_str(), newName.c_str()); LOG("Character %s now known as %s", character->GetName().c_str(), newName.c_str());
WorldPackets::SendCharacterRenameResponse(sysAddr, eRenameResponse::SUCCESS); response.response = eRenameResponse::SUCCESS;
UserManager::RequestCharacterList(sysAddr);
} else { } else {
Database::Get()->SetPendingCharacterName(charID, newName); Database::Get()->SetPendingCharacterName(charID, newName);
LOG("Character %s has been renamed to %s and is pending approval by a moderator.", character->GetName().c_str(), newName.c_str()); LOG("Character %s has been renamed to %s and is pending approval by a moderator.", character->GetName().c_str(), newName.c_str());
WorldPackets::SendCharacterRenameResponse(sysAddr, eRenameResponse::SUCCESS); response.response = eRenameResponse::SUCCESS;
UserManager::RequestCharacterList(sysAddr);
} }
} else { } else {
WorldPackets::SendCharacterRenameResponse(sysAddr, eRenameResponse::NAME_IN_USE); response.response = eRenameResponse::NAME_IN_USE;
} }
} else { } else {
LOG("Unknown error occurred when renaming character, either hasCharacter or character variable != true."); LOG("Unknown error occurred when renaming character, either hasCharacter or character variable != true.");
WorldPackets::SendCharacterRenameResponse(sysAddr, eRenameResponse::UNKNOWN_ERROR); response.response = eRenameResponse::UNKNOWN_ERROR;
}
response.Send(sysAddr);
if (response.response == eRenameResponse::SUCCESS) {
UserManager::RequestCharacterList(sysAddr);
} }
} }
@@ -537,7 +548,11 @@ void UserManager::LoginCharacter(const SystemAddress& sysAddr, uint32_t playerID
character->SetZoneInstance(zoneInstance); character->SetZoneInstance(zoneInstance);
character->SetZoneClone(zoneClone); character->SetZoneClone(zoneClone);
} }
WorldPackets::SendTransferToWorld(sysAddr, serverIP, serverPort, mythranShift); ClientPackets::TransferToWorld response;
response.serverIP = serverIP;
response.serverPort = serverPort;
response.mythranShift = mythranShift;
response.Send(sysAddr);
return; return;
}); });
} else { } else {

View File

@@ -5,7 +5,7 @@
#include "Character.h" #include "Character.h"
#include "CharacterComponent.h" #include "CharacterComponent.h"
#include "ChatPackets.h" #include "ChatPackets.h"
#include "WorldPackets.h" #include "ClientPackets.h"
#include "EntityManager.h" #include "EntityManager.h"
#include "Game.h" #include "Game.h"
#include "ZoneInstanceManager.h" #include "ZoneInstanceManager.h"
@@ -55,7 +55,11 @@ void PropertyTeleportBehavior::Handle(BehaviorContext* context, RakNet::BitStrea
entity->GetCharacter()->SaveXMLToDatabase(); entity->GetCharacter()->SaveXMLToDatabase();
WorldPackets::SendTransferToWorld(sysAddr, serverIP, serverPort, mythranShift); ClientPackets::TransferToWorld response;
response.serverIP = serverIP;
response.serverPort = serverPort;
response.mythranShift = mythranShift;
response.Send(sysAddr);
return; return;
}); });
} }

View File

@@ -7,7 +7,7 @@
#include "ZoneInstanceManager.h" #include "ZoneInstanceManager.h"
#include "Game.h" #include "Game.h"
#include "Logger.h" #include "Logger.h"
#include "WorldPackets.h" #include "ClientPackets.h"
#include "EntityManager.h" #include "EntityManager.h"
#include "ChatPackets.h" #include "ChatPackets.h"
#include "BitStreamUtils.h" #include "BitStreamUtils.h"
@@ -537,7 +537,11 @@ void ActivityInstance::StartZone() {
player->GetCharacter()->SetZoneClone(zoneClone); player->GetCharacter()->SetZoneClone(zoneClone);
} }
WorldPackets::SendTransferToWorld(player->GetSystemAddress(), serverIP, serverPort, mythranShift); ClientPackets::TransferToWorld response;
response.serverIP = serverIP;
response.serverPort = serverPort;
response.mythranShift = mythranShift;
response.Send(player->GetSystemAddress());
return; return;
}); });
} }

View File

@@ -21,7 +21,7 @@
#include "CDRewardCodesTable.h" #include "CDRewardCodesTable.h"
#include "Mail.h" #include "Mail.h"
#include "ZoneInstanceManager.h" #include "ZoneInstanceManager.h"
#include "WorldPackets.h" #include "ClientPackets.h"
#include "MessageType/Game.h" #include "MessageType/Game.h"
#include <ctime> #include <ctime>
@@ -868,8 +868,11 @@ void CharacterComponent::SendToZone(LWOMAPID zoneId, LWOCLONEID cloneId) const {
character->SaveXMLToDatabase(); character->SaveXMLToDatabase();
} }
WorldPackets::SendTransferToWorld(sysAddr, serverIP, serverPort, mythranShift); ClientPackets::TransferToWorld response;
response.serverIP = serverIP;
response.serverPort = serverPort;
response.mythranShift = mythranShift;
response.Send(sysAddr);
Game::entityManager->DestructEntity(entity); Game::entityManager->DestructEntity(entity);
}); });
} }

View File

@@ -34,7 +34,7 @@ void HavokVehiclePhysicsComponent::SetIsOnRail(bool val) {
m_IsOnRail = val; m_IsOnRail = val;
} }
void HavokVehiclePhysicsComponent::SetRemoteInputInfo(const RemoteInputInfo& remoteInputInfo) { void HavokVehiclePhysicsComponent::SetRemoteInputInfo(const WorldPackets::PositionUpdate::RemoteInputInfo& remoteInputInfo) {
if (remoteInputInfo == m_RemoteInputInfo) return; if (remoteInputInfo == m_RemoteInputInfo) return;
this->m_RemoteInputInfo = remoteInputInfo; this->m_RemoteInputInfo = remoteInputInfo;
m_DirtyPosition = true; m_DirtyPosition = true;

View File

@@ -4,7 +4,7 @@
#include "Entity.h" #include "Entity.h"
#include "PhysicsComponent.h" #include "PhysicsComponent.h"
#include "eReplicaComponentType.h" #include "eReplicaComponentType.h"
#include "PositionUpdate.h" #include "WorldPackets.h"
/** /**
* Physics component for vehicles. * Physics component for vehicles.
@@ -65,7 +65,7 @@ public:
*/ */
const bool GetIsOnRail() const { return m_IsOnRail; } const bool GetIsOnRail() const { return m_IsOnRail; }
void SetRemoteInputInfo(const RemoteInputInfo&); void SetRemoteInputInfo(const WorldPackets::PositionUpdate::RemoteInputInfo& remoteInputInfo);
private: private:
NiPoint3 m_Velocity; NiPoint3 m_Velocity;
@@ -76,5 +76,5 @@ private:
float m_SoftUpdate = 0; float m_SoftUpdate = 0;
uint32_t m_EndBehavior; uint32_t m_EndBehavior;
RemoteInputInfo m_RemoteInputInfo; WorldPackets::PositionUpdate::RemoteInputInfo m_RemoteInputInfo;
}; };

View File

@@ -17,7 +17,7 @@
#include "CppScripts.h" #include "CppScripts.h"
#include "UserManager.h" #include "UserManager.h"
#include "ZoneInstanceManager.h" #include "ZoneInstanceManager.h"
#include "WorldPackets.h" #include "ClientPackets.h"
#include "Item.h" #include "Item.h"
#include "ZCompression.h" #include "ZCompression.h"
#include "dConfig.h" #include "dConfig.h"
@@ -4936,7 +4936,11 @@ void GameMessages::HandleFireEventServerSide(RakNet::BitStream& inStream, Entity
character->SetZoneClone(zoneClone); character->SetZoneClone(zoneClone);
} }
WorldPackets::SendTransferToWorld(sysAddr, serverIP, serverPort, mythranShift); ClientPackets::TransferToWorld response;
response.serverIP = serverIP;
response.serverPort = serverPort;
response.mythranShift = mythranShift;
response.Send(sysAddr);
return; return;
}); });
} }

View File

@@ -17,7 +17,7 @@
#include "UserManager.h" #include "UserManager.h"
#include "User.h" #include "User.h"
#include "VanityUtilities.h" #include "VanityUtilities.h"
#include "WorldPackets.h" #include "ClientPackets.h"
#include "ZoneInstanceManager.h" #include "ZoneInstanceManager.h"
// Database // Database
@@ -73,7 +73,13 @@ namespace DEVGMCommands {
bool success = user->GetMaxGMLevel() >= level; bool success = user->GetMaxGMLevel() >= level;
if (success) { if (success) {
WorldPackets::SendGMLevelChange(entity->GetSystemAddress(), success, user->GetMaxGMLevel(), entity->GetGMLevel(), level); ClientPackets::GMLevelChange response;
response.success = success;
response.prevLevel = entity->GetGMLevel();
response.newLevel = level;
response.highestLevel = user->GetMaxGMLevel();
response.Send(entity->GetSystemAddress());
GameMessages::SendChatModeUpdate(entity->GetObjectID(), level); GameMessages::SendChatModeUpdate(entity->GetObjectID(), level);
entity->SetGMLevel(level); entity->SetGMLevel(level);
LOG("User %s (%i) has changed their GM level to %i for charID %llu", user->GetUsername().c_str(), user->GetAccountID(), level, entity->GetObjectID()); LOG("User %s (%i) has changed their GM level to %i for charID %llu", user->GetUsername().c_str(), user->GetAccountID(), level, entity->GetObjectID());
@@ -81,7 +87,13 @@ namespace DEVGMCommands {
#ifndef DEVELOPER_SERVER #ifndef DEVELOPER_SERVER
if ((entity->GetGMLevel() > user->GetMaxGMLevel()) || (entity->GetGMLevel() > eGameMasterLevel::CIVILIAN && user->GetMaxGMLevel() == eGameMasterLevel::JUNIOR_DEVELOPER)) { if ((entity->GetGMLevel() > user->GetMaxGMLevel()) || (entity->GetGMLevel() > eGameMasterLevel::CIVILIAN && user->GetMaxGMLevel() == eGameMasterLevel::JUNIOR_DEVELOPER)) {
WorldPackets::SendGMLevelChange(entity->GetSystemAddress(), true, user->GetMaxGMLevel(), entity->GetGMLevel(), eGameMasterLevel::CIVILIAN); ClientPackets::GMLevelChange response;
response.success = false;
response.prevLevel = entity->GetGMLevel();
response.newLevel = eGameMasterLevel::CIVILIAN;
response.highestLevel = user->GetMaxGMLevel();
response.Send(entity->GetSystemAddress());
GameMessages::SendChatModeUpdate(entity->GetObjectID(), eGameMasterLevel::CIVILIAN); GameMessages::SendChatModeUpdate(entity->GetObjectID(), eGameMasterLevel::CIVILIAN);
entity->SetGMLevel(eGameMasterLevel::CIVILIAN); entity->SetGMLevel(eGameMasterLevel::CIVILIAN);
@@ -1061,7 +1073,11 @@ namespace DEVGMCommands {
entity->GetCharacter()->SaveXMLToDatabase(); entity->GetCharacter()->SaveXMLToDatabase();
WorldPackets::SendTransferToWorld(sysAddr, serverIP, serverPort, mythranShift); ClientPackets::TransferToWorld response;
response.serverIP = serverIP;
response.serverPort = serverPort;
response.mythranShift = mythranShift;
response.Send(sysAddr);
return; return;
}); });
} else { } else {

View File

@@ -10,7 +10,7 @@
#include "PlayerManager.h" #include "PlayerManager.h"
#include "SlashCommandHandler.h" #include "SlashCommandHandler.h"
#include "VanityUtilities.h" #include "VanityUtilities.h"
#include "WorldPackets.h" #include "ClientPackets.h"
#include "ZoneInstanceManager.h" #include "ZoneInstanceManager.h"
#include "Database.h" #include "Database.h"
@@ -179,7 +179,11 @@ namespace GMZeroCommands {
entity->GetCharacter()->SaveXMLToDatabase(); entity->GetCharacter()->SaveXMLToDatabase();
WorldPackets::SendTransferToWorld(sysAddr, serverIP, serverPort, mythranShift); ClientPackets::TransferToWorld response;
response.serverIP = serverIP;
response.serverPort = serverPort;
response.mythranShift = mythranShift;
response.Send(sysAddr);
}); });
} }
@@ -205,7 +209,11 @@ namespace GMZeroCommands {
entity->GetCharacter()->SaveXMLToDatabase(); entity->GetCharacter()->SaveXMLToDatabase();
WorldPackets::SendTransferToWorld(sysAddr, serverIP, serverPort, mythranShift); ClientPackets::TransferToWorld response;
response.serverIP = serverIP;
response.serverPort = serverPort;
response.mythranShift = mythranShift;
response.Send(sysAddr);
}); });
} }

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

@@ -29,4 +29,5 @@ target_include_directories(dNet PRIVATE
"${PROJECT_SOURCE_DIR}/dGame/dInventory" # via PossessableComponent.h "${PROJECT_SOURCE_DIR}/dGame/dInventory" # via PossessableComponent.h
"${PROJECT_SOURCE_DIR}/dGame/dUtilities" # via Item.h "${PROJECT_SOURCE_DIR}/dGame/dUtilities" # via Item.h
"${PROJECT_SOURCE_DIR}/dScripts" # transitive through components "${PROJECT_SOURCE_DIR}/dScripts" # transitive through components
"${PROJECT_SOURCE_DIR}/dChatFilter" # for chat message handling
) )

View File

@@ -5,119 +5,123 @@
#include "ClientPackets.h" #include "ClientPackets.h"
#include "dCommonVars.h" #include "dCommonVars.h"
#include "PositionUpdate.h" #include "LDFFormat.h"
#include "ZCompression.h"
ChatMessage ClientPackets::HandleChatMessage(Packet* packet) { namespace ClientPackets {
CINSTREAM_SKIP_HEADER; void LoadStaticZone::Serialize(RakNet::BitStream &bitStream) const {
bitStream.Write<uint16_t>(zoneID.GetMapID());
ChatMessage message; bitStream.Write<uint16_t>(zoneID.GetInstanceID());
uint32_t messageLength; bitStream.Write<uint32_t>(zoneID.GetCloneID());
bitStream.Write<uint32_t>(checksum);
inStream.Read(message.chatChannel); bitStream.Write<uint8_t>(editorEnabled);
inStream.Read(message.unknown); bitStream.Write<uint8_t>(editorLevel);
inStream.Read(messageLength); bitStream.Write(position.x);
bitStream.Write(position.y);
for (uint32_t i = 0; i < (messageLength - 1); ++i) { bitStream.Write(position.z);
uint16_t character; bitStream.Write<uint32_t>(instanceType);
inStream.Read(character); }
message.message.push_back(character); void CharacterCreationResponse::Serialize(RakNet::BitStream &bitStream) const {
bitStream.Write(response);
} }
return message; void CharacterRenameResponse::Serialize(RakNet::BitStream &bitStream) const {
bitStream.Write(response);
} }
PositionUpdate ClientPackets::HandleClientPositionUpdate(Packet* packet) { void CharacterDeleteResponse::Serialize(RakNet::BitStream &bitStream) const {
PositionUpdate update; bitStream.Write<uint8_t>(success);
CINSTREAM_SKIP_HEADER;
inStream.Read(update.position.x);
inStream.Read(update.position.y);
inStream.Read(update.position.z);
inStream.Read(update.rotation.x);
inStream.Read(update.rotation.y);
inStream.Read(update.rotation.z);
inStream.Read(update.rotation.w);
inStream.Read(update.onGround);
inStream.Read(update.onRail);
bool velocityFlag = false;
inStream.Read(velocityFlag);
if (velocityFlag) {
inStream.Read(update.velocity.x);
inStream.Read(update.velocity.y);
inStream.Read(update.velocity.z);
} }
bool angVelocityFlag = false; void TransferToWorld::Serialize(RakNet::BitStream &bitStream) const {
inStream.Read(angVelocityFlag); bitStream.Write(LUString(serverIP));
if (angVelocityFlag) { bitStream.Write<uint16_t>(serverPort);
inStream.Read(update.angularVelocity.x); bitStream.Write<uint8_t>(mythranShift);
inStream.Read(update.angularVelocity.y);
inStream.Read(update.angularVelocity.z);
} }
// TODO figure out how to use these. Ignoring for now, but reading in if they exist. void ServerState::Serialize(RakNet::BitStream &bitStream) const {
bool hasLocalSpaceInfo{}; bitStream.Write<uint8_t>(serverReady);
if (inStream.Read(hasLocalSpaceInfo) && hasLocalSpaceInfo) {
inStream.Read(update.localSpaceInfo.objectId);
inStream.Read(update.localSpaceInfo.position.x);
inStream.Read(update.localSpaceInfo.position.y);
inStream.Read(update.localSpaceInfo.position.z);
bool hasLinearVelocity = false;
if (inStream.Read(hasLinearVelocity) && hasLinearVelocity) {
inStream.Read(update.localSpaceInfo.linearVelocity.x);
inStream.Read(update.localSpaceInfo.linearVelocity.y);
inStream.Read(update.localSpaceInfo.linearVelocity.z);
} }
void CreateCharacter::Serialize(RakNet::BitStream &bitStream) const {
RakNet::BitStream data;
data.Write<uint32_t>(7); // LDF key count
LDFData<LWOOBJID>(u"objid", objid).WriteToPacket(data);
LDFData<LOT>(u"template", templateID).WriteToPacket(data);
LDFData<std::u16string>(u"name", name).WriteToPacket(data);
LDFData<int32_t>(u"gmlevel", static_cast<int32_t>(gmLevel)).WriteToPacket(data);
LDFData<int32_t>(u"chatmode", static_cast<int32_t>(chatMode)).WriteToPacket(data);
LDFData<std::string_view>(u"xmlData", xmlData).WriteToPacket(data);
LDFData<int64_t>(u"reputation", reputation).WriteToPacket(data);
// Compress the data before sending:
const uint32_t reservedSize = ZCompression::GetMaxCompressedLength(data.GetNumberOfBytesUsed());
uint8_t* compressedData = new uint8_t[reservedSize];
if (!compressedData) throw std::runtime_error("Failed to allocate memory for compressed data");
size_t size = ZCompression::Compress(data.GetData(), data.GetNumberOfBytesUsed(), compressedData, reservedSize);
assert(size <= reservedSize);
bitStream.Write<uint32_t>(size + 9); // size of data + header bytes (8)
bitStream.Write<uint8_t>(1); // compressed boolean, true
bitStream.Write<uint32_t>(data.GetNumberOfBytesUsed());
bitStream.Write<uint32_t>(size);
/**
* In practice, this warning serves no purpose for us. We allocate the max memory needed on the heap
* and then compress the data. In the off chance that the compression actually increases the size,
* an assertion is done to prevent bad data from being saved or sent.
*/
#pragma warning(disable:6385) // C6385 Reading invalid data from 'compressedData'.
bitStream.WriteAlignedBytes(compressedData, size);
#pragma warning(default:6385)
delete[] compressedData;
};
void ChatModerationString::Serialize(RakNet::BitStream &bitStream) const {
bitStream.Write<uint8_t>(rejectedWords.empty()); // Accepted
bitStream.Write<uint16_t>(0); // padding
bitStream.Write(chatChannel);
bitStream.Write(chatMode);
bitStream.Write(LUWString(receiver, 42));
// Write the rejected words
// There has to be 64 items written so we need to pad the rest with 0s
int toWrite = 64;
for (auto it : rejectedWords) {
if (toWrite <= 0) return;
bitStream.Write<uint8_t>(it.first); // start index
bitStream.Write<uint8_t>(it.second); // length
toWrite--;
}
for (; toWrite <= 0; toWrite--) {
bitStream.Write<uint16_t>(0);
} }
bool hasRemoteInputInfo{};
if (inStream.Read(hasRemoteInputInfo) && hasRemoteInputInfo) {
inStream.Read(update.remoteInputInfo.m_RemoteInputX);
inStream.Read(update.remoteInputInfo.m_RemoteInputY);
inStream.Read(update.remoteInputInfo.m_IsPowersliding);
inStream.Read(update.remoteInputInfo.m_IsModified);
} }
return update; void GMLevelChange::Serialize(RakNet::BitStream &bitStream) const {
bitStream.Write<uint8_t>(success);
bitStream.Write(static_cast<uint16_t>(highestLevel));
bitStream.Write(static_cast<uint16_t>(prevLevel));
bitStream.Write(static_cast<uint16_t>(newLevel));
} }
ChatModerationRequest ClientPackets::HandleChatModerationRequest(Packet* packet) { void DebugOutput::Serialize(RakNet::BitStream &bitStream) const {
CINSTREAM_SKIP_HEADER; bitStream.Write<uint32_t>(data.size());
bitStream.Write(data);
ChatModerationRequest request;
inStream.Read(request.chatLevel);
inStream.Read(request.requestID);
for (uint32_t i = 0; i < 42; ++i) {
uint16_t character;
inStream.Read(character);
request.receiver.push_back(static_cast<uint8_t>(character));
} }
if (!request.receiver.empty()) { void HTTPMonitorInfoResponse::Serialize(RakNet::BitStream &bitStream) const {
if (std::string(request.receiver.c_str(), 4) == "[GM]") { // Shift the string forward if we are speaking to a GM as the client appends "[GM]" if they are bitStream.Write<uint16_t>(port);
request.receiver = std::string(request.receiver.c_str() + 4, request.receiver.size() - 4); bitStream.Write<uint8_t>(openWeb);
bitStream.Write<uint8_t>(supportsSum);
bitStream.Write<uint8_t>(supportsDetail);
bitStream.Write<uint8_t>(supportsWho);
bitStream.Write<uint8_t>(supportsObjects);
} }
} }
uint16_t messageLength;
inStream.Read(messageLength);
for (uint32_t i = 0; i < messageLength; ++i) {
uint16_t character;
inStream.Read(character);
request.message.push_back(static_cast<uint8_t>(character));
}
return request;
}
int32_t ClientPackets::SendTop5HelpIssues(Packet* packet) {
CINSTREAM_SKIP_HEADER;
int32_t language = 0;
inStream.Read(language);
return language;
}

View File

@@ -8,29 +8,122 @@
#include <cstdint> #include <cstdint>
#include <string> #include <string>
#include "BitStreamUtils.h"
#include "eGameMasterLevel.h"
#include "eChatChannel.h"
#include "dCommonVars.h"
class PositionUpdate; class PositionUpdate;
struct Packet; struct Packet;
struct ChatMessage { class User;
uint8_t chatChannel = 0; struct SystemAddress;
uint16_t unknown = 0; enum class eCharacterCreationResponse : uint8_t;
std::u16string message; enum class eRenameResponse : uint8_t;
};
struct ChatModerationRequest {
uint8_t chatLevel = 0;
uint8_t requestID = 0;
std::string receiver;
std::string message;
};
namespace ClientPackets { namespace ClientPackets {
ChatMessage HandleChatMessage(Packet* packet); struct LoadStaticZone : public LUBitStream {
PositionUpdate HandleClientPositionUpdate(Packet* packet); LWOZONEID zoneID;
ChatModerationRequest HandleChatModerationRequest(Packet* packet); uint32_t checksum = 0;
int32_t SendTop5HelpIssues(Packet* packet); bool editorEnabled = false;
uint8_t editorLevel = 0;
NiPoint3 position = NiPoint3Constant::ZERO;
uint32_t instanceType = 0;
LoadStaticZone() : LUBitStream(eConnectionType::CLIENT, MessageType::Client::LOAD_STATIC_ZONE) {};
void Serialize(RakNet::BitStream& bitStream) const override;
};
struct CharacterCreationResponse : public LUBitStream {
eCharacterCreationResponse response;
CharacterCreationResponse() : LUBitStream(eConnectionType::CLIENT, MessageType::Client::CHARACTER_CREATE_RESPONSE) {};
void Serialize(RakNet::BitStream& bitStream) const override;
};
struct CharacterRenameResponse : public LUBitStream {
eRenameResponse response;
CharacterRenameResponse() : LUBitStream(eConnectionType::CLIENT, MessageType::Client::CHARACTER_RENAME_RESPONSE) {};
void Serialize(RakNet::BitStream& bitStream) const override;
};
struct CharacterDeleteResponse : public LUBitStream {
bool success;
CharacterDeleteResponse() : LUBitStream(eConnectionType::CLIENT, MessageType::Client::DELETE_CHARACTER_RESPONSE) {};
void Serialize(RakNet::BitStream& bitStream) const override;
};
struct TransferToWorld : public LUBitStream {
std::string serverIP;
uint32_t serverPort = 0;
bool mythranShift = false;
TransferToWorld() : LUBitStream(eConnectionType::CLIENT, MessageType::Client::TRANSFER_TO_WORLD) {};
void Serialize(RakNet::BitStream& bitStream) const override;
};
struct ServerState : public LUBitStream {
bool serverReady = false;
ServerState() : LUBitStream(eConnectionType::CLIENT, MessageType::Client::SERVER_STATES) {};
void Serialize(RakNet::BitStream& bitStream) const override;
};
struct CreateCharacter : public LUBitStream {
LWOOBJID objid = LWOOBJID_EMPTY;
LOT templateID = 1;
std::u16string name;
eGameMasterLevel gmLevel = eGameMasterLevel::CIVILIAN;
int32_t chatMode = 0;
std::string_view xmlData;
int64_t reputation = 0;
CreateCharacter() : LUBitStream(eConnectionType::CLIENT, MessageType::Client::CREATE_CHARACTER) {};
void Serialize(RakNet::BitStream& bitStream) const override;
};
struct ChatModerationString : public LUBitStream {
eChatChannel chatChannel = eChatChannel::SYSTEMNOTIFY;
uint8_t chatMode = 0;
std::string receiver;
std::set<std::pair<uint8_t, uint8_t>> rejectedWords;
ChatModerationString() : LUBitStream(eConnectionType::CLIENT, MessageType::Client::CHAT_MODERATION_STRING) {};
void Serialize(RakNet::BitStream& bitStream) const override;
};
struct GMLevelChange : public LUBitStream {
bool success = false;
eGameMasterLevel highestLevel = eGameMasterLevel::CIVILIAN;
eGameMasterLevel prevLevel = eGameMasterLevel::CIVILIAN;
eGameMasterLevel newLevel = eGameMasterLevel::CIVILIAN;
GMLevelChange() : LUBitStream(eConnectionType::CLIENT, MessageType::Client::MAKE_GM_RESPONSE) {};
void Serialize(RakNet::BitStream& bitStream) const override;
};
struct DebugOutput : public LUBitStream {
std::string data;
DebugOutput() : LUBitStream(eConnectionType::CLIENT, MessageType::Client::DEBUG_OUTPUT) {};
void Serialize(RakNet::BitStream& bitStream) const override;
};
struct HTTPMonitorInfoResponse : public LUBitStream {
uint16_t port = 80;
bool openWeb = false;
bool supportsSum = false;
bool supportsDetail = false;
bool supportsWho = false;
bool supportsObjects = false;
HTTPMonitorInfoResponse() : LUBitStream(eConnectionType::CLIENT, MessageType::Client::HTTP_MONITOR_INFO_RESPONSE) {};
void Serialize(RakNet::BitStream& bitStream) const override;
};
}; };
#endif // CLIENTPACKETS_H #endif // CLIENTPACKETS_H

View File

@@ -1,186 +1,246 @@
#include "WorldPackets.h" #include "WorldPackets.h"
#include "dCommonVars.h" #include "Amf3.h"
#include "BitStream.h" #include "dConfig.h"
#include "GeneralUtils.h" #include "GameMessages.h"
#include "Logger.h" #include "Entity.h"
#include "Game.h" #include "EntityManager.h"
#include "LDFFormat.h" #include "UserManager.h"
#include "dServer.h" #include "User.h"
#include "ZCompression.h" #include "Character.h"
#include "eConnectionType.h" #include "dChatFilter.h"
#include "BitStreamUtils.h" #include "ChatPackets.h"
#include "ClientPackets.h"
#include "Database.h"
#include <iostream> namespace WorldPackets {
void HTTPMonitorInfo::Serialize(RakNet::BitStream &bitStream) const { bool UIHelpTop5::Deserialize(RakNet::BitStream& bitStream) {
bitStream.Write(port); VALIDATE_READ(bitStream.Read(languageCode));
bitStream.Write<uint8_t>(openWeb); return true;
bitStream.Write<uint8_t>(supportsSum);
bitStream.Write<uint8_t>(supportsDetail);
bitStream.Write<uint8_t>(supportsWho);
bitStream.Write<uint8_t>(supportsObjects);
} }
void WorldPackets::SendLoadStaticZone(const SystemAddress& sysAddr, float x, float y, float z, uint32_t checksum, LWOZONEID zone) { void UIHelpTop5::Handle() {
RakNet::BitStream bitStream; Entity* player = Game::entityManager->GetEntity(objectID);
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, MessageType::Client::LOAD_STATIC_ZONE); if (!player) {
LOG("Unable to get player for UIHelpTop5");
bitStream.Write<uint16_t>(zone.GetMapID()); return;
bitStream.Write<uint16_t>(zone.GetInstanceID());
//bitStream.Write<uint32_t>(zone.GetCloneID());
bitStream.Write(0);
bitStream.Write(checksum);
bitStream.Write<uint16_t>(0); // ??
bitStream.Write(x);
bitStream.Write(y);
bitStream.Write(z);
bitStream.Write<uint32_t>(0); // Change this to eventually use 4 on activity worlds
SEND_PACKET;
} }
void WorldPackets::SendCharacterCreationResponse(const SystemAddress& sysAddr, eCharacterCreationResponse response) { auto sysAddr = player->GetSystemAddress();
RakNet::BitStream bitStream; if (sysAddr == UNASSIGNED_SYSTEM_ADDRESS) {
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, MessageType::Client::CHARACTER_CREATE_RESPONSE); LOG("Unable to get system address for player for UIHelpTop5");
bitStream.Write(response); return;
SEND_PACKET;
} }
void WorldPackets::SendCharacterRenameResponse(const SystemAddress& sysAddr, eRenameResponse response) { AMFArrayValue data;
RakNet::BitStream bitStream; switch (languageCode) {
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, MessageType::Client::CHARACTER_RENAME_RESPONSE); case eLanguageCodeID::EN_US:
bitStream.Write(response); // Summaries
SEND_PACKET; data.Insert("Summary0", Game::config->GetValue("help_0_summary"));
data.Insert("Summary1", Game::config->GetValue("help_1_summary"));
data.Insert("Summary2", Game::config->GetValue("help_2_summary"));
data.Insert("Summary3", Game::config->GetValue("help_3_summary"));
data.Insert("Summary4", Game::config->GetValue("help_4_summary"));
// Descriptions
data.Insert("Description0", Game::config->GetValue("help_0_description"));
data.Insert("Description1", Game::config->GetValue("help_1_description"));
data.Insert("Description2", Game::config->GetValue("help_2_description"));
data.Insert("Description3", Game::config->GetValue("help_3_description"));
data.Insert("Description4", Game::config->GetValue("help_4_description"));
break;
case eLanguageCodeID::PL_US:
[[fallthrough]];
case eLanguageCodeID::DE_DE:
[[fallthrough]];
case eLanguageCodeID::EN_GB:
[[fallthrough]];
default:
break;
}
GameMessages::SendUIMessageServerToSingleClient(player, sysAddr, "UIHelpTop5", data);
} }
void WorldPackets::SendCharacterDeleteResponse(const SystemAddress& sysAddr, bool response) { bool GeneralChatMessage::Deserialize(RakNet::BitStream& bitStream) {
RakNet::BitStream bitStream; VALIDATE_READ(bitStream.Read(chatChannel));
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, MessageType::Client::DELETE_CHARACTER_RESPONSE); uint16_t padding;
bitStream.Write<uint8_t>(response); VALIDATE_READ(bitStream.Read(padding));
SEND_PACKET;
uint32_t messageLength;
VALIDATE_READ(bitStream.Read(messageLength));
for (uint32_t i = 0; i < (messageLength - 1); ++i) {
uint16_t character;
VALIDATE_READ(bitStream.Read(character));
message.push_back(character);
} }
void WorldPackets::SendTransferToWorld(const SystemAddress& sysAddr, const std::string& serverIP, uint32_t serverPort, bool mythranShift) { return true;
RakNet::BitStream bitStream;
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, MessageType::Client::TRANSFER_TO_WORLD);
bitStream.Write(LUString(serverIP));
bitStream.Write<uint16_t>(serverPort);
bitStream.Write<uint8_t>(mythranShift);
SEND_PACKET;
} }
void WorldPackets::SendServerState(const SystemAddress& sysAddr) { void GeneralChatMessage::Handle() {
RakNet::BitStream bitStream; Entity* player = Game::entityManager->GetEntity(objectID);
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, MessageType::Client::SERVER_STATES); if (!player) return;
bitStream.Write<uint8_t>(1); //If the server is receiving this request, it probably is ready anyway. auto sysAddr = player->GetSystemAddress();
SEND_PACKET; User* user = UserManager::Instance()->GetUser(sysAddr);
if (!user) {
LOG("Unable to get user to parse chat message");
return;
} }
void WorldPackets::SendCreateCharacter(const SystemAddress& sysAddr, int64_t reputation, LWOOBJID player, const std::string& xmlData, const std::u16string& username, eGameMasterLevel gm) { std::string playerName = user->GetLastUsedChar()->GetName();
RakNet::BitStream bitStream; bool isMythran = user->GetLastUsedChar()->GetGMLevel() > eGameMasterLevel::CIVILIAN;
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, MessageType::Client::CREATE_CHARACTER); 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;
RakNet::BitStream data; std::string sMessage = GeneralUtils::UTF16ToWTF8(message);
data.Write<uint32_t>(7); //LDF key count LOG("%s: %s", playerName.c_str(), sMessage.c_str());
ChatPackets::SendChatMessage(sysAddr, chatChannel, playerName, user->GetLoggedInChar(), isMythran, message);
std::unique_ptr<LDFData<LWOOBJID>> objid(new LDFData<LWOOBJID>(u"objid", player));
std::unique_ptr<LDFData<LOT>> lot(new LDFData<LOT>(u"template", 1));
std::unique_ptr<LDFData<std::string>> xmlConfigData(new LDFData<std::string>(u"xmlData", xmlData));
std::unique_ptr<LDFData<std::u16string>> name(new LDFData<std::u16string>(u"name", username));
std::unique_ptr<LDFData<int32_t>> gmlevel(new LDFData<int32_t>(u"gmlevel", static_cast<int32_t>(gm)));
std::unique_ptr<LDFData<int32_t>> chatmode(new LDFData<int32_t>(u"chatmode", static_cast<int32_t>(gm)));
std::unique_ptr<LDFData<int64_t>> reputationLdf(new LDFData<int64_t>(u"reputation", reputation));
objid->WriteToPacket(data);
lot->WriteToPacket(data);
name->WriteToPacket(data);
gmlevel->WriteToPacket(data);
chatmode->WriteToPacket(data);
xmlConfigData->WriteToPacket(data);
reputationLdf->WriteToPacket(data);
//Compress the data before sending:
const uint32_t reservedSize = ZCompression::GetMaxCompressedLength(data.GetNumberOfBytesUsed());
uint8_t* compressedData = new uint8_t[reservedSize];
// TODO There should be better handling here for not enough memory...
if (!compressedData) return;
size_t size = ZCompression::Compress(data.GetData(), data.GetNumberOfBytesUsed(), compressedData, reservedSize);
assert(size <= reservedSize);
bitStream.Write<uint32_t>(size + 9); //size of data + header bytes (8)
bitStream.Write<uint8_t>(1); //compressed boolean, true
bitStream.Write<uint32_t>(data.GetNumberOfBytesUsed());
bitStream.Write<uint32_t>(size);
/**
* In practice, this warning serves no purpose for us. We allocate the max memory needed on the heap
* and then compress the data. In the off chance that the compression actually increases the size,
* an assertion is done to prevent bad data from being saved or sent.
*/
#pragma warning(disable:6385) // C6385 Reading invalid data from 'compressedData'.
bitStream.WriteAlignedBytes(compressedData, size);
#pragma warning(default:6385)
SEND_PACKET;
delete[] compressedData;
LOG("Sent CreateCharacter for ID: %llu", player);
} }
void WorldPackets::SendChatModerationResponse(const SystemAddress& sysAddr, bool requestAccepted, uint32_t requestID, const std::string& receiver, std::set<std::pair<uint8_t, uint8_t>> unacceptedItems) { bool PositionUpdate::Deserialize(RakNet::BitStream& bitStream) {
CBITSTREAM; VALIDATE_READ(bitStream.Read(position.x));
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, MessageType::Client::CHAT_MODERATION_STRING); VALIDATE_READ(bitStream.Read(position.y));
VALIDATE_READ(bitStream.Read(position.z));
bitStream.Write<uint8_t>(unacceptedItems.empty()); // Is sentence ok? VALIDATE_READ(bitStream.Read(rotation.x));
bitStream.Write<uint16_t>(0x16); // Source ID, unknown VALIDATE_READ(bitStream.Read(rotation.y));
VALIDATE_READ(bitStream.Read(rotation.z));
VALIDATE_READ(bitStream.Read(rotation.w));
bitStream.Write<uint8_t>(requestID); // request ID VALIDATE_READ(bitStream.Read(onGround));
bitStream.Write<char>(0); // chat mode VALIDATE_READ(bitStream.Read(onRail));
bitStream.Write(LUWString(receiver, 42)); // receiver name bool velocityFlag = false;
if (bitStream.Read(velocityFlag) && velocityFlag) {
for (auto it : unacceptedItems) { VALIDATE_READ(bitStream.Read(velocity.x));
bitStream.Write<uint8_t>(it.first); // start index VALIDATE_READ(bitStream.Read(velocity.y));
bitStream.Write<uint8_t>(it.second); // length VALIDATE_READ(bitStream.Read(velocity.z));
} }
for (int i = unacceptedItems.size(); 64 > i; i++) { bool angVelocityFlag = false;
bitStream.Write<uint16_t>(0); if (bitStream.Read(angVelocityFlag) && angVelocityFlag) {
VALIDATE_READ(bitStream.Read(angularVelocity.x));
VALIDATE_READ(bitStream.Read(angularVelocity.y));
VALIDATE_READ(bitStream.Read(angularVelocity.z));
} }
SEND_PACKET; // TODO figure out how to use these. Ignoring for now, but reading in if they exist.
bool hasLocalSpaceInfo{};
VALIDATE_READ(bitStream.Read(hasLocalSpaceInfo));
if (hasLocalSpaceInfo) {
VALIDATE_READ(bitStream.Read(localSpaceInfo.objectId));
VALIDATE_READ(bitStream.Read(localSpaceInfo.position.x));
VALIDATE_READ(bitStream.Read(localSpaceInfo.position.y));
VALIDATE_READ(bitStream.Read(localSpaceInfo.position.z));
bool hasLinearVelocity = false;
if (bitStream.Read(hasLinearVelocity) && hasLinearVelocity) {
VALIDATE_READ(bitStream.Read(localSpaceInfo.linearVelocity.x));
VALIDATE_READ(bitStream.Read(localSpaceInfo.linearVelocity.y));
VALIDATE_READ(bitStream.Read(localSpaceInfo.linearVelocity.z));
}
}
bool hasRemoteInputInfo{};
VALIDATE_READ(bitStream.Read(hasRemoteInputInfo));
if (hasRemoteInputInfo) {
VALIDATE_READ(bitStream.Read(remoteInputInfo.m_RemoteInputX));
VALIDATE_READ(bitStream.Read(remoteInputInfo.m_RemoteInputY));
VALIDATE_READ(bitStream.Read(remoteInputInfo.m_IsPowersliding));
VALIDATE_READ(bitStream.Read(remoteInputInfo.m_IsModified));
} }
void WorldPackets::SendGMLevelChange(const SystemAddress& sysAddr, bool success, eGameMasterLevel highestLevel, eGameMasterLevel prevLevel, eGameMasterLevel newLevel) { return true;
CBITSTREAM;
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, MessageType::Client::MAKE_GM_RESPONSE);
bitStream.Write<uint8_t>(success);
bitStream.Write(static_cast<uint16_t>(highestLevel));
bitStream.Write(static_cast<uint16_t>(prevLevel));
bitStream.Write(static_cast<uint16_t>(newLevel));
SEND_PACKET;
} }
void WorldPackets::SendHTTPMonitorInfo(const SystemAddress& sysAddr, const HTTPMonitorInfo& info) { void PositionUpdate::Handle() {
CBITSTREAM; Entity* entity = Game::entityManager->GetEntity(objectID);
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, MessageType::Client::HTTP_MONITOR_INFO_RESPONSE); if (entity) entity->ProcessPositionUpdate(*this);
info.Serialize(bitStream);
SEND_PACKET; }
bool StringCheck::Deserialize(RakNet::BitStream& bitStream) {
VALIDATE_READ(bitStream.Read(chatMode));
VALIDATE_READ(bitStream.Read(requestID));
for (uint32_t i = 0; i < 42; ++i) {
uint16_t character;
VALIDATE_READ(bitStream.Read(character));
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);
}
}
uint32_t messageLength;
VALIDATE_READ(bitStream.Read(messageLength));
for (uint32_t i = 0; i < messageLength; ++i) {
uint16_t character;
VALIDATE_READ(bitStream.Read(character));
message.push_back(static_cast<uint8_t>(character));
}
return true;
}
void StringCheck::Handle() {
auto* entity = Game::entityManager->GetEntity(objectID);
if (!entity) {
LOG("Unable to get player to handle string check request");
return;
}
auto* character = entity->GetCharacter();
if (!character) {
LOG("Unable to get character to handle string check request");
return;
}
auto* user = character->GetParentUser();
if (!user) {
LOG("Unable to get user to handle string check request");
return;
}
// Check if the player has restricted chat access
if (character->HasPermission(ePermissionMap::RestrictedChatAccess)) {
ChatPackets::SendSystemMessage(
entity->GetSystemAddress(),
u"This character has restricted chat access."
);
return;
}
bool isBestFriend = false;
if (chatMode == eChatMode::UNRESTRICTED) {
// Check if the receiver is a best friend
LWOOBJID idOfReceiver = LWOOBJID_EMPTY;
{
auto characterIdFetch = Database::Get()->GetCharacterInfo(receiver);
if (characterIdFetch) idOfReceiver = characterIdFetch->id;
}
const auto& bffMap = user->GetIsBestFriendMap();
if (bffMap.find(receiver) == bffMap.end() && idOfReceiver != LWOOBJID_EMPTY) {
auto bffInfo = Database::Get()->GetBestFriendStatus(entity->GetObjectID(), idOfReceiver);
if (bffInfo) isBestFriend = bffInfo->bestFriendStatus == 3;
if (isBestFriend) user->UpdateBestFriendValue(receiver, true);
} else if (bffMap.find(receiver) != bffMap.end()) {
isBestFriend = true;
}
}
const auto segments = Game::chatFilter->IsSentenceOkay(message, entity->GetGMLevel(), !(isBestFriend && chatMode == eChatMode::UNRESTRICTED));
bool bAllClean = segments.empty();
if (user->GetIsMuted()) bAllClean = false;
user->SetLastChatMessageApproved(bAllClean);
ClientPackets::ChatModerationString response;
response.receiver = receiver;
response.rejectedWords = segments;
response.Send(entity->GetSystemAddress());
} }
void WorldPackets::SendDebugOuput(const SystemAddress& sysAddr, const std::string& data){
CBITSTREAM;
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, MessageType::Client::DEBUG_OUTPUT);
bitStream.Write<uint32_t>(data.size());
bitStream.Write(data);
SEND_PACKET;
} }

View File

@@ -2,40 +2,76 @@
#define WORLDPACKETS_H #define WORLDPACKETS_H
#include "dCommonVars.h" #include "dCommonVars.h"
#include <vector> #include "BitStreamUtils.h"
#include <string> #include "MessageType/World.h"
#include "eChatMode.h"
class User; class Entity;
struct SystemAddress; enum class eLanguageCodeID : int32_t {
enum class eGameMasterLevel : uint8_t; EN_US = 0,
enum class eCharacterCreationResponse : uint8_t; PL_US = 1,
enum class eRenameResponse : uint8_t; DE_DE = 2,
namespace RakNet { EN_GB = 3
class BitStream;
};
struct HTTPMonitorInfo {
uint16_t port = 80;
bool openWeb = false;
bool supportsSum = false;
bool supportsDetail = false;
bool supportsWho = false;
bool supportsObjects = false;
void Serialize(RakNet::BitStream &bitstream) const;
}; };
namespace WorldPackets { namespace WorldPackets {
void SendLoadStaticZone(const SystemAddress& sysAddr, float x, float y, float z, uint32_t checksum, LWOZONEID zone);
void SendCharacterCreationResponse(const SystemAddress& sysAddr, eCharacterCreationResponse response); struct UIHelpTop5: public LUBitStream {
void SendCharacterRenameResponse(const SystemAddress& sysAddr, eRenameResponse response); eLanguageCodeID languageCode = eLanguageCodeID::EN_US;
void SendCharacterDeleteResponse(const SystemAddress& sysAddr, bool response);
void SendTransferToWorld(const SystemAddress& sysAddr, const std::string& serverIP, uint32_t serverPort, bool mythranShift); UIHelpTop5() : LUBitStream(eConnectionType::WORLD, MessageType::World::UI_HELP_TOP_5) {};
void SendServerState(const SystemAddress& sysAddr); bool Deserialize(RakNet::BitStream& bitStream) override;
void SendCreateCharacter(const SystemAddress& sysAddr, int64_t reputation, LWOOBJID player, const std::string& xmlData, const std::u16string& username, eGameMasterLevel gm); void Handle() override;
void SendChatModerationResponse(const SystemAddress& sysAddr, bool requestAccepted, uint32_t requestID, const std::string& receiver, std::set<std::pair<uint8_t, uint8_t>> unacceptedItems); };
void SendGMLevelChange(const SystemAddress& sysAddr, bool success, eGameMasterLevel highestLevel, eGameMasterLevel prevLevel, eGameMasterLevel newLevel);
void SendHTTPMonitorInfo(const SystemAddress& sysAddr, const HTTPMonitorInfo& info); struct GeneralChatMessage : public LUBitStream {
void SendDebugOuput(const SystemAddress& sysAddr, const std::string& data); uint8_t chatChannel = 0;
std::u16string message;
GeneralChatMessage() : LUBitStream(eConnectionType::WORLD, MessageType::World::GENERAL_CHAT_MESSAGE) {};
bool Deserialize(RakNet::BitStream& bitStream) override;
void Handle() override;
};
struct PositionUpdate : public LUBitStream {
NiPoint3 position = NiPoint3Constant::ZERO;
NiQuaternion rotation = NiQuaternionConstant::IDENTITY;
bool onGround = false;
bool onRail = false;
NiPoint3 velocity = NiPoint3Constant::ZERO;
NiPoint3 angularVelocity = NiPoint3Constant::ZERO;
struct LocalSpaceInfo {
LWOOBJID objectId = LWOOBJID_EMPTY;
NiPoint3 position = NiPoint3Constant::ZERO;
NiPoint3 linearVelocity = NiPoint3Constant::ZERO;
};
LocalSpaceInfo localSpaceInfo;
struct RemoteInputInfo {
bool operator==(const RemoteInputInfo& other) {
return m_RemoteInputX == other.m_RemoteInputX && m_RemoteInputY == other.m_RemoteInputY && m_IsPowersliding == other.m_IsPowersliding && m_IsModified == other.m_IsModified;
}
float m_RemoteInputX = 0;
float m_RemoteInputY = 0;
bool m_IsPowersliding = false;
bool m_IsModified = false;
};
RemoteInputInfo remoteInputInfo;
PositionUpdate() : LUBitStream(eConnectionType::WORLD, MessageType::World::POSITION_UPDATE) {};
bool Deserialize(RakNet::BitStream& bitStream) override;
void Handle() override;
};
struct StringCheck : public LUBitStream {
eChatMode chatMode = eChatMode::RESTRICTED;
uint8_t requestID = 0;
std::string receiver;
std::string message;
StringCheck() : LUBitStream(eConnectionType::WORLD, MessageType::World::STRING_CHECK) {};
bool Deserialize(RakNet::BitStream& bitStream) override;
void Handle() override;
};
} }
#endif // WORLDPACKETS_H #endif // WORLDPACKETS_H

View File

@@ -31,6 +31,7 @@
#include "AuthPackets.h" #include "AuthPackets.h"
#include "BitStreamUtils.h" #include "BitStreamUtils.h"
#include "WorldPackets.h" #include "WorldPackets.h"
#include "ClientPackets.h"
#include "UserManager.h" #include "UserManager.h"
#include "CDClientManager.h" #include "CDClientManager.h"
#include "CDClientDatabase.h" #include "CDClientDatabase.h"
@@ -76,7 +77,6 @@
#include "eGameMasterLevel.h" #include "eGameMasterLevel.h"
#include "StringifiedEnum.h" #include "StringifiedEnum.h"
#include "Server.h" #include "Server.h"
#include "PositionUpdate.h"
#include "PlayerManager.h" #include "PlayerManager.h"
#include "eLoginResponse.h" #include "eLoginResponse.h"
#include "MissionComponent.h" #include "MissionComponent.h"
@@ -715,18 +715,16 @@ void HandleMasterPacket(Packet* packet) {
auto zone = Game::zoneManager->GetZone(); auto zone = Game::zoneManager->GetZone();
if (zone) { if (zone) {
float x = 0.0f; NiPoint3 pos = NiPoint3Constant::ZERO;
float y = 0.0f;
float z = 0.0f;
if (zone->GetZoneID().GetMapID() == 1100) { if (zone->GetZoneID().GetMapID() == 1100) {
auto pos = zone->GetSpawnPos(); pos = zone->GetSpawnPos();
x = pos.x;
y = pos.y;
z = pos.z;
} }
WorldPackets::SendLoadStaticZone(it->second.sysAddr, x, y, z, zone->GetChecksum(), Game::zoneManager->GetZoneID()); ClientPackets::LoadStaticZone load;
load.zoneID = Game::zoneManager->GetZoneID();
load.checksum = zone->GetChecksum();
load.position = pos;
load.Send(it->second.sysAddr);
} }
if (Game::server->GetZoneID() == 0) { if (Game::server->GetZoneID() == 0) {
@@ -1040,8 +1038,17 @@ void HandlePacket(Packet* packet) {
auto* characterComponent = player->GetComponent<CharacterComponent>(); auto* characterComponent = player->GetComponent<CharacterComponent>();
if (!characterComponent) return; if (!characterComponent) return;
WorldPackets::SendCreateCharacter(packet->systemAddress, player->GetComponent<CharacterComponent>()->GetReputation(), player->GetObjectID(), c->GetXMLData(), username, c->GetGMLevel()); ClientPackets::CreateCharacter createCharacter;
WorldPackets::SendServerState(packet->systemAddress); createCharacter.objid = player->GetObjectID();
createCharacter.name = username;
createCharacter.gmLevel = c->GetGMLevel();
createCharacter.xmlData = c->GetXMLData();
createCharacter.reputation = characterComponent->GetReputation();
createCharacter.Send(packet->systemAddress);
ClientPackets::ServerState serverState;
serverState.serverReady = true;
serverState.Send(packet->systemAddress);
const auto respawnPoint = player->GetCharacter()->GetRespawnPoint(Game::zoneManager->GetZone()->GetWorldID()); const auto respawnPoint = player->GetCharacter()->GetRespawnPoint(Game::zoneManager->GetZone()->GetWorldID());
@@ -1216,16 +1223,15 @@ void HandlePacket(Packet* packet) {
} }
case MessageType::World::POSITION_UPDATE: { case MessageType::World::POSITION_UPDATE: {
auto positionUpdate = ClientPackets::HandleClientPositionUpdate(packet); WorldPackets::PositionUpdate positionUpdate;
positionUpdate.Deserialize(inStream);
User* user = UserManager::Instance()->GetUser(packet->systemAddress); User* user = UserManager::Instance()->GetUser(packet->systemAddress);
if (!user) { if (!user) {
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()); positionUpdate.Handle();
if (entity) entity->ProcessPositionUpdate(positionUpdate);
break; break;
} }
@@ -1269,74 +1275,17 @@ void HandlePacket(Packet* packet) {
} }
case MessageType::World::STRING_CHECK: { case MessageType::World::STRING_CHECK: {
auto request = ClientPackets::HandleChatModerationRequest(packet); WorldPackets::StringCheck request;
request.Deserialize(inStream);
// TODO: Find a good home for the logic in this case.
User* user = UserManager::Instance()->GetUser(packet->systemAddress);
if (!user) {
LOG("Unable to get user to parse chat moderation request");
return;
}
auto* entity = PlayerManager::GetPlayer(packet->systemAddress); auto* entity = PlayerManager::GetPlayer(packet->systemAddress);
if (entity == nullptr) { if (entity == nullptr) {
LOG("Unable to get player to parse chat moderation request"); LOG("Unable to get player to parse chat moderation request");
return; return;
} }
// Check if the player has restricted chat access request.objectID = entity->GetObjectID();
auto* character = entity->GetCharacter(); request.Handle();
if (character->HasPermission(ePermissionMap::RestrictedChatAccess)) {
// Send a message to the player
ChatPackets::SendSystemMessage(
packet->systemAddress,
u"This character has restricted chat access."
);
return;
}
bool isBestFriend = false;
if (request.chatLevel == 1) {
// Private chat
LWOOBJID idOfReceiver = LWOOBJID_EMPTY;
{
auto characterIdFetch = Database::Get()->GetCharacterInfo(request.receiver);
if (characterIdFetch) {
idOfReceiver = characterIdFetch->id;
}
}
const auto& bffMap = user->GetIsBestFriendMap();
if (bffMap.find(request.receiver) == bffMap.end() && idOfReceiver != LWOOBJID_EMPTY) {
auto bffInfo = Database::Get()->GetBestFriendStatus(entity->GetObjectID(), idOfReceiver);
if (bffInfo) {
isBestFriend = bffInfo->bestFriendStatus == 3;
}
if (isBestFriend) {
user->UpdateBestFriendValue(request.receiver, true);
}
} else if (bffMap.find(request.receiver) != bffMap.end()) {
isBestFriend = true;
}
}
const auto segments = Game::chatFilter->IsSentenceOkay(request.message, entity->GetGMLevel(), !(isBestFriend && request.chatLevel == 1));
bool bAllClean = segments.empty();
if (user->GetIsMuted()) {
bAllClean = false;
}
user->SetLastChatMessageApproved(bAllClean);
WorldPackets::SendChatModerationResponse(packet->systemAddress, bAllClean, request.requestID, request.receiver, segments);
break; break;
} }
@@ -1344,7 +1293,8 @@ void HandlePacket(Packet* packet) {
if (g_ChatDisabled) { if (g_ChatDisabled) {
ChatPackets::SendMessageFail(packet->systemAddress); ChatPackets::SendMessageFail(packet->systemAddress);
} else { } else {
auto chatMessage = ClientPackets::HandleChatMessage(packet); WorldPackets::GeneralChatMessage chatMessage;
chatMessage.Deserialize(inStream);
// TODO: Find a good home for the logic in this case. // TODO: Find a good home for the logic in this case.
User* user = UserManager::Instance()->GetUser(packet->systemAddress); User* user = UserManager::Instance()->GetUser(packet->systemAddress);
@@ -1352,21 +1302,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;
@@ -1390,15 +1337,9 @@ void HandlePacket(Packet* packet) {
break; break;
} }
case MessageType::World::UI_HELP_TOP_5: { case MessageType::World::UI_HELP_TOP_5: {
auto language = ClientPackets::SendTop5HelpIssues(packet); WorldPackets::UIHelpTop5 help;
// TODO: Handle different languages in a nice way help.Deserialize(inStream);
// 0: en_US
// 1: pl_US
// 2: de_DE
// 3: en_GB
// TODO: Find a good home for the logic in this case. // TODO: Find a good home for the logic in this case.
auto* user = UserManager::Instance()->GetUser(packet->systemAddress); auto* user = UserManager::Instance()->GetUser(packet->systemAddress);
if (!user) return; if (!user) return;
@@ -1407,22 +1348,9 @@ void HandlePacket(Packet* packet) {
auto* entity = character->GetEntity(); auto* entity = character->GetEntity();
if (!entity) return; if (!entity) return;
AMFArrayValue data; help.objectID = entity->GetObjectID();
// Summaries help.Handle();
data.Insert("Summary0", Game::config->GetValue("help_0_summary"));
data.Insert("Summary1", Game::config->GetValue("help_1_summary"));
data.Insert("Summary2", Game::config->GetValue("help_2_summary"));
data.Insert("Summary3", Game::config->GetValue("help_3_summary"));
data.Insert("Summary4", Game::config->GetValue("help_4_summary"));
// Descriptions
data.Insert("Description0", Game::config->GetValue("help_0_description"));
data.Insert("Description1", Game::config->GetValue("help_1_description"));
data.Insert("Description2", Game::config->GetValue("help_2_description"));
data.Insert("Description3", Game::config->GetValue("help_3_description"));
data.Insert("Description4", Game::config->GetValue("help_4_description"));
GameMessages::SendUIMessageServerToSingleClient(entity, packet->systemAddress, "UIHelpTop5", data);
break; break;
} }