summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authoruis <uis9936@gmail.com>2018-10-14 19:28:27 +0200
committeruis <uis9936@gmail.com>2018-10-17 18:34:53 +0200
commitfcdaed08febfc95dacfb099f27cbcd7f9db59369 (patch)
tree31a921e8413ff4e944cacf4ab096c9a6d81e390e /src
parentUpdate README.md (diff)
downloadAltCraft-fcdaed08febfc95dacfb099f27cbcd7f9db59369.tar
AltCraft-fcdaed08febfc95dacfb099f27cbcd7f9db59369.tar.gz
AltCraft-fcdaed08febfc95dacfb099f27cbcd7f9db59369.tar.bz2
AltCraft-fcdaed08febfc95dacfb099f27cbcd7f9db59369.tar.lz
AltCraft-fcdaed08febfc95dacfb099f27cbcd7f9db59369.tar.xz
AltCraft-fcdaed08febfc95dacfb099f27cbcd7f9db59369.tar.zst
AltCraft-fcdaed08febfc95dacfb099f27cbcd7f9db59369.zip
Diffstat (limited to 'src')
-rw-r--r--src/GlobalState.cpp4
-rw-r--r--src/Render.cpp18
-rw-r--r--src/Render.hpp3
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
+};