Changeset 10612 for code/branches/presentationFS15merge
- Timestamp:
- Oct 4, 2015, 12:13:42 PM (9 years ago)
- Location:
- code/branches/presentationFS15merge
- Files:
-
- 22 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentationFS15merge
- Property svn:mergeinfo changed
/code/branches/multiplayerFS15 (added) merged: 10324,10334,10427,10434,10446-10447,10456-10457
- Property svn:mergeinfo changed
-
code/branches/presentationFS15merge/data/gui/scripts/MultiplayerMenu.lua
r8858 r10612 70 70 if choice then 71 71 local index = tolua.cast(choice, "CEGUI::ListboxItem"):getID() 72 destination = P.serverList[index][ 2]72 destination = P.serverList[index][1] 73 73 else 74 74 return … … 93 93 local servername = "" 94 94 local serverip = "" 95 local serverrtt = "" 96 local playernumber = "" 95 97 while true do 96 98 servername = discovery:getServerListItemName(index) … … 102 104 break 103 105 end 104 table.insert(P.serverList, {servername, serverip}) 106 --serverrtt = discovery:getServerListItemRTT(index) 107 playernumber = discovery:getServerListItemPlayerNumber(index) 108 109 table.insert(P.serverList, {serverip, servername, playernumber}) 105 110 index = index + 1 106 111 end 107 112 index = 1 108 113 for k,v in pairs(P.serverList) do 109 local item = CEGUI.createListboxTextItem( v[1] .. ": " .. v[2])114 local item = CEGUI.createListboxTextItem("IP: " .. v[1] .. " Name: " .. v[2] .. " Players: " .. v[3]) 110 115 item:setID(index) 111 116 index = index + 1 … … 125 130 local servername = "" 126 131 local serverip = "" 132 local serverrtt = "" 133 local playernumber = "" 127 134 while true do 128 135 servername = discovery:getServerListItemName(index) … … 134 141 break 135 142 end 136 table.insert(P.serverList, {servername, serverip}) 143 --serverrtt = discovery:getServerListItemRTT(index) 144 playernumber = discovery:getServerListItemPlayerNumber(index) 145 146 table.insert(P.serverList, {serverip, servername, playernumber}) 137 147 index = index + 1 138 148 end 139 149 index = 1 140 150 for k,v in pairs(P.serverList) do 141 local item = CEGUI.createListboxTextItem( v[1] .. ": " .. v[2])151 local item = CEGUI.createListboxTextItem("IP: " .. v[1] .. " Name: " .. v[2] .. " Players: " .. v[3]) 142 152 item:setID(index) 143 153 index = index + 1 … … 150 160 151 161 return P 152 -
code/branches/presentationFS15merge/src/libraries/network/GamestateManager.h
r8402 r10612 1 /*1 /* 2 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 3 * > www.orxonox.net < … … 78 78 std::map< uint32_t, packet::Gamestate* > gamestates; 79 79 }; 80 80 81 81 public: 82 82 83 83 GamestateManager(); 84 84 ~GamestateManager(); … … 88 88 virtual uint32_t getLastReceivedGamestateID( unsigned int peerID ); 89 89 virtual uint32_t getCurrentGamestateID(){ if( currentGamestate_) return currentGamestate_->getID(); else return GAMESTATEID_INITIAL; } 90 90 91 91 bool processGamestates(); 92 92 bool sendAck(unsigned int gamestateID, uint32_t peerID); -
code/branches/presentationFS15merge/src/libraries/network/LANDiscoverable.cc
r8858 r10612 35 35 #include "util/Output.h" 36 36 #include "packet/ServerInformation.h" 37 #include "core/config/ConfigValueIncludes.h" 38 #include "core/CoreIncludes.h" 39 37 40 38 41 namespace orxonox … … 43 46 LANDiscoverable::LANDiscoverable() 44 47 { 48 /* register object in orxonox */ 49 RegisterObject(LANDiscoverable); 50 51 this->setConfigValues(); 52 // this->setActivity(true); 45 53 this->host_ = 0; 46 54 this->bActive_ = false; 47 // this->setActivity(true); 55 } 56 57 void LANDiscoverable::setConfigValues() 58 { 59 /* update ownName string from orxonox.ini config file, if it 60 * has changed. 61 */ 62 SetConfigValueExternal(ownName, "Discovery", "ownName", "OrxServer"); 48 63 } 49 64 … … 61 76 if( bActive == this->bActive_ ) // no change 62 77 return; 63 78 64 79 if( bActive ) 65 80 { … … 84 99 { 85 100 ENetEvent event; 86 101 87 102 if( this->bActive_==false ) 88 103 return; 89 104 assert(this->host_); 90 105 91 106 while( enet_host_service( this->host_, &event, 0 ) > 0 ) 92 107 { … … 104 119 orxout(internal_info, context::network) << "Received LAN discovery message from client " << event.peer->host->receivedAddress << endl; 105 120 packet::ServerInformation info; 106 info.setServerName("Orxonox Server"); 121 info.setServerName(this->ownName); 122 info.setClientNumber(this->clientNumber); 107 123 info.send(event.peer); 108 124 // ENetPacket* packet = enet_packet_create( LAN_DISCOVERY_ACK, strlen(LAN_DISCOVERY_ACK)+1, ENET_PACKET_FLAG_RELIABLE ); -
code/branches/presentationFS15merge/src/libraries/network/LANDiscoverable.h
r8351 r10612 31 31 32 32 #include "NetworkPrereqs.h" 33 #include "core/config/Configurable.h" 33 34 34 35 namespace orxonox 35 36 { 36 37 37 class LANDiscoverable 38 class LANDiscoverable: public Configurable 38 39 { 39 40 public: … … 42 43 void setActivity( bool bActive ); 43 44 void update(); 45 void updateClientNumber(int clientNumber) {this->clientNumber = clientNumber;} 46 ; 47 /** Function used for the configuration file parameter update */ 48 void setConfigValues(); 44 49 45 50 private: 46 51 bool bActive_; 47 52 ENetHost* host_; 53 std::string ownName; 54 int clientNumber; 48 55 }; 49 56 -
code/branches/presentationFS15merge/src/libraries/network/LANDiscovery.cc
r8858 r10612 89 89 { 90 90 packet::ServerInformation info(&event); 91 orxout(internal_info, context::network) << "Received LAN discovery server information; Name: " << info.getServerName() << ", Address: " << info.getServerIP() << ", RTT: " << info.getServerRTT() << endl; 91 std::string payload = info.getServerName(); 92 info.setServerName(payload.substr(0,payload.length()-2)); 93 info.setClientNumber( Ogre::StringConverter::parseInt(payload.substr(payload.length()-1))); 94 orxout(internal_info, context::network) << "Received LAN discovery server information; Name: " << info.getServerName() << ", Address: " << info.getServerIP() << ", Players: " << info.getClientNumber() << ", RTT: " << info.getServerRTT() << endl; 92 95 std::vector<packet::ServerInformation>::iterator it; 93 96 for( it=this->servers_.begin(); it!=this->servers_.end(); ++it ) … … 124 127 } 125 128 129 std::string LANDiscovery::getServerListItemRTT(unsigned int index) 130 { 131 if( index >= this->servers_.size() ) 132 return BLANKSTRING; 133 else{ 134 uint32_t serverrtt = this->servers_[index].getServerRTT(); 135 return Ogre::StringConverter::toString(serverrtt); 136 } 137 } 126 138 139 std::string LANDiscovery::getServerListItemPlayerNumber(unsigned int index) 140 { 141 if( index >= this->servers_.size() ) 142 return BLANKSTRING; 143 else{ 144 int playerNumber = this->servers_[index].getClientNumber(); 145 return Ogre::StringConverter::toString(playerNumber); 146 } 147 } 127 148 } // namespace orxonox -
code/branches/presentationFS15merge/src/libraries/network/LANDiscovery.h
r8858 r10612 33 33 #include "packet/ServerInformation.h" 34 34 #include "util/Singleton.h" 35 #include <OgreStringConverter.h> 35 36 36 37 #include <vector> … … 51 52 std::string getServerListItemName( unsigned int index ); // tolua_export 52 53 std::string getServerListItemIP( unsigned int index ); // tolua_export 54 std::string getServerListItemRTT( unsigned int index ); // tolua_export 55 std::string getServerListItemPlayerNumber( unsigned int index ); // tolua_export 53 56 static LANDiscovery& getInstance(){ return Singleton<LANDiscovery>::getInstance(); } // tolua_export 54 57 55 58 private: 56 59 static LANDiscovery* singletonPtr_s; -
code/branches/presentationFS15merge/src/libraries/network/MasterServer.cc
r8952 r10612 34 34 #include "util/Output.h" 35 35 36 namespace orxonox 36 namespace orxonox 37 37 { 38 38 /*** MACROS ***/ … … 45 45 MasterServer *MasterServer::instance = NULL; 46 46 47 48 49 50 47 /* command: list servers */ 51 void 48 void 52 49 MasterServer::listServers( void ) 53 50 { … … 59 56 60 57 /* loop through list elements */ 61 for( i = MasterServer::getInstance()->mainlist.serverlist.begin(); 62 i != MasterServer::getInstance()->mainlist.serverlist.end(); ++i ) 58 for( i = MasterServer::getInstance()->mainlist.serverlist.begin(); 59 i != MasterServer::getInstance()->mainlist.serverlist.end(); ++i ) 63 60 { 64 61 orxout(user_info) << " " << (*i).ServerInfo.getServerIP() << std::endl; … … 70 67 } 71 68 72 void 69 void 73 70 MasterServer::delServer( std::string todeladdr ) 74 71 { 75 72 /* tell the user we're now removing the entry from the server list */ 76 orxout(user_info) << "MS: Deleting server \"" << todeladdr << "\"..." 73 orxout(user_info) << "MS: Deleting server \"" << todeladdr << "\"..." 77 74 << std::endl; 78 75 79 76 /* see if we actually have that server on our list */ 80 ServerListSearchResult shandle = 77 ServerListSearchResult shandle = 81 78 MasterServer::getInstance()->mainlist.findServerByAddress(todeladdr); 82 79 … … 86 83 } 87 84 88 /* force-disconnect the server */ 85 /* force-disconnect the server */ 89 86 enet_peer_disconnect( shandle.result.peer, 0 ); 90 87 … … 98 95 99 96 /* helpers */ 100 static void 97 static void 101 98 helper_output_debug( ENetEvent *event, char *addrconv ) 102 99 { 103 100 orxout(verbose, context::master_server) 104 << "A packet of length" 101 << "A packet of length" 105 102 << event->packet->dataLength 106 103 << " containing " 107 104 << (const char*)event->packet->data 108 105 << " was received from " 109 << addrconv 106 << addrconv 110 107 << " on channel " 111 108 << event->channelID << endl; … … 122 119 123 120 /* loop through list elements */ 124 for( i = mainlist.serverlist.begin(); i 125 != mainlist.serverlist.end(); ++i ) 121 for( i = mainlist.serverlist.begin(); i 122 != mainlist.serverlist.end(); ++i ) 126 123 { 127 124 /* send this particular server */ 128 125 /* build reply string */ 129 char *tosend = (char *)calloc( (*i).ServerInfo.getServerIP().length()130 + MSPROTO_SERVERLIST_ITEM_LEN + 2,1 );131 if( !tosend ) 126 int packetlen = MSPROTO_SERVERLIST_ITEM_LEN + 1 + (*i).ServerInfo.getServerIP().length() + 1 + (*i).ServerInfo.getServerName().length() + 1 + sizeof((*i).ServerInfo.getClientNumber()) + 1; 127 char *tosend = (char *)calloc(packetlen ,1 ); 128 if( !tosend ) 132 129 { orxout(internal_warning, context::master_server) << "Masterserver.cc: Memory allocation failed." << endl; 133 130 continue; 134 } 135 sprintf( tosend, "%s %s ", MSPROTO_SERVERLIST_ITEM,136 (*i).ServerInfo.getServerIP().c_str() 131 } 132 sprintf( tosend, "%s %s %s %u", MSPROTO_SERVERLIST_ITEM, 133 (*i).ServerInfo.getServerIP().c_str(), (*i).ServerInfo.getServerName().c_str(), (*i).ServerInfo.getClientNumber()); 137 134 138 135 /* create packet from it */ 139 136 reply = enet_packet_create( tosend, 140 strlen( tosend ) + 1, 137 strlen( tosend ) + 1, 141 138 ENET_PACKET_FLAG_RELIABLE); 142 139 … … 149 146 /* free the tosend buffer */ 150 147 free( tosend ); 151 } 148 } 152 149 153 150 /* create end-of-list packet */ … … 163 160 } 164 161 165 /* maybe the two methods below can be merged into one and 166 * made to use ENet's RTT functionality to check for disconnected 162 /* maybe the two methods below can be merged into one and 163 * made to use ENet's RTT functionality to check for disconnected 167 164 * servers. 168 165 */ 169 void 166 void 170 167 MasterServer::helper_cleanupServers( void ) 171 168 { 172 169 /* get an iterator */ 173 170 std::list<ServerListElem>::iterator i; 174 171 175 172 if( mainlist.serverlist.size() == 0 ) 176 173 return; 177 174 178 175 /* loop through list elements */ 179 for( i = mainlist.serverlist.begin(); i 180 != mainlist.serverlist.end(); ++i ) 176 for( i = mainlist.serverlist.begin(); i 177 != mainlist.serverlist.end(); ++i ) 181 178 { /* see if we have a disconnected peer */ 182 if( (*i).peer && 179 if( (*i).peer && 183 180 ((*i).peer->state == ENET_PEER_STATE_DISCONNECTED || 184 181 (*i).peer->state == ENET_PEER_STATE_ZOMBIE )) 185 { 182 { 186 183 /* Remove it from the list */ 187 184 orxout(internal_warning) << (char*)(*i).peer->data << " timed out.\n"; … … 190 187 /* stop iterating, we manipulated the list */ 191 188 /* TODO note: this only removes one dead server per loop 192 * iteration. not beautiful, but one iteration is ~100ms, 189 * iteration. not beautiful, but one iteration is ~100ms, 193 190 * so not really relevant for the moment. 194 191 */ … … 196 193 } 197 194 } 198 195 199 196 } 200 197 … … 204 201 /***** EVENTS *****/ 205 202 /* connect event */ 206 int 203 int 207 204 MasterServer::eventConnect( ENetEvent *event ) 208 205 { /* check for bad parameters */ … … 217 214 218 215 /* output debug info */ 219 orxout(verbose, context::master_server) << "A new client connected from " 220 << addrconv 221 << " on port " 216 orxout(verbose, context::master_server) << "A new client connected from " 217 << addrconv 218 << " on port " 222 219 << event->peer->address.port << endl; 223 220 224 221 /* store string form of address here */ 225 event->peer->data = addrconv; 222 event->peer->data = addrconv; 226 223 227 224 /* all fine. */ … … 230 227 231 228 /* disconnect event */ 232 int 229 int 233 230 MasterServer::eventDisconnect( ENetEvent *event ) 234 231 { /* check for bad parameters */ … … 255 252 256 253 /* data event */ 257 int 254 int 258 255 MasterServer::eventData( ENetEvent *event ) 259 256 { /* validate packet */ … … 262 259 return -1; 263 260 } 264 261 265 262 /* generate address in readable form */ 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 ); 283 282 mainlist.addServer( packet::ServerInformation( event ), event->peer ); 283 284 284 /* tell people we did so */ 285 orxout(internal_info, context::master_server) << "Added new server to list: " << 285 orxout(internal_info, context::master_server) << "Added new server to list: " << 286 286 packet::ServerInformation( event ).getServerIP() << endl; 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 { 289 else if( !strncmp( packetdata + MSPROTO_GAME_SERVER_LEN+1, MSPROTO_SERVERDC, MSPROTO_SERVERDC_LEN ) ) 290 { /* disconnect server */ 291 292 /* remove the server from the list it belongs to */ 293 this->mainlist.delServerByAddress( ip ); 294 295 /* tell the user */ 296 orxout(internal_info, context::master_server) << "Removed server " << ip << " from list." << endl; 297 } 298 /* TODO add hook for disconnect here */ 299 300 else if( !strncmp( packetdata + MSPROTO_GAME_SERVER_LEN+1, MSPROTO_SET_NAME, MSPROTO_SET_NAME_LEN ) ) 301 { /* save server name */ 293 302 /* create string from peer data */ 294 std::string name = std::string( addrconv ); 303 std::string data (event->packet->data,event->packet->data + event->packet->dataLength ); 304 std::string name = data.substr(MSPROTO_GAME_SERVER_LEN+1 + MSPROTO_SET_NAME_LEN + 1); 295 305 296 306 /* remove the server from the list it belongs to */ 297 this->mainlist. delServerByAddress(name );307 this->mainlist.setNameByAddress( ip, name ); 298 308 299 309 /* tell the user */ 300 orxout(internal_info, context::master_server) << "Removed server " << name << " from list." << endl; 301 } 302 303 /* TODO add hook for disconnect here */ 304 } 305 else if( !strncmp( (char *)event->packet->data, MSPROTO_CLIENT, 306 MSPROTO_CLIENT_LEN) ) 310 orxout(internal_info, context::master_server) << "Updated server " << ip << " with new name " << name << endl; 311 } 312 313 else if( !strncmp( packetdata + MSPROTO_GAME_SERVER_LEN+1, MSPROTO_SET_CLIENTS, MSPROTO_SET_CLIENTS_LEN ) ) 314 { /* save client count from server */ 315 /* create string from peer data */ 316 std::string data (event->packet->data,event->packet->data + event->packet->dataLength ); 317 std::string textform= data.substr(MSPROTO_GAME_SERVER_LEN + 1 + MSPROTO_SET_CLIENTS_LEN + 1); 318 int clientNumber = Ogre::StringConverter::parseInt(textform); 319 320 this->mainlist.setClientsByAddress( ip, clientNumber); 321 322 /* tell the user */ 323 orxout(internal_info, context::master_server) << "Updated server " << ip << " with new client number " << clientNumber << endl; 324 } 325 } 326 else if( !strncmp( packetdata, MSPROTO_CLIENT, MSPROTO_CLIENT_LEN) ) 307 327 { /* client */ 308 if( !strncmp( (char *)event->packet->data + MSPROTO_CLIENT_LEN+1, 309 MSPROTO_REQ_LIST, MSPROTO_REQ_LIST_LEN ) ) 328 if( !strncmp( packetdata + MSPROTO_CLIENT_LEN+1, MSPROTO_REQ_LIST, MSPROTO_REQ_LIST_LEN ) ) 310 329 /* send server list */ 311 330 helper_sendlist( event ); 312 331 } 313 332 else 314 { /* bad message, don't do anything. */ } 315 316 /* delete addrconv */ 317 if( addrconv ) free( addrconv ); 333 { /* bad message, don't do anything. */ } 318 334 319 335 /* Clean up the packet now that we're done using it. */ … … 324 340 325 341 /**** MAIN ROUTINE *****/ 326 int 342 int 327 343 MasterServer::run() 328 344 { … … 330 346 ENetEvent *event = (ENetEvent *)calloc(sizeof(ENetEvent), sizeof(char)); 331 347 if( event == NULL ) 332 { 348 { 333 349 orxout(user_error, context::master_server) << "Could not create ENetEvent structure, exiting." << endl; 334 350 exit( EXIT_FAILURE ); … … 345 361 switch (event->type) 346 362 { /* new connection */ 347 case ENET_EVENT_TYPE_CONNECT: 363 case ENET_EVENT_TYPE_CONNECT: 348 364 eventConnect( event ); break; 349 365 350 366 /* disconnect */ 351 case ENET_EVENT_TYPE_DISCONNECT: 367 case ENET_EVENT_TYPE_DISCONNECT: 352 368 eventDisconnect( event ); break; 353 369 … … 358 374 359 375 /* done */ 376 free(event); 360 377 return 0; 361 } 378 } 362 379 363 380 /* constructor */ … … 380 397 this->address.port = ORX_MSERVER_PORT; 381 398 382 /* create a host with the above settings (the last two 0 mean: accept 399 /* create a host with the above settings (the last two 0 mean: accept 383 400 * any input/output bandwidth */ 384 this->server = enet_host_create( &this->address, ORX_MSERVER_MAXCONNS, 401 this->server = enet_host_create( &this->address, ORX_MSERVER_MAXCONNS, 385 402 ORX_MSERVER_MAXCHANS, 0, 0 ); 386 403 assert(this->server); … … 388 405 /* see if creation worked */ 389 406 if( !this->server ) 390 { orxout(user_error, context::master_server) << 407 { orxout(user_error, context::master_server) << 391 408 "An error occurred while trying to create an ENet server host." << endl; 392 409 exit( EXIT_FAILURE ); -
code/branches/presentationFS15merge/src/libraries/network/MasterServer.h
r8937 r10612 49 49 #include <cstdio> 50 50 51 namespace orxonox 51 #include <OgreStringConverter.h> 52 53 54 namespace orxonox 52 55 { 53 56 /* singleton */ … … 63 66 /* static pointer for commands */ 64 67 static MasterServer *instance; 65 static MasterServer *getInstance() 68 static MasterServer *getInstance() 66 69 { return instance; } 67 static void setInstance( MasterServer *setto ) 70 static void setInstance( MasterServer *setto ) 68 71 { instance = setto; } 69 72 70 73 /* functions for commands */ 71 74 static void listServers( void ); -
code/branches/presentationFS15merge/src/libraries/network/MasterServerProtocol.h
r8351 r10612 37 37 /* Client token (shows that the party sending data is a client */ 38 38 #define MSPROTO_CLIENT "CL" 39 #define MSPROTO_CLIENT_LEN 2 39 #define MSPROTO_CLIENT_LEN 2 40 40 41 41 /* Request: Serverlist (requiest made from client to master server */ 42 42 #define MSPROTO_REQ_LIST "REQ:LIST" 43 43 #define MSPROTO_REQ_LIST_LEN 8 44 45 46 44 47 45 … … 67 65 /* ping request from server */ 68 66 #define MSPROTO_PING_GAMESERVER "PING" 69 #define MSPROTO_PING_GAMESERVER_LEN 4 67 #define MSPROTO_PING_GAMESERVER_LEN 4 70 68 71 69 /* server disconnect */ … … 75 73 /* ping reply */ 76 74 #define MSPROTO_ACK "ACK" 77 #define MSPROTO_ACK_LEN 3 75 #define MSPROTO_ACK_LEN 3 78 76 77 /* server name */ 78 #define MSPROTO_SET_NAME "NAM" 79 #define MSPROTO_SET_NAME_LEN 3 79 80 81 /* server number of clients */ 82 #define MSPROTO_SET_CLIENTS "CLI" 83 #define MSPROTO_SET_CLIENTS_LEN 3 84 85 #define SERVER_NAME_MAXLEN 7 80 86 81 87 /* default master server port */ -
code/branches/presentationFS15merge/src/libraries/network/PeerList.cc
r8858 r10612 38 38 PeerList::~PeerList() { } 39 39 40 int 40 int 41 41 PeerList::addPeer( ENetPeer *toadd ) 42 42 { /* error correction */ 43 if( toadd == NULL ) 43 if( toadd == NULL ) 44 44 { orxout(internal_error, context::master_server) << "PeerList::addPeer: empty peer given." << endl; 45 45 return -1; … … 52 52 53 53 bool sub_compAddr( ENetAddress addr1, ENetAddress addr2 ) 54 { 54 { 55 55 for( int i = 0; i < 16; ++i ) 56 56 if( addr1.host.addr[i] < addr2.host.addr[i] ) … … 61 61 return 0; 62 62 } 63 63 64 64 65 65 bool … … 69 69 70 70 /* loop through list elements */ 71 for( i = peerlist.begin(); i != peerlist.end(); ++i ) 71 for( i = peerlist.begin(); i != peerlist.end(); ++i ) 72 72 if( !sub_compAddr((*i)->address, addr ) ) 73 73 { /* found this name, remove and quit */ … … 86 86 87 87 /* loop through list elements */ 88 for( i = peerlist.begin(); i != peerlist.end(); ++i ) 88 for( i = peerlist.begin(); i != peerlist.end(); ++i ) 89 89 if( !sub_compAddr((*i)->address, addr ) ) 90 90 /* found this name, remove and quit */ … … 95 95 } 96 96 97 int 98 PeerList::count(){ 99 return this->peerlist.size(); 100 } 101 97 102 } 98 -
code/branches/presentationFS15merge/src/libraries/network/PeerList.h
r8351 r10612 35 35 36 36 /* peer list */ 37 namespace orxonox 37 namespace orxonox 38 38 { 39 /** This class keeps a list of open connections 39 /** This class keeps a list of open connections 40 40 * and some info about them. 41 41 */ 42 class PeerList 42 class PeerList 43 43 { public: 44 44 /** constructor */ … … 50 50 /** \param toadd The peer to add 51 51 * \return 0 for success, -1 for error. 52 * 53 * Add new peer to list 52 * 53 * Add new peer to list 54 54 */ 55 55 int addPeer( ENetPeer *toadd ); … … 57 57 /** \param addr Address to look for 58 58 * \return if the peer was found or not 59 * 60 * Remove peer from list by address 59 * 60 * Remove peer from list by address 61 61 */ 62 62 bool remPeerByAddr( ENetAddress addr ); 63 63 64 64 /** \param addr The address to find by 65 * 66 * Find a connection by address */ 65 * 66 * Find a connection by address 67 */ 67 68 ENetPeer *findPeerByAddr( ENetAddress addr ); 68 69 69 /* NOTE: making this list public so it can easily 70 /** 71 * Count current peers 72 */ 73 int count(); 74 75 /* NOTE: making this list public so it can easily 70 76 * be iterated. This makes sense since iterating it 71 77 * will happen all the time, and using getter methods -
code/branches/presentationFS15merge/src/libraries/network/Server.cc
r9667 r10612 77 77 this->timeSinceLastUpdate_=0; 78 78 } 79 79 /* 80 Server::Server(int port, const std::string name) 81 { 82 this->setPort( port ); 83 this->timeSinceLastUpdate_=0; 84 this->serverName_=name; 85 }*/ 80 86 /** 81 87 * Constructor … … 108 114 /* make discoverable on LAN */ 109 115 LANDiscoverable::setActivity(true); 116 LANDiscoverable::updateClientNumber(0); 110 117 111 118 /* make discoverable on WAN */ 112 119 WANDiscoverable::setActivity(true); 120 WANDiscoverable::updateClientNumber(0); 113 121 114 122 /* done */ … … 283 291 // inform all the listeners 284 292 this->clientIDs_.push_back(peerID); 293 WANDiscoverable::updateClientNumber(this->clientIDs_.size()); 294 LANDiscoverable::updateClientNumber(this->clientIDs_.size()); 295 285 296 ClientConnectionListener::broadcastClientConnected(peerID); 286 297 GamestateManager::addPeer(peerID); … … 289 300 290 301 orxout(internal_info, context::network) << "Server: added client id: " << peerID << endl; 302 291 303 createClient(peerID); 292 304 } … … 309 321 } 310 322 } 323 WANDiscoverable::updateClientNumber(this->clientIDs_.size()); 324 LANDiscoverable::updateClientNumber(this->clientIDs_.size()); 325 311 326 ClientConnectionListener::broadcastClientDisconnected(peerID); 312 327 GamestateManager::removePeer(peerID); -
code/branches/presentationFS15merge/src/libraries/network/Server.h
r8858 r10612 67 67 virtual void printRTT(); 68 68 float getPacketLoss(unsigned int clientID); 69 int getClientCount() { return this->clientIDs_.size();} 70 std::string getServerName() { return this->serverName_;} 71 69 72 protected: 70 73 void updateGamestate(); … … 89 92 std::deque<packet::Packet*> packetQueue_; 90 93 std::vector<uint32_t> clientIDs_; 94 std::string serverName_; 91 95 }; 92 96 -
code/branches/presentationFS15merge/src/libraries/network/ServerList.cc
r8937 r10612 30 30 31 31 namespace orxonox 32 { 32 { 33 33 ServerList::ServerList() 34 34 { /* create a new list */ } … … 39 39 } 40 40 41 int 41 int 42 42 ServerList::addServer( packet::ServerInformation toadd, 43 43 ENetPeer *peer ) 44 { 44 { 45 45 ServerListElem toAdd; 46 46 toAdd.ServerInfo = toadd; 47 47 toAdd.peer = peer; 48 48 49 this->serverlist.push_back( toAdd ); 49 this->serverlist.push_back( toAdd ); 50 50 return 0; 51 51 } 52 52 53 bool 53 bool 54 54 ServerList::delServerByName( std::string name ) 55 { 55 { 56 56 /* get an iterator */ 57 57 std::list<ServerListElem>::iterator i; 58 58 59 59 /* loop through list elements */ 60 for( i = serverlist.begin(); i != serverlist.end(); ++i ) 60 for( i = serverlist.begin(); i != serverlist.end(); ++i ) 61 61 if( (*i).ServerInfo.getServerName() == name ) 62 62 { /* found this name, remove and quit */ … … 68 68 69 69 bool ServerList::delServerByAddress( std::string address ) 70 { 70 { 71 71 /* get an iterator */ 72 72 std::list<ServerListElem>::iterator i; 73 73 74 74 /* loop through list elements */ 75 for( i = serverlist.begin(); i != serverlist.end(); ++i ) 75 for( i = serverlist.begin(); i != serverlist.end(); ++i ) 76 76 if( (*i).ServerInfo.getServerIP() == address ) 77 77 { /* found this name, remove and quit */ … … 90 90 91 91 /* loop through list elements */ 92 for( i = serverlist.begin(); i != serverlist.end(); ++i ) 92 for( i = serverlist.begin(); i != serverlist.end(); ++i ) 93 93 if( (*i).ServerInfo.getServerIP() == address ) 94 94 { /* found the target, return it */ … … 110 110 /* iterate, return when name found */ 111 111 /* loop through list elements */ 112 for( i = serverlist.begin(); i != serverlist.end(); ++i ) 112 for( i = serverlist.begin(); i != serverlist.end(); ++i ) 113 113 if( (*i).ServerInfo.getServerName() == name ) 114 { 114 { 115 115 ServerListSearchResult res = { (*i), true }; 116 116 return res; … … 124 124 /* SORTING */ 125 125 /* sort by name */ 126 bool sub_compare_names( ServerListElem no1, 126 bool sub_compare_names( ServerListElem no1, 127 127 ServerListElem no2 ) 128 128 { return no1.ServerInfo.getServerName() > no2.ServerInfo.getServerName(); } 129 129 130 130 void ServerList::sortByName() 131 { 132 this->serverlist.sort( sub_compare_names ); 131 { 132 this->serverlist.sort( sub_compare_names ); 133 133 } 134 134 135 135 /* sort by ping */ 136 bool sub_compare_pings( ServerListElem no1, 136 bool sub_compare_pings( ServerListElem no1, 137 137 ServerListElem no2 ) 138 { 139 return no1.ServerInfo.getServer Name() > no2.ServerInfo.getServerName();138 { 139 return no1.ServerInfo.getServerRTT() > no2.ServerInfo.getServerRTT(); 140 140 } 141 141 142 142 void ServerList::sortByPing() 143 143 { 144 this->serverlist.sort( sub_compare_pings ); 144 this->serverlist.sort( sub_compare_pings ); 145 145 } 146 146 147 bool ServerList::setNameByAddress( std::string address, std::string name ){ 148 /* get an iterator */ 149 std::list<ServerListElem>::iterator i; 150 151 /* loop through list elements */ 152 for( i = serverlist.begin(); i != serverlist.end(); ++i ) 153 if( (*i).ServerInfo.getServerIP() == address ) 154 { /* found this adress, rename and quit */ 155 (*i).ServerInfo.setServerName( name ); 156 return true; 157 } 158 return false; 159 }; 160 161 bool ServerList::setClientsByAddress( std::string address, int clientNumber ){ 162 /* get an iterator */ 163 std::list<ServerListElem>::iterator i; 164 165 /* loop through list elements */ 166 for( i = serverlist.begin(); i != serverlist.end(); ++i ) 167 if( (*i).ServerInfo.getServerIP() == address ) 168 { /* found this adress, rename and quit */ 169 (*i).ServerInfo.setClientNumber( clientNumber ); 170 return true; 171 } 172 return false; 173 }; 174 147 175 } -
code/branches/presentationFS15merge/src/libraries/network/ServerList.h
r8937 r10612 35 35 36 36 /* methods necessary */ 37 namespace orxonox 38 { 37 namespace orxonox 38 { 39 39 /* HELPER STRUCTURES */ 40 struct ServerListElem 40 struct ServerListElem 41 41 { 42 42 /* server information (name, IP, etc) */ … … 63 63 * and some info about them. 64 64 */ 65 class ServerList 65 class ServerList 66 66 { public: 67 67 /** constructor */ … … 74 74 /* BASIC MANIPULATION */ 75 75 /** \param toadd the server to add. 76 * 76 * 77 77 * Add server to the game server list 78 78 */ … … 81 81 82 82 /** \param name Name of the server to remove 83 * 84 * Remove server by name 83 * 84 * Remove server by name 85 85 */ 86 86 bool delServerByName( std::string name ); 87 87 88 88 /** \param address IP address of the server to remove 89 * 89 * 90 90 * Remove server by address 91 91 */ 92 92 bool delServerByAddress( std::string address ); 93 93 94 bool setNameByAddress( std::string address, std::string name ); 94 95 95 96 bool setClientsByAddress( std::string address, int clientNumber ); 96 97 97 98 /* SEARCHING */ 98 /* \param address The address of the server that is to be 99 /* \param address The address of the server that is to be 99 100 * found 100 101 * \return A struct containing a result of the search and a boolean 101 102 * that is only true if the search was successful 102 * 103 * 103 104 * Find and return the list handle of a given address. 104 105 */ … … 107 108 108 109 109 /* \param name The name of the server that is to be 110 /* \param name The name of the server that is to be 110 111 * found 111 112 * \return The struct containing the list entry of the server 112 * 113 * 113 114 * Find and return the list handle of a given name. 114 115 */ … … 120 121 /** sort by name */ 121 122 void sortByName(); 122 123 123 124 /** sort by ping */ 124 125 void sortByPing(); -
code/branches/presentationFS15merge/src/libraries/network/WANDiscoverable.cc
r9667 r10612 44 44 /* debugging output */ 45 45 orxout(verbose, context::master_server) << "Creating WANDiscoverable." << endl; 46 46 47 47 /* register object in orxonox */ 48 48 RegisterObject(WANDiscoverable); … … 50 50 /* check for the masterserver address option in orxonox.ini */ 51 51 this->setConfigValues(); 52 52 53 53 } 54 54 55 55 void WANDiscoverable::setConfigValues() 56 56 { 57 /* update msaddress string from orxonox.ini config file, if it 58 * has changed. 57 /* update msaddress string from orxonox.ini config file, if it 58 * has changed. 59 59 */ 60 SetConfigValueExternal(msaddress, " WANDiscovery", "msaddress", "orxonox.net");61 // SetConfigValue( msaddress, "orxonox.net");62 } 60 SetConfigValueExternal(msaddress, "Discovery", "msaddress", "orxonox.net"); 61 SetConfigValueExternal(ownName, "Discovery", "ownName", "OrxServer"); 62 } 63 63 64 64 WANDiscoverable::~WANDiscoverable() … … 67 67 this->disconnect(); 68 68 } 69 69 70 70 void WANDiscoverable::setActivity(bool bActive) 71 71 { 72 72 if( bActive==this->bActive_ ) 73 73 return; 74 74 75 75 if( bActive ) 76 76 { … … 84 84 } 85 85 } 86 86 87 87 bool WANDiscoverable::connect() 88 88 { … … 93 93 return false; 94 94 } 95 95 96 96 /* connect and see if it worked */ 97 97 if( msc.connect( this->msaddress.c_str(), ORX_MSERVER_PORT ) ) 98 98 { 99 orxout(internal_error, context::master_server) << "Could not connect to master server at " 99 orxout(internal_error, context::master_server) << "Could not connect to master server at " 100 100 << this->msaddress << endl; 101 101 return false; 102 102 } 103 103 104 104 /* debugging output */ 105 105 orxout(verbose, context::master_server) << "Initialization of WANDiscoverable complete." << endl; 106 107 106 108 107 // Now register the server at the master server 109 108 this->msc.sendRequest( MSPROTO_GAME_SERVER " " MSPROTO_REGISTER_SERVER ); 110 109 110 std::string request = MSPROTO_GAME_SERVER " " MSPROTO_SET_NAME " "; 111 request += this->ownName; 112 this->msc.sendRequest( request ); 113 111 114 return true; 112 115 } … … 118 121 } 119 122 123 void WANDiscoverable::updateClientNumber(int clientNumber) 124 { 125 orxout(verbose, context::master_server) << "Sending new number of clients: " << clientNumber << endl; 126 std::string request = MSPROTO_GAME_SERVER " " MSPROTO_SET_CLIENTS " "; 127 request += Ogre::StringConverter::toString(clientNumber); 128 129 this->msc.sendRequest( request ); 130 } 120 131 121 132 122 133 134 123 135 } // namespace orxonox -
code/branches/presentationFS15merge/src/libraries/network/WANDiscoverable.h
r9667 r10612 32 32 #include "core/config/Configurable.h" 33 33 #include "MasterServerComm.h" 34 #include <OgreStringConverter.h> 34 35 35 36 namespace orxonox … … 46 47 47 48 /** \return Address of the master server 48 * 49 * Get the master server address 49 * 50 * Get the master server address 50 51 */ 51 52 std::string getMSAddress() … … 54 55 /** Function used for the configuration file parameter update */ 55 56 void setConfigValues(); 56 57 57 58 /** Function used to set the activity/discoverability */ 58 59 void setActivity( bool bActive ); 59 60 61 void updateClientNumber(int clientNumber); 62 60 63 /** Master server communications object */ 61 64 MasterServerComm msc; 62 65 63 66 private: 64 67 /** Function used to connect to the master server */ 65 68 bool connect(); 66 69 67 70 /** Function used to disconnect from the master server */ 68 71 void disconnect(); 69 72 70 73 /** master server address */ 71 74 std::string msaddress; 75 std::string ownName; 72 76 bool bActive_; 73 77 -
code/branches/presentationFS15merge/src/libraries/network/WANDiscovery.cc
r8858 r10612 41 41 /* debugging output */ 42 42 orxout(verbose, context::master_server) << "Creating WANDiscovery." << endl; 43 43 44 44 /* register object in orxonox */ 45 45 RegisterObject(WANDiscovery); … … 54 54 /* connect and see if it worked */ 55 55 if( msc.connect( this->msaddress.c_str(), ORX_MSERVER_PORT ) ) 56 orxout(internal_error, context::master_server) << "Could not connect to master server at " 56 orxout(internal_error, context::master_server) << "Could not connect to master server at " 57 57 << this->msaddress << endl; 58 58 … … 63 63 void WANDiscovery::setConfigValues() 64 64 { 65 /* update msaddress string from orxonox.ini config file, if it 66 * has changed. 65 /* update msaddress string from orxonox.ini config file, if it 66 * has changed. 67 67 */ 68 68 SetConfigValue( msaddress, "master.orxonox.net"); 69 } 69 } 70 70 71 71 WANDiscovery::~WANDiscovery() 72 { 72 { 73 73 /* clear server list */ 74 this->servers_.clear(); 74 this->servers_.clear(); 75 75 } 76 76 77 77 /* callback for the network reply poller */ 78 78 int WANDiscovery::rhandler( char *addr, ENetEvent *ev ) 79 { 79 { 80 80 /* error recognition */ 81 81 if( !ev || !ev->packet || !ev->packet->data ) … … 88 88 if( !strncmp( (char*)ev->packet->data, MSPROTO_SERVERLIST_ITEM, 89 89 MSPROTO_SERVERLIST_ITEM_LEN ) ) 90 { 90 { 91 91 /* create server structure from that item */ 92 92 packet::ServerInformation toadd; 93 93 94 94 /* fill in data, -1 for the index: index should be length -1 */ 95 toadd.setServerName( std::string((char*)ev->packet->data + 96 MSPROTO_SERVERLIST_ITEM_LEN+1) ); 97 toadd.setServerIP( std::string((char*)ev->packet->data + 98 MSPROTO_SERVERLIST_ITEM_LEN+1) ); 95 std::string datastr = std::string((char*)ev->packet->data + MSPROTO_SERVERLIST_ITEM_LEN+1); 96 int separator = datastr.find(" "); 97 toadd.setServerIP(datastr.substr(0,separator)); 98 int secondsep = datastr.find(" ", separator + 1); 99 toadd.setServerName(datastr.substr(separator + 1, secondsep - separator - 1)); 100 toadd.setClientNumber(Ogre::StringConverter::parseInt(datastr.substr(secondsep+1))); 101 102 orxout(internal_info, context::network) << "Received WAN discovery server information; Name: " << toadd.getServerName() << ", Address: " << toadd.getServerIP() << ", Players: " << toadd.getClientNumber() << ", RTT: " << toadd.getServerRTT() << endl; 99 103 100 104 /* add to list */ … … 103 107 else if( !strncmp( (char*)ev->packet->data, MSPROTO_SERVERLIST_END, 104 108 MSPROTO_SERVERLIST_END_LEN ) ) 105 { 109 { 106 110 /* this is the only case where 2 should be returned, 107 111 * as 1 is used to signal that we're done receiving 108 112 * the list 109 113 */ 110 return 2; 114 return 2; 111 115 } 112 116 … … 114 118 return 1; 115 119 } 116 120 117 121 void WANDiscovery::discover() 118 122 { … … 131 135 { case 0: /* no event occured, decrease timeout */ 132 136 --i; break; 133 case 1: /* got a list element, continue */ 137 case 1: /* got a list element, continue */ 134 138 break; 135 139 case 2: /* done. */ … … 159 163 } 160 164 165 std::string WANDiscovery::getServerListItemRTT(unsigned int index) 166 { 167 if( index >= this->servers_.size() ) 168 return BLANKSTRING; 169 else{ 170 uint32_t serverrtt = this->servers_[index].getServerRTT(); 171 return Ogre::StringConverter::toString(serverrtt); 172 } 173 174 } 175 std::string WANDiscovery::getServerListItemPlayerNumber(unsigned int index) 176 { 177 if( index >= this->servers_.size() ) 178 return BLANKSTRING; 179 else{ 180 int playerNumber = this->servers_[index].getClientNumber(); 181 return Ogre::StringConverter::toString(playerNumber); 182 } 183 } 161 184 162 185 } // namespace orxonox -
code/branches/presentationFS15merge/src/libraries/network/WANDiscovery.h
r9667 r10612 35 35 #include "MasterServerComm.h" 36 36 #include "MasterServerProtocol.h" 37 #include <OgreStringConverter.h> 37 38 38 39 #include <vector> … … 56 57 57 58 /** \return Address of the master server 58 * 59 * Get the master server address 59 * 60 * Get the master server address 60 61 */ 61 62 std::string getMSAddress() … … 65 66 void discover(); // tolua_export 66 67 67 /** \param index Index to get the name of 68 /** \param index Index to get the name of 68 69 * \return The name of the server 69 * 70 * Get the name of the server at index index. 70 * 71 * Get the name of the server at index index. 71 72 */ 72 73 std::string getServerListItemName( unsigned int index ); // tolua_export 73 74 74 /** \param index Index to get the IP of 75 /** \param index Index to get the IP of 75 76 * \return The IP of the server 76 * 77 * Get the IP of the server at index index. 77 * 78 * Get the IP of the server at index index. 78 79 */ 79 80 std::string getServerListItemIP( unsigned int index ); // tolua_export 80 81 82 /** \param index Index to get the RTT of 83 * \return The RTT of the server 84 * 85 * Get the RTT of the server at index index. 86 */ 87 std::string getServerListItemRTT( unsigned int index ); // tolua_export 88 89 /** \param index Index to get the RTT of 90 * \return The number of players on the server 91 * 92 * Get the number of players on the server 93 */ 94 std::string getServerListItemPlayerNumber( unsigned int index ); // tolua_export 95 81 96 /* todo: might make this private and use getter/setter methods 82 * at some later time. 97 * at some later time. 83 98 */ 84 99 /** game server list */ … … 92 107 93 108 int rhandler( char *addr, ENetEvent *ev ); 94 109 95 110 private: 96 111 /** master server address */ -
code/branches/presentationFS15merge/src/libraries/network/packet/ServerInformation.cc
r8351 r10612 39 39 namespace packet 40 40 { 41 41 42 42 ServerInformation::ServerInformation() 43 43 { 44 45 44 } 46 45 47 46 ServerInformation::ServerInformation(ENetEvent* event) 48 47 { … … 69 68 ServerInformation::~ServerInformation() 70 69 { 71 70 72 71 } 73 72 74 73 void ServerInformation::send(ENetPeer* peer) 75 74 { 76 uint32_t size = returnSize((char*&)LAN_DISCOVERY_ACK) + returnSize(this->serverName_); 75 std::string payload = this->serverName_ + Ogre::StringConverter::toString(this->clientNumber_); 76 uint32_t size = returnSize((char*&)LAN_DISCOVERY_ACK) + returnSize(payload); 77 77 uint8_t* temp = new uint8_t[size]; 78 78 uint8_t* temp2 = temp; 79 79 saveAndIncrease((char*&)LAN_DISCOVERY_ACK, temp2); 80 saveAndIncrease( this->serverName_, temp2);80 saveAndIncrease(payload, temp2); 81 81 ENetPacket* packet = enet_packet_create( temp, size, 0 ); 82 82 enet_peer_send(peer, 0, packet); 83 83 84 84 delete[] temp; 85 85 } 86 86 87 87 } // namespace packet 88 88 … … 95 95 } 96 96 } // namespace orxonox 97 -
code/branches/presentationFS15merge/src/libraries/network/packet/ServerInformation.h
r8351 r10612 30 30 31 31 #include <string> 32 #include <OgreStringConverter.h> 33 32 34 33 35 #ifndef SERVERINFORMATION_H … … 45 47 ServerInformation(ENetEvent* event); 46 48 ~ServerInformation(); 47 49 48 50 void send( ENetPeer* peer ); 51 void setServerName(std::string name) { this->serverName_ = name; } 52 std::string getServerName() { return this->serverName_; } 53 void setServerIP( std::string IP ) { this->serverIP_ = IP; } 49 54 std::string getServerIP() { return this->serverIP_; } 50 std::string getServerName() { return this->serverName_; } 51 void setServerName(std::string name) { this->serverName_ = name; } 52 void setServerIP( std::string IP ) { this->serverIP_ = IP; } 55 void setClientNumber( int clientNumber ) { this->clientNumber_ = clientNumber; } 56 int getClientNumber() { return this->clientNumber_; } 53 57 uint32_t getServerRTT() { return this->serverRTT_; } 54 58 55 59 private: 56 60 std::string serverName_; 61 int clientNumber_; 57 62 std::string serverIP_; 58 63 uint32_t serverRTT_;
Note: See TracChangeset
for help on using the changeset viewer.