using System; using System.Collections.Generic; using System.Threading.Tasks; using asap.core; using tysdk; using System.Linq; using game.PlayerDataStorage; namespace game { public class AggKvUserService : KvUserService { private bool channelLoginRunning; protected override string NewPlayerName { get { if (TYSdkFacade.TYAccountInfo == null) { return base.NewPlayerName; } if (TYSdkFacade.TYAccountInfo.channel == EAccoutType.hwFacebook || TYSdkFacade.TYAccountInfo.channel == EAccoutType.hwGoogle) { if (!string.IsNullOrEmpty(TYSdkFacade.TYAccountInfo.userName)) { return TYSdkFacade.TYAccountInfo.userName; } } return base.NewPlayerName; } } protected override string NewPlayerAvatar { get { if (TYSdkFacade.TYAccountInfo == null) { return base.NewPlayerAvatar; } if (TYSdkFacade.TYAccountInfo.channel == EAccoutType.hwFacebook /*|| TYSdkFacade.TYAccountInfo.channel == EAccoutType.hwGoogle*/) { if (!string.IsNullOrEmpty(TYSdkFacade.TYAccountInfo.avatar)) { return TYSdkFacade.TYAccountInfo.avatar; } } return base.NewPlayerAvatar; } } public override async Task Login(Action progress, bool tryLoginByToken = true) { if (channelLoginRunning || LoginLifetime.IsCancellationRequested) { return ELoginStep.Sdk; } channelLoginRunning = true; try { if (IsLogin) { progress?.Invoke(3); return ELoginStep.Done; } UnityEngine.Debug.Log("AggUserService Login"); LoginInfo loginInfo = new LoginInfo(); if (!TYSdkFacade.IsLoggedIn) { loginInfo = await TYSdkFacade.Instance.LoginBySns(); if (LoginLifetime.IsCancellationRequested) { return ELoginStep.Sdk; } if (!loginInfo.isSuccess && tryLoginByToken) { loginInfo = await TYSdkFacade.Instance.LoginByToken(); if (LoginLifetime.IsCancellationRequested) { return ELoginStep.Sdk; } } if (!loginInfo.isSuccess) { var evt = new LoginTypeEvt(); GContext.Publish(evt); var loginType = await evt.loginType.Task; if (LoginLifetime.IsCancellationRequested) { return ELoginStep.Sdk; } loginInfo = await TYSdkFacade.Instance.Login(loginType); if (LoginLifetime.IsCancellationRequested) { return ELoginStep.Sdk; } } } else { loginInfo.isSuccess = true; loginInfo.userId = TYSdkFacade.TYAccountInfo.userId; } if (!loginInfo.isSuccess) { return ELoginStep.Sdk; } progress.Invoke(1); CustomId = loginInfo.StrUserId; var step = await base.Login(step => progress?.Invoke(step + 1)); if (LoginLifetime.IsCancellationRequested) { return ELoginStep.Api; } if (step != ELoginStep.Done) { return step; } if (ChannelManager.IsRustoreStore) { GEvent.SetProp("sdk_channel", "ru_store"); } GEvent.SetProps(new Dictionary() { {"pf_id", UserId}, {"CreateTime",CreateTime.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss")} }); GEvent.SetUserProps(new Dictionary() { {"pf_id", UserId}, {"CreateTime",CreateTime.ToString("yyyy-MM-dd HH:mm:ss")} }); AvatarToKV(TYSdkFacade.TYAccountInfo); GEvent.OnLogin(UserId, CustomId); if (config.Get("NewlyCreated", false)) { using (var e = GEvent.CompleteRegistrationEvent()) { e.AddContent("login_type", TYSdkFacade.TYAccountInfo.channel.ToString()); } GEvent.SetProps(new Dictionary() { {"vip_level", 0} }); GEvent.SetUserProps(new Dictionary() { {"vip_level", 0}, {"total_consumption", 0} }); if (AFHelper.Instance.GetDLReferer(out var pid, out var uid)) { UnityEngine.Debug.Log("[AggUserService] deeplink referer:" + pid + " " + uid); using (var e = GEvent.GameEvent("deeplink_invited")) { e.AddContent("referrer_uid", uid); e.AddContent("referrer_pid", pid); } var refererData = new Dictionary() { {"refererPid", pid}, {"refererUid", uid}, {"playerUid", CustomId} }; _ = customServerMgr.CustomServerPost("friend/RecoreReferer", Newtonsoft.Json.JsonConvert.SerializeObject(refererData)); } } using (var e = GEvent.LoginEvent()) { e.AddContent("login_type", TYSdkFacade.TYAccountInfo.channel.ToString()); e.AddContent("display_name", DisplayName); e.AddContent("avatar_url", AvatarUrl); e.AddContent("linkedAccout", string.Join('#', TYSdkFacade.TYAccountInfo.linkedAccout)); } return step; } finally { channelLoginRunning = false; } } public override void Logout() { TYSdkFacade.Instance.Logout(); base.Logout(); } public override async Task GetLinkState(EAccoutType accoutType) { return await TYSdkFacade.Instance.LinkCheck(accoutType); } public override async Task<(int code, int userid)> LinkAccount(EAccoutType accoutType) { var linkResult = await TYSdkFacade.Instance.LinkAccount(accoutType); if (linkResult.code == 0 && !LoginLifetime.IsCancellationRequested) { var _accountInfo = TYSdkFacade.TYAccountInfo; if (_accountInfo != null) { AvatarToKV(_accountInfo); if (_accountInfo.channel == EAccoutType.hwFacebook) { _ = UpdateAvatarUrl(_accountInfo.avatar); } } } return (linkResult.code, linkResult.userId); } protected override void InitData(IDictionary data) { if (data.TryGetValue(EAccoutType.hwGoogle.ToString(), out var google) && google == "1") { TYSdkFacade.TYAccountInfo.linkedAccout.Add(EAccoutType.hwGoogle); } if (data.TryGetValue(EAccoutType.hwFacebook.ToString(), out var facebook) && facebook == "1") { TYSdkFacade.TYAccountInfo.linkedAccout.Add(EAccoutType.hwFacebook); } if (data.TryGetValue(EAccoutType.Apple.ToString(), out var apple) && apple == "1") { TYSdkFacade.TYAccountInfo.linkedAccout.Add(EAccoutType.Apple); } if (TYSdkFacade.TYAccountInfo.channel != EAccoutType.hwGuest && TYSdkFacade.TYAccountInfo.channel != EAccoutType.none) { var channel = TYSdkFacade.TYAccountInfo.channel.ToString(); if (!data.ContainsKey(channel)) { data.Add(channel, "1"); SaveStore.Write(channel, "1").RequireAccepted(); } } if (data.TryGetValue("EAccoutUrl", out var data_value)) { EAccoutUrl = Newtonsoft.Json.JsonConvert.DeserializeObject>(data_value); } } } }