Merge pull request #768 from diamante0018/develop

[Download]: Add maprotation to info endpoint
This commit is contained in:
Edo 2023-02-10 00:19:51 +00:00 committed by GitHub
commit e924c2907f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 43 additions and 26 deletions

View File

@ -4,8 +4,6 @@
#define STB_TRUETYPE_IMPLEMENTATION #define STB_TRUETYPE_IMPLEMENTATION
#include <stb_truetype.hpp> #include <stb_truetype.hpp>
#include <json.hpp>
namespace Assets namespace Assets
{ {
namespace namespace

View File

@ -1,8 +1,6 @@
#include <STDInclude.hpp> #include <STDInclude.hpp>
#include "IGameWorldMp.hpp" #include "IGameWorldMp.hpp"
#include <json.hpp>
#define IW4X_GAMEWORLD_VERSION 1 #define IW4X_GAMEWORLD_VERSION 1
namespace Assets namespace Assets

View File

@ -1,8 +1,6 @@
#include <STDInclude.hpp> #include <STDInclude.hpp>
#include "ILocalizeEntry.hpp" #include "ILocalizeEntry.hpp"
#include <json.hpp>
namespace Assets namespace Assets
{ {
void ILocalizeEntry::load(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* builder) void ILocalizeEntry::load(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* builder)

View File

@ -1,8 +1,6 @@
#include <STDInclude.hpp> #include <STDInclude.hpp>
#include "Bans.hpp" #include "Bans.hpp"
#include <json.hpp>
namespace Components namespace Components
{ {
const char* Bans::BanListFile = "userraw/bans.json"; const char* Bans::BanListFile = "userraw/bans.json";

View File

@ -5,8 +5,6 @@
#include "GSC/Script.hpp" #include "GSC/Script.hpp"
#include <json.hpp>
namespace Components namespace Components
{ {
Dvar::Var Chat::cg_chatWidth; Dvar::Var Chat::cg_chatWidth;

View File

@ -3,6 +3,7 @@
#include <Utils/WebIO.hpp> #include <Utils/WebIO.hpp>
#include "Download.hpp" #include "Download.hpp"
#include "MapRotation.hpp"
#include "Party.hpp" #include "Party.hpp"
#include "ServerInfo.hpp" #include "ServerInfo.hpp"
@ -348,10 +349,6 @@ namespace Components
} }
} }
#pragma endregion
#pragma region Server
void Download::DownloadProgress(FileDownload* fDownload, std::size_t bytes) void Download::DownloadProgress(FileDownload* fDownload, std::size_t bytes)
{ {
fDownload->receivedBytes += bytes; fDownload->receivedBytes += bytes;
@ -415,6 +412,10 @@ namespace Components
} }
} }
#pragma endregion
#pragma region Server
static std::string InfoHandler() static std::string InfoHandler()
{ {
const auto status = ServerInfo::GetInfo(); const auto status = ServerInfo::GetInfo();
@ -423,6 +424,7 @@ namespace Components
std::unordered_map<std::string, nlohmann::json> info; std::unordered_map<std::string, nlohmann::json> info;
info["status"] = status.to_json(); info["status"] = status.to_json();
info["host"] = host.to_json(); info["host"] = host.to_json();
info["map_rotation"] = MapRotation::to_json();
std::vector<nlohmann::json> players; std::vector<nlohmann::json> players;

View File

@ -1,7 +1,5 @@
#include <STDInclude.hpp> #include <STDInclude.hpp>
#include <json.hpp>
#include "ScriptStorage.hpp" #include "ScriptStorage.hpp"
#include "Script.hpp" #include "Script.hpp"

View File

@ -78,6 +78,32 @@ namespace Components
}); });
} }
nlohmann::json MapRotation::RotationData::to_json() const
{
std::vector<std::string> mapVector;
std::vector<std::string> gametypeVector;
for (const auto& [key, val] : this->rotationEntries_)
{
if (key == "map"s)
{
mapVector.emplace_back(val);
}
else if (key == "gametype"s)
{
gametypeVector.emplace_back(val);
}
}
auto mapRotationJson = nlohmann::json
{
{"maps", mapVector},
{"gametypes", gametypeVector},
};
return mapRotationJson;
}
void MapRotation::LoadRotation(const std::string& data) void MapRotation::LoadRotation(const std::string& data)
{ {
try try
@ -142,6 +168,12 @@ namespace Components
return DedicatedRotation.contains(key, value); return DedicatedRotation.contains(key, value);
} }
nlohmann::json MapRotation::to_json()
{
assert(!DedicatedRotation.empty());
return DedicatedRotation.to_json();
}
bool MapRotation::ShouldRotate() bool MapRotation::ShouldRotate()
{ {
if (!Dedicated::IsEnabled() && SVDontRotate.get<bool>()) if (!Dedicated::IsEnabled() && SVDontRotate.get<bool>())

View File

@ -9,6 +9,8 @@ namespace Components
static bool Contains(const std::string& key, const std::string& value); static bool Contains(const std::string& key, const std::string& value);
static nlohmann::json to_json();
bool unitTest() override; bool unitTest() override;
private: private:
@ -39,6 +41,8 @@ namespace Components
[[nodiscard]] bool empty() const noexcept; [[nodiscard]] bool empty() const noexcept;
[[nodiscard]] bool contains(const std::string& key, const std::string& value) const; [[nodiscard]] bool contains(const std::string& key, const std::string& value) const;
[[nodiscard]] nlohmann::json to_json() const;
private: private:
std::vector<rotationEntry> rotationEntries_; std::vector<rotationEntry> rotationEntries_;

View File

@ -1,7 +1,5 @@
#include <STDInclude.hpp> #include <STDInclude.hpp>
#include <json.hpp>
#include "FastFiles.hpp" #include "FastFiles.hpp"
#include "RawFiles.hpp" #include "RawFiles.hpp"
#include "StartupMessages.hpp" #include "StartupMessages.hpp"

View File

@ -1,8 +1,6 @@
#include <STDInclude.hpp> #include <STDInclude.hpp>
#include "StructuredData.hpp" #include "StructuredData.hpp"
#include <json.hpp>
namespace Components namespace Components
{ {
Utils::Memory::Allocator StructuredData::MemAllocator; Utils::Memory::Allocator StructuredData::MemAllocator;

View File

@ -1,7 +1,5 @@
#include <STDInclude.hpp> #include <STDInclude.hpp>
#include <json.hpp>
#include "Theatre.hpp" #include "Theatre.hpp"
#include "UIFeeder.hpp" #include "UIFeeder.hpp"

View File

@ -4,8 +4,6 @@
#include "Console.hpp" #include "Console.hpp"
#include "FastFiles.hpp" #include "FastFiles.hpp"
#include <json.hpp>
#include <version.hpp> #include <version.hpp>
#include "AssetInterfaces/ILocalizeEntry.hpp" #include "AssetInterfaces/ILocalizeEntry.hpp"

View File

@ -109,6 +109,7 @@ using namespace std::literals;
#define AssertUnreachable assert(0 && "unreachable") #define AssertUnreachable assert(0 && "unreachable")
#include <gsl/gsl> #include <gsl/gsl>
#include <json.hpp>
#include <tomcrypt.h> #include <tomcrypt.h>
#pragma warning(pop) #pragma warning(pop)

View File

@ -1,5 +1,4 @@
#pragma once #pragma once
#include <json.hpp>
namespace Utils namespace Utils
{ {

View File

@ -1,5 +1,4 @@
#pragma once #pragma once
#include <json.hpp>
namespace Utils::Json namespace Utils::Json
{ {