Beispiel #1
0
        /// <summary>执行指令</summary>
        public override void ExecuteCommand(TGGSession session, BinaryRequestInfo requestInfo)
        {
#if DEBUG
            //XTrace.WriteLine("接收数据:{0}", BitConverter.ToString(requestInfo.Body, 0, requestInfo.Body.Length));
            session.Logger.Debug(string.Format("接收数据:{0}", BitConverter.ToString(requestInfo.Body, 0, requestInfo.Body.Length)));
#endif
            try
            {
                var sobj = new SocketObjectData {
                    session = session, requestInfo = requestInfo
                };

                var _temp = new CancellationTokenSource();
                new Task(m =>
                {
                    var model = m as SocketObjectData;

                    if (model == null)
                    {
                        return;
                    }
                    if (model.requestInfo.Body.Length <= 0)
                    {
                        return;
                    }
                    var stream    = new MemoryStream(model.requestInfo.Body, 0, model.requestInfo.Body.Length);
                    var byteArray = new ByteArray(stream);
                    var dy        = byteArray.ReadObject();
                    var retype    = dy.GetType().Name;
                    //判断接收数据类型
                    ASObject obj;
                    switch (retype)
                    {
                    case "ASObject": { obj = (ASObject)dy; break; }

                    case "ProtocolVo": { obj = AMFConvert.ToASObject(dy); break; }

                    default: { return; }
                    }
                    var pv = AutoParseAsObject <ProtocolVo> .Parse(obj);
                    if (pv.className != "ProtocolVo")
                    {
                        return;
                    }
                    ModuleQueue.GetInstance().LoadQueue(pv.moduleNumber, pv, model.session);
#if DEBUG
                    XTrace.WriteLine("Socket Handle接收数据Number:{0} - {1}", pv.moduleNumber, pv.commandNumber);
#endif

                    _temp.Cancel();
                }, sobj, _temp.Token).Start();
            }
            catch (Exception ex) { XTrace.WriteException(ex); }
        }
Beispiel #2
0
        /// <summary>
        /// 充值
        /// </summary>
        internal Int32 Recharge(Int64 user_id, Int32 amount)
        {
            var s = new MvcSocket(IP, Port);

            var str = string.Format("{0}|{1}", user_id, amount);
            var dic = new Dictionary <string, object>()
            {
                { "key", "" },
                { "data", CryptoHelper.Encrypt(str, "") },
            };

            XTrace.WriteLine("充值:{0}", str);
            var data = Build(new ASObject(dic));

            s.Send(data);
            var result = s.Receive();

            s.Dispose();
            //解析返回结果
            var len = result.Length - 8;
            var da  = new byte[len];

            Array.Copy(result, 8, da, 0, len);

            var bytea  = new ByteArray(da);
            var dy     = bytea.ReadObject();
            var retype = dy.GetType().Name;
            //XTrace.WriteLine("retype:{0}", retype);
            ASObject obj;

            switch (retype)  //判断接收数据类型
            {
            case "ASObject": { obj = (ASObject)dy; break; }

            case "ProtocolVo": { obj = AMFConvert.ToASObject(dy); break; }

            default: { return((int)ApiType.FAIL); }
            }
            var pv = AutoParseAsObject <ProtocolVo> .Parse(obj);

            //XTrace.WriteLine("pv.className:{0}", pv.className);
            if (pv.className != "ProtocolVo")
            {
                return((int)ApiType.FAIL);
            }
            var r = pv.data;

            // 解析返回结果数据
            var _state = Convert.ToInt32(r.FirstOrDefault(q => q.Key == "state").Value);

            return(_state);
        }
Beispiel #3
0
        /// <summary>
        /// 停止公告
        /// </summary>
        internal Int32 StopNotice(Int64 nid)
        {
#if DEBUG
            IP   = "192.168.1.111";
            Port = 10086;
#endif
            var s   = new MvcSocket(IP, Port);
            var str = string.Format("{0}", nid);
            var dic = new Dictionary <string, object>()
            {
                { "key", "" },
                { "data", CryptoHelper.Encrypt(str, "") },
            };

            var data = Build(new ASObject(dic));
            s.Send(data);
            var result = s.Receive();
            s.Dispose();
            //解析返回结果
            var len = result.Length - 8;
            var da  = new byte[len];
            Array.Copy(result, 8, da, 0, len);

            var      bytea  = new ByteArray(da);
            var      dy     = bytea.ReadObject();
            var      retype = dy.GetType().Name;
            ASObject obj;
            switch (retype)  //判断接收数据类型
            {
            case "ASObject": { obj = (ASObject)dy; break; }

            case "ProtocolVo": { obj = AMFConvert.ToASObject(dy); break; }

            default: { return((int)ApiType.FAIL); }
            }
            var pv = AutoParseAsObject <ProtocolVo> .Parse(obj);

            if (pv.className != "ProtocolVo")
            {
                return((int)ApiType.FAIL);
            }
            var r = pv.data;

            // 解析返回结果数据
            var state = Convert.ToInt32(r.FirstOrDefault(q => q.Key == "state").Value);
            return(state);
        }