using Tiger.Communication.Messages.Interfaces; using Tiger.Communication.Messages.Outgoing.Navigator; using Tiger.Communication.Messages.Types; using Tiger.Game.Rooms; using Tiger.Networking.Game.Sessions; using Tiger.Storage; namespace Tiger.Communication.Messages.Incoming.Navigator; public class CreateFlatEvent : IMessageEvent { private readonly IRepository _roomRepository; private readonly IRoomManager _roomManager; public CreateFlatEvent(IRepository roomRepository, IRoomManager roomManager) { _roomRepository = roomRepository; _roomManager = roomManager; } public IncomingHeaders Header => IncomingHeaders.CreateFlat; public async Task HandleAsync(GameSession gameSession, ClientMessage request) { if (gameSession.Habbo == null) { await gameSession.CloseAsync(); return; } var name = request.ReadString(); var roomModel = request.ReadString(); var roomAccess = request.ReadString(); var showOwner = request.ReadBoolean(); if ( string.IsNullOrEmpty(name.Trim()) || !roomModel.StartsWith("model_") || ( roomModel != "model_a" && roomModel != "model_b" && roomModel != "model_c" && roomModel != "model_d" && roomModel != "model_e" && roomModel != "model_f" && roomModel != "model_i" && roomModel != "model_j" && roomModel != "model_k" && roomModel != "model_l" && roomModel != "model_m" && roomModel != "model_n" ) ) { return; } if (!_roomManager.Models.TryGetValue(roomModel, out var model)) { return; } var room = new Room() { Name = name, AccessType = Enum.Parse(roomAccess, true), ModelId = model.Id, Model = model, Owner = gameSession.Habbo, ShowOwner = showOwner }; await _roomRepository.SaveAsync(room); await gameSession.SendComposerAsync(new FlatCreatedComposer(room.Id, room.Name)); } }