TigerEmu/Communication/Messages/Incoming/Navigator/NavigatorSearchEvent.cs

33 lines
1.2 KiB
C#

using Tiger.Communication.Messages.Interfaces;
using Tiger.Communication.Messages.Outgoing.Navigator;
using Tiger.Communication.Messages.Types;
using Tiger.Game.Navigator;
using Tiger.Networking.Game.Sessions;
namespace Tiger.Communication.Messages.Incoming.Navigator;
public class NavigatorSearchEvent : IMessageEvent
{
private readonly IGameSessionManager _gameSessionManager;
private readonly INavigatorManager _navigatorManager;
public NavigatorSearchEvent(IGameSessionManager gameSessionManager, INavigatorManager navigatorManager)
{
_gameSessionManager = gameSessionManager;
_navigatorManager = navigatorManager;
}
public IncomingHeaders Header => IncomingHeaders.NavigatorSearch;
public async Task HandleAsync(GameSession gameSession, ClientMessage request)
{
if (gameSession.Habbo == null)
{
await _gameSessionManager.CloseAsync("Not logged in", gameSession);
return;
}
if (!_navigatorManager.NavigatorViews.TryGetValue(request.ReadString(), out var navigatorView)) return;
await gameSession.SendComposerAsync(new NavigatorSearchComposer(navigatorView, request.ReadString(), gameSession.Habbo));
}
}