Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6190 in orxonox.OLD for branches/network/src/lib


Ignore:
Timestamp:
Dec 20, 2005, 2:51:37 PM (19 years ago)
Author:
rennerc
Message:

synchronizeable: added sender parameter to writeBytes
network_stream: creates now a network_game_manager
network_game_manager: implemented some functions

Location:
branches/network/src/lib/network
Files:
8 edited

Legend:

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

    r6139 r6190  
    3737}
    3838
    39 void Handshake::writeBytes( const byte * data, int length )
     39void Handshake::writeBytes( const byte * data, int length, int sender)
    4040{
    4141  PRINTF(5)("Handshake::writeBytes states = %d %d %d %d (%d)\n", hasState( HS_RECVD_INIT ), hasState( HS_RECVD_VER ), hasState( HS_RECVD_HID ), hasState( HS_COMPLETED ), state);
  • branches/network/src/lib/network/handshake.h

    r6139 r6190  
    4242    inline void       doReject(){ setState(HS_DO_REJECT); }
    4343
    44     virtual void      writeBytes(const byte* data, int length);
     44    virtual void      writeBytes(const byte* data, int length, int sender);
    4545    virtual int       readBytes(byte* data, int maxLength, int * reciever);
    4646    virtual void      writeDebug() const;
  • branches/network/src/lib/network/network_game_manager.cc

    r6139 r6190  
    2020#define DEBUG_MODULE_NETWORK
    2121
     22#include "factory.h"
     23#include "network_stream.h"
     24
    2225/* include your own header */
    2326#include "network_game_manager.h"
     
    4144NetworkGameManager::~NetworkGameManager()
    4245{
    43 }
    44 
    45 
    46 void NetworkGameManager::writeBytes(const byte* data, int length)
     46  for ( int i = 0; i<inBuffer.size(); i++)
     47  {
     48    if ( inBuffer[i].buffer )
     49      delete inBuffer[i].buffer;
     50    if ( outBuffer[i].buffer )
     51      delete outBuffer[i].buffer;
     52  }
     53}
     54
     55
     56void NetworkGameManager::writeBytes(const byte* data, int length, int sender)
    4757{
    4858}
     
    121131bool NetworkGameManager::canCreateEntity(int classID)
    122132{
    123 }
     133  return true;
     134}
     135
     136/*!
     137 * Sends the Entities to the new connected client
     138 * @param userID: The ID of the user
     139 */
     140void NetworkGameManager::sendEntityList( int userID )
     141{
     142}
     143
     144/**
     145 * Creates a buffer for user n
     146 * @param n The ID of the user
     147 */
     148void NetworkGameManager::resizeBufferVector( int n )
     149{
     150  for ( int i = inBuffer.size(); i<=n; i++)
     151  {
     152    clientBuffer inBuf;
     153    clientBuffer outBuf;
     154
     155    inBuf.length = 0;
     156    outBuf.length = 0;
     157
     158    inBuf.maxLength = 5*1014;
     159    outBuf.maxLength = 5*1024;
     160
     161    inBuf.buffer = new byte[5*1014];
     162    outBuf.buffer = new byte[5*1014];
     163
     164    inBuffer.push_back(inBuf);
     165    outBuffer.push_back(outBuf);
     166  }
     167}
     168
     169/**
     170 * Creates the entity on this host
     171 * @param classID: ClassID of the entity to create
     172 * @param uniqueID: Unique ID to assign to the synchronizeable
     173 * @param owner: owner of this synchronizealbe
     174 */
     175void NetworkGameManager::doCreateEntity( ClassID classID, int uniqueID, int owner )
     176{
     177  BaseObject * b = Factory::fabricate( classID );
     178
     179  if ( b->isA(CL_SYNCHRONIZEABLE) )
     180  {
     181    Synchronizeable * s = dynamic_cast<Synchronizeable*>(b);
     182    s->setUniqueID( uniqueID );
     183    s->setOwner( owner );
     184    this->networkStream->connectSynchronizeable( *s );
     185  }
     186  else
     187  {
     188    PRINTF(1)("Class with ID %d is not a synchronizeable!", (int)classID);
     189    delete b;
     190  }
     191}
     192
     193/**
     194 * Removes a entity on this host
     195 * @param uniqueID: unique ID assigned with the entity to remove
     196 */
     197void NetworkGameManager::doRemoveEntity( int uniqueID )
     198{
     199  SynchronizeableList::const_iterator it,e;
     200  it = this->networkStream->getSyncBegin();
     201  e = this->networkStream->getSyncEnd();
     202
     203  while ( it != e )
     204  {
     205    if ( (*it)->getUniqueID() == uniqueID )
     206    {
     207      delete *it;
     208      break;
     209    }
     210  }
     211}
     212
     213/**
     214 * Tell the synchronizeable that a user's synchronizeable is out of sync
     215 * @param uniqueID: unique ID assigned with the entity which is out of sync
     216 * @param userID: user ID who's synchronizeable is out of sync
     217 */
     218void NetworkGameManager::doRequestSync( int uniqueID, int userID )
     219{
     220  SynchronizeableList::const_iterator it,e;
     221  it = this->networkStream->getSyncBegin();
     222  e = this->networkStream->getSyncEnd();
     223
     224  while ( it != e )
     225  {
     226    if ( (*it)->getUniqueID() == uniqueID )
     227    {
     228      (*it)->requestSync( userID );
     229      break;
     230    }
     231  }
     232}
  • branches/network/src/lib/network/network_game_manager.h

    r6139 r6190  
    1818 * protocol definition
    1919 *
    20  *  CREATE_ENTITY:      CLASS_ID, UNIQUE_ID, OWNER
    21  *  REMOVE_ENTITY:      UNIQUE_ID
     20 *  CREATE_ENTITY:       CLASS_ID, UNIQUE_ID, OWNER
     21 *  REMOVE_ENTITY:       UNIQUE_ID
    2222 *
    23  *  CREATE_ENTITY_LIST: NUMBER, [CLASS_ID, UNIQUE_ID, OWNER][0..NUMBER]
    24  *  REMOVE_ENTITY_LIST: NUMBER, [UNIQUE_ID][0..NUMBER]
     23 *  CREATE_ENTITY_LIST:  NUMBER, [CLASS_ID, UNIQUE_ID, OWNER][0..NUMBER]
     24 *  REMOVE_ENTITY_LIST:  NUMBER, [UNIQUE_ID][0..NUMBER]
    2525 *
    26  *  REQUEST_CREATE:     CLASS_ID
    27  *  REQUEST_REMOVE:     UNIQUE_ID
     26 *  REQUEST_CREATE:      CLASS_ID
     27 *  REQUEST_REMOVE:      UNIQUE_ID
    2828 *
    29  *  REQUEST_SYNC:       UNIQUE_ID
    30  *  REQUEST_SYNC_LIST:  NUMBER, [UNIQUE_ID][0..NUMBER]
     29 *  REQUEST_CREATE_LIST: NUMBER, [CLASS_ID][0..NUMBER]
     30 *  REQUEST_CREATE_LIST: NUMBER, [UNIQUE_ID][0..NUMBER]
     31 *
     32 *  REQUEST_SYNC:        UNIQUE_ID
     33 *  REQUEST_SYNC_LIST:   NUMBER, [UNIQUE_ID][0..NUMBER]
    3134 *
    3235 *
    3336 */
    3437
     38typedef enum NetworkGameManagerProtocol{
     39  CREATE_ENTITY = 0,
     40  REMOVE_ENTITY,
     41  REQUEST_CREATE,
     42  REQUEST_SYNC
     43};
    3544
    36 
    37 
    38 
    39 
    40 
    41 
    42 
     45struct clientBuffer
     46{
     47  int length;
     48  int maxLength;
     49  byte * buffer;
     50};
    4351
    4452/*!
     
    5159    ~NetworkGameManager();
    5260
    53     virtual void writeBytes(const byte* data, int length);
     61    virtual void writeBytes(const byte* data, int length, int sender);
    5462    virtual int readBytes(byte* data, int maxLength, int * reciever);
    5563    virtual void writeDebug() const;
     
    5765
    5866    void createEntity(int classID);
    59     void createEntityList(int* classIDList);
    6067    void removeEntity(int uniqueID);
    61     void removeEntityList(int* uniqueIDList);
    6268
    6369    void sync(int uniqueID);
    64     void syncList(int* uniqueIDList);
    6570
     71    void sendEntityList(int userID);
    6672
    6773  private:
    6874    void requestCreateEntity(int classID);
    6975    void executeCreateEntity(int classID);
    70     void requestCreateEntityList(int* classIDList);
    71     void executeCreateEntityList(int* classIDList);
    7276
    7377    void requestRemoveEntity(int uniqueID);
    7478    void executeRemoveEntity(int uniqueID);
    75     void requestRemoveEntityList(int* uniqueIDList);
    76     void executeRemoveEntityList(int* uniqueIDList);
    7779
    78 
     80    void doCreateEntity(ClassID classID, int uniqueID, int owner);
     81    void doRemoveEntity(int uniqueID);
     82    void doRequestSync(int uniqueID, int userID);
    7983
    8084    bool canCreateEntity(int classID);
    8185
    82 
     86    void resizeBufferVector(int n);
    8387
    8488  private:
    85     byte*          inBuffer;
    86     byte*          outBuffer;
     89    std::vector<clientBuffer>     inBuffer;
     90    std::vector<clientBuffer>     outBuffer;
    8791};
    8892
  • branches/network/src/lib/network/network_stream.cc

    r6139 r6190  
    2727#include "synchronizeable.h"
    2828#include "network_manager.h"
     29#include "network_game_manager.h"
    2930#include "list.h"
    3031#include "debug.h"
     
    7778  this->handshakes.push_back( NULL );
    7879  this->bActive = true;
     80  this->networkGameManager = new NetworkGameManager();
     81  // setUniqueID( maxCon+2 ) because we need one id for every handshake
     82  // and one for handshake to reject client maxCon+1
     83  this->networkGameManager->setUniqueID( this->maxConnections+2 );
     84  this->connectSynchronizeable( *(this->networkGameManager) );
    7985
    8086  this->setMaxConnections( 10 );
     
    8894  this->bActive = false;
    8995  this->serverSocket = NULL;
     96  this->networkGameManager = NULL;
    9097  myHostId = 0;
    9198}
     
    175182          }
    176183          PRINT(0)("handshake finished\n");
     184
     185          this->networkGameManager = new NetworkGameManager();
     186          this->networkGameManager->setUniqueID( handshakes[i]->getNetworkGameManagerId() );
     187          this->connectSynchronizeable( *(this->networkGameManager) );
     188
    177189          delete handshakes[i];
    178190          handshakes[i] = NULL;
    179           //TODO: replace handshake by entitymanager
    180191        }
    181192        else
     
    199210  for (SynchronizeableList::iterator it = synchronizeables.begin(); it!=synchronizeables.end(); it++)
    200211  {
    201     //TODO: remove items from synchronizeables if they dont exist
    202212    if ( (*it)!=NULL && (*it)->getOwner() == myHostId )
    203213    {
     
    214224        dataLength = networkProtocol->createHeader((byte*)downBuffer, dataLength, DATA_STREAM_BUFFER_SIZE, static_cast<const Synchronizeable&>(*(*it)));
    215225
    216         //FIXME: this is a hack, find a better way
    217226        Header* header = (Header*)downBuffer;
    218         if ( header->synchronizeableID<100 )
     227        if ( header->synchronizeableID < this->maxConnections )
    219228          header->synchronizeableID = 0;
    220229
     
    284293        {
    285294          if ( *it && (*it)->getUniqueID()==header.synchronizeableID )
    286             (*it)->writeBytes(upBuffer+sizeof(header), dataLength);
     295            (*it)->writeBytes(upBuffer+sizeof(header), dataLength, i);
    287296        }
    288297
     
    306315      freeSocketSlots.pop_back();
    307316      networkSockets[clientId] = tempNetworkSocket;
    308       handshakes[clientId] = new Handshake(true, clientId);
     317      handshakes[clientId] = new Handshake(true, clientId, this->networkGameManager->getUniqueID());
    309318      handshakes[clientId]->setUniqueID(clientId);
    310319    } else
     
    312321      clientId = networkSockets.size();
    313322      networkSockets.push_back(tempNetworkSocket);
    314       Handshake* tHs = new Handshake(true, clientId);
     323      Handshake* tHs = new Handshake(true, clientId, this->networkGameManager->getUniqueID());
    315324      tHs->setUniqueID(clientId);
    316325      handshakes.push_back(tHs);
     
    374383  }
    375384  this->maxConnections = n;
    376 }
    377 
    378 
     385  this->networkGameManager->setUniqueID( n+2 );
     386}
     387
     388
  • branches/network/src/lib/network/network_stream.h

    r6139 r6190  
    2020class ConnectionMonitor;
    2121class NetworkProtocol;
     22class NetworkGameManager;
    2223
    2324typedef std::list<Synchronizeable*>  SynchronizeableList;
     
    4849    virtual void processData();
    4950
     51    inline SynchronizeableList::const_iterator getSyncBegin(){ return synchronizeables.begin(); }
     52    inline SynchronizeableList::const_iterator getSyncEnd(){ return synchronizeables.end(); }
     53
    5054  private:
    5155    NetworkProtocol*       networkProtocol;
     
    6367    int                    maxConnections;
    6468
     69    NetworkGameManager*   networkGameManager;
     70
    6571    void updateConnectionList();
    6672};
  • branches/network/src/lib/network/synchronizeable.cc

    r6146 r6190  
    5959 *  write data to NetworkStream
    6060 */
    61 void Synchronizeable::writeBytes(const byte* data, int length)
     61void Synchronizeable::writeBytes(const byte* data, int length, int sender)
    6262{
    6363  PRINTF(1)("Synchronizeable::writeBytes was called\n");
  • branches/network/src/lib/network/synchronizeable.h

    r6139 r6190  
    3030    ~Synchronizeable();
    3131
    32     virtual void      writeBytes(const byte* data, int length);
     32    virtual void      writeBytes(const byte* data, int length, int sender);
    3333    virtual int       readBytes(byte* data, int maxLength, int * reciever);
    3434    virtual void      writeDebug() const;
     
    6060    std::list<int> synchronizeRequests;
    6161
     62  protected:
    6263    NetworkStream* networkStream;
    6364
Note: See TracChangeset for help on using the changeset viewer.