Working on Networking
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Server.Data;
|
||||
|
||||
public sealed class Account
|
||||
{
|
||||
public ulong Id { get; set; }
|
||||
public string Username { get; set; } = "";
|
||||
public string? Email { get; set; }
|
||||
public byte[] PasswordHash { get; set; } = Array.Empty<byte>();
|
||||
public byte[] PasswordSalt { get; set; } = Array.Empty<byte>();
|
||||
public bool IsBanned { get; set; }
|
||||
public DateTime? BannedUntil { get; set; }
|
||||
public DateTime CreatedAt { get; set; }
|
||||
public DateTime UpdatedAt { get; set; }
|
||||
|
||||
public ICollection<Session> Sessions { get; set; } = new List<Session>();
|
||||
public ICollection<Character> Characters { get; set; } = new List<Character>();
|
||||
}
|
||||
|
||||
public sealed class AccountConfig : IEntityTypeConfiguration<Account>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<Account> e)
|
||||
{
|
||||
e.ToTable("accounts");
|
||||
e.HasKey(x => x.Id);
|
||||
e.Property(x => x.Id).ValueGeneratedOnAdd();
|
||||
e.Property(x => x.Username).HasMaxLength(32).IsRequired();
|
||||
e.Property(x => x.Email).HasMaxLength(255);
|
||||
e.HasIndex(x => x.Username).IsUnique();
|
||||
e.HasIndex(x => x.Email).IsUnique();
|
||||
e.Property(x => x.PasswordHash).HasColumnType("varbinary(64)");
|
||||
e.Property(x => x.PasswordSalt).HasColumnType("varbinary(32)");
|
||||
e.Property(x => x.CreatedAt).HasDefaultValueSql("CURRENT_TIMESTAMP(6)");
|
||||
e.Property(x => x.UpdatedAt).HasDefaultValueSql("CURRENT_TIMESTAMP(6)")
|
||||
.ValueGeneratedOnAddOrUpdate();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Server.Data;
|
||||
|
||||
public sealed class Character
|
||||
{
|
||||
public ulong Id { get; set; }
|
||||
public ulong AccountId { get; set; }
|
||||
public string Name { get; set; } = "";
|
||||
|
||||
public uint Level { get; set; } = 1;
|
||||
public ulong Xp { get; set; } = 0;
|
||||
|
||||
public uint StatStrength { get; set; } = 1;
|
||||
public uint StatDexterity { get; set; } = 1;
|
||||
public uint StatWisdom { get; set; } = 1;
|
||||
public uint StatIntelligence { get; set; } = 1;
|
||||
public uint StatEndurance { get; set; } = 1;
|
||||
|
||||
public uint HpCurrent { get; set; } = 10;
|
||||
public uint HpMax { get; set; } = 10;
|
||||
public uint MpCurrent { get; set; } = 0;
|
||||
public uint MpMax { get; set; } = 0;
|
||||
public uint StaminaCurrent { get; set; } = 0;
|
||||
public uint StaminaMax { get; set; } = 0;
|
||||
|
||||
public ulong ZoneId { get; set; }
|
||||
public double PosX { get; set; }
|
||||
public double PosY { get; set; }
|
||||
public double PosZ { get; set; }
|
||||
public float FacingDeg { get; set; }
|
||||
|
||||
// store as JSON in MySQL 8
|
||||
public string? AppearanceJson { get; set; }
|
||||
|
||||
public DateTime CreatedAt { get; set; }
|
||||
public DateTime UpdatedAt { get; set; }
|
||||
|
||||
public Account? Account { get; set; }
|
||||
public Zone? Zone { get; set; }
|
||||
}
|
||||
|
||||
public sealed class CharacterConfig : IEntityTypeConfiguration<Character>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<Character> e)
|
||||
{
|
||||
e.ToTable("characters");
|
||||
e.HasKey(x => x.Id);
|
||||
e.Property(x => x.Id).ValueGeneratedOnAdd();
|
||||
e.Property(x => x.Name).HasMaxLength(32).IsRequired();
|
||||
|
||||
e.HasIndex(x => x.AccountId).IsUnique(); // 1 character per account (change later if needed)
|
||||
e.HasIndex(x => x.ZoneId);
|
||||
|
||||
e.Property(x => x.AppearanceJson).HasColumnType("json");
|
||||
e.Property(x => x.CreatedAt).HasDefaultValueSql("CURRENT_TIMESTAMP(6)");
|
||||
e.Property(x => x.UpdatedAt).HasDefaultValueSql("CURRENT_TIMESTAMP(6)")
|
||||
.ValueGeneratedOnAddOrUpdate();
|
||||
|
||||
e.HasOne(x => x.Account).WithMany(a => a.Characters).HasForeignKey(x => x.AccountId).OnDelete(DeleteBehavior.Cascade);
|
||||
e.HasOne(x => x.Zone).WithMany().HasForeignKey(x => x.ZoneId).OnDelete(DeleteBehavior.Restrict);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Server.Data;
|
||||
|
||||
public sealed class EquipmentSlot
|
||||
{
|
||||
public ulong Id { get; set; }
|
||||
public ulong CharacterId { get; set; }
|
||||
public byte SlotCode { get; set; } // 1=head,2=chest,...
|
||||
public ulong ItemTemplateId { get; set; }
|
||||
public DateTime CreatedAt { get; set; }
|
||||
public DateTime UpdatedAt { get; set; }
|
||||
|
||||
public Character? Character { get; set; }
|
||||
public ItemTemplate? ItemTemplate { get; set; }
|
||||
}
|
||||
|
||||
public sealed class EquipmentSlotConfig : IEntityTypeConfiguration<EquipmentSlot>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<EquipmentSlot> e)
|
||||
{
|
||||
e.ToTable("equipment");
|
||||
e.HasKey(x => x.Id);
|
||||
e.Property(x => x.Id).ValueGeneratedOnAdd();
|
||||
e.HasIndex(x => new { x.CharacterId, x.SlotCode }).IsUnique();
|
||||
e.Property(x => x.CreatedAt).HasDefaultValueSql("CURRENT_TIMESTAMP(6)");
|
||||
e.Property(x => x.UpdatedAt).HasDefaultValueSql("CURRENT_TIMESTAMP(6)")
|
||||
.ValueGeneratedOnAddOrUpdate();
|
||||
|
||||
e.HasOne(x => x.Character).WithMany().HasForeignKey(x => x.CharacterId).OnDelete(DeleteBehavior.Cascade);
|
||||
e.HasOne(x => x.ItemTemplate).WithMany().HasForeignKey(x => x.ItemTemplateId).OnDelete(DeleteBehavior.Restrict);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Server.Data;
|
||||
|
||||
public sealed class InventoryItem
|
||||
{
|
||||
public ulong Id { get; set; }
|
||||
public ulong CharacterId { get; set; }
|
||||
public uint SlotIndex { get; set; }
|
||||
public ulong ItemTemplateId { get; set; }
|
||||
public uint Quantity { get; set; } = 1;
|
||||
public DateTime CreatedAt { get; set; }
|
||||
public DateTime UpdatedAt { get; set; }
|
||||
|
||||
public Character? Character { get; set; }
|
||||
public ItemTemplate? ItemTemplate { get; set; }
|
||||
}
|
||||
|
||||
public sealed class InventoryItemConfig : IEntityTypeConfiguration<InventoryItem>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<InventoryItem> e)
|
||||
{
|
||||
e.ToTable("inventories");
|
||||
e.HasKey(x => x.Id);
|
||||
e.Property(x => x.Id).ValueGeneratedOnAdd();
|
||||
e.HasIndex(x => new { x.CharacterId, x.SlotIndex }).IsUnique();
|
||||
e.HasIndex(x => x.CharacterId);
|
||||
e.Property(x => x.CreatedAt).HasDefaultValueSql("CURRENT_TIMESTAMP(6)");
|
||||
e.Property(x => x.UpdatedAt).HasDefaultValueSql("CURRENT_TIMESTAMP(6)")
|
||||
.ValueGeneratedOnAddOrUpdate();
|
||||
|
||||
e.HasOne(x => x.Character).WithMany().HasForeignKey(x => x.CharacterId).OnDelete(DeleteBehavior.Cascade);
|
||||
e.HasOne(x => x.ItemTemplate).WithMany().HasForeignKey(x => x.ItemTemplateId).OnDelete(DeleteBehavior.Restrict);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Server.Data;
|
||||
|
||||
public sealed class ItemTemplate
|
||||
{
|
||||
public ulong Id { get; set; }
|
||||
public string Name { get; set; } = "";
|
||||
public byte ItemType { get; set; } = 1;
|
||||
public byte Rarity { get; set; } = 1;
|
||||
public uint MaxStack { get; set; } = 1;
|
||||
public uint Weight { get; set; } = 0;
|
||||
public string? StatsJson { get; set; }
|
||||
public DateTime CreatedAt { get; set; }
|
||||
public DateTime UpdatedAt { get; set; }
|
||||
}
|
||||
|
||||
public sealed class ItemTemplateConfig : IEntityTypeConfiguration<ItemTemplate>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<ItemTemplate> e)
|
||||
{
|
||||
e.ToTable("item_templates");
|
||||
e.HasKey(x => x.Id);
|
||||
e.Property(x => x.Id).ValueGeneratedOnAdd();
|
||||
e.Property(x => x.Name).HasMaxLength(64).IsRequired();
|
||||
e.HasIndex(x => x.Name).IsUnique();
|
||||
e.Property(x => x.StatsJson).HasColumnType("json");
|
||||
e.Property(x => x.CreatedAt).HasDefaultValueSql("CURRENT_TIMESTAMP(6)");
|
||||
e.Property(x => x.UpdatedAt).HasDefaultValueSql("CURRENT_TIMESTAMP(6)")
|
||||
.ValueGeneratedOnAddOrUpdate();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Server.Data;
|
||||
|
||||
public sealed class Session
|
||||
{
|
||||
public ulong Id { get; set; }
|
||||
public ulong AccountId { get; set; }
|
||||
public string Token { get; set; } = ""; // 64-char base64url/hex
|
||||
public DateTime ExpiresAt { get; set; }
|
||||
public DateTime CreatedAt { get; set; }
|
||||
|
||||
public Account? Account { get; set; }
|
||||
}
|
||||
|
||||
public sealed class SessionConfig : IEntityTypeConfiguration<Session>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<Session> e)
|
||||
{
|
||||
e.ToTable("sessions");
|
||||
e.HasKey(x => x.Id);
|
||||
e.Property(x => x.Id).ValueGeneratedOnAdd();
|
||||
e.HasIndex(x => x.Token).IsUnique();
|
||||
e.HasIndex(x => x.AccountId);
|
||||
e.Property(x => x.Token).HasMaxLength(64).IsRequired();
|
||||
e.Property(x => x.CreatedAt).HasDefaultValueSql("CURRENT_TIMESTAMP(6)");
|
||||
e.HasOne(x => x.Account).WithMany(a => a.Sessions).HasForeignKey(x => x.AccountId).OnDelete(DeleteBehavior.Cascade);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Server.Data;
|
||||
|
||||
public sealed class Zone
|
||||
{
|
||||
public ulong Id { get; set; }
|
||||
public string Name { get; set; } = "";
|
||||
public double MinX { get; set; }
|
||||
public double MinY { get; set; }
|
||||
public double MinZ { get; set; }
|
||||
public double MaxX { get; set; }
|
||||
public double MaxY { get; set; }
|
||||
public double MaxZ { get; set; }
|
||||
public DateTime CreatedAt { get; set; }
|
||||
public DateTime UpdatedAt { get; set; }
|
||||
}
|
||||
|
||||
public sealed class ZoneConfig : IEntityTypeConfiguration<Zone>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<Zone> e)
|
||||
{
|
||||
e.ToTable("zones");
|
||||
e.HasKey(x => x.Id);
|
||||
e.Property(x => x.Id).ValueGeneratedOnAdd();
|
||||
e.Property(x => x.Name).HasMaxLength(64).IsRequired();
|
||||
e.HasIndex(x => x.Name).IsUnique();
|
||||
e.Property(x => x.CreatedAt).HasDefaultValueSql("CURRENT_TIMESTAMP(6)");
|
||||
e.Property(x => x.UpdatedAt).HasDefaultValueSql("CURRENT_TIMESTAMP(6)")
|
||||
.ValueGeneratedOnAddOrUpdate();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user