feat: initial character data

This commit is contained in:
Timothy Schenk 2023-08-14 22:30:35 +02:00
parent 756031b186
commit 8816fb2944
5 changed files with 23 additions and 1 deletions

View file

@ -18,4 +18,5 @@ public class Account
public string Email { get; set; }
public byte PermissionLevel { get; set; }
public byte[] Salt { get; set; }
public ICollection<Character> Characters { get; } = new List<Character>();
}

View file

@ -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; }
}

View file

@ -17,6 +17,7 @@ public class WonderkingContext : DbContext
}
public DbSet<Account> Accounts { get; set; }
public DbSet<Character> 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<Character>(builder =>
{
builder.HasKey(c => c.Id);
builder.HasOne<Account>().WithOne().HasForeignKey("AccountId").IsRequired();
builder.Property(c => c.Name).HasColumnType("varchar(20)");
});
}

View file

@ -77,6 +77,7 @@ public class LoginHandler : IPacketHandler<LoginInfoPacket>
IsGameMaster = true
};
var sess = session as AuthSession;
sess.AccountId = account.Id;
sess.Send(loginResponsePacket);
}
}

View file

@ -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);