Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8623 in orxonox.OLD for trunk/src


Ignore:
Timestamp:
Jun 20, 2006, 1:39:01 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the network branche back here
merged with command:
svn merge -r8230:HEAD https://svn.orxonox.net/orxonox/branches/network .
conflicts resolved in favour of the network branche (conflicts were in network)

Location:
trunk/src
Files:
28 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/event/event_handler.cc

    r8619 r8623  
    503503
    504504
     505int EventHandler::releaseMouse(void* p)
     506{
     507  SDL_WM_GrabInput(SDL_GRAB_OFF);
     508  SDL_ShowCursor(SDL_DISABLE);
     509  return 0;
     510}
     511
     512
    505513/**
    506514 * @param state The State to get the Name of.
  • trunk/src/lib/event/event_handler.h

    r8148 r8623  
    5656  static elState StringToELState(const std::string& stateName);
    5757
     58  static int releaseMouse(void* p);
     59
    5860private:
    5961  EventHandler();
  • trunk/src/lib/network/Makefile.am

    r8068 r8623  
    2424                      zip.cc \
    2525                      player_stats.cc \
     26                      udp_broadcast.cc \
    2627                      \
    2728                      synchronizeable_var/synchronizeable_var.cc \
     
    5859                 zip.h \
    5960                 player_stats.h \
     61                 udp_broadcast.h \
    6062                 \
    6163                 synchronizeable_var/synchronizeable_var.h \
  • trunk/src/lib/network/connection_monitor.cc

    r8068 r8623  
    130130
    131131/**
     132 * remove old packets
     133 * @param packetHistory
     134 * @param tick
     135 */
     136void ConnectionMonitor::removeOldPackets( std::map< int, int > & packetHistory, int tick )
     137{
     138  while ( packetHistory.begin()->first < tick - MSECS_TO_CALC_BWIDTH )
     139    packetHistory.erase( packetHistory.begin() );
     140}
     141
     142/**
    132143 * calculate bandwidth out of packethistory
    133144 * @param packetHistory packet history
     
    135146 * @return bandwidth in bytes/sec
    136147 */
    137 float ConnectionMonitor::calculateBandWidth( std::map< int, int > packetHistory, int tick )
    138 {
    139   // delete old packets
    140   while ( packetHistory.begin()->first < tick - MSECS_TO_CALC_BWIDTH )
    141     packetHistory.erase( packetHistory.begin() );
     148float ConnectionMonitor::calculateBandWidth( std::map< int, int > & packetHistory, int tick )
     149{
     150  removeOldPackets( packetHistory, tick );
    142151 
    143152  float res = 0.0f;
    144  
     153#if 0
    145154  for ( std::map<int,int>::iterator it = packetHistory.begin(); it != packetHistory.end(); it++ )
    146155  {
     
    155164 
    156165  res *= 1000.0f;
    157  
     166#endif
     167
     168  for ( std::map<int,int>::iterator it = packetHistory.begin(); it != packetHistory.end(); it++ )
     169  {
     170    res += it->second;
     171  }
     172 
     173  if ( packetHistory.size() <= 1 )
     174    res = 0.0f;
     175  else
     176    res /= (float)(tick - packetHistory.begin()->first);
     177 
     178  res *= 1000.0f;
     179
    158180  return res;
    159181}
  • trunk/src/lib/network/connection_monitor.h

    r8362 r8623  
    1515#define N_PACKETS_FOR_PING 20
    1616#define MSECS_TO_CALC_BWIDTH 1000
    17 #define SECS_TO_TIMEOUT 10
     17#define SECS_TO_TIMEOUT 30
    1818
    1919class ConnectionMonitor : virtual public BaseObject
     
    3636
    3737  private:
    38     float calculateBandWidth( std::map<int,int> packetHistory, int tick );
     38    float calculateBandWidth( std::map<int,int> & packetHistory, int tick );
     39    void removeOldPackets( std::map<int,int> & packetHistory, int tick );
    3940
    4041    int userId;       //!< user's id
  • trunk/src/lib/network/data_stream.cc

    r7954 r8623  
    5353DataStream::~DataStream()
    5454{
    55 
     55  delete [] this->upBuffer;
     56  this->upBuffer = NULL;
     57  delete [] this->downBuffer;
     58  this->downBuffer = NULL;
    5659}
    5760
     
    120123int passUp(byte* data)
    121124{
    122 
     125  return 0;
    123126}
  • trunk/src/lib/network/message_manager.cc

    r8228 r8623  
    4747      if ( it2->data )
    4848      {
    49         delete it2->data;
     49        delete [] it2->data;
    5050        it2->data = NULL;
    5151      }
     
    319319    {
    320320      NetworkMessage msg;
    321      
     321
    322322      msg.data = new byte[dataLength];
    323323      memcpy( msg.data, data, dataLength );
     
    326326      msg.number = newNumber++;
    327327      msg.priority = messagePriority;
    328      
     328
    329329      it->second.messages.push_back( msg );
    330330     
    331       if ( recieverType == RT_ALL_ME )
    332         incomingMessabeBuffer.push_back( msg );
    333     }
    334   }
    335 }
    336 
    337 
     331     
     332    }
     333  }
     334 
     335  if ( recieverType == RT_ALL_ME )
     336  {
     337    NetworkMessage msg;
     338
     339    msg.data = new byte[dataLength];
     340    memcpy( msg.data, data, dataLength );
     341    msg.length = dataLength;
     342    msg.messageId = messageId;
     343    msg.number = newNumber++;
     344    msg.priority = messagePriority;
     345
     346    incomingMessabeBuffer.push_back( msg );
     347  }
     348}
     349
     350
  • trunk/src/lib/network/message_manager.h

    r8228 r8623  
    3131  MSGID_DELETESYNCHRONIZEABLE,
    3232  MSGID_PREFEREDTEAM,
    33   MSGID_CHANGEPLAYERNAME
     33  MSGID_CHANGENICKNAME,
     34  MSGID_CHATMESSAGE
    3435};
    3536
  • trunk/src/lib/network/network_game_manager.cc

    r8362 r8623  
    2323#include "state.h"
    2424#include "class_list.h"
     25#include "debug.h"
    2526
    2627#include "network_stream.h"
     
    3940#include "network_game_manager.h"
    4041
    41 #include "debug.h"
    42 
    4342
    4443/* using namespace std is default, this needs to be here */
     
    5958
    6059  this->setSynchronized(true);
    61 
     60 
    6261  MessageManager::getInstance()->registerMessageHandler( MSGID_DELETESYNCHRONIZEABLE, delSynchronizeableHandler, NULL );
    6362  MessageManager::getInstance()->registerMessageHandler( MSGID_PREFEREDTEAM, preferedTeamHandler, NULL );
    64 
     63  MessageManager::getInstance()->registerMessageHandler( MSGID_CHATMESSAGE, chatMessageHandler, NULL );
     64 
    6565  this->gameState = 0;
    6666  registerVar( new SynchronizeableInt( &gameState, &gameState, "gameState" ) );
     
    7272NetworkGameManager::~NetworkGameManager()
    7373{
     74  delete MessageManager::getInstance();
     75 
     76  PlayerStats::deleteAllPlayerStats();
    7477}
    7578
     
    7780/**
    7881 * insert new player into game
    79  * @param userId
    80  * @return
     82 * @param userId 
     83 * @return 
    8184 */
    8285bool NetworkGameManager::signalNewPlayer( int userId )
     
    8588  assert( State::getGameRules() );
    8689  assert( State::getGameRules()->isA( CL_NETWORK_GAME_RULES ) );
    87 
     90 
    8891  NetworkGameRules & rules = *(dynamic_cast<NetworkGameRules*>(State::getGameRules()));
    89 
     92 
    9093  int team = rules.getTeamForNewUser();
    9194  ClassID playableClassId = rules.getPlayableClassId( userId, team );
    9295  std::string playableModel = rules.getPlayableModelFileName( userId, team, playableClassId );
    93 
     96 
    9497  BaseObject * bo = Factory::fabricate( playableClassId );
    95 
     98 
    9699  assert( bo != NULL );
    97100  assert( bo->isA( CL_PLAYABLE ) );
    98 
     101 
    99102  Playable & playable = *(dynamic_cast<Playable*>(bo));
    100 
    101   playable.loadModel( playableModel );
     103 
     104  if (  playableModel != "" )
     105    playable.loadModel( playableModel );
    102106  playable.setOwner( userId );
    103107  playable.setUniqueID( SharedNetworkData::getInstance()->getNewUniqueID() );
    104108  playable.setSynchronized( true );
    105 
     109 
    106110  PlayerStats * stats = rules.getNewPlayerStats( userId );
    107 
     111 
    108112  stats->setUniqueID( SharedNetworkData::getInstance()->getNewUniqueID() );
    109113  stats->setSynchronized( true );
    110114  stats->setOwner( getHostID() );
    111 
     115 
    112116  stats->setTeamId( team );
    113117  stats->setPlayableClassId( playableClassId );
    114118  stats->setPlayableUniqueId( playable.getUniqueID() );
    115119  stats->setModelFileName( playableModel );
    116 
     120 
    117121  return true;
    118122}
     
    121125/**
    122126 * remove player from game
    123  * @param userID
    124  * @return
     127 * @param userID 
     128 * @return 
    125129 */
    126130bool NetworkGameManager::signalLeftPlayer(int userID)
     
    132136    delete PlayerStats::getStats( userID );
    133137  }
    134 
     138 
    135139  return true;
    136140}
     
    140144/**
    141145 * handler for remove synchronizeable messages
    142  * @param messageId
    143  * @param data
    144  * @param dataLength
    145  * @param someData
    146  * @param userId
     146 * @param messageId 
     147 * @param data 
     148 * @param dataLength 
     149 * @param someData 
     150 * @param userId 
    147151 * @return true on successfull handling else handler will be called again
    148152 */
     
    154158    return true;
    155159  }
    156 
     160 
    157161  int uniqueId = 0;
    158162  int len = Converter::byteArrayToInt( data, &uniqueId );
    159 
     163 
    160164  if ( len != dataLength )
    161165  {
     
    163167    return true;
    164168  }
    165 
     169 
    166170  const std::list<BaseObject*> * list = ClassList::getList( CL_SYNCHRONIZEABLE );
    167 
     171 
    168172  for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ )
    169173  {
     
    175179        return true;
    176180      }
    177 
     181     
    178182      delete dynamic_cast<Synchronizeable*>(*it);
    179183      return true;
    180184    }
    181185  }
    182 
     186 
    183187  return true;
    184188}
     
    191195{
    192196  byte buf[INTSIZE];
    193 
     197 
    194198  assert( Converter::intToByteArray( uniqueId, buf, INTSIZE ) == INTSIZE );
    195199
     
    201205/**
    202206 * handler for MSGID_PREFEREDTEAM message
    203  * @param messageId
    204  * @param data
    205  * @param dataLength
    206  * @param someData
    207  * @param userId
    208  * @return
     207 * @param messageId 
     208 * @param data 
     209 * @param dataLength 
     210 * @param someData 
     211 * @param userId 
     212 * @return 
    209213 */
    210214bool NetworkGameManager::preferedTeamHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId )
    211215{
    212216  assert( NetworkGameManager::getInstance()->isServer() );
    213 
     217 
    214218  int teamId = 0;
    215219  int len = Converter::byteArrayToInt( data, &teamId );
    216 
     220 
    217221  if ( len != dataLength )
    218222  {
     
    220224    return true;
    221225  }
    222 
     226 
    223227  NetworkGameManager::getInstance()->setPreferedTeam( userId, teamId );
    224 
     228 
    225229  return true;
    226230}
     
    230234  if ( !PlayerStats::getStats( userId ) )
    231235    return;
    232 
     236 
    233237  PlayerStats & stats = *(PlayerStats::getStats( userId ));
    234 
     238 
    235239  stats.setPreferedTeamId( teamId );
    236240}
     
    238242/**
    239243 * set prefered team for this host
    240  * @param teamId
     244 * @param teamId 
    241245 */
    242246void NetworkGameManager::prefereTeam( int teamId )
     
    247251  {
    248252    byte buf[INTSIZE];
    249 
     253   
    250254    assert( Converter::intToByteArray( teamId, buf, INTSIZE) == INTSIZE );
    251 
     255   
    252256    MessageManager::getInstance()->sendMessage( MSGID_PREFEREDTEAM, buf, INTSIZE, RT_USER, 0, MP_HIGHBANDWIDTH );
    253257  }
     
    278282
    279283
    280 
     284bool NetworkGameManager::chatMessageHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId )
     285{
     286  assert( State::getGameRules() );
     287  assert( State::getGameRules()->isA( CL_NETWORK_GAME_RULES ) );
     288 
     289  NetworkGameRules & rules = *(dynamic_cast<NetworkGameRules*>(State::getGameRules()));
     290 
     291  if ( dataLength < 2*INTSIZE )
     292  {
     293    PRINTF(2)("got too small chatmessage from client %d\n", userId);
     294   
     295    return true;
     296  }
     297 
     298  int messageType = 0;
     299  Converter::byteArrayToInt( data, &messageType );
     300  std::string message;
     301  Converter::byteArrayToString( data+INTSIZE, message, dataLength-INTSIZE );
     302 
     303  rules.handleChatMessage( userId, message, messageType );
     304
     305  return true;
     306}
     307
     308/**
     309 * send chat message
     310 * @param message message text
     311 * @param messageType some int
     312 * @param userId user to send message to -1 = ALL
     313 */
     314void NetworkGameManager::sendChatMessage( const std::string & message, int messageType, int userId )
     315{
     316  byte * buf = new byte[message.length()+2*INTSIZE];
     317
     318  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 );
     323  else
     324    MessageManager::getInstance()->sendMessage( MSGID_CHATMESSAGE, buf, message.length()+2*INTSIZE, RT_USER, userId, MP_HIGHBANDWIDTH );
     325 
     326  delete [] buf;
     327}
     328
     329
     330
  • trunk/src/lib/network/network_game_manager.h

    r8147 r8623  
    6464   
    6565    void tick( float ds );
     66   
     67    void sendChatMessage( const std::string & message, int messageType, int userId = -1 );
    6668
    6769  private:
     
    7072    static bool delSynchronizeableHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId );
    7173    static bool preferedTeamHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId );
     74    static bool chatMessageHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId );
    7275   
    7376    void setPreferedTeam( int userId, int teamId );
  • trunk/src/lib/network/network_stream.cc

    r8228 r8623  
    9595  remainingBytesToWriteToDict = Preferences::getInstance()->getInt( "compression", "writedict", 0 );
    9696 
    97   assert( Zip::getInstance()->loadDictionary( "testdict" ) );
     97  assert( Zip::getInstance()->loadDictionary( "testdict" ) >= 0 );
     98  this->dictClient = Zip::getInstance()->loadDictionary( "dict2pl_client" );
     99  assert( this->dictClient >= 0 );
     100  this->dictServer = Zip::getInstance()->loadDictionary( "dict2p_server" );
     101  assert( this->dictServer >= 0 );
    98102}
    99103
     
    121125      delete i->second.handshake;
    122126      i->second.handshake = NULL;
     127    }
     128   
     129    if ( i->second.connectionMonitor )
     130    {
     131      delete i->second.connectionMonitor;
     132      i->second.connectionMonitor = NULL;
    123133    }
    124134  }
     
    198208        delete peers[0].handshake;
    199209      peers[0].handshake = NULL;
     210     
     211      if ( peers[0].connectionMonitor )
     212        delete peers[0].connectionMonitor;
     213      peers[0].connectionMonitor = NULL;
    200214    }
    201215  }
     
    282296      it->second.socket = NULL;
    283297
     298      if ( it->second.connectionMonitor )
     299        delete it->second.connectionMonitor;
     300      it->second.connectionMonitor = NULL;
     301     
    284302      if ( it->second.handshake )
    285303        delete it->second.handshake;
     
    490508    assert( Converter::intToByteArray( offset, buf, INTSIZE ) == INTSIZE );
    491509   
    492     int compLength = Zip::getInstance()->zip( buf, offset, compBuf, UDP_PACKET_SIZE );
    493    
    494     if ( compLength < 0 )
     510    int compLength = 0;
     511    if ( this->isServer() )
     512      compLength = Zip::getInstance()->zip( buf, offset, compBuf, UDP_PACKET_SIZE, dictServer );
     513    else
     514      compLength = Zip::getInstance()->zip( buf, offset, compBuf, UDP_PACKET_SIZE, dictClient );
     515   
     516    if ( compLength <= 0 )
    495517    {
    496518      PRINTF(1)("compression failed!\n");
     
    501523   
    502524    if ( this->remainingBytesToWriteToDict > 0 )
    503       writeToNewDict( buf, offset );
     525      writeToNewDict( buf, offset, true );
    504526   
    505527    peer->second.connectionMonitor->processUnzippedOutgoingPacket( tick, buf, offset, currentState );
     
    538560      //PRINTF(0)("GGGGGOOOOOOOOOOTTTTTTTT: %d\n", compLength);
    539561      packetLength = Zip::getInstance()->unZip( compBuf, compLength, buf, UDP_PACKET_SIZE );
    540      
     562
    541563      if ( packetLength < 4*INTSIZE )
    542564      {
     
    547569     
    548570      if ( this->remainingBytesToWriteToDict > 0 )
    549         writeToNewDict( buf, packetLength );
     571        writeToNewDict( buf, packetLength, false );
    550572   
    551573      assert( Converter::byteArrayToInt( buf, &length ) == INTSIZE );
     
    556578      offset = 4*INTSIZE;
    557579     
    558       peer->second.connectionMonitor->processUnzippedIncomingPacket( tick, buf, offset, state, ackedState );
     580      peer->second.connectionMonitor->processUnzippedIncomingPacket( tick, buf, packetLength, state, ackedState );
    559581
    560582      //NETPRINTF(n)("got packet: %d, %d\n", length, packetLength);
     
    729751 * @param length length
    730752 */
    731 void NetworkStream::writeToNewDict( byte * data, int length )
     753void NetworkStream::writeToNewDict( byte * data, int length, bool upstream )
    732754{
    733755  if ( remainingBytesToWriteToDict <= 0 )
     
    739761  std::string fileName = ResourceManager::getInstance()->getDataDir();
    740762  fileName += "/dicts/newdict";
     763 
     764  if ( upstream )
     765    fileName += "_upstream";
     766  else
     767    fileName += "_downstream";
    741768 
    742769  FILE * f = fopen( fileName.c_str(), "a" );
  • trunk/src/lib/network/network_stream.h

    r8068 r8623  
    8484    void cleanUpOldSyncList();
    8585   
    86     void writeToNewDict( byte * data, int length );
     86    void writeToNewDict( byte * data, int length, bool upstream );
    8787
    8888
     
    107107
    108108    int                        remainingBytesToWriteToDict; //!< if > 0 NetworkStream will write packets to DATA/dicts/newdict
     109
     110    int dictServer;
     111    int dictClient;
    109112};
    110113#endif /* _NETWORK_STREAM */
  • trunk/src/lib/network/player_stats.cc

    r8362 r8623  
    2424
    2525#include "debug.h"
     26#include "shell_command.h"
    2627
    2728
    2829CREATE_FACTORY(PlayerStats, CL_PLAYER_STATS);
    2930
     31
    3032/**
    3133 * constructor
     
    3436{
    3537  init();
    36 
     38 
    3739  this->userId = userId;
    3840}
     
    5658  this->playableClassId = 0;
    5759  this->modelFileName = "";
    58 
     60  this->nickName = "Player";
     61  this->oldNickName = "Player";
     62 
    5963  userId_handle = registerVarId( new SynchronizeableInt( &userId, &userId, "userId" ) );
    6064  teamId_handle = registerVarId( new SynchronizeableInt( &teamId, &teamId, "teamId" ) );
     
    6468  playableUniqueId_handle = registerVarId( new SynchronizeableInt( &playableUniqueId, &playableUniqueId, "playableUniqueId" ) );
    6569  modelFileName_handle = registerVarId( new SynchronizeableString( &modelFileName, &modelFileName, "modelFileName" ) );
    66 
     70  nickName_handler = registerVarId( new SynchronizeableString( &nickName, &nickName, "nickName" ) );
     71 
     72  MessageManager::getInstance()->registerMessageHandler( MSGID_CHANGENICKNAME, changeNickHandler, NULL );
     73 
    6774  PRINTF(0)("PlayerStats created\n");
    6875}
     
    8794  {
    8895    this->setPlayableUniqueId( this->playableUniqueId );
    89 
     96   
    9097    PRINTF(0)("uniqueID changed %d %d %d\n", userId, getHostID(), getUniqueID());
     98  }
     99 
     100  if ( std::find( id.begin(), id.end(), nickName_handler ) != id.end() )
     101  {
     102    PRINTF(0)("user %s is now known as %s\n", oldNickName.c_str(), nickName.c_str());
     103    oldNickName = nickName;
    91104  }
    92105}
     
    100113{
    101114  const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYER_STATS );
    102 
     115 
    103116  if ( !list )
    104117  {
    105118    return NULL;
    106119  }
    107 
     120 
    108121  for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ )
    109122  {
     
    113126    }
    114127  }
    115 
     128 
    116129  return NULL;
    117130}
     
    123136{
    124137  const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYABLE );
    125 
     138 
    126139  if ( !list )
    127140  {
     
    129142    return;
    130143  }
    131 
     144 
    132145  this->playable = NULL;
    133146  for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ )
     
    141154    }
    142155  }
    143 
     156 
    144157  if ( this->playable && userId == getHostID() )
    145158  {
    146159    State::getPlayer()->setPlayable( this->playable );
    147160  }
    148 
     161 
    149162  this->playableUniqueId = uniqueId;
    150163}
     
    158171  if ( playable )
    159172    return playable;
    160 
     173 
    161174  assert( playableUniqueId > 0 );
    162 
     175 
    163176  setPlayableUniqueId( playableUniqueId );
    164 
     177 
    165178  assert( playable );
    166 
     179 
    167180  return playable;
    168181}
    169182
    170 
     183/**
     184 * client sends server a message to change nick and server changes nick directly
     185 * @param nick new nickname
     186 */
     187void PlayerStats::setNickName( std::string nick )
     188{
     189  if ( isServer() )
     190  {
     191    this->nickName = nick;
     192    PRINTF(0)("user %s is now known as %s\n", oldNickName.c_str(), nickName.c_str());
     193    oldNickName = nickName;
     194    return;
     195  }
     196  else
     197  {
     198    byte * data = new byte[nick.length()+INTSIZE];
     199   
     200    assert( Converter::stringToByteArray( nick, data, nick.length()+INTSIZE) == nick.length()+INTSIZE );
     201   
     202    MessageManager::getInstance()->sendMessage( MSGID_CHANGENICKNAME, data, nick.length()+INTSIZE, RT_SERVER, 0, MP_HIGHBANDWIDTH );
     203    return;
     204  }
     205}
     206
     207bool PlayerStats::changeNickHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId )
     208{
     209  std::string newNick;
     210  int res = Converter::byteArrayToString( data, newNick, dataLength );
     211 
     212  if ( res != dataLength )
     213  {
     214    PRINTF(2)("invalid message size from user %d\n", userId);
     215    newNick = "invalid";
     216  }
     217 
     218  if ( PlayerStats::getStats( userId ) )
     219    PlayerStats::getStats( userId )->setNickName( newNick );
     220 
     221  return true;
     222}
     223
     224void PlayerStats::shellNick( const std::string& newNick )
     225{
     226  if ( getStats( SharedNetworkData::getInstance()->getHostID() ) )
     227    getStats( SharedNetworkData::getInstance()->getHostID() )->setNickName( newNick );
     228}
     229
     230
     231
     232void PlayerStats::deleteAllPlayerStats( )
     233{
     234  const std::list<BaseObject*> * list;
     235 
     236  while ( (list  = ClassList::getList( CL_PLAYER_STATS )) != NULL && list->begin() != list->end() )
     237    delete *list->begin();
     238}
     239
  • trunk/src/lib/network/player_stats.h

    r8068 r8623  
    99#include "synchronizeable.h"
    1010#include "playable.h"
     11#include "message_manager.h"
    1112
    1213#include <string>
     
    5455   
    5556    Playable * getPlayable();
     57   
     58    inline std::string getNickName(){ return this->nickName; }
     59    void setNickName( std::string nick );
     60    static bool changeNickHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId );
     61    void shellNick( const std::string&  newNick );
     62   
     63    static void deleteAllPlayerStats();
    5664
    5765  private:
     
    5967    int teamId;                //!< teamId
    6068    int preferedTeamId;        //!< preferedTeamId
     69
     70    std::string nickName;      //!< players nickname
     71    std::string oldNickName;   //!< nickname player had before
    6172
    6273    int score;                 //!< users score points
     
    7586    int playableUniqueId_handle;
    7687    int modelFileName_handle;
     88    int nickName_handler;
    7789   
    7890    void init();
  • trunk/src/lib/network/synchronizeable.cc

    r8228 r8623  
    7070    this->networkStream->disconnectSynchronizeable(*this);
    7171 
    72   if ( this->isServer() && this->beSynchronized() && this->getUniqueID() > 0 )
     72  if ( this->isServer() && this->beSynchronized() && this->getUniqueID() > 0 && !this->isA( CL_MESSAGE_MANAGER ) )
    7373    NetworkGameManager::getInstance()->removeSynchronizeable( this->getUniqueID() );
     74   
     75  for ( SyncVarList::iterator it = syncVarList.begin(); it != syncVarList.end(); it++ )
     76  {
     77    delete *it;
     78  }
     79  syncVarList.clear();
     80 
     81  for ( UserStateHistory::iterator it = recvStates.begin(); it != recvStates.end(); it++ )
     82  {
     83    for ( StateHistory::iterator it2 = it->begin(); it2 != it->end(); it2++ )
     84    {
     85      if ( (*it2)->data )
     86      {
     87        delete [] (*it2)->data;
     88        (*it2)->data = NULL;
     89      }
     90      delete *it2;
     91    }
     92
     93  }
     94 
     95  for ( UserStateHistory::iterator it = sentStates.begin(); it != sentStates.end(); it++ )
     96  {
     97    for ( StateHistory::iterator it2 = it->begin(); it2 != it->end(); it2++ )
     98    {
     99      if ( (*it2)->data )
     100      {
     101        delete [] (*it2)->data;
     102        (*it2)->data = NULL;
     103      }
     104      delete *it2;
     105    }
     106
     107  }
    74108}
    75109
     
    134168        (*it2)->data = NULL;
    135169      }
     170     
     171      delete *it2;
    136172    }
    137173    sentStates[userId].erase( sentStates[userId].begin(), it );
     
    159195
    160196    stateFrom = initialEntry;
     197   
     198    sentStates[userId].push_back( stateFrom );
    161199  }
    162200  else
    163201    stateFrom = (*it);
    164202
    165   StateHistoryEntry * stateTo = new StateHistoryEntry();
    166 
     203  StateHistoryEntry * stateTo = new StateHistoryEntry;
     204
     205  sentStates[userId].push_back( stateTo );
     206 
    167207  stateTo->stateId = stateId;
    168208  stateTo->dataLength = neededSize;
     
    175215 
    176216  bool hasPermission;
     217  bool sizeChanged = false;
    177218
    178219  // now do the actual synchronization: kick all variables to write into a common buffer
     
    186227                    );
    187228   
    188     if ( ( sizeIter != stateFrom->sizeList.end() && *sizeIter != (*it)->getSize() ) || ( hasPermission && (*it)->getPriority() >= priorityTH ) || sizeIter == stateFrom->sizeList.end() )
     229    if ( sizeIter == stateFrom->sizeList.end() || *sizeIter != (*it)->getSize() )
     230      sizeChanged = true;
     231   
     232    if ( ( hasPermission && (*it)->getPriority() >= priorityTH ) || sizeChanged )
    189233    {
    190234      n = (*it)->writeToBuf( stateTo->data+i, stateTo->dataLength - i );
     
    210254  }
    211255
    212   sentStates[userId].push_back( stateTo );
    213  
    214256  if ( i != neededSize )
    215257  {
     
    275317
    276318    stateFrom = initialEntry;
     319   
     320    recvStates[userId].push_back( stateFrom );
    277321  }
    278322  else
     
    374418    {
    375419      if ( (*it)->data )
     420      {
    376421        delete [] (*it)->data;
    377       (*it)->data = NULL;
     422        (*it)->data = NULL;
     423      }
    378424   
    379425      delete *it;
     
    388434    {
    389435      if ( (*it)->data )
     436      {
    390437        delete [] (*it)->data;
    391       (*it)->data = NULL;
     438        (*it)->data = NULL;
     439      }
    392440   
    393441      delete *it;
     
    438486     
    439487      if ( (*delIt)->data )
     488      {
    440489        delete [] (*delIt)->data;
     490        (*delIt)->data = NULL;
     491      }
     492      delete *delIt;
    441493      recvStates[userId].erase( delIt );
    442494     
     
    506558     
    507559      if ( (*delIt)->data )
     560      {
    508561        delete [] (*delIt)->data;
     562        (*delIt)->data = NULL;
     563      }
     564      delete *delIt;
    509565      sentStates[userId].erase( delIt );
    510566     
  • trunk/src/lib/network/udp_server_socket.cc

    r8362 r8623  
    220220bool UdpServerSocket::sendPacket( NetworkPacket networkPacket , int userId )
    221221{
     222  if ( !socket )
     223    return false;
     224 
    222225  assert( networkPacket.length <= UDP_PACKET_SIZE );
    223226
  • trunk/src/lib/network/zip.cc

    r8362 r8623  
    4949 * @return true on success
    5050 */
    51 bool Zip::loadDictionary( std::string name )
     51int Zip::loadDictionary( std::string name )
    5252{
    5353  std::string fileName = ResourceManager::getInstance()->getDataDir();
     
    6161  {
    6262    PRINTF(1)("Could not open %d\n", fileName.c_str());
    63     return false;
     63    return -1;
    6464  }
    6565
     
    8888  PRINTF(3)("Loaded dictionary '%s' with adler = %d\n", name.c_str(), entry.adler );
    8989
    90   return true;
     90  return dicts.size()-1;
    9191}
    9292
  • trunk/src/lib/network/zip.h

    r7954 r8623  
    2828    inline static Zip* getInstance(void) { if (!singletonRef) singletonRef = new Zip();  return singletonRef; };
    2929   
    30     bool loadDictionary( std::string name );
     30    int loadDictionary( std::string name );
    3131    int zip( byte * from, int fromLength, byte * to, int maxLength, int dict = 0 );
    3232    int unZip( byte * from, int fromLength, byte * to, int maxLength );
  • trunk/src/lib/shell/some_shell_commands.cc

    r7725 r8623  
    2828using namespace OrxShell;
    2929
     30#include "network_game_rules.h"
     31  SHELL_COMMAND(say, NetworkGameRules, shellSay)->setAlias("say");
    3032
     33#include "player_stats.h"
     34  SHELL_COMMAND(nick, PlayerStats, shellNick)->setAlias("nick");
    3135
    3236#include "class_list.h"
  • trunk/src/orxonox.cc

    r8363 r8623  
    445445  {
    446446    SignalHandler::getInstance()->doCatch( argv[0], GDB_RUN_IN_FOREGROUND );
     447    SignalHandler::getInstance()->registerCallback(EventHandler::releaseMouse, NULL);
    447448  }
    448449  else if ( Preferences::getInstance()->getString("misc", "bt-to-file", "1") == "1" )
  • trunk/src/subprojects/network/network_unit_test.cc

    r7954 r8623  
    276276  for(;;)
    277277  {
    278     MessageManager::getInstance()->sendMessage( TESTMESSAGEID, (byte*)"server to client", 18, RT_ALL, 0, MP_HIGHBANDWIDTH );
     278    MessageManager::getInstance()->sendMessage( TESTMESSAGEID, (byte*)"server to client", 18, RT_ALL_NOT_ME, 0, MP_HIGHBANDWIDTH );
    279279    netMan->synchronize( 100 );
    280280    SDL_Delay(100);
     
    323323  {
    324324    netMan->synchronize( 100 );
    325     MessageManager::getInstance()->sendMessage( TESTMESSAGEID, (byte*)"client to server", 18, RT_ALL, 0, MP_HIGHBANDWIDTH );
     325    MessageManager::getInstance()->sendMessage( TESTMESSAGEID, (byte*)"client to server", 18, RT_ALL_NOT_ME, 0, MP_HIGHBANDWIDTH );
    326326    ss = dynamic_cast<SimpleSync*>(ClassList::getObject( "Server", CL_SIMPLE_SYNC ) );
    327327    SDL_Delay(100);
  • trunk/src/util/game_rules.h

    r8362 r8623  
    2020
    2121
    22 class GameRules : public BaseObject
     22class GameRules : virtual public BaseObject
    2323{
    2424
  • trunk/src/util/multiplayer_team_deathmatch.cc

    r8147 r8623  
    6565  this->currentGameState = GAMESTATE_PRE_GAME;
    6666  this->gameStateTimer = 10.0f;
     67  this->bShowTeamChange = false;
    6768 
    6869  this->box = NULL;
     
    7778  if( root != NULL)
    7879    this->loadParams(root);
     80 
     81  subscribeEvent( ES_GAME, SDLK_o );
    7982}
    8083
     
    8689  if( this->deathScreen)
    8790    delete this->deathScreen;
     91 
     92  unsubscribeEvent( ES_GAME, SDLK_o );
    8893}
    8994
     
    150155    return;
    151156 
    152   if ( currentGameState == GAMESTATE_PRE_GAME )
     157  if ( currentGameState == GAMESTATE_PRE_GAME || currentGameState == GAMESTATE_GAME )
    153158  {
    154159    if ( PlayerStats::getStats( SharedNetworkData::getInstance()->getHostID() )
    155          && PlayerStats::getStats( SharedNetworkData::getInstance()->getHostID() )->getPreferedTeamId() == TEAM_NOTEAM
    156160         && box == NULL
     161         &&  (PlayerStats::getStats( SharedNetworkData::getInstance()->getHostID() )->getPreferedTeamId() == TEAM_NOTEAM
     162         || bShowTeamChange )
     163         
    157164       )
    158165    {
     
    180187      buttonTeam1->connect(SIGNAL(buttonTeam1, released), this, SLOT(MultiplayerTeamDeathmatch, onButtonTeam1));
    181188     
     189      if ( bShowTeamChange )
     190      {
     191        OrxGui::GLGuiPushButton * buttonCancel = new OrxGui::GLGuiPushButton("Cancel");
     192        box->pack( buttonCancel );
     193        buttonCancel->connect(SIGNAL(buttonCancel, released), this, SLOT(MultiplayerTeamDeathmatch, onButtonCancel));
     194      }
     195     
    182196      OrxGui::GLGuiPushButton * buttonExit = new OrxGui::GLGuiPushButton("Exit");
    183197      box->pack( buttonExit );
     
    191205       && PlayerStats::getStats( SharedNetworkData::getInstance()->getHostID() )
    192206       && PlayerStats::getStats( SharedNetworkData::getInstance()->getHostID() )->getPreferedTeamId() != TEAM_NOTEAM
     207       && !bShowTeamChange
    193208     )
    194209  {
     
    479494{
    480495  State::getCurrentStoryEntity()->stop();
     496  this->bShowTeamChange = false;
    481497}
    482498
     
    484500{
    485501  NetworkGameManager::getInstance()->prefereTeam( TEAM_RANDOM );
     502  this->bShowTeamChange = false;
    486503}
    487504
     
    489506{
    490507  NetworkGameManager::getInstance()->prefereTeam( 0 );
     508  this->bShowTeamChange = false;
    491509}
    492510
     
    494512{
    495513  NetworkGameManager::getInstance()->prefereTeam( 1 );
     514  this->bShowTeamChange = false;
    496515}
    497516
     
    499518{
    500519  NetworkGameManager::getInstance()->prefereTeam( TEAM_SPECTATOR );
     520  this->bShowTeamChange = false;
    501521}
    502522
     
    507527}
    508528
    509 
    510 
    511 
    512 
    513 
     529  /**
     530   * function that processes events from the handler
     531   * @param event: the event
     532   * @todo replace SDLK_o with something from KeyMapper
     533   */
     534void MultiplayerTeamDeathmatch::process( const Event & event )
     535{
     536  if ( event.type == SDLK_o )
     537  {
     538    if ( event.bPressed )
     539      this->bShowTeamChange = true;
     540  }
     541}
     542
     543void MultiplayerTeamDeathmatch::onButtonCancel( )
     544{
     545  this->bShowTeamChange = false;
     546}
     547
     548
     549
     550/**
     551 * this method is called by NetworkGameManger when he recieved a chat message
     552 * @param userId senders user id
     553 * @param message message string
     554 * @param messageType some int
     555 */
     556void MultiplayerTeamDeathmatch::handleChatMessage( int userId, const std::string & message, int messageType )
     557{
     558  std::string name = "unknown";
     559 
     560  if ( PlayerStats::getStats( userId ) )
     561  {
     562    name = PlayerStats::getStats( userId )->getNickName();
     563  }
     564 
     565  PRINTF(0)("CHATMESSAGE %s: %s\n", name.c_str(), message.c_str() );
     566}
     567
     568
     569
     570
  • trunk/src/util/multiplayer_team_deathmatch.h

    r8147 r8623  
    1212#include "network_game_rules.h"
    1313
    14 #include "glgui_box.h"
     14#include "glgui.h"
    1515
    1616class TiXmlElement;
     
    2727
    2828
    29 class MultiplayerTeamDeathmatch : public NetworkGameRules
     29class MultiplayerTeamDeathmatch : public NetworkGameRules, public EventListener
    3030{
    3131
     
    5555   
    5656    int getRandomTeam();
     57   
     58    virtual void process(const Event &event);
     59   
     60    virtual void handleChatMessage( int userId, const std::string & message, int messageType );
    5761
    5862  protected:
     
    7478    float              gameStateTimer;             //!< if less than 0 -> change game state
    7579
     80    bool               bShowTeamChange;            //!< if true -> show team change dialog
     81
    7682    OrxGui::GLGuiBox* box;
    77 
    78 
     83   
    7984    void calculateTeamScore();
    8085    void nextGameState();
     
    8792    void onButtonTeam0();
    8893    void onButtonTeam1();
     94    void onButtonCancel();
    8995    void onButtonExit();
    9096};
  • trunk/src/util/network_game_rules.cc

    r8147 r8623  
    1717
    1818#include "network_game_rules.h"
     19
     20#include "network_game_manager.h"
    1921
    2022using namespace std;
     
    5355}
    5456
     57
     58void NetworkGameRules::shellSay( const std::string & message )
     59{
     60  NetworkGameManager::getInstance()->sendChatMessage( message, 0 );
     61}
     62
     63
  • trunk/src/util/network_game_rules.h

    r8147 r8623  
    2525   
    2626    virtual PlayerStats * getNewPlayerStats( int userId ){ return new PlayerStats( userId ); }
     27   
     28    virtual void handleChatMessage( int userId, const std::string & message, int messageType ) = 0;
     29   
     30    void shellSay( const std::string & message );
    2731
    2832
  • trunk/src/util/signal_handler.h

    r8523 r8623  
    1717};
    1818
    19 typedef bool (*SignalCallback)( void * someData );
     19typedef int (*SignalCallback)( void * someData );
    2020
    2121#ifndef __WIN32__
     
    4444  public:
    4545    inline static SignalHandler* getInstance() { if (!SignalHandler::singletonRef) SignalHandler::singletonRef = new SignalHandler(); return SignalHandler::singletonRef; }
    46      
     46
    4747    void registerCallback( SignalCallback cb, void * someData );
    4848
     
    5555    void catchSignal( int sig );
    5656    SignalRecList sigRecList;
    57    
     57
    5858    SignalCallbackList callbackList;
    5959
  • trunk/src/world_entities/space_ships/turbine_hover.cc

    r8362 r8623  
    211211  this->getWeaponManager().getFixedTarget()->setParent(&this->cameraNode);
    212212  this->getWeaponManager().getFixedTarget()->setRelCoor(1000,0,0);
     213 
     214  registerVar( new SynchronizeableBool( &bForward, &bForward, "bForward", PERMISSION_OWNER ) );
     215  registerVar( new SynchronizeableBool( &bBackward, &bBackward, "bBackward", PERMISSION_OWNER ) );
     216  registerVar( new SynchronizeableBool( &bLeft, &bLeft, "bLeft", PERMISSION_OWNER ) );
     217  registerVar( new SynchronizeableBool( &bRight, &bRight, "bRight", PERMISSION_OWNER ) );
     218  registerVar( new SynchronizeableBool( &bAscend, &bAscend, "bAscend", PERMISSION_OWNER ) );
     219  registerVar( new SynchronizeableBool( &bDescend, &bDescend, "bDescend", PERMISSION_OWNER ) );
     220  //registerVar( new SynchronizeableQuaternion( &direction, &direction, "direction", PERMISSION_OWNER ) );
     221  registerVar( new SynchronizeableFloat( &cameraLook, &cameraLook, "cameraLook", PERMISSION_OWNER ) );
     222  registerVar( new SynchronizeableFloat( &rotation, &rotation, "rotation", PERMISSION_OWNER ) );
    213223}
    214224
Note: See TracChangeset for help on using the changeset viewer.