Changeset 9257 in orxonox.OLD for branches/proxy/src/lib
- Timestamp:
- Jul 12, 2006, 5:10:09 PM (18 years ago)
- Location:
- branches/proxy/src/lib/network
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/proxy/src/lib/network/network_game_manager.cc
r9253 r9257 91 91 bool NetworkGameManager::signalNewPlayer( int userId ) 92 92 { 93 assert( SharedNetworkData::getInstance()->is GameServer() );93 assert( SharedNetworkData::getInstance()->isMasterServer() ); 94 94 assert( State::getGameRules() ); 95 95 assert( State::getGameRules()->isA( CL_NETWORK_GAME_RULES ) ); -
branches/proxy/src/lib/network/network_manager.cc
r9059 r9257 53 53 this->networkStream = NULL; 54 54 this->elapsedTime = 0.0f; 55 56 55 56 57 57 int port = Preferences::getInstance()->getInt( "network", "telnetport", 0 ); 58 58 59 59 if ( port > 0 ) 60 60 NetworkLog::getInstance()->listen( port ); … … 75 75 this->networkStream = NULL; 76 76 } 77 77 78 78 NetworkManager::singletonRef = NULL; 79 79 } … … 118 118 { 119 119 SharedNetworkData::getInstance()->setHostID(0); 120 SharedNetworkData::getInstance()->set GameServer(true);120 SharedNetworkData::getInstance()->setNodeType(NET_MASTER_SERVER); 121 121 this->networkStream = new NetworkStream(port); 122 122 SharedNetworkData::getInstance()->setDefaultSyncStream(this->networkStream); … … 148 148 if ( networkStream ) 149 149 networkStream->processData(); 150 150 151 151 NetworkGameManager::getInstance()->tick( this->elapsedTime ); 152 152 } -
branches/proxy/src/lib/network/network_manager.h
r9059 r9257 41 41 /** Returns the hostID @return The hostID of the object */ 42 42 inline int getHostID() { return SharedNetworkData::getInstance()->getHostID(); } 43 inline bool isGameServer() { return SharedNetworkData::getInstance()->isGameServer(); } 43 inline bool isMasterServer() { return SharedNetworkData::getInstance()->isMasterServer(); } 44 inline bool isProxyServer() { return SharedNetworkData::getInstance()->isProxyServer(); } 45 inline bool isClient() { return SharedNetworkData::getInstance()->isClient(); } 44 46 45 47 -
branches/proxy/src/lib/network/player_stats.cc
r9235 r9257 38 38 { 39 39 init(); 40 40 41 41 this->userId = userId; 42 42 } … … 62 62 this->nickName = "Player"; 63 63 this->oldNickName = "Player"; 64 64 65 65 userId_handle = registerVarId( new SynchronizeableInt( &userId, &userId, "userId" ) ); 66 66 teamId_handle = registerVarId( new SynchronizeableInt( &teamId, &teamId, "teamId" ) ); … … 71 71 modelFileName_handle = registerVarId( new SynchronizeableString( &modelFileName, &modelFileName, "modelFileName" ) ); 72 72 nickName_handler = registerVarId( new SynchronizeableString( &nickName, &nickName, "nickName" ) ); 73 73 74 74 MessageManager::getInstance()->registerMessageHandler( MSGID_CHANGENICKNAME, changeNickHandler, NULL ); 75 75 76 76 PRINTF(0)("PlayerStats created\n"); 77 77 } … … 96 96 { 97 97 this->setPlayableUniqueId( this->playableUniqueId ); 98 98 99 99 PRINTF(0)("uniqueID changed %d %d %d\n", userId, SharedNetworkData::getInstance()->getHostID(), getUniqueID()); 100 100 } 101 101 102 102 if ( std::find( id.begin(), id.end(), nickName_handler ) != id.end() ) 103 103 { … … 115 115 { 116 116 const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYER_STATS ); 117 117 118 118 if ( !list ) 119 119 { 120 120 return NULL; 121 121 } 122 122 123 123 for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ ) 124 124 { … … 128 128 } 129 129 } 130 130 131 131 return NULL; 132 132 } … … 138 138 { 139 139 const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYABLE ); 140 140 141 141 if ( !list ) 142 142 { … … 144 144 return; 145 145 } 146 146 147 147 this->playable = NULL; 148 148 for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ ) … … 156 156 } 157 157 } 158 158 159 159 if ( this->playable && userId == SharedNetworkData::getInstance()->getHostID() ) 160 160 { 161 161 State::getPlayer()->setPlayable( this->playable ); 162 162 } 163 163 164 164 this->playableUniqueId = uniqueId; 165 165 } … … 173 173 if ( playable ) 174 174 return playable; 175 175 176 176 assert( playableUniqueId > 0 ); 177 177 178 178 setPlayableUniqueId( playableUniqueId ); 179 179 180 180 assert( playable ); 181 181 182 182 return playable; 183 183 } … … 189 189 void PlayerStats::setNickName( std::string nick ) 190 190 { 191 if ( SharedNetworkData::getInstance()->is GameServer() )191 if ( SharedNetworkData::getInstance()->isMasterServer() ) 192 192 { 193 193 this->nickName = nick; … … 199 199 { 200 200 byte * data = new byte[nick.length()+INTSIZE]; 201 201 202 202 assert( Converter::stringToByteArray( nick, data, nick.length()+INTSIZE) == nick.length()+INTSIZE ); 203 203 204 204 MessageManager::getInstance()->sendMessage( MSGID_CHANGENICKNAME, data, nick.length()+INTSIZE, RT_SERVER, 0, MP_HIGHBANDWIDTH ); 205 205 return; … … 211 211 std::string newNick; 212 212 int res = Converter::byteArrayToString( data, newNick, dataLength ); 213 213 214 214 if ( res != dataLength ) 215 215 { … … 217 217 newNick = "invalid"; 218 218 } 219 219 220 220 if ( PlayerStats::getStats( userId ) ) 221 221 PlayerStats::getStats( userId )->setNickName( newNick ); 222 222 223 223 return true; 224 224 } … … 228 228 if ( getStats( SharedNetworkData::getInstance()->getHostID() ) ) 229 229 getStats( SharedNetworkData::getInstance()->getHostID() )->setNickName( newNick ); 230 230 231 231 Preferences::getInstance()->setString( "multiplayer", "nickname", newNick ); 232 232 } … … 237 237 { 238 238 const std::list<BaseObject*> * list; 239 239 240 240 while ( (list = ClassList::getList( CL_PLAYER_STATS )) != NULL && list->begin() != list->end() ) 241 241 delete *list->begin(); … … 247 247 { 248 248 ScoreList result; 249 249 250 250 const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYER_STATS ); 251 251 252 252 if ( !list ) 253 253 { 254 254 return result; 255 255 } 256 256 257 257 for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ ) 258 258 { 259 259 PlayerStats & stats = *dynamic_cast<PlayerStats*>(*it); 260 260 261 261 TeamScoreList::iterator it = result[stats.getTeamId()].begin(); 262 262 263 263 while ( it != result[stats.getTeamId()].end() && stats.score > it->score ) 264 264 { 265 265 it++; 266 266 } 267 267 268 268 PlayerScore score; 269 269 score.name = stats.getNickName(); 270 270 score.score = stats.getScore(); 271 271 272 272 result[stats.getTeamId()].insert(it, score); 273 273 } 274 274 275 275 return result; 276 276 } -
branches/proxy/src/lib/network/shared_network_data.cc
r9110 r9257 36 36 this->defaultSyncStream = NULL; 37 37 this->newUniqueID = MAX_CONNECTIONS + 2; 38 this-> bGameServer = false;38 this->nodeType = NET_CLIENT; 39 39 } 40 40 -
branches/proxy/src/lib/network/shared_network_data.h
r6695 r9257 8 8 9 9 #include "base_object.h" 10 #include "netdefs.h" 10 11 11 12 … … 25 26 26 27 /** @returns the next uniqueID free for an object */ 27 inline int getNewUniqueID() { return ( this-> bGameServer)?this->newUniqueID++:-1; }28 inline int getNewUniqueID() { return ( this->nodeType != NET_CLIENT)?this->newUniqueID++:-1; } 28 29 29 /** @returns true is this node is a game server */ 30 inline bool isGameServer() { return this->bGameServer; } 30 /** @returns true is this node is a master server */ 31 inline bool isMasterServer() { return this->nodeType == NET_MASTER_SERVER; } 32 /** @returns true is this node is a proxy server */ 33 inline bool isProxyServer() { return this->nodeType == NET_PROXY_SERVER; } 34 /** @returns true is this node is a client*/ 35 inline bool isClient() { return this->nodeType == NET_CLIENT; } 31 36 /** sets the game server flag @param bGameServer true if it is a game server */ 32 inline void set GameServer(bool bGameServer) { this->bGameServer = bGameServer; }37 inline void setNodeType(int nodeType) { this->nodeType = nodeType; } 33 38 34 39 /** @returns the hostID of the node */ … … 49 54 private: 50 55 int newUniqueID; //!< next uniqueID 51 bool bGameServer; //!< true if it is a server 56 int nodeType; //!< saves the node type here 57 52 58 int hostID; //!< The Host-ID of the Manager 53 59 NetworkStream* defaultSyncStream; //!< default synchronize NetworkStream
Note: See TracChangeset
for help on using the changeset viewer.