mirror of
https://github.com/DarkflameUniverse/DarkflameServer
synced 2024-08-30 18:43:58 +00:00
Remove GameConfig
This commit is contained in:
parent
a8f8de0689
commit
cef5cdeea2
@ -51,3 +51,7 @@ void dConfig::ProcessLine(const std::string& line) {
|
||||
|
||||
this->m_ConfigValues.insert(std::make_pair(key, value));
|
||||
}
|
||||
|
||||
void dConfig::AddToConfig(std::string& key, std::string& value) {
|
||||
this->m_ConfigValues.insert_or_assign(key, value);
|
||||
}
|
||||
|
@ -25,6 +25,11 @@ public:
|
||||
*/
|
||||
void ReloadConfig();
|
||||
|
||||
/**
|
||||
* Adds to or replaces a config in the config values.
|
||||
*/
|
||||
void AddToConfig(std::string& key, std::string& value);
|
||||
|
||||
private:
|
||||
void ProcessLine(const std::string& line);
|
||||
|
||||
|
@ -25,7 +25,6 @@
|
||||
#include "dConfig.h"
|
||||
#include "TeamManager.h"
|
||||
#include "ChatPackets.h"
|
||||
#include "GameConfig.h"
|
||||
#include "RocketLaunchLupComponent.h"
|
||||
#include "eUnequippableActiveType.h"
|
||||
|
||||
@ -999,7 +998,7 @@ void GameMessages::SendSetNetworkScriptVar(Entity* entity, const SystemAddress&
|
||||
}
|
||||
|
||||
void GameMessages::SendDropClientLoot(Entity* entity, const LWOOBJID& sourceID, LOT item, int currency, NiPoint3 spawnPos, int count) {
|
||||
if (GameConfig::GetValue<int32_t>("no_drops") == 1) {
|
||||
if (Game::config->GetValue("no_drops") == "1") {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
set(DGAME_DUTILITIES_SOURCES "BrickDatabase.cpp"
|
||||
"GameConfig.cpp"
|
||||
"GUID.cpp"
|
||||
"Loot.cpp"
|
||||
"Mail.cpp"
|
||||
|
@ -1,50 +0,0 @@
|
||||
#include "GameConfig.h"
|
||||
#include <sstream>
|
||||
|
||||
std::map<std::string, std::string> GameConfig::m_Config{};
|
||||
std::string GameConfig::m_EmptyString{};
|
||||
|
||||
void GameConfig::Load(const std::string& filepath) {
|
||||
m_EmptyString = "";
|
||||
std::ifstream in(filepath);
|
||||
if (!in.good()) return;
|
||||
|
||||
std::string line;
|
||||
while (std::getline(in, line)) {
|
||||
if (line.length() > 0) {
|
||||
if (line[0] != '#') ProcessLine(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const std::string& GameConfig::GetValue(const std::string& key) {
|
||||
const auto& it = m_Config.find(key);
|
||||
|
||||
if (it != m_Config.end()) {
|
||||
return it->second;
|
||||
}
|
||||
|
||||
return m_EmptyString;
|
||||
}
|
||||
|
||||
void GameConfig::SetValue(const std::string& key, const std::string& value) {
|
||||
m_Config.insert_or_assign(key, value);
|
||||
}
|
||||
|
||||
void GameConfig::ProcessLine(const std::string& line) {
|
||||
std::stringstream ss(line);
|
||||
std::string segment;
|
||||
std::vector<std::string> seglist;
|
||||
|
||||
while (std::getline(ss, segment, '=')) {
|
||||
seglist.push_back(segment);
|
||||
}
|
||||
|
||||
if (seglist.size() != 2) return;
|
||||
|
||||
//Make sure that on Linux, we remove special characters:
|
||||
if (!seglist[1].empty() && seglist[1][seglist[1].size() - 1] == '\r')
|
||||
seglist[1].erase(seglist[1].size() - 1);
|
||||
|
||||
m_Config.insert_or_assign(seglist[0], seglist[1]);
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
#pragma once
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#include "GeneralUtils.h"
|
||||
|
||||
class GameConfig {
|
||||
public:
|
||||
static void Load(const std::string& filepath);
|
||||
|
||||
static const std::string& GetValue(const std::string& key);
|
||||
|
||||
static void SetValue(const std::string& key, const std::string& value);
|
||||
|
||||
template <typename T>
|
||||
static T GetValue(const std::string& key) {
|
||||
T value;
|
||||
|
||||
if (GeneralUtils::TryParse(GetValue(key), value)) {
|
||||
return value;
|
||||
}
|
||||
|
||||
return T();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static void SetValue(const std::string& key, const T& value) {
|
||||
SetValue(key, std::to_string(value));
|
||||
}
|
||||
|
||||
private:
|
||||
static void ProcessLine(const std::string& line);
|
||||
|
||||
static std::map<std::string, std::string> m_Config;
|
||||
static std::string m_EmptyString;
|
||||
};
|
@ -60,7 +60,6 @@
|
||||
#include "BuffComponent.h"
|
||||
#include "SkillComponent.h"
|
||||
#include "VanityUtilities.h"
|
||||
#include "GameConfig.h"
|
||||
#include "ScriptedActivityComponent.h"
|
||||
#include "LevelProgressionComponent.h"
|
||||
#include "AssetManager.h"
|
||||
@ -1712,7 +1711,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
|
||||
}
|
||||
|
||||
if (chatCommand == "config-set" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER && args.size() >= 2) {
|
||||
GameConfig::SetValue(args[0], args[1]);
|
||||
Game::config->AddToConfig(args[0], args[1]);
|
||||
|
||||
ChatPackets::SendSystemMessage(
|
||||
sysAddr, u"Set config value: " + GeneralUtils::UTF8ToUTF16(args[0]) + u" to " + GeneralUtils::UTF8ToUTF16(args[1])
|
||||
@ -1720,7 +1719,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
|
||||
}
|
||||
|
||||
if (chatCommand == "config-get" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER && args.size() >= 1) {
|
||||
const auto& value = GameConfig::GetValue(args[0]);
|
||||
const auto& value = Game::config->GetValue(args[0]);
|
||||
|
||||
std::u16string u16key = GeneralUtils::UTF8ToUTF16(args[0]);
|
||||
if (value.empty()) {
|
||||
|
Loading…
Reference in New Issue
Block a user