Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 11, 2005, 6:01:04 PM (18 years ago)
Author:
rennerc
Message:

handshake works now

File:
1 edited

Legend:

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

    r6043 r6053  
    2929#include "list.h"
    3030#include "debug.h"
     31#include "class_list.h"
    3132
    3233/* include your own header */
     
    7374  this->connectionMonitor = new ConnectionMonitor();
    7475  this->networkSockets.push_back( NULL );
     76  this->handshakes.push_back( NULL );
    7577  this->bActive = true;
    7678}
     
    128130void NetworkStream::processData()
    129131{
    130   //PRINTF(0)("processData()\n");
     132  PRINTF(0)("processData()\n");
    131133  if ( this->type == NET_SERVER )
    132134    this->updateConnectionList();
    133135
    134   for (HandshakeVector::iterator it = handshakes.begin(); it!=handshakes.end(); it++)
    135   {
    136     if ( *it )
    137     {
    138       if ( (*it)->completed() )
     136  for (int i = 0; i<handshakes.size(); i++)
     137  {
     138    if ( handshakes[i] )
     139    {
     140      if ( handshakes[i]->completed() )
    139141      {
    140         if ( (*it)->ok() )
    141         {
    142           NetworkManager::getInstance()->setHostID( (*it)->getHostId() );
    143           myHostId = NetworkManager::getInstance()->getHostID();
    144           delete *it;
    145           *it = NULL;
     142        if ( handshakes[i]->ok() )
     143        {
     144          if ( type != NET_SERVER )
     145          {
     146            NetworkManager::getInstance()->setHostID( handshakes[i]->getHostId() );
     147            myHostId = NetworkManager::getInstance()->getHostID();
     148          }
    146149          PRINT(0)("handshake finished\n");
    147150        }
     
    149152        {
    150153          PRINT(1)("handshake failed!\n");
    151           delete *it;
    152           *it = NULL;
     154          networkSockets[i]->disconnectServer();
    153155          //TODO: handle error
    154156        }
     
    165167  for (SynchronizeableList::iterator it = synchronizeables.begin(); it!=synchronizeables.end(); it++)
    166168  {
    167     if ( (*it)->getOwner() == myHostId )
    168     {
    169       PRINTF(0)("sync: %s\n", (*it)->getName());
    170       reciever = 0;
     169    if ( (*it) && (*it)->getOwner() == myHostId )
     170    {
    171171      do {
    172         dataLength = (*it)->readBytes(downBuffer, DATA_STREAM_BUFFER_SIZE, reciever);
     172        reciever = 0;
     173        dataLength = (*it)->readBytes(downBuffer, DATA_STREAM_BUFFER_SIZE, &reciever);
     174
     175        PRINTF(0)("reciever = %d\n", reciever);
    173176
    174177        if ( dataLength<=0 ){
     
    179182        PRINTF(0)("read %d bytes\n", dataLength);
    180183
    181         dataLength = networkProtocol->createHeader((byte*)downBuffer, dataLength, DATA_STREAM_BUFFER_SIZE, static_cast<const Synchronizeable&>(*(*it)));
     184        if (ClassList::exists((*it)))
     185        {
     186          PRINTF(0)("before cast\n");
     187          dataLength = networkProtocol->createHeader((byte*)downBuffer, dataLength, DATA_STREAM_BUFFER_SIZE, static_cast<const Synchronizeable&>(*(*it)));
     188          PRINTF(0)("after cast\n");
     189        }
     190        else
     191        {
     192          PRINTF(0)("instance does not exist anymore\n");
     193          //synchronizeables.remove(it);
     194        }
    182195
    183196        if ( dataLength<=0 )
     
    188201          if ( networkSockets[reciever] )
    189202          {
    190             PRINTF(0)("write %d bytes to socket\n", dataLength);
     203            PRINTF(0)("write %d bytes to socket %d\n", dataLength, reciever);
    191204            networkSockets[reciever]->writePacket(downBuffer, dataLength);
    192205          }
     
    198211        else
    199212        {
    200           for ( int i = 1; i<networkSockets.size(); i++)
     213          for ( int i = 0; i<networkSockets.size(); i++)
    201214          {
    202215            if ( networkSockets[i] )
     216            {
     217              PRINTF(0)("write %d bytes to socket %d\n", dataLength, reciever);
    203218              networkSockets[i]->writePacket(downBuffer, dataLength);
     219            }
    204220          }
    205221        }
     
    211227  /* UPSTREAM */
    212228
    213   for ( int i = 1; i<networkSockets.size(); i++)
     229  for ( int i = 0; i<networkSockets.size(); i++)
    214230  {
    215231    if ( networkSockets[i] )
Note: See TracChangeset for help on using the changeset viewer.