public async Task E2E_AppServer_ReadAccountData_And_WriteAccountData_Test() { var registerResponse = await CreateTestAccount(); var loginResponse = await cClient.AccountLoginAsync(new AccountLoginInfo { AccountName = registerResponse.AccountName, Password = ValidAccountPassword }); var data = @"{ 'id': 1, 'name': 'abc'}"; var accountData = new AppAccountDataInfo { AppId = TestAppId, AppSecret = TestAppSecret, AccountId = loginResponse.AccountId, Data = data }; await sClient.AppWriteAccountDataAsync(accountData); var result = await sClient.AppReadAccountDataAsync(accountData); Assert.AreEqual(accountData.AppId, result.AppId); Assert.AreEqual(accountData.AccountId, result.AccountId); Assert.AreEqual(accountData.Data, result.Data); }
public async Task <IActionResult> WriteAccountData(string appId, [FromBody] AppAccountDataInfo info, CancellationToken token) { this.CheckAppPermission(appId, info.AppSecret); var account = await this.GetAndVerifyAccount(info.AccountId, token); var dataId = this.GetAppAccountDataId(info.AppId, info.AccountId); var accountData = await this.Database.AppAccountDatas.GetSingleAsync(dataId, token); if (accountData != null) { accountData.Data = info.Data; } else { accountData = new AppAccountDataEntity { Id = dataId, AppId = info.AppId, AccountId = info.AccountId, Data = info.Data }; } await this.Database.AppAccountDatas.UpsertAsync(accountData, token); var response = new AppAccountDataResponse { AppId = info.AppId, AccountId = info.AccountId, Data = accountData.Data }; return(this.CreateSuccessResult(response)); }
/// <summary> /// Write application data. /// </summary> /// <param name="info">Indicating the application information.</param> /// <returns>Async response.</returns> public async Task <AppAccountDataResponse> AppWriteAccountDataAsync(AppAccountDataInfo info) { string url = this.GenerateApiEndpoint("apps", $"{info.AppId}/writedata"); var response = await this.httpClient.SendAsyncWithException <AppAccountDataInfo, AppAccountDataResponse>( HttpMethod.Post, url, info); return(response); }
//--------------------------------------------------------------------- public async Task <AppAccountDataResponse> AppReadAccountDataAsync(AppAccountDataInfo info) { string url = GenerateApiEndpoint("app", "readdata"); var response = await httpClient.SendAsyncWithException <AppAccountDataInfo, AppAccountDataResponse>(HttpMethod.Post, url, info); return(response); }
public async Task <IActionResult> ReadAccountData(string appId, [FromBody] AppAccountDataInfo info, CancellationToken token) { this.CheckAppPermission(appId, info.AppSecret); var dataId = this.GetAppAccountDataId(info.AppId, info.AccountId); var accountData = await this.Database.AppAccountDatas.GetSingleAsync(dataId, token); var response = new AppAccountDataResponse { AppId = info.AppId, AccountId = info.AccountId, Data = accountData?.Data }; return(this.CreateSuccessResult(response)); }
public async Task E2E_AppServer_ReadAccountData_IncorrectAppSecret_Test() { var registerResponse = await CreateTestAccount(); var loginResponse = await cClient.AccountLoginAsync(new AccountLoginInfo { AccountName = registerResponse.AccountName, Password = ValidAccountPassword }); var accountData = new AppAccountDataInfo { AppId = TestAppId, AppSecret = InvalidAppSecret, AccountId = loginResponse.AccountId }; TestExpector.ExpectUCenterErrorAsync(UCenterErrorCode.AppAuthFailedSecretNotMatch, async() => { await sClient.AppReadAccountDataAsync(accountData); }); }
public async Task <IHttpActionResult> ReadAppAccountData(AppAccountDataInfo info, CancellationToken token) { CustomTrace.TraceInformation($"App.ReadAppAccountData AppId={info.AppId} AccountId={info.AccountId}"); await this.VerifyApp(info.AppId, info.AppSecret, token); var account = await this.GetAndVerifyAccount(info.AccountId, token); var dataId = this.CreateAppAccountDataId(info.AppId, info.AccountId); var accountData = await this.Database.AppAccountDatas.GetSingleAsync(dataId, token); var response = new AppAccountDataResponse { AppId = info.AppId, AccountId = info.AccountId, Data = accountData?.Data }; return(this.CreateSuccessResult(response)); }
public async Task <IHttpActionResult> ReadAppAccountData(AppAccountDataInfo info) { Logger.Info($"App.ReadAppAccountData AppId={info.AppId} AccountId={info.AccountId}"); await VerifyApp(info.AppId, info.AppSecret); var account = await this.GetAndVerifyAccount(info.AccountId); var dataId = this.CreateAppAccountDataId(info.AppId, info.AccountId); var accountData = await DatabaseContext.Bucket.GetByEntityIdSlimAsync <AppAccountDataEntity>(dataId); var response = new AppAccountDataResponse { AppId = info.AppId, AccountId = info.AccountId, Data = accountData?.Data }; return(CreateSuccessResult(response)); }
public async Task E2E_AppServer_ReadAccountData_IncorrectAppSecret_Test() { var registerResponse = await CreateTestAccount(); var loginResponse = await acClient.AccountLoginAsync(new AccountLoginInfo { AccountName = registerResponse.AccountName, Password = ValidAccountPassword, Device = TestDevice }); var accountData = new AppAccountDataInfo { AppId = TestAppId, AppSecret = InvalidAppSecret, AccountId = loginResponse.AccountId }; await TestExpector.ExpectUCenterErrorAsync( UCenterErrorCode.AppTokenUnauthorized, async() => { await asClient.AppReadAccountDataAsync(accountData); }); }
public async Task E2E_AppServer_WriteAccountData_InvalidAppSecret_Test() { var registerResponse = await CreateTestAccount(); var loginResponse = await acClient.AccountLoginAsync(new AccountLoginInfo { AccountName = registerResponse.AccountName, Password = ValidAccountPassword }); var data = @"{ 'id': 1, 'name': 'abc'}"; var accountData = new AppAccountDataInfo { AppId = TestAppId, AppSecret = InvalidAppSecret, AccountId = loginResponse.AccountId, Data = data }; await TestExpector.ExpectUCenterErrorAsync(UCenterErrorCode.AppAuthFailedSecretNotMatch, async() => { await asClient.AppWriteAccountDataAsync(accountData); }); }
public async Task <IHttpActionResult> WriteAppAccountData(AppAccountDataInfo info, CancellationToken token) { CustomTrace.TraceInformation($"App.WriteAppAccountData AppId={info.AppId} AccountId={info.AccountId}"); await this.VerifyApp(info.AppId, info.AppSecret, token); var account = await this.GetAndVerifyAccount(info.AccountId, token); var dataId = this.CreateAppAccountDataId(info.AppId, info.AccountId); var accountData = await this.Database.AppAccountDatas.GetSingleAsync(dataId, token); if (accountData != null) { accountData.Data = info.Data; } else { accountData = new AppAccountDataEntity { Id = dataId, AppId = info.AppId, AccountId = info.AccountId, Data = info.Data }; } await this.Database.AppAccountDatas.UpsertAsync(accountData, token); var response = new AppAccountDataResponse { AppId = info.AppId, AccountId = info.AccountId, Data = accountData.Data }; return(this.CreateSuccessResult(response)); }
public async Task <IHttpActionResult> WriteAppAccountData(AppAccountDataInfo info) { Logger.Info($"App.WriteAppAccountData AppId={info.AppId} AccountId={info.AccountId}"); await VerifyApp(info.AppId, info.AppSecret); var account = await this.GetAndVerifyAccount(info.AccountId); var dataId = this.CreateAppAccountDataId(info.AppId, info.AccountId); var accountData = await DatabaseContext.Bucket.GetByEntityIdSlimAsync <AppAccountDataEntity>(dataId); if (accountData != null) { accountData.Data = info.Data; } else { accountData = new AppAccountDataEntity { Id = dataId, AppId = info.AppId, AccountId = info.AccountId, Data = info.Data }; } await DatabaseContext.Bucket.UpsertSlimAsync(accountData); var response = new AppAccountDataResponse { AppId = info.AppId, AccountId = info.AccountId, Data = accountData.Data }; return(CreateSuccessResult(response)); }
//--------------------------------------------------------------------- // 客户端请求 async Task <MethodData> ICellClientService.c2sRequest(MethodData method_data) { MethodData result = new MethodData(); result.method_id = MethodType.None; var account_request = EbTool.protobufDeserialize <AccountRequest>(method_data.param1); switch (account_request.id) { case AccountRequestId.EnterWorld: // 请求进入游戏世界 { var enterworld_request = EbTool.protobufDeserialize <ClientEnterWorldRequest>(account_request.data); string info = string.Format("客户端请求进入游戏世界\nAccId={0}, AccName={1}, Token={2}", enterworld_request.acc_id, enterworld_request.acc_name, enterworld_request.token); Logger.Info(info); ClientEnterWorldResponse enterworld_response = new ClientEnterWorldResponse(); enterworld_response.result = ProtocolResult.Failed; enterworld_response.acc_id = enterworld_request.acc_id; enterworld_response.acc_name = enterworld_request.acc_name; enterworld_response.token = enterworld_request.token; AppVerifyAccountInfo app_verifyaccount_request = new AppVerifyAccountInfo(); app_verifyaccount_request.AppId = ConfigurationManager.AppSettings["UCenterAppId"]; app_verifyaccount_request.AppSecret = ConfigurationManager.AppSettings["UCenterAppSecret"]; app_verifyaccount_request.AccountId = enterworld_request.acc_id; app_verifyaccount_request.AccountToken = enterworld_request.token; // 去UCenter验证Account AppVerifyAccountResponse app_verifyaccount_response = null; try { app_verifyaccount_response = await CoUCenterSDK.AppVerifyAccountAsync(app_verifyaccount_request); } catch (Exception ex) { Logger.Info(ex.ToString()); enterworld_response.result = ProtocolResult.EnterWorldAccountVerifyFailed; goto End; } // 去UCenter获取Account对应的AppData AppAccountDataResponse app_data_response = null; try { AppAccountDataInfo app_data_info = new AppAccountDataInfo(); app_data_info.AppId = app_verifyaccount_request.AppId; app_data_info.AppSecret = app_verifyaccount_request.AppSecret; app_data_info.AccountId = app_verifyaccount_request.AccountId; app_data_info.Data = null; app_data_response = await CoUCenterSDK.AppReadAccountDataAsync(app_data_info); } catch (Exception ex) { Logger.Info(ex.ToString()); enterworld_response.result = ProtocolResult.EnterWorldAccountVerifyFailed; goto End; } // 检测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; //} // PlayerEtGuid string new_player_etguid = ""; if (app_data_response != null && !string.IsNullOrEmpty(app_data_response.Data)) { var data_read = EbTool.jsonDeserialize <Dictionary <string, string> >(app_data_response.Data); new_player_etguid = data_read["player_etguid"]; } if (string.IsNullOrEmpty(new_player_etguid)) { // 玩家角色未创建 new_player_etguid = Guid.NewGuid().ToString(); // 去UCenter写入Account对应的AppData try { Dictionary <string, string> data_write = new Dictionary <string, string>(); data_write["player_etguid"] = new_player_etguid; AppAccountDataInfo app_data_info = new AppAccountDataInfo(); app_data_info.AppId = app_verifyaccount_request.AppId; app_data_info.AppSecret = app_verifyaccount_request.AppSecret; app_data_info.AccountId = app_verifyaccount_request.AccountId; app_data_info.Data = EbTool.jsonSerialize(data_write); await CoUCenterSDK.AppWriteAccountDataAsync(app_data_info); } catch (Exception ex) { Logger.Info(ex.ToString()); enterworld_response.result = ProtocolResult.EnterWorldAccountVerifyFailed; goto End; } } NewPlayerInfo new_player_info = new NewPlayerInfo(); new_player_info.account_id = enterworld_request.acc_id; new_player_info.account_name = enterworld_request.acc_name; new_player_info.gender = true; new_player_info.is_bot = false; new_player_info.et_player_guid = new_player_etguid; // 角色进入游戏 ICellPlayer grain_player = GrainFactory.GetGrain <ICellPlayer>(new Guid(new_player_etguid)); enterworld_response.et_player_data = await grain_player.c2sEnterWorld(new_player_info); enterworld_response.result = ProtocolResult.Success; End: Ps.AccountResponse account_response; account_response.id = AccountResponseId.EnterWorld; account_response.data = EbTool.protobufSerialize <ClientEnterWorldResponse>(enterworld_response); result.method_id = MethodType.s2cAccountResponse; result.param1 = EbTool.protobufSerialize <Ps.AccountResponse>(account_response); } break; default: break; } return(result); }