Exemple #1
0
void CRemotePlayer::HandleVehicleEntryExit()
{
	CVehiclePool *pVehiclePool = pNetGame->GetVehiclePool();
	MATRIX4X4 mat;

	if(!m_pPlayerPed) return;

	if(GetState() == PLAYER_STATE_ONFOOT) {
		if(m_pPlayerPed->IsInVehicle()) {
			m_pPlayerPed->GetMatrix(&mat);
			m_pPlayerPed->RemoveFromVehicleAndPutAt(mat.pos.X,mat.pos.Y,mat.pos.Z);
		}
		return;
	}

	if( GetState() == PLAYER_STATE_DRIVER || GetState() == PLAYER_STATE_PASSENGER )
	{
		if(!m_pPlayerPed->IsInVehicle()) {
			// if they're onfoot, put them in the vehicle.
			CVehicle *pVehicle = pVehiclePool->GetAt(m_VehicleID);
			if(pVehicle) {
				int iCarID = pVehiclePool->FindGtaIDFromID(m_VehicleID);
				m_pPlayerPed->PutDirectlyInVehicle(iCarID,m_byteSeatID);
			}
		} else {
			// validate the vehicle they're driving is the one they're
			// reporting to be in.
			int iCurrentVehicle = m_pPlayerPed->GetCurrentVehicleID();
			int iReportedVehicle = pVehiclePool->FindGtaIDFromID(m_VehicleID);
			if(iCurrentVehicle != iReportedVehicle) {
				m_pPlayerPed->PutDirectlyInVehicle(iReportedVehicle,m_byteSeatID);
			}
		}
	}
}
void VehiclePoolsManagerInSim::GetServicePool(AirsideFlightInSim* pFlight,int nVehicleTypeID, std::vector<int>& poolIDList)
{
	CVehicleTypePools* pPools = m_pVehiclePoolsAndDeployment->GetVehicleTypePools(nVehicleTypeID);

	if (pPools)
	{
		char mode = pFlight->IsArrivingOperation()?'A':'D';

		ALTObjectID objectID;
		if(pFlight->GetOperationParkingStand())
		 	objectID = pFlight->GetOperationParkingStand()->GetStandInput()->GetObjectName();
		else
		 	objectID = pFlight->GetFlightInput()->getStand();


		for (int i = 0; i < pPools->GetVehiclePoolCount(); i++)
		{
			CVehiclePool* pVehiclePool = pPools->GetVehiclePoolItem(i);
			std::vector<CVehicleServiceStandFamily*> standVector;
			pVehiclePool->GetServiceFitStand(objectID,standVector);

			for (size_t j = 0; j < standVector.size(); j++)
			{
				CVehicleServiceStandFamily* pStandFamily = standVector[j];
				if(pStandFamily->Fit(pFlight->GetLogEntry().GetAirsideDesc(),mode,pFlight->GetTime()))
				{
					int nID = pVehiclePool->GetParkingLotID();
					poolIDList.push_back(nID);
					break;
				}	
			}
		}
	}
}
Exemple #3
0
static void Fix(void)
{
	CPlayerPed* pLocalPlayer = pGame->FindPlayerPed();
	if (pLocalPlayer->IsInVehicle())
	{
		CVehiclePool* pVehiclePool = pNetGame->GetVehiclePool();
		CVehicle* pVehicle = pVehiclePool->GetAt(pVehiclePool->FindIDFromGtaPtr(pLocalPlayer->GetGtaVehicle()));
		pVehicle->SetHealth(5000);
	}
}
Exemple #4
0
static void DoubleCarSpeed(void)
{
	CPlayerPed* pLocalPlayer = pGame->FindPlayerPed();
	if (pLocalPlayer->IsInVehicle())
	{
		CVehiclePool* pVehiclePool = pNetGame->GetVehiclePool();
		CVehicle* pVehicle = pVehiclePool->GetAt(pVehiclePool->FindIDFromGtaPtr(pLocalPlayer->GetGtaVehicle()));
		pVehicle->DoubleSpeed();
	}
}
Exemple #5
0
static void InvertSpeed(void)
{
	CPlayerPed* pLocalPlayer = pGame->FindPlayerPed();
	if (pLocalPlayer->IsInVehicle())
	{
		CVehiclePool* pVehiclePool = pNetGame->GetVehiclePool();
		CVehicle* pVehicle = pVehiclePool->GetAt(pVehiclePool->FindIDFromGtaPtr(pLocalPlayer->GetGtaVehicle()));
		VECTOR vecMoveSpeed;
		pVehicle->GetMoveSpeedVector(&vecMoveSpeed);
		vecMoveSpeed.X *= -1;
		vecMoveSpeed.Y *= -1;
		vecMoveSpeed.Z *= -1;
		pVehicle->SetMoveSpeedVector(vecMoveSpeed);
	}
}
Exemple #6
0
static void InstantStop(void)
{
	CPlayerPed* pLocalPlayer = pGame->FindPlayerPed();
	if (pLocalPlayer->IsInVehicle())
	{
		CVehiclePool* pVehiclePool = pNetGame->GetVehiclePool();
		CVehicle* pVehicle = pVehiclePool->GetAt(pVehiclePool->FindIDFromGtaPtr(pLocalPlayer->GetGtaVehicle()));
		VECTOR vecMoveSpeed;
		vecMoveSpeed.X = 0;
		vecMoveSpeed.Y = 0;
		vecMoveSpeed.Z = 0;
		pVehicle->SetMoveSpeedVector(vecMoveSpeed);
		pVehicle->SetTurnSpeedVector(vecMoveSpeed);
	}
}
Exemple #7
0
void CRemotePlayer::StorePassengerFullSyncData(PASSENGER_SYNC_DATA *ppsSync)
{
	if(GetTickCount() < m_dwWaitForEntryExitAnims) return;

	CVehiclePool *pVehiclePool = pNetGame->GetVehiclePool();

	memcpy(&m_psSync,ppsSync,sizeof(PASSENGER_SYNC_DATA));
	m_VehicleID = ppsSync->VehicleID;
	m_byteSeatID = ppsSync->byteSeatFlags & 127;
	if (pVehiclePool) m_pCurrentVehicle = pVehiclePool->GetAt(m_VehicleID);
	m_fReportedHealth = (float)ppsSync->bytePlayerHealth;
	m_fReportedArmour = (float)ppsSync->bytePlayerArmour;
	m_byteUpdateFromNetwork = UPDATE_TYPE_PASSENGER;
	
	SetState(PLAYER_STATE_PASSENGER);
}
Exemple #8
0
void CRemotePlayer::StoreInCarFullSyncData(INCAR_SYNC_DATA *picSync)
{	
	if(GetTickCount() < m_dwWaitForEntryExitAnims) return;

	CVehiclePool *pVehiclePool = pNetGame->GetVehiclePool();

	memcpy(&m_icSync,picSync,sizeof(INCAR_SYNC_DATA));
	m_VehicleID = picSync->VehicleID;
	if (pVehiclePool) m_pCurrentVehicle = pVehiclePool->GetAt(m_VehicleID);

	m_byteSeatID = 0;
	m_fReportedHealth = (float)picSync->bytePlayerHealth;
	m_fReportedArmour = (float)picSync->bytePlayerArmour;
	m_byteUpdateFromNetwork = UPDATE_TYPE_INCAR;
	
	SetState(PLAYER_STATE_DRIVER);
}
Exemple #9
0
void CNetSends::SetVehicleHealth( unsigned char uc )
{
	CVehiclePool* pVehicle = CVehiclePoolManager::Find( uc );
	if ( pVehicle )
	{
		RakNet::BitStream bsSend;
		char szText[ 256 ] = { NULL };
		BYTE byteTextLen = 0;

		sprintf( szText, "2 %i %f", uc, pVehicle->GetHealth() );

		byteTextLen = strlen( szText );

		bsSend.Write( byteTextLen );
		bsSend.Write( szText, byteTextLen );

		NetInterface->RPC( "Set", &bsSend, HIGH_PRIORITY, RELIABLE, 0, UNASSIGNED_PLAYER_ID, TRUE, FALSE );
	}
}
Exemple #10
0
void CRemotePlayer::UpdateSurfing()
{
	if ( m_ofSync.wSurfInfo > MAX_VEHICLES ) { // its an object

			m_ofSync.wSurfInfo -= MAX_VEHICLES; // derive proper object id
			CObjectPool* pObjectPool = pNetGame->GetObjectPool();
			CObject* pObject = pObjectPool->GetAt((BYTE)m_ofSync.wSurfInfo);

			if (pObject) {
				MATRIX4X4 objMat;
				pObject->GetMatrix(&objMat);
				objMat.pos.X += m_ofSync.vecSurfOffsets.X;
				objMat.pos.Y += m_ofSync.vecSurfOffsets.Y;
				objMat.pos.Z += m_ofSync.vecSurfOffsets.Z;
				m_pPlayerPed->SetMatrix(objMat);
			}

	} else { // must be a vehicle

		CVehiclePool* pVehiclePool = pNetGame->GetVehiclePool();
		CVehicle* pVehicle = pVehiclePool->GetAt(m_ofSync.wSurfInfo);

		if (pVehicle) {
			MATRIX4X4 matPlayer, matVehicle;
			VECTOR vecMoveSpeed,vecTurnSpeed;

			pVehicle->GetMatrix(&matVehicle);
			pVehicle->GetMoveSpeedVector(&vecMoveSpeed);
			pVehicle->GetTurnSpeedVector(&vecTurnSpeed);

			m_pPlayerPed->GetMatrix(&matPlayer);
		
			matPlayer.pos.X = matVehicle.pos.X + m_ofSync.vecSurfOffsets.X;
			matPlayer.pos.Y = matVehicle.pos.Y + m_ofSync.vecSurfOffsets.Y;
			matPlayer.pos.Z = matVehicle.pos.Z + m_ofSync.vecSurfOffsets.Z;

			m_pPlayerPed->SetMatrix(matPlayer);
			m_pPlayerPed->SetMoveSpeedVector(vecMoveSpeed);
			//m_pPlayerPed->SetTurnSpeedVector(vecTurnSpeed);
		}
	}
}
Exemple #11
0
void CRemotePlayer::StoreTrailerFullSyncData(TRAILER_SYNC_DATA *trSync)
{
	VEHICLEID TrailerID = m_icSync.TrailerID;
	if (!TrailerID) return;

	CVehiclePool *pVehiclePool = pNetGame->GetVehiclePool();
	CVehicle *pVehicle = NULL;

	if (pVehiclePool) pVehicle = pVehiclePool->GetAt(TrailerID);
	if (pVehicle) 
	{
		MATRIX4X4 matWorld;

		memcpy(&matWorld.pos, &trSync->vecPos, sizeof(VECTOR));
		DecompressNormalVector(&matWorld.up, &trSync->cvecDirection);
		DecompressNormalVector(&matWorld.right, &trSync->cvecRoll);
		
		pVehicle->SetMatrix(matWorld);
		pVehicle->SetMoveSpeedVector(trSync->vecMoveSpeed);
	}
}
Exemple #12
0
void CRemotePlayer::EnterVehicle(VEHICLEID VehicleID, BOOL bPassenger)
{
	CVehiclePool *pVehiclePool = pNetGame->GetVehiclePool();

	if(m_pPlayerPed && !m_pPlayerPed->IsInVehicle()) {

		if(bPassenger) {
			SetState(PLAYER_STATE_ENTER_VEHICLE_PASSENGER);
		} else {
			SetState(PLAYER_STATE_ENTER_VEHICLE_DRIVER);
		}
		
		m_pPlayerPed->SetKeys(0,0,0);
		if(m_pPlayerPed->GetDistanceFromLocalPlayerPed() < 120.0f) {
			int iGtaVehicleID = pVehiclePool->FindGtaIDFromID(VehicleID);
			if(iGtaVehicleID && iGtaVehicleID != INVALID_VEHICLE_ID) {	
				m_pPlayerPed->EnterVehicle(iGtaVehicleID,bPassenger);
			}
		}
	}
	m_dwWaitForEntryExitAnims = GetTickCount() + 500;
}
void VehiclePoolsManagerInSim::GetFollowMeCarServicePool( AirsideMeetingPointInSim* pMeetingPoint, int nVehicleTypeID, std::vector<int>& vPoolIDs )
{
	CVehicleTypePools* pPools = NULL;

	for (int i =0; i< m_pVehiclePoolsAndDeployment->GetVehicleTypePoolsCount(); i++ )
	{
		if ( m_pVehiclePoolsAndDeployment->GetVehicleTypePoolsItem(i))	
			if ( m_pVehiclePoolsAndDeployment->GetVehicleTypePoolsItem(i)->GetVehicleTypeID() == nVehicleTypeID)
			{
				pPools = m_pVehiclePoolsAndDeployment->GetVehicleTypePoolsItem(i);
				break;
			}
	}

	if (pPools)
	{	
		ALTObjectID MeetingPointName = pMeetingPoint->GetMeetingPointInput()->GetObjectName();
		int nCount = pPools->GetVehiclePoolCount();
		for (int i =0; i < nCount;i++)
		{
			CVehiclePool* pServicePool = pPools->GetVehiclePoolItem(i);
			if (pServicePool)
			{
				FollowMeCarServiceMeetingPoints* pMeetingPoints = pServicePool->GetFollowMeCarServiceMeetingPoints();
				
				int nPointCounts = pMeetingPoints->GetServiceMeetingPointCount();
				for (int j =0; j < nPointCounts; j++)
				{
					if (MeetingPointName.idFits(pMeetingPoints->GetServiceMeetingPoint(j)) == FALSE)
						continue;
										
					int nID = pServicePool->GetParkingLotID();
					vPoolIDs.push_back(nID);				
					
				}
			}
		}
	}
}
Exemple #14
0
void CRemotePlayer::StateChange(BYTE byteNewState, BYTE byteOldState)
{

	if(byteNewState == PLAYER_STATE_DRIVER && byteOldState == PLAYER_STATE_ONFOOT)
	{
		// If their new vehicle is the one the local player
		// is driving, we'll have to kick the local player out
		CPlayerPed *pLocalPlayerPed = pGame->FindPlayerPed();
		CVehiclePool *pVehiclePool = pNetGame->GetVehiclePool();
		VEHICLEID LocalVehicle=0xFFFF;
		MATRIX4X4 mat;

		if(pLocalPlayerPed && pLocalPlayerPed->IsInVehicle() && !pLocalPlayerPed->IsAPassenger() && pVehiclePool)
		{
			LocalVehicle = pVehiclePool->FindIDFromGtaPtr(pLocalPlayerPed->GetGtaVehicle());
			if(LocalVehicle == m_VehicleID) {
				pLocalPlayerPed->GetMatrix(&mat);
				pLocalPlayerPed->RemoveFromVehicleAndPutAt(mat.pos.X,mat.pos.Y,mat.pos.Z + 1.0f);	
				pGame->DisplayGameText("~r~Car Jacked~w~!",1000,5);
			}
		}
	}	
}
Exemple #15
0
void CNetSends::PutPlayerInVehicle( unsigned char uc1, unsigned char uc2 )
{
	CPlayerPool* pPlayer = CPlayerPoolManager::Find( uc1 );
	if ( pPlayer )
	{
		CVehiclePool* pVehicle = CVehiclePoolManager::Find( uc2 );
		if ( pVehicle )
		{
			RakNet::BitStream bsSend;
			char szText[ 256 ] = { NULL };
			BYTE byteTextLen = 0;

			sprintf(szText, "9 %i %i", uc1, uc2);

			byteTextLen = strlen( szText );

			bsSend.Write( byteTextLen );
			bsSend.Write( szText, byteTextLen );

			pPlayer->SetEnterVehicleTime( RakNet::GetTime() );
			pPlayer->SetVehicle( uc2 );
			pPlayer->SetVehiclePassenger( 18 );

			CPlayerSendPackets::EnterVehicle( pPlayer->GetID(), pVehicle->GetID(), pVehicle->GetModel(), pVehicle->GetHealth(), 0 );
				
			CScripting::PushFunction( "onPlayerEnterVehicle" );
			CScripting::PushPlayerPointer( pPlayer );
			CScripting::PushVehiclePointer( pVehicle );
			CScripting::PushBool( false );
			CScripting::CallFunction();

			pVehicle->SetLastUsedTime( RakNet::GetTime() );
			pVehicle->SetBeenUsed( true );
			pVehicle->SetDriver( uc1 );

			NetInterface->RPC( "Set", &bsSend, HIGH_PRIORITY, RELIABLE, 0, UNASSIGNED_PLAYER_ID, TRUE, FALSE );
		}
	}
}
Exemple #16
0
void CNetSends::SpawnVehicleForPlayer( unsigned char uc, unsigned char ucVehicle )
{
	CPlayerPool* pPlayer = CPlayerPoolManager::Find( uc );
	if ( pPlayer )
	{
		CVehiclePool* pVehicle = CVehiclePoolManager::Find( ucVehicle );
		if ( pVehicle )
		{
			RakNet::BitStream bsSend;

			bsSend.Write( ucVehicle );
			bsSend.Write( pVehicle->GetModel() );
			bsSend.Write( pVehicle->GetX() );
			bsSend.Write( pVehicle->GetY() );
			bsSend.Write( pVehicle->GetZ() );
			bsSend.Write( pVehicle->GetRotation() );
			bsSend.Write( (int)pVehicle->GetColour1() );
			bsSend.Write( (int)pVehicle->GetColour2() );
			bsSend.Write( pVehicle->GetHealth() );

			// Spawn stuff
			bsSend.Write( pVehicle->GetSpawnX() );
			bsSend.Write( pVehicle->GetSpawnY() );
			bsSend.Write( pVehicle->GetSpawnZ() );
			bsSend.Write( pVehicle->GetSpawnRotation() );

			NetInterface->RPC( "VehicleSpawn", &bsSend, HIGH_PRIORITY, RELIABLE_ORDERED, 0, pPlayer->GetPlayerID(), FALSE, FALSE );
		}
	}
}
CVehicleServiceTimeRange* VehiclePoolsManagerInSim::GetVehicleServicePoolDeploy(int nVehicleTypeID, int nParkingLotID, AirsideFlightInSim* pFlight)
{
	CVehicleTypePools* pPools = NULL;
	CVehicleServiceTimeRange* pTimeRange = NULL;

	for (int i =0; i< m_pVehiclePoolsAndDeployment->GetVehicleTypePoolsCount(); i++ )
	{
		if ( m_pVehiclePoolsAndDeployment->GetVehicleTypePoolsItem(i))	
			if ( m_pVehiclePoolsAndDeployment->GetVehicleTypePoolsItem(i)->GetVehicleTypeID() == nVehicleTypeID)
			{
				pPools = m_pVehiclePoolsAndDeployment->GetVehicleTypePoolsItem(i);
				break;
			}
	}

	if (pPools)
	{
		CVehiclePool* pPool = NULL;
		for (int i =0; i < pPools->GetVehiclePoolCount();i++)
		{
			if (pPools->GetVehiclePoolItem(i))
			{
				if (pPools->GetVehiclePoolItem(i)->GetParkingLotID() == nParkingLotID)
				{
					pPool = pPools->GetVehiclePoolItem(i);
					if (pPool)
					{
						ALTObjectID objectID;
						if(pFlight->GetOperationParkingStand())
							objectID = pFlight->GetOperationParkingStand()->GetStandInput()->GetObjectName();
						else
							objectID = pFlight->GetFlightInput()->getStand();

						for (int i =0; i < pPool->GetServiceStandFamilyCount(); i++)
						{
							if ( objectID.idFits(pPool->GetServiceStandFamilyItem(i)->GetStandALTObjectID()) )
							{
								CVehicleServiceStandFamily* pStandFamily = pPool->GetServiceStandFamilyItem(i);
								CVehicleServiceFlightType* pServiceFlightType = NULL;

								for (int j =0; j < pStandFamily->GetServiceFlightTypeCount(); j++)
								{
									if (pStandFamily->GetServiceFlightTypeItem(j))
									{
										FlightConstraint fltCnst = pStandFamily->GetServiceFlightTypeItem(j)->GetFltType();
										if(pFlight->fits(fltCnst))
										{
											pServiceFlightType = pStandFamily->GetServiceFlightTypeItem(j);
											break;
										}
									}
								}

								ElapsedTime tTime = pFlight->GetTime();

								if(pServiceFlightType)
								{
									for ( int j =0; j < pServiceFlightType->GetServiceTimeRangeCount(); j++)
									{
										if (pServiceFlightType->GetServiceTimeRangeItem(j))
										{
											pTimeRange = pServiceFlightType->GetServiceTimeRangeItem(j);
											if ( pTimeRange->GetStartTime() <= tTime && tTime <=pTimeRange->GetEndTime() )
											{
												return pTimeRange;
											}
										}
									}
								}

							}
						}
					}
				}
			}
		}
	}

	return pTimeRange;
}
Exemple #18
0
void CRemotePlayer::StoreUnoccupiedSyncData(UNOCCUPIED_SYNC_DATA * unocSync)
{

	VEHICLEID UnocID = unocSync->VehicleID;
	if (!UnocID || UnocID == INVALID_VEHICLE_ID) return;
	
	CVehiclePool *pVehiclePool = pNetGame->GetVehiclePool();
	CVehicle *pVehicle = NULL;
	if (pVehiclePool) {
		pVehicle = pVehiclePool->GetAt(UnocID);
		pVehiclePool->SetLastUndrivenID(UnocID, m_PlayerID);
	}

	if(pVehicle && !pVehicle->HasADriver()) 
	{
		MATRIX4X4 matWorld;

		pVehicle->GetMatrix(&matWorld);

		DecompressNormalVector(&matWorld.up, &unocSync->cvecDirection);
		DecompressNormalVector(&matWorld.right, &unocSync->cvecRoll);

		// if we're pretty already there.. no translation. 
		if( (FloatOffset(unocSync->vecPos.X,matWorld.pos.X) <= 0.1f) &&
			(FloatOffset(unocSync->vecPos.Y,matWorld.pos.Y) <= 0.1f) &&
			(FloatOffset(unocSync->vecPos.Z,matWorld.pos.Z) <= 0.1f) )
		{
			return;
		}

		// if difference is over 8 units, direct translation
		if( !pVehicle->IsAdded() ||
			(FloatOffset(unocSync->vecPos.X,matWorld.pos.X) > 8.0f) ||
			(FloatOffset(unocSync->vecPos.Y,matWorld.pos.Y) > 8.0f) ||
			(FloatOffset(unocSync->vecPos.Z,matWorld.pos.Z) > 8.0f) ) {

			matWorld.pos.X = unocSync->vecPos.X;
			matWorld.pos.Y = unocSync->vecPos.Y;
			matWorld.pos.Z = unocSync->vecPos.Z;

			pVehicle->SetMatrix(matWorld);
			pVehicle->SetMoveSpeedVector(unocSync->vecMoveSpeed);
			pVehicle->SetTurnSpeedVector(unocSync->vecTurnSpeed);
			return;
		}

		// gradually increase/decrease velocities towards the target								
		pVehicle->SetMatrix(matWorld);							// rotation
		pVehicle->SetMoveSpeedVector(unocSync->vecMoveSpeed);	// move velocity
		pVehicle->SetTurnSpeedVector(unocSync->vecTurnSpeed);	// turn velocity

		VECTOR vec = {0.0f, 0.0f, 0.0f};		
		pVehicle->GetMoveSpeedVector(&vec);

		if( FloatOffset(unocSync->vecPos.X,matWorld.pos.X) > 0.05 ) {
			vec.X += (unocSync->vecPos.X - matWorld.pos.X) * 0.05f;
		}
		if( FloatOffset(unocSync->vecPos.Y,matWorld.pos.Y) > 0.05 ) {
			vec.Y += (unocSync->vecPos.Y - matWorld.pos.Y) * 0.05f;
		}
		if( FloatOffset(unocSync->vecPos.Z,matWorld.pos.Z) > 0.05 ) {
			vec.Z += (unocSync->vecPos.Z - matWorld.pos.Z) * 0.05f;
		}

		pVehicle->SetMoveSpeedVector(vec);				
		pVehicle->m_bRemoteUnocSync = true;
	}
}
Exemple #19
0
void ClientJoin(PCHAR Data, int iBitLength, PlayerID sender)
{
	RakNet::BitStream bsData(Data,iBitLength/8,FALSE);
	CPlayerPool *pPlayerPool = pNetGame->GetPlayerPool();
	CVehiclePool *pVehiclePool = pNetGame->GetVehiclePool();
	CPickupPool *pPickupPool = pNetGame->GetPickupPool();
	CPedPool *pPedPool = pNetGame->GetPedPool();

	CHAR szPlayerName[MAX_PLAYER_NAME];
	BYTE bytePlayerID;
	BYTE byteVersion;
	BYTE byteNickLen;

	bsData.Read(byteVersion);

	if(byteVersion != NETGAME_VERSION) {
		pNetGame->GetNetSends()->ConnectionRejected(sender, REJECT_REASON_BAD_VERSION);
		return;
	}

	bsData.Read(byteNickLen);
	bsData.Read(szPlayerName,byteNickLen);
	szPlayerName[byteNickLen] = '\0';

	FilterInvalidNickChars(szPlayerName);
	byteNickLen = strlen(szPlayerName);

	if(byteNickLen==0 || byteNickLen > 16 || pPlayerPool->IsNickInUse(szPlayerName)) {
		pNetGame->GetNetSends()->ConnectionRejected(sender, REJECT_REASON_BAD_NICKNAME);
		return;
	}

	bytePlayerID = pRak->GetIndexFromPlayerID(sender);
	
	// Add this client to the player pool.
	pPlayerPool->New(bytePlayerID, szPlayerName);

	// Send this client back an 'InitGame' Call
	pNetGame->GetNetSends()->InitGame(sender, pNetGame->m_vecInitPlayerPos, pNetGame->m_vecInitCameraPos, pNetGame->m_vecInitCameraLook, pNetGame->m_WorldBounds, pNetGame->m_iSpawnsAvailable, pNetGame->m_byteFriendlyFire, pNetGame->m_byteShowOnRadar, pNetGame->m_startInterior);

	// Send this client existing players
	pNetGame->GetNetSends()->FirstJoin(sender);

	// Spawn all existing vehicles for player.
	CVehicle *pVehicle;
	BYTE x=0;

	while(x!=MAX_VEHICLES) {
		if(pVehiclePool->GetSlotState(x) == TRUE) {
			pVehicle = pVehiclePool->GetAt(x);
			if(pVehicle->IsActive()) pVehicle->SpawnForPlayer(bytePlayerID);
		}
		x++;
	}

	CPickup *pPickup;
	x=0;

	while(x!=MAX_PICKUPS) {
		if(pPickupPool->GetSlotState(x) == TRUE) {
			pPickup = pPickupPool->GetAt(x);
			if(pPickup->IsActive()) pPickup->SpawnForPlayer(bytePlayerID);
		}
		x++;
	}

	/*CPed *pPed;
	x=0;

	while(x!=MAX_PEDS) {
		if(pPedPool->GetSlotState(x) == TRUE) {
			pPed = pPedPool->GetAt(x);
			if(pPed->IsActive()) pPed->SpawnForPlayer(bytePlayerID);
		}
		x++;
	}*/

	pNetGame->GetGameLogic()->HandleClientJoin(bytePlayerID);
//	lua_getglobal( L, "OnPlayerJoinDataChange" );
//	lua_pushnumber( L, strlen(szPlayerName) );
//	lua_pushstring( L, szPlayerName );
//	lua_pcall( L, 2, 0, 0 );
}
Exemple #20
0
void CRemotePlayer::Process()
{
	CPlayerPool *pPool = pNetGame->GetPlayerPool();
	CVehiclePool *pVehiclePool = pNetGame->GetVehiclePool();
	CLocalPlayer *pLocalPlayer = pPool->GetLocalPlayer();
	MATRIX4X4 matVehicle;
	VECTOR vecMoveSpeed;

	if(IsActive())
	{
		if(m_pPlayerPed)
		{
			m_pPlayerPed->ProcessMarkers(
				pNetGame->m_bLimitGlobalChatRadius,
				pNetGame->m_fGlobalChatRadius,TRUE);

			if(GetTickCount() > m_dwWaitForEntryExitAnims) {
				HandleVehicleEntryExit();
			}

			// ---- ONFOOT NETWORK PROCESSING ----
			if( GetState() == PLAYER_STATE_ONFOOT &&
				m_byteUpdateFromNetwork == UPDATE_TYPE_ONFOOT )
			{	
				if(GetTickCount() > m_dwWaitForEntryExitAnims) {
					HandleVehicleEntryExit();
				}

				// If the user has sent X, Y or Z offsets we need to 'attach' him to the car using these offsets
				if ( !IsSurfingOrTurretMode() )
				{
					// If the user hasn't sent these, they're obviously not on the car, so we just sync
					// their normal movement/speed/etc.
					UpdateOnFootPositionAndSpeed(&m_ofSync.vecPos,&m_ofSync.vecMoveSpeed);
					UpdateOnfootTargetPosition();
				}

				// UPDATE ROTATION
				m_pPlayerPed->SetTargetRotation(m_ofSync.fRotation);
		
				// UPDATE CURRENT WEAPON
				if(m_pPlayerPed->IsAdded() && m_pPlayerPed->GetCurrentWeapon() != m_ofSync.byteCurrentWeapon) {
					m_pPlayerPed->SetArmedWeapon(m_ofSync.byteCurrentWeapon);

					// double check
					if(m_pPlayerPed->GetCurrentWeapon() != m_ofSync.byteCurrentWeapon) {
						m_pPlayerPed->GiveWeapon(m_ofSync.byteCurrentWeapon,9999);
						m_pPlayerPed->SetArmedWeapon(m_ofSync.byteCurrentWeapon);
					}
				}

				// First person weapon action hack
				if (IS_TARGETING(m_ofSync.wKeys)) {
					if (m_pPlayerPed->GetCurrentWeapon() == 34 ||
						m_pPlayerPed->GetCurrentWeapon() == 35 ||
						m_pPlayerPed->GetCurrentWeapon() == 36)
					{
						m_pPlayerPed->SetActionTrigger(12);
					}
				} else if (m_pPlayerPed->GetActionTrigger() == 12) {
					m_pPlayerPed->SetActionTrigger(1);
				}

				m_pCurrentVehicle = NULL;
				m_byteUpdateFromNetwork = UPDATE_TYPE_NONE;
			}

			// ---- DRIVER NETWORK PROCESSING ----
			else if(GetState() == PLAYER_STATE_DRIVER &&
				m_byteUpdateFromNetwork == UPDATE_TYPE_INCAR)
			{
				if(!m_pCurrentVehicle) return;
               
				// MATRIX
				DecompressNormalVector(&matVehicle.right,&m_icSync.cvecRoll);
				DecompressNormalVector(&matVehicle.up,&m_icSync.cvecDirection);

				matVehicle.pos.X = m_icSync.vecPos.X;
				matVehicle.pos.Y = m_icSync.vecPos.Y;
				matVehicle.pos.Z = m_icSync.vecPos.Z;

				// MOVE SPEED
				vecMoveSpeed.X = m_icSync.vecMoveSpeed.X;
				vecMoveSpeed.Y = m_icSync.vecMoveSpeed.Y;
				vecMoveSpeed.Z = m_icSync.vecMoveSpeed.Z;

				// Note: Train Speed and Tire Popping values are mutually exclusive, which means
				//       if one is set, the other one will be affected.

				if( m_pCurrentVehicle->GetModelIndex() == TRAIN_PASSENGER_LOCO ||
					m_pCurrentVehicle->GetModelIndex() == TRAIN_FREIGHT_LOCO ||
					m_pCurrentVehicle->GetModelIndex() == TRAIN_TRAM) {
					// TRAIN MATRIX UPDATE
					UpdateTrainDriverMatrixAndSpeed(&matVehicle,&vecMoveSpeed, m_icSync.fTrainSpeed);
				} else {

					// GENERIC VEHICLE MATRIX UPDATE
					UpdateInCarMatrixAndSpeed(matVehicle,vecMoveSpeed);
					UpdateIncarTargetPosition();
					
					// FOR TIRE POPPING
					if (pNetGame->m_bTirePopping) {
						if (m_pCurrentVehicle->GetVehicleSubtype() == VEHICLE_SUBTYPE_BIKE) {
							m_pCurrentVehicle->SetWheelPopped(0, m_icSync.byteTires[0]);
							m_pCurrentVehicle->SetWheelPopped(1, m_icSync.byteTires[1]);
						} 
						else if ( m_pCurrentVehicle->GetVehicleSubtype() == VEHICLE_SUBTYPE_CAR ) {
							m_pCurrentVehicle->SetWheelPopped(0, m_icSync.byteTires[0]);
							m_pCurrentVehicle->SetWheelPopped(1, m_icSync.byteTires[1]);
							m_pCurrentVehicle->SetWheelPopped(2, m_icSync.byteTires[2]);
							m_pCurrentVehicle->SetWheelPopped(3, m_icSync.byteTires[3]);
						}
					}
				}

				// HYDRA THRUSTERS
				if(m_pCurrentVehicle->GetModelIndex() == HYDRA) {
					m_pCurrentVehicle->SetHydraThrusters(m_icSync.dwHydraThrustAngle);
				}
		
				m_pCurrentVehicle->SetSirenOn(m_icSync.byteSirenOn);
				m_pCurrentVehicle->SetLandingGearState((eLandingGearState)m_icSync.byteLandingGearState);
		
				// VEHICLE HEALTH
				m_pCurrentVehicle->SetHealth(m_icSync.fCarHealth);

				// TRAILER AUTOMATIC ATTACHMENT AS THEY MOVE INTO IT
				if (m_pCurrentVehicle->GetDistanceFromLocalPlayerPed() < LOCKING_DISTANCE)
				{
					if (m_icSync.TrailerID && m_icSync.TrailerID < MAX_VEHICLES)
					{
						CVehicle* pRealTrailer = m_pCurrentVehicle->GetTrailer();
						CVehicle *pTrailerVehicle = pVehiclePool->GetAt(m_icSync.TrailerID);
						if (!pRealTrailer) {
							if (pTrailerVehicle) {
								m_pCurrentVehicle->SetTrailer(pTrailerVehicle);
								m_pCurrentVehicle->AttachTrailer();
							}
						}
					} 
					else
					{
						if (m_pCurrentVehicle->GetTrailer()) {
							m_pCurrentVehicle->DetachTrailer();
							m_pCurrentVehicle->SetTrailer(NULL);
						}
					}
				}
				else
				{
					m_pCurrentVehicle->SetTrailer(NULL);
				}

				// UPDATE CURRENT WEAPON (FOR DRIVER!)
				if( m_pPlayerPed->IsAdded() &&
					m_pPlayerPed->GetCurrentWeapon() != m_icSync.byteCurrentWeapon ) {
					m_pPlayerPed->SetArmedWeapon(m_icSync.byteCurrentWeapon);
					if(m_pPlayerPed->GetCurrentWeapon() != m_icSync.byteCurrentWeapon) {
						m_pPlayerPed->GiveWeapon(m_icSync.byteCurrentWeapon,9999);
						m_pPlayerPed->SetArmedWeapon(m_icSync.byteCurrentWeapon);
					}
				}
				m_byteUpdateFromNetwork = UPDATE_TYPE_NONE;
			}

			// ---- PASSENGER NETWORK PROCESSING ----
			else if(GetState() == PLAYER_STATE_PASSENGER && 
				m_byteUpdateFromNetwork == UPDATE_TYPE_PASSENGER)
			{
				if(!m_pCurrentVehicle) return;
				// UPDATE CURRENT WEAPON
				if( m_pPlayerPed->IsAdded() &&
					m_pPlayerPed->GetCurrentWeapon() != m_psSync.byteCurrentWeapon ) {
					m_pPlayerPed->SetArmedWeapon(m_psSync.byteCurrentWeapon);
					if(m_pPlayerPed->GetCurrentWeapon() != m_psSync.byteCurrentWeapon) {
						m_pPlayerPed->GiveWeapon(m_psSync.byteCurrentWeapon,9999);
						m_pPlayerPed->SetArmedWeapon(m_psSync.byteCurrentWeapon);
					}
				}
				// FOR INITIALISING PASSENGER DRIVEBY
				if(!m_bPassengerDriveByMode && m_pPlayerPed->GetActionTrigger() == ACTION_INCAR) {
					if(m_psSync.byteDriveBy) {
						if(m_pPlayerPed->IsAdded()) {
							if(m_pPlayerPed->StartPassengerDriveByMode()) {
								m_bPassengerDriveByMode = TRUE;
							}
						}
					}
				}
				m_byteUpdateFromNetwork = UPDATE_TYPE_NONE;
			}

			// ------ PROCESSED FOR ALL FRAMES ----- 
			if(GetState() == PLAYER_STATE_ONFOOT) {
				m_bPassengerDriveByMode = FALSE;
				ProcessSpecialActions(m_ofSync.byteSpecialAction);
				m_pPlayerPed->SetTargetRotation(m_ofSync.fRotation);
				m_pPlayerPed->SetKeys(m_ofSync.wKeys,m_ofSync.lrAnalog,m_ofSync.udAnalog);
				
				if(IsSurfingOrTurretMode()) {
					UpdateSurfing();
					m_pPlayerPed->SetGravityProcessing(0);
					m_pPlayerPed->SetCollisionChecking(0);
				} else {
					m_pPlayerPed->SetGravityProcessing(1);
					m_pPlayerPed->SetCollisionChecking(1);
				}
			}
			else if(GetState() == PLAYER_STATE_DRIVER) {
				m_bPassengerDriveByMode = FALSE;
				m_pPlayerPed->CheckVehicleParachute();
				
				// REMOVE PLAYER MODEL IN RC VEHICLE
				if(m_pCurrentVehicle && m_pCurrentVehicle->IsRCVehicle()) {
					m_pPlayerPed->Remove();
				}

				if(m_iIsInAModShop)	{
					VECTOR vec = {0.0f,0.0f,0.0f};
					m_pPlayerPed->SetKeys(0,0,0);
					if(m_pCurrentVehicle) m_pCurrentVehicle->SetMoveSpeedVector(vec);
				} else {
					m_pPlayerPed->SetKeys(m_icSync.wKeys,m_icSync.lrAnalog,m_icSync.udAnalog);
				}
			}
			else if(GetState() == PLAYER_STATE_PASSENGER) {
				m_pPlayerPed->CheckVehicleParachute();
				m_pPlayerPed->SetKeys(m_psSync.wKeys,0,0);
			}
			else {
				m_bPassengerDriveByMode = FALSE;
				m_pPlayerPed->SetKeys(0,0,0);
			}

			m_pPlayerPed->SetHealth(100.0f);
			//m_pPlayerPed->SetArmour(100.0f);
		}
	}
	else {
		// NOT ACTIVE
		if(m_pPlayerPed) {
			ResetAllSyncAttributes();
			m_pPlayerPed->Destroy();
			delete m_pPlayerPed;
			m_pPlayerPed = NULL;
		}
	}
}