Exemplo n.º 1
0
    public static void RequestPlayerIndex(object caller, DataStreamReader stream, ref DataStreamReader.Context context, NetworkConnection source)
    {
        //bind this connection to a specific player index
        MyServerBehaviour server = caller as MyServerBehaviour;
        uint eventType           = (uint)GameEvent.ASSIGN_PLAYERINDEX;
        uint index = server.AddNextAvailablePlayerIndex(source);

        Debug.Log("Sending player index " + index + " to client");

        //Tell source client what their player index is
        using (var writer = new DataStreamWriter(8, Allocator.Temp))
        {
            writer.Write(eventType);
            writer.Write(index);
            source.Send(server.m_Driver, writer);
        }

        //Create remoteclient representation for newly connected player
        //TODO: figure out what the server needs to store here (if anything)
        //server.CreateRemoteClientForIndex(index);

        //Send message to all other clients about newly connected player
        using (var writer = new DataStreamWriter(8, Allocator.Temp)) {
            writer.Write((uint)GameEvent.PLAYER_JOINED);
            writer.Write(index);
            server.BroadcastToClientsExcluding(source, writer);
        }

        //Send message per existing client to newly connected player
        server.SendExistingPlayersTo(source);
    }
Exemplo n.º 2
0
    public static void ClientInputChanged(object caller, DataStreamReader stream, ref DataStreamReader.Context context, NetworkConnection source)
    {
        MyServerBehaviour server = caller as MyServerBehaviour;
        uint  playerIndex        = stream.ReadUInt(ref context);
        uint  dirtFlags          = stream.ReadUInt(ref context);
        uint  buttonState        = stream.ReadUInt(ref context);
        float mouseX             = stream.ReadFloat(ref context);
        float mouseY             = stream.ReadFloat(ref context);
        float mouseZ             = stream.ReadFloat(ref context);

        server.UpdateClientInput(playerIndex, buttonState, mouseX, mouseY, mouseZ);

        Debug.Log("Got Client Input for " + playerIndex);
    }
Exemplo n.º 3
0
    public static void Pong(object caller, DataStreamReader stream, ref DataStreamReader.Context context, NetworkConnection source)
    {
        MyServerBehaviour server = caller as MyServerBehaviour;

        //calculate client lag from half-time of total event
    }