Fixed multiple issues.

This commit is contained in:
Tom 2024-12-27 22:29:54 +00:00
parent 6176e6f3b9
commit 06bfe110bb
5 changed files with 24 additions and 13 deletions

View File

@ -19,9 +19,17 @@ namespace HermesSocketServer.Requests
public async Task<RequestResult> Grant(string sender, IDictionary<string, object>? data) public async Task<RequestResult> Grant(string sender, IDictionary<string, object>? data)
{ {
var channel = _channels.Get(sender); var channel = _channels.Get(sender);
channel.Policies.Remove(data!["id"].ToString());
_logger.Information($"Deleted a policy by id [policy id: {data["id"]}]"); string policyId = data!["id"].ToString()!;
return RequestResult.Successful(null); 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.");
} }
} }
} }

View File

@ -13,6 +13,7 @@ namespace HermesSocketServer.Socket.Handlers
private readonly HashSet<string> _history; private readonly HashSet<string> _history;
private readonly EmoteUsageMessage[] _array; private readonly EmoteUsageMessage[] _array;
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly object _lock;
private int _index; private int _index;
@ -22,6 +23,7 @@ namespace HermesSocketServer.Socket.Handlers
_logger = logger; _logger = logger;
_history = new HashSet<string>(101); _history = new HashSet<string>(101);
_array = new EmoteUsageMessage[100]; _array = new EmoteUsageMessage[100];
_lock = new object();
_index = -1; _index = -1;
} }
@ -31,7 +33,7 @@ namespace HermesSocketServer.Socket.Handlers
if (message is not EmoteUsageMessage data || sender.Id == null) if (message is not EmoteUsageMessage data || sender.Id == null)
return; return;
lock (_logger) lock (_lock)
{ {
if (_history.Contains(data.MessageId)) if (_history.Contains(data.MessageId))
{ {

View File

@ -77,6 +77,7 @@ namespace HermesSocketServer.Socket.Handlers
var ack = new LoginAckMessage() var ack = new LoginAckMessage()
{ {
UserId = userId, UserId = userId,
SessionId = sender.UID,
OwnerId = _configuration.Tts.OwnerId, OwnerId = _configuration.Tts.OwnerId,
Admin = sender.Admin, Admin = sender.Admin,
WebLogin = data.WebLogin, WebLogin = data.WebLogin,

View File

@ -72,9 +72,9 @@ namespace HermesSocketServer.Store
count = list.Count; count = list.Count;
sql = _generator.GeneratePreparedInsertSql("TtsChatVoice", count, ["userId", "chatterId", "ttsVoiceId"]); 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); 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()) if (_modified.Any())
{ {
@ -86,9 +86,9 @@ namespace HermesSocketServer.Store
count = list.Count; count = list.Count;
sql = _generator.GeneratePreparedUpdateSql("TtsChatVoice", count, ["userId", "chatterId"], ["ttsVoiceId"]); 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); 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()) if (_deleted.Any())
{ {
@ -100,8 +100,8 @@ namespace HermesSocketServer.Store
count = list.Count; count = list.Count;
sql = _generator.GeneratePreparedDeleteSql("TtsChatVoice", count, ["userId", "chatterId"]); sql = _generator.GeneratePreparedDeleteSql("TtsChatVoice", count, ["userId", "chatterId"]);
_logger.Debug($"User - Deleting {count} rows from database: {sql}"); _logger.Debug($"Chatter - Deleting {count} rows from database: {sql}");
await _generator.DoPreparedStatementRaw(_database, sql, list, ["id"]); await _generator.DoPreparedStatementRaw(_database, sql, list, ["userId", "chatterId"]);
} }
} }
} }

View File

@ -75,7 +75,7 @@ namespace HermesSocketServer.Store
count = list.Count; count = list.Count;
sql = _generator.GeneratePreparedInsertSql("TtsVoice", count, ["id", "name"]); 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); 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, ["id", "name", "email", "role", "ttsDefaultVoice"]);
} }
@ -89,7 +89,7 @@ namespace HermesSocketServer.Store
count = list.Count; count = list.Count;
sql = _generator.GeneratePreparedUpdateSql("TtsVoice", count, ["id"], ["name"]); 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); 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, ["id", "name", "email", "role", "ttsDefaultVoice"]);
} }
@ -103,7 +103,7 @@ namespace HermesSocketServer.Store
count = list.Count; count = list.Count;
sql = _generator.GeneratePreparedDeleteSql("TtsVoice", count, ["id"]); 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"]); await _generator.DoPreparedStatementRaw(_database, sql, list, ["id"]);
} }
} }