internal static Packet Instantiate(byte[] source, PacketDefinitionRegistry packetRegistry = null) { packetRegistry = packetRegistry ?? PacketDefinitionRegistryFactory.CreateClassicClient(); var processingStream = new MemoryStream(source); var received = new byte[source.Length]; var packetReader = new StreamPacketReader(processingStream, received); int packetId = packetReader.ReadByte(); if ((packetId < 0) || (packetId > 255)) { throw new EndOfStreamException(); } var packetDefinition = packetRegistry.Find(packetId); var packetSize = packetDefinition.GetSize(packetReader); packetReader.ReadBytes(packetSize - packetReader.Position); var payload = new byte[packetSize]; Array.Copy(received, 0, payload, 0, packetSize); var packet = new Packet(packetId, payload); return(packet); }
public ServerConnection(ServerConnectionStatus status, IDiagnosticPullStream diagnosticPullStream, IDiagnosticPushStream diagnosticPushStream, byte[] newGameKey, uint loginSeed, LoginEncryptionKey loginKey) : this(status, diagnosticPullStream, diagnosticPushStream, PacketDefinitionRegistryFactory.CreateClassicClient(), EncryptionSetup.Autodetect) { InitNewGameEncryption(newGameKey); this.loginStream = new LoginPushStream(loginSeed, loginKey); }
public HeadlessClient(Legacy legacyApi, IConsole console, HeadlessStartConfig startConfig) { this.legacyApi = legacyApi; this.console = console; this.startConfig = startConfig; packetRegistry = PacketDefinitionRegistryFactory.CreateClassicClient(startConfig.ClientVersion); diagnosticProvider = new InfusionDiagnosticPushStreamProvider(LogConfig, console); serverDiagnosticPushStream = new CompositeDiagnosticPushStream(new ConsoleDiagnosticPushStream(packetLogger, "headless -> server", packetRegistry), new InfusionBinaryDiagnosticPushStream(DiagnosticStreamDirection.ClientToServer, diagnosticProvider.GetStream)); serverDiagnosticPullStream = new ConsoleDiagnosticPullStream(packetLogger, "server -> headless", packetRegistry); serverConnection = new ServerConnection(ServerConnectionStatus.Initial, serverDiagnosticPullStream, serverDiagnosticPushStream, packetRegistry, startConfig.Encryption); serverConnection.PacketReceived += ServerConnectionOnPacketReceived; ultimaServer = new UltimaServer(serverPacketHandler, SendToServer, packetRegistry); serverPacketHandler = new ServerPacketHandler(packetRegistry); clientPacketHandler = new ClientPacketHandler(packetRegistry); serverEndpoint = startConfig.ServerEndPoint; ultimaClient = new UltimaClient(clientPacketHandler, SendToClient); serverPacketHandler.RegisterFilter(FilterServerPacket); serverPacketHandler.Subscribe(PacketDefinitions.GameServerList, HandleGameServerList); serverPacketHandler.Subscribe(PacketDefinitions.CharactersStartingLocations, HandleCharactersStartingLocationsPacket); serverPacketHandler.Subscribe(PacketDefinitions.EnableLockedClientFeatures, HandleEnableLockedClientFeatures); clientPacketHandler.Subscribe(PacketDefinitions.LoginRequest, HandleLoginRequest); clientPacketHandler.Subscribe(PacketDefinitions.GameServerLoginRequest, HandleGameServerLoginRequest); clientPacketHandler.Subscribe(PacketDefinitions.SelectServerRequest, HandleSelectServerRequest); }
public Task Start(ProxyStartConfig config) { proxyStartConfig = config; Console.Info($"Default protocol version: {config.ProtocolVersion}"); Console.Info($"Encryption: {config.Encryption}"); if (config.LoginEncryptionKey.HasValue) { Console.Info($"Encryption key {config.LoginEncryptionKey.Value}"); } packetRegistry = PacketDefinitionRegistryFactory.CreateClassicClient(proxyStartConfig.ProtocolVersion); serverPacketHandler = new ServerPacketHandler(packetRegistry); clientPacketHandler = new ClientPacketHandler(packetRegistry); serverPacketHandler.RegisterFilter(RedirectConnectToGameServer); clientPacketHandler.Subscribe(PacketDefinitions.ExtendedLoginSeed, HandleExtendedLoginSeed); LegacyApi = new Legacy(LogConfig, commandHandler, new UltimaServer(serverPacketHandler, SendToServer, packetRegistry), new UltimaClient(clientPacketHandler, SendToClient), Console, packetRegistry, ConfigRepository, injectionWindow, SoundPlayer); UO.Initialize(LegacyApi); commandHandler.RegisterCommand(new Command("dump", DumpPacketLog, false, true, "Dumps packet log - log of network communication between game client and server. Network communication logs are very useful for diagnosing issues like crashes.", executionMode: CommandExecutionMode.Direct)); commandHandler.RegisterCommand(new Command("help", HelpCommand, false, true, "Shows command help.")); commandHandler.RegisterCommand(new Command(ListCommandName, ListRunningCommands, false, true, "Lists running commands")); commandHandler.RegisterCommand(new Command("proxy-latency", PrintProxyLatency, false, true, "Shows proxy latency.")); serverEndpoint = config.ServerEndPoint; return(Main(config.LocalProxyPort, packetRingBufferLogger)); }
internal InfusionTestProxy(ITimeSource timeSource, PacketDefinitionRegistry packetRegistry = null) { packetRegistry = packetRegistry ?? PacketDefinitionRegistryFactory.CreateClassicClient(); ServerPacketHandler = new ServerPacketHandler(PacketDefinitionRegistryFactory.CreateClassicClient()); ClientPacketHandler = new ClientPacketHandler(PacketDefinitionRegistryFactory.CreateClassicClient()); Server = new UltimaServer(ServerPacketHandler, packet => { var filteredPacket = ClientPacketHandler.FilterOutput(packet); if (filteredPacket.HasValue) { packetsSentToServer.Add(filteredPacket.Value); } }, packetRegistry); Client = new UltimaClient(ClientPacketHandler, packet => { var filteredPacket = ServerPacketHandler.FilterOutput(packet); if (filteredPacket.HasValue) { packetsSentToClient.Add(filteredPacket.Value); } }); var console = new NullConsole(); Api = new Legacy(new LogConfiguration(), new CommandHandler(console), Server, Client, console, packetRegistry, timeSource, ClilocSource, KeywordSource, new MemoryConfigBagRepository(), new NullInjectionWindow(), new NullSoundPlayer()); UO.Initialize(Api); ServerApi = new TestServerApi(PacketReceivedFromServer, Api); }
public void Can_materialize_packet() { var packet = PacketDefinitionRegistryFactory.CreateClassicClient() .Materialize <ConnectToGameServerPacket>(FakePackets.ConnectToGameServerPacket); packet.Should().NotBeNull(); }
private void HandleExtendedLoginSeed(ExtendedLoginSeed extendedLoginSeed) { Console.Info($"Detected client version: {extendedLoginSeed.ClientVersion}"); var detectedProtocolVersion = PacketDefinitionRegistryFactory.GetProtocolVersion(extendedLoginSeed.ClientVersion); if (detectedProtocolVersion != proxyStartConfig.ProtocolVersion) { Console.Info($"Using detected protocol version {detectedProtocolVersion} instead configured version {proxyStartConfig.ProtocolVersion}."); PacketDefinitionRegistryFactory.CreateClassicClient(packetRegistry, detectedProtocolVersion); } }
public void Initialize() { packetRegistry = PacketDefinitionRegistryFactory.CreateClassicClient(); }
public UltimaClientConnection(UltimaClientConnectionStatus status) : this(status, NullDiagnosticPullStream.Instance, NullDiagnosticPushStream.Instance, PacketDefinitionRegistryFactory.CreateClassicClient(), EncryptionSetup.Autodetect, null) { }
public BinaryPacketFileParser() : this(PacketDefinitionRegistryFactory.CreateClassicClient()) { }
public ServerConnection(ServerConnectionStatus status, IDiagnosticPullStream diagnosticPullStream, IDiagnosticPushStream diagnosticPushStream) : this(status, diagnosticPullStream, diagnosticPushStream, PacketDefinitionRegistryFactory.CreateClassicClient(), EncryptionSetup.Autodetect) { }
public ServerConnection() : this(ServerConnectionStatus.PreLogin, NullDiagnosticPullStream.Instance, NullDiagnosticPushStream.Instance, PacketDefinitionRegistryFactory.CreateClassicClient(), EncryptionSetup.Autodetect) { }