Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9253 in orxonox.OLD


Ignore:
Timestamp:
Jul 12, 2006, 11:28:38 AM (18 years ago)
Author:
patrick
Message:

cleanup minor

Location:
branches/proxy/src/lib/network
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/proxy/src/lib/network/netdefs.h

    r9248 r9253  
     1/*
     2   orxonox - the future of 3D-vertical-scrollers
    13
     4   Copyright (C) 2004 orx
     5
     6   This program is free software; you can redistribute it and/or modify
     7   it under the terms of the GNU General Public License as published by
     8   the Free Software Foundation; either version 2, or (at your option)
     9   any later version.
     10
     11### File Specific:
     12   main-programmer: Christoph Renner rennerc@ee.ethz.ch
     13   co-programmer:   Patrick Boenzli  boenzlip@orxonox.ethz.ch
     14
     15     June 2006: finishing work on the network stream for pps presentation (rennerc@ee.ethz.ch)
     16     July 2006: some code rearangement and integration of the proxy server mechanism (boenzlip@ee.ethz.ch)
     17*/
    218
    319/*!
  • branches/proxy/src/lib/network/network_game_manager.cc

    r9235 r9253  
    1010
    1111### File Specific:
    12    main-programmer: Benjamin Wuest
    13    co-programmer: ...
     12   main-programmer: Christoph Renner rennerc@ee.ethz.ch
     13   co-programmer:   Patrick Boenzli  boenzlip@orxonox.ethz.ch
     14
     15     June 2006: finishing work on the network stream for pps presentation (rennerc@ee.ethz.ch)
     16     July 2006: some code rearangement and integration of the proxy server mechanism (boenzlip@ee.ethz.ch)
    1417*/
    1518
    1619
    17 /* this is for debug output. It just says, that all calls to PRINT() belong to the DEBUG_MODULE_NETWORK module
    18    For more information refere to https://www.orxonox.net/cgi-bin/trac.cgi/wiki/DebugOutput
    19 */
     20
    2021#define DEBUG_MODULE_NETWORK
    2122
     
    4546
    4647
    47 /* using namespace std is default, this needs to be here */
    4848using namespace std;
    4949
     
    6262
    6363  this->setSynchronized(true);
    64  
     64
    6565  MessageManager::getInstance()->registerMessageHandler( MSGID_DELETESYNCHRONIZEABLE, delSynchronizeableHandler, NULL );
    6666  MessageManager::getInstance()->registerMessageHandler( MSGID_PREFEREDTEAM, preferedTeamHandler, NULL );
    6767  MessageManager::getInstance()->registerMessageHandler( MSGID_CHATMESSAGE, chatMessageHandler, NULL );
    68  
     68
    6969  this->gameState = 0;
    7070  registerVar( new SynchronizeableInt( &gameState, &gameState, "gameState" ) );
     
    7777{
    7878  delete MessageManager::getInstance();
    79  
     79
    8080  PlayerStats::deleteAllPlayerStats();
    81  
     81
    8282  NetworkGameManager::singletonRef = NULL;
    8383}
     
    8686/**
    8787 * insert new player into game
    88  * @param userId 
    89  * @return 
     88 * @param userId
     89 * @return
    9090 */
    9191bool NetworkGameManager::signalNewPlayer( int userId )
     
    9494  assert( State::getGameRules() );
    9595  assert( State::getGameRules()->isA( CL_NETWORK_GAME_RULES ) );
    96  
     96
    9797  NetworkGameRules & rules = *(dynamic_cast<NetworkGameRules*>(State::getGameRules()));
    98  
     98
    9999  int team = rules.getTeamForNewUser();
    100100  ClassID playableClassId = rules.getPlayableClassId( userId, team );
     
    102102  std::string playableTexture = rules.getPlayableModelFileName( userId, team, playableClassId );
    103103  float       playableScale = rules.getPlayableScale( userId, team, playableClassId );
    104  
     104
    105105  BaseObject * bo = Factory::fabricate( playableClassId );
    106  
     106
    107107  assert( bo != NULL );
    108108  assert( bo->isA( CL_PLAYABLE ) );
    109  
     109
    110110  Playable & playable = *(dynamic_cast<Playable*>(bo));
    111  
     111
    112112  playable.loadMD2Texture( playableTexture );
    113  
     113
    114114  playable.loadModel( playableModel, 100.0f );
    115115  playable.setOwner( userId );
    116116  playable.setUniqueID( SharedNetworkData::getInstance()->getNewUniqueID() );
    117117  playable.setSynchronized( true );
    118  
     118
    119119  PlayerStats * stats = rules.getNewPlayerStats( userId );
    120  
     120
    121121  stats->setUniqueID( SharedNetworkData::getInstance()->getNewUniqueID() );
    122122  stats->setSynchronized( true );
    123123  stats->setOwner( SharedNetworkData::getInstance()->getHostID() );
    124  
     124
    125125  stats->setTeamId( team );
    126126  stats->setPlayableClassId( playableClassId );
    127127  stats->setPlayableUniqueId( playable.getUniqueID() );
    128128  stats->setModelFileName( playableModel );
    129  
     129
    130130  if ( userId == 0 )
    131131    stats->setNickName( Preferences::getInstance()->getString( "multiplayer", "nickname", "Server" ) );
    132  
     132
    133133  if ( rules.isA( CL_MULTIPLAYER_TEAM_DEATHMATCH ) )
    134134    dynamic_cast<MultiplayerTeamDeathmatch*>(&rules)->respawnPlayable( &playable, team, 0.0f );
    135  
     135
    136136  return true;
    137137}
     
    140140/**
    141141 * remove player from game
    142  * @param userID 
    143  * @return 
     142 * @param userID
     143 * @return
    144144 */
    145145bool NetworkGameManager::signalLeftPlayer(int userID)
     
    151151    delete PlayerStats::getStats( userID );
    152152  }
    153  
     153
    154154  return true;
    155155}
     
    159159/**
    160160 * handler for remove synchronizeable messages
    161  * @param messageId 
    162  * @param data 
    163  * @param dataLength 
    164  * @param someData 
    165  * @param userId 
     161 * @param messageId
     162 * @param data
     163 * @param dataLength
     164 * @param someData
     165 * @param userId
    166166 * @return true on successfull handling else handler will be called again
    167167 */
     
    173173    return true;
    174174  }
    175  
     175
    176176  int uniqueId = 0;
    177177  int len = Converter::byteArrayToInt( data, &uniqueId );
    178  
     178
    179179  if ( len != dataLength )
    180180  {
     
    182182    return true;
    183183  }
    184  
     184
    185185  const std::list<BaseObject*> * list = ClassList::getList( CL_SYNCHRONIZEABLE );
    186  
     186
    187187  for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ )
    188188  {
     
    194194        return true;
    195195      }
    196      
     196
    197197      delete dynamic_cast<Synchronizeable*>(*it);
    198198      return true;
    199199    }
    200200  }
    201  
     201
    202202  return true;
    203203}
     
    210210{
    211211  byte buf[INTSIZE];
    212  
     212
    213213  assert( Converter::intToByteArray( uniqueId, buf, INTSIZE ) == INTSIZE );
    214214
     
    220220/**
    221221 * handler for MSGID_PREFEREDTEAM message
    222  * @param messageId 
    223  * @param data 
    224  * @param dataLength 
    225  * @param someData 
    226  * @param userId 
    227  * @return 
     222 * @param messageId
     223 * @param data
     224 * @param dataLength
     225 * @param someData
     226 * @param userId
     227 * @return
    228228 */
    229229bool NetworkGameManager::preferedTeamHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId )
    230230{
    231231  assert( NetworkGameManager::getInstance()->isServer() );
    232  
     232
    233233  int teamId = 0;
    234234  int len = Converter::byteArrayToInt( data, &teamId );
    235  
     235
    236236  if ( len != dataLength )
    237237  {
     
    239239    return true;
    240240  }
    241  
     241
    242242  NetworkGameManager::getInstance()->setPreferedTeam( userId, teamId );
    243  
     243
    244244  return true;
    245245}
     
    249249  if ( !PlayerStats::getStats( userId ) )
    250250    return;
    251  
     251
    252252  PlayerStats & stats = *(PlayerStats::getStats( userId ));
    253  
     253
    254254  stats.setPreferedTeamId( teamId );
    255255}
     
    257257/**
    258258 * set prefered team for this host
    259  * @param teamId 
     259 * @param teamId
    260260 */
    261261void NetworkGameManager::prefereTeam( int teamId )
     
    266266  {
    267267    byte buf[INTSIZE];
    268    
     268
    269269    assert( Converter::intToByteArray( teamId, buf, INTSIZE) == INTSIZE );
    270    
     270
    271271    MessageManager::getInstance()->sendMessage( MSGID_PREFEREDTEAM, buf, INTSIZE, RT_USER, 0, MP_HIGHBANDWIDTH );
    272272  }
     
    285285    {
    286286      const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYABLE );
    287        
     287
    288288      if ( list && std::find( list->begin(), list->end(), *it ) != list->end() )
    289       {     
     289      {
    290290        PRINTF(0)("Delete unused playable: %s owner: %d\n", (*it)->getClassName(), (*it)->getOwner() );
    291291        std::list<Playable*>::iterator delit = it;
     
    309309    MessageManager::getInstance()->sendMessage( messageId, data, dataLength, RT_ALL_NOT_ME, 0, MP_HIGHBANDWIDTH );
    310310  }
    311  
     311
    312312  assert( State::getGameRules() );
    313313  assert( State::getGameRules()->isA( CL_NETWORK_GAME_RULES ) );
    314  
     314
    315315  NetworkGameRules & rules = *(dynamic_cast<NetworkGameRules*>(State::getGameRules()));
    316  
     316
    317317  if ( dataLength < 3*INTSIZE )
    318318  {
    319319    PRINTF(2)("got too small chatmessage from client %d\n", userId);
    320    
     320
    321321    return true;
    322322  }
    323  
     323
    324324  int messageType = 0;
    325325  Converter::byteArrayToInt( data, &messageType );
     
    328328  std::string message;
    329329  Converter::byteArrayToString( data+2*INTSIZE, message, dataLength-2*INTSIZE );
    330  
     330
    331331  rules.handleChatMessage( senderUserId, message, messageType );
    332332
     
    346346  assert( Converter::intToByteArray( SharedNetworkData::getInstance()->getHostID(), buf+INTSIZE, INTSIZE ) == INTSIZE );
    347347  assert( Converter::stringToByteArray(message, buf+2*INTSIZE, message.length()+INTSIZE) == message.length()+INTSIZE );
    348  
     348
    349349  if ( this->isServer() )
    350350    MessageManager::getInstance()->sendMessage( MSGID_CHATMESSAGE, buf, message.length()+3*INTSIZE, RT_ALL_ME, 0, MP_HIGHBANDWIDTH );
     
    352352    MessageManager::getInstance()->sendMessage( MSGID_CHATMESSAGE, buf, message.length()+3*INTSIZE, RT_ALL_NOT_ME, 0, MP_HIGHBANDWIDTH );
    353353
    354  
     354
    355355  delete [] buf;
    356356}
  • branches/proxy/src/lib/network/network_game_manager.h

    r9248 r9253  
    2828  NET_YOU_ARE_ENTITY,
    2929  NET_REQUEST_ENTITY_LIST,
    30   NET_REQUEST_PNODE_PATH,
    31   NET_SEND_PNODE_PATH,
    3230
    3331  NET_NUMBER
Note: See TracChangeset for help on using the changeset viewer.