feat: add dns
This commit is contained in:
@@ -8,6 +8,8 @@
|
|||||||
|
|
||||||
#include "render/Renderer.h"
|
#include "render/Renderer.h"
|
||||||
|
|
||||||
|
#include "network/Network.h"
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
namespace client {
|
namespace client {
|
||||||
|
|
||||||
@@ -31,7 +33,7 @@ public:
|
|||||||
|
|
||||||
void render();
|
void render();
|
||||||
|
|
||||||
void connect(const std::string& address, std::uint16_t port);
|
void connect(const network::IPAddresses& addresses, std::uint16_t port);
|
||||||
void closeConnection();
|
void closeConnection();
|
||||||
|
|
||||||
bool isConnected() const { return m_Connexion.getSocketStatus() == network::Socket::Connected; }
|
bool isConnected() const { return m_Connexion.getSocketStatus() == network::Socket::Connected; }
|
||||||
|
|||||||
@@ -5,10 +5,15 @@
|
|||||||
namespace td {
|
namespace td {
|
||||||
namespace client {
|
namespace client {
|
||||||
|
|
||||||
void Client::connect(const std::string& address, std::uint16_t port) {
|
void Client::connect(const network::IPAddresses& addresses, std::uint16_t port) {
|
||||||
if (!m_Connexion.connect(address, 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";
|
std::cout << "Failed to connect !\n";
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
m_Connected = true;
|
m_Connected = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
#include "misc/Time.h"
|
#include "misc/Time.h"
|
||||||
#include "imgui/imgui_filebrowser.h"
|
#include "imgui/imgui_filebrowser.h"
|
||||||
#include "render/Renderer.h"
|
#include "render/Renderer.h"
|
||||||
|
#include "network/Network.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
@@ -115,7 +116,7 @@ void renderMainMenu() {
|
|||||||
ImGui::InputText("Server Adress", buffer, sizeof(buffer));
|
ImGui::InputText("Server Adress", buffer, sizeof(buffer));
|
||||||
ImGui::InputInt("Port", &port, -1);
|
ImGui::InputInt("Port", &port, -1);
|
||||||
if (ImGui::Button("Rejoindre")) {
|
if (ImGui::Button("Rejoindre")) {
|
||||||
client->connect(buffer, port);
|
client->connect(td::network::Dns::Resolve(buffer), port);
|
||||||
triedToConnect = true;
|
triedToConnect = true;
|
||||||
}
|
}
|
||||||
if (triedToConnect) {
|
if (triedToConnect) {
|
||||||
@@ -145,7 +146,7 @@ void renderMainMenu() {
|
|||||||
if (!startServer(port, worldFilePath)) {
|
if (!startServer(port, worldFilePath)) {
|
||||||
triedToCreate = true;
|
triedToCreate = true;
|
||||||
} else {
|
} else {
|
||||||
client->connect("127.0.0.1", port);
|
client->connect(td::network::Dns::Resolve("localhost"), port);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (triedToCreate)
|
if (triedToCreate)
|
||||||
|
|||||||
Reference in New Issue
Block a user