Fixed emote duplicate issue. Improved chatter tracking. Used stores in Login Handler in cases where databases was used instead.

This commit is contained in:
Tom
2025-03-07 17:34:27 +00:00
parent fd0bca5c7c
commit 4d0743c4aa
4 changed files with 64 additions and 69 deletions

View File

@@ -7,18 +7,25 @@ namespace HermesSocketServer.Socket.Handlers
{
public class EmoteDetailsHandler : ISocketHandler
{
private const int EMOTE_BUFFER_SIZE = 5000;
public int OperationCode { get; } = 7;
private readonly Database _database;
private readonly HashSet<string> _emotes;
private readonly string[] _array;
private readonly ILogger _logger;
private readonly object _lock;
private int _index;
public EmoteDetailsHandler(Database database, ILogger logger)
{
_database = database;
_emotes = new HashSet<string>(EMOTE_BUFFER_SIZE);
_array = new string[EMOTE_BUFFER_SIZE];
_logger = logger;
_emotes = new HashSet<string>(501);
_lock = new object();
_index = -1;
}
public async Task Execute<T>(WebSocketUser sender, T message, HermesSocketManager sockets)
@@ -40,6 +47,16 @@ namespace HermesSocketServer.Socket.Handlers
}
_emotes.Add(entry.Key);
if (_index == _array.Length - 1)
_index = -1;
var previous = _array[++_index];
if (previous != null)
{
_emotes.Remove(previous);
}
_array[_index] = entry.Key;
}
}
@@ -47,7 +64,7 @@ namespace HermesSocketServer.Socket.Handlers
return;
int rows = 0;
string sql = "INSERT INTO \"Emote\" (id, name) VALUES (@idd, @name)";
string sql = "INSERT INTO \"Emote\" (id, name) VALUES (@idd, @name) ON CONFLICT (id) DO UPDATE SET name = @name;";
using (var connection = await _database.DataSource.OpenConnectionAsync())
{
using (var command = new NpgsqlCommand(sql, connection))