private ClientMessage TryParseAsOldCrypto(byte[] packet) { try { int i = 0; while (i < packet.Length) { int lenght = Base64Encoding.DecodeInt32(new byte[] { (byte)packet[i++], (byte)packet[i++], (byte)packet[i++] }); if (lenght > 0) { uint id = Base64Encoding.DecodeUInt32(new byte[] { (byte)packet[i++], (byte)packet[i++] }); if (id > 0) { byte[] bytes = new byte[lenght - 2]; for (int j = 0; j < bytes.Length; j++) { bytes[j] = packet[i++]; } OldCryptoClientMessage crypto = new OldCryptoClientMessage(); crypto.Init(id, bytes); return(crypto); } } } } catch { return(null); } return(null); }
public override bool HandlePacket(GameClient session, ref byte[] packet) { try { for (int i = 0; i < packet.Length; i++) { if (this.ReadByte(packet[i])) { if (this.RC4 != null) { this.Packet = this.RC4.Decipher(this.Packet); } OldCryptoClientMessage message = new OldCryptoClientMessage(); message.Init(Base64Encoding.DecodeUInt32(new byte[] { this.Packet[0], this.Packet[1] }), this.Packet); message.Skip(2); session.HandlePacket(message); Array.Clear(this.Packet, 0, this.Packet.Length); this.Packet = null; this.Lenght = null; this.LenghtBytes = null; this.Pointer = 0; if (session.Disconnected) { return(false); //packet disconnected the user! :D } } } return(true); } catch (Exception ex) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine("Exception: " + ex.ToString()); stringBuilder.AppendLine("- - - DEBUG INFORMATION BELOW - - - "); stringBuilder.AppendLine("Lenght bytes:" + string.Join(",", this.LenghtBytes)); stringBuilder.Append("Lenght bytes as UTF8: "); foreach (byte?byte_ in this.LenghtBytes) { stringBuilder.Append(Encoding.UTF8.GetString(new byte[1] { (byte)byte_ })); } stringBuilder.AppendLine(); stringBuilder.AppendLine("Lenght: " + this.Lenght); if (this.Packet != null) { stringBuilder.AppendLine("Bytes readed: " + string.Join(",", this.Packet)); stringBuilder.AppendLine("Bytes readed as UTF8: " + Encoding.UTF8.GetString(this.Packet)); } stringBuilder.AppendLine("Pointer: " + this.Pointer); stringBuilder.AppendLine("Reading bytes: " + string.Join(",", packet)); stringBuilder.AppendLine("Reading bytes as UTF8: " + Encoding.UTF8.GetString(packet)); Logging.LogPacketException(stringBuilder.ToString()); session.Stop("OldCryptoDataDecoderHandler failed"); return(false); } }