private void StartMatch()
 {
     enemyText.text = enemyName;
     playBtn.SetActive(true);
     backBtn.GetComponent <Button>().interactable = true;
     PlayfabUtils.OnSuccess(feedbackText, "Match started!");
 }
Beispiel #2
0
    public void Login()
    {
        Debug.Log("Logging in");
        Debug.Log(emailInput.text);
        Debug.Log(passwordInput.text);
        if (emailInput.text.Equals("") || passwordInput.text.Equals(""))
        {
            PlayfabUtils.OnError(feedbackText, "Login needs email and password!");
            return;
        }
        if (passwordInput.text.Length < 6)
        {
            PlayfabUtils.OnError(feedbackText, "Password needs to be at least 6 characters!");
            return;
        }
        var request = new LoginWithEmailAddressRequest
        {
            Email    = emailInput.text,
            Password = passwordInput.text,
            InfoRequestParameters = new GetPlayerCombinedInfoRequestParams
            {
                GetPlayerProfile   = true,
                GetUserData        = true,
                GetUserAccountInfo = true
            }
        };

        Debug.Log("Sending the data...");
        PlayFabClientAPI.LoginWithEmailAddress(request, OnLoginSuccess, OnError);
    }
    private void OnTicketCreated(CreateMatchmakingTicketResult res)
    {
        ticketId = res.TicketId;
        leaveBtn.SetActive(true);

        PlayfabUtils.OnSuccess(feedbackText, "Match Ticket Created!");
        pollTicketCoroutine = StartCoroutine(PollTicket());
    }
Beispiel #4
0
    private void OnNameUpdated(UpdateUserTitleDisplayNameResult res)
    {
        loginManager.playerData.accountInfo.name = res.DisplayName;
        nameText.text = res.DisplayName;

        nameInput.text = "";

        PlayfabUtils.OnSuccess(feedbackText, "Display Name Updated!");
    }
 public void OnPageActive()
 {
     loginManager      = gameObject.GetComponent <PlayfabLogin>();
     feedbackText.text = "";
     usernameText.text = loginManager.getDisplayName();
     if (loginManager.isLoggedIn())
     {
         GetLeaderboard();
     }
     else
     {
         PlayfabUtils.OnError(feedbackText, "You must login first to see the leaderboard!");
     }
 }
Beispiel #6
0
    public void ResetPassword()
    {
        if (emailInput.text.Equals(""))
        {
            PlayfabUtils.OnError(feedbackText, "Reset Password needs email!");
            return;
        }
        var request = new SendAccountRecoveryEmailRequest
        {
            Email   = emailInput.text,
            TitleId = PlayfabUtils.TITLE_ID
        };

        PlayFabClientAPI.SendAccountRecoveryEmail(request, OnPasswordRecoverySent, OnError);
    }
Beispiel #7
0
    public void ResetPassword()
    {
        if (loginManager.getEmail() == "")
        {
            PlayfabUtils.OnError(feedbackText, "Reset Password needs login!");
            return;
        }
        var request = new SendAccountRecoveryEmailRequest
        {
            Email   = loginManager.getEmail(),
            TitleId = PlayfabUtils.TITLE_ID
        };

        PlayFabClientAPI.SendAccountRecoveryEmail(request, OnPasswordRecoverySent, OnError);
    }
