mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-11-25 15:07:28 +00:00
provide all the info for a some integration client to use
who->players add teams endpoint
This commit is contained in:
parent
55a52b6cc0
commit
ed7b33d8ab
@ -40,13 +40,36 @@ void ChatHttpApi::Listen(const uint32_t port) {
|
|||||||
Game::server->Send(bitStream, UNASSIGNED_SYSTEM_ADDRESS, true);
|
Game::server->Send(bitStream, UNASSIGNED_SYSTEM_ADDRESS, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
m_APIServer.Get("/who", [](const httplib::Request& req, httplib::Response& res) {
|
m_APIServer.Get("/players", [](const httplib::Request& req, httplib::Response& res) {
|
||||||
json data;
|
auto data = json::array();
|
||||||
for (auto& [playerID, playerData ]: Game::playerContainer.GetAllPlayers()){
|
for (auto& [playerID, playerData ]: Game::playerContainer.GetAllPlayers()){
|
||||||
if (!playerData) continue;
|
if (!playerData) continue;
|
||||||
auto map = std::to_string(playerData.zoneID.GetMapID());
|
data.push_back(playerData.to_json());
|
||||||
if (!data.contains(map)) data[map] = json::array();
|
}
|
||||||
data[map].push_back(playerData.playerName);
|
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");
|
res.set_content(data.dump(), "application/json");
|
||||||
if (data.empty()) res.status = 204;
|
if (data.empty()) res.status = 204;
|
||||||
@ -55,8 +78,6 @@ void ChatHttpApi::Listen(const uint32_t port) {
|
|||||||
m_APIServer.listen("0.0.0.0", port);
|
m_APIServer.listen("0.0.0.0", port);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void ChatHttpApi::Stop(){
|
void ChatHttpApi::Stop(){
|
||||||
m_APIServer.stop();
|
m_APIServer.stop();
|
||||||
}
|
}
|
@ -1,7 +1,8 @@
|
|||||||
#include "PlayerContainer.h"
|
|
||||||
#include "dNetCommon.h"
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
#include "PlayerContainer.h"
|
||||||
|
#include "dNetCommon.h"
|
||||||
#include "Game.h"
|
#include "Game.h"
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include "ChatPacketHandler.h"
|
#include "ChatPacketHandler.h"
|
||||||
@ -13,6 +14,22 @@
|
|||||||
#include "dConfig.h"
|
#include "dConfig.h"
|
||||||
#include "eChatMessageType.h"
|
#include "eChatMessageType.h"
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
void PlayerContainer::Initialize() {
|
void PlayerContainer::Initialize() {
|
||||||
m_MaxNumberOfBestFriends =
|
m_MaxNumberOfBestFriends =
|
||||||
GeneralUtils::TryParse<uint32_t>(Game::config->GetValue("max_number_of_best_friends")).value_or(m_MaxNumberOfBestFriends);
|
GeneralUtils::TryParse<uint32_t>(Game::config->GetValue("max_number_of_best_friends")).value_or(m_MaxNumberOfBestFriends);
|
||||||
|
@ -7,6 +7,9 @@
|
|||||||
#include "dServer.h"
|
#include "dServer.h"
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
using json = nlohmann::json;
|
||||||
|
|
||||||
enum class eGameMasterLevel : uint8_t;
|
enum class eGameMasterLevel : uint8_t;
|
||||||
|
|
||||||
struct IgnoreData {
|
struct IgnoreData {
|
||||||
@ -36,6 +39,8 @@ struct PlayerData {
|
|||||||
return muteExpire == 1 || muteExpire > time(NULL);
|
return muteExpire == 1 || muteExpire > time(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const json to_json() const;
|
||||||
|
|
||||||
SystemAddress sysAddr{};
|
SystemAddress sysAddr{};
|
||||||
LWOZONEID zoneID{};
|
LWOZONEID zoneID{};
|
||||||
LWOOBJID playerID = LWOOBJID_EMPTY;
|
LWOOBJID playerID = LWOOBJID_EMPTY;
|
||||||
@ -88,6 +93,7 @@ public:
|
|||||||
LWOOBJID GetId(const std::u16string& playerName);
|
LWOOBJID GetId(const std::u16string& playerName);
|
||||||
uint32_t GetMaxNumberOfBestFriends() { return m_MaxNumberOfBestFriends; }
|
uint32_t GetMaxNumberOfBestFriends() { return m_MaxNumberOfBestFriends; }
|
||||||
uint32_t GetMaxNumberOfFriends() { return m_MaxNumberOfFriends; }
|
uint32_t GetMaxNumberOfFriends() { return m_MaxNumberOfFriends; }
|
||||||
|
const std::vector<TeamData*> GetAllTeams() { return mTeams;};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
LWOOBJID m_TeamIDCounter = 0;
|
LWOOBJID m_TeamIDCounter = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user