Example #1
0
    private void on(OpponentPaused message)
    {
        Debug.Log("Opponent Paused, time remaining: " + message.TimeRemaining);

        matchInfoDisplay.GameState = "Paused by " + matchInfoDisplay.OpponentId + ", " + message.TimeRemaining + "s left...";
        matchInfoDisplay.SetInputAllowed(false);
    }
Example #2
0
 public static Offset <OpponentPaused> CreateOpponentPaused(FlatBufferBuilder builder,
                                                            short opcode        = 7,
                                                            short timeRemaining = 0)
 {
     builder.StartTable(2);
     OpponentPaused.AddTimeRemaining(builder, timeRemaining);
     OpponentPaused.AddOpcode(builder, opcode);
     return(OpponentPaused.EndOpponentPaused(builder));
 }
Example #3
0
 public static OpponentPaused GetRootAsOpponentPaused(ByteBuffer _bb, OpponentPaused obj)
 {
     return(obj.__assign(_bb.GetInt(_bb.Position) + _bb.Position, _bb));
 }
Example #4
0
    private void Update()
    {
        if (doAbort)
        {
            doAbort = false;
            AbortGame();
        }
        if (didConnectSuccessfully)
        {
            didConnectSuccessfully = false;
            OnConnected();
        }
        if (doAttemptConnect)
        {
            doAttemptConnect = false;
            OnAttemptingReconnect();
        }

        if (!client.IsConnected && tickCount > 0 && !UserData.Instance.IsGameOver)
        {
            matchInfoDisplay.GameState = "Disconnected";
        }

        // Process all packets that have been received by the server thus far
        byte[] data;
        while (client.GetNextPacket(out data))
        {
            if (UserData.Instance.IsGameOver)
            {
                return;
            }

            var packet     = PacketFactory.BytesToPacket(data);
            var byteBuffer = new ByteBuffer(data);

            // Uncomment for logs containing which packet type you receive
            // Debug.Log("SyncGameController: Received packet: " + (Opcode)packet.Opcode);
            switch ((Opcode)packet.Opcode)
            {
            case Opcode.MatchSuccess:
                client.ResetReadTimer();
                on(MatchSuccess.GetRootAsMatchSuccess(byteBuffer));

                client.SetReadTimeout(2000);
                break;

            case Opcode.GameState:
                on(GameState.GetRootAsGameState(byteBuffer));
                break;

            case Opcode.MatchOver:
                on(MatchOver.GetRootAsMatchOver(byteBuffer));
                break;

            case Opcode.OpponentConnectionStatus:
                on(OpponentConnectionStatus.GetRootAsOpponentConnectionStatus(byteBuffer));
                break;

            case Opcode.PlayerReconnected:
                on(PlayerReconnected.GetRootAsPlayerReconnected(byteBuffer));
                break;

            case Opcode.OpponentPaused:
                on(OpponentPaused.GetRootAsOpponentPaused(byteBuffer));
                break;

            case Opcode.OpponentResumed:
                on(OpponentResumed.GetRootAsOpponentResumed(byteBuffer));
                break;

            case Opcode.Chat:
                on(Chat.GetRootAsChat(byteBuffer));
                break;

            case Opcode.KeepAlive:
                break;

            default:
                Debug.Log("SyncGameController: Received packet with unimplemented/unsupported authcode: " + packet.Opcode);
                break;
            }
        }
    }