Beispiel #8
0
    public void UpdateDisplayName()
    {
        if (!loginManager.isLoggedIn())
        {
            PlayfabUtils.OnError(feedbackText, "Please login first!");
            return;
        }
        if (nameInput.text == "")
        {
            PlayfabUtils.OnError(feedbackText, "New Display Name must not be empty!");
            return;
        }
        var request = new UpdateUserTitleDisplayNameRequest
        {
            DisplayName = nameInput.text
        };

        PlayFabClientAPI.UpdateUserTitleDisplayName(request, OnNameUpdated, OnError);
    }
    private void OnTicketGet(GetMatchmakingTicketResult res)
    {
        PlayfabUtils.OnSuccess(feedbackText, $"Matchmaking Status: {res.Status}");

        switch (res.Status)
        {
        case "Matched":
            StopCoroutine(pollTicketCoroutine);
            leaveBtn.SetActive(false);
            PrepareMatch(res.MatchId);
            break;

        case "Canceled":
            PlayfabUtils.OnError(feedbackText, "Matchmaking timeout! Please try again...");
            StopCoroutine(pollTicketCoroutine);
            leaveBtn.SetActive(false);
            backBtn.GetComponent <Button>().interactable = true;
            break;
        }
    }
    public void OnPageActive()
    {
        loginManager      = gameObject.GetComponent <PlayfabLogin>();
        feedbackText.text = "";
        leaveBtn.SetActive(false);
        playBtn.SetActive(false);

        usernameText.text = loginManager.getDisplayName();
        enemyText.text    = "Loading...";
        if (loginManager.isLoggedIn())
        {
            backBtn.GetComponent <Button>().interactable = false;
            StartMatchmaking();
        }
        else
        {
            backBtn.GetComponent <Button>().interactable = true;
            PlayfabUtils.OnError(feedbackText, "You must login first to start matchmaking!");
        }
    }
Beispiel #11
0
    private void OnDataGet(GetUserDataResult res)
    {
        if (res.Data != null && res.Data.ContainsKey("PlayerData"))
        {
            loginManager.playerData.LoadJson(res.Data["PlayerData"].Value);

            sprintTicketText.text    = loginManager.playerData.powerUps.sprintTicket.ToString();
            marathonTicketText.text  = loginManager.playerData.powerUps.marathonTicket.ToString();
            foodCouponText.text      = loginManager.playerData.powerUps.foodCoupon.ToString();
            milkCouponText.text      = loginManager.playerData.powerUps.milkCoupon.ToString();
            exchangeProgramText.text = loginManager.playerData.powerUps.exchangeProgram.ToString();

            speedText.text      = loginManager.playerData.stats.maxSpeed.ToString();
            staminaText.text    = loginManager.playerData.stats.minStamina.ToString();
            widthText.text      = loginManager.playerData.stats.width.ToString();
            heightText.text     = loginManager.playerData.stats.height.ToString();
            rankPointsText.text = loginManager.playerData.stats.rankPoints.ToString();

            PlayfabUtils.OnSuccess(feedbackText, "Player Data Updated!");
        }
    }
 public void OnLeaderboardGet(GetLeaderboardAroundPlayerResult res)
 {
     foreach (Transform item in tableTransform)
     {
         Destroy(item.gameObject);
     }
     foreach (var item in res.Leaderboard)
     {
         GameObject newItem = Instantiate(tableItemPrefab, tableTransform);
         Text[]     texts   = newItem.GetComponentsInChildren <Text>();
         texts[0].text = (item.Position + 1).ToString();
         texts[1].text = item.DisplayName;
         texts[2].text = item.StatValue.ToString();
         if (item.PlayFabId == loginManager.playerData.accountInfo.playfabId)
         {
             texts[0].color = Color.yellow;
             texts[1].color = Color.yellow;
             texts[2].color = Color.yellow;
         }
     }
     PlayfabUtils.OnSuccess(feedbackText, "Leaderboard Updated!");
 }
Beispiel #13
0
    public void Register()
    {
        if (emailInput.text.Equals("") || nameInput.text.Equals("") || passwordInput.text.Equals(""))
        {
            PlayfabUtils.OnError(feedbackText, "Register needs email, name, and password!");
            return;
        }
        if (passwordInput.text.Length < 6)
        {
            PlayfabUtils.OnError(feedbackText, "Password needs to be at least 6 characters!");
            return;
        }
        var request = new RegisterPlayFabUserRequest
        {
            Email       = emailInput.text,
            Password    = passwordInput.text,
            DisplayName = nameInput.text,
            RequireBothUsernameAndEmail = false
        };

        PlayFabClientAPI.RegisterPlayFabUser(request, OnRegisterSuccess, OnError);
    }
