From fdbebf0be573ed2c1ac1243e033220cb99315b56 Mon Sep 17 00:00:00 2001 From: Dex Date: Fri, 9 Mar 2018 00:45:43 -0500 Subject: [PATCH] Fixed dependency issue of copying on build, fixed other script registration issues, Fixed Multiple registration issues, Added Registration list to verify how many times a vehicle has attempted registration, Updated readme --- .gitignore | 1 + README.md | 42 ++++---- server/ELS-Server/Properties/AssemblyInfo.cs | 4 +- src/ELS.csproj | 1 + src/Manager/VehicleList.cs | 78 ++++++++++---- src/Manager/VehicleManager.cs | 107 +++++++++++++------ src/Properties/AssemblyInfo.cs | 4 +- 7 files changed, 164 insertions(+), 73 deletions(-) diff --git a/.gitignore b/.gitignore index 1584b57..7eeb540 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ config.yml *.user *.userosscache *.sln.docstates +*.sync-conflict* # User-specific files (MonoDevelop/Xamarin Studio) *.userprefs diff --git a/README.md b/README.md index 4c446ab..d06d6d7 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ # ELS-Plus -See: https://github.com/ejb1123/ELS-Plus/issues to submit an issue. It is important that if you test ELS for FiveM that you submit issues so that we may work to resolve these. Here's some things to consider: +See: https://github.com/friendsincode/ELS-Plus/issues to submit an issue or use our discord here: . It is important that if you test ELS Plus for FiveM that you submit issues so that we may work to resolve these. Here's some things to consider: -- ELS vehicles are not yet supported. -- Lights are in progress. Currently sync is not working but you are able to use lights. +- ELS vehicles are fully supported. +- Full VCF parsing so you can totally customize vehicles. - Custom cars will require VCF files to be created by following the [How to add custom Vehicles](#how-to-add-els-vehicles-to-els-fivem) section. - You can spawn a vehicle using /elscar {model} -- You can obtain a list of the vehicles ELS has detected by typing /elslist and pressing F8 to view console. +- You can obtain a list of the vehicles ELS has detected by typing /elslist and pressing F8 to view console.(Plans to make menu in progress :D) @@ -44,24 +44,28 @@ See: https://github.com/ejb1123/ELS-Plus/issues to submit an issue. It is import ### How to install -1. Copy the `ELS-FiveM` folder to `cfx-server\resources\` -2. Add `ELS-FiveM` to `server.cfg` +1. Copy the `els-plus` folder to `cfx-server\resources\` +2. Add `start els-plus` to `server.cfg` 3. Add `add_ace resource.RESOURCE_NAME command.add_ace allow` to `server.cfg` remember to replace `RESOURCE_NAME` with the name of this resource. -4. Add your user to the `group.admin` principle to allow you to use the elscar commmand to spawn a vehicle +4. Modify settings via ini file how you see fit. +5. If you set AllowAdminOnly to `true` Add your user to the `group.admin` + principal with the following `add_principal identifier.[license||steam]:id# group.admin` + to allow you to use the elscar commmand to spawn a vehicle. +6. You can also add custom groups to els-plus to allow better control on who you wish to use the command. -### How to add ELS Vehicles to ELS-FiveM + +### How to add ELS Vehicles to ELS-Plus 1. Create add-on/replace Vehicle with stream folder and relevant files. -2. In `__resource.lua` add the `VCF` xml file to the `files` list. -3. Add `is_els 'true'` to bottom of `__resource.lua`. -4. Restart Server -5. Profit +2. In `__resource.lua` of that add-on/replace vehicle add the `VCF` xml file to the `files` list. +3. Make sure to validate the xml file to avoid issues with vehicle not showing up. +4. Add `is_els 'true'` to bottom of `__resource.lua`. +5. Restart Server +6. Profit #### Important Notes -- When running the rcon command `restart ELS-FiveM` or `start ELS-FiveM`. -Make sure you restart any resources that have ELS vehicles. -- Make sure ELS-FiveM is located below all ELS enabled vehicle stream resources in the `server.cfg` file. +- When running the rcon command `restart els-plus` or `start els-plus`. ## Contribute if you are a developer and would like to contribute any help is welcome! @@ -71,14 +75,14 @@ The contribution guide can be found [here](CONTRIBUTING.md). 1. Add the enviroment variable `FXSERVERDATA` and set its value to the `resources` directory path. -2. `git clone https://github.com/FiveM-Scripts/ELS-FiveM.git` +2. `git clone https://github.com/friendsincode/ELS-Plus.git` -3. Open `ELS-FiveM\src\ELS-for-FiveM.sln` in Visual Studio +3. Open `ELS-Plus\src\elsplus.sln` in Visual Studio 4. Select `Release` and `Any CPU` next to the Start button 5. In the menu bar under Build click on `Build Solution` -6. Copy all the files from `ELS-FiveM\src\bin\Release` to `cfx-server\resources\ELS-FiveM` +6. Copy all the files from `ELS-Plus\src\bin\Release` to `cfx-server\resources\els-plus` -7. Add `ELS-FiveM` to `AutoStartResources` in `cfx-server\citmp-server.yml` +7. Add `start els-plus` to `server.cfg` diff --git a/server/ELS-Server/Properties/AssemblyInfo.cs b/server/ELS-Server/Properties/AssemblyInfo.cs index 4009a1c..1b501f2 100644 --- a/server/ELS-Server/Properties/AssemblyInfo.cs +++ b/server/ELS-Server/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.2.1.0")] -[assembly: AssemblyFileVersion("0.2.1.0")] +[assembly: AssemblyVersion("0.2.2.0")] +[assembly: AssemblyFileVersion("0.2.2.0")] diff --git a/src/ELS.csproj b/src/ELS.csproj index 9f17cfa..345d762 100644 --- a/src/ELS.csproj +++ b/src/ELS.csproj @@ -82,6 +82,7 @@ ..\libs\CitizenFx\CitizenFX.Core.dll + False diff --git a/src/Manager/VehicleList.cs b/src/Manager/VehicleList.cs index acf3c40..762b1fc 100644 --- a/src/Manager/VehicleList.cs +++ b/src/Manager/VehicleList.cs @@ -12,10 +12,16 @@ namespace ELS.Manager { class VehicleList : Dictionary { + internal Dictionary> VehRegAttempts; //public new void Add(ELSVehicle veh) //{ // base.Add(veh); //} + + internal VehicleList() + { + VehRegAttempts = new Dictionary>(); + } public void Add(int NetworkID) { var veh = new ELSVehicle(API.NetToVeh(NetworkID)); @@ -38,7 +44,7 @@ public void RunExternalTick([Optional] ELSVehicle vehicle) } catch (Exception e) { - CitizenFX.Core.Debug.WriteLine($"VehicleList Error: {e.Message}"); + Utils.DebugWriteLine($"VehicleList Error: {e.Message}"); } } public bool MakeSureItExists(int NetworkID, [Optional]out ELSVehicle vehicle) @@ -52,6 +58,14 @@ public bool MakeSureItExists(int NetworkID, [Optional]out ELSVehicle vehicle) else if (!ContainsKey(NetworkID)) { + if (VehRegAttempts.ContainsKey(NetworkID)) + { + VehRegAttempts[NetworkID] = new Tuple(VehRegAttempts[NetworkID].Item1 + 1, Game.GameTime); + } + else + { + VehRegAttempts.Add(NetworkID, new Tuple(1, Game.GameTime)); + } try { ELSVehicle veh = null; @@ -65,14 +79,14 @@ public bool MakeSureItExists(int NetworkID, [Optional]out ELSVehicle vehicle) veh = new ELSVehicle(handle); } Add(NetworkID,veh); + //CurrentlyRegisteringVehicle.Remove(NetworkID); vehicle = veh; return true; } catch (Exception ex) { -#if DEBUG - CitizenFX.Core.Debug.Write($"Exsits Error: {ex.Message} due to {ex.InnerException}"); -#endif + Utils.DebugWriteLine($"Exsits Error: {ex.Message} due to {ex.InnerException}"); + //CurrentlyRegisteringVehicle.Remove(NetworkID); vehicle = null; return false; throw ex; @@ -85,7 +99,7 @@ public bool MakeSureItExists(int NetworkID, [Optional]out ELSVehicle vehicle) return true; } } - public bool MakeSureItExists(int NetworkID, IDictionary data, [Optional]out ELSVehicle vehicle) + public bool MakeSureItExists(int NetworkID, IDictionary data, [Optional]out ELSVehicle vehicle, int PlayerId = -1) { if (NetworkID == 0) { @@ -96,30 +110,55 @@ public bool MakeSureItExists(int NetworkID, IDictionary data, [O else if (!ContainsKey(NetworkID)) { + if (VehRegAttempts.ContainsKey(NetworkID)) + { + VehRegAttempts[NetworkID] = new Tuple(VehRegAttempts[NetworkID].Item1 + 1, Game.GameTime); + } + else + { + VehRegAttempts.Add(NetworkID, new Tuple(1, Game.GameTime)); + } try { ELSVehicle veh = null; - int handle = API.NetToVeh(NetworkID); - if (handle == 0) + int handle = API.NetworkGetEntityFromNetworkId(NetworkID); + if (handle == 0 && PlayerId != -1) { - veh = new ELSVehicle(Game.PlayerPed.CurrentVehicle.Handle,data); + Player player = new Player(API.GetPlayerFromServerId(PlayerId)); + Utils.DebugWriteLine($"Registering vehicle with netid of {NetworkID} to list from {player.Name}"); + if (!player.Character.IsSittingInELSVehicle()) + { + Utils.DebugWriteLine($"{player.Name} is not in an Els vehicle"); + vehicle = null; + return false; + } + veh = new ELSVehicle(player.Character.CurrentVehicle.Handle, data); } else { + Utils.DebugWriteLine($"Registering vehicle {NetworkID} to list from netid to veh"); veh = new ELSVehicle(handle,data); } - Add(NetworkID,veh); -#if DEBUG - CitizenFX.Core.Debug.Write($"Adding Vehicle"); -#endif - vehicle = veh; - return true; + if (veh != null) + { + //CurrentlyRegisteringVehicle.Remove(NetworkID); + Add(NetworkID, veh); + Utils.DebugWriteLine($"Added {NetworkID} to vehicle list"); + vehicle = veh; + return true; + } + else + { + //CurrentlyRegisteringVehicle.Remove(NetworkID); + Utils.DebugWriteLine("Failed to add vehicle to list please try again"); + vehicle = null; + return false; + } } catch (Exception ex) { -#if DEBUG - CitizenFX.Core.Debug.Write($"Exsits Error With Data: {ex.Message}"); -#endif + //CurrentlyRegisteringVehicle.Remove(NetworkID); + Utils.DebugWriteLine($"Exsits Error With Data: {ex.Message}"); vehicle = null; return false; throw ex; @@ -128,10 +167,13 @@ public bool MakeSureItExists(int NetworkID, IDictionary data, [O } else { - vehicle = this[NetworkID];//Find(poolObject => ((ELSVehicle)poolObject).GetNetworkId() == NetworkID); + Utils.DebugWriteLine($"Returning vehicle {NetworkID} from list"); + vehicle = this[NetworkID]; return true; } } + + public void CleanUP() { for(int i = 0; i < Count; i++) diff --git a/src/Manager/VehicleManager.cs b/src/Manager/VehicleManager.cs index 150da8d..440e13f 100644 --- a/src/Manager/VehicleManager.cs +++ b/src/Manager/VehicleManager.cs @@ -17,12 +17,13 @@ namespace ELS.Manager class VehicleManager { internal static VehicleList vehicleList; - bool notified = false; + static bool notified = false; public VehicleManager() { vehicleList = new VehicleList(); } - private void makenetworked(Vehicle veh) + + internal static void makenetworked(Vehicle veh) { ////////// /// @@ -34,7 +35,7 @@ private void makenetworked(Vehicle veh) var attempts = 0; do { - BaseScript.Delay(500); + //BaseScript.Delay(500); var netid = API.NetworkGetNetworkIdFromEntity(veh.Handle); API.NetworkRegisterEntityAsNetworked(veh.Handle); API.SetEntityAsMissionEntity(veh.Handle, false, false); @@ -64,43 +65,48 @@ internal async void RunTickAsync() (Game.PlayerPed.CurrentVehicle.GetPedOnSeat(VehicleSeat.Driver) == Game.PlayerPed || Game.PlayerPed.CurrentVehicle.GetPedOnSeat(VehicleSeat.Passenger) == Game.PlayerPed)) { - if (vehicleList.MakeSureItExists(API.VehToNet(Game.PlayerPed.CurrentVehicle.Handle), vehicle: out ELSVehicle _currentVehicle)) + if (vehicleList.ContainsKey(Game.PlayerPed.CurrentVehicle.GetNetworkId())) { + ELSVehicle _currentVehicle = vehicleList[Game.PlayerPed.CurrentVehicle.GetNetworkId()]; _currentVehicle?.RunTick(); vehicleList.RunExternalTick(_currentVehicle); Game.PlayerPed.CurrentVehicle.SetExistOnAllMachines(true); } else { - makenetworked(Game.PlayerPed.CurrentVehicle); - //var pos = Game.PlayerPed.CurrentVehicle.Position; - //var rot = Game.PlayerPed.CurrentVehicle.Rotation; - //var model = Game.PlayerPed.CurrentVehicle.Model; - //Game.PlayerPed.CurrentVehicle.Delete(); - //var veh = await World.CreateVehicle(model, pos, rot.Z); - //Game.PlayerPed.SetIntoVehicle(veh,VehicleSeat.Driver); - //vehicleList.Add(new ELSVehicle(Game.PlayerPed.CurrentVehicle.Handle)); + if (!vehicleList.VehRegAttempts.ContainsKey(Game.PlayerPed.CurrentVehicle.GetNetworkId()) || Game.GameTime - vehicleList.VehRegAttempts[Game.PlayerPed.CurrentVehicle.GetNetworkId()].Item2 >= 60000 && vehicleList.VehRegAttempts[Game.PlayerPed.CurrentVehicle.GetNetworkId()].Item1 < 5) + { + if (vehicleList.MakeSureItExists(API.VehToNet(Game.PlayerPed.CurrentVehicle.Handle), vehicle: out ELSVehicle _currentVehicle)) + { + _currentVehicle?.RunTick(); + vehicleList.RunExternalTick(_currentVehicle); + Game.PlayerPed.CurrentVehicle.SetExistOnAllMachines(true); + } + } } if (Game.PlayerPed.IsInVehicle() && (Game.PlayerPed.CurrentVehicle.GetPedOnSeat(VehicleSeat.Driver) == Game.PlayerPed) && (VehicleClass.Boats != Game.PlayerPed.CurrentVehicle.ClassType || VehicleClass.Trains != Game.PlayerPed.CurrentVehicle.ClassType || VehicleClass.Planes != Game.PlayerPed.CurrentVehicle.ClassType || VehicleClass.Helicopters != Game.PlayerPed.CurrentVehicle.ClassType)) { - makenetworked(Game.PlayerPed.CurrentVehicle); + if (Game.PlayerPed.CurrentVehicle.GetNetworkId() == 0) + { + makenetworked(Game.PlayerPed.CurrentVehicle); + } Indicator.RunAsync(Game.PlayerPed.CurrentVehicle); } #if DEBUG - if (Game.IsControlJustPressed(0, Control.Cover)) - { - FullSync.FullSyncManager.SendDataBroadcast( - _currentVehicle.GetData(), - Game.Player.ServerId - ); - CitizenFX.Core.UI.Screen.ShowNotification("FullSync™ ran"); - CitizenFX.Core.Debug.WriteLine("FullSync™ ran"); - } - Debug.DebugText(); + //if (Game.IsControlJustPressed(0, Control.Cover)) + //{ + // FullSync.FullSyncManager.SendDataBroadcast( + // _currentVehicle.GetData(), + // Game.Player.ServerId + // ); + // CitizenFX.Core.UI.Screen.ShowNotification("FullSync™ ran"); + // CitizenFX.Core.Debug.WriteLine("FullSync™ ran"); + //} + //Debug.DebugText(); #endif } else @@ -122,17 +128,54 @@ internal async void RunTickAsync() /// data async internal void SetVehicleSyncData(IDictionary dataDic,int PlayerId) { - if (Game.Player.ServerId == PlayerId) return; - var bo = vehicleList.MakeSureItExists((int)dataDic["NetworkID"] - , dataDic, out ELSVehicle veh1); - if (bo && dataDic.ContainsKey("siren") || dataDic.ContainsKey("light")) + if (Game.Player.ServerId == PlayerId) { - veh1.SetData(dataDic); + Utils.DebugWriteLine("We are player exiting set sync data"); + return; + } -#if DEBUG - CitizenFX.Core.Debug.Write($" Applying vehicle data with NETID of {(int)dataDic["NetworkID"]} LOCALID of {CitizenFX.Core.Native.API.NetToVeh((int)dataDic["NetworkID"])}"); -#endif + Utils.DebugWriteLine($"{PlayerId} has sent us data parsing"); + if (vehicleList.ContainsKey((int)dataDic["NetworkID"])) + { + vehicleList[(int)dataDic["NetworkID"]].SetData(dataDic); + Utils.DebugWriteLine($" Applying vehicle data with NETID of {(int)dataDic["NetworkID"]} LOCALID of {CitizenFX.Core.Native.API.NetToVeh((int)dataDic["NetworkID"])}"); + } + else + { + if (!vehicleList.VehRegAttempts.ContainsKey((int)dataDic["NetworkID"]) || Game.GameTime - vehicleList.VehRegAttempts[(int)dataDic["NetworkID"]].Item2 >= 600000 && vehicleList.VehRegAttempts[(int)dataDic["NetworkID"]].Item1 < 5) + { + if (!vehicleList.MakeSureItExists((int)dataDic["NetworkID"], dataDic, out ELSVehicle veh1, PlayerId)) + { + Utils.DebugWriteLine("Failed to register other clients vehicle"); + return; + } + veh1.SetData(dataDic); + } + else + { + Utils.DebugWriteLine("Attempting to register be patient"); + } } + //var bo = vehicleList.MakeSureItExists((int)dataDic["NetworkID"] + // , dataDic, out ELSVehicle veh1); + + //if (bo && dataDic.ContainsKey("siren") || dataDic.ContainsKey("light") && veh1 != null) + //{ + // veh1.SetData(dataDic); + + // Utils.DebugWriteLine($" Applying vehicle data with NETID of {(int)dataDic["NetworkID"]} LOCALID of {CitizenFX.Core.Native.API.NetToVeh((int)dataDic["NetworkID"])}"); + //} + //else if (veh1 == null && dataDic.ContainsKey("siren") || dataDic.ContainsKey("light")) + //{ + // Utils.DebugWriteLine("Vehicle is null we are fucking up"); + // bo = vehicleList.MakeSureItExists((int)dataDic["NetworkID"], dataDic, out veh1, PlayerId); + // if (!bo) + // { + // Utils.DebugWriteLine("Failed to register other clients vehicle"); + // return; + // } + // veh1.SetData(dataDic); + //} if (dataDic.ContainsKey("IndState")) { Utils.DebugWriteLine($"Ind sync data for {dataDic["NetworkID"].ToString()} is {dataDic["IndState"]}"); @@ -154,7 +197,7 @@ internal static void SyncRequestReply(Commands command,int NetworkId,int PlayerI { if (NetworkId == 0) { - CitizenFX.Core.Debug.WriteLine("ERROR sending vehicle data NetwordID equals 0\n"); + Utils.DebugWriteLine("ERROR sending vehicle data NetwordID equals 0\n"); return; } switch (command) diff --git a/src/Properties/AssemblyInfo.cs b/src/Properties/AssemblyInfo.cs index 6b235c4..46dd4ff 100644 --- a/src/Properties/AssemblyInfo.cs +++ b/src/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.2.1.0")] -[assembly: AssemblyFileVersion("0.2.1.0")] +[assembly: AssemblyVersion("0.2.2.0")] +[assembly: AssemblyFileVersion("0.2.2.0")]