Exemple #1
0
/*
================
sdProficiencyTable::ReadNetworkState
================
*/
void sdProficiencyTable::ReadNetworkState( const sdNetworkData& baseData, sdNetworkData& newData, const idBitMsg& msg ) const {
	if ( msg.ReadBool() ) {
		for ( int i = 0; i < points.Num(); i++ ) {
			newData.points[ i ] = msg.ReadDeltaFloat( baseData.points[ i ] );
		}
	} else {
		for ( int i = 0; i < points.Num(); i++ ) {
			newData.points[ i ] = baseData.points[ i ];
		}
	}

	if ( msg.ReadBool() ) {
		for ( int i = 0; i < basePoints.Num(); i++ ) {
			newData.basePoints[ i ] = msg.ReadDeltaFloat( baseData.basePoints[ i ] );
		}
	} else {
		for ( int i = 0; i < basePoints.Num(); i++ ) {
			newData.basePoints[ i ] = baseData.basePoints[ i ];
		}
	}

	if ( msg.ReadBool() ) {
		for ( int i = 0; i < points.Num(); i++ ) {
			newData.spawnLevels[ i ] = msg.ReadDeltaLong( baseData.spawnLevels[ i ] );
		}
	} else {
		for ( int i = 0; i < points.Num(); i++ ) {
			newData.spawnLevels[ i ] = baseData.spawnLevels[ i ];
		}
	}

	if ( !baseData.fixedRank ) {
		newData.fixedRank = msg.ReadBool();
		if ( newData.fixedRank ) {
			newData.fixedRankIndex = msg.ReadLong();
		} else {
			newData.fixedRankIndex = -1;
		}
	} else {
		newData.fixedRank = true;
		newData.fixedRankIndex = baseData.fixedRankIndex;
	}
}
/*
========================
idLobby::HandleHeadsetStateChange
========================
*/
void idLobby::HandleHeadsetStateChange( int fromPeer, idBitMsg & msg ) {
	int userCount = msg.ReadLong();
	
	for ( int i = 0; i < userCount; ++i ) {
		lobbyUserID_t lobbyUserID;
		lobbyUserID.ReadFromMsg( msg );
		bool state = msg.ReadBool();
		
		int talkerIndex = sessionCB->GetVoiceChat()->FindTalkerByUserId( lobbyUserID, lobbyType );
		sessionCB->GetVoiceChat()->SetHeadsetState( talkerIndex, state );

		idLib::Printf( "User %d headset status: %d\n", talkerIndex, state );

		// If we are the host, let the other clients know about the headset state of this peer
		if ( IsHost() ) {

			// We should not be receiving a message with a user count > 1 if we are the host
			assert( userCount == 1 );

			byte buffer[ idPacketProcessor::MAX_MSG_SIZE ];
			idBitMsg outMsg( buffer, sizeof( buffer ) );
			outMsg.WriteLong( 1 );
			lobbyUserID.WriteToMsg( outMsg );
			outMsg.WriteBool( state );

			for ( int j = 0; j < peers.Num(); ++j ) {
				// Don't send this to the player that we just received the message from
				if ( !peers[ j ].IsConnected() || j == fromPeer ) {
					continue;
				}

				QueueReliableMessage( j, RELIABLE_HEADSET_STATE, outMsg.GetReadData(), outMsg.GetSize() );
			}
		}
	}
}
/*
================
idGameLocal::ServerProcessReliableMessage
================
*/
void idGameLocal::ServerProcessReliableMessage( int clientNum, int type, const idBitMsg& msg )
{
	if( clientNum < 0 )
	{
		return;
	}
	switch( type )
	{
		case GAME_RELIABLE_MESSAGE_CHAT:
		case GAME_RELIABLE_MESSAGE_TCHAT:
		{
			char name[128];
			char text[128];
			
			msg.ReadString( name, sizeof( name ) );
			msg.ReadString( text, sizeof( text ) );
			
			mpGame.ProcessChatMessage( clientNum, type == GAME_RELIABLE_MESSAGE_TCHAT, name, text, NULL );
			break;
		}
		case GAME_RELIABLE_MESSAGE_VCHAT:
		{
			int index = msg.ReadLong();
			bool team = msg.ReadBits( 1 ) != 0;
			mpGame.ProcessVoiceChat( clientNum, team, index );
			break;
		}
		case GAME_RELIABLE_MESSAGE_DROPWEAPON:
		{
			mpGame.DropWeapon( clientNum );
			break;
		}
		case GAME_RELIABLE_MESSAGE_EVENT:
		{
			// allocate new event
			entityNetEvent_t* event = eventQueue.Alloc();
			eventQueue.Enqueue( event, idEventQueue::OUTOFORDER_DROP );
			
			event->spawnId = msg.ReadBits( 32 );
			event->event = msg.ReadByte();
			event->time = msg.ReadLong();
			
			event->paramsSize = msg.ReadBits( idMath::BitsForInteger( MAX_EVENT_PARAM_SIZE ) );
			if( event->paramsSize )
			{
				if( event->paramsSize > MAX_EVENT_PARAM_SIZE )
				{
					NetworkEventWarning( event, "invalid param size" );
					return;
				}
				msg.ReadByteAlign();
				msg.ReadData( event->paramsBuf, event->paramsSize );
			}
			break;
		}
		case GAME_RELIABLE_MESSAGE_SPECTATE:
		{
			bool spec = msg.ReadBool();
			idPlayer* player = GetClientByNum( clientNum );
			if( serverInfo.GetBool( "si_spectators" ) )
			{
				// never let spectators go back to game while sudden death is on
				if( mpGame.GetGameState() == idMultiplayerGame::SUDDENDEATH && !spec && player->wantSpectate )
				{
					// Don't allow the change
				}
				else
				{
					if( player->wantSpectate && !spec )
					{
						player->forceRespawn = true;
					}
					player->wantSpectate = spec;
				}
			}
			else
			{
				// If the server turned off si_spectators while a player is spectating, then any spectate message forces the player out of spectate mode
				if( player->wantSpectate )
				{
					player->forceRespawn = true;
				}
				player->wantSpectate = false;
			}
			break;
		}
		case GAME_RELIABLE_MESSAGE_CLIENT_HITSCAN_HIT:
		{
			const int attackerNum = msg.ReadShort();
			const int victimNum = msg.ReadShort();
			idVec3 dir;
			msg.ReadVectorFloat( dir );
			const int damageDefIndex = msg.ReadLong();
			const float damageScale = msg.ReadFloat();
			const int location = msg.ReadLong();
			
			if( gameLocal.entities[victimNum] == NULL )
			{
				break;
			}
			
			if( gameLocal.entities[attackerNum] == NULL )
			{
				break;
			}
			
			idPlayer& victim = static_cast< idPlayer& >( *gameLocal.entities[victimNum] );
			idPlayer& attacker = static_cast< idPlayer& >( *gameLocal.entities[attackerNum] );
			
			if( victim.GetPhysics() == NULL )
			{
				break;
			}
			
			if( attacker.weapon.GetEntity() == NULL )
			{
				break;
			}
			
			if( location == INVALID_JOINT )
			{
				break;
			}
			
			// Line of sight check. As a basic precaution against cheating,
			// the server performs a ray intersection from the client's position
			// to the joint he hit on the target.
			idVec3 muzzleOrigin;
			idMat3 muzzleAxis;
			
			attacker.weapon.GetEntity()->GetProjectileLaunchOriginAndAxis( muzzleOrigin, muzzleAxis );
			
			idVec3 targetLocation = victim.GetRenderEntity()->origin + victim.GetRenderEntity()->joints[location].ToVec3() * victim.GetRenderEntity()->axis;
			
			trace_t tr;
			gameLocal.clip.Translation( tr, muzzleOrigin, targetLocation, NULL, mat3_identity, MASK_SHOT_RENDERMODEL, &attacker );
			
			idEntity* hitEnt = gameLocal.entities[ tr.c.entityNum ];
			if( hitEnt != &victim )
			{
				break;
			}
			const idDeclEntityDef* damageDef = static_cast<const idDeclEntityDef*>( declManager->DeclByIndex( DECL_ENTITYDEF, damageDefIndex, false ) );
			
			if( damageDef != NULL )
			{
				victim.Damage( NULL, gameLocal.entities[attackerNum], dir, damageDef->GetName(), damageScale, location );
			}
			break;
		}
		default:
		{
			Warning( "Unknown reliable message (%d) from client %d", type, clientNum );
			break;
		}
	}
}
/*
========================
idDedicatedServerSearch::Clear
========================
*/
void idDedicatedServerSearch::HandleQueryAck( lobbyAddress_t& addr, idBitMsg& msg )
{
	bool found = false;
	// Find the server this ack belongs to
	for( int i = 0; i < list.Num(); i++ )
	{
		serverInfoDedicated_t& query = list[i];
		
		
		if( query.addr.Compare( addr ) )
		{
			// Found the server
			found = true;
			
			bool canJoin = msg.ReadBool();
			
			if( !canJoin )
			{
				// If we can't join this server, then remove it
				list.RemoveIndex( i-- );
				break;
			}
			
			query.serverInfo.Read( msg );
			query.connectedPlayers.Clear();
			for( int i = 0; i < query.serverInfo.numPlayers; i++ )
			{
				idStr user;
				msg.ReadString( user );
				query.connectedPlayers.Append( user );
			}
			break;
		}
	}
	
	if( !found )
	{
		bool canJoin = msg.ReadBool();
		if( canJoin )
		{
			serverInfoDedicated_t newServer;
			newServer.addr = addr;
			newServer.serverInfo.Read( msg );
			if( newServer.serverInfo.serverName.IsEmpty() )
			{
				newServer.serverInfo.serverName = addr.ToString();
			}
			newServer.connectedPlayers.Clear();
			for( int i = 0; i < newServer.serverInfo.numPlayers; i++ )
			{
				idStr user;
				msg.ReadString( user );
				newServer.connectedPlayers.Append( user );
			}
			list.Append( newServer );
		}
	}
	
	
	if( callback != NULL )
	{
		callback->Call();
	}
}