@@ -82,10 +82,8 @@ void ConnectToServer::setup()
8282{
8383 Log::info (" ConnectToServer" , " SETUPP" );
8484 m_state = NONE;
85- m_public_address.ip = 0 ;
86- m_public_address.port = 0 ;
87- m_server_address.ip = 0 ;
88- m_server_address.port = 0 ;
85+ m_public_address.clear ();
86+ m_server_address.clear ();
8987 m_current_protocol_id = 0 ;
9088}
9189
@@ -139,7 +137,7 @@ void ConnectToServer::asynchronousUpdate()
139137 == PROTOCOL_STATE_TERMINATED) // we know the server address
140138 {
141139 Log::info (" ConnectToServer" , " Server's address known" );
142- if (m_server_address.ip == m_public_address.ip ) // we're in the same lan (same public ip address) !!
140+ if (m_server_address.m_ip == m_public_address.m_ip ) // we're in the same lan (same public ip address) !!
143141 Log::info (" ConnectToServer" , " Server appears to be in the same LAN." );
144142 m_state = REQUESTING_CONNECTION;
145143 m_current_protocol_id = m_listener->requestStart (new RequestConnection (m_server_id));
@@ -150,23 +148,24 @@ void ConnectToServer::asynchronousUpdate()
150148 == PROTOCOL_STATE_TERMINATED) // server knows we wanna connect
151149 {
152150 Log::info (" ConnectToServer" , " Connection request made" );
153- if (m_server_address.ip == 0 || m_server_address.port == 0 )
151+ if (m_server_address.m_ip == 0 || m_server_address.m_port == 0 )
154152 { // server data not correct, hide address and stop
155153 m_state = HIDING_ADDRESS;
156- Log::error (" ConnectToServer" , " Server address is " ADDRESS_FORMAT, ADDRESS_ARGS (m_server_address.ip , m_server_address.port ));
154+ Log::error (" ConnectToServer" , " Server address is %s" ,
155+ m_server_address.toString ().c_str ());
157156 m_current_protocol_id = m_listener->requestStart (new HidePublicAddress ());
158157 return ;
159158 }
160- if (m_server_address.ip == m_public_address.ip ) // we're in the same lan (same public ip address) !!
159+ if (m_server_address.m_ip == m_public_address.m_ip ) // we're in the same lan (same public ip address) !!
161160 {
162161 // just send a broadcast packet, the client will know our ip address and will connect
163162 STKHost* host = NetworkManager::getInstance ()->getHost ();
164163 host->stopListening (); // stop the listening
165164 TransportAddress sender;
166165
167166 TransportAddress broadcast_address;
168- broadcast_address.ip = -1 ; // 255.255.255.255
169- broadcast_address.port = 7321 ; // 0b10101100000101101101111111111111; // for test
167+ broadcast_address.m_ip = -1 ; // 255.255.255.255
168+ broadcast_address.m_port = 7321 ; // 0b10101100000101101101111111111111; // for test
170169 char data2[] = " aloha_stk\0 " ;
171170 host->sendRawPacket ((uint8_t *)(data2), 10 , broadcast_address);
172171
@@ -177,7 +176,8 @@ void ConnectToServer::asynchronousUpdate()
177176 const char data[] = " aloha_stk\0 " ;
178177 if (strcmp (data, (char *)(received_data)) == 0 )
179178 {
180- Log::info (" ConnectToServer" , " LAN Server found : %u:%u" , sender.ip , sender.port );
179+ Log::info (" ConnectToServer" , " LAN Server found : %s" ,
180+ sender.toString ());
181181#ifndef WIN32
182182 // just check if the ip is ours : if so, then just use localhost (127.0.0.1)
183183 struct ifaddrs *ifap, *ifa;
@@ -219,9 +219,9 @@ void ConnectToServer::asynchronousUpdate()
219219 for (unsigned int i=0 ; i<table->dwNumEntries ; i++)
220220 {
221221 unsigned int ip = ntohl (table->table [i].dwAddr );
222- if (sender.ip == ip) // this interface is ours
222+ if (sender.m_ip == ip) // this interface is ours
223223 {
224- sender.ip = 0x7f000001 ; // 127.0.0.1
224+ sender.m_ip = 0x7f000001 ; // 127.0.0.1
225225 break ;
226226 }
227227 }
@@ -246,7 +246,8 @@ void ConnectToServer::asynchronousUpdate()
246246 {
247247 timer = StkTime::getRealTime ();
248248 NetworkManager::getInstance ()->connect (m_server_address);
249- Log::info (" ConnectToServer" , " Trying to connect to %u:%u" , m_server_address.ip , m_server_address.port );
249+ Log::info (" ConnectToServer" , " Trying to connect to %s" ,
250+ m_server_address.toString ());
250251 }
251252 break ;
252253 }
0 commit comments