public string ToStr() { long previousOffset; long size; string result; previousOffset = buf.Seek(0, System.IO.SeekOrigin.Current); buf.Seek(0, System.IO.SeekOrigin.Begin); size = buf.GetSize(); result = buf.ReadStr(size); buf.Seek((uint)previousOffset, System.IO.SeekOrigin.Begin); return(result); }
void send(membuffer data, bool encrypt = true) { long oldPos, size; string buf; oldPos = data.Seek(0, System.IO.SeekOrigin.Current); data.Seek(0, System.IO.SeekOrigin.Begin); size = data.GetSize(); buf = data.ReadStr(size); send(buf, encrypt); data.Seek((uint)oldPos, System.IO.SeekOrigin.Begin); }
/* 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); }