Skip to content
This repository has been archived by the owner on Aug 8, 2024. It is now read-only.

Commit

Permalink
Merge pull request #45 from dexslab/master
Browse files Browse the repository at this point in the history
Removed System.XML requirement, Added NanoXML, Added ability to add g…
  • Loading branch information
ejb1123 authored Feb 22, 2018
2 parents 5903da3 + d28f42c commit 5a8b99e
Show file tree
Hide file tree
Showing 48 changed files with 2,213 additions and 1,216 deletions.
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
20 changes: 11 additions & 9 deletions server/ELS-Server/Class1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<int, List<object>, string>((source, arguments, raw) =>
{
Debug.WriteLine($"{Players[source].Name} has activated a VCF Refresh");
Expand All @@ -39,10 +39,12 @@ public Class1()
TriggerClientEvent(Players[source], "ELS:SpawnCar", arguments[0]);
}), Configuration.ElsCarAdminOnly);

EventHandlers["ELS:VcfSync:Server"] += new Action<int>((int source) =>
EventHandlers["ELS:VcfSync:Server"] += new Action<int>(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<int,int,string>((veh,seat,name) =>
Expand All @@ -51,7 +53,7 @@ public Class1()
TriggerClientEvent("ELS:VehicleEntered", veh);
});

EventHandlers.Add("onResourceStart", new Action<string>((resource) =>
/*EventHandlers.Add("onResourceStart", new Action<string>((resource) =>
{
if (VcfSync.ElsResources.Exists(res => res.Equals(resource)))
{
Expand All @@ -60,7 +62,7 @@ public Class1()
VcfSync.LoadFilesPromScript(resource, p);
}
}
}));
}));*/
EventHandlers["ELS:FullSync:Unicast"] += new Action(() => { });
EventHandlers["ELS:FullSync:Broadcast"] += new Action<System.Dynamic.ExpandoObject, int>((dataDic, playerID) =>
{
Expand Down
12 changes: 11 additions & 1 deletion server/ELS-Server/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,23 @@ internal static bool ElsCarAdminOnly
get; private set;
}

internal static List<string> 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<string>();
foreach(string s in u["ADMIN"]["Groups"].StringValueArray)
{
ElsVehicleGroups.Add(s);
}
}
}

Expand Down
25 changes: 9 additions & 16 deletions server/ELS-Server/CustomPatterns.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,24 @@ namespace ELS_Server
{
public class CustomPatterns
{
static List<Tuple<string, string, string>> Patterns = new List<Tuple<string, string, string>>();
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++)
{
var name = Function.Call<string>(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)
Expand All @@ -39,33 +40,25 @@ internal static void ParsePatterns(string name, Player player)
for (int i = 0; i < num; i++)
{
var filename = Function.Call<string>(Hash.GET_RESOURCE_METADATA, name, "file", i);

var data = Function.Call<string>(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<string, string, string>(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");
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions server/ELS-Server/ELS-Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,16 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Class1.cs" />
<Compile Include="Configuration.cs" />
<Compile Include="CustomPatterns.cs" />
<Compile Include="NanoXMLParser.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Utils.cs" />
<Compile Include="VCF.cs" />
Expand Down
Loading

0 comments on commit 5a8b99e

Please sign in to comment.