/// <summary> /// 创建一个新Session /// </summary> public Session Create(IPEndPoint ipEndPoint) { AChannel channel = this.m_AService.ConnectChannel(ipEndPoint); Session session = Create(channel); return(session); }
/// <summary> /// 创建一个新Session /// </summary> public Session Create(string address) { AChannel channel = this.m_AService.ConnectChannel(address); Session session = Create(channel); return(session); }
private Session Create(AChannel channel) { Session session = new Session(channel); session.Parent = this; this.m_Dict_Sessions.Add(session.Id, session); return(session); }
public KChannel GetKChannel(long id) { AChannel aChannel = this.GetChannel(id); if (aChannel == null) { return(null); } return((KChannel)aChannel); }
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); }
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)); }
protected void OnRead(AChannel ac, MemoryStream memoryStream) { m_ReadCallback.InvokeGracefully(ac, memoryStream); }
protected void OnAccept(AChannel channel) { this.m_AcceptCallback.Invoke(channel); }
public void OnDisConnected(AChannel channel) { m_DisConnectedCallback.InvokeGracefully(channel); Remove(channel.Id); }
protected void OnAccept(AChannel channel) { Session session = Create(channel); }
private void OnDisConnected(AChannel ac) { Log.Debug($"session disconnect {ac.Id}"); Remove(ac.Id); }
public Session(AChannel aChannel) { m_AChannel = aChannel; m_AChannel.ReadCallback += this.OnRead; }