Changeset 9347 in orxonox.OLD for branches/proxy/src/lib/network/udp_socket.cc
- Timestamp:
- Jul 20, 2006, 11:43:27 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/proxy/src/lib/network/udp_socket.cc
r8802 r9347 74 74 { 75 75 this->init(); 76 this->ip = ip; 76 77 this->serverSocket = serverSocket; 77 78 this->userId = userId; … … 105 106 assert( serverSocket == NULL ); 106 107 107 IPaddress ip;108 109 108 this->randomByte = generateNewRandomByte(); 110 109 111 110 PRINTF(0)("connect to server %s on port %d\n", host.c_str(), port); 112 111 113 if ( SDLNet_ResolveHost( & ip, host.c_str(), port ) != 0 )112 if ( SDLNet_ResolveHost( &this->ip, host.c_str(), port ) != 0 ) 114 113 { 115 114 PRINTF(1)("SDLNet_ResolveHost: %s\n", SDLNet_GetError() ); … … 126 125 } 127 126 128 int channel = SDLNet_UDP_Bind(socket, 1, & ip);127 int channel = SDLNet_UDP_Bind(socket, 1, &this->ip); 129 128 if ( channel == -1 ) 130 129 { … … 147 146 bOk = false; 148 147 socket = NULL; 149 } 148 149 this->ip.host = 0; 150 this->ip.port = 0; 151 } 152 153 154 /** 155 * reconnects to 156 * @param host new server address 157 * @param port new port number 158 * 159 * this terminates the current connection and starts a new connection to the new server 160 */ 161 void UdpSocket::reconnectToServer( std::string host, int port) 162 { 163 // first disconnect the old server 164 this->disconnectServer(); 165 166 // now connect to the new 167 this->connectToServer( host, port); 168 } 169 170 171 /** 172 * reconnects to 173 * @param host new server address 174 * @param port new port number 175 * 176 * this terminates the current connection and starts a new connection to the new server 177 */ 178 void UdpSocket::reconnectToServerSoft( std::string host, int port) 179 {} 180 150 181 151 182 /** … … 179 210 180 211 byte udpCmd = 0; 181 212 182 213 if ( networkPacket.length > 0 ) 183 214 { … … 189 220 else 190 221 return 0; 191 222 192 223 if ( !checkRandomByte( networkPacket.data[0] ) ) 193 224 return 0; … … 198 229 networkPacket.data = NULL; 199 230 } 200 231 201 232 if ( !checkUdpCmd( udpCmd ) ) 202 233 return 0; … … 207 238 { 208 239 int numrecv = SDLNet_UDP_Recv( socket, packet); 209 240 210 241 byte udpCmd = 0; 211 242 … … 218 249 else 219 250 return 0; 220 251 221 252 if ( !checkRandomByte( packet->data[0] ) ) 222 253 return 0; 223 254 224 255 if ( !checkUdpCmd( udpCmd ) ) 225 256 return 0; … … 283 314 return false; 284 315 } 285 316 286 317 if ( !this->serverSocket && ( udpCmd & UDPCMD_INVALIDRNDBYTE ) ) 287 318 { … … 292 323 return false; 293 324 } 294 325 295 326 return true; 296 327 } … … 300 331 srand( SDL_GetTicks() ); 301 332 byte res = ( rand() & 0xFC ); 302 333 303 334 PRINTF(0)("generated random byte: %x\n", res); 304 335 305 336 return res; 306 337 }
Note: See TracChangeset
for help on using the changeset viewer.