Timothy Schenk
b68e058429
All checks were successful
Build, Package and Push Images / preprocess (push) Successful in 4s
Build, Package and Push Images / docs (push) Successful in 47s
Build, Package and Push Images / build (push) Successful in 46s
Build, Package and Push Images / sonarqube (push) Has been skipped
Build, Package and Push Images / sbom-scan (push) Successful in 1m1s
Build, Package and Push Images / build-docs-container (push) Successful in 1m40s
Build, Package and Push Images / deploy-wiki (push) Successful in 4s
Build, Package and Push Images / container-build (push) Successful in 2m31s
Build, Package and Push Images / container-sbom-scan (push) Successful in 42s
93 lines
3.6 KiB
C#
93 lines
3.6 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using Server.DB.Documents;
|
|
using Wonderking.Packets.Incoming;
|
|
using Wonderking.Packets.Outgoing;
|
|
using Wonderking.Packets.Outgoing.Data;
|
|
|
|
namespace Server.PacketHandlers;
|
|
|
|
using DB;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.Logging;
|
|
using NetCoreServer;
|
|
|
|
public class ChannelSelectionHandler : IPacketHandler<ChannelSelectionPacket>
|
|
{
|
|
private readonly IConfiguration _configuration;
|
|
private readonly ILogger<ChannelSelectionHandler> _logger;
|
|
private readonly WonderkingContext _wonderkingContext;
|
|
|
|
public ChannelSelectionHandler(IConfiguration configuration, ILogger<ChannelSelectionHandler> logger,
|
|
WonderkingContext wonderkingContext)
|
|
{
|
|
this._configuration = configuration;
|
|
this._logger = logger;
|
|
this._wonderkingContext = wonderkingContext;
|
|
}
|
|
|
|
public ChannelSelectionHandler()
|
|
{
|
|
}
|
|
|
|
public Task HandleAsync(ChannelSelectionPacket packet, TcpSession session)
|
|
{
|
|
var authSession = (AuthSession)session;
|
|
ChannelSelectionResponsePacket responsePacket;
|
|
var guildNameResponsePacket = new CharacterSelectionSetGuildNamePacket { GuildNames = Array.Empty<string>() };
|
|
|
|
var hasCharacters = this._wonderkingContext.Accounts.Include(account => account.Characters)
|
|
.FirstOrDefault(a => a.Id == authSession.AccountId)?.Characters.Count > 0;
|
|
if (hasCharacters)
|
|
{
|
|
responsePacket = new ChannelSelectionResponsePacket
|
|
{
|
|
ChannelIsFullFlag = 0,
|
|
Endpoint = "127.0.0.1",
|
|
Port = 12345,
|
|
Characters = this._wonderkingContext.Characters.AsNoTracking()
|
|
.Where(c => c.Account.Id == authSession.AccountId)
|
|
.Select(c =>
|
|
new CharacterData
|
|
{
|
|
Name = c.Name,
|
|
Job = c.JobData,
|
|
Gender = c.Gender,
|
|
Level = c.Level,
|
|
// TODO: Calculate instead of clamping based on max experience for level
|
|
Experience = Math.Clamp(c.Experience, 0, 100),
|
|
Stats = c.BaseStats,
|
|
Health = c.Health,
|
|
Mana = c.Mana,
|
|
EquippedItems =
|
|
c.InventoryItems.Where(item => item.InventoryTab == InventoryTab.WornEquipment)
|
|
.Select(item => item.ItemId)
|
|
.ToArray(),
|
|
EquippedCashItems = c.InventoryItems
|
|
.Where(item => item.InventoryTab == InventoryTab.WornCashEquipment)
|
|
.Select(item => item.ItemId)
|
|
.ToArray()
|
|
})
|
|
.ToArray(),
|
|
};
|
|
|
|
guildNameResponsePacket.GuildNames = this._wonderkingContext.Characters
|
|
.Where(c => c.Account.Id == authSession.AccountId)
|
|
.Select(character => character.Guild.Name).ToArray();
|
|
}
|
|
else
|
|
{
|
|
responsePacket = new ChannelSelectionResponsePacket
|
|
{
|
|
ChannelIsFullFlag = 0,
|
|
Endpoint = "127.0.0.1",
|
|
Port = 12345,
|
|
Characters = Array.Empty<CharacterData>()
|
|
};
|
|
}
|
|
|
|
authSession.Send(responsePacket);
|
|
authSession.Send(guildNameResponsePacket);
|
|
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|