[9537] | 1 | /* |
---|
| 2 | orxonox - the future of 3D-vertical-scrollers |
---|
| 3 | |
---|
| 4 | Copyright (C) 2004 orx |
---|
| 5 | |
---|
| 6 | This program is free software; you can redistribute it and/or modify |
---|
| 7 | it under the terms of the GNU General Public License as published by |
---|
| 8 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 9 | any later version. |
---|
| 10 | |
---|
| 11 | ### File Specific: |
---|
| 12 | main-programmer: Patrick Boenzli (patrick@orxonox.ethz.ch) |
---|
| 13 | */ |
---|
| 14 | |
---|
| 15 | #include "proxy_control.h" |
---|
| 16 | |
---|
| 17 | #include "class_list.h" |
---|
| 18 | |
---|
| 19 | |
---|
| 20 | #include "player.h" |
---|
| 21 | #include "state.h" |
---|
| 22 | #include "shared_network_data.h" |
---|
[9541] | 23 | #include "network_game_manager.h" |
---|
[9537] | 24 | |
---|
| 25 | #include "converter.h" |
---|
| 26 | |
---|
| 27 | #include "preferences.h" |
---|
| 28 | |
---|
| 29 | #include "debug.h" |
---|
| 30 | |
---|
| 31 | |
---|
| 32 | |
---|
| 33 | |
---|
| 34 | ProxyControl* ProxyControl::singletonRef = NULL; |
---|
| 35 | |
---|
| 36 | |
---|
| 37 | /** |
---|
| 38 | * constructor |
---|
| 39 | */ |
---|
| 40 | ProxyControl::ProxyControl() |
---|
| 41 | { |
---|
| 42 | this->setClassID( CL_PROXY_CONTROL, "ProxyControl" ); |
---|
| 43 | |
---|
[9538] | 44 | MessageManager::getInstance()->registerMessageHandler( MSGID_PROXY_NEWCLIENT, messageHandlerNewClient, NULL ); |
---|
[9537] | 45 | |
---|
| 46 | PRINTF(0)("ProxyControl created\n"); |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | |
---|
| 50 | /** |
---|
| 51 | * standard deconstructor |
---|
| 52 | */ |
---|
| 53 | ProxyControl::~ProxyControl() |
---|
| 54 | { |
---|
| 55 | ProxyControl::singletonRef = NULL; |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | |
---|
| 59 | /** |
---|
| 60 | * override this function to be notified on change |
---|
| 61 | * of your registred variables. |
---|
| 62 | * @param id id's which have changed |
---|
| 63 | */ |
---|
| 64 | void ProxyControl::varChangeHandler( std::list< int > & id ) |
---|
| 65 | { |
---|
| 66 | // if ( std::find( id.begin(), id.end(), playableUniqueId_handle ) != id.end() ) |
---|
| 67 | // { |
---|
| 68 | // this->setPlayableUniqueId( this->playableUniqueId ); |
---|
| 69 | // |
---|
| 70 | // PRINTF(0)("uniqueID changed %d %d %d\n", userId, SharedNetworkData::getInstance()->getHostID(), getUniqueID()); |
---|
| 71 | // } |
---|
| 72 | } |
---|
| 73 | |
---|
[9538] | 74 | |
---|
| 75 | /** |
---|
| 76 | * signals new client connected to this local proxy |
---|
| 77 | * @param userId userId of the new client |
---|
| 78 | */ |
---|
| 79 | void ProxyControl::signalNewClient(int userId) |
---|
| 80 | { |
---|
[9543] | 81 | PRINTF(0)("Signaling new Client: %i\n"); |
---|
[9538] | 82 | // make sure we are a proxy server |
---|
| 83 | assert(SharedNetworkData::getInstance()->isProxyServerActive()); |
---|
| 84 | |
---|
[9539] | 85 | byte * data = new byte[INTSIZE]; |
---|
[9538] | 86 | |
---|
[9539] | 87 | assert( Converter::intToByteArray( userId, data + INTSIZE, INTSIZE ) == INTSIZE ); |
---|
| 88 | |
---|
[9542] | 89 | MessageManager::getInstance()->sendMessage( MSGID_PROXY_NEWCLIENT, data, INTSIZE, RT_SERVER, NET_UNASSIGNED, MP_HIGHBANDWIDTH ); |
---|
[9538] | 90 | } |
---|
| 91 | |
---|
| 92 | |
---|
| 93 | /** |
---|
| 94 | * this is the handler for proxy signals: new clients |
---|
| 95 | * |
---|
| 96 | * @param messageType the type of the message |
---|
| 97 | * @param data message data |
---|
| 98 | * @param dataLength length of the message data |
---|
| 99 | * @param someData some other atteched data |
---|
| 100 | * @param senderId id of the sender client |
---|
| 101 | * @param destinationId id of the destination client |
---|
| 102 | * @return true if succeeded |
---|
| 103 | */ |
---|
| 104 | bool ProxyControl::messageHandlerNewClient( MessageType messageType, byte * data, int dataLength, void * someData, int senderId, int destinationId ) |
---|
| 105 | { |
---|
[9543] | 106 | int userId = 0; |
---|
[9541] | 107 | // body data length correct? |
---|
| 108 | if ( dataLength != INTSIZE ) |
---|
| 109 | { |
---|
| 110 | PRINTF(2)("new client message has wrong size: %d\n", dataLength ); |
---|
| 111 | return true; |
---|
| 112 | } |
---|
| 113 | // read the userId fromt he message body |
---|
| 114 | assert( Converter::byteArrayToInt( data, &userId) == INTSIZE ); |
---|
| 115 | |
---|
| 116 | PRINTF(0)("Got Signal: new player arrived with userId: %i\n", userId); |
---|
[9538] | 117 | // part for the master server |
---|
| 118 | if( SharedNetworkData::getInstance()->isMasterServer()) |
---|
| 119 | { |
---|
[9541] | 120 | // we now create the new player ship and stuff... |
---|
| 121 | NetworkGameManager::getInstance()->signalNewPlayer(userId); |
---|
[9538] | 122 | } |
---|
| 123 | else if(SharedNetworkData::getInstance()->isProxyServerActive()) |
---|
| 124 | { |
---|
| 125 | |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | return true; |
---|
| 129 | } |
---|