From 6c82895fa750a58e341b86379f8c05924b9b89f0 Mon Sep 17 00:00:00 2001 From: xEntenKoeniqx <109136581+xEntenKoeniqx@users.noreply.github.com> Date: Mon, 5 Sep 2022 13:02:09 +0200 Subject: [PATCH] code cleaned up --- RageCoop.Client/Properties/AssemblyInfo.cs | 4 +- .../Sync/Entities/Ped/SyncedPed.cs | 20 ++-- .../Sync/Entities/Vehicle/SyncedVehicle.cs | 15 +-- RageCoop.Client/Util/VehicleExtensions.cs | 19 ++-- RageCoop.Client/Util/WeaponUtil.cs | 15 +-- RageCoop.Client/WorldThread.cs | 1 - RageCoop.Core/CoreUtils.cs | 6 +- RageCoop.Core/MathExtensions.cs | 12 +-- RageCoop.Core/Networking/CoopPeer.cs | 1 - RageCoop.Core/Networking/HttpHelper.cs | 4 +- RageCoop.Core/Packets/VehicleSync.cs | 2 - RageCoop.Core/Scripting/CustomEvents.cs | 12 +-- .../Networking/Server.Background.cs | 7 +- .../Networking/Server.Connections.cs | 5 +- .../Networking/Server.EntitySync.cs | 2 - RageCoop.Server/Networking/Server.cs | 6 +- RageCoop.Server/Program.cs | 5 +- RageCoop.Server/Properties/AssemblyInfo.cs | 4 +- RageCoop.Server/Scripting/ServerEntities.cs | 91 +++---------------- 19 files changed, 71 insertions(+), 160 deletions(-) diff --git a/RageCoop.Client/Properties/AssemblyInfo.cs b/RageCoop.Client/Properties/AssemblyInfo.cs index f98ba17..8600f12 100644 --- a/RageCoop.Client/Properties/AssemblyInfo.cs +++ b/RageCoop.Client/Properties/AssemblyInfo.cs @@ -16,7 +16,7 @@ using System.Resources; // Version informationr( -[assembly: AssemblyVersion("1.5.3.147")] -[assembly: AssemblyFileVersion("1.5.3.147")] +[assembly: AssemblyVersion("1.5.3.149")] +[assembly: AssemblyFileVersion("1.5.3.149")] [assembly: NeutralResourcesLanguageAttribute( "en-US" )] diff --git a/RageCoop.Client/Sync/Entities/Ped/SyncedPed.cs b/RageCoop.Client/Sync/Entities/Ped/SyncedPed.cs index d378d7a..40b724d 100644 --- a/RageCoop.Client/Sync/Entities/Ped/SyncedPed.cs +++ b/RageCoop.Client/Sync/Entities/Ped/SyncedPed.cs @@ -433,22 +433,18 @@ namespace RageCoop.Client } return; } - else + if (MainPed.IsRagdoll) { - if (MainPed.IsRagdoll) + if (Speed == 0) { - if (Speed==0) - { - MainPed.CancelRagdoll(); - } - else - { - MainPed.Task.ClearAllImmediately(); - } - return; + MainPed.CancelRagdoll(); + } + else + { + MainPed.Task.ClearAllImmediately(); } - _lastRagdoll = false; + return; } if (IsReloading) diff --git a/RageCoop.Client/Sync/Entities/Vehicle/SyncedVehicle.cs b/RageCoop.Client/Sync/Entities/Vehicle/SyncedVehicle.cs index 3b6f222..73dfe54 100644 --- a/RageCoop.Client/Sync/Entities/Vehicle/SyncedVehicle.cs +++ b/RageCoop.Client/Sync/Entities/Vehicle/SyncedVehicle.cs @@ -149,8 +149,6 @@ namespace RageCoop.Client MainVehicle.AreHighBeamsOn = HighBeamsOn; } - - if (IsAircraft) { if (LandingGear != (byte)MainVehicle.LandingGearState) @@ -274,7 +272,7 @@ namespace RageCoop.Client MainVehicle.Quaternion = Quaternion; return; } - else if (dist > 0.03) + if (dist > 0.03) { MainVehicle.Velocity = Velocity + cali; } @@ -286,10 +284,7 @@ namespace RageCoop.Client MainVehicle.RotationVelocity = RotationVelocity; return; } - else - { - MainVehicle.RotationVelocity = RotationVelocity + calirot * 0.2f; - } + MainVehicle.RotationVelocity = RotationVelocity + calirot * 0.2f; } private Vector3 GetCalibrationRotation() { @@ -316,7 +311,7 @@ namespace RageCoop.Client // GTA.UI.Notification.Show($"~r~(Vehicle)Model ({CurrentVehicleModelHash}) cannot be loaded!"); return false; } - else if (MainVehicle==null) + if (MainVehicle==null) { Model.Request(); return false; @@ -339,7 +334,7 @@ namespace RageCoop.Client Model.MarkAsNoLongerNeeded(); return true; } -#region -- PEDALING -- + #region -- PEDALING -- /* * Thanks to @oldnapalm. */ @@ -375,7 +370,5 @@ namespace RageCoop.Client MainVehicle.Driver.Task.ClearAnimation(PedalingAnimDict(), PedalingAnimName(fast)); } #endregion - - } } diff --git a/RageCoop.Client/Util/VehicleExtensions.cs b/RageCoop.Client/Util/VehicleExtensions.cs index cf2aa57..1644819 100644 --- a/RageCoop.Client/Util/VehicleExtensions.cs +++ b/RageCoop.Client/Util/VehicleExtensions.cs @@ -54,31 +54,36 @@ namespace RageCoop.Client { flags |= VehicleDataFlags.IsTransformed; } + if (v.IsAircraft) { flags |= VehicleDataFlags.IsAircraft; } + if (v.IsDeluxo && veh.IsDeluxoHovering()) { - flags|= VehicleDataFlags.IsDeluxoHovering; + flags |= VehicleDataFlags.IsDeluxoHovering; } + if (v.HasRoof) { - flags|=VehicleDataFlags.HasRoof; + flags |= VehicleDataFlags.HasRoof; } + if (v.HasRocketBoost && veh.IsRocketBoostActive()) { - flags|=VehicleDataFlags.IsRocketBoostActive; + flags |= VehicleDataFlags.IsRocketBoostActive; } + if(v.HasParachute && veh.IsParachuteActive()){ - flags|=VehicleDataFlags.IsParachuteActive; + flags |= VehicleDataFlags.IsParachuteActive; } + if (veh.IsOnFire) { flags|=VehicleDataFlags.IsOnFire; } - return flags; } public static bool IsRocketBoostActive(this Vehicle veh) @@ -133,7 +138,6 @@ namespace RageCoop.Client } } - // Bursted tires short burstedTires = 0; foreach (VehicleWheel wheel in veh.Wheels.GetAllWheels()) @@ -234,7 +238,6 @@ namespace RageCoop.Client return ps; } - public static void SetDeluxoHoverState(this Vehicle deluxo, bool hover) { Function.Call(Hash._SET_VEHICLE_HOVER_TRANSFORM_PERCENTAGE, deluxo, hover ? 1f : 0f); @@ -283,8 +286,6 @@ namespace RageCoop.Client { Function.Call(Hash.SET_VEHICLE_FLIGHT_NOZZLE_POSITION, plane, ratio); } - - #endregion } } diff --git a/RageCoop.Client/Util/WeaponUtil.cs b/RageCoop.Client/Util/WeaponUtil.cs index af9e1cc..cb427ed 100644 --- a/RageCoop.Client/Util/WeaponUtil.cs +++ b/RageCoop.Client/Util/WeaponUtil.cs @@ -371,17 +371,11 @@ namespace RageCoop.Client var type = Function.Call(Hash.GET_WEAPON_DAMAGE_TYPE, vp); if (vp!=VehicleWeaponHash.Invalid) { - if (type==3) - { - return false; - } - return VehicleProjectileWeapons.Contains(vp) || (type==5 && !ExplosiveBullets.Contains((uint)vp)); - } - else - { - var w = p.Weapons.Current; - return w.Group==WeaponGroup.Thrown || ProjectileWeapons.Contains(w.Hash); + return type == 3 ? false : VehicleProjectileWeapons.Contains(vp) || (type==5 && !ExplosiveBullets.Contains((uint)vp)); } + + var w = p.Weapons.Current; + return w.Group == WeaponGroup.Thrown || ProjectileWeapons.Contains(w.Hash); } public static readonly HashSet ExplosiveBullets = new HashSet @@ -460,7 +454,6 @@ namespace RageCoop.Client }; - public static readonly HashSet ProjectileWeapons = new HashSet { WeaponHash.HomingLauncher, WeaponHash.RPG, diff --git a/RageCoop.Client/WorldThread.cs b/RageCoop.Client/WorldThread.cs index b5124d3..706cbe3 100644 --- a/RageCoop.Client/WorldThread.cs +++ b/RageCoop.Client/WorldThread.cs @@ -126,7 +126,6 @@ namespace RageCoop.Client ped.Kill(); ped.Delete(); } - } foreach (Vehicle veh in World.GetAllVehicles()) diff --git a/RageCoop.Core/CoreUtils.cs b/RageCoop.Core/CoreUtils.cs index 65261d1..ac0cc58 100644 --- a/RageCoop.Core/CoreUtils.cs +++ b/RageCoop.Core/CoreUtils.cs @@ -200,11 +200,11 @@ namespace RageCoop.Core { return "win-" + RuntimeInformation.OSArchitecture.ToString().ToLower(); } - else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { return "linux-" + RuntimeInformation.OSArchitecture.ToString().ToLower(); } - else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { return "osx-" + RuntimeInformation.OSArchitecture.ToString().ToLower(); } @@ -419,7 +419,7 @@ namespace RageCoop.Core } public static string Dump(this IEnumerable objects) { - return "{"+string.Join(",",objects)+"}"; + return $"{{{string.Join(",", objects)}}}"; } public static void ForEach(this IEnumerable objects,Action action) { diff --git a/RageCoop.Core/MathExtensions.cs b/RageCoop.Core/MathExtensions.cs index c10d150..ef81abe 100644 --- a/RageCoop.Core/MathExtensions.cs +++ b/RageCoop.Core/MathExtensions.cs @@ -3,7 +3,6 @@ using GTA.Math; namespace RageCoop.Core { - internal static class MathExtensions { public const float Deg2Rad=(float)(Math.PI* 2) / 360; @@ -146,16 +145,12 @@ namespace RageCoop.Core } private static float CopySign(double x, double y) { - bool isPositive = y>=0; - if (isPositive) + if (y >= 0) { - if (x>=0) { return (float)x; } else { return (float)-x; } + return x >= 0 ? (float)x : (float)-x; } - else - { - if (x>=0) { return (float)-x; } else { return (float)x; } - } + return x >= 0 ? (float)-x : (float)x; } public static double AngelTo(this Vector3 v1, Vector3 v2) { @@ -163,7 +158,6 @@ namespace RageCoop.Core } public static float GetCosTheta(this Vector3 v1, Vector3 v2) { - return Vector3.Dot(v1, v2)/(v1.Length()*v2.Length()); } diff --git a/RageCoop.Core/Networking/CoopPeer.cs b/RageCoop.Core/Networking/CoopPeer.cs index e581728..4966304 100644 --- a/RageCoop.Core/Networking/CoopPeer.cs +++ b/RageCoop.Core/Networking/CoopPeer.cs @@ -57,6 +57,5 @@ namespace RageCoop.Core p.Pack(outgoingMessage); SendMessage(outgoingMessage, cons, method, (int)channel); } - } } diff --git a/RageCoop.Core/Networking/HttpHelper.cs b/RageCoop.Core/Networking/HttpHelper.cs index f9ddeb5..993439d 100644 --- a/RageCoop.Core/Networking/HttpHelper.cs +++ b/RageCoop.Core/Networking/HttpHelper.cs @@ -32,7 +32,9 @@ namespace RageCoop.Core { // TLS only ServicePointManager.Expect100Continue = true; - ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; + ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | + SecurityProtocolType.Tls11 | + SecurityProtocolType.Tls; ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; WebClient client = new WebClient(); diff --git a/RageCoop.Core/Packets/VehicleSync.cs b/RageCoop.Core/Packets/VehicleSync.cs index bb8c00e..198cabd 100644 --- a/RageCoop.Core/Packets/VehicleSync.cs +++ b/RageCoop.Core/Packets/VehicleSync.cs @@ -128,8 +128,6 @@ namespace RageCoop.Core byteArray.Add(0x00); } - - // Write LockStatus byteArray.Add((byte)LockStatus); diff --git a/RageCoop.Core/Scripting/CustomEvents.cs b/RageCoop.Core/Scripting/CustomEvents.cs index c252721..78b9bf7 100644 --- a/RageCoop.Core/Scripting/CustomEvents.cs +++ b/RageCoop.Core/Scripting/CustomEvents.cs @@ -49,16 +49,12 @@ namespace RageCoop.Core.Scripting { throw new ArgumentException($"Hashed value has collision with another name:{name}, hashed value:{hash}"); } - else - { - return hash; - } - } - else - { - Hashed.Add(hash, s); + return hash; } + + Hashed.Add(hash, s); + return hash; } } } diff --git a/RageCoop.Server/Networking/Server.Background.cs b/RageCoop.Server/Networking/Server.Background.cs index c645013..f601dd9 100644 --- a/RageCoop.Server/Networking/Server.Background.cs +++ b/RageCoop.Server/Networking/Server.Background.cs @@ -54,7 +54,10 @@ namespace RageCoop.Server { // TLS only ServicePointManager.Expect100Continue = true; - ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls13 | SecurityProtocolType.Tls12; + ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls13 | + SecurityProtocolType.Tls12 | + SecurityProtocolType.Tls11 | + SecurityProtocolType.Tls; ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; try @@ -77,6 +80,7 @@ namespace RageCoop.Server Logger?.Error($"MasterServer: {ex.Message}"); } } + try { Security.GetPublicKey(out var pModulus, out var pExpoenet); @@ -161,6 +165,7 @@ namespace RageCoop.Server Logger?.Error("Update",ex); } } + private void KickAssholes() { foreach(var c in ClientsByNetHandle.Values.ToArray()) diff --git a/RageCoop.Server/Networking/Server.Connections.cs b/RageCoop.Server/Networking/Server.Connections.cs index 4cc82b4..47cee88 100644 --- a/RageCoop.Server/Networking/Server.Connections.cs +++ b/RageCoop.Server/Networking/Server.Connections.cs @@ -43,6 +43,7 @@ namespace RageCoop.Server connection.Deny("Username is already taken!"); return; } + try { Security.AddConnection(connection.RemoteEndPoint, packet.AesKeyCrypted, packet.AesIVCrypted); @@ -68,6 +69,7 @@ namespace RageCoop.Server connection.Deny("Malformed handshak packet!"); return; } + var handshakeSuccess = MainNetServer.CreateMessage(); var currentClients = ClientsByID.Values.ToArray(); var players = new Packets.PlayerData[currentClients.Length]; @@ -79,6 +81,7 @@ namespace RageCoop.Server Username=currentClients[i].Username, }; } + new Packets.HandshakeSuccess() { Players=players @@ -146,8 +149,6 @@ namespace RageCoop.Server // Send all blips to this player BaseScript.SendServerBlipsTo(new(Entities.Blips.Values), new() { newClient }); - - // Create P2P connection if (Settings.UseP2P) { diff --git a/RageCoop.Server/Networking/Server.EntitySync.cs b/RageCoop.Server/Networking/Server.EntitySync.cs index 11641a4..69501aa 100644 --- a/RageCoop.Server/Networking/Server.EntitySync.cs +++ b/RageCoop.Server/Networking/Server.EntitySync.cs @@ -64,7 +64,6 @@ namespace RageCoop.Server { continue; } - } else if ((Settings.NpcStreamingDistance!=-1)&&(packet.Position.DistanceTo(c.Player.Position)>Settings.NpcStreamingDistance)) { @@ -77,7 +76,6 @@ namespace RageCoop.Server } private void ProjectileSync(Packets.ProjectileSync packet, Client client) { - if (Settings.UseP2P) { return; } Forward(packet, client, ConnectionChannel.ProjectileSync); } diff --git a/RageCoop.Server/Networking/Server.cs b/RageCoop.Server/Networking/Server.cs index 2e6fe43..192364f 100644 --- a/RageCoop.Server/Networking/Server.cs +++ b/RageCoop.Server/Networking/Server.cs @@ -293,10 +293,8 @@ namespace RageCoop.Server p.Deserialize(response); return p; } - else - { - return null; - } + + return null; } internal void SendFile(string path,string name,Client client,Action updateCallback=null) { diff --git a/RageCoop.Server/Program.cs b/RageCoop.Server/Program.cs index d6c0166..fb61c57 100644 --- a/RageCoop.Server/Program.cs +++ b/RageCoop.Server/Program.cs @@ -18,10 +18,9 @@ namespace RageCoop.Server if (args.Length>=2 && args[0]=="update") { var target = args[1]; - int i =0; - while (i < 10) + int i = 0; + while (i++ < 10) { - i++; try { Console.WriteLine("Applying update to "+target); diff --git a/RageCoop.Server/Properties/AssemblyInfo.cs b/RageCoop.Server/Properties/AssemblyInfo.cs index 024670b..a7151c9 100644 --- a/RageCoop.Server/Properties/AssemblyInfo.cs +++ b/RageCoop.Server/Properties/AssemblyInfo.cs @@ -15,7 +15,7 @@ using System.Resources; [assembly: AssemblyCulture("")] // Version information -[assembly: AssemblyVersion("1.5.3.128")] -[assembly: AssemblyFileVersion("1.5.3.128")] +[assembly: AssemblyVersion("1.5.3.130")] +[assembly: AssemblyFileVersion("1.5.3.130")] [assembly: NeutralResourcesLanguageAttribute( "en-US" )] diff --git a/RageCoop.Server/Scripting/ServerEntities.cs b/RageCoop.Server/Scripting/ServerEntities.cs index 6f81b3f..53c1851 100644 --- a/RageCoop.Server/Scripting/ServerEntities.cs +++ b/RageCoop.Server/Scripting/ServerEntities.cs @@ -33,68 +33,28 @@ namespace RageCoop.Server.Scripting /// /// /// - public ServerPed GetPedByID(int id) - { - if(Peds.TryGetValue(id,out var ped)) - { - return ped; - } - else - { - return null; - } - } + public ServerPed GetPedByID(int id) => Peds.TryGetValue(id, out var ped) ? ped : null; /// /// Get a by it's id /// /// /// - public ServerVehicle GetVehicleByID(int id) - { - if (Vehicles.TryGetValue(id, out var veh)) - { - return veh; - } - else - { - return null; - } - } + public ServerVehicle GetVehicleByID(int id) => Vehicles.TryGetValue(id, out var veh) ? veh : null; /// /// Get a owned by server from it's ID. /// /// /// - public ServerProp GetPropByID(int id) - { - if (ServerProps.TryGetValue(id, out var obj)) - { - return obj; - } - else - { - return null; - } - } + public ServerProp GetPropByID(int id) => ServerProps.TryGetValue(id, out var obj) ? obj : null; /// /// Get a by it's id. /// /// /// - public ServerBlip GetBlipByID(int id) - { - if (Blips.TryGetValue(id, out var obj)) - { - return obj; - } - else - { - return null; - } - } + public ServerBlip GetBlipByID(int id) => Blips.TryGetValue(id, out var obj) ? obj : null; /// /// Create a static prop owned by server. @@ -164,45 +124,32 @@ namespace RageCoop.Server.Scripting /// Get all peds on this server /// /// - public ServerPed[] GetAllPeds() - { - return Peds.Values.ToArray(); - } + public ServerPed[] GetAllPeds() => Peds.Values.ToArray(); /// /// Get all vehicles on this server /// /// - public ServerVehicle[] GetAllVehicles() - { - return Vehicles.Values.ToArray(); - } + public ServerVehicle[] GetAllVehicles() => Vehicles.Values.ToArray(); /// /// Get all static prop objects owned by server /// /// - public ServerProp[] GetAllProps() - { - return ServerProps.Values.ToArray(); - } + public ServerProp[] GetAllProps() => ServerProps.Values.ToArray(); /// /// Get all blips owned by server /// /// - public ServerBlip[] GetAllBlips() - { - return Blips.Values.ToArray(); - } + public ServerBlip[] GetAllBlips() => Blips.Values.ToArray(); /// /// Not thread safe /// internal void Update(Packets.PedSync p,Client sender) { - ServerPed ped; - if(!Peds.TryGetValue(p.ID,out ped)) + if(!Peds.TryGetValue(p.ID,out ServerPed ped)) { Peds.TryAdd(p.ID,ped=new ServerPed(Server)); ped.ID=p.ID; @@ -229,8 +176,7 @@ namespace RageCoop.Server.Scripting } internal void Update(Packets.VehicleSync p, Client sender) { - ServerVehicle veh; - if (!Vehicles.TryGetValue(p.ID, out veh)) + if (!Vehicles.TryGetValue(p.ID, out ServerVehicle veh)) { Vehicles.TryAdd(p.ID, veh=new ServerVehicle(Server)); veh.ID=p.ID; @@ -277,14 +223,8 @@ namespace RageCoop.Server.Scripting } } - internal void RemoveProp(int id) - { - ServerProps.TryRemove(id, out _); - } - internal void RemoveServerBlip(int id) - { - Blips.TryRemove(id, out _); - } + internal void RemoveProp(int id) => ServerProps.TryRemove(id, out _); + internal void RemoveServerBlip(int id) => Blips.TryRemove(id, out _); internal void RemovePed(int id) { Peds.TryRemove(id, out var ped); @@ -299,11 +239,10 @@ namespace RageCoop.Server.Scripting if (Peds.ContainsKey(ped.ID)) { Peds[ped.ID]=ped; + return; } - else - { - Peds.TryAdd(ped.ID, ped); - } + + Peds.TryAdd(ped.ID, ped); } internal int RequestNetworkID() {