Skip to content

Commit 12e41b3

Browse files
authored
Merge pull request #103 from maelbecel/dev
Dev
2 parents 198d8a9 + be6b8eb commit 12e41b3

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

Client/src/Layer/RTypeLayer.cpp

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace RType {
2929

3030
ApplicationCommandLineArgs commandLine = Application::Get().GetSpecification().CommandLineArgs;
3131

32-
// TODO: Temp port ./r-type_client {port}
32+
// TODO: Temp port ./r-type_client {port} {ip} {port}
3333
int port = 8083; // Default port
3434
if (commandLine.Count > 1) {
3535
port = std::stoi(commandLine[1]);
@@ -42,23 +42,53 @@ namespace RType {
4242
return port;
4343
}
4444

45-
void RTypeLayer::ConnectToServer(int port) {
45+
std::string RTypeLayer::GetIp() {
46+
47+
ApplicationCommandLineArgs commandLine = Application::Get().GetSpecification().CommandLineArgs;
48+
49+
// TODO: Temp ip ./r-type_client {port} {ip} {port}
50+
std::string ip = "127.0.0.1"; // Default ip
51+
if (commandLine.Count > 2) {
52+
ip = commandLine[2];
53+
}
54+
return ip;
55+
}
56+
57+
int RTypeLayer::GetServerPort() {
58+
ApplicationCommandLineArgs commandLine = Application::Get().GetSpecification().CommandLineArgs;
59+
60+
// TODO: Temp port ./r-type_client {port} {ip} {port}
61+
int port = 8083; // Default port
62+
if (commandLine.Count > 3) {
63+
port = std::stoi(commandLine[3]);
64+
65+
if (port < 1024 || port > 65535) {
66+
Application::Get().Close();
67+
return -1;
68+
}
69+
}
70+
return port;
71+
}
72+
73+
void RTypeLayer::ConnectToServer(int port, std::string ip, int serverPort) {
4674
_Network = CreateScope<Network::Network>(_WorldNetwork, _IOContextManager, port);
4775

4876
_Network->Loop();
49-
_Network->SendAskConnect("127.0.0.1", 8082);
77+
_Network->SendAskConnect(ip, (short)serverPort);
5078
// TODO: change ip and port when the server is on a different machine
5179
}
5280

5381
void RTypeLayer::OnAttach() {
5482
EXODIA_PROFILE_FUNCTION();
5583

5684
int port = GetPort();
85+
std::string ip = GetIp();
86+
int serverPort = GetServerPort();
5787

5888
if (port == -1)
5989
return;
6090

61-
ConnectToServer(port);
91+
ConnectToServer(port, ip, serverPort);
6292

6393
// Create world
6494
CurrentScene = GAME;

Client/src/Layer/RTypeLayer.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ namespace RType {
4141

4242
private:
4343
int GetPort();
44-
void ConnectToServer(int port);
44+
std::string GetIp();
45+
int GetServerPort();
46+
void ConnectToServer(int port, std::string ip, int serverPort);
4547

4648
////////////////
4749
// Attributes //

0 commit comments

Comments
 (0)