示例#1
0
    public static void Login(Action <LoginResult> successCallback, Action <PlayFabError> errorCallback)
    {
#if UNITY_ANDROID
        LoginWithAndroidDeviceIDRequest req = new LoginWithAndroidDeviceIDRequest
        {
            AndroidDeviceId       = SystemInfo.deviceUniqueIdentifier,
            CreateAccount         = true,
            InfoRequestParameters = new GetPlayerCombinedInfoRequestParams
            {
                GetUserAccountInfo = true
            }
        };

        PlayFabClientAPI.LoginWithAndroidDeviceID(req,
                                                  result =>
        {
            SuccessHandler(result);
            successCallback(result);
        },

                                                  error =>
        {
            ErrorHandler(error);
            errorCallback(error);
        }
                                                  );
#elif UNITY_IOS
        LoginWithIOSDeviceIDRequest req = new LoginWithIOSDeviceIDRequest
        {
            DeviceModel           = SystemInfo.deviceModel,
            OS                    = SystemInfo.operatingSystem,
            DeviceId              = SystemInfo.deviceUniqueIdentifier,
            CreateAccount         = true,
            InfoRequestParameters = new GetPlayerCombinedInfoRequestParams
            {
                GetUserAccountInfo = true
            }
        };

        PlayFabClientAPI.LoginWithIOSDeviceID(req,
                                              result =>
        {
            SuccessHandler(result);
            successCallback(result);
        },

                                              error =>
        {
            ErrorHandler(error);
            errorCallback(error);
        }
                                              );
#else
        LoginWithCustomIDRequest req = new LoginWithCustomIDRequest
        {
            TitleId               = PlayFabSettings.TitleId,
            CustomId              = SystemInfo.deviceUniqueIdentifier,
            CreateAccount         = true,
            InfoRequestParameters = new GetPlayerCombinedInfoRequestParams
            {
                GetUserAccountInfo = true
            }
        };

        PlayFabClientAPI.LoginWithCustomID(req,
                                           result =>
        {
            SuccessHandler(result);
            successCallback(result);
        },

                                           error =>
        {
            ErrorHandler(error);
            errorCallback(error);
        }
                                           );
#endif
    }
示例#2
0
        private static async Task Run(string titleId, string playerId, string buildId, bool verbose)
        {
            PlayFabApiSettings settings = new PlayFabApiSettings()
            {
                TitleId = titleId
            };
            PlayFabClientInstanceAPI clientApi = new PlayFabClientInstanceAPI(settings);

            // Login
            var loginRequest = new LoginWithCustomIDRequest()
            {
                CustomId      = playerId,
                CreateAccount = true
            };
            PlayFabResult <LoginResult> login = await clientApi.LoginWithCustomIDAsync(loginRequest);

            if (login.Error != null)
            {
                Console.WriteLine(login.Error.ErrorMessage);
                throw new Exception($"Login failed with HttpStatus={login.Error.HttpStatus}");
            }
            Console.WriteLine($"Logged in player {login.Result.PlayFabId} (CustomId={playerId})");
            Console.WriteLine();

            // Measure QoS
            Stopwatch     sw        = Stopwatch.StartNew();
            PlayFabQosApi qosApi    = new PlayFabQosApi(settings, clientApi.authenticationContext);
            QosResult     qosResult = await qosApi.GetQosResultAsync(250, degreeOfParallelism : 4, pingsPerRegion : 10);

            if (qosResult.ErrorCode != 0)
            {
                Console.WriteLine(qosResult.ErrorMessage);
                throw new Exception($"QoS ping failed with ErrorCode={qosResult.ErrorCode}");
            }

            Console.WriteLine($"Pinged QoS servers in {sw.ElapsedMilliseconds}ms with results:");

            if (verbose)
            {
                string resultsStr = JsonConvert.SerializeObject(qosResult.RegionResults, Formatting.Indented);
                Console.WriteLine(resultsStr);
            }

            int timeouts = qosResult.RegionResults.Sum(x => x.NumTimeouts);

            Console.WriteLine(string.Join(Environment.NewLine,
                                          qosResult.RegionResults.Select(x => $"{x.Region} - {x.LatencyMs}ms")));

            Console.WriteLine($"NumTimeouts={timeouts}");
            Console.WriteLine();

            // Allocate a server
            string        sessionId        = Guid.NewGuid().ToString();
            List <string> preferredRegions = qosResult.RegionResults
                                             .Where(x => x.ErrorCode == (int)QosErrorCode.Success)
                                             .Select(x => x.Region).ToList();

            PlayFabMultiplayerInstanceAPI mpApi = new PlayFabMultiplayerInstanceAPI(settings, clientApi.authenticationContext);
            PlayFabResult <RequestMultiplayerServerResponse> server =
                await mpApi.RequestMultiplayerServerAsync(new RequestMultiplayerServerRequest()
            {
                BuildId          = buildId,
                PreferredRegions = preferredRegions,
                SessionId        = sessionId
            }
                                                          );

            if (server.Error != null)
            {
                Console.WriteLine(server.Error.ErrorMessage);
                throw new Exception($"Allocation failed with HttpStatus={server.Error.HttpStatus}");
            }

            string serverLoc = $"{server.Result.IPV4Address}:{server.Result.Ports[0].Num}";

            Console.WriteLine($"Allocated server {serverLoc}");

            // Issue Http request against the server
            using (HttpResponseMessage getResult = await HttpClient.GetAsync("http://" + serverLoc))
            {
                getResult.EnsureSuccessStatusCode();

                Console.WriteLine("Received response:");
                string responseStr = await getResult.Content.ReadAsStringAsync();

                Console.WriteLine(responseStr);
                Console.WriteLine();
            }
        }
