Changeset 7651
- Timestamp:
- Nov 17, 2010, 4:18:14 PM (14 years ago)
- Location:
- code/branches/masterserver/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/masterserver/src/libraries/network/WANDiscovery.cc
r7650 r7651 62 62 63 63 /* callback for the network reply poller */ 64 /* WORK MARK WORK WORK */ 64 65 /* NOTE implement protocol-specific part here. */ 65 int rhandler( char *addr, ENetEvent *ev )66 int WANDiscovery::rhandler( char *addr, ENetEvent *ev ) 66 67 { 67 68 /* handle incoming data */ 68 69 /* if a list entry arrives add to list */ 69 if( !strncmp( ev->packet->data, MSPROTO_SERVERLIST_ITEM,70 if( !strncmp( (char*)ev->packet->data, MSPROTO_SERVERLIST_ITEM, 70 71 MSPROTO_SERVERLIST_ITEM_LEN ) ) 71 72 { 72 73 /* create server structure from that item */ 73 ServerInformation toadd;74 packet::ServerInformation toadd; 74 75 75 76 /* fill in data */ 76 toadd ->setName( std::string(ev->packet->data +77 toadd.setServerName( std::string((char*)ev->packet->data + 77 78 MSPROTO_SERVERLIST_ITEM_LEN) ); 78 toadd ->setIP( std::string(ev->packet->data +79 toadd.setServerIP( std::string((char*)ev->packet->data + 79 80 MSPROTO_SERVERLIST_ITEM_LEN) ); 80 81 81 82 /* add to list */ 82 this->servers_. add( toadd );83 this->servers_.push_back( toadd ); 83 84 } 84 else if( !strncmp( ev->packet->data, MSPROTO_SERVERLIST_END,85 else if( !strncmp( (char*)ev->packet->data, MSPROTO_SERVERLIST_END, 85 86 MSPROTO_SERVERLIST_END_LEN ) ) 86 87 { return 1; } … … 99 100 100 101 /* deal with replies */ 101 while( !msc.pollForReply( rhandler ) )102 while( !msc.pollForReply( WANDiscovery::rhandler ) ) 102 103 /* nothing */; 103 104 -
code/branches/masterserver/src/libraries/network/WANDiscovery.h
r7650 r7651 77 77 */ 78 78 static WANDiscovery& getInstance() { return Singleton<WANDiscovery>::getInstance(); } // tolua_export 79 80 int rhandler( char *addr, ENetEvent *ev ); 79 81 80 82 private: -
code/branches/masterserver/src/libraries/network/packet/ServerInformation.h
r7459 r7651 50 50 std::string getServerName() { return this->serverName_; } 51 51 void setServerName(std::string name) { this->serverName_ = name; } 52 void setServerIP( std::string IP ) { this->serverIP_ = IP; } 52 53 uint32_t getServerRTT() { return this->serverRTT_; } 53 54 -
code/branches/masterserver/src/modules/masterserver/MasterServer.cc
r7630 r7651 57 57 << event->peer->address.port << "\n"; 58 58 59 /* game server or client connection? */60 /* -> decide in protocol */61 /* game server */62 /* add to game server list */63 /* */64 65 /* client */66 /* add to client list */67 68 59 /* store string form of address here */ 69 60 event->peer->data = addrconv; … … 82 73 } 83 74 84 /* output that the disconnect happened , to be removed at a later time.*/75 /* output that the disconnect happened */ 85 76 COUT(4) << (char*)event->peer->data << " disconnected.\n"; 86 77 78 /* create string from peer data */ 79 std::string name = std::string( (char*)event->peer->data ); 80 87 81 /* remove the server from the list it belongs to */ 82 this->mainlist->delServerByName( name ); 88 83 89 84 /* Reset the peer's client information. */ 90 85 if( event->peer->data ) free( event->peer->data ); 86 87 /* done */ 91 88 return 0; 92 89 } … … 95 92 int 96 93 MasterServer::eventData( ENetEvent *event ) 97 { /* output what's in the packet (to be removed later)*/94 { /* validate packet */ 98 95 if( !event || !(event->packet) || !(event->peer) ) 96 //|| !(event->packet->data) || !strlen(event->packet->data) ) 99 97 { COUT(2) << "No complete event given.\n"; 100 98 return -1; … … 110 108 << event->packet->dataLength 111 109 << " containing " 112 << event->packet->data110 << (const char*)event->packet->data 113 111 << " was received from " 114 112 << addrconv … … 116 114 << event->channelID << "\n"; 117 115 116 /* 118 117 //[> send some packet back for testing <] 119 118 //[> TESTING <] … … 131 130 132 131 //[> /TESTING <] 132 */ 133 133 134 134 /* GAME SERVER OR CLIENT CONNECTION? */ 135 136 /* Game server */ 137 /* parse data */ 138 /* start actions */ 139 /* and send reply */ 140 141 /* client */ 142 /* parse data */ 143 /* start actions */ 144 /* and send reply */ 135 if( !strncmp( (char *)event->packet->data, MSPROTO_GAME_SERVER, 136 MSPROTO_GAME_SERVER_LEN ) ) 137 { /* Game server */ 138 139 if( !strncmp( (char *)event->packet->data 140 + MSPROTO_GAME_SERVER_LEN+1, 141 MSPROTO_REGISTER_SERVER, MSPROTO_REGISTER_SERVER_LEN ) ) 142 { /* register new server */ 143 mainlist->addServer( packet::ServerInformation( event ) ); 144 } 145 } 146 else if( !strncmp( (char *)event->packet->data, MSPROTO_CLIENT, 147 MSPROTO_CLIENT_LEN) ) 148 { /* client */ 149 150 if( !strncmp( (char *)event->packet->data + MSPROTO_CLIENT_LEN+1, 151 MSPROTO_REQ_LIST ) ) 152 { /* send server list */ 153 154 /* get an iterator */ 155 std::list<packet::ServerInformation *>::iterator i; 156 157 /* loop through list elements */ 158 for( i = serverlist.begin(); i != serverlist.end(); ++i ) 159 { 160 /* WORK MARK */ 161 /* send this particular server */ 162 /* build reply string */ 163 char *tosend = (char *)calloc( (*i)->getServerIP().length() + 1,1 ); 164 snprintf( "%s %s", MSPROTO_SERVERLIST_ITEM, (*i)->getServerIP() ); 165 166 /* create packet from it */ 167 ENetPacket * reply = enet_packet_create( tosend, 168 strlen( tosend ) + 1, 169 ENET_PACKET_FLAG_RELIABLE); 170 171 /* Send the reply to the peer over channel id 0. */ 172 enet_peer_send( event->peer, 0, reply ); 173 174 /* One could just use enet_host_service() instead. */ 175 enet_host_flush( this->server ); 176 } 177 } 178 } 179 else 180 { /* bad message, don't do anything. */ } 145 181 146 182 /* delete addrconv */ -
code/branches/masterserver/src/modules/masterserver/MasterServer.h
r7611 r7651 39 39 #include <network/packet/Welcome.h> 40 40 #include <util/Singleton.h> 41 #include <network/MasterServerProtocol.h> 41 42 42 43 /* my includes */ … … 46 47 /* c compatibility */ 47 48 #include <cstdio> 48 49 #define ORX_MSERVER_PORT 123450 #define ORX_MSERVER_MAXCONNS 3251 #define ORX_MSERVER_MAXCHANS 252 49 53 50 namespace orxonox -
code/branches/masterserver/src/modules/masterserver/ServerList.h
r7631 r7651 77 77 void sortByPing(); 78 78 79 private:80 79 /** the list of servers for internal storage */ 81 80 std::list<packet::ServerInformation *> serverlist; 81 private: 82 82 }; 83 83 }
Note: See TracChangeset
for help on using the changeset viewer.