mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-12-21 03:35:05 -06:00
Compare commits
2 Commits
chat-http-
...
chore--rem
| Author | SHA1 | Date | |
|---|---|---|---|
| facc181ddc | |||
|
|
35c463656d |
@@ -96,7 +96,6 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
|
||||
|
||||
find_package(MariaDB)
|
||||
find_package(JSON)
|
||||
|
||||
# Create a /resServer directory
|
||||
make_directory(${CMAKE_BINARY_DIR}/resServer)
|
||||
@@ -285,7 +284,7 @@ add_subdirectory(dPhysics)
|
||||
add_subdirectory(dServer)
|
||||
|
||||
# Create a list of common libraries shared between all binaries
|
||||
set(COMMON_LIBRARIES "dCommon" "dDatabase" "dNet" "raknet" "MariaDB::ConnCpp" "magic_enum" "nlohmann_json::nlohmann_json")
|
||||
set(COMMON_LIBRARIES "dCommon" "dDatabase" "dNet" "raknet" "MariaDB::ConnCpp" "magic_enum")
|
||||
|
||||
# Add platform specific common libraries
|
||||
if(UNIX)
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
include(FetchContent)
|
||||
|
||||
message(STATUS "Fetching json...")
|
||||
|
||||
FetchContent_Declare(
|
||||
json
|
||||
GIT_REPOSITORY https://github.com/nlohmann/json
|
||||
GIT_TAG v3.11.3
|
||||
)
|
||||
|
||||
FetchContent_GetProperties(json)
|
||||
if(NOT json_POPULATED)
|
||||
FetchContent_Populate(json)
|
||||
add_subdirectory(${json_SOURCE_DIR} ${json_BINARY_DIR} EXCLUDE_FROM_ALL)
|
||||
endif()
|
||||
|
||||
FetchContent_MakeAvailable(json)
|
||||
|
||||
message(STATUS "json fetched and is now ready.")
|
||||
set(JSON_FOUND TRUE)
|
||||
@@ -1,5 +1,4 @@
|
||||
set(DCHATSERVER_SOURCES
|
||||
"ChatWebApi.cpp"
|
||||
"ChatIgnoreList.cpp"
|
||||
"ChatPacketHandler.cpp"
|
||||
"PlayerContainer.cpp"
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
#include "eWorldMessageType.h"
|
||||
#include "ChatIgnoreList.h"
|
||||
#include "StringifiedEnum.h"
|
||||
#include "ChatWebApi.h"
|
||||
|
||||
#include "Game.h"
|
||||
#include "Server.h"
|
||||
@@ -37,7 +36,7 @@ namespace Game {
|
||||
AssetManager* assetManager = nullptr;
|
||||
Game::signal_t lastSignal = 0;
|
||||
std::mt19937 randomEngine;
|
||||
PlayerContainer playerContainer;
|
||||
PlayerContainer playerContainer;
|
||||
}
|
||||
|
||||
void HandlePacket(Packet* packet);
|
||||
@@ -123,9 +122,6 @@ int main(int argc, char** argv) {
|
||||
uint32_t framesSinceMasterDisconnect = 0;
|
||||
uint32_t framesSinceLastSQLPing = 0;
|
||||
|
||||
// start the web api thread
|
||||
std::thread webAPIThread(ChatWebApi::Listen, ourPort);
|
||||
|
||||
Game::logger->Flush(); // once immediately before main loop
|
||||
while (!Game::ShouldShutdown()) {
|
||||
//Check if we're still connected to master:
|
||||
@@ -178,10 +174,6 @@ int main(int argc, char** argv) {
|
||||
delete Game::server;
|
||||
delete Game::logger;
|
||||
delete Game::config;
|
||||
|
||||
// rejoin the web api thread
|
||||
ChatWebApi::Stop();
|
||||
webAPIThread.join();
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -1,93 +0,0 @@
|
||||
#include "ChatWebApi.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "dCommonVars.h"
|
||||
#include "eConnectionType.h"
|
||||
#include "eChatMessageType.h"
|
||||
#include "httplib.h"
|
||||
#include "dServer.h"
|
||||
#include "PlayerContainer.h"
|
||||
#include "dConfig.h"
|
||||
#include "httplib.h"
|
||||
#include "nlohmann/json.hpp"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace {
|
||||
httplib::Server m_APIServer;
|
||||
}
|
||||
|
||||
void ChatWebApi::Listen(const uint32_t port) {
|
||||
if (Game::config->GetValue("enable_chat_web_api") != "1") {
|
||||
LOG("Chat Web API is disabled");
|
||||
return;
|
||||
}
|
||||
LOG("Chat Web API is enabled, starting web server...");
|
||||
|
||||
m_APIServer.Post("/announce", [](const httplib::Request& req, httplib::Response& res) {
|
||||
const json data = json::parse(req.body);
|
||||
if (!data.contains("title")) {
|
||||
res.set_content("{\"error\":\"Missing paramater: title\"}", "application/json");
|
||||
res.status = 400;
|
||||
return;
|
||||
}
|
||||
std::string title = data["title"];
|
||||
if (!data.contains("message")) {
|
||||
res.set_content("{\"error\":\"Missing paramater: message\"}", "application/json");
|
||||
res.status = 400;
|
||||
return;
|
||||
}
|
||||
std::string message = data["message"];
|
||||
// build and send the packet to all world servers
|
||||
CBITSTREAM;
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, eChatMessageType::GM_ANNOUNCE);
|
||||
bitStream.Write<uint32_t>(title.size());
|
||||
bitStream.Write(title);
|
||||
bitStream.Write<uint32_t>(message.size());
|
||||
bitStream.Write(message);
|
||||
Game::server->Send(bitStream, UNASSIGNED_SYSTEM_ADDRESS, true);
|
||||
});
|
||||
|
||||
m_APIServer.Get("/players", [](const httplib::Request& req, httplib::Response& res) {
|
||||
auto data = json::array();
|
||||
for (auto& [playerID, playerData ]: Game::playerContainer.GetAllPlayers()){
|
||||
if (!playerData) continue;
|
||||
data.push_back(playerData.to_json());
|
||||
}
|
||||
res.set_content(data.dump(), "application/json");
|
||||
if (data.empty()) res.status = 204;
|
||||
});
|
||||
|
||||
m_APIServer.Get("/teams", [](const httplib::Request& req, httplib::Response& res) {
|
||||
auto data = json::array();
|
||||
for (auto& teamData: Game::playerContainer.GetAllTeams()){
|
||||
if (!teamData) continue;
|
||||
json toInsert;
|
||||
toInsert["id"] = teamData->teamID;
|
||||
toInsert["loot_flag"] = teamData->lootFlag;
|
||||
toInsert["local"] = teamData->local;
|
||||
|
||||
auto& leader = Game::playerContainer.GetPlayerData(teamData->leaderID);
|
||||
toInsert["leader"] = leader.to_json();
|
||||
|
||||
json members;
|
||||
for (auto& member : teamData->memberIDs){
|
||||
auto playerData = Game::playerContainer.GetPlayerData(member);
|
||||
if (!playerData) continue;
|
||||
members.push_back(playerData.to_json());
|
||||
}
|
||||
toInsert["members"] = members;
|
||||
data.push_back(toInsert);
|
||||
}
|
||||
res.set_content(data.dump(), "application/json");
|
||||
if (data.empty()) res.status = 204;
|
||||
});
|
||||
|
||||
m_APIServer.listen(Game::config->GetValue("chat_web_api_listen_address").c_str(), port);
|
||||
};
|
||||
|
||||
void ChatWebApi::Stop(){
|
||||
LOG("Stopping Chat Web API server...");
|
||||
m_APIServer.stop();
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
#include <cstdint>
|
||||
|
||||
namespace ChatWebApi {
|
||||
void Listen(const uint32_t port);
|
||||
void Stop();
|
||||
};
|
||||
@@ -1,9 +1,7 @@
|
||||
#include "PlayerContainer.h"
|
||||
|
||||
#include "dNetCommon.h"
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
|
||||
#include "dNetCommon.h"
|
||||
#include "Game.h"
|
||||
#include "Logger.h"
|
||||
#include "ChatPacketHandler.h"
|
||||
@@ -13,24 +11,7 @@
|
||||
#include "eConnectionType.h"
|
||||
#include "ChatPackets.h"
|
||||
#include "dConfig.h"
|
||||
#include "eChatMessageType.h"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
const json PlayerData::to_json() const {
|
||||
json data;
|
||||
data["id"] = this->playerID;
|
||||
data["name"] = this->playerName;
|
||||
data["gm_level"] = this->gmLevel;
|
||||
data["muted"] = this->GetIsMuted();
|
||||
|
||||
json zoneID;
|
||||
zoneID["map_id"] = std::to_string(this->zoneID.GetMapID());
|
||||
zoneID["instance_id"] = std::to_string(this->zoneID.GetInstanceID());
|
||||
zoneID["clone_id"] = std::to_string(this->zoneID.GetCloneID());
|
||||
data["zone_id"] = zoneID;
|
||||
return data;
|
||||
}
|
||||
#include "eChatMessageType.h"
|
||||
|
||||
void PlayerContainer::Initialize() {
|
||||
m_MaxNumberOfBestFriends =
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
#include "Game.h"
|
||||
#include "dServer.h"
|
||||
#include <unordered_map>
|
||||
#include "nlohmann/json.hpp"
|
||||
|
||||
enum class eGameMasterLevel : uint8_t;
|
||||
|
||||
@@ -37,8 +36,6 @@ struct PlayerData {
|
||||
return muteExpire == 1 || muteExpire > time(NULL);
|
||||
}
|
||||
|
||||
const nlohmann::json to_json() const;
|
||||
|
||||
SystemAddress sysAddr{};
|
||||
LWOZONEID zoneID{};
|
||||
LWOOBJID playerID = LWOOBJID_EMPTY;
|
||||
@@ -91,7 +88,6 @@ public:
|
||||
LWOOBJID GetId(const std::u16string& playerName);
|
||||
uint32_t GetMaxNumberOfBestFriends() { return m_MaxNumberOfBestFriends; }
|
||||
uint32_t GetMaxNumberOfFriends() { return m_MaxNumberOfFriends; }
|
||||
const std::vector<TeamData*>& GetAllTeams() { return mTeams;};
|
||||
|
||||
private:
|
||||
LWOOBJID m_TeamIDCounter = 0;
|
||||
|
||||
@@ -7,7 +7,7 @@ services:
|
||||
- darkflame
|
||||
image: mariadb:latest
|
||||
volumes:
|
||||
- ${DB_DATA_DIR:-./db/data}:/var/lib/mysql
|
||||
- ${DB_DATA_DIR:-db-data}:/var/lib/mysql
|
||||
environment:
|
||||
- MARIADB_RANDOM_ROOT_PASSWORD=1
|
||||
- MARIADB_USER=${MARIADB_USER:-darkflame}
|
||||
@@ -79,3 +79,6 @@ services:
|
||||
|
||||
networks:
|
||||
darkflame:
|
||||
|
||||
volumes:
|
||||
db-data:
|
||||
|
||||
@@ -1,151 +0,0 @@
|
||||
openapi: 3.0.3
|
||||
info:
|
||||
title: DLU Chat Server API
|
||||
description: |-
|
||||
This documents the available api endpoints for the DLU Chat Server Web API
|
||||
|
||||
contact:
|
||||
name: DarkflameUniverse Github
|
||||
url: https://github.com/DarkflameUniverse/DarkflameServer/issues
|
||||
license:
|
||||
name: GNU AGPL v3.0
|
||||
url: https://github.com/DarkflameUniverse/DarkflameServer/blob/main/LICENSE
|
||||
version: 1.0.0
|
||||
|
||||
externalDocs:
|
||||
description: Find out more about Swagger
|
||||
url: http://swagger.io
|
||||
|
||||
servers:
|
||||
- url: http://localhost:2005/
|
||||
description: localhost
|
||||
|
||||
tags:
|
||||
- name: management
|
||||
description: Server Management Utilities
|
||||
- name: user
|
||||
description: User Data Utilities
|
||||
|
||||
paths:
|
||||
/announce:
|
||||
post:
|
||||
tags:
|
||||
- management
|
||||
summary: Send an announcement to the game server
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Announce"
|
||||
required: true
|
||||
responses:
|
||||
"200":
|
||||
description: Successful operation
|
||||
"400":
|
||||
description: Missing Parameter
|
||||
|
||||
/players:
|
||||
get:
|
||||
tags:
|
||||
- user
|
||||
summary: Get all online Players
|
||||
responses:
|
||||
"200":
|
||||
description: Successful operation
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: "#/components/schemas/Player"
|
||||
"204":
|
||||
description: No Data
|
||||
|
||||
/teams:
|
||||
get:
|
||||
tags:
|
||||
- user
|
||||
summary: Get all active Teams
|
||||
responses:
|
||||
"200":
|
||||
description: Successful operation
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: "#/components/schemas/Team"
|
||||
"204":
|
||||
description: No Data
|
||||
|
||||
components:
|
||||
schemas:
|
||||
Player:
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
format: int64
|
||||
example: 1152921508901824000
|
||||
gm_level:
|
||||
type: integer
|
||||
format: uint8
|
||||
example: 0
|
||||
name:
|
||||
type: string
|
||||
example: thisisatestname
|
||||
muted:
|
||||
type: boolean
|
||||
example: false
|
||||
zone_id:
|
||||
$ref: "#/components/schemas/ZoneID"
|
||||
|
||||
ZoneID:
|
||||
type: object
|
||||
properties:
|
||||
map_id:
|
||||
type: integer
|
||||
format: uint16
|
||||
example: 1200
|
||||
instance_id:
|
||||
type: integer
|
||||
format: uint16
|
||||
example: 2
|
||||
clone_id:
|
||||
type: integer
|
||||
format: uint32
|
||||
example: 0
|
||||
|
||||
Team:
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
format: int64
|
||||
example: 1152921508901824000
|
||||
loot_flag:
|
||||
type: integer
|
||||
format: uint8
|
||||
example: 1
|
||||
local:
|
||||
type: boolean
|
||||
example: false
|
||||
leader:
|
||||
$ref: "#/components/schemas/Player"
|
||||
members:
|
||||
type: array
|
||||
items:
|
||||
$ref: "#/components/schemas/Player"
|
||||
|
||||
Announce:
|
||||
required:
|
||||
- title
|
||||
- message
|
||||
type: object
|
||||
properties:
|
||||
title:
|
||||
type: string
|
||||
example: A Mythran has taken Action against you!
|
||||
message:
|
||||
type: string
|
||||
example: Check your mailbox for details!
|
||||
@@ -6,11 +6,3 @@ max_number_of_best_friends=5
|
||||
# Change the value below to what you would like this to be (50 is live accurate)
|
||||
# going over 50 will be allowed in some secnarios, but proper handling will require client modding
|
||||
max_number_of_friends=50
|
||||
|
||||
# Enable or disable the chat web API, disabled by default
|
||||
# It will run on the same port the chat server is running on, defined in shardconfig.ini
|
||||
enable_chat_web_api=0
|
||||
|
||||
# If that chat web api is enabled, it will only listen for connections on this ip address
|
||||
# 127.0.0.1 is localhost
|
||||
chat_web_api_listen_address=127.0.0.1
|
||||
|
||||
Reference in New Issue
Block a user