Пример #1
0
        public void SendMessage(DemoMessage message)
        {
            var serializedMesage  = JsonSerializer.Serialize(message);
            var cloudQueueMessage = new Message(Encoding.UTF8.GetBytes(serializedMesage));

            _queue.SendAsync(cloudQueueMessage);
        }
Пример #2
0
        static void Main(string[] args)
        {
            var bus = Bus.Factory.CreateUsingRabbitMq(cfg =>
            {
                var host = cfg.Host(new Uri("rabbitmq://192.168.17.129"), h =>
                {
                    h.Username("guest");
                    h.Password("guest");
                });
            });

            bus.Start();

            var message = new DemoMessage
            {
                Id              = 1,
                Text            = "MassTransit.SendReceive.Demo",
                CurrentDateTime = DateTime.Now
            };

            bus.Publish(message).Wait();

            bus.Stop();

            Console.WriteLine(" Press [enter] to exit.");
            Console.ReadLine();
        }
Пример #3
0
        public async Task StartReceivingMessages()
        {
            await CreateSubscription(_options.TopicName, _options.SubscriptionName);

            _client = await CreateClient();

            Helper.WriteLine($"Started receiving messages from subscription  \"{_options.SubscriptionName}\".", ConsoleColor.Magenta);
            var handlerOptions = new MessageHandlerOptions(ExceptionReceivedHandler)
            {
                AutoComplete       = _options.AutoComplete,
                MaxConcurrentCalls = _options.MaxConcurrentCalls
            };

            _client.RegisterMessageHandler(async(message, token) =>
            {
                if (token.IsCancellationRequested)
                {
                    return;
                }

                DemoMessage receivedMessage = JsonConvert.DeserializeObject <DemoMessage>(Encoding.UTF8.GetString(message.Body));
                Priority?priority           = null;
                if (message.UserProperties.TryGetValue(Helper.PriorityKey, out object priorityStr))
                {
                    priority = Program.ParsePriority((string)priorityStr);
                }
                await Program.ProcessMessage(receivedMessage, _options.ProcessTime, priority);

                if (!token.IsCancellationRequested)
                {
                    await _client.CompleteAsync(message.SystemProperties.LockToken);
                }
            }, handlerOptions);
        }
Пример #4
0
        public async Task StartReceivingMessages()
        {
            await CreateQueue();

            _client = CreateClient();
            Helper.WriteLine($"Started receiving messages from queue \"{_options.QueueName}\".", ConsoleColor.Magenta);
            var options = new MessageHandlerOptions(ExceptionReceivedHandler)
            {
                AutoComplete       = _options.AutoComplete,
                MaxConcurrentCalls = _options.MaxConcurrentCalls
            };

            _client.RegisterMessageHandler(async(message, token) =>
            {
                if (token.IsCancellationRequested)
                {
                    return;
                }

                DemoMessage receivedMessage = JsonConvert.DeserializeObject <DemoMessage>(Encoding.UTF8.GetString(message.Body));
                await Program.ProcessMessage(receivedMessage, _options.ProcessTime);

                if (!token.IsCancellationRequested)
                {
                    await _client.CompleteAsync(message.SystemProperties.LockToken);
                }
            }, options);
        }
Пример #5
0
        public void SendMessage(DemoMessage message)
        {
            var serializedMesage  = JsonSerializer.Serialize(message);
            var cloudQueueMessage = new CloudQueueMessage(serializedMesage);

            _queue.AddMessage(cloudQueueMessage);
        }
Пример #6
0
        public void SendMessage(DemoMessage message)
        {
            var serializedMesage  = JsonSerializer.Serialize(message);
            var cloudQueueMessage = new Message(Encoding.UTF8.GetBytes(serializedMesage));

            cloudQueueMessage.UserProperties.Add("MSName", message.Name);
            topic.SendAsync(cloudQueueMessage);
        }
Пример #7
0
        private IEnumerable <Tuple <int, string> > ParseGameState(DemoMessage demoMessage)
        {
            // Skip sequence number. We don't need it.
            demoMessage.ReadInt32();

            var idx = -1;

            while (!demoMessage.IsAtEndOfData)
            {
                var command = demoMessage.ReadByte();

                // Iterate trough strings in message until no longer in the config command.
                if (command != 2)
                {
                    break;
                }

                var stringIdx = demoMessage.ReadInt16();

                if (_gameVersion == GameType.CallOfDuty2)
                {
                    idx       = stringIdx;
                    stringIdx = 1;
                }

                while (stringIdx > 0)
                {
                    if (demoMessage.IsAtEndOfData)
                    {
                        break;
                    }

                    if (_gameVersion != GameType.CallOfDuty2)
                    {
                        if (demoMessage.ReadAlignedBits(1) != 0)
                        {
                            idx++;
                        }
                        else
                        {
                            idx = demoMessage.ReadAlignedBits(12);
                        }
                    }

                    var value = demoMessage.ReadString();

                    // TODO: Find the right terminator... waiting for stringIdx to be 0 causes troubles
                    if (value == "fffffffffffffffffffffffffffff300")
                    {
                        break;
                    }

                    yield return(new Tuple <int, string>(idx, value));

                    stringIdx--;
                }
            }
        }
