Working on Networking

This commit is contained in:
dingo
2025-11-07 09:03:02 -05:00
parent 6c4ba9b568
commit 28f7c83b64
24 changed files with 2023 additions and 20 deletions
@@ -0,0 +1,327 @@
using System;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace SystemRevivalServer.Migrations
{
/// <inheritdoc />
public partial class InitialGameSchema : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterDatabase()
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "accounts",
columns: table => new
{
Id = table.Column<ulong>(type: "bigint unsigned", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
Username = table.Column<string>(type: "varchar(32)", maxLength: 32, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
Email = table.Column<string>(type: "varchar(255)", maxLength: 255, nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
PasswordHash = table.Column<byte[]>(type: "varbinary(64)", nullable: false),
PasswordSalt = table.Column<byte[]>(type: "varbinary(32)", nullable: false),
IsBanned = table.Column<bool>(type: "tinyint(1)", nullable: false),
BannedUntil = table.Column<DateTime>(type: "datetime(6)", nullable: true),
CreatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP(6)"),
UpdatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP(6)")
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.ComputedColumn)
},
constraints: table =>
{
table.PrimaryKey("PK_accounts", x => x.Id);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "item_templates",
columns: table => new
{
Id = table.Column<ulong>(type: "bigint unsigned", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
Name = table.Column<string>(type: "varchar(64)", maxLength: 64, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
ItemType = table.Column<byte>(type: "tinyint unsigned", nullable: false),
Rarity = table.Column<byte>(type: "tinyint unsigned", nullable: false),
MaxStack = table.Column<uint>(type: "int unsigned", nullable: false),
Weight = table.Column<uint>(type: "int unsigned", nullable: false),
StatsJson = table.Column<string>(type: "json", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
CreatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP(6)"),
UpdatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP(6)")
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.ComputedColumn)
},
constraints: table =>
{
table.PrimaryKey("PK_item_templates", x => x.Id);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "zones",
columns: table => new
{
Id = table.Column<ulong>(type: "bigint unsigned", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
Name = table.Column<string>(type: "varchar(64)", maxLength: 64, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
MinX = table.Column<double>(type: "double", nullable: false),
MinY = table.Column<double>(type: "double", nullable: false),
MinZ = table.Column<double>(type: "double", nullable: false),
MaxX = table.Column<double>(type: "double", nullable: false),
MaxY = table.Column<double>(type: "double", nullable: false),
MaxZ = table.Column<double>(type: "double", nullable: false),
CreatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP(6)"),
UpdatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP(6)")
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.ComputedColumn)
},
constraints: table =>
{
table.PrimaryKey("PK_zones", x => x.Id);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "sessions",
columns: table => new
{
Id = table.Column<ulong>(type: "bigint unsigned", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
AccountId = table.Column<ulong>(type: "bigint unsigned", nullable: false),
Token = table.Column<string>(type: "varchar(64)", maxLength: 64, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
ExpiresAt = table.Column<DateTime>(type: "datetime(6)", nullable: false),
CreatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP(6)")
},
constraints: table =>
{
table.PrimaryKey("PK_sessions", x => x.Id);
table.ForeignKey(
name: "FK_sessions_accounts_AccountId",
column: x => x.AccountId,
principalTable: "accounts",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "characters",
columns: table => new
{
Id = table.Column<ulong>(type: "bigint unsigned", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
AccountId = table.Column<ulong>(type: "bigint unsigned", nullable: false),
Name = table.Column<string>(type: "varchar(32)", maxLength: 32, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
Level = table.Column<uint>(type: "int unsigned", nullable: false),
Xp = table.Column<ulong>(type: "bigint unsigned", nullable: false),
StatStrength = table.Column<uint>(type: "int unsigned", nullable: false),
StatDexterity = table.Column<uint>(type: "int unsigned", nullable: false),
StatWisdom = table.Column<uint>(type: "int unsigned", nullable: false),
StatIntelligence = table.Column<uint>(type: "int unsigned", nullable: false),
StatEndurance = table.Column<uint>(type: "int unsigned", nullable: false),
HpCurrent = table.Column<uint>(type: "int unsigned", nullable: false),
HpMax = table.Column<uint>(type: "int unsigned", nullable: false),
MpCurrent = table.Column<uint>(type: "int unsigned", nullable: false),
MpMax = table.Column<uint>(type: "int unsigned", nullable: false),
StaminaCurrent = table.Column<uint>(type: "int unsigned", nullable: false),
StaminaMax = table.Column<uint>(type: "int unsigned", nullable: false),
ZoneId = table.Column<ulong>(type: "bigint unsigned", nullable: false),
PosX = table.Column<double>(type: "double", nullable: false),
PosY = table.Column<double>(type: "double", nullable: false),
PosZ = table.Column<double>(type: "double", nullable: false),
FacingDeg = table.Column<float>(type: "float", nullable: false),
AppearanceJson = table.Column<string>(type: "json", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
CreatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP(6)"),
UpdatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP(6)")
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.ComputedColumn)
},
constraints: table =>
{
table.PrimaryKey("PK_characters", x => x.Id);
table.ForeignKey(
name: "FK_characters_accounts_AccountId",
column: x => x.AccountId,
principalTable: "accounts",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_characters_zones_ZoneId",
column: x => x.ZoneId,
principalTable: "zones",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "equipment",
columns: table => new
{
Id = table.Column<ulong>(type: "bigint unsigned", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
CharacterId = table.Column<ulong>(type: "bigint unsigned", nullable: false),
SlotCode = table.Column<byte>(type: "tinyint unsigned", nullable: false),
ItemTemplateId = table.Column<ulong>(type: "bigint unsigned", nullable: false),
CreatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP(6)"),
UpdatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP(6)")
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.ComputedColumn)
},
constraints: table =>
{
table.PrimaryKey("PK_equipment", x => x.Id);
table.ForeignKey(
name: "FK_equipment_characters_CharacterId",
column: x => x.CharacterId,
principalTable: "characters",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_equipment_item_templates_ItemTemplateId",
column: x => x.ItemTemplateId,
principalTable: "item_templates",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "inventories",
columns: table => new
{
Id = table.Column<ulong>(type: "bigint unsigned", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
CharacterId = table.Column<ulong>(type: "bigint unsigned", nullable: false),
SlotIndex = table.Column<uint>(type: "int unsigned", nullable: false),
ItemTemplateId = table.Column<ulong>(type: "bigint unsigned", nullable: false),
Quantity = table.Column<uint>(type: "int unsigned", nullable: false),
CreatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP(6)"),
UpdatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP(6)")
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.ComputedColumn)
},
constraints: table =>
{
table.PrimaryKey("PK_inventories", x => x.Id);
table.ForeignKey(
name: "FK_inventories_characters_CharacterId",
column: x => x.CharacterId,
principalTable: "characters",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_inventories_item_templates_ItemTemplateId",
column: x => x.ItemTemplateId,
principalTable: "item_templates",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateIndex(
name: "IX_accounts_Email",
table: "accounts",
column: "Email",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_accounts_Username",
table: "accounts",
column: "Username",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_characters_AccountId",
table: "characters",
column: "AccountId",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_characters_ZoneId",
table: "characters",
column: "ZoneId");
migrationBuilder.CreateIndex(
name: "IX_equipment_CharacterId_SlotCode",
table: "equipment",
columns: new[] { "CharacterId", "SlotCode" },
unique: true);
migrationBuilder.CreateIndex(
name: "IX_equipment_ItemTemplateId",
table: "equipment",
column: "ItemTemplateId");
migrationBuilder.CreateIndex(
name: "IX_inventories_CharacterId",
table: "inventories",
column: "CharacterId");
migrationBuilder.CreateIndex(
name: "IX_inventories_CharacterId_SlotIndex",
table: "inventories",
columns: new[] { "CharacterId", "SlotIndex" },
unique: true);
migrationBuilder.CreateIndex(
name: "IX_inventories_ItemTemplateId",
table: "inventories",
column: "ItemTemplateId");
migrationBuilder.CreateIndex(
name: "IX_item_templates_Name",
table: "item_templates",
column: "Name",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_sessions_AccountId",
table: "sessions",
column: "AccountId");
migrationBuilder.CreateIndex(
name: "IX_sessions_Token",
table: "sessions",
column: "Token",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_zones_Name",
table: "zones",
column: "Name",
unique: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "equipment");
migrationBuilder.DropTable(
name: "inventories");
migrationBuilder.DropTable(
name: "sessions");
migrationBuilder.DropTable(
name: "characters");
migrationBuilder.DropTable(
name: "item_templates");
migrationBuilder.DropTable(
name: "accounts");
migrationBuilder.DropTable(
name: "zones");
}
}
}