- Timestamp:
- May 7, 2015, 5:21:45 PM (10 years ago)
- Location:
- code/branches/multiplayerFS15/src/libraries/network
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/multiplayerFS15/src/libraries/network/LANDiscoverable.cc
r10427 r10434 57 57 void LANDiscoverable::setConfigValues() 58 58 { 59 /* update msaddressstring from orxonox.ini config file, if it59 /* update ownName string from orxonox.ini config file, if it 60 60 * has changed. 61 61 */ 62 SetConfigValueExternal(ownName, " WANDiscovery", "ownName", "tme213");62 SetConfigValueExternal(ownName, "Discovery", "ownName", "tme213"); 63 63 } 64 64 … … 120 120 packet::ServerInformation info; 121 121 info.setServerName(this->ownName); 122 info.setClientNumber(this->clientNumber); 122 123 info.send(event.peer); 123 124 // ENetPacket* packet = enet_packet_create( LAN_DISCOVERY_ACK, strlen(LAN_DISCOVERY_ACK)+1, ENET_PACKET_FLAG_RELIABLE ); -
code/branches/multiplayerFS15/src/libraries/network/LANDiscoverable.h
r10427 r10434 43 43 void setActivity( bool bActive ); 44 44 void update(); 45 void updateClientNumber(int clientNumber) {this->clientNumber = clientNumber;} 46 ; 45 47 /** Function used for the configuration file parameter update */ 46 48 void setConfigValues(); … … 50 52 ENetHost* host_; 51 53 std::string ownName; 54 int clientNumber; 52 55 }; 53 56 -
code/branches/multiplayerFS15/src/libraries/network/LANDiscovery.cc
r10334 r10434 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 orxout(internal_info, context::network) << "Received LAN discovery server information; Name: " << info.getServerName() << ", Address: " << info.getServerIP() << ", Players: " << info.getClientNumber() << ", RTT: " << info.getServerRTT() << endl; 92 92 std::vector<packet::ServerInformation>::iterator it; 93 93 for( it=this->servers_.begin(); it!=this->servers_.end(); ++it ) … … 132 132 return Ogre::StringConverter::toString(serverrtt); 133 133 } 134 135 134 } 136 135 137 136 std::string LANDiscovery::getServerListItemPlayerNumber(unsigned int index) 137 { 138 if( index >= this->servers_.size() ) 139 return BLANKSTRING; 140 else{ 141 int playerNumber = this->servers_[index].getClientNumber(); 142 return Ogre::StringConverter::toString(playerNumber); 143 } 144 } 138 145 } // namespace orxonox -
code/branches/multiplayerFS15/src/libraries/network/LANDiscovery.h
r10334 r10434 53 53 std::string getServerListItemIP( unsigned int index ); // tolua_export 54 54 std::string getServerListItemRTT( unsigned int index ); // tolua_export 55 std::string getServerListItemPlayerNumber( unsigned int index ); // tolua_export 55 56 static LANDiscovery& getInstance(){ return Singleton<LANDiscovery>::getInstance(); } // tolua_export 56 57 -
code/branches/multiplayerFS15/src/libraries/network/MasterServer.cc
r10427 r10434 127 127 /* send this particular server */ 128 128 /* build reply string */ 129 int packetlen = MSPROTO_SERVERLIST_ITEM_LEN + 1 + (*i).ServerInfo.getServerIP().length() + 1 + (*i).ServerInfo.getServerName().length() + 1 ;129 int packetlen = MSPROTO_SERVERLIST_ITEM_LEN + 1 + (*i).ServerInfo.getServerIP().length() + 1 + (*i).ServerInfo.getServerName().length() + 1 + sizeof((*i).ServerInfo.getClientNumber()) + 1; 130 130 char *tosend = (char *)calloc(packetlen ,1 ); 131 131 if( !tosend ) … … 133 133 continue; 134 134 } 135 sprintf( tosend, "%s %s %s ", MSPROTO_SERVERLIST_ITEM,136 (*i).ServerInfo.getServerIP().c_str(), (*i).ServerInfo.getServerName().c_str() );135 sprintf( tosend, "%s %s %s %u", MSPROTO_SERVERLIST_ITEM, 136 (*i).ServerInfo.getServerIP().c_str(), (*i).ServerInfo.getServerName().c_str(), (*i).ServerInfo.getClientNumber()); 137 137 138 138 /* create packet from it */ … … 300 300 orxout(internal_info, context::master_server) << "Removed server " << ip << " from list." << endl; 301 301 } 302 /* TODO add hook for disconnect here */ 302 303 303 304 else if( !strncmp( (char *)event->packet->data … … 317 318 } 318 319 319 /* TODO add hook for disconnect here */ 320 else if( !strncmp( (char *)event->packet->data 321 + MSPROTO_GAME_SERVER_LEN+1, 322 MSPROTO_SET_CLIENTS, MSPROTO_SET_CLIENTS_LEN ) ) 323 { 324 /* create string from peer data */ 325 std::string ip = std::string( addrconv ); 326 std::string data (event->packet->data,event->packet->data + event->packet->dataLength ); 327 std::string textform= data.substr(MSPROTO_GAME_SERVER_LEN + 1 + MSPROTO_SET_CLIENTS_LEN + 1); 328 int clientNumber = Ogre::StringConverter::parseInt(textform); 329 330 this->mainlist.setClientsByAddress( ip, clientNumber); 331 332 /* tell the user */ 333 orxout(internal_info, context::master_server) << "Updated server " << ip << " with new client number " << clientNumber << endl; 334 } 320 335 } 321 336 else if( !strncmp( (char *)event->packet->data, MSPROTO_CLIENT, -
code/branches/multiplayerFS15/src/libraries/network/MasterServer.h
r8937 r10434 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/multiplayerFS15/src/libraries/network/Server.cc
r10427 r10434 114 114 /* make discoverable on LAN */ 115 115 LANDiscoverable::setActivity(true); 116 LANDiscoverable::updateClientNumber(0); 116 117 117 118 /* make discoverable on WAN */ 118 119 WANDiscoverable::setActivity(true); 120 WANDiscoverable::updateClientNumber(0); 119 121 120 122 /* done */ … … 289 291 // inform all the listeners 290 292 this->clientIDs_.push_back(peerID); 293 WANDiscoverable::updateClientNumber(this->clientIDs_.size()); 294 LANDiscoverable::updateClientNumber(this->clientIDs_.size()); 295 291 296 ClientConnectionListener::broadcastClientConnected(peerID); 292 297 GamestateManager::addPeer(peerID); … … 295 300 296 301 orxout(internal_info, context::network) << "Server: added client id: " << peerID << endl; 302 297 303 createClient(peerID); 298 304 } … … 315 321 } 316 322 } 323 WANDiscoverable::updateClientNumber(this->clientIDs_.size()); 324 LANDiscoverable::updateClientNumber(this->clientIDs_.size()); 325 317 326 ClientConnectionListener::broadcastClientDisconnected(peerID); 318 327 GamestateManager::removePeer(peerID); -
code/branches/multiplayerFS15/src/libraries/network/ServerList.cc
r10427 r10434 159 159 }; 160 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 161 175 } -
code/branches/multiplayerFS15/src/libraries/network/ServerList.h
r10427 r10434 94 94 bool setNameByAddress( std::string address, std::string name ); 95 95 96 bool setClientsByAddress( std::string address, int clientNumber ); 97 96 98 /* SEARCHING */ 97 99 /* \param address The address of the server that is to be -
code/branches/multiplayerFS15/src/libraries/network/WANDiscoverable.cc
r10427 r10434 58 58 * has changed. 59 59 */ 60 SetConfigValueExternal(msaddress, " WANDiscovery", "msaddress", "orxonox.net");61 SetConfigValueExternal(ownName, " WANDiscovery", "ownName", "tme213");60 SetConfigValueExternal(msaddress, "Discovery", "msaddress", "orxonox.net"); 61 SetConfigValueExternal(ownName, "Discovery", "ownName", "tme213"); 62 62 // SetConfigValue( msaddress, "orxonox.net"); 63 63 } … … 106 106 orxout(verbose, context::master_server) << "Initialization of WANDiscoverable complete." << endl; 107 107 108 // Now register the server at the master server 109 this->msc.sendRequest( MSPROTO_GAME_SERVER " " MSPROTO_REGISTER_SERVER ); 110 108 111 std::string request = MSPROTO_GAME_SERVER " " MSPROTO_SET_NAME " "; 109 112 request += this->ownName; 110 111 // Now register the server at the master server112 this->msc.sendRequest( MSPROTO_GAME_SERVER " " MSPROTO_REGISTER_SERVER );113 113 this->msc.sendRequest( request ); 114 115 114 116 115 return true; … … 123 122 } 124 123 124 void WANDiscoverable::updateClientNumber(int clientNumber) 125 { 126 orxout(verbose, context::master_server) << "Sending new number of clients: " << clientNumber << endl; 127 std::string request = MSPROTO_GAME_SERVER " " MSPROTO_SET_CLIENTS " "; 128 std::stringstream ss; 129 ss << clientNumber; 130 request += ss.str(); 131 132 this->msc.sendRequest( request ); 133 } 134 125 135 126 136 -
code/branches/multiplayerFS15/src/libraries/network/WANDiscoverable.h
r10427 r10434 58 58 void setActivity( bool bActive ); 59 59 60 void updateClientNumber(int clientNumber); 61 60 62 /** Master server communications object */ 61 63 MasterServerComm msc; -
code/branches/multiplayerFS15/src/libraries/network/WANDiscovery.cc
r10427 r10434 96 96 int separator = datastr.find(" "); 97 97 toadd.setServerIP(datastr.substr(0,separator)); 98 toadd.setServerName(datastr.substr(separator+1)); 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 */ … … 169 173 170 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 } 171 184 172 185 } // namespace orxonox -
code/branches/multiplayerFS15/src/libraries/network/WANDiscovery.h
r10427 r10434 87 87 std::string getServerListItemRTT( unsigned int index ); // tolua_export 88 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 89 96 /* todo: might make this private and use getter/setter methods 90 97 * at some later time. -
code/branches/multiplayerFS15/src/libraries/network/packet/ServerInformation.cc
r10334 r10434 42 42 ServerInformation::ServerInformation() 43 43 { 44 45 44 } 46 45 -
code/branches/multiplayerFS15/src/libraries/network/packet/ServerInformation.h
r10427 r10434 51 51 void setServerIP( std::string IP ) { this->serverIP_ = IP; } 52 52 std::string getServerIP() { return this->serverIP_; } 53 void setClientNumber( int clientNumber ) { this->clientNumber_ = clientNumber; } 54 int getClientNumber() { return this->clientNumber_; } 53 55 uint32_t getServerRTT() { return this->serverRTT_; } 54 56 … … 57 59 std::string serverIP_; 58 60 uint32_t serverRTT_; 61 int clientNumber_; 59 62 }; 60 63
Note: See TracChangeset
for help on using the changeset viewer.