Beispiel #14
0
    private void OnLoginSuccess(LoginResult result)
    {
        PlayfabUtils.OnSuccess(feedbackText, "Login success!");
        usernameText.text = result.InfoResultPayload.PlayerProfile.DisplayName;
        hasLogin          = true;
        var displayName   = result.InfoResultPayload.PlayerProfile.DisplayName;
        var email         = result.InfoResultPayload.AccountInfo.PrivateInfo.Email;
        var playfabId     = result.InfoResultPayload.AccountInfo.PlayFabId;
        var sessionTicket = result.SessionTicket;
        var entityId      = result.EntityToken.Entity.Id;

        if (result.InfoResultPayload.UserData != null && result.InfoResultPayload.UserData.ContainsKey("PlayerData"))
        {
            playerData = PlayerData.FromJson(result.InfoResultPayload.UserData["PlayerData"].Value);
        }
        else
        {
            playerData = new PlayerData();
        }

        playerData.setAccountInfo(displayName, email, playfabId, sessionTicket, entityId);
        ClearTextFields();
    }
 private void OnError(PlayFabError error)
 {
     PlayfabUtils.OnError(feedbackText, error.ErrorMessage);
 }
    public void StartMatchmaking()
    {
        PlayfabUtils.OnSuccess(feedbackText, "Matchmaking in progress...");

        PlayFabMultiplayerAPI.ListQosServersForTitle(new ListQosServersForTitleRequest(), qosRes =>
        {
            var qosServer = qosRes.QosServers[0].ServerUrl;
            var qosRegion = qosRes.QosServers[0].Region;
            Debug.Log($"Pinging QoS Server {qosServer} at {qosRegion}");
            Debug.Log(qosRes.ToJson());

            var sw = System.Diagnostics.Stopwatch.StartNew();

            var udpPort = 5600;
            var done    = false;
            while (!done || udpPort > 5610)
            {
                try
                {
                    UdpClient client = new UdpClient(udpPort);
                    client.Connect(qosServer, 3075);
                    byte[] sendBytes = BitConverter.GetBytes(0xFFFF);
                    client.Send(sendBytes, sendBytes.Length);

                    IPEndPoint remoteEndPoint = new IPEndPoint(IPAddress.Any, 3075);
                    byte[] receiveBytes       = client.Receive(ref remoteEndPoint);
                    client.Close();
                    done = true;
                }
                catch (Exception e)
                {
                    Debug.LogError($"[QoS Ping Error]: {e.Message}");
                    udpPort++;
                    Debug.Log($"Retrying with port {udpPort}");
                }
            }
            var pingTime = sw.ElapsedMilliseconds;
            Debug.Log($"Ping success with {pingTime}ms");
            if (udpPort > 5610)
            {
                StartMatchmaking();
                return;
            }

            var request = new CreateMatchmakingTicketRequest
            {
                Creator = new MatchmakingPlayer
                {
                    Entity = new PlayFab.MultiplayerModels.EntityKey
                    {
                        Id   = loginManager.playerData.accountInfo.entityId,
                        Type = PlayfabUtils.ENTITY_TYPE
                    },
                    Attributes = new MatchmakingPlayerAttributes
                    {
                        DataObject = new LatenciesData
                        {
                            Latencies = new List <Latency>
                            {
                                { new Latency {
                                      region = qosRegion, latency = pingTime
                                  } }
                            }
                        }
                    }
                },
                GiveUpAfterSeconds = PlayfabUtils.MATCHMAKING_TIMEOUT,
                QueueName          = PlayfabUtils.MATCHMAKING_NAME
            };

            PlayFabMultiplayerAPI.CreateMatchmakingTicket(request, OnTicketCreated, OnError);
        }, OnError);
    }
 private void OnTicketCancelled(CancelMatchmakingTicketResult res)
 {
     StopCoroutine(pollTicketCoroutine);
     backBtn.GetComponent <Button>().interactable = true;
     PlayfabUtils.OnSuccess(feedbackText, "Matchmaking cancelled!");
 }
Beispiel #18
0
 private void OnRegisterSuccess(RegisterPlayFabUserResult result)
 {
     PlayfabUtils.OnSuccess(feedbackText, "Register success!");
     SendPlayerData();
     ClearTextFields();
 }
Beispiel #19
0
 void Awake()
 {
     Instance = this;
 }
Beispiel #20
0
 private void OnPasswordRecoverySent(SendAccountRecoveryEmailResult result)
 {
     PlayfabUtils.OnSuccess(feedbackText, "Email for password reset sent!");
 }