Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8708 in orxonox.OLD for trunk/src/lib


Ignore:
Timestamp:
Jun 22, 2006, 12:48:01 PM (18 years ago)
Author:
bensch
Message:

merged network back
merged with command:
svn merge -r8625:HEAD https://svn.orxonox.net/orxonox/branches/network .
no conflicts

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

Legend:

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

    r8623 r8708  
    1919
    2020#include "network_stream.h"
     21#include "shared_network_data.h"
    2122
    2223using namespace std;
     
    196197        msg.number = userId;
    197198       
    198         incomingMessabeBuffer.push_back( msg );
     199        incomingMessageBuffer.push_back( msg );
    199200      }
    200201      messageQueue[userId].recievedMessages.push_back( number );
     
    204205 
    205206 
    206   for ( std::list<NetworkMessage>::iterator it = incomingMessabeBuffer.begin(); it != incomingMessabeBuffer.end();  )
     207  //TODO maybe handle incomingMessage in tick function. else local messages will not be handled if no clients are connected
     208  for ( std::list<NetworkMessage>::iterator it = incomingMessageBuffer.begin(); it != incomingMessageBuffer.end();  )
    207209  {
    208210    if ( (*(messageHandlerMap[it->messageId].cb))( it->messageId, it->data, it->length, messageHandlerMap[it->messageId].someData, it->number ) )
     
    212214        delete it->data;
    213215      it++;
    214       incomingMessabeBuffer.erase( delIt );
     216      incomingMessageBuffer.erase( delIt );
    215217      continue;
    216218    }
     
    328330
    329331      it->second.messages.push_back( msg );
    330      
    331      
    332332    }
    333333  }
     
    341341    msg.length = dataLength;
    342342    msg.messageId = messageId;
    343     msg.number = newNumber++;
     343    msg.number = SharedNetworkData::getInstance()->getHostID();
    344344    msg.priority = messagePriority;
    345345
    346     incomingMessabeBuffer.push_back( msg );
    347   }
    348 }
    349 
    350 
     346    incomingMessageBuffer.push_back( msg );
     347  }
     348}
     349
     350
  • trunk/src/lib/network/message_manager.h

    r8623 r8708  
    109109
    110110   int                       newNumber;              //!< used to create unique message numbers
    111    std::list<NetworkMessage> incomingMessabeBuffer;
     111   std::list<NetworkMessage> incomingMessageBuffer;
    112112
    113113};
  • trunk/src/lib/network/network_game_manager.cc

    r8623 r8708  
    112112  stats->setUniqueID( SharedNetworkData::getInstance()->getNewUniqueID() );
    113113  stats->setSynchronized( true );
    114   stats->setOwner( getHostID() );
     114  stats->setOwner( SharedNetworkData::getInstance()->getHostID() );
    115115 
    116116  stats->setTeamId( team );
     
    247247{
    248248  if ( isServer() )
    249     setPreferedTeam( getHostID(), teamId );
     249    setPreferedTeam( SharedNetworkData::getInstance()->getHostID(), teamId );
    250250  else
    251251  {
     
    284284bool NetworkGameManager::chatMessageHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId )
    285285{
     286  PRINTF(0)("NetworkGameManager::chatMessageHandler %d %d\n", userId, SharedNetworkData::getInstance()->getHostID() );
     287  if ( NetworkGameManager::getInstance()->isServer() && userId !=  SharedNetworkData::getInstance()->getHostID() )
     288  {
     289    MessageManager::getInstance()->sendMessage( messageId, data, dataLength, RT_ALL_NOT_ME, 0, MP_HIGHBANDWIDTH );
     290  }
     291 
    286292  assert( State::getGameRules() );
    287293  assert( State::getGameRules()->isA( CL_NETWORK_GAME_RULES ) );
     
    289295  NetworkGameRules & rules = *(dynamic_cast<NetworkGameRules*>(State::getGameRules()));
    290296 
    291   if ( dataLength < 2*INTSIZE )
     297  if ( dataLength < 3*INTSIZE )
    292298  {
    293299    PRINTF(2)("got too small chatmessage from client %d\n", userId);
     
    298304  int messageType = 0;
    299305  Converter::byteArrayToInt( data, &messageType );
     306  int senderUserId = 0;
     307  Converter::byteArrayToInt( data+INTSIZE, &senderUserId );
    300308  std::string message;
    301   Converter::byteArrayToString( data+INTSIZE, message, dataLength-INTSIZE );
    302  
    303   rules.handleChatMessage( userId, message, messageType );
     309  Converter::byteArrayToString( data+2*INTSIZE, message, dataLength-2*INTSIZE );
     310 
     311  rules.handleChatMessage( senderUserId, message, messageType );
    304312
    305313  return true;
     
    310318 * @param message message text
    311319 * @param messageType some int
    312  * @param userId user to send message to -1 = ALL
    313  */
    314 void NetworkGameManager::sendChatMessage( const std::string & message, int messageType, int userId )
    315 {
    316   byte * buf = new byte[message.length()+2*INTSIZE];
     320 */
     321void NetworkGameManager::sendChatMessage( const std::string & message, int messageType )
     322{
     323  byte * buf = new byte[message.length()+3*INTSIZE];
    317324
    318325  assert( Converter::intToByteArray( messageType, buf, INTSIZE ) == INTSIZE );
    319   assert( Converter::stringToByteArray(message, buf+INTSIZE, message.length()+INTSIZE) == message.length()+INTSIZE );
    320  
    321   if ( userId == -1 )
    322     MessageManager::getInstance()->sendMessage( MSGID_CHATMESSAGE, buf, message.length()+2*INTSIZE, RT_ALL_ME, 0, MP_HIGHBANDWIDTH );
     326  assert( Converter::intToByteArray( SharedNetworkData::getInstance()->getHostID(), buf+INTSIZE, INTSIZE ) == INTSIZE );
     327  assert( Converter::stringToByteArray(message, buf+2*INTSIZE, message.length()+INTSIZE) == message.length()+INTSIZE );
     328 
     329  if ( this->isServer() )
     330    MessageManager::getInstance()->sendMessage( MSGID_CHATMESSAGE, buf, message.length()+3*INTSIZE, RT_ALL_ME, 0, MP_HIGHBANDWIDTH );
    323331  else
    324     MessageManager::getInstance()->sendMessage( MSGID_CHATMESSAGE, buf, message.length()+2*INTSIZE, RT_USER, userId, MP_HIGHBANDWIDTH );
     332    MessageManager::getInstance()->sendMessage( MSGID_CHATMESSAGE, buf, message.length()+3*INTSIZE, RT_ALL_NOT_ME, 0, MP_HIGHBANDWIDTH );
     333
    325334 
    326335  delete [] buf;
  • trunk/src/lib/network/network_game_manager.h

    r8623 r8708  
    6565    void tick( float ds );
    6666   
    67     void sendChatMessage( const std::string & message, int messageType, int userId = -1 );
     67    void sendChatMessage( const std::string & message, int messageType );
    6868
    6969  private:
  • trunk/src/lib/network/network_manager.cc

    r8228 r8708  
    144144  this->elapsedTime = 0.0f;
    145145
    146   if ( networkStream->isActive() )
     146//  if ( networkStream->isActive() )
    147147    networkStream->processData();
    148148 
  • trunk/src/lib/network/player_stats.cc

    r8623 r8708  
    9595    this->setPlayableUniqueId( this->playableUniqueId );
    9696   
    97     PRINTF(0)("uniqueID changed %d %d %d\n", userId, getHostID(), getUniqueID());
     97    PRINTF(0)("uniqueID changed %d %d %d\n", userId, SharedNetworkData::getInstance()->getHostID(), getUniqueID());
    9898  }
    9999 
     
    155155  }
    156156 
    157   if ( this->playable && userId == getHostID() )
     157  if ( this->playable && userId == SharedNetworkData::getInstance()->getHostID() )
    158158  {
    159159    State::getPlayer()->setPlayable( this->playable );
  • trunk/src/lib/network/synchronizeable.cc

    r8623 r8708  
    3838  this->setClassID(CL_SYNCHRONIZEABLE, "Synchronizeable");
    3939  this->owner = 0;
    40   this->hostID = SharedNetworkData::getInstance()->getHostID();
    41   this->setIsServer(this->hostID == 0);
     40  this->setIsServer(SharedNetworkData::getInstance()->getHostID() == 0);
    4241  this->uniqueID = NET_UID_UNASSIGNED;
    4342  this->networkStream = NULL;
     
    222221    hasPermission = (
    223222            this->isServer() && (*it)->checkPermission( PERMISSION_SERVER ) ||
    224             this->owner == this->hostID && (*it)->checkPermission( PERMISSION_OWNER ) ||
     223        this->owner == SharedNetworkData::getInstance()->getHostID() && (*it)->checkPermission( PERMISSION_OWNER ) ||
    225224            this->isServer() && this->owner != userId && (*it)->checkPermission( PERMISSION_OWNER ) ||
    226225            (*it)->checkPermission( PERMISSION_ALL )
     
    345344        (*it)->checkPermission( PERMISSION_SERVER ) && networkStream->isUserServer( userId ) ||
    346345        (*it)->checkPermission( PERMISSION_OWNER ) && this->owner == userId ||
    347         networkStream->isUserServer( userId ) && this->owner != getHostID() && (*it)->checkPermission( PERMISSION_OWNER ) ||
     346        networkStream->isUserServer( userId ) && this->owner != SharedNetworkData::getInstance()->getHostID() && (*it)->checkPermission( PERMISSION_OWNER ) ||
    348347        (*it)->checkPermission( PERMISSION_ALL )
    349348       )
  • trunk/src/lib/network/synchronizeable.h

    r8068 r8708  
    6767    inline void setUniqueID( int id ){ uniqueID = id; }
    6868    inline int  getUniqueID() const { return uniqueID; }
    69     inline int getHostID() { return this->hostID; }
    7069
    7170    inline int getOwner(){ return owner; }
     
    8988    int               mLeafClassId;   //!< store leafClassId to send via states
    9089    int               owner;          //!< hostId of owner ( 0 if none / server )
    91     int               hostID;         //!< my own host id
    9290    bool              bSynchronize;   //!< do we need beeing synchronized?
    9391
Note: See TracChangeset for help on using the changeset viewer.