diff --git a/RageCoop.Client/Networking/HolePunch.cs b/RageCoop.Client/Networking/HolePunch.cs index 58e6cf3..16a26ed 100644 --- a/RageCoop.Client/Networking/HolePunch.cs +++ b/RageCoop.Client/Networking/HolePunch.cs @@ -29,7 +29,7 @@ namespace RageCoop.Client { if (p.InternalEndPoint!=null && p.ExternalEndPoint!=null && (p.Connection==null || p.Connection.Status==NetConnectionStatus.Disconnected)) { - Main.Logger.Trace($"Sending HolePunch message to {p.InternalEndPoint},{p.ExternalEndPoint}. {p.Username}:{p.PedID}"); + Main.Logger.Trace($"Sending HolePunch message to {p.InternalEndPoint},{p.ExternalEndPoint}. {p.Username}:{p.ID}"); var msg = Networking.Peer.CreateMessage(); new Packets.HolePunch { @@ -69,7 +69,7 @@ namespace RageCoop.Client puncher.HolePunchStatus=(byte)(p.Status+1); if (p.Status>=3) { - Main.Logger.Debug("HolePunch sucess: "+from+", "+puncher.PedID); + Main.Logger.Debug("HolePunch sucess: "+from+", "+puncher.ID); if (puncher.ConnectWhenPunched && (puncher.Connection==null || puncher.Connection.Status==NetConnectionStatus.Disconnected)) { Main.Logger.Debug("Connecting to peer: "+from); diff --git a/RageCoop.Client/Networking/Networking.cs b/RageCoop.Client/Networking/Networking.cs index 1b02c23..9c250ba 100644 --- a/RageCoop.Client/Networking/Networking.cs +++ b/RageCoop.Client/Networking/Networking.cs @@ -141,7 +141,7 @@ namespace RageCoop.Client { var p = new Player { - PedID = packet.PedID, + ID = packet.PedID, Username= packet.Username, }; PlayerList.SetPlayer(packet.PedID, packet.Username); diff --git a/RageCoop.Client/PlayerList.cs b/RageCoop.Client/PlayerList.cs index 0f20598..9ffcacc 100644 --- a/RageCoop.Client/PlayerList.cs +++ b/RageCoop.Client/PlayerList.cs @@ -67,12 +67,12 @@ namespace RageCoop.Client if (Players.TryGetValue(id, out p)) { p.Username=username; - p.PedID=id; + p.ID=id; p._latencyToServer=latency; } else { - p = new Player { PedID=id, Username=username, _latencyToServer=latency }; + p = new Player { ID=id, Username=username, _latencyToServer=latency }; Players.Add(id, p); } } @@ -90,7 +90,7 @@ namespace RageCoop.Client { p.FakeBlip=World.CreateBlip(p.Position); } - if (EntityPool.PedExists(p.PedID)) + if (EntityPool.PedExists(p.ID)) { p.FakeBlip.DisplayType = BlipDisplayType.NoDisplay; } @@ -139,32 +139,32 @@ namespace RageCoop.Client } } - internal class Player + public class Player { - public byte HolePunchStatus { get; set; } = 1; - public bool IsHost; + public byte HolePunchStatus { get; internal set; } = 1; + public bool IsHost { get; internal set; } public string Username { get; internal set; } /// - /// Universal character ID. + /// Universal ped ID. /// - public int PedID + public int ID { get; internal set; } - public IPEndPoint InternalEndPoint { get; set; } - public IPEndPoint ExternalEndPoint { get; set; } - public bool ConnectWhenPunched { get; set; } - public Blip FakeBlip { get; set; } - public Vector3 Position { get; set; } - public SyncedPed Character { get; set; } + public IPEndPoint InternalEndPoint { get; internal set; } + public IPEndPoint ExternalEndPoint { get; internal set; } + internal bool ConnectWhenPunched { get; set; } + public Blip FakeBlip { get; internal set; } + public Vector3 Position { get; internal set; } + public SyncedPed Character { get; internal set; } /// - /// Player round-trip time in seconds, will be the latency to server if not using P2P connection. + /// Player round-trip time in seconds, will be the rtt to server if not using P2P connection. /// - public float Ping => Main.LocalPlayerID==PedID ? Networking.Latency*2 : (HasDirectConnection ? Connection.AverageRoundtripTime : _latencyToServer*2); + public float Ping => Main.LocalPlayerID==ID ? Networking.Latency*2 : (HasDirectConnection ? Connection.AverageRoundtripTime : _latencyToServer*2); public float PacketTravelTime => HasDirectConnection ? Connection.AverageRoundtripTime/2 : Networking.Latency+_latencyToServer; - public float _latencyToServer = 0; + internal float _latencyToServer = 0; public bool DisplayNameTag { get; set; } = true; - public NetConnection Connection { get; set; } - public bool HasDirectConnection => Connection?.Status==NetConnectionStatus.Connected; + public NetConnection Connection { get; internal set; } + public bool HasDirectConnection => Connection?.Status == NetConnectionStatus.Connected; } } diff --git a/RageCoop.Client/Scripting/API.cs b/RageCoop.Client/Scripting/API.cs index d52cfc5..82777f8 100644 --- a/RageCoop.Client/Scripting/API.cs +++ b/RageCoop.Client/Scripting/API.cs @@ -4,6 +4,7 @@ using RageCoop.Core; using System; using System.Collections.Generic; using System.Windows.Forms; +using Newtonsoft.Json; namespace RageCoop.Client.Scripting { @@ -212,13 +213,12 @@ namespace RageCoop.Client.Scripting /// Get a that RAGECOOP is currently using. /// /// - public static Logger Logger - { - get - { - return Main.Logger; - } - } + public static Logger Logger => Main.Logger; + /// + /// Get all players indexed by their ID + /// + public static Dictionary Players => new Dictionary(PlayerList.Players); + #endregion #region FUNCTIONS @@ -245,6 +245,15 @@ namespace RageCoop.Client.Scripting Networking.ToggleConnection(null); } } + + /// + /// List all servers from master server address + /// + /// + public static List ListServers() + { + return JsonConvert.DeserializeObject>(HttpHelper.DownloadString(Main.Settings.MasterServer)); + } /// /// Send a local chat message to this player diff --git a/RageCoop.Client/WorldThread.cs b/RageCoop.Client/WorldThread.cs index 3262ca1..b5124d3 100644 --- a/RageCoop.Client/WorldThread.cs +++ b/RageCoop.Client/WorldThread.cs @@ -114,64 +114,34 @@ namespace RageCoop.Client Function.Call(Hash.SET_NUMBER_OF_PARKED_VEHICLES, 0); Function.Call(Hash.SET_DISTANT_CARS_ENABLED, false); Function.Call(Hash.DISABLE_VEHICLE_DISTANTLIGHTS, true); - - if (Networking.IsOnServer) + foreach (Ped ped in World.GetAllPeds()) { - - foreach (Ped ped in World.GetAllPeds()) + SyncedPed c = EntityPool.GetPedByHandle(ped.Handle); + if ((c == null) || (c.IsLocal && (ped.Handle != Game.Player.Character.Handle) && ped.PopulationType != EntityPopulationType.Mission)) { - 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"); - ped.CurrentVehicle?.Delete(); - ped.Kill(); - ped.Delete(); - } + if (ped.Handle == Game.Player.Character.Handle) { continue; } + // Main.Logger.Trace($"Removing ped {ped.Handle}. Reason:RemoveTraffic"); + ped.CurrentVehicle?.Delete(); + ped.Kill(); + ped.Delete(); } - foreach (Vehicle veh in World.GetAllVehicles()) - { - SyncedVehicle v = veh.GetSyncEntity(); - if (v.MainVehicle == Game.Player.LastVehicle || v.MainVehicle==Game.Player.Character.CurrentVehicle) - { - // Don't delete player's vehicle - continue; - } - if ((v == null) || (v.IsLocal && veh.PopulationType != EntityPopulationType.Mission)) - { - // Main.Logger.Debug($"Removing Vehicle {veh.Handle}. Reason:ClearTraffic"); - - veh.Delete(); - } - } } - else + + foreach (Vehicle veh in World.GetAllVehicles()) { - foreach (Ped ped in World.GetAllPeds()) + SyncedVehicle v = veh.GetSyncEntity(); + if (v.MainVehicle == Game.Player.LastVehicle || v.MainVehicle == Game.Player.Character.CurrentVehicle) { - if ((ped != Game.Player.Character) && (ped.PopulationType != EntityPopulationType.Mission)) - { - // Main.Logger.Trace($"Removing ped {ped.Handle}. Reason:RemoveTraffic"); - ped.CurrentVehicle?.Delete(); - ped.Kill(); - ped.Delete(); - } - + // Don't delete player's vehicle + continue; } - var last = Game.Player.Character.LastVehicle; - var current = Game.Player.Character.CurrentVehicle; - foreach (Vehicle veh in World.GetAllVehicles()) + if ((v == null) || (v.IsLocal && veh.PopulationType != EntityPopulationType.Mission)) { - if (veh.PopulationType != EntityPopulationType.Mission && veh != last && veh!=current) - { - // Main.Logger.Debug($"Removing Vehicle {veh.Handle}. Reason:ClearTraffic"); + // Main.Logger.Debug($"Removing Vehicle {veh.Handle}. Reason:ClearTraffic"); - veh.Delete(); - } + veh.Delete(); } } } diff --git a/RageCoop.Core/Networking/ServerInfo.cs b/RageCoop.Core/Networking/ServerInfo.cs index 9a2ba42..62795a3 100644 --- a/RageCoop.Core/Networking/ServerInfo.cs +++ b/RageCoop.Core/Networking/ServerInfo.cs @@ -5,9 +5,12 @@ using Newtonsoft.Json; namespace RageCoop.Core { - - internal class ServerInfo + /// + /// A json object representing a server's information as annouced to master server. + /// + public class ServerInfo { +#pragma warning disable 1591 public string address { get; set; } public string port { get; set; } public string name { get; set; }