Пример #8
0
        public async Task <string> GetName(string name)
        {
            var message = new DemoMessage {
                Name = name
            };
            var str = await SystemActors.DemoActor.Ask <string>(message);

            return(str);
        }
Пример #9
0
        private void Parse()
        {
            var reader = new BinaryReader(_fstream, Encoding.ASCII);

            Info.ParsingErrors = new List <string>();
            ParseHeader(reader);

            while (true)
            {
                var msg = new DemoMessage(Info, (MessageType)reader.ReadByte());
                if (msg.Type == MessageType.Stop)
                {
                    msg.Data = reader.ReadBytes((int)(reader.BaseStream.Length - reader.BaseStream.Position));
                    msg.Tick = int.MaxValue;
                    Info.Messages.Add(msg);
                    break;
                }
                msg.Tick = reader.ReadInt32();

                switch (msg.Type)
                {
                case MessageType.Signon:
                case MessageType.Packet:
                case MessageType.ConsoleCmd:
                case MessageType.UserCmd:
                case MessageType.DataTables:
                case MessageType.StringTables:
                    if (msg.Type == MessageType.Packet || msg.Type == MessageType.Signon)
                    {
                        msg.PriorData = reader.ReadBytes(0x54);                                 // command/sequence info
                    }
                    else if (msg.Type == MessageType.UserCmd)
                    {
                        msg.PriorData = reader.ReadBytes(0x4);                                 // unknown
                    }
                    msg.Data = reader.ReadBytes(reader.ReadInt32());

                    break;

                case MessageType.SyncTick:
                case MessageType.Nop:
                    msg.Data = new byte[0];
                    break;

                default:
                    throw new Exception("Unknown msg");
                }

                Info.Messages.Add(msg);
            }
        }
Пример #10
0
        static void Main(string[] args)
        {
            using (var activator = new BuiltinHandlerActivator())
            {
                var message = new DemoMessage("Demo Message");
                var bus     = Configure.With(activator)
                              .Transport(t => t.UseMsmq("Sender"))
                              .Routing(r => r.TypeBased().Map <DemoMessage>("Receiver"))
                              .Start();

                bus.Send(message).Wait();
                Console.ReadLine();
            }
        }
Пример #11
0
        /// <summary>
        /// Writes the demo message into the file.
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="msg"></param>
        /// <param name="runningTick"></param>
        public void WriteMessage(BinaryWriter writer, DemoMessage msg, int runningTick, bool inRange, int netProtocol)
        {
            writer.Write((byte)msg.Type);
            if (msg.Type == MessageType.SyncTick)
            {
                writer.Write(0);
            }
            else
            {
                writer.Write(runningTick);
            }

            switch (msg.Type)
            {
            case MessageType.Signon:
            case MessageType.Packet:
            case MessageType.ConsoleCmd:
            case MessageType.UserCmd:
            case MessageType.DataTables:
            case MessageType.StringTables:
                if (msg.PriorData != null)
                {
                    writer.Write(msg.PriorData);
                }

                if (!inRange && msg.Type == MessageType.Signon)
                {
                    var data = Packet.GetPacketDataWithoutType(Info, msg.Data, new int[] { 17 });
                    writer.Write(data.Length);
                    writer.Write(data);
                }
                else if (msg.Type == MessageType.Packet && !inRange)
                {
                    var data = Packet.GetPacketDataWithoutType(Info, msg.Data, new int[] { 17 });
                    writer.Write(data.Length);
                    writer.Write(data);
                }
                else
                {
                    writer.Write(msg.Data.Length);
                    writer.Write(msg.Data);
                }

                break;
            }
        }
Пример #12
0
        static void Main(string[] args)
        {
            using (var bus = RabbitHutch.CreateBus("host=192.168.17.129"))
            {
                var input   = "EasyNetQ.PublishSubscribe.Demo";
                var request = new DemoMessage
                {
                    Id              = 1,
                    Text            = input,
                    CurrentDateTime = DateTime.Now
                };

                var response = bus.Request <DemoMessage, DemoResponse>(request);
                Console.WriteLine(response.Result);
            }

            Console.WriteLine(" Press [enter] to exit.");
            Console.ReadLine();
        }
