Beispiel #1
0
 private void BroadcastConnection(int playerId)
 {
     for (int i = 0; i < players.Count; i++)
     {
         ServerPlayerController playerToSendTo         = players[i];
         PlayerConnectedMessage playerConnectedMessage = PlayerConnectedMessage.CreatePCMToSend(playerToSendTo, playerId);
         playerToSendTo.CommunicationManager.SendMessage(playerConnectedMessage);
     }
 }
        protected override void InitPlayerSpawn(ServerPlayerController playerController)
        {
            base.InitPlayerSpawn(playerController);
            var player = SpawnPlayer(0);

            playerController.PossessPlayerPawn(player);

            if (data.player2)
            {
                var player2 = SpawnPlayer(1);
                player2.team = player.team;
            }
        }
Beispiel #3
0
    void ProcessDisconnectPlayer(DisconnectPlayerMessage disconnectPlayerMessage)
    {
        ServerPlayerController player = GetPlayerWithEndPoint(disconnectPlayerMessage.From);

        if (player != null)
        {
            DisconnectPlayer(player);
            for (int i = 0; i < players.Count; i++)
            {
                ServerPlayerController    playerToSendTo            = players[i];
                PlayerDisconnectedMessage playerDisconnectedMessage = PlayerDisconnectedMessage.CreatePDMToSend(playerToSendTo, player.Id);
                playerToSendTo.CommunicationManager.SendMessage(playerDisconnectedMessage);
            }
        }
    }
        private void FixedUpdate()
        {
            foreach (PlayerPositionInputData input in UnprocessedPlayerMovementInput)
            {
                ServerPlayerController controller = CurrentPlayers[input.ID].GetComponent <ServerPlayerController>();
                controller.UpdateNavTarget(input.Pos);

                ProccessedPlayerMovementInput.Add(input);
            }

            ProccessedPlayerMovementData proccessedMovement = new ProccessedPlayerMovementData(ProccessedPlayerMovementInput.ToArray());

            ServerManager.Instance.SendToAll(Tags.PlayerMovementUpdate, proccessedMovement);

            UnprocessedPlayerMovementInput.Clear();
            ProccessedPlayerMovementInput.Clear();
        }
Beispiel #5
0
    private void SendPackets()
    {
        for (int playerIdx = 0; playerIdx < players.Count; playerIdx++)
        {
            ServerPlayerController player = players[playerIdx];
            Packet packet = player.CommunicationManager.BuildPacket();

            if (packet != null)
            {
                bool shouldDropPacket = Random.Range(0.0001f, 100.0f) < fakePacketLoss;
                if (!shouldDropPacket)
                {
                    channel.Send(packet, player.endPoint);
                }
            }
        }
    }
Beispiel #6
0
    public void ProcessConnectPlayer(ConnectPlayerMessage connectPlayerMessage)
    {
        int playerId = connectPlayerMessage.PlayerId;
        ServerPlayerController player = GetPlayerWithId(playerId);

        if (player != null)
        {
            DisconnectPlayer(player);
        }

        GameObject playerGO = Instantiate(playerPrefab) as GameObject;

        playerGO.name   = PLAYER + " " + playerId;
        player          = playerGO.GetComponent <ServerPlayerController>();
        player.endPoint = connectPlayerMessage.EndPoint;
        player.Id       = playerId;
        players.Add(player);

        BroadcastConnection(playerId);
    }
Beispiel #7
0
    void Update()
    {
        Packet inPacket = channel.GetPacket();

        if (inPacket != null)
        {
            BitBuffer bitBuffer    = inPacket.buffer;
            int       messageCount = bitBuffer.GetInt();
            for (int i = 0; i < messageCount; i++)
            {
                Message clientMessage = ReadClientMessage(bitBuffer, inPacket.fromEndPoint);
                if (clientMessage != null)
                {
                    switch (clientMessage.Type)
                    {
                    case MessageType.CONNECT_PLAYER:
                        ProcessConnectPlayer(clientMessage as ConnectPlayerMessage); break;

                    case MessageType.DISCONNECT_PLAYER:
                        ProcessDisconnectPlayer(clientMessage as DisconnectPlayerMessage); break;

                    default:
                        ServerPlayerController player = GetPlayerWithEndPoint(inPacket.fromEndPoint);
                        if (player != null)
                        {
                            player.CommunicationManager.ReceiveMessage(clientMessage);
                        }
                        break;
                    }
                }
            }
        }

        SendSnapshot();
        SendPackets();
    }
    public static PlayerDisconnectedMessage CreatePDMToSend(ServerPlayerController receiver, int playerDisconnectedId)
    {
        int messageId = receiver.CommunicationManager.GetReliableSEFMessageId();

        return(new PlayerDisconnectedMessage(messageId, playerDisconnectedId));
    }
 protected override ServerTeam GetTeamForSpawningPlayer(ServerPlayerController playerController)
 {
     // TODO: base assigns every player to a new team
     return(base.GetTeamForSpawningPlayer(playerController));
 }
Beispiel #10
0
 void DisconnectPlayer(ServerPlayerController player)
 {
     Destroy(player.gameObject);
     players.Remove(player);
 }