Changeset 7589
- Timestamp:
- Oct 27, 2010, 3:24:56 PM (14 years ago)
- Location:
- code/branches/masterserver/src/modules/masterserver
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/masterserver/src/modules/masterserver/MasterServer.cpp
r7580 r7589 33 33 /***** EVENTS *****/ 34 34 /* connect event */ 35 int eventConnect( ENetEvent *event ) 35 int eventConnect( ENetEvent *event, 36 orxonox::ServerList *serverlist, 37 orxonox::PeerList *peers ) 36 38 { /* check for bad parameters */ 37 39 if( !event ) … … 41 43 42 44 /* output debug info */ 43 //printf( "A new client connected from %x:%u.\n",44 //event->peer->address.host,45 //event->peer->address.port);45 printf( "A new client connected from %x:%u.\n", 46 event->peer->address.host, 47 event->peer->address.port); 46 48 47 49 /* game server or client connection? */ 50 /* -> decide in protocol */ 48 51 /* game server */ 49 52 /* add to game server list */ 53 /* */ 54 50 55 /* client */ 51 56 /* add to client list */ … … 61 66 62 67 /* disconnect event */ 63 int eventDisconnect( ENetEvent *event ) 68 int eventDisconnect( ENetEvent *event, 69 orxonox::ServerList *serverlist, 70 orxonox::PeerList *peers ) 64 71 { /* check for bad parameters */ 65 72 if( !event ) … … 69 76 70 77 /* output that the disconnect happened, to be removed at a later time. */ 71 //printf ("%s disconnected.\n", event->peer -> data);78 printf( "%s disconnected.\n", event->peer->data ); 72 79 73 80 /* remove the server from the list it belongs to */ … … 126 133 ENetHost *server; 127 134 128 /* Bind the server to the default localhost. */ 129 /* A specific host address can be specified by */ 130 /* enet_address_set_host (& address, "x.x.x.x"); */ 135 /* Bind the server to the default localhost and port ORX_MSERVER_PORT */ 131 136 address.host = ENET_HOST_ANY; 132 133 /* Bind the server to port 1234. */134 137 address.port = ORX_MSERVER_PORT; 135 138 136 server = enet_host_create( & address /* the address to bind the server host to */, 137 ORX_MSERVER_MAXCONNS /* allow up to 32 clients and/or outgoing connections */, 138 ORX_MSERVER_MAXCHANS /* allow up to 2 channels to be used, 0 and 1 */, 139 0 /* assume any amount of incoming bandwidth */, 140 0 /* assume any amount of outgoing bandwidth */); 139 /* create a host with the above settings (the last two 0 mean: accept 140 * any input/output bandwidth */ 141 server = enet_host_create( &address, ORX_MSERVER_MAXCONNS, 142 ORX_MSERVER_MAXCHANS, 0, 0 ); 141 143 142 144 /* see if creation worked */ … … 149 151 /***** INITIALIZE GAME SERVER LIST *****/ 150 152 orxonox::ServerList *mainlist = new orxonox::ServerList(); 151 //if( mainlist == NULL ) 152 //{ fprintf( stderr, "Error creating server list.\n" ); 153 //exit( EXIT_FAILURE ); 154 //} 153 if( mainlist == NULL ) 154 { fprintf( stderr, "Error creating server list.\n" ); 155 exit( EXIT_FAILURE ); 156 } 157 158 /***** INITIALIZE PEER LIST *****/ 159 orxonox::PeerList *peers = new orxonox::PeerList(); 155 160 156 161 /***** ENTER MAIN LOOP *****/ … … 161 166 } 162 167 163 /* NOTE this only waits on one client, we need to find some way to 164 * actually listen on all active connections. This will be implemented 165 * together with the list of active connections. 166 */ 167 /* Wait up to 1000 milliseconds for an event. */ 168 while (enet_host_service (client, event, 1000) > 0) 168 /* create an iterator for the loop */ 169 while( enet_host_service( server, event, 1000 ) > 0 ) 169 170 { /* check what type of event it is and react accordingly */ 170 switch (event .type)171 switch (event->type) 171 172 { /* new connection */ 172 case ENET_EVENT_TYPE_CONNECT: eventConnect( event ); break; 173 case ENET_EVENT_TYPE_CONNECT: 174 eventConnect( event, mainlist, peers ); break; 173 175 174 176 /* disconnect */ 175 case ENET_EVENT_TYPE_DISCONNECT: eventDisconnect( event ); break; 177 case ENET_EVENT_TYPE_DISCONNECT: 178 eventDisconnect( event, mainlist, peers ); break; 176 179 177 180 /* incoming data */ 178 181 case ENET_EVENT_TYPE_RECEIVE: eventData( event ); break; 182 default: break; 179 183 } 180 184 } -
code/branches/masterserver/src/modules/masterserver/MasterServer.h
r7569 r7589 41 41 /* my includes */ 42 42 #include "ServerList.h" 43 #include "PeerList.h" 43 44 44 45 /* c compatibility */ -
code/branches/masterserver/src/modules/masterserver/PeerList.h
r7580 r7589 67 67 ENetPeer *findPeerByAddr( ENetAddress addr ); 68 68 69 /* NOTE: making this list public so it can easily 70 * be iterated. This makes sense since iterating it 71 * will happen all the time, and using getter methods 72 * for the next in list would slow things down unnecessarily. 73 */ 74 /** the list of servers for internal storage */ 75 std::list<ENetPeer *> peerlist; 69 76 private: 70 /** the list of servers for internal storage */ 71 std::list<packet::ENetPeer *> peerlist; 77 /* nothing so far. */ 72 78 }; 73 79 } -
code/branches/masterserver/src/modules/masterserver/ServerList.cpp
r7565 r7589 27 27 */ 28 28 29 29 #include "ServerList.h" 30 30 31 31 namespace orxonox … … 36 36 ServerList::~ServerList() 37 37 { /* delete the list */ 38 serverlist.clear(); }38 serverlist.clear(); 39 39 } 40 40 41 int ServerList::addServer( ServerInformation *toadd ) 41 int 42 ServerList::addServer( packet::ServerInformation *toadd ) 42 43 { this->serverlist.push_back( toadd ); 43 44 return 0; 44 45 } 45 46 46 bool ServerList::delServerByName( std::string name ) 47 bool 48 ServerList::delServerByName( std::string name ) 47 49 { 48 50 /* get an iterator */ 49 list<ServerInformation *>::iterator i;51 std::list<packet::ServerInformation *>::iterator i; 50 52 51 53 /* loop through list elements */ 52 54 for( i = serverlist.begin(); i != serverlist.end(); ++i ) 53 if( (*i)-> serverName_== name )55 if( (*i)->getServerName() == name ) 54 56 { /* found this name, remove and quit */ 55 this->serverlist.remove( i );57 this->serverlist.remove( *i ); 56 58 return true; 57 59 } … … 62 64 { 63 65 /* get an iterator */ 64 list<ServerInformation *>::iterator i;66 std::list<packet::ServerInformation *>::iterator i; 65 67 66 68 /* loop through list elements */ 67 69 for( i=serverlist.begin(); i != serverlist.end(); ++i ) 68 if( (*i)-> serverIP_== address )70 if( (*i)->getServerIP() == address ) 69 71 { /* found this name, remove and quit */ 70 this->serverlist.remove( i );72 this->serverlist.remove( *i ); 71 73 return true; 72 74 } … … 76 78 77 79 /* sort by name */ 78 bool sub_compare_names( ServerInformation *no1, ServerInformation *no2 ) 79 { return no1->serverName_ > no2->serverName_; } 80 bool sub_compare_names( packet::ServerInformation *no1, 81 packet::ServerInformation *no2 ) 82 { return no1->getServerName() > no2->getServerName(); } 80 83 81 84 void ServerList::sortByName() … … 85 88 86 89 /* sort by ping */ 87 bool sub_compare_pings( ServerInformation *no1, ServerInformation *no2 ) 88 { TODO return no1->serverName_ > no2->serverName_; } 90 bool sub_compare_pings( packet::ServerInformation *no1, 91 packet::ServerInformation *no2 ) 92 { 93 /* TODO */ 94 return no1->getServerName() > no2->getServerName(); 95 } 89 96 90 97 void ServerList::sortByPing()
Note: See TracChangeset
for help on using the changeset viewer.