* feat(g1): version central translator source code * feat(g1): version central translator source code * feat(g1): version central translator source code * feat(g1): version central translator source code * feat(g1): add centralized translation service and schema * feat(g1): add centralized translation service and schema * feat(g1): add centralized translation service and schema * feat(g1): add centralized translation service and schema * feat(g1): track centralized update service and operations docs * feat(g1): track centralized update service and operations docs * feat(g1): track centralized update service and operations docs * feat(g1): track centralized update service and operations docs * build(g1): reproducible sanitized binary release candidate and main/EventSim parity manifest * build(g1): reproducible sanitized binary release candidate and main/EventSim parity manifest
64 lines
2.6 KiB
C#
64 lines
2.6 KiB
C#
// SPDX-License-Identifier: LicenseRef-OpenGenesisLINK-EULA
|
|
using log4net;
|
|
using Mono.Addins;
|
|
using Nini.Config;
|
|
using OpenMetaverse;
|
|
using OpenSim.Framework;
|
|
using OpenSim.Region.CoreModules.Avatar.InstantMessage;
|
|
|
|
namespace OpenGenesisLINK.Addons.UniversalTranslator;
|
|
|
|
/// <summary>
|
|
/// Direct person-to-person IM translation before the existing grid transfer
|
|
/// module; offline IM processing and all system/group dialogs remain untouched.
|
|
/// </summary>
|
|
[Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "OglTranslatedInstantMessageModule")]
|
|
public sealed class OglTranslatedInstantMessageModule : InstantMessageModule
|
|
{
|
|
private static readonly ILog Log = LogManager.GetLogger(typeof(OglTranslatedInstantMessageModule));
|
|
private readonly TranslatorRuntime _runtime = TranslatorRuntime.Shared;
|
|
public override string Name => "OglTranslatedInstantMessageModule";
|
|
|
|
public override void Initialise(IConfigSource source)
|
|
{
|
|
_runtime.Configure(source);
|
|
m_enabled = source.Configs["OglUniversalTranslator"]?.GetBoolean("Enabled", false) == true;
|
|
if (m_enabled)
|
|
Log.Info("[OGL TRANSLATOR] Direct IM translation module enabled (bilateral opt-in).");
|
|
}
|
|
|
|
public override void OnInstantMessage(IClientAPI? client, GridInstantMessage im)
|
|
{
|
|
if (client is null || im is null || im.fromGroup ||
|
|
im.dialog != (byte)InstantMessageDialog.MessageFromAgent ||
|
|
client.AgentId.Guid != im.fromAgentID ||
|
|
!_runtime.Eligible(new UUID(im.fromAgentID), new UUID(im.toAgentID),
|
|
im.message, true, out string sourceLanguage, out string targetLanguage))
|
|
{
|
|
base.OnInstantMessage(client!, im);
|
|
return;
|
|
}
|
|
|
|
// Clone before async work: caller may reuse/mutate the original message.
|
|
GridInstantMessage outgoing = new(im, false);
|
|
outgoing.timestamp = im.timestamp;
|
|
_ = Task.Run(async () =>
|
|
{
|
|
try
|
|
{
|
|
outgoing.message = await _runtime.TranslateAsync(im.message,
|
|
new UUID(im.fromAgentID),new UUID(im.toAgentID),true).ConfigureAwait(false);
|
|
base.OnInstantMessage(client, outgoing);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Log.Warn("[OGL TRANSLATOR] IM translation failed, sending original: " + e.GetType().Name);
|
|
try { base.OnInstantMessage(client, im); }
|
|
catch (Exception sendError)
|
|
{
|
|
Log.Error("[OGL TRANSLATOR] Original IM delivery failed", sendError);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
} |