Ejemplo n.º 1
0
        private void OnTimer(object sender)
        {
            int y;

            if (m_buffout.GetSize() > 0)
            {
                y = socket_.Send(m_buffout.Read((int)m_buffout.GetSize()));
                m_buffout.Delete(0, y);
            }
        }
Ejemplo n.º 2
0
        /* End Dummy functions */

        public void OnClientRead(Socket socket_)
        {
            int  size = 0;
            uint realPacketSize;

            byte[]       rec_buf = new byte[5012];
            string       buffer;
            ClientPacket clientPacket_;

            allDone.Set();
            m_log.write("cSyncClient.OnClientRead", cLogging.e_LogType.LMSG_NOTICE);

            socket_.Receive(rec_buf);
            System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
            buffer = enc.GetString(rec_buf);

            m_buffin.WriteStr(buffer);

            if (m_buffin.GetSize() > 2)
            {
                m_buffin.Seek(2, System.IO.SeekOrigin.Begin);
                size = BitConverter.ToInt32(m_buffin.Read(2), 0);
            }
            else
            {
                return;
            }

            realPacketSize = (uint)size + 4;

            do
            {
                m_buffin.Seek(0, System.IO.SeekOrigin.Begin);
                buffer = m_buffin.ReadStr(realPacketSize);
                m_buffin.Delete(0, (int)realPacketSize);

                if (!m_haveKey)
                {
                    clientPacket_ = new ClientPacket(buffer);
                    HandleReadKey(clientPacket_);
                    TriggerOnConnect();
                }
                else
                {
                    buffer        = m_cryptlib.ClientDecrypt(buffer, m_key);
                    clientPacket_ = new ClientPacket(buffer);
                    TriggerOnRead(clientPacket_);
                }

                // Clear data.
                clientPacket_ = null;

                if (m_buffin.GetSize() > 2)
                {
                    m_buffin.Seek(2, System.IO.SeekOrigin.Begin);
                    size           = BitConverter.ToInt32(m_buffin.Read(2), 0);
                    realPacketSize = (uint)size + 4;
                }
                else
                {
                    return;
                }
            }while (m_buffin.GetSize() >= realPacketSize);
        }