TigerEmu/Communication/Messages/Incoming/Handshake/SsoTicketMessageEvent.cs

61 lines
2.3 KiB
C#
Raw Normal View History

using Microsoft.Extensions.Logging;
2023-09-23 11:11:07 +00:00
using Tiger.Communication.Messages.Interfaces;
using Tiger.Communication.Messages.Outgoing.Notifications;
using Tiger.Communication.Messages.Outgoing.Security;
2023-09-23 11:11:07 +00:00
using Tiger.Communication.Messages.Types;
using Tiger.Game.Achievements;
2023-09-23 11:11:07 +00:00
using Tiger.Game.Habbos;
using Tiger.Game.Settings;
using Tiger.Networking.Game.Sessions;
2023-09-23 12:20:45 +00:00
using Tiger.Storage;
2023-09-23 11:11:07 +00:00
namespace Tiger.Communication.Messages.Incoming.Handshake;
public class SsoTicketMessageEvent : IMessageEvent
2023-09-23 11:11:07 +00:00
{
2023-09-23 12:20:45 +00:00
private readonly IRepository<Habbo> _habboRepository;
2023-09-23 11:11:07 +00:00
private readonly IGameSessionManager _gameSessionManager;
2023-09-23 12:20:45 +00:00
private readonly ISettingManager _settingManager;
private readonly ILogger<SsoTicketMessageEvent> _logger;
private readonly IAchievementManager _achievementManager;
2023-09-23 11:11:07 +00:00
public SsoTicketMessageEvent(IRepository<Habbo> habboRepository, IGameSessionManager gameSessionManager, ISettingManager settingManager, ILogger<SsoTicketMessageEvent> logger, IAchievementManager achievementManager)
2023-09-23 11:11:07 +00:00
{
2023-09-23 12:20:45 +00:00
_habboRepository = habboRepository;
2023-09-23 11:11:07 +00:00
_gameSessionManager = gameSessionManager;
2023-09-23 12:20:45 +00:00
_settingManager = settingManager;
_logger = logger;
_achievementManager = achievementManager;
2023-09-23 11:11:07 +00:00
}
public IncomingHeaders Header => IncomingHeaders.SecurityTicket;
2023-09-23 11:11:07 +00:00
public async Task HandleAsync(GameSession gameSession, ClientMessage request)
{
var habbo = await _habboRepository.FindOneByAsync(h => h.SsoTicket == request.ReadString());
2023-09-23 11:11:07 +00:00
if (habbo == null)
{
await _gameSessionManager.CloseAsync("User not found", gameSession);
return;
}
gameSession.Habbo = habbo;
gameSession.Habbo.LastLogin = DateTime.Now;
gameSession.Habbo.Online = true;
_habboRepository.SaveAsync(gameSession.Habbo);
if (DateTime.Now.Hour == 15)
{
_achievementManager.UpdateAchievementAsync("ACH_HappyHour", 1, gameSession);
}
_logger.LogInformation("{User} logged in", gameSession.Habbo.Username);
2023-09-23 11:11:07 +00:00
await gameSession.SendComposerAsync(new AuthenticatedComposer());
2023-09-23 11:11:07 +00:00
await gameSession.SendComposerAsync(new HabboBroadcastMessageComposer(
2023-09-23 12:20:45 +00:00
_settingManager.GetSetting<string>("welcome.message")
2023-09-23 11:11:07 +00:00
.Replace("{user}", gameSession.Habbo.Username)
));
}
}