Skip to content

Commit

Permalink
Added client NuiRequest method to communicate with resource main nui.
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown committed Dec 6, 2020
1 parent 46c08da commit a639da7
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 7 deletions.
Binary file added Newtonsoft.Json.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion VinaFrameworkClient/Core/BaseClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public BaseClient()
/// **Experimental**
/// Cleanup the garbage once a minutes to keep memory usage low.
/// </summary>
protected bool UseGarbageCollector { get; set; } = true;
protected bool UseGarbageCollector { get; set; } = false;

/// <summary>
/// **Experimental**
Expand Down
33 changes: 33 additions & 0 deletions VinaFrameworkClient/Core/ModuleScript.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using System;
using System.Threading.Tasks;

using Newtonsoft.Json;

using CitizenFX.Core;
using CitizenFX.Core.Native;

namespace VinaFrameworkClient.Core
{
Expand Down Expand Up @@ -103,6 +106,36 @@ public dynamic GetExport(string resourceName)
public void SetExport(string name, Delegate method)
{
Exports.Add(name, method);
Log($"Export {name} set!");
}

/// <summary>
/// Send a message to this resource Nui.
/// </summary>
/// <param name="nuiRequest">The nui request object.</param>
public void SendNuiActionData(NuiRequest nuiRequest)
{
try
{
string serializedQuery = JsonConvert.SerializeObject(nuiRequest, Formatting.Indented);

API.SendNuiMessage(serializedQuery);
}
catch (Exception exception)
{
LogError(exception, " in SendNuiActionData");
}
}

/// <summary>
/// Send a message to this resource Nui.
/// </summary>
/// <param name="action">The action name.</param>
/// <param name="data">Some data will be sent as a string.</param>
public void SendNuiActionData(string action, dynamic data = null)
{
NuiRequest request = new NuiRequest(action, data);
SendNuiActionData(request);
}

/// <summary>
Expand Down
19 changes: 19 additions & 0 deletions VinaFrameworkClient/Shared/NuiRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace VinaFrameworkClient.Core
{
public class NuiRequest
{
public string action { get; set; }
public dynamic data { get; set; }

public NuiRequest() { }
public NuiRequest(string action)
{
this.action = action;
}
public NuiRequest(string action, dynamic data)
{
this.action = action;
this.data = data;
}
}
}
4 changes: 4 additions & 0 deletions VinaFrameworkClient/VinaFrameworkClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
<HintPath>..\..\..\..\FiveM.app\citizen\clr2\lib\mono\4.5\CitizenFX.Core.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>..\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
Expand All @@ -50,6 +53,7 @@
<Compile Include="Core\BaseClient.cs" />
<Compile Include="Core\Module.cs" />
<Compile Include="Core\ModuleScript.cs" />
<Compile Include="Shared\NuiRequest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup />
Expand Down
6 changes: 0 additions & 6 deletions VinaFrameworkServer/Core/BaseServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ public BaseServer()

private void onPlayerConnecting([FromSource] Player player)
{
Log($"PlayerConnecting {player.Name}");

foreach (Module module in modules)
{
try
Expand All @@ -73,8 +71,6 @@ private void onPlayerConnecting([FromSource] Player player)

private void onPlayerDropped([FromSource] Player player, string reason)
{
Log($"PlayerDropped {player.Name}");

foreach (Module module in modules)
{
try
Expand All @@ -90,8 +86,6 @@ private void onPlayerDropped([FromSource] Player player, string reason)

private void onPlayerClientInitialized([FromSource] Player player)
{
Log($"PlayerClientInitialized {player.Name}");

foreach (Module module in modules)
{
try
Expand Down
1 change: 1 addition & 0 deletions VinaFrameworkServer/Core/ModuleScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public dynamic GetExport(string resourceName)
public void SetExport(string name, Delegate method)
{
Exports.Add(name, method);
Log($"Export {name} set!");
}

/// <summary>
Expand Down
7 changes: 7 additions & 0 deletions VinaFrameworkServer/VinaFrameworkServer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
<HintPath>..\..\..\fivem_server\citizen\clr2\lib\mono\4.5\CitizenFX.Core.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
Expand All @@ -47,6 +51,9 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\VinaFrameworkClient\Shared\NuiRequest.cs">
<Link>Shared\NuiRequest.cs</Link>
</Compile>
<Compile Include="Core\Module.cs" />
<Compile Include="Core\BaseServer.cs" />
<Compile Include="Core\ModuleScript.cs" />
Expand Down
7 changes: 7 additions & 0 deletions __resource.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
game 'gta5'
--client_script 'MyClientScript.net.dll'
--server_script 'MyServerScript.net.dll'

files {
"Newtonsoft.Json.dll",
}

0 comments on commit a639da7

Please sign in to comment.