/* End Dummy functions */ public void Send(string data, bool encrypted = true) { m_log.write("cSyncClient.Send", cLogging.e_LogType.LMSG_STATUS); if (encrypted) { m_buffout.WriteStr(m_cryptlib.ClientEncrypt(data, m_key, 0)); } else { m_buffout.WriteStr(data); } return; }
void send(string data, bool encrypt) { string encrypted; if (encrypt) { if (UID.login == "Sync") { encrypted = m_cryptLib.ClientEncrypt(data, m_key, 0); } else { encrypted = m_cryptLib.ServerEncrypt(data, m_key); } m_buffout.WriteStr(encrypted); } else { m_buffout.WriteStr(data); } }
/* 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); }
public ClientPacket(string buffer) { buf = new membuffer(); buf.WriteStr(buffer); buf.Seek(0, System.IO.SeekOrigin.Begin); }