mirror of
				https://github.com/DarkflameUniverse/DarkflameServer.git
				synced 2025-10-31 12:41:55 +00:00 
			
		
		
		
	Remove GameConfig
This commit is contained in:
		| @@ -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()) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 EmosewaMC
					EmosewaMC