Example #1
0
void CheckpointExit(RakNet::BitStream * pBitStream, RakNet::Packet * pPacket)
{
	// Get the player id
	EntityId playerId = (EntityId)pPacket->guid.systemIndex;

	// Read the checkpoint id
	EntityId checkpointId;
	pBitStream->Read(checkpointId);

	// Get the player instance
	CPlayerEntity * pPlayer = CServer::GetInstance()->GetPlayerManager()->GetAt(playerId);

	// Get the checkpoint instance
	CCheckpointEntity * pCheckpoint = CServer::GetInstance()->GetCheckpointManager()->GetAt(checkpointId);

	// Is the player instance valid?
	if (pPlayer)
	{
		CScriptArguments args;
		args.push(pPlayer->GetScriptPlayer());
		args.push(pCheckpoint->GetScriptCheckpoint());
		CEvents::GetInstance()->Call("playerExitCheckpoint", &args, CEventHandler::eEventType::NATIVE_EVENT, 0);
	}

	CLogFile::Printf("RPC_EXIT_CHECKPOINT");
}
Example #2
0
void VehicleExit(RakNet::BitStream * pBitStream, RakNet::Packet * pPacket)
{
	// Get the player id
	EntityId playerId = (EntityId) pPacket->guid.systemIndex;

	// Read the vehicle id
	EntityId vehicleId;
	pBitStream->Read(vehicleId);

	// Read the seat
	byte byteSeat;
	pBitStream->Read(byteSeat);

	// Get the player instance
	CPlayerEntity * pPlayer = CServer::GetInstance()->GetPlayerManager()->GetAt(playerId);

	// Is the player instance valid?
	if (pPlayer)
	{
		// Handle this with the player
		RakNet::BitStream bitStream;
		bitStream.Write(playerId);
		bitStream.Write(vehicleId);
		bitStream.Write(byteSeat);
		CServer::GetInstance()->GetNetworkModule()->Call(GET_RPC_CODEX(RPC_EXIT_VEHICLE), &bitStream, HIGH_PRIORITY, RELIABLE_ORDERED, -1, true);
		CScriptArguments args;
		args.push(pPlayer->GetScriptPlayer());
		CEvents::GetInstance()->Call("playerExitVehicle", &args, CEventHandler::eEventType::NATIVE_EVENT, 0);
	}

	CLogFile::Printf("RPC_EXIT_VEHICLE - Player: %d, Vehicle: %d, Seat: %d", playerId, vehicleId, byteSeat);
}
Example #3
0
void PlayerRequestSpawn(RakNet::BitStream * pBitStream, RakNet::Packet * pPacket)
{
	CLogFile::Printf("%s", __FUNCTION__);

	// Get the player id
	EntityId playerId = (EntityId) pPacket->guid.systemIndex;

	// Get a pointer to the player
	CPlayerEntity * pPlayer = CServer::GetInstance()->GetPlayerManager()->GetAt(playerId);

	// Is the player pointer valid?
	if (pPlayer)
	{
		if (CEvents::GetInstance()->IsEventRegistered("playerRequestSpawn"))
		{
			CScriptArguments args;
			args.push(pPlayer->GetScriptPlayer());
			CEvents::GetInstance()->Call("playerRequestSpawn", &args, CEventHandler::eEventType::NATIVE_EVENT, 0);
		}
		else
		{
			RakNet::BitStream bitStream;
			bitStream.Write(CVector3(DEFAULT_SPAWN_POSITION)); //spawnPos
			bitStream.Write(0.0f); //fHeading
			CServer::GetInstance()->GetNetworkModule()->Call(GET_RPC_CODEX(RPC_PLAYER_SPAWN), &bitStream, HIGH_PRIORITY, RELIABLE_ORDERED, playerId, false);
		}
		CLogFile::Printf("[spawn] %s has requestred a spawn.", pPlayer->GetName().Get());
	}
}
Example #4
0
void PlayerChat(RakNet::BitStream * pBitStream, RakNet::Packet * pPacket)
{
	// Get the playerid
	EntityId playerId = (EntityId) pPacket->guid.systemIndex;

	// Read if this is a command
	bool bIsCommand = pBitStream->ReadBit();

	// Read the input
	RakNet::RakString strInput;
	pBitStream->Read(strInput);

	// Is the player active?
	if (CServer::GetInstance()->GetPlayerManager()->DoesExists(playerId))
	{
		// Get a pointer to the player
		CPlayerEntity * pPlayer = CServer::GetInstance()->GetPlayerManager()->GetAt(playerId);

		// Is the pointer valid?
		if (pPlayer)
		{
			// Is this not a command?
			if (!bIsCommand)
			{
				CLogFile::Printf("[chat] %s: %s", pPlayer->GetName().Get(), strInput.C_String());

				// Send the RPC back to other players
				RakNet::BitStream bitStream;
				bitStream.Write(playerId);
				bitStream.Write(strInput);
				CServer::GetInstance()->GetNetworkModule()->Call(GET_RPC_CODEX(RPC_PLAYER_CHAT), &bitStream, HIGH_PRIORITY, RELIABLE_ORDERED, -1, true);
			}
			else
			{
				CLogFile::Printf("[command] %s: %s", pPlayer->GetName().Get(), strInput.C_String());

				CScriptArguments args;
				args.push(strInput);
				args.push(pPlayer->GetScriptPlayer());
				CEvents::GetInstance()->Call("playerCommand", &args, CEventHandler::eEventType::NATIVE_EVENT, nullptr);
			}
		}
	}
}
Example #5
0
void PlayerDeath(RakNet::BitStream * pBitStream, RakNet::Packet * pPacket)
{
	CLogFile::Printf("%s", __FUNCTION__);

	// Get the player id
	EntityId playerId = (EntityId) pPacket->guid.systemIndex;

	// Read the killer id
	EntityId killerId;
	pBitStream->Read(killerId);

	// Get a pointer to the player
	CPlayerEntity * pPlayer = CServer::GetInstance()->GetPlayerManager()->GetAt(playerId);

	// Is the player pointer valid?
	if (pPlayer)
	{
		// Kill the player
		//pPlayer->KillForWorld();

		// Is the killer a player?
		if (killerId != INVALID_ENTITY_ID)
		{
			// Find the killer
			CPlayerEntity* pKiller = CServer::GetInstance()->GetPlayerManager()->GetAt(killerId);

			// Is the killer valid?
			if (pKiller)
				CLogFile::Printf("[death] %s has been killed by %s!", pPlayer->GetName().Get(), pKiller->GetName().Get());
			else
				CLogFile::Printf("[death] %s has been killed!", pPlayer->GetName().Get());
		}
		else
		{
			CLogFile::Printf("[death] %s has died!", pPlayer->GetName().Get());
		}

		CScriptArguments args;
		args.push(pPlayer->GetScriptPlayer());
		CEvents::GetInstance()->Call("playerDeath", &args, CEventHandler::eEventType::NATIVE_EVENT, 0);
	}
}
Example #6
0
void PlayerSpawn(RakNet::BitStream * pBitStream, RakNet::Packet * pPacket)
{
	// Get the player id
	EntityId playerId = (EntityId) pPacket->guid.systemIndex;

	// Get a pointer to the player
	CPlayerEntity * pPlayer = CServer::GetInstance()->GetPlayerManager()->GetAt(playerId);

	// Is the player pointer valid?
	if (pPlayer)
	{
		// Spawn the player
		//pPlayer->SpawnForWorld();

		// Spawn everyone else connected for this player
		//CServer::GetInstance()->GetPlayerManager()->HandlePlayerSpawn(playerId);
		CScriptArguments args;
		args.push(pPlayer->GetScriptPlayer());
		CEvents::GetInstance()->Call("onSpawn", &args, CEventHandler::eEventType::GLOBAL_EVENT, 0);
		CLogFile::Printf("[spawn] %s has spawned.", pPlayer->GetName().Get());
	}
	CLogFile::Printf("%s", __FUNCTION__);
}