OnTick added. Bug fixes. Remove server created objects/vehicles/peds/checkpoints/blips on disconnect. More...

This commit is contained in:
EntenKoeniq
2021-12-26 03:25:00 +01:00
parent a4ffc25823
commit f4e563f93b
8 changed files with 269 additions and 13 deletions

View File

@ -128,12 +128,21 @@ namespace CoopServer
_actionQueue.Enqueue(new Action(() => _script.API.InvokePlayerHealthUpdate(playerData)));
}
}
public void InvokeTick(long tick)
{
lock (_actionQueue.SyncRoot)
{
_actionQueue.Enqueue(new Action(() => _script.API.InvokeTick(tick)));
}
}
}
public class API
{
#region DELEGATES
public delegate void EmptyEvent();
public delegate void OnTickEvent(long tick);
public delegate void ChatEvent(string username, string message, CancelEventArgs cancel);
public delegate void PlayerEvent(Client client);
public delegate void ModEvent(long from, long target, string mod, byte customID, byte[] bytes, CancelEventArgs args);
@ -141,6 +150,10 @@ namespace CoopServer
#region EVENTS
/// <summary>
/// Called every tick
/// </summary>
public event OnTickEvent OnTick;
/// <summary>
/// Called when the server has started
/// </summary>
public event EmptyEvent OnStart;
@ -181,6 +194,11 @@ namespace CoopServer
/// </summary>
public event ModEvent OnModPacketReceived;
internal void InvokeTick(long tick)
{
OnTick?.Invoke(tick);
}
internal void InvokeStart()
{
OnStart?.Invoke();
@ -276,7 +294,7 @@ namespace CoopServer
/// </summary>
/// <param name="hash">The hash (Example: 0x25223CA6B4D20B7F = GET_CLOCK_HOURS)</param>
/// <param name="args">The arguments (Example: string = int, object = 5)</param>
public static void SendNativeCallToAll(ulong hash, List<object> args = null)
public static void SendNativeCallToAll(ulong hash, params object[] args)
{
try
{
@ -285,7 +303,7 @@ namespace CoopServer
return;
}
if (args != null && args.Count == 0)
if (args != null && args.Length == 0)
{
Logging.Error($"[ServerScript->SendNativeCallToAll(ulong hash, params object[] args)]: args is not null!");
return;
@ -294,7 +312,7 @@ namespace CoopServer
NativeCallPacket packet = new()
{
Hash = hash,
Args = args ?? new List<object>()
Args = new List<object>(args) ?? new List<object>()
};
NetOutgoingMessage outgoingMessage = Server.MainNetServer.CreateMessage();
@ -362,6 +380,25 @@ namespace CoopServer
}
}
/// <summary>
///
/// </summary>
public static void SendCleanUpWorldToAll(List<long> netHandleList = null)
{
if (Server.MainNetServer.ConnectionsCount == 0)
{
return;
}
List<NetConnection> connections = netHandleList == null
? Server.MainNetServer.Connections
: Server.MainNetServer.Connections.FindAll(c => netHandleList.Contains(c.RemoteUniqueIdentifier));
NetOutgoingMessage outgoingMessage = Server.MainNetServer.CreateMessage();
outgoingMessage.Write((byte)PacketTypes.CleanUpWorldPacket);
Server.MainNetServer.SendMessage(outgoingMessage, connections, NetDeliveryMethod.ReliableOrdered, (byte)ConnectionChannel.Default);
}
/// <summary>
/// Register a new command chat command (Example: "/test")
/// </summary>