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