feat: add dns
This commit is contained in:
@@ -8,6 +8,8 @@
|
||||
|
||||
#include "render/Renderer.h"
|
||||
|
||||
#include "network/Network.h"
|
||||
|
||||
namespace td {
|
||||
namespace client {
|
||||
|
||||
@@ -31,7 +33,7 @@ public:
|
||||
|
||||
void render();
|
||||
|
||||
void connect(const std::string& address, std::uint16_t port);
|
||||
void connect(const network::IPAddresses& addresses, std::uint16_t port);
|
||||
void closeConnection();
|
||||
|
||||
bool isConnected() const { return m_Connexion.getSocketStatus() == network::Socket::Connected; }
|
||||
|
||||
@@ -5,10 +5,15 @@
|
||||
namespace td {
|
||||
namespace client {
|
||||
|
||||
void Client::connect(const std::string& address, std::uint16_t port) {
|
||||
if (!m_Connexion.connect(address, port)) {
|
||||
void Client::connect(const network::IPAddresses& addresses, std::uint16_t port) {
|
||||
for (const network::IPAddress& address : addresses) {
|
||||
if (address.IsValid() && m_Connexion.connect(address.ToString(), port)) {
|
||||
m_Connected = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!m_Connected) {
|
||||
std::cout << "Failed to connect !\n";
|
||||
return;
|
||||
}
|
||||
m_Connected = true;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "misc/Time.h"
|
||||
#include "imgui/imgui_filebrowser.h"
|
||||
#include "render/Renderer.h"
|
||||
#include "network/Network.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
@@ -115,14 +116,14 @@ void renderMainMenu() {
|
||||
ImGui::InputText("Server Adress", buffer, sizeof(buffer));
|
||||
ImGui::InputInt("Port", &port, -1);
|
||||
if (ImGui::Button("Rejoindre")) {
|
||||
client->connect(buffer, port);
|
||||
client->connect(td::network::Dns::Resolve(buffer), port);
|
||||
triedToConnect = true;
|
||||
}
|
||||
if (triedToConnect) {
|
||||
ImGui::Text("Impossible de se connecter");
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
} else {
|
||||
} else {
|
||||
triedToConnect = false;
|
||||
}
|
||||
|
||||
@@ -144,14 +145,14 @@ void renderMainMenu() {
|
||||
if (ImGui::Button("Créer")) {
|
||||
if (!startServer(port, worldFilePath)) {
|
||||
triedToCreate = true;
|
||||
} else {
|
||||
client->connect("127.0.0.1", port);
|
||||
} else {
|
||||
client->connect(td::network::Dns::Resolve("localhost"), port);
|
||||
}
|
||||
}
|
||||
if (triedToCreate)
|
||||
ImGui::Text("Failed to launch server");
|
||||
ImGui::EndPopup();
|
||||
} else {
|
||||
} else {
|
||||
triedToCreate = false;
|
||||
}
|
||||
|
||||
@@ -209,7 +210,7 @@ void showLobbyProgress() {
|
||||
ImGui::ProgressBar(progress, ImVec2(0.0f, 0.0f), std::string(std::to_string(client->getGame().getLobbyTime() / 1000) + "s").c_str());
|
||||
ImGui::SameLine(0.0f, ImGui::GetStyle().ItemInnerSpacing.x);
|
||||
ImGui::Text("Time Remaining");
|
||||
} else {
|
||||
} else {
|
||||
ImGui::Text("Waiting for players ...\n");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user