mirror of
https://github.com/sebastian-heinz/Arrowgene.DragonsDogmaOnline
synced 2026-08-03 11:12:41 -04:00
* Suppress some logging for: missing scheduleIds relating to board quests due to rotation; leaving a party that you're not a part of, usually due to leaving the server; Camellia cipher complaining about packet size. * Fix issue with Postgres and rental pawn feedback. * Tweaks to backend BBM behavior; prevent getting certain achievements in BBM. Add /bbminfo command. * More logging tweaks. Don't return dead socket clients in the client lookup? * Fix /godmode. * Implement valuable item recovery for job emblems.
105 lines
3.6 KiB
C#
105 lines
3.6 KiB
C#
using Arrowgene.Ddon.Shared.Entity;
|
|
using Arrowgene.Ddon.Shared.Model;
|
|
using Arrowgene.Ddon.Shared.Network;
|
|
using Arrowgene.Logging;
|
|
using Npgsql;
|
|
using System;
|
|
using System.Data.SQLite;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
namespace Arrowgene.Ddon.Server.Network
|
|
{
|
|
public abstract class RequestPacketHandler<TClient, TReqStruct, TResStruct> : StructurePacketHandler<TClient, TReqStruct>
|
|
where TClient : Client
|
|
where TReqStruct : class, IPacketStructure, new()
|
|
where TResStruct : ServerResponse, new()
|
|
{
|
|
private static readonly ServerLogger Logger = LogProvider.Logger<ServerLogger>(typeof(RequestPacketHandler<TClient, TReqStruct, TResStruct>));
|
|
|
|
protected RequestPacketHandler(DdonServer<TClient> server) : base(server)
|
|
{
|
|
#if DEBUG
|
|
if (!EntitySerializer.Contains(typeof(TResStruct)))
|
|
{
|
|
Logger.Error($"RequestPacketHandler missing serializer for {typeof(TResStruct).Name}");
|
|
}
|
|
#endif
|
|
}
|
|
|
|
public abstract TResStruct Handle(TClient client, TReqStruct request);
|
|
|
|
public sealed override void Handle(TClient client, StructurePacket<TReqStruct> request)
|
|
{
|
|
TResStruct response;
|
|
try
|
|
{
|
|
response = Handle(client, request.Structure);
|
|
}
|
|
catch (SQLiteException ex)
|
|
{
|
|
if (ex.ErrorCode == (int)SQLiteErrorCode.Busy)
|
|
{
|
|
response = new TResStruct
|
|
{
|
|
Error = (uint)ErrorCode.ERROR_CODE_DB_DEAD_LOCK
|
|
};
|
|
}
|
|
else
|
|
{
|
|
response = new TResStruct
|
|
{
|
|
Error = (uint)ErrorCode.ERROR_CODE_DB_FAILURE
|
|
};
|
|
}
|
|
client.Send(response);
|
|
client.Close(); // Do not tolerate SqLiteExceptions because of desync issues.
|
|
throw;
|
|
}
|
|
catch (PostgresException ex)
|
|
{
|
|
response = new TResStruct
|
|
{
|
|
Error = (uint)ErrorCode.ERROR_CODE_DB_FAILURE
|
|
};
|
|
client.Send(response);
|
|
client.Close();
|
|
throw;
|
|
}
|
|
catch (NotImplementedException ex)
|
|
{
|
|
throw new ResponseErrorException(ErrorCode.ERROR_CODE_NOT_IMPLEMENTED, ex.Message, ex);
|
|
}
|
|
catch (ResponseErrorException ex)
|
|
{
|
|
response = new TResStruct();
|
|
response.Error = (uint) ex.ErrorCode;
|
|
|
|
var stringBuilder = new StringBuilder();
|
|
stringBuilder.AppendLine($"{(ex.Critical ? "!!CRITICAL!! " : "")}{ex.ErrorCode} thrown when handling {typeof(TReqStruct).Name}");
|
|
if (ex.Message.Length > 0)
|
|
{
|
|
stringBuilder.AppendLine($"\tMessage: {ex.Message}");
|
|
}
|
|
stringBuilder.AppendLine(ex.StackTrace?.Split(Environment.NewLine).FirstOrDefault());
|
|
Logger.Error(client, stringBuilder.ToString());
|
|
|
|
client.Send(response);
|
|
|
|
if (ex.Critical)
|
|
{
|
|
client.Close();
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
response = new TResStruct();
|
|
response.Error = (uint) ErrorCode.ERROR_CODE_FAIL;
|
|
client.Send(response);
|
|
throw;
|
|
}
|
|
client.Send(response);
|
|
}
|
|
|
|
}
|
|
}
|