- Timestamp:
- Jun 22, 2006, 12:48:01 PM (19 years ago)
- Location:
- trunk/src
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/network/message_manager.cc
r8623 r8708 19 19 20 20 #include "network_stream.h" 21 #include "shared_network_data.h" 21 22 22 23 using namespace std; … … 196 197 msg.number = userId; 197 198 198 incomingMessa beBuffer.push_back( msg );199 incomingMessageBuffer.push_back( msg ); 199 200 } 200 201 messageQueue[userId].recievedMessages.push_back( number ); … … 204 205 205 206 206 for ( std::list<NetworkMessage>::iterator it = incomingMessabeBuffer.begin(); it != incomingMessabeBuffer.end(); ) 207 //TODO maybe handle incomingMessage in tick function. else local messages will not be handled if no clients are connected 208 for ( std::list<NetworkMessage>::iterator it = incomingMessageBuffer.begin(); it != incomingMessageBuffer.end(); ) 207 209 { 208 210 if ( (*(messageHandlerMap[it->messageId].cb))( it->messageId, it->data, it->length, messageHandlerMap[it->messageId].someData, it->number ) ) … … 212 214 delete it->data; 213 215 it++; 214 incomingMessa beBuffer.erase( delIt );216 incomingMessageBuffer.erase( delIt ); 215 217 continue; 216 218 } … … 328 330 329 331 it->second.messages.push_back( msg ); 330 331 332 332 } 333 333 } … … 341 341 msg.length = dataLength; 342 342 msg.messageId = messageId; 343 msg.number = newNumber++;343 msg.number = SharedNetworkData::getInstance()->getHostID(); 344 344 msg.priority = messagePriority; 345 345 346 incomingMessa beBuffer.push_back( msg );347 } 348 } 349 350 346 incomingMessageBuffer.push_back( msg ); 347 } 348 } 349 350 -
trunk/src/lib/network/message_manager.h
r8623 r8708 109 109 110 110 int newNumber; //!< used to create unique message numbers 111 std::list<NetworkMessage> incomingMessa beBuffer;111 std::list<NetworkMessage> incomingMessageBuffer; 112 112 113 113 }; -
trunk/src/lib/network/network_game_manager.cc
r8623 r8708 112 112 stats->setUniqueID( SharedNetworkData::getInstance()->getNewUniqueID() ); 113 113 stats->setSynchronized( true ); 114 stats->setOwner( getHostID() );114 stats->setOwner( SharedNetworkData::getInstance()->getHostID() ); 115 115 116 116 stats->setTeamId( team ); … … 247 247 { 248 248 if ( isServer() ) 249 setPreferedTeam( getHostID(), teamId );249 setPreferedTeam( SharedNetworkData::getInstance()->getHostID(), teamId ); 250 250 else 251 251 { … … 284 284 bool NetworkGameManager::chatMessageHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId ) 285 285 { 286 PRINTF(0)("NetworkGameManager::chatMessageHandler %d %d\n", userId, SharedNetworkData::getInstance()->getHostID() ); 287 if ( NetworkGameManager::getInstance()->isServer() && userId != SharedNetworkData::getInstance()->getHostID() ) 288 { 289 MessageManager::getInstance()->sendMessage( messageId, data, dataLength, RT_ALL_NOT_ME, 0, MP_HIGHBANDWIDTH ); 290 } 291 286 292 assert( State::getGameRules() ); 287 293 assert( State::getGameRules()->isA( CL_NETWORK_GAME_RULES ) ); … … 289 295 NetworkGameRules & rules = *(dynamic_cast<NetworkGameRules*>(State::getGameRules())); 290 296 291 if ( dataLength < 2*INTSIZE )297 if ( dataLength < 3*INTSIZE ) 292 298 { 293 299 PRINTF(2)("got too small chatmessage from client %d\n", userId); … … 298 304 int messageType = 0; 299 305 Converter::byteArrayToInt( data, &messageType ); 306 int senderUserId = 0; 307 Converter::byteArrayToInt( data+INTSIZE, &senderUserId ); 300 308 std::string message; 301 Converter::byteArrayToString( data+ INTSIZE, message, dataLength-INTSIZE );302 303 rules.handleChatMessage( userId, message, messageType );309 Converter::byteArrayToString( data+2*INTSIZE, message, dataLength-2*INTSIZE ); 310 311 rules.handleChatMessage( senderUserId, message, messageType ); 304 312 305 313 return true; … … 310 318 * @param message message text 311 319 * @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]; 320 */ 321 void NetworkGameManager::sendChatMessage( const std::string & message, int messageType ) 322 { 323 byte * buf = new byte[message.length()+3*INTSIZE]; 317 324 318 325 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 ); 326 assert( Converter::intToByteArray( SharedNetworkData::getInstance()->getHostID(), buf+INTSIZE, INTSIZE ) == INTSIZE ); 327 assert( Converter::stringToByteArray(message, buf+2*INTSIZE, message.length()+INTSIZE) == message.length()+INTSIZE ); 328 329 if ( this->isServer() ) 330 MessageManager::getInstance()->sendMessage( MSGID_CHATMESSAGE, buf, message.length()+3*INTSIZE, RT_ALL_ME, 0, MP_HIGHBANDWIDTH ); 323 331 else 324 MessageManager::getInstance()->sendMessage( MSGID_CHATMESSAGE, buf, message.length()+2*INTSIZE, RT_USER, userId, MP_HIGHBANDWIDTH ); 332 MessageManager::getInstance()->sendMessage( MSGID_CHATMESSAGE, buf, message.length()+3*INTSIZE, RT_ALL_NOT_ME, 0, MP_HIGHBANDWIDTH ); 333 325 334 326 335 delete [] buf; -
trunk/src/lib/network/network_game_manager.h
r8623 r8708 65 65 void tick( float ds ); 66 66 67 void sendChatMessage( const std::string & message, int messageType , int userId = -1);67 void sendChatMessage( const std::string & message, int messageType ); 68 68 69 69 private: -
trunk/src/lib/network/network_manager.cc
r8228 r8708 144 144 this->elapsedTime = 0.0f; 145 145 146 if ( networkStream->isActive() )146 // if ( networkStream->isActive() ) 147 147 networkStream->processData(); 148 148 -
trunk/src/lib/network/player_stats.cc
r8623 r8708 95 95 this->setPlayableUniqueId( this->playableUniqueId ); 96 96 97 PRINTF(0)("uniqueID changed %d %d %d\n", userId, getHostID(), getUniqueID());97 PRINTF(0)("uniqueID changed %d %d %d\n", userId, SharedNetworkData::getInstance()->getHostID(), getUniqueID()); 98 98 } 99 99 … … 155 155 } 156 156 157 if ( this->playable && userId == getHostID() )157 if ( this->playable && userId == SharedNetworkData::getInstance()->getHostID() ) 158 158 { 159 159 State::getPlayer()->setPlayable( this->playable ); -
trunk/src/lib/network/synchronizeable.cc
r8623 r8708 38 38 this->setClassID(CL_SYNCHRONIZEABLE, "Synchronizeable"); 39 39 this->owner = 0; 40 this->hostID = SharedNetworkData::getInstance()->getHostID(); 41 this->setIsServer(this->hostID == 0); 40 this->setIsServer(SharedNetworkData::getInstance()->getHostID() == 0); 42 41 this->uniqueID = NET_UID_UNASSIGNED; 43 42 this->networkStream = NULL; … … 222 221 hasPermission = ( 223 222 this->isServer() && (*it)->checkPermission( PERMISSION_SERVER ) || 224 this->owner == this->hostID&& (*it)->checkPermission( PERMISSION_OWNER ) ||223 this->owner == SharedNetworkData::getInstance()->getHostID() && (*it)->checkPermission( PERMISSION_OWNER ) || 225 224 this->isServer() && this->owner != userId && (*it)->checkPermission( PERMISSION_OWNER ) || 226 225 (*it)->checkPermission( PERMISSION_ALL ) … … 345 344 (*it)->checkPermission( PERMISSION_SERVER ) && networkStream->isUserServer( userId ) || 346 345 (*it)->checkPermission( PERMISSION_OWNER ) && this->owner == userId || 347 networkStream->isUserServer( userId ) && this->owner != getHostID() && (*it)->checkPermission( PERMISSION_OWNER ) ||346 networkStream->isUserServer( userId ) && this->owner != SharedNetworkData::getInstance()->getHostID() && (*it)->checkPermission( PERMISSION_OWNER ) || 348 347 (*it)->checkPermission( PERMISSION_ALL ) 349 348 ) -
trunk/src/lib/network/synchronizeable.h
r8068 r8708 67 67 inline void setUniqueID( int id ){ uniqueID = id; } 68 68 inline int getUniqueID() const { return uniqueID; } 69 inline int getHostID() { return this->hostID; }70 69 71 70 inline int getOwner(){ return owner; } … … 89 88 int mLeafClassId; //!< store leafClassId to send via states 90 89 int owner; //!< hostId of owner ( 0 if none / server ) 91 int hostID; //!< my own host id92 90 bool bSynchronize; //!< do we need beeing synchronized? 93 91 -
trunk/src/util/multiplayer_team_deathmatch.cc
r8623 r8708 43 43 44 44 #include "story_entity.h" 45 46 #include "shell_command.h" 45 47 46 48 … … 80 82 81 83 subscribeEvent( ES_GAME, SDLK_o ); 84 subscribeEvent( ES_GAME, SDLK_TAB ); 85 86 this->notifier = new OrxGui::GLGuiNotifier(); 87 this->notifier->show(); 88 this->notifier->setAbsCoor2D(5, 30); 89 this->notifier->setFadeAge( 6.0 ); 90 this->notifier->setHideAge( 8.0 ); 91 this->input = new OrxGui::GLGuiInputLine(); 92 this->input->setAbsCoor2D(180, 5); 93 this->input->connect(SIGNAL(input, enterPushed), this, SLOT(MultiplayerTeamDeathmatch, onInputEnter)); 82 94 } 83 95 … … 91 103 92 104 unsubscribeEvent( ES_GAME, SDLK_o ); 105 unsubscribeEvent( ES_GAME, SDLK_TAB ); 106 107 if ( this->notifier ) 108 { 109 delete this->notifier; 110 this->notifier = NULL; 111 } 112 113 if ( this->input ) 114 { 115 delete this->input; 116 this->input = NULL; 117 } 93 118 } 94 119 … … 539 564 this->bShowTeamChange = true; 540 565 } 566 else if ( event.type == SDLK_TAB ) 567 { 568 if ( !event.bPressed ) 569 { 570 EventHandler::getInstance()->pushState( ES_MENU ); 571 OrxGui::GLGuiHandler::getInstance()->activateCursor(); 572 OrxGui::GLGuiHandler::getInstance()->deactivateCursor(); 573 input->show(); 574 input->giveFocus(); 575 input->setText("say "); 576 } 577 } 541 578 } 542 579 … … 563 600 } 564 601 565 PRINTF(0)("CHATMESSAGE %s: %s\n", name.c_str(), message.c_str() ); 566 } 567 568 569 570 602 PRINTF(0)("CHATMESSAGE %s (%d): %s\n", name.c_str(), userId, message.c_str() ); 603 notifier->pushNotifyMessage(name + ": " + message); 604 } 605 606 void MultiplayerTeamDeathmatch::onInputEnter( const std::string & text ) 607 { 608 EventHandler::getInstance()->popState(); 609 input->breakFocus(); 610 input->hide(); 611 input->setText(""); 612 613 std::string command = text; 614 615 //HACK insert " in say commands so user doesn't have to type them 616 if ( command.length() >= 4 && command[0] == 's' && command[1] == 'a' && command[2] == 'y' && command[3] == ' ' ) 617 { 618 command.insert( 4, "\"" ); 619 command = command + "\""; 620 } 621 622 OrxShell::ShellCommand::execute( command ); 623 } 624 625 626 627 -
trunk/src/util/multiplayer_team_deathmatch.h
r8623 r8708 13 13 14 14 #include "glgui.h" 15 #include "specials/glgui_notifier.h" 15 16 16 17 class TiXmlElement; … … 82 83 OrxGui::GLGuiBox* box; 83 84 85 OrxGui::GLGuiNotifier* notifier; 86 OrxGui::GLGuiInputLine* input; 87 84 88 void calculateTeamScore(); 85 89 void nextGameState(); … … 94 98 void onButtonCancel(); 95 99 void onButtonExit(); 100 101 void onInputEnter( const std::string & text ); 96 102 }; 97 103 -
trunk/src/world_entities/space_ships/space_ship.cc
r8228 r8708 33 33 34 34 #include "network_game_manager.h" 35 #include "shared_network_data.h" 35 36 36 37 #include "power_ups/weapon_power_up.h" … … 326 327 Playable::tick(time); 327 328 328 if( ( xMouse != 0 || yMouse != 0 ) && this->getOwner() == this->getHostID() )329 if( ( xMouse != 0 || yMouse != 0 ) && this->getOwner() == SharedNetworkData::getInstance()->getHostID() ) 329 330 { 330 331 if (xMouse > controlVelocityX) xMouse = controlVelocityX; -
trunk/src/world_entities/spectator.cc
r8228 r8708 20 20 #include "key_mapper.h" 21 21 22 #include "shared_network_data.h" 22 23 23 24 CREATE_FACTORY(Spectator, CL_SPECTATOR); … … 161 162 Playable::tick( time ); 162 163 163 if( ( xMouse != 0 || yMouse != 0 ) && this->getOwner() == this->getHostID() )164 if( ( xMouse != 0 || yMouse != 0 ) && this->getOwner() == SharedNetworkData::getInstance()->getHostID() ) 164 165 { 165 166 xMouse *= time / 10;
Note: See TracChangeset
for help on using the changeset viewer.