Beispiel #1
0
    public void SendPlayerDisconnect()
    {
        var packet = Packet.Obtain();

        ClientSerializationManager.SerializePlayerDisconnect(packet.buffer);
        packet.buffer.Flush();

        channel.Send(packet, serverIpEndPoint);

        packet.Free();
    }
Beispiel #2
0
    private void SendPlayerJoinedAck(int newPlayerId)
    {
        var packet = Packet.Obtain();

        ClientSerializationManager.SerializePlayerJoinedAck(packet.buffer, newPlayerId, clientId);
        packet.buffer.Flush();

        channel.Send(packet, serverIpEndPoint);

        packet.Free();
    }
Beispiel #3
0
    // Serialize & send commands to server
    private void SendCommands(List <Commands> commandsList)
    {
        var packet = Packet.Obtain();

        ClientSerializationManager.SerializeCommands(packet.buffer, commandsList, clientId);
        packet.buffer.Flush();

        if (latency != 0)
        {
            Task.Delay(latency).ContinueWith(t => channel.Send(packet, serverIpEndPoint)).ContinueWith(t => packet.Free());
        }
        else
        {
            channel.Send(packet, serverIpEndPoint);
            packet.Free();
        }
    }
Beispiel #4
0
    public void SendPlayerShotMessage(int shotPlayerId)
    {
        unAckedShots.Add(new Shot(shotSeq, shotPlayerId));
        shotSeq++;

        var packet = Packet.Obtain();

        ClientSerializationManager.SerializePlayerShot(packet.buffer, unAckedShots, clientId);
        packet.buffer.Flush();

        if (latency != 0)
        {
            Task.Delay(latency).ContinueWith(t => channel.Send(packet, serverIpEndPoint)).ContinueWith(t => packet.Free());
        }
        else
        {
            channel.Send(packet, serverIpEndPoint);
            packet.Free();
        }
    }