Added start of navigator
parent
f56198e9cb
commit
77f3b6a983
|
@ -0,0 +1,32 @@
|
||||||
|
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;
|
||||||
|
|
||||||
|
namespace Tiger.Communication.Messages.Incoming.Navigator;
|
||||||
|
|
||||||
|
public class GetUserFlatCatsMessageEvent : IMessageEvent
|
||||||
|
{
|
||||||
|
private readonly IGameSessionManager _gameSessionManager;
|
||||||
|
private readonly IRoomManager _roomManager;
|
||||||
|
|
||||||
|
public GetUserFlatCatsMessageEvent(IRoomManager roomManager, IGameSessionManager gameSessionManager)
|
||||||
|
{
|
||||||
|
_roomManager = roomManager;
|
||||||
|
_gameSessionManager = gameSessionManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IncomingHeaders Header => IncomingHeaders.GetUserFlatCats;
|
||||||
|
public async Task HandleAsync(GameSession gameSession, ClientMessage request)
|
||||||
|
{
|
||||||
|
if (gameSession.Habbo == null)
|
||||||
|
{
|
||||||
|
await _gameSessionManager.CloseAsync("Not logged in", gameSession);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await gameSession.SendComposerAsync(new UserFlatCatsComposer(_roomManager.PrivateCategories.Values,
|
||||||
|
gameSession.Habbo.Rank));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
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 NavigatorInitEvent : IMessageEvent
|
||||||
|
{
|
||||||
|
private readonly IGameSessionManager _gameSessionManager;
|
||||||
|
private readonly INavigatorManager _navigatorManager;
|
||||||
|
|
||||||
|
public NavigatorInitEvent(IGameSessionManager gameSessionManager, INavigatorManager navigatorManager)
|
||||||
|
{
|
||||||
|
_gameSessionManager = gameSessionManager;
|
||||||
|
_navigatorManager = navigatorManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IncomingHeaders Header => IncomingHeaders.NavigatorInit;
|
||||||
|
public async Task HandleAsync(GameSession gameSession, ClientMessage request)
|
||||||
|
{
|
||||||
|
if (gameSession.Habbo == null)
|
||||||
|
{
|
||||||
|
await _gameSessionManager.CloseAsync("Not logged in", gameSession);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await gameSession.SendComposerAsync(new NavigatorMetadataComposer(_navigatorManager.NavigatorViews.Values));
|
||||||
|
await gameSession.SendComposerAsync(new NavigatorCollapsedComposer());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
var viewName = request.ReadString();
|
||||||
|
var query = request.ReadString();
|
||||||
|
|
||||||
|
if (viewName is null || query is null ||
|
||||||
|
!_navigatorManager.NavigatorViews.TryGetValue(viewName, out var navigatorView)) return;
|
||||||
|
|
||||||
|
await gameSession.SendComposerAsync(new NavigatorSearchComposer(navigatorView, query, gameSession.Habbo));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
using Tiger.Communication.Messages.Interfaces;
|
||||||
|
using Tiger.Communication.Messages.Types;
|
||||||
|
|
||||||
|
namespace Tiger.Communication.Messages.Outgoing.Navigator;
|
||||||
|
|
||||||
|
public class NavigatorCollapsedComposer : IMessageComposer
|
||||||
|
{
|
||||||
|
public OutgoingHeaders Header => OutgoingHeaders.NavigatorCollapsed;
|
||||||
|
public void Compose(ServerMessage message)
|
||||||
|
{
|
||||||
|
message.AppendInt32(1);
|
||||||
|
message.AppendString("official");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
using Tiger.Communication.Messages.Interfaces;
|
||||||
|
using Tiger.Communication.Messages.Types;
|
||||||
|
using Tiger.Game.Navigator.Views;
|
||||||
|
|
||||||
|
namespace Tiger.Communication.Messages.Outgoing.Navigator;
|
||||||
|
|
||||||
|
public class NavigatorMetadataComposer : IMessageComposer
|
||||||
|
{
|
||||||
|
private readonly ICollection<INavigatorView> _navigatorViews;
|
||||||
|
|
||||||
|
public NavigatorMetadataComposer(ICollection<INavigatorView> navigatorViews)
|
||||||
|
{
|
||||||
|
_navigatorViews = navigatorViews;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OutgoingHeaders Header => OutgoingHeaders.NavigatorMetadata;
|
||||||
|
public void Compose(ServerMessage message)
|
||||||
|
{
|
||||||
|
message.AppendInt32(_navigatorViews.Count);
|
||||||
|
|
||||||
|
foreach (var navigatorView in _navigatorViews)
|
||||||
|
{
|
||||||
|
message.AppendString(navigatorView.Code);
|
||||||
|
message.AppendInt32(0); // saved searches
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
using Tiger.Communication.Messages.Interfaces;
|
||||||
|
using Tiger.Communication.Messages.Types;
|
||||||
|
using Tiger.Game.Habbos;
|
||||||
|
using Tiger.Game.Navigator.Views;
|
||||||
|
|
||||||
|
namespace Tiger.Communication.Messages.Outgoing.Navigator;
|
||||||
|
|
||||||
|
public class NavigatorSearchComposer : IMessageComposer
|
||||||
|
{
|
||||||
|
private readonly INavigatorView _navigatorView;
|
||||||
|
private readonly string _query;
|
||||||
|
private readonly Habbo _habbo;
|
||||||
|
|
||||||
|
public NavigatorSearchComposer(INavigatorView navigatorView, string query, Habbo habbo)
|
||||||
|
{
|
||||||
|
_navigatorView = navigatorView;
|
||||||
|
_query = query;
|
||||||
|
_habbo = habbo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OutgoingHeaders Header => OutgoingHeaders.NavigatorSearch;
|
||||||
|
public void Compose(ServerMessage message)
|
||||||
|
{
|
||||||
|
message.AppendString(_navigatorView.Code);
|
||||||
|
message.AppendString(_query);
|
||||||
|
_navigatorView.Compose(message, _habbo, _query);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
using Tiger.Communication.Messages.Interfaces;
|
||||||
|
using Tiger.Communication.Messages.Types;
|
||||||
|
using Tiger.Game.Rooms;
|
||||||
|
|
||||||
|
namespace Tiger.Communication.Messages.Outgoing.Navigator;
|
||||||
|
|
||||||
|
public class UserFlatCatsComposer : IMessageComposer
|
||||||
|
{
|
||||||
|
private readonly ICollection<RoomPrivateCategory> _privateCategories;
|
||||||
|
private readonly int _rank;
|
||||||
|
|
||||||
|
public UserFlatCatsComposer(ICollection<RoomPrivateCategory> privateCategories, int rank)
|
||||||
|
{
|
||||||
|
_privateCategories = privateCategories;
|
||||||
|
_rank = rank;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OutgoingHeaders Header => OutgoingHeaders.NavigatorCategories;
|
||||||
|
public void Compose(ServerMessage message)
|
||||||
|
{
|
||||||
|
message.AppendInt32(_privateCategories.Count);
|
||||||
|
|
||||||
|
foreach (var privateCategory in _privateCategories)
|
||||||
|
{
|
||||||
|
message.AppendInt32(privateCategory.Id);
|
||||||
|
message.AppendString(privateCategory.Name);
|
||||||
|
message.AppendBoolean(privateCategory.MinRank <= _rank);
|
||||||
|
message.AppendBoolean(true); // automatic?
|
||||||
|
message.AppendString(""); // automatic category key?
|
||||||
|
message.AppendString(""); // global category key?
|
||||||
|
message.AppendBoolean(privateCategory.MinRank >= 4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
using Tiger.Game.Navigator.Views;
|
||||||
|
|
||||||
|
namespace Tiger.Game.Navigator;
|
||||||
|
|
||||||
|
public interface INavigatorManager
|
||||||
|
{
|
||||||
|
IDictionary<string, INavigatorView> NavigatorViews { get; }
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
using Tiger.Game.Navigator.Views;
|
||||||
|
|
||||||
|
namespace Tiger.Game.Navigator;
|
||||||
|
|
||||||
|
public class NavigatorManager : INavigatorManager
|
||||||
|
{
|
||||||
|
public IDictionary<string, INavigatorView> NavigatorViews { get; }
|
||||||
|
|
||||||
|
public NavigatorManager(IEnumerable<INavigatorView> navigatorViews)
|
||||||
|
{
|
||||||
|
NavigatorViews = navigatorViews.ToDictionary(n => n.Code);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
using Tiger.Communication.Messages.Types;
|
||||||
|
using Tiger.Game.Habbos;
|
||||||
|
|
||||||
|
namespace Tiger.Game.Navigator.Views;
|
||||||
|
|
||||||
|
public interface INavigatorView
|
||||||
|
{
|
||||||
|
string Code { get; }
|
||||||
|
void Compose(ServerMessage message, Habbo habbo, string query);
|
||||||
|
}
|
|
@ -0,0 +1,54 @@
|
||||||
|
using System.Collections;
|
||||||
|
using Tiger.Communication.Messages.Types;
|
||||||
|
using Tiger.Game.Habbos;
|
||||||
|
|
||||||
|
namespace Tiger.Game.Navigator.Views;
|
||||||
|
|
||||||
|
public class MyWorldView : INavigatorView
|
||||||
|
{
|
||||||
|
private const int OwnRoomsType = 0;
|
||||||
|
private const int FavoriteRoomsType = 1;
|
||||||
|
private const int GroupRoomsType = 2;
|
||||||
|
private const int VisitedRoomsType = 3;
|
||||||
|
private const int FriendRoomsType = 4;
|
||||||
|
private const int RightsRoomType = 5;
|
||||||
|
|
||||||
|
public string Code => "myworld_view";
|
||||||
|
|
||||||
|
private readonly IDictionary<string, int> _categories = new Dictionary<string, int>
|
||||||
|
{
|
||||||
|
{"My Rooms", OwnRoomsType},
|
||||||
|
{"My Favorite Rooms", FavoriteRoomsType},
|
||||||
|
{"My Groups", GroupRoomsType},
|
||||||
|
{"My Room Visit History", VisitedRoomsType},
|
||||||
|
{"My Friends' Rooms", FriendRoomsType},
|
||||||
|
{"Rooms Where I Have Rights", RightsRoomType}
|
||||||
|
};
|
||||||
|
|
||||||
|
public MyWorldView()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Compose(ServerMessage message, Habbo habbo, string query)
|
||||||
|
{
|
||||||
|
message.AppendInt32(_categories.Count);
|
||||||
|
|
||||||
|
foreach (var (category, type) in _categories)
|
||||||
|
{
|
||||||
|
message.AppendString(category);
|
||||||
|
message.AppendString(category);
|
||||||
|
message.AppendInt32(0); // action?
|
||||||
|
message.AppendBoolean(false); // closed?
|
||||||
|
message.AppendInt32(0); // mode?
|
||||||
|
|
||||||
|
var rooms = GetRoomsByType(habbo, type);
|
||||||
|
|
||||||
|
message.AppendInt32(rooms.Count); // TODO: Rooms, this will ALWAYS return 0.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private ICollection GetRoomsByType(Habbo habbo, int type)
|
||||||
|
{
|
||||||
|
return new List<object>();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
using Tiger.Communication.Messages.Types;
|
||||||
|
using Tiger.Game.Habbos;
|
||||||
|
|
||||||
|
namespace Tiger.Game.Navigator.Views;
|
||||||
|
|
||||||
|
public class OfficialView : INavigatorView
|
||||||
|
{
|
||||||
|
public string Code => "official_view";
|
||||||
|
public void Compose(ServerMessage message, Habbo habbo, string query)
|
||||||
|
{
|
||||||
|
message.AppendInt32(0);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
namespace Tiger.Game.Rooms;
|
||||||
|
|
||||||
|
public interface IRoomManager
|
||||||
|
{
|
||||||
|
IDictionary<int, RoomPrivateCategory> PrivateCategories { get; }
|
||||||
|
Task LoadPrivateCategoriesAsync();
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Tiger.Storage;
|
||||||
|
|
||||||
|
namespace Tiger.Game.Rooms;
|
||||||
|
|
||||||
|
public class RoomManager : IRoomManager
|
||||||
|
{
|
||||||
|
private readonly IRepository<RoomPrivateCategory> _roomPrivateCategoryRepository;
|
||||||
|
private readonly ILogger<IRoomManager> _logger;
|
||||||
|
|
||||||
|
public IDictionary<int, RoomPrivateCategory> PrivateCategories { get; private set; }
|
||||||
|
|
||||||
|
public RoomManager(IRepository<RoomPrivateCategory> roomPrivateCategoryRepository, ILogger<IRoomManager> logger)
|
||||||
|
{
|
||||||
|
_roomPrivateCategoryRepository = roomPrivateCategoryRepository;
|
||||||
|
_logger = logger;
|
||||||
|
|
||||||
|
PrivateCategories = new Dictionary<int, RoomPrivateCategory>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task LoadPrivateCategoriesAsync()
|
||||||
|
{
|
||||||
|
PrivateCategories =
|
||||||
|
(await _roomPrivateCategoryRepository.FindByAsync()).ToDictionary(rpc => rpc.Id);
|
||||||
|
|
||||||
|
_logger.LogInformation("Loaded {Count} private room categories", PrivateCategories.Count);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
namespace Tiger.Game.Rooms;
|
||||||
|
|
||||||
|
public class RoomPrivateCategory
|
||||||
|
{
|
||||||
|
public virtual int Id { get; set; }
|
||||||
|
public virtual int MinRank { get; set; }
|
||||||
|
public virtual string Code { get; set; } = null!;
|
||||||
|
public virtual string Name { get; set; } = null!;
|
||||||
|
public virtual bool CanTrade { get; set; }
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
namespace Tiger.Game.Rooms;
|
||||||
|
|
||||||
|
public class RoomPrivateCategoryMap
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
10
Program.cs
10
Program.cs
|
@ -3,11 +3,15 @@ using Microsoft.Extensions.Configuration.Yaml;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Tiger.Communication.Messages;
|
using Tiger.Communication.Messages;
|
||||||
|
using Tiger.Communication.Messages.Interfaces;
|
||||||
using Tiger.Game.Achievements;
|
using Tiger.Game.Achievements;
|
||||||
using Tiger.Game.Catalogue;
|
using Tiger.Game.Catalogue;
|
||||||
using Tiger.Game.Figuredata;
|
using Tiger.Game.Figuredata;
|
||||||
using Tiger.Game.Habbos;
|
using Tiger.Game.Habbos;
|
||||||
using Tiger.Game.LandingView;
|
using Tiger.Game.LandingView;
|
||||||
|
using Tiger.Game.Navigator;
|
||||||
|
using Tiger.Game.Navigator.Views;
|
||||||
|
using Tiger.Game.Rooms;
|
||||||
using Tiger.Game.Settings;
|
using Tiger.Game.Settings;
|
||||||
using Tiger.Networking.Game;
|
using Tiger.Networking.Game;
|
||||||
using Tiger.Networking.Game.Sessions;
|
using Tiger.Networking.Game.Sessions;
|
||||||
|
@ -41,7 +45,10 @@ collection.AddSingleton<ICatalogueManager, CatalogueManager>();
|
||||||
collection.AddSingleton<IFigureDataManager, FiguredataManager>();
|
collection.AddSingleton<IFigureDataManager, FiguredataManager>();
|
||||||
collection.AddSingleton<ILandingViewManager, LandingViewManager>();
|
collection.AddSingleton<ILandingViewManager, LandingViewManager>();
|
||||||
collection.AddSingleton<IAchievementManager, AchievementManager>();
|
collection.AddSingleton<IAchievementManager, AchievementManager>();
|
||||||
collection.RegisterMessageEvents();
|
collection.AddSingleton<INavigatorManager, NavigatorManager>();
|
||||||
|
collection.AddSingleton<IRoomManager, RoomManager>();
|
||||||
|
collection.RegisterOnInherited<IMessageEvent>();
|
||||||
|
collection.RegisterOnInherited<INavigatorView>();
|
||||||
|
|
||||||
var provider = collection.BuildServiceProvider();
|
var provider = collection.BuildServiceProvider();
|
||||||
|
|
||||||
|
@ -51,6 +58,7 @@ await provider.GetRequiredService<ICatalogueManager>().LoadFeaturedPagesAsync();
|
||||||
provider.GetRequiredService<IFigureDataManager>();
|
provider.GetRequiredService<IFigureDataManager>();
|
||||||
await provider.GetRequiredService<ILandingViewManager>().LoadPromoArticlesAsync();
|
await provider.GetRequiredService<ILandingViewManager>().LoadPromoArticlesAsync();
|
||||||
await provider.GetRequiredService<IAchievementManager>().LoadAchievementsAsync();
|
await provider.GetRequiredService<IAchievementManager>().LoadAchievementsAsync();
|
||||||
|
await provider.GetRequiredService<IRoomManager>().LoadPrivateCategoriesAsync();
|
||||||
|
|
||||||
provider.GetRequiredService<IWebSocketServer>().Start($"http://{configuration["Network:Game:Ip"]}:{configuration["Network:Game:Port"]}/");
|
provider.GetRequiredService<IWebSocketServer>().Start($"http://{configuration["Network:Game:Ip"]}:{configuration["Network:Game:Port"]}/");
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,4 @@
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
|
||||||
<Folder Include="Communication\Messages\Incoming\Avatar\" />
|
|
||||||
</ItemGroup>
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -6,19 +6,19 @@ namespace Tiger.Utils;
|
||||||
|
|
||||||
public static class DependencyInjectionExtensions
|
public static class DependencyInjectionExtensions
|
||||||
{
|
{
|
||||||
public static void RegisterMessageEvents(this IServiceCollection services)
|
public static void RegisterOnInherited<T>(this IServiceCollection services)
|
||||||
{
|
{
|
||||||
// Get the assembly you are interested in (this could be any Assembly)
|
// Get the assembly you are interested in (this could be any Assembly)
|
||||||
var assembly = Assembly.GetExecutingAssembly();
|
var assembly = Assembly.GetExecutingAssembly();
|
||||||
|
|
||||||
// Get all types that implement IMessageEvent and are not abstract
|
// Get all types that implement IMessageEvent and are not abstract
|
||||||
var messageEventTypes = assembly.GetTypes()
|
var types = assembly.GetTypes()
|
||||||
.Where(t => t.GetInterfaces().Contains(typeof(IMessageEvent)) && !t.IsAbstract);
|
.Where(t => t.GetInterfaces().Contains(typeof(T)) && !t.IsAbstract);
|
||||||
|
|
||||||
// Register each type with AddSingleton
|
// Register each type with AddSingleton
|
||||||
foreach (var type in messageEventTypes)
|
foreach (var type in types)
|
||||||
{
|
{
|
||||||
services.AddSingleton(typeof(IMessageEvent), type);
|
services.AddSingleton(typeof(T), type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue