mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-12-16 20:24:39 -06:00
Compare commits
10 Commits
despawn
...
world-pack
| Author | SHA1 | Date | |
|---|---|---|---|
| 49dab14911 | |||
| 74601c6887 | |||
| 4627168871 | |||
| 80a4f77441 | |||
| d6c07c85c6 | |||
| b98470331d | |||
| c8a3a2c6de | |||
| 5628664060 | |||
| 47015fda08 | |||
| 3e8a417f62 |
@@ -20,6 +20,7 @@
|
||||
#include "eGameMasterLevel.h"
|
||||
#include "ChatPackets.h"
|
||||
#include "TeamContainer.h"
|
||||
#include "eChatChannel.h"
|
||||
|
||||
void ChatPacketHandler::HandleFriendlistRequest(Packet* packet) {
|
||||
//Get from the packet which player we want to do something with:
|
||||
|
||||
@@ -6,33 +6,7 @@
|
||||
struct PlayerData;
|
||||
|
||||
enum class eAddFriendResponseType : 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 eChatChannel : uint8_t;
|
||||
|
||||
enum class eChatMessageResponseCode : uint8_t {
|
||||
SENT = 0,
|
||||
|
||||
@@ -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__
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <cstdint>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include "dTypeDefs.h"
|
||||
#include "BitStream.h"
|
||||
#include "BitStreamUtils.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_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 ==============
|
||||
|
||||
struct LWOSCENEID {
|
||||
|
||||
36
dCommon/dEnums/eChatChannel.h
Normal file
36
dCommon/dEnums/eChatChannel.h
Normal 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__
|
||||
10
dCommon/dEnums/eChatMode.h
Normal file
10
dCommon/dEnums/eChatMode.h
Normal 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
29
dCommon/dTypeDefs.h
Normal 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__
|
||||
@@ -23,9 +23,9 @@
|
||||
#include "eMissionTaskType.h"
|
||||
#include "eTriggerEventType.h"
|
||||
#include "eObjectBits.h"
|
||||
#include "PositionUpdate.h"
|
||||
#include "MessageType/Chat.h"
|
||||
#include "PlayerManager.h"
|
||||
#include "WorldPackets.h"
|
||||
|
||||
//Component includes:
|
||||
#include "Component.h"
|
||||
@@ -99,7 +99,7 @@
|
||||
|
||||
#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) {
|
||||
m_ObjectID = objectID;
|
||||
@@ -2112,7 +2112,7 @@ uint8_t Entity::GetCollectibleID() const {
|
||||
return collectible ? collectible->GetCollectibleId() : 0;
|
||||
}
|
||||
|
||||
void Entity::ProcessPositionUpdate(PositionUpdate& update) {
|
||||
void Entity::ProcessPositionUpdate(WorldPackets::PositionUpdate& update) {
|
||||
if (!IsPlayer()) return;
|
||||
auto* controllablePhysicsComponent = GetComponent<ControllablePhysicsComponent>();
|
||||
if (!controllablePhysicsComponent) return;
|
||||
|
||||
@@ -20,6 +20,9 @@ namespace GameMessages {
|
||||
struct ChildLoaded;
|
||||
struct PlayerResurrectionFinished;
|
||||
};
|
||||
namespace WorldPackets {
|
||||
struct PositionUpdate;
|
||||
};
|
||||
|
||||
namespace MessageType {
|
||||
enum class Game : uint16_t;
|
||||
@@ -316,7 +319,7 @@ public:
|
||||
|
||||
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
|
||||
void SetScale(const float scale) { m_Scale = scale; };
|
||||
@@ -328,7 +331,7 @@ public:
|
||||
/**
|
||||
* @brief The observable for player entity position updates.
|
||||
*/
|
||||
static Observable<Entity*, const PositionUpdate&> OnPlayerPositionUpdate;
|
||||
static Observable<Entity*, const WorldPackets::PositionUpdate&> OnPlayerPositionUpdate;
|
||||
|
||||
protected:
|
||||
LWOOBJID m_ObjectID;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include "Game.h"
|
||||
#include "Logger.h"
|
||||
#include "User.h"
|
||||
#include "WorldPackets.h"
|
||||
#include "ClientPackets.h"
|
||||
#include "Character.h"
|
||||
#include "BitStream.h"
|
||||
#include "ObjectIDManager.h"
|
||||
@@ -308,13 +308,17 @@ void UserManager::CreateCharacter(const SystemAddress& sysAddr, Packet* packet)
|
||||
|
||||
if (!name.empty() && Database::Get()->IsNameInUse(name)) {
|
||||
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;
|
||||
}
|
||||
|
||||
if (Database::Get()->IsNameInUse(predefinedName)) {
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -328,7 +332,8 @@ void UserManager::CreateCharacter(const SystemAddress& sysAddr, Packet* packet)
|
||||
ObjectIDManager::RequestPersistentID([=, this](uint32_t objectID) {
|
||||
if (Database::Get()->GetCharacterInfo(objectID)) {
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -393,8 +398,10 @@ void UserManager::CreateCharacter(const SystemAddress& sysAddr, Packet* packet)
|
||||
|
||||
//Now finally insert our character xml:
|
||||
Database::Get()->InsertCharacterXml(objectID, xml.str());
|
||||
|
||||
WorldPackets::SendCharacterCreationResponse(sysAddr, eCharacterCreationResponse::SUCCESS);
|
||||
|
||||
ClientPackets::CharacterCreationResponse response;
|
||||
response.response = eCharacterCreationResponse::SUCCESS;
|
||||
response.Send(sysAddr);
|
||||
UserManager::RequestCharacterList(sysAddr);
|
||||
});
|
||||
}
|
||||
@@ -419,10 +426,12 @@ void UserManager::DeleteCharacter(const SystemAddress& sysAddr, Packet* packet)
|
||||
CheckType::User,
|
||||
"User %i tried to delete a character that it does not own!",
|
||||
u->GetAccountID());
|
||||
|
||||
|
||||
ClientPackets::CharacterDeleteResponse response;
|
||||
if (!hasCharacter) {
|
||||
WorldPackets::SendCharacterDeleteResponse(sysAddr, false);
|
||||
response.success = false;
|
||||
} else {
|
||||
response.success = true;
|
||||
LOG("Deleting character %i", 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);
|
||||
bitStream.Write(objectID);
|
||||
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) {
|
||||
@@ -473,32 +482,34 @@ void UserManager::RenameCharacter(const SystemAddress& sysAddr, Packet* packet)
|
||||
return false;
|
||||
});
|
||||
|
||||
ClientPackets::CharacterRenameResponse response;
|
||||
if (!ownsCharacter || !character) {
|
||||
WorldPackets::SendCharacterRenameResponse(sysAddr, eRenameResponse::UNKNOWN_ERROR);
|
||||
response.response = eRenameResponse::UNKNOWN_ERROR;
|
||||
|
||||
} else if (ownsCharacter && character) {
|
||||
if (newName == character->GetName()) {
|
||||
WorldPackets::SendCharacterRenameResponse(sysAddr, eRenameResponse::NAME_UNAVAILABLE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Database::Get()->GetCharacterInfo(newName)) {
|
||||
response.response = eRenameResponse::NAME_UNAVAILABLE;
|
||||
|
||||
} else if (!Database::Get()->GetCharacterInfo(newName)) {
|
||||
if (IsNamePreapproved(newName)) {
|
||||
Database::Get()->SetCharacterName(charID, newName);
|
||||
LOG("Character %s now known as %s", character->GetName().c_str(), newName.c_str());
|
||||
WorldPackets::SendCharacterRenameResponse(sysAddr, eRenameResponse::SUCCESS);
|
||||
UserManager::RequestCharacterList(sysAddr);
|
||||
response.response = eRenameResponse::SUCCESS;
|
||||
} else {
|
||||
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());
|
||||
WorldPackets::SendCharacterRenameResponse(sysAddr, eRenameResponse::SUCCESS);
|
||||
UserManager::RequestCharacterList(sysAddr);
|
||||
response.response = eRenameResponse::SUCCESS;
|
||||
}
|
||||
} else {
|
||||
WorldPackets::SendCharacterRenameResponse(sysAddr, eRenameResponse::NAME_IN_USE);
|
||||
response.response = eRenameResponse::NAME_IN_USE;
|
||||
}
|
||||
} else {
|
||||
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->SetZoneClone(zoneClone);
|
||||
}
|
||||
WorldPackets::SendTransferToWorld(sysAddr, serverIP, serverPort, mythranShift);
|
||||
ClientPackets::TransferToWorld response;
|
||||
response.serverIP = serverIP;
|
||||
response.serverPort = serverPort;
|
||||
response.mythranShift = mythranShift;
|
||||
response.Send(sysAddr);
|
||||
return;
|
||||
});
|
||||
} else {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include "Character.h"
|
||||
#include "CharacterComponent.h"
|
||||
#include "ChatPackets.h"
|
||||
#include "WorldPackets.h"
|
||||
#include "ClientPackets.h"
|
||||
#include "EntityManager.h"
|
||||
#include "Game.h"
|
||||
#include "ZoneInstanceManager.h"
|
||||
@@ -55,7 +55,11 @@ void PropertyTeleportBehavior::Handle(BehaviorContext* context, RakNet::BitStrea
|
||||
|
||||
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;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include "ZoneInstanceManager.h"
|
||||
#include "Game.h"
|
||||
#include "Logger.h"
|
||||
#include "WorldPackets.h"
|
||||
#include "ClientPackets.h"
|
||||
#include "EntityManager.h"
|
||||
#include "ChatPackets.h"
|
||||
#include "BitStreamUtils.h"
|
||||
@@ -537,7 +537,11 @@ void ActivityInstance::StartZone() {
|
||||
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;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#include "CDRewardCodesTable.h"
|
||||
#include "Mail.h"
|
||||
#include "ZoneInstanceManager.h"
|
||||
#include "WorldPackets.h"
|
||||
#include "ClientPackets.h"
|
||||
#include "MessageType/Game.h"
|
||||
#include <ctime>
|
||||
|
||||
@@ -868,8 +868,11 @@ void CharacterComponent::SendToZone(LWOMAPID zoneId, LWOCLONEID cloneId) const {
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ void HavokVehiclePhysicsComponent::SetIsOnRail(bool val) {
|
||||
m_IsOnRail = val;
|
||||
}
|
||||
|
||||
void HavokVehiclePhysicsComponent::SetRemoteInputInfo(const RemoteInputInfo& remoteInputInfo) {
|
||||
void HavokVehiclePhysicsComponent::SetRemoteInputInfo(const WorldPackets::PositionUpdate::RemoteInputInfo& remoteInputInfo) {
|
||||
if (remoteInputInfo == m_RemoteInputInfo) return;
|
||||
this->m_RemoteInputInfo = remoteInputInfo;
|
||||
m_DirtyPosition = true;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include "Entity.h"
|
||||
#include "PhysicsComponent.h"
|
||||
#include "eReplicaComponentType.h"
|
||||
#include "PositionUpdate.h"
|
||||
#include "WorldPackets.h"
|
||||
|
||||
/**
|
||||
* Physics component for vehicles.
|
||||
@@ -65,7 +65,7 @@ public:
|
||||
*/
|
||||
const bool GetIsOnRail() const { return m_IsOnRail; }
|
||||
|
||||
void SetRemoteInputInfo(const RemoteInputInfo&);
|
||||
void SetRemoteInputInfo(const WorldPackets::PositionUpdate::RemoteInputInfo& remoteInputInfo);
|
||||
|
||||
private:
|
||||
NiPoint3 m_Velocity;
|
||||
@@ -76,5 +76,5 @@ private:
|
||||
|
||||
float m_SoftUpdate = 0;
|
||||
uint32_t m_EndBehavior;
|
||||
RemoteInputInfo m_RemoteInputInfo;
|
||||
WorldPackets::PositionUpdate::RemoteInputInfo m_RemoteInputInfo;
|
||||
};
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#include "CppScripts.h"
|
||||
#include "UserManager.h"
|
||||
#include "ZoneInstanceManager.h"
|
||||
#include "WorldPackets.h"
|
||||
#include "ClientPackets.h"
|
||||
#include "Item.h"
|
||||
#include "ZCompression.h"
|
||||
#include "dConfig.h"
|
||||
@@ -4936,7 +4936,11 @@ void GameMessages::HandleFireEventServerSide(RakNet::BitStream& inStream, Entity
|
||||
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;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#include "UserManager.h"
|
||||
#include "User.h"
|
||||
#include "VanityUtilities.h"
|
||||
#include "WorldPackets.h"
|
||||
#include "ClientPackets.h"
|
||||
#include "ZoneInstanceManager.h"
|
||||
|
||||
// Database
|
||||
@@ -73,7 +73,13 @@ namespace DEVGMCommands {
|
||||
bool success = user->GetMaxGMLevel() >= level;
|
||||
|
||||
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);
|
||||
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());
|
||||
@@ -81,7 +87,13 @@ namespace DEVGMCommands {
|
||||
|
||||
#ifndef DEVELOPER_SERVER
|
||||
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);
|
||||
entity->SetGMLevel(eGameMasterLevel::CIVILIAN);
|
||||
|
||||
@@ -1061,7 +1073,11 @@ namespace DEVGMCommands {
|
||||
|
||||
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;
|
||||
});
|
||||
} else {
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include "PlayerManager.h"
|
||||
#include "SlashCommandHandler.h"
|
||||
#include "VanityUtilities.h"
|
||||
#include "WorldPackets.h"
|
||||
#include "ClientPackets.h"
|
||||
#include "ZoneInstanceManager.h"
|
||||
#include "Database.h"
|
||||
|
||||
@@ -179,7 +179,11 @@ namespace GMZeroCommands {
|
||||
|
||||
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();
|
||||
|
||||
WorldPackets::SendTransferToWorld(sysAddr, serverIP, serverPort, mythranShift);
|
||||
ClientPackets::TransferToWorld response;
|
||||
response.serverIP = serverIP;
|
||||
response.serverPort = serverPort;
|
||||
response.mythranShift = mythranShift;
|
||||
response.Send(sysAddr);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -29,4 +29,5 @@ target_include_directories(dNet PRIVATE
|
||||
"${PROJECT_SOURCE_DIR}/dGame/dInventory" # via PossessableComponent.h
|
||||
"${PROJECT_SOURCE_DIR}/dGame/dUtilities" # via Item.h
|
||||
"${PROJECT_SOURCE_DIR}/dScripts" # transitive through components
|
||||
"${PROJECT_SOURCE_DIR}/dChatFilter" # for chat message handling
|
||||
)
|
||||
|
||||
@@ -5,119 +5,123 @@
|
||||
|
||||
#include "ClientPackets.h"
|
||||
#include "dCommonVars.h"
|
||||
#include "PositionUpdate.h"
|
||||
#include "LDFFormat.h"
|
||||
#include "ZCompression.h"
|
||||
|
||||
ChatMessage ClientPackets::HandleChatMessage(Packet* packet) {
|
||||
CINSTREAM_SKIP_HEADER;
|
||||
|
||||
ChatMessage message;
|
||||
uint32_t messageLength;
|
||||
|
||||
inStream.Read(message.chatChannel);
|
||||
inStream.Read(message.unknown);
|
||||
inStream.Read(messageLength);
|
||||
|
||||
for (uint32_t i = 0; i < (messageLength - 1); ++i) {
|
||||
uint16_t character;
|
||||
inStream.Read(character);
|
||||
message.message.push_back(character);
|
||||
namespace ClientPackets {
|
||||
void LoadStaticZone::Serialize(RakNet::BitStream &bitStream) const {
|
||||
bitStream.Write<uint16_t>(zoneID.GetMapID());
|
||||
bitStream.Write<uint16_t>(zoneID.GetInstanceID());
|
||||
bitStream.Write<uint32_t>(zoneID.GetCloneID());
|
||||
bitStream.Write<uint32_t>(checksum);
|
||||
bitStream.Write<uint8_t>(editorEnabled);
|
||||
bitStream.Write<uint8_t>(editorLevel);
|
||||
bitStream.Write(position.x);
|
||||
bitStream.Write(position.y);
|
||||
bitStream.Write(position.z);
|
||||
bitStream.Write<uint32_t>(instanceType);
|
||||
}
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
PositionUpdate ClientPackets::HandleClientPositionUpdate(Packet* packet) {
|
||||
PositionUpdate update;
|
||||
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);
|
||||
void CharacterCreationResponse::Serialize(RakNet::BitStream &bitStream) const {
|
||||
bitStream.Write(response);
|
||||
}
|
||||
|
||||
bool angVelocityFlag = false;
|
||||
inStream.Read(angVelocityFlag);
|
||||
if (angVelocityFlag) {
|
||||
inStream.Read(update.angularVelocity.x);
|
||||
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.
|
||||
bool hasLocalSpaceInfo{};
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
ChatModerationRequest ClientPackets::HandleChatModerationRequest(Packet* packet) {
|
||||
CINSTREAM_SKIP_HEADER;
|
||||
|
||||
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));
|
||||
void CharacterRenameResponse::Serialize(RakNet::BitStream &bitStream) const {
|
||||
bitStream.Write(response);
|
||||
}
|
||||
|
||||
if (!request.receiver.empty()) {
|
||||
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
|
||||
request.receiver = std::string(request.receiver.c_str() + 4, request.receiver.size() - 4);
|
||||
void CharacterDeleteResponse::Serialize(RakNet::BitStream &bitStream) const {
|
||||
bitStream.Write<uint8_t>(success);
|
||||
}
|
||||
|
||||
void TransferToWorld::Serialize(RakNet::BitStream &bitStream) const {
|
||||
bitStream.Write(LUString(serverIP));
|
||||
bitStream.Write<uint16_t>(serverPort);
|
||||
bitStream.Write<uint8_t>(mythranShift);
|
||||
}
|
||||
|
||||
void ServerState::Serialize(RakNet::BitStream &bitStream) const {
|
||||
bitStream.Write<uint8_t>(serverReady);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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));
|
||||
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));
|
||||
}
|
||||
|
||||
return request;
|
||||
}
|
||||
void DebugOutput::Serialize(RakNet::BitStream &bitStream) const {
|
||||
bitStream.Write<uint32_t>(data.size());
|
||||
bitStream.Write(data);
|
||||
}
|
||||
|
||||
int32_t ClientPackets::SendTop5HelpIssues(Packet* packet) {
|
||||
CINSTREAM_SKIP_HEADER;
|
||||
int32_t language = 0;
|
||||
inStream.Read(language);
|
||||
return language;
|
||||
void HTTPMonitorInfoResponse::Serialize(RakNet::BitStream &bitStream) const {
|
||||
bitStream.Write<uint16_t>(port);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,29 +8,122 @@
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include "BitStreamUtils.h"
|
||||
#include "eGameMasterLevel.h"
|
||||
#include "eChatChannel.h"
|
||||
#include "dCommonVars.h"
|
||||
|
||||
class PositionUpdate;
|
||||
|
||||
struct Packet;
|
||||
|
||||
struct ChatMessage {
|
||||
uint8_t chatChannel = 0;
|
||||
uint16_t unknown = 0;
|
||||
std::u16string message;
|
||||
};
|
||||
|
||||
struct ChatModerationRequest {
|
||||
uint8_t chatLevel = 0;
|
||||
uint8_t requestID = 0;
|
||||
std::string receiver;
|
||||
std::string message;
|
||||
};
|
||||
class User;
|
||||
struct SystemAddress;
|
||||
enum class eCharacterCreationResponse : uint8_t;
|
||||
enum class eRenameResponse : uint8_t;
|
||||
|
||||
namespace ClientPackets {
|
||||
ChatMessage HandleChatMessage(Packet* packet);
|
||||
PositionUpdate HandleClientPositionUpdate(Packet* packet);
|
||||
ChatModerationRequest HandleChatModerationRequest(Packet* packet);
|
||||
int32_t SendTop5HelpIssues(Packet* packet);
|
||||
struct LoadStaticZone : public LUBitStream {
|
||||
LWOZONEID zoneID;
|
||||
uint32_t checksum = 0;
|
||||
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
|
||||
|
||||
@@ -1,186 +1,246 @@
|
||||
#include "WorldPackets.h"
|
||||
#include "dCommonVars.h"
|
||||
#include "BitStream.h"
|
||||
#include "GeneralUtils.h"
|
||||
#include "Logger.h"
|
||||
#include "Game.h"
|
||||
#include "LDFFormat.h"
|
||||
#include "dServer.h"
|
||||
#include "ZCompression.h"
|
||||
#include "eConnectionType.h"
|
||||
#include "BitStreamUtils.h"
|
||||
#include "Amf3.h"
|
||||
#include "dConfig.h"
|
||||
#include "GameMessages.h"
|
||||
#include "Entity.h"
|
||||
#include "EntityManager.h"
|
||||
#include "UserManager.h"
|
||||
#include "User.h"
|
||||
#include "Character.h"
|
||||
#include "dChatFilter.h"
|
||||
#include "ChatPackets.h"
|
||||
#include "ClientPackets.h"
|
||||
#include "Database.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
void HTTPMonitorInfo::Serialize(RakNet::BitStream &bitStream) const {
|
||||
bitStream.Write(port);
|
||||
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);
|
||||
}
|
||||
|
||||
void WorldPackets::SendLoadStaticZone(const SystemAddress& sysAddr, float x, float y, float z, uint32_t checksum, LWOZONEID zone) {
|
||||
RakNet::BitStream bitStream;
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, MessageType::Client::LOAD_STATIC_ZONE);
|
||||
|
||||
bitStream.Write<uint16_t>(zone.GetMapID());
|
||||
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) {
|
||||
RakNet::BitStream bitStream;
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, MessageType::Client::CHARACTER_CREATE_RESPONSE);
|
||||
bitStream.Write(response);
|
||||
SEND_PACKET;
|
||||
}
|
||||
|
||||
void WorldPackets::SendCharacterRenameResponse(const SystemAddress& sysAddr, eRenameResponse response) {
|
||||
RakNet::BitStream bitStream;
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, MessageType::Client::CHARACTER_RENAME_RESPONSE);
|
||||
bitStream.Write(response);
|
||||
SEND_PACKET;
|
||||
}
|
||||
|
||||
void WorldPackets::SendCharacterDeleteResponse(const SystemAddress& sysAddr, bool response) {
|
||||
RakNet::BitStream bitStream;
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, MessageType::Client::DELETE_CHARACTER_RESPONSE);
|
||||
bitStream.Write<uint8_t>(response);
|
||||
SEND_PACKET;
|
||||
}
|
||||
|
||||
void WorldPackets::SendTransferToWorld(const SystemAddress& sysAddr, const std::string& serverIP, uint32_t serverPort, bool mythranShift) {
|
||||
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) {
|
||||
RakNet::BitStream bitStream;
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, MessageType::Client::SERVER_STATES);
|
||||
bitStream.Write<uint8_t>(1); //If the server is receiving this request, it probably is ready anyway.
|
||||
SEND_PACKET;
|
||||
}
|
||||
|
||||
void WorldPackets::SendCreateCharacter(const SystemAddress& sysAddr, int64_t reputation, LWOOBJID player, const std::string& xmlData, const std::u16string& username, eGameMasterLevel gm) {
|
||||
RakNet::BitStream bitStream;
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, MessageType::Client::CREATE_CHARACTER);
|
||||
|
||||
RakNet::BitStream data;
|
||||
data.Write<uint32_t>(7); //LDF key count
|
||||
|
||||
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) {
|
||||
CBITSTREAM;
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, MessageType::Client::CHAT_MODERATION_STRING);
|
||||
|
||||
bitStream.Write<uint8_t>(unacceptedItems.empty()); // Is sentence ok?
|
||||
bitStream.Write<uint16_t>(0x16); // Source ID, unknown
|
||||
|
||||
bitStream.Write<uint8_t>(requestID); // request ID
|
||||
bitStream.Write<char>(0); // chat mode
|
||||
|
||||
bitStream.Write(LUWString(receiver, 42)); // receiver name
|
||||
|
||||
for (auto it : unacceptedItems) {
|
||||
bitStream.Write<uint8_t>(it.first); // start index
|
||||
bitStream.Write<uint8_t>(it.second); // length
|
||||
namespace WorldPackets {
|
||||
|
||||
bool UIHelpTop5::Deserialize(RakNet::BitStream& bitStream) {
|
||||
VALIDATE_READ(bitStream.Read(languageCode));
|
||||
return true;
|
||||
}
|
||||
|
||||
for (int i = unacceptedItems.size(); 64 > i; i++) {
|
||||
bitStream.Write<uint16_t>(0);
|
||||
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:
|
||||
// Summaries
|
||||
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);
|
||||
}
|
||||
|
||||
bool GeneralChatMessage::Deserialize(RakNet::BitStream& bitStream) {
|
||||
VALIDATE_READ(bitStream.Read(chatChannel));
|
||||
uint16_t padding;
|
||||
VALIDATE_READ(bitStream.Read(padding));
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
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) {
|
||||
VALIDATE_READ(bitStream.Read(position.x));
|
||||
VALIDATE_READ(bitStream.Read(position.y));
|
||||
VALIDATE_READ(bitStream.Read(position.z));
|
||||
|
||||
VALIDATE_READ(bitStream.Read(rotation.x));
|
||||
VALIDATE_READ(bitStream.Read(rotation.y));
|
||||
VALIDATE_READ(bitStream.Read(rotation.z));
|
||||
VALIDATE_READ(bitStream.Read(rotation.w));
|
||||
|
||||
VALIDATE_READ(bitStream.Read(onGround));
|
||||
VALIDATE_READ(bitStream.Read(onRail));
|
||||
|
||||
bool velocityFlag = false;
|
||||
if (bitStream.Read(velocityFlag) && velocityFlag) {
|
||||
VALIDATE_READ(bitStream.Read(velocity.x));
|
||||
VALIDATE_READ(bitStream.Read(velocity.y));
|
||||
VALIDATE_READ(bitStream.Read(velocity.z));
|
||||
}
|
||||
|
||||
bool angVelocityFlag = false;
|
||||
if (bitStream.Read(angVelocityFlag) && angVelocityFlag) {
|
||||
VALIDATE_READ(bitStream.Read(angularVelocity.x));
|
||||
VALIDATE_READ(bitStream.Read(angularVelocity.y));
|
||||
VALIDATE_READ(bitStream.Read(angularVelocity.z));
|
||||
}
|
||||
|
||||
// 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));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void PositionUpdate::Handle() {
|
||||
Entity* entity = Game::entityManager->GetEntity(objectID);
|
||||
if (entity) entity->ProcessPositionUpdate(*this);
|
||||
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
SEND_PACKET;
|
||||
}
|
||||
|
||||
void WorldPackets::SendGMLevelChange(const SystemAddress& sysAddr, bool success, eGameMasterLevel highestLevel, eGameMasterLevel prevLevel, eGameMasterLevel newLevel) {
|
||||
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) {
|
||||
CBITSTREAM;
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, MessageType::Client::HTTP_MONITOR_INFO_RESPONSE);
|
||||
info.Serialize(bitStream);
|
||||
SEND_PACKET;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -2,40 +2,76 @@
|
||||
#define WORLDPACKETS_H
|
||||
|
||||
#include "dCommonVars.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "BitStreamUtils.h"
|
||||
#include "MessageType/World.h"
|
||||
#include "eChatMode.h"
|
||||
|
||||
class User;
|
||||
struct SystemAddress;
|
||||
enum class eGameMasterLevel : uint8_t;
|
||||
enum class eCharacterCreationResponse : uint8_t;
|
||||
enum class eRenameResponse : uint8_t;
|
||||
namespace RakNet {
|
||||
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;
|
||||
class Entity;
|
||||
enum class eLanguageCodeID : int32_t {
|
||||
EN_US = 0,
|
||||
PL_US = 1,
|
||||
DE_DE = 2,
|
||||
EN_GB = 3
|
||||
};
|
||||
|
||||
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);
|
||||
void SendCharacterRenameResponse(const SystemAddress& sysAddr, eRenameResponse response);
|
||||
void SendCharacterDeleteResponse(const SystemAddress& sysAddr, bool response);
|
||||
void SendTransferToWorld(const SystemAddress& sysAddr, const std::string& serverIP, uint32_t serverPort, bool mythranShift);
|
||||
void SendServerState(const SystemAddress& sysAddr);
|
||||
void SendCreateCharacter(const SystemAddress& sysAddr, int64_t reputation, LWOOBJID player, const std::string& xmlData, const std::u16string& username, eGameMasterLevel gm);
|
||||
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);
|
||||
void SendDebugOuput(const SystemAddress& sysAddr, const std::string& data);
|
||||
|
||||
struct UIHelpTop5: public LUBitStream {
|
||||
eLanguageCodeID languageCode = eLanguageCodeID::EN_US;
|
||||
|
||||
UIHelpTop5() : LUBitStream(eConnectionType::WORLD, MessageType::World::UI_HELP_TOP_5) {};
|
||||
bool Deserialize(RakNet::BitStream& bitStream) override;
|
||||
void Handle() override;
|
||||
};
|
||||
|
||||
struct GeneralChatMessage : public LUBitStream {
|
||||
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
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include "AuthPackets.h"
|
||||
#include "BitStreamUtils.h"
|
||||
#include "WorldPackets.h"
|
||||
#include "ClientPackets.h"
|
||||
#include "UserManager.h"
|
||||
#include "CDClientManager.h"
|
||||
#include "CDClientDatabase.h"
|
||||
@@ -76,7 +77,6 @@
|
||||
#include "eGameMasterLevel.h"
|
||||
#include "StringifiedEnum.h"
|
||||
#include "Server.h"
|
||||
#include "PositionUpdate.h"
|
||||
#include "PlayerManager.h"
|
||||
#include "eLoginResponse.h"
|
||||
#include "MissionComponent.h"
|
||||
@@ -715,18 +715,16 @@ void HandleMasterPacket(Packet* packet) {
|
||||
|
||||
auto zone = Game::zoneManager->GetZone();
|
||||
if (zone) {
|
||||
float x = 0.0f;
|
||||
float y = 0.0f;
|
||||
float z = 0.0f;
|
||||
|
||||
NiPoint3 pos = NiPoint3Constant::ZERO;
|
||||
if (zone->GetZoneID().GetMapID() == 1100) {
|
||||
auto pos = zone->GetSpawnPos();
|
||||
x = pos.x;
|
||||
y = pos.y;
|
||||
z = pos.z;
|
||||
pos = zone->GetSpawnPos();
|
||||
}
|
||||
|
||||
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) {
|
||||
@@ -1040,8 +1038,17 @@ void HandlePacket(Packet* packet) {
|
||||
auto* characterComponent = player->GetComponent<CharacterComponent>();
|
||||
if (!characterComponent) return;
|
||||
|
||||
WorldPackets::SendCreateCharacter(packet->systemAddress, player->GetComponent<CharacterComponent>()->GetReputation(), player->GetObjectID(), c->GetXMLData(), username, c->GetGMLevel());
|
||||
WorldPackets::SendServerState(packet->systemAddress);
|
||||
ClientPackets::CreateCharacter createCharacter;
|
||||
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());
|
||||
|
||||
@@ -1216,16 +1223,15 @@ void HandlePacket(Packet* packet) {
|
||||
}
|
||||
|
||||
case MessageType::World::POSITION_UPDATE: {
|
||||
auto positionUpdate = ClientPackets::HandleClientPositionUpdate(packet);
|
||||
|
||||
WorldPackets::PositionUpdate positionUpdate;
|
||||
positionUpdate.Deserialize(inStream);
|
||||
User* user = UserManager::Instance()->GetUser(packet->systemAddress);
|
||||
if (!user) {
|
||||
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();
|
||||
positionUpdate.Handle();
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1269,74 +1275,17 @@ void HandlePacket(Packet* packet) {
|
||||
}
|
||||
|
||||
case MessageType::World::STRING_CHECK: {
|
||||
auto request = ClientPackets::HandleChatModerationRequest(packet);
|
||||
|
||||
// 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;
|
||||
}
|
||||
WorldPackets::StringCheck request;
|
||||
request.Deserialize(inStream);
|
||||
|
||||
auto* entity = PlayerManager::GetPlayer(packet->systemAddress);
|
||||
|
||||
if (entity == nullptr) {
|
||||
LOG("Unable to get player to parse chat moderation request");
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if the player has restricted chat access
|
||||
auto* character = entity->GetCharacter();
|
||||
|
||||
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);
|
||||
request.objectID = entity->GetObjectID();
|
||||
request.Handle();
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1344,7 +1293,8 @@ void HandlePacket(Packet* packet) {
|
||||
if (g_ChatDisabled) {
|
||||
ChatPackets::SendMessageFail(packet->systemAddress);
|
||||
} else {
|
||||
auto chatMessage = ClientPackets::HandleChatMessage(packet);
|
||||
WorldPackets::GeneralChatMessage chatMessage;
|
||||
chatMessage.Deserialize(inStream);
|
||||
|
||||
// TODO: Find a good home for the logic in this case.
|
||||
User* user = UserManager::Instance()->GetUser(packet->systemAddress);
|
||||
@@ -1352,21 +1302,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;
|
||||
@@ -1390,15 +1337,9 @@ void HandlePacket(Packet* packet) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
case MessageType::World::UI_HELP_TOP_5: {
|
||||
auto language = ClientPackets::SendTop5HelpIssues(packet);
|
||||
// TODO: Handle different languages in a nice way
|
||||
// 0: en_US
|
||||
// 1: pl_US
|
||||
// 2: de_DE
|
||||
// 3: en_GB
|
||||
|
||||
WorldPackets::UIHelpTop5 help;
|
||||
help.Deserialize(inStream);
|
||||
// TODO: Find a good home for the logic in this case.
|
||||
auto* user = UserManager::Instance()->GetUser(packet->systemAddress);
|
||||
if (!user) return;
|
||||
@@ -1407,22 +1348,9 @@ void HandlePacket(Packet* packet) {
|
||||
auto* entity = character->GetEntity();
|
||||
if (!entity) return;
|
||||
|
||||
AMFArrayValue data;
|
||||
// Summaries
|
||||
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);
|
||||
help.objectID = entity->GetObjectID();
|
||||
help.Handle();
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user