From 02e0f76ac4c4afd774259c034554747dd1a7d118 Mon Sep 17 00:00:00 2001 From: Hjalte Dalland Date: Fri, 26 Jan 2024 09:15:31 +0100 Subject: [PATCH] Ip and port --- src/client/Application.cpp | 7 ++++--- src/client/Application.hpp | 2 +- src/engine/NetworkClientSystem.cpp | 7 +++++-- src/engine/NetworkClientSystem.hpp | 4 +++- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/client/Application.cpp b/src/client/Application.cpp index 72b86e3..0539a48 100644 --- a/src/client/Application.cpp +++ b/src/client/Application.cpp @@ -23,14 +23,15 @@ #include "NetworkServerSystem.hpp" #include "NetworkClientSystem.hpp" -void App::run(bool isClient) { +void App::run(int argc, char* argv[]) { instance = this; setupCallBacks(); // We create ImGui in the renderer, so callbacks have to happen before. device = std::make_unique(window); AssetManager manager(device); renderer = std::make_unique(window, device, manager); physicsWorld = std::make_unique(registry); - if (isClient) { + if (argc > 1) { + // TODO: send the ip and port networkSystem = std::make_unique(); } else { networkSystem = std::make_unique(); @@ -870,7 +871,7 @@ App::App() = default; int main(int argc, char* argv[]) { App app; try { - app.run(argc > 1); + app.run(argc, argv); } catch (const std::exception& e) { std::cerr << e.what() << std::endl; return EXIT_FAILURE; diff --git a/src/client/Application.hpp b/src/client/Application.hpp index 747f7ef..d432b63 100644 --- a/src/client/Application.hpp +++ b/src/client/Application.hpp @@ -20,7 +20,7 @@ class App { public: App(); - void run(bool isClient); + void run(int argc, char* argv[]); App inline static* instance = nullptr; diff --git a/src/engine/NetworkClientSystem.cpp b/src/engine/NetworkClientSystem.cpp index 50d5108..8978a99 100644 --- a/src/engine/NetworkClientSystem.cpp +++ b/src/engine/NetworkClientSystem.cpp @@ -12,7 +12,10 @@ using namespace yojimbo; -NetworkClientSystem::NetworkClientSystem() {} +NetworkClientSystem::NetworkClientSystem(std::string ip, uint16_t port) { + this->ip = ip; + this->port = port; +} NetworkClientSystem::~NetworkClientSystem() { client->Disconnect(); @@ -56,7 +59,7 @@ void NetworkClientSystem::init(entt::registry ®istry) { adapter = std::make_unique(); client = std::make_unique(GetDefaultAllocator(), Address("0.0.0.0"), config, *adapter, clientTime); - Address serverAddress("127.0.0.1", ServerPort); + Address serverAddress(ip.data(), port); client->InsecureConnect(privateKey, clientId, serverAddress); } diff --git a/src/engine/NetworkClientSystem.hpp b/src/engine/NetworkClientSystem.hpp index daccd5b..37a98ce 100644 --- a/src/engine/NetworkClientSystem.hpp +++ b/src/engine/NetworkClientSystem.hpp @@ -12,7 +12,7 @@ typedef uint64_t NetworkID; // TODO: Delete this file. Or at least gut it and rework it a bunch class NetworkClientSystem : public INetworkSystem { public: - NetworkClientSystem(); + NetworkClientSystem(std::string ip = "127.0.0.1", uint16_t port = ServerPort); ~NetworkClientSystem(); virtual void init(entt::registry& registry) override; @@ -29,6 +29,8 @@ class NetworkClientSystem : public INetworkSystem { uint8_t privateKey[yojimbo::KeyBytes] = {0}; yojimbo::ClientServerConfig config; yojimbo::NetworkInfo networkInfo; + std::string ip; + uint16_t port; void onNetworkedConstructed(entt::registry& registry, entt::entity entity); void onNetworkedDestroyed(entt::registry& registry, entt::entity entity);