Compare commits
No commits in common. "9f14c69cb652a6a868ea39e839759826dd664282" and "d55ed7719eb311d1647ef2ee9674614a148a90c0" have entirely different histories.
9f14c69cb6
...
d55ed7719e
2
.gitignore
vendored
2
.gitignore
vendored
@ -405,5 +405,3 @@ FodyWeavers.xsd
|
|||||||
|
|
||||||
# Hemtt
|
# Hemtt
|
||||||
.hemttout/
|
.hemttout/
|
||||||
.hemttprivatekey
|
|
||||||
.biprivatekey
|
|
||||||
Binary file not shown.
Binary file not shown.
@ -19,9 +19,13 @@ PREP(listGet);
|
|||||||
PREP(listLoad);
|
PREP(listLoad);
|
||||||
PREP(listRemove);
|
PREP(listRemove);
|
||||||
PREP(listSet);
|
PREP(listSet);
|
||||||
|
PREP(pubSubFetch);
|
||||||
|
PREP(pubSubHandler);
|
||||||
PREP(processQueue);
|
PREP(processQueue);
|
||||||
|
PREP(publish);
|
||||||
PREP(saveDB);
|
PREP(saveDB);
|
||||||
PREP(scheduler);
|
PREP(scheduler);
|
||||||
PREP(set);
|
PREP(set);
|
||||||
PREP(setup);
|
PREP(setup);
|
||||||
|
PREP(subscribe);
|
||||||
PREP(test);
|
PREP(test);
|
||||||
@ -24,7 +24,7 @@ None. The function sets up internal variables and logs initialization informatio
|
|||||||
This function is automatically executed during framework initialization and doesn't need to be called manually.
|
This function is automatically executed during framework initialization and doesn't need to be called manually.
|
||||||
|
|
||||||
## Notes
|
## Notes
|
||||||
- Sets the global buffer size to 20480 bytes (10KB)
|
- Sets the global buffer size to 10240 bytes (10KB)
|
||||||
- Logs the DLL version number for reference
|
- Logs the DLL version number for reference
|
||||||
- Confirms successful loading of all functions
|
- Confirms successful loading of all functions
|
||||||
- Outputs initialization status to the RPT logs
|
- Outputs initialization status to the RPT logs
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@ -5,6 +5,7 @@ namespace ArmaDragonflyClient
|
|||||||
internal class DragonflyDB
|
internal class DragonflyDB
|
||||||
{
|
{
|
||||||
private readonly static DragonflyClient _client = new(Main.ADC_HOST, Main.ADC_PORT, Main.ADC_PASSWORD);
|
private readonly static DragonflyClient _client = new(Main.ADC_HOST, Main.ADC_PORT, Main.ADC_PASSWORD);
|
||||||
|
private static CancellationTokenSource _listenerCts;
|
||||||
|
|
||||||
public static async Task<string> DragonflyRaw(string key, string keyValue, string function = null)
|
public static async Task<string> DragonflyRaw(string key, string keyValue, string function = null)
|
||||||
{
|
{
|
||||||
@ -166,5 +167,76 @@ namespace ArmaDragonflyClient
|
|||||||
string response = await _client.SendCommandAsync("SAVE");
|
string response = await _client.SendCommandAsync("SAVE");
|
||||||
Main.Log($"ArmaDragonflyClient 'SAVE', Response: '{response}'", "debug");
|
Main.Log($"ArmaDragonflyClient 'SAVE', Response: '{response}'", "debug");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static async Task DragonflyPublishAsync(string channel, string message, string uniqueID)
|
||||||
|
{
|
||||||
|
await _client.ConnectAsync();
|
||||||
|
await _client.SendCommandAsync($"PUBLISH {channel} {message}");
|
||||||
|
Main.Log($"ArmaDragonflyClient 'PUBLISH', Channel: '{channel}', Message: '{message}'", "debug");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Task DragonflySubscribeAsync(string channel, string eventType, string eventName, string uniqueID, string target = null, int bufferSize = Main.ADC_BUFFERSIZE)
|
||||||
|
{
|
||||||
|
await _client.ConnectAsync();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await _client.SendCommandAsync($"SUBSCRIBE {channel}");
|
||||||
|
Main.Log($"ArmaDragonflyClient 'SUBSCRIBE', Channel: '{channel}'", "debug");
|
||||||
|
|
||||||
|
_listenerCts = new CancellationTokenSource();
|
||||||
|
|
||||||
|
await Task.Run(async () =>
|
||||||
|
{
|
||||||
|
await StartMessageListener(message => {
|
||||||
|
Utils.CheckByteCountPubSub(uniqueID, message, eventType, eventName, target, bufferSize);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Main.Log($"ArmaDragonflyClient 'SUBSCRIBE', Exception: '{ex.Message}'", "error");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static async Task StartMessageListener(Action<string> messageHandler)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
while (!_listenerCts.Token.IsCancellationRequested)
|
||||||
|
{
|
||||||
|
string response = await _client.ReceiveMessageAsync();
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(response))
|
||||||
|
{
|
||||||
|
var messageParts = response.Split(',');
|
||||||
|
if (messageParts.Length >= 3)
|
||||||
|
{
|
||||||
|
string messageType = messageParts[0];
|
||||||
|
string channel = messageParts[1];
|
||||||
|
string message = messageParts[2];
|
||||||
|
|
||||||
|
Main.Log($"ArmaDragonflyClient 'SUBSCRIBE', Channel: '{channel}', Message: '{message}'", "debug");
|
||||||
|
messageHandler(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await Task.Delay(10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Main.Log($"ArmaDragonflyClient 'SUBSCRIBE', Exception: '{ex.Message}'", "error");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void StopMessageListener()
|
||||||
|
{
|
||||||
|
_listenerCts.Cancel();
|
||||||
|
_listenerCts.Dispose();
|
||||||
|
_listenerCts = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -18,7 +18,7 @@ namespace ArmaDragonflyClient
|
|||||||
public class Main
|
public class Main
|
||||||
{
|
{
|
||||||
private const string ADC_VERSION = "1.0.0";
|
private const string ADC_VERSION = "1.0.0";
|
||||||
public const int ADC_BUFFERSIZE = 20480;
|
public const int ADC_BUFFERSIZE = 10240;
|
||||||
public static string ADC_HOST {get; private set; } = "127.0.0.1";
|
public static string ADC_HOST {get; private set; } = "127.0.0.1";
|
||||||
public static int ADC_PORT {get; private set; } = 6379;
|
public static int ADC_PORT {get; private set; } = 6379;
|
||||||
public static string ADC_PASSWORD {get; private set; } = "xyz123";
|
public static string ADC_PASSWORD {get; private set; } = "xyz123";
|
||||||
@ -276,6 +276,14 @@ namespace ArmaDragonflyClient
|
|||||||
HandleHDelIdOperation(argsArr);
|
HandleHDelIdOperation(argsArr);
|
||||||
WriteOutput(output, "Async");
|
WriteOutput(output, "Async");
|
||||||
return 200;
|
return 200;
|
||||||
|
case "publish":
|
||||||
|
HandlePublishOperation(_id, argsArr);
|
||||||
|
WriteOutput(output, $"[\"{_id}_publish\"]");
|
||||||
|
return 100;
|
||||||
|
case "subscribe":
|
||||||
|
HandleSubscribeOperation(_id, argsArr, argc);
|
||||||
|
WriteOutput(output, $"[\"{_id}_subscribe\"]");
|
||||||
|
return 100;
|
||||||
case "savedb":
|
case "savedb":
|
||||||
HandleSaveDBOperation();
|
HandleSaveDBOperation();
|
||||||
WriteOutput(output, "Async");
|
WriteOutput(output, "Async");
|
||||||
@ -615,5 +623,31 @@ namespace ArmaDragonflyClient
|
|||||||
|
|
||||||
Log($"DragonflyDB connection settings updated - Host: '{host}', Port: '{port}', Password: '{password}'", "action");
|
Log($"DragonflyDB connection settings updated - Host: '{host}', Port: '{port}', Password: '{password}'", "action");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void HandlePublishOperation(long _id, List<string> argsArr)
|
||||||
|
{
|
||||||
|
Task.Run(async () =>
|
||||||
|
{
|
||||||
|
string _uniqueID = $"{_id}_publish";
|
||||||
|
await DragonflyDB.DragonflyPublishAsync(argsArr[0].Trim('"'), argsArr[1].Trim('"'), _uniqueID);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void HandleSubscribeOperation(long _id, List<string> argsArr, int argsCnt)
|
||||||
|
{
|
||||||
|
Task.Run(async () =>
|
||||||
|
{
|
||||||
|
string _uniqueID = $"{_id}_subscribe";
|
||||||
|
switch (argsCnt)
|
||||||
|
{
|
||||||
|
case 3:
|
||||||
|
await DragonflyDB.DragonflySubscribeAsync(argsArr[0].Trim('"'), argsArr[1].Trim('"'), argsArr[2].Trim('"'), _uniqueID);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
await DragonflyDB.DragonflySubscribeAsync(argsArr[0].Trim('"'), argsArr[1].Trim('"'), argsArr[2].Trim('"'), _uniqueID, argsArr[3].Trim('"'));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -78,5 +78,40 @@ namespace ArmaDragonflyClient
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void CheckByteCountPubSub(string uniqueId, string data, string eventType, string eventName, string target, int bufferSize)
|
||||||
|
{
|
||||||
|
if (Encoding.UTF8.GetByteCount(data) <= bufferSize)
|
||||||
|
{
|
||||||
|
if (!data.StartsWith('['))
|
||||||
|
data = BuildArray(data);
|
||||||
|
|
||||||
|
Main.Log($"Single chunk data: {data}", "debug");
|
||||||
|
|
||||||
|
string dataAsString = $"[\"{uniqueId}\",\"{eventType}\",\"{eventName}\",{data},\"{target}\"]";
|
||||||
|
|
||||||
|
Main.Log($"Single chunk data: {dataAsString}", "debug");
|
||||||
|
Main.Callback("ArmaDragonflyClient", "dragonfly_db_fnc_pubSubHandler", dataAsString);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!data.StartsWith('['))
|
||||||
|
data = BuildArray(data);
|
||||||
|
|
||||||
|
Main.Log($"Single chunk data: {data}", "debug");
|
||||||
|
|
||||||
|
var chunks = SplitIntoChunks(data, bufferSize);
|
||||||
|
int totalChunks = chunks.Count;
|
||||||
|
|
||||||
|
for (int chunkIndex = 0; chunkIndex < chunks.Count; chunkIndex++)
|
||||||
|
{
|
||||||
|
string escapedChunkData = chunks[chunkIndex].Replace("\"", "\"\"");
|
||||||
|
string chunkAsString = $"[\"{uniqueId}\",\"{eventType}\",\"{eventName}\",{chunkIndex+1},{totalChunks},\"{escapedChunkData}\",\"{target}\"]";
|
||||||
|
|
||||||
|
Main.Log($"Chunk {chunkIndex+1}/{totalChunks}: {chunkAsString}", "debug");
|
||||||
|
Main.Callback("ArmaDragonflyClient", "dragonfly_db_fnc_pubSubFetch", chunkAsString);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
31
mission/init.sqf
Normal file
31
mission/init.sqf
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
writeLog = {
|
||||||
|
diag_log format ["[ArmaExtensionDotNet] LOG: %1", _this];
|
||||||
|
};
|
||||||
|
|
||||||
|
execSqf = {
|
||||||
|
_this spawn {
|
||||||
|
"ArmaExtensionDotNet" callExtension ["sendResponse", [call compile _this]];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
addMissionEventHandler [
|
||||||
|
"ExtensionCallback",
|
||||||
|
{
|
||||||
|
params ["_name", "_function", "_data"];
|
||||||
|
|
||||||
|
diag_log format["ExtensionCallback - name: '%1', function: '%2', data: '%3'", _name, _function, _data];
|
||||||
|
|
||||||
|
if (_name isEqualTo "ArmaExtensionDotNet") then {
|
||||||
|
_func = missionNamespace getVariable [_function, objNull];
|
||||||
|
|
||||||
|
if (_func isEqualTo objNull) then {
|
||||||
|
hint "Function does not exist!";
|
||||||
|
} else {
|
||||||
|
_data call _func;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
_result = "ArmaExtensionDotNet" callExtension "runSqfTest";
|
||||||
|
systemChat _result;
|
||||||
Loading…
x
Reference in New Issue
Block a user