- Timestamp:
- May 21, 2015, 2:39:05 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/multiplayerFS15/src/libraries/network/MasterServer.cc
r10434 r10447 44 44 /* forward declaration so the linker doesn't complain */ 45 45 MasterServer *MasterServer::instance = NULL; 46 47 48 49 46 50 47 /* command: list servers */ … … 266 263 char *addrconv = (char *) calloc( 50, 1 ); 267 264 enet_address_get_host_ip( &(event->peer->address), addrconv, 49 ); 265 /* convert to string */ 266 std::string ip = std::string( addrconv ); 267 /* delete addrconv */ 268 if( addrconv ) free( addrconv ); 269 270 /* pointer to full packet data */ 271 char * packetdata = (char *)event->packet->data; 268 272 269 273 /* output debug info about the data that has come */ … … 271 275 272 276 /* GAME SERVER OR CLIENT CONNECTION? */ 273 if( !strncmp( (char *)event->packet->data, MSPROTO_GAME_SERVER, 274 MSPROTO_GAME_SERVER_LEN ) ) 277 if( !strncmp(packetdata, MSPROTO_GAME_SERVER, MSPROTO_GAME_SERVER_LEN ) ) 275 278 { /* Game server */ 276 279 277 if( !strncmp( (char *)event->packet->data 278 + MSPROTO_GAME_SERVER_LEN+1, 279 MSPROTO_REGISTER_SERVER, MSPROTO_REGISTER_SERVER_LEN ) ) 280 if( !strncmp( packetdata + MSPROTO_GAME_SERVER_LEN+1, MSPROTO_REGISTER_SERVER, MSPROTO_REGISTER_SERVER_LEN ) ) 280 281 { /* register new server */ 281 mainlist.addServer( packet::ServerInformation( event ), 282 event->peer ); 282 mainlist.addServer( packet::ServerInformation( event ), event->peer ); 283 283 284 284 /* tell people we did so */ … … 287 287 } 288 288 289 else if( !strncmp( (char *)event->packet->data 290 + MSPROTO_GAME_SERVER_LEN+1, 291 MSPROTO_SERVERDC, MSPROTO_SERVERDC_LEN ) ) 292 { 293 /* create string from peer data */ 294 std::string ip = std::string( addrconv ); 289 else if( !strncmp( packetdata + MSPROTO_GAME_SERVER_LEN+1, MSPROTO_SERVERDC, MSPROTO_SERVERDC_LEN ) ) 290 { /* disconnect server */ 295 291 296 292 /* remove the server from the list it belongs to */ … … 302 298 /* TODO add hook for disconnect here */ 303 299 304 else if( !strncmp( (char *)event->packet->data 305 + MSPROTO_GAME_SERVER_LEN+1, 306 MSPROTO_SET_NAME, MSPROTO_SET_NAME_LEN ) ) 307 { 300 else if( !strncmp( packetdata + MSPROTO_GAME_SERVER_LEN+1, MSPROTO_SET_NAME, MSPROTO_SET_NAME_LEN ) ) 301 { /* save server name */ 308 302 /* create string from peer data */ 309 std::string ip = std::string( addrconv );310 303 std::string data (event->packet->data,event->packet->data + event->packet->dataLength ); 311 304 std::string name = data.substr(MSPROTO_GAME_SERVER_LEN+1 + MSPROTO_SET_NAME_LEN + 1); … … 318 311 } 319 312 320 else if( !strncmp( (char *)event->packet->data 321 + MSPROTO_GAME_SERVER_LEN+1, 322 MSPROTO_SET_CLIENTS, MSPROTO_SET_CLIENTS_LEN ) ) 323 { 313 else if( !strncmp( packetdata + MSPROTO_GAME_SERVER_LEN+1, MSPROTO_SET_CLIENTS, MSPROTO_SET_CLIENTS_LEN ) ) 314 { /* save client count from server */ 324 315 /* create string from peer data */ 325 std::string ip = std::string( addrconv );326 316 std::string data (event->packet->data,event->packet->data + event->packet->dataLength ); 327 317 std::string textform= data.substr(MSPROTO_GAME_SERVER_LEN + 1 + MSPROTO_SET_CLIENTS_LEN + 1); … … 334 324 } 335 325 } 336 else if( !strncmp( (char *)event->packet->data, MSPROTO_CLIENT, 337 MSPROTO_CLIENT_LEN) ) 326 else if( !strncmp( packetdata, MSPROTO_CLIENT, MSPROTO_CLIENT_LEN) ) 338 327 { /* client */ 339 if( !strncmp( (char *)event->packet->data + MSPROTO_CLIENT_LEN+1, 340 MSPROTO_REQ_LIST, MSPROTO_REQ_LIST_LEN ) ) 328 if( !strncmp( packetdata + MSPROTO_CLIENT_LEN+1, MSPROTO_REQ_LIST, MSPROTO_REQ_LIST_LEN ) ) 341 329 /* send server list */ 342 330 helper_sendlist( event ); … … 344 332 else 345 333 { /* bad message, don't do anything. */ } 346 347 /* delete addrconv */348 if( addrconv ) free( addrconv );349 334 350 335 /* Clean up the packet now that we're done using it. */
Note: See TracChangeset
for help on using the changeset viewer.