Commit remaining changes

This commit is contained in:
Jacob Schmidt 2026-01-13 20:20:28 -06:00
parent d6f9923eb5
commit d7138d4f1f
26 changed files with 21 additions and 195 deletions

2
.gitignore vendored
View File

@ -405,3 +405,5 @@ FodyWeavers.xsd
# Hemtt # Hemtt
.hemttout/ .hemttout/
.hemttprivatekey
.biprivatekey

Binary file not shown.

Binary file not shown.

View File

@ -19,13 +19,9 @@ 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);

View File

@ -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 10240 bytes (10KB) - Sets the global buffer size to 20480 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

View File

@ -5,7 +5,6 @@ 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)
{ {
@ -167,76 +166,5 @@ 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;
}
} }
} }

View File

@ -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 = 10240; public const int ADC_BUFFERSIZE = 20480;
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,14 +276,6 @@ 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");
@ -623,31 +615,5 @@ 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;
}
});
}
} }
} }

View File

@ -78,40 +78,5 @@ 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);
}
}
}
} }
} }

View File

@ -1,31 +0,0 @@
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;