private async Task SendServerRequest(string roomName, string playerId)
    {
        Debug.Log("Sending Join Request: " + roomName + " : " + playerId);
        if (!string.IsNullOrEmpty(roomName) && !string.IsNullOrEmpty(playerId))
        {
            // No Nulls in request room!
            Debug.Log("Valid. Sent.");

            var             serverApi        = ServerApi.Instance;
            RoomInformation joinRoomResponse = await serverApi.JoinRoomAsync(roomName, playerId);

            Debug.Log($"{nameof(joinRoomResponse)}:{joinRoomResponse.ToJson()}");
            GameLogicManager.instance.UpdateGameState(joinRoomResponse.Playing, joinRoomResponse.Waiting);
            bool badResponse = joinRoomResponse.ToJson() == "{}";
            if (badResponse)
            {
                // Try room info as fallback. Maybe we're already in there.
                Debug.Log("Trying to get Room Info Anyway...");
                RoomInformation roomInfoResponse = await serverApi.RoomInformationAsync(roomName);

                Debug.Log($"{nameof(roomInfoResponse)}:{roomInfoResponse.ToJson()}");
                GameLogicManager.instance.UpdateGameState(roomInfoResponse.Playing, roomInfoResponse.Waiting);
            }
        }
    }
Пример #2
0
        public async Task SendRoomInfoRequest()
        {
            string roomId = serverRoomName.Value;

            if (!string.IsNullOrEmpty(roomId))
            {
                try
                {
                    var serverApi = ServerApi.Instance;
                    Debug.Log($"[{DateTime.Now:HH:mm:ss}]{nameof(SendRoomInfoRequest)}");
                    RoomInformation roomInfoResponse = await serverApi.RoomInformationAsync(roomId);

                    Debug.Log($"[{DateTime.Now:HH:mm:ss}]{nameof(roomInfoResponse)}:{roomInfoResponse.ToJson()}");
                    UpdateGameState(roomInfoResponse.Playing, roomInfoResponse.Waiting);
                }
                catch (Exception e)
                {
                    LogException(e);
                }
            }
        }