using System; using System.Collections.Generic; using Network; using Newtonsoft.Json; using Net = Network.Net; namespace Oxide.Plugins { [Info("CountryBlocker", "M&B-Studios / beee", "1.0.5")] class CountryBlocker : RustPlugin { private Configuration _config; private const string perm = "countryblocker.ignore"; #region Config private class Configuration { [JsonProperty("Countries")] public Dictionary CountriesSettings { get; set; } [JsonProperty("Block Message")] public string BlockMessage { get; set; } internal class CountrySettings { [JsonProperty("Name")] public string FullName { get; set; } [JsonProperty("Is Blocked?")] public bool IsBlocked { get; set; } } } protected override void LoadConfig() { base.LoadConfig(); try { _config = Config.ReadObject(); if (_config == null) throw new Exception(); SaveConfig(); } catch { PrintError("Your configuration file contains an error. Using default configuration values."); LoadDefaultConfig(); } } protected override void SaveConfig() { Config.WriteObject(_config); } protected override void LoadDefaultConfig() { _config = new Configuration { CountriesSettings = new Dictionary { { "AF", new Configuration.CountrySettings(){ FullName = "Afghanistan", IsBlocked = false} }, { "AX", new Configuration.CountrySettings(){ FullName = "Aland Islands", IsBlocked = false} }, { "AL", new Configuration.CountrySettings(){ FullName = "Albania", IsBlocked = false} }, { "DZ", new Configuration.CountrySettings(){ FullName = "Algeria", IsBlocked = false} }, { "AS", new Configuration.CountrySettings(){ FullName = "American Samoa", IsBlocked = false} }, { "AD", new Configuration.CountrySettings(){ FullName = "Andorra", IsBlocked = false} }, { "AO", new Configuration.CountrySettings(){ FullName = "Angola", IsBlocked = false} }, { "AI", new Configuration.CountrySettings(){ FullName = "Anguilla", IsBlocked = false} }, { "AQ", new Configuration.CountrySettings(){ FullName = "Antarctica", IsBlocked = false} }, { "AG", new Configuration.CountrySettings(){ FullName = "Antigua And Barbuda", IsBlocked = false} }, { "AR", new Configuration.CountrySettings(){ FullName = "Argentina", IsBlocked = false} }, { "AM", new Configuration.CountrySettings(){ FullName = "Armenia", IsBlocked = false} }, { "AW", new Configuration.CountrySettings(){ FullName = "Aruba", IsBlocked = false} }, { "AU", new Configuration.CountrySettings(){ FullName = "Australia", IsBlocked = false} }, { "AT", new Configuration.CountrySettings(){ FullName = "Austria", IsBlocked = false} }, { "AZ", new Configuration.CountrySettings(){ FullName = "Azerbaijan", IsBlocked = false} }, { "BS", new Configuration.CountrySettings(){ FullName = "Bahamas", IsBlocked = false} }, { "BH", new Configuration.CountrySettings(){ FullName = "Bahrain", IsBlocked = false} }, { "BD", new Configuration.CountrySettings(){ FullName = "Bangladesh", IsBlocked = false} }, { "BB", new Configuration.CountrySettings(){ FullName = "Barbados", IsBlocked = false} }, { "BY", new Configuration.CountrySettings(){ FullName = "Belarus", IsBlocked = false} }, { "BE", new Configuration.CountrySettings(){ FullName = "Belgium", IsBlocked = false} }, { "BZ", new Configuration.CountrySettings(){ FullName = "Belize", IsBlocked = false} }, { "BJ", new Configuration.CountrySettings(){ FullName = "Benin", IsBlocked = false} }, { "BM", new Configuration.CountrySettings(){ FullName = "Bermuda", IsBlocked = false} }, { "BT", new Configuration.CountrySettings(){ FullName = "Bhutan", IsBlocked = false} }, { "BO", new Configuration.CountrySettings(){ FullName = "Bolivia", IsBlocked = false} }, { "BA", new Configuration.CountrySettings(){ FullName = "Bosnia And Herzegovina", IsBlocked = false} }, { "BW", new Configuration.CountrySettings(){ FullName = "Botswana", IsBlocked = false} }, { "BV", new Configuration.CountrySettings(){ FullName = "Bouvet Island", IsBlocked = false} }, { "BR", new Configuration.CountrySettings(){ FullName = "Brazil", IsBlocked = false} }, { "IO", new Configuration.CountrySettings(){ FullName = "British Indian Ocean Territory", IsBlocked = false} }, { "BN", new Configuration.CountrySettings(){ FullName = "Brunei Darussalam", IsBlocked = false} }, { "BG", new Configuration.CountrySettings(){ FullName = "Bulgaria", IsBlocked = false} }, { "BF", new Configuration.CountrySettings(){ FullName = "Burkina Faso", IsBlocked = false} }, { "BI", new Configuration.CountrySettings(){ FullName = "Burundi", IsBlocked = false} }, { "KH", new Configuration.CountrySettings(){ FullName = "Cambodia", IsBlocked = false} }, { "CM", new Configuration.CountrySettings(){ FullName = "Cameroon", IsBlocked = false} }, { "CA", new Configuration.CountrySettings(){ FullName = "Canada", IsBlocked = false} }, { "CV", new Configuration.CountrySettings(){ FullName = "Cape Verde", IsBlocked = false} }, { "KY", new Configuration.CountrySettings(){ FullName = "Cayman Islands", IsBlocked = false} }, { "CF", new Configuration.CountrySettings(){ FullName = "Central African Republic", IsBlocked = false} }, { "TD", new Configuration.CountrySettings(){ FullName = "Chad", IsBlocked = false} }, { "CL", new Configuration.CountrySettings(){ FullName = "Chile", IsBlocked = false} }, { "CN", new Configuration.CountrySettings(){ FullName = "China", IsBlocked = false} }, { "CX", new Configuration.CountrySettings(){ FullName = "Christmas Island", IsBlocked = false} }, { "CC", new Configuration.CountrySettings(){ FullName = "Cocos (Keeling) Islands", IsBlocked = false} }, { "CO", new Configuration.CountrySettings(){ FullName = "Colombia", IsBlocked = false} }, { "KM", new Configuration.CountrySettings(){ FullName = "Comoros", IsBlocked = false} }, { "CG", new Configuration.CountrySettings(){ FullName = "Congo", IsBlocked = false} }, { "CD", new Configuration.CountrySettings(){ FullName = "Congo, Democratic Republic", IsBlocked = false} }, { "CK", new Configuration.CountrySettings(){ FullName = "Cook Islands", IsBlocked = false} }, { "CR", new Configuration.CountrySettings(){ FullName = "Costa Rica", IsBlocked = false} }, { "CI", new Configuration.CountrySettings(){ FullName = "Cote D\"Ivoire", IsBlocked = false} }, { "HR", new Configuration.CountrySettings(){ FullName = "Croatia", IsBlocked = false} }, { "CU", new Configuration.CountrySettings(){ FullName = "Cuba", IsBlocked = false} }, { "CY", new Configuration.CountrySettings(){ FullName = "Cyprus", IsBlocked = false} }, { "CZ", new Configuration.CountrySettings(){ FullName = "Czech Republic", IsBlocked = false} }, { "DK", new Configuration.CountrySettings(){ FullName = "Denmark", IsBlocked = false} }, { "DJ", new Configuration.CountrySettings(){ FullName = "Djibouti", IsBlocked = false} }, { "DM", new Configuration.CountrySettings(){ FullName = "Dominica", IsBlocked = false} }, { "DO", new Configuration.CountrySettings(){ FullName = "Dominican Republic", IsBlocked = false} }, { "EC", new Configuration.CountrySettings(){ FullName = "Ecuador", IsBlocked = false} }, { "EG", new Configuration.CountrySettings(){ FullName = "Egypt", IsBlocked = false} }, { "SV", new Configuration.CountrySettings(){ FullName = "El Salvador", IsBlocked = false} }, { "GQ", new Configuration.CountrySettings(){ FullName = "Equatorial Guinea", IsBlocked = false} }, { "ER", new Configuration.CountrySettings(){ FullName = "Eritrea", IsBlocked = false} }, { "EE", new Configuration.CountrySettings(){ FullName = "Estonia", IsBlocked = false} }, { "ET", new Configuration.CountrySettings(){ FullName = "Ethiopia", IsBlocked = false} }, { "FK", new Configuration.CountrySettings(){ FullName = "Falkland Islands (Malvinas)", IsBlocked = false} }, { "FO", new Configuration.CountrySettings(){ FullName = "Faroe Islands", IsBlocked = false} }, { "FJ", new Configuration.CountrySettings(){ FullName = "Fiji", IsBlocked = false} }, { "FI", new Configuration.CountrySettings(){ FullName = "Finland", IsBlocked = false} }, { "FR", new Configuration.CountrySettings(){ FullName = "France", IsBlocked = false} }, { "GF", new Configuration.CountrySettings(){ FullName = "French Guiana", IsBlocked = false} }, { "PF", new Configuration.CountrySettings(){ FullName = "French Polynesia", IsBlocked = false} }, { "TF", new Configuration.CountrySettings(){ FullName = "French Southern Territories", IsBlocked = false} }, { "GA", new Configuration.CountrySettings(){ FullName = "Gabon", IsBlocked = false} }, { "GM", new Configuration.CountrySettings(){ FullName = "Gambia", IsBlocked = false} }, { "GE", new Configuration.CountrySettings(){ FullName = "Georgia", IsBlocked = false} }, { "DE", new Configuration.CountrySettings(){ FullName = "Germany", IsBlocked = false} }, { "GH", new Configuration.CountrySettings(){ FullName = "Ghana", IsBlocked = false} }, { "GI", new Configuration.CountrySettings(){ FullName = "Gibraltar", IsBlocked = false} }, { "GR", new Configuration.CountrySettings(){ FullName = "Greece", IsBlocked = false} }, { "GL", new Configuration.CountrySettings(){ FullName = "Greenland", IsBlocked = false} }, { "GD", new Configuration.CountrySettings(){ FullName = "Grenada", IsBlocked = false} }, { "GP", new Configuration.CountrySettings(){ FullName = "Guadeloupe", IsBlocked = false} }, { "GU", new Configuration.CountrySettings(){ FullName = "Guam", IsBlocked = false} }, { "GT", new Configuration.CountrySettings(){ FullName = "Guatemala", IsBlocked = false} }, { "GG", new Configuration.CountrySettings(){ FullName = "Guernsey", IsBlocked = false} }, { "GN", new Configuration.CountrySettings(){ FullName = "Guinea", IsBlocked = false} }, { "GW", new Configuration.CountrySettings(){ FullName = "Guinea-Bissau", IsBlocked = false} }, { "GY", new Configuration.CountrySettings(){ FullName = "Guyana", IsBlocked = false} }, { "HT", new Configuration.CountrySettings(){ FullName = "Haiti", IsBlocked = false} }, { "HM", new Configuration.CountrySettings(){ FullName = "Heard Island & Mcdonald Islands", IsBlocked = false} }, { "VA", new Configuration.CountrySettings(){ FullName = "Holy See (Vatican City State)", IsBlocked = false} }, { "HN", new Configuration.CountrySettings(){ FullName = "Honduras", IsBlocked = false} }, { "HK", new Configuration.CountrySettings(){ FullName = "Hong Kong", IsBlocked = false} }, { "HU", new Configuration.CountrySettings(){ FullName = "Hungary", IsBlocked = false} }, { "IS", new Configuration.CountrySettings(){ FullName = "Iceland", IsBlocked = false} }, { "IN", new Configuration.CountrySettings(){ FullName = "India", IsBlocked = false} }, { "ID", new Configuration.CountrySettings(){ FullName = "Indonesia", IsBlocked = false} }, { "IR", new Configuration.CountrySettings(){ FullName = "Iran, Islamic Republic Of", IsBlocked = false} }, { "IQ", new Configuration.CountrySettings(){ FullName = "Iraq", IsBlocked = false} }, { "IE", new Configuration.CountrySettings(){ FullName = "Ireland", IsBlocked = false} }, { "IM", new Configuration.CountrySettings(){ FullName = "Isle Of Man", IsBlocked = false} }, { "IL", new Configuration.CountrySettings(){ FullName = "Israel", IsBlocked = false} }, { "IT", new Configuration.CountrySettings(){ FullName = "Italy", IsBlocked = false} }, { "JM", new Configuration.CountrySettings(){ FullName = "Jamaica", IsBlocked = false} }, { "JP", new Configuration.CountrySettings(){ FullName = "Japan", IsBlocked = false} }, { "JE", new Configuration.CountrySettings(){ FullName = "Jersey", IsBlocked = false} }, { "JO", new Configuration.CountrySettings(){ FullName = "Jordan", IsBlocked = false} }, { "KZ", new Configuration.CountrySettings(){ FullName = "Kazakhstan", IsBlocked = false} }, { "KE", new Configuration.CountrySettings(){ FullName = "Kenya", IsBlocked = false} }, { "KI", new Configuration.CountrySettings(){ FullName = "Kiribati", IsBlocked = false} }, { "KR", new Configuration.CountrySettings(){ FullName = "Korea", IsBlocked = false} }, { "KP", new Configuration.CountrySettings(){ FullName = "North Korea", IsBlocked = false} }, { "KW", new Configuration.CountrySettings(){ FullName = "Kuwait", IsBlocked = false} }, { "KG", new Configuration.CountrySettings(){ FullName = "Kyrgyzstan", IsBlocked = false} }, { "LA", new Configuration.CountrySettings(){ FullName = "Lao People\"s Democratic Republic", IsBlocked = false} }, { "LV", new Configuration.CountrySettings(){ FullName = "Latvia", IsBlocked = false} }, { "LB", new Configuration.CountrySettings(){ FullName = "Lebanon", IsBlocked = false} }, { "LS", new Configuration.CountrySettings(){ FullName = "Lesotho", IsBlocked = false} }, { "LR", new Configuration.CountrySettings(){ FullName = "Liberia", IsBlocked = false} }, { "LY", new Configuration.CountrySettings(){ FullName = "Libyan Arab Jamahiriya", IsBlocked = false} }, { "LI", new Configuration.CountrySettings(){ FullName = "Liechtenstein", IsBlocked = false} }, { "LT", new Configuration.CountrySettings(){ FullName = "Lithuania", IsBlocked = false} }, { "LU", new Configuration.CountrySettings(){ FullName = "Luxembourg", IsBlocked = false} }, { "MO", new Configuration.CountrySettings(){ FullName = "Macao", IsBlocked = false} }, { "MK", new Configuration.CountrySettings(){ FullName = "Macedonia", IsBlocked = false} }, { "MG", new Configuration.CountrySettings(){ FullName = "Madagascar", IsBlocked = false} }, { "MW", new Configuration.CountrySettings(){ FullName = "Malawi", IsBlocked = false} }, { "MY", new Configuration.CountrySettings(){ FullName = "Malaysia", IsBlocked = false} }, { "MV", new Configuration.CountrySettings(){ FullName = "Maldives", IsBlocked = false} }, { "ML", new Configuration.CountrySettings(){ FullName = "Mali", IsBlocked = false} }, { "MT", new Configuration.CountrySettings(){ FullName = "Malta", IsBlocked = false} }, { "MH", new Configuration.CountrySettings(){ FullName = "Marshall Islands", IsBlocked = false} }, { "MQ", new Configuration.CountrySettings(){ FullName = "Martinique", IsBlocked = false} }, { "MR", new Configuration.CountrySettings(){ FullName = "Mauritania", IsBlocked = false} }, { "MU", new Configuration.CountrySettings(){ FullName = "Mauritius", IsBlocked = false} }, { "YT", new Configuration.CountrySettings(){ FullName = "Mayotte", IsBlocked = false} }, { "MX", new Configuration.CountrySettings(){ FullName = "Mexico", IsBlocked = false} }, { "FM", new Configuration.CountrySettings(){ FullName = "Micronesia, Federated States Of", IsBlocked = false} }, { "MD", new Configuration.CountrySettings(){ FullName = "Moldova", IsBlocked = false} }, { "MC", new Configuration.CountrySettings(){ FullName = "Monaco", IsBlocked = false} }, { "MN", new Configuration.CountrySettings(){ FullName = "Mongolia", IsBlocked = false} }, { "ME", new Configuration.CountrySettings(){ FullName = "Montenegro", IsBlocked = false} }, { "MS", new Configuration.CountrySettings(){ FullName = "Montserrat", IsBlocked = false} }, { "MA", new Configuration.CountrySettings(){ FullName = "Morocco", IsBlocked = false} }, { "MZ", new Configuration.CountrySettings(){ FullName = "Mozambique", IsBlocked = false} }, { "MM", new Configuration.CountrySettings(){ FullName = "Myanmar", IsBlocked = false} }, { "NA", new Configuration.CountrySettings(){ FullName = "Namibia", IsBlocked = false} }, { "NR", new Configuration.CountrySettings(){ FullName = "Nauru", IsBlocked = false} }, { "NP", new Configuration.CountrySettings(){ FullName = "Nepal", IsBlocked = false} }, { "NL", new Configuration.CountrySettings(){ FullName = "Netherlands", IsBlocked = false} }, { "AN", new Configuration.CountrySettings(){ FullName = "Netherlands Antilles", IsBlocked = false} }, { "NC", new Configuration.CountrySettings(){ FullName = "New Caledonia", IsBlocked = false} }, { "NZ", new Configuration.CountrySettings(){ FullName = "New Zealand", IsBlocked = false} }, { "NI", new Configuration.CountrySettings(){ FullName = "Nicaragua", IsBlocked = false} }, { "NE", new Configuration.CountrySettings(){ FullName = "Niger", IsBlocked = false} }, { "NG", new Configuration.CountrySettings(){ FullName = "Nigeria", IsBlocked = false} }, { "NU", new Configuration.CountrySettings(){ FullName = "Niue", IsBlocked = false} }, { "NF", new Configuration.CountrySettings(){ FullName = "Norfolk Island", IsBlocked = false} }, { "MP", new Configuration.CountrySettings(){ FullName = "Northern Mariana Islands", IsBlocked = false} }, { "NO", new Configuration.CountrySettings(){ FullName = "Norway", IsBlocked = false} }, { "OM", new Configuration.CountrySettings(){ FullName = "Oman", IsBlocked = false} }, { "PK", new Configuration.CountrySettings(){ FullName = "Pakistan", IsBlocked = false} }, { "PW", new Configuration.CountrySettings(){ FullName = "Palau", IsBlocked = false} }, { "PS", new Configuration.CountrySettings(){ FullName = "Palestinian Territory, Occupied", IsBlocked = false} }, { "PA", new Configuration.CountrySettings(){ FullName = "Panama", IsBlocked = false} }, { "PG", new Configuration.CountrySettings(){ FullName = "Papua New Guinea", IsBlocked = false} }, { "PY", new Configuration.CountrySettings(){ FullName = "Paraguay", IsBlocked = false} }, { "PE", new Configuration.CountrySettings(){ FullName = "Peru", IsBlocked = false} }, { "PH", new Configuration.CountrySettings(){ FullName = "Philippines", IsBlocked = false} }, { "PN", new Configuration.CountrySettings(){ FullName = "Pitcairn", IsBlocked = false} }, { "PL", new Configuration.CountrySettings(){ FullName = "Poland", IsBlocked = false} }, { "PT", new Configuration.CountrySettings(){ FullName = "Portugal", IsBlocked = false} }, { "PR", new Configuration.CountrySettings(){ FullName = "Puerto Rico", IsBlocked = false} }, { "QA", new Configuration.CountrySettings(){ FullName = "Qatar", IsBlocked = false} }, { "RE", new Configuration.CountrySettings(){ FullName = "Reunion", IsBlocked = false} }, { "RO", new Configuration.CountrySettings(){ FullName = "Romania", IsBlocked = false} }, { "RU", new Configuration.CountrySettings(){ FullName = "Russian Federation", IsBlocked = false} }, { "RW", new Configuration.CountrySettings(){ FullName = "Rwanda", IsBlocked = false} }, { "BL", new Configuration.CountrySettings(){ FullName = "Saint Barthelemy", IsBlocked = false} }, { "SH", new Configuration.CountrySettings(){ FullName = "Saint Helena", IsBlocked = false} }, { "KN", new Configuration.CountrySettings(){ FullName = "Saint Kitts And Nevis", IsBlocked = false} }, { "LC", new Configuration.CountrySettings(){ FullName = "Saint Lucia", IsBlocked = false} }, { "MF", new Configuration.CountrySettings(){ FullName = "Saint Martin", IsBlocked = false} }, { "PM", new Configuration.CountrySettings(){ FullName = "Saint Pierre And Miquelon", IsBlocked = false} }, { "VC", new Configuration.CountrySettings(){ FullName = "Saint Vincent And Grenadines", IsBlocked = false} }, { "WS", new Configuration.CountrySettings(){ FullName = "Samoa", IsBlocked = false} }, { "SM", new Configuration.CountrySettings(){ FullName = "San Marino", IsBlocked = false} }, { "ST", new Configuration.CountrySettings(){ FullName = "Sao Tome And Principe", IsBlocked = false} }, { "SA", new Configuration.CountrySettings(){ FullName = "Saudi Arabia", IsBlocked = false} }, { "SN", new Configuration.CountrySettings(){ FullName = "Senegal", IsBlocked = false} }, { "RS", new Configuration.CountrySettings(){ FullName = "Serbia", IsBlocked = false} }, { "SC", new Configuration.CountrySettings(){ FullName = "Seychelles", IsBlocked = false} }, { "SL", new Configuration.CountrySettings(){ FullName = "Sierra Leone", IsBlocked = false} }, { "SG", new Configuration.CountrySettings(){ FullName = "Singapore", IsBlocked = false} }, { "SK", new Configuration.CountrySettings(){ FullName = "Slovakia", IsBlocked = false} }, { "SI", new Configuration.CountrySettings(){ FullName = "Slovenia", IsBlocked = false} }, { "SB", new Configuration.CountrySettings(){ FullName = "Solomon Islands", IsBlocked = false} }, { "SO", new Configuration.CountrySettings(){ FullName = "Somalia", IsBlocked = false} }, { "ZA", new Configuration.CountrySettings(){ FullName = "South Africa", IsBlocked = false} }, { "GS", new Configuration.CountrySettings(){ FullName = "South Georgia And Sandwich Isl.", IsBlocked = false} }, { "ES", new Configuration.CountrySettings(){ FullName = "Spain", IsBlocked = false} }, { "LK", new Configuration.CountrySettings(){ FullName = "Sri Lanka", IsBlocked = false} }, { "SD", new Configuration.CountrySettings(){ FullName = "Sudan", IsBlocked = false} }, { "SR", new Configuration.CountrySettings(){ FullName = "Suriname", IsBlocked = false} }, { "SJ", new Configuration.CountrySettings(){ FullName = "Svalbard And Jan Mayen", IsBlocked = false} }, { "SZ", new Configuration.CountrySettings(){ FullName = "Swaziland", IsBlocked = false} }, { "SE", new Configuration.CountrySettings(){ FullName = "Sweden", IsBlocked = false} }, { "CH", new Configuration.CountrySettings(){ FullName = "Switzerland", IsBlocked = false} }, { "SY", new Configuration.CountrySettings(){ FullName = "Syrian Arab Republic", IsBlocked = false} }, { "TW", new Configuration.CountrySettings(){ FullName = "Taiwan", IsBlocked = false} }, { "TJ", new Configuration.CountrySettings(){ FullName = "Tajikistan", IsBlocked = false} }, { "TZ", new Configuration.CountrySettings(){ FullName = "Tanzania", IsBlocked = false} }, { "TH", new Configuration.CountrySettings(){ FullName = "Thailand", IsBlocked = false} }, { "TL", new Configuration.CountrySettings(){ FullName = "Timor-Leste", IsBlocked = false} }, { "TG", new Configuration.CountrySettings(){ FullName = "Togo", IsBlocked = false} }, { "TK", new Configuration.CountrySettings(){ FullName = "Tokelau", IsBlocked = false} }, { "TO", new Configuration.CountrySettings(){ FullName = "Tonga", IsBlocked = false} }, { "TT", new Configuration.CountrySettings(){ FullName = "Trinidad And Tobago", IsBlocked = false} }, { "TN", new Configuration.CountrySettings(){ FullName = "Tunisia", IsBlocked = false} }, { "TR", new Configuration.CountrySettings(){ FullName = "Turkey", IsBlocked = false} }, { "TM", new Configuration.CountrySettings(){ FullName = "Turkmenistan", IsBlocked = false} }, { "TC", new Configuration.CountrySettings(){ FullName = "Turks And Caicos Islands", IsBlocked = false} }, { "TV", new Configuration.CountrySettings(){ FullName = "Tuvalu", IsBlocked = false} }, { "UG", new Configuration.CountrySettings(){ FullName = "Uganda", IsBlocked = false} }, { "UA", new Configuration.CountrySettings(){ FullName = "Ukraine", IsBlocked = false} }, { "AE", new Configuration.CountrySettings(){ FullName = "United Arab Emirates", IsBlocked = false} }, { "GB", new Configuration.CountrySettings(){ FullName = "United Kingdom", IsBlocked = false} }, { "US", new Configuration.CountrySettings(){ FullName = "United States", IsBlocked = false} }, { "UM", new Configuration.CountrySettings(){ FullName = "United States Outlying Islands", IsBlocked = false} }, { "UY", new Configuration.CountrySettings(){ FullName = "Uruguay", IsBlocked = false} }, { "UZ", new Configuration.CountrySettings(){ FullName = "Uzbekistan", IsBlocked = false} }, { "VU", new Configuration.CountrySettings(){ FullName = "Vanuatu", IsBlocked = false} }, { "VE", new Configuration.CountrySettings(){ FullName = "Venezuela", IsBlocked = false} }, { "VN", new Configuration.CountrySettings(){ FullName = "Vietnam", IsBlocked = false} }, { "VG", new Configuration.CountrySettings(){ FullName = "Virgin Islands, British", IsBlocked = false} }, { "VI", new Configuration.CountrySettings(){ FullName = "Virgin Islands, U.S.", IsBlocked = false} }, { "WF", new Configuration.CountrySettings(){ FullName = "Wallis And Futuna", IsBlocked = false} }, { "EH", new Configuration.CountrySettings(){ FullName = "Western Sahara", IsBlocked = false} }, { "YE", new Configuration.CountrySettings(){ FullName = "Yemen", IsBlocked = false} }, { "ZM", new Configuration.CountrySettings(){ FullName = "Zambia", IsBlocked = false} }, { "ZW", new Configuration.CountrySettings(){ FullName = "Zimbabwe", IsBlocked = false} } }, BlockMessage = "COUNTRY BLOCKED: {countryCode}" }; } #endregion private void Init() { permission.RegisterPermission(perm, this); } void OnClientAuth(Connection connection) { // Puts($"User with steamid {connection.userid.ToString()} connecting, they {(permission.UserHasPermission(connection.userid.ToString(), perm) ? "" : "do not ")}have permission {perm}"); if (permission.UserHasPermission(connection.userid.ToString(), perm)) return; var objects = new Dictionary(); webrequest.EnqueueGet($"http://ip-api.com/json/{connection.ipaddress.Split(':')[0]}", (code, response) => { // Puts($"Response from http://www.geoplugin.net/json.gp?ip={connection.ipaddress.Split(':')[0]} is {((response == null) ? "" : "not ")}null"); // Puts($"Response code = {code}"); if (response == null || code != 200) { return; } objects = JsonConvert.DeserializeObject>(response); string countryCode = objects["countryCode"].ToString(); if(_config.CountriesSettings.ContainsKey(countryCode)) { Puts($"IP {connection.ipaddress.Split(':')[0]} from {countryCode} trying to connect, and is {(_config.CountriesSettings[countryCode].IsBlocked ? "" : "not ")}blocked"); } else { Puts($"IP {connection.ipaddress.Split(':')[0]} from {countryCode} trying to connect, and does not appear in the config"); } if (_config.CountriesSettings.ContainsKey(countryCode) && _config.CountriesSettings[countryCode].IsBlocked) { string blockMessage = _config.BlockMessage.Replace("{countryCode}", countryCode); Net.sv.Kick(connection, blockMessage); } }, this); } } }