diff --git a/RageCoop.Client/Networking/Networking.cs b/RageCoop.Client/Networking/Networking.cs
index 703c779..41257cf 100644
--- a/RageCoop.Client/Networking/Networking.cs
+++ b/RageCoop.Client/Networking/Networking.cs
@@ -25,6 +25,7 @@ namespace RageCoop.Client
static Networking()
{
Security = new Security(Main.Logger);
+ Packets.CustomEvent.ResolveHandle = _resolveHandle;
}
public static void ToggleConnection(string address, string username = null, string password = null, PublicKey publicKey = null)
diff --git a/RageCoop.Client/Networking/Receive.cs b/RageCoop.Client/Networking/Receive.cs
index e3b6a37..c5e1da3 100644
--- a/RageCoop.Client/Networking/Receive.cs
+++ b/RageCoop.Client/Networking/Receive.cs
@@ -259,22 +259,22 @@ namespace RageCoop.Client
case PacketType.CustomEvent:
{
- Packets.CustomEvent packet = new Packets.CustomEvent(_resolveHandle);
+ Packets.CustomEvent packet = new Packets.CustomEvent();
packet.Deserialize(msg);
- Scripting.API.Events.InvokeCustomEventReceived(packet);
- }
- break;
-
- case PacketType.CustomEventQueued:
- {
- recycle = false;
- Packets.CustomEvent packet = new Packets.CustomEvent(_resolveHandle);
- Main.QueueAction(() =>
+ if (packet.Flags.HasEventFlag(Core.Scripting.CustomEventFlags.Queued))
+ {
+ recycle = false;
+ Main.QueueAction(() =>
+ {
+ packet.Deserialize(msg);
+ Scripting.API.Events.InvokeCustomEventReceived(packet);
+ Peer.Recycle(msg);
+ });
+ }
+ else
{
- packet.Deserialize(msg);
Scripting.API.Events.InvokeCustomEventReceived(packet);
- Peer.Recycle(msg);
- });
+ }
}
break;
diff --git a/RageCoop.Client/Properties/AssemblyInfo.cs b/RageCoop.Client/Properties/AssemblyInfo.cs
index 6a66801..407605a 100644
--- a/RageCoop.Client/Properties/AssemblyInfo.cs
+++ b/RageCoop.Client/Properties/AssemblyInfo.cs
@@ -16,7 +16,7 @@ using System.Resources;
// Version informationr(
-[assembly: AssemblyVersion("1.5.4.3")]
-[assembly: AssemblyFileVersion("1.5.4.3")]
+[assembly: AssemblyVersion("1.5.4.7")]
+[assembly: AssemblyFileVersion("1.5.4.7")]
[assembly: NeutralResourcesLanguageAttribute( "en-US" )]
diff --git a/RageCoop.Client/RageCoop.Client.csproj b/RageCoop.Client/RageCoop.Client.csproj
index 8311337..e7b80f2 100644
--- a/RageCoop.Client/RageCoop.Client.csproj
+++ b/RageCoop.Client/RageCoop.Client.csproj
@@ -1,311 +1,313 @@
-
-
-
- Debug
- AnyCPU
- {EF56D109-1F22-43E0-9DFF-CFCFB94E0681}
- Library
- Properties
- RageCoop.Client
- RageCoop.Client
- v4.8
- 512
- true
-
-
-
-
-
- ..\bin\Debug\Client
- true
- DEBUG
- 4
-
-
- ..\bin\Release\Client
- true
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- True
- True
- AssemblyInfo.tt
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- {cc2e8102-e568-4524-aa1f-f8e0f1cfe58a}
- RageCoop.Core
-
-
-
-
- ..\packages\Costura.Fody.5.7.0\lib\netstandard1.0\Costura.dll
-
-
- ..\packages\SharpZipLib.1.3.3\lib\net45\ICSharpCode.SharpZipLib.dll
-
-
- False
- ..\libs\LemonUI.SHVDN3.dll
-
-
- False
- ..\libs\Lidgren.Network.dll
-
-
-
- ..\packages\Microsoft.Extensions.ObjectPool.6.0.8\lib\net461\Microsoft.Extensions.ObjectPool.dll
-
-
- ..\packages\Microsoft.Win32.Primitives.4.3.0\lib\net46\Microsoft.Win32.Primitives.dll
- True
- True
-
-
- ..\packages\Microsoft.Win32.Registry.4.7.0\lib\net461\Microsoft.Win32.Registry.dll
-
-
- ..\packages\NAudio.2.1.0\lib\net472\NAudio.dll
-
-
- ..\packages\NAudio.Asio.2.1.0\lib\netstandard2.0\NAudio.Asio.dll
-
-
- ..\packages\NAudio.Core.2.1.0\lib\netstandard2.0\NAudio.Core.dll
-
-
- ..\packages\NAudio.Midi.2.1.0\lib\netstandard2.0\NAudio.Midi.dll
-
-
- ..\packages\NAudio.Wasapi.2.1.0\lib\netstandard2.0\NAudio.Wasapi.dll
-
-
- ..\packages\NAudio.WinForms.2.1.0\lib\net472\NAudio.WinForms.dll
-
-
- ..\packages\NAudio.WinMM.2.1.0\lib\netstandard2.0\NAudio.WinMM.dll
-
-
- False
- ..\libs\Newtonsoft.Json.dll
-
-
- ..\libs\ScriptHookVDotNet.dll
-
-
- ..\libs\ScriptHookVDotNet3.dll
-
-
-
- ..\packages\System.AppContext.4.3.0\lib\net463\System.AppContext.dll
- True
- True
-
-
-
- ..\packages\System.Console.4.3.0\lib\net46\System.Console.dll
- True
- True
-
-
- ..\packages\System.Diagnostics.DiagnosticSource.4.3.0\lib\net46\System.Diagnostics.DiagnosticSource.dll
-
-
- ..\packages\System.Diagnostics.Tracing.4.3.0\lib\net462\System.Diagnostics.Tracing.dll
- True
- True
-
-
-
- ..\packages\System.Globalization.Calendars.4.3.0\lib\net46\System.Globalization.Calendars.dll
- True
- True
-
-
- ..\packages\System.IO.4.3.0\lib\net462\System.IO.dll
- True
- True
-
-
- ..\packages\System.IO.Compression.4.3.0\lib\net46\System.IO.Compression.dll
- True
- True
-
-
-
- ..\packages\System.IO.Compression.ZipFile.4.3.0\lib\net46\System.IO.Compression.ZipFile.dll
- True
- True
-
-
- ..\packages\System.IO.FileSystem.4.3.0\lib\net46\System.IO.FileSystem.dll
- True
- True
-
-
- ..\packages\System.IO.FileSystem.Primitives.4.3.0\lib\net46\System.IO.FileSystem.Primitives.dll
- True
- True
-
-
- ..\packages\System.Linq.4.3.0\lib\net463\System.Linq.dll
- True
- True
-
-
- ..\packages\System.Linq.Expressions.4.3.0\lib\net463\System.Linq.Expressions.dll
- True
- True
-
-
- ..\packages\System.Net.Http.4.3.0\lib\net46\System.Net.Http.dll
- True
- True
-
-
- ..\packages\System.Net.Sockets.4.3.0\lib\net46\System.Net.Sockets.dll
- True
- True
-
-
-
- ..\packages\System.Reflection.4.3.0\lib\net462\System.Reflection.dll
- True
- True
-
-
- ..\packages\System.Runtime.4.3.0\lib\net462\System.Runtime.dll
- True
- True
-
-
- ..\packages\System.Runtime.Extensions.4.3.0\lib\net462\System.Runtime.Extensions.dll
- True
- True
-
-
- ..\packages\System.Runtime.InteropServices.4.3.0\lib\net463\System.Runtime.InteropServices.dll
- True
- True
-
-
- ..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll
- True
- True
-
-
- ..\packages\System.Security.AccessControl.4.7.0\lib\net461\System.Security.AccessControl.dll
-
-
- ..\packages\System.Security.Cryptography.Algorithms.4.3.0\lib\net463\System.Security.Cryptography.Algorithms.dll
- True
- True
-
-
- ..\packages\System.Security.Cryptography.Encoding.4.3.0\lib\net46\System.Security.Cryptography.Encoding.dll
- True
- True
-
-
- ..\packages\System.Security.Cryptography.Primitives.4.3.0\lib\net46\System.Security.Cryptography.Primitives.dll
- True
- True
-
-
- ..\packages\System.Security.Cryptography.X509Certificates.4.3.0\lib\net461\System.Security.Cryptography.X509Certificates.dll
- True
- True
-
-
- ..\packages\System.Security.Principal.Windows.4.7.0\lib\net461\System.Security.Principal.Windows.dll
-
-
- ..\packages\System.Text.RegularExpressions.4.3.0\lib\net463\System.Text.RegularExpressions.dll
- True
- True
-
-
-
-
-
- ..\packages\System.Xml.ReaderWriter.4.3.0\lib\net46\System.Xml.ReaderWriter.dll
- True
- True
-
-
-
-
-
-
-
-
-
- TextTemplatingFileGenerator
- AssemblyInfo.cs
-
-
-
-
-
-
-
-
-
- This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
-
-
-
-
-
-
-
- "$(DevEnvDir)TextTransform.exe" -a !!BuildConfiguration!$(Configuration) "$(ProjectDir)Properties\AssemblyInfo.tt"
-
+
+
+
+ None
+ Debug
+ AnyCPU
+ {EF56D109-1F22-43E0-9DFF-CFCFB94E0681}
+ Library
+ Properties
+ RageCoop.Client
+ RageCoop.Client
+ v4.8
+ 512
+ true
+
+
+
+
+
+ ..\bin\Debug\Client
+ true
+ DEBUG
+ 4
+ 1591
+
+
+ ..\bin\Release\Client
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ True
+ True
+ AssemblyInfo.tt
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {cc2e8102-e568-4524-aa1f-f8e0f1cfe58a}
+ RageCoop.Core
+
+
+
+
+ ..\packages\Costura.Fody.5.7.0\lib\netstandard1.0\Costura.dll
+
+
+ ..\packages\SharpZipLib.1.3.3\lib\net45\ICSharpCode.SharpZipLib.dll
+
+
+ False
+ ..\libs\LemonUI.SHVDN3.dll
+
+
+ False
+ ..\libs\Lidgren.Network.dll
+
+
+
+ ..\packages\Microsoft.Extensions.ObjectPool.6.0.8\lib\net461\Microsoft.Extensions.ObjectPool.dll
+
+
+ ..\packages\Microsoft.Win32.Primitives.4.3.0\lib\net46\Microsoft.Win32.Primitives.dll
+ True
+ True
+
+
+ ..\packages\Microsoft.Win32.Registry.4.7.0\lib\net461\Microsoft.Win32.Registry.dll
+
+
+ ..\packages\NAudio.2.1.0\lib\net472\NAudio.dll
+
+
+ ..\packages\NAudio.Asio.2.1.0\lib\netstandard2.0\NAudio.Asio.dll
+
+
+ ..\packages\NAudio.Core.2.1.0\lib\netstandard2.0\NAudio.Core.dll
+
+
+ ..\packages\NAudio.Midi.2.1.0\lib\netstandard2.0\NAudio.Midi.dll
+
+
+ ..\packages\NAudio.Wasapi.2.1.0\lib\netstandard2.0\NAudio.Wasapi.dll
+
+
+ ..\packages\NAudio.WinForms.2.1.0\lib\net472\NAudio.WinForms.dll
+
+
+ ..\packages\NAudio.WinMM.2.1.0\lib\netstandard2.0\NAudio.WinMM.dll
+
+
+ False
+ ..\libs\Newtonsoft.Json.dll
+
+
+ ..\libs\ScriptHookVDotNet.dll
+
+
+ ..\libs\ScriptHookVDotNet3.dll
+
+
+
+ ..\packages\System.AppContext.4.3.0\lib\net463\System.AppContext.dll
+ True
+ True
+
+
+
+ ..\packages\System.Console.4.3.0\lib\net46\System.Console.dll
+ True
+ True
+
+
+ ..\packages\System.Diagnostics.DiagnosticSource.4.3.0\lib\net46\System.Diagnostics.DiagnosticSource.dll
+
+
+ ..\packages\System.Diagnostics.Tracing.4.3.0\lib\net462\System.Diagnostics.Tracing.dll
+ True
+ True
+
+
+
+ ..\packages\System.Globalization.Calendars.4.3.0\lib\net46\System.Globalization.Calendars.dll
+ True
+ True
+
+
+ ..\packages\System.IO.4.3.0\lib\net462\System.IO.dll
+ True
+ True
+
+
+ ..\packages\System.IO.Compression.4.3.0\lib\net46\System.IO.Compression.dll
+ True
+ True
+
+
+
+ ..\packages\System.IO.Compression.ZipFile.4.3.0\lib\net46\System.IO.Compression.ZipFile.dll
+ True
+ True
+
+
+ ..\packages\System.IO.FileSystem.4.3.0\lib\net46\System.IO.FileSystem.dll
+ True
+ True
+
+
+ ..\packages\System.IO.FileSystem.Primitives.4.3.0\lib\net46\System.IO.FileSystem.Primitives.dll
+ True
+ True
+
+
+ ..\packages\System.Linq.4.3.0\lib\net463\System.Linq.dll
+ True
+ True
+
+
+ ..\packages\System.Linq.Expressions.4.3.0\lib\net463\System.Linq.Expressions.dll
+ True
+ True
+
+
+ ..\packages\System.Net.Http.4.3.0\lib\net46\System.Net.Http.dll
+ True
+ True
+
+
+ ..\packages\System.Net.Sockets.4.3.0\lib\net46\System.Net.Sockets.dll
+ True
+ True
+
+
+
+ ..\packages\System.Reflection.4.3.0\lib\net462\System.Reflection.dll
+ True
+ True
+
+
+ ..\packages\System.Runtime.4.3.0\lib\net462\System.Runtime.dll
+ True
+ True
+
+
+ ..\packages\System.Runtime.Extensions.4.3.0\lib\net462\System.Runtime.Extensions.dll
+ True
+ True
+
+
+ ..\packages\System.Runtime.InteropServices.4.3.0\lib\net463\System.Runtime.InteropServices.dll
+ True
+ True
+
+
+ ..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll
+ True
+ True
+
+
+ ..\packages\System.Security.AccessControl.4.7.0\lib\net461\System.Security.AccessControl.dll
+
+
+ ..\packages\System.Security.Cryptography.Algorithms.4.3.0\lib\net463\System.Security.Cryptography.Algorithms.dll
+ True
+ True
+
+
+ ..\packages\System.Security.Cryptography.Encoding.4.3.0\lib\net46\System.Security.Cryptography.Encoding.dll
+ True
+ True
+
+
+ ..\packages\System.Security.Cryptography.Primitives.4.3.0\lib\net46\System.Security.Cryptography.Primitives.dll
+ True
+ True
+
+
+ ..\packages\System.Security.Cryptography.X509Certificates.4.3.0\lib\net461\System.Security.Cryptography.X509Certificates.dll
+ True
+ True
+
+
+ ..\packages\System.Security.Principal.Windows.4.7.0\lib\net461\System.Security.Principal.Windows.dll
+
+
+ ..\packages\System.Text.RegularExpressions.4.3.0\lib\net463\System.Text.RegularExpressions.dll
+ True
+ True
+
+
+
+
+
+ ..\packages\System.Xml.ReaderWriter.4.3.0\lib\net46\System.Xml.ReaderWriter.dll
+ True
+ True
+
+
+
+
+
+
+
+
+
+ TextTemplatingFileGenerator
+ AssemblyInfo.cs
+
+
+
+
+
+
+
+
+
+ This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
+
+
+
+
+
+
+
+ "$(DevEnvDir)TextTransform.exe" -a !!BuildConfiguration!$(Configuration) "$(ProjectDir)Properties\AssemblyInfo.tt"
+
\ No newline at end of file
diff --git a/RageCoop.Client/Scripting/API.cs b/RageCoop.Client/Scripting/API.cs
index 0cd5ff3..0394653 100644
--- a/RageCoop.Client/Scripting/API.cs
+++ b/RageCoop.Client/Scripting/API.cs
@@ -2,6 +2,7 @@
using GTA;
using Newtonsoft.Json;
using RageCoop.Core;
+using RageCoop.Core.Scripting;
using System;
using System.Collections.Generic;
using System.Windows.Forms;
@@ -280,7 +281,7 @@ namespace RageCoop.Client.Scripting
///
/// An unique identifier of the event
/// The objects conataing your data, see for a list of supported types
- public static void SendCustomEvent(int eventHash, params object[] args)
+ public static void SendCustomEvent(CustomEventHash eventHash, params object[] args)
{
Networking.Peer.SendTo(new Packets.CustomEvent()
@@ -289,13 +290,27 @@ namespace RageCoop.Client.Scripting
Hash = eventHash
}, Networking.ServerConnection, ConnectionChannel.Event, Lidgren.Network.NetDeliveryMethod.ReliableOrdered);
}
+ ///
+ /// Send an event and data to the server
+ ///
+ ///
+ /// An unique identifier of the event
+ /// The objects conataing your data, see for a list of supported types
+ public static void SendCustomEvent(CustomEventFlags flags,CustomEventHash eventHash, params object[] args)
+ {
+ Networking.Peer.SendTo(new Packets.CustomEvent(flags)
+ {
+ Args = args,
+ Hash = eventHash
+ }, Networking.ServerConnection, ConnectionChannel.Event, Lidgren.Network.NetDeliveryMethod.ReliableOrdered);
+ }
///
/// Register an handler to the specifed event hash, one event can have multiple handlers. This will be invoked from backgound thread, use in the handler to dispatch code to script thread.
///
/// An unique identifier of the event, you can hash your event name with
/// An handler to be invoked when the event is received from the server.
- public static void RegisterCustomEventHandler(int hash, Action handler)
+ public static void RegisterCustomEventHandler(CustomEventHash hash, Action handler)
{
lock (CustomEventHandlers)
{
diff --git a/RageCoop.Core/CoreUtils.cs b/RageCoop.Core/CoreUtils.cs
index d2d97ad..fc63ef4 100644
--- a/RageCoop.Core/CoreUtils.cs
+++ b/RageCoop.Core/CoreUtils.cs
@@ -1,6 +1,7 @@
using GTA.Math;
using Lidgren.Network;
using Newtonsoft.Json;
+using RageCoop.Core.Scripting;
using System;
using System.Collections.Generic;
using System.IO;
@@ -13,6 +14,7 @@ using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text;
+using static ICSharpCode.SharpZipLib.Zip.ExtendedUnixData;
[assembly: InternalsVisibleTo("RageCoop.Server")]
[assembly: InternalsVisibleTo("RageCoop.Client")]
@@ -272,22 +274,27 @@ namespace RageCoop.Core
p.Deserialize(msg);
return p;
}
- public static bool HasPedFlag(this PedDataFlags flagToCheck, PedDataFlags flag)
+ public static bool HasPedFlag(this PedDataFlags flags, PedDataFlags flag)
{
- return (flagToCheck & flag) != 0;
+ return (flags & flag) != 0;
}
- public static bool HasProjDataFlag(this ProjectileDataFlags flagToCheck, ProjectileDataFlags flag)
+ public static bool HasProjDataFlag(this ProjectileDataFlags flags, ProjectileDataFlags flag)
{
- return (flagToCheck & flag) != 0;
+ return (flags & flag) != 0;
}
- public static bool HasVehFlag(this VehicleDataFlags flagToCheck, VehicleDataFlags flag)
+ public static bool HasVehFlag(this VehicleDataFlags flags, VehicleDataFlags flag)
{
- return (flagToCheck & flag) != 0;
+ return (flags & flag) != 0;
}
- public static bool HasConfigFlag(this PlayerConfigFlags flagToCheck, PlayerConfigFlags flag)
+ public static bool HasConfigFlag(this PlayerConfigFlags flags, PlayerConfigFlags flag)
{
- return (flagToCheck & flag) != 0;
+ return (flags & flag) != 0;
+ }
+ public static bool HasEventFlag(this CustomEventFlags flags,CustomEventFlags flag)
+ {
+ return (flags & flag) != 0;
+
}
public static Type GetActualType(this TypeCode code)
{
diff --git a/RageCoop.Core/Packets/CustomEvent.cs b/RageCoop.Core/Packets/CustomEvent.cs
index d2eadfd..850e0d4 100644
--- a/RageCoop.Core/Packets/CustomEvent.cs
+++ b/RageCoop.Core/Packets/CustomEvent.cs
@@ -1,4 +1,5 @@
using Lidgren.Network;
+using RageCoop.Core.Scripting;
using System;
namespace RageCoop.Core
{
@@ -7,21 +8,20 @@ namespace RageCoop.Core
internal class CustomEvent : Packet
{
- public override PacketType Type => (_queued ? PacketType.CustomEventQueued : PacketType.CustomEvent);
- public CustomEvent(Func onResolve = null, bool queued = false)
+ public static Func ResolveHandle = null;
+ public CustomEventFlags Flags;
+ public override PacketType Type => PacketType.CustomEvent;
+ public CustomEvent(CustomEventFlags flags = CustomEventFlags.None)
{
- _resolve = onResolve;
- _queued = queued;
+ Flags = flags;
}
- private readonly bool _queued;
- private Func _resolve { get; set; }
public int Hash { get; set; }
public object[] Args { get; set; }
protected override void Serialize(NetOutgoingMessage m)
{
Args = Args ?? new object[] { };
-
+ m.Write((byte)Flags);
m.Write(Hash);
m.Write(Args.Length);
foreach (var arg in Args)
@@ -33,7 +33,7 @@ namespace RageCoop.Core
public override void Deserialize(NetIncomingMessage m)
{
-
+ Flags = (CustomEventFlags)m.ReadByte();
Hash = m.ReadInt32();
var len = m.ReadInt32();
Args = new object[len];
@@ -73,13 +73,13 @@ namespace RageCoop.Core
case 0x15:
Args[i] = m.ReadByteArray(); break;
default:
- if (_resolve == null)
+ if (ResolveHandle == null)
{
throw new InvalidOperationException($"Unexpected type: {type}");
}
else
{
- Args[i] = _resolve(type, m); break;
+ Args[i] = ResolveHandle(type, m); break;
}
}
}
diff --git a/RageCoop.Core/Packets/Packets.cs b/RageCoop.Core/Packets/Packets.cs
index b92936d..d8fb308 100644
--- a/RageCoop.Core/Packets/Packets.cs
+++ b/RageCoop.Core/Packets/Packets.cs
@@ -24,7 +24,6 @@ namespace RageCoop.Core
AllResourcesSent = 15,
CustomEvent = 16,
- CustomEventQueued = 17,
ConnectionRequest = 18,
P2PConnect = 19,
diff --git a/RageCoop.Core/RageCoop.Core.csproj b/RageCoop.Core/RageCoop.Core.csproj
index f4aa435..3807e0c 100644
--- a/RageCoop.Core/RageCoop.Core.csproj
+++ b/RageCoop.Core/RageCoop.Core.csproj
@@ -24,6 +24,14 @@
4
+
+ 1701;1702;1591
+
+
+
+ 1701;1702;1591
+
+
all
diff --git a/RageCoop.Core/Scripting/CustomEvents.cs b/RageCoop.Core/Scripting/CustomEvents.cs
index f448100..1a7ccb0 100644
--- a/RageCoop.Core/Scripting/CustomEvents.cs
+++ b/RageCoop.Core/Scripting/CustomEvents.cs
@@ -1,4 +1,5 @@
-using System;
+using GTA.Native;
+using System;
using System.Collections.Generic;
using System.Security.Cryptography;
using System.Text;
@@ -6,38 +7,59 @@ using System.Text;
namespace RageCoop.Core.Scripting
{
///
- ///
+ /// Describes how the event should be sent or processed
///
- public static class CustomEvents
+ public enum CustomEventFlags : byte
+ {
+ None=0,
+
+ ///
+ /// Data will be encrypted and decrypted on target client
+ ///
+ Encrypted=1,
+
+ ///
+ /// Event will be queued and fired in script thread, specify this flag if your handler will call native functions.
+ ///
+ Queued=2,
+
+ }
+
+ ///
+ /// Struct to identify different event using hash
+ ///
+ public struct CustomEventHash
{
private static readonly MD5 Hasher = MD5.Create();
private static readonly Dictionary Hashed = new Dictionary();
- internal static readonly int OnPlayerDied = Hash("RageCoop.OnPlayerDied");
- internal static readonly int SetWeather = Hash("RageCoop.SetWeather");
- internal static readonly int OnPedDeleted = Hash("RageCoop.OnPedDeleted");
- internal static readonly int OnVehicleDeleted = Hash("RageCoop.OnVehicleDeleted");
- internal static readonly int SetAutoRespawn = Hash("RageCoop.SetAutoRespawn");
- internal static readonly int SetDisplayNameTag = Hash("RageCoop.SetDisplayNameTag");
- internal static readonly int NativeCall = Hash("RageCoop.NativeCall");
- internal static readonly int NativeResponse = Hash("RageCoop.NativeResponse");
- internal static readonly int AllResourcesSent = Hash("RageCoop.AllResourcesSent");
- internal static readonly int ServerPropSync = Hash("RageCoop.ServerPropSync");
- internal static readonly int ServerBlipSync = Hash("RageCoop.ServerBlipSync");
- internal static readonly int SetEntity = Hash("RageCoop.SetEntity");
- internal static readonly int DeleteServerProp = Hash("RageCoop.DeleteServerProp");
- internal static readonly int UpdatePedBlip = Hash("RageCoop.UpdatePedBlip");
- internal static readonly int DeleteEntity = Hash("RageCoop.DeleteEntity");
- internal static readonly int DeleteServerBlip = Hash("RageCoop.DeleteServerBlip");
- internal static readonly int CreateVehicle = Hash("RageCoop.CreateVehicle");
- internal static readonly int WeatherTimeSync = Hash("RageCoop.WeatherTimeSync");
- internal static readonly int IsHost = Hash("RageCoop.IsHost");
+ ///
+ /// Hash value
+ ///
+ public int Hash;
+ ///
+ /// Create from hash
+ ///
+ ///
+ public static implicit operator CustomEventHash(int hash)
+ {
+ return new CustomEventHash() { Hash = hash };
+ }
+ ///
+ /// Create from string
+ ///
+ ///
+ public static implicit operator CustomEventHash(string name)
+ {
+ return new CustomEventHash() { Hash = FromString(name) };
+
+ }
///
/// Get a Int32 hash of a string.
///
///
///
/// The exception is thrown when the name did not match a previously computed one and the hash was the same.
- public static int Hash(string s)
+ public static int FromString(string s)
{
var hash = BitConverter.ToInt32(Hasher.ComputeHash(Encoding.UTF8.GetBytes(s)), 0);
lock (Hashed)
@@ -56,5 +78,39 @@ namespace RageCoop.Core.Scripting
return hash;
}
}
+ ///
+ /// To int
+ ///
+ ///
+ public static implicit operator int(CustomEventHash h)
+ {
+ return h.Hash;
+ }
+ }
+ ///
+ ///
+ ///
+ public static class CustomEvents
+ {
+ internal static readonly CustomEventHash OnPlayerDied = "RageCoop.OnPlayerDied";
+ internal static readonly CustomEventHash SetWeather = "RageCoop.SetWeather";
+ internal static readonly CustomEventHash OnPedDeleted = "RageCoop.OnPedDeleted";
+ internal static readonly CustomEventHash OnVehicleDeleted = "RageCoop.OnVehicleDeleted";
+ internal static readonly CustomEventHash SetAutoRespawn = "RageCoop.SetAutoRespawn";
+ internal static readonly CustomEventHash SetDisplayNameTag = "RageCoop.SetDisplayNameTag";
+ internal static readonly CustomEventHash NativeCall = "RageCoop.NativeCall";
+ internal static readonly CustomEventHash NativeResponse = "RageCoop.NativeResponse";
+ internal static readonly CustomEventHash AllResourcesSent = "RageCoop.AllResourcesSent";
+ internal static readonly CustomEventHash ServerPropSync = "RageCoop.ServerPropSync";
+ internal static readonly CustomEventHash ServerBlipSync = "RageCoop.ServerBlipSync";
+ internal static readonly CustomEventHash SetEntity = "RageCoop.SetEntity";
+ internal static readonly CustomEventHash DeleteServerProp = "RageCoop.DeleteServerProp";
+ internal static readonly CustomEventHash UpdatePedBlip = "RageCoop.UpdatePedBlip";
+ internal static readonly CustomEventHash DeleteEntity = "RageCoop.DeleteEntity";
+ internal static readonly CustomEventHash DeleteServerBlip = "RageCoop.DeleteServerBlip";
+ internal static readonly CustomEventHash CreateVehicle = "RageCoop.CreateVehicle";
+ internal static readonly CustomEventHash WeatherTimeSync = "RageCoop.WeatherTimeSync";
+ internal static readonly CustomEventHash IsHost = "RageCoop.IsHost";
+
}
}
diff --git a/RageCoop.Server/Client.cs b/RageCoop.Server/Client.cs
index 2fb6884..d9edaec 100644
--- a/RageCoop.Server/Client.cs
+++ b/RageCoop.Server/Client.cs
@@ -170,9 +170,10 @@ namespace RageCoop.Server
///
/// Trigger a CustomEvent for this client
///
- /// An unique identifier of the event, you can use to get it from a string
+ ///
+ /// An unique identifier of the event
/// Arguments
- public void SendCustomEvent(int hash, params object[] args)
+ public void SendCustomEvent(CustomEventFlags flags,CustomEventHash hash, params object[] args)
{
if (!IsReady)
{
@@ -183,7 +184,7 @@ namespace RageCoop.Server
{
NetOutgoingMessage outgoingMessage = Server.MainNetServer.CreateMessage();
- new Packets.CustomEvent()
+ new Packets.CustomEvent(flags)
{
Hash = hash,
Args = args
@@ -196,37 +197,13 @@ namespace RageCoop.Server
Server.Logger?.Error(ex);
}
}
-
- ///
- /// Send a CustomEvent that'll be queued at client side and invoked from script thread
- ///
- ///
- ///
- public void SendCustomEventQueued(int hash, params object[] args)
- {
- if (!IsReady)
- {
- Server.Logger?.Warning($"Player \"{Username}\" is not ready!");
- }
-
- try
- {
-
- NetOutgoingMessage outgoingMessage = Server.MainNetServer.CreateMessage();
- new Packets.CustomEvent(null, true)
- {
- Hash = hash,
- Args = args
- }.Pack(outgoingMessage);
- Server.MainNetServer.SendMessage(outgoingMessage, Connection, NetDeliveryMethod.ReliableOrdered, (byte)ConnectionChannel.Event);
-
- }
- catch (Exception ex)
- {
- Server.Logger?.Error(ex);
- }
+ public void SendCustomEventQueued(CustomEventHash hash, params object[] args) {
+ SendCustomEvent(CustomEventFlags.Queued, hash, args);
+ }
+ public void SendCustomEvent(CustomEventHash hash, params object[] args)
+ {
+ SendCustomEvent(CustomEventFlags.None, hash, args);
}
-
#endregion
}
}
diff --git a/RageCoop.Server/Properties/AssemblyInfo.cs b/RageCoop.Server/Properties/AssemblyInfo.cs
index 6a28ef3..1242a23 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.4.2")]
-[assembly: AssemblyFileVersion("1.5.4.2")]
+[assembly: AssemblyVersion("1.5.4.5")]
+[assembly: AssemblyFileVersion("1.5.4.5")]
[assembly: NeutralResourcesLanguageAttribute( "en-US" )]
diff --git a/RageCoop.Server/RageCoop.Server.csproj b/RageCoop.Server/RageCoop.Server.csproj
index ab0f1c3..7c0fdf6 100644
--- a/RageCoop.Server/RageCoop.Server.csproj
+++ b/RageCoop.Server/RageCoop.Server.csproj
@@ -28,6 +28,12 @@
..\bin\Release\Server
+
+ 1701;1702;1591
+
+
+ 1701;1702;1591
+
diff --git a/RageCoop.Server/Scripting/API.cs b/RageCoop.Server/Scripting/API.cs
index b59adef..a1afa6c 100644
--- a/RageCoop.Server/Scripting/API.cs
+++ b/RageCoop.Server/Scripting/API.cs
@@ -302,57 +302,50 @@ namespace RageCoop.Server.Scripting
{
var argsList = new List