From d28f42c91af0c1eabe38d2cd1810b4ffed3385a7 Mon Sep 17 00:00:00 2001 From: Anthony Williams Date: Thu, 22 Feb 2018 15:15:10 -0500 Subject: [PATCH] Removed System.XML requirement, Added NanoXML, Added ability to add groups to elscar command, added better VCF sync handling to improve client connection performance and not bring server to crawl, removed crap, added indicator sync for all vehicles, added sounds, added forced patterns sync to sirens and horn, Fixed networking to get vehicle from all scripts, added better tick management to keep fps up, Changed controls to avoid conflicts with other scripts --- README.md | 28 +- server/ELS-Server/Class1.cs | 20 +- server/ELS-Server/Configuration.cs | 12 +- server/ELS-Server/CustomPatterns.cs | 25 +- server/ELS-Server/ELS-Server.csproj | 3 +- server/ELS-Server/NanoXMLParser.cs | 314 ++++ server/ELS-Server/Properties/AssemblyInfo.cs | 4 +- server/ELS-Server/VCF.cs | 6 +- server/ELS-Server/VcfSync.cs | 6 +- src/Decorator/DecorManager.cs | 24 - src/Decorator/EntityDecoration.cs | 83 -- src/ELS.cs | 84 +- src/ELS.csproj | 13 +- src/ELS.ini | 15 +- src/ELSStates/State.cs | 12 - src/Extra/Extra.cs | 66 +- src/FileLoader.cs | 2 +- src/Light/IPatterns.cs | 1 + src/Light/Indicator.cs | 125 ++ src/Light/Light.Loop.cs | 1 + src/Light/LightStage.cs | 67 - src/Light/Lights.Patterns.cs | 78 +- src/Light/Lights.cs | 2 +- src/Light/Lights.logic.cs | 64 +- src/Light/Patterns/CustomPattern.cs | 24 + src/Light/Stage.cs | 3 +- src/Manager/VehicleList.cs | 55 +- src/Manager/VehicleManager.cs | 102 +- src/NUI/ELSVehicleUIState.cs | 71 - src/NUI/ElsUiPanel.cs | 12 + src/Properties/AssemblyInfo.cs | 6 +- src/RemoteEventManager.cs | 5 +- src/Siren/MainSiren/MainSiren.FullSync.cs | 2 +- src/Siren/MainSiren/MainSiren.cs | 11 +- src/Siren/Siren/Controls/Siren.Controls.KB.cs | 4 +- src/Siren/Siren/Siren.Logic.cs | 125 +- src/Siren/Siren/Siren.Loop.cs | 7 +- src/Siren/Siren/Siren.cs | 26 +- src/Siren/Tone/Tone.cs | 27 +- src/TrafficControl/Vehicles.cs | 21 +- src/Vehicle/ELSVehicle.cs | 53 +- src/__resource.lua | 11 +- src/configuration/ElsConfiguration.cs | 12 + src/configuration/NanoXMLParser.cs | 314 ++++ src/configuration/VCF.cs | 1303 +++++++++++------ src/{ELS-FiveM.sln => elsplus.sln} | 0 src/extentions.cs | 2 +- src/panel/test.cs | 178 --- 48 files changed, 2213 insertions(+), 1216 deletions(-) create mode 100644 server/ELS-Server/NanoXMLParser.cs delete mode 100644 src/Decorator/DecorManager.cs delete mode 100644 src/Decorator/EntityDecoration.cs delete mode 100644 src/ELSStates/State.cs create mode 100644 src/Light/Indicator.cs delete mode 100644 src/Light/LightStage.cs create mode 100644 src/Light/Patterns/CustomPattern.cs delete mode 100644 src/NUI/ELSVehicleUIState.cs create mode 100644 src/configuration/NanoXMLParser.cs rename src/{ELS-FiveM.sln => elsplus.sln} (100%) delete mode 100644 src/panel/test.cs diff --git a/README.md b/README.md index d07f1e9..4c446ab 100644 --- a/README.md +++ b/README.md @@ -14,20 +14,20 @@ See: https://github.com/ejb1123/ELS-Plus/issues to submit an issue. It is import |Action Key|Default Key|Default Binding |---|---|---| -|Team Text Chat | Y key | Horn control| -|Select Unarmed Weapon | 1 Key | Wail tone | -|Select Melee Weapon | 2 Key | Yelp tone | -|Select Shotgun Weapon | 3 Key | Auxilary tone 1| -|Select Heavy Weapon | 4 Key | Auxilary tone 2| -|Select Special Weapon | 5 Key | Toggles Dual Siren Mode| -|Chat All| T Key|Goes to next tone or plays tone 1| -|Throw Grenade| G Key|Toggles main siren| -|Vehicle Horn | E Key | Toggles vehicle's Light Stages| -|Multiplayer Info | Z Key | Toggles vehicle's Primary Patterns| -| | X Key | Toggles vehicle's Secondary Patterns| -| | C Key | Toggles vehicle's Warning Patterns| -|Cover | Q Key | Toggles vehicle's Takedown Lights (Extra 12)| -|Cover | Alt + Q Key | Toggles vehicle's Scene Lights (Extra 11)| +| Vehicle Horn | E key | Horn control| +| Select Unarmed Weapon | 1 Key | Wail tone | +| Select Melee Weapon | 2 Key | Yelp tone | +| Select Shotgun Weapon | 3 Key | Auxilary tone 1| +| Select Heavy Weapon | 4 Key | Auxilary tone 2| +| Select Special Weapon | 5 Key | Toggles Dual Siren Mode| +| Chat All| Y Key|Goes to next tone or plays tone 1| +| Throw Grenade| G Key|Toggles main siren| +| Radio Wheel | Q Key | Toggles vehicle's Light Stages| +| Multiplayer Info | Z Key | Toggles vehicle's Primary Patterns| +| Drop Projectile | X Key | Toggles vehicle's Secondary Patterns| +| Look Behind | C Key | Toggles vehicle's Warning Patterns| +| Vehicle Next Radio Track | . Key | Toggles vehicle's Takedown Lights (Extra 12)| +| Vehicle Next Radio Track | Alt + . Key | Toggles vehicle's Scene Lights (Extra 11)| |Replay Show Hot Key | K Key | Toggles vehicle's secondary lights| |Cinematic Slo Mo | L Key | Toggles vehicle's warning lights| || [ Key | Toggles vehicle's Cruise Lights| diff --git a/server/ELS-Server/Class1.cs b/server/ELS-Server/Class1.cs index 39ff35a..e18ef9f 100644 --- a/server/ELS-Server/Class1.cs +++ b/server/ELS-Server/Class1.cs @@ -14,11 +14,11 @@ public class Class1 : BaseScript VcfSync _vcfSync; public Class1() { - - API.ExecuteCommand("add_ace group.admin command.elscar allow"); - API.ExecuteCommand("add_ace group.superadmin command.elscar allow"); - Debug.WriteLine("Welcome to ELS for FiveM"); - + Debug.WriteLine("Welcome to ELS+ for FiveM"); + foreach(string s in Configuration.ElsVehicleGroups) + { + API.ExecuteCommand($"add_ace group.{s} command.elscar allow"); + } API.RegisterCommand("vcfrefresh", new Action, string>((source, arguments, raw) => { Debug.WriteLine($"{Players[source].Name} has activated a VCF Refresh"); @@ -39,10 +39,12 @@ public Class1() TriggerClientEvent(Players[source], "ELS:SpawnCar", arguments[0]); }), Configuration.ElsCarAdminOnly); - EventHandlers["ELS:VcfSync:Server"] += new Action((int source) => + EventHandlers["ELS:VcfSync:Server"] += new Action(async (int source) => { + Utils.DebugWriteLine($"Sending Data to {Players[source].Name}"); _vcfSync = new VcfSync(); - _vcfSync.CheckVCF(Players[source]); + await _vcfSync.CheckVCF(Players[source]); + await CustomPatterns.CheckCustomPatterns(Players[source]); }); EventHandlers["baseevents:enteredVehicle"] += new Action((veh,seat,name) => @@ -51,7 +53,7 @@ public Class1() TriggerClientEvent("ELS:VehicleEntered", veh); }); - EventHandlers.Add("onResourceStart", new Action((resource) => + /*EventHandlers.Add("onResourceStart", new Action((resource) => { if (VcfSync.ElsResources.Exists(res => res.Equals(resource))) { @@ -60,7 +62,7 @@ public Class1() VcfSync.LoadFilesPromScript(resource, p); } } - })); + }));*/ EventHandlers["ELS:FullSync:Unicast"] += new Action(() => { }); EventHandlers["ELS:FullSync:Broadcast"] += new Action((dataDic, playerID) => { diff --git a/server/ELS-Server/Configuration.cs b/server/ELS-Server/Configuration.cs index 1bd9a37..72c773b 100644 --- a/server/ELS-Server/Configuration.cs +++ b/server/ELS-Server/Configuration.cs @@ -34,13 +34,23 @@ internal static bool ElsCarAdminOnly get; private set; } + internal static List ElsVehicleGroups + { + get; set; + } + static Configuration() { var data = API.LoadResourceFile(API.GetCurrentResourceName(), "ELS.ini"); if (isValidData(data)) { - var u = SharpConfig.Configuration.LoadFromString(data); + SharpConfig.Configuration u = SharpConfig.Configuration.LoadFromString(data); ElsCarAdminOnly = u["ADMIN"]["ElsCarAdminOnly"].BoolValue; + ElsVehicleGroups = new List(); + foreach(string s in u["ADMIN"]["Groups"].StringValueArray) + { + ElsVehicleGroups.Add(s); + } } } diff --git a/server/ELS-Server/CustomPatterns.cs b/server/ELS-Server/CustomPatterns.cs index 8b454bd..03a0539 100644 --- a/server/ELS-Server/CustomPatterns.cs +++ b/server/ELS-Server/CustomPatterns.cs @@ -11,16 +11,16 @@ namespace ELS_Server { public class CustomPatterns { + static List> Patterns = new List>(); internal static bool IsValidPatternData(string data) { if (String.IsNullOrEmpty(data)) return false; - System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); - doc.LoadXml(data); + NanoXMLDocument doc = new NanoXMLDocument(data); //TODO change how below is detected to account for xml meta tag being before it. - return doc.DocumentElement.Name == "pattern"; + return doc.RootNode.Name == "pattern"; } - public void CheckVCF(Player player) + public async static Task CheckCustomPatterns(Player player) { var numResources = API.GetNumResources(); for (int x = 0; x < numResources; x++) @@ -28,6 +28,7 @@ public void CheckVCF(Player player) var name = Function.Call(Hash.GET_RESOURCE_BY_FIND_INDEX, x); ParsePatterns(name, player); } + Class1.TriggerClientEvent(player, "ELS:PatternSync:Client", Patterns); } internal static void ParsePatterns(string name, Player player) @@ -39,33 +40,25 @@ internal static void ParsePatterns(string name, Player player) for (int i = 0; i < num; i++) { var filename = Function.Call(Hash.GET_RESOURCE_METADATA, name, "file", i); - var data = Function.Call(Hash.LOAD_RESOURCE_FILE, name, filename); - -#if DEBUG - CitizenFX.Core.Debug.WriteLine($"Checking {filename}"); -#endif + Utils.DebugWriteLine($"Checking {filename}"); if (Path.GetExtension(filename).ToLower() == ".xml") { if (CustomPatterns.IsValidPatternData(data)) { - Class1.TriggerClientEvent(player, "ELS:PatternSync:Client", name, filename, data); + Patterns.Add(new Tuple(name, filename, data)); } else { -#if DEBUG - CitizenFX.Core.Debug.WriteLine($"XML Pattern data for {filename} is not valid"); -#endif + Utils.DebugWriteLine($"XML Pattern data for {filename} is not valid"); } } } } else { -#if DEBUG - CitizenFX.Core.Debug.WriteLine($"{name} is not an ELS Vehicle Resource"); -#endif + Utils.DebugWriteLine($"{name} is not an ELS Vehicle Resource"); } } } diff --git a/server/ELS-Server/ELS-Server.csproj b/server/ELS-Server/ELS-Server.csproj index 9bd7813..7fe4acd 100644 --- a/server/ELS-Server/ELS-Server.csproj +++ b/server/ELS-Server/ELS-Server.csproj @@ -38,17 +38,16 @@ - - + diff --git a/server/ELS-Server/NanoXMLParser.cs b/server/ELS-Server/NanoXMLParser.cs new file mode 100644 index 0000000..0a7fa59 --- /dev/null +++ b/server/ELS-Server/NanoXMLParser.cs @@ -0,0 +1,314 @@ +using System; +using System.Collections.Generic; + +namespace ELS_Server +{ + /// + /// Base class containing usefull features for all XML classes + /// + class NanoXMLBase + { + protected static bool IsSpace(char c) + { + return c == ' ' || c == '\t' || c == '\n' || c == '\r'; + } + + protected static void SkipSpaces(string str, ref int i) + { + while (i < str.Length) + { + if (!IsSpace(str[i])) + { + if (str[i] == '<' && i + 4 < str.Length && str[i + 1] == '!' && str[i + 2] == '-' && str[i + 3] == '-') + { + i += 4; // skip