2024-03-04 13:19:32 +00:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using Supercell.GUT.Logic.Message.Account;
|
2024-03-06 15:00:12 +00:00
|
|
|
|
using Supercell.GUT.Server.Database.Document;
|
|
|
|
|
using Supercell.GUT.Server.Document;
|
2024-03-04 13:19:32 +00:00
|
|
|
|
using Supercell.GUT.Server.Network.Connection;
|
|
|
|
|
using Supercell.GUT.Server.Protocol.Attributes;
|
|
|
|
|
|
|
|
|
|
namespace Supercell.GUT.Server.Protocol.Handlers;
|
|
|
|
|
|
|
|
|
|
[ServiceNode(1)]
|
|
|
|
|
internal class AccountMessageHandler : MessageHandlerBase
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
private readonly ClientConnection _connection;
|
2024-03-06 15:00:12 +00:00
|
|
|
|
private readonly DocumentManager _documentManager;
|
2024-03-04 13:19:32 +00:00
|
|
|
|
|
2024-03-06 15:00:12 +00:00
|
|
|
|
public AccountMessageHandler(ClientConnection connection, ILogger<AccountMessageHandler> logger, DocumentManager documentManager)
|
2024-03-04 13:19:32 +00:00
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_connection = connection;
|
2024-03-06 15:00:12 +00:00
|
|
|
|
_documentManager = documentManager;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[MessageHandler(10108)]
|
|
|
|
|
public async Task OnKeepAlive(KeepAliveMessage keepAliveMessage)
|
|
|
|
|
{
|
|
|
|
|
await Task.CompletedTask;
|
2024-03-04 13:19:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[MessageHandler(10105)]
|
|
|
|
|
public async Task OnStartSecureConnection(StartSecureConnectionMessage startSecureConnectionMessage)
|
|
|
|
|
{
|
|
|
|
|
string nonce = "nonce";
|
|
|
|
|
|
|
|
|
|
await _connection.SendMessage(new SecureConnectionOkMessage()
|
|
|
|
|
{
|
|
|
|
|
Nonce = nonce
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
_connection.SetNonce(nonce);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[MessageHandler(10103)]
|
|
|
|
|
public async Task OnCreateAccount(CreateAccountMessage createAccountMessage)
|
|
|
|
|
{
|
2024-03-06 15:00:12 +00:00
|
|
|
|
await _documentManager.CreateAccount();
|
|
|
|
|
|
|
|
|
|
AccountDocument? accountDocument = _documentManager.AccountDocument;
|
|
|
|
|
if (accountDocument == null)
|
|
|
|
|
{
|
|
|
|
|
await _connection.SendMessage(new CreateAccountFailedMessage()
|
|
|
|
|
{
|
|
|
|
|
ErrorCode = 1
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-03-04 13:19:32 +00:00
|
|
|
|
|
|
|
|
|
await _connection.SendMessage(new CreateAccountOkMessage()
|
|
|
|
|
{
|
2024-03-06 15:00:12 +00:00
|
|
|
|
AccountIdHigherInt = accountDocument.DocumentId.HigherInt,
|
|
|
|
|
AccountIdLowerInt = accountDocument.DocumentId.LowerInt,
|
|
|
|
|
SessionKey = accountDocument.SessionKey
|
2024-03-05 10:37:18 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[MessageHandler(10102)]
|
|
|
|
|
public async Task OnLoginUsingSession(LoginUsingSessionMessage loginUsingSessionMessage)
|
|
|
|
|
{
|
2024-03-06 15:00:12 +00:00
|
|
|
|
if (_documentManager.Id.LowerInt == 0)
|
|
|
|
|
_documentManager.SetDocumentId(new (loginUsingSessionMessage.AccountIdHigherInt, loginUsingSessionMessage.AccountIdLowerInt));
|
|
|
|
|
|
|
|
|
|
await _documentManager.EnsureAccountDocument();
|
|
|
|
|
|
|
|
|
|
AccountDocument? accountDocument = _documentManager.AccountDocument;
|
|
|
|
|
if (accountDocument == null)
|
|
|
|
|
{
|
|
|
|
|
await _connection.SendMessage(new LoginFailedMessage()
|
|
|
|
|
{
|
|
|
|
|
ErrorCode = 2
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else if (accountDocument.SessionKey != loginUsingSessionMessage.SessionKey)
|
|
|
|
|
{
|
|
|
|
|
await _connection.SendMessage(new LoginFailedMessage()
|
|
|
|
|
{
|
|
|
|
|
ErrorCode = 5
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-03-05 10:37:18 +00:00
|
|
|
|
|
|
|
|
|
await _connection.SendMessage(new LoginOkMessage()
|
|
|
|
|
{
|
2024-03-06 15:00:12 +00:00
|
|
|
|
PrimaryAvatarIdHigherInt = accountDocument.DocumentId.HigherInt,
|
|
|
|
|
PrimaryAvatarIdLowerInt = accountDocument.DocumentId.LowerInt,
|
2024-03-05 10:37:18 +00:00
|
|
|
|
|
|
|
|
|
Fingerprint = "fece25cfc941db1a5bb3e79d4e6a60c34659f49e"
|
2024-03-04 13:19:32 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|