bugfix/87-client-dc-on-char-deletion #90
4 changed files with 44 additions and 29 deletions
|
@ -39,7 +39,7 @@ public class ChannelSelectionHandler : IPacketHandler<ChannelSelectionPacket>
|
||||||
{
|
{
|
||||||
ChannelIsFullFlag = 0,
|
ChannelIsFullFlag = 0,
|
||||||
Endpoint = "127.0.0.1",
|
Endpoint = "127.0.0.1",
|
||||||
Port = 12345,
|
Port = 2000,
|
||||||
Characters = await _wonderkingContext.Characters.AsNoTracking()
|
Characters = await _wonderkingContext.Characters.AsNoTracking()
|
||||||
.Where(c => c.Account.Id == authSession.AccountId)
|
.Where(c => c.Account.Id == authSession.AccountId)
|
||||||
.Select(c =>
|
.Select(c =>
|
||||||
|
@ -54,20 +54,19 @@ public class ChannelSelectionHandler : IPacketHandler<ChannelSelectionPacket>
|
||||||
Stats = c.BaseStats,
|
Stats = c.BaseStats,
|
||||||
Health = c.Health,
|
Health = c.Health,
|
||||||
Mana = c.Mana,
|
Mana = c.Mana,
|
||||||
EquippedItems =
|
EquippedItems = GetItemIDsByInventoryTab(c.InventoryItems
|
||||||
c.InventoryItems.Where(item => item.InventoryTab == InventoryTab.WornEquipment)
|
.Where(item => item.InventoryTab == InventoryTab.WornEquipment)
|
||||||
.Select(item => item.ItemId)
|
.Select(item => new Tuple<ushort, byte>(item.ItemId, item.Slot)).ToArray()),
|
||||||
.ToArray(),
|
EquippedCashItems = GetItemIDsByInventoryTab(c.InventoryItems
|
||||||
EquippedCashItems = c.InventoryItems
|
|
||||||
.Where(item => item.InventoryTab == InventoryTab.WornCashEquipment)
|
.Where(item => item.InventoryTab == InventoryTab.WornCashEquipment)
|
||||||
.Select(item => item.ItemId)
|
.Select(item => new Tuple<ushort, byte>(item.ItemId, item.Slot)).ToArray()),
|
||||||
.ToArray()
|
|
||||||
})
|
})
|
||||||
.ToArrayAsync().ConfigureAwait(true),
|
.ToArrayAsync().ConfigureAwait(true),
|
||||||
};
|
};
|
||||||
|
|
||||||
guildNameResponsePacket.GuildNames = await _wonderkingContext.Characters
|
guildNameResponsePacket.GuildNames = await _wonderkingContext.Characters
|
||||||
.Where(c => c.Account.Id == authSession.AccountId)
|
.Where(c => c.Account.Id == authSession.AccountId)
|
||||||
|
.Where(c => c.Guild != null)
|
||||||
.Select(character => character.Guild.Name).ToArrayAsync().ConfigureAwait(true);
|
.Select(character => character.Guild.Name).ToArrayAsync().ConfigureAwait(true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -88,4 +87,16 @@ public class ChannelSelectionHandler : IPacketHandler<ChannelSelectionPacket>
|
||||||
authSession.Send(guildNameResponsePacket);
|
authSession.Send(guildNameResponsePacket);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static ushort[] GetItemIDsByInventoryTab(Tuple<ushort, byte>[] items)
|
||||||
|
{
|
||||||
|
var ids = new ushort[20];
|
||||||
|
|
||||||
|
for (var i = 0; i < 20; i++)
|
||||||
|
{
|
||||||
|
ids[i] = items.FirstOrDefault(item => item.Item2 == i)?.Item1 ?? 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ids;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,8 +34,8 @@ public class CharacterDeletionHandler : IPacketHandler<CharacterDeletePacket>
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_wonderkingContext.Characters.Remove(character);
|
//_wonderkingContext.Characters.Remove(character);
|
||||||
await _wonderkingContext.SaveChangesAsync().ConfigureAwait(false);
|
//await _wonderkingContext.SaveChangesAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
authSession.Send(response);
|
authSession.Send(response);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,39 +29,41 @@ public class ChannelSelectionResponsePacket : IPacket
|
||||||
// Character Data
|
// Character Data
|
||||||
for (var i = 0; i < Characters.Length; i++)
|
for (var i = 0; i < Characters.Length; i++)
|
||||||
{
|
{
|
||||||
|
int offset = 20 + (i * 132);
|
||||||
var character = Characters[i];
|
var character = Characters[i];
|
||||||
BinaryPrimitives.WriteInt32LittleEndian(data.Slice(20 + (i * 132), 4), i);
|
// Character Data
|
||||||
Encoding.ASCII.GetBytes(character.Name, data.Slice(24 + (i * 132), 20));
|
BinaryPrimitives.WriteInt32LittleEndian(data.Slice(offset, 4), i);
|
||||||
|
Encoding.ASCII.GetBytes(character.Name, data.Slice(offset + 4, 20));
|
||||||
|
|
||||||
// Job Data
|
// Job Data
|
||||||
data[44 + (i * 132)] = character.Job.FirstJob;
|
data[offset + 24] = character.Job.FirstJob;
|
||||||
data[45 + (i * 132)] = character.Job.SecondJob;
|
data[offset + 25] = character.Job.SecondJob;
|
||||||
data[46 + (i * 132)] = character.Job.ThirdJob;
|
data[offset + 26] = character.Job.ThirdJob;
|
||||||
data[47 + (i * 132)] = character.Job.FourthJob;
|
data[offset + 27] = character.Job.FourthJob;
|
||||||
|
|
||||||
data[48 + (i * 132)] = (byte)character.Gender;
|
data[offset + 28] = (byte)character.Gender;
|
||||||
BinaryPrimitives.WriteUInt16LittleEndian(data.Slice(49 + (i * 132), 2), character.Level);
|
BinaryPrimitives.WriteUInt16LittleEndian(data.Slice(offset + 29, 2), character.Level);
|
||||||
data[51 + (i * 132)] = (byte)character.Experience;
|
data[offset + 31] = (byte)character.Experience;
|
||||||
|
|
||||||
// Stats
|
// Stats
|
||||||
BinaryPrimitives.WriteInt16LittleEndian(data.Slice(52 + (i * 132), 2), character.Stats.Strength);
|
BinaryPrimitives.WriteInt16LittleEndian(data.Slice(offset + 32, 2), character.Stats.Strength);
|
||||||
BinaryPrimitives.WriteInt16LittleEndian(data.Slice(54 + (i * 132), 2), character.Stats.Dexterity);
|
BinaryPrimitives.WriteInt16LittleEndian(data.Slice(offset + 34, 2), character.Stats.Dexterity);
|
||||||
BinaryPrimitives.WriteInt16LittleEndian(data.Slice(56 + (i * 132), 2), character.Stats.Intelligence);
|
BinaryPrimitives.WriteInt16LittleEndian(data.Slice(offset + 36, 2), character.Stats.Intelligence);
|
||||||
BinaryPrimitives.WriteInt16LittleEndian(data.Slice(58 + (i * 132), 2), character.Stats.Vitality);
|
BinaryPrimitives.WriteInt16LittleEndian(data.Slice(offset + 38, 2), character.Stats.Vitality);
|
||||||
BinaryPrimitives.WriteInt16LittleEndian(data.Slice(60 + (i * 132), 2), character.Stats.Luck);
|
BinaryPrimitives.WriteInt16LittleEndian(data.Slice(offset + 40, 2), character.Stats.Luck);
|
||||||
BinaryPrimitives.WriteInt16LittleEndian(data.Slice(62 + (i * 132), 2), character.Stats.Wisdom);
|
BinaryPrimitives.WriteInt16LittleEndian(data.Slice(offset + 42, 2), character.Stats.Wisdom);
|
||||||
|
|
||||||
BinaryPrimitives.WriteInt32LittleEndian(data.Slice(64 + (i * 132), 4), character.Health);
|
BinaryPrimitives.WriteInt32LittleEndian(data.Slice(offset + 44, 4), character.Health);
|
||||||
BinaryPrimitives.WriteInt32LittleEndian(data.Slice(68 + (i * 132), 4), character.Mana);
|
BinaryPrimitives.WriteInt32LittleEndian(data.Slice(offset + 48, 4), character.Mana);
|
||||||
|
|
||||||
for (var j = 0; j < 20; j++)
|
for (var j = 0; j < 20; j++)
|
||||||
{
|
{
|
||||||
// Equipped Items
|
// Equipped Items
|
||||||
BinaryPrimitives.WriteUInt16LittleEndian(data.Slice(72 + (i * 132) + (j * 2), 2),
|
BinaryPrimitives.WriteUInt16LittleEndian(data.Slice(offset + 52 + j * 2, 2),
|
||||||
character.EquippedItems.Length > j ? character.EquippedItems[j] : (ushort)0);
|
character.EquippedItems.Length > j ? character.EquippedItems[j] : (ushort)0);
|
||||||
|
|
||||||
// Equipped Cash Items
|
// Equipped Cash Items
|
||||||
BinaryPrimitives.WriteUInt16LittleEndian(data.Slice(112 + (i * 132) + (j * 2), 2),
|
BinaryPrimitives.WriteUInt16LittleEndian(data.Slice(offset + 92 + j * 2, 2),
|
||||||
character.EquippedCashItems.Length > j ? character.EquippedCashItems[j] : (ushort)0);
|
character.EquippedCashItems.Length > j ? character.EquippedCashItems[j] : (ushort)0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,8 @@ public class CharacterCreationResponsePacket : IPacket
|
||||||
{
|
{
|
||||||
Span<byte> data = stackalloc byte[1 + 132];
|
Span<byte> data = stackalloc byte[1 + 132];
|
||||||
data[0] = isDuplicate ? (byte)1 : (byte)0;
|
data[0] = isDuplicate ? (byte)1 : (byte)0;
|
||||||
|
|
||||||
|
// Character Data
|
||||||
BinaryPrimitives.WriteInt32LittleEndian(data.Slice(1, 4), Slot);
|
BinaryPrimitives.WriteInt32LittleEndian(data.Slice(1, 4), Slot);
|
||||||
Encoding.ASCII.GetBytes(Character.Name, data.Slice(5, 20));
|
Encoding.ASCII.GetBytes(Character.Name, data.Slice(5, 20));
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue