Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 19, 2006, 10:29:14 PM (19 years ago)
Author:
patrick
Message:

work of the day in one commit:D

  • switched whole network framework to ip sturcture
  • extended ip structrue a little bit
  • reimplemented the disconnection/reconnection algorithm
  • synchronizeable ip bug discovered and solved
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/proxy/src/lib/network/network_stream.cc

    r9327 r9334  
    2828#include "monitor/network_monitor.h"
    2929#include "synchronizeable.h"
     30#include "ip.h"
    3031#include "network_game_manager.h"
    3132#include "shared_network_data.h"
     
    8586  this->pInfo->nodeType = NET_CLIENT;
    8687  // get the local ip address
    87   SDLNet_ResolveHost( &this->pInfo->ip, NULL, port );
     88  IPaddress ip;
     89  SDLNet_ResolveHost( &ip, NULL, port );
     90  this->pInfo->ip = ip;
    8891}
    8992
     
    99102  this->pInfo->nodeType = NET_MASTER_SERVER;
    100103  // get the local ip address
    101   SDLNet_ResolveHost( &this->pInfo->ip, NULL, port );
     104  IPaddress ip;
     105  SDLNet_ResolveHost( &ip, NULL, port );
     106  this->pInfo->ip = ip;
    102107}
    103108
     
    356361
    357362    // check if the connecting client should reconnect to a proxy server
    358     peers[clientId].handshake->setRedirect(this->networkMonitor->reconnectNextClient());
     363    peers[clientId].handshake->setRedirect(this->networkMonitor->isReconnectNextClient());
    359364
    360365
     
    364369
    365370    // check if there are too many clients connected (DEPRECATED: new: the masterserver sends a list of proxy servers)
    366     if ( clientId > SharedNetworkData::getInstance()->getMaxPlayer() )
    367     {
    368 //       peers[clientId].handshake->setRedirect(true);
    369 //
    370 //       peers[clientId].handshake->doReject( "too many connections" );
    371       PRINTF(0)("Will reject client %d because there are to many connections!\n", clientId);
    372     }
    373     else
    374     {
    375       PRINTF(0)("New Client: %d\n", clientId);
    376     }
    377 
    378     //this->connectSynchronizeable(*handshakes[clientId]);
     371//     if ( clientId > SharedNetworkData::getInstance()->getMaxPlayer() )
     372//     {
     373// //       peers[clientId].handshake->setRedirect(true);
     374// //
     375// //       peers[clientId].handshake->doReject( "too many connections" );
     376//       PRINTF(0)("Will reject client %d because there are to many connections!\n", clientId);
     377//     }
     378//     else
     379//     {
     380//       PRINTF(0)("New Client: %d\n", clientId);
     381//     }
     382    PRINTF(0)("New Client: %d\n", clientId);
     383
     384
    379385  }
    380386
     
    493499              it->second.nodeType = it->second.handshake->getRemoteNodeType();
    494500              it->second.ip = it->second.socket->getRemoteAddress();
     501              // add the new server to the nodes list (it can be a NET_MASTER_SERVER or NET_PROXY_SERVER)
    495502              this->networkMonitor->addNode(&it->second);
    496 
    497503              // get proxy 1 address and add it
    498504              this->networkMonitor->addNode(it->second.handshake->getProxy1Address(), NET_PROXY_SERVER_ACTIVE);
     
    500506              this->networkMonitor->addNode(it->second.handshake->getProxy2Address(), NET_PROXY_SERVER_ACTIVE);
    501507
    502 
    503               // now check if there server accepted the connection
     508              // now check if the server accepted the connection
    504509              if( it->second.handshake->redirect())
    505               {
    506                 // handle the redirection
    507                 PRINTF(0)("===============================================\n");
    508                 PRINTF(0)("Client is redirected to the other proxy servers\n");
    509                 PRINTF(0)("===============================================\n");
    510 
    511                 // disconnect from the current server and reconnect to proxy server
    512 //                 it->second.socket->disconnectServer();
    513               }
     510                this->handleReconnect( it->second.userId);
    514511
    515512              // create the new network game manager and init it
     
    537534                this->networkMonitor->addNode(&it->second);
    538535
    539                 handleNewClient( it->second.userId );
     536                this->handleNewClient( it->second.userId );
    540537
    541538                if ( PlayerStats::getStats( it->second.userId ) && it->second.handshake->getPreferedNickName() != "" )
     
    560557    }
    561558  }
     559}
     560
     561
     562/**
     563 * this functions handles a reconnect event received from the a NET_MASTER_SERVER or NET_PROXY_SERVER
     564 */
     565void NetworkStream::handleReconnect(int userId)
     566{
     567  PRINTF(0)("===============================================\n");
     568  PRINTF(0)("Client is redirected to the other proxy servers\n");
     569  PRINTF(0)("===============================================\n");
     570
     571  PeerInfo* pInfo = &this->peers[userId];
     572
     573  // reject the server
     574  pInfo->handshake->doReject( "redirected to different server");
     575
     576  // flush the old synchronization states, since the numbering could be completely different
     577  pInfo->lastAckedState = 0;
     578  pInfo->lastRecvedState = 0;
     579  // not sure if this works as expected
     580  if( pInfo->handshake)
     581    delete pInfo->handshake;
     582
     583  // disconnect from the current server and reconnect to proxy server
     584  pInfo->socket->reconnectToServer( pInfo->handshake->getProxy1Address().ipString(), pInfo->handshake->getProxy1Address().port());
     585
     586  // and restart the handshake
     587  this->startHandshake();
    562588}
    563589
Note: See TracChangeset for help on using the changeset viewer.