Exemple #1
0
        public void SelectZone(Action success, Action <string> error = null)
        {
            this.GatewayUrl = null;
            SendTo(LoginUrl, new RequestSelectZone()
            {
            }, (WWW www) =>
            {
                var recv = HttpPackageReturn <RequestSelectZoneReturn> .Create(www, this);
                if (recv == null)
                {
                    var msg = string.Format("[WWW] ERROR {0} {1}\n{2}", LoginUrl, www.error, www.text);
                    if (error == null)
                    {
                        Debug.LogError(msg);
                    }
                    else
                    {
                        error(msg);
                    }
                    return;
                }
                if (recv.errno == HttpReturnCode.HttpReturnCode_SignError)
                {
                    Login(login => SelectZone(success, error), error);
                    return;
                }
                this.GatewayUrl = recv.data.gatewayurl;

                if (success != null)
                {
                    success();
                }
            });
        }
Exemple #2
0
        /// <summary>
        /// LoginServer登陆,需要预先设置PlatInfo
        /// </summary>
        /// <param name="success"></param>
        /// <param name="error"></param>
        public void Login(Action <Pmd.PlatTokenLoginReturn> success, Action <string> error = null)
        {
            var platinfo = PlatInfoFactory();

            if (platinfo == null)
            {
                var msg = "[WWW] ERROR PlatInfo is null";
                if (error == null)
                {
                    Debug.LogError(msg);
                }
                else
                {
                    error(msg);
                }
                return;
            }

            // 清除上次平台登录痕迹
            this.GatewayUrl = null;
            this.TimeZone   = 0;
            this.ResetSession();

            SendTo(LoginUrl, new Pmd.PlatTokenLogin()
            {
                platinfo = platinfo
            }, (WWW www) =>
            {
                var recv = HttpPackageReturn <Pmd.PlatTokenLoginReturn> .Create(www, this);
                if (recv == null || recv.errno == Pmd.HttpReturnCode.HttpReturnCode_SignError)
                {
                    var msg = string.Format("[WWW] ERROR {0} {1}\n{2}", LoginUrl, www.error, www.text);
                    if (error == null)
                    {
                        Debug.LogError(msg);
                    }
                    else
                    {
                        error(msg);
                    }
                    return;
                }

                this.TimeZone = recv.data.timezone_offset;

                // session更新
                this.UID              = recv.data.uid;
                this.SID              = recv.data.sid;
                this.PlatKey          = recv.data.unigame_plat_key;
                this.PlatToken        = recv.data.unigame_plat_login;
                this.PlatTokenTimeout = DateTime.Now + TimeSpan.FromSeconds(recv.data.unigame_plat_login_life);
                this.Serialize();

                if (success != null)
                {
                    success(recv.data);
                }
            });
        }
Exemple #3
0
 public void RequestLoginUserInfo(Action <Pmd.RequestUserZoneInfoLoginUserPmd_S> userInfo)
 {
     SendTo(LoginUrl, new Pmd.RequestUserZoneInfoLoginUserPmd_C()
     {
         gameid = GameID
     }, (WWW www) =>
     {
         var recv = HttpPackageReturn <Pmd.RequestUserZoneInfoLoginUserPmd_S> .Create(www, this);
         if (recv != null && userInfo != null)
         {
             userInfo(recv.data);
         }
     });
 }
Exemple #4
0
        /// <summary>
        /// 发送消息,可自动填充平台必要字段
        /// </summary>
        /// <param name="message"></param>
        /// <param name="success"></param>
        /// <returns></returns>
        protected void SendMessage <TResponse>(object message, Action <TResponse> success, Action <string> error)
        {
            // 确保平台登陆有效
            if (HasSession() == false)
            {
                Deserialize();
                if (HasSession() == false)
                {
                    Login(login => SendMessage(message, success, error), error);
                    return;
                }
            }

            // 选区以确保网关地址有效
            if (string.IsNullOrEmpty(GatewayUrl))
            {
                SelectZone(() => SendMessage(message, success, error), error);
                return;
            }

            // 向unilight逻辑服务器发送消息
            SendTo(GatewayUrl, message, (WWW www) =>
            {
                var recv = HttpPackageReturn <TResponse> .Create(www, this);
                if (recv == null)
                {
                    var msg = string.Format("[WWW] ERROR {0} {1}\n{2}", GatewayUrl, www.error, www.text);
                    if (error == null)
                    {
                        Debug.LogError(msg);
                    }
                    else
                    {
                        error(msg);
                    }
                    return;
                }
                if (recv.errno == Pmd.HttpReturnCode.HttpReturnCode_SignError)
                {
                    Login(login => SendMessage(message, success, error), error);
                    return;
                }
                if (success != null)
                {
                    success(recv.data);
                }
            });
        }
Exemple #5
0
 /// <summary>
 /// 获取区列表
 /// </summary>
 /// <param name="success"></param>
 /// <returns></returns>
 public void RequestZoneList(Action <Pmd.ZoneInfoListLoginUserPmd_S> success, Action <string> error = null)
 {
     SendTo(LoginUrl, new Pmd.RequestZoneList()
     {
     }, (WWW www) =>
     {
         var recv = HttpPackageReturn <Pmd.ZoneInfoListLoginUserPmd_S> .Create(www, this);
         if (recv == null || recv.errno == Pmd.HttpReturnCode.HttpReturnCode_SignError)
         {
             var msg = string.Format("[WWW] ERROR {0} {1}\n{2}", LoginUrl, www.error, www.text);
             if (error == null)
             {
                 Debug.LogError(msg);
             }
             else
             {
                 error(msg);
             }
             return;
         }
         Dispatch(recv.data, success);
     });
 }