Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8187 in orxonox.OLD


Ignore:
Timestamp:
Jun 7, 2006, 2:44:34 PM (18 years ago)
Author:
rennerc
Message:

reverted playerstats. disconnect works now

Location:
branches/network/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/network/src/lib/network/network_stream.cc

    r8174 r8187  
    105105    serverSocket->close();
    106106    delete serverSocket;
     107    serverSocket = NULL;
    107108  }
    108109
     
    123124  }
    124125 
    125   if ( serverSocket )
    126   {
    127     delete serverSocket;
    128     serverSocket = NULL;
    129   }
    130 
     126  for ( SynchronizeableList::const_iterator it = getSyncBegin(); it != getSyncEnd(); it ++ )
     127    (*it)->setNetworkStream( NULL );
    131128}
    132129
  • branches/network/src/lib/network/player_stats.cc

    r8184 r8187  
    6262  playableUniqueId_handle = registerVarId( new SynchronizeableInt( &playableUniqueId, &playableUniqueId, "playableUniqueId" ) );
    6363  modelFileName_handle = registerVarId( new SynchronizeableString( &modelFileName, &modelFileName, "modelFileName" ) );
    64   playerName_handle = registerVarId( new SynchronizeableString( &playerName, &playerName, "playerName" ) );
    65  
    66   MessageManager::getInstance()->registerMessageHandler( MSGID_CHANGEPLAYERNAME, changePlayernameHandler, NULL );
    6764 
    6865  PRINTF(0)("PlayerStats created\n");
     
    167164}
    168165
    169 bool PlayerStats::changePlayernameHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId )
    170 {
    171   if ( !SharedNetworkData::getInstance()->isGameServer() )
    172     return true;
    173  
    174   if ( Converter::byteArrayToString( data, getStats(userId)->playerName, dataLength ) != dataLength );
    175   {
    176     PRINTF(1)("recieved invalid message from user %d\n", userId);
    177     // TODO give user a name
    178     getStats( userId )->playerName = "invalid name";
    179   }
    180  
    181   return true;
    182 }
    183166
    184 std::string PlayerStats::setPlayerName( std::string name )
    185 {
    186   if ( isServer() )
    187   {
    188     this->playerName = name;
    189   }
    190   else
    191   {
    192     if ( userId == getHostID() )
    193     {
    194       byte * data = new byte[INTSIZE+playerName.length()];
    195      
    196       assert( Converter::stringToByteArray( playerName, data, INTSIZE+playerName.length() ) == INTSIZE+playerName.length() );
    197      
    198       MessageManager::getInstance()->sendMessage( MSGID_CHANGEPLAYERNAME, data, INTSIZE+playerName.length(), RT_SERVER, 0, MP_HIGHBANDWIDTH );
    199     }
    200     else
    201     {
    202       PRINTF(1)("Clients cannot set PlayerNames of other hosts!\n");
    203     }
    204   }
    205 }
    206 
    207 
  • branches/network/src/lib/network/player_stats.h

    r8184 r8187  
    1 /*!
    2  * @file player_stats.h
    3  * @brief Definition of PlayerStats
     1/*
     2   orxonox - the future of 3D-vertical-scrollers
     3
     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
     13   co-programmer: ...
     14*/
     15
     16#include "player_stats.h"
     17
     18#include "class_list.h"
     19#include "src/lib/util/loading/factory.h"
     20
     21#include "player.h"
     22#include "state.h"
     23#include "shared_network_data.h"
     24
     25
     26CREATE_FACTORY(PlayerStats, CL_PLAYER_STATS);
     27
     28/**
     29 * constructor
    430 */
     31PlayerStats::PlayerStats( int userId )
     32{
     33  init();
     34 
     35  this->userId = userId;
     36}
    537
    6 #ifndef _PLAYER_STATS_H
    7 #define _PLAYER_STATS_H
     38/**
     39 * constructor
     40 */
     41PlayerStats::PlayerStats( const TiXmlElement* root )
     42{
     43  init();
     44}
    845
    9 #include "synchronizeable.h"
    10 #include "playable.h"
    11 #include "message_manager.h"
     46void PlayerStats::init( )
     47{
     48  this->setClassID( CL_PLAYER_STATS, "PlayerStats" );
    1249
    13 #include <string>
    14 #include <list>
     50  this->userId = 0;
     51  this->teamId = TEAM_NOTEAM;
     52  this->preferedTeamId = TEAM_NOTEAM;
     53  this->score = 0;
     54  this->playableClassId = 0;
     55  this->modelFileName = "";
     56 
     57  userId_handle = registerVarId( new SynchronizeableInt( &userId, &userId, "userId" ) );
     58  teamId_handle = registerVarId( new SynchronizeableInt( &teamId, &teamId, "teamId" ) );
     59  preferedTeamId_handle = registerVarId( new SynchronizeableInt( &preferedTeamId, &preferedTeamId, "preferedUserId" ) );
     60  score_handle = registerVarId( new SynchronizeableInt( &score, &score, "score" ) );
     61  playableClassId_handle = registerVarId( new SynchronizeableInt( &playableClassId, &playableClassId, "playableClassId") );
     62  playableUniqueId_handle = registerVarId( new SynchronizeableInt( &playableUniqueId, &playableUniqueId, "playableUniqueId" ) );
     63  modelFileName_handle = registerVarId( new SynchronizeableString( &modelFileName, &modelFileName, "modelFileName" ) );
     64 
     65  PRINTF(0)("PlayerStats created\n");
     66}
    1567
    16 enum
     68
     69/**
     70 * standard deconstructor
     71 */
     72PlayerStats::~PlayerStats()
    1773{
    18   TEAM_NOTEAM = -3,
    19   TEAM_RANDOM = -2,
    20   TEAM_SPECTATOR = -1
    21 };
     74}
    2275
    23 //! A class for storing player information
    24 class PlayerStats : public Synchronizeable
     76
     77 /**
     78 * override this function to be notified on change
     79 * of your registred variables.
     80 * @param id id's which have changed
     81  */
     82void PlayerStats::varChangeHandler( std::list< int > & id )
    2583{
     84  if ( std::find( id.begin(), id.end(), playableUniqueId_handle ) != id.end() )
     85  {
     86    this->setPlayableUniqueId( this->playableUniqueId );
     87   
     88    PRINTF(0)("uniqueID changed %d %d %d\n", userId, getHostID(), getUniqueID());
     89  }
     90}
    2691
    27   public:
    28     PlayerStats( const TiXmlElement* root = NULL );
    29     PlayerStats( int userId );
    30     virtual ~PlayerStats();
    31    
    32     virtual void varChangeHandler( std::list<int> & id );
    33    
    34     static PlayerStats * getStats( int userId );
    35    
    36     inline int getUserId(){ return userId; }
    37    
    38     inline std::string getPlayerName(){ return playerName; }
    39     inline std::string setPlayerName( std::string name );
    40    
    41     inline int getTeamId(){ return teamId; }
    42     inline void setTeamId( int teamId ){ this->teamId = teamId; }
    43    
    44     inline int getPreferedTeamId(){ return preferedTeamId; }
    45     inline void setPreferedTeamId( int preferedTeamId ){ this->preferedTeamId = preferedTeamId; }
    46    
    47     inline int getScore(){ return score; }
    48     inline void setScore( int score ){ this->score = score; }
    49    
    50     inline int getPlayableClassId(){ return playableClassId; }
    51     void setPlayableClassId( int classId ){ this->playableClassId = classId; };
    52    
    53     inline int getPlayableUniqueId(){ return playableUniqueId; }
    54     void setPlayableUniqueId( int uniqueId );
    55    
    56     inline std::string getModelFileName(){ return modelFileName; }
    57     inline void setModelFileName( std::string filename ){ modelFileName = filename; }
    58    
    59     Playable * getPlayable();
    60    
    61     static bool changePlayernameHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId );
     92/**
     93 * get stats for user userId
     94 * @param userId user's id
     95 * @return stats assigned to user
     96 */
     97PlayerStats * PlayerStats::getStats( int userId )
     98{
     99  const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYER_STATS );
     100 
     101  if ( !list )
     102  {
     103    return NULL;
     104  }
     105 
     106  for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ )
     107  {
     108    if ( dynamic_cast<PlayerStats*>(*it)->getUserId() == userId )
     109    {
     110      return dynamic_cast<PlayerStats*>(*it);
     111    }
     112  }
     113 
     114  return NULL;
     115}
    62116
    63   private:
    64     int userId;                //!< userId
     117/**
     118 * set playable class id and set playable
     119 */
     120void PlayerStats::setPlayableUniqueId( int uniqueId )
     121{
     122  const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYABLE );
     123 
     124  if ( !list )
     125  {
     126    this->playableUniqueId = uniqueId;
     127    return;
     128  }
     129 
     130  this->playable = NULL;
     131  for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ )
     132  {
     133    if ( dynamic_cast<Playable*>(*it)->getUniqueID() == uniqueId )
     134    {
     135      this->playable = dynamic_cast<Playable*>(*it);
     136      break;
     137    }
     138  }
     139 
     140  if ( this->playable && userId == getHostID() )
     141  {
     142    State::getPlayer()->setPlayable( this->playable );
     143  }
     144 
     145  this->playableUniqueId = uniqueId;
     146}
    65147
    66     std::string playerName;    //!< playername
     148/**
     149 * get playable associated to player
     150 * @return playable associated to player
     151 */
     152Playable * PlayerStats::getPlayable()
     153{
     154  if ( playable )
     155    return playable;
     156 
     157  assert( playableUniqueId > 0 );
     158 
     159  setPlayableUniqueId( playableUniqueId );
     160 
     161  assert( playable );
     162 
     163  return playable;
     164}
    67165
    68     int teamId;                //!< teamId
    69     int preferedTeamId;        //!< preferedTeamId
    70166
    71     int score;                 //!< users score points
    72     int playableClassId;       //!< players playable class id
    73     int playableUniqueId;      //!< playable's uniqueId
    74     std::string modelFileName; //!< model filename
    75 
    76     Playable * playable;       //!< pointer to players playable
    77 
    78     // handles for SynchronizeableVars
    79     int userId_handle;
    80     int playerName_handle;
    81     int teamId_handle;
    82     int preferedTeamId_handle;
    83     int score_handle;
    84     int playableClassId_handle;
    85     int playableUniqueId_handle;
    86     int modelFileName_handle;
    87    
    88     void init();
    89 };
    90 
    91 #endif /* _PLAYER_STATS_H */
  • branches/network/src/lib/network/udp_socket.cc

    r8184 r8187  
    135135void UdpSocket::disconnectServer( )
    136136{
    137   PRINTF(0)("disconnect from server\n");
     137  PRINTF(0)("disconnect\n");
    138138  writePacket( NULL, 0 );
    139139  SDLNet_UDP_Unbind( socket, -1 );
     
    171171    packet->len = length;
    172172   
    173     if ( SDLNet_UDP_Send( socket, 1, packet) == 0 )
     173    if ( socket && SDLNet_UDP_Send( socket, 1, packet) == 0 )
    174174    {
    175175      PRINTF(1)("SDLNet_UDP_Send: %s\n", SDLNet_GetError());
  • branches/network/src/story_entities/multi_player_world.cc

    r8184 r8187  
    127127ErrorMessage MultiPlayerWorld::unloadData( )
    128128{
     129   
    129130  GameWorld::unloadData();
    130131 
    131132  delete NetworkManager::getInstance();
    132133  delete NetworkGameManager::getInstance();
     134
    133135}
Note: See TracChangeset for help on using the changeset viewer.