|
|
@@ -13,6 +13,7 @@ public class UserPlayer : JCEntity
|
|
|
ins = this;
|
|
|
components.Add("PKComp", PKComp.Instance);
|
|
|
components.Add("UserComp", UserComp.Instance);
|
|
|
+ GetUserInfo();
|
|
|
}
|
|
|
public static void ConnectServer() {
|
|
|
if (ins != null) return;
|
|
|
@@ -67,6 +68,7 @@ public class UserPlayer : JCEntity
|
|
|
}
|
|
|
|
|
|
public override void onDestroy() {
|
|
|
+ loginAuthed = false;
|
|
|
Debug.Log("UserPlayer onDestroy()");
|
|
|
if (canReconnnect) {
|
|
|
JCUnityLib.CoroutineStarter.Start(ReconnenctServer());
|
|
|
@@ -96,46 +98,30 @@ public class UserPlayer : JCEntity
|
|
|
}
|
|
|
|
|
|
//被服务端调用的函数
|
|
|
+ public bool loginAuthed;
|
|
|
public void onAuthRes(bool res) {
|
|
|
Debug.Log("onAuthRes," + res);
|
|
|
- if (res) {
|
|
|
- JCUnityLib.CoroutineStarter.Start(RequestUserInfoAvoidFail());
|
|
|
- } else {
|
|
|
- handleAuthExpire();
|
|
|
- }
|
|
|
+ loginAuthed = res;
|
|
|
+ if (!loginAuthed) handleAuthExpire();
|
|
|
}
|
|
|
- public void RetryRequestUserInfoAvoidFail()
|
|
|
- {
|
|
|
- _hasExecuteRequestUserInfoAvoidFail = false;
|
|
|
- _getUserInfoRetryCount = -1;
|
|
|
- _getUserInfoFailed = false;
|
|
|
- JCUnityLib.CoroutineStarter.Start(RequestUserInfoAvoidFail());
|
|
|
- }
|
|
|
- //获取用户信息,超时了就重试
|
|
|
- private bool _hasExecuteRequestUserInfoAvoidFail = false;
|
|
|
- private int _getUserInfoRetryCount = -1;
|
|
|
- private bool _getUserInfoFailed = false;
|
|
|
- IEnumerator RequestUserInfoAvoidFail()
|
|
|
+ //获取用户信息,失败了就重试
|
|
|
+ public void GetUserInfo()
|
|
|
{
|
|
|
- if (_hasExecuteRequestUserInfoAvoidFail) yield break;
|
|
|
- _hasExecuteRequestUserInfoAvoidFail = true;
|
|
|
- while (!_hasGetUserInfo && ins == this) {
|
|
|
- if (++_getUserInfoRetryCount <= 3) {
|
|
|
- UserComp.Instance.getUserInfo(DoAfterGetUserInfo);
|
|
|
- if (_getUserInfoRetryCount > 0)
|
|
|
- AuthLoginMask.ins?.SetRetryCount(_getUserInfoRetryCount);
|
|
|
- yield return new WaitForSeconds(3.3f);
|
|
|
- } else {
|
|
|
- _getUserInfoFailed = true;
|
|
|
- AuthLoginMask.ins?.SetAutoRetryFail();
|
|
|
- yield break;
|
|
|
+ UserPlayer userPlayer = this;
|
|
|
+ CoroutineStarter.Start(LoginController.Instance.GetUserInfo((res) =>
|
|
|
+ {
|
|
|
+ if (ins != userPlayer) return;
|
|
|
+ if (res.code == 0)
|
|
|
+ {
|
|
|
+ UserInfo userInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<UserInfo>(res.data as string);
|
|
|
+ DoAfterGetUserInfo(userInfo);
|
|
|
}
|
|
|
- }
|
|
|
+ else AuthLoginMask.ins?.SetAutoRetryFail();
|
|
|
+ }));
|
|
|
}
|
|
|
private bool _hasGetUserInfo = false;
|
|
|
private void DoAfterGetUserInfo(UserInfo userInfo)
|
|
|
{
|
|
|
- if (_getUserInfoFailed) return; //主要是为了避免提示了(网络异常后请稍后再试),又突然可以了
|
|
|
if (_hasGetUserInfo) return;
|
|
|
_hasGetUserInfo = true;
|
|
|
LoginMgr.myUserInfo = userInfo;
|