Changeset 8623 in orxonox.OLD for trunk/src/lib
- Timestamp:
- Jun 20, 2006, 1:39:01 PM (18 years ago)
- Location:
- trunk/src/lib
- Files:
-
- 19 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/event/event_handler.cc
r8619 r8623 503 503 504 504 505 int EventHandler::releaseMouse(void* p) 506 { 507 SDL_WM_GrabInput(SDL_GRAB_OFF); 508 SDL_ShowCursor(SDL_DISABLE); 509 return 0; 510 } 511 512 505 513 /** 506 514 * @param state The State to get the Name of. -
trunk/src/lib/event/event_handler.h
r8148 r8623 56 56 static elState StringToELState(const std::string& stateName); 57 57 58 static int releaseMouse(void* p); 59 58 60 private: 59 61 EventHandler(); -
trunk/src/lib/network/Makefile.am
r8068 r8623 24 24 zip.cc \ 25 25 player_stats.cc \ 26 udp_broadcast.cc \ 26 27 \ 27 28 synchronizeable_var/synchronizeable_var.cc \ … … 58 59 zip.h \ 59 60 player_stats.h \ 61 udp_broadcast.h \ 60 62 \ 61 63 synchronizeable_var/synchronizeable_var.h \ -
trunk/src/lib/network/connection_monitor.cc
r8068 r8623 130 130 131 131 /** 132 * remove old packets 133 * @param packetHistory 134 * @param tick 135 */ 136 void ConnectionMonitor::removeOldPackets( std::map< int, int > & packetHistory, int tick ) 137 { 138 while ( packetHistory.begin()->first < tick - MSECS_TO_CALC_BWIDTH ) 139 packetHistory.erase( packetHistory.begin() ); 140 } 141 142 /** 132 143 * calculate bandwidth out of packethistory 133 144 * @param packetHistory packet history … … 135 146 * @return bandwidth in bytes/sec 136 147 */ 137 float ConnectionMonitor::calculateBandWidth( std::map< int, int > packetHistory, int tick ) 138 { 139 // delete old packets 140 while ( packetHistory.begin()->first < tick - MSECS_TO_CALC_BWIDTH ) 141 packetHistory.erase( packetHistory.begin() ); 148 float ConnectionMonitor::calculateBandWidth( std::map< int, int > & packetHistory, int tick ) 149 { 150 removeOldPackets( packetHistory, tick ); 142 151 143 152 float res = 0.0f; 144 153 #if 0 145 154 for ( std::map<int,int>::iterator it = packetHistory.begin(); it != packetHistory.end(); it++ ) 146 155 { … … 155 164 156 165 res *= 1000.0f; 157 166 #endif 167 168 for ( std::map<int,int>::iterator it = packetHistory.begin(); it != packetHistory.end(); it++ ) 169 { 170 res += it->second; 171 } 172 173 if ( packetHistory.size() <= 1 ) 174 res = 0.0f; 175 else 176 res /= (float)(tick - packetHistory.begin()->first); 177 178 res *= 1000.0f; 179 158 180 return res; 159 181 } -
trunk/src/lib/network/connection_monitor.h
r8362 r8623 15 15 #define N_PACKETS_FOR_PING 20 16 16 #define MSECS_TO_CALC_BWIDTH 1000 17 #define SECS_TO_TIMEOUT 1017 #define SECS_TO_TIMEOUT 30 18 18 19 19 class ConnectionMonitor : virtual public BaseObject … … 36 36 37 37 private: 38 float calculateBandWidth( std::map<int,int> packetHistory, int tick ); 38 float calculateBandWidth( std::map<int,int> & packetHistory, int tick ); 39 void removeOldPackets( std::map<int,int> & packetHistory, int tick ); 39 40 40 41 int userId; //!< user's id -
trunk/src/lib/network/data_stream.cc
r7954 r8623 53 53 DataStream::~DataStream() 54 54 { 55 55 delete [] this->upBuffer; 56 this->upBuffer = NULL; 57 delete [] this->downBuffer; 58 this->downBuffer = NULL; 56 59 } 57 60 … … 120 123 int passUp(byte* data) 121 124 { 122 125 return 0; 123 126 } -
trunk/src/lib/network/message_manager.cc
r8228 r8623 47 47 if ( it2->data ) 48 48 { 49 delete it2->data;49 delete [] it2->data; 50 50 it2->data = NULL; 51 51 } … … 319 319 { 320 320 NetworkMessage msg; 321 321 322 322 msg.data = new byte[dataLength]; 323 323 memcpy( msg.data, data, dataLength ); … … 326 326 msg.number = newNumber++; 327 327 msg.priority = messagePriority; 328 328 329 329 it->second.messages.push_back( msg ); 330 330 331 if ( recieverType == RT_ALL_ME ) 332 incomingMessabeBuffer.push_back( msg ); 333 } 334 } 335 } 336 337 331 332 } 333 } 334 335 if ( recieverType == RT_ALL_ME ) 336 { 337 NetworkMessage msg; 338 339 msg.data = new byte[dataLength]; 340 memcpy( msg.data, data, dataLength ); 341 msg.length = dataLength; 342 msg.messageId = messageId; 343 msg.number = newNumber++; 344 msg.priority = messagePriority; 345 346 incomingMessabeBuffer.push_back( msg ); 347 } 348 } 349 350 -
trunk/src/lib/network/message_manager.h
r8228 r8623 31 31 MSGID_DELETESYNCHRONIZEABLE, 32 32 MSGID_PREFEREDTEAM, 33 MSGID_CHANGEPLAYERNAME 33 MSGID_CHANGENICKNAME, 34 MSGID_CHATMESSAGE 34 35 }; 35 36 -
trunk/src/lib/network/network_game_manager.cc
r8362 r8623 23 23 #include "state.h" 24 24 #include "class_list.h" 25 #include "debug.h" 25 26 26 27 #include "network_stream.h" … … 39 40 #include "network_game_manager.h" 40 41 41 #include "debug.h"42 43 42 44 43 /* using namespace std is default, this needs to be here */ … … 59 58 60 59 this->setSynchronized(true); 61 60 62 61 MessageManager::getInstance()->registerMessageHandler( MSGID_DELETESYNCHRONIZEABLE, delSynchronizeableHandler, NULL ); 63 62 MessageManager::getInstance()->registerMessageHandler( MSGID_PREFEREDTEAM, preferedTeamHandler, NULL ); 64 63 MessageManager::getInstance()->registerMessageHandler( MSGID_CHATMESSAGE, chatMessageHandler, NULL ); 64 65 65 this->gameState = 0; 66 66 registerVar( new SynchronizeableInt( &gameState, &gameState, "gameState" ) ); … … 72 72 NetworkGameManager::~NetworkGameManager() 73 73 { 74 delete MessageManager::getInstance(); 75 76 PlayerStats::deleteAllPlayerStats(); 74 77 } 75 78 … … 77 80 /** 78 81 * insert new player into game 79 * @param userId 80 * @return 82 * @param userId 83 * @return 81 84 */ 82 85 bool NetworkGameManager::signalNewPlayer( int userId ) … … 85 88 assert( State::getGameRules() ); 86 89 assert( State::getGameRules()->isA( CL_NETWORK_GAME_RULES ) ); 87 90 88 91 NetworkGameRules & rules = *(dynamic_cast<NetworkGameRules*>(State::getGameRules())); 89 92 90 93 int team = rules.getTeamForNewUser(); 91 94 ClassID playableClassId = rules.getPlayableClassId( userId, team ); 92 95 std::string playableModel = rules.getPlayableModelFileName( userId, team, playableClassId ); 93 96 94 97 BaseObject * bo = Factory::fabricate( playableClassId ); 95 98 96 99 assert( bo != NULL ); 97 100 assert( bo->isA( CL_PLAYABLE ) ); 98 101 99 102 Playable & playable = *(dynamic_cast<Playable*>(bo)); 100 101 playable.loadModel( playableModel ); 103 104 if ( playableModel != "" ) 105 playable.loadModel( playableModel ); 102 106 playable.setOwner( userId ); 103 107 playable.setUniqueID( SharedNetworkData::getInstance()->getNewUniqueID() ); 104 108 playable.setSynchronized( true ); 105 109 106 110 PlayerStats * stats = rules.getNewPlayerStats( userId ); 107 111 108 112 stats->setUniqueID( SharedNetworkData::getInstance()->getNewUniqueID() ); 109 113 stats->setSynchronized( true ); 110 114 stats->setOwner( getHostID() ); 111 115 112 116 stats->setTeamId( team ); 113 117 stats->setPlayableClassId( playableClassId ); 114 118 stats->setPlayableUniqueId( playable.getUniqueID() ); 115 119 stats->setModelFileName( playableModel ); 116 120 117 121 return true; 118 122 } … … 121 125 /** 122 126 * remove player from game 123 * @param userID 124 * @return 127 * @param userID 128 * @return 125 129 */ 126 130 bool NetworkGameManager::signalLeftPlayer(int userID) … … 132 136 delete PlayerStats::getStats( userID ); 133 137 } 134 138 135 139 return true; 136 140 } … … 140 144 /** 141 145 * handler for remove synchronizeable messages 142 * @param messageId 143 * @param data 144 * @param dataLength 145 * @param someData 146 * @param userId 146 * @param messageId 147 * @param data 148 * @param dataLength 149 * @param someData 150 * @param userId 147 151 * @return true on successfull handling else handler will be called again 148 152 */ … … 154 158 return true; 155 159 } 156 160 157 161 int uniqueId = 0; 158 162 int len = Converter::byteArrayToInt( data, &uniqueId ); 159 163 160 164 if ( len != dataLength ) 161 165 { … … 163 167 return true; 164 168 } 165 169 166 170 const std::list<BaseObject*> * list = ClassList::getList( CL_SYNCHRONIZEABLE ); 167 171 168 172 for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ ) 169 173 { … … 175 179 return true; 176 180 } 177 181 178 182 delete dynamic_cast<Synchronizeable*>(*it); 179 183 return true; 180 184 } 181 185 } 182 186 183 187 return true; 184 188 } … … 191 195 { 192 196 byte buf[INTSIZE]; 193 197 194 198 assert( Converter::intToByteArray( uniqueId, buf, INTSIZE ) == INTSIZE ); 195 199 … … 201 205 /** 202 206 * handler for MSGID_PREFEREDTEAM message 203 * @param messageId 204 * @param data 205 * @param dataLength 206 * @param someData 207 * @param userId 208 * @return 207 * @param messageId 208 * @param data 209 * @param dataLength 210 * @param someData 211 * @param userId 212 * @return 209 213 */ 210 214 bool NetworkGameManager::preferedTeamHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId ) 211 215 { 212 216 assert( NetworkGameManager::getInstance()->isServer() ); 213 217 214 218 int teamId = 0; 215 219 int len = Converter::byteArrayToInt( data, &teamId ); 216 220 217 221 if ( len != dataLength ) 218 222 { … … 220 224 return true; 221 225 } 222 226 223 227 NetworkGameManager::getInstance()->setPreferedTeam( userId, teamId ); 224 228 225 229 return true; 226 230 } … … 230 234 if ( !PlayerStats::getStats( userId ) ) 231 235 return; 232 236 233 237 PlayerStats & stats = *(PlayerStats::getStats( userId )); 234 238 235 239 stats.setPreferedTeamId( teamId ); 236 240 } … … 238 242 /** 239 243 * set prefered team for this host 240 * @param teamId 244 * @param teamId 241 245 */ 242 246 void NetworkGameManager::prefereTeam( int teamId ) … … 247 251 { 248 252 byte buf[INTSIZE]; 249 253 250 254 assert( Converter::intToByteArray( teamId, buf, INTSIZE) == INTSIZE ); 251 255 252 256 MessageManager::getInstance()->sendMessage( MSGID_PREFEREDTEAM, buf, INTSIZE, RT_USER, 0, MP_HIGHBANDWIDTH ); 253 257 } … … 278 282 279 283 280 284 bool NetworkGameManager::chatMessageHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId ) 285 { 286 assert( State::getGameRules() ); 287 assert( State::getGameRules()->isA( CL_NETWORK_GAME_RULES ) ); 288 289 NetworkGameRules & rules = *(dynamic_cast<NetworkGameRules*>(State::getGameRules())); 290 291 if ( dataLength < 2*INTSIZE ) 292 { 293 PRINTF(2)("got too small chatmessage from client %d\n", userId); 294 295 return true; 296 } 297 298 int messageType = 0; 299 Converter::byteArrayToInt( data, &messageType ); 300 std::string message; 301 Converter::byteArrayToString( data+INTSIZE, message, dataLength-INTSIZE ); 302 303 rules.handleChatMessage( userId, message, messageType ); 304 305 return true; 306 } 307 308 /** 309 * send chat message 310 * @param message message text 311 * @param messageType some int 312 * @param userId user to send message to -1 = ALL 313 */ 314 void NetworkGameManager::sendChatMessage( const std::string & message, int messageType, int userId ) 315 { 316 byte * buf = new byte[message.length()+2*INTSIZE]; 317 318 assert( Converter::intToByteArray( messageType, buf, INTSIZE ) == INTSIZE ); 319 assert( Converter::stringToByteArray(message, buf+INTSIZE, message.length()+INTSIZE) == message.length()+INTSIZE ); 320 321 if ( userId == -1 ) 322 MessageManager::getInstance()->sendMessage( MSGID_CHATMESSAGE, buf, message.length()+2*INTSIZE, RT_ALL_ME, 0, MP_HIGHBANDWIDTH ); 323 else 324 MessageManager::getInstance()->sendMessage( MSGID_CHATMESSAGE, buf, message.length()+2*INTSIZE, RT_USER, userId, MP_HIGHBANDWIDTH ); 325 326 delete [] buf; 327 } 328 329 330 -
trunk/src/lib/network/network_game_manager.h
r8147 r8623 64 64 65 65 void tick( float ds ); 66 67 void sendChatMessage( const std::string & message, int messageType, int userId = -1 ); 66 68 67 69 private: … … 70 72 static bool delSynchronizeableHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId ); 71 73 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 ); 72 75 73 76 void setPreferedTeam( int userId, int teamId ); -
trunk/src/lib/network/network_stream.cc
r8228 r8623 95 95 remainingBytesToWriteToDict = Preferences::getInstance()->getInt( "compression", "writedict", 0 ); 96 96 97 assert( Zip::getInstance()->loadDictionary( "testdict" ) ); 97 assert( Zip::getInstance()->loadDictionary( "testdict" ) >= 0 ); 98 this->dictClient = Zip::getInstance()->loadDictionary( "dict2pl_client" ); 99 assert( this->dictClient >= 0 ); 100 this->dictServer = Zip::getInstance()->loadDictionary( "dict2p_server" ); 101 assert( this->dictServer >= 0 ); 98 102 } 99 103 … … 121 125 delete i->second.handshake; 122 126 i->second.handshake = NULL; 127 } 128 129 if ( i->second.connectionMonitor ) 130 { 131 delete i->second.connectionMonitor; 132 i->second.connectionMonitor = NULL; 123 133 } 124 134 } … … 198 208 delete peers[0].handshake; 199 209 peers[0].handshake = NULL; 210 211 if ( peers[0].connectionMonitor ) 212 delete peers[0].connectionMonitor; 213 peers[0].connectionMonitor = NULL; 200 214 } 201 215 } … … 282 296 it->second.socket = NULL; 283 297 298 if ( it->second.connectionMonitor ) 299 delete it->second.connectionMonitor; 300 it->second.connectionMonitor = NULL; 301 284 302 if ( it->second.handshake ) 285 303 delete it->second.handshake; … … 490 508 assert( Converter::intToByteArray( offset, buf, INTSIZE ) == INTSIZE ); 491 509 492 int compLength = Zip::getInstance()->zip( buf, offset, compBuf, UDP_PACKET_SIZE ); 493 494 if ( compLength < 0 ) 510 int compLength = 0; 511 if ( this->isServer() ) 512 compLength = Zip::getInstance()->zip( buf, offset, compBuf, UDP_PACKET_SIZE, dictServer ); 513 else 514 compLength = Zip::getInstance()->zip( buf, offset, compBuf, UDP_PACKET_SIZE, dictClient ); 515 516 if ( compLength <= 0 ) 495 517 { 496 518 PRINTF(1)("compression failed!\n"); … … 501 523 502 524 if ( this->remainingBytesToWriteToDict > 0 ) 503 writeToNewDict( buf, offset );525 writeToNewDict( buf, offset, true ); 504 526 505 527 peer->second.connectionMonitor->processUnzippedOutgoingPacket( tick, buf, offset, currentState ); … … 538 560 //PRINTF(0)("GGGGGOOOOOOOOOOTTTTTTTT: %d\n", compLength); 539 561 packetLength = Zip::getInstance()->unZip( compBuf, compLength, buf, UDP_PACKET_SIZE ); 540 562 541 563 if ( packetLength < 4*INTSIZE ) 542 564 { … … 547 569 548 570 if ( this->remainingBytesToWriteToDict > 0 ) 549 writeToNewDict( buf, packetLength );571 writeToNewDict( buf, packetLength, false ); 550 572 551 573 assert( Converter::byteArrayToInt( buf, &length ) == INTSIZE ); … … 556 578 offset = 4*INTSIZE; 557 579 558 peer->second.connectionMonitor->processUnzippedIncomingPacket( tick, buf, offset, state, ackedState );580 peer->second.connectionMonitor->processUnzippedIncomingPacket( tick, buf, packetLength, state, ackedState ); 559 581 560 582 //NETPRINTF(n)("got packet: %d, %d\n", length, packetLength); … … 729 751 * @param length length 730 752 */ 731 void NetworkStream::writeToNewDict( byte * data, int length )753 void NetworkStream::writeToNewDict( byte * data, int length, bool upstream ) 732 754 { 733 755 if ( remainingBytesToWriteToDict <= 0 ) … … 739 761 std::string fileName = ResourceManager::getInstance()->getDataDir(); 740 762 fileName += "/dicts/newdict"; 763 764 if ( upstream ) 765 fileName += "_upstream"; 766 else 767 fileName += "_downstream"; 741 768 742 769 FILE * f = fopen( fileName.c_str(), "a" ); -
trunk/src/lib/network/network_stream.h
r8068 r8623 84 84 void cleanUpOldSyncList(); 85 85 86 void writeToNewDict( byte * data, int length );86 void writeToNewDict( byte * data, int length, bool upstream ); 87 87 88 88 … … 107 107 108 108 int remainingBytesToWriteToDict; //!< if > 0 NetworkStream will write packets to DATA/dicts/newdict 109 110 int dictServer; 111 int dictClient; 109 112 }; 110 113 #endif /* _NETWORK_STREAM */ -
trunk/src/lib/network/player_stats.cc
r8362 r8623 24 24 25 25 #include "debug.h" 26 #include "shell_command.h" 26 27 27 28 28 29 CREATE_FACTORY(PlayerStats, CL_PLAYER_STATS); 29 30 31 30 32 /** 31 33 * constructor … … 34 36 { 35 37 init(); 36 38 37 39 this->userId = userId; 38 40 } … … 56 58 this->playableClassId = 0; 57 59 this->modelFileName = ""; 58 60 this->nickName = "Player"; 61 this->oldNickName = "Player"; 62 59 63 userId_handle = registerVarId( new SynchronizeableInt( &userId, &userId, "userId" ) ); 60 64 teamId_handle = registerVarId( new SynchronizeableInt( &teamId, &teamId, "teamId" ) ); … … 64 68 playableUniqueId_handle = registerVarId( new SynchronizeableInt( &playableUniqueId, &playableUniqueId, "playableUniqueId" ) ); 65 69 modelFileName_handle = registerVarId( new SynchronizeableString( &modelFileName, &modelFileName, "modelFileName" ) ); 66 70 nickName_handler = registerVarId( new SynchronizeableString( &nickName, &nickName, "nickName" ) ); 71 72 MessageManager::getInstance()->registerMessageHandler( MSGID_CHANGENICKNAME, changeNickHandler, NULL ); 73 67 74 PRINTF(0)("PlayerStats created\n"); 68 75 } … … 87 94 { 88 95 this->setPlayableUniqueId( this->playableUniqueId ); 89 96 90 97 PRINTF(0)("uniqueID changed %d %d %d\n", userId, getHostID(), getUniqueID()); 98 } 99 100 if ( std::find( id.begin(), id.end(), nickName_handler ) != id.end() ) 101 { 102 PRINTF(0)("user %s is now known as %s\n", oldNickName.c_str(), nickName.c_str()); 103 oldNickName = nickName; 91 104 } 92 105 } … … 100 113 { 101 114 const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYER_STATS ); 102 115 103 116 if ( !list ) 104 117 { 105 118 return NULL; 106 119 } 107 120 108 121 for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ ) 109 122 { … … 113 126 } 114 127 } 115 128 116 129 return NULL; 117 130 } … … 123 136 { 124 137 const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYABLE ); 125 138 126 139 if ( !list ) 127 140 { … … 129 142 return; 130 143 } 131 144 132 145 this->playable = NULL; 133 146 for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ ) … … 141 154 } 142 155 } 143 156 144 157 if ( this->playable && userId == getHostID() ) 145 158 { 146 159 State::getPlayer()->setPlayable( this->playable ); 147 160 } 148 161 149 162 this->playableUniqueId = uniqueId; 150 163 } … … 158 171 if ( playable ) 159 172 return playable; 160 173 161 174 assert( playableUniqueId > 0 ); 162 175 163 176 setPlayableUniqueId( playableUniqueId ); 164 177 165 178 assert( playable ); 166 179 167 180 return playable; 168 181 } 169 182 170 183 /** 184 * client sends server a message to change nick and server changes nick directly 185 * @param nick new nickname 186 */ 187 void PlayerStats::setNickName( std::string nick ) 188 { 189 if ( isServer() ) 190 { 191 this->nickName = nick; 192 PRINTF(0)("user %s is now known as %s\n", oldNickName.c_str(), nickName.c_str()); 193 oldNickName = nickName; 194 return; 195 } 196 else 197 { 198 byte * data = new byte[nick.length()+INTSIZE]; 199 200 assert( Converter::stringToByteArray( nick, data, nick.length()+INTSIZE) == nick.length()+INTSIZE ); 201 202 MessageManager::getInstance()->sendMessage( MSGID_CHANGENICKNAME, data, nick.length()+INTSIZE, RT_SERVER, 0, MP_HIGHBANDWIDTH ); 203 return; 204 } 205 } 206 207 bool PlayerStats::changeNickHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId ) 208 { 209 std::string newNick; 210 int res = Converter::byteArrayToString( data, newNick, dataLength ); 211 212 if ( res != dataLength ) 213 { 214 PRINTF(2)("invalid message size from user %d\n", userId); 215 newNick = "invalid"; 216 } 217 218 if ( PlayerStats::getStats( userId ) ) 219 PlayerStats::getStats( userId )->setNickName( newNick ); 220 221 return true; 222 } 223 224 void PlayerStats::shellNick( const std::string& newNick ) 225 { 226 if ( getStats( SharedNetworkData::getInstance()->getHostID() ) ) 227 getStats( SharedNetworkData::getInstance()->getHostID() )->setNickName( newNick ); 228 } 229 230 231 232 void PlayerStats::deleteAllPlayerStats( ) 233 { 234 const std::list<BaseObject*> * list; 235 236 while ( (list = ClassList::getList( CL_PLAYER_STATS )) != NULL && list->begin() != list->end() ) 237 delete *list->begin(); 238 } 239 -
trunk/src/lib/network/player_stats.h
r8068 r8623 9 9 #include "synchronizeable.h" 10 10 #include "playable.h" 11 #include "message_manager.h" 11 12 12 13 #include <string> … … 54 55 55 56 Playable * getPlayable(); 57 58 inline std::string getNickName(){ return this->nickName; } 59 void setNickName( std::string nick ); 60 static bool changeNickHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId ); 61 void shellNick( const std::string& newNick ); 62 63 static void deleteAllPlayerStats(); 56 64 57 65 private: … … 59 67 int teamId; //!< teamId 60 68 int preferedTeamId; //!< preferedTeamId 69 70 std::string nickName; //!< players nickname 71 std::string oldNickName; //!< nickname player had before 61 72 62 73 int score; //!< users score points … … 75 86 int playableUniqueId_handle; 76 87 int modelFileName_handle; 88 int nickName_handler; 77 89 78 90 void init(); -
trunk/src/lib/network/synchronizeable.cc
r8228 r8623 70 70 this->networkStream->disconnectSynchronizeable(*this); 71 71 72 if ( this->isServer() && this->beSynchronized() && this->getUniqueID() > 0 )72 if ( this->isServer() && this->beSynchronized() && this->getUniqueID() > 0 && !this->isA( CL_MESSAGE_MANAGER ) ) 73 73 NetworkGameManager::getInstance()->removeSynchronizeable( this->getUniqueID() ); 74 75 for ( SyncVarList::iterator it = syncVarList.begin(); it != syncVarList.end(); it++ ) 76 { 77 delete *it; 78 } 79 syncVarList.clear(); 80 81 for ( UserStateHistory::iterator it = recvStates.begin(); it != recvStates.end(); it++ ) 82 { 83 for ( StateHistory::iterator it2 = it->begin(); it2 != it->end(); it2++ ) 84 { 85 if ( (*it2)->data ) 86 { 87 delete [] (*it2)->data; 88 (*it2)->data = NULL; 89 } 90 delete *it2; 91 } 92 93 } 94 95 for ( UserStateHistory::iterator it = sentStates.begin(); it != sentStates.end(); it++ ) 96 { 97 for ( StateHistory::iterator it2 = it->begin(); it2 != it->end(); it2++ ) 98 { 99 if ( (*it2)->data ) 100 { 101 delete [] (*it2)->data; 102 (*it2)->data = NULL; 103 } 104 delete *it2; 105 } 106 107 } 74 108 } 75 109 … … 134 168 (*it2)->data = NULL; 135 169 } 170 171 delete *it2; 136 172 } 137 173 sentStates[userId].erase( sentStates[userId].begin(), it ); … … 159 195 160 196 stateFrom = initialEntry; 197 198 sentStates[userId].push_back( stateFrom ); 161 199 } 162 200 else 163 201 stateFrom = (*it); 164 202 165 StateHistoryEntry * stateTo = new StateHistoryEntry(); 166 203 StateHistoryEntry * stateTo = new StateHistoryEntry; 204 205 sentStates[userId].push_back( stateTo ); 206 167 207 stateTo->stateId = stateId; 168 208 stateTo->dataLength = neededSize; … … 175 215 176 216 bool hasPermission; 217 bool sizeChanged = false; 177 218 178 219 // now do the actual synchronization: kick all variables to write into a common buffer … … 186 227 ); 187 228 188 if ( ( sizeIter != stateFrom->sizeList.end() && *sizeIter != (*it)->getSize() ) || ( hasPermission && (*it)->getPriority() >= priorityTH ) || sizeIter == stateFrom->sizeList.end() ) 229 if ( sizeIter == stateFrom->sizeList.end() || *sizeIter != (*it)->getSize() ) 230 sizeChanged = true; 231 232 if ( ( hasPermission && (*it)->getPriority() >= priorityTH ) || sizeChanged ) 189 233 { 190 234 n = (*it)->writeToBuf( stateTo->data+i, stateTo->dataLength - i ); … … 210 254 } 211 255 212 sentStates[userId].push_back( stateTo );213 214 256 if ( i != neededSize ) 215 257 { … … 275 317 276 318 stateFrom = initialEntry; 319 320 recvStates[userId].push_back( stateFrom ); 277 321 } 278 322 else … … 374 418 { 375 419 if ( (*it)->data ) 420 { 376 421 delete [] (*it)->data; 377 (*it)->data = NULL; 422 (*it)->data = NULL; 423 } 378 424 379 425 delete *it; … … 388 434 { 389 435 if ( (*it)->data ) 436 { 390 437 delete [] (*it)->data; 391 (*it)->data = NULL; 438 (*it)->data = NULL; 439 } 392 440 393 441 delete *it; … … 438 486 439 487 if ( (*delIt)->data ) 488 { 440 489 delete [] (*delIt)->data; 490 (*delIt)->data = NULL; 491 } 492 delete *delIt; 441 493 recvStates[userId].erase( delIt ); 442 494 … … 506 558 507 559 if ( (*delIt)->data ) 560 { 508 561 delete [] (*delIt)->data; 562 (*delIt)->data = NULL; 563 } 564 delete *delIt; 509 565 sentStates[userId].erase( delIt ); 510 566 -
trunk/src/lib/network/udp_server_socket.cc
r8362 r8623 220 220 bool UdpServerSocket::sendPacket( NetworkPacket networkPacket , int userId ) 221 221 { 222 if ( !socket ) 223 return false; 224 222 225 assert( networkPacket.length <= UDP_PACKET_SIZE ); 223 226 -
trunk/src/lib/network/zip.cc
r8362 r8623 49 49 * @return true on success 50 50 */ 51 boolZip::loadDictionary( std::string name )51 int Zip::loadDictionary( std::string name ) 52 52 { 53 53 std::string fileName = ResourceManager::getInstance()->getDataDir(); … … 61 61 { 62 62 PRINTF(1)("Could not open %d\n", fileName.c_str()); 63 return false;63 return -1; 64 64 } 65 65 … … 88 88 PRINTF(3)("Loaded dictionary '%s' with adler = %d\n", name.c_str(), entry.adler ); 89 89 90 return true;90 return dicts.size()-1; 91 91 } 92 92 -
trunk/src/lib/network/zip.h
r7954 r8623 28 28 inline static Zip* getInstance(void) { if (!singletonRef) singletonRef = new Zip(); return singletonRef; }; 29 29 30 boolloadDictionary( std::string name );30 int loadDictionary( std::string name ); 31 31 int zip( byte * from, int fromLength, byte * to, int maxLength, int dict = 0 ); 32 32 int unZip( byte * from, int fromLength, byte * to, int maxLength ); -
trunk/src/lib/shell/some_shell_commands.cc
r7725 r8623 28 28 using namespace OrxShell; 29 29 30 #include "network_game_rules.h" 31 SHELL_COMMAND(say, NetworkGameRules, shellSay)->setAlias("say"); 30 32 33 #include "player_stats.h" 34 SHELL_COMMAND(nick, PlayerStats, shellNick)->setAlias("nick"); 31 35 32 36 #include "class_list.h"
Note: See TracChangeset
for help on using the changeset viewer.