备份CatanBuilding瘦身独立工程
This commit is contained in:
219
Assets/Scripts/Services/AggUserService.cs
Normal file
219
Assets/Scripts/Services/AggUserService.cs
Normal file
@@ -0,0 +1,219 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using asap.core;
|
||||
using tysdk;
|
||||
|
||||
namespace game
|
||||
{
|
||||
public class LoginTypeEvt
|
||||
{
|
||||
public TaskCompletionSource<EAccoutType> loginType = new TaskCompletionSource<EAccoutType>();
|
||||
}
|
||||
|
||||
public class AggUserService : PlayFabUserService
|
||||
{
|
||||
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<ELoginStep> Login(Action<int> progress)
|
||||
{
|
||||
if (IsLogin)
|
||||
{
|
||||
progress?.Invoke(3);
|
||||
return ELoginStep.Done;
|
||||
}
|
||||
|
||||
UnityEngine.Debug.Log("AggUserService Login");
|
||||
|
||||
|
||||
LoginInfo loginInfo = new LoginInfo();
|
||||
if (!TYSdkFacade.IsLoggedIn)
|
||||
{
|
||||
loginInfo = await TYSdkFacade.Instance.LoginByToken();
|
||||
if (!loginInfo.isSuccess)
|
||||
{
|
||||
var evt = new LoginTypeEvt();
|
||||
GContext.Publish(evt);
|
||||
var loginType = await evt.loginType.Task;
|
||||
loginInfo = await TYSdkFacade.Instance.Login(loginType);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
loginInfo.isSuccess = true;
|
||||
loginInfo.userId = TYSdkFacade.TYAccountInfo.userId;
|
||||
}
|
||||
|
||||
if (!loginInfo.isSuccess) return ELoginStep.Sdk;
|
||||
|
||||
progress.Invoke(1);
|
||||
|
||||
CustomId = loginInfo.StrUserId;
|
||||
|
||||
|
||||
OnInitData += InitData;
|
||||
|
||||
var step = await base.Login(step => progress?.Invoke(step + 1));
|
||||
if (step != ELoginStep.Done)
|
||||
{
|
||||
OnInitData -= InitData;
|
||||
return step;
|
||||
}
|
||||
|
||||
OnInitData -= InitData;
|
||||
|
||||
GEvent.SetProps(new Dictionary<string, object>(){
|
||||
{"pf_id", UserId},
|
||||
{"CreateTime",CreateTime.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss")}
|
||||
});
|
||||
|
||||
GEvent.SetUserProps(new Dictionary<string, object>(){
|
||||
{"pf_id", UserId},
|
||||
{"CreateTime",CreateTime.ToString("yyyy-MM-dd HH:mm:ss")}
|
||||
});
|
||||
|
||||
AvatarToPF(TYSdkFacade.TYAccountInfo);
|
||||
|
||||
GEvent.OnLogin(UserId, CustomId);
|
||||
|
||||
if (config.Get<bool>("NewlyCreated", false))
|
||||
{
|
||||
using (var e = GEvent.CompleteRegistrationEvent())
|
||||
{
|
||||
e.AddContent("login_type", TYSdkFacade.TYAccountInfo.channel.ToString());
|
||||
}
|
||||
|
||||
GEvent.SetProps(new Dictionary<string, object>(){
|
||||
{"vip_level", 0}
|
||||
});
|
||||
|
||||
GEvent.SetUserProps(new Dictionary<string, object>(){
|
||||
{"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<string, object>()
|
||||
{
|
||||
{"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;
|
||||
}
|
||||
|
||||
|
||||
public override void Logout()
|
||||
{
|
||||
TYSdkFacade.Instance.Logout();
|
||||
base.Logout();
|
||||
}
|
||||
|
||||
public override async Task<bool> GetLinkState(EAccoutType accoutType)
|
||||
{
|
||||
return await TYSdkFacade.Instance.LinkCheck(accoutType);
|
||||
}
|
||||
|
||||
public override async Task<bool> LinkAccount(EAccoutType accoutType)
|
||||
{
|
||||
bool result = await TYSdkFacade.Instance.LinkAccount(accoutType);
|
||||
if (result)
|
||||
{
|
||||
var _accountInfo = TYSdkFacade.TYAccountInfo;
|
||||
if (_accountInfo != null)
|
||||
{
|
||||
AvatarToPF(_accountInfo);
|
||||
if (_accountInfo.channel == EAccoutType.hwFacebook)
|
||||
{
|
||||
_ = UpdateAvatarUrl(_accountInfo.avatar);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void InitData(IDictionary<string, string> 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");
|
||||
PlayFabMgr.Instance.UpdateUserDataValue(channel, "1");
|
||||
}
|
||||
}
|
||||
|
||||
if (data.TryGetValue("EAccoutUrl", out var data_value))
|
||||
{
|
||||
EAccoutUrl = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, string>>(data_value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user