Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8588 in orxonox.OLD for branches/network/src


Ignore:
Timestamp:
Jun 19, 2006, 6:46:49 PM (18 years ago)
Author:
rennerc
Message:

implemented chat functionality

Location:
branches/network/src
Files:
6 edited

Legend:

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

    r8236 r8588  
    3131  MSGID_DELETESYNCHRONIZEABLE,
    3232  MSGID_PREFEREDTEAM,
    33   MSGID_CHANGENICKNAME
     33  MSGID_CHANGENICKNAME,
     34  MSGID_CHATMESSAGE
    3435};
    3536
  • branches/network/src/lib/network/network_game_manager.cc

    r8459 r8588  
    280280
    281281
    282 
     282bool NetworkGameManager::chatMessageHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId )
     283{
     284  assert( State::getGameRules() );
     285  assert( State::getGameRules()->isA( CL_NETWORK_GAME_RULES ) );
     286 
     287  NetworkGameRules & rules = *(dynamic_cast<NetworkGameRules*>(State::getGameRules()));
     288 
     289  if ( dataLength < 2*INTSIZE )
     290  {
     291    PRINTF(2)("got too small chatmessage from client %d\n", userId);
     292   
     293    return true;
     294  }
     295 
     296  int messageType = 0;
     297  Converter::byteArrayToInt( data, &messageType );
     298  std::string message;
     299  Converter::byteArrayToString( data+INTSIZE, message, dataLength-INTSIZE );
     300 
     301  rules.handleChatMessage( userId, message, messageType );
     302 
     303  return true;
     304}
     305
     306/**
     307 * send chat message
     308 * @param message message text
     309 * @param messageType some int
     310 * @param userId user to send message to -1 = ALL
     311 */
     312void NetworkGameManager::sendChatMessage( const std::string & message, int messageType, int userId )
     313{
     314  byte * buf = new byte[message.length()]+2*INTSIZE;
     315 
     316  assert( Converter::intToByteArray( messageType, buf, INTSIZE ) == INTSIZE );
     317  assert( Converter::stringToByteArray(message, buf+INTSIZE, message.length()+INTSIZE) == message.length()+INTSIZE );
     318 
     319  if ( userId == -1 )
     320    MessageManager::getInstance()->sendMessage( MSGID_CHATMESSAGE, buf, sizeof(buf), RT_ALL_ME, 0, MP_HIGHBANDWIDTH );
     321  else
     322    MessageManager::getInstance()->sendMessage( MSGID_CHATMESSAGE, buf, sizeof(buf), RT_USER, userId, MP_HIGHBANDWIDTH );
     323 
     324  delete [] buf;
     325}
     326
     327
     328
  • branches/network/src/lib/network/network_game_manager.h

    r8147 r8588  
    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 );
  • branches/network/src/util/multiplayer_team_deathmatch.cc

    r8466 r8588  
    548548
    549549
    550 
    551 
    552 
     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
  • branches/network/src/util/multiplayer_team_deathmatch.h

    r8331 r8588  
    5757   
    5858    virtual void process(const Event &event);
     59   
     60    virtual void handleChatMessage( int userId, const std::string & message, int messageType );
    5961
    6062  protected:
  • branches/network/src/util/network_game_rules.h

    r8147 r8588  
    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;
    2729
    2830
Note: See TracChangeset for help on using the changeset viewer.