Added badges
parent
6e9b6d0449
commit
66744ead65
|
@ -5,5 +5,5 @@ namespace Tiger.Communication.Messages;
|
||||||
|
|
||||||
public interface IMessageHandler
|
public interface IMessageHandler
|
||||||
{
|
{
|
||||||
Task TryHandleAsync(GameSession session, ClientMessage request);
|
Task TryHandleAsync(GameSession gameSession, ClientMessage request);
|
||||||
}
|
}
|
|
@ -150,7 +150,7 @@ public enum IncomingHeaders : short
|
||||||
GetRoomEntryTileEvent = 3559,
|
GetRoomEntryTileEvent = 3559,
|
||||||
GetRoomSettingsEvent = 3129,
|
GetRoomSettingsEvent = 3129,
|
||||||
GetRoomVisitsEvent = 3526,
|
GetRoomVisitsEvent = 3526,
|
||||||
GetSelectedBadgesEvent = 2091,
|
GetSelectedBadgesMessageEvent = 2091,
|
||||||
GetSellablePetPalettesEvent = 1756,
|
GetSellablePetPalettesEvent = 1756,
|
||||||
GetSongInfoEvent = 3082,
|
GetSongInfoEvent = 3082,
|
||||||
GetSoundSettingsEvent = 2388,
|
GetSoundSettingsEvent = 2388,
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
using Tiger.Communication.Messages.Interfaces;
|
||||||
|
using Tiger.Communication.Messages.Outgoing.Inventory.Badges;
|
||||||
|
using Tiger.Communication.Messages.Types;
|
||||||
|
using Tiger.Networking.Game.Sessions;
|
||||||
|
|
||||||
|
namespace Tiger.Communication.Messages.Incoming.Inventory.Badges;
|
||||||
|
|
||||||
|
public class GetBadgesEvent : IMessageEvent
|
||||||
|
{
|
||||||
|
private readonly IGameSessionManager _gameSessionManager;
|
||||||
|
|
||||||
|
public GetBadgesEvent(IGameSessionManager gameSessionManager)
|
||||||
|
{
|
||||||
|
_gameSessionManager = gameSessionManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IncomingHeaders Header => IncomingHeaders.GetBadgesEvent;
|
||||||
|
public async Task HandleAsync(GameSession gameSession, ClientMessage request)
|
||||||
|
{
|
||||||
|
if (gameSession.Habbo == null)
|
||||||
|
{
|
||||||
|
await _gameSessionManager.CloseAsync("Not logged in", gameSession);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await gameSession.SendComposerAsync(new BadgesComposer(gameSession.Habbo.Badges));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,59 @@
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
using Tiger.Communication.Messages.Interfaces;
|
||||||
|
using Tiger.Communication.Messages.Outgoing.Users;
|
||||||
|
using Tiger.Communication.Messages.Types;
|
||||||
|
using Tiger.Game.Habbos;
|
||||||
|
using Tiger.Networking.Game.Sessions;
|
||||||
|
using Tiger.Storage;
|
||||||
|
|
||||||
|
namespace Tiger.Communication.Messages.Incoming.Inventory.Badges;
|
||||||
|
|
||||||
|
public class SetActivatedBadgesEvent : IMessageEvent
|
||||||
|
{
|
||||||
|
private readonly IGameSessionManager _gameSessionManager;
|
||||||
|
private readonly IRepository<Badge> _badgeRepository;
|
||||||
|
|
||||||
|
public SetActivatedBadgesEvent(IGameSessionManager gameSessionManager, IRepository<Badge> badgeRepository)
|
||||||
|
{
|
||||||
|
_gameSessionManager = gameSessionManager;
|
||||||
|
_badgeRepository = badgeRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IncomingHeaders Header => IncomingHeaders.SetActivatedBadgesEvent;
|
||||||
|
public async Task HandleAsync(GameSession gameSession, ClientMessage request)
|
||||||
|
{
|
||||||
|
if (gameSession.Habbo == null)
|
||||||
|
{
|
||||||
|
await _gameSessionManager.CloseAsync("Not logged in", gameSession);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gameSession.Habbo.Badges == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var wearingBadges = new Collection<Badge>();
|
||||||
|
foreach (var currentBadge in gameSession.Habbo.Badges)
|
||||||
|
{
|
||||||
|
currentBadge.Slot = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var i = 0; i < 5; i++)
|
||||||
|
{
|
||||||
|
var slotId = request.ReadInt32();
|
||||||
|
var code = request.ReadString();
|
||||||
|
|
||||||
|
if (slotId == null || slotId is < 1 or > 5 || string.IsNullOrEmpty(code)) continue;
|
||||||
|
|
||||||
|
var badge = gameSession.Habbo.Badges.FirstOrDefault(b => b.Code == code);
|
||||||
|
|
||||||
|
if (badge == null) continue;
|
||||||
|
|
||||||
|
badge.Slot = slotId.Value;
|
||||||
|
wearingBadges.Add(badge);
|
||||||
|
|
||||||
|
_badgeRepository.SaveAsync(badge);
|
||||||
|
}
|
||||||
|
|
||||||
|
await gameSession.SendComposerAsync(new HabboUserBadgesMessageComposer(gameSession.Habbo.Id, wearingBadges));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
using Tiger.Communication.Messages.Interfaces;
|
||||||
|
using Tiger.Communication.Messages.Outgoing.Users;
|
||||||
|
using Tiger.Communication.Messages.Types;
|
||||||
|
using Tiger.Game.Habbos;
|
||||||
|
using Tiger.Networking.Game.Sessions;
|
||||||
|
using Tiger.Storage;
|
||||||
|
|
||||||
|
namespace Tiger.Communication.Messages.Incoming.Users;
|
||||||
|
|
||||||
|
public class GetSelectedBadgesMessageEvent : IMessageEvent
|
||||||
|
{
|
||||||
|
private readonly IGameSessionManager _gameSessionManager;
|
||||||
|
private readonly IRepository<Badge> _badgeRepository;
|
||||||
|
|
||||||
|
public GetSelectedBadgesMessageEvent(IGameSessionManager gameSessionManager, IRepository<Badge> badgeRepository)
|
||||||
|
{
|
||||||
|
_gameSessionManager = gameSessionManager;
|
||||||
|
_badgeRepository = badgeRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IncomingHeaders Header => IncomingHeaders.GetSelectedBadgesMessageEvent;
|
||||||
|
public async Task HandleAsync(GameSession gameSession, ClientMessage request)
|
||||||
|
{
|
||||||
|
if (gameSession.Habbo == null)
|
||||||
|
{
|
||||||
|
await _gameSessionManager.CloseAsync("Not logged in", gameSession);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var habboId = request.ReadInt32();
|
||||||
|
|
||||||
|
if (habboId == null) return;
|
||||||
|
|
||||||
|
var badges = await _badgeRepository.FindByAsync(b => b.Habbo.Id == habboId && b.Slot > 0);
|
||||||
|
await gameSession.SendComposerAsync(new HabboUserBadgesMessageComposer(habboId.Value, badges.ToList()));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
using Tiger.Communication.Messages.Interfaces;
|
||||||
|
using Tiger.Communication.Messages.Types;
|
||||||
|
using Tiger.Game.Habbos;
|
||||||
|
|
||||||
|
namespace Tiger.Communication.Messages.Outgoing.Inventory.Badges;
|
||||||
|
|
||||||
|
public class BadgesComposer : IMessageComposer
|
||||||
|
{
|
||||||
|
private readonly IReadOnlyList<Badge> _badges;
|
||||||
|
|
||||||
|
public BadgesComposer(IEnumerable<Badge>? badges)
|
||||||
|
{
|
||||||
|
_badges = badges != null ? badges.ToList() : new List<Badge>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public OutgoingHeaders Header => OutgoingHeaders.BadgesComposer;
|
||||||
|
public void Compose(ServerMessage message)
|
||||||
|
{
|
||||||
|
message.AppendInt32(_badges.Count);
|
||||||
|
|
||||||
|
foreach (var badge in _badges)
|
||||||
|
{
|
||||||
|
message.AppendInt32(badge.Id);
|
||||||
|
message.AppendString(badge.Code);
|
||||||
|
}
|
||||||
|
|
||||||
|
var wearingBadges = _badges.Where(b => b.Slot > 0).ToList();
|
||||||
|
|
||||||
|
message.AppendInt32(wearingBadges.Count);
|
||||||
|
|
||||||
|
foreach (var wearingBadge in wearingBadges)
|
||||||
|
{
|
||||||
|
message.AppendInt32(wearingBadge.Slot);
|
||||||
|
message.AppendString(wearingBadge.Code);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -432,7 +432,7 @@ public enum OutgoingHeaders
|
||||||
UpdateStackHeightTileHeightComposer = 2816,
|
UpdateStackHeightTileHeightComposer = 2816,
|
||||||
UpdateThreadMessageComposer = 2528,
|
UpdateThreadMessageComposer = 2528,
|
||||||
UseObjectMessageComposer = 1774,
|
UseObjectMessageComposer = 1774,
|
||||||
UserBadgesComposer = 1087,
|
HabboUserBadgesMessageComposer = 1087,
|
||||||
UserBannedMessageComposer = 1683,
|
UserBannedMessageComposer = 1683,
|
||||||
UserBcLimitsComposer = -1,
|
UserBcLimitsComposer = -1,
|
||||||
UserChangeMessageComposer = 3920,
|
UserChangeMessageComposer = 3920,
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
using Tiger.Communication.Messages.Interfaces;
|
||||||
|
using Tiger.Communication.Messages.Types;
|
||||||
|
using Tiger.Game.Habbos;
|
||||||
|
|
||||||
|
namespace Tiger.Communication.Messages.Outgoing.Users;
|
||||||
|
|
||||||
|
public class HabboUserBadgesMessageComposer : IMessageComposer
|
||||||
|
{
|
||||||
|
private readonly int _habboId;
|
||||||
|
private readonly ICollection<Badge> _badges;
|
||||||
|
|
||||||
|
public HabboUserBadgesMessageComposer(int habboId, ICollection<Badge> badges)
|
||||||
|
{
|
||||||
|
_habboId = habboId;
|
||||||
|
_badges = badges;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OutgoingHeaders Header => OutgoingHeaders.HabboUserBadgesMessageComposer;
|
||||||
|
public void Compose(ServerMessage message)
|
||||||
|
{
|
||||||
|
message.AppendInt32(_habboId);
|
||||||
|
message.AppendInt32(_badges.Count);
|
||||||
|
|
||||||
|
foreach (var badge in _badges)
|
||||||
|
{
|
||||||
|
message.AppendInt32(badge.Slot);
|
||||||
|
message.AppendString(badge.Code);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
namespace Tiger.Game.Habbos;
|
||||||
|
|
||||||
|
public class Badge
|
||||||
|
{
|
||||||
|
public virtual int Id { get; set; }
|
||||||
|
public virtual Habbo Habbo { get; set; } = null!;
|
||||||
|
public virtual string Code { get; set; } = null!;
|
||||||
|
public virtual int Slot { get; set; }
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
using FluentNHibernate.Mapping;
|
||||||
|
|
||||||
|
namespace Tiger.Game.Habbos;
|
||||||
|
|
||||||
|
public class BadgeMap : ClassMap<Badge>
|
||||||
|
{
|
||||||
|
public BadgeMap()
|
||||||
|
{
|
||||||
|
Table("habbo_badges");
|
||||||
|
LazyLoad();
|
||||||
|
Id(b => b.Id).Column("id").GeneratedBy.Identity();
|
||||||
|
References(b => b.Habbo).Column("habbo_id").Not.Nullable();
|
||||||
|
Map(b => b.Code).Column("code").Not.Nullable();
|
||||||
|
Map(b => b.Slot).Column("slot").Not.Nullable();
|
||||||
|
}
|
||||||
|
}
|
|
@ -18,4 +18,5 @@ public class Habbo
|
||||||
public virtual int? GroupId { get; set; }
|
public virtual int? GroupId { get; set; }
|
||||||
public virtual string? SsoTicket { get; set; }
|
public virtual string? SsoTicket { get; set; }
|
||||||
public virtual IEnumerable<Activitypoints>? Activitypoints { get; set; }
|
public virtual IEnumerable<Activitypoints>? Activitypoints { get; set; }
|
||||||
|
public virtual IEnumerable<Badge>? Badges { get; set; }
|
||||||
}
|
}
|
|
@ -24,5 +24,6 @@ public class HabboMap : ClassMap<Habbo>
|
||||||
Map(h => h.GroupId).Column("group_id").Nullable();
|
Map(h => h.GroupId).Column("group_id").Nullable();
|
||||||
Map(h => h.SsoTicket).Column("sso_ticket").Nullable();
|
Map(h => h.SsoTicket).Column("sso_ticket").Nullable();
|
||||||
HasMany<Activitypoints>(h => h.Activitypoints).LazyLoad().Inverse().Cascade.All();
|
HasMany<Activitypoints>(h => h.Activitypoints).LazyLoad().Inverse().Cascade.All();
|
||||||
|
HasMany<Badge>(h => h.Badges).LazyLoad().Inverse().Cascade.All();
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue