From f4551e8db11e680e470c5495d2e388c33516e19b Mon Sep 17 00:00:00 2001 From: icemagetv Date: Sat, 24 May 2014 16:34:45 -0500 Subject: [PATCH] Cleaned up dekessler vessel type detection, added asteroids. Cast protoVessel node of result to ConfigNode in order to extract values more accurately instead of using a string search. Added asteroids to dekessler (SpaceObject) as they will crash servers. --- KMPServer/Server.cs | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/KMPServer/Server.cs b/KMPServer/Server.cs index 9d34aab..9e1dd69 100644 --- a/KMPServer/Server.cs +++ b/KMPServer/Server.cs @@ -1311,19 +1311,12 @@ record => foreach (Tuple result in results) { KMPVesselUpdate vessel_update = (KMPVesselUpdate)ByteArrayToObject(result.Item1); - if (vessel_update.tick < cutOffTick) + ConfigNode protoVessel = (ConfigNode)ByteArrayToObject(result.Item2); + string vesselType = protoVessel.GetValue("type", 0); + if ((vessel_update.tick < cutOffTick && vesselType.Equals("Debris")) || vesselType.Equals("SpaceObject")) { - byte[] configNodeBytes = result.Item2; - string s = Encoding.UTF8.GetString(configNodeBytes, 0, configNodeBytes.Length); - if (s.IndexOf("type") > 0 && s.Length > s.IndexOf("type") + 20) - { - if (s.Substring(s.IndexOf("type"), 20).Contains("Debris")) - { - Database.ExecuteNonQuery("UPDATE kmpVessel SET Destroyed = 1 WHERE Guid = @guid", - "guid", result.Item3); - clearedCount++; - } - } + Database.ExecuteNonQuery("UPDATE kmpVessel SET Destroyed = 1 WHERE Guid = @guid", "guid", result.Item3); + clearedCount++; } } Log.Info("Debris older than {0} minutes cleared from universe database, {1} vessels affected.", minsToKeep, clearedCount); @@ -3876,4 +3869,4 @@ public int activeClientCount() return clients.Where(cl => cl.isReady).Count(); } } -} \ No newline at end of file +}