Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9494 in orxonox.OLD


Ignore:
Timestamp:
Jul 27, 2006, 10:44:28 AM (18 years ago)
Author:
bensch
Message:

merged the proxy back

Location:
trunk/src
Files:
2 deleted
47 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/collision_detection/aabb_tree_node.cc

    r9406 r9494  
    6666{
    6767  this->depth = depth;
     68
     69  this->init();
    6870}
    6971
     
    8789
    8890  this->owner = NULL;
    89 
    90   /* debug ids */
    91   if( this->nodePrev)
    92     this->treeIndex = 100 * this->depth + this->nodePrev->getID();
    93   else
    94     this->treeIndex = 0;
    9591}
    9692
  • trunk/src/lib/network/Makefile.am

    r9406 r9494  
    2828                      proxy/network_settings.cc \
    2929                      \
    30                                   monitor/connection_monitor.cc \
     30                      monitor/connection_monitor.cc \
    3131                      monitor/network_monitor.cc \
    3232                      monitor/network_node.cc \
     33                      monitor/network_stats_widget.cc \
    3334                      \
    3435                      synchronizeable_var/synchronizeable_var.cc \
     
    7778                proxy/network_settings.cc \
    7879                \
    79                 monitor/connection_monitor.h \
    80                 monitor/network_monitor.h \
    81                 monitor/network_node.h \
     80                monitor/connection_monitor.h \
     81                monitor/network_monitor.h \
     82                monitor/network_node.h \
     83                monitor/network_stats_widget.h \
    8284                \
    8385                synchronizeable_var/synchronizeable_var.h \
  • trunk/src/lib/network/README.NETWORK

    r9406 r9494  
     1
     2
     3
     4WORKING_STACK:
     5==============
     6 - it works to connecto to a master server which is connected to a proxy itself
     7
     8
     9
     10UNSOLVED:
     11=========
     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
     15
    116
    217
     
    823
    924UserId:
     25=======
    1026containing the id of a user (==client). This id must be unique within a orxonox network its used especialy in the NetworkStream for node identification and also in the Synchronizeable base class for permissions checking (PERMISSION_OWNER)
    11 WARNING:
    12 There is some correlation between userids and the maxplayer, do not touch this.
     27
     28the connections belonging tu toe userId's are stored in the NetworkStream::peers std::map. As a keyvalue the userId's are used. Therefore the usage of this peers map is very delicate. Don't ever try to add anything you are not sure about the id stuff.
     29
     30There are some reserved id's, don't mess with them:
     310 :                  Master Server
     321 :                  First Proxy Server
     332 :                  Second Proxy Server
     343 :                  Third Proxy Server
     354 :                  Fourth Proxy Server
     36.
     37.
     38.
     39NET_MAX_PROXY        The maximal number of proxy servers
     40NET_MAX... + 1       First Client
     41NET_MAX... + 2       Second Client
     42.
     43.
     44.
     45NET_MAX_CONNECTION   Last client
     46
     47The proxy server ids are assigned as stated in the data/trunk/config/network_settings.conf, the first proxy server in the list gets the id NET_ID_PROXY_01 and so on.
     48
    1349
    1450
    1551uniqueId:
     52=========
    1653uniqueId 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
    1754
    1855
     56permissions:
     57============
     58Each synchronizeable variable has some write permissions. this permission systems allows to manage which network nodes are able to write the variables.
     59PERMISSION_MASTER_SERVER       : only the master server can write this variable
     60PERMISSION_PROXY_SERVER        : only the proxy server can write this variable
     61PERMISSION_OWNER               : only the owner can write this variable
     62PERMISSION_ALL                 : all clients can write this variable
     63
     64
     65
     66
     67
    1968NetworkStream PeerInfo list: (peers)
     69=====================================
    2070The network node with the offset 0 is always the server to which the client must connect to (in case there are connections to other hosts at the same time).
     71
     72
     73
  • trunk/src/lib/network/handshake.cc

    r9406 r9494  
    7676  remoteState.orxId = 0;
    7777  remoteState.version = 0;
    78   remoteState.nodeType = NET_CLIENT;
     78  remoteState.nodeType = NET_UNASSIGNED;
    7979  remoteState.canDel = 0;
    8080
  • trunk/src/lib/network/handshake.h

    r9406 r9494  
    4949    /* functions indicating states of the handshake */
    5050    /** @returns true if the handshake is completed */
    51     inline bool completed(){ return localState.completed != 0 && remoteState.completed != 0; }
     51    inline bool completed() const { return localState.completed != 0 && remoteState.completed != 0; }
    5252    /** @returns true if no error has occured until now */
    53     inline bool ok(){ return localState.error == 0 && remoteState.error == 0; }
     53    inline bool ok() const { return localState.error == 0 && remoteState.error == 0; }
    5454    /** stops the handshake and reject the other side with @param reason: string describing the reason */
    5555    inline void doReject( std::string reason ){ localState.error = 1; localState.errorString = "the server rejected your connection ["+ reason +"]"; }
    5656    /** @returns true if the handshake is finished and the instances can be deleted */
    57     inline bool canDel(){ return localState.canDel == 1 && remoteState.canDel == 1; }
     57    inline bool canDel() const { return localState.canDel == 1 && remoteState.canDel == 1; }
    5858    /** @returns true if the local state can be removed*/
    59     inline bool allowDel(){ return localState.canDel == 1; }
     59    inline bool allowDel() const { return localState.canDel == 1; }
    6060    /** marks the handshake to be deleted */
    61     inline void del(){ localState.canDel = 1; }
     61    inline void del() { localState.canDel = 1; }
    6262
    6363
    6464    /* the actual informations exchanged in the handshake */
    6565    /** @returns the host id of the remote host */
    66     inline int  getHostId(){ return remoteState.hostId; }
     66    inline int  getHostId() const { return remoteState.hostId; }
    6767    /** @returns the unique id of the network game manager*/
    68     inline int  getNetworkGameManagerId(){ return remoteState.networkManagerId; }
     68    inline int  getNetworkGameManagerId() const { return remoteState.networkManagerId; }
    6969    /** @returns the unique id of the message manager */
    70     inline int  getMessageManagerId(){ return remoteState.messageManagerId; }
     70    inline int  getMessageManagerId() const { return remoteState.messageManagerId; }
    7171    /** @returns the node type of the remote host */
    72     inline int getRemoteNodeType() { return this->remoteState.nodeType; }
     72    inline int getRemoteNodeType() const { return this->remoteState.nodeType; }
    7373
    7474    /** sets @param nick the prefereded nick name */
    7575    inline void setPreferedNickName( const std::string & nick ){ localState.preferedNickName = nick; }
    7676    /** @returns the prefered nick name */
    77     inline std::string getPreferedNickName(){ return remoteState.preferedNickName; }
     77    inline const std::string& getPreferedNickName() const { return remoteState.preferedNickName; }
    7878
    7979    /** @returns if true the local client should reconnect to a proxy server from the proxy server list */
    80     inline bool redirect() { return this->redirectProxy;}
     80    inline bool redirect() const  { return this->redirectProxy; }
    8181    /** @param flag: indicating if the client should be redirected */
    8282    inline void setRedirect(bool flag) { if( SharedNetworkData::getInstance()->isClient()) return; this->redirectProxy = (int)flag; }
     
    8585    inline void setProxy1Address(IP address) { if( SharedNetworkData::getInstance()->isClient()) return; this->proxy1 = address; }
    8686    /** @returns the address of the proxy server 1 if any */
    87     inline IP getProxy1Address() { return this->proxy1; }
     87    inline IP getProxy1Address() const { return this->proxy1; }
    8888    /** @param address: the address of the proxy server 2 if any */
    8989    inline void setProxy2Address(IP address) { if( SharedNetworkData::getInstance()->isClient()) return; this->proxy2 = address; }
    9090    /** @returns the address of the proxy server 2 if any */
    91     inline IP getProxy2Address() { return this->proxy2; }
     91    inline IP getProxy2Address() const { return this->proxy2; }
    9292
    9393
  • trunk/src/lib/network/ip.cc

    r9406 r9494  
    111111IP::IP(unsigned int first, unsigned int second, unsigned int third, unsigned int fourth, int port)
    112112{
    113   this->_host = (first << 24) +
    114                 (second << 16) +
    115                 (third <<  8) +
    116                 fourth;
     113  this->_host = (fourth << 24) +
     114                (third << 16) +
     115                (second <<  8) +
     116                (first);
    117117  this->_port = port;
    118118}
     
    185185    IPaddress ipaddr;
    186186
    187     SDLNet_ResolveHost(&ipaddr, NULL, 2000);
    188 
    189     return IP(ipaddr.host, port);
     187    SDLNet_ResolveHost(&ipaddr, ip.c_str(), port);
     188
     189    return IP(ipaddr);
    190190  }
    191191  else
     
    255255/**
    256256 * @brief converts a IP into a String (without port).
    257  * @param ip the IP to put into the string.
     257 * @param host the IP to put into the string.
    258258 * @param port -1 if not wanted
    259259 * @return the string of the ip.
    260260 */
    261 std::string IP::ipToString(int ip, int port)
    262 {
    263   MultiType part0((int) (ip & 0xFF000000) >> 24);
    264   MultiType part1((int) (ip & 0x00FF0000) >> 16);
    265   MultiType part2((int) (ip & 0x0000FF00) >>  8);
    266   MultiType part3((int) (ip & 0x000000FF) );
     261std::string IP::ipToString(int host, int port)
     262{
     263  MultiType part0((int) ((host & 0xFF000000) >> 24));
     264  MultiType part1((int) ((host & 0x00FF0000) >> 16));
     265  MultiType part2((int) ((host & 0x0000FF00) >>  8));
     266  MultiType part3((int) ((host & 0x000000FF) ));
    267267
    268268  std::string addr = part3.getString() + "." + part2.getString() + "." +
    269269                     part1.getString() + "." + part0.getString();
    270270
    271   if (port != -1)
    272     addr += ":" + MultiType(port).getString();
    273271  return addr;
    274272}
  • trunk/src/lib/network/ip.h

    r9406 r9494  
    5454
    5555    static std::string ipToString(const IPaddress& ipaddr);
    56     static std::string ipToString(int ip, int port = -1);
     56    static std::string ipToString(int host, int port = -1);
    5757
    5858    static void setDefaultPort(int defaultPort);
  • trunk/src/lib/network/message_manager.cc

    r9406 r9494  
    320320    if (
    321321         recieverType == RT_ALL_ME ||
    322          recieverType == RT_ALL_NOT_ME ||
     322         recieverType == RT_ALL_BUT_ME ||
    323323         recieverType == RT_USER && it->first == reciever ||
    324324         recieverType == RT_NOT_USER && it->first != reciever ||
    325          recieverType == RT_SERVER && getNetworkStream()->isUserMasterServer( it->first )
     325         recieverType == RT_SERVER && getNetworkStream()->isUserMasterServer( it->first ) ||
     326         recieverType == RT_SERVER && getNetworkStream()->isUserProxyServerActive( it->first )
    326327       )
    327328    {
  • trunk/src/lib/network/message_manager.h

    r9008 r9494  
    2626
    2727
    28 enum MessageId 
     28enum MessageId
    2929{
    3030  TESTMESSAGEID = 1,
     
    4040enum RecieverType
    4141{
    42   RT_ALL_NOT_ME = 1,   //!< message is sent to all users
     42  RT_ALL_BUT_ME = 1,   //!< message is sent to all users but myself
    4343  RT_ALL_ME,           //!< message is sent to all users
    4444  RT_USER,             //!< message is only sent to reciever
     
    5252  MP_HIGHBANDWIDTH = 1,  //!< fast and reliable but uses a lot of bandwidth
    5353  MP_LOWBANDWIDTH,       //!< may take a long time to arrive. reliable
    54   MP_UNRELIABLE          //!< unreliable. low bandwidth 
     54  MP_UNRELIABLE          //!< unreliable. low bandwidth
    5555};
    5656
     
    8888 public:
    8989   inline static MessageManager * getInstance(){ if (!singletonRef) singletonRef = new MessageManager();  return singletonRef; }
    90    
     90
    9191   virtual ~MessageManager();
    92    
     92
    9393   bool registerMessageHandler( MessageId messageId, MessageCallback cb, void * someData );
    94    
     94
    9595   void sendMessage( MessageId messageId, byte * data, int dataLength, RecieverType recieverType, int reciever, MessagePriority messagePriority );
    9696
     
    100100   virtual void handleSentState( int userId, int stateId, int fromStateId ){}
    101101   virtual void handleRecvState( int userId, int stateId, int fromStateId ){}
    102    
     102
    103103   void initUser( int userId );
    104104
     
    110110
    111111   int                       newNumber;              //!< used to create unique message numbers
    112    std::list<NetworkMessage> incomingMessageBuffer; 
     112   std::list<NetworkMessage> incomingMessageBuffer;
    113113
    114114};
  • trunk/src/lib/network/monitor/connection_monitor.cc

    r9406 r9494  
    3232  /* set the class id for the base object and add ist to class list*/
    3333  this->setClassID(CL_CONNECTION_MONITOR, "ConnectionMonitor");
    34  
     34
    3535  this->userId = userId;
    3636  this->ping = 0;
     
    4343  this->nZIncomingPackets = 0;
    4444  this->nZOutgoingPackets = 0;
    45  
     45
    4646  this->lastPacketTick = 0;
    4747  this->lastPrintTick = 0;
     
    6464{
    6565  nOutgoingPackets++;
    66  
     66
    6767  // for ping calculation
    6868  sentStateTicks[stateId] = tick;
    69  
     69
    7070  // calculate bandwidth
    7171  outgoingUnzippedPacketHistory[tick] = length;
    7272  outgoingUnzippedBandWidth = calculateBandWidth( outgoingUnzippedPacketHistory, tick );
    73  
     73
    7474  //NETPRINTF(n)("UNZIPPED UPSTREAM: user: %d bandwidth %f\n", userId, outgoingUnzippedBandWidth );
    75  
     75
    7676  // count zero bytes
    7777  //int nZeroBytes = 0;
    78  
     78
    7979  //for ( int i = 0; i < length; i++ )
    8080  //  if ( data[i] == '\0' )
    8181  //    nZeroBytes++;
    82  
     82
    8383  //NETPRINTF(n)( "ZEROBYTES: %d (%f%%)\n", nZeroBytes, ((float)100)*nZeroBytes/length );
    8484}
     
    9494{
    9595  nIncomingPackets++;
    96  
     96
    9797  lastPacketTick = tick;
    98  
     98
    9999  // calculate ping
    100100  if ( sentStateTicks.find( ackedState ) != sentStateTicks.end() )
     
    102102    ackDelay.push_back( tick - sentStateTicks[ackedState] );
    103103  }
    104  
     104
    105105  while ( sentStateTicks.begin() != sentStateTicks.end() && sentStateTicks.begin()->first <= ackedState )
    106106    sentStateTicks.erase( sentStateTicks.begin() );
    107      
     107
    108108  while ( ackDelay.size() > N_PACKETS_FOR_PING )
    109109    ackDelay.erase( ackDelay.begin() );
    110      
     110
    111111  ping = 0;
    112      
     112
    113113  for ( std::list<int>::iterator it = ackDelay.begin(); it != ackDelay.end(); it++ )
    114114    ping += *it;
    115      
     115
    116116  if ( ackDelay.size() == 0 )
    117117    ping = -1;
    118118  else
    119119    ping /= ackDelay.size();
    120      
     120
    121121  //NETPRINTF(n)("PING: user: %d ping: %d\n", userId, ping );
    122  
     122
    123123  // calculate bandwidth
    124124  incomingUnzippedPacketHistory[tick] = length;
    125125  incomingUnzippedBandWidth = calculateBandWidth( incomingUnzippedPacketHistory, tick );
    126  
     126
    127127  //NETPRINTF(n)("UNZIPPED DOWNSTREAM: user: %d bandwidth %f\n", userId, incomingUnzippedBandWidth );
    128  
     128
    129129}
    130130
    131131/**
    132132 * remove old packets
    133  * @param packetHistory 
    134  * @param tick 
     133 * @param packetHistory
     134 * @param tick
    135135 */
    136136void ConnectionMonitor::removeOldPackets( std::map< int, int > & packetHistory, int tick )
     
    149149{
    150150  removeOldPackets( packetHistory, tick );
    151  
     151
    152152  float res = 0.0f;
    153153#if 0
     
    157157      res += it->second;
    158158  }
    159  
     159
    160160  if ( packetHistory.size() <= 1 || tick - packetHistory.begin()->first == 0 )
    161161    res = 0.0f;
    162162  else
    163163    res /= (float)(tick - packetHistory.begin()->first);
    164  
     164
    165165  res *= 1000.0f;
    166166#endif
    167167
    168   for ( std::map<int,int>::iterator it = packetHistory.begin(); it != packetHistory.end(); it++ )
     168  for ( std::map<int,int>::const_iterator it = packetHistory.begin(); it != packetHistory.end(); it++ )
    169169  {
    170170    res += it->second;
    171171  }
    172  
     172
    173173  if ( packetHistory.size() <= 1 )
    174174    res = 0.0f;
    175175  else
    176176    res /= (float)(tick - packetHistory.begin()->first);
    177  
     177
    178178  res *= 1000.0f;
    179179
     
    191191{
    192192  nZOutgoingPackets++;
    193  
     193
    194194  // calculate bandwidth
    195195  outgoingZippedPacketHistory[tick] = length;
    196196  outgoingZippedBandWidth = calculateBandWidth( outgoingZippedPacketHistory, tick );
    197  
     197
    198198  //NETPRINTF(n)("UPSTREAM: user: %d bandwidth %f nOutgoingPackets %d\n", userId, outgoingZippedBandWidth, nOutgoingPackets );
    199199
     
    216216{
    217217  nZIncomingPackets++;
    218  
     218
    219219  // calculate bandwidth
    220220  incomingZippedPacketHistory[tick] = length;
    221221  incomingZippedBandWidth = calculateBandWidth( incomingZippedPacketHistory, tick );
    222  
     222
    223223  //NETPRINTF(n)("DOWNSTREAM: user: %d bandwidth %f nIncomingPackets %d\n", userId, incomingZippedBandWidth, nIncomingPackets );
    224  
     224
    225225}
    226226
     
    230230 * @return true if last packet recieved \< NOW() - SECS_TO_TIMEOUT
    231231 */
    232 bool ConnectionMonitor::hasTimedOut( )
     232bool ConnectionMonitor::hasTimedOut( ) const
    233233{
    234234  if ( lastPacketTick + SECS_TO_TIMEOUT*1000 < SDL_GetTicks() && nIncomingPackets > 0 )
    235235    return true;
    236  
     236
    237237  if ( nIncomingPackets == 0 && nOutgoingPackets >= NETWORK_FREQUENCY*SECS_TO_TIMEOUT )
    238238    return true;
    239  
     239
    240240  return false;
    241241}
     
    246246 * prints bandwith usage, ping and other important things to telnet-console
    247247 */
    248 void ConnectionMonitor::printStatis( )
     248void ConnectionMonitor::printStatis( ) const
    249249{
    250250  NETPRINT(n)("============NETWORKSTATS FOR USER %d============\n", userId);
  • trunk/src/lib/network/monitor/connection_monitor.h

    r9406 r9494  
    3131    void calculatePing();
    3232
    33     bool hasTimedOut();
     33    bool hasTimedOut() const;
    3434
    35     void printStatis();
     35    void printStatis() const;
     36    float getIncomingUnzippedBandWidth() const { return incomingUnzippedBandWidth; }
     37    float getOutgoingUnzippedBandWidth() const { return outgoingUnzippedBandWidth; }
     38    float getIncomingZippedBandWidth() const { return incomingZippedBandWidth; }
     39    float getOutgoingZippedBandWidth() const { return outgoingZippedBandWidth; }
    3640
    3741  private:
  • trunk/src/lib/network/monitor/network_monitor.cc

    r9406 r9494  
    3131
    3232
    33 SHELL_COMMAND(showGUI, NetworkMonitor, showGUI);
    34 SHELL_COMMAND(hideGUI, NetworkMonitor, hideGUI);
     33#include "network_stats_widget.h"
     34
     35SHELL_COMMAND(gui, NetworkMonitor, toggleGUI)
     36 ->setAlias("ProxyGui");
    3537SHELL_COMMAND(debug, NetworkMonitor, debug);
    3638
     
    5759  {
    5860    // assuming that the config files are already read we get the proxy servers
    59     std::vector<IPaddress*>* proxyList = NetworkSettings::getInstance()->getProxyList();
    60     std::vector<IPaddress*>::iterator it = proxyList->begin();
     61    std::vector<IP>* proxyList = NetworkSettings::getInstance()->getProxyList();
     62    std::vector<IP>::iterator it = proxyList->begin();
    6163    // create a peer info class and a network node class for each new proxy and add them to the passive list
    6264    for(; it < proxyList->end(); it++)
    6365    {
    6466      PeerInfo* peer = new PeerInfo();
    65       peer->ip = *(*it);
     67      peer->ip = (*it);
    6668      peer->nodeType = NET_PROXY_SERVER_ACTIVE;
    6769      peer->userId = -1;
     
    7274    }
    7375  }
     76  this->box = NULL;
    7477}
    7578
     
    119122 * @param ip ip of the new node
    120123 */
    121 void NetworkMonitor::addNode(IP ip, int nodeType)
     124void NetworkMonitor::addNode(const IP& ip, int nodeType)
    122125{
    123126  PeerInfo* pInfo = new PeerInfo();
     
    140143  if( pInfo->isClient())
    141144    this->localNode->addClient(pInfo);
    142   else if( pInfo->isProxyServer())
     145  else if( pInfo->isProxyServerActive())
    143146  {
    144147    this->localNode->addActiveProxyServer(pInfo);
     
    166169  if( pInfo->isClient())
    167170    node->addClient(pInfo);
    168   else if( pInfo->isProxyServer())
     171  else if( pInfo->isProxyServerActive())
    169172    node->addActiveProxyServer(pInfo);
    170173  else if( pInfo->isMasterServer())
     
    176179 * @returns the proxy server of the first choice
    177180 */
    178 PeerInfo* NetworkMonitor::getFirstChoiceProxy()
     181PeerInfo* NetworkMonitor::getFirstChoiceProxy() const
    179182{
    180183  // return the fist proxy in the list
     
    186189 * @returns the proxy server of second choice
    187190 */
    188 PeerInfo* NetworkMonitor::getSecondChoiceProxy()
     191PeerInfo* NetworkMonitor::getSecondChoiceProxy() const
    189192{
    190193  // return the second server in the list
     
    196199 * this displays the network monitor gui
    197200 */
    198 void NetworkMonitor::showGUI()
     201void NetworkMonitor::toggleGUI()
    199202{
    200203  if (this->box == NULL)
     
    202205    this->box = new OrxGui::GLGuiBox(OrxGui::Vertical);
    203206    {
    204       OrxGui::GLGuiBox* waterColorBox = new OrxGui::GLGuiBox(OrxGui::Horizontal);
    205       {
    206         OrxGui::GLGuiText* waterColorText = new OrxGui::GLGuiText();
    207         waterColorText->setText("NetworkMonitor");
    208         waterColorBox->pack(waterColorText);
    209       }
    210       this->box->pack(waterColorBox);
     207      NetworkStatsWidget* netStats = new NetworkStatsWidget(this);
     208      this->box->pack(netStats);
     209
    211210    }
    212211
    213212    this->box->showAll();
    214213    this->box->setAbsCoor2D(300, 40);
    215     OrxGui::GLGuiHandler::getInstance()->activate();
    216 //     OrxGui::GLGuiHandler::getInstance()->activateCursor();
    217   }
    218 }
    219 
    220 
    221 /**
    222  * hides the network monitor gui again
    223  */
    224 void NetworkMonitor::hideGUI()
    225 {
    226   if( this->box == NULL)
    227     return;
    228 
    229   OrxGui::GLGuiHandler::getInstance()->deactivate();
    230 //   OrxGui::GLGuiHandler::getInstance()->deactivateCursor();
    231 
    232   delete this->box;
    233   this->box = NULL;
    234 }
    235 
     214  }
     215  else
     216  {
     217    delete this->box;
     218    this->box = NULL;
     219  }
     220}
    236221
    237222/**
     
    255240 * prints out the debug informations
    256241 */
    257 void NetworkMonitor::debug()
     242void NetworkMonitor::debug() const
    258243{
    259244  PRINT(0)("================================= Network Monitor::debug() =====\n");
    260245  PRINT(0)(" I am: %s\n", this->localNode->getPeerInfo()->getNodeTypeString().c_str());
    261   PRINT(0)(" Total count of network connections: %i\n", this->playerNumber);
     246  PRINT(0)(" Total count of network connections: %i\n", this->connectionNumber);
     247  PRINT(0)(" Total count of players: %i\n", this->playerNumber);
    262248  PRINT(0)(" Max players on this server: %i\n", SharedNetworkData::getInstance()->getMaxPlayer());
    263249
    264   std::list<NetworkNode*>::iterator it = this->nodeList.begin();
     250  std::list<NetworkNode*>::const_iterator it = this->nodeList.begin();
    265251  for(; it != this->nodeList.end(); it++)
    266252  {
  • trunk/src/lib/network/monitor/network_monitor.h

    r9406 r9494  
    3737
    3838    void addNode(PeerInfo* pInfo);
    39     void addNode(IP ip, int nodeType);
     39    void addNode(const IP& ip, int nodeType);
    4040    void addNode(NetworkNode* node) { this->nodeList.push_back(node); }
    4141    void addNode(NetworkNode* node, PeerInfo* pInfo);
     
    5555    inline void removeMasterServer(NetworkNode* node, PeerInfo* pInfo) { node->removeMasterServer(pInfo); }
    5656
    57     PeerInfo* getFirstChoiceProxy();
    58     PeerInfo* getSecondChoiceProxy();
     57    PeerInfo* getFirstChoiceProxy() const;
     58    PeerInfo* getSecondChoiceProxy() const;
     59    /** @returns the local node */
     60    inline NetworkNode* getLocalNode() const { return this->localNode; };
    5961
    6062    /** @returns the active proxy server list of the localnode */
    61     inline std::list<PeerInfo*> getActiveProxyServer() { return this->localNode->getActiveProxyServer(); }
     63    inline std::list<PeerInfo*> getActiveProxyServer() const { return this->localNode->getActiveProxyServer(); }
    6264
    6365    /* slots admin and info interface */
    6466    /** @returns the total number of players in this game (including all proxy servers etc)*/
    65     inline int getPlayerNumber() { return this->playerNumber; }
     67    inline int getPlayerNumber() const { return this->playerNumber; }
    6668
    6769    /** @returns true if there are still free network slots available at the local node*/
    68     inline bool gotFreeSlots() { return (this->localNode->getPlayerNumber() < SharedNetworkData::getInstance()->getMaxPlayer())?true:false; }
     70    inline bool gotFreeSlots() const { return (this->localNode->getPlayerNumber() < SharedNetworkData::getInstance()->getMaxPlayer()); }
    6971    /** @param node node to be checked for slots @returns true if there are still free network slots available at this node */
    70     inline bool gotFreeSlots(NetworkNode* node) { return (node->getPlayerNumber() < SharedNetworkData::getInstance()->getMaxPlayer())?true:false; }
     72    inline bool gotFreeSlots(NetworkNode* node) const { return (node->getPlayerNumber() < SharedNetworkData::getInstance()->getMaxPlayer()); }
    7173
    7274    /** @returns true if the next client should be reconnected to some other proxy server with more connections */
    73     inline bool isReconnectNextClient() { return (this->localNode->getPlayerNumber() >= SharedNetworkData::getInstance()->getMaxPlayer())?true:false; }
     75    inline bool isReconnectNextClient() const { return (this->localNode->getPlayerNumber() >= SharedNetworkData::getInstance()->getMaxPlayer()); }
    7476
     77    inline const std::list<NetworkNode*>& getNodeList() const { return this->nodeList; };
    7578
    76     void showGUI();
    77     void hideGUI();
     79    void toggleGUI();
    7880
    7981    void process();
    80     void debug();
     82    void debug() const;
    8183
    8284
  • trunk/src/lib/network/monitor/network_node.cc

    r9406 r9494  
    152152 * @return the client in the list or NULL if none
    153153 */
    154 PeerInfo* NetworkNode::getClient(int index)
     154PeerInfo* NetworkNode::getClient(int index) const
    155155{
    156156  if( this->clientList.size() < index)
    157157    return NULL;
    158158
    159   std::list<PeerInfo*>::iterator it = this->clientList.begin();
     159  std::list<PeerInfo*>::const_iterator it = this->clientList.begin();
    160160  for(int i = 0; it != this->clientList.end(); it++, i++)
    161161  {
     
    172172 * @return the active proxy server in the list or NULL if none
    173173 */
    174 PeerInfo* NetworkNode::getActiveProxyServer(int index)
     174PeerInfo* NetworkNode::getActiveProxyServer(int index) const
    175175{
    176176  if( this->activeProxyServerList.size() < index)
    177177    return NULL;
    178178
    179   std::list<PeerInfo*>::iterator it = this->activeProxyServerList.begin();
     179  std::list<PeerInfo*>::const_iterator it = this->activeProxyServerList.begin();
    180180  for(int i = 0; it != this->activeProxyServerList.end(); it++, i++)
    181181  {
     
    192192 * @return the passive proxy server in the list or NULL if none
    193193 */
    194 PeerInfo* NetworkNode::getPassiveProxyServer(int index)
     194PeerInfo* NetworkNode::getPassiveProxyServer(int index) const
    195195{
    196196  if( this->passiveProxyServerList.size() < index)
    197197    return NULL;
    198198
    199   std::list<PeerInfo*>::iterator it = this->passiveProxyServerList.begin();
     199  std::list<PeerInfo*>::const_iterator it = this->passiveProxyServerList.begin();
    200200  for(int i = 0; it != this->passiveProxyServerList.end(); it++, i++)
    201201  {
     
    212212 * @return the master server in the list or NULL if none
    213213 */
    214 PeerInfo* NetworkNode::getMasterServer(int index)
     214PeerInfo* NetworkNode::getMasterServer(int index) const
    215215{
    216216  if( this->masterServerList.size() < index)
    217217    return NULL;
    218218
    219   std::list<PeerInfo*>::iterator it = this->masterServerList.begin();
     219  std::list<PeerInfo*>::const_iterator it = this->masterServerList.begin();
    220220  for(int i = 0; it != this->masterServerList.end(); it++, i++)
    221221  {
     
    232232 * @param depth: depth in the tree
    233233 */
    234 void NetworkNode::debug(int depth)
     234void NetworkNode::debug(int depth) const
    235235{
    236236  PRINT(0)(" = %s\n", this->peerInfo->getNodeTypeString().c_str());
    237237
    238238  PRINT(0)("    master servers: %i\n", this->masterServerList.size());
    239   std::list<PeerInfo*>::iterator it = this->masterServerList.begin();
     239  std::list<PeerInfo*>::const_iterator it = this->masterServerList.begin();
    240240  for(; it != this->masterServerList.end(); it++)
    241241  {
  • trunk/src/lib/network/monitor/network_node.h

    r9406 r9494  
    3232    void removeMasterServer(PeerInfo* node);
    3333
    34     PeerInfo* getClient(int index);
    35     PeerInfo* getActiveProxyServer(int index);
    36     PeerInfo* getPassiveProxyServer(int index);
    37     PeerInfo* getMasterServer(int index);
     34    PeerInfo* getClient(int index) const;
     35    PeerInfo* getActiveProxyServer(int index) const;
     36    PeerInfo* getPassiveProxyServer(int index) const;
     37    PeerInfo* getMasterServer(int index) const;
    3838
    3939    /** @returns the master server list */
    40     inline std::list<PeerInfo*> getMasterServer() { return this->masterServerList; }
     40    inline std::list<PeerInfo*> getMasterServer() const { return this->masterServerList; }
    4141    /** @returns the active proxy server list */
    42     inline std::list<PeerInfo*> getActiveProxyServer() { return this->activeProxyServerList; }
     42    inline std::list<PeerInfo*> getActiveProxyServer() const { return this->activeProxyServerList; }
    4343    /** @returns the passive proxy server list */
    44     inline std::list<PeerInfo*> getPassiveProxyServer() { return this->passiveProxyServerList; }
     44    inline std::list<PeerInfo*> getPassiveProxyServer() const { return this->passiveProxyServerList; }
    4545    /** @returns the client list */
    46     inline std::list<PeerInfo*> getClient() { return this->clientList; }
     46    inline std::list<PeerInfo*> getClient() const { return this->clientList; }
    4747
    4848
    4949    /** @returns the number of players */
    50     inline int getPlayerNumber() { return this->playerNumber; }
     50    inline int getPlayerNumber() const { return this->playerNumber; }
    5151    /** @returns the node type of this node */
    52     inline int getNodeType() { return this->peerInfo->nodeType; }
     52    inline int getNodeType() const { return this->peerInfo->nodeType; }
    5353    /** @returns the peer info of this node */
    54     inline PeerInfo* getPeerInfo() { return this->peerInfo; }
     54    inline PeerInfo* getPeerInfo() const { return this->peerInfo; }
    5555
    56     void debug(int depth);
     56    void debug(int depth) const;
    5757
    5858
     
    6060    int                          playerNumber;                 //!< localy direct connected player number
    6161    int                          connectionNumber;             //!< number of connections ( can but musn't be equal players)
    62     PeerInfo*                    peerInfo;                     //!< the peer informationa about this node
     62    PeerInfo*                    peerInfo;                     //!< the peer information about this node
    6363
    6464    /* network nodes directly connected to this node */
  • trunk/src/lib/network/netdefs.h

    r9406 r9494  
    4343
    4444
     45
     46
    4547//!< enum indicating the type of the node
    4648typedef enum {
    47   NET_MASTER_SERVER,
     49  NET_UNASSIGNED              = -1,
     50
     51  NET_MASTER_SERVER           =  0,
    4852  NET_PROXY_SERVER_ACTIVE,
    4953  NET_PROXY_SERVER_PASSIVE,
     
    5458} NodeType;
    5559
     60
    5661//!< enum indicating the type of the network connection (2 protocols supported)
    5762typedef enum ConnectionType {
     
    6065};
    6166
    62 //!< the type of the user id (special number never used elsewhere)
     67
     68//!< the type of the unique id (special number never used elsewhere)
    6369typedef enum {
    6470  NET_UID_UNASSIGNED = -1,
     71
     72  NET_UID_HANDSHAKE  =  0,
     73
    6574
    6675  NET_UID_NUMBER
    6776} UidType;
    6877
     78
     79//!< the network id list
     80typedef enum nodeId {
     81  NET_ID_UNASSIGNED       =-1,
     82
     83  NET_ID_MASTER_SERVER    = 0,
     84
     85  NET_ID_PROXY_SERVER_01  = 1,
     86  NET_ID_PROXY_SERVER_02,
     87  NET_ID_PROXY_SERVER_03,
     88  NET_ID_PROXY_SERVER_04,
     89  NET_ID_PROXY_SERVER_05,
     90  NET_ID_PROXY_SERVER_06,
     91  NET_ID_PROXY_SERVER_07,
     92  NET_ID_PROXY_SERVER_08  = 8,
     93
     94  NET_ID_PROXY_MAX        = 8,
     95
     96  NET_ID_CLIENT_01        = 9,
     97  NET_ID_CLIENT_02,
     98  NET_ID_CLIENT_03,
     99  NET_ID_CLIENT_04,
     100  NET_ID_CLIENT_05,
     101  NET_ID_CLIENT_06,
     102  NET_ID_CLIENT_07,
     103  NET_ID_CLIENT_08,
     104  NET_ID_CLIENT_09,
     105  NET_ID_CLIENT_10,
     106  NET_ID_CLIENT_11,
     107  NET_ID_CLIENT_12,
     108  NET_ID_CLIENT_13,
     109  NET_ID_CLIENT_14,
     110  NET_ID_CLIENT_15,
     111  NET_ID_CLIENT_16,
     112  NET_ID_CLIENT_17,
     113  NET_ID_CLIENT_18,
     114  NET_ID_CLIENT_19,
     115  NET_ID_CLIENT_20,
     116  NET_ID_CLIENT_21,
     117  NET_ID_CLIENT_22,
     118  NET_ID_CLIENT_23,
     119  NET_ID_CLIENT_24,
     120  NET_ID_CLIENT_25,
     121  NET_ID_CLIENT_26,
     122  NET_ID_CLIENT_27,
     123  NET_ID_CLIENT_28,
     124  NET_ID_CLIENT_29,
     125  NET_ID_CLIENT_30,
     126  NET_ID_CLIENT_31,
     127  NET_ID_CLIENT_32,
     128  NET_ID_CLIENT_33,
     129  NET_ID_CLIENT_34,
     130  NET_ID_CLIENT_35,
     131  NET_ID_CLIENT_36,
     132  NET_ID_CLIENT_37,
     133  NET_ID_CLIENT_38,
     134  NET_ID_CLIENT_39,
     135  NET_ID_CLIENT_40,
     136
     137  NET_ID_CLIENT_MAX        = 40
     138};
    69139#endif /* _NETDEFS_H */
  • trunk/src/lib/network/nettypes.h

    r9406 r9494  
    55typedef unsigned char byte;
    66
     7
     8//!< this are the network write variable permissions
     9typedef enum netPermissions {
     10  PERMISSION_MASTER_SERVER = 1,
     11  PERMISSION_PROXY_SERVER  = 2,
     12  PERMISSION_OWNER         = 4,
     13  PERMISSION_ALL           = 8
     14};
     15
     16
    717#endif /* __NET_TYPES_H */
  • trunk/src/lib/network/network_game_manager.cc

    r9406 r9494  
    9191bool NetworkGameManager::signalNewPlayer( int userId )
    9292{
    93   assert( SharedNetworkData::getInstance()->isMasterServer() ||  SharedNetworkData::getInstance()->isProxyServer());
     93  assert( SharedNetworkData::getInstance()->isMasterServer() ||  SharedNetworkData::getInstance()->isProxyServerActive());
    9494  assert( State::getGameRules() );
    9595  assert( State::getGameRules()->isA( CL_NETWORK_GAME_RULES ) );
     
    168168bool NetworkGameManager::delSynchronizeableHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId )
    169169{
    170   if ( SharedNetworkData::getInstance()->isMasterServer() ||  SharedNetworkData::getInstance()->isProxyServer())
    171   {
    172     PRINTF(2)("Recieved DeleteSynchronizeable message from client %d!\n", userId);
     170
     171  PRINTF(0)(" del synchronizeable\n");
     172
     173  if ( SharedNetworkData::getInstance()->isMasterServer() ||
     174       SharedNetworkData::getInstance()->isProxyServerActive() && SharedNetworkData::getInstance()->isUserClient(userId))
     175  {
     176    PRINTF(0)("Recieved DeleteSynchronizeable message from client %d!\n", userId);
    173177    return true;
    174178  }
     
    213217  assert( Converter::intToByteArray( uniqueId, buf, INTSIZE ) == INTSIZE );
    214218
    215   MessageManager::getInstance()->sendMessage( MSGID_DELETESYNCHRONIZEABLE, buf, INTSIZE, RT_ALL_NOT_ME, 0, MP_HIGHBANDWIDTH );
     219  MessageManager::getInstance()->sendMessage( MSGID_DELETESYNCHRONIZEABLE, buf, INTSIZE, RT_ALL_BUT_ME, 0, MP_HIGHBANDWIDTH );
    216220}
    217221
     
    229233bool NetworkGameManager::preferedTeamHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId )
    230234{
    231   assert( SharedNetworkData::getInstance()->isMasterServer() ||  SharedNetworkData::getInstance()->isProxyServer());
     235  assert( SharedNetworkData::getInstance()->isMasterServer() ||  SharedNetworkData::getInstance()->isProxyServerActive());
    232236
    233237  int teamId = 0;
     
    261265void NetworkGameManager::prefereTeam( int teamId )
    262266{
    263   if ( SharedNetworkData::getInstance()->isMasterServer() || SharedNetworkData::getInstance()->isProxyServer())
     267  if ( SharedNetworkData::getInstance()->isMasterServer() /*|| SharedNetworkData::getInstance()->isProxyServerActive()*/)
    264268    setPreferedTeam( SharedNetworkData::getInstance()->getHostID(), teamId );
    265269  else
     
    305309{
    306310  PRINTF(0)("NetworkGameManager::chatMessageHandler %d %d\n", userId, SharedNetworkData::getInstance()->getHostID() );
    307   if ( (SharedNetworkData::getInstance()->isMasterServer() || SharedNetworkData::getInstance()->isProxyServer()) && userId !=  SharedNetworkData::getInstance()->getHostID() )
    308   {
    309     MessageManager::getInstance()->sendMessage( messageId, data, dataLength, RT_ALL_NOT_ME, 0, MP_HIGHBANDWIDTH );
     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 );
    310314  }
    311315
     
    347351  assert( Converter::stringToByteArray(message, buf+2*INTSIZE, message.length()+INTSIZE) == message.length()+INTSIZE );
    348352
    349   if ( SharedNetworkData::getInstance()->isMasterServer() || SharedNetworkData::getInstance()->isProxyServer())
     353  if ( SharedNetworkData::getInstance()->isMasterServer() /*|| SharedNetworkData::getInstance()->isProxyServerActive()*/)
    350354    MessageManager::getInstance()->sendMessage( MSGID_CHATMESSAGE, buf, message.length()+3*INTSIZE, RT_ALL_ME, 0, MP_HIGHBANDWIDTH );
    351355  else
    352     MessageManager::getInstance()->sendMessage( MSGID_CHATMESSAGE, buf, message.length()+3*INTSIZE, RT_ALL_NOT_ME, 0, MP_HIGHBANDWIDTH );
     356    MessageManager::getInstance()->sendMessage( MSGID_CHATMESSAGE, buf, message.length()+3*INTSIZE, RT_ALL_BUT_ME, 0, MP_HIGHBANDWIDTH );
    353357
    354358
  • trunk/src/lib/network/network_manager.cc

    r9406 r9494  
    101101/**
    102102 *  creates a new NetworkStream of server type
    103  * @param port: number of the TCP port
     103 * @param clientPort: number of the TCP/UDP port for client connections
     104 * @param proxyPort: number of the TCP/UDP port for proxy connections
    104105 */
    105106int NetworkManager::createMasterServer(unsigned int port)
     
    110111  // create the network stream
    111112  this->networkStream = new NetworkStream(NET_MASTER_SERVER);
    112   this->networkStream->createServer( port);
     113  this->networkStream->createServer( port, port + 1);
    113114
    114115  // start the network game manager
     
    129130  NetworkSettings::getInstance()->loadData();
    130131
    131   // create the network stream
    132   this->networkStream = new NetworkStream(NET_PROXY_SERVER_ACTIVE);
    133   this->networkStream->createServer( port);
    134   // and connect to the master server for synchronization
    135 //   this->networkStream->connectToMasterServer(NetworkSettings::getInstance()->getMasterAddr());
    136   // and to the other proxy servers
    137 
     132  // create the network stream af
     133  this->networkStream = new NetworkStream(NET_PROXY_SERVER_ACTIVE );
     134  // first connect to the master server for synchronization
     135  this->networkStream->connectToMasterServer(NetworkSettings::getInstance()->getMasterAddr().ipString(), 10000);
     136  // start the handshake with the master server
     137  this->networkStream->startHandshake(NET_ID_MASTER_SERVER);
     138
     139  // then start the server
     140  this->networkStream->createServer( port, port +1);
     141
     142
     143  // and to the other proxy servers also, this would be very nice if its works
    138144
    139145
    140146  // start the network game manager
    141   this->networkStream->createNetworkGameManager();
     147  //this->networkStream->createNetworkGameManager();
    142148
    143149
     
    165171  this->networkStream->startHandshake();
    166172
    167   PRINTF(0)("Created Network Client");
     173  PRINTF(0)("Created Network Client\n");
    168174  return 1;
    169175}
  • trunk/src/lib/network/network_manager.h

    r9406 r9494  
    1717
    1818
    19 /* forward declarations for the header file (include the header via #include "bla.h" in the source file) */
     19
    2020class NetworkStream;
    2121class Synchronizeable;
    22 template<typename>
    23 class tList;
     22
    2423
    2524/* and here is the class itsself*/
  • trunk/src/lib/network/network_stream.cc

    r9406 r9494  
    6565  this->init();
    6666  /* initialize the references */
    67   this->pInfo->nodeType = NET_CLIENT;
     67  this->pInfo->nodeType = NET_UNASSIGNED;
    6868}
    6969
     
    7979    case NET_MASTER_SERVER:
    8080      // init the shared network data
    81       SharedNetworkData::getInstance()->setHostID(0);
    82 //       SharedNetworkData::getInstance()->setNodeType(NET_MASTER_SERVER);
     81      SharedNetworkData::getInstance()->setHostID(NET_ID_MASTER_SERVER);
    8382      break;
    84 
    8583    case NET_PROXY_SERVER_ACTIVE:
    8684      // init the shared network data
    87       SharedNetworkData::getInstance()->setHostID(0);
    88 //       SharedNetworkData::getInstance()->setNodeType(NET_PROXY_SERVER_ACTIVE);
     85      SharedNetworkData::getInstance()->setHostID(NET_ID_PROXY_SERVER_01);
    8986      break;
    9087    case NET_PROXY_SERVER_PASSIVE:
    91             // init the shared network data
    92       SharedNetworkData::getInstance()->setHostID(0);
    93 //       SharedNetworkData::getInstance()->setNodeType(NET_PROXY_SERVER_PASSIVE);
     88      // init the shared network data
     89      SharedNetworkData::getInstance()->setHostID(NET_ID_PROXY_SERVER_01);
    9490      break;
    9591    case NET_CLIENT:
    96 //       SharedNetworkData::getInstance()->setNodeType(NET_CLIENT);
     92      SharedNetworkData::getInstance()->setHostID(NET_ID_UNASSIGNED);
    9793      break;
    9894  }
     
    115111  /* set the class id for the base object */
    116112  this->setClassID(CL_NETWORK_STREAM, "NetworkStream");
    117   this->serverSocket = NULL;
     113  this->clientSocket = NULL;
     114  this->proxySocket = NULL;
    118115  this->networkGameManager = NULL;
    119116  this->networkMonitor = NULL;
     
    124121  this->pInfo->lastRecvedState = 0;
    125122
     123  this->bRedirect = false;
    126124
    127125  this->currentState = 0;
     
    142140NetworkStream::~NetworkStream()
    143141{
    144   if ( this->serverSocket )
    145   {
    146     serverSocket->close();
    147     delete serverSocket;
    148     serverSocket = NULL;
     142  if ( this->clientSocket )
     143  {
     144    clientSocket->close();
     145    delete clientSocket;
     146    clientSocket = NULL;
     147  }
     148  if ( this->proxySocket)
     149  {
     150    proxySocket->close();
     151    delete proxySocket;
     152    proxySocket = NULL;
    149153  }
    150154  for ( PeerList::iterator i = peers.begin(); i!=peers.end(); i++)
     
    187191void NetworkStream::connectToMasterServer(std::string host, int port)
    188192{
    189   int node = this->peers.size();
     193  int node = NET_ID_MASTER_SERVER;
     194  // this create the new node in the peers map
    190195  this->peers[node].socket = new UdpSocket( host, port );
    191   this->peers[node].userId = 0;
     196  this->peers[node].userId = NET_ID_MASTER_SERVER;
    192197
    193198  this->peers[node].nodeType = NET_MASTER_SERVER;
    194   this->peers[node].connectionMonitor = new ConnectionMonitor( 0 );
     199  this->peers[node].connectionMonitor = new ConnectionMonitor( NET_ID_MASTER_SERVER );
    195200  this->peers[node].ip = this->peers[node].socket->getRemoteAddress();
    196201}
     
    202207 * @param port: the port number
    203208 */
    204 void NetworkStream::connectToProxyServer(std::string host, int port)
    205 {
    206   int node = this->peers.size();
    207   this->peers[node].socket = new UdpSocket( host, port );
    208   this->peers[node].userId = 0;
    209 
    210   this->peers[node].nodeType = NET_PROXY_SERVER_ACTIVE;
    211   this->peers[node].connectionMonitor = new ConnectionMonitor( 0 );
    212   this->peers[node].ip = this->peers[node].socket->getRemoteAddress();
     209void NetworkStream::connectToProxyServer(int proxyId, std::string host, int port)
     210{
     211  PRINTF(0)("connect to proxy %s, this is proxyId %i\n", host.c_str(), proxyId);
     212
     213  // this creates the new proxyId in the peers map
     214  this->peers[proxyId].socket = new UdpSocket( host, port );
     215  this->peers[proxyId].userId = proxyId;
     216
     217  this->peers[proxyId].nodeType = NET_PROXY_SERVER_ACTIVE;
     218  this->peers[proxyId].connectionMonitor = new ConnectionMonitor( proxyId );
     219  this->peers[proxyId].ip = this->peers[proxyId].socket->getRemoteAddress();
    213220}
    214221
     
    218225 * @param port: interface port for all clients
    219226 */
    220 void NetworkStream::createServer(int port)
    221 {
    222   this->serverSocket = new UdpServerSocket(port);
     227void NetworkStream::createServer(int clientPort, int proxyPort)
     228{
     229  PRINTF(0)(" Creating new Server: listening for clients on port %i and for proxies on port %i", clientPort, proxyPort);
     230  this->clientSocket= new UdpServerSocket(clientPort);
     231  this->proxySocket = new UdpServerSocket(proxyPort);
    223232}
    224233
     
    240249 * handsakes are always initialized from the client side first. this starts the handshake and therefore is only
    241250 * executed as client
    242  */
    243 void NetworkStream::startHandshake()
     251 * @param userId: start handshake for this user id (optional, default == 0)
     252 */
     253void NetworkStream::startHandshake(int userId)
    244254{
    245255  Handshake* hs = new Handshake(this->pInfo->nodeType);
    246   hs->setUniqueID( 0 );
    247   assert( peers[0].handshake == NULL );
    248   peers[0].handshake = hs;
     256  // fake the unique id
     257  hs->setUniqueID( NET_UID_HANDSHAKE );
     258  assert( peers[userId].handshake == NULL );
     259  peers[userId].handshake = hs;
    249260
    250261  // set the preferred nick name
     
    259270 * it all over the network and creating it on the other platforms (if and only if it is a
    260271 * server
     272 * @param sync: the synchronizeable to add
    261273 */
    262274void NetworkStream::connectSynchronizeable(Synchronizeable& sync)
     
    264276  this->synchronizeables.push_back(&sync);
    265277  sync.setNetworkStream( this );
    266 
    267 //   this->bActive = true;
    268278}
    269279
     
    271281/**
    272282 * removes the synchronizeable from the list of synchronized entities
     283 * @param sync: the syncronizeable to remove
    273284 */
    274285void NetworkStream::disconnectSynchronizeable(Synchronizeable& sync)
     
    302313  }
    303314
    304   if ( this->pInfo->isMasterServer())
     315  if ( SharedNetworkData::getInstance()->isMasterServer())
    305316  {
    306317    // execute everytthing the master server shoudl do
    307     if ( serverSocket )
    308       serverSocket->update();
     318    if ( this->clientSocket )
     319      this->clientSocket->update();
     320    if( this->proxySocket)
     321      this->proxySocket->update();
    309322
    310323    this->updateConnectionList();
    311324  }
    312   else if( this->pInfo->isProxyServer())
    313   {
    314     // execute everything the proxy server should do
    315     if ( serverSocket )
    316       serverSocket->update();
     325  else if( SharedNetworkData::getInstance()->isProxyServerActive())
     326  {
     327    //execute everything the proxy server should do
     328    if ( this->clientSocket )
     329      this->clientSocket->update();
     330    if( this->proxySocket)
     331      this->proxySocket->update();
    317332
    318333    this->updateConnectionList();
    319334  }
    320   else
     335
     336#warning make this more modular: every proxy/master server connection should be watched for termination
     337  if( !SharedNetworkData::getInstance()->isMasterServer())
    321338  {
    322339    // check if the connection is ok else terminate and remove
    323     if ( peers[0].socket && ( !peers[0].socket->isOk() || peers[0].connectionMonitor->hasTimedOut() ) )
    324     {
     340    if ( !peers.empty() && peers[NET_ID_MASTER_SERVER].socket &&
     341          ( !peers[NET_ID_MASTER_SERVER].socket->isOk() ||
     342          peers[NET_ID_MASTER_SERVER].connectionMonitor->hasTimedOut() ) )
     343    {
     344      this->handleDisconnect( NET_ID_MASTER_SERVER);
    325345      PRINTF(1)("lost connection to server\n");
    326 
    327       peers[0].socket->disconnectServer();
    328       delete peers[0].socket;
    329       peers[0].socket = NULL;
    330 
    331       if ( peers[0].handshake )
    332         delete peers[0].handshake;
    333       peers[0].handshake = NULL;
    334 
    335       if ( peers[0].connectionMonitor )
    336         delete peers[0].connectionMonitor;
    337       peers[0].connectionMonitor = NULL;
    338     }
    339   }
    340 
    341   cleanUpOldSyncList();
    342   handleHandshakes();
     346    }
     347    // check if there is a redirection command
     348    if( this->bRedirect)
     349    {
     350      this->handleReconnect( NET_ID_MASTER_SERVER);
     351    }
     352  }
     353
     354  this->cleanUpOldSyncList();
     355  this->handleHandshakes();
    343356
    344357  // update the network monitor
     
    347360  // order of up/downstream is important!!!!
    348361  // don't change it
    349   handleDownstream( tick );
    350   handleUpstream( tick );
    351 }
    352 
    353 
    354 /**
    355  * if we are a NET_MASTER_SERVER or NET_PROXY_SERVER_ACTIVE update the connection list to accept new
    356  * connections (clients) also start the handsake for the new clients
     362  this->handleDownstream( tick );
     363  this->handleUpstream( tick );
     364}
     365
     366
     367/**
     368 * @brief handles incoming connections
     369 *
     370 * if we are a NET_MASTER_SERVER or NET_PROXY_SERVER_ACTIVE update the connection list to accept new connections (clients)
     371 * start and initialize the handsake for the new clients
    357372 */
    358373void NetworkStream::updateConnectionList( )
     
    360375  //check for new connections
    361376
    362   NetworkSocket* tempNetworkSocket = serverSocket->getNewSocket();
    363 
    364   // we got new network node
    365   if ( tempNetworkSocket )
    366   {
    367     int clientId;
    368     // if there is a list of free client id slots, take these
    369     if ( freeSocketSlots.size() > 0 )
    370     {
    371       clientId = freeSocketSlots.back();
    372       freeSocketSlots.pop_back();
    373     }
    374     else
    375     {
    376       clientId = 1;
    377 
    378       for ( PeerList::iterator it = peers.begin(); it != peers.end(); it++ )
    379         if ( it->first >= clientId )
    380           clientId = it->first + 1;
    381     }
    382     peers[clientId].socket = tempNetworkSocket;
    383 
    384 
    385     // create new handshake and init its variables
    386     peers[clientId].handshake = new Handshake(this->pInfo->nodeType, clientId, this->networkGameManager->getUniqueID(), MessageManager::getInstance()->getUniqueID());
    387     peers[clientId].handshake->setUniqueID(clientId);
    388 
    389     peers[clientId].connectionMonitor = new ConnectionMonitor( clientId );
    390     peers[clientId].userId = clientId;
    391 
    392     PRINTF(0)("num sync: %d\n", synchronizeables.size());
    393 
    394     // get the proxy server informations and write them to the handshake, if any (proxy)
    395     assert( this->networkMonitor != NULL);
    396     PeerInfo* pi = this->networkMonitor->getFirstChoiceProxy();
    397     if( pi != NULL)
    398     {
    399       peers[clientId].handshake->setProxy1Address( pi->ip);
    400     }
    401     pi = this->networkMonitor->getSecondChoiceProxy();
    402     if( pi != NULL)
    403       peers[clientId].handshake->setProxy2Address( pi->ip);
    404 
    405     // check if the connecting client should reconnect to a proxy server
    406     peers[clientId].handshake->setRedirect(/*this->networkMonitor->isReconnectNextClient()*/false);
    407 
    408     // the connecting node of course is a client
    409     peers[clientId].nodeType = NET_CLIENT;
    410     peers[clientId].ip = peers[clientId].socket->getRemoteAddress();
    411 
    412 
    413     // check if there are too many clients connected (DEPRECATED: new: the masterserver sends a list of proxy servers)
    414 //     if ( clientId > SharedNetworkData::getInstance()->getMaxPlayer() )
    415 //     {
    416 // //       peers[clientId].handshake->setRedirect(true);
    417 // //
    418 // //       peers[clientId].handshake->doReject( "too many connections" );
    419 //       PRINTF(0)("Will reject client %d because there are to many connections!\n", clientId);
    420 //     }
    421 //     else
    422 //     {
    423 //       PRINTF(0)("New Client: %d\n", clientId);
    424 //     }
    425     PRINTF(0)("New Client: %d\n", clientId);
    426 
    427 
    428   }
    429 
     377  NetworkSocket* tempNetworkSocket = NULL;
     378  int userId;
     379
     380  if( this->clientSocket != NULL)
     381  {
     382    tempNetworkSocket = this->clientSocket->getNewSocket();
     383
     384    // we got new NET_CLIENT connecting
     385    if ( tempNetworkSocket )
     386    {
     387      // determine the network node id
     388      if ( freeSocketSlots.size() > 0 )
     389      {
     390        userId = freeSocketSlots.back();
     391        freeSocketSlots.pop_back();
     392      }
     393      else
     394      {
     395        userId = 1;
     396
     397        for ( PeerList::iterator it = peers.begin(); it != peers.end(); it++ )
     398          if ( it->first >= userId )
     399            userId = it->first + 1;
     400      }
     401      // this creates a new entry in the peers list
     402      peers[userId].socket = tempNetworkSocket;
     403      peers[userId].nodeType = NET_CLIENT;
     404
     405      // handle the newly connected client
     406      this->handleConnect(userId);
     407
     408      PRINTF(0)("New Client: %d\n", userId);
     409    }
     410  }
     411
     412
     413  if( this->proxySocket != NULL)
     414  {
     415    tempNetworkSocket = this->proxySocket->getNewSocket();
     416
     417    // we got new NET_PROXY_SERVER_ACTIVE connecting
     418    if ( tempNetworkSocket )
     419    {
     420      // determine the network node id
     421      if ( freeSocketSlots.size() > 0 )
     422      {
     423        userId = freeSocketSlots.back();
     424        freeSocketSlots.pop_back();
     425      }
     426      else
     427      {
     428        userId = 1;
     429
     430        for ( PeerList::iterator it = peers.begin(); it != peers.end(); it++ )
     431          if ( it->first >= userId )
     432            userId = it->first + 1;
     433      }
     434
     435      // this creates a new entry in the peers list
     436      peers[userId].socket = tempNetworkSocket;
     437      peers[userId].nodeType = NET_PROXY_SERVER_ACTIVE;
     438
     439      // handle the newly connected proxy server
     440      this->handleConnect(userId);
     441
     442      PRINTF(0)("New proxy connected: %d\n", userId);
     443    }
     444  }
    430445
    431446
     
    446461      PRINTF(0)("Client is gone: %d (%s)\n", it->second.userId, reason.c_str());
    447462
    448 
    449       // clean up the network data
    450       it->second.socket->disconnectServer();
    451       delete it->second.socket;
    452       it->second.socket = NULL;
    453 
    454       // remove the old connectin monitor
    455       if ( it->second.connectionMonitor )
    456         delete it->second.connectionMonitor;
    457       it->second.connectionMonitor = NULL;
    458 
    459       // remove the handshake
    460       if ( it->second.handshake )
    461         delete it->second.handshake;
    462       it->second.handshake = NULL;
    463 
    464       // and cleanup the user infos
    465       for ( SynchronizeableList::iterator it2 = synchronizeables.begin(); it2 != synchronizeables.end(); it2++ )
    466       {
    467         (*it2)->cleanUpUser( it->second.userId );
    468       }
    469 
    470       NetworkGameManager::getInstance()->signalLeftPlayer(it->second.userId);
    471 
    472       freeSocketSlots.push_back( it->second.userId );
    473 
    474       PeerList::iterator delit = it;
     463      this->handleDisconnect( it->second.userId);
     464
    475465      it++;
    476 
    477       peers.erase( delit );
    478 
    479466      continue;
    480467    }
     
    487474
    488475
     476/**
     477 * this handles new connections
     478 * @param userId: the id of the new user node
     479 */
     480void NetworkStream::handleConnect( int userId)
     481{
     482  // 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;
     488
     489  PRINTF(0)("num sync: %d\n", synchronizeables.size());
     490
     491  // get the proxy server informations and write them to the handshake, if any (proxy)
     492  assert( this->networkMonitor != NULL);
     493  PeerInfo* pi = this->networkMonitor->getFirstChoiceProxy();
     494  if( pi != NULL)
     495  {
     496    peers[userId].handshake->setProxy1Address( pi->ip);
     497  }
     498  pi = this->networkMonitor->getSecondChoiceProxy();
     499  if( pi != NULL)
     500    peers[userId].handshake->setProxy2Address( pi->ip);
     501
     502  // check if the connecting client should reconnect to a proxy server
     503  if( SharedNetworkData::getInstance()->isMasterServer())
     504    peers[userId].handshake->setRedirect(/*this->networkMonitor->isReconnectNextClient()*/false);
     505
     506  // the connecting node of course is a client
     507  peers[userId].ip = peers[userId].socket->getRemoteAddress();
     508}
     509
     510
     511
     512/**
     513 * some debug output
     514 */
    489515void NetworkStream::debug()
    490516{
     
    492518    PRINT(0)(" Host ist Master Server with ID: %i\n", this->pInfo->userId);
    493519  }
    494   else if( SharedNetworkData::getInstance()->isProxyServer()) {
     520  else if( SharedNetworkData::getInstance()->isProxyServerActive()) {
    495521    PRINT(0)(" Host ist Proxy Server with ID: %i\n", this->pInfo->userId);
    496522  }
     
    541567        if ( it->second.handshake->ok() )
    542568        {
    543           // the server gave it free for deletion
     569          // write the first informations into the node so they can be read from there for case differentiation
     570          it->second.nodeType = it->second.handshake->getRemoteNodeType();
     571
     572          // the counter part didn't mark it free for deletion yet
    544573          if ( !it->second.handshake->allowDel() )
    545574          {
    546 
    547             if ( this->pInfo->isClient() )
     575            // make sure this is a connection:
     576            // - client       <==> master server
     577            // - proxy server <==> master server
     578            if(  SharedNetworkData::getInstance()->isClient() || SharedNetworkData::getInstance()->isProxyServerActive() && it->second.isMasterServer())
    548579            {
     580              PRINTF(0)("Handshake: i am in client role\n");
     581
    549582              SharedNetworkData::getInstance()->setHostID( it->second.handshake->getHostId() );
    550583              this->pInfo->userId = SharedNetworkData::getInstance()->getHostID();
    551584
    552               it->second.nodeType = it->second.handshake->getRemoteNodeType();
    553               it->second.ip = it->second.socket->getRemoteAddress();
     585#warning the ip address is not set here because it results in a segfault when connecting to a proxy server => trace this later
     586//               it->second.ip = it->second.socket->getRemoteAddress();
     587
     588              // it->second.nodeType = it->second.handshake->getRemoteNodeType();
     589              // it->second.ip = it->second.socket->getRemoteAddress();
    554590              // add the new server to the nodes list (it can be a NET_MASTER_SERVER or NET_PROXY_SERVER)
    555591              this->networkMonitor->addNode(&it->second);
     
    560596
    561597              // now check if the server accepted the connection
    562               if( it->second.handshake->redirect())
    563                 this->handleReconnect( it->second.userId);
     598              if( SharedNetworkData::getInstance()->isClient() && it->second.handshake->redirect() )
     599              {
     600                this->bRedirect = true;
     601              }
    564602
    565603              // create the new network game manager and init it
     
    570608            }
    571609
    572 
    573610            PRINT(0)("handshake finished id=%d\n", it->second.handshake->getNetworkGameManagerId());
    574611            it->second.handshake->del();
     612
    575613          }
    576614          else
     
    580618            {
    581619
    582               if ( this->pInfo->isMasterServer() )
     620              if (  SharedNetworkData::getInstance()->isMasterServer() )
    583621              {
    584                 it->second.nodeType = it->second.handshake->getRemoteNodeType();
    585622                it->second.ip = it->second.socket->getRemoteAddress();
    586623
     
    594631                }
    595632              }
    596               else if ( this->pInfo->isProxyServer() )
     633              else if ( SharedNetworkData::getInstance()->isProxyServerActive() && it->second.isClient() )
    597634              {
    598                 it->second.nodeType = it->second.handshake->getRemoteNodeType();
     635                PRINTF(0)("Handshake: i am in server role\n");
     636
    599637                it->second.ip = it->second.socket->getRemoteAddress();
    600638
     
    632670void NetworkStream::handleReconnect(int userId)
    633671{
     672  this->bRedirect = false;
     673  PeerInfo* pInfo = &this->peers[userId];
     674
    634675  PRINTF(0)("===============================================\n");
    635676  PRINTF(0)("Client is redirected to the other proxy servers\n");
     677  PRINTF(0)("  user id: %i\n", userId);
     678  PRINTF(0)("  connecting to: %s\n", this->networkMonitor->getFirstChoiceProxy()->ip.ipString().c_str());
    636679  PRINTF(0)("===============================================\n");
    637 
    638   return;
    639 
    640   PeerInfo* pInfo = &this->peers[userId];
    641 
    642   // reject the server
    643   pInfo->handshake->doReject( "redirected to different server");
    644680
    645681  // flush the old synchronization states, since the numbering could be completely different
    646682  pInfo->lastAckedState = 0;
    647683  pInfo->lastRecvedState = 0;
    648   // not sure if this works as expected
    649   if( pInfo->handshake)
    650     delete pInfo->handshake;
     684
     685  // temp save the ip address here
     686  IP proxyIP = pInfo->handshake->getProxy1Address();
    651687
    652688  // disconnect from the current server and reconnect to proxy server
    653   pInfo->socket->reconnectToServer( pInfo->handshake->getProxy1Address().ipString(), pInfo->handshake->getProxy1Address().port());
     689  this->handleDisconnect( userId);
     690  this->connectToProxyServer(NET_ID_PROXY_SERVER_01, proxyIP.ipString(), 9999);
     691  #warning the ports are not yet integrated correctly in the ip class
    654692
    655693  // and restart the handshake
    656   this->startHandshake();
    657 }
     694  this->startHandshake( userId);
     695}
     696
     697
     698/**
     699 * handles the disconnect event
     700 * @param userId id of the user to remove
     701 */
     702void NetworkStream::handleDisconnect( int userId )
     703{
     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
     717  for ( SynchronizeableList::iterator it2 = synchronizeables.begin(); it2 != synchronizeables.end(); it2++ )  {
     718    (*it2)->cleanUpUser( userId );
     719  }
     720
     721  if( SharedNetworkData::getInstance()->isMasterServer())
     722    NetworkGameManager::getInstance()->signalLeftPlayer(userId);
     723
     724  this->freeSocketSlots.push_back( userId );
     725
     726  peers.erase( userId);
     727}
     728
    658729
    659730
    660731/**
    661732 * handle upstream network traffic
     733 * @param tick: seconds elapsed since last update
    662734 */
    663735void NetworkStream::handleUpstream( int tick )
     
    698770
    699771      // do not include synchronizeables with uninit id and syncs that don't want to be synchronized
    700       if ( !sync.beSynchronized() || sync.getUniqueID() < 0 )
     772      if ( !sync.beSynchronized() || sync.getUniqueID() <= NET_UID_UNASSIGNED )
    701773        continue;
    702774
     
    706778
    707779      // if we are a server (both master and proxy servers) and this is not our handshake
    708       if ( ( SharedNetworkData::getInstance()->isMasterServer() || SharedNetworkData::getInstance()->isProxyServer() ) && sync.getLeafClassID() == CL_HANDSHAKE && sync.getUniqueID() != peer->second.userId )
     780      if ( ( SharedNetworkData::getInstance()->isMasterServer() ||
     781             SharedNetworkData::getInstance()->isProxyServerActive() &&  peer->second.isClient())
     782             && sync.getLeafClassID() == CL_HANDSHAKE && sync.getUniqueID() != peer->second.userId )
    709783        continue;
    710784
     
    720794
    721795      // server fakes uniqueid == 0 for handshake
    722       if ( ( SharedNetworkData::getInstance()->isMasterServer() || SharedNetworkData::getInstance()->isProxyServer() ) &&
     796      if ( ( SharedNetworkData::getInstance()->isMasterServer() ||
     797             SharedNetworkData::getInstance()->isProxyServerActive() &&  peer->second.isClient() ) &&
    723798             sync.getUniqueID() <= SharedNetworkData::getInstance()->getMaxPlayer() + 1) // plus one to handle one client more than the max to redirect it
    724799        n = Converter::intToByteArray( 0, buf + offset, UDP_PACKET_SIZE - offset );
     
    760835      Synchronizeable & sync = **it;
    761836
    762       if ( !sync.beSynchronized() || sync.getUniqueID() < 0 )
     837      // again exclude all unwanted syncs
     838      if ( !sync.beSynchronized() || sync.getUniqueID() <= NET_UID_UNASSIGNED)
    763839        continue;
    764840
     
    771847    // now compress the data with the zip library
    772848    int compLength = 0;
    773     if ( SharedNetworkData::getInstance()->isMasterServer() || SharedNetworkData::getInstance()->isProxyServer())
     849    if ( SharedNetworkData::getInstance()->isMasterServer() ||
     850         SharedNetworkData::getInstance()->isProxyServerActive())
    774851      compLength = Zip::getInstance()->zip( buf, offset, compBuf, UDP_PACKET_SIZE, dictServer );
    775852    else
     
    888965          }
    889966
    890           // if the node we got this unknown sync from is a client we ignore it (since it has no rights to create a new sync)
    891           if ( peers[peer->second.userId].isClient() )
     967          // if the node we got this unknown sync we ignore it if:
     968          //  - the remote host is a client
     969          //  - the remote host is a proxy server and we are master server
     970          // (since it has no rights to create a new sync)
     971          if ( peers[peer->second.userId].isClient() ||
     972               (peers[peer->second.userId].isProxyServerActive() && SharedNetworkData::getInstance()->isMasterServer()))
    892973          {
    893974            offset += syncDataLength;
     
    9601041        Synchronizeable & sync = **it;
    9611042
    962         if ( !sync.beSynchronized() || sync.getUniqueID() < 0 )
     1043        if ( !sync.beSynchronized() || sync.getUniqueID() <= NET_UID_UNASSIGNED )
    9631044          continue;
    9641045
  • trunk/src/lib/network/network_stream.h

    r9406 r9494  
    4242
    4343    void connectToMasterServer(std::string host, int port);
    44     void connectToProxyServer(std::string host, int port);
    45     void createServer(int port);
     44    void connectToProxyServer(int proxyId, std::string host, int port);
     45    void createServer(int clientPort, int proxyPort);
    4646
    4747    void createNetworkGameManager();
    48     void startHandshake();
     48    void startHandshake(int userId = NET_ID_MASTER_SERVER);
    4949
    5050    /* synchronizeable interface */
     
    5555
    5656    /* functions for the peerInfo information retreival */
     57    /** @returns true if this userId is activated at this client false if not*/
    5758    inline bool isUserIdActive( int userID ) { return (peers.find(userID) != peers.end()); }
     59    /** @returns true if this userId is a local client */
     60    inline bool isUserLocal( int userID) { return this->isUserIdActive(userID); }
     61    /** @returns true if this user is a master server */
    5862    inline bool isUserMasterServer( int userID ){ if ( !isUserIdActive(userID) ) return false; return peers[userID].isMasterServer(); }
    59     inline bool isUserProxyServer( int userID ){ if ( !isUserIdActive(userID) ) return false; return peers[userID].isProxyServer(); }
     63    /** @returns true if this user is a proxy server */
     64    inline bool isUserProxyServerActive( int userID ){ if ( !isUserIdActive(userID) ) return false; return peers[userID].isProxyServerActive(); }
     65    /** @returns true if this user is a client */
    6066    inline bool isUserClient( int userID ){ if ( !isUserIdActive(userID) ) return false; return peers[userID].isClient(); }
    6167
     
    8086
    8187    void updateConnectionList();
     88
    8289    /* handle processes */
    8390    void handleHandshakes();
     
    8794    /* handle events*/
    8895    void handleNewClient( int userId );
     96
     97    void handleConnect( int userId);
    8998    void handleReconnect( int userId );
     99    void handleDisconnect( int userId );
    90100
    91101    void writeToNewDict( byte * data, int length, bool upstream );
     
    102112    NetworkMonitor*            networkMonitor;              //!< the network monitor
    103113    NetworkGameManager*        networkGameManager;          //!< reference to the network game manager
    104     ServerSocket*              serverSocket;                //!< the listening socket of the server
     114    ServerSocket*              clientSocket;                //!< the listening socket of the server
     115    ServerSocket*              proxySocket;                 //!< socket for proxy connections
    105116
    106117    std::map<int,int>          oldSynchronizeables;         //!< used to save recently deleted sync ids to not recreate them
     
    113124    int                        dictServer;                  //!< the zip dict for the server
    114125    int                        dictClient;                  //!< the zip dict for the client
     126
     127    bool                       bRedirect;                   //!< true if the master server sent a redirect command
    115128};
    116129#endif /* _NETWORK_STREAM */
  • trunk/src/lib/network/peer_info.cc

    r9406 r9494  
    5454
    5555
    56 std::string PeerInfo::getNodeTypeString()
     56const std::string& PeerInfo::getNodeTypeString() const
    5757{
    58   switch( this->nodeType)
    59   {
    60     case NET_CLIENT:
    61       return std::string("client");
    62     case NET_PROXY_SERVER_ACTIVE:
    63       return std::string("proxy server active");
    64     case NET_PROXY_SERVER_PASSIVE:
    65       return std::string("proxy server passive");
    66     case NET_MASTER_SERVER:
    67       return std::string("master server");
    68   }
     58  return PeerInfo::nodeTypeToString( this->nodeType );
     59  // the above does the same, and is faster in it. (there is no case where node is uninit i hope!)
     60}
    6961
    70   return std::string("node is uninit");
     62const std::string& PeerInfo::nodeTypeToString(unsigned int type)
     63{
     64  return PeerInfo::nodeNames[type];
    7165}
     66
     67
     68const std::string PeerInfo::nodeNames[] =
     69{
     70
     71  "maser server",
     72  "proxy server active",
     73  "proxy server passive",
     74  "client",
     75  "node is not initialized"
     76};
  • trunk/src/lib/network/peer_info.h

    r9406 r9494  
    2222
    2323
    24     inline bool isMasterServer() { return this->nodeType == NET_MASTER_SERVER; }
    25     inline bool isProxyServer() { return this->nodeType == NET_PROXY_SERVER_ACTIVE; }
    26     inline bool isProxyServerPassive() { return this->nodeType == NET_PROXY_SERVER_PASSIVE; }
    27     inline bool isClient() { return this->nodeType == NET_CLIENT; }
     24    inline bool isMasterServer() const { return this->nodeType == NET_MASTER_SERVER; }
     25    inline bool isProxyServerActive() const { return this->nodeType == NET_PROXY_SERVER_ACTIVE; }
     26    inline bool isProxyServerActivePassive() const { return this->nodeType == NET_PROXY_SERVER_PASSIVE; }
     27    inline bool isClient() const { return this->nodeType == NET_CLIENT; }
    2828
    29     std::string getNodeTypeString();
     29    const std::string& getNodeTypeString() const;
     30    static const std::string& nodeTypeToString(unsigned int type);
     31
    3032
    3133
     
    4143    int                 lastAckedState;          //!< last acked state synchronized state
    4244    int                 lastRecvedState;         //!< last received state
     45
     46    static const std::string nodeNames[];
     47
    4348};
    4449
  • trunk/src/lib/network/player_stats.cc

    r9406 r9494  
    191191void PlayerStats::setNickName( std::string nick )
    192192{
    193   if ( SharedNetworkData::getInstance()->isMasterServer() || SharedNetworkData::getInstance()->isProxyServer() )
     193  if ( SharedNetworkData::getInstance()->isMasterServer())
    194194  {
    195195    this->nickName = nick;
  • trunk/src/lib/network/proxy/network_settings.cc

    r9406 r9494  
    4040  // suggest a good standard max players value
    4141  this->maxPlayer = 10;
    42 
    43 //   this->loadData();
    4442}
    4543
     
    5351
    5452  // remove all unused proxy data again
    55   for( int i = 0; i < this->proxies.size(); i++)
     53  for(unsigned int i = 0; i < this->proxies.size(); i++)
    5654  {
    57     IPaddress* ip = this->proxies.back();
     55    IP ip = this->proxies.back();
    5856    this->proxies.pop_back();
    59     delete ip;
    6057  }
    6158}
     
    104101
    105102  LoadParam(root, "max-player", this, NetworkSettings, setMaxPlayer);
     103  LoadParam(root, "max-player-saturation", this, NetworkSettings, setMaxPlayerSaturation);
    106104
    107105
     
    140138    return;
    141139
    142   IPaddress *ip = new IPaddress;
    143 
    144   SDLNet_ResolveHost( ip, proxyAddr.c_str(), 9999 );
    145 
    146   this->proxies.push_back(ip);
     140  this->proxies.push_back(IP(proxyAddr, 9999));
    147141}
    148142
  • trunk/src/lib/network/proxy/network_settings.h

    r9406 r9494  
    3737    inline void setMaxPlayer(int number) { this->maxPlayer = number; }
    3838    /** @returns teh max number of players */
    39     int getMaxPlayer() { return this->maxPlayer; }
     39    int getMaxPlayer() const { return this->maxPlayer; }
     40    /** sets the @param saturation: a threshold in percente when the proxy servers should be activated to be able to redirect the clients */
     41    inline void setMaxPlayerSaturation(float saturation) { this->maxPlayerSaturation = saturation; }
     42
    4043
    4144    void setMasterAddr(const std::string& masterAddr);
    4245    /** @returns the address of the master server read from the network config file */
    43     inline IP getMasterAddr() { return this->masterServer; }
     46    inline const IP& getMasterAddr() const { return this->masterServer; }
    4447
    4548    void setProxyAddr(const std::string& proxyAddr);
    4649    /** @returns the list of proxy servers from the init file */
    47     inline std::vector<IPaddress*>* getProxyList() { return &this->proxies; }
     50    inline std::vector<IP>* getProxyList() { return &this->proxies; }
    4851
    4952
     
    5356
    5457  private:
    55     static NetworkSettings*        singletonRef;            //!< Pointer to the only instance of this Class
     58    static NetworkSettings*      singletonRef;            //!< Pointer to the only instance of this Class
     59
    5660    int                          maxPlayer;               //!< maximal number of players
    57     std::vector<IPaddress*>      proxies;                 //!< all registered proxies
     61    float                        maxPlayerSaturation;     //!< the saturation level from where on the proxy server should be activated
     62
     63    std::vector<IP>              proxies;                 //!< all registered proxies
    5864    IP                           masterServer;            //!< master server ip address
    5965
  • trunk/src/lib/network/shared_network_data.cc

    r9406 r9494  
    2020#include "state.h"
    2121
     22#include "network_stream.h"
     23
    2224#include "debug.h"
    2325
     
    3436  this->setClassID(CL_SHARED_NETWORK_DATA, "SharedNetworkData");
    3537
    36   this->nodeType = NET_CLIENT;
     38  this->nodeType = NET_MASTER_SERVER;
    3739  this->hostID = -1;
    3840  this->defaultSyncStream = NULL;
     
    5153  SharedNetworkData::singletonRef = NULL;
    5254}
     55
     56
     57
     58/** @return true if this user is connected to the local host */
     59bool SharedNetworkData::isUserLocal( int userID)
     60{
     61  return this->defaultSyncStream->isUserLocal(userID);
     62}
     63
     64
     65/** @returns true if this user is a master server */
     66bool SharedNetworkData::isUserMasterServer( int userID )
     67{
     68  return this->defaultSyncStream->isUserMasterServer(userID);
     69}
     70
     71
     72/** @returns true if this user is a proxy server */
     73bool SharedNetworkData::isUserProxyServerActive( int userID )
     74{
     75   return this->defaultSyncStream->isUserProxyServerActive(userID);
     76}
     77
     78
     79/** @returns true if this user is a client */
     80bool SharedNetworkData::isUserClient( int userID )
     81{
     82  return this->defaultSyncStream->isUserClient(userID);
     83}
  • trunk/src/lib/network/shared_network_data.h

    r9406 r9494  
    1414#define NET_MAX_CONNECTIONS 2
    1515
    16 class NetworkStream;
     16
    1717class Synchronizeable;
    1818
     
    2828
    2929    /** @returns the next uniqueID free for an object */
    30     inline int getNewUniqueID() { return ( this->nodeType != NET_CLIENT)?this->newUniqueID++:-1; }
     30    inline int getNewUniqueID() { return ( isMasterServer())?this->newUniqueID++:-1; }
    3131    /** sets the @param newUniqueID: the new offset for the next unique id */
    3232    inline void setNewUniqueID(int newUniqueID) { this->newUniqueID = newUniqueID; }
    3333
     34    /** sets the game server flag @param bGameServer true if it is a game server */
     35    inline void setNodeType(int nodeType) { this->nodeType = nodeType; }
    3436    /** @returns true is this node is a master server */
    3537    inline bool isMasterServer() { return this->nodeType == NET_MASTER_SERVER; }
    3638    /** @returns true is this node is a proxy server */
    37     inline bool isProxyServer() { return this->nodeType == NET_PROXY_SERVER_ACTIVE; }
     39    inline bool isProxyServerActive() { return this->nodeType == NET_PROXY_SERVER_ACTIVE; }
    3840    /** @returns true is this node is a client*/
    3941    inline bool isClient() { return this->nodeType == NET_CLIENT; }
    40     /** sets the game server flag @param bGameServer true if it is a game server */
    41     inline void setNodeType(int nodeType) { this->nodeType = nodeType; }
     42
     43    /** @return true if this user is connected to the local host */
     44    bool isUserLocal( int userID);
     45    /** @returns true if this user is a master server */
     46    bool isUserMasterServer( int userID );
     47    /** @returns true if this user is a proxy server */
     48    bool isUserProxyServerActive( int userID );
     49    /** @returns true if this user is a client */
     50    bool isUserClient( int userID );
     51
    4252
    4353    /** @returns the maximum number of players for this server */
  • trunk/src/lib/network/synchronizeable.cc

    r9406 r9494  
    7272    this->networkStream->disconnectSynchronizeable(*this);
    7373
    74     if ( (SharedNetworkData::getInstance()->isMasterServer() || SharedNetworkData::getInstance()->isProxyServer() )
     74    // remove the message manager only by the server
     75    if ( (SharedNetworkData::getInstance()->isMasterServer() )
    7576           && this->beSynchronized() && this->getUniqueID() > 0 && !this->isA( CL_MESSAGE_MANAGER ) )
    7677      NetworkGameManager::getInstance()->removeSynchronizeable( this->getUniqueID() );
     
    213214      hasPermission = true;
    214215    // now check PROXY_SERVER permissions
    215     else if( SharedNetworkData::getInstance()->isProxyServer() && (*it)->checkPermission( PERMISSION_MASTER_SERVER ))
     216    else if( SharedNetworkData::getInstance()->isProxyServerActive() && (*it)->checkPermission( PERMISSION_PROXY_SERVER ))
    216217      hasPermission = true;
    217218    // now check OWNER permissions
     
    222223      hasPermission = true;
    223224    // 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
    224226    else if( SharedNetworkData::getInstance()->isMasterServer() && this->owner != userId && (*it)->checkPermission( PERMISSION_OWNER ))
    225227      hasPermission = true;
    226228    // SPECIAL: get write permissions if i am proxy server and i am able to overwrite the client stuff
    227     else if( SharedNetworkData::getInstance()->isProxyServer()  && this->owner != userId && (*it)->checkPermission( PERMISSION_OWNER ))
     229    else if( SharedNetworkData::getInstance()->isProxyServerActive() && this->networkStream->isUserClient(userId)
     230             && this->owner != userId && (*it)->checkPermission( PERMISSION_OWNER ) )
    228231      hasPermission = true;
    229232    else
     
    354357      hasPermission = true;
    355358    // now check PROXY_SERVER permissions
    356     else if( this->networkStream->isUserProxyServer( userId )  && (*it)->checkPermission( PERMISSION_MASTER_SERVER ))
     359    else if( this->networkStream->isUserProxyServerActive( userId )  && (*it)->checkPermission( PERMISSION_MASTER_SERVER )
     360             && SharedNetworkData::getInstance()->isClient())
    357361      hasPermission = true;
    358362    // now check OWNER permissions
     
    366370      hasPermission = true;
    367371    // SPECIAL: get write permissions if im sending to a proxy server that does not own this sync
    368     else if( this->networkStream->isUserProxyServer( userId )  && this->owner != SharedNetworkData::getInstance()->getHostID() && (*it)->checkPermission( PERMISSION_OWNER ))
     372    else if( this->networkStream->isUserProxyServerActive( userId ) && SharedNetworkData::getInstance()->isClient()
     373              && this->owner != SharedNetworkData::getInstance()->getHostID() && (*it)->checkPermission( PERMISSION_OWNER ))
    369374      hasPermission = true;
    370375    else
     
    388393    else
    389394    {
    390 //      PRINTF(0)("DONT SET VAR BECAUSE OF PERMISSION: %s %d %d %d %d %d %d\n", (*it)->getName().c_str(), (*it)->checkPermission( PERMISSION_MASTER_SERVER ), (*it)->checkPermission( PERMISSION_OWNER ), (*it)->checkPermission( PERMISSION_ALL ), networkStream->isUserServer( userId ), this->owner, userId );
     395//       PRINTF(0)("DONT SET VAR BECAUSE OF PERMISSION: %s perm: %d %d %d - %d %d %d\n", (*it)->getName().c_str(), (*it)->checkPermission( PERMISSION_MASTER_SERVER ), (*it)->checkPermission( PERMISSION_OWNER ), (*it)->checkPermission( PERMISSION_ALL ), networkStream->isUserMasterServer( userId ), this->owner, userId );
    391396      n = (*it)->getSizeFromBuf( stateTo->data + i, stateTo->dataLength - i );
    392397      //NETPRINTF(0)("%s::setvar %s %d\n", getClassCName(), (*it)->getName().c_str(), n);
     
    416421void Synchronizeable::registerVar( SynchronizeableVar * var )
    417422{
    418   //PRINTF(0)("ADDING VAR: %s\n", var->getName().c_str());
    419423  syncVarList.push_back( var );
    420424}
     
    428432int Synchronizeable::registerVarId( SynchronizeableVar * var )
    429433{
    430   //PRINTF(0)("ADDING VAR: %s\n", var->getName().c_str());
    431434  syncVarList.push_back( var );
    432435  var->setWatched( true );
  • trunk/src/lib/network/synchronizeable_var/synchronizeable_var.h

    r9406 r9494  
    1010#include <string>
    1111
    12 enum {
    13   PERMISSION_MASTER_SERVER = 1,
    14   PERMISSION_PROXY_SERVER  = 2,
    15   PERMISSION_OWNER         = 4,
    16   PERMISSION_ALL           = 8
    17 };
     12
    1813
    1914class SynchronizeableVar {
  • trunk/src/lib/network/tcp_server_socket.cc

    r9406 r9494  
    126126}
    127127
     128
     129
    128130void TcpServerSocket::close( )
    129131{
  • trunk/src/lib/network/udp_server_socket.cc

    r8802 r9494  
    9494}
    9595
     96
    9697/**
    9798 * stop listening on server
     
    220221  if ( !socket )
    221222    return false;
    222  
     223
    223224  assert( networkPacket.length <= UDP_PACKET_SIZE );
    224225
     
    232233    return false;
    233234  }
    234  
     235
    235236  return true;
    236237}
     
    244245  int newConn = 0;
    245246
     247  // iterate through all newly received packets and assign them to the users packet buffer
    246248  for ( res = SDLNet_UDP_Recv( socket, packet ); res == 1; res = SDLNet_UDP_Recv( socket, packet ) )
    247249  {
     
    250252
    251253    if ( packet->len <= 0 )
    252       continue;
    253        
    254     for ( userId =0; userId < (int)userList.size(); userId++ )
    255       if ( userList[userId].addr.host == packet->address.host && userList[userId].addr.port == packet->address.port && userList[userId].randomByte == ( packet->data[0] & 0xFC ) )
     254      continue;
     255
     256    // search the user id this backet belongs to
     257    for ( userId = 0; userId < (int)userList.size(); userId++ )
     258    {
     259      if ( userList[userId].addr.host == packet->address.host &&
     260           userList[userId].addr.port == packet->address.port &&
     261           userList[userId].randomByte == ( packet->data[0] & 0xFC ) )
    256262        break;
    257 
     263    }
     264
     265    // is it a new packet initializing a new connecion?
    258266    if ( userId >= (int)userList.size() )
    259267    {
     
    271279          break;
    272280
    273       initUser( userId, packet->address, packet->data[0] & 0xFC );
     281      this->initUser( userId, packet->address, packet->data[0] & 0xFC );
    274282      UdpSocket * sock = new UdpSocket( this, packet->address, userId, packet->data[0] & 0xFC );
    275283      newSocketList.push_back( sock );
     
    277285    }
    278286
    279     //add new packet to packetbuffer
    280 
     287
     288    // add new packet to packetbuffer
    281289    NetworkPacket networkPacket;
    282290    networkPacket.length = packet->len;
  • trunk/src/lib/network/udp_server_socket.h

    r9246 r9494  
    3333typedef std::vector<NetworkPacketList> PacketBuffer;
    3434
     35
     36//!< informations struct for each user
    3537struct UserInfo
    3638{
    37   IPaddress addr;
    38   byte randomByte;
     39  IPaddress     addr;            //!< ip address of this user
     40  byte          randomByte;      //!< random byte of this user
    3941};
     42
    4043
    4144typedef std::vector<UserInfo> UserList;
     
    4346typedef std::list<UdpSocket*> UdpSocketList;
    4447
     48
     49//!< the upd server socket listening for incoming connections
    4550class UdpServerSocket : public ServerSocket
    4651{
     
    4954    virtual ~UdpServerSocket();
    5055
     56    /* server socket manipulations */
    5157    virtual bool listen( unsigned int port );
    52 
    5358    virtual NetworkSocket* getNewSocket( void );
    54 
    5559    virtual void close();
    5660
    5761    virtual void update();
    5862
     63    /* network traffic interface */
     64    NetworkPacket getPacket( int userId );
     65    void removeUser( int userId );
     66    bool sendPacket( NetworkPacket networkPacket, int userId );
     67
     68
     69  private:
    5970    void removeUserPackets( int userId );
    60     void removeUser( int userId );
    61     NetworkPacket getPacket( int userId );
    62     bool sendPacket( NetworkPacket networkPacket, int userId );
    6371    int getPacketCount( int childId );
    6472    void initUser( int childId, IPaddress ip, byte randomByte );
    6573
     74
    6675  private:
    67     UDPsocket     socket;           //!< will be uses to send/recieve data
    68     UDPpacket *   packet;           //!< packet structure to recieve packet
    69     PacketBuffer  packetBuffer;     //!< will store recieved packets for UdpSockets
    70     UserList      userList;         //!< contains information about clients
    71     UdpSocketList newSocketList;    //!< contains new socket
     76    UDPsocket          socket;           //!< will be used to send/recieve data to/from clients
     77    UDPpacket *        packet;           //!< packet structure to recieve packet
     78    PacketBuffer       packetBuffer;     //!< will store recieved packets for UdpSockets
     79    UserList           userList;         //!< contains information about clients
     80    UdpSocketList      newSocketList;    //!< contains new socket
    7281
    7382};
  • trunk/src/lib/network/zip.h

    r8623 r9494  
    2121
    2222//! A class for compressing/uncompressing packes.
    23 class Zip 
     23class Zip
    2424{
    2525  public:
     
    2727    /** @returns a Pointer to the only object of this Class */
    2828    inline static Zip* getInstance(void) { if (!singletonRef) singletonRef = new Zip();  return singletonRef; };
    29    
     29
    3030    int loadDictionary( std::string name );
    3131    int zip( byte * from, int fromLength, byte * to, int maxLength, int dict = 0 );
    3232    int unZip( byte * from, int fromLength, byte * to, int maxLength );
    33    
     33
    3434    int getDictCount(){ return dicts.size(); }
    3535
     
    3737    Zip();
    3838    static Zip* singletonRef;
    39    
     39
    4040    std::vector<DictionaryEntry> dicts;
    4141};
    4242
    43 #endif /* _PROTO_SINGLETON_H */
     43#endif /* _ZIP_H */
  • trunk/src/story_entities/game_world.cc

    r9406 r9494  
    414414    double currentFrame = Timer::getNow();
    415415
     416    if (currentFrame - this->lastFrame < .01)
     417    {
     418      SDL_Delay(1000.0 * (0.01 - (currentFrame - lastFrame)));
     419      currentFrame = Timer::getNow();
     420    }
     421
     422
    416423    frameTimesIndex = this->cycle % TICK_SMOOTH_VALUE;
    417424    this->frameTimes[frameTimesIndex] = currentFrame - this->lastFrame;
     
    469476      this->dataTank->objectManager->getObjectList(OM_GROUP_00_PROJ));
    470477  CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_GROUP_01),
    471     this->dataTank->objectManager->getObjectList(OM_GROUP_00));
     478      this->dataTank->objectManager->getObjectList(OM_GROUP_00));
    472479
    473480  CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_GROUP_01),
    474   this->dataTank->objectManager->getObjectList(OM_GROUP_02));
     481      this->dataTank->objectManager->getObjectList(OM_GROUP_02));
    475482  CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_GROUP_02),
    476   this->dataTank->objectManager->getObjectList(OM_GROUP_01_PROJ));
     483      this->dataTank->objectManager->getObjectList(OM_GROUP_01_PROJ));
    477484
    478485
     
    513520{
    514521
    515     // if this server is a dedicated server the game workd does not need to be drawn
     522  // if this server is a dedicated server the game workd does not need to be drawn
    516523  if( !GraphicsEngine::getInstance()->isDedicated())
    517524  {
    518   // render the reflection texture
    519   this->renderPassReflection();
    520   // redner the refraction texture
    521   this->renderPassRefraction();
     525    // render the reflection texture
     526    this->renderPassReflection();
     527    // redner the refraction texture
     528    this->renderPassRefraction();
    522529  }
    523530  // render all
  • trunk/src/story_entities/multi_player_world_data.cc

    r9406 r9494  
    112112  const TiXmlElement* element = NULL;
    113113
    114   if( SharedNetworkData::getInstance()->isMasterServer() || SharedNetworkData::getInstance()->isProxyServer())
     114  if( SharedNetworkData::getInstance()->isMasterServer() /*|| SharedNetworkData::getInstance()->isProxyServerActive()*/)
    115115  {
    116116    /* load the spawning points */
     
    148148    element = element->FirstChildElement();
    149149
    150     if( SharedNetworkData::getInstance()->isMasterServer() || SharedNetworkData::getInstance()->isProxyServer())
     150    if( SharedNetworkData::getInstance()->isMasterServer() /*|| SharedNetworkData::getInstance()->isProxyServerActive()*/)
    151151    {
    152152      while( element != NULL)
     
    206206
    207207
    208     if( SharedNetworkData::getInstance()->isMasterServer() || SharedNetworkData::getInstance()->isProxyServer())
     208    if( SharedNetworkData::getInstance()->isMasterServer() /*|| SharedNetworkData::getInstance()->isProxyServerActive()*/)
    209209    {
    210210      this->localPlayer = new Player();
     
    284284
    285285  // create server playable
    286   if ( SharedNetworkData::getInstance()->isMasterServer() || SharedNetworkData::getInstance()->isProxyServer())
     286  if ( SharedNetworkData::getInstance()->isMasterServer() /*|| SharedNetworkData::getInstance()->isProxyServerActive()*/)
    287287  {
    288288    NetworkGameManager::getInstance()->signalNewPlayer( 0 );
  • trunk/src/subprojects/network/network_unit_test.cc

    r9406 r9494  
    276276  for(;;)
    277277  {
    278     MessageManager::getInstance()->sendMessage( TESTMESSAGEID, (byte*)"server to client", 18, RT_ALL_NOT_ME, 0, MP_HIGHBANDWIDTH );
     278    MessageManager::getInstance()->sendMessage( TESTMESSAGEID, (byte*)"server to client", 18, RT_ALL_BUT_ME, 0, MP_HIGHBANDWIDTH );
    279279    netMan->synchronize( 100 );
    280280    SDL_Delay(100);
     
    323323  {
    324324    netMan->synchronize( 100 );
    325     MessageManager::getInstance()->sendMessage( TESTMESSAGEID, (byte*)"client to server", 18, RT_ALL_NOT_ME, 0, MP_HIGHBANDWIDTH );
     325    MessageManager::getInstance()->sendMessage( TESTMESSAGEID, (byte*)"client to server", 18, RT_ALL_BUT_ME, 0, MP_HIGHBANDWIDTH );
    326326    ss = dynamic_cast<SimpleSync*>(ClassList::getObject( "Server", CL_SIMPLE_SYNC ) );
    327327    SDL_Delay(100);
  • trunk/src/util/Makefile.am

    r9406 r9494  
    2626                        animation/animation_player.cc \
    2727                        \
    28                         track/pilot_node.cc \
    29                         \
    30                         network_stats_widget.cc
     28                        track/pilot_node.cc
    3129
    3230#                       track/track_manager.cc \
     
    5452                        animation/t_animation.h \
    5553                        \
    56                         track/pilot_node.h \
    57                         \
    58                         network_stats_widget.h
    59 
     54                        track/pilot_node.h
    6055
    6156#                       track/track_manager.h \
  • trunk/src/util/game_rules.cc

    r9406 r9494  
    8787void GameRules::registerKill(const Kill& kill)
    8888{
    89   if ( SharedNetworkData::getInstance()->isClient() )
     89  if ( SharedNetworkData::getInstance()->isClient() || SharedNetworkData::getInstance()->isProxyServerActive())
    9090    return;
    9191
  • trunk/src/util/multiplayer_team_deathmatch.cc

    r9406 r9494  
    152152      box->setAbsCoor2D( 300, 100 );
    153153
    154       OrxGui::GLGuiPushButton * buttonSpectator = new OrxGui::GLGuiPushButton("Spectator");
    155       box->pack( buttonSpectator );
    156       buttonSpectator->released.connect(this, &MultiplayerTeamDeathmatch::onButtonSpectator);
    157 
    158       OrxGui::GLGuiPushButton * buttonRandom = new OrxGui::GLGuiPushButton("Random");
    159       box->pack( buttonRandom );
    160       buttonRandom->released.connect(this, &MultiplayerTeamDeathmatch::onButtonRandom);
    161 
    162       OrxGui::GLGuiPushButton * buttonTeam0 = new OrxGui::GLGuiPushButton("Blue Team");
    163       box->pack( buttonTeam0 );
    164       buttonTeam0->released.connect(this, &MultiplayerTeamDeathmatch::onButtonTeam0);
    165 
    166       OrxGui::GLGuiPushButton * buttonTeam1 = new OrxGui::GLGuiPushButton("Red Team");
    167       box->pack( buttonTeam1 );
    168       buttonTeam1->released.connect(this, &MultiplayerTeamDeathmatch::onButtonTeam1);
     154      if( SharedNetworkData::getInstance()->isClient() ||  SharedNetworkData::getInstance()->isProxyServerActive())
     155      {
     156        OrxGui::GLGuiPushButton * buttonSpectator = new OrxGui::GLGuiPushButton("Spectator");
     157        box->pack( buttonSpectator );
     158        buttonSpectator->released.connect(this, &MultiplayerTeamDeathmatch::onButtonSpectator);
     159
     160        OrxGui::GLGuiPushButton * buttonRandom = new OrxGui::GLGuiPushButton("Random");
     161        box->pack( buttonRandom );
     162        buttonRandom->released.connect(this, &MultiplayerTeamDeathmatch::onButtonRandom);
     163
     164        OrxGui::GLGuiPushButton * buttonTeam0 = new OrxGui::GLGuiPushButton("Blue Team");
     165        box->pack( buttonTeam0 );
     166        buttonTeam0->released.connect(this, &MultiplayerTeamDeathmatch::onButtonTeam0);
     167
     168        OrxGui::GLGuiPushButton * buttonTeam1 = new OrxGui::GLGuiPushButton("Red Team");
     169        box->pack( buttonTeam1 );
     170        buttonTeam1->released.connect(this, &MultiplayerTeamDeathmatch::onButtonTeam1);
     171      }
     172      else
     173      {
     174        OrxGui::GLGuiText* text = new OrxGui::GLGuiText();
     175        text->setText("Server Mode: not able to play at this node");
     176        box->pack( text);
     177      }
     178
    169179
    170180      if ( bShowTeamChange )
     
    204214  assignPlayable();
    205215
    206   if ( SharedNetworkData::getInstance()->isClient() )
     216  if ( SharedNetworkData::getInstance()->isClient() || SharedNetworkData::getInstance()->isProxyServerActive())
    207217    return;
    208218
     
    268278void MultiplayerTeamDeathmatch::checkGameRules()
    269279{
    270   if ( SharedNetworkData::getInstance()->isClient() )
     280  if ( SharedNetworkData::getInstance()->isClient() || SharedNetworkData::getInstance()->isProxyServerActive())
    271281    return;
    272282
     
    296306
    297307  if ( team == 0 || team == 1 )
    298     return CL_FPS_PLAYER;
     308    return CL_TURBINE_HOVER;
    299309
    300310  assert( false );
     
    303313std::string MultiplayerTeamDeathmatch::getPlayableModelFileName( int userId, int team, ClassID classId )
    304314{
     315  if (classId == CL_TURBINE_HOVER)
     316   return "models/ships/hoverglider_mainbody.obj";
    305317  if ( team == 0 )
    306318    return "models/creatures/doom_guy.md2";
  • trunk/src/world_entities/creatures/fps_player.cc

    r9406 r9494  
    287287  //dealing damage
    288288
    289   if ( State::isOnline() && (SharedNetworkData::getInstance()->isMasterServer() || SharedNetworkData::getInstance()->isProxyServer()))
     289  if ( State::isOnline() && (SharedNetworkData::getInstance()->isMasterServer() /*|| SharedNetworkData::getInstance()->isProxyServerActive()*/))
    290290  {
    291291    this->damageTicker -= time;
  • trunk/src/world_entities/space_ships/space_ship.cc

    r9406 r9494  
    310310void SpaceShip::collidesWith(WorldEntity* entity, const Vector& location)
    311311{
    312   Playable::collidesWith(entity, location);
    313 
    314   if( entity->isA(CL_PROJECTILE) && entity != ref)
    315   {
    316     if ( SharedNetworkData::getInstance()->isMasterServer() || SharedNetworkData::getInstance()->isProxyServer())
    317     {
    318       //TODO handle this
    319     }
    320   }
    321   PRINTF(3)("collision %s vs %s @ (%f,%f,%f)\n", this->getClassCName(), entity->getClassCName(), location.x, location.y, location.z);
     312
    322313}
    323314
  • trunk/src/world_entities/space_ships/turbine_hover.cc

    r8623 r9494  
    126126  this->cameraNode.addNodeFlags(PNODE_PROHIBIT_CHILD_DELETE);
    127127  //this->cameraNode.setParentMode(PNODE_ROTATE_MOVEMENT);
    128   //this->cameraNode.setParent(this);
     128  this->cameraNode.setParent(this);
     129  this->cameraNode.setRelCoor(0,5,0);
    129130
    130131  // rotors
     
    211212  this->getWeaponManager().getFixedTarget()->setParent(&this->cameraNode);
    212213  this->getWeaponManager().getFixedTarget()->setRelCoor(1000,0,0);
    213  
     214
    214215  registerVar( new SynchronizeableBool( &bForward, &bForward, "bForward", PERMISSION_OWNER ) );
    215216  registerVar( new SynchronizeableBool( &bBackward, &bBackward, "bBackward", PERMISSION_OWNER ) );
     
    218219  registerVar( new SynchronizeableBool( &bAscend, &bAscend, "bAscend", PERMISSION_OWNER ) );
    219220  registerVar( new SynchronizeableBool( &bDescend, &bDescend, "bDescend", PERMISSION_OWNER ) );
    220   //registerVar( new SynchronizeableQuaternion( &direction, &direction, "direction", PERMISSION_OWNER ) );
     221  registerVar( new SynchronizeableQuaternion( &direction, &direction, "direction", PERMISSION_OWNER ) );
    221222  registerVar( new SynchronizeableFloat( &cameraLook, &cameraLook, "cameraLook", PERMISSION_OWNER ) );
    222223  registerVar( new SynchronizeableFloat( &rotation, &rotation, "rotation", PERMISSION_OWNER ) );
     
    294295
    295296  // spaceship controlled movement
     297
     298  // TRYING TO FIX PNode.
     299  //this->cameraNode.setRelCoor(Vector(0.0f, 5.0f, 0.0f));//, 30.0f);
     300  //this->cameraNode.setRelDir(Quaternion(this->smoothRotator  *10.0, Vector(0,1,0)));
     301
    296302  this->movement(dt);
    297303  this->rotorCycle += this->rotorSpeed * dt;
    298 
    299   // TRYING TO FIX PNode.
    300   this->cameraNode.setAbsCoorSoft(this->getAbsCoor() + Vector(0.0f, 5.0f, 0.0f), 30.0f);
    301   this->cameraNode.setRelDirSoft(this->getAbsDir(), 30.0f);
    302 }
     304}
     305
     306
     307#include "shared_network_data.h"
    303308
    304309/**
     
    349354
    350355        this->velocity += (accelerationDir - damping)* dt;
    351         this->shiftCoor (this->velocity * dt);
     356        //if (this->getOwner() != SharedNetworkData::getInstance()->getHostID())
     357          this->shiftCoor (this->velocity * dt);
    352358
    353359        // limit the maximum rotation speed.
     
    362368        }
    363369
    364         this->setRelDirSoft(this->direction * Quaternion(-cameraLook, Vector(0,0,1)), 5);
     370        //if (this->getOwner() != SharedNetworkData::getInstance()->getHostID())
     371          this->setRelDirSoft(this->direction * Quaternion(-cameraLook, Vector(0,0,1)), 5);
    365372
    366373        this->wingNodeLeft.setRelDirSoft(Quaternion(accel.z * .05 +this->rotation, Vector(1,0,0)), 5);
     
    407414
    408415    case Playable::Vertical:
    409     {
    410       accel.z = 0;
    411       Vector accelerationDir = this->getAbsDir().apply(accel * this->acceleration);
    412       accelerationDir.z=0;
     416      {
     417        accel.z = 0;
     418        Vector accelerationDir = this->getAbsDir().apply(accel * this->acceleration);
     419        accelerationDir.z=0;
    413420
    414421        // this is the air friction (necessary for a smooth control)
    415       Vector damping = (this->velocity * this->airFriction);
    416 
    417       this->velocity += (accelerationDir - damping)* dt;
    418       this->shiftCoor (this->velocity * dt);
    419 
    420       this->setRelDirSoft(this->direction * Quaternion(-cameraLook, Vector(0,0,1)), 5);
    421 
    422       this->wingNodeLeft.setRelDirSoft(Quaternion(accel.z * .05 +this->rotation, Vector(1,0,0)), 5);
    423       this->rotorNodeLeft.setRelDirSoft(Quaternion(-accel.x * .07+this->rotation + cameraLook, Vector(0,0,1)), 5);
    424 
    425       this->wingNodeRight.setRelDirSoft(Quaternion(accel.z * .05 +this->rotation, Vector(1,0,0)), 5);
    426       this->rotorNodeRight.setRelDirSoft(Quaternion(-accel.x*.07 -this->rotation + cameraLook, Vector(0,0,1)), 5);
    427     }
    428     break;
     422        Vector damping = (this->velocity * this->airFriction);
     423
     424        this->velocity += (accelerationDir - damping)* dt;
     425        this->shiftCoor (this->velocity * dt);
     426
     427        this->setRelDirSoft(this->direction * Quaternion(-cameraLook, Vector(0,0,1)), 5);
     428
     429        this->wingNodeLeft.setRelDirSoft(Quaternion(accel.z * .05 +this->rotation, Vector(1,0,0)), 5);
     430        this->rotorNodeLeft.setRelDirSoft(Quaternion(-accel.x * .07+this->rotation + cameraLook, Vector(0,0,1)), 5);
     431
     432        this->wingNodeRight.setRelDirSoft(Quaternion(accel.z * .05 +this->rotation, Vector(1,0,0)), 5);
     433        this->rotorNodeRight.setRelDirSoft(Quaternion(-accel.x*.07 -this->rotation + cameraLook, Vector(0,0,1)), 5);
     434      }
     435      break;
    429436    default:
    430437      PRINTF(2)("Playmode %s Not Implemented\n", Playable::playmodeToString(this->getPlaymode()).c_str());
  • trunk/src/world_entities/spawning_point.cc

    r9406 r9494  
    178178      }
    179179
    180       if ( found && SharedNetworkData::getInstance()->isMasterServer() || SharedNetworkData::getInstance()->isProxyServer())
     180      if ( found && SharedNetworkData::getInstance()->isMasterServer() /*|| SharedNetworkData::getInstance()->isProxyServerActive()*/)
    181181        this->sendRespawnMessage( it->entity->getUniqueID() );
    182182
     
    201201 * Just override this function with whatever you want to be drawn.
    202202 */
    203 void SpawningPoint::draw()
     203void SpawningPoint::draw() const
    204204{
    205205}
     
    213213  assert( Converter::intToByteArray( uniqueId, buf + INTSIZE, INTSIZE ) == INTSIZE );
    214214
    215   MessageManager::getInstance()->sendMessage( MSGID_RESPAWN, buf, 2*INTSIZE, RT_ALL_NOT_ME, 0, MP_HIGHBANDWIDTH );
     215  MessageManager::getInstance()->sendMessage( MSGID_RESPAWN, buf, 2*INTSIZE, RT_ALL_BUT_ME, 0, MP_HIGHBANDWIDTH );
    216216}
    217217
    218218bool SpawningPoint::respawnMessageHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId )
    219219{
    220   if ( SharedNetworkData::getInstance()->isMasterServer() || SharedNetworkData::getInstance()->isProxyServer())
     220  if ( SharedNetworkData::getInstance()->isMasterServer() /*|| SharedNetworkData::getInstance()->isProxyServerActive()*/)
    221221  {
    222222    PRINTF(2)("server received spawn message!\n");
  • trunk/src/world_entities/spawning_point.h

    r9008 r9494  
    5050    virtual void loadParams(const TiXmlElement* root);
    5151
    52     inline int getTeamId(){ return this->teamId; }
    53     inline void setTeamId( int teamId ){ this->teamId = teamId; }
     52    inline int getTeamId() const { return this->teamId; }
     53    inline void setTeamId( int teamId ) { this->teamId = teamId; }
    5454
    5555    void pushEntity(Playable* entity, float delay = 0);
     
    6363
    6464    virtual void tick(float dt);
    65     virtual void draw();
     65    virtual void draw() const;
    6666
    6767
    6868  private:
    6969    void spawn(Playable* entity);
    70    
     70
    7171    void sendRespawnMessage( int uniqueId );
    7272    static bool respawnMessageHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId );
  • trunk/src/world_entities/world_entity.cc

    r9406 r9494  
    257257bool WorldEntity::buildObbTree(int depth)
    258258{
    259   if (this->obbTree)
     259  if( this->obbTree != NULL)
     260  {
    260261    delete this->obbTree;
     262    this->obbTree = NULL;
     263  }
    261264
    262265  if (this->models[0] != NULL)
     
    280283    this->aabbNode = new AABBTreeNode();
    281284    this->aabbNode->spawnBVTree(this->models[0]);
     285  }
     286  else
     287  {
     288    PRINTF(1)("could not create aabb bounding box, because no model was loaded yet\n");
     289    this->aabbNode = NULL;
     290    return false;
    282291  }
    283292  return true;
Note: See TracChangeset for help on using the changeset viewer.