public void Setup() { string dbPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase); dbPath = dbPath.Remove(0, 6); dbPath = Path.Combine(dbPath, @"..\..\..\Test Data\GeoLiteCity.dat"); DirectoryInfo dirInfo = new DirectoryInfo(dbPath); service = new LookupService(dirInfo.FullName); }
private MaxMind.GeoIP.LookupService GetLookupService() { return(_cacheManager.Get("GeoCountryLookup", () => { var lookupService = new MaxMind.GeoIP.LookupService(_webHelper.MapPath("~/App_Data/GeoIP.dat")); return lookupService; })); }
private MaxMind.GeoIP.LookupService GetLookupService() { return _cacheManager.Get("GeoCountryLookup", () => { var lookupService = new MaxMind.GeoIP.LookupService(_webHelper.MapPath("~/App_Data/GeoIP.dat")); return lookupService; }); }
///<summary> /// This method is for handling the plugin's commands. ///</summary> ///<param name="args">Containing event data.</param> private void TSGeoIPCMD(CommandArgs args) { if (args.Parameters.Count < 1) { args.Player.SendErrorMessage("Invalid syntax! Proper syntax:"); args.Player.SendErrorMessage("{0}tsgeoip reload_set", TShock.Config.CommandSpecifier); args.Player.SendErrorMessage("{0}tsgeoip save_set", TShock.Config.CommandSpecifier); args.Player.SendErrorMessage("{0}tsgeoip dbmode <geoip/geoip2>", TShock.Config.CommandSpecifier); args.Player.SendErrorMessage("{0}tsgeoip prefix true|false", TShock.Config.CommandSpecifier); args.Player.SendErrorMessage("{0}tsgeoip suffix true|false", TShock.Config.CommandSpecifier); args.Player.SendErrorMessage("{0}tsgeoip prefix_str \"({0}) \"", TShock.Config.CommandSpecifier); args.Player.SendErrorMessage("{0}tsgeoip suffix_str \" ({0})\"", TShock.Config.CommandSpecifier); args.Player.SendErrorMessage("{0}tsgeoip akl <add/remove> <country code>", TShock.Config.CommandSpecifier); args.Player.SendErrorMessage("{0}tsgeoip akl_list", TShock.Config.CommandSpecifier); args.Player.SendErrorMessage("{0}tsgeoip aklw <add/remove> <player name>", TShock.Config.CommandSpecifier); args.Player.SendErrorMessage("{0}tsgeoip aklw_list", TShock.Config.CommandSpecifier); return; } switch (args.Parameters[0].ToLower()) { case "reload_set": { Settings.LoadSettings(); } return; case "save_set": { Settings.SaveSettting(); } return; case "dbmode": { if (args.Parameters.Count != 2) { args.Player.SendErrorMessage("Invalid syntax: {0}tsgeoip dbmode <geoip/geoip2>", TShock.Config.CommandSpecifier); return; } switch (args.Parameters[1].ToLower()) { case "geoip": { iSettings.GeoIP_API = "GeoIP"; if (File.Exists(this.geoIPDB)) { this.geoIPLS = new LookupService(this.geoIPDB, LookupService.GEOIP_STANDARD); try { this.geoIP2DBR.Dispose(); } catch (Exception) { } try { this.geoIP2DBR = null; } catch (Exception) { } } else { ConsoleLOG("There is no GeoLiteCity.dat", TraceLevel.Error); this.geoIPLS = null; } Settings.SaveSettting(); } return; case "geoip2": { iSettings.GeoIP_API = "GeoIP2"; if (File.Exists(this.geoIP2DB)) { this.geoIP2DBR = new DatabaseReader(this.geoIP2DB); try { this.geoIPLS = null; } catch (Exception) { } } else { ConsoleLOG("There is no GeoLite2-City.mmdb", TraceLevel.Error); this.geoIP2DBR = null; } Settings.SaveSettting(); } return; } } return; case "prefix": { try { if (args.Parameters[1].ToLower() == "false" || args.Parameters[1].ToLower() == "true" || args.Parameters.Count == 2) { iSettings.AsPrefix = bool.Parse(args.Parameters[1].ToLower()); Settings.SaveSettting(); } else { args.Player.SendErrorMessage("Invalid syntax: {0}tsgeoip prefix true|false", TShock.Config.CommandSpecifier); } } catch (Exception) { args.Player.SendErrorMessage("Invalid syntax: {0}tsgeoip prefix true|false", TShock.Config.CommandSpecifier); } } return; case "suffix": { try { if (args.Parameters[1].ToLower() == "false" || args.Parameters[1].ToLower() == "true" || args.Parameters.Count == 2) { iSettings.AsSuffix = bool.Parse(args.Parameters[1].ToLower()); Settings.SaveSettting(); } else { args.Player.SendErrorMessage("Invalid syntax: {0}tsgeoip suffix true|false", TShock.Config.CommandSpecifier); } } catch (Exception) { args.Player.SendErrorMessage("Invalid syntax: {0}tsgeoip suffix true|false", TShock.Config.CommandSpecifier); } } return; case "prefix_str": { if (args.Parameters.Count == 2 || args.Parameters[1].Contains("{0}")) { iSettings.PrefixString = args.Parameters[1]; Settings.SaveSettting(); } else { args.Player.SendErrorMessage("Invalid syntax: {0}tsgeoip prefix_str \"({0}) \"", TShock.Config.CommandSpecifier); } } return; case "suffix_str": { if (args.Parameters.Count == 2 || args.Parameters[1].Contains("{0}")) { iSettings.SuffixString = args.Parameters[1]; Settings.SaveSettting(); } else { args.Player.SendErrorMessage("Invalid syntax: {0}tsgeoip suffix_str \" ({0})\"", TShock.Config.CommandSpecifier); } } return; case "akl_list": { args.Player.SendInfoMessage("**AKL LIST**"); foreach (string ccode in TSGeoIP.iSettings.AKC_List) { args.Player.SendInfoMessage(" " + ccode); } args.Player.SendInfoMessage("**AKL LIST**"); } return; case "aklw_list": { args.Player.SendInfoMessage("**AKL WHITELIST**"); foreach (string ccode in TSGeoIP.iSettings.AKC_White_List) { args.Player.SendInfoMessage(" " + ccode); } args.Player.SendInfoMessage("**AKL WHITELIST**"); } return; case "akl": { if (args.Parameters.Count != 3) { args.Player.SendErrorMessage("Invalid syntax: {0}tsgeoip akl <add/remove> <country code>", TShock.Config.CommandSpecifier); return; } switch (args.Parameters[1].ToLower()) { case "add": { TSGeoIP.iSettings.AKC_List.Add(args.Parameters[2].ToLower()); args.Player.SendInfoMessage("Added the country code to the list!"); Settings.SaveSettting(); } return; case "remove": { TSGeoIP.iSettings.AKC_List.Remove(args.Parameters[2].ToLower()); args.Player.SendInfoMessage("Removed the country code from the list!"); Settings.SaveSettting(); } return; } } return; case "aklw": { if (args.Parameters.Count != 3) { args.Player.SendErrorMessage("Invalid syntax: {0}tsgeoip aklw <add/remove> <player name>", TShock.Config.CommandSpecifier); return; } switch (args.Parameters[1].ToLower()) { case "add": { TSGeoIP.iSettings.AKC_White_List.Add(args.Parameters[2].ToLower()); args.Player.SendInfoMessage("Added player to the whitelist!"); Settings.SaveSettting(); } return; case "remove": { TSGeoIP.iSettings.AKC_White_List.Remove(args.Parameters[2].ToLower()); args.Player.SendInfoMessage("Removed player from the whitelist!"); Settings.SaveSettting(); } return; } } return; case "help": { args.Player.SendInfoMessage("{0}tsgeoip reload_set", TShock.Config.CommandSpecifier); args.Player.SendInfoMessage("{0}tsgeoip save_set", TShock.Config.CommandSpecifier); args.Player.SendInfoMessage("{0}tsgeoip dbmode <geoip/geoip2>", TShock.Config.CommandSpecifier); args.Player.SendInfoMessage("{0}tsgeoip prefix true|false", TShock.Config.CommandSpecifier); args.Player.SendInfoMessage("{0}tsgeoip suffix true|false", TShock.Config.CommandSpecifier); args.Player.SendInfoMessage("{0}tsgeoip prefix_str \"({0}) \"", TShock.Config.CommandSpecifier); args.Player.SendInfoMessage("{0}tsgeoip suffix_str \" ({0})\"", TShock.Config.CommandSpecifier); args.Player.SendInfoMessage("{0}tsgeoip akl <add/remove> <country code>", TShock.Config.CommandSpecifier); args.Player.SendInfoMessage("{0}tsgeoip akl_list", TShock.Config.CommandSpecifier); args.Player.SendInfoMessage("{0}tsgeoip aklw <add/remove> <player name>", TShock.Config.CommandSpecifier); args.Player.SendInfoMessage("{0}tsgeoip aklw_list", TShock.Config.CommandSpecifier); } return; default: { args.Player.SendErrorMessage("Invalid subcommand. Type {0}tsgeoip help for a list of valid commands.", TShock.Config.CommandSpecifier); } return; } }
///<summary> /// Method to Initialize plugin's code. ///</summary> public override void Initialize() { that = this; ConsoleLOG("Initializing TSGeoIP!"); if (!Directory.Exists(dataDir)) { ConsoleLOG("Didn't found TSGeoIP folder!"); Directory.CreateDirectory(dataDir); ConsoleLOG("Created TSGeoIP folder!"); } else { ConsoleLOG("Found TSGeoIP folder!"); } iSettings = new Settings(); Settings.LoadSettings(); if (iSettings.GeoIP_API.ToLower() == "geoip") { if (File.Exists(this.geoIPDB)) { this.geoIPLS = new LookupService(this.geoIPDB, LookupService.GEOIP_STANDARD); } else { ConsoleLOG("There is no GeoLiteCity.dat", TraceLevel.Error); this.geoIPLS = null; } } if (iSettings.GeoIP_API.ToLower() == "geoip2") { if (File.Exists(this.geoIP2DB)) { this.geoIP2DBR = new DatabaseReader(this.geoIP2DB); } else { ConsoleLOG("There is no GeoLite2-City.mmdb", TraceLevel.Error); this.geoIP2DBR = null; } } ServerApi.Hooks.GameInitialize.Register(this, this.OnInitialize); ServerApi.Hooks.ServerJoin.Register(this, this.OnJoin); ServerApi.Hooks.NetGreetPlayer.Register(this, this.OnNetGreet); ServerApi.Hooks.ServerChat.Register(this, this.OnChat); ServerApi.Hooks.ServerLeave.Register(this, this.OnLeave); }