コード例 #1
0
        /// <summary>
        /// 创建一个新Session
        /// </summary>
        public Session Create(IPEndPoint ipEndPoint)
        {
            AChannel channel = this.m_AService.ConnectChannel(ipEndPoint);
            Session  session = Create(channel);

            return(session);
        }
コード例 #2
0
        /// <summary>
        /// 创建一个新Session
        /// </summary>
        public Session Create(string address)
        {
            AChannel channel = this.m_AService.ConnectChannel(address);
            Session  session = Create(channel);

            return(session);
        }
コード例 #3
0
        private Session Create(AChannel channel)
        {
            Session session = new Session(channel);

            session.Parent = this;
            this.m_Dict_Sessions.Add(session.Id, session);
            return(session);
        }
コード例 #4
0
        public KChannel GetKChannel(long id)
        {
            AChannel aChannel = this.GetChannel(id);

            if (aChannel == null)
            {
                return(null);
            }

            return((KChannel)aChannel);
        }
コード例 #5
0
        public static void Output(IntPtr bytes, int count, IntPtr user)
        {
            if (Instance == null)
            {
                return;
            }

            AChannel aChannel = Instance.GetChannel((uint)user);

            if (aChannel == null)
            {
                Log.Error($"not found kchannel, {(uint)user}");
                return;
            }

            KChannel kChannel = aChannel as KChannel;

            kChannel.Output(bytes, count);
        }
コード例 #6
0
        public void OnRead(AChannel ac, MemoryStream memoryStream)
        {
            ushort   opcode  = 0;
            IMessage message = null;

            try
            {
                memoryStream.Seek(Packet.MessageIndex, SeekOrigin.Begin);
                opcode  = BitConverter.ToUInt16(memoryStream.GetBuffer(), Packet.OpcodeIndex);
                message = Network.MessagePacker.DeserializeFrom(Network.IOpCodeType.GetType(opcode), memoryStream) as IMessage;
            }
            catch (Exception e)
            {
                // 出现任何消息解析异常都要断开Session,防止客户端伪造消息
                Log.Error($"opcode:{opcode}:{e}");
                this.Error = ErrorCode.ERR_PacketParserError;
                this.Network.Remove(this.Id);
                return;
            }
            Network.IMessageDispatcher.Dispatch(this, new MessageInfo(opcode, message));
        }
コード例 #7
0
 protected void OnRead(AChannel ac, MemoryStream memoryStream)
 {
     m_ReadCallback.InvokeGracefully(ac, memoryStream);
 }
コード例 #8
0
ファイル: AService.cs プロジェクト: yymqwl/Barrage
 protected void OnAccept(AChannel channel)
 {
     this.m_AcceptCallback.Invoke(channel);
 }
コード例 #9
0
ファイル: AService.cs プロジェクト: yymqwl/Barrage
 public void OnDisConnected(AChannel channel)
 {
     m_DisConnectedCallback.InvokeGracefully(channel);
     Remove(channel.Id);
 }
コード例 #10
0
 protected void OnAccept(AChannel channel)
 {
     Session session = Create(channel);
 }
コード例 #11
0
 private void OnDisConnected(AChannel ac)
 {
     Log.Debug($"session disconnect {ac.Id}");
     Remove(ac.Id);
 }
コード例 #12
0
 public Session(AChannel aChannel)
 {
     m_AChannel = aChannel;
     m_AChannel.ReadCallback += this.OnRead;
 }