Пример #13
0
        private DemoMessage ReadDemoMessage()
        {
            // Read the sequence number.
            ReadFromStream();

            // Read the length.
            var length = ReadFromStream();

            var compressedMessage = new DemoMessage(length);

            // The message starts with an unknown value. Skip this value.
            ReadFromStream();
            compressedMessage.CurrentSize -= 4;

            // Fill the message contents from the stream.
            ReadFromStream(compressedMessage.Data, compressedMessage.CurrentSize);

            // Decode the message contents.
            return(compressedMessage.Decode(_huffmanTree));
        }
Пример #14
0
        static void Main(string[] args)
        {
            var bus = Bus.Factory.CreateUsingRabbitMq(cfg =>
            {
                var host = cfg.Host(new Uri("rabbitmq://192.168.17.129"), h =>
                {
                    h.Username("guest");
                    h.Password("guest");
                });
            });

            bus.Start();

            var uri      = new Uri("rabbitmq://192.168.17.129/rabbitmq.demo.masstransit.sendreceive");
            var endPoint = bus.GetSendEndpoint(uri).GetAwaiter().GetResult();
            var message  = new DemoMessage
            {
                Id              = 1,
                Text            = "MassTransit.SendReceive.Demo",
                CurrentDateTime = DateTime.Now
            };

            endPoint.Send(message).Wait();
            //EndpointConvention.Map<DemoMessage>(new Uri("rabbitmq://192.168.17.129/rabbitmq.demo.masstransit.sendreceive"));
            //var message = new DemoMessage
            //{
            //    Id = 1,
            //    Text = "MassTransit.SendReceive.Demo",
            //    CurrentDateTime = DateTime.Now
            //};
            //bus.Send(message).Wait();

            bus.Stop();

            Console.WriteLine(" Press [enter] to exit.");
            Console.ReadLine();
        }
Пример #15
0
 static void HandleDemoMessage2(DemoMessage demoMessage)
 {
     Console.WriteLine("Got Message from subscription 2: {0} {1} {2}", demoMessage.Id, demoMessage.Text, demoMessage.CurrentDateTime);
 }
Пример #16
0
        private void Parse()
        {
            var reader = new BinaryReader(_fstream);

            Info.Flags         = new List <Saveflag>();
            Info.ParsingErrors = new List <string>();
            var id = reader.ReadBytes(8);

            if (Encoding.ASCII.GetString(id) != "HL2DEMO\0")
            {
                Info.ParsingErrors.Add("Source parser: Incorrect mw");
            }

            Info.DemoProtocol = reader.ReadInt32();
            if (Info.DemoProtocol >> 2 > 0)
            {
                Info.ParsingErrors.Add("Unsupported L4D2 branch demo!");
            }
            //return;

            Info.NetProtocol = reader.ReadInt32();

            Info.ServerName    = new string(reader.ReadChars(260)).Replace("\0", "");
            Info.ClientName    = new string(reader.ReadChars(260)).Replace("\0", "");
            Info.MapName       = new string(reader.ReadChars(260)).Replace("\0", "");
            Info.GameDirectory = new string(reader.ReadChars(260)).Replace("\0", "");

            Info.Seconds    = Math.Abs(reader.ReadSingle());
            Info.TickCount  = Math.Abs(reader.ReadInt32());
            Info.EventCount = Math.Abs(reader.ReadInt32());

            Info.SignonLength = reader.ReadInt32();

            while (true)
            {
                var msg = new DemoMessage {
                    Type = (MessageType)reader.ReadByte()
                };
                if (msg.Type == MessageType.Stop)
                {
                    break;
                }

                msg.Tick = reader.ReadInt32();

                switch (msg.Type)
                {
                case MessageType.Signon:
                case MessageType.Packet:
                case MessageType.ConsoleCmd:
                case MessageType.UserCmd:
                case MessageType.DataTables:
                case MessageType.StringTables:
                    if (msg.Type == MessageType.Packet || msg.Type == MessageType.Signon)
                    {
                        reader.BaseStream.Seek(0x54, SeekOrigin.Current);     // command/sequence info
                    }
                    else if (msg.Type == MessageType.UserCmd)
                    {
                        reader.BaseStream.Seek(0x4, SeekOrigin.Current);     // unknown
                    }
                    msg.Data = reader.ReadBytes(reader.ReadInt32());
                    break;

                case MessageType.SyncTick:
                    msg.Data = new byte[0];
                    break;

                default:
                    Info.ParsingErrors.Add("Unknown demo message type encountered: " + msg.Type + "at " +
                                           reader.BaseStream.Position);
                    return;
                }

                if (msg.Data != null)
                {
                    if (Encoding.ASCII.GetString(msg.Data).Contains("#SAVE#") ||
                        Encoding.ASCII.GetString(msg.Data).Contains("autosave"))
                    {
                        var tempf = new Saveflag
                        {
                            Tick = msg.Tick,
                            Time = (float)(msg.Tick * 0.015)
                        };
                        if (Encoding.ASCII.GetString(msg.Data).Contains("#SAVE#"))
                        {
                            tempf.Name = "#SAVE#";
                        }

                        if (Encoding.ASCII.GetString(msg.Data).Contains("autosave"))
                        {
                            tempf.Name = "autosave";
                        }

                        Info.Flags.Add(tempf);
                    }
                }

                Info.Messages.Add(msg);
            }
        }
