From 23e9326f5ff9d857eb12d24c9442e702c38ef30f Mon Sep 17 00:00:00 2001 From: Sardelka Date: Wed, 7 Sep 2022 09:52:40 +0800 Subject: [PATCH] Fix stuff, add listening address display and projectile shoot prediction --- RageCoop.Client/Main.cs | 10 ++++---- RageCoop.Client/Networking/Receive.cs | 1 + RageCoop.Client/Properties/AssemblyInfo.cs | 8 ++++--- .../Sync/Entities/SyncedProjectile.cs | 3 ++- .../Sync/Entities/Vehicle/SyncedVehicle.cs | 1 + RageCoop.Client/Sync/EntityPool.cs | 8 +++---- RageCoop.Client/WorldThread.cs | 4 ++-- RageCoop.Core/CoreUtils.cs | 22 +++++++++++++++-- RageCoop.Server/Networking/Server.cs | 24 +++++++++++++------ RageCoop.Server/Properties/AssemblyInfo.cs | 4 ++-- 10 files changed, 59 insertions(+), 26 deletions(-) diff --git a/RageCoop.Client/Main.cs b/RageCoop.Client/Main.cs index 0e36a9c..a3fa2bd 100644 --- a/RageCoop.Client/Main.cs +++ b/RageCoop.Client/Main.cs @@ -325,11 +325,6 @@ namespace RageCoop.Client public static void Disconnected(string reason) { - Memory.RestorePatches(); - DownloadManager.Cleanup(); - Voice.ClearAll(); - PlayerList.Cleanup(); - LocalPlayerID = default; Logger.Info($">> Disconnected << reason: {reason}"); QueueAction(() => @@ -338,13 +333,18 @@ namespace RageCoop.Client { MainChat.Focused = false; } + PlayerList.Cleanup(); MainChat.Clear(); EntityPool.Cleanup(); WorldThread.Traffic(true); Function.Call(Hash.SET_ENABLE_VEHICLE_SLIPSTREAMING, false); CoopMenu.DisconnectedMenuSetting(); GTA.UI.Notification.Show("~r~Disconnected: " + reason); + LocalPlayerID = default; }); + Memory.RestorePatches(); + DownloadManager.Cleanup(); + Voice.ClearAll(); Resources.Unload(); } private static void DoQueuedActions() diff --git a/RageCoop.Client/Networking/Receive.cs b/RageCoop.Client/Networking/Receive.cs index 3d37ddb..0e44705 100644 --- a/RageCoop.Client/Networking/Receive.cs +++ b/RageCoop.Client/Networking/Receive.cs @@ -396,6 +396,7 @@ namespace RageCoop.Client p.Shooter = packet.Flags.HasProjDataFlag(ProjectileDataFlags.IsShotByVehicle) ? (SyncedEntity)EntityPool.GetVehicleByID(packet.ShooterID) : EntityPool.GetPedByID(packet.ShooterID); p.LastSynced = Main.Ticked; + p.LastSyncedStopWatch.Restart(); } } } diff --git a/RageCoop.Client/Properties/AssemblyInfo.cs b/RageCoop.Client/Properties/AssemblyInfo.cs index 3bb1ca1..bd2f357 100644 --- a/RageCoop.Client/Properties/AssemblyInfo.cs +++ b/RageCoop.Client/Properties/AssemblyInfo.cs @@ -1,5 +1,7 @@  using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using System.Resources; // General Information @@ -14,7 +16,7 @@ using System.Resources; // Version informationr( -[assembly: AssemblyVersion("1.5.3.155")] -[assembly: AssemblyFileVersion("1.5.3.155")] -[assembly: NeutralResourcesLanguageAttribute("en-US")] +[assembly: AssemblyVersion("1.5.3.174")] +[assembly: AssemblyFileVersion("1.5.3.174")] +[assembly: NeutralResourcesLanguageAttribute( "en-US" )] diff --git a/RageCoop.Client/Sync/Entities/SyncedProjectile.cs b/RageCoop.Client/Sync/Entities/SyncedProjectile.cs index 1076409..461977b 100644 --- a/RageCoop.Client/Sync/Entities/SyncedProjectile.cs +++ b/RageCoop.Client/Sync/Entities/SyncedProjectile.cs @@ -101,7 +101,7 @@ namespace RageCoop.Client CreateProjectile(); return; } - MainProjectile.Velocity = Velocity + (Position + Shooter.Owner.PacketTravelTime * Velocity - MainProjectile.Position); + MainProjectile.Velocity = Velocity + (Predict(Position) - MainProjectile.Position); MainProjectile.Rotation = Rotation; LastUpdated = Main.Ticked; } @@ -113,6 +113,7 @@ namespace RageCoop.Client if (Shooter == null) { return; } Entity owner; owner = (Shooter as SyncedPed)?.MainPed ?? (Entity)(Shooter as SyncedVehicle)?.MainVehicle; + Position = (Owner.PacketTravelTime + 0.001f * LastSyncedStopWatch.ElapsedMilliseconds) * Shooter.Velocity + Position; var end = Position + Velocity; Function.Call(Hash.SHOOT_SINGLE_BULLET_BETWEEN_COORDS_IGNORE_ENTITY, Position.X, Position.Y, Position.Z, end.X, end.Y, end.Z, 0, 1, WeaponHash, owner?.Handle ?? 0, 1, 0, -1, owner); var ps = World.GetAllProjectiles(); diff --git a/RageCoop.Client/Sync/Entities/Vehicle/SyncedVehicle.cs b/RageCoop.Client/Sync/Entities/Vehicle/SyncedVehicle.cs index 91a692a..9c20dcb 100644 --- a/RageCoop.Client/Sync/Entities/Vehicle/SyncedVehicle.cs +++ b/RageCoop.Client/Sync/Entities/Vehicle/SyncedVehicle.cs @@ -31,6 +31,7 @@ namespace RageCoop.Client } internal void SetUpFixedData() { + if (MainVehicle == null) { return; } IsAircraft = MainVehicle.IsAircraft; IsMotorcycle = MainVehicle.IsMotorcycle; diff --git a/RageCoop.Client/Sync/EntityPool.cs b/RageCoop.Client/Sync/EntityPool.cs index da36223..31a76a8 100644 --- a/RageCoop.Client/Sync/EntityPool.cs +++ b/RageCoop.Client/Sync/EntityPool.cs @@ -43,10 +43,10 @@ namespace RageCoop.Client #endregion public static void Cleanup(bool keepPlayer = true, bool keepMine = true) { - foreach (int id in new List(PedsByID.Keys)) + foreach (var ped in PedsByID.Values) { - if (keepPlayer && (id == Main.LocalPlayerID) || keepMine && (PedsByID[id].OwnerID == Main.LocalPlayerID)) { continue; } - RemovePed(id); + if ((keepPlayer && (ped.ID == Main.LocalPlayerID)) || (keepMine && (ped.OwnerID == Main.LocalPlayerID))) { continue; } + RemovePed(ped.ID); } PedsByID.Clear(); PedsByHandle.Clear(); @@ -333,7 +333,7 @@ namespace RageCoop.Client if (p.MainProjectile.AttachedEntity == null) { // Prevent projectiles from exploding next to vehicle - if (p.WeaponHash == (WeaponHash)VehicleWeaponHash.Tank || p.MainProjectile.Position.DistanceTo(p.Origin) < 2) + if (p.WeaponHash == (WeaponHash)VehicleWeaponHash.Tank || (p.MainProjectile.OwnerEntity?.EntityType==EntityType.Vehicle && p.MainProjectile.Position.DistanceTo(p.Origin) < 2)) { continue; } diff --git a/RageCoop.Client/WorldThread.cs b/RageCoop.Client/WorldThread.cs index 1be7963..4192477 100644 --- a/RageCoop.Client/WorldThread.cs +++ b/RageCoop.Client/WorldThread.cs @@ -115,12 +115,12 @@ namespace RageCoop.Client Function.Call(Hash.DISABLE_VEHICLE_DISTANTLIGHTS, true); foreach (Ped ped in World.GetAllPeds()) { + if (ped == Game.Player.Character) { continue; } SyncedPed c = EntityPool.GetPedByHandle(ped.Handle); if ((c == null) || (c.IsLocal && (ped.Handle != Game.Player.Character.Handle) && ped.PopulationType != EntityPopulationType.Mission)) { - if (ped.Handle == Game.Player.Character.Handle) { continue; } - // Main.Logger.Trace($"Removing ped {ped.Handle}. Reason:RemoveTraffic"); + Main.Logger.Trace($"Removing ped {ped.Handle}. Reason:RemoveTraffic"); ped.CurrentVehicle?.Delete(); ped.Kill(); ped.Delete(); diff --git a/RageCoop.Core/CoreUtils.cs b/RageCoop.Core/CoreUtils.cs index ac0cc58..87dfb17 100644 --- a/RageCoop.Core/CoreUtils.cs +++ b/RageCoop.Core/CoreUtils.cs @@ -13,6 +13,7 @@ using System.Runtime.CompilerServices; using Lidgren.Network; using Newtonsoft.Json; using System.Runtime.InteropServices; +using System.Net.NetworkInformation; [assembly: InternalsVisibleTo("RageCoop.Server")] [assembly: InternalsVisibleTo("RageCoop.Client")] @@ -193,8 +194,7 @@ namespace RageCoop.Core foreach (FileInfo file in source.GetFiles()) file.CopyTo(Path.Combine(target.FullName, file.Name), true); } - public - static string GetInvariantRID() + public static string GetInvariantRID() { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { @@ -211,6 +211,23 @@ namespace RageCoop.Core return "unknown"; } + /// + /// Get local ip addresses on all network interfaces + /// + /// + public static List GetLocalAddress() + { + var addresses = new List(); + foreach (NetworkInterface netInterface in NetworkInterface.GetAllNetworkInterfaces()) + { + IPInterfaceProperties ipProps = netInterface.GetIPProperties(); + foreach (UnicastIPAddressInformation addr in ipProps.UnicastAddresses) + { + addresses.Add(addr.Address); + } + } + return addresses; + } } internal class IpInfo { @@ -502,5 +519,6 @@ namespace RageCoop.Core { return IPAddress.Parse(ip); } + } } diff --git a/RageCoop.Server/Networking/Server.cs b/RageCoop.Server/Networking/Server.cs index dab5553..18cfacc 100644 --- a/RageCoop.Server/Networking/Server.cs +++ b/RageCoop.Server/Networking/Server.cs @@ -18,6 +18,7 @@ using Timer = System.Timers.Timer; using System.Net.Sockets; using System.Threading.Tasks; using RageCoop.Core.Scripting; +using System.Net.NetworkInformation; namespace RageCoop.Server { @@ -117,13 +118,23 @@ namespace RageCoop.Server /// public void Start() { - Logger?.Info("================"); - Logger?.Info($"Server bound to: 0.0.0.0:{Settings.Port}"); + Logger?.Info("================"); + Logger?.Info($"Listening port: {Settings.Port}"); Logger?.Info($"Server version: {Version}"); - Logger?.Info($"Compatible RAGECOOP versions: {Version.ToString(3)}"); + Logger?.Info($"Compatible client version: {Version.ToString(3)}"); Logger?.Info($"Runtime: {CoreUtils.GetInvariantRID()} => {System.Runtime.InteropServices.RuntimeInformation.RuntimeIdentifier}"); Logger?.Info("================"); - + Logger?.Info($"Listening addresses:"); + foreach (NetworkInterface netInterface in NetworkInterface.GetAllNetworkInterfaces()) + { + Logger?.Info($"[{netInterface.Description}]:"); + IPInterfaceProperties ipProps = netInterface.GetIPProperties(); + foreach (UnicastIPAddressInformation addr in ipProps.UnicastAddresses) + { + Logger.Info(string.Join(", ", addr.Address)); + } + Logger.Info(""); + } if (Settings.UseZeroTier) { Logger?.Info($"Joining ZeroTier network: "+Settings.ZeroTierNetworkID); @@ -152,12 +163,12 @@ namespace RageCoop.Server MainNetServer = new NetServer(config); MainNetServer.Start(); - Logger?.Info(string.Format("Server listening on {0}:{1}", config.LocalAddress.ToString(), config.Port)); - BaseScript.API=API; BaseScript.OnStart(); Resources.LoadAll(); _listenerThread.Start(); + Logger?.Info("Listening for clients"); + _playerUpdateTimer.Enabled=true; if (Settings.AnnounceSelf) { @@ -170,7 +181,6 @@ namespace RageCoop.Server _antiAssholesTimer.Enabled = true; - Logger?.Info("Listening for clients"); } /// /// Terminate threads and stop the server diff --git a/RageCoop.Server/Properties/AssemblyInfo.cs b/RageCoop.Server/Properties/AssemblyInfo.cs index cf07ed0..c03dc66 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.137")] -[assembly: AssemblyFileVersion("1.5.3.137")] +[assembly: AssemblyVersion("1.5.3.156")] +[assembly: AssemblyFileVersion("1.5.3.156")] [assembly: NeutralResourcesLanguageAttribute( "en-US" )]