Changeset 8202
- Timestamp:
- Apr 7, 2011, 4:18:08 PM (14 years ago)
- Location:
- code/branches/masterserver2/src/libraries/network
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/masterserver2/src/libraries/network/MasterServer.cc
r8163 r8202 52 52 { 53 53 /* get an iterator */ 54 std::list< packet::ServerInformation>::iterator i;54 std::list<ServerListElem>::iterator i; 55 55 56 56 /* packet holder */ … … 63 63 /* send this particular server */ 64 64 /* build reply string */ 65 char *tosend = (char *)calloc( (*i). getServerIP().length()65 char *tosend = (char *)calloc( (*i).ServerInfo.getServerIP().length() 66 66 + MSPROTO_SERVERLIST_ITEM_LEN + 2,1 ); 67 67 if( !tosend ) … … 70 70 } 71 71 sprintf( tosend, "%s %s", MSPROTO_SERVERLIST_ITEM, 72 (*i). getServerIP().c_str() );72 (*i).ServerInfo.getServerIP().c_str() ); 73 73 74 74 /* create packet from it */ … … 104 104 */ 105 105 void 106 MasterServer::helper_ pingServers( void)106 MasterServer::helper_cleanupServers() 107 107 { 108 108 /* get an iterator */ 109 std::list<packet::ServerInformation>::iterator i; 109 std::list<ServerListElem>::iterator i; 110 110 111 /* loop through list elements */ 111 112 for( i = mainlist.serverlist.begin(); i 112 113 != mainlist.serverlist.end(); ++i ) 113 114 { 114 /* to be implemented, waiting for Oli to reply to my email - sandro */ 115 115 if( mainlist.serverlist.size() != 0 && (*i).peer && 116 ((*i).peer->state == ENET_PEER_STATE_DISCONNECTED || 117 (*i).peer->state == ENET_PEER_STATE_ZOMBIE )) 118 { mainlist.delServerByName( (*i).ServerInfo.getServerName() ); 119 COUT(2) << "someone timed out.\n"; 120 } 116 121 } 117 122 118 }119 120 void121 MasterServer::helper_cleanupServers()122 {123 /* same as above. */124 125 123 } 126 124 … … 165 163 166 164 /* output that the disconnect happened */ 167 COUT( 4) << (char*)event->peer->data << " disconnected.\n";165 COUT(2) << (char*)event->peer->data << " disconnected.\n"; 168 166 169 167 /* create string from peer data */ … … 205 203 MSPROTO_REGISTER_SERVER, MSPROTO_REGISTER_SERVER_LEN ) ) 206 204 { /* register new server */ 207 mainlist.addServer( packet::ServerInformation( event ) ); 205 mainlist.addServer( packet::ServerInformation( event ), 206 event->peer ); 208 207 209 208 /* tell people we did so */ … … 260 259 } 261 260 262 /* TODO schedule pings for servers somewhere here */263 /* Iterate through servers and send pings */264 helper_pingServers();265 266 261 /* check for timed out pings and remove those guys from 267 262 * the server list -
code/branches/masterserver2/src/libraries/network/ServerList.cc
r7801 r8202 40 40 41 41 int 42 ServerList::addServer( packet::ServerInformation toadd ) 43 { this->serverlist.push_back( toadd ); 42 ServerList::addServer( packet::ServerInformation toadd, 43 ENetPeer *peer ) 44 { 45 ServerListElem toAdd; 46 toAdd.ServerInfo = toadd; 47 toAdd.peer = peer; 48 49 this->serverlist.push_back( toAdd ); 44 50 return 0; 45 51 } … … 49 55 { 50 56 /* get an iterator */ 51 std::list< packet::ServerInformation>::iterator i;57 std::list<ServerListElem>::iterator i; 52 58 53 59 /* loop through list elements */ 54 60 for( i = serverlist.begin(); i != serverlist.end(); ++i ) 55 if( (*i). getServerName() == name )61 if( (*i).ServerInfo.getServerName() == name ) 56 62 { /* found this name, remove and quit */ 57 63 this->serverlist.erase( i ); … … 64 70 { 65 71 /* get an iterator */ 66 std::list< packet::ServerInformation>::iterator i;72 std::list<ServerListElem>::iterator i; 67 73 68 74 /* loop through list elements */ 69 for( i =serverlist.begin(); i != serverlist.end(); ++i )70 if( (*i). getServerIP() == address )75 for( i = serverlist.begin(); i != serverlist.end(); ++i ) 76 if( (*i).ServerInfo.getServerIP() == address ) 71 77 { /* found this name, remove and quit */ 72 78 this->serverlist.erase( i ); … … 78 84 79 85 /* sort by name */ 80 bool sub_compare_names( packet::ServerInformationno1,81 packet::ServerInformationno2 )82 { return no1. getServerName() > no2.getServerName(); }86 bool sub_compare_names( ServerListElem no1, 87 ServerListElem no2 ) 88 { return no1.ServerInfo.getServerName() > no2.ServerInfo.getServerName(); } 83 89 84 90 void ServerList::sortByName() … … 88 94 89 95 /* sort by ping */ 90 bool sub_compare_pings( packet::ServerInformationno1,91 packet::ServerInformationno2 )96 bool sub_compare_pings( ServerListElem no1, 97 ServerListElem no2 ) 92 98 { 93 /* TODO */ 94 return no1.getServerName() > no2.getServerName(); 99 return no1.ServerInfo.getServerName() > no2.ServerInfo.getServerName(); 95 100 } 96 101 -
code/branches/masterserver2/src/libraries/network/ServerList.h
r7801 r8202 37 37 namespace orxonox 38 38 { 39 struct ServerListElem 40 { 41 /* server information (name, IP, etc) */ 42 packet::ServerInformation ServerInfo; 43 44 /* peer pointer */ 45 ENetPeer* peer; 46 }; 47 39 48 /** This class is keeps a list of game servers 40 49 * and some info about them. … … 54 63 * Add server to the game server list 55 64 */ 56 int addServer( packet::ServerInformation toadd ); 65 int addServer( packet::ServerInformation toadd, 66 ENetPeer *peer ); 57 67 58 68 /** \param name Name of the server to remove … … 78 88 79 89 /** the list of servers for internal storage */ 80 std::list< packet::ServerInformation> serverlist;90 std::list<ServerListElem> serverlist; 81 91 private: 82 92 };
Note: See TracChangeset
for help on using the changeset viewer.