Example #1
0
        public NetMsgProcessPluginBase GetPlugin(byte property)
        {
            NetMsgProcessPluginBase plugin = null;

            plugins.TryGetValue(property, out plugin);

            return(plugin);
        }
Example #2
0
        internal AutoReconnectPlugin GetReconnectPlugin()
        {
            AutoReconnectPlugin     pingPlugin = null;
            NetMsgProcessPluginBase p          = GetPlugin(99);

            if (p != null)
            {
                pingPlugin = (AutoReconnectPlugin)p;
            }
            return(pingPlugin);
        }
Example #3
0
        public void Start()
        {
            NetStart(0);

            NetMsgProcessPluginBase plugin = Configuration.GetPlugin((byte)NetProperty.Pong);

            autoReconnectPlugin = ((ClientConfiguration)Configuration).GetReconnectPlugin();

            if (plugin != null)
            {
                pingPlugin = (NetPingPlugin)plugin;
            }
        }
Example #4
0
        public NetConfiguration AddPlugin(NetMsgProcessPluginBase plugin)
        {
            if (plugin == null)
            {
                throw new System.Exception("NetConfiguration.AddPlugin Exception");
            }
            if (plugins.ContainsKey(plugin.GetNetProperty()))
            {
                NetMsgProcessPluginBase old = plugins[plugin.GetNetProperty()];
                plugins.Remove(plugin.GetNetProperty());
                pluginList.Remove(old);
            }

            plugins.Add(plugin.GetNetProperty(), plugin);
            pluginList.Add(plugin);

            return(this);
        }
Example #5
0
 internal override void Init(NetworkCommon networkCommon)
 {
     {
         NetMsgProcessPluginBase p = GetPlugin((byte)NetProperty.Pong);
         if (p != null)
         {
             NetPingPlugin pingPlugin = (NetPingPlugin)p;
             pingPlugin.Enable = enablePing;
         }
     }
     {
         AutoReconnectPlugin p = GetReconnectPlugin();
         if (p != null)
         {
             p.Enable = enableReconnect;
         }
     }
     base.Init(networkCommon);
 }
        private void Send2TransportProcess()
        {
            SendMsgTempData tempData;

            while (sendMsgLoop.TryDequeue(out tempData))
            {
                try
                {
                    Session session = tempData.session;
                    if (session == null)
                    {
                        continue;
                    }
                    byte[] datas = tempData.datas;
                    if (datas == null)
                    {
                        datas = new byte[0];
                    }

                    byte msgProperty = (byte)NetProperty.Data;
                    //必须能msgProperty发送接收一样的才行
                    NetMsgProcessPluginBase plugin = configuration.GetPlugin(msgProperty);
                    if (plugin == null)
                    {
                        NetDebug.LogError("No NetMsgProcessPluginBase:" + msgProperty);
                        continue;
                    }
                    byte[] res = plugin.SendProcess(session, msgProperty, datas);
                    if (res == null)
                    {
                        NetDebug.LogError("No Implement NetMsgProcessPluginBase.SendProcess:" + msgProperty);
                        continue;
                    }
                    //NetDebug.Log("Send byte:" + res.Length );
                    session.StatisticSendPackets(msgProperty, res.Length);
                    Sendbytes(session, res);
                }
                catch (Exception e)
                {
                    NetDebug.LogError("Send error:" + e);
                }
            }
        }
        private void LoopDealwithReceiveData()
        {
            if (Transport == null)
            {
                return;
            }

            TransportEventData eventData;

            while (Transport.Receive(out eventData))
            {
                Session session = null;

                sessions.TryGetValue(eventData.connectionId, out session);

                if (eventData.type == ENetworkEvent.DataEvent)
                {
                    if (session == null)
                    {
                        NetDebug.LogError("session is null, connectionId :" + session + " is not Connnected");
                        return;
                    }
                    MsgPackest packest;
                    try
                    {
                        packest = new MsgPackest(configuration.byteOrder, session, eventData.data);
                    }
                    catch (Exception e)
                    {
                        NetDebug.LogError("Parse MsgPackest Error :" + e);
                        continue;
                    }
                    if (eventData.data != null)
                    {
                        session.StatisticReceivePackets(packest.msgProperty, eventData.data.Length);
                    }
                    //NetDebug.Log("接收到消息 connectionId:" + packest.connectionId);
                    NetMsgProcessPluginBase plugin = configuration.GetPlugin(packest.msgProperty);
                    if (plugin == null)
                    {
                        NetDebug.LogError("No NetMsgProcessPluginBase By msgProperty:" + packest.msgProperty);
                    }
                    else
                    {
                        plugin.ReceveProcess(packest);
                    }
                }
                else
                {
                    if (eventData.type == ENetworkEvent.ConnectEvent)
                    {
                        session = new Session(eventData.connectionId);
                        session.OpenNetStatistics(Configuration.UseStatistics);
                        session.SetConnectTimeInStatistic();
                        sessions.Add(session.ConnectionId, session);

                        foreach (var plugin in configuration.GetNetMsgProcessPlugins())
                        {
                            plugin.PeerConnectedEvent(session);
                        }
                    }
                    else if (eventData.type == ENetworkEvent.DisconnectEvent)
                    {
                        if (session != null)
                        {
                            session.SetDisconnectTimeInStatistic();
                        }
                        sessions.Remove(eventData.connectionId);

                        foreach (var plugin in configuration.GetNetMsgProcessPlugins())
                        {
                            plugin.DisconnectedEvent(session, eventData.disconnectInfo);
                        }
                    }

                    eventData.session = session;
                    //NetDebug.Log("循环接收事件:" + eventData.type);
                    AddNetEvent(eventData);
                }
            }
        }