Fixed a few issues.
This commit is contained in:
@@ -23,8 +23,10 @@ namespace HermesSocketServer.Requests
|
|||||||
string accessToken = data["access_token"].ToString()!;
|
string accessToken = data["access_token"].ToString()!;
|
||||||
string grantType = data["grant_type"].ToString()!;
|
string grantType = data["grant_type"].ToString()!;
|
||||||
string scope = data["scope"].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."));
|
return Task.FromResult(RequestResult.Failed("Expiration needs to be a date time string."));
|
||||||
|
|
||||||
|
var previous = channel.Connections.Get(name);
|
||||||
|
|
||||||
var connection = new Connection()
|
var connection = new Connection()
|
||||||
{
|
{
|
||||||
@@ -36,12 +38,13 @@ namespace HermesSocketServer.Requests
|
|||||||
GrantType = grantType,
|
GrantType = grantType,
|
||||||
Scope = scope,
|
Scope = scope,
|
||||||
ExpiresAt = expiresAt,
|
ExpiresAt = expiresAt,
|
||||||
|
Default = previous?.Default ?? false,
|
||||||
};
|
};
|
||||||
|
|
||||||
bool result = channel.Connections.Set(name, connection);
|
bool result = channel.Connections.Set(name, connection);
|
||||||
if (result)
|
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.Successful(connection));
|
||||||
}
|
}
|
||||||
return Task.FromResult(RequestResult.Failed("Something went wrong when updating the cache."));
|
return Task.FromResult(RequestResult.Failed("Something went wrong when updating the cache."));
|
||||||
|
|||||||
@@ -116,6 +116,7 @@ namespace HermesSocketLibrary
|
|||||||
{
|
{
|
||||||
await client.Send(9, new SlaveMessage() { Slave = false });
|
await client.Send(9, new SlaveMessage() { Slave = false });
|
||||||
client.Slave = false;
|
client.Slave = false;
|
||||||
|
socket.Slave = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,11 @@ namespace HermesSocketServer.Socket.Handlers
|
|||||||
{
|
{
|
||||||
if (message is not ChatterMessage data || sender.Id == null)
|
if (message is not ChatterMessage data || sender.Id == null)
|
||||||
return;
|
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
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -32,9 +32,13 @@ namespace HermesSocketServer.Socket.Handlers
|
|||||||
{
|
{
|
||||||
if (message is not EmoteDetailsMessage data || sender.Id == null)
|
if (message is not EmoteDetailsMessage data || sender.Id == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (data.Emotes == null || !data.Emotes.Any())
|
if (data.Emotes == null || !data.Emotes.Any())
|
||||||
return;
|
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
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -32,9 +32,15 @@ namespace HermesSocketServer.Socket.Handlers
|
|||||||
{
|
{
|
||||||
if (message is not EmoteUsageMessage data || sender.Id == null)
|
if (message is not EmoteUsageMessage data || sender.Id == null)
|
||||||
return;
|
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
|
try
|
||||||
{
|
{
|
||||||
|
_mutex.WaitOne();
|
||||||
if (_history.Contains(data.MessageId))
|
if (_history.Contains(data.MessageId))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -53,8 +53,8 @@ namespace HermesSocketServer.Socket.Handlers
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
sender.Id = userId;
|
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);
|
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.ApiKey = data.ApiKey;
|
||||||
sender.WebLogin = data.WebLogin;
|
sender.WebLogin = data.WebLogin;
|
||||||
@@ -87,6 +87,8 @@ namespace HermesSocketServer.Socket.Handlers
|
|||||||
}
|
}
|
||||||
|
|
||||||
var voices = _voices.Get();
|
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()
|
var ack = new LoginAckMessage()
|
||||||
{
|
{
|
||||||
UserId = userId,
|
UserId = userId,
|
||||||
@@ -98,8 +100,8 @@ namespace HermesSocketServer.Socket.Handlers
|
|||||||
WebLogin = data.WebLogin,
|
WebLogin = data.WebLogin,
|
||||||
WordFilters = channel.Filters.Get().Values,
|
WordFilters = channel.Filters.Get().Values,
|
||||||
DefaultTTSVoice = channel.User.DefaultVoice ?? _configuration.Tts.DefaultTtsVoice,
|
DefaultTTSVoice = channel.User.DefaultVoice ?? _configuration.Tts.DefaultTtsVoice,
|
||||||
TTSVoicesAvailable = _voices.Get().ToDictionary(v => v.Key, v => v.Value.Name),
|
TTSVoicesAvailable = voices.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(),
|
EnabledTTSVoices = voicesEnabled,
|
||||||
Connections = channel.Connections.Get().Values.ToList(),
|
Connections = channel.Connections.Get().Values.ToList(),
|
||||||
Slave = sender.Slave,
|
Slave = sender.Slave,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -23,6 +23,11 @@ namespace HermesSocketServer.Socket.Handlers
|
|||||||
{
|
{
|
||||||
if (message is not RequestMessage data || sender.Id == null)
|
if (message is not RequestMessage data || sender.Id == null)
|
||||||
return;
|
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;
|
RequestResult? result = null;
|
||||||
_logger.Debug("Executing request handler: " + data.Type);
|
_logger.Debug("Executing request handler: " + data.Type);
|
||||||
|
|||||||
Reference in New Issue
Block a user