From 75fc3abea5a4e64578999973c1a45baf817cbb9c Mon Sep 17 00:00:00 2001 From: hourcadettej Date: Sun, 13 Nov 2022 21:49:11 +0100 Subject: [PATCH 1/2] feat: implement server info in Connection.hpp --- src/client/AssetLoader.hpp | 12 ++++++++++++ src/ecs/components/client/Connection.hpp | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/client/AssetLoader.hpp b/src/client/AssetLoader.hpp index ed5266e5..a9c8f3f1 100644 --- a/src/client/AssetLoader.hpp +++ b/src/client/AssetLoader.hpp @@ -169,6 +169,11 @@ namespace asset return smart; } + static void LoadServerInfo(const std::string &key, const std::string &info) + { + getInstance()._serverInfo[key] = info; + } + /** * @brief Get an Asset object from the map * @param key of the asset to get @@ -199,6 +204,8 @@ namespace asset static sf::Keyboard::Key &GetKeybind(const std::string &key) { return getInstance()._keyMap[key]; } + static std::string GetServerInfo(const std::string &key) {return getInstance()._serverInfo[key];} + /** * @brief Load a .ini file with boost loading assets into the map */ @@ -224,6 +231,8 @@ namespace asset loadKeybind(value.first, value.second.data()); continue; } + if (section.first == "server") + LoadServerInfo(value.first, value.second.data()); paths.push_back(value.second.data()); if (section.first == "texture") @@ -234,6 +243,7 @@ namespace asset LoadSFX(value.first, paths); if (section.first == "font") LoadFont(value.first, paths); + } } } @@ -289,5 +299,7 @@ namespace asset * Map of all the keybinds, loaded in the [keybinds] section of the .ini file */ std::unordered_map _keyMap; + + std::unordered_map _serverInfo; }; } // namespace asset \ No newline at end of file diff --git a/src/ecs/components/client/Connection.hpp b/src/ecs/components/client/Connection.hpp index eef9715d..7402d4da 100644 --- a/src/ecs/components/client/Connection.hpp +++ b/src/ecs/components/client/Connection.hpp @@ -11,7 +11,7 @@ namespace ecs::component { struct Connection { - Connection(int port = 8000, const std::string &host = "localhost") : _port(std::to_string(port)), _host(host), _isSet(false) {} + Connection() : _port(asset::AssetLoader::GetServerInfo("port")), _host(asset::AssetLoader::GetServerInfo("host")), _isSet(false) {} void setPort(int port) { _port = std::to_string(port); From 5ae9122a6c8ee94e79b04db14cbb0c2bf29a1b92 Mon Sep 17 00:00:00 2001 From: hourcadettej Date: Sun, 13 Nov 2022 22:01:26 +0100 Subject: [PATCH 2/2] feat: implement getServerInfo in entrypoint client --- src/client/entrypoint.cpp | 6 +++--- src/ecs/components/client/Connection.hpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/client/entrypoint.cpp b/src/client/entrypoint.cpp index b0472800..02b8235f 100644 --- a/src/client/entrypoint.cpp +++ b/src/client/entrypoint.cpp @@ -21,12 +21,12 @@ int main() ecs::Engine engine; network::Message msg; - network::Client::setHost("localhost"); - network::Client::setPort("8000"); + asset::AssetLoader::LoadIniFile(asset::AssetLoader::smartPath("assets", "config.ini")); + network::Client::setHost(asset::AssetLoader::GetServerInfo("host")); + network::Client::setPort(asset::AssetLoader::GetServerInfo("port")); msg.fill(0); network::Client::connect(); network::Client::getOutgoingMessages().push(msg); - asset::AssetLoader::LoadIniFile(asset::AssetLoader::smartPath("assets", "config.ini")); audio::AudioManager::playSFX("splash_screen"); ecs::WorldManager::setWaitingWorld(getMenuWorld); audio::AudioManager::setBGMVolume(50); diff --git a/src/ecs/components/client/Connection.hpp b/src/ecs/components/client/Connection.hpp index 7402d4da..8c47a0be 100644 --- a/src/ecs/components/client/Connection.hpp +++ b/src/ecs/components/client/Connection.hpp @@ -11,7 +11,7 @@ namespace ecs::component { struct Connection { - Connection() : _port(asset::AssetLoader::GetServerInfo("port")), _host(asset::AssetLoader::GetServerInfo("host")), _isSet(false) {} + Connection() : _port("8001"), _host(asset::AssetLoader::GetServerInfo("host")), _isSet(false) {} void setPort(int port) { _port = std::to_string(port);