From 06bfe110bbc8538a0c217598fca697de42551e0a Mon Sep 17 00:00:00 2001 From: Tom Date: Fri, 27 Dec 2024 22:29:54 +0000 Subject: [PATCH] Fixed multiple issues. --- Requests/DeletePolicy.cs | 14 +++++++++++--- Socket/Handlers/EmoteUsageHandler.cs | 4 +++- Socket/Handlers/HermesLoginHandler.cs | 1 + Store/ChatterStore.cs | 12 ++++++------ Store/VoiceStore.cs | 6 +++--- 5 files changed, 24 insertions(+), 13 deletions(-) diff --git a/Requests/DeletePolicy.cs b/Requests/DeletePolicy.cs index f879261..a7b3726 100644 --- a/Requests/DeletePolicy.cs +++ b/Requests/DeletePolicy.cs @@ -19,9 +19,17 @@ namespace HermesSocketServer.Requests public async Task Grant(string sender, IDictionary? data) { var channel = _channels.Get(sender); - channel.Policies.Remove(data!["id"].ToString()); - _logger.Information($"Deleted a policy by id [policy id: {data["id"]}]"); - return RequestResult.Successful(null); + + string policyId = data!["id"].ToString()!; + var policy = channel.Policies.Get(policyId); + if (policy != null) { + channel.Policies.Remove(policyId); + _logger.Information($"Deleted a policy by id [policy id: {data["id"]}]"); + return RequestResult.Successful(policy.GroupId + "/" + policy.Path); + } + + _logger.Warning("Failed to find policy by id "); + return RequestResult.Failed("Cannot find the policy by id."); } } } \ No newline at end of file diff --git a/Socket/Handlers/EmoteUsageHandler.cs b/Socket/Handlers/EmoteUsageHandler.cs index 3f36b79..dbd9157 100644 --- a/Socket/Handlers/EmoteUsageHandler.cs +++ b/Socket/Handlers/EmoteUsageHandler.cs @@ -13,6 +13,7 @@ namespace HermesSocketServer.Socket.Handlers private readonly HashSet _history; private readonly EmoteUsageMessage[] _array; private readonly ILogger _logger; + private readonly object _lock; private int _index; @@ -22,6 +23,7 @@ namespace HermesSocketServer.Socket.Handlers _logger = logger; _history = new HashSet(101); _array = new EmoteUsageMessage[100]; + _lock = new object(); _index = -1; } @@ -31,7 +33,7 @@ namespace HermesSocketServer.Socket.Handlers if (message is not EmoteUsageMessage data || sender.Id == null) return; - lock (_logger) + lock (_lock) { if (_history.Contains(data.MessageId)) { diff --git a/Socket/Handlers/HermesLoginHandler.cs b/Socket/Handlers/HermesLoginHandler.cs index 319c5f5..8410f65 100644 --- a/Socket/Handlers/HermesLoginHandler.cs +++ b/Socket/Handlers/HermesLoginHandler.cs @@ -77,6 +77,7 @@ namespace HermesSocketServer.Socket.Handlers var ack = new LoginAckMessage() { UserId = userId, + SessionId = sender.UID, OwnerId = _configuration.Tts.OwnerId, Admin = sender.Admin, WebLogin = data.WebLogin, diff --git a/Store/ChatterStore.cs b/Store/ChatterStore.cs index ba890a6..7a5b4bc 100644 --- a/Store/ChatterStore.cs +++ b/Store/ChatterStore.cs @@ -72,9 +72,9 @@ namespace HermesSocketServer.Store count = list.Count; sql = _generator.GeneratePreparedInsertSql("TtsChatVoice", count, ["userId", "chatterId", "ttsVoiceId"]); - _logger.Debug($"User - Adding {count} rows to database: {sql}"); + _logger.Debug($"Chatter - Adding {count} rows to database: {sql}"); var values = list.Select(id => _store[id]).Where(v => v != null); - await _generator.DoPreparedStatement(_database, sql, values, ["id", "name", "email", "role", "ttsDefaultVoice"]); + await _generator.DoPreparedStatement(_database, sql, values, ["userId", "chatterId", "ttsVoiceId"]); } if (_modified.Any()) { @@ -86,9 +86,9 @@ namespace HermesSocketServer.Store count = list.Count; sql = _generator.GeneratePreparedUpdateSql("TtsChatVoice", count, ["userId", "chatterId"], ["ttsVoiceId"]); - _logger.Debug($"User - Modifying {count} rows in database: {sql}"); + _logger.Debug($"Chatter - Modifying {count} rows in database: {sql}"); var values = list.Select(id => _store[id]).Where(v => v != null); - await _generator.DoPreparedStatement(_database, sql, values, ["id", "name", "email", "role", "ttsDefaultVoice"]); + await _generator.DoPreparedStatement(_database, sql, values, ["userId", "chatterId", "ttsVoiceId"]); } if (_deleted.Any()) { @@ -100,8 +100,8 @@ namespace HermesSocketServer.Store count = list.Count; sql = _generator.GeneratePreparedDeleteSql("TtsChatVoice", count, ["userId", "chatterId"]); - _logger.Debug($"User - Deleting {count} rows from database: {sql}"); - await _generator.DoPreparedStatementRaw(_database, sql, list, ["id"]); + _logger.Debug($"Chatter - Deleting {count} rows from database: {sql}"); + await _generator.DoPreparedStatementRaw(_database, sql, list, ["userId", "chatterId"]); } } } diff --git a/Store/VoiceStore.cs b/Store/VoiceStore.cs index 635f52d..ca3efc1 100644 --- a/Store/VoiceStore.cs +++ b/Store/VoiceStore.cs @@ -75,7 +75,7 @@ namespace HermesSocketServer.Store count = list.Count; sql = _generator.GeneratePreparedInsertSql("TtsVoice", count, ["id", "name"]); - _logger.Debug($"User - Adding {count} rows to database: {sql}"); + _logger.Debug($"Voice - Adding {count} rows to database: {sql}"); var values = list.Select(id => _store[id]).Where(v => v != null); await _generator.DoPreparedStatement(_database, sql, values, ["id", "name", "email", "role", "ttsDefaultVoice"]); } @@ -89,7 +89,7 @@ namespace HermesSocketServer.Store count = list.Count; sql = _generator.GeneratePreparedUpdateSql("TtsVoice", count, ["id"], ["name"]); - _logger.Debug($"User - Modifying {count} rows in database: {sql}"); + _logger.Debug($"Voice - Modifying {count} rows in database: {sql}"); var values = list.Select(id => _store[id]).Where(v => v != null); await _generator.DoPreparedStatement(_database, sql, values, ["id", "name", "email", "role", "ttsDefaultVoice"]); } @@ -103,7 +103,7 @@ namespace HermesSocketServer.Store count = list.Count; sql = _generator.GeneratePreparedDeleteSql("TtsVoice", count, ["id"]); - _logger.Debug($"User - Deleting {count} rows from database: {sql}"); + _logger.Debug($"Voice - Deleting {count} rows from database: {sql}"); await _generator.DoPreparedStatementRaw(_database, sql, list, ["id"]); } }