Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 18, 2006, 10:48:17 AM (18 years ago)
Author:
rennerc
Message:

started implementing MessageManager

File:
1 edited

Legend:

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

    r7659 r7671  
    2929#include "network_game_manager.h"
    3030#include "shared_network_data.h"
     31#include "message_manager.h"
    3132
    3233#include "lib/util/loading/factory.h"
     
    199200
    200201  handleHandshakes();
     202  handleDownstream();
    201203  handleUpstream();
    202   handleDownstream();
    203 
    204 
    205 
    206   /* DOWNSTREAM */
    207 #if 0
    208 
    209 
    210   int dataLength;
    211   int reciever;
    212   Header header;
    213   int counter;
    214 
    215   for (SynchronizeableList::iterator it = synchronizeables.begin(); it!=synchronizeables.end(); it++)
    216   {
    217     counter = 0;
    218 
    219     if ( (*it)!=NULL && (*it)->beSynchronized() /*&& (*it)->getOwner() == myHostId*/ )
    220     {
    221       do {
    222         counter++;
    223 
    224         reciever = 0;
    225 #warning fix this
    226 dataLength = 0;
    227 //TODO fix
    228         //dataLength = (*it)->readBytes(downBuffer, DATA_STREAM_BUFFER_SIZE, &reciever);
    229 
    230         if ( dataLength<=0 ){
    231           reciever = 0;
    232           continue;
    233         }
    234 
    235         dataLength = networkProtocol->createHeader((byte*)downBuffer, dataLength, DATA_STREAM_BUFFER_SIZE, static_cast<const Synchronizeable&>(*(*it)));
    236 
    237         Header* header = (Header*)downBuffer;
    238         if ( header->synchronizeableID < this->maxConnections+2 )
    239         {
    240           //if ( !isServer() ) PRINTF(0)("RESET UNIQUEID FROM %d TO 0 maxCon=%d\n", header->synchronizeableID, this->maxConnections);
    241           header->synchronizeableID = 0;
    242         }
    243         else
    244         {
    245           //if ( !isServer() ) PRINTF(0)("UNIQUEID=%d\n", header->synchronizeableID);
    246         }
    247 
    248         if ( dataLength<=0 )
    249           continue;
    250 
    251         if ( reciever!=0 )
    252         {
    253           if ( reciever < 0)
    254           {
    255             for ( int i = 0; i<networkSockets.size(); i++)
    256             {
    257               if ( i!=abs(reciever) && networkSockets[i] != NULL )
    258               {
    259                 PRINTF(0)("write %d bytes to socket %d uniqueid %d reciever %d\n", dataLength, i, (*it)->getUniqueID(), reciever);
    260                 networkSockets[i]->writePacket(downBuffer, dataLength);
    261               }
    262             }
    263           }
    264           else
    265           {
    266             if ( networkSockets[reciever] != NULL )
    267             {
    268               PRINTF(5)("write %d bytes to socket %d\n", dataLength, reciever);
    269               networkSockets[reciever]->writePacket(downBuffer, dataLength);
    270             }
    271             else
    272             {
    273               PRINTF(1)("networkSockets[reciever] == NULL\n");
    274             }
    275           }
    276         }
    277         else
    278         {
    279           for ( int i = 0; i<networkSockets.size(); i++)
    280           {
    281             if ( networkSockets[i] != NULL )
    282             {
    283               PRINTF(5)("write %d bytes to socket %d\n", dataLength, i);
    284               networkSockets[i]->writePacket(downBuffer, dataLength);
    285             }
    286           }
    287         }
    288 
    289       } while( reciever!=0 );
    290     }
    291   }
    292 
    293   /* UPSTREAM */
    294 
    295   for ( int i = 0; i<networkSockets.size(); i++)
    296   {
    297     if ( networkSockets[i] )
    298     {
    299       do {
    300         dataLength = networkSockets[i]->readPacket(upBuffer, DATA_STREAM_BUFFER_SIZE);
    301 
    302         if ( dataLength<=0 )
    303           continue;
    304 
    305         header = networkProtocol->extractHeader(upBuffer, dataLength);
    306         dataLength -= sizeof(header);
    307 
    308         PRINTF(5)("read %d bytes from socket uniqueID = %d\n", dataLength, header.synchronizeableID);
    309 
    310         if ( dataLength != header.length )
    311         {
    312           PRINTF(1)("packetsize in header and real packetsize do not match! %d:%d\n", dataLength, header.length);
    313           continue;
    314         }
    315 
    316         if ( header.synchronizeableID == 0 )
    317         {
    318           header.synchronizeableID = i;
    319         }
    320 
    321         for (SynchronizeableList::iterator it = synchronizeables.begin(); it!=synchronizeables.end(); it++)
    322         {
    323 #warning fix this
    324 
    325           if ( *it && (*it)->getUniqueID()==header.synchronizeableID )
    326           {
    327             if ( (*it)->writeBytes(upBuffer+sizeof(header), dataLength, i) != header.length )
    328             {
    329               PRINTF(1)("%s did not read all the data id = %d!\n", (*it)->getClassName(), (*it)->getUniqueID());
    330               break;
    331             }
    332             continue;
    333           }
    334 
    335         }
    336 
    337       } while ( dataLength>0 );
    338     }
    339 
    340   }
    341 #endif
     204
    342205}
    343206
     
    476339          delete it->second.handshake;
    477340          it->second.handshake = NULL;
     341         
     342          handleNewClient( it->second.userId );
    478343        }
    479344        else
     
    699564}
    700565
    701 
    702 
    703 
    704 
    705 
     566/**
     567 * is executed when a handshake has finished
     568 * @todo create playable for new user
     569 */
     570void NetworkStream::handleNewClient( int userId )
     571{
     572  MessageManager::getInstance()->initUser( userId );
     573}
     574
     575
     576
     577
     578
     579
Note: See TracChangeset for help on using the changeset viewer.