Exemple #1
0
        // output methods
        public string Info()
        {
            // this is what USED to be displayed by the submit button

            return("Name: " + Name + ", Salary: " + Salary.ToString("C") + ", Investment Income: " + InvestmentIncome.ToString("C")
                   + ", Exemptions: " + Exemptions.ToString() + ", Marital Status: " + FormatMarriedString() + Environment.NewLine);
        }
Exemple #2
0
        public static void SerializeExemptions()
        {
            if (File.Exists(ExemptionFileName))
            {
                File.Delete(ExemptionFileName);
            }

            File.WriteAllLines(
                ExemptionFileName, Exemptions.Select(kv => String.Format("{0}\t{1}", kv.Key, kv.Value)), Encoding.UTF8);
        }
Exemple #3
0
        public static void DeserializeExemptions()
        {
            if (!File.Exists(ExemptionFileName))
            {
                return;
            }

            Exemptions.Clear();

            var lines = File.ReadAllLines(ExemptionFileName, Encoding.UTF8);
            var schar = new[] { ' ', '\t' };

            foreach (var line in
                     lines.Where(line => !String.IsNullOrWhiteSpace(line) && !line.StartsWith("#") && !line.StartsWith("//"))
                     .Select(line => line.Split(schar, StringSplitOptions.RemoveEmptyEntries)))
            {
                string addr = line.First();
                string note = String.Join(" ", line.Skip(1));

                IPAddress ip;

                if (!IPAddress.TryParse(addr, out ip))
                {
                    continue;
                }

                if (!Exemptions.ContainsKey(ip))
                {
                    Exemptions.Add(ip, note);
                }
                else
                {
                    Exemptions[ip] = note;
                }
            }
        }
Exemple #4
0
        private static void OnWhiteListCommand(CommandEventArgs e)
        {
            if (e.Mobile == null)
            {
                return;
            }

            if (e.Arguments == null || e.Arguments.Length < 1)
            {
                e.Mobile.SendMessage("Usage: {0}WhiteList <add | remove | save | reload | clear>", CommandSystem.Prefix);
                return;
            }

            IPAddress ip;

            switch (e.Arguments[0].ToLower())
            {
            case "add":
            {
                if (e.Arguments.Length < 2 || !IPAddress.TryParse(e.Arguments[1], out ip))
                {
                    e.Mobile.SendMessage("Usage: {0}WhiteList <add> <ip> [note]", CommandSystem.Prefix);
                    return;
                }

                string note = e.Arguments.Length < 3 ? String.Empty : e.Arguments[2];

                if (Exemptions.ContainsKey(ip))
                {
                    if (!String.IsNullOrEmpty(note))
                    {
                        Exemptions[ip] = note;
                    }

                    e.Mobile.SendMessage("IP '{0}' is already in the exemption list.", ip);
                    return;
                }

                Exemptions.Add(ip, note);
                e.Mobile.SendMessage("IP '{0}' has been added to the exemption list.", ip);
                return;
            }

            case "remove":
            {
                if (e.Arguments.Length < 2 || !IPAddress.TryParse(e.Arguments[1], out ip))
                {
                    e.Mobile.SendMessage("Usage: {0}WhiteList <remove> <ip>", CommandSystem.Prefix);
                    return;
                }

                if (!Exemptions.Remove(ip))
                {
                    e.Mobile.SendMessage("IP '{0}' does not exist in the exemption list.", ip);
                    return;
                }

                e.Mobile.SendMessage("IP '{0}' has been removed from the exemption list.", ip);
                return;
            }

            case "save":
            {
                SerializeExemptions();
                e.Mobile.SendMessage("IP exemption list has been saved.");
                return;
            }

            case "reload":
            {
                DeserializeExemptions();
                e.Mobile.SendMessage("IP exemption list has been reloaded.");
                return;
            }

            case "clear":
            {
                Exemptions.Clear();
                e.Mobile.SendMessage("IP exemption list has been cleared.");
                return;
            }
            }
        }
Exemple #5
0
 public static bool IsExempt(IPAddress ip)
 {
     return(!Enabled || Exemptions.ContainsKey(ip));
 }