Fixed a few issues.

This commit is contained in:
Tom
2025-04-10 17:04:27 +00:00
parent c7904f120d
commit 78b6d4b789
7 changed files with 32 additions and 6 deletions

View File

@@ -23,8 +23,10 @@ namespace HermesSocketServer.Requests
string accessToken = data["access_token"].ToString()!;
string grantType = data["grant_type"].ToString()!;
string scope = data["scope"].ToString()!;
if (!DateTime.TryParse(data["expiration"].ToString()!, out var expiresAt))
if (data["expiration"] == null || !DateTime.TryParse(data["expiration"].ToString(), out var expiresAt))
return Task.FromResult(RequestResult.Failed("Expiration needs to be a date time string."));
var previous = channel.Connections.Get(name);
var connection = new Connection()
{
@@ -36,12 +38,13 @@ namespace HermesSocketServer.Requests
GrantType = grantType,
Scope = scope,
ExpiresAt = expiresAt,
Default = previous?.Default ?? false,
};
bool result = channel.Connections.Set(name, connection);
if (result)
{
_logger.Information($"Added connection to channel [name: {name}][type: {type}][scope: {scope}][expiration: {expiresAt}][channel: {channel.Id}]");
_logger.Information($"Added or updated connection to channel [name: {name}][type: {type}][scope: {scope}][expiration: {expiresAt}][channel: {channel.Id}]");
return Task.FromResult(RequestResult.Successful(connection));
}
return Task.FromResult(RequestResult.Failed("Something went wrong when updating the cache."));

View File

@@ -116,6 +116,7 @@ namespace HermesSocketLibrary
{
await client.Send(9, new SlaveMessage() { Slave = false });
client.Slave = false;
socket.Slave = true;
}
}
}

View File

@@ -31,6 +31,11 @@ namespace HermesSocketServer.Socket.Handlers
{
if (message is not ChatterMessage data || sender.Id == null)
return;
if (sender.Slave && !sender.WebLogin)
{
_logger.Warning($"Received message from a slave client [message type: chatter details][sender id: {sender.Id}][sender session: {sender.SessionId}]");
return;
}
try
{

View File

@@ -32,9 +32,13 @@ namespace HermesSocketServer.Socket.Handlers
{
if (message is not EmoteDetailsMessage data || sender.Id == null)
return;
if (data.Emotes == null || !data.Emotes.Any())
return;
if (sender.Slave && !sender.WebLogin)
{
_logger.Warning($"Received message from a slave client [message type: emote details][sender id: {sender.Id}][sender session: {sender.SessionId}]");
return;
}
try
{

View File

@@ -32,9 +32,15 @@ namespace HermesSocketServer.Socket.Handlers
{
if (message is not EmoteUsageMessage data || sender.Id == null)
return;
if (sender.Slave && !sender.WebLogin)
{
_logger.Warning($"Received message from a slave client [message type: emote usage][sender id: {sender.Id}][sender session: {sender.SessionId}]");
return;
}
try
{
_mutex.WaitOne();
if (_history.Contains(data.MessageId))
{
return;

View File

@@ -53,8 +53,8 @@ namespace HermesSocketServer.Socket.Handlers
return;
sender.Id = userId;
sender.Slave = data.WebLogin || recipients.Where(r => r != null && !r.WebLogin).Any();
recipients = _sockets.GetSockets(userId).ToList().Where(s => s.SessionId != sender.SessionId);
sender.Slave = data.WebLogin || recipients.Where(r => r != null && !r.WebLogin).Any();
sender.ApiKey = data.ApiKey;
sender.WebLogin = data.WebLogin;
@@ -87,6 +87,8 @@ namespace HermesSocketServer.Socket.Handlers
}
var voices = _voices.Get();
var voiceStates = channel.VoiceStates.Get();
var voicesEnabled = voices.Values.Where(v => !voiceStates.TryGetValue(v.Id, out var voice) || voice.Enabled).Select(v => v.Name).ToList();
var ack = new LoginAckMessage()
{
UserId = userId,
@@ -98,8 +100,8 @@ namespace HermesSocketServer.Socket.Handlers
WebLogin = data.WebLogin,
WordFilters = channel.Filters.Get().Values,
DefaultTTSVoice = channel.User.DefaultVoice ?? _configuration.Tts.DefaultTtsVoice,
TTSVoicesAvailable = _voices.Get().ToDictionary(v => v.Key, v => v.Value.Name),
EnabledTTSVoices = channel.VoiceStates.Get().Values.Where(v => v.Enabled && voices.ContainsKey(v.Id)).Select(v => voices[v.Id].Name).ToList(),
TTSVoicesAvailable = voices.ToDictionary(v => v.Key, v => v.Value.Name),
EnabledTTSVoices = voicesEnabled,
Connections = channel.Connections.Get().Values.ToList(),
Slave = sender.Slave,
};

View File

@@ -23,6 +23,11 @@ namespace HermesSocketServer.Socket.Handlers
{
if (message is not RequestMessage data || sender.Id == null)
return;
if (sender.Slave && !sender.WebLogin && !data.Type.StartsWith("get"))
{
_logger.Warning($"Received a non-get request from a slave client [request type: {data.Type}][sender id: {sender.Id}][sender session: {sender.SessionId}]");
return;
}
RequestResult? result = null;
_logger.Debug("Executing request handler: " + data.Type);