61 lines
2.3 KiB
C#
61 lines
2.3 KiB
C#
using Microsoft.Extensions.Logging;
|
|
using Tiger.Communication.Messages.Interfaces;
|
|
using Tiger.Communication.Messages.Outgoing.Notifications;
|
|
using Tiger.Communication.Messages.Outgoing.Security;
|
|
using Tiger.Communication.Messages.Types;
|
|
using Tiger.Game.Achievements;
|
|
using Tiger.Game.Habbos;
|
|
using Tiger.Game.Settings;
|
|
using Tiger.Networking.Game.Sessions;
|
|
using Tiger.Storage;
|
|
|
|
namespace Tiger.Communication.Messages.Incoming.Handshake;
|
|
|
|
public class SsoTicketMessageEvent : IMessageEvent
|
|
{
|
|
private readonly IRepository<Habbo> _habboRepository;
|
|
private readonly IGameSessionManager _gameSessionManager;
|
|
private readonly ISettingManager _settingManager;
|
|
private readonly ILogger<SsoTicketMessageEvent> _logger;
|
|
private readonly IAchievementManager _achievementManager;
|
|
|
|
public SsoTicketMessageEvent(IRepository<Habbo> habboRepository, IGameSessionManager gameSessionManager, ISettingManager settingManager, ILogger<SsoTicketMessageEvent> logger, IAchievementManager achievementManager)
|
|
{
|
|
_habboRepository = habboRepository;
|
|
_gameSessionManager = gameSessionManager;
|
|
_settingManager = settingManager;
|
|
_logger = logger;
|
|
_achievementManager = achievementManager;
|
|
}
|
|
|
|
public IncomingHeaders Header => IncomingHeaders.SecurityTicket;
|
|
|
|
public async Task HandleAsync(GameSession gameSession, ClientMessage request)
|
|
{
|
|
var habbo = await _habboRepository.FindOneByAsync(h => h.SsoTicket == request.ReadString());
|
|
|
|
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);
|
|
|
|
await gameSession.SendComposerAsync(new AuthenticatedComposer());
|
|
await gameSession.SendComposerAsync(new HabboBroadcastMessageComposer(
|
|
_settingManager.GetSetting<string>("welcome.message")
|
|
.Replace("{user}", gameSession.Habbo.Username)
|
|
));
|
|
}
|
|
} |