2023-10-27 17:47:17 +00:00
|
|
|
using Microsoft.EntityFrameworkCore;
|
2023-11-13 20:12:12 +00:00
|
|
|
using Server.DB.Documents;
|
|
|
|
using Wonderking.Game.Data.Character;
|
2023-10-27 17:47:17 +00:00
|
|
|
using Wonderking.Packets.Incoming;
|
2023-11-13 20:12:12 +00:00
|
|
|
using Wonderking.Packets.Outgoing;
|
2023-11-14 20:25:28 +00:00
|
|
|
using Wonderking.Packets.Outgoing.Data;
|
2023-10-27 17:47:17 +00:00
|
|
|
|
2023-10-12 07:15:34 +00:00
|
|
|
namespace Server.PacketHandlers;
|
2023-08-14 20:22:43 +00:00
|
|
|
|
|
|
|
using DB;
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
using NetCoreServer;
|
|
|
|
|
|
|
|
public class ChannelSelectionHandler : IPacketHandler<ChannelSelectionPacket>
|
|
|
|
{
|
2023-10-27 17:47:17 +00:00
|
|
|
private readonly IConfiguration _configuration;
|
|
|
|
private readonly ILogger<ChannelSelectionHandler> _logger;
|
|
|
|
private readonly WonderkingContext _wonderkingContext;
|
2023-08-14 20:22:43 +00:00
|
|
|
|
|
|
|
public ChannelSelectionHandler(IConfiguration configuration, ILogger<ChannelSelectionHandler> logger,
|
|
|
|
WonderkingContext wonderkingContext)
|
|
|
|
{
|
2023-10-27 17:47:17 +00:00
|
|
|
this._configuration = configuration;
|
|
|
|
this._logger = logger;
|
|
|
|
this._wonderkingContext = wonderkingContext;
|
2023-08-14 20:22:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public ChannelSelectionHandler()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public Task HandleAsync(ChannelSelectionPacket packet, TcpSession session)
|
|
|
|
{
|
|
|
|
var authSession = (AuthSession)session;
|
2023-11-13 20:12:12 +00:00
|
|
|
ChannelSelectionResponsePacket responsePacket;
|
2023-11-14 19:07:45 +00:00
|
|
|
CharacterSelectionSetGuildNamePacket guildNameResponsePacket;
|
2023-11-13 20:12:12 +00:00
|
|
|
|
2023-11-14 19:07:45 +00:00
|
|
|
var hasCharacters = this._wonderkingContext.Accounts.Include(account => account.Characters)
|
2023-11-14 20:38:34 +00:00
|
|
|
.FirstOrDefault(a => a.Id == authSession.AccountId)?.Characters.Count > 0;
|
2023-11-14 19:07:45 +00:00
|
|
|
var testingChars = false;
|
|
|
|
if (hasCharacters && !testingChars)
|
2023-11-13 20:12:12 +00:00
|
|
|
{
|
|
|
|
responsePacket = new ChannelSelectionResponsePacket
|
|
|
|
{
|
|
|
|
ChannelIsFullFlag = 0,
|
|
|
|
Endpoint = "127.0.0.1",
|
|
|
|
Port = 12345,
|
2023-11-15 19:00:08 +00:00
|
|
|
Characters = this._wonderkingContext.Characters.AsNoTracking().Where(c => c.Account.Id == authSession.AccountId)
|
2023-11-14 19:07:45 +00:00
|
|
|
.Select(c =>
|
|
|
|
new CharacterData
|
2023-11-13 20:12:12 +00:00
|
|
|
{
|
2023-11-14 19:07:45 +00:00
|
|
|
Name = c.Name,
|
|
|
|
Job = c.JobData,
|
|
|
|
Gender = c.Gender,
|
|
|
|
Level = c.Level,
|
2023-11-13 20:12:12 +00:00
|
|
|
Experience = 0,
|
2023-11-14 19:07:45 +00:00
|
|
|
Stats = c.BaseStats,
|
|
|
|
Health = c.Health,
|
|
|
|
Mana = c.Mana,
|
2023-11-13 20:12:12 +00:00
|
|
|
EquippedItems =
|
2023-11-15 19:00:08 +00:00
|
|
|
c.InventoryItems.Where(item => item.InventoryTab == InventoryTab.WornEquipment)
|
2023-11-14 19:07:45 +00:00
|
|
|
.Select(item => item.ItemId)
|
|
|
|
.ToArray(),
|
|
|
|
EquippedCashItems = c.InventoryItems
|
2023-11-15 19:00:08 +00:00
|
|
|
.Where(item => item.InventoryTab == InventoryTab.WornCashEquipment)
|
2023-11-13 20:12:12 +00:00
|
|
|
.Select(item => item.ItemId)
|
|
|
|
.ToArray(),
|
|
|
|
})
|
|
|
|
.ToArray(),
|
|
|
|
};
|
2023-11-14 19:07:45 +00:00
|
|
|
|
|
|
|
guildNameResponsePacket = new CharacterSelectionSetGuildNamePacket
|
|
|
|
{
|
2023-11-15 19:00:08 +00:00
|
|
|
GuildNames = this._wonderkingContext.Characters.Where(c => c.Account.Id == authSession.AccountId)
|
2023-11-14 19:07:45 +00:00
|
|
|
.Select(character => character.Guild.Name).ToArray()
|
|
|
|
};
|
2023-11-13 20:12:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-11-13 20:17:44 +00:00
|
|
|
responsePacket = testingChars
|
|
|
|
? CreateTestChannelSelectionResponsePacket()
|
|
|
|
: new ChannelSelectionResponsePacket
|
|
|
|
{
|
|
|
|
ChannelIsFullFlag = 0,
|
|
|
|
Endpoint = "127.0.0.1",
|
|
|
|
Port = 12345,
|
|
|
|
Characters = Array.Empty<CharacterData>()
|
|
|
|
};
|
2023-11-14 19:07:45 +00:00
|
|
|
guildNameResponsePacket = new CharacterSelectionSetGuildNamePacket
|
|
|
|
{
|
|
|
|
GuildNames = new[] { "ABCDEFGHIJKLMNOP", "QRSTUVWXYZ123456", "A Guild Name For" }
|
|
|
|
};
|
2023-11-13 20:16:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
authSession.Send(responsePacket);
|
2023-11-14 19:07:45 +00:00
|
|
|
if (guildNameResponsePacket.GuildNames.Length > 0)
|
|
|
|
{
|
|
|
|
authSession.Send(guildNameResponsePacket);
|
|
|
|
}
|
|
|
|
|
2023-11-13 20:16:02 +00:00
|
|
|
return Task.CompletedTask;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static ChannelSelectionResponsePacket CreateTestChannelSelectionResponsePacket()
|
|
|
|
{
|
|
|
|
return new ChannelSelectionResponsePacket
|
|
|
|
{
|
|
|
|
ChannelIsFullFlag = 0,
|
|
|
|
Endpoint = "127.0.0.1",
|
|
|
|
Port = 12345,
|
|
|
|
Characters = new[]
|
2023-11-13 20:12:12 +00:00
|
|
|
{
|
2023-11-13 20:16:02 +00:00
|
|
|
new CharacterData
|
2023-11-13 20:12:12 +00:00
|
|
|
{
|
2023-11-13 21:43:37 +00:00
|
|
|
Name = "1",
|
2023-11-13 20:16:02 +00:00
|
|
|
Job = new JobData { FirstJob = 1, SecondJob = 0, ThirdJob = 0, FourthJob = 0 },
|
2023-11-13 21:43:37 +00:00
|
|
|
Gender = Gender.Female,
|
2023-11-13 20:16:02 +00:00
|
|
|
Level = ushort.MaxValue - 1,
|
|
|
|
Experience = 255,
|
|
|
|
Stats = new BaseStats
|
2023-11-13 20:12:12 +00:00
|
|
|
{
|
2023-11-13 20:16:02 +00:00
|
|
|
Strength = 5,
|
|
|
|
Dexterity = 5,
|
|
|
|
Intelligence = 5,
|
|
|
|
Vitality = 5,
|
|
|
|
Luck = 5,
|
|
|
|
Wisdom = 5
|
2023-11-13 20:12:12 +00:00
|
|
|
},
|
2023-11-13 20:16:02 +00:00
|
|
|
Health = int.MaxValue - 1,
|
|
|
|
Mana = int.MaxValue - 1,
|
|
|
|
EquippedItems = Enumerable.Repeat((ushort)25, 20).ToArray(),
|
2023-11-13 21:43:37 +00:00
|
|
|
EquippedCashItems = Enumerable.Repeat((ushort)70, 20).ToArray()
|
2023-11-13 20:12:12 +00:00
|
|
|
},
|
2023-11-13 21:43:37 +00:00
|
|
|
new CharacterData
|
|
|
|
{
|
|
|
|
Name = "2",
|
|
|
|
Job = new JobData { FirstJob = 1, SecondJob = 0, ThirdJob = 0, FourthJob = 0 },
|
|
|
|
Gender = Gender.Female,
|
|
|
|
Level = ushort.MaxValue - 1,
|
|
|
|
Experience = 255,
|
|
|
|
Stats = new BaseStats
|
|
|
|
{
|
|
|
|
Strength = 5,
|
|
|
|
Dexterity = 5,
|
|
|
|
Intelligence = 5,
|
|
|
|
Vitality = 5,
|
|
|
|
Luck = 5,
|
|
|
|
Wisdom = 5
|
|
|
|
},
|
|
|
|
Health = int.MaxValue - 1,
|
|
|
|
Mana = int.MaxValue - 1,
|
2023-11-14 19:07:45 +00:00
|
|
|
EquippedItems = Enumerable.Repeat((ushort)35, 20).ToArray(),
|
|
|
|
EquippedCashItems = Enumerable.Repeat((ushort)55, 20).ToArray()
|
2023-11-13 21:43:37 +00:00
|
|
|
},
|
|
|
|
new CharacterData
|
|
|
|
{
|
|
|
|
Name = "3",
|
|
|
|
Job = new JobData { FirstJob = 1, SecondJob = 0, ThirdJob = 0, FourthJob = 0 },
|
|
|
|
Gender = Gender.Female,
|
|
|
|
Level = ushort.MaxValue - 1,
|
|
|
|
Experience = 255,
|
|
|
|
Stats = new BaseStats
|
|
|
|
{
|
|
|
|
Strength = 5,
|
|
|
|
Dexterity = 5,
|
|
|
|
Intelligence = 5,
|
|
|
|
Vitality = 5,
|
|
|
|
Luck = 5,
|
|
|
|
Wisdom = 5
|
|
|
|
},
|
|
|
|
Health = int.MaxValue - 1,
|
|
|
|
Mana = int.MaxValue - 1,
|
2023-11-14 19:07:45 +00:00
|
|
|
EquippedItems = Enumerable.Repeat((ushort)45, 20).ToArray(),
|
2023-11-13 21:43:37 +00:00
|
|
|
EquippedCashItems = Enumerable.Repeat((ushort)65, 20).ToArray()
|
|
|
|
}
|
2023-11-13 20:16:02 +00:00
|
|
|
},
|
|
|
|
};
|
2023-08-14 20:22:43 +00:00
|
|
|
}
|
|
|
|
}
|