Changeset 9257 in orxonox.OLD for branches/proxy/src
- Timestamp:
- Jul 12, 2006, 5:10:09 PM (19 years ago)
- Location:
- branches/proxy/src
- Files:
-
- 13 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 -
branches/proxy/src/story_entities/multi_player_world_data.cc
r9235 r9257 110 110 { 111 111 const TiXmlElement* element = NULL; 112 113 if( NetworkManager::getInstance()->is GameServer() )112 113 if( NetworkManager::getInstance()->isMasterServer() ) 114 114 { 115 115 /* load the spawning points */ … … 147 147 element = element->FirstChildElement(); 148 148 149 if( NetworkManager::getInstance()->is GameServer() )149 if( NetworkManager::getInstance()->isMasterServer() ) 150 150 { 151 151 while( element != NULL) … … 205 205 206 206 207 if( NetworkManager::getInstance()->is GameServer())207 if( NetworkManager::getInstance()->isMasterServer()) 208 208 { 209 209 this->localPlayer = new Player(); … … 281 281 282 282 // create server playable 283 if ( NetworkManager::getInstance()->is GameServer() )283 if ( NetworkManager::getInstance()->isMasterServer() ) 284 284 { 285 285 NetworkGameManager::getInstance()->signalNewPlayer( 0 ); -
branches/proxy/src/util/game_rules.cc
r9008 r9257 88 88 void GameRules::registerKill(const Kill& kill) 89 89 { 90 if ( !SharedNetworkData::getInstance()->is GameServer() )90 if ( !SharedNetworkData::getInstance()->isMasterServer() ) 91 91 return; 92 92 -
branches/proxy/src/util/multiplayer_team_deathmatch.cc
r9235 r9257 204 204 assignPlayable(); 205 205 206 if ( !SharedNetworkData::getInstance()->is GameServer() )206 if ( !SharedNetworkData::getInstance()->isMasterServer() ) 207 207 return; 208 208 … … 214 214 this->killList.erase( this->killList.begin() ); 215 215 } 216 216 217 217 218 218 … … 268 268 void MultiplayerTeamDeathmatch::checkGameRules() 269 269 { 270 if ( !SharedNetworkData::getInstance()->is GameServer() )270 if ( !SharedNetworkData::getInstance()->isMasterServer() ) 271 271 return; 272 272 … … 320 320 return "maps/male_fiend.pcx"; 321 321 } 322 322 323 323 return ""; 324 324 } … … 330 330 return 10.0f; 331 331 } 332 332 333 333 return 1.0f; 334 334 } … … 680 680 char st[10]; 681 681 int i = 0; 682 682 683 683 i = 2; 684 684 for ( TeamScoreList::const_iterator it = scoreList[0].begin(); it != scoreList[0].end(); it++ ) … … 719 719 return; 720 720 } 721 721 722 722 int killerUserId = killer->getOwner(); 723 723 int victimUserId = victim->getOwner(); 724 724 725 725 PRINTF(0)("%d %d %x %x %s %s\n", killerUserId, victimUserId, killer, victim, killer->getClassName(), victim->getClassName()); 726 726 727 727 PlayerStats & victimStats = *PlayerStats::getStats( victimUserId ); 728 728 PlayerStats & killerStats = *PlayerStats::getStats( killerUserId ); 729 729 730 730 if ( killerStats.getPlayable() != killer || victimStats.getPlayable() != victim ) 731 731 { -
branches/proxy/src/world_entities/creatures/fps_player.cc
r9235 r9257 287 287 //dealing damage 288 288 289 if ( State::isOnline() && SharedNetworkData::getInstance()->is GameServer() )289 if ( State::isOnline() && SharedNetworkData::getInstance()->isMasterServer() ) 290 290 { 291 291 this->damageTicker -= time; -
branches/proxy/src/world_entities/playable.cc
r9235 r9257 361 361 } 362 362 } 363 /**364 * @brief helps us colliding Playables365 * @param entity the Entity to collide366 * @param location where the collision occured.367 */368 void Playable::collidesWith(WorldEntity* entity, const Vector& location)369 {370 if (entity == collider)371 return;372 collider = entity;373 374 if ( entity->isA(CL_PROJECTILE) && ( !State::isOnline() || SharedNetworkData::getInstance()->isGameServer() ) )375 {376 this->decreaseHealth(entity->getHealth() *(float)rand()/(float)RAND_MAX);377 // EXTREME HACK378 if (this->getHealth() <= 0.0f)379 {380 // this->destory();381 382 if( State::getGameRules() != NULL)383 State::getGameRules()->registerKill(Kill(entity, this));384 }385 }386 }387 363 388 364 … … 413 389 } 414 390 this->bDead = true; 415 391 416 392 if( State::getGameRules() != NULL) 417 393 State::getGameRules()->registerKill(Kill(killer, this)); -
branches/proxy/src/world_entities/playable.h
r9235 r9257 82 82 virtual void destroy(WorldEntity* killer); 83 83 virtual void respawn(); 84 virtual void collidesWith(WorldEntity* entity, const Vector& location);85 84 virtual void process(const Event &event); 86 85 virtual void tick(float dt); … … 90 89 static const std::string& playmodeToString(Playable::Playmode playmode); 91 90 static const std::string playmodeNames[]; 92 91 93 92 inline bool beFire(){ return this->bFire; } 94 93 inline void fire(bool bF){ this->bFire = bF;} -
branches/proxy/src/world_entities/spawning_point.cc
r9235 r9257 41 41 42 42 this->init(); 43 43 44 44 if (root != NULL) 45 45 this->loadParams(root); … … 50 50 this->setClassID(CL_SPAWNING_POINT, "SpawningPoint"); 51 51 PRINTF(0)("Created SpawningPoint\n"); 52 52 53 53 this->teamId = -1; 54 54 this->localTimer = 0.0f; 55 55 56 56 this->toList( OM_DEAD_TICK ); 57 57 58 58 MessageManager::getInstance()->registerMessageHandler( MSGID_RESPAWN, respawnMessageHandler, NULL ); 59 59 60 60 this->setSynchronized( true ); 61 61 } … … 94 94 qe.entity = entity; 95 95 qe.respawnTime = this->localTimer + delay; 96 96 97 97 queue.push_back( qe ); 98 98 } … … 105 105 { 106 106 const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYABLE ); 107 107 108 108 bool found = false; 109 109 110 110 if ( !list ) 111 111 return; 112 112 113 113 for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ ) 114 114 { … … 119 119 } 120 120 } 121 121 122 122 if ( !found ) 123 123 return; … … 128 128 entity->setAbsCoor( this->getAbsCoor() ); 129 129 entity->setAbsDir( this->getAbsDir() ); 130 130 131 131 //TODO set camera (not smooth) 132 132 133 133 if ( State::getGameRules() ) 134 134 { 135 135 (State::getGameRules())->registerSpawn( entity ); 136 136 } 137 137 138 138 entity->respawn(); 139 139 } … … 157 157 //spawn the player 158 158 this->spawn(it->entity); 159 159 160 160 const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYABLE ); 161 161 162 162 bool found = false; 163 163 164 164 if ( !list ) 165 165 return; 166 166 167 167 for ( std::list<BaseObject*>::const_iterator it2 = list->begin(); it2 != list->end(); it2++ ) 168 168 { … … 173 173 } 174 174 } 175 176 if ( found && SharedNetworkData::getInstance()->is GameServer() )175 176 if ( found && SharedNetworkData::getInstance()->isMasterServer() ) 177 177 this->sendRespawnMessage( it->entity->getUniqueID() ); 178 178 179 179 std::list<QueueEntry>::iterator delit = it; 180 180 it++; 181 181 182 182 queue.erase( delit ); 183 183 184 184 continue; 185 185 } 186 186 187 187 it++; 188 188 } … … 204 204 { 205 205 byte * buf = new byte[2*INTSIZE]; 206 206 207 207 assert( Converter::intToByteArray( this->getUniqueID(), buf, INTSIZE ) == INTSIZE ); 208 208 assert( Converter::intToByteArray( uniqueId, buf + INTSIZE, INTSIZE ) == INTSIZE ); 209 209 210 210 MessageManager::getInstance()->sendMessage( MSGID_RESPAWN, buf, 2*INTSIZE, RT_ALL_NOT_ME, 0, MP_HIGHBANDWIDTH ); 211 211 } … … 213 213 bool SpawningPoint::respawnMessageHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId ) 214 214 { 215 if ( SharedNetworkData::getInstance()->is GameServer() )215 if ( SharedNetworkData::getInstance()->isMasterServer() ) 216 216 { 217 217 PRINTF(2)("server received spawn message!\n"); 218 218 return true; 219 219 } 220 220 221 221 int spUniqueId; 222 222 int uniqueId; 223 223 224 224 if ( dataLength != 2*INTSIZE ) 225 225 { … … 227 227 return true; 228 228 } 229 229 230 230 assert( Converter::byteArrayToInt( data, &spUniqueId ) == INTSIZE ); 231 231 assert( Converter::byteArrayToInt( data+INTSIZE, &uniqueId ) == INTSIZE ); 232 232 233 233 PRINTF(0)("SPAWNMESSAGE %d\n", uniqueId); 234 234 235 235 SpawningPoint * sp = NULL; 236 236 Playable * playable = NULL; 237 237 238 238 const std::list<BaseObject*> * list = ClassList::getList( CL_SPAWNING_POINT ); 239 239 240 240 if ( list ) 241 241 { … … 250 250 } 251 251 } 252 252 253 253 if ( !sp ) 254 254 { … … 256 256 return false; 257 257 } 258 258 259 259 list = ClassList::getList( CL_PLAYABLE ); 260 260 261 261 if ( list ) 262 262 { … … 270 270 } 271 271 } 272 272 273 273 if ( !playable ) 274 274 { … … 276 276 return false; 277 277 } 278 278 279 279 sp->spawn( playable ); 280 280 281 281 return true; 282 282 }
Note: See TracChangeset
for help on using the changeset viewer.