Exemplo n.º 1
0
        /// <summary>指令业务</summary>
        public void Service(ProtocolQueue model)
        {
#if DEBUG
            XTrace.WriteLine("commandNumber:{0}", model.Protocol.commandNumber);
#endif
            try
            {
                if (model.Session == null)
                {
                    return;
                }
                if (model.Protocol.commandNumber == (int)UserCommand.HEARTBEAT)
                {
                    CommandSwitch.GetInstance().Switch(model.Protocol.commandNumber, model.Session, model.Protocol.data);
                    return;
                }
                TGGSession session = model.Session;

                var key = string.Format("{0}_{1}_{2}", session.Player.User.id, model.Protocol.moduleNumber, model.Protocol.commandNumber);
                if (Variable.CCI.ContainsKey(key))
                {
                    session.SendData(session.InitProtocol(model, (int)ResponseType.TYPE_COMMAND_FAST, null));
                    return;
                }
                Variable.CCI.TryAdd(key, true);

                var data = CommandSwitch.GetInstance().Switch(model.Protocol.commandNumber, session, model.Protocol.data);
                var pv   = session.InitProtocol(model, (int)ResponseType.TYPE_SUCCESS, data);
                session.SendData(pv);
                RemoveCommand(key);
            }
            catch (Exception ex)
            {
                XTrace.WriteException(ex);
                if (model.Session != null)
                {
                    model.Session.CommandEnd(model);
                }
            }
        }
Exemplo n.º 2
0
 /// <summary>CommandSwitch单例模式</summary>
 public static CommandSwitch GetInstance()
 {
     return(ObjInstance ?? (ObjInstance = new CommandSwitch()));
 }