예제 #1
0
        /// <summary>
        /// 路由用.需要提前生成localconn
        /// </summary>
        /// <param name="self"></param>
        /// <param name="channelId"></param>
        /// <param name="realIPEndPoint"></param>
        /// <returns></returns>
        public static Session Create(this NetKcpComponent self, long channelId, IPEndPoint realIPEndPoint)
        {
            Session session = self.AddChildWithId <Session, AService>(channelId, self.Service);

            session.RemoteAddress = realIPEndPoint;
            session.AddComponent <SessionIdleCheckerComponent, int>(NetThreadComponent.checkInteral);
            self.Service.GetOrCreate(session.Id, realIPEndPoint);
            return(session);
        }
예제 #2
0
        // 这个channelId是由CreateAcceptChannelId生成的
        public static void OnAccept(this NetKcpComponent self, long channelId, IPEndPoint ipEndPoint)
        {
            Session session = EntityFactory.CreateWithParentAndId <Session, AService>(self, channelId, self.Service);

            session.RemoteAddress = ipEndPoint;

            session.AddComponent <SessionAcceptTimeoutComponent>();
            // 客户端连接,2秒检查一次recv消息,10秒没有消息则断开
            session.AddComponent <SessionIdleCheckerComponent, int>(NetThreadComponent.checkInteral);
        }
예제 #3
0
        // 这个channelId是由CreateAcceptChannelId生成的
        public static void OnAccept(this NetKcpComponent self, long channelId, IPEndPoint ipEndPoint)
        {
            Session session = self.AddChildWithId <Session, AService>(channelId, self.Service);

            session.RemoteAddress = ipEndPoint;

            // 挂上这个组件,5秒就会删除session,所以客户端验证完成要删除这个组件。该组件的作用就是防止外挂一直连接不发消息也不进行权限验证
            session.AddComponent <SessionAcceptTimeoutComponent>();
            // 客户端连接,2秒检查一次recv消息,10秒没有消息则断开
            session.AddComponent <SessionIdleCheckerComponent, int>(NetThreadComponent.checkInteral);
        }
예제 #4
0
        public static void OnError(this NetKcpComponent self, long channelId, int error)
        {
            Session session = self.GetChild <Session>(channelId);

            if (session == null)
            {
                return;
            }

            session.Error = error;
            session.Dispose();
        }
예제 #5
0
        public static void OnRead(this NetKcpComponent self, long channelId, MemoryStream memoryStream)
        {
            Session session = self.GetChild <Session>(channelId);

            if (session == null)
            {
                return;
            }

            session.LastRecvTime = TimeHelper.ClientNow();
            self.MessageDispatcher.Dispatch(session, memoryStream);
        }
예제 #6
0
        public static Session Create(this NetKcpComponent self, IPEndPoint realIPEndPoint)
        {
            long    channelId = RandomHelper.RandInt64();
            Session session   = EntityFactory.CreateWithParentAndId <Session, AService>(self, channelId, self.Service);

            session.RemoteAddress = realIPEndPoint;
            session.AddComponent <SessionIdleCheckerComponent, int>(NetThreadComponent.checkInteral);

            self.Service.GetOrCreate(session.Id, realIPEndPoint);

            return(session);
        }
예제 #7
0
        public static void OnRead(this NetKcpComponent self, long channelId, MemoryStream memoryStream)
        {
            Session session = self.GetChild <Session>(channelId);

            if (session == null)
            {
                return;
            }

            session.LastRecvTime = TimeHelper.ClientNow();

            Game.EventSystem.Callback(self.SessionStreamDispatcherType, session, memoryStream);
        }
예제 #8
0
        public static Session Get(this NetKcpComponent self, long id)
        {
            Session session = self.GetChild <Session>(id);

            return(session);
        }