示例#1
0
        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);
        }
示例#2
0
        private void SendToClient(Packet rawPacket)
        {
            var filteredPacket = serverPacketHandler.FilterOutput(rawPacket);

            if (filteredPacket.HasValue)
            {
                lock (clientLock)
                {
                    if (clientStream == null)
                    {
                        return;
                    }

                    using (var memoryStream = new MemoryStream(1024))
                    {
                        clientConnection.Send(filteredPacket.Value, memoryStream);
                        var buffer = memoryStream.GetBuffer();

#if DUMP_RAW
                        Console.Info("proxy -> client");
                        Console.Info(buffer.Take((int)memoryStream.Length).Select(x => x.ToString("X2")).Aggregate((l, r) => l + " " + r));
#endif

                        clientStream.Write(buffer, 0, (int)memoryStream.Length);
                    }
                }
            }
        }
示例#3
0
        public InfusionTestProxy()
        {
            ServerPacketHandler = new ServerPacketHandler();
            ClientPacketHandler = new ClientPacketHandler();
            Server = new UltimaServer(ServerPacketHandler, packet =>
            {
                var filteredPacket = ClientPacketHandler.FilterOutput(packet);
                if (filteredPacket.HasValue)
                {
                    packetsSentToServer.Add(filteredPacket.Value);
                }
            });
            Client = new UltimaClient(ClientPacketHandler, packet =>
            {
                var filteredPacket = ServerPacketHandler.FilterOutput(packet);
                if (filteredPacket.HasValue)
                {
                    packetsSentToClient.Add(filteredPacket.Value);
                }
            });

            var logger = new NullLogger();

            Api = new Legacy(new Configuration(), new CommandHandler(logger), Server, Client, logger);
        }
示例#4
0
        public static void SendToClient(Packet rawPacket)
        {
            if (clientConnection == null || ClientStream == null)
            {
                return;
            }

            var filteredPacket = serverPacketHandler.FilterOutput(rawPacket);

            if (filteredPacket.HasValue)
            {
                lock (serverConnectionLock)
                {
                    using (var memoryStream = new MemoryStream(1024))
                    {
                        clientConnection.Send(filteredPacket.Value, memoryStream);
                        ClientStream.Write(memoryStream.GetBuffer(), 0, (int)memoryStream.Length);
                    }
                }
            }
        }