/// <summary>加载模块到队列</summary> /// <param name="moduleNumber">模块号</param> /// <param name="protocol">协议</param> /// <param name="session">会话</param> public void LoadQueue(int moduleNumber, ProtocolVo protocol, TGGSession session) { //枚举反射 var fields_enum = typeof(ModuleNumber).GetFields(BindingFlags.Static | BindingFlags.Public); foreach (var item_enum in fields_enum) { var value = Convert.ToInt32(item_enum.GetValue(null)); if (value != moduleNumber) { continue; } var firstOrDefault = Variable.LMMQ.FirstOrDefault(m => m.Name == item_enum.Name); if (firstOrDefault == null) { continue; } var v = firstOrDefault.Value; var fields_queue = typeof(Variable).GetFields(BindingFlags.Static | BindingFlags.Public); foreach (var q in from item_queue in fields_queue let queue = item_queue.GetValue(null) where v == item_queue.Name select queue as ConcurrentQueue <dynamic> ) { if (q != null) { q.Enqueue(new ProtocolQueue { Protocol = protocol, Session = session }); } return; } } }
/// <summary>物品更新指令</summary> private void CommandSend(Int64 user_id, ASObject data) { #if DEBUG XTrace.WriteLine("{0}:{1}", "REWARDS", "物品更新"); #endif var b = Variable.OnlinePlayer.ContainsKey(user_id); if (!b) { return; } var session = Variable.OnlinePlayer[user_id] as TGGSession; if (session == null) { return; } var pv = new ProtocolVo { serialNumber = 1, verificationCode = 1, moduleNumber = (int)ModuleNumber.USER, commandNumber = (int)UserCommand.REWARDS, sendTime = 1000, serverTime = (DateTime.Now.Ticks - 621355968000000000) / 10000, status = (int)ResponseType.TYPE_SUCCESS, data = data, }; session.SendData(pv); }
/// <summary>发送数据</summary> /// <param name="pv">通讯协议对象</param> /// <param name="ispush">是否推送</param> public void SendData(ProtocolVo pv, bool ispush) { var protocol = new Protocol(pv); var send_data = protocol.AFMData(); Send(send_data, 0, send_data.Length); //发送数据 if (ispush) { PushData(); //推送数据 } // CommandEnd(pv.moduleNumber, pv.commandNumber); }
/// <summary> /// 发送协议 /// </summary> /// <param name="session"></param> /// <param name="data"></param> /// <param name="commandNumber"></param> /// <param name="mn"></param> public void SendPushCommand(TGGSession session, ASObject data, int commandNumber, int mn) { var pv = new ProtocolVo { serialNumber = 1, verificationCode = 1, moduleNumber = mn, commandNumber = commandNumber, sendTime = 1000, serverTime = (DateTime.Now.Ticks - 621355968000000000) / 10000, status = (int)ResponseType.TYPE_SUCCESS, data = data, }; session.SendData(pv); }
//private static REWARDS ObjInstance; ///// <summary>REWARDS单例模式</summary> //public static REWARDS GetInstance() //{ // return ObjInstance ?? (ObjInstance = new REWARDS()); //} /// <summary>物品更新指令</summary> public void CommandStart(TGGSession session, ASObject data) { #if DEBUG XTrace.WriteLine("{0}:{1}", "REWARDS", "物品更新"); #endif var pv = new ProtocolVo { serialNumber = 1, verificationCode = 1, moduleNumber = (int)ModuleNumber.USER, commandNumber = (int)UserCommand.REWARDS, sendTime = 1000, serverTime = (DateTime.Now.Ticks - 621355968000000000) / 10000, status = (int)ResponseType.TYPE_SUCCESS, data = data, }; session.SendData(pv); }
/// <summary>组建发送协议</summary> /// <param name="aso">协议数据</param> protected byte[] Build(ASObject aso) { //组装发送数据 var pv = new ProtocolVo { status = 0, sendTime = 30000, serialNumber = 1, verificationCode = 1, serverTime = DateTime.Now.Ticks, moduleNumber = MN, //模块号 commandNumber = (Int32)CN, //指令号 data = aso, }; var protocol = new Protocol(pv); return(protocol.AFMData()); }
/// <summary> /// 发送战报推送协议 /// </summary> /// <param name="report"></param> /// <param name="isattack">是否被攻击</param> private void ReportSend(tg_war_fight_report report, bool isattack) { if (Variable.OnlinePlayer.ContainsKey(report.user_id)) { var vo = new WarRecordInfoVo { id = report.id, warRecordId = report.base_id, times = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), replaceList = isattack ? new List <string>() { report.city_id.ToString() } : new List <string>() { report.city_id.ToString(), report.attack_user_name }, }; var dic = new Dictionary <string, object>() { { "report", vo } }; var session = Variable.OnlinePlayer[report.user_id] as TGGSession; var pv = new ProtocolVo { serialNumber = 1, verificationCode = 1, moduleNumber = (int)ModuleNumber.WAR, commandNumber = (int)WarCommand.WAR_REPORT_PUSH, sendTime = 1000, serverTime = (DateTime.Now.Ticks - 621355968000000000) / 10000, status = (int)ResponseType.TYPE_SUCCESS, data = new ASObject(dic), }; session.SendData(pv); } }
/// <summary>发送数据</summary> public void SendData(ProtocolVo pv) { SendData(pv, true); }