Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="mpnet"></param>
        public void AddMPNetClient(MPNetClient mpnet)
        {
            if (mpnet == null)
            {
                throw new ArgumentException("Controller is null, it can't be added.");
            }
            if (connecters.ContainsKey(mpnet.Id))
            {
                throw new ArgumentException(string.Concat("A controller with id: ", mpnet.Id, " already exists! Controller can't be added: ", mpnet));
            }
            lock (connecters)
            {
                connecters.Add(mpnet.Id, mpnet);
            }

            ICollection <MessageTransmitter> tms = transmitters.Values;

            foreach (MessageTransmitter tm in tms)
            {
                if (tm.PrefabConnecterId == mpnet.Id)
                {
                    tm.SetMPNetClient(mpnet);
                }
            }
        }
Пример #2
0
 /// <summary>
 /// The process events
 /// </summary>
 public void ProcessEvents()
 {
     if (!isInit)
     {
         throw new Exception("not init net manager!");
     }
     if (CacheQueueProcess && m_CacheQueue.Count > 0)
     {
         Runnable[] runnableArray;
         lock (cachesLocker)
         {
             runnableArray = m_CacheQueue.ToArray();
             m_CacheQueue.Clear();
         }
         foreach (Runnable runnable in runnableArray)
         {
             runnable();
         }
     }
     if (m_EventsQueue.Count > 0)
     {
         BaseEvent[] eventArray;
         lock (eventsLocker)
         {
             eventArray = m_EventsQueue.ToArray();
             m_EventsQueue.Clear();
         }
         foreach (BaseEvent event2 in eventArray)
         {
             Dispatcher.DispatchEvent(event2);
         }
     }
     if (m_LuaEventsQueue.Count > 0)
     {
         LuaEvent[] eventArray;
         lock (m_LuaEventsQueue)
         {
             eventArray = m_LuaEventsQueue.ToArray();
             m_LuaEventsQueue.Clear();
         }
         foreach (LuaEvent event2 in eventArray)
         {
             m_LuaDispatcher.DispatchEvent(event2.eventType, event2.arguments);
         }
     }
     if (connecters.Count > 0)
     {
         MPNetClient[] tem = null;
         lock (connecters)
         {
             tem = new MPNetClient[connecters.Count];
             connecters.Values.CopyTo(tem, 0);
         }
         for (int i = 0; i < tem.Length; ++i)
         {
             MPNetClient nc = tem[i];
             nc.ProcessEvents();
         }
     }
 }
Пример #3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="mpnet"></param>
 /// <param name="cmd"></param>
 /// <param name="parameters"></param>
 internal void HandleExtension(MPNetClient mpnet, string cmd, IMPObject parameters)
 {
     if (extensionMessages.ContainsKey(mpnet.Id))
     {
         Hashtable messages = extensionMessages[mpnet.Id];
         ExtensionMessageDelegate delegate2 = messages[cmd] as ExtensionMessageDelegate;
         if (delegate2 != null)
         {
             try
             {
                 delegate2(parameters);
             }
             catch (Exception exception)
             {
                 throw new Exception(string.Concat("Error extension handler [", cmd, "]: ", exception.Message, " ", exception.StackTrace), exception);
             }
         }
     }
     if (luaExtensionMessages.ContainsKey(mpnet.Id))
     {
         Hashtable   messages  = luaExtensionMessages[mpnet.Id];
         LuaFunction delegate2 = messages[cmd] as LuaFunction;
         if (delegate2 != null)
         {
             delegate2.Call(parameters.ToLuaTable());
         }
     }
 }
Пример #4
0
    static int AddMPNetClient(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 2);
        INetManager obj = LuaScriptMgr.GetNetObject <INetManager>(L, 1);

        com.gt.mpnet.MPNetClient arg0 = LuaScriptMgr.GetNetObject <com.gt.mpnet.MPNetClient>(L, 2);
        obj.AddMPNetClient(arg0);
        return(0);
    }
Пример #5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="mpnet"></param>
 /// <param name="interval"></param>
 /// <param name="queueSize"></param>
 public LagMonitor(MPNetClient mpnet, int interval, int queueSize)
 {
     if (interval < 1)
     {
         interval = 1;
     }
     this.mpnet          = mpnet;
     this.queueSize      = queueSize;
     valueQueue          = new List <int>();
     pollTimer           = new Timer();
     pollTimer.Enabled   = false;
     pollTimer.AutoReset = true;
     pollTimer.Elapsed  += new ElapsedEventHandler(OnPollEvent);
     pollTimer.Interval  = interval * 1000;
 }
Пример #6
0
        /// <summary>
        /// 断开指定连接
        /// </summary>
        /// <param name="id"></param>
        public void KillConnection(int id)
        {
            MPNetClient nc = connecters[id];

            if (nc != null)
            {
                nc.RemoveAllEventListeners();
                RemoveAllMessageHandlers(id);
                nc.KillConnection();
                lock (connecters)
                {
                    connecters.Remove(id);
                }
                ICollection <MessageTransmitter> tms = transmitters.Values;
                foreach (MessageTransmitter tm in tms)
                {
                    if (tm.PrefabConnecterId == id)
                    {
                        tm.SetMPNetClient(null);
                    }
                }
            }
        }
Пример #7
0
 /// <summary>
 ///
 /// </summary>
 public void Destroy()
 {
     Stop();
     pollTimer.Dispose();
     mpnet = null;
 }
Пример #8
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="mpnet"></param>
 /// <param name="interval"></param>
 public LagMonitor(MPNetClient mpnet, int interval) : this(mpnet, interval, 10)
 {
 }
Пример #9
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="sfs"></param>
 public LagMonitor(MPNetClient mpnet) : this(mpnet, 4, 10)
 {
 }
Пример #10
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="mpnet"></param>
 internal void SetMPNetClient(MPNetClient mpnet)
 {
     this.mpnet = mpnet;
 }