Exemple #1
0
            public WebSocketCreateProxy Register(JsonSocket target, Action <JsonSocket, UserLoginReturnOkLoginUserPmd_S> success, Action <string, UserLoginReturnFailLoginUserPmd_S> error)
            {
                this.target  = target;
                this.success = success;
                this.error   = error;

                keeplive.Add(this.target);
                this.target.Dispatcher.Register(this);
                return(this);
            }
Exemple #2
0
        /// <summary>
        /// 由弱联网转强联网链接
        /// </summary>
        /// <param name="http"></param>
        /// <param name="success"></param>
        /// <param name="error"></param>
        public static void CreateAsync(JsonHttp http, Action <JsonSocket, UserLoginReturnOkLoginUserPmd_S> success, Action <string, UserLoginReturnFailLoginUserPmd_S> error = null)
        {
            ulong accountid = 0;

            if (http.UID.TryParse(out accountid) == false)
            {
                var msg = string.Format("[WS ERROR] Parse HTTP.UID error: {0}", http.UID);
                if (error == null)
                {
                    Debug.LogError(msg);
                }
                else
                {
                    error(msg, null);
                }
                return;
            }
            http.SendAsync(new WebSocketForwardUserPmd_C()
            {
                accountid = accountid
            },
                           (WebSocketForwardUserPmd_S recv) =>
            {
                var websocket = new JsonSocket(recv.jsongatewayurl);
                websocket.Dispatcher.StaticRegister();
                new WebSocketCreateProxy().Register(websocket, success, error);
                // websocket登陆消息
                var cmd = new UserLoginTokenLoginUserPmd_C()
                {
                    gameid      = http.GameID,
                    zoneid      = http.ZoneID,
                    accountid   = recv.accountid,
                    logintempid = recv.logintempid,
                    timestamp   = DateTime.Now.ToUnixTime(),
                    compress    = http.Compress.ToString(),
                    encrypt     = null,
                    encryptkey  = null,
                };
                cmd.tokenmd5 = MD5.ComputeHashString(cmd.accountid.ToString() + cmd.logintempid.ToString() + cmd.timestamp.ToString() + recv.tokenid.ToString());
                websocket.Send(cmd);
            },
                           error == null ? null : new Action <string>(s => error(s, null)));
        }