Fix stuff, add listening address display and projectile shoot prediction

This commit is contained in:
Sardelka
2022-09-07 09:52:40 +08:00
parent 4621fb4987
commit 23e9326f5f
10 changed files with 59 additions and 26 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -31,6 +31,7 @@ namespace RageCoop.Client
}
internal void SetUpFixedData()
{
if (MainVehicle == null) { return; }
IsAircraft = MainVehicle.IsAircraft;
IsMotorcycle = MainVehicle.IsMotorcycle;

View File

@ -43,10 +43,10 @@ namespace RageCoop.Client
#endregion
public static void Cleanup(bool keepPlayer = true, bool keepMine = true)
{
foreach (int id in new List<int>(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;
}

View File

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

View File

@ -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";
}
/// <summary>
/// Get local ip addresses on all network interfaces
/// </summary>
/// <returns></returns>
public static List<IPAddress> GetLocalAddress()
{
var addresses = new List<IPAddress>();
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);
}
}
}

View File

@ -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
{
@ -118,12 +119,22 @@ namespace RageCoop.Server
public void Start()
{
Logger?.Info("================");
Logger?.Info($"Server bound to: 0.0.0.0:{Settings.Port}");
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");
}
/// <summary>
/// Terminate threads and stop the server

View File

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