Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8708 in orxonox.OLD for trunk/src


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
Files:
12 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
  • trunk/src/util/multiplayer_team_deathmatch.cc

    r8623 r8708  
    4343
    4444#include "story_entity.h"
     45
     46#include "shell_command.h"
    4547
    4648
     
    8082 
    8183  subscribeEvent( ES_GAME, SDLK_o );
     84  subscribeEvent( ES_GAME, SDLK_TAB );
     85 
     86  this->notifier = new OrxGui::GLGuiNotifier();
     87  this->notifier->show();
     88  this->notifier->setAbsCoor2D(5, 30);
     89  this->notifier->setFadeAge( 6.0 );
     90  this->notifier->setHideAge( 8.0 );
     91  this->input = new OrxGui::GLGuiInputLine();
     92  this->input->setAbsCoor2D(180, 5);
     93  this->input->connect(SIGNAL(input, enterPushed), this, SLOT(MultiplayerTeamDeathmatch, onInputEnter));
    8294}
    8395
     
    91103 
    92104  unsubscribeEvent( ES_GAME, SDLK_o );
     105  unsubscribeEvent( ES_GAME, SDLK_TAB );
     106 
     107  if ( this->notifier )
     108  {
     109    delete this->notifier;
     110    this->notifier = NULL;
     111  }
     112 
     113  if ( this->input )
     114  {
     115    delete this->input;
     116    this->input = NULL;
     117  }
    93118}
    94119
     
    539564      this->bShowTeamChange = true;
    540565  }
     566  else if ( event.type == SDLK_TAB )
     567  {
     568    if ( !event.bPressed )
     569    {
     570      EventHandler::getInstance()->pushState( ES_MENU );
     571      OrxGui::GLGuiHandler::getInstance()->activateCursor();
     572      OrxGui::GLGuiHandler::getInstance()->deactivateCursor();
     573      input->show();
     574      input->giveFocus();
     575      input->setText("say ");
     576    }
     577  }
    541578}
    542579
     
    563600  }
    564601 
    565   PRINTF(0)("CHATMESSAGE %s: %s\n", name.c_str(), message.c_str() );
    566 }
    567 
    568 
    569 
    570 
     602  PRINTF(0)("CHATMESSAGE %s (%d): %s\n", name.c_str(), userId, message.c_str() );
     603  notifier->pushNotifyMessage(name + ": " + message);
     604}
     605
     606void MultiplayerTeamDeathmatch::onInputEnter( const std::string & text )
     607{
     608  EventHandler::getInstance()->popState();
     609  input->breakFocus();
     610  input->hide();
     611  input->setText("");
     612
     613  std::string command = text;
     614 
     615  //HACK insert " in say commands so user doesn't have to type them
     616  if ( command.length() >= 4 && command[0] == 's' && command[1] == 'a' && command[2] == 'y' && command[3] == ' ' )
     617  {
     618    command.insert( 4, "\"" );
     619    command = command + "\"";
     620  }
     621
     622  OrxShell::ShellCommand::execute( command );
     623}
     624
     625
     626
     627
  • trunk/src/util/multiplayer_team_deathmatch.h

    r8623 r8708  
    1313
    1414#include "glgui.h"
     15#include "specials/glgui_notifier.h"
    1516
    1617class TiXmlElement;
     
    8283    OrxGui::GLGuiBox* box;
    8384   
     85    OrxGui::GLGuiNotifier* notifier;
     86    OrxGui::GLGuiInputLine* input;
     87   
    8488    void calculateTeamScore();
    8589    void nextGameState();
     
    9498    void onButtonCancel();
    9599    void onButtonExit();
     100   
     101    void onInputEnter( const std::string & text );
    96102};
    97103
  • trunk/src/world_entities/space_ships/space_ship.cc

    r8228 r8708  
    3333
    3434#include "network_game_manager.h"
     35#include "shared_network_data.h"
    3536
    3637#include "power_ups/weapon_power_up.h"
     
    326327  Playable::tick(time);
    327328
    328   if( ( xMouse != 0 || yMouse != 0 ) && this->getOwner() == this->getHostID() )
     329  if( ( xMouse != 0 || yMouse != 0 ) && this->getOwner() == SharedNetworkData::getInstance()->getHostID() )
    329330   {
    330331    if (xMouse > controlVelocityX) xMouse = controlVelocityX;
  • trunk/src/world_entities/spectator.cc

    r8228 r8708  
    2020#include "key_mapper.h"
    2121
     22#include "shared_network_data.h"
    2223
    2324CREATE_FACTORY(Spectator, CL_SPECTATOR);
     
    161162  Playable::tick( time );
    162163 
    163   if( ( xMouse != 0 || yMouse != 0 ) && this->getOwner() == this->getHostID() )
     164  if( ( xMouse != 0 || yMouse != 0 ) && this->getOwner() == SharedNetworkData::getInstance()->getHostID() )
    164165  {
    165166    xMouse *= time / 10;
Note: See TracChangeset for help on using the changeset viewer.