MatchMakeResponse GetResponseObject(object msg)
    {
        IndexedDictionary <string, object> message  = (IndexedDictionary <string, object>)msg;
        IndexedDictionary <string, object> roomData = (IndexedDictionary <string, object>)message["room"];

        RoomAvailable roomAvailable = new RoomAvailable();

        roomAvailable.name      = roomData["name"] as string;
        roomAvailable.processId = roomData["processId"] as string;
        roomAvailable.roomId    = roomData["roomId"] as string;

        MatchMakeResponse response = new MatchMakeResponse();

        response.room      = roomAvailable;
        response.sessionId = message["sessionId"] as string;

        return(response);
    }
    private async void OnMatchMessage(object msg)
    {
        if (msg.GetType() == typeof(System.Byte))
        {
            Debug.Log("Number of ships in matchmaker: " + msg);
        }
        else if (msg is ShipList)
        {
            Debug.Log("ShipList message received.");
            ShipList sl = msg as ShipList;
            RoomManager.ClearMatchMakerShips();
            RoomManager.AddMatchMakerShips(sl);
        }
        else if (msg.GetType() == typeof(IndexedDictionary <string, object>))
        {
            MatchMakeResponse response = GetResponseObject(msg);
            RoomManager.HandleEnterGame(response);
            await this.matchRoom.Send(1);

            RoomManager.HandleOnMatchFound();
        }
    }
Example #3
0
    public async void HandleEnterGame(MatchMakeResponse response)
    {
        if (response == null)
        {
            Dictionary <string, object> options = new Dictionary <string, object>()
            {
                { "token", PlayerPrefs.GetString("token") },
                { "waveRank", PlayerData.CurrentShip().rank - 5 }
            };
            gameRoom = await RoomManager.JoinOrCreate <GameState>("GameRoom", options);

            SetupGameRoomListeners();
        }
        else
        {
            Dictionary <string, string> headers = new Dictionary <string, string>();
            gameRoom = await RoomManager.ConsumeSeatReservation <GameState>(response, headers);

            SetupGameRoomListeners();
        }

        gameRoom.OnLeave += async(code) =>
        {
            Debug.Log("[GameRoom] On Leave: " + code + " : Attempting Reconnect");
            try
            {
                gameRoom = await RoomManager.ReconnectToGame <GameState>(gameRoom.Id, gameRoom.SessionId);

                SetupGameRoomListeners();
                Debug.Log("[GameRoom] Reconnection Success: " + gameRoom.SessionId);
            }
            catch
            {
                Debug.Log("[GameRoom] On Leave: Could not reconnnect");
            }
        };
    }
Example #4
0
 public void HandleEnterGame(MatchMakeResponse response)
 {
     game.HandleEnterGame(response);
 }
Example #5
0
 public async Task <Room <T> > ConsumeSeatReservation <T>(MatchMakeResponse response, Dictionary <string, string> headers)
 {
     return(await client.ConsumeSeatReservation <T>(response, headers));
 }