From 8816fb2944a493940a21b33f7b4e03a513234588 Mon Sep 17 00:00:00 2001 From: Timothy Schenk Date: Mon, 14 Aug 2023 22:30:35 +0200 Subject: [PATCH] feat: initial character data --- Server/DB/Documents/Account.cs | 1 + Server/DB/Documents/Character.cs | 12 ++++++++++++ Server/DB/WonderkingContext.cs | 7 +++++++ Server/PacketHandlers/LoginHandler.cs | 1 + Server/Services/PacketDistributorService.cs | 3 ++- 5 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 Server/DB/Documents/Character.cs diff --git a/Server/DB/Documents/Account.cs b/Server/DB/Documents/Account.cs index 336db96..b360b74 100644 --- a/Server/DB/Documents/Account.cs +++ b/Server/DB/Documents/Account.cs @@ -18,4 +18,5 @@ public class Account public string Email { get; set; } public byte PermissionLevel { get; set; } public byte[] Salt { get; set; } + public ICollection Characters { get; } = new List(); } diff --git a/Server/DB/Documents/Character.cs b/Server/DB/Documents/Character.cs new file mode 100644 index 0000000..9303404 --- /dev/null +++ b/Server/DB/Documents/Character.cs @@ -0,0 +1,12 @@ +namespace Server.DB.Documents; + +using Microsoft.EntityFrameworkCore.Metadata.Internal; + +public class Character +{ + public Guid AccountId { get; set; } + public Account Account { get; set; } = null!; + public Guid Id { get; set; } + public ushort MapId { get; set; } + public string Name { get; set; } +} diff --git a/Server/DB/WonderkingContext.cs b/Server/DB/WonderkingContext.cs index 23fe41f..4ad9982 100644 --- a/Server/DB/WonderkingContext.cs +++ b/Server/DB/WonderkingContext.cs @@ -17,6 +17,7 @@ public class WonderkingContext : DbContext } public DbSet Accounts { get; set; } + public DbSet Characters { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) => optionsBuilder @@ -31,5 +32,11 @@ public class WonderkingContext : DbContext builder.Property(b => b.Password).HasColumnType("bytea"); builder.Property(b => b.Salt).HasColumnType("bytea"); builder.HasKey(b => b.Id); + builder.HasMany(e => e.Characters).WithOne(e => e.Account).HasForeignKey(e => e.AccountId).IsRequired(); + }).Entity(builder => + { + builder.HasKey(c => c.Id); + builder.HasOne().WithOne().HasForeignKey("AccountId").IsRequired(); + builder.Property(c => c.Name).HasColumnType("varchar(20)"); }); } diff --git a/Server/PacketHandlers/LoginHandler.cs b/Server/PacketHandlers/LoginHandler.cs index d0fc443..f205658 100644 --- a/Server/PacketHandlers/LoginHandler.cs +++ b/Server/PacketHandlers/LoginHandler.cs @@ -77,6 +77,7 @@ public class LoginHandler : IPacketHandler IsGameMaster = true }; var sess = session as AuthSession; + sess.AccountId = account.Id; sess.Send(loginResponsePacket); } } diff --git a/Server/Services/PacketDistributorService.cs b/Server/Services/PacketDistributorService.cs index 458f0e8..40b17bf 100644 --- a/Server/Services/PacketDistributorService.cs +++ b/Server/Services/PacketDistributorService.cs @@ -9,6 +9,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Microsoft.VisualBasic.CompilerServices; +using Newtonsoft.Json; using PacketHandlers; using Packets; using static DotNext.Metaprogramming.CodeGenerator; @@ -142,10 +143,10 @@ public class PacketDistributorService : IHostedService } var packet = this.deserializationMap[item.OperationCode](item.MessageBody); + this.logger.LogInformation("Packet data {PacketData}", JsonConvert.SerializeObject(packet)); this.packetHandlersInstantiation[item.OperationCode].GetType().GetMethod("HandleAsync") ?.Invoke(this.packetHandlersInstantiation[item.OperationCode], new object[] { packet, item.Session }); - //this.logger.LogDebug("Packet data {PacketData}", JsonConvert.SerializeObject(packet)); this.logger.LogTrace("[{TempId}] Packet with ID: {MessageOperationCode} has finished", item.Session.Id, item.OperationCode);