Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
May 18, 2006, 3:52:44 PM (19 years ago)
Author:
rennerc
Message:

server creates client spaceships now

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

Legend:

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

    r7681 r7693  
    184184    if ( std::find( messageQueue[userId].recievedMessages.begin(), messageQueue[userId].recievedMessages.end(), number )== messageQueue[userId].recievedMessages.end() )
    185185    {
    186       (*(messageHandlerMap[(MessageId)messageId].cb))( (MessageId)messageId, data + i, messageLength, messageHandlerMap[(MessageId)messageId].someData, userId );
     186      if ( !(*(messageHandlerMap[(MessageId)messageId].cb))( (MessageId)messageId, data + i, messageLength, messageHandlerMap[(MessageId)messageId].someData, userId ) )
     187      {
     188        NetworkMessage msg;
     189       
     190        msg.data = new byte[messageLength];
     191        memcpy( msg.data, data + i, messageLength );
     192        msg.length = messageLength;
     193        msg.messageId = (MessageId)messageId;
     194        msg.number = userId;
     195       
     196        incomingMessabeBuffer.push_back( msg );
     197      }
    187198      messageQueue[userId].recievedMessages.push_back( number );
    188199    }
     
    190201  }
    191202 
     203 
     204  for ( std::list<NetworkMessage>::iterator it = incomingMessabeBuffer.begin(); it != incomingMessabeBuffer.end(); it++ )
     205  {
     206    if ( (*(messageHandlerMap[it->messageId].cb))( it->messageId, data + i, it->length, messageHandlerMap[it->messageId].someData, it->number ) )
     207    {
     208      std::list<NetworkMessage>::iterator delIt = it;
     209      it++;
     210      incomingMessabeBuffer.erase( delIt );
     211      continue;
     212    }
     213    it++;
     214  }
    192215 
    193216  //walk throu message queue and remove acked messages
  • branches/network/src/lib/network/message_manager.h

    r7681 r7693  
    2828enum MessageId
    2929{
    30   TESTMESSAGEID = 1
     30  TESTMESSAGEID = 1,
     31  MSGID_YOU_ARE
    3132};
    3233
    33 typedef void (*MessageCallback)( MessageId messageId, byte * data, int dataLength, void * someData, int userId );
     34typedef bool (*MessageCallback)( MessageId messageId, byte * data, int dataLength, void * someData, int userId );
    3435
    3536enum RecieverType
     
    9697
    9798 private:
    98    static MessageManager * singletonRef;
    99    MessageQueue            messageQueue;        //!< stores messages to send
    100    MessageHandlerMap       messageHandlerMap;   //!< contains handlers for messages
     99   static MessageManager *   singletonRef;
     100   MessageQueue              messageQueue;           //!< stores messages to send
     101   MessageHandlerMap         messageHandlerMap;      //!< contains handlers for messages
    101102
    102    int                     newNumber;           //!< used to create unique message numbers
     103   int                       newNumber;              //!< used to create unique message numbers
     104   std::list<NetworkMessage> incomingMessabeBuffer;
    103105
    104106};
  • branches/network/src/lib/network/network_game_manager.cc

    r7567 r7693  
    2727#include "shared_network_data.h"
    2828#include "converter.h"
     29#include "message_manager.h"
    2930
    3031#include "playable.h"
     
    212213  if ( this->isServer())
    213214  {
    214     if ( SharedNetworkData::getInstance()->getNewUniqueID() < 0 )
     215    int res = this->executeCreateEntity( classID, SharedNetworkData::getInstance()->getNewUniqueID(), owner );
     216   
     217    if ( res < 0 )
    215218    {
    216219      PRINTF(1)("Cannot create entity! There are no more uniqueIDs left!\n");
    217220      return -1;
    218221    }
    219     return this->executeCreateEntity( classID, SharedNetworkData::getInstance()->getNewUniqueID(), owner );
     222   
     223    return res;
    220224  }
    221225  else
     
    461465bool NetworkGameManager::signalNewPlayer(int userId)
    462466{
    463 #if 0
    464   if ( userId >= outBuffer.size() )
    465     resizeBufferVector( userId );
    466 
    467467  /* create new playable for Player*/
    468468  PRINTF(0)("Request for creation: %i\n", userId);
     
    470470  PRINTF(0)("Request for creation: userid: %i, uniqueid: %i\n", userId, uniqueId);
    471471  this->sendYouAre(uniqueId, userId);
    472 #endif
    473472}
    474473
     
    709708  if ( !isServer() )
    710709    return;
    711 #if 0
    712   if ( userID != 0 )
    713   {
    714     if ( !writeToClientBuffer( outBuffer[userID], (byte)NET_YOU_ARE_ENTITY ) )
    715       return;
    716 
    717     if ( !writeToClientBuffer( outBuffer[userID], uniqueID ) )
    718       return;
    719   }
    720   else
    721   {
    722 #endif
    723     doYouAre(uniqueID);
    724 #if 0
    725   }
    726 #endif
    727 
     710 
     711  byte buf[INTSIZE];
     712 
     713  Converter::intToByteArray( uniqueID, buf, INTSIZE );
     714 
     715  MessageManager::getInstance()->sendMessage( MSGID_YOU_ARE, buf, INTSIZE, RT_USER, userID, MP_HIGHBANDWIDTH);
    728716}
    729717
     
    939927}
    940928
     929bool NetworkGameManager::youAreHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId )
     930{
     931  assert( dataLength == INTSIZE );
     932  int uniqueId;
     933 
     934  Converter::byteArrayToInt( data, &uniqueId );
     935 
     936  NetworkGameManager::getInstance()->doYouAre( uniqueId );
     937}
     938
    941939#if 0
    942940bool NetworkGameManager::writeToClientBuffer( clientBuffer & cb, byte b )
  • branches/network/src/lib/network/network_game_manager.h

    r7567 r7693  
    1212/* include base_object.h since all classes are derived from this one */
    1313#include "synchronizeable.h"
     14#include "message_manager.h"
    1415
    1516
    1617class TiXmlElement;
    1718class PNode;
    18 
    19 /**
    20  * protocol definition
    21  *
    22  *  CREATE_ENTITY:       >> CLASS_ID, UNIQUE_ID, OWNER
    23  *  REMOVE_ENTITY:       >> UNIQUE_ID
    24  *
    25  *  CREATE_ENTITY_LIST:  >> NUMBER, [CLASS_ID, UNIQUE_ID, OWNER][0..NUMBER]
    26  *  REMOVE_ENTITY_LIST:  >> NUMBER, [UNIQUE_ID][0..NUMBER]
    27  *
    28  *  REQUEST_CREATE:      >> CLASS_ID
    29  *                       << [Sync Info]
    30  *  REQUEST_REMOVE:      >> UNIQUE_ID
    31  *                       << [Sync Info]
    32  *
    33  *  //REQUEST_CREATE_LIST: NUMBER, [CLASS_ID][0..NUMBER]
    34  *  //REQUEST_CREATE_LIST: NUMBER, [UNIQUE_ID][0..NUMBER]
    35  *
    36  *  REQUEST_ENTITY_LIST: //request the whole world :D
    37  *  YOU_ARE_ENTITY:      >> UNIQUE_ID
    38  *
    39  *  REQUEST_PNODE_PATH   >> UNIQUE_ID_START   UNIQUE_ID_STOP
    40  *                       << UNIQUE_ID_1   UNIQUE_ID_2   UNIQUE_ID_3 ...   UNIQUE_ID_N
    41  *
    42  *  SEND_PNODE_PATH      >> UNIQUE_ID_START   UNIQUE_ID_STOP NUMBER [UNIQUE_ID][0..NUMBER]
    43  */
    4419
    4520typedef enum NetworkGameManagerProtocol {
     
    9873  private:
    9974    NetworkGameManager();
     75   
     76    static bool youAreHandler(MessageId messageId, byte * data, int dataLength, void * someData, int userId );
    10077
    10178
  • branches/network/src/lib/network/network_stream.cc

    r7684 r7693  
    569569 * @todo create playable for new user
    570570 */
     571#include "world_entities/space_ships/space_ship.h"
    571572void NetworkStream::handleNewClient( int userId )
    572573{
    573574  MessageManager::getInstance()->initUser( userId );
    574 }
    575 
    576 
    577 
    578 
    579 
    580 
     575 
     576  networkGameManager->signalNewPlayer( userId );
     577}
     578
     579
     580
     581
     582
     583
Note: See TracChangeset for help on using the changeset viewer.