示例#1
0
        ////////////////////////////////////// 请求 ////////////////////////////////////
        public string Login(LoginPara para, string secretKey, Signature signature, Action <ResponseEvent> callback)
        {
            const int subcmd = (int)ProtoCmd.ECmdLoginReq;
            ulong     timestamp;
            ulong     nonce;
            string    sign;

            if (signature != null)
            {
                timestamp = signature.Timestamp;
                nonce     = signature.Nonce;
                sign      = signature.Sign;
            }
            else
            {
                timestamp = SdkUtil.GetCurrentTimeSeconds();
                var gRand  = new Random();
                var buffer = new byte[sizeof(UInt32)];
                gRand.NextBytes(buffer);
                nonce = BitConverter.ToUInt32(buffer, 0);
                sign  = CreateSignature(secretKey, para.GameId, para.OpenId, timestamp, nonce);
            }

            var loginReq = new LoginReq {
                GameId    = para.GameId,
                OpenId    = para.OpenId,
                Sign      = sign,
                Timestamp = timestamp,
                Nonce     = nonce,
                Platform  = 0,
                Channel   = 0,
                DeviceId  = para.OpenId + "_" + SdkUtil.deviceId,
                Mac       = "",
                Imei      = ""
            };

            UserStatus.SetStatus(UserStatus.StatusType.Logining);
            var response = new NetResponseCallback(LoginResponse);
            var seq      = Send(loginReq, subcmd, response, callback);

            Debugger.Log("Login_Para {0} {1}", loginReq, seq);

            return(seq);
        }
示例#2
0
文件: User.cs 项目: brucelevis/MGOBE
        ////////////////////////////////////// 请求 ////////////////////////////////////
        public string Login(LoginPara para, string secretKey, Signature signature, Action <ResponseEvent> callback)
        {
            const int subcmd = (int)ProtoCmd.ECmdLoginReq;
            ulong     timestamp;
            ulong     nonce;
            string    sign;

            if (signature != null)
            {
                timestamp = signature.Timestamp;
                nonce     = signature.Nonce;
                sign      = signature.Sign;
            }
            else
            {
                timestamp = SdkUtil.GetCurrentTimeSeconds();
                var gRand  = new Random();
                var buffer = new byte[sizeof(UInt32)];
                gRand.NextBytes(buffer);
                nonce = BitConverter.ToUInt32(buffer, 0);
                // nonce = (ulong)(new Random().Next() * (int)(Math.Pow(2, 32) - 1));
                sign = CreateSignature(secretKey, para.GameId, para.OpenId, timestamp, nonce);
            }

            var loginReq = new LoginReq {
                GameId    = para.GameId,
                OpenId    = para.OpenId,
                Sign      = sign,
                Timestamp = timestamp,
                Nonce     = nonce,
                Platform  = 0,
                Channel   = 0,
                DeviceId  = "OaAV1Lg9DexJNKbN01dk5Em8RvMqQ0ZY",
                Mac       = "",
                Imei      = ""
            };
            var data = loginReq.ToByteString();

            UserStatus.SetStatus(UserStatus.StatusType.Logining);
            var response = new NetResponseCallback(LoginResponse);
            var seq      = Send(data, subcmd, response, callback);

            return(seq);
        }
示例#3
0
        public static void Login(Action <ResponseEvent> callback)
        {
            var para = new LoginPara();

            void Cb(ResponseEvent e)
            {
                callback?.Invoke(e);
                UserUtil.LoginRsp(e);
            }

            // 使用签名函数的方式
            if (GameInfo.CreateSignature != null && Core.User != null)
            {
                GameInfo.CreateSignature = (Signature signature) => {
                    Debugger.Log("使用签名函数方法登录");
                    Core.User.Login(para, null, signature, Cb);
                };
                Debugger.Log("创建签名函数方法成功");
            }
            if (Core.User != null)
            {
                Core.User.Login(para, GameInfo.SecretKey, null, Cb);
            }
        }