From da91d56513537b564697dc810d888474c6784773 Mon Sep 17 00:00:00 2001 From: high Date: Mon, 5 Sep 2011 22:07:51 -0400 Subject: [PATCH] Fixed geoip crashing on startup if geoip.dat is missing. Also fixed it crashing if you enable it without restarting tshock. --- TShockAPI/Rest/RestManager.cs | 1 - TShockAPI/TShock.cs | 8 +++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/TShockAPI/Rest/RestManager.cs b/TShockAPI/Rest/RestManager.cs index b7f2eef7..2b6a1f48 100644 --- a/TShockAPI/Rest/RestManager.cs +++ b/TShockAPI/Rest/RestManager.cs @@ -48,7 +48,6 @@ namespace TShockAPI object Status(RestVerbs verbs, IParameterCollection parameters) { - if (TShock.Config.EnableTokenEndpointAuthentication) return new RestObject("403") { Error = "Server settings require a token for this API call." }; diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index 6b1140c3..bebb5e35 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -182,8 +182,10 @@ namespace TShockAPI RestApi.Port = Config.RestApiPort; RestManager = new RestManager(RestApi); RestManager.RegisterRestfulCommands(); - if (Config.EnableGeoIP) - Geo = new MaxMind.GeoIPCountry(Path.Combine(SavePath, "GeoIP.dat")); + + var geoippath = Path.Combine(SavePath, "GeoIP.dat"); + if (Config.EnableGeoIP && File.Exists(geoippath)) + Geo = new MaxMind.GeoIPCountry(geoippath); Log.ConsoleInfo(string.Format("TShock Version {0} ({1}) now running.", Version, VersionCodename)); @@ -660,7 +662,7 @@ namespace TShockAPI NetMessage.SendData((int)PacketTypes.TimeSet, -1, -1, "", 0, 0, Main.sunModY, Main.moonModY); NetMessage.syncPlayers(); - if (Config.EnableGeoIP) + if (Config.EnableGeoIP && Geo != null) { var code = Geo.TryGetCountryCode(IPAddress.Parse(player.IP)); player.Country = code == null ? "N/A" : MaxMind.GeoIPCountry.GetCountryNameByCode(code);