示例#3
0
 private void OnLoginWithCustomId(LoginWithCustomIDRequest request)
 {
     Callbacks.Add("OnRequest_InstLogin");
 }
示例#4
0
    /// <summary>
    /// Logins the with device identifier (iOS & Android only).
    /// </summary>
    public static void LoginWithDeviceId(bool createAcount, UnityAction errCallback)
    {
        Action <bool> processResponse = (bool response) =>
        {
            if (response && GetDeviceId())
            {
                if (!string.IsNullOrEmpty(android_id))
                {
                    Debug.Log("Using Android Device ID: " + android_id);
                    var request = new LoginWithAndroidDeviceIDRequest
                    {
                        AndroidDeviceId = android_id,
                        TitleId         = PlayFabSettings.TitleId,
                        CreateAccount   = createAcount
                    };

                    DialogCanvasController.RequestLoadingPrompt(PlayFabAPIMethods.GenericLogin);
                    PlayFabClientAPI.LoginWithAndroidDeviceID(request, OnLoginResult, (PlayFabError error) =>
                    {
                        if (errCallback != null && error.Error == PlayFabErrorCode.AccountNotFound)
                        {
                            errCallback();
                            PF_Bridge.RaiseCallbackError("Account not found, please select a login method to continue.", PlayFabAPIMethods.GenericLogin, MessageDisplayStyle.none);
                        }
                        else
                        {
                            OnLoginError(error);
                        }
                    });
                }
                else if (!string.IsNullOrEmpty(ios_id))
                {
                    Debug.Log("Using IOS Device ID: " + ios_id);
                    var request = new LoginWithIOSDeviceIDRequest
                    {
                        DeviceId      = ios_id,
                        TitleId       = PlayFabSettings.TitleId,
                        CreateAccount = createAcount
                    };

                    DialogCanvasController.RequestLoadingPrompt(PlayFabAPIMethods.GenericLogin);
                    PlayFabClientAPI.LoginWithIOSDeviceID(request, OnLoginResult, (PlayFabError error) =>
                    {
                        if (errCallback != null && error.Error == PlayFabErrorCode.AccountNotFound)
                        {
                            errCallback();
                            PF_Bridge.RaiseCallbackError("Account not found, please select a login method to continue.", PlayFabAPIMethods.GenericLogin, MessageDisplayStyle.none);
                        }
                        else
                        {
                            OnLoginError(error);
                        }
                    });
                }
            }
            else
            {
                Debug.Log("Using custom device ID: " + custom_id);
                var request = new LoginWithCustomIDRequest
                {
                    CustomId      = custom_id,
                    TitleId       = PlayFabSettings.TitleId,
                    CreateAccount = createAcount
                };

                DialogCanvasController.RequestLoadingPrompt(PlayFabAPIMethods.GenericLogin);
                PlayFabClientAPI.LoginWithCustomID(request, OnLoginResult, error =>
                {
                    if (errCallback != null && error.Error == PlayFabErrorCode.AccountNotFound)
                    {
                        errCallback();
                        PF_Bridge.RaiseCallbackError("Account not found, please select a login method to continue.", PlayFabAPIMethods.GenericLogin, MessageDisplayStyle.none);
                    }
                    else
                    {
                        OnLoginError(error);
                    }
                });
            }
        };

        processResponse(true);
        //DialogCanvasController.RequestConfirmationPrompt("Login With Device ID", "Logging in with device ID has some issue. Are you sure you want to contine?", processResponse);
    }
