@@ -29,7 +29,7 @@ namespace RType {
29
29
30
30
ApplicationCommandLineArgs commandLine = Application::Get ().GetSpecification ().CommandLineArgs ;
31
31
32
- // TODO: Temp port ./r-type_client {port}
32
+ // TODO: Temp port ./r-type_client {port} {ip} {port}
33
33
int port = 8083 ; // Default port
34
34
if (commandLine.Count > 1 ) {
35
35
port = std::stoi (commandLine[1 ]);
@@ -42,23 +42,53 @@ namespace RType {
42
42
return port;
43
43
}
44
44
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) {
46
74
_Network = CreateScope<Network::Network>(_WorldNetwork, _IOContextManager, port);
47
75
48
76
_Network->Loop ();
49
- _Network->SendAskConnect (" 127.0.0.1 " , 8082 );
77
+ _Network->SendAskConnect (ip, ( short )serverPort );
50
78
// TODO: change ip and port when the server is on a different machine
51
79
}
52
80
53
81
void RTypeLayer::OnAttach () {
54
82
EXODIA_PROFILE_FUNCTION ();
55
83
56
84
int port = GetPort ();
85
+ std::string ip = GetIp ();
86
+ int serverPort = GetServerPort ();
57
87
58
88
if (port == -1 )
59
89
return ;
60
90
61
- ConnectToServer (port);
91
+ ConnectToServer (port, ip, serverPort );
62
92
63
93
// Create world
64
94
CurrentScene = GAME;
0 commit comments