Sync every 30 ms
This commit is contained in:
@ -10,7 +10,7 @@ namespace RageCoop.Client
|
|||||||
internal static partial class Networking
|
internal static partial class Networking
|
||||||
{
|
{
|
||||||
|
|
||||||
|
public static int SyncInterval = 30;
|
||||||
#region -- SEND --
|
#region -- SEND --
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Pack the packet then send to server.
|
/// Pack the packet then send to server.
|
||||||
@ -27,6 +27,10 @@ namespace RageCoop.Client
|
|||||||
|
|
||||||
public static void SendPed(SyncedPed c, bool full)
|
public static void SendPed(SyncedPed c, bool full)
|
||||||
{
|
{
|
||||||
|
if (c.LastSentStopWatch.ElapsedMilliseconds<SyncInterval)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
Ped p = c.MainPed;
|
Ped p = c.MainPed;
|
||||||
var packet = new Packets.PedSync()
|
var packet = new Packets.PedSync()
|
||||||
{
|
{
|
||||||
@ -54,6 +58,7 @@ namespace RageCoop.Client
|
|||||||
{
|
{
|
||||||
packet.Position = p.ReadPosition();
|
packet.Position = p.ReadPosition();
|
||||||
}
|
}
|
||||||
|
c.LastSentStopWatch.Restart();
|
||||||
if (full)
|
if (full)
|
||||||
{
|
{
|
||||||
packet.Flags |= PedDataFlags.IsFullSync;
|
packet.Flags |= PedDataFlags.IsFullSync;
|
||||||
@ -84,6 +89,10 @@ namespace RageCoop.Client
|
|||||||
}
|
}
|
||||||
public static void SendVehicle(SyncedVehicle v, bool full)
|
public static void SendVehicle(SyncedVehicle v, bool full)
|
||||||
{
|
{
|
||||||
|
if (v.LastSentStopWatch.ElapsedMilliseconds<SyncInterval)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
Vehicle veh = v.MainVehicle;
|
Vehicle veh = v.MainVehicle;
|
||||||
var packet = new Packets.VehicleSync()
|
var packet = new Packets.VehicleSync()
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using GTA;
|
using GTA;
|
||||||
using GTA.Math;
|
using GTA.Math;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
namespace RageCoop.Client
|
namespace RageCoop.Client
|
||||||
{
|
{
|
||||||
@ -60,6 +61,9 @@ namespace RageCoop.Client
|
|||||||
/// Last time the local entity has been updated,
|
/// Last time the local entity has been updated,
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ulong LastUpdated { get; set; } = 0;
|
public ulong LastUpdated { get; set; } = 0;
|
||||||
|
|
||||||
|
|
||||||
|
internal Stopwatch LastSentStopWatch { get; set; } = Stopwatch.StartNew();
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
public bool SendNextFrame { get; set; } = false;
|
public bool SendNextFrame { get; set; } = false;
|
||||||
|
@ -484,7 +484,6 @@ namespace RageCoop.Client
|
|||||||
|
|
||||||
internal float LastEngineHealth { get; set; }
|
internal float LastEngineHealth { get; set; }
|
||||||
internal Vector3 LastVelocity { get; set; }
|
internal Vector3 LastVelocity { get; set; }
|
||||||
internal Stopwatch LastSentStopWatch { get; set; }=new Stopwatch();
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -325,11 +325,11 @@ namespace RageCoop.Server
|
|||||||
if (status == NetConnectionStatus.Disconnected)
|
if (status == NetConnectionStatus.Disconnected)
|
||||||
{
|
{
|
||||||
|
|
||||||
SendPlayerDisconnectPacket(sender);
|
PlayerDisconnected(sender);
|
||||||
}
|
}
|
||||||
else if (status == NetConnectionStatus.Connected)
|
else if (status == NetConnectionStatus.Connected)
|
||||||
{
|
{
|
||||||
SendPlayerConnectPacket(sender);
|
PlayerConnected(sender);
|
||||||
_worker.QueueJob(() => API.Events.InvokePlayerConnected(sender));
|
_worker.QueueJob(() => API.Events.InvokePlayerConnected(sender));
|
||||||
Resources.SendTo(sender);
|
Resources.SendTo(sender);
|
||||||
}
|
}
|
||||||
@ -512,8 +512,6 @@ namespace RageCoop.Server
|
|||||||
senderConnection.Disconnect(e.Message);
|
senderConnection.Disconnect(e.Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
#region -- SYNC --
|
|
||||||
// Before we approve the connection, we must shake hands
|
|
||||||
private void GetHandshake(NetConnection connection, Packets.Handshake packet)
|
private void GetHandshake(NetConnection connection, Packets.Handshake packet)
|
||||||
{
|
{
|
||||||
Logger?.Debug("New handshake from: [Name: " + packet.Username + " | Address: " + connection.RemoteEndPoint.Address.ToString() + "]");
|
Logger?.Debug("New handshake from: [Name: " + packet.Username + " | Address: " + connection.RemoteEndPoint.Address.ToString() + "]");
|
||||||
@ -595,7 +593,7 @@ namespace RageCoop.Server
|
|||||||
}
|
}
|
||||||
|
|
||||||
// The connection has been approved, now we need to send all other players to the new player and the new player to all players
|
// The connection has been approved, now we need to send all other players to the new player and the new player to all players
|
||||||
private void SendPlayerConnectPacket(Client newClient)
|
private void PlayerConnected(Client newClient)
|
||||||
{
|
{
|
||||||
if (newClient==_hostClient)
|
if (newClient==_hostClient)
|
||||||
{
|
{
|
||||||
@ -647,7 +645,7 @@ namespace RageCoop.Server
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Send all players a message that someone has left the server
|
// Send all players a message that someone has left the server
|
||||||
private void SendPlayerDisconnectPacket(Client localClient)
|
private void PlayerDisconnected(Client localClient)
|
||||||
{
|
{
|
||||||
var cons = MainNetServer.Connections.Exclude(localClient.Connection);
|
var cons = MainNetServer.Connections.Exclude(localClient.Connection);
|
||||||
if (cons.Count!=0)
|
if (cons.Count!=0)
|
||||||
@ -674,6 +672,7 @@ namespace RageCoop.Server
|
|||||||
Security.RemoveConnection(localClient.Connection.RemoteEndPoint);
|
Security.RemoveConnection(localClient.Connection.RemoteEndPoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region -- SYNC --
|
||||||
#region SyncEntities
|
#region SyncEntities
|
||||||
|
|
||||||
private void PedSync(Packets.PedSync packet, Client client)
|
private void PedSync(Packets.PedSync packet, Client client)
|
||||||
|
Reference in New Issue
Block a user