示例#5
0
        public override void NetLoginHandler(NetLogin data)
        {
            base.NetLoginHandler(data);

            if (Client.State == ClientState.Uninitialized)
            {
                RefreshNetInfo("正在登录PlayFab...");
                Client.State = ClientState.Queued;

                LoginWithCustomIDRequest request = new LoginWithCustomIDRequest()
                {
                    TitleId       = TitleId,
                    CreateAccount = true,
                    CustomId      = data.CustomID
                };
                PlayFabClientAPI.LoginWithCustomID(request, loginResult => {
                    PlayFabId = loginResult.PlayFabId;
                    CustomId  = data.CustomID;

                    if (loginResult.NewlyCreated)
                    {
                        RefreshNetInfo("登录成功,正在为新用户设置名称...");

                        UpdateUserTitleDisplayNameRequest request2 = new UpdateUserTitleDisplayNameRequest()
                        {
                            DisplayName = data.CustomID
                        };
                        PlayFabClientAPI.UpdateUserTitleDisplayName(request2, result2 => {
                            DisplayName = data.CustomID;
                            RefreshUserInfo();
                            // PlayFab 部分登录及初始化完毕
                            OnPlayFabSuccessLogin();
                        }, error2 => {
                            ResetUserInfo();
                            Client.State = ClientState.Uninitialized;
                            RefreshNetInfo("错误:未能更新用户显示名称");
                        });
                    }
                    else
                    {
                        RefreshNetInfo("登录成功,正在同步用户信息...");

                        GetUserCombinedInfoRequest r1 = new GetUserCombinedInfoRequest()
                        {
                            PlayFabId = PlayFabId
                        };
                        PlayFabClientAPI.GetUserCombinedInfo(r1, rs1 => {
                            DisplayName = rs1.AccountInfo.TitleInfo.DisplayName;
                            RefreshUserInfo();
                            // PlayFab 部分登录及初始化完毕
                            OnPlayFabSuccessLogin();
                        }, re1 => {
                            ResetUserInfo();
                            Client.State = ClientState.Uninitialized;
                            RefreshNetInfo("错误:未能获取用户信息");
                        });
                    }
                }, error => {
                    ResetUserInfo();
                    Client.State = ClientState.Uninitialized;
                    RefreshNetInfo("错误:未能成功登录 PlayFab");
                });
            }
        }
示例#6
0
 private static PlayFabClientAPI.LoginWithCustomIDResponseCallback _onResponseLogin = OnResponse_StaticLogin; // Static methods can be cast once and saved as a static variable
 private static void OnResponse_StaticLogin(string url, int callId, LoginWithCustomIDRequest request, LoginResult result, PlayFabError error, object customData)
 {
     callbacks.Add("OnResponse_StaticLogin");
 }
示例#7
0
 private static PlayFabClientAPI.LoginWithCustomIDRequestCallback _onRequestLogin = OnRequest_StaticLogin; // Static methods can be cast once and saved as a static variable
 private static void OnRequest_StaticLogin(string url, int callId, LoginWithCustomIDRequest request, object customData)
 {
     callbacks.Add("OnRequest_StaticLogin");
 }