Ejemplo n.º 1
0
        public async Task E2E_AppServer_AccountLoginApp_Test()
        {
            var registerResponse = await CreateTestAccount();

            var loginResponse = await acClient.AccountLoginAsync(new AccountLoginInfo
            {
                AccountName = registerResponse.AccountName,
                Password    = ValidAccountPassword,
                Device      = TestDevice
            });

            var accountLoginAppInfo = new AccountLoginAppInfo
            {
                AppId        = TestAppId,
                AppSecret    = TestAppSecret,
                AccountId    = loginResponse.AccountId,
                AccountToken = loginResponse.Token
            };
            var result = await asClient.AccountLoginAppAsync(accountLoginAppInfo);

            Assert.IsNotNull(result.AccountId);
            Assert.IsNotNull(result.AccountName);
            Assert.IsNotNull(result.AccountToken);
            Assert.IsNotNull(result.LastLoginDateTime);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Account login to application.
        /// </summary>
        /// <param name="info">Indicating the application information.</param>
        /// <returns>Async response.</returns>
        public async Task <AccountLoginAppResponse> AccountLoginAppAsync(AccountLoginAppInfo info)
        {
            string url      = this.GenerateApiEndpoint("apps", $"{info.AppId}/accountlogin");
            var    response = await this.httpClient.SendAsyncWithException <AccountLoginAppInfo, AccountLoginAppResponse>(
                HttpMethod.Post,
                url,
                info);

            return(response);
        }
Ejemplo n.º 3
0
        public async Task E2E_AppServer_AccountLoginApp_AccountNotExist_Test()
        {
            var accountLoginAppInfo = new AccountLoginAppInfo
            {
                AppId        = TestAppId,
                AppSecret    = TestAppSecret,
                AccountId    = "___Test_Account_No_Exist___",
                AccountToken = ValidAccountPassword
            };

            await TestExpector.ExpectUCenterErrorAsync(
                UCenterErrorCode.AccountNotExist,
                async() => { await asClient.AccountLoginAppAsync(accountLoginAppInfo); });
        }
Ejemplo n.º 4
0
        public async Task E2E_AppServer_AccountLoginApp_IncorrectAppSecret_Test()
        {
            var registerResponse = await CreateTestAccount();

            var loginResponse = await acClient.AccountLoginAsync(new AccountLoginInfo
            {
                AccountName = registerResponse.AccountName,
                Password    = ValidAccountPassword,
                Device      = TestDevice
            });

            var accountLoginAppInfo = new AccountLoginAppInfo
            {
                AppId        = TestAppId,
                AppSecret    = InvalidAppSecret,
                AccountId    = loginResponse.AccountId,
                AccountToken = ValidAccountPassword
            };

            await TestExpector.ExpectUCenterErrorAsync(
                UCenterErrorCode.AppTokenUnauthorized,
                async() => { await asClient.AccountLoginAppAsync(accountLoginAppInfo); });
        }
Ejemplo n.º 5
0
        public async Task E2E_AppServer_AccountLoginApp_AppNotExist_Test()
        {
            var registerResponse = await CreateTestAccount();

            var loginResponse = await acClient.AccountLoginAsync(new AccountLoginInfo
            {
                AccountName = registerResponse.AccountName,
                Password    = ValidAccountPassword,
                Device      = TestDevice
            });

            var accountLoginAppInfo = new AccountLoginAppInfo
            {
                AppId        = "___Test_App_No_Exist___",
                AppSecret    = TestAppSecret,
                AccountId    = registerResponse.AccountId,
                AccountToken = loginResponse.Token
            };

            await TestExpector.ExpectUCenterErrorAsync(
                UCenterErrorCode.AppNotExists,
                async() => { await asClient.AccountLoginAppAsync(accountLoginAppInfo); });
        }
        public async Task <IActionResult> AccountLogin(string appId, [FromBody] AccountLoginAppInfo info, CancellationToken token)
        {
            var account = await this.GetAndVerifyAccount(info.AccountId, info.AccountToken, token);

            this.CheckAppPermission(appId, info.AppSecret);

            var result = new AccountLoginAppResponse();

            result.AccountId         = account.Id;
            result.AccountName       = account.AccountName;
            result.AccountToken      = account.Token;
            result.LastLoginDateTime = account.LastLoginDateTime;

            var dataId      = this.GetAppAccountDataId(info.AppId, info.AccountId);
            var accountData = await this.Database.AppAccountDatas.GetSingleAsync(dataId, token);

            if (accountData != null)
            {
                result.AccountData = accountData.Data;
            }

            return(this.CreateSuccessResult(result));
        }
Ejemplo n.º 7
0
        //---------------------------------------------------------------------
        async Task _c2sAccountRequest(AccountRequest account_request)
        {
            switch (account_request.id)
            {
                case AccountRequestId.LoginIM:// 请求登录IM
                    {
                        var loginim_request = EbTool.protobufDeserialize<ClientLoginIMRequest>(MemoryStream, account_request.data);

                        string info = string.Format("ClientLoginIM\nAccId={0}, AccName={1}, Token={2}",
                            loginim_request.acc_id, loginim_request.acc_name, loginim_request.token);
                        Logger.Info(info);

                        ClientLoginIMResponse loginim_response = new ClientLoginIMResponse();
                        loginim_response.result = IMProtocolResult.Failed;

                        AccountLoginAppInfo acc_login_app_info = new AccountLoginAppInfo();
                        acc_login_app_info.AppId = UCenterAppId;
                        acc_login_app_info.AppSecret = UCenterAppSecret;
                        acc_login_app_info.AccountId = loginim_request.acc_id;
                        acc_login_app_info.AccountToken = loginim_request.token;

                        // 去UCenter验证Account
                        //AccountLoginAppResponse acc_login_app_response = null;
                        //try
                        //{
                        //    acc_login_app_response = await IMContext.Instance.UCenterSDK.AccountLoginAppAsync(acc_login_app_info);
                        //}
                        //catch (Exception ex)
                        //{
                        //    Logger.Info(ex.ToString());
                        //    loginim_response.result = IMProtocolResult.LoginAccountVerifyFailed;
                        //    goto EndLoginIM;
                        //}

                        // 检测Token是否过期
                        //TimeSpan ts = app_verifyaccount_response.now_dt - app_verifyaccount_response.last_login_dt;
                        // if (ts.TotalSeconds > 60)
                        // {
                        //     enterworld_response.result = ProtocolResult.EnterWorldTokenExpire;
                        //     goto End;
                        // }

                        loginim_response.result = IMProtocolResult.Success;

                        //EndLoginIM:
                        AccId = loginim_request.acc_id;
                        Token = loginim_request.token;
                        AccName = loginim_request.acc_name;
                        GrainPlayerKey = string.Empty;

                        //if (loginim_response.result == IMProtocolResult.Success)
                        //{
                        //    AccId = loginim_request.acc_id;
                        //    Token = loginim_request.token;
                        //    AccName = loginim_request.acc_name;
                        //    GrainPlayerGuid = Guid.Empty;
                        //}
                        //else
                        //{
                        //    AccId = string.Empty;
                        //    Token = string.Empty;
                        //    AccName = string.Empty;
                        //    GrainPlayerGuid = Guid.Empty;
                        //}

                        AccountNotify account_notify;
                        account_notify.id = AccountNotifyId.LoginIM;
                        account_notify.data = EbTool.protobufSerialize<ClientLoginIMResponse>(MemoryStream, loginim_response);

                        MethodInfo methodInfo;
                        methodInfo.id = (ushort)IMMethodType.AccountNotify;
                        methodInfo.data = EbTool.protobufSerialize<AccountNotify>(MemoryStream, account_notify);

                        ((IGrainClientProxy)this).Notify(methodInfo);
                    }
                    break;
                case AccountRequestId.EnterWorld:// 请求进入游戏世界
                    {
                        ClientEnterWorldResponse enterworld_response = null;

                        if (string.IsNullOrEmpty(AccId))
                        {
                            Logger.Error((int)IMErrorCode.ClientEnterWorld, "ClientEnterWorld Error Not Login!");

                            enterworld_response = new ClientEnterWorldResponse();
                            enterworld_response.result = IMProtocolResult.Failed;
                            goto EndEnterWorld;
                        }

                        var enterworld_request = EbTool.protobufDeserialize<ClientEnterWorldRequest>(MemoryStream, account_request.data);

                        string info = string.Format("ClientEnterWorld\nAccId={0}, IMAppId={1}, IMAppChannel={2}",
                            enterworld_request.acc_id, enterworld_request.imapp_id, enterworld_request.imapp_channel);
                        Logger.Info(info);

                        if (AccId != enterworld_request.acc_id || Token != enterworld_request.token)
                        {
                            Logger.Error((int)IMErrorCode.ClientEnterWorld, "ClientEnterWorld Error AccId or Token!");

                            enterworld_response = new ClientEnterWorldResponse();
                            enterworld_response.result = IMProtocolResult.Failed;
                            goto EndEnterWorld;
                        }

                        // 检测IM中存贮的IMAppID+AccId对应的IMAppAccountData
                        var grain_service_appproxy = GrainFactory.GetGrain<IGrainAppProxyService>(0);
                        string player_guid = await grain_service_appproxy.GetPlayer(enterworld_request.imapp_id, enterworld_request.imapp_channel, enterworld_request.acc_id);

                        if (string.IsNullOrEmpty(player_guid))
                        {
                            Logger.Error((int)IMErrorCode.ClientEnterWorld, "ClientEnterWorld Error Not Create Player!");

                            enterworld_response = new ClientEnterWorldResponse();
                            enterworld_response.result = IMProtocolResult.EnterWorldNotExistPlayer;
                            goto EndEnterWorld;
                        }

                        // 角色进入游戏
                        GrainPlayerKey = string.Format("{0}_{1}", IMAppId, player_guid);
                        var grain_player = GrainFactory.GetGrain<IGrainPlayer>(GrainPlayerKey);
                        enterworld_response = await grain_player.ClientEnterWorld(GrainClientKey);
                        if (enterworld_response.result == IMProtocolResult.Success)
                        {
                            IMAppId = enterworld_request.imapp_id;
                            IMAppChannel = enterworld_request.imapp_channel;
                        }
                        else
                        {
                            Logger.Error((int)IMErrorCode.ClientEnterWorld, "ClientEnterWorld Error EnterWorld Failed!");

                            IMAppId = string.Empty;
                            IMAppChannel = string.Empty;
                            GrainPlayerKey = string.Empty;
                        }

                    EndEnterWorld:
                        AccountNotify account_notify;
                        account_notify.id = AccountNotifyId.EnterWorld;
                        account_notify.data = EbTool.protobufSerialize<ClientEnterWorldResponse>(MemoryStream, enterworld_response);

                        MethodInfo methodInfo;
                        methodInfo.id = (ushort)IMMethodType.AccountNotify;
                        methodInfo.data = EbTool.protobufSerialize<AccountNotify>(MemoryStream, account_notify);

                        ((IGrainClientProxy)this).Notify(methodInfo);
                    }
                    break;
                default:
                    break;
            }
        }