Пример #17
0
 private void HandleDemoMessage(DemoMessage demoMessage)
 {
     _logger.LogInformation($"Got Message : {demoMessage.Id} {demoMessage.Text} {demoMessage.CreatedTime}");
 }
Пример #18
0
        private void Parse()
        {
            var reader = new BinaryReader(_fstream);

            Info.Flags = new List <Saveflag>();
            var id = reader.ReadBytes(8);

            if (Encoding.ASCII.GetString(id) != "HL2DEMO\0")
            {
                throw new Exception("Unsupported file format.");
            }

            Info.DemoProtocol = reader.ReadInt32();
            if (Info.DemoProtocol >> 8 > 0)
            {
                throw new Exception("Demos recorded on L4D branch games are currently unsupported.");
            }

            Info.NetProtocol = reader.ReadInt32();

            Info.ServerName    = new string(reader.ReadChars(260)).Replace("\0", "");
            Info.ClientName    = new string(reader.ReadChars(260)).Replace("\0", "");
            Info.MapName       = new string(reader.ReadChars(260)).Replace("\0", "");
            Info.GameDirectory = new string(reader.ReadChars(260)).Replace("\0", "");

            Info.Seconds    = Math.Abs(reader.ReadSingle());
            Info.TickCount  = Math.Abs(reader.ReadInt32());
            Info.FrameCount = Math.Abs(reader.ReadInt32());

            Info.SignonLength = reader.ReadInt32();

            while (true)
            {
                var msg = new DemoMessage {
                    Type = (MessageType)reader.ReadByte()
                };
                if (msg.Type == MessageType.Stop)
                {
                    break;
                }
                msg.Tick = reader.ReadInt32();

                switch (msg.Type)
                {
                case MessageType.Signon:
                case MessageType.Packet:
                case MessageType.ConsoleCmd:
                case MessageType.UserCmd:
                case MessageType.DataTables:
                case MessageType.StringTables:
                    if (msg.Type == MessageType.Packet || msg.Type == MessageType.Signon)
                    {
                        reader.BaseStream.Seek(0x54, SeekOrigin.Current);     // command/sequence info
                    }
                    else if (msg.Type == MessageType.UserCmd)
                    {
                        reader.BaseStream.Seek(0x4, SeekOrigin.Current);     // unknown
                    }
                    msg.Data = reader.ReadBytes(reader.ReadInt32());
                    break;

                case MessageType.SyncTick:
                    msg.Data = new byte[0];     // lol wut
                    break;

                default:
                    throw new Exception("Unknown demo message type encountered.");     //TODO: fix this bs
                }

                if (msg.Data != null)
                {
                    if (Encoding.ASCII.GetString(msg.Data).Contains("#SAVE#") ||
                        Encoding.ASCII.GetString(msg.Data).Contains("autosave"))
                    {
                        var tempf = new Saveflag
                        {
                            Tick = msg.Tick,
                            Time = (float)(msg.Tick * 0.015)
                        };
                        if (Encoding.ASCII.GetString(msg.Data).Contains("#SAVE#"))
                        {
                            tempf.Name = "#SAVE#";
                        }
                        if (Encoding.ASCII.GetString(msg.Data).Contains("autosave"))
                        {
                            tempf.Name = "autosave";
                        }
                        Info.Flags.Add(tempf);
                    }
                }
                Info.Messages.Add(msg);
            }
        }
