Changeset 7651 for code/branches/masterserver/src/modules
- Timestamp:
- Nov 17, 2010, 4:18:14 PM (14 years ago)
- Location:
- code/branches/masterserver/src/modules/masterserver
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
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.