Added error message to request acks.

This commit is contained in:
Tom 2024-12-27 23:33:13 +00:00
parent 8277ea0154
commit 21cb5c9453
2 changed files with 15 additions and 12 deletions

View File

@ -78,20 +78,22 @@ namespace HermesSocketLibrary
await socket.Send(5, new LoggingMessage("Received no data in the message.", HermesLoggingLevel.Warn)); await socket.Send(5, new LoggingMessage("Received no data in the message.", HermesLoggingLevel.Warn));
continue; continue;
} }
else if (obj.OpCode == 0)
obj.Data = JsonSerializer.Deserialize<HeartbeatMessage>(obj.Data.ToString(), _options); string data = obj.Data.ToString()!;
if (obj.OpCode == 0)
obj.Data = JsonSerializer.Deserialize<HeartbeatMessage>(data, _options);
else if (obj.OpCode == 1) else if (obj.OpCode == 1)
obj.Data = JsonSerializer.Deserialize<HermesLoginMessage>(obj.Data.ToString(), _options); obj.Data = JsonSerializer.Deserialize<HermesLoginMessage>(data, _options);
else if (obj.OpCode == 3) else if (obj.OpCode == 3)
obj.Data = JsonSerializer.Deserialize<RequestMessage>(obj.Data.ToString(), _options); obj.Data = JsonSerializer.Deserialize<RequestMessage>(data, _options);
else if (obj.OpCode == 5) else if (obj.OpCode == 5)
obj.Data = JsonSerializer.Deserialize<LoggingMessage>(obj.Data.ToString(), _options); obj.Data = JsonSerializer.Deserialize<LoggingMessage>(data, _options);
else if (obj.OpCode == 6) else if (obj.OpCode == 6)
obj.Data = JsonSerializer.Deserialize<ChatterMessage>(obj.Data.ToString(), _options); obj.Data = JsonSerializer.Deserialize<ChatterMessage>(data, _options);
else if (obj.OpCode == 7) else if (obj.OpCode == 7)
obj.Data = JsonSerializer.Deserialize<EmoteDetailsMessage>(obj.Data.ToString(), _options); obj.Data = JsonSerializer.Deserialize<EmoteDetailsMessage>(data, _options);
else if (obj.OpCode == 8) else if (obj.OpCode == 8)
obj.Data = JsonSerializer.Deserialize<EmoteUsageMessage>(obj.Data.ToString(), _options); obj.Data = JsonSerializer.Deserialize<EmoteUsageMessage>(data, _options);
else else
{ {
await socket.Send(5, new LoggingMessage("Received an invalid message: " + message, HermesLoggingLevel.Error)); await socket.Send(5, new LoggingMessage("Received an invalid message: " + message, HermesLoggingLevel.Error));

View File

@ -35,17 +35,18 @@ namespace HermesSocketServer.Socket.Handlers
_logger.Error(e, $"Failed to grant a request of type '{data.Type}'."); _logger.Error(e, $"Failed to grant a request of type '{data.Type}'.");
} }
if (result == null || !result.Success) if (result == null)
return; return;
var ack = new RequestAckMessage() var ack = new RequestAckMessage()
{ {
Request = data, Request = data,
Data = result.Result, Data = result.Success ? result.Result : null,
Nounce = data.Nounce Nounce = data.Nounce,
Error = result.Success ? null : result.Result?.ToString()
}; };
if (!result.NotifyClientsOnAccount) if (!result.NotifyClientsOnAccount || !result.Success)
{ {
await sender.Send(4, ack); await sender.Send(4, ack);
return; return;