Exemplo n.º 1
0
        public static void Initialize()
        {
            CommandSystem.Register("GetThrottle", AccessLevel.Administrator, GetThrottle);
            CommandSystem.Register("SetThrottle", AccessLevel.Administrator, SetThrottle);

            var configPath = ThrottlesConfiguration;
            var path       = Path.Join(Core.BaseDirectory, configPath);

            if (File.Exists(path))
            {
                var throttles = JsonConfig.Deserialize <SortedDictionary <string, int> >(path);
                foreach (var(k, v) in throttles)
                {
                    if (!Utility.ToInt32(k, out var packetId))
                    {
                        Utility.PushColor(ConsoleColor.DarkYellow);
                        Console.WriteLine("Packet Throttles: Error deserializing {0} from {1}", k, configPath);
                        Utility.PopColor();
                        continue;
                    }

                    Delays[packetId] = v;
                }
            }
            else
            {
                Delays[0x03] = 5;   // Speech
                Delays[0xAD] = 5;   // Speech
                Delays[0x75] = 500; // Rename request
            }

            for (int i = 0; i < 0x100; i++)
            {
                if (Delays[i] > 0)
                {
                    IncomingPackets.RegisterThrottler(i, Throttle);
                }
            }

            SaveDelays();
        }
Exemplo n.º 2
0
        public static void SetThrottle(CommandEventArgs e)
        {
            if (e.Length != 2)
            {
                e.Mobile.SendMessage("Invalid Command Format. Should be [SetThrottle <packetID> <timeInMilliseconds>");
                return;
            }

            int packetID = e.GetInt32(0);
            int delay    = e.GetInt32(1);

            if (packetID < 0 || packetID > 0x100)
            {
                e.Mobile.SendMessage("Invalid Command Format. PacketID must be between 0 and 0x100.");
                return;
            }


            if (delay > 5000)
            {
                e.Mobile.SendMessage("Invalid Command Format. Delay cannot exceed 5000 milliseconds.");
                return;
            }

            long oldDelay = Delays[packetID];

            if (oldDelay == 0 && delay > 0)
            {
                IncomingPackets.RegisterThrottler(packetID, Throttle);
            }
            else if (oldDelay > 0 && delay == 0)
            {
                IncomingPackets.RegisterThrottler(packetID, null);
            }

            Delays[packetID] = delay;
            SaveDelays();
        }