diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/GlobalState.cpp | 4 | ||||
-rw-r--r-- | src/Render.cpp | 18 | ||||
-rw-r--r-- | src/Render.hpp | 3 |
3 files changed, 16 insertions, 9 deletions
diff --git a/src/GlobalState.cpp b/src/GlobalState.cpp index 8d75bac..9675d4b 100644 --- a/src/GlobalState.cpp +++ b/src/GlobalState.cpp @@ -36,7 +36,7 @@ void InitEvents() { LOG(ERROR) << "Already connected"; return; } - LOG(INFO) << "Connecting to server"; + LOG(INFO) << "Connecting to server at address " + std::get<0>(data) + ":" + std::to_string(std::get<1>(data)) + " as " + std::get<2>(data); PUSH_EVENT("Connecting",0); gs = std::make_unique<GameState>(); isPhysRunning = true; @@ -228,4 +228,4 @@ void GlobalState::SetState(const State &newState) { if (newState != state) PUSH_EVENT("StateUpdated", 0); state = newState; -}
\ No newline at end of file +} diff --git a/src/Render.cpp b/src/Render.cpp index 58cf53d..21e815c 100644 --- a/src/Render.cpp +++ b/src/Render.cpp @@ -33,7 +33,6 @@ Render::Render(unsigned int windowWidth, unsigned int windowHeight, //Read settings strcpy(fieldUsername, Settings::Read("username", "HelloOne").c_str()); strcpy(fieldServerAddr, Settings::Read("serverAddr", "127.0.0.1").c_str()); - fieldServerPort = Settings::ReadInt("serverPort", 25565); fieldDistance = Settings::ReadDouble("renderDistance", 2.0); fieldTargetFps = Settings::ReadDouble("targetFps", 60.0); fieldSensetivity = Settings::ReadDouble("mouseSensetivity", 0.1); @@ -60,7 +59,6 @@ Render::Render(unsigned int windowWidth, unsigned int windowHeight, Render::~Render() { Settings::Write("username", fieldUsername); Settings::Write("serverAddr", fieldServerAddr); - Settings::WriteInt("serverPort", fieldServerPort); Settings::WriteDouble("renderDistance", fieldDistance); Settings::WriteDouble("targetFps", fieldTargetFps); Settings::WriteDouble("mouseSensetivity", fieldSensetivity); @@ -432,12 +430,22 @@ void Render::RenderGui() { ImGui::SetNextWindowPosCenter(); ImGui::Begin("Menu", 0, windowFlags); if (ImGui::Button("Connect")) { - PUSH_EVENT("ConnectToServer", std::make_tuple(std::string(fieldServerAddr), - (unsigned short) fieldServerPort, std::string(fieldUsername))); + std::string addr(fieldServerAddr); + size_t index = addr.find_last_of(':'); + unsigned short port; + if (index == std::string::npos) + port = 25565; + else { + try { + port = std::stoi(addr.substr(index + 1)); + } catch (std::exception &e) { + port = 25565; + } + } + PUSH_EVENT("ConnectToServer", std::make_tuple(addr.substr(0, index), port, std::string(fieldUsername))); } ImGui::InputText("Username", fieldUsername, 512); ImGui::InputText("Address", fieldServerAddr, 512); - ImGui::InputInt("Port", &fieldServerPort); ImGui::Separator(); if (ImGui::Button("Exit")) PUSH_EVENT("Exit",0); diff --git a/src/Render.hpp b/src/Render.hpp index 1157ebb..adb0547 100644 --- a/src/Render.hpp +++ b/src/Render.hpp @@ -34,7 +34,6 @@ class Render { std::string stateString; char fieldUsername[512]; char fieldServerAddr[512]; - int fieldServerPort; float fieldDistance; float fieldSensetivity; float fieldTargetFps; @@ -68,4 +67,4 @@ public: ~Render(); void Update(); -};
\ No newline at end of file +}; |