Changeset 9599 in orxonox.OLD for branches/proxy
- Timestamp:
- Jul 29, 2006, 9:33:34 AM (18 years ago)
- Location:
- branches/proxy/src/lib/network
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/proxy/src/lib/network/message_manager.h
r9570 r9599 37 37 38 38 MSGID_PROXY_NEWCLIENT, //!< informs the master server about a new client 39 MSGID_PROXY_LEAVECLIENT //!< informs the master and other proxy servers about a leaving client 39 MSGID_PROXY_LEAVECLIENT, //!< informs the master and other proxy servers about a leaving client 40 MSGID_PROXY_COMMAND, //!< command handler: delivers commands from and to proxies/clients 40 41 }; 41 42 -
branches/proxy/src/lib/network/proxy/proxy_control.cc
r9589 r9599 45 45 MessageManager::getInstance()->registerMessageHandler( MSGID_PROXY_NEWCLIENT, messageHandlerNewClient, NULL ); 46 46 MessageManager::getInstance()->registerMessageHandler( MSGID_PROXY_LEAVECLIENT, messageHandlerLeaveClient, NULL ); 47 MessageManager::getInstance()->registerMessageHandler( MSGID_PROXY_COMMAND, messageHandlerCommand, NULL ); 47 48 48 49 … … 197 198 netMon->removeNode(nNode, netMon->getPeerByUserId(leaveClientId)); 198 199 199 PRINTF(0)("Got Signal: from %i newplayer left with userId: %i\n", senderId, leaveClientId);200 PRINTF(0)("Got Signal: from %i player left with userId: %i\n", senderId, leaveClientId); 200 201 // part for the master server 201 202 if( SharedNetworkData::getInstance()->isMasterServer()) … … 211 212 return true; 212 213 } 214 215 216 217 /** 218 * forces a client to reconnect to another server 219 * @param userId the userId of the client/user :D 220 * @param newAddress the addresss the client should connect to (fully quali dns) 221 */ 222 void ProxyControl::forceReconnection(int userId, const std::string& newAddress) 223 { 224 IP ipAddr = IP(newAddress, 9999); 225 this->forceReconnection(userId, newAddress); 226 } 227 228 229 230 /** 231 * forces a client to reconnect to another server 232 * @param userId the userId of the client/user :D 233 * @param serverId the userId of the server to connect to 234 */ 235 void ProxyControl::forceReconnection(int userId, int serverId) 236 { 237 PeerInfo* serverInfo = SharedNetworkData::getInstance()->getNetworkMonitor()->getPeerByUserId(serverId); 238 if( serverInfo == NULL) 239 { 240 PRINTF(0)("There is no node with userId %i registered in this network. Check the uid again\n"); 241 return; 242 } 243 else if( serverInfo->isMasterServer() || serverInfo->isProxyServerActive()) 244 { 245 PRINTF(0)("You can't connecto to a client (userId %i)\n", serverId); 246 return; 247 } 248 249 250 this->forceReconnection(userId, serverInfo->ip); 251 } 252 253 254 /** 255 * forces a client to reconnect to another server 256 * @param userId the userId of the client/user :D 257 * @param newAddress the addresss the client should connect to 258 */ 259 void ProxyControl::forceReconnection(int userId, IP newAddress) 260 { 261 PRINTF(0)("forcing reconnection: userId %i to %s\n", userId, newAddress.ipString().c_str()); 262 // make sure we are a proxy server 263 264 if( SharedNetworkData::getInstance()->isClient()) 265 { 266 PRINTF(1)("I am client, got no right to force reconnection\n"); 267 return; 268 } 269 270 271 byte data[3 * INTSIZE]; 272 273 // write type of message 274 int type = PXY_RECONNECT; 275 assert( Converter::intToByteArray( type, data, INTSIZE ) == INTSIZE ); 276 // write the userId in the message 277 assert( Converter::intToByteArray( userId, data + INTSIZE, INTSIZE ) == INTSIZE ); 278 // and the ip as an int 279 PeerInfo* pInfo = SharedNetworkData::getInstance()->getNetworkMonitor()->getPeerByUserId(userId); 280 if( pInfo == NULL) 281 { 282 PRINTF(0)("There is no node with userId %i registered in this network. Check the uid again\n"); 283 return; 284 } 285 else if( pInfo->isMasterServer() || pInfo->isProxyServerActive()) 286 { 287 PRINTF(0)("You cannont reconnect a %s, abording\n", pInfo->getNodeTypeString().c_str()); 288 return; 289 } 290 assert( Converter::intToByteArray( newAddress.host(), data + 2 * INTSIZE, INTSIZE ) == INTSIZE ); 291 292 MessageManager::getInstance()->sendMessage( MSGID_PROXY_COMMAND, data, 3*INTSIZE, RT_ALL_ME, NET_UNASSIGNED, MP_HIGHBANDWIDTH ); 293 } 294 295 296 /** 297 * this is the handler for proxy commands 298 * 299 * @param messageType the type of the message 300 * @param data message data 301 * @param dataLength length of the message data 302 * @param someData some other atteched data 303 * @param senderId id of the sender client 304 * @param destinationId id of the destination client 305 * @return true if succeeded 306 */ 307 bool ProxyControl::messageHandlerCommand( MessageType messageType, byte * data, int dataLength, void * someData, int senderId, int destinationId ) 308 { 309 // body data length correct? 310 if ( dataLength != 3 * INTSIZE ) 311 { 312 PRINTF(1)("leave client message has wrong size: %d\n", dataLength ); 313 return true; 314 } 315 316 // read the command type 317 int type = 0; 318 assert( Converter::byteArrayToInt( data, &type) == INTSIZE ); 319 PRINTF(0)("got command from %i with code %i\n", senderId, type); 320 321 // now distingush all different sorts of commands 322 switch( type) 323 { 324 case PXY_RECONNECT: 325 { 326 // now read the user id 327 int userId; 328 assert( Converter::byteArrayToInt( data + INTSIZE, &userId) == INTSIZE ); 329 // and read the dest address 330 int ipHost = 0; 331 assert( Converter::byteArrayToInt( data + INTSIZE, &ipHost) == INTSIZE ); 332 333 // handle it 334 if( SharedNetworkData::getInstance()->isMasterServer() || SharedNetworkData::getInstance()->isProxyServerActive()) 335 { 336 } 337 break; 338 } 339 default: 340 PRINTF(0)("Command not known with id %i\n", type); 341 } 342 343 344 // part for the master server 345 if( SharedNetworkData::getInstance()->isMasterServer()) 346 { 347 // we now create the new player ship and stuff... 348 // NetworkGameManager::getInstance()->signalLeftPlayer(leaveClientId); 349 } 350 else if(SharedNetworkData::getInstance()->isProxyServerActive()) 351 { 352 353 } 354 355 return true; 356 } 357 -
branches/proxy/src/lib/network/proxy/proxy_control.h
r9573 r9599 16 16 17 17 18 typedef enum proxyCommand { 19 PXY_RECONNECT = 0, //!< forces a reconnection of the node 20 21 PXY_NUMBER 22 }; 18 23 19 24 … … 30 35 virtual void varChangeHandler( std::list<int> & id ); 31 36 37 /* connection signal handling */ 32 38 void signalNewClient(int userId); 33 39 static bool messageHandlerNewClient( MessageType messageType, byte * data, int dataLength, void * someData, int senderId, int destinationId ); … … 36 42 static bool messageHandlerLeaveClient( MessageType messageType, byte * data, int dataLength, void * someData, int senderId, int destinationId ); 37 43 44 /* proxy server network control */ 45 void forceReconnection(int userId, int serverId); 46 void forceReconnection(int userId, IP newAddress); 47 void forceReconnection(int userId, const std::string& newAddress); 48 static bool messageHandlerCommand( MessageType messageType, byte * data, int dataLength, void * someData, int senderId, int destinationId ); 38 49 39 50 private:
Note: See TracChangeset
for help on using the changeset viewer.