示例#1
0
        public void SendTCP(GSPacketIn packet)
        {
            //Fix the packet size
            packet.WriteHeader();

            //reset the offset for read
            packet.Offset = 0;

            //Check if client is connected
            if (m_client.Socket.Connected)
            {
                try
                {
                    Statistics.BytesOut += packet.Length;
                    Statistics.PacketsOut++;

                    if (log.IsDebugEnabled)
                    {
                        log.Debug(Marshal.ToHexDump(string.Format("Send Pkg to {0} :", m_client.TcpEndpoint), packet.Buffer, 0, packet.Length));
                    }

                    lock (m_tcpQueue.SyncRoot)
                    {
                        m_tcpQueue.Enqueue(packet);
                        if (m_sendingTcp)
                        {
                            return;
                        }
                        else
                        {
                            m_sendingTcp = true;
                        }
                    }

                    if (m_client.AsyncPostSend)
                    {
                        ThreadPool.QueueUserWorkItem(new WaitCallback(AsyncSendTcpImp), this);
                    }
                    else
                    {
                        AsyncTcpSendCallback(this, send_event);
                    }
                }
                catch (Exception e)
                {
                    log.Error("SendTCP", e);
                    log.WarnFormat("It seems <{0}> went linkdead. Closing connection. (SendTCP, {1}: {2})", m_client, e.GetType(), e.Message);
                    m_client.Disconnect();
                }
            }
        }
示例#2
0
        public void SendTCP(GSPacketIn packet)
        {
            if (packet.Length > packet.Buffer.Length)
            {
                throw new Exception(Marshal.ToHexDump(string.Format("Error package:  buffer:{0}     length:{1}", packet.Buffer.Length, packet.Length), packet.Buffer, 0, (packet.Buffer.Length > 128) ? 128 : packet.Buffer.Length));
            }
            packet.WriteHeader();
            packet.Offset = 0;
            if (this.m_client.Socket.Connected)
            {
                try
                {
                    Statistics.BytesOut   += (long)packet.Length;
                    Statistics.PacketsOut += 1L;

                    object syncRoot;
                    Monitor.Enter(syncRoot = this.m_tcpQueue.SyncRoot);
                    try
                    {
                        this.m_tcpQueue.Enqueue(packet);
                        if (this.m_sendingTcp)
                        {
                            return;
                        }
                        this.m_sendingTcp = true;
                    }
                    finally
                    {
                        Monitor.Exit(syncRoot);
                    }
                    this.m_firstPkgOffset = 0;
                    if (this.m_client.AsyncPostSend)
                    {
                        ThreadPool.QueueUserWorkItem(new WaitCallback(StreamProcessor.AsyncSendTcpImp), this);
                    }
                    else
                    {
                        StreamProcessor.AsyncTcpSendCallback(this, this.send_event);
                    }
                }
                catch (Exception e)
                {
                    StreamProcessor.log.Error("SendTCP", e);
                    StreamProcessor.log.WarnFormat("It seems <{0}> went linkdead. Closing connection. (SendTCP, {1}: {2})", this.m_client, e.GetType(), e.Message);
                    this.m_client.Disconnect();
                }
            }
        }
 public void SendTCP(GSPacketIn packet)
 {
     packet.WriteHeader();
     packet.Offset = 0;
     if (this.m_client.Socket.Connected)
     {
         try
         {
             Statistics.BytesOut   += (long)packet.Length;
             Statistics.PacketsOut += 1L;
             if (StreamProcessor.log.IsDebugEnabled)
             {
                 StreamProcessor.log.Debug(Marshal.ToHexDump(string.Format("Send Pkg to {0} :", this.m_client.TcpEndpoint), packet.Buffer, 0, packet.Length));
             }
             object syncRoot;
             Monitor.Enter(syncRoot = this.m_tcpQueue.SyncRoot);
             try
             {
                 this.m_tcpQueue.Enqueue(packet);
                 if (this.m_sendingTcp)
                 {
                     return;
                 }
                 this.m_sendingTcp = true;
             }
             finally
             {
                 Monitor.Exit(syncRoot);
             }
             if (this.m_client.AsyncPostSend)
             {
                 ThreadPool.QueueUserWorkItem(new WaitCallback(StreamProcessor.AsyncSendTcpImp), this);
             }
             else
             {
                 StreamProcessor.AsyncTcpSendCallback(this, this.send_event);
             }
         }
         catch (Exception ex)
         {
             StreamProcessor.log.Error("SendTCP", ex);
             StreamProcessor.log.WarnFormat("It seems <{0}> went linkdead. Closing connection. (SendTCP, {1}: {2})", this.m_client, ex.GetType(), ex.Message);
             this.m_client.Disconnect();
         }
     }
 }
示例#4
0
 public void WritePacket_(GSPacketIn pkg)
 {
     pkg.WriteHeader();
     Write(pkg.Buffer, 0, pkg.Length);
 }
示例#5
0
 public void WritePacket(GSPacketIn content)
 {
     content.WriteHeader();
     WriteShort((short)content.Length);
     WriteShort(0);
     Write(content.Buffer, 2, content.Length - 2);
 }
示例#6
0
 /// <summary>
 /// 收到协议包
 /// </summary>
 /// <param name="pkg"></param>
 public override void OnRecvPacket(GSPacketIn pkg)
 {
     if (m_packetProcessor == null)
     {
         m_packetLib = AbstractPacketLib.CreatePacketLibForVersion(1, this);
         m_packetProcessor = new PacketProcessor(this);
     }
     if (m_player != null)
     {
         pkg.ClientID = m_player.PlayerId;
         pkg.WriteHeader();
     }
     //LogMsg(Marshal.ToHexDump("recevie:", pkg.Buffer, 0, pkg.Length));
     m_packetProcessor.HandlePacket(pkg);
 }
示例#7
0
        public void SendTCP(GSPacketIn packet)
        {
            //Fix the packet size
            packet.WriteHeader();

            //reset the offset for read
            packet.Offset = 0;

            //Check if client is connected
            if (m_client.Socket.Connected)
            {
                try
                {
                    Statistics.BytesOut += packet.Length;
                    Statistics.PacketsOut++;

                    if (log.IsDebugEnabled)
                    {
                        log.Debug(Marshal.ToHexDump(string.Format("Send Pkg to {0} :", m_client.TcpEndpoint), packet.Buffer, 0, packet.Length));
                    }

                    lock (m_tcpQueue.SyncRoot)
                    {
                        m_tcpQueue.Enqueue(packet);
                        if (m_sendingTcp)
                        {
                            return;
                        }
                        else
                        {
                            m_sendingTcp = true;
                        }
                    }

                    if (m_client.AsyncPostSend)
                    {
                        ThreadPool.QueueUserWorkItem(new WaitCallback(AsyncSendTcpImp), this);
                    }
                    else
                    {
                        AsyncTcpSendCallback(this, send_event);
                    }
                }
                catch (Exception e)
                {
                    log.Error("SendTCP", e);
                    log.WarnFormat("It seems <{0}> went linkdead. Closing connection. (SendTCP, {1}: {2})", m_client, e.GetType(), e.Message);
                    m_client.Disconnect();
                }
            }
        }
示例#8
0
 public void WritePacket(GSPacketIn pkg)
 {
     pkg.WriteHeader();
     this.Write(pkg.Buffer, 0, pkg.Length);
 }