Changeset 8187 in orxonox.OLD
- Timestamp:
- Jun 7, 2006, 2:44:34 PM (18 years ago)
- Location:
- branches/network/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/network/src/lib/network/network_stream.cc
r8174 r8187 105 105 serverSocket->close(); 106 106 delete serverSocket; 107 serverSocket = NULL; 107 108 } 108 109 … … 123 124 } 124 125 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 ); 131 128 } 132 129 -
branches/network/src/lib/network/player_stats.cc
r8184 r8187 62 62 playableUniqueId_handle = registerVarId( new SynchronizeableInt( &playableUniqueId, &playableUniqueId, "playableUniqueId" ) ); 63 63 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 );67 64 68 65 PRINTF(0)("PlayerStats created\n"); … … 167 164 } 168 165 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 name178 getStats( userId )->playerName = "invalid name";179 }180 181 return true;182 }183 166 184 std::string PlayerStats::setPlayerName( std::string name )185 {186 if ( isServer() )187 {188 this->playerName = name;189 }190 else191 {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 else201 {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 26 CREATE_FACTORY(PlayerStats, CL_PLAYER_STATS); 27 28 /** 29 * constructor 4 30 */ 31 PlayerStats::PlayerStats( int userId ) 32 { 33 init(); 34 35 this->userId = userId; 36 } 5 37 6 #ifndef _PLAYER_STATS_H 7 #define _PLAYER_STATS_H 38 /** 39 * constructor 40 */ 41 PlayerStats::PlayerStats( const TiXmlElement* root ) 42 { 43 init(); 44 } 8 45 9 #include "synchronizeable.h" 10 #include "playable.h" 11 #include "message_manager.h" 46 void PlayerStats::init( ) 47 { 48 this->setClassID( CL_PLAYER_STATS, "PlayerStats" ); 12 49 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 } 15 67 16 enum 68 69 /** 70 * standard deconstructor 71 */ 72 PlayerStats::~PlayerStats() 17 73 { 18 TEAM_NOTEAM = -3, 19 TEAM_RANDOM = -2, 20 TEAM_SPECTATOR = -1 21 }; 74 } 22 75 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 */ 82 void PlayerStats::varChangeHandler( std::list< int > & id ) 25 83 { 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 } 26 91 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 */ 97 PlayerStats * 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 } 62 116 63 private: 64 int userId; //!< userId 117 /** 118 * set playable class id and set playable 119 */ 120 void 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 } 65 147 66 std::string playerName; //!< playername 148 /** 149 * get playable associated to player 150 * @return playable associated to player 151 */ 152 Playable * 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 } 67 165 68 int teamId; //!< teamId69 int preferedTeamId; //!< preferedTeamId70 166 71 int score; //!< users score points72 int playableClassId; //!< players playable class id73 int playableUniqueId; //!< playable's uniqueId74 std::string modelFileName; //!< model filename75 76 Playable * playable; //!< pointer to players playable77 78 // handles for SynchronizeableVars79 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 135 135 void UdpSocket::disconnectServer( ) 136 136 { 137 PRINTF(0)("disconnect from server\n");137 PRINTF(0)("disconnect\n"); 138 138 writePacket( NULL, 0 ); 139 139 SDLNet_UDP_Unbind( socket, -1 ); … … 171 171 packet->len = length; 172 172 173 if ( SDLNet_UDP_Send( socket, 1, packet) == 0 )173 if ( socket && SDLNet_UDP_Send( socket, 1, packet) == 0 ) 174 174 { 175 175 PRINTF(1)("SDLNet_UDP_Send: %s\n", SDLNet_GetError()); -
branches/network/src/story_entities/multi_player_world.cc
r8184 r8187 127 127 ErrorMessage MultiPlayerWorld::unloadData( ) 128 128 { 129 129 130 GameWorld::unloadData(); 130 131 131 132 delete NetworkManager::getInstance(); 132 133 delete NetworkGameManager::getInstance(); 134 133 135 }
Note: See TracChangeset
for help on using the changeset viewer.