mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-11-21 21:17:25 +00:00
Dynamic GM sending proof of concept
This commit is contained in:
parent
e0ddbce8e7
commit
e55a2e36e6
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -17,3 +17,6 @@
|
|||||||
[submodule "thirdparty/magic_enum"]
|
[submodule "thirdparty/magic_enum"]
|
||||||
path = thirdparty/magic_enum
|
path = thirdparty/magic_enum
|
||||||
url = https://github.com/Neargye/magic_enum.git
|
url = https://github.com/Neargye/magic_enum.git
|
||||||
|
[submodule "thirdparty/json"]
|
||||||
|
path = thirdparty/json
|
||||||
|
url = https://github.com/nlohmann/json
|
||||||
|
@ -96,7 +96,7 @@ make_directory(${CMAKE_BINARY_DIR}/resServer)
|
|||||||
make_directory(${CMAKE_BINARY_DIR}/logs)
|
make_directory(${CMAKE_BINARY_DIR}/logs)
|
||||||
|
|
||||||
# Copy resource files on first build
|
# Copy resource files on first build
|
||||||
set(RESOURCE_FILES "sharedconfig.ini" "authconfig.ini" "chatconfig.ini" "worldconfig.ini" "masterconfig.ini" "blacklist.dcf")
|
set(RESOURCE_FILES "sharedconfig.ini" "authconfig.ini" "chatconfig.ini" "worldconfig.ini" "masterconfig.ini" "blacklist.dcf" "gms.json")
|
||||||
message(STATUS "Checking resource file integrity")
|
message(STATUS "Checking resource file integrity")
|
||||||
|
|
||||||
include(Utils)
|
include(Utils)
|
||||||
@ -244,6 +244,7 @@ set(INCLUDED_DIRECTORIES
|
|||||||
"thirdparty/SQLite"
|
"thirdparty/SQLite"
|
||||||
"thirdparty/cpplinq"
|
"thirdparty/cpplinq"
|
||||||
"thirdparty/cpp-httplib"
|
"thirdparty/cpp-httplib"
|
||||||
|
"thirdparty/json/include"
|
||||||
|
|
||||||
"tests"
|
"tests"
|
||||||
"tests/dCommonTests"
|
"tests/dCommonTests"
|
||||||
@ -317,7 +318,7 @@ add_subdirectory(dPhysics)
|
|||||||
add_subdirectory(dServer)
|
add_subdirectory(dServer)
|
||||||
|
|
||||||
# Create a list of common libraries shared between all binaries
|
# Create a list of common libraries shared between all binaries
|
||||||
set(COMMON_LIBRARIES "dCommon" "dDatabase" "dNet" "raknet" "mariadbConnCpp" "magic_enum")
|
set(COMMON_LIBRARIES "dCommon" "dDatabase" "dNet" "raknet" "mariadbConnCpp" "magic_enum" "nlohmann_json")
|
||||||
|
|
||||||
# Add platform specific common libraries
|
# Add platform specific common libraries
|
||||||
if(UNIX)
|
if(UNIX)
|
||||||
|
@ -2,7 +2,8 @@ set(DGAME_DGAMEMESSAGES_SOURCES
|
|||||||
"GameMessageHandler.cpp"
|
"GameMessageHandler.cpp"
|
||||||
"GameMessages.cpp"
|
"GameMessages.cpp"
|
||||||
"PropertyDataMessage.cpp"
|
"PropertyDataMessage.cpp"
|
||||||
"PropertySelectQueryProperty.cpp")
|
"PropertySelectQueryProperty.cpp"
|
||||||
|
"GameMessage.cpp")
|
||||||
|
|
||||||
add_library(dGameMessages STATIC ${DGAME_DGAMEMESSAGES_SOURCES})
|
add_library(dGameMessages STATIC ${DGAME_DGAMEMESSAGES_SOURCES})
|
||||||
target_link_libraries(dGameMessages PUBLIC dDatabase)
|
target_link_libraries(dGameMessages PUBLIC dDatabase)
|
||||||
|
107
dGame/dGameMessages/GameMessage.cpp
Normal file
107
dGame/dGameMessages/GameMessage.cpp
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
#include "GameMessage.h"
|
||||||
|
|
||||||
|
#include "AssetManager.h"
|
||||||
|
#include <BinaryPathFinder.h>
|
||||||
|
|
||||||
|
#include "dServer.h"
|
||||||
|
|
||||||
|
GameMessageStorage::GameMessageStorage() {
|
||||||
|
auto path = BinaryPathFinder::GetBinaryDir() / "gms.json";
|
||||||
|
|
||||||
|
std::ifstream i(path);
|
||||||
|
i >> m_Storage;
|
||||||
|
i.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t GameMessageStorage::GetGMFromName(std::string name) {
|
||||||
|
auto messages = m_Storage["messages"];
|
||||||
|
|
||||||
|
for (auto& [key, value] : messages.items()) {
|
||||||
|
if (value["name"] == name) {
|
||||||
|
return std::stoi(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
nlohmann::json GameMessageStorage::GetGM(uint32_t id) {
|
||||||
|
auto messages = m_Storage["messages"];
|
||||||
|
|
||||||
|
if (messages.contains(std::to_string(id))) {
|
||||||
|
return messages[std::to_string(id)];
|
||||||
|
}
|
||||||
|
|
||||||
|
return nlohmann::json();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
GameMessageStorage::~GameMessageStorage() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
GameMessage::GameMessage(std::string name) {
|
||||||
|
auto id = GameMessageStorage::Instance().GetGMFromName(name);
|
||||||
|
if (id == 0) {
|
||||||
|
throw std::exception("GameMessage not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
new(this) GameMessage((eGameMessageType)id);
|
||||||
|
}
|
||||||
|
|
||||||
|
GameMessage::GameMessage(eGameMessageType type) {
|
||||||
|
m_Type = type;
|
||||||
|
m_Message = GameMessageStorage::Instance().GetGM((uint32_t)type);
|
||||||
|
|
||||||
|
m_State = std::map<std::string, std::any>();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GameMessage::Serialize(RakNet::BitStream* bs) {
|
||||||
|
bs->Write<uint16_t>((uint16_t)m_Type);
|
||||||
|
|
||||||
|
for (auto& value : m_Message["params"]) {
|
||||||
|
bool presentInState = m_State.contains(value["name"]);
|
||||||
|
|
||||||
|
if (value["type"] != "bool") {
|
||||||
|
if (!presentInState) {
|
||||||
|
if (value.contains("default")) {
|
||||||
|
|
||||||
|
LOG("Written type %s as default", value["name"].get<std::string>().c_str());
|
||||||
|
bs->Write0();
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
throw std::exception("Fuck.");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (value.contains("default") && value["type"] != "bool") {
|
||||||
|
bs->Write1();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// special case for bool
|
||||||
|
|
||||||
|
if (!presentInState) {
|
||||||
|
if (!value.contains("default")) throw std::exception("uh oh");
|
||||||
|
|
||||||
|
m_State.insert(std::make_pair(value["name"].get<std::string>(), std::any(value["default"] == "true" ? true : false)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string type = value["type"];
|
||||||
|
|
||||||
|
if (type == "Vector3") {
|
||||||
|
auto res = std::any_cast<Vector3>(m_State[value["name"]]);
|
||||||
|
bs->Write(res.GetX());
|
||||||
|
bs->Write(res.GetY());
|
||||||
|
bs->Write(res.GetZ());
|
||||||
|
LOG("Written type %s with values %f %f %f", value["name"].get<std::string>().c_str(), res.GetX(), res.GetY(), res.GetZ());
|
||||||
|
} else if (type == "float") {
|
||||||
|
bs->Write<float>(std::any_cast<float>(m_State[value["name"]]));
|
||||||
|
LOG("Written type %s with value %s", value["name"].get<std::string>().c_str(), std::to_string(std::any_cast<float>(m_State[value["name"]])).c_str());
|
||||||
|
} else if (type == "bool") {
|
||||||
|
bs->Write(std::any_cast<bool>(m_State[value["name"]]));
|
||||||
|
LOG("Written type %s with value %s", value["name"].get<std::string>().c_str(), std::to_string(std::any_cast<bool>(m_State[value["name"]])).c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
56
dGame/dGameMessages/GameMessage.h
Normal file
56
dGame/dGameMessages/GameMessage.h
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <any>
|
||||||
|
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
#include "Singleton.h"
|
||||||
|
#include "eGameMessageType.h"
|
||||||
|
|
||||||
|
typedef std::map<std::string, std::any> StateStorage;
|
||||||
|
|
||||||
|
class GameMessageStorage : public Singleton<GameMessageStorage> {
|
||||||
|
public:
|
||||||
|
GameMessageStorage();
|
||||||
|
~GameMessageStorage();
|
||||||
|
|
||||||
|
uint32_t GetGMFromName(std::string name);
|
||||||
|
nlohmann::json GetGM(uint32_t id);
|
||||||
|
private:
|
||||||
|
nlohmann::json m_Storage;
|
||||||
|
};
|
||||||
|
|
||||||
|
class GameMessage {
|
||||||
|
public:
|
||||||
|
GameMessage(std::string name);
|
||||||
|
GameMessage(eGameMessageType type);
|
||||||
|
|
||||||
|
void Serialize(RakNet::BitStream* bs);
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
inline void Set(std::string key, T value) {
|
||||||
|
m_State[key] = std::any(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
inline T Get(std::string key) {
|
||||||
|
return m_State[key];
|
||||||
|
}
|
||||||
|
|
||||||
|
inline eGameMessageType GetType() {
|
||||||
|
return m_Type;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline StateStorage GetState() {
|
||||||
|
return m_State;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline nlohmann::json GetMessage() {
|
||||||
|
return m_Message;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
eGameMessageType m_Type;
|
||||||
|
nlohmann::json m_Message;
|
||||||
|
|
||||||
|
StateStorage m_State;
|
||||||
|
};
|
@ -100,6 +100,8 @@
|
|||||||
#include "CDComponentsRegistryTable.h"
|
#include "CDComponentsRegistryTable.h"
|
||||||
#include "CDObjectsTable.h"
|
#include "CDObjectsTable.h"
|
||||||
|
|
||||||
|
#include "GameMessage.h"
|
||||||
|
|
||||||
void GameMessages::SendFireEventClientSide(const LWOOBJID& objectID, const SystemAddress& sysAddr, std::u16string args, const LWOOBJID& object, int64_t param1, int param2, const LWOOBJID& sender) {
|
void GameMessages::SendFireEventClientSide(const LWOOBJID& objectID, const SystemAddress& sysAddr, std::u16string args, const LWOOBJID& object, int64_t param1, int param2, const LWOOBJID& sender) {
|
||||||
CBITSTREAM;
|
CBITSTREAM;
|
||||||
CMSGHEADER;
|
CMSGHEADER;
|
||||||
@ -127,30 +129,15 @@ void GameMessages::SendTeleport(const LWOOBJID& objectID, const NiPoint3& pos, c
|
|||||||
CBITSTREAM;
|
CBITSTREAM;
|
||||||
CMSGHEADER;
|
CMSGHEADER;
|
||||||
bitStream.Write(objectID);
|
bitStream.Write(objectID);
|
||||||
bitStream.Write(eGameMessageType::TELEPORT);
|
|
||||||
|
|
||||||
bool bIgnoreY = (pos.y == 0.0f);
|
GameMessage msg = GameMessage(eGameMessageType::TELEPORT);
|
||||||
bool bUseNavmesh = false;
|
|
||||||
bool bSkipAllChecks = false;
|
|
||||||
//float w = 1.0f;
|
|
||||||
//float x = 0.0f;
|
|
||||||
//float y = 0.0f;
|
|
||||||
//float z = 0.0f;
|
|
||||||
|
|
||||||
bitStream.Write(bIgnoreY);
|
msg.Set("pos", pos);
|
||||||
bitStream.Write(bSetRotation);
|
msg.Set("x", rot.x);
|
||||||
bitStream.Write(bSkipAllChecks);
|
msg.Set("y", rot.y);
|
||||||
bitStream.Write(pos.x);
|
msg.Set("z", rot.z);
|
||||||
bitStream.Write(pos.y);
|
|
||||||
bitStream.Write(pos.z);
|
|
||||||
bitStream.Write(bUseNavmesh);
|
|
||||||
|
|
||||||
bitStream.Write(rot.w != 1.0f);
|
msg.Serialize(&bitStream);
|
||||||
if (rot.w != 1.0f) bitStream.Write(rot.w);
|
|
||||||
|
|
||||||
bitStream.Write(rot.x);
|
|
||||||
bitStream.Write(rot.y);
|
|
||||||
bitStream.Write(rot.z);
|
|
||||||
|
|
||||||
SEND_PACKET;
|
SEND_PACKET;
|
||||||
}
|
}
|
||||||
|
5708
resources/gms.json
Normal file
5708
resources/gms.json
Normal file
File diff suppressed because it is too large
Load Diff
3
thirdparty/CMakeLists.txt
vendored
3
thirdparty/CMakeLists.txt
vendored
@ -34,6 +34,9 @@ include(CMakeMariaDBLists.txt)
|
|||||||
# Create our third party library objects
|
# Create our third party library objects
|
||||||
add_subdirectory(raknet)
|
add_subdirectory(raknet)
|
||||||
|
|
||||||
|
# Add nlohmann JSON library
|
||||||
|
add_subdirectory(json)
|
||||||
|
|
||||||
# Download Backtrace if configured
|
# Download Backtrace if configured
|
||||||
if(UNIX AND NOT APPLE)
|
if(UNIX AND NOT APPLE)
|
||||||
include(FetchContent)
|
include(FetchContent)
|
||||||
|
1
thirdparty/json
vendored
Submodule
1
thirdparty/json
vendored
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit a259ecc51e1951e12f757ce17db958e9881e9c6c
|
Loading…
Reference in New Issue
Block a user