public UltimaClientConnection(UltimaClientConnectionStatus status, IDiagnosticPullStream diagnosticPullStream, IDiagnosticPushStream diagnosticPushStream, PacketDefinitionRegistry packetRegistry, EncryptionSetup encryption, LoginEncryptionKey? configuedLoginEncryptionKey) { this.diagnosticPullStream = diagnosticPullStream; this.diagnosticPushStream = diagnosticPushStream; this.encryption = encryption; this.configuedLoginEncryptionKey = configuedLoginEncryptionKey; Status = status; packetLogParser = new PacketLogParser(packetRegistry); loginStream = new LoginPullStream(); loginStream.BaseStream = diagnosticPullStream; receiveNewGameStream = new ClientNewGamePullStream(); receiveNewGameStream.BaseStream = diagnosticPullStream; sendNewGameStream = new ClientNewGamePushStream(); }
private void DetectEncryption(IDiagnosticPullStream inputStream) { if (!inputStream.DataAvailable) return; var result = loginEncryptionDetector.Detect(this.loginSeed, inputStream, encryptionVersion); switch (encryption) { case EncryptionSetup.Autodetect: case EncryptionSetup.EncryptedClient: if (result.Encryption != null) { requiresEncryption = true; loginStream = new LoginPullStream(result.Encryption); loginStream.BaseStream = diagnosticPullStream; LoginEncryptionStarted?.Invoke(loginSeed, result.Key.Value); } break; case EncryptionSetup.EncryptedServer: if (!configuedLoginEncryptionKey.HasValue) throw new InvalidOperationException("Unecrypted client and encrypted server specified, without encryption key"); requiresEncryption = false; loginStream = new LoginPullStream(result.Encryption); loginStream.BaseStream = diagnosticPullStream; LoginEncryptionStarted?.Invoke(loginSeed, configuedLoginEncryptionKey.Value); break; default: throw new NotImplementedException($"EncryptionSetup {encryption}"); } var packet = packetLogParser.ParsePacket(result.DecryptedPacket); OnPacketReceived(packet); Status = UltimaClientConnectionStatus.ServerLogin; }