Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9656 in orxonox.OLD for trunk/src/lib/network


Ignore:
Timestamp:
Aug 4, 2006, 11:01:28 PM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the proxy bache back with no conflicts

Location:
trunk/src/lib/network
Files:
36 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/network/Makefile.am

    r9494 r9656  
    2727                      \
    2828                      proxy/network_settings.cc \
     29                      proxy/proxy_control.cc \
    2930                      \
    3031                      monitor/connection_monitor.cc \
     
    7677                udp_broadcast.h \
    7778                \
    78                 proxy/network_settings.cc \
     79                proxy/network_settings.h \
     80                proxy/proxy_control.h \
    7981                \
    8082                monitor/connection_monitor.h \
  • trunk/src/lib/network/README.NETWORK

    r9494 r9656  
    11
     2
     3
     4
     5WORD OF WARNING:
     6================
     7 - Allways keep the network_settings.conf file from the data repos up-to-date!! Its very important, that the user numbers are synchronized!
    28
    39
    410WORKING_STACK:
    511==============
    6  - it works to connecto to a master server which is connected to a proxy itself
    7 
     12 - removed compiler warnings in some modules
     13 - totaly rework of the permission system
     14 - introduced a new PERMISSION layer: PERMISSION_SERVER which gives the nearest server the authority to handle
    815
    916
    1017UNSOLVED:
    1118=========
    12  - what if the proxy server gets a new client and wants to add it to the game? There are some problems waiting in the network game manager
    13  - actualy the whole message sending system won't work in this network topic. proxys have to relay messages to clients
    14  - the clients cant get its ip in the handleHandshakes without throuwing sigseg
     19 - the clients cant get its ip in the handleHandshakes without throwing sigseg
     20 - MessageManager: proxy/server forward the messages always. Perhaps there is a case, where messages get forwarded forever if there is a loop in the network. think about it again.
     21 - Permissions: Proxy Servers shouldn't be able to create new eneitites on the server
     22 - the nick name must be handled new
    1523
    1624
     
    4856
    4957
     58The ids are created by the master/proxy servers. Each server receives an address space of 1000 nodes where it is able to assign nodes to. This address space could be extended quite easely, since we got plenty of numbers in 4bytes (integer)
     59
     60The handshake sync has always the uniqueId == userId. This is why there are some reserved uniqueIds
     61
    5062
    5163uniqueId:
    5264=========
    5365uniqueId is an id (unique :D) for each synchronizeable to be identified in a network. the number space for uniqueIds goes from 0 to maxplayers - 1
     66
     67The handshake sync has always the uniqueId == userId. This is why there are some reserved uniqueIds
    5468
    5569
     
    6276PERMISSION_ALL                 : all clients can write this variable
    6377
     78Only the master server should have the permission to create new WorldEntities and to add them to the game
    6479
    6580
     
    7287
    7388
     89MessageManager:
     90===============
     91The message manager has special handling if its a master/proxy: the messages will simply be forwarded to the other server
     92
     93
     94Proxy Control:
     95==============
     96The ProxyControl class manages the state of the network by exchanging state messages.
  • trunk/src/lib/network/handshake.cc

    r9494 r9656  
    7171  remoteState.error = 0;
    7272  remoteState.errorString = "";
    73   remoteState.hostId = -1;
     73  remoteState.hostId = NET_ID_UNASSIGNED;
    7474  remoteState.networkManagerId = -1;
    7575  remoteState.messageManagerId = -1;
  • trunk/src/lib/network/message_manager.cc

    r9494 r9656  
    1111   ### File Specific:
    1212   main-programmer: Christoph Renner
    13    co-programmer: ...
     13   co-programmer: Patrick Boenzli (patrick@orxonox.ethz.ch)
     14
     15     June 2006: finishing work on the network stream for pps presentation (rennerc@ee.ethz.ch)
     16     July 2006: some code rearangement and integration of the proxy server mechanism (boenzlip@ee.ethz.ch)
     17     July 2006: message forwarding algorithms
    1418*/
    1519
     
    4448MessageManager::~MessageManager ()
    4549{
    46   for ( MessageQueue::iterator it = messageQueue.begin(); it != messageQueue.end(); it++ )
     50  for ( MessageQueue::iterator it = outgoingMessageQueue.begin(); it != outgoingMessageQueue.end(); it++ )
    4751  {
    4852    for ( std::list<NetworkMessage>::iterator it2 = it->second.messages.begin(); it2 != it->second.messages.end(); it2++ )
     
    5963  }
    6064
    61   messageQueue.clear();
     65  outgoingMessageQueue.clear();
    6266
    6367  this->messageHandlerMap.clear();
     
    8589  int n;
    8690
    87   n = Converter::intToByteArray( messageQueue[userId].toAck.size(), data + i, maxLength );
     91  n = Converter::intToByteArray( outgoingMessageQueue[userId].toAck.size(), data + i, maxLength );
    8892  i += n;
    8993  assert( n == INTSIZE );
    9094
    91   for ( std::list<int>::iterator it = messageQueue[userId].toAck.begin(); it != messageQueue[userId].toAck.end(); it++)
     95  for ( std::list<int>::iterator it = outgoingMessageQueue[userId].toAck.begin(); it != outgoingMessageQueue[userId].toAck.end(); it++)
    9296  {
    9397    n = Converter::intToByteArray( *it, data + i, maxLength );
     
    96100  }
    97101
    98   messageQueue[userId].toAck.clear();
    99 
    100   n = Converter::intToByteArray( messageQueue[userId].messages.size(), data + i, maxLength );
     102  outgoingMessageQueue[userId].toAck.clear();
     103
     104  n = Converter::intToByteArray( outgoingMessageQueue[userId].messages.size(), data + i, maxLength );
    101105  i += n;
    102106  assert( n == INTSIZE );
    103107
    104   for ( std::list<NetworkMessage>::iterator it = messageQueue[userId].messages.begin(); it != messageQueue[userId].messages.end(); it++ )
    105   {
     108  // write the message down, a message has this structure:
     109  //   | data_length | serial_number | message_type | source_id | dest_id | ...data... |
     110  //      4byte        4byte            4byte         4byte      4byte     data_length
     111  for ( std::list<NetworkMessage>::iterator it = outgoingMessageQueue[userId].messages.begin(); it != outgoingMessageQueue[userId].messages.end(); it++ )
     112  {
     113    // send data length
    106114    n = Converter::intToByteArray( it->length, data + i, maxLength );
    107115    i += n;
    108116    assert( n == INTSIZE );
    109117
     118    // send serial number
    110119    n = Converter::intToByteArray( it->number, data + i, maxLength );
    111120    i += n;
    112121    assert( n == INTSIZE );
    113122
    114     n = Converter::intToByteArray( it->messageId, data + i, maxLength );
    115     i += n;
    116     assert( n == INTSIZE );
    117 
     123    // send message type
     124    n = Converter::intToByteArray( it->messageType, data + i, maxLength );
     125    i += n;
     126    assert( n == INTSIZE );
     127
     128    // send sender id
     129    n = Converter::intToByteArray( it->senderId, data + i, maxLength );
     130    i += n;
     131    assert( n == INTSIZE );
     132
     133    // send destination id
     134    n = Converter::intToByteArray( it->destinationId, data + i, maxLength );
     135    i += n;
     136    assert( n == INTSIZE );
     137
     138    // send receiver type
     139    n = Converter::intToByteArray( it->recieverType, data + i, maxLength );
     140    i += n;
     141    assert( n == INTSIZE );
     142
     143    // and copy the data
    118144    assert( i + it->length <= maxLength );
    119145    memcpy( data + i, it->data, it->length );
     
    141167  int nAcks;
    142168
     169
    143170  assert( i + INTSIZE <= length );
    144171  n = Converter::byteArrayToInt( data + i, &nAcks );
     
    167194  i += n;
    168195
    169   int messageLength, messageId;
    170 
     196  int messageLength, messageType;
     197  int senderId, destinationId, recieverType;
     198
     199  // now go through all newly received messages and assemble them
    171200  for ( int j = 0; j < nMessages; j++ )
    172201  {
     202    // read the length
    173203    assert( i + INTSIZE <= length );
    174204    n = Converter::byteArrayToInt( data + i, &messageLength );
     
    176206    i += n;
    177207
     208    // read the serial number
    178209    assert( i + INTSIZE <= length );
    179210    n = Converter::byteArrayToInt( data + i, &number );
     
    181212    i += n;
    182213
    183     assert( i + INTSIZE <= length );
    184     n = Converter::byteArrayToInt( data + i, &messageId );
     214    // read the message type
     215    assert( i + INTSIZE <= length );
     216    n = Converter::byteArrayToInt( data + i, &messageType );
     217    assert( n == INTSIZE );
     218    i += n;
     219
     220    // read the sender id
     221    assert( i + INTSIZE <= length );
     222    n = Converter::byteArrayToInt( data + i, &senderId );
     223    assert( n == INTSIZE );
     224    i += n;
     225
     226    //read the destination id
     227    assert( i + INTSIZE <= length );
     228    n = Converter::byteArrayToInt( data + i, &destinationId);
     229    assert( n == INTSIZE );
     230    i += n;
     231
     232    // read the receiver type
     233    assert( i + INTSIZE <= length );
     234    n = Converter::byteArrayToInt( data + i, &recieverType);
    185235    assert( n == INTSIZE );
    186236    i += n;
    187237
    188238    if ( number > 0 )
    189       messageQueue[userId].toAck.push_back( number );
    190 
     239      outgoingMessageQueue[userId].toAck.push_back( number );
     240
     241//     PRINTF(0)("got message with type: %i\n", messageType);
    191242    assert( i + messageLength <= length );
    192     assert( messageHandlerMap.find( (MessageId)messageId ) != messageHandlerMap.end() );
    193     if ( std::find( messageQueue[userId].recievedMessages.begin(), messageQueue[userId].recievedMessages.end(), number )== messageQueue[userId].recievedMessages.end() )
     243    // make sure there is a message handler for this message type
     244    assert( messageHandlerMap.find( (MessageType)messageType ) != messageHandlerMap.end());
     245
     246
     247    if ( std::find( outgoingMessageQueue[userId].recievedMessages.begin(), outgoingMessageQueue[userId].recievedMessages.end(), number ) ==
     248         outgoingMessageQueue[userId].recievedMessages.end() )
    194249    {
    195       if ( !(*(messageHandlerMap[(MessageId)messageId].cb))( (MessageId)messageId, data + i, messageLength, messageHandlerMap[(MessageId)messageId].someData, userId ) )
     250
     251      // find out if this message is addressed for this client too
     252      if( recieverType == RT_ALL_BUT_ME  && SharedNetworkData::getInstance()->getHostID() != senderId ||
     253          recieverType == RT_ALL_ME ||
     254          recieverType == RT_NOT_USER && SharedNetworkData::getInstance()->getHostID() != destinationId ||
     255          recieverType == RT_USER  && SharedNetworkData::getInstance()->getHostID() == destinationId ||
     256          recieverType == RT_SERVER && SharedNetworkData::getInstance()->isMasterServer() ||
     257          recieverType == RT_SERVER && SharedNetworkData::getInstance()->isProxyServerActive())
    196258      {
    197         NetworkMessage msg;
    198 
    199         msg.data = new byte[messageLength];
    200         memcpy( msg.data, data + i, messageLength );
    201         msg.length = messageLength;
    202         msg.messageId = (MessageId)messageId;
    203         msg.number = userId;
    204 
    205         incomingMessageBuffer.push_back( msg );
     259
     260        PRINTF(0)("<<< MessageManager: got msg with type: %i, from sender %i, to rec: %i\n", messageType, senderId, destinationId);
     261      // call the handler function and handle errors
     262        if ( !(*(messageHandlerMap[(MessageType)messageType].cb))( (MessageType)messageType, data + i, messageLength,
     263                 messageHandlerMap[(MessageType)messageType].someData, senderId, destinationId ) )
     264        {
     265        // if the message is not handled correctly, bush it back to the incoming packets therefore trying it later
     266          NetworkMessage msg;
     267
     268          msg.data = new byte[messageLength];
     269          memcpy( msg.data, data + i, messageLength );
     270          msg.length = messageLength;
     271          msg.messageType = (MessageType)messageType;
     272          msg.number = userId;
     273          msg.senderId = senderId;
     274          msg.recieverType = (RecieverType)recieverType;
     275          msg.destinationId = destinationId;
     276
     277          incomingMessageQueue.push_back( msg );
     278        }
    206279      }
    207       messageQueue[userId].recievedMessages.push_back( number );
     280
     281
     282      // check if the message needs to be forwarded
     283      if( recieverType == RT_ALL_BUT_ME ||
     284          recieverType == RT_ALL_ME ||
     285          recieverType == RT_NOT_USER ||
     286          recieverType == RT_USER  && SharedNetworkData::getInstance()->getHostID() != destinationId ||
     287          recieverType == RT_SERVER && SharedNetworkData::getInstance()->isProxyServerActive() )
     288      {
     289        // forwarding the messages but only if its a proxy
     290        if( SharedNetworkData::getInstance()->isProxyServerActive())
     291        {
     292          PRINTF(0)("===========>> Forwarding Message msg with type: %i, from sender %i, to rec: %i\n", messageType, senderId, destinationId);
     293          NetworkMessage msg;
     294
     295          msg.data = new byte[messageLength];
     296          memcpy( msg.data, data + i, messageLength );
     297          msg.length = messageLength;
     298          msg.messageType = (MessageType)messageType;
     299          msg.number = userId;
     300          msg.senderId = senderId;
     301          msg.destinationId = destinationId;
     302          msg.recieverType = (RecieverType)recieverType;
     303
     304          this->sendMessage(msg.messageType, msg.data, msg.length, msg.recieverType, msg.senderId = senderId, msg.destinationId, MP_HIGHBANDWIDTH);
     305        }
     306      }
     307
     308      // save the serial number for ack signaling
     309      outgoingMessageQueue[userId].recievedMessages.push_back( number );
    208310    }
     311
    209312    i += messageLength;
    210313  }
    211314
    212315
    213   //TODO maybe handle incomingMessage in tick function. else local messages will not be handled if no clients are connected
    214   for ( std::list<NetworkMessage>::iterator it = incomingMessageBuffer.begin(); it != incomingMessageBuffer.end();  )
    215   {
    216     if ( (*(messageHandlerMap[it->messageId].cb))( it->messageId, it->data, it->length, messageHandlerMap[it->messageId].someData, it->number ) )
     316  //walk throu message queue and remove acked messages
     317  for ( std::list<NetworkMessage>::iterator it = outgoingMessageQueue[userId].messages.begin(); it != outgoingMessageQueue[userId].messages.end();  )
     318  {
     319    if ( std::find( acks.begin(), acks.end(), it->number) != acks.end() )
     320    {
     321      std::list<NetworkMessage>::iterator delIt = it;
     322      it++;
     323      outgoingMessageQueue[userId].messages.erase( delIt );
     324      continue;
     325    }
     326    it++;
     327  }
     328
     329  //TODO find bether way. maybe with timestamp
     330  if ( outgoingMessageQueue[userId].recievedMessages.size() > 1000 )
     331  {
     332    for ( int j = 0; j < (int)outgoingMessageQueue[userId].recievedMessages.size() - 1000; j++ )
     333      outgoingMessageQueue[userId].recievedMessages.erase( outgoingMessageQueue[userId].recievedMessages.begin() );
     334  }
     335
     336  return i;
     337}
     338
     339
     340
     341
     342/**
     343 * processes the message manager data, specialy check for localy generated messages
     344 */
     345void MessageManager::processData()
     346{
     347  // now call the message handlers with the new message
     348  for ( std::list<NetworkMessage>::iterator it = incomingMessageQueue.begin(); it != incomingMessageQueue.end();  )
     349  {
     350    PRINTF(0)("<<< MessageManager: got local msg with type: %i, from sender %i, to rec: %i\n", (*it).messageType, (*it).senderId, (*it).destinationId);
     351
     352    if ( (*(messageHandlerMap[it->messageType].cb))( it->messageType, it->data, it->length, messageHandlerMap[it->messageType].someData,
     353                                                     /*it->number, */it->senderId, it->destinationId ) )
    217354    {
    218355      std::list<NetworkMessage>::iterator delIt = it;
     
    220357        delete it->data;
    221358      it++;
    222       incomingMessageBuffer.erase( delIt );
     359      incomingMessageQueue.erase( delIt );
    223360      continue;
    224361    }
     
    226363  }
    227364
    228   //walk throu message queue and remove acked messages
    229   for ( std::list<NetworkMessage>::iterator it = messageQueue[userId].messages.begin(); it != messageQueue[userId].messages.end();  )
    230   {
    231     if ( std::find( acks.begin(), acks.end(), it->number) != acks.end() )
    232     {
    233       std::list<NetworkMessage>::iterator delIt = it;
    234       it++;
    235       messageQueue[userId].messages.erase( delIt );
    236       continue;
    237     }
    238     it++;
    239   }
    240 
    241   //TODO find bether way. maybe with timestamp
    242   if ( messageQueue[userId].recievedMessages.size() > 1000 )
    243   {
    244     for ( int j = 0; j < messageQueue[userId].recievedMessages.size() - 1000; j++ )
    245       messageQueue[userId].recievedMessages.erase( messageQueue[userId].recievedMessages.begin() );
    246   }
    247 
    248   return i;
    249 }
     365}
     366
     367
     368
    250369
    251370/**
     
    255374void MessageManager::cleanUpUser( int userId )
    256375{
    257   if ( messageQueue.find( userId ) == messageQueue.end() )
     376  if ( outgoingMessageQueue.find( userId ) == outgoingMessageQueue.end() )
    258377    return;
    259378
    260   for ( std::list<NetworkMessage>::iterator it = messageQueue[userId].messages.begin(); it != messageQueue[userId].messages.end(); it++ )
     379  for ( std::list<NetworkMessage>::iterator it = outgoingMessageQueue[userId].messages.begin(); it != outgoingMessageQueue[userId].messages.end(); it++ )
    261380  {
    262381    if ( it->data )
     
    265384  }
    266385
    267   messageQueue[userId].toAck.clear();
    268 
    269   messageQueue.erase( userId );
    270 }
    271 
    272 /**
    273  * registers function to handle messages with id messageId. someData is passed to callbackfuntion
    274  * @param messageId message id to handle
     386  outgoingMessageQueue[userId].toAck.clear();
     387
     388  outgoingMessageQueue.erase( userId );
     389}
     390
     391/**
     392 * registers function to handle messages with id messageType. someData is passed to callbackfuntion
     393 * @param messageType message id to handle
    275394 * @param cb function pointer to callback function
    276395 * @param someData this pointer is passed to callback function without modification
    277396 * @return true on success
    278397 */
    279 bool MessageManager::registerMessageHandler( MessageId messageId, MessageCallback cb, void * someData )
     398bool MessageManager::registerMessageHandler( MessageType messageType, MessageCallback cb, void * someData )
    280399{
    281400  MessageHandler messageHandler;
    282401
    283402  messageHandler.cb = cb;
    284   messageHandler.messageId = messageId;
     403  messageHandler.messageType = messageType;
    285404  messageHandler.someData = someData;
    286405
    287   messageHandlerMap[messageId] = messageHandler;
     406  messageHandlerMap[messageType] = messageHandler;
    288407
    289408  return true;
     
    297416{
    298417  // just do something so map creates a new entry
    299   messageQueue[userId].toAck.clear();
    300   //assert( messageQueue[userId].messages.size() == 0 );
    301 }
     418  outgoingMessageQueue[userId].toAck.clear();
     419  //assert( outgoingMessageQueue[userId].messages.size() == 0 );
     420}
     421
     422
    302423
    303424/**
     
    308429 *               RT_NOT_USER send to all but reciever
    309430 *
    310  * @param messageId message id
     431 * @param messageType message id
    311432 * @param data pointer to data
    312433 * @param dataLength length of data
    313  * @param recieverType
    314  * @param reciever
    315  */
    316 void MessageManager::sendMessage( MessageId messageId, byte * data, int dataLength, RecieverType recieverType, int reciever, MessagePriority messagePriority )
    317 {
    318   for ( MessageQueue::iterator it = messageQueue.begin(); it != messageQueue.end(); it++ )
    319   {
     434 * @param recieverType type of the receiver
     435 * @param reciever the userId of the receiver if needed (depends on the ReceiverType)
     436 */
     437void MessageManager::sendMessage( MessageType messageType, byte * data, int dataLength, RecieverType recieverType, int reciever, MessagePriority messagePriority )
     438{
     439  this->sendMessage(messageType, data, dataLength, recieverType, SharedNetworkData::getInstance()->getHostID(), reciever, messagePriority);
     440}
     441
     442
     443/**
     444 * send a message to one or more clients as a special client
     445 * recieverType:
     446 *               RT_ALL send to all users. reciever is ignored
     447 *               RT_USER send only to reciever
     448 *               RT_NOT_USER send to all but reciever
     449 *
     450 * @param messageType message id
     451 * @param data pointer to data
     452 * @param dataLength length of data
     453 * @param recieverType type of the receiver
     454 * @param sender the userId of the sender if there is need for shadowing it (eg. for msg forwarding)
     455 * @param reciever the userId of the receiver if needed (depends on the ReceiverType)
     456 */
     457    void MessageManager::sendMessage( MessageType messageType, byte * data, int dataLength, RecieverType recieverType, int sender, int reciever, MessagePriority messagePriority )
     458{
     459  PRINTF(0)(" >>> MessageManager: sending msg with type: %i, recieverType: %i, reciever %i\n", messageType, recieverType, reciever);
     460
     461  // go through all outgoing message queues and add the message if its appropriate
     462  for ( MessageQueue::iterator it = this->outgoingMessageQueue.begin(); it != this->outgoingMessageQueue.end(); it++ )
     463  {
     464
    320465    if (
    321          recieverType == RT_ALL_ME ||
    322          recieverType == RT_ALL_BUT_ME ||
    323          recieverType == RT_USER && it->first == reciever ||
    324          recieverType == RT_NOT_USER && it->first != reciever ||
    325          recieverType == RT_SERVER && getNetworkStream()->isUserMasterServer( it->first ) ||
    326          recieverType == RT_SERVER && getNetworkStream()->isUserProxyServerActive( it->first )
    327        )
     466         recieverType == RT_ALL_ME      ||
     467         recieverType == RT_ALL_BUT_ME  ||
     468         recieverType == RT_USER        && it->first == reciever ||
     469         recieverType == RT_USER        && reciever == NET_ID_MASTER_SERVER && !getNetworkStream()->isUserMasterServer( it->first ) ||  //(*)
     470         recieverType == RT_NOT_USER    && it->first != reciever ||
     471         recieverType == RT_SERVER      && getNetworkStream()->isUserMasterServer( it->first ) ||
     472         recieverType == RT_SERVER      && getNetworkStream()->isUserProxyServerActive( it->first )
     473       )// (*) special case: forward
    328474    {
    329475      NetworkMessage msg;
     
    332478      memcpy( msg.data, data, dataLength );
    333479      msg.length = dataLength;
    334       msg.messageId = messageId;
    335       msg.number = newNumber++;
     480      msg.messageType = messageType;
     481      msg.number = this->newNumber++;
     482      msg.senderId = sender;
     483      msg.destinationId = reciever;
     484      msg.recieverType = recieverType;
    336485      msg.priority = messagePriority;
    337486
    338487      it->second.messages.push_back( msg );
    339488    }
    340   }
    341 
    342   if ( recieverType == RT_ALL_ME )
     489
     490
     491  }
     492
     493
     494  // if the message is also for myself, handle it here
     495  if ( recieverType == RT_ALL_ME ||
     496       recieverType == RT_USER   && reciever == SharedNetworkData::getInstance()->getHostID()
     497     )
    343498  {
    344499    NetworkMessage msg;
     
    347502    memcpy( msg.data, data, dataLength );
    348503    msg.length = dataLength;
    349     msg.messageId = messageId;
     504    msg.messageType = messageType;
    350505    msg.number = SharedNetworkData::getInstance()->getHostID();
     506    msg.senderId = sender;
     507    msg.destinationId = reciever;
     508    msg.recieverType = recieverType;
    351509    msg.priority = messagePriority;
    352510
    353     incomingMessageBuffer.push_back( msg );
    354   }
    355 }
    356 
    357 
     511    this->incomingMessageQueue.push_back( msg );
     512  }
     513}
     514
     515
  • trunk/src/lib/network/message_manager.h

    r9494 r9656  
    2020      int length
    2121      int number
    22       int MessageId
     22      int MessageType
    2323      byte * data
    2424    )[1..nmsg]
     
    2626
    2727
    28 enum MessageId
     28//!< different message ids
     29enum MessageType
    2930{
    30   TESTMESSAGEID = 1,
    31   MSGID_DELETESYNCHRONIZEABLE,
    32   MSGID_PREFEREDTEAM,
    33   MSGID_CHANGENICKNAME,
    34   MSGID_CHATMESSAGE,
    35   MSGID_RESPAWN
     31  TESTMESSAGEID                  = 1,         //!< for testing purposes
     32  MSGID_DELETESYNCHRONIZEABLE,                //!< message for sync deletion
     33  MSGID_PREFEREDTEAM,                         //!< change prefered team
     34  MSGID_CHANGENICKNAME,                       //!< change nicknames
     35  MSGID_CHATMESSAGE,                          //!< chat message
     36  MSGID_RESPAWN,                              //!< respawn message
     37
     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
     40  MSGID_PROXY_COMMAND,                         //!< command handler: delivers commands from and to proxies/clients
    3641};
    3742
    38 typedef bool (*MessageCallback)( MessageId messageId, byte * data, int dataLength, void * someData, int userId );
    3943
    40 enum RecieverType
     44typedef bool (*MessageCallback)( MessageType messageType, byte * data, int dataLength, void * someData, int senderId, int destinationId );
     45
     46typedef enum RecieverType
    4147{
    4248  RT_ALL_BUT_ME = 1,   //!< message is sent to all users but myself
     
    5763struct NetworkMessage
    5864{
    59   MessageId        messageId;
    60   byte *           data;
    61   int              length;
    62   int              number;
    63   MessagePriority  priority;
     65  MessageType      messageType;                         //!< type of the message
     66  byte *           data;                                //!< data
     67  int              length;                              //!< length of the data
     68  int              number;                              //!< serial number
     69  int              senderId;                            //!< userId of the sender
     70  int              destinationId;                       //!< userId of the destination
     71  RecieverType     recieverType;                        //!< type of the receiver
     72  MessagePriority  priority;                            //!< priority of the messages
    6473};
    6574
     
    7382typedef std::map<int,MessageUserQueue> MessageQueue;
    7483
     84
     85
    7586struct MessageHandler
    7687{
    77   MessageCallback cb;
    78   MessageId       messageId;
    79   void *          someData;
     88  MessageCallback   cb;
     89  MessageType       messageType;
     90  void *            someData;
    8091};
    8192
    82 typedef std::map<MessageId,MessageHandler> MessageHandlerMap;
     93typedef std::map<MessageType,MessageHandler> MessageHandlerMap;
    8394
    8495//! A class for sending messages over network
    8596class MessageManager : public Synchronizeable {
    86  protected:
    87    MessageManager();
     97
     98
    8899 public:
    89100   inline static MessageManager * getInstance(){ if (!singletonRef) singletonRef = new MessageManager();  return singletonRef; }
     
    91102   virtual ~MessageManager();
    92103
    93    bool registerMessageHandler( MessageId messageId, MessageCallback cb, void * someData );
     104   bool registerMessageHandler( MessageType messageType, MessageCallback cb, void * someData );
    94105
    95    void sendMessage( MessageId messageId, byte * data, int dataLength, RecieverType recieverType, int reciever, MessagePriority messagePriority );
     106   void sendMessage( MessageType messageType, byte * data, int dataLength, RecieverType recieverType, int reciever, MessagePriority messagePriority );
     107   void sendMessage( MessageType messageType, byte * data, int dataLength, RecieverType recieverType, int sender, int reciever, MessagePriority messagePriority );
    96108
     109   void initUser( int userId );
     110
     111   void processData();
     112
     113
     114  protected:
     115    MessageManager();
     116
     117
     118  private:
    97119   virtual int getStateDiff( int userId, byte* data, int maxLength, int stateId, int fromStateId, int priorityTH );
    98120   virtual int setStateDiff( int userId, byte* data, int length, int stateId, int fromStateId );
     
    101123   virtual void handleRecvState( int userId, int stateId, int fromStateId ){}
    102124
    103    void initUser( int userId );
    104 
    105125
    106126 private:
    107    static MessageManager *   singletonRef;
    108    MessageQueue              messageQueue;           //!< stores messages to send
     127   static MessageManager *   singletonRef;           //!< the singleton reference
     128
     129   std::list<NetworkMessage> incomingMessageQueue;   //!< the incoming message buffer
     130   MessageQueue              outgoingMessageQueue;   //!< stores messages to send
    109131   MessageHandlerMap         messageHandlerMap;      //!< contains handlers for messages
    110132
    111133   int                       newNumber;              //!< used to create unique message numbers
    112    std::list<NetworkMessage> incomingMessageBuffer;
     134
    113135
    114136};
    115137
    116 #endif /* _PROTO_CLASS_H */
     138#endif /* _MESSAGE_MANAGER_H */
  • trunk/src/lib/network/monitor/network_monitor.cc

    r9494 r9656  
    1010
    1111### File Specific:
    12    main-programmer: Patrick Boenzli
     12   main-programmer: Patrick Boenzli (patrick@orxonox.ethz.ch)
    1313*/
    1414
     
    4949  this->networkStream = networkStream;
    5050  this->playerNumber = 0;
     51  this->connectionNumber = 0;
    5152  // create the localnode, init it and add it to the nodes list
    5253  this->localNode = new NetworkNode( this->networkStream->getPeerInfo());
     
    6667      PeerInfo* peer = new PeerInfo();
    6768      peer->ip = (*it);
    68       peer->nodeType = NET_PROXY_SERVER_ACTIVE;
     69      peer->nodeType = NET_PROXY_SERVER_PASSIVE;
    6970      peer->userId = -1;
    7071
    71       NetworkNode* node = new NetworkNode(peer);
    72       this->addNode( node);
    7372      this->addActiveProxyServer( this->localNode, peer);
    7473    }
     
    141140    return;
    142141
     142  PRINTF(0)("^^^^^^^^^^^^^^^^^^^^^^^^^^ adding node: %i with type: %s\n\n", pInfo->userId, pInfo->getNodeTypeString().c_str());
     143
    143144  if( pInfo->isClient())
    144     this->localNode->addClient(pInfo);
     145  {
     146    this->localNode->addClient(new NetworkNode(pInfo));
     147  }
    145148  else if( pInfo->isProxyServerActive())
    146149  {
    147     this->localNode->addActiveProxyServer(pInfo);
    148     // create a new node, since a proxy can connect clients again
    149     NetworkNode* node = new NetworkNode(pInfo);
    150     this->nodeList.push_back(node);
     150    this->localNode->addActiveProxyServer(new NetworkNode(pInfo));
     151  }
     152  else if( pInfo->isProxyServerActivePassive())
     153  {
     154    this->localNode->addPassiveProxyServer(new NetworkNode(pInfo));
    151155  }
    152156  else if( pInfo->isMasterServer())
    153157  {
    154     this->localNode->addMasterServer(pInfo);
    155   }
     158    this->localNode->addMasterServer(new NetworkNode(pInfo));
     159  }
     160  else
     161    assert(false);
    156162}
    157163
     
    168174
    169175  if( pInfo->isClient())
    170     node->addClient(pInfo);
     176    node->addClient(new NetworkNode(pInfo));
    171177  else if( pInfo->isProxyServerActive())
    172     node->addActiveProxyServer(pInfo);
     178    node->addActiveProxyServer(new NetworkNode(pInfo));
    173179  else if( pInfo->isMasterServer())
    174     node->addMasterServer(pInfo);
     180    node->addMasterServer(new NetworkNode(pInfo));
     181}
     182
     183
     184
     185/**
     186 * removes a node from the network monitor
     187 * @param pInfo the node to remove
     188 */
     189void NetworkMonitor::removeNode(PeerInfo* pInfo)
     190{
     191  this->removeNode(this->localNode, pInfo);
     192}
     193
     194
     195/**
     196 * removes the network node
     197 * @param node the network node where the PeerInfo node is connected to
     198 * @param pInfo the PeerInfo to remove
     199 */
     200void NetworkMonitor::removeNode(NetworkNode* node, PeerInfo* pInfo)
     201{
     202  if( node == NULL || pInfo == NULL)
     203    return;
     204
     205  if( pInfo->isClient())
     206    node->removeClient(pInfo->userId);
     207  else if( pInfo->isProxyServerActive())
     208    node->removeActiveProxyServer(pInfo->userId);
     209  else if( pInfo->isMasterServer())
     210    node->removeMasterServer(pInfo->userId);
    175211}
    176212
     
    197233
    198234/**
     235 * @param userId of the searched node
     236 * @returns the PeerInfo of the userId peer
     237 */
     238PeerInfo* NetworkMonitor::getPeerByUserId( int userId)
     239{
     240  NetworkNode* node = this->getNodeByUserId(userId);
     241  if( node != NULL)
     242    return node->getPeerInfo();
     243
     244  return NULL;
     245}
     246
     247/**
     248 * searches for a given NetworkNode
     249 * @param userId of the searched node
     250 * @returns the PeerInfo of the userId peer
     251 */
     252NetworkNode* NetworkMonitor::getNodeByUserId( int userId)
     253{
     254  std::list<NetworkNode*>::iterator it = this->nodeList.begin();
     255  NetworkNode* node = NULL;
     256  for(; it != this->nodeList.end(); it++)
     257  {
     258    node = (*it)->getNodeByUserId(userId);
     259    if( node != NULL)
     260      return node;
     261  }
     262
     263  return NULL;
     264}
     265
     266
     267/**
    199268 * this displays the network monitor gui
    200269 */
     
    203272  if (this->box == NULL)
    204273  {
    205     this->box = new OrxGui::GLGuiBox(OrxGui::Vertical);
    206     {
    207       NetworkStatsWidget* netStats = new NetworkStatsWidget(this);
    208       this->box->pack(netStats);
    209 
    210     }
    211 
     274    this->box = new NetworkStatsWidget(this);
    212275    this->box->showAll();
    213     this->box->setAbsCoor2D(300, 40);
    214276  }
    215277  else
     
    251313  for(; it != this->nodeList.end(); it++)
    252314  {
    253     (*it)->debug(0);
     315    (*it)->debug(1);
    254316  }
    255317
  • trunk/src/lib/network/monitor/network_monitor.h

    r9494 r9656  
    4242
    4343    /** adds to @param node a network node @param pInfo a new client */
    44     inline void addClient(NetworkNode* node, PeerInfo* pInfo) { node->addClient(pInfo); }
     44    inline void addClient(NetworkNode* node, PeerInfo* pInfo) { node->addClient(new NetworkNode(pInfo)); }
    4545    /** adds to @param node a network node @param pInfo a new proxy server */
    46     inline void addActiveProxyServer(NetworkNode* node, PeerInfo* pInfo) { node->addActiveProxyServer(pInfo); }
     46    inline void addActiveProxyServer(NetworkNode* node, PeerInfo* pInfo) { node->addActiveProxyServer(new NetworkNode(pInfo)); }
    4747    /** adds to @param node a network node @param pInfo a new proxy server */
    48     inline void addPassiveProxyServer(NetworkNode* node, PeerInfo* pInfo) { node->addPassiveProxyServer(pInfo); }
     48    inline void addPassiveProxyServer(NetworkNode* node, PeerInfo* pInfo) { node->addPassiveProxyServer(new NetworkNode(pInfo)); }
    4949    /** adds to @param node a network node @param pInfo a new master server*/
    50     inline void addMasterServer(NetworkNode* node, PeerInfo* pInfo) { node->addMasterServer(pInfo); }
     50    inline void addMasterServer(NetworkNode* node, PeerInfo* pInfo) { node->addMasterServer(new NetworkNode(pInfo)); }
    5151
    52     inline void removeClient(NetworkNode* node, PeerInfo* pInfo) { node->removeClient(pInfo); }
    53     inline void removeActiveProxyServer(NetworkNode* node, PeerInfo* pInfo) { node->removeActiveProxyServer(pInfo); }
    54     inline void removePassiveProxyServer(NetworkNode* node, PeerInfo* pInfo) { node->removePassiveProxyServer(pInfo); }
    55     inline void removeMasterServer(NetworkNode* node, PeerInfo* pInfo) { node->removeMasterServer(pInfo); }
     52    void removeNode(PeerInfo* pInfo);
     53    void removeNode(NetworkNode* node, PeerInfo* pInfo);
     54
     55    inline void removeClient(NetworkNode* node, int userId) { node->removeClient(userId); }
     56    inline void removeActiveProxyServer(NetworkNode* node, int userId) { node->removeActiveProxyServer(userId); }
     57    inline void removePassiveProxyServer(NetworkNode* node, int userId) { node->removePassiveProxyServer(userId); }
     58    inline void removeMasterServer(NetworkNode* node, int userId) { node->removeMasterServer(userId); }
    5659
    5760    PeerInfo* getFirstChoiceProxy() const;
     
    6164
    6265    /** @returns the active proxy server list of the localnode */
    63     inline std::list<PeerInfo*> getActiveProxyServer() const { return this->localNode->getActiveProxyServer(); }
     66    inline std::list<NetworkNode*> getActiveProxyServers() const { return this->localNode->getActiveProxyServers(); }
    6467
    6568    /* slots admin and info interface */
     
    7679
    7780    inline const std::list<NetworkNode*>& getNodeList() const { return this->nodeList; };
     81    PeerInfo* getPeerByUserId( int userId);
     82    NetworkNode* getNodeByUserId( int userId);
     83
     84    /* forced reconnection interface */
     85    inline void setForcedReconnection(IP address) { this->bForcedRecon = true; this->forcedReconnection = address;}
     86    inline bool isForcedReconnection() const { return this->bForcedRecon; }
     87    inline IP getForcedReconnectionIP() { this->bForcedRecon = false; return this->forcedReconnection; }
     88
    7889
    7990    void toggleGUI();
     
    92103    int                          playerNumber;                 //!< total number of players in the game
    93104    int                          connectionNumber;             //!< total number of connections at this localhost
     105
     106    IP                           forcedReconnection;           //!< ip of a forced reconnection
     107    bool                         bForcedRecon;                 //!< true if there is a forced recon
    94108};
    95109
  • trunk/src/lib/network/monitor/network_node.cc

    r9494 r9656  
    1818#include "debug.h"
    1919
    20 
    2120/**
    2221 * constructor
     
    3938 * adds a client
    4039 */
    41 void NetworkNode::addClient(PeerInfo* node)
     40void NetworkNode::addClient(NetworkNode* node)
    4241{
    4342  this->clientList.push_back(node);
     
    4948 * adds a proxy server
    5049 */
    51 void NetworkNode::addActiveProxyServer(PeerInfo* node)
     50void NetworkNode::addActiveProxyServer(NetworkNode* node)
    5251{
    5352  this->activeProxyServerList.push_back(node);
     
    5857 * adds a proxy server
    5958 */
    60 void NetworkNode::addPassiveProxyServer(PeerInfo* node)
     59void NetworkNode::addPassiveProxyServer(NetworkNode* node)
    6160{
    6261  this->passiveProxyServerList.push_back(node);
     
    6665 * adds a master server
    6766 */
    68 void NetworkNode::addMasterServer(PeerInfo* node)
     67void NetworkNode::addMasterServer(NetworkNode* node)
    6968{
    7069  this->masterServerList.push_back(node);
     
    7574 * removes a client
    7675 */
    77 void NetworkNode::removeClient(PeerInfo* node)
    78 {
    79   std::list<PeerInfo*>::iterator it = this->clientList.begin();
     76void NetworkNode::removeClient(NetworkNode* node)
     77{
     78  std::list<NetworkNode*>::iterator it = this->clientList.begin();
    8079  for(; it != this->clientList.end(); it++)
    8180  {
     
    9493 * removes a proxy server
    9594 */
    96 void NetworkNode::removeActiveProxyServer(PeerInfo* node)
    97 {
    98   std::list<PeerInfo*>::iterator it = this->activeProxyServerList.begin();
     95void NetworkNode::removeActiveProxyServer(NetworkNode* node)
     96{
     97  std::list<NetworkNode*>::iterator it = this->activeProxyServerList.begin();
    9998  for(; it != this->activeProxyServerList.end(); it++)
    10099  {
     
    113112 * removes a proxy server
    114113 */
    115 void NetworkNode::removePassiveProxyServer(PeerInfo* node)
    116 {
    117   std::list<PeerInfo*>::iterator it = this->passiveProxyServerList.begin();
     114void NetworkNode::removePassiveProxyServer(NetworkNode* node)
     115{
     116  std::list<NetworkNode*>::iterator it = this->passiveProxyServerList.begin();
    118117  for(; it != this->passiveProxyServerList.end(); it++)
    119118  {
     
    131130 * removes a master server
    132131 */
    133 void NetworkNode::removeMasterServer(PeerInfo* node)
    134 {
    135   std::list<PeerInfo*>::iterator it = this->masterServerList.begin();
     132void NetworkNode::removeMasterServer(NetworkNode* node)
     133{
     134  std::list<NetworkNode*>::iterator it = this->masterServerList.begin();
    136135  for(; it != this->masterServerList.end(); it++)
    137136  {
     
    145144
    146145  PRINTF(2)("Could not remove client from the list, very strange...");
     146}
     147
     148
     149
     150
     151/**
     152 * removes a client
     153 */
     154void NetworkNode::removeClient(int userId)
     155{
     156  std::list<NetworkNode*>::iterator it = this->clientList.begin();
     157  for(; it != this->clientList.end(); it++)
     158  {
     159    if( (*it)->getPeerInfo()->userId == userId)
     160    {
     161      this->clientList.erase(it);
     162      this->playerNumber--;
     163      return;
     164    }
     165  }
     166
     167  PRINTF(2)("Could not remove client from the list, very strange...");
     168}
     169
     170/**
     171 * removes a proxy server
     172 */
     173void NetworkNode::removeActiveProxyServer(int userId)
     174{
     175  std::list<NetworkNode*>::iterator it = this->activeProxyServerList.begin();
     176  for(; it != this->activeProxyServerList.end(); it++)
     177  {
     178    if( (*it)->getPeerInfo()->userId == userId)
     179    {
     180      this->activeProxyServerList.erase(it);
     181      this->playerNumber--;
     182      return;
     183    }
     184  }
     185
     186  PRINTF(2)("Could not remove proxy server from the list, very strange...");
     187}
     188
     189/**
     190 * removes a proxy server
     191 */
     192void NetworkNode::removePassiveProxyServer(int userId)
     193{
     194  std::list<NetworkNode*>::iterator it = this->passiveProxyServerList.begin();
     195  for(; it != this->passiveProxyServerList.end(); it++)
     196  {
     197    if( (*it)->getPeerInfo()->userId == userId)
     198    {
     199      this->passiveProxyServerList.erase(it);
     200      return;
     201    }
     202  }
     203
     204  PRINTF(2)("Could not remove proxy server from the list, very strange...");
     205}
     206
     207/**
     208 * removes a master server
     209 */
     210void NetworkNode::removeMasterServer(int userId)
     211{
     212  std::list<NetworkNode*>::iterator it = this->masterServerList.begin();
     213  for(; it != this->masterServerList.end(); it++)
     214  {
     215    if( (*it)->getPeerInfo()->userId == userId)
     216    {
     217      this->masterServerList.erase(it);
     218      this->playerNumber--;
     219      return;
     220    }
     221  }
     222
     223  PRINTF(2)("Could not remove client from the list, very strange...");
     224}
     225
     226
     227
     228
     229
     230/**
     231 *  gets the peer info by user id
     232 * @param userId  the user id of the node to look up
     233 * @return the peer info of this node NULL if nothing found
     234 */
     235PeerInfo* NetworkNode::getPeerByUserId( int userId)
     236{
     237  // look through the master server lists
     238  std::list<NetworkNode*>::const_iterator it = this->masterServerList.begin();
     239  for( ;it != this->masterServerList.end(); it++)
     240  {
     241    if( (*it)->getPeerInfo()->userId == userId)
     242      return (*it)->getPeerInfo();
     243  }
     244
     245  // look through the active proxy server list
     246  it = this->activeProxyServerList.begin();
     247  for( ; it != this->activeProxyServerList.end(); it++)
     248  {
     249    if( (*it)->getPeerInfo()->userId == userId)
     250      return (*it)->getPeerInfo();
     251  }
     252
     253  // look through the passive server list
     254  it = this->passiveProxyServerList.begin();
     255  for( ; it != this->passiveProxyServerList.end(); it++)
     256  {
     257    if( (*it)->getPeerInfo()->userId == userId)
     258      return (*it)->getPeerInfo();
     259  }
     260
     261  // look through the client list
     262  it = this->clientList.begin();
     263  for( ; it != this->clientList.end(); it++)
     264  {
     265    if( (*it)->getPeerInfo()->userId == userId)
     266      return (*it)->getPeerInfo();
     267  }
     268
     269  return NULL;
    147270}
    148271
     
    154277PeerInfo* NetworkNode::getClient(int index) const
    155278{
    156   if( this->clientList.size() < index)
     279  if( (int)this->clientList.size() < index)
    157280    return NULL;
    158281
    159   std::list<PeerInfo*>::const_iterator it = this->clientList.begin();
     282  std::list<NetworkNode*>::const_iterator it = this->clientList.begin();
    160283  for(int i = 0; it != this->clientList.end(); it++, i++)
    161284  {
    162285  if( i == index)
    163     return (*it);
     286    return (*it)->getPeerInfo();
    164287  }
    165288
     
    174297PeerInfo* NetworkNode::getActiveProxyServer(int index) const
    175298{
    176   if( this->activeProxyServerList.size() < index)
     299  if( (int)this->activeProxyServerList.size() < index)
    177300    return NULL;
    178301
    179   std::list<PeerInfo*>::const_iterator it = this->activeProxyServerList.begin();
     302  std::list<NetworkNode*>::const_iterator it = this->activeProxyServerList.begin();
    180303  for(int i = 0; it != this->activeProxyServerList.end(); it++, i++)
    181304  {
    182305    if( i == index)
    183       return (*it);
     306      return (*it)->getPeerInfo();
    184307  }
    185308
     
    194317PeerInfo* NetworkNode::getPassiveProxyServer(int index) const
    195318{
    196   if( this->passiveProxyServerList.size() < index)
     319  if( (int)this->passiveProxyServerList.size() < index)
    197320    return NULL;
    198321
    199   std::list<PeerInfo*>::const_iterator it = this->passiveProxyServerList.begin();
     322  std::list<NetworkNode*>::const_iterator it = this->passiveProxyServerList.begin();
    200323  for(int i = 0; it != this->passiveProxyServerList.end(); it++, i++)
    201324  {
    202325    if( i == index)
    203       return (*it);
     326      return (*it)->getPeerInfo();
    204327  }
    205328
     
    214337PeerInfo* NetworkNode::getMasterServer(int index) const
    215338{
    216   if( this->masterServerList.size() < index)
     339  if( (int)this->masterServerList.size() < index)
    217340    return NULL;
    218341
    219   std::list<PeerInfo*>::const_iterator it = this->masterServerList.begin();
     342  std::list<NetworkNode*>::const_iterator it = this->masterServerList.begin();
    220343  for(int i = 0; it != this->masterServerList.end(); it++, i++)
    221344  {
    222345    if( i == index)
    223       return (*it);
     346      return (*it)->getPeerInfo();
     347  }
     348
     349  return NULL;
     350}
     351
     352
     353
     354/**
     355 * searches for a given NetworkNode
     356 * @param userId of the searched node
     357 * @returns the PeerInfo of the userId peer
     358 */
     359NetworkNode* NetworkNode::getNodeByUserId( int userId)
     360{
     361  if( this->peerInfo->userId == userId)
     362    return this;
     363
     364
     365  NetworkNode* node = NULL;
     366  std::list<NetworkNode*>::const_iterator it = this->masterServerList.begin();
     367
     368  for(; it != this->masterServerList.end(); it++)
     369  {
     370    node = (*it)->getNodeByUserId(userId);
     371    if( node != NULL)
     372      return node;
     373  }
     374
     375  it = this->activeProxyServerList.begin();
     376  for(; it != this->activeProxyServerList.end(); it++)
     377  {
     378    node = (*it)->getNodeByUserId(userId);
     379    if( node != NULL)
     380      return node;
     381  }
     382
     383  it = this->passiveProxyServerList.begin();
     384  for(; it != this->passiveProxyServerList.end(); it++)
     385  {
     386    node = (*it)->getNodeByUserId(userId);
     387    if( node != NULL)
     388      return node;
     389  }
     390
     391  it = this->clientList.begin();
     392  for(; it != this->clientList.end(); it++)
     393  {
     394    node = (*it)->getNodeByUserId(userId);
     395    if( node != NULL)
     396      return node;
    224397  }
    225398
     
    234407void NetworkNode::debug(int depth) const
    235408{
    236   PRINT(0)(" = %s\n", this->peerInfo->getNodeTypeString().c_str());
    237 
    238   PRINT(0)("    master servers: %i\n", this->masterServerList.size());
    239   std::list<PeerInfo*>::const_iterator it = this->masterServerList.begin();
    240   for(; it != this->masterServerList.end(); it++)
    241   {
    242     IP* ip = &(*it)->ip;
    243     PRINT(0)("     - ms, id: %i (%s)\n", (*it)->userId, ip->ipString().c_str());
    244   }
    245 
    246   PRINT(0)("    proxy servers active: %i\n", this->activeProxyServerList.size());
    247   it = this->activeProxyServerList.begin();
    248   for(; it != this->activeProxyServerList.end(); it++)
    249   {
    250     IP* ip = &(*it)->ip;
    251     PRINT(0)("     - ps-a, id: %i (%s)\n", (*it)->userId, ip->ipString().c_str());
    252   }
    253 
    254   PRINT(0)("    proxy servers passive: %i\n", this->passiveProxyServerList.size());
    255   it = this->passiveProxyServerList.begin();
    256   for(; it != this->passiveProxyServerList.end(); it++)
    257   {
    258     IP* ip = &(*it)->ip;
    259     PRINT(0)("     - ps-p, id: %i (%s)\n", (*it)->userId, ip->ipString().c_str());
    260   }
    261 
    262   PRINT(0)("    clients: %i\n", this->clientList.size());
    263   it = this->clientList.begin();
    264   for(; it != this->clientList.end(); it++)
    265   {
    266     IP* ip = &(*it)->ip;
    267     PRINT(0)("     - client, id: %i (%s)\n", (*it)->userId, ip->ipString().c_str());
    268   }
    269 }
    270 
     409  char indent[depth +1];
     410  for( int i = 0; i < depth; i++) {     indent[i] = ' ';  }
     411  indent[depth] = '\0';
     412
     413  PRINT(0)("%s + %s, with id %i and ip: %s\n", indent, this->peerInfo->getNodeTypeString().c_str(), this->peerInfo->userId, this->peerInfo->ip.ipString().c_str());
     414
     415
     416
     417  std::list<NetworkNode*>::const_iterator it;
     418  if( !this->masterServerList.empty())
     419  {
     420    it = this->masterServerList.begin();
     421
     422    for(; it != this->masterServerList.end(); it++)
     423    {
     424      (*it)->debug(depth+1);
     425    }
     426  }
     427
     428  if( !this->activeProxyServerList.empty())
     429  {
     430    it = this->activeProxyServerList.begin();
     431
     432    for(; it != this->activeProxyServerList.end(); it++)
     433    {
     434      (*it)->debug(depth+1);
     435    }
     436  }
     437
     438
     439  if( !this->passiveProxyServerList.empty())
     440  {
     441    it = this->passiveProxyServerList.begin();
     442
     443    for(; it != this->passiveProxyServerList.end(); it++)
     444    {
     445      (*it)->debug(depth+1);
     446    }
     447  }
     448
     449  if( !this->clientList.empty())
     450  {
     451    it = this->clientList.begin();
     452
     453    for(; it != this->clientList.end(); it++)
     454    {
     455      (*it)->debug(depth+1);
     456    }
     457  }
     458}
     459
  • trunk/src/lib/network/monitor/network_node.h

    r9494 r9656  
    1313#include <list>
    1414
    15 
    1615//!< a class representing a node in the network (this can be a MASTER_SERVER, PROXY_SERVER or a CLIENT
    1716class NetworkNode
     
    2221
    2322
    24     void addClient(PeerInfo* node);
    25     void addActiveProxyServer(PeerInfo* node);
    26     void addPassiveProxyServer(PeerInfo* node);
    27     void addMasterServer(PeerInfo* node);
     23    void addClient(NetworkNode* node);
     24    void addActiveProxyServer(NetworkNode* node);
     25    void addPassiveProxyServer(NetworkNode* node);
     26    void addMasterServer(NetworkNode* node);
    2827
    29     void removeClient(PeerInfo* node);
    30     void removeActiveProxyServer(PeerInfo* node);
    31     void removePassiveProxyServer(PeerInfo* node);
    32     void removeMasterServer(PeerInfo* node);
     28    void removeClient(NetworkNode* node);
     29    void removeActiveProxyServer(NetworkNode* node);
     30    void removePassiveProxyServer(NetworkNode* node);
     31    void removeMasterServer(NetworkNode* node);
     32
     33    void removeClient(int userId);
     34    void removeActiveProxyServer(int userId);
     35    void removePassiveProxyServer(int userId);
     36    void removeMasterServer(int userId);
     37
    3338
    3439    PeerInfo* getClient(int index) const;
     
    3843
    3944    /** @returns the master server list */
    40     inline std::list<PeerInfo*> getMasterServer() const { return this->masterServerList; }
     45    inline std::list<NetworkNode*> getMasterServers() const { return this->masterServerList; }
    4146    /** @returns the active proxy server list */
    42     inline std::list<PeerInfo*> getActiveProxyServer() const { return this->activeProxyServerList; }
     47    inline std::list<NetworkNode*> getActiveProxyServers() const { return this->activeProxyServerList; }
    4348    /** @returns the passive proxy server list */
    44     inline std::list<PeerInfo*> getPassiveProxyServer() const { return this->passiveProxyServerList; }
     49    inline std::list<NetworkNode*> getPassiveProxyServers() const { return this->passiveProxyServerList; }
    4550    /** @returns the client list */
    46     inline std::list<PeerInfo*> getClient() const { return this->clientList; }
     51    inline std::list<NetworkNode*> getClients() const { return this->clientList; }
    4752
     53    PeerInfo* getPeerByUserId( int userId);
    4854
    4955    /** @returns the number of players */
     
    5359    /** @returns the peer info of this node */
    5460    inline PeerInfo* getPeerInfo() const { return this->peerInfo; }
     61
     62    NetworkNode* getNodeByUserId( int userId);
    5563
    5664    void debug(int depth) const;
     
    6371
    6472    /* network nodes directly connected to this node */
    65     std::list<PeerInfo*>         clientList;                   //!< list of all clients in the network
    66     std::list<PeerInfo*>         activeProxyServerList;        //!< list of all proxy servers in the network
    67     std::list<PeerInfo*>         passiveProxyServerList;       //!< list of all proxy servers in the network
    68     std::list<PeerInfo*>         masterServerList;             //!< list of all master servers in the network (should be 1!! :D)
     73    std::list<NetworkNode*>         clientList;                   //!< list of all clients in the network
     74    std::list<NetworkNode*>         activeProxyServerList;        //!< list of all proxy servers in the network
     75    std::list<NetworkNode*>         passiveProxyServerList;       //!< list of all proxy servers in the network
     76    std::list<NetworkNode*>         masterServerList;             //!< list of all master servers in the network (should be 1!! :D)
    6977
    7078};
  • trunk/src/lib/network/monitor/network_stats_widget.cc

    r9494 r9656  
    1818#include "network_stats_widget.h"
    1919#include "network_monitor.h"
     20#include "peer_info.h"
    2021
    2122#include "multi_type.h"
     
    2324#include "shell_command.h"
    2425
    25 // SHELL_COMMAND(gui, NetworkMonitor, toggleGUI)
    26 //  ->setAlias("ProxyGui");
     26#include "loading/resource_manager.h"
     27
     28// this fcuk does not work!
     29// SHELL_COMMAND(gui, NetworkStatsWidget, toggleGUI)
     30// ->setAlias("ProxyGui");
    2731
    2832
     
    3034    : GLGuiBox(OrxGui::Horizontal)
    3135{
     36  this->init();
     37
    3238  this->setName(name);
    3339  this->setIP(ip);
    3440
     41}
     42
     43HostWidget::HostWidget(const PeerInfo* peerInfo)
     44    : GLGuiBox(OrxGui::Horizontal)
     45{
     46  this->init();
     47  if (peerInfo == NULL)
     48  {
     49    this->setName("INVALID");
     50    return;
     51  }
     52  this->setName(peerInfo->getNodeTypeString() + "ID: " + MultiType(peerInfo->userId).getString());
     53  this->setIP(peerInfo->ip);
     54}
     55
     56void HostWidget::init()
     57{
     58  if(_font == NULL)
     59    _font = new Font(ResourceManager::getInstance()->getDataDir() + "/fonts/arial.ttf", 20);
     60
     61  //this->_name.setFont(*_font);
     62  this->_name.setTextSize(15);
     63  //this->_ip.setFont(*_font);
     64  this->_ip.setTextSize(15);
     65
    3566  this->pack(&this->_name);
    3667  this->pack(&this->_ip);
     
    4980}
    5081
     82Font* HostWidget::_font = NULL;
     83
     84
    5185
    5286
     
    5488
    5589
    56 ProxyWidget::ProxyWidget(const std::string& proxyName, const IP& ip)
     90NodeWidget::NodeWidget(const std::string& proxyName, const IP& ip)
    5791    : _proxyWidget(proxyName, ip)
    5892{
    59   this->_clientNameWidth = 100.0f;
     93  this->_nodeNameWidth = 100.0f;
    6094  this->pack(&_proxyWidget);
    6195}
    6296
    63 void ProxyWidget::addClient(const std::string& name, const IP& ip)
     97NodeWidget::NodeWidget(const NetworkNode* node)
     98    : _proxyWidget(node->getPeerInfo())// "node", node->getPeerInfo()->ip)
     99{
     100  this->_nodeNameWidth = 100.0f;
     101  this->pack(&_proxyWidget);
     102
     103  std::list<NetworkNode*> list = node->getMasterServers();
     104  std::list<NetworkNode*>::const_iterator it;
     105
     106  for(it = list.begin(); it != list.end(); it++)
     107    this->addNode(*it);
     108
     109  list = node->getActiveProxyServers();
     110  for(it = list.begin(); it != list.end(); it++)
     111    this->addNode(*it);
     112
     113  list = node->getPassiveProxyServers();
     114  for(it = list.begin(); it != list.end(); it++)
     115    this->addNode(*it);
     116
     117  list = node->getClients();
     118  for(it = list.begin(); it != list.end(); it++)
     119    this->addNode(*it);
     120}
     121
     122
     123void NodeWidget::addNode(const NetworkNode* node)
     124{
     125  this->_nodes.push_back(new NodeWidget(node));
     126  this->pack(this->_nodes.back());
     127  this->_nodes.back()->show();
     128}
     129
     130
     131void NodeWidget::addNode(const std::string& name, const IP& ip)
    64132{
    65133  HostWidget* newClient = new HostWidget(name, ip);
    66   newClient->setNameWidth(this->_clientNameWidth);
     134  newClient->setNameWidth(this->_nodeNameWidth);
    67135
    68136  this->pack(newClient);
     
    72140}
    73141
    74 bool ProxyWidget::removeClient(const IP& ip)
    75 {
    76   std::vector<HostWidget*>::iterator rmIt;
    77   for(rmIt = this->_clients.begin(); rmIt != this->_clients.end(); ++rmIt)
    78   {
    79     if (*(*rmIt) == ip)
    80     {
    81       delete (*rmIt);
    82       this->_clients.erase(rmIt);
    83       return true;
    84     }
    85   }
    86   return false;
    87 }
    88 
    89 bool ProxyWidget::removeClient(const std::string& name)
    90 {
    91   std::vector<HostWidget*>::iterator rmIt;
    92   for(rmIt = this->_clients.begin(); rmIt != this->_clients.end(); ++rmIt)
    93   {
    94     if (*(*rmIt) == name)
    95     {
    96       delete (*rmIt);
    97       this->_clients.erase(rmIt);
    98       return true;
    99     }
    100   }
    101   return false;
    102 
    103 }
    104 
    105 bool ProxyWidget::removeClient(const std::string& name, const IP& ip)
    106 {
    107   std::vector<HostWidget*>::iterator rmIt;
    108   for(rmIt = this->_clients.begin(); rmIt != this->_clients.end(); ++rmIt)
    109   {
    110     if (*(*rmIt) == ip && *(*rmIt) == name)
    111     {
    112       delete (*rmIt);
    113       this->_clients.erase(rmIt);
    114       return true;
    115     }
    116   }
    117   return false;
    118 }
    119 
    120 
    121 void ProxyWidget::setClientNameWidths(float width)
    122 {
    123   this->_clientNameWidth = width;
    124   for (unsigned int i = 0; i < this->_clients.size(); ++i)
    125     this->_clients[i]->setNameWidth(width);
    126 }
    127 
    128 void ProxyWidget::hiding()
     142bool NodeWidget::removeNode(const IP& ip)
     143{
     144//   std::vector<HostWidget*>::iterator rmIt;
     145//   for(rmIt = this->_nodes.begin(); rmIt != this->_nodes.end(); ++rmIt)
     146//   {
     147//     if (*(*rmIt) == ip)
     148//     {
     149//       delete (*rmIt);
     150//       this->_nodes.erase(rmIt);
     151//       return true;
     152//     }
     153//   }
     154//   return false;
     155}
     156
     157bool NodeWidget::removeNode(const std::string& name)
     158{
     159//   std::vector<HostWidget*>::iterator rmIt;
     160//   for(rmIt = this->_nodes.begin(); rmIt != this->_nodes.end(); ++rmIt)
     161//   {
     162//     if (*(*rmIt) == name)
     163//     {
     164//       delete (*rmIt);
     165//       this->_nodes.erase(rmIt);
     166//       return true;
     167//     }
     168//   }
     169//   return false;
     170
     171}
     172
     173bool NodeWidget::removeNode(const std::string& name, const IP& ip)
     174{
     175//   std::vector<HostWidget*>::iterator rmIt;
     176//   for(rmIt = this->_nodes.begin(); rmIt != this->_nodes.end(); ++rmIt)
     177//   {
     178//     if (*(*rmIt) == ip && *(*rmIt) == name)
     179//     {
     180//       delete (*rmIt);
     181//       this->_nodes.erase(rmIt);
     182//       return true;
     183//     }
     184//   }
     185//   return false;
     186}
     187
     188
     189void NodeWidget::setNodeNameWidths(float width)
     190{
     191/*  this->_nodeNameWidth = width;
     192  for (unsigned int i = 0; i < this->_nodes.size(); ++i)
     193    this->_nodes[i]->setNameWidth(width);*/
     194}
     195
     196void NodeWidget::hiding()
    129197{
    130198  this->_proxyWidget.hide();
    131   for (unsigned int i = 0; i < this->_clients.size(); ++i)
    132     this->_clients[i]->hide();
    133 }
    134 
    135 void ProxyWidget::showing()
     199  for (unsigned int i = 0; i < this->_nodes.size(); ++i)
     200    this->_nodes[i]->hide();
     201}
     202
     203void NodeWidget::showing()
    136204{
    137205  this->_proxyWidget.show();
    138   for (unsigned int i = 0; i < this->_clients.size(); ++i)
    139     this->_clients[i]->show();
     206  for (unsigned int i = 0; i < this->_nodes.size(); ++i)
     207    this->_nodes[i]->show();
    140208}
    141209
     
    147215 */
    148216NetworkStatsWidget::NetworkStatsWidget(const NetworkMonitor* monitor)
    149     : GLGuiBox(OrxGui::Vertical), _thisHost("myName", IP(127, 0, 0 , 1))
     217    : OrxGui::GLGuiFixedpositionBox(OrxGui::Center, OrxGui::Vertical), _thisHost("myName", IP(127, 0, 0 , 1))
    150218{
    151219  this->_monitor = monitor;
     220  this->_passedTime = 0.0f;
    152221
    153222  /*
     
    169238  this->_bar.setChangedValueColor(Color::black);
    170239  */
     240  this->_thisHostIs.setText(std::string("I am ") + _monitor->getLocalNode()->getPeerInfo()->getNodeTypeString());
     241
     242  this->pack(&this->_thisHostIs);
     243
    171244  this->pack(&this->_thisHost);
     245
     246  this->pack(&this->_serverBox);
    172247
    173248  this->pack(&this->_upstreamText);
    174249  this->pack(&this->_downstreamText);
    175250
    176   this->pack(&this->_serverIP);
     251
     252  this->rebuild();
    177253}
    178254
     
    183259NetworkStatsWidget::~NetworkStatsWidget ()
    184260{}
     261
     262
     263void NetworkStatsWidget::addNode(const NetworkNode* node)
     264{
     265  this->_proxies.push_back(new NodeWidget(node));
     266  this->_serverBox.pack(this->_proxies.back());
     267  this->_proxies.back()->show();
     268}
     269
     270
     271
     272
     273NetworkStatsWidget* NetworkStatsWidget::_statsWidget = NULL;
     274
     275#include "class_list.h"
     276
     277void NetworkStatsWidget::toggleGUI()
     278{
     279  BaseObject* bo = NULL;
     280  const std::list<BaseObject*>* ls = ClassList::getList(CL_NETWORK_MONITOR);
     281  if (ls != NULL && !ls->empty())
     282    bo = ls->front();
     283
     284  if (bo != NULL && NetworkStatsWidget::_statsWidget == NULL)
     285  {
     286    NetworkStatsWidget::_statsWidget = new NetworkStatsWidget(dynamic_cast<NetworkMonitor*> (bo));
     287    NetworkStatsWidget::_statsWidget->showAll();
     288  }
     289  else
     290  {
     291    delete NetworkStatsWidget::_statsWidget;
     292    NetworkStatsWidget::_statsWidget = NULL;
     293  }
     294}
    185295
    186296
     
    204314
    205315
     316void NetworkStatsWidget::addProxy(const std::string& name, const IP& proxy)
     317{}
     318
     319void NetworkStatsWidget::clearProxies()
     320{}
     321
     322
     323void NetworkStatsWidget::rebuild()
     324{
     325  while (!this->_proxies.empty())
     326  {
     327    delete this->_proxies.back();
     328    this->_proxies.pop_back();
     329  }
     330
     331  const NetworkNode* node = this->_monitor->getLocalNode();
     332  if (node == NULL)
     333  {
     334    printf("NO NODE\n");
     335    return;
     336  }
     337
     338  this->addNode(node);
     339}
     340
     341
     342
    206343void NetworkStatsWidget::tick(float dt)
    207344{
     345
     346  if ((_passedTime+= dt) > 1.0f)
     347  {
     348    this->_passedTime = 0.0f;
     349    this->rebuild();
     350  }
     351
    208352  assert (this->_monitor->getLocalNode() != NULL);
    209353  assert(this->_monitor->getLocalNode()->getPeerInfo() != NULL);
     
    220364void NetworkStatsWidget::resize()
    221365{
    222   GLGuiBox::resize();
     366  GLGuiFixedpositionBox::resize();
    223367}
    224368
  • trunk/src/lib/network/monitor/network_stats_widget.h

    r9494 r9656  
    22 * @file network_stats_widget.h
    33 * @brief Definition of an EnergyWidget, that displays a bar and a Text
    4 */
     4 */
    55
    66#ifndef _NETWORK_STATS_WIDGET_H
    77#define _NETWORK_STATS_WIDGET_H
    88
    9 #include "glgui_box.h"
     9#include "glgui_fixedposition_box.h"
    1010#include "glgui_bar.h"
    1111#include "glgui_text.h"
     12#include "glgui_pushbutton.h"
    1213
    1314#include "network/ip.h"
    1415
    1516class NetworkMonitor;
    16 
     17class NetworkNode;
     18class PeerInfo;
    1719
    1820class HostWidget : public OrxGui::GLGuiBox
     
    2022  public:
    2123    HostWidget(const std::string& name, const IP& ip);
    22     ~HostWidget() {};
     24    HostWidget(const PeerInfo* peerInfo);
    2325
    2426    void setName(const std::string& name) { this->_name.setText(name); };
    25     void setIP(const IP& ip) { this->_ip.setText(ip.ipString()); this->_storedIP = ip; };
     27    void setIP(const IP& ip) { this->_ip.setText(std::string("at ") + ip.ipString()); this->_storedIP = ip; };
    2628
    2729    void setNameWidth(float width) { this->_name.setLineWidth(width); };
     
    3537
    3638  private:
     39    void init();
     40  private:
    3741    OrxGui::GLGuiText _name;           //!< The Name of the Proxy server to be displayed.
    3842    OrxGui::GLGuiText _ip;             //!< The IP of the proxy server.
    3943    IP                _storedIP;       //!< The ip to compare.
     44
     45    static Font*      _font;
    4046};
    4147
    4248
    43 class ProxyWidget : public OrxGui::GLGuiBox
     49class NodeWidget : public OrxGui::GLGuiBox
    4450{
    4551  public:
    46     ProxyWidget(const std::string& proxyName, const IP& ip);
     52    NodeWidget(const std::string& proxyName, const IP& ip);
     53    NodeWidget(const NetworkNode* node);
    4754
    48     void addClient(const std::string& name, const IP& ip);
     55    void addNode(const NetworkNode* node);
     56    void addNode(const std::string& name, const IP& ip);
    4957
    50     bool removeClient(const IP& ip);
    51     bool removeClient(const std::string& name);
    52     bool removeClient(const std::string& name, const IP& ip);
     58    bool removeNode(const IP& ip);
     59    bool removeNode(const std::string& name);
     60    bool removeNode(const std::string& name, const IP& ip);
    5361
    54     void setClientNameWidths(float width);
     62    void setNodeNameWidths(float width);
    5563
    5664
     
    6371    HostWidget                _proxyWidget;
    6472
    65     std::vector<HostWidget*>  _clients;
    66     float                     _clientNameWidth;
     73    std::vector<NodeWidget*>  _nodes;
     74    float                     _nodeNameWidth;
    6775};
    6876
     
    7179
    7280//! A class to display network Statistics.
    73 class NetworkStatsWidget : public OrxGui::GLGuiBox
     81class NetworkStatsWidget : public OrxGui::GLGuiFixedpositionBox
    7482{
    7583  public:
     84    static void toggleGUI();
     85
    7686    NetworkStatsWidget(const NetworkMonitor* monitor);
    7787    virtual ~NetworkStatsWidget();
     
    8494
    8595    void addProxy(const std::string& name, const IP& proxy);
     96    void addNode(const NetworkNode* node);
    8697
     98    void clearProxies();
     99
     100    void rebuild();
    87101
    88102    //void rebuildConnectedHosts(std::vector<hosts> hosts);
     
    101115    const NetworkMonitor*  _monitor;
    102116
     117    OrxGui::GLGuiText      _thisHostIs;
    103118    HostWidget             _thisHost;
    104119
     
    106121    OrxGui::GLGuiText      _downstreamText;
    107122
    108     std::vector<HostWidget*>_connectedProxies;
     123    OrxGui::GLGuiBox       _serverBox;
    109124
    110     OrxGui::GLGuiText       _serverIP;
     125    std::vector<NodeWidget*> _proxies;
    111126
    112127
     128    static NetworkStatsWidget*    _statsWidget;
     129
     130
     131    float                   _passedTime;
    113132    //OrxGui::GLGuiText       _valueText;
    114133    //OrxGui::GLGuiBar        _bar;
  • trunk/src/lib/network/nettypes.h

    r9494 r9656  
    1010  PERMISSION_MASTER_SERVER = 1,
    1111  PERMISSION_PROXY_SERVER  = 2,
    12   PERMISSION_OWNER         = 4,
    13   PERMISSION_ALL           = 8
     12  PERMISSION_SERVER        = 4,
     13  PERMISSION_OWNER         = 8,
     14  PERMISSION_ALL           = 16
    1415};
    1516
  • trunk/src/lib/network/network_game_manager.cc

    r9494 r9656  
    6868
    6969  this->gameState = 0;
    70   registerVar( new SynchronizeableInt( &gameState, &gameState, "gameState" ) );
     70  registerVar( new SynchronizeableInt( &gameState, &gameState, "gameState", PERMISSION_MASTER_SERVER ) );
    7171}
    7272
     
    9191bool NetworkGameManager::signalNewPlayer( int userId )
    9292{
    93   assert( SharedNetworkData::getInstance()->isMasterServer() ||  SharedNetworkData::getInstance()->isProxyServerActive());
     93  assert( SharedNetworkData::getInstance()->isMasterServer());
    9494  assert( State::getGameRules() );
    9595  assert( State::getGameRules()->isA( CL_NETWORK_GAME_RULES ) );
     
    9797  NetworkGameRules & rules = *(dynamic_cast<NetworkGameRules*>(State::getGameRules()));
    9898
    99   int team = rules.getTeamForNewUser();
    100   ClassID playableClassId = rules.getPlayableClassId( userId, team );
    101   std::string playableModel = rules.getPlayableModelFileName( userId, team, playableClassId );
    102   std::string playableTexture = rules.getPlayableModelFileName( userId, team, playableClassId );
    103   float       playableScale = rules.getPlayableScale( userId, team, playableClassId );
     99  int          team = rules.getTeamForNewUser();
     100  ClassID      playableClassId = rules.getPlayableClassId( userId, team );
     101  std::string  playableModel = rules.getPlayableModelFileName( userId, team, playableClassId );
     102  std::string  playableTexture = rules.getPlayableModelFileName( userId, team, playableClassId );
     103  float        playableScale = rules.getPlayableScale( userId, team, playableClassId );
    104104
    105105  BaseObject * bo = Factory::fabricate( playableClassId );
     
    111111
    112112  playable.loadMD2Texture( playableTexture );
    113 
     113  playable.setTeam(team);
    114114  playable.loadModel( playableModel, 100.0f );
    115115  playable.setOwner( userId );
     
    159159/**
    160160 * handler for remove synchronizeable messages
    161  * @param messageId
     161 * @param messageType
    162162 * @param data
    163163 * @param dataLength
     
    166166 * @return true on successfull handling else handler will be called again
    167167 */
    168 bool NetworkGameManager::delSynchronizeableHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId )
     168bool NetworkGameManager::delSynchronizeableHandler( MessageType messageType, byte * data, int dataLength, void * someData, int senderId, int destinationId )
    169169{
    170170
     
    172172
    173173  if ( SharedNetworkData::getInstance()->isMasterServer() ||
    174        SharedNetworkData::getInstance()->isProxyServerActive() && SharedNetworkData::getInstance()->isUserClient(userId))
    175   {
    176     PRINTF(0)("Recieved DeleteSynchronizeable message from client %d!\n", userId);
     174       SharedNetworkData::getInstance()->isProxyServerActive() && SharedNetworkData::getInstance()->isUserClient(senderId))
     175  {
     176    PRINTF(0)("Recieved DeleteSynchronizeable message from client %d!\n", senderId);
    177177    return true;
    178178  }
     
    183183  if ( len != dataLength )
    184184  {
    185     PRINTF(2)("Recieved DeleteSynchronizeable message with incorrect size (%d) from client %d!\n", dataLength, userId);
     185    PRINTF(2)("Recieved DeleteSynchronizeable message with incorrect size (%d) from client %d!\n", dataLength, senderId);
    186186    return true;
    187187  }
     
    217217  assert( Converter::intToByteArray( uniqueId, buf, INTSIZE ) == INTSIZE );
    218218
    219   MessageManager::getInstance()->sendMessage( MSGID_DELETESYNCHRONIZEABLE, buf, INTSIZE, RT_ALL_BUT_ME, 0, MP_HIGHBANDWIDTH );
     219  MessageManager::getInstance()->sendMessage( MSGID_DELETESYNCHRONIZEABLE, buf, INTSIZE, RT_ALL_BUT_ME, NET_UNASSIGNED, MP_HIGHBANDWIDTH );
    220220}
    221221
     
    224224/**
    225225 * handler for MSGID_PREFEREDTEAM message
    226  * @param messageId
     226 * @param messageType
    227227 * @param data
    228228 * @param dataLength
     
    231231 * @return
    232232 */
    233 bool NetworkGameManager::preferedTeamHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId )
    234 {
    235   assert( SharedNetworkData::getInstance()->isMasterServer() ||  SharedNetworkData::getInstance()->isProxyServerActive());
     233bool NetworkGameManager::preferedTeamHandler( MessageType messageType, byte * data, int dataLength, void * someData, int senderId, int destinationId )
     234{
     235  assert( SharedNetworkData::getInstance()->isMasterServer() );
    236236
    237237  int teamId = 0;
     
    240240  if ( len != dataLength )
    241241  {
    242     PRINTF(2)("Recieved DeleteSynchronizeable message with incorrect size (%d) from client %d!\n", dataLength, userId);
     242    PRINTF(2)("Recieved DeleteSynchronizeable message with incorrect size (%d) from client %d!\n", dataLength, senderId);
    243243    return true;
    244244  }
    245245
    246   NetworkGameManager::getInstance()->setPreferedTeam( userId, teamId );
    247 
    248   return true;
    249 }
    250 
     246  PRINTF(0)("Client %i wishes to play in team %i\n", senderId, teamId);
     247  NetworkGameManager::getInstance()->setPreferedTeam( senderId, teamId );
     248
     249  return true;
     250}
     251
     252
     253/**
     254 * this actualy sets the new prefered team id
     255 * @param userId: the user that changes team
     256 * @param teamId: the new team id for the user
     257 */
    251258void NetworkGameManager::setPreferedTeam( int userId, int teamId )
    252259{
     
    259266}
    260267
     268
    261269/**
    262270 * set prefered team for this host
     
    265273void NetworkGameManager::prefereTeam( int teamId )
    266274{
    267   if ( SharedNetworkData::getInstance()->isMasterServer() /*|| SharedNetworkData::getInstance()->isProxyServerActive()*/)
    268     setPreferedTeam( SharedNetworkData::getInstance()->getHostID(), teamId );
     275  if ( SharedNetworkData::getInstance()->isMasterServer() )
     276    this->setPreferedTeam( SharedNetworkData::getInstance()->getHostID(), teamId );
    269277  else
    270278  {
     
    273281    assert( Converter::intToByteArray( teamId, buf, INTSIZE) == INTSIZE );
    274282
    275     MessageManager::getInstance()->sendMessage( MSGID_PREFEREDTEAM, buf, INTSIZE, RT_USER, 0, MP_HIGHBANDWIDTH );
     283    // send this message to the master server
     284    MessageManager::getInstance()->sendMessage( MSGID_PREFEREDTEAM, buf, INTSIZE, RT_USER, NET_ID_MASTER_SERVER, MP_HIGHBANDWIDTH );
    276285  }
    277286}
     
    306315
    307316
    308 bool NetworkGameManager::chatMessageHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId )
    309 {
    310   PRINTF(0)("NetworkGameManager::chatMessageHandler %d %d\n", userId, SharedNetworkData::getInstance()->getHostID() );
    311   if ( (SharedNetworkData::getInstance()->isMasterServer() /*|| SharedNetworkData::getInstance()->isProxyServerActive()*/) && userId !=  SharedNetworkData::getInstance()->getHostID() )
    312   {
    313     MessageManager::getInstance()->sendMessage( messageId, data, dataLength, RT_ALL_BUT_ME, 0, MP_HIGHBANDWIDTH );
     317bool NetworkGameManager::chatMessageHandler( MessageType messageType, byte * data, int dataLength, void * someData, int senderId, int destinationId )
     318{
     319  PRINTF(0)("NetworkGameManager::chatMessageHandler %d %d\n", senderId, SharedNetworkData::getInstance()->getHostID() );
     320  if ( (SharedNetworkData::getInstance()->isMasterServer() /*|| SharedNetworkData::getInstance()->isProxyServerActive()*/) && senderId !=  SharedNetworkData::getInstance()->getHostID() )
     321  {
     322    MessageManager::getInstance()->sendMessage( messageType, data, dataLength, RT_ALL_BUT_ME, NET_UNASSIGNED, MP_HIGHBANDWIDTH );
    314323  }
    315324
     
    321330  if ( dataLength < 3*INTSIZE )
    322331  {
    323     PRINTF(2)("got too small chatmessage from client %d\n", userId);
     332    PRINTF(2)("got too small chatmessage from client %d\n", senderId);
    324333
    325334    return true;
    326335  }
    327336
    328   int messageType = 0;
    329   Converter::byteArrayToInt( data, &messageType );
     337  int chatType = 0;
     338  Converter::byteArrayToInt( data, &chatType);
    330339  int senderUserId = 0;
    331340  Converter::byteArrayToInt( data+INTSIZE, &senderUserId );
     
    333342  Converter::byteArrayToString( data+2*INTSIZE, message, dataLength-2*INTSIZE );
    334343
    335   rules.handleChatMessage( senderUserId, message, messageType );
     344  rules.handleChatMessage( senderUserId, message, chatType);
    336345
    337346  return true;
     
    352361
    353362  if ( SharedNetworkData::getInstance()->isMasterServer() /*|| SharedNetworkData::getInstance()->isProxyServerActive()*/)
    354     MessageManager::getInstance()->sendMessage( MSGID_CHATMESSAGE, buf, message.length()+3*INTSIZE, RT_ALL_ME, 0, MP_HIGHBANDWIDTH );
     363    MessageManager::getInstance()->sendMessage( MSGID_CHATMESSAGE, buf, message.length()+3*INTSIZE, RT_ALL_ME, NET_UNASSIGNED, MP_HIGHBANDWIDTH );
    355364  else
    356     MessageManager::getInstance()->sendMessage( MSGID_CHATMESSAGE, buf, message.length()+3*INTSIZE, RT_ALL_BUT_ME, 0, MP_HIGHBANDWIDTH );
     365    MessageManager::getInstance()->sendMessage( MSGID_CHATMESSAGE, buf, message.length()+3*INTSIZE, RT_ALL_BUT_ME, NET_UNASSIGNED, MP_HIGHBANDWIDTH );
    357366
    358367
  • trunk/src/lib/network/network_game_manager.h

    r9406 r9656  
    1919class PNode;
    2020
    21 typedef enum NetworkGameManagerProtocol {
    22   NET_CREATE_ENTITY = 0,
    23   NET_REMOVE_ENTITY,
    24   NET_CREATE_ENTITY_LIST,
    25   NET_REMOVE_ENTITY_LIST,
    26   NET_REQUEST_CREATE,
    27   NET_REQUEST_REMOVE,
    28   NET_YOU_ARE_ENTITY,
    29   NET_REQUEST_ENTITY_LIST,
    3021
    31   NET_NUMBER
    32 };
    3322
    3423struct clientBuffer
     
    7059    NetworkGameManager();
    7160
    72     static bool delSynchronizeableHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId );
    73     static bool preferedTeamHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId );
    74     static bool chatMessageHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId );
     61    static bool delSynchronizeableHandler( MessageType messageType, byte * data, int dataLength, void * someData, int senderId, int destinationId );
     62    static bool preferedTeamHandler( MessageType messageType, byte * data, int dataLength, void * someData, int senderId, int destinationId );
     63    static bool chatMessageHandler( MessageType messageType, byte * data, int dataLength, void * someData, int senderId, int destinationId );
    7564
    7665    void setPreferedTeam( int userId, int teamId );
  • trunk/src/lib/network/network_manager.cc

    r9494 r9656  
    3131#include "network_log.h"
    3232#include "network_game_manager.h"
     33#include "proxy/proxy_control.h"
    3334
    3435
     
    3738
    3839SHELL_COMMAND(debug, NetworkManager, debug);
     40SHELL_COMMAND(redirTest, NetworkManager, setRedirectionTest);
     41
    3942
    4043
     
    111114  // create the network stream
    112115  this->networkStream = new NetworkStream(NET_MASTER_SERVER);
    113   this->networkStream->createServer( port, port + 1);
     116  this->networkStream->createServer( port, port + 1, port + 2);
    114117
    115118  // start the network game manager
    116119  this->networkStream->createNetworkGameManager();
     120
     121  // init the proxy control center
     122  ProxyControl::getInstance();
    117123
    118124  PRINTF(0)("Created Network Master Server\n");
     
    138144
    139145  // then start the server
    140   this->networkStream->createServer( port, port +1);
    141 
     146  this->networkStream->createServer( port, port + 1, port + 2);
    142147
    143148  // and to the other proxy servers also, this would be very nice if its works
    144 
    145 
    146   // start the network game manager
    147   //this->networkStream->createNetworkGameManager();
    148 
     149  /* put it here....*/
     150
     151  // init the proxy control center
     152  ProxyControl::getInstance();
    149153
    150154  PRINTF(0)("Created Network Proxy Server\n");
     
    168172  this->networkStream->connectToMasterServer( name, port);
    169173
     174
    170175  // and start the handshake
    171176  this->networkStream->startHandshake();
     177  // create the proxy control
     178  ProxyControl::getInstance();
    172179
    173180  PRINTF(0)("Created Network Client\n");
    174181  return 1;
     182}
     183
     184
     185/**
     186 * reconnects this client to another server
     187 * @param address new server address
     188 */
     189void NetworkManager::reconnectToServer(IP address)
     190{
     191  PRINTF(0)("Rec. reconnection command\n");
     192  this->networkStream->reconnectToServer(address);
    175193}
    176194
     
    216234  PRINT(0)("===========================================\n");
    217235}
     236
     237
     238void NetworkManager::setRedirectionTest()
     239{
     240  this->networkStream->setRedirectionTest();
     241}
     242
  • trunk/src/lib/network/network_manager.h

    r9494 r9656  
    3939    int createProxyServer( unsigned int port);
    4040
     41    void reconnectToServer(IP address);
     42
    4143    void connectSynchronizeable(Synchronizeable& sync);
    4244    void synchronize(float dtS);
    4345
    4446    void debug();
     47
     48    void setRedirectionTest();
     49
    4550
    4651
  • trunk/src/lib/network/network_stream.cc

    r9494 r9656  
    1111### File Specific:
    1212   main-programmer: Christoph Renner rennerc@ee.ethz.ch
    13    co-programmer:   Patrick Boenzli  boenzlip@orxonox.ethz.ch
     13   co-programmer:   Patrick Boenzli  patrick@orxonox.ethz.ch
    1414
    1515     June 2006: finishing work on the network stream for pps presentation (rennerc@ee.ethz.ch)
    16      July 2006: some code rearangement and integration of the proxy server mechanism (boenzlip@ee.ethz.ch)
     16     July 2006: some code rearangement and integration of the proxy server mechanism (patrick@orxonox.ethz.ch)
    1717*/
    1818
     
    2020#define DEBUG_MODULE_NETWORK
    2121
     22#include "proxy/proxy_control.h"
    2223
    2324#include "base_object.h"
     
    8081      // init the shared network data
    8182      SharedNetworkData::getInstance()->setHostID(NET_ID_MASTER_SERVER);
     83      this->pInfo->userId = NET_ID_MASTER_SERVER;
     84      this->pInfo->nodeType = NET_MASTER_SERVER;
     85
    8286      break;
    8387    case NET_PROXY_SERVER_ACTIVE:
    8488      // init the shared network data
    8589      SharedNetworkData::getInstance()->setHostID(NET_ID_PROXY_SERVER_01);
     90      this->pInfo->nodeType = NET_PROXY_SERVER_ACTIVE;
     91
    8692      break;
    8793    case NET_PROXY_SERVER_PASSIVE:
    8894      // init the shared network data
    8995      SharedNetworkData::getInstance()->setHostID(NET_ID_PROXY_SERVER_01);
     96      this->pInfo->nodeType = NET_PROXY_SERVER_PASSIVE;
     97
    9098      break;
    9199    case NET_CLIENT:
    92100      SharedNetworkData::getInstance()->setHostID(NET_ID_UNASSIGNED);
     101      this->pInfo->nodeType = NET_CLIENT;
    93102      break;
    94103  }
     
    97106
    98107  // get the local ip address
    99   IPaddress ip;
    100   SDLNet_ResolveHost( &ip, NULL, 0);
     108  IP ip("localhost", 0);
    101109  this->pInfo->ip = ip;
    102110}
     
    112120  this->setClassID(CL_NETWORK_STREAM, "NetworkStream");
    113121  this->clientSocket = NULL;
     122  this->clientSoftSocket = NULL;
    114123  this->proxySocket = NULL;
    115124  this->networkGameManager = NULL;
     
    117126
    118127  this->pInfo = new PeerInfo();
    119   this->pInfo->userId = 0;
     128  this->pInfo->userId = NET_UID_UNASSIGNED;
    120129  this->pInfo->lastAckedState = 0;
    121130  this->pInfo->lastRecvedState = 0;
     131  this->pInfo->bLocal = true;
    122132
    123133  this->bRedirect = false;
    124134
    125135  this->currentState = 0;
     136  this->redirectionUID = NET_ID_MASTER_SERVER;
    126137
    127138  remainingBytesToWriteToDict = Preferences::getInstance()->getInt( "compression", "writedict", 0 );
     
    142153  if ( this->clientSocket )
    143154  {
    144     clientSocket->close();
    145     delete clientSocket;
    146     clientSocket = NULL;
     155    this->clientSocket->close();
     156    delete this->clientSocket;
     157    this->clientSocket = NULL;
     158  }
     159  if ( this->clientSoftSocket )
     160  {
     161    this->clientSoftSocket->close();
     162    delete this->clientSoftSocket;
     163    this->clientSoftSocket = NULL;
    147164  }
    148165  if ( this->proxySocket)
     
    199216  this->peers[node].connectionMonitor = new ConnectionMonitor( NET_ID_MASTER_SERVER );
    200217  this->peers[node].ip = this->peers[node].socket->getRemoteAddress();
     218  this->peers[node].bLocal = true;
    201219}
    202220
     
    218236  this->peers[proxyId].connectionMonitor = new ConnectionMonitor( proxyId );
    219237  this->peers[proxyId].ip = this->peers[proxyId].socket->getRemoteAddress();
     238  this->peers[proxyId].bLocal = true;
    220239}
    221240
     
    225244 * @param port: interface port for all clients
    226245 */
    227 void NetworkStream::createServer(int clientPort, int proxyPort)
     246void NetworkStream::createServer(int clientPort, int proxyPort, int clientSoftPort)
    228247{
    229248  PRINTF(0)(" Creating new Server: listening for clients on port %i and for proxies on port %i", clientPort, proxyPort);
    230249  this->clientSocket= new UdpServerSocket(clientPort);
     250  this->clientSoftSocket= new UdpServerSocket(clientSoftPort);
    231251  this->proxySocket = new UdpServerSocket(proxyPort);
    232252}
     
    255275  Handshake* hs = new Handshake(this->pInfo->nodeType);
    256276  // fake the unique id
    257   hs->setUniqueID( NET_UID_HANDSHAKE );
    258   assert( peers[userId].handshake == NULL );
    259   peers[userId].handshake = hs;
     277  hs->setUniqueID( userId);
     278  assert( this->peers[userId].handshake == NULL );
     279  this->peers[userId].handshake = hs;
     280  this->peers[userId].bLocal = true;
    260281
    261282  // set the preferred nick name
     
    301322  // create the network monitor after all the init work and before there is any connection handlings
    302323  if( this->networkMonitor == NULL)
     324  {
    303325    this->networkMonitor = new NetworkMonitor(this);
     326    SharedNetworkData::getInstance()->setNetworkMonitor( this->networkMonitor);
     327  }
    304328
    305329
     
    318342    if ( this->clientSocket )
    319343      this->clientSocket->update();
     344    if ( this->clientSoftSocket)
     345      this->clientSoftSocket->update();
    320346    if( this->proxySocket)
    321347      this->proxySocket->update();
     
    328354    if ( this->clientSocket )
    329355      this->clientSocket->update();
     356    if ( this->clientSoftSocket)
     357      this->clientSoftSocket->update();
    330358    if( this->proxySocket)
    331359      this->proxySocket->update();
     
    348376    if( this->bRedirect)
    349377    {
    350       this->handleReconnect( NET_ID_MASTER_SERVER);
     378      this->handleReconnect( this->redirectionUID);
    351379    }
    352380  }
     
    362390  this->handleDownstream( tick );
    363391  this->handleUpstream( tick );
     392
     393  // process the local data of the message manager
     394  MessageManager::getInstance()->processData();
     395
     396  if( this->bSoftRedirect)
     397    this->softReconnectToServer(0, IP("localhost", 10001));
    364398}
    365399
     
    385419    if ( tempNetworkSocket )
    386420    {
    387       // determine the network node id
    388       if ( freeSocketSlots.size() > 0 )
     421      // get a userId
     422//       if ( freeSocketSlots.size() > 0 )
     423//       {
     424//         // this should never be called
     425//         userId = freeSocketSlots.back();
     426//         freeSocketSlots.pop_back();
     427//       }
     428//       else
    389429      {
    390         userId = freeSocketSlots.back();
    391         freeSocketSlots.pop_back();
    392       }
    393       else
    394       {
    395         userId = 1;
     430        // each server (proxy and master) have an address space for new network nodes of 1000 nodes
     431        // the first NET_ID_PROXY_MAX are always reserved for proxy servers
     432        userId = SharedNetworkData::getInstance()->getHostID() * 1000 + NET_ID_PROXY_MAX + 1;
    396433
    397434        for ( PeerList::iterator it = peers.begin(); it != peers.end(); it++ )
    398435          if ( it->first >= userId )
    399436            userId = it->first + 1;
     437
     438        // make sure that this server only uses an address space of 1000
     439        assert( userId < (SharedNetworkData::getInstance()->getHostID() + 1) * 1000);
    400440      }
    401441      // this creates a new entry in the peers list
     
    410450  }
    411451
     452  if( this->clientSoftSocket != NULL)
     453  {
     454    tempNetworkSocket = this->clientSoftSocket->getNewSocket();
     455
     456    // we got new NET_CLIENT connecting
     457    if ( tempNetworkSocket )
     458    {
     459
     460      // this creates a new entry in the peers list
     461      peers[userId].socket = tempNetworkSocket;
     462      peers[userId].nodeType = NET_CLIENT;
     463
     464      // handle the newly connected client
     465      this->handleSoftConnect(userId);
     466
     467      PRINTF(0)("New Client softly connected: %d :D\n", userId);
     468    }
     469  }
     470
    412471
    413472  if( this->proxySocket != NULL)
     
    419478    {
    420479      // determine the network node id
    421       if ( freeSocketSlots.size() > 0 )
    422       {
    423         userId = freeSocketSlots.back();
    424         freeSocketSlots.pop_back();
    425       }
    426       else
     480//       if ( freeSocketSlots.size() > 0 )
     481//       {
     482//         userId = freeSocketSlots.back();
     483//         freeSocketSlots.pop_back();
     484//       }
     485//       else
    427486      {
    428487        userId = 1;
    429488
    430         for ( PeerList::iterator it = peers.begin(); it != peers.end(); it++ )
    431           if ( it->first >= userId )
    432             userId = it->first + 1;
     489        // find an empty slot within the range
     490        for( int i = 0; i < NET_ID_PROXY_MAX; i++)
     491        {
     492          if( this->peers.find( i) == this->peers.end())
     493          {
     494            userId = i;
     495            break;
     496          }
     497        }
     498
     499//         for ( PeerList::iterator it = peers.begin(); it != peers.end(); it++ )
     500//           if ( it->first >= userId )
     501//             userId = it->first + 1;
    433502      }
    434503
     
    443512    }
    444513  }
     514
    445515
    446516
     
    461531      PRINTF(0)("Client is gone: %d (%s)\n", it->second.userId, reason.c_str());
    462532
     533
    463534      this->handleDisconnect( it->second.userId);
     535
     536      if( SharedNetworkData::getInstance()->isProxyServerActive())
     537        ProxyControl::getInstance()->signalLeaveClient(it->second.userId);
    464538
    465539      it++;
     
    469543    it++;
    470544  }
    471 
    472 
    473545}
    474546
     
    481553{
    482554  // create new handshake and init its variables
    483   peers[userId].handshake = new Handshake(this->pInfo->nodeType, userId, this->networkGameManager->getUniqueID(), MessageManager::getInstance()->getUniqueID());
    484   peers[userId].handshake->setUniqueID(userId);
    485 
    486   peers[userId].connectionMonitor = new ConnectionMonitor( userId );
    487   peers[userId].userId = userId;
     555  this->peers[userId].handshake = new Handshake(this->pInfo->nodeType, userId, this->networkGameManager->getUniqueID(), MessageManager::getInstance()->getUniqueID());
     556  this->peers[userId].handshake->setUniqueID(userId);
     557
     558  this->peers[userId].connectionMonitor = new ConnectionMonitor( userId );
     559  this->peers[userId].userId = userId;
     560  this->peers[userId].bLocal = true;
    488561
    489562  PRINTF(0)("num sync: %d\n", synchronizeables.size());
     
    494567  if( pi != NULL)
    495568  {
    496     peers[userId].handshake->setProxy1Address( pi->ip);
     569    this->peers[userId].handshake->setProxy1Address( pi->ip);
    497570  }
    498571  pi = this->networkMonitor->getSecondChoiceProxy();
    499572  if( pi != NULL)
    500     peers[userId].handshake->setProxy2Address( pi->ip);
     573    this->peers[userId].handshake->setProxy2Address( pi->ip);
    501574
    502575  // check if the connecting client should reconnect to a proxy server
    503576  if( SharedNetworkData::getInstance()->isMasterServer())
    504     peers[userId].handshake->setRedirect(/*this->networkMonitor->isReconnectNextClient()*/false);
     577  {
     578    if( this->networkMonitor->isReconnectNextClient())
     579    {
     580      this->peers[userId].handshake->setRedirect(true);
     581      PRINTF(0)("forwarding client to proxy server because this server is saturated\n");
     582    }
     583  }
    505584
    506585  // the connecting node of course is a client
    507   peers[userId].ip = peers[userId].socket->getRemoteAddress();
    508 }
     586  this->peers[userId].ip = this->peers[userId].socket->getRemoteAddress();
     587}
     588
     589
     590/**
     591 * this handles new soft connections
     592 * @param userId: the id of the new user node
     593 *
     594 * soft connections are connections from clients that are already in the network and don't need a new handshake etc.
     595 * the state of all entitites owned by userId are not deleted and stay
     596 * soft connections can not be redirected therefore they are negotiated between the to parties
     597 */
     598void NetworkStream::handleSoftConnect( int userId)
     599{
     600  // create new handshake and init its variables
     601  this->peers[userId].handshake = NULL;
     602  this->peers[userId].handshake->setUniqueID(userId);
     603
     604  this->peers[userId].connectionMonitor = new ConnectionMonitor( userId );
     605  this->peers[userId].userId = userId;
     606  this->peers[userId].bLocal = true;
     607
     608  PRINTF(0)("num sync: %d\n", synchronizeables.size());
     609
     610  // the connecting node of course is a client
     611  this->peers[userId].ip = this->peers[userId].socket->getRemoteAddress();
     612}
     613
    509614
    510615
     
    524629    PRINT(0)(" Host ist Client with ID: %i\n", this->pInfo->userId);
    525630  }
     631
     632  PRINT(0)(" Current number of connections is: %i\n", this->peers.size());
     633  for ( PeerList::iterator it = peers.begin(); it != peers.end(); it++ )
     634  {
     635    PRINT(0)("  peers[%i] with uniqueId %i and address: %s\n", it->first, it->second.userId, it->second.ip.ipString().c_str());
     636  }
     637  PRINT(0)("\n\n");
     638
    526639
    527640  PRINT(0)(" Got %i connected Synchronizeables, showing active Syncs:\n", this->synchronizeables.size());
     
    576689            // - client       <==> master server
    577690            // - proxy server <==> master server
    578             if(  SharedNetworkData::getInstance()->isClient() || SharedNetworkData::getInstance()->isProxyServerActive() && it->second.isMasterServer())
     691            if(  SharedNetworkData::getInstance()->isClient() ||
     692                 SharedNetworkData::getInstance()->isProxyServerActive() &&
     693                 SharedNetworkData::getInstance()->isUserMasterServer(it->second.userId))
    579694            {
    580               PRINTF(0)("Handshake: i am in client role\n");
     695              PRINTF(4)("Handshake: i am in client role\n");
    581696
    582697              SharedNetworkData::getInstance()->setHostID( it->second.handshake->getHostId() );
    583698              this->pInfo->userId = SharedNetworkData::getInstance()->getHostID();
    584699
    585 #warning the ip address is not set here because it results in a segfault when connecting to a proxy server => trace this later
    586700//               it->second.ip = it->second.socket->getRemoteAddress();
    587701
    588               // it->second.nodeType = it->second.handshake->getRemoteNodeType();
     702              it->second.nodeType = it->second.handshake->getRemoteNodeType();
    589703              // it->second.ip = it->second.socket->getRemoteAddress();
    590704              // add the new server to the nodes list (it can be a NET_MASTER_SERVER or NET_PROXY_SERVER)
     
    633747              else if ( SharedNetworkData::getInstance()->isProxyServerActive() && it->second.isClient() )
    634748              {
    635                 PRINTF(0)("Handshake: i am in server role\n");
     749                PRINTF(4)("Handshake: Proxy in server role: connecting %i\n", it->second.userId);
    636750
    637751                it->second.ip = it->second.socket->getRemoteAddress();
     
    639753                this->networkMonitor->addNode(&it->second);
    640754
    641                 this->handleNewClient( it->second.userId );
     755                // work with the ProxyControl to init the new client
     756                ProxyControl::getInstance()->signalNewClient( it->second.userId);
    642757
    643758                if ( PlayerStats::getStats( it->second.userId ) && it->second.handshake->getPreferedNickName() != "" )
     
    667782/**
    668783 * this functions handles a reconnect event received from the a NET_MASTER_SERVER or NET_PROXY_SERVER
     784 * @param userId
    669785 */
    670786void NetworkStream::handleReconnect(int userId)
    671787{
    672788  this->bRedirect = false;
     789#warning this peer will be created if it does not yet exist: dangerous
    673790  PeerInfo* pInfo = &this->peers[userId];
     791
     792  IP proxyIP;
     793  if( this->networkMonitor->isForcedReconnection())
     794    proxyIP = this->networkMonitor->getForcedReconnectionIP();
     795  else
     796    proxyIP = pInfo->handshake->getProxy1Address();
    674797
    675798  PRINTF(0)("===============================================\n");
    676799  PRINTF(0)("Client is redirected to the other proxy servers\n");
    677800  PRINTF(0)("  user id: %i\n", userId);
    678   PRINTF(0)("  connecting to: %s\n", this->networkMonitor->getFirstChoiceProxy()->ip.ipString().c_str());
     801  PRINTF(0)("  connecting to: %s\n", proxyIP.ipString().c_str());
    679802  PRINTF(0)("===============================================\n");
    680803
     
    683806  pInfo->lastRecvedState = 0;
    684807
    685   // temp save the ip address here
    686   IP proxyIP = pInfo->handshake->getProxy1Address();
    687 
    688808  // disconnect from the current server and reconnect to proxy server
    689809  this->handleDisconnect( userId);
    690810  this->connectToProxyServer(NET_ID_PROXY_SERVER_01, proxyIP.ipString(), 9999);
     811//   this->connectToMasterServer(proxyIP.ipString(), 9999);
    691812  #warning the ports are not yet integrated correctly in the ip class
    692813
     
    696817
    697818
     819
     820/**
     821 * reconnects to another server, with full handshake
     822 * @param address of the new server
     823 */
     824void NetworkStream::reconnectToServer(IP address)
     825{
     826  ///TODO make a redirection struct and push it to the network monitor
     827  this->networkMonitor->setForcedReconnection(address);
     828
     829  // reconnect (depending on how we are connected at the moment)
     830  if ( peers.find( NET_ID_MASTER_SERVER) != peers.end() )
     831    this->redirectionUID = NET_ID_MASTER_SERVER;
     832  else if( peers.find( NET_ID_PROXY_SERVER_01) != peers.end() )
     833    this->redirectionUID = NET_ID_PROXY_SERVER_01;
     834
     835  this->bRedirect = true;
     836}
     837
     838
     839
     840/**
     841 * softly reconnecting to another server
     842 * @param serverUserId the id of the client
     843 * @param address  of the new server
     844 */
     845void NetworkStream::softReconnectToServer(int serverUserId, IP address)
     846{
     847//   this->networkMonitor->setForcedReconnection(address);
     848//   this->handleReconnect( NET_ID_MASTER_SERVER);
     849
     850  // create the new udp socket and open the connection to the soft connection port
     851  NetworkSocket* newSocket = new UdpSocket(address.ipString(), 10001);
     852
     853  // delete the synchronization state of this client for all syncs
     854  for ( SynchronizeableList::iterator it2 = synchronizeables.begin(); it2 != synchronizeables.end(); it2++ )  {
     855    (*it2)->cleanUpUser( serverUserId );
     856  }
     857
     858  // temp save the old socket
     859  NetworkSocket* oldSocket = this->peers[serverUserId].socket;
     860
     861  // now integrate the new socket
     862  this->peers[serverUserId].socket = newSocket;
     863
     864  this->bSoftRedirect = false;
     865  return;
     866
     867  // now remove the old socket
     868  oldSocket->disconnectServer();
     869  delete oldSocket;
     870
     871  // replace the old connection monitor
     872  if ( this->peers[serverUserId].connectionMonitor )
     873    delete this->peers[serverUserId].connectionMonitor;
     874  this->peers[serverUserId].connectionMonitor = new ConnectionMonitor(serverUserId);
     875
     876  // remove old node from the network monitor
     877  this->networkMonitor->removeNode(&this->peers[serverUserId]);
     878
     879}
     880
     881
     882
     883/**
     884 * prepares a soft connection for a client to connect to
     885 * @param userId that will connect to this server
     886 */
     887void NetworkStream::prepareSoftConnection(int userId)
     888{
     889  PRINTF(0)("prepare soft connection for userId %i\n");
     890}
     891
     892
     893
    698894/**
    699895 * handles the disconnect event
     
    702898void NetworkStream::handleDisconnect( int userId )
    703899{
    704   peers[userId].socket->disconnectServer();
    705   delete peers[userId].socket;
    706   peers[userId].socket = NULL;
    707 
    708   if ( peers[userId].handshake )
    709     delete peers[userId].handshake;
    710   peers[userId].handshake = NULL;
    711 
    712   if ( peers[userId].connectionMonitor )
    713     delete peers[userId].connectionMonitor;
    714   peers[userId].connectionMonitor = NULL;
    715 
    716 
     900  this->peers[userId].socket->disconnectServer();
     901  delete this->peers[userId].socket;
     902  this->peers[userId].socket = NULL;
     903
     904  if ( this->peers[userId].handshake )
     905    delete this->peers[userId].handshake;
     906  this->peers[userId].handshake = NULL;
     907
     908  if ( this->peers[userId].connectionMonitor )
     909    delete this->peers[userId].connectionMonitor;
     910  this->peers[userId].connectionMonitor = NULL;
     911
     912  // delete the synchronization state of this client for all syncs
    717913  for ( SynchronizeableList::iterator it2 = synchronizeables.begin(); it2 != synchronizeables.end(); it2++ )  {
    718914    (*it2)->cleanUpUser( userId );
     
    724920  this->freeSocketSlots.push_back( userId );
    725921
    726   peers.erase( userId);
    727 }
    728 
     922  this->networkMonitor->removeNode(&this->peers[userId]);
     923  this->peers.erase( userId);
     924}
    729925
    730926
     
    793989      assert( offset + INTSIZE <= UDP_PACKET_SIZE );
    794990
    795       // server fakes uniqueid == 0 for handshake
     991      // server fakes uniqueid == 0 for handshake synchronizeable
    796992      if ( ( SharedNetworkData::getInstance()->isMasterServer() ||
    797993             SharedNetworkData::getInstance()->isProxyServerActive() &&  peer->second.isClient() ) &&
    798              sync.getUniqueID() <= SharedNetworkData::getInstance()->getMaxPlayer() + 1) // plus one to handle one client more than the max to redirect it
     994             ( sync.getUniqueID() >= 1000 || sync.getUniqueID() <= SharedNetworkData::getInstance()->getMaxPlayer() + 1 + NET_ID_PROXY_MAX))
    799995        n = Converter::intToByteArray( 0, buf + offset, UDP_PACKET_SIZE - offset );
    800996      else
     
    9301126      while ( offset + 2 * INTSIZE < length )
    9311127      {
     1128        // read the unique id of the sync
    9321129        assert( offset > 0 );
    9331130        assert( Converter::byteArrayToInt( buf + offset, &uniqueId ) == INTSIZE );
    9341131        offset += INTSIZE;
    9351132
     1133        // read the data length
    9361134        assert( Converter::byteArrayToInt( buf + offset, &syncDataLength ) == INTSIZE );
    9371135        offset += INTSIZE;
     
    9451143        for ( SynchronizeableList::iterator it = synchronizeables.begin(); it != synchronizeables.end(); it++ )
    9461144        {
    947           // client thinks his handshake has id 0!!!!!
    948           if ( (*it)->getUniqueID() == uniqueId || ( uniqueId == 0 && (*it)->getUniqueID() == peer->second.userId ) )
     1145          // client thinks his handshake has a special id: hostId * 1000 (host id of this server)
     1146          if ( (*it)->getUniqueID() == uniqueId ||                                          // so this client exists already go to sync work
     1147                 ( uniqueId == 0  && (*it)->getUniqueID() == peer->second.userId ) )        // so this is a Handshake!
    9491148          {
    9501149            sync = *it;
  • trunk/src/lib/network/network_stream.h

    r9494 r9656  
    4141    void init();
    4242
     43    /* network interface controls */
    4344    void connectToMasterServer(std::string host, int port);
    4445    void connectToProxyServer(int proxyId, std::string host, int port);
    45     void createServer(int clientPort, int proxyPort);
     46    void createServer(int clientPort, int proxyPort, int clientSoftPort);
    4647
    4748    void createNetworkGameManager();
    4849    void startHandshake(int userId = NET_ID_MASTER_SERVER);
     50
     51    void reconnectToServer(IP address);
     52    void softReconnectToServer(int serverUserId, IP address);
     53    void prepareSoftConnection(int userId);
     54
    4955
    5056    /* synchronizeable interface */
     
    7076    inline PeerInfo* getPeerInfo() { return this->pInfo; }
    7177    inline PeerList getPeerInfoList() { return this->peers; }
     78
     79    inline void setRedirectionTest() { this->bSoftRedirect = true; }
    7280
    7381    /* data processing*/
     
    96104
    97105    void handleConnect( int userId);
     106    void handleSoftConnect( int userId);
    98107    void handleReconnect( int userId );
    99108    void handleDisconnect( int userId );
     109    void handleSoftDisconnect( int userId);
    100110
    101111    void writeToNewDict( byte * data, int length, bool upstream );
     
    112122    NetworkMonitor*            networkMonitor;              //!< the network monitor
    113123    NetworkGameManager*        networkGameManager;          //!< reference to the network game manager
    114     ServerSocket*              clientSocket;                //!< the listening socket of the server
     124    ServerSocket*              clientSocket;                //!< the listening socket for clients of the server
     125    ServerSocket*              clientSoftSocket;            //!< the listening socket for soft connections to the server
    115126    ServerSocket*              proxySocket;                 //!< socket for proxy connections
    116127
     
    126137
    127138    bool                       bRedirect;                   //!< true if the master server sent a redirect command
     139    int                        redirectionUID;              //!< uid of the redir host
     140    bool                       bSoftRedirect;               //!< tsting
    128141};
    129142#endif /* _NETWORK_STREAM */
  • trunk/src/lib/network/peer_info.cc

    r9494 r9656  
    4242void PeerInfo::clear()
    4343{
    44   this->userId = 0;
    45   this->nodeType = NET_CLIENT;
     44  this->userId = NET_ID_UNASSIGNED;
     45  this->nodeType = NET_UNASSIGNED;
    4646  this->socket = NULL;
    4747  this->handshake = NULL;
     
    4949  this->lastRecvedState = 0;
    5050  this->connectionMonitor = NULL;
     51  this->bLocal = false;
    5152
    5253  this->ip = IP(0,0);
     
    6869const std::string PeerInfo::nodeNames[] =
    6970{
    70 
    71   "maser server",
     71  "master server",
    7272  "proxy server active",
    7373  "proxy server passive",
  • trunk/src/lib/network/peer_info.h

    r9494 r9656  
    3030    static const std::string& nodeTypeToString(unsigned int type);
    3131
     32    inline bool isLocal() { return this->bLocal; }
    3233
    3334
     
    4445    int                 lastRecvedState;         //!< last received state
    4546
     47    bool                bLocal;                  //!< true if this node is localy connected to this node
     48
    4649    static const std::string nodeNames[];
    4750
  • trunk/src/lib/network/player_stats.cc

    r9494 r9656  
    4141  init();
    4242
    43   this->userId = userId;
     43  this->assignedUserId = userId;
    4444}
    4545
     
    5656  this->setClassID( CL_PLAYER_STATS, "PlayerStats" );
    5757
    58   this->userId = 0;
     58  this->assignedUserId = 0;
    5959  this->teamId = TEAM_NOTEAM;
    6060  this->preferedTeamId = TEAM_NOTEAM;
     
    6565  this->oldNickName = "Player";
    6666
    67   userId_handle = registerVarId( new SynchronizeableInt( &userId, &userId, "userId" ) );
    68   teamId_handle = registerVarId( new SynchronizeableInt( &teamId, &teamId, "teamId" ) );
    69   preferedTeamId_handle = registerVarId( new SynchronizeableInt( &preferedTeamId, &preferedTeamId, "preferedUserId" ) );
    70   score_handle = registerVarId( new SynchronizeableInt( &score, &score, "score" ) );
    71   playableClassId_handle = registerVarId( new SynchronizeableInt( &playableClassId, &playableClassId, "playableClassId") );
    72   playableUniqueId_handle = registerVarId( new SynchronizeableInt( &playableUniqueId, &playableUniqueId, "playableUniqueId" ) );
    73   modelFileName_handle = registerVarId( new SynchronizeableString( &modelFileName, &modelFileName, "modelFileName" ) );
    74   nickName_handler = registerVarId( new SynchronizeableString( &nickName, &nickName, "nickName" ) );
     67  userId_handle = registerVarId( new SynchronizeableInt( &assignedUserId, &assignedUserId, "userId", PERMISSION_MASTER_SERVER ) );
     68  teamId_handle = registerVarId( new SynchronizeableInt( &teamId, &teamId, "teamId", PERMISSION_MASTER_SERVER ) );
     69  preferedTeamId_handle = registerVarId( new SynchronizeableInt( &preferedTeamId, &preferedTeamId, "preferedUserId", PERMISSION_MASTER_SERVER ) );
     70  score_handle = registerVarId( new SynchronizeableInt( &score, &score, "score", PERMISSION_MASTER_SERVER ) );
     71  playableClassId_handle = registerVarId( new SynchronizeableInt( &playableClassId, &playableClassId, "playableClassId", PERMISSION_MASTER_SERVER) );
     72  playableUniqueId_handle = registerVarId( new SynchronizeableInt( &playableUniqueId, &playableUniqueId, "playableUniqueId", PERMISSION_MASTER_SERVER ) );
     73  modelFileName_handle = registerVarId( new SynchronizeableString( &modelFileName, &modelFileName, "modelFileName", PERMISSION_MASTER_SERVER ) );
     74  nickName_handler = registerVarId( new SynchronizeableString( &nickName, &nickName, "nickName", PERMISSION_MASTER_SERVER ) );
    7575
    7676  MessageManager::getInstance()->registerMessageHandler( MSGID_CHANGENICKNAME, changeNickHandler, NULL );
    7777
    78   PRINTF(0)("PlayerStats created\n");
     78  PRINTF(5)("PlayerStats created\n");
    7979}
    8080
     
    8484 */
    8585PlayerStats::~PlayerStats()
    86 {
    87 }
    88 
    89 
    90  /**
    91  * override this function to be notified on change
    92  * of your registred variables.
    93  * @param id id's which have changed
    94   */
     86{}
     87
     88
     89/**
     90* override this function to be notified on change
     91* of your registred variables.
     92* @param id id's which have changed
     93 */
    9594void PlayerStats::varChangeHandler( std::list< int > & id )
    9695{
     
    9998    this->setPlayableUniqueId( this->playableUniqueId );
    10099
    101     PRINTF(0)("uniqueID changed %d %d %d\n", userId, SharedNetworkData::getInstance()->getHostID(), getUniqueID());
     100    PRINTF(4)("uniqueID changed %d %d %d\n", assignedUserId, SharedNetworkData::getInstance()->getHostID(), getUniqueID());
    102101  }
    103102
     
    105104  {
    106105    PRINTF(0)("user %s is now known as %s\n", oldNickName.c_str(), nickName.c_str());
    107     oldNickName = nickName;
    108   }
    109 }
     106    this->oldNickName = nickName;
     107  }
     108
     109  if ( std::find( id.begin(), id.end(), preferedTeamId_handle) != id.end() )
     110  {
     111    PRINTF(0)("user %s has changed team to %i\n", nickName.c_str(), this->teamId);
     112  }
     113}
     114
     115
    110116
    111117/**
     
    123129  }
    124130
    125   for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ )
    126   {
    127     if ( dynamic_cast<PlayerStats*>(*it)->getUserId() == userId )
     131  for ( std::list<BaseObject*>::const_iterator it = list->
     132        begin();
     133        it != list->end();
     134        it++ )
     135  {
     136
     137
     138    if ( dynamic_cast<PlayerStats*>(*it)->getAssignedUserId() == userId )
    128139    {
    129140      return dynamic_cast<PlayerStats*>(*it);
     
    148159
    149160  this->playable = NULL;
    150   for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ )
    151   {
    152     if ( dynamic_cast<Playable*>(*it)->getUniqueID() == uniqueId )
     161  for ( std::list<BaseObject*>::const_iterator it = list->
     162        begin();
     163        it != list->end();
     164        it++ )
     165  {
     166    if ( dynamic_cast<Playable*>(*it)->
     167         getUniqueID() == uniqueId )
    153168    {
    154169      this->playable = dynamic_cast<Playable*>(*it);
     
    159174  }
    160175
    161   if ( this->playable && userId == SharedNetworkData::getInstance()->getHostID() )
     176  if ( this->playable && this->assignedUserId == SharedNetworkData::getInstance()
     177       ->getHostID() )
    162178  {
    163179    State::getPlayer()->setPlayable( this->playable );
     180    // also set the team id
    164181  }
    165182
     
    204221    assert( Converter::stringToByteArray( nick, data, nick.length()+INTSIZE) == nick.length()+INTSIZE );
    205222
    206     MessageManager::getInstance()->sendMessage( MSGID_CHANGENICKNAME, data, nick.length()+INTSIZE, RT_SERVER, 0, MP_HIGHBANDWIDTH );
     223    MessageManager::getInstance()->sendMessage( MSGID_CHANGENICKNAME, data, nick.length()+INTSIZE, RT_SERVER, NET_MASTER_SERVER, MP_HIGHBANDWIDTH );
    207224    return;
    208225  }
    209226}
    210227
    211 bool PlayerStats::changeNickHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId )
     228/**
     229 * handler for the nick name
     230 * @param messageType type of the message
     231 * @param data  data of the message
     232 * @param dataLength length of the data
     233 * @param someData some additional data
     234 * @param senderId userId of the sender
     235 * @param destinationId userId of the rec
     236 * @return true if handled correctly
     237 */
     238bool PlayerStats::changeNickHandler( MessageType messageType, byte * data, int dataLength, void * someData, int senderId, int destinationId  )
    212239{
    213240  std::string newNick;
     
    216243  if ( res != dataLength )
    217244  {
    218     PRINTF(2)("invalid message size from user %d\n", userId);
     245    PRINTF(2)("invalid message size from user %d\n", senderId);
    219246    newNick = "invalid";
    220247  }
    221248
    222   if ( PlayerStats::getStats( userId ) )
    223     PlayerStats::getStats( userId )->setNickName( newNick );
     249  if ( PlayerStats::getStats( senderId) )
     250    PlayerStats::getStats( senderId )->setNickName( newNick );
    224251
    225252  return true;
    226253}
    227254
     255/**
     256 * sets the nick name from the shell
     257 * @param newNick new prefered nick name
     258 */
    228259void PlayerStats::shellNick( const std::string& newNick )
    229260{
     
    236267
    237268
     269/**
     270 * removes and delets all player stats
     271 */
    238272void PlayerStats::deleteAllPlayerStats( )
    239273{
     
    246280
    247281
     282/**
     283 * @return the score list of this player stat
     284 */
    248285ScoreList PlayerStats::getScoreList( )
    249286{
     
    257294  }
    258295
    259   for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ )
     296  for ( std::list<BaseObject*>::const_iterator it = list->
     297        begin();
     298        it != list->end();
     299        it++ )
    260300  {
    261301    PlayerStats & stats = *dynamic_cast<PlayerStats*>(*it);
  • trunk/src/lib/network/player_stats.h

    r9110 r9656  
    1616enum
    1717{
    18   TEAM_NOTEAM = -3,
    19   TEAM_RANDOM = -2,
    20   TEAM_SPECTATOR = -1
     18  TEAM_NOTEAM       = -3,
     19  TEAM_RANDOM       = -2,
     20  TEAM_SPECTATOR    = -1
    2121};
     22
    2223
    2324struct PlayerScore
     
    2627  int score;
    2728};
     29
     30
    2831typedef std::list<PlayerScore> TeamScoreList;
    2932typedef std::map<int,TeamScoreList> ScoreList;
    3033
     34
    3135//! A class for storing player information
    32 class PlayerStats : public Synchronizeable 
     36class PlayerStats : public Synchronizeable
    3337{
    3438
     
    3741    PlayerStats( int userId );
    3842    virtual ~PlayerStats();
    39    
     43
    4044    virtual void varChangeHandler( std::list<int> & id );
    41    
     45
    4246    static PlayerStats * getStats( int userId );
    43    
    44     inline int getUserId(){ return userId; }
    45    
     47    inline int getAssignedUserId(){ return this->assignedUserId; }
     48
     49
    4650    inline int getTeamId(){ return teamId; }
    4751    inline void setTeamId( int teamId ){ this->teamId = teamId; }
    48    
     52
    4953    inline int getPreferedTeamId(){ return preferedTeamId; }
    50     inline void setPreferedTeamId( int preferedTeamId ){ this->preferedTeamId = preferedTeamId; }
    51    
     54    inline void setPreferedTeamId( int preferedTeamId ) { this->preferedTeamId = preferedTeamId; }
     55
    5256    inline int getScore(){ return score; }
    5357    inline void setScore( int score ){ this->score = score; }
    54    
     58
    5559    inline int getPlayableClassId(){ return playableClassId; }
    5660    void setPlayableClassId( int classId ){ this->playableClassId = classId; };
    57    
     61
    5862    inline int getPlayableUniqueId(){ return playableUniqueId; }
    5963    void setPlayableUniqueId( int uniqueId );
    60    
     64
    6165    inline std::string getModelFileName(){ return modelFileName; }
    6266    inline void setModelFileName( std::string filename ){ modelFileName = filename; }
    63    
     67
    6468    Playable * getPlayable();
    65    
     69
    6670    inline std::string getNickName(){ return this->nickName; }
    6771    void setNickName( std::string nick );
    68     static bool changeNickHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId );
     72    static bool changeNickHandler( MessageType messageType, byte * data, int dataLength, void * someData, int senderId, int destinationId );
    6973    void shellNick( const std::string&  newNick );
    70    
     74
    7175    static void deleteAllPlayerStats();
    72    
     76
    7377    static ScoreList getScoreList();
    7478
     79
    7580  private:
    76     int userId;                //!< userId
    77     int teamId;                //!< teamId
    78     int preferedTeamId;        //!< preferedTeamId
     81    void init();
    7982
    80     std::string nickName;      //!< players nickname
    81     std::string oldNickName;   //!< nickname player had before
    8283
    83     int score;                 //!< users score points
    84     int playableClassId;       //!< players playable class id
    85     int playableUniqueId;      //!< playable's uniqueId
    86     std::string modelFileName; //!< model filename
     84  private:
     85    // handles for SynchronizeableVars
     86    int              userId_handle;
     87    int              teamId_handle;
     88    int              preferedTeamId_handle;
     89    int              score_handle;
     90    int              playableClassId_handle;
     91    int              playableUniqueId_handle;
     92    int              modelFileName_handle;
     93    int              nickName_handler;
    8794
    88     Playable * playable;       //!< pointer to players playable
     95    int              assignedUserId;            //!< userId
     96    int              teamId;                    //!< teamId
     97    int              preferedTeamId;            //!< preferedTeamId
    8998
    90     // handles for SynchronizeableVars
    91     int userId_handle;
    92     int teamId_handle;
    93     int preferedTeamId_handle;
    94     int score_handle;
    95     int playableClassId_handle;
    96     int playableUniqueId_handle;
    97     int modelFileName_handle;
    98     int nickName_handler;
    99    
    100     void init();
     99    std::string      nickName;                  //!< players nickname
     100    std::string      oldNickName;               //!< nickname player had before
     101
     102    int              score;                     //!< users score points
     103    int              playableClassId;           //!< players playable class id
     104    int              playableUniqueId;          //!< playable's uniqueId
     105    std::string      modelFileName;             //!< model filename
     106
     107    Playable *       playable;                  //!< pointer to players playable
    101108};
    102109
  • trunk/src/lib/network/proxy/network_settings.cc

    r9494 r9656  
    8787  // setUniqueID( maxCon+2 ) because we need one id for every handshake
    8888  // and one for handshake to reject client maxCon+1
    89   SharedNetworkData::getInstance()->setNewUniqueID( this->maxPlayer + 2);
     89  // NEW: at most there will be
     90  SharedNetworkData::getInstance()->setNewUniqueID( this->maxPlayer + NET_ID_PROXY_MAX + 2);
    9091}
    9192
  • trunk/src/lib/network/server_socket.h

    r7954 r9656  
    11/*!
    22 * @file server_socket.h
    3  *  waits for incoming connections
    4 
     3 * waits for incoming connections and handles them.
     4 *
    55 */
    66
  • trunk/src/lib/network/shared_network_data.h

    r9494 r9656  
    1616
    1717class Synchronizeable;
     18class NetworkMonitor;
    1819
    1920
     
    6465    inline void setDefaultSyncStream(NetworkStream* defaultSyncStream) { this->defaultSyncStream = defaultSyncStream; }
    6566
     67    /** @returns the network monitor reference */
     68    inline NetworkMonitor* getNetworkMonitor() { return this->networkMonitor; }
     69    /** @param networkMonitor sets the NetworkMonitor reference */
     70    inline void setNetworkMonitor( NetworkMonitor* networkMonitor) { this->networkMonitor = networkMonitor; }
     71
    6672
    6773  private:
     
    7581    int                             hostID;                  //!< The Host-ID of the Manager
    7682    NetworkStream*                  defaultSyncStream;       //!< default synchronize NetworkStream
     83    NetworkMonitor*                 networkMonitor;          //!< reference to the NetworkMonitor
    7784
    7885    static SharedNetworkData*       singletonRef;            //!< Pointer to the only instance of this Class
  • trunk/src/lib/network/synchronizeable.cc

    r9494 r9656  
    5555  /* make sure loadClassId is first synced var because this is read by networkStream */
    5656  assert( syncVarList.size() == 0 );
    57   mLeafClassId = this->registerVarId( new SynchronizeableInt( (int*)&this->getLeafClassID(), (int*)&this->getLeafClassID(), "leafClassId" ) );
    58 
    59   this->registerVar( new SynchronizeableInt( &this->owner, &this->owner, "owner" ) );
    60   this->registerVar( new SynchronizeableString( &this->objectName, &this->objectName, "objectName" ) );
     57  mLeafClassId = this->registerVarId( new SynchronizeableInt( (int*)&this->getLeafClassID(), (int*)&this->getLeafClassID(), "leafClassId", PERMISSION_MASTER_SERVER) );
     58
     59  this->registerVar( new SynchronizeableInt( &this->owner, &this->owner, "owner", PERMISSION_MASTER_SERVER ) );
     60  this->registerVar( new SynchronizeableString( &this->objectName, &this->objectName, "objectName", PERMISSION_MASTER_SERVER ) );
    6161}
    6262
     
    126126int Synchronizeable::getStateDiff( int userId, byte* data, int maxLength, int stateId, int fromStateId, int priorityTH )
    127127{
    128   //make sure this user has his history
    129   if ( sentStates.size() <= userId )
     128  // make sure this user has his history or resize for new clients
     129  if ( (int)sentStates.size() <= userId )
    130130    sentStates.resize( userId+1 );
    131131
     
    133133  int neededSize = 0;
    134134
     135  // calculate the needed space for network packet by summing up
    135136  for ( SyncVarList::iterator it = syncVarList.begin(); it != syncVarList.end(); it++ )
    136137  {
     
    201202  int n;
    202203
    203   bool hasPermission = false;
    204204  bool sizeChanged = false;
    205205
     
    207207  for ( SyncVarList::iterator it = syncVarList.begin(); it != syncVarList.end(); it++ )
    208208  {
    209     // DATA PERMISSIONS
    210     // check if this synchronizeable has the permissions to write the data
    211 
    212     // first check MASTER_SERVER permissions
    213     if( SharedNetworkData::getInstance()->isMasterServer() && (*it)->checkPermission( PERMISSION_MASTER_SERVER ))
    214       hasPermission = true;
    215     // now check PROXY_SERVER permissions
    216     else if( SharedNetworkData::getInstance()->isProxyServerActive() && (*it)->checkPermission( PERMISSION_PROXY_SERVER ))
    217       hasPermission = true;
    218     // now check OWNER permissions
    219     else if( this->owner == SharedNetworkData::getInstance()->getHostID() && (*it)->checkPermission( PERMISSION_OWNER ))
    220       hasPermission = true;
    221     // now check ALL permissions
    222     else if( (*it)->checkPermission( PERMISSION_ALL ))
    223       hasPermission = true;
    224     // SPECIAL: get write permissions if i am master server and i am able to overwrite the client stuff
    225 #warning this could probably override also clients that are connected to another proxy: the master server overwrites it
    226     else if( SharedNetworkData::getInstance()->isMasterServer() && this->owner != userId && (*it)->checkPermission( PERMISSION_OWNER ))
    227       hasPermission = true;
    228     // SPECIAL: get write permissions if i am proxy server and i am able to overwrite the client stuff
    229     else if( SharedNetworkData::getInstance()->isProxyServerActive() && this->networkStream->isUserClient(userId)
    230              && this->owner != userId && (*it)->checkPermission( PERMISSION_OWNER ) )
    231       hasPermission = true;
     209
     210    ////////////////////////////////
     211    // Data SENDING Permissions
     212    ////////////////////////////////
     213    bool hasPermission = false;
     214    bool b1, b2, b3, b4, b5, b6, b7, b8, b9;
     215    b1 = b2 = b3 = b4 = b5 = b6 = b7 = b8 = b9 = false;
     216
     217
     218    // Permission   OWNER accept if:
     219    // I am the owner
     220    if(       (*it)->checkPermission( PERMISSION_OWNER ) && this->owner == SharedNetworkData::getInstance()->getHostID()) {
     221      hasPermission = true; b1 = true; }
     222    // reciever != owner && owner is local
     223    else if(  (*it)->checkPermission( PERMISSION_OWNER ) && userId != this->owner &&
     224                (SharedNetworkData::getInstance()->isUserLocal(this->owner) || this->owner == SharedNetworkData::getInstance()->getHostID())) {
     225      hasPermission = true; b2 = true; }
     226
     227
     228    // Permission   MASTER_SERVER accept if:
     229    // im MASTER_SERVER
     230    else if( (*it)->checkPermission( PERMISSION_MASTER_SERVER ) && SharedNetworkData::getInstance()->isMasterServer()) {
     231      hasPermission = true; b3 = true; }
     232    // im PROXY_SERVER && reciever == CLIENT
     233    else if( (*it)->checkPermission( PERMISSION_MASTER_SERVER ) && SharedNetworkData::getInstance()->isProxyServerActive() &&
     234               SharedNetworkData::getInstance()->isUserClient( userId)) {
     235      hasPermission = true;  b4 = true; }
     236
     237
     238    // Pemission    SERVER accept if:
     239    // i am server && reciever == CLIENT
     240    else if( (*it)->checkPermission( PERMISSION_SERVER ) && !SharedNetworkData::getInstance()->isClient() &&
     241               SharedNetworkData::getInstance()->isUserClient( userId)) {
     242      hasPermission = true; b5 = true; }
     243    // i am SERVER && reciever == SERVER && reciever != owner && ( owner is local || i am owner)
     244    else if( (*it)->checkPermission( PERMISSION_SERVER ) && !SharedNetworkData::getInstance()->isClient() &&
     245               userId != this->owner &&
     246               ( SharedNetworkData::getInstance()->isUserLocal( this->owner) || this->owner ==  SharedNetworkData::getInstance()->getHostID())) {
     247      hasPermission = true; b6 = true; }
     248
     249
     250    // Permission   ALL accept if:
     251    else if( (*it)->checkPermission( PERMISSION_ALL )) {
     252      hasPermission = true; b7 = true; }
     253    // or else refuse sending data
    232254    else
    233255      hasPermission = false;
    234256
    235257
     258
    236259    if ( sizeIter == stateFrom->sizeList.end() || *sizeIter != (*it)->getSize() )
    237260      sizeChanged = true;
     
    241264      n = (*it)->writeToBuf( stateTo->data+i, stateTo->dataLength - i );
    242265      //NETPRINTF(0)("getvar %s %d\n", (*it)->getName().c_str(), n);
    243       //PRINTF(0)("getvar %s %d\n", (*it)->getName().c_str(), n);
     266//       PRINTF(0)("sending %s %d\n", (*it)->getName().c_str(), n);
     267
     268//       if( this->isA(CL_PLAYABLE))
     269//       {
     270//         PRINTF(0)("ms: %i, ps: %i, c: %i, sender: %i, reciever: %i, owner: %i, perm: (ow %i, ms %i, s %i, a %i)\n",
     271//         SharedNetworkData::getInstance()->isMasterServer(), SharedNetworkData::getInstance()->isProxyServerActive(), SharedNetworkData::getInstance()->isClient(),
     272//         SharedNetworkData::getInstance()->getHostID(), userId, this->owner,
     273//         (*it)->checkPermission( PERMISSION_OWNER ), (*it)->checkPermission( PERMISSION_MASTER_SERVER ),
     274//         (*it)->checkPermission( PERMISSION_SERVER ), (*it)->checkPermission( PERMISSION_ALL ));
     275//         PRINTF(0)("hasPermission: %i, sizeChanged: %i, eval: %i, %i, %i, %i, %i, %i, %i\n", hasPermission, sizeChanged, b1, b2, b3, b4, b5, b6, b7);
     276//         PRINTF(0)("sending %s %s %d\n", this->getClassCName(), (*it)->getName().c_str(), n);
     277//       }
     278
     279
    244280      stateTo->sizeList.push_back( n );
    245281      // this is only for very hardcore debug sessions
     
    282318
    283319/**
    284  * sets a new state out of a diff created on another host
     320 * sets a new state out of a diff created on another host (recieving data)
    285321 * @param userId hostId of user who send me that diff
    286322 * @param data pointer to diff
     
    295331{
    296332  //make sure this user has his history
    297   if ( recvStates.size() <= userId )
     333  if ( (int)recvStates.size() <= userId )
    298334    recvStates.resize( userId+1 );
    299335
     
    345381  int n = 0;
    346382  std::list<int> changes;
    347   bool hasPermission = false;
    348383
    349384  // extract the new state for every client
     
    353388    // check if this synchronizeable has the permissions to write the data
    354389
    355     // first check MASTER_SERVER permissions
    356     if(  this->networkStream->isUserMasterServer( userId ) && (*it)->checkPermission( PERMISSION_MASTER_SERVER ))
    357       hasPermission = true;
    358     // now check PROXY_SERVER permissions
    359     else if( this->networkStream->isUserProxyServerActive( userId )  && (*it)->checkPermission( PERMISSION_MASTER_SERVER )
    360              && SharedNetworkData::getInstance()->isClient())
    361       hasPermission = true;
    362     // now check OWNER permissions
    363     else if( this->owner == userId && (*it)->checkPermission( PERMISSION_OWNER ))
    364       hasPermission = true;
    365     // now check ALL permissions
    366     else if( (*it)->checkPermission( PERMISSION_ALL ))
    367       hasPermission = true;
    368     // SPECIAL: get write permissions if im sending to a master server that does not own this sync
    369     else if( this->networkStream->isUserMasterServer( userId ) && this->owner != SharedNetworkData::getInstance()->getHostID() && (*it)->checkPermission( PERMISSION_OWNER ))
    370       hasPermission = true;
    371     // SPECIAL: get write permissions if im sending to a proxy server that does not own this sync
    372     else if( this->networkStream->isUserProxyServerActive( userId ) && SharedNetworkData::getInstance()->isClient()
    373               && this->owner != SharedNetworkData::getInstance()->getHostID() && (*it)->checkPermission( PERMISSION_OWNER ))
    374       hasPermission = true;
     390    bool hasPermission = false;
     391    bool b1, b2, b3, b4, b5, b6, b7, b8, b9;
     392    b1 = b2 = b3 = b4 = b5 = b6 = b7 = b8 = b9 = false;
     393
     394    ////////////////////////////////
     395    // Data RECIEVING Permissions
     396    ////////////////////////////////
     397
     398    // i should never ever receive a state update from a synchronizeable, that belongs to me! If it does somethings wrong with the send rules
     399//     assert(   !((*it)->checkPermission( PERMISSION_OWNER ) && this->owner == SharedNetworkData::getInstance()->getHostID()));
     400
     401
     402    // Permission   OWNER accept if:
     403    // sender == owner
     404    if(      (*it)->checkPermission( PERMISSION_OWNER ) && this->owner == userId) {
     405      hasPermission = true; b1 = true; }
     406    // sender == MASTER_SERVER
     407    else if( (*it)->checkPermission( PERMISSION_OWNER ) && SharedNetworkData::getInstance()->isUserMasterServer( userId)
     408               && this->owner != SharedNetworkData::getInstance()->getHostID()) {
     409      hasPermission = true; b2 = true; }
     410    // sender == PROXY_SERVER
     411      else if( (*it)->checkPermission( PERMISSION_OWNER ) && SharedNetworkData::getInstance()->isUserProxyServerActive( userId) &&
     412                 this->owner != SharedNetworkData::getInstance()->getHostID()) {
     413        hasPermission = true; b3 = true; }
     414
     415
     416
     417    // Permission   MASTER_SERVER accept if:
     418    // sender == MASTER_SERVER
     419    else if( (*it)->checkPermission( PERMISSION_MASTER_SERVER) && SharedNetworkData::getInstance()->isUserMasterServer( userId)) {
     420      hasPermission = true; b4 = true; }
     421    // sender == PROXY_SERVER && im not MASTER_SERVER && im not PROXY_SERVER
     422    else if( (*it)->checkPermission( PERMISSION_MASTER_SERVER) && SharedNetworkData::getInstance()->isClient() &&
     423               SharedNetworkData::getInstance()->isUserProxyServerActive( userId)) {
     424      hasPermission = true; b5 = true; }
     425
     426    // Permission   SERVER accept if:
     427    // sender == SERVER
     428    else if( (*it)->checkPermission( PERMISSION_SERVER ) && !SharedNetworkData::getInstance()->isUserClient( userId) /*&&
     429               SharedNetworkData::getInstance()->isClient()*/) {
     430      hasPermission = true; b6 = true; }
     431
     432
     433
     434    // Pemission    ALL accept if:
     435    else if(  (*it)->checkPermission( PERMISSION_ALL )) {
     436      hasPermission = true; b8 = true; }
     437
     438
     439   // no rights to over-write local data
    375440    else
    376441      hasPermission = false;
     
    384449      i += n;
    385450      //NETPRINTF(0)("%s::setvar %s %d\n", getClassCName(), (*it)->getName().c_str(), n);
    386       //PRINTF(0)("%s::setvar %s %d\n", getClassCName(), (*it)->getName().c_str(), n);
     451//       PRINTF(0)("recieving: %s %d\n", (*it)->getName().c_str(), n);
    387452      //(*it)->debug();
     453
     454//       if( this->isA(CL_PLAYABLE))
     455//       {
     456//         PRINTF(0)("ms: %i, ps: %i, c: %i, sender: %i, reciever: %i, owner: %i, perm: (ow %i, ms %i, s %i, a %i)\n",
     457//         SharedNetworkData::getInstance()->isMasterServer(), SharedNetworkData::getInstance()->isProxyServerActive(), SharedNetworkData::getInstance()->isClient(),
     458//         userId, SharedNetworkData::getInstance()->getHostID(), this->owner,
     459//         (*it)->checkPermission( PERMISSION_OWNER ), (*it)->checkPermission( PERMISSION_MASTER_SERVER ),
     460//         (*it)->checkPermission( PERMISSION_SERVER ), (*it)->checkPermission( PERMISSION_ALL ));
     461//         PRINTF(0)("hasPermission: %i, eval: %i, %i, %i, %i, %i, %i, %i, %i\n", hasPermission, b1, b2, b3, b4, b5, b6, b7, b8);
     462//         PRINTF(0)("rec %s %s %d\n", this->getClassCName(), (*it)->getName().c_str(), n);
     463//       }
     464
     465
    388466      if ( (*it)->getHasChanged() )
    389467      {
     
    444522void Synchronizeable::cleanUpUser( int userId )
    445523{
    446   if ( recvStates.size() > userId )
     524  if ( (int)recvStates.size() > userId )
    447525  {
    448526    for ( std::list<StateHistoryEntry*>::iterator it = recvStates[userId].begin(); it != recvStates[userId].end(); it++ )
     
    459537  }
    460538
    461   if ( sentStates.size() > userId )
     539  if ( (int)sentStates.size() > userId )
    462540  {
    463541
     
    485563{
    486564   //make sure this user has his history
    487   if ( recvStates.size() <= userId )
     565  if ( (int)recvStates.size() <= userId )
    488566    recvStates.resize( userId+1 );
    489567
     
    575653{
    576654   //make sure this user has his history
    577   if ( sentStates.size() <= userId )
     655  if ( (int)sentStates.size() <= userId )
    578656    sentStates.resize( userId+1 );
    579657
  • trunk/src/lib/network/synchronizeable_var/synchronizeable_bool.h

    r9406 r9656  
    1212
    1313  public:
    14     SynchronizeableBool( bool * ptrIn, bool * ptrOut, std::string name, int permission = PERMISSION_MASTER_SERVER, int priority = 0 );
     14    SynchronizeableBool( bool * ptrIn, bool * ptrOut, std::string name, int permission, int priority = 0 );
    1515    virtual ~SynchronizeableBool();
    1616
  • trunk/src/lib/network/synchronizeable_var/synchronizeable_float.h

    r9406 r9656  
    1313
    1414  public:
    15     SynchronizeableFloat( float * ptrIn, float * ptrOut, std::string name, int permission = PERMISSION_MASTER_SERVER, int priority = 0 );
     15    SynchronizeableFloat( float * ptrIn, float * ptrOut, std::string name, int permission, int priority = 0 );
    1616    virtual ~SynchronizeableFloat();
    1717
  • trunk/src/lib/network/synchronizeable_var/synchronizeable_int.h

    r9406 r9656  
    1313
    1414  public:
    15     SynchronizeableInt( int * ptrIn, int * ptrOut, std::string name, int permission = PERMISSION_MASTER_SERVER, int priority = 0 );
     15    SynchronizeableInt( int * ptrIn, int * ptrOut, std::string name, int permission, int priority = 0 );
    1616    virtual ~SynchronizeableInt();
    1717
  • trunk/src/lib/network/synchronizeable_var/synchronizeable_ip.h

    r9406 r9656  
    1515
    1616  public:
    17     SynchronizeableIP( IP *ptrIn, IP * ptrOut, std::string name, int permission = PERMISSION_MASTER_SERVER, int priority = 0 );
     17    SynchronizeableIP( IP *ptrIn, IP * ptrOut, std::string name, int permission, int priority = 0 );
    1818    virtual ~SynchronizeableIP();
    1919
  • trunk/src/lib/network/synchronizeable_var/synchronizeable_quaternion.h

    r9406 r9656  
    1414
    1515  public:
    16     SynchronizeableQuaternion( Quaternion * ptrIn, Quaternion * ptrOut, std::string name, int permission = PERMISSION_MASTER_SERVER, int priority = 0 );
     16    SynchronizeableQuaternion( Quaternion * ptrIn, Quaternion * ptrOut, std::string name, int permission, int priority = 0 );
    1717    virtual ~SynchronizeableQuaternion();
    1818
  • trunk/src/lib/network/synchronizeable_var/synchronizeable_string.h

    r9406 r9656  
    1414
    1515  public:
    16     SynchronizeableString( std::string * ptrIn, std::string * ptrOut, std::string name, int permission = PERMISSION_MASTER_SERVER, int priority = 0 );
     16    SynchronizeableString( std::string * ptrIn, std::string * ptrOut, std::string name, int permission, int priority = 0 );
    1717    virtual ~SynchronizeableString();
    1818
  • trunk/src/lib/network/synchronizeable_var/synchronizeable_uint.h

    r9406 r9656  
    1313
    1414  public:
    15     SynchronizeableUInt( unsigned int * ptrIn, unsigned int * ptrOut, std::string name, int permission = PERMISSION_MASTER_SERVER, int priority = 0 );
     15    SynchronizeableUInt( unsigned int * ptrIn, unsigned int * ptrOut, std::string name, int permission, int priority = 0 );
    1616    virtual ~SynchronizeableUInt();
    1717
  • trunk/src/lib/network/synchronizeable_var/synchronizeable_var.h

    r9494 r9656  
    1515
    1616  public:
    17     SynchronizeableVar( void * ptrIn, void * ptrOut, std::string name, int length, int permission = PERMISSION_MASTER_SERVER, int priority = 0 );
     17    SynchronizeableVar( void * ptrIn, void * ptrOut, std::string name, int length, int permission, int priority = 0 );
    1818    virtual ~SynchronizeableVar();
    1919
  • trunk/src/lib/network/synchronizeable_var/synchronizeable_vector.h

    r9406 r9656  
    1414
    1515  public:
    16     SynchronizeableVector( Vector * ptrIn, Vector * ptrOut, std::string name, int permission = PERMISSION_MASTER_SERVER, int priority = 0 );
     16    SynchronizeableVector( Vector * ptrIn, Vector * ptrOut, std::string name, int permission, int priority = 0 );
    1717    virtual ~SynchronizeableVector();
    1818
  • trunk/src/lib/network/udp_socket.h

    r9406 r9656  
    4141
    4242  private:
     43    void init();
     44
     45    bool writeRawPacket( byte * data, int length );
     46    bool checkUdpCmd( byte udpCmd );
     47    bool checkRandomByte( byte rndByte );
     48    byte generateNewRandomByte();
     49
     50
     51  private:
    4352    UdpServerSocket * serverSocket;   //!< will get packets here
    4453    int               userId;         //!< user id used by serverSocket
     
    4756
    4857    byte              randomByte;     //!< contains random bytes & 0xFC
    49 
    50     bool writeRawPacket( byte * data, int length );
    51     bool checkUdpCmd( byte udpCmd );
    52     bool checkRandomByte( byte rndByte );
    53     byte generateNewRandomByte();
    54 
    55     void init();
    56 
    5758};
    5859
Note: See TracChangeset for help on using the changeset viewer.