Пример #19
0
 private static bool ShouldTurnOnDrawHistory(DemoMessage msg, int startTick, bool historyOn, int netProtocol)
 {
     return(!historyOn && msg.IsDelta(netProtocol) && msg.Tick - 6 > startTick);
 }
Пример #20
0
        void Parse()
        {
            var reader = new BinaryReader(fstream);
            var id     = reader.ReadBytes(8);

            if (Encoding.ASCII.GetString(id) != "HL2DEMO\0")
            {
                throw new Exception("Unsupported file format.");
            }

            Info.DemoProtocol = reader.ReadInt32();
            if (Info.DemoProtocol >> 8 > 0)
            {
                throw new Exception("Demos recorded on L4D branch games are currently unsupported.");
            }

            Info.NetProtocol = reader.ReadInt32();

            Info.ServerName    = new string(reader.ReadChars(260)).Replace("\0", "");
            Info.ClientName    = new string(reader.ReadChars(260)).Replace("\0", "");
            Info.MapName       = new string(reader.ReadChars(260)).Replace("\0", "");
            Info.GameDirectory = new string(reader.ReadChars(260)).Replace("\0", "");

            Info.Seconds    = reader.ReadSingle();
            Info.TickCount  = reader.ReadInt32();
            Info.FrameCount = reader.ReadInt32();

            Info.SignonLength = reader.ReadInt32();

            while (true)
            {
                var msg = new DemoMessage {
                    Type = (MessageType)reader.ReadByte()
                };
                if (msg.Type == MessageType.Stop)
                {
                    break;
                }
                msg.Tick = reader.ReadInt32();

                switch (msg.Type)
                {
                case MessageType.Signon:
                case MessageType.Packet:
                case MessageType.ConsoleCmd:
                case MessageType.UserCmd:
                case MessageType.DataTables:
                case MessageType.StringTables:
                    if (msg.Type == MessageType.Packet || msg.Type == MessageType.Signon)
                    {
                        reader.BaseStream.Seek(0x54, SeekOrigin.Current);     // command/sequence info
                    }
                    else if (msg.Type == MessageType.UserCmd)
                    {
                        reader.BaseStream.Seek(0x4, SeekOrigin.Current);     // unknown
                    }
                    msg.Data = reader.ReadBytes(reader.ReadInt32());
                    break;

                case MessageType.SyncTick:
                    msg.Data = new byte[0];     // lol wut
                    break;

                default:
                    throw new Exception("Unknown demo message type encountered.");
                }

                Messages.Add(msg);
            }
        }
Пример #21
0
        void Parse()
        {
            var reader = new BinaryReader(fstream);
            var id = reader.ReadBytes(8);

            if (Encoding.ASCII.GetString(id) != "HL2DEMO\0")
                throw new Exception("Unsupported file format.");

            Info.DemoProtocol = reader.ReadInt32();
            if (Info.DemoProtocol >> 8 > 0)
                throw new Exception("Demos recorded on L4D branch games are currently unsupported.");

            Info.NetProtocol = reader.ReadInt32();

            Info.ServerName = new string(reader.ReadChars(260)).Replace("\0", "");
            Info.ClientName = new string(reader.ReadChars(260)).Replace("\0", "");
            Info.MapName = new string(reader.ReadChars(260)).Replace("\0", "");
            Info.GameDirectory = new string(reader.ReadChars(260)).Replace("\0", "");

            Info.Seconds = reader.ReadSingle();
            Info.TickCount = reader.ReadInt32();
            Info.FrameCount = reader.ReadInt32();

            Info.SignonLength = reader.ReadInt32();

            while (true)
            {
                var msg = new DemoMessage {Type = (MessageType) reader.ReadByte()};
                if (msg.Type == MessageType.Stop)
                    break;
                msg.Tick = reader.ReadInt32();

                switch (msg.Type)
                {
                    case MessageType.Signon:
                    case MessageType.Packet:
                    case MessageType.ConsoleCmd:
                    case MessageType.UserCmd:
                    case MessageType.DataTables:
                    case MessageType.StringTables:
                        if (msg.Type == MessageType.Packet || msg.Type == MessageType.Signon)
                            reader.BaseStream.Seek(0x54, SeekOrigin.Current); // command/sequence info
                        else if (msg.Type == MessageType.UserCmd)
                            reader.BaseStream.Seek(0x4, SeekOrigin.Current); // unknown
                        msg.Data = reader.ReadBytes(reader.ReadInt32());
                        break;
                    case MessageType.SyncTick:
                        msg.Data = new byte[0]; // lol wut
                        break;
                    default:
                        throw new Exception("Unknown demo message type encountered.");
                }

                Messages.Add(msg);
            }
        }