code cleaned up

This commit is contained in:
xEntenKoeniqx
2022-09-05 13:02:09 +02:00
parent 84b040766f
commit 6c82895fa7
19 changed files with 71 additions and 160 deletions

View File

@ -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" )]

View File

@ -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)

View File

@ -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
}
}

View File

@ -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
}
}

View File

@ -371,17 +371,11 @@ namespace RageCoop.Client
var type = Function.Call<int>(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<uint> ExplosiveBullets = new HashSet<uint>
@ -460,7 +454,6 @@ namespace RageCoop.Client
};
public static readonly HashSet<WeaponHash> ProjectileWeapons = new HashSet<WeaponHash> {
WeaponHash.HomingLauncher,
WeaponHash.RPG,

View File

@ -126,7 +126,6 @@ namespace RageCoop.Client
ped.Kill();
ped.Delete();
}
}
foreach (Vehicle veh in World.GetAllVehicles())

View File

@ -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<T>(this IEnumerable<T> objects)
{
return "{"+string.Join(",",objects)+"}";
return $"{{{string.Join(",", objects)}}}";
}
public static void ForEach<T>(this IEnumerable<T> objects,Action<T> action)
{

View File

@ -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());
}

View File

@ -57,6 +57,5 @@ namespace RageCoop.Core
p.Pack(outgoingMessage);
SendMessage(outgoingMessage, cons, method, (int)channel);
}
}
}

View File

@ -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();

View File

@ -128,8 +128,6 @@ namespace RageCoop.Core
byteArray.Add(0x00);
}
// Write LockStatus
byteArray.Add((byte)LockStatus);

View File

@ -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;
}
}
}

View File

@ -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())

View File

@ -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)
{

View File

@ -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);
}

View File

@ -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<float> updateCallback=null)
{

View File

@ -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);

View File

@ -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" )]

View File

@ -33,68 +33,28 @@ namespace RageCoop.Server.Scripting
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
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;
/// <summary>
/// Get a <see cref="ServerVehicle"/> by it's id
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
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;
/// <summary>
/// Get a <see cref="ServerProp"/> owned by server from it's ID.
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
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;
/// <summary>
/// Get a <see cref="ServerBlip"/> by it's id.
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
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;
/// <summary>
/// Create a static prop owned by server.
@ -164,45 +124,32 @@ namespace RageCoop.Server.Scripting
/// Get all peds on this server
/// </summary>
/// <returns></returns>
public ServerPed[] GetAllPeds()
{
return Peds.Values.ToArray();
}
public ServerPed[] GetAllPeds() => Peds.Values.ToArray();
/// <summary>
/// Get all vehicles on this server
/// </summary>
/// <returns></returns>
public ServerVehicle[] GetAllVehicles()
{
return Vehicles.Values.ToArray();
}
public ServerVehicle[] GetAllVehicles() => Vehicles.Values.ToArray();
/// <summary>
/// Get all static prop objects owned by server
/// </summary>
/// <returns></returns>
public ServerProp[] GetAllProps()
{
return ServerProps.Values.ToArray();
}
public ServerProp[] GetAllProps() => ServerProps.Values.ToArray();
/// <summary>
/// Get all blips owned by server
/// </summary>
/// <returns></returns>
public ServerBlip[] GetAllBlips()
{
return Blips.Values.ToArray();
}
public ServerBlip[] GetAllBlips() => Blips.Values.ToArray();
/// <summary>
/// Not thread safe
/// </summary>
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()
{