Server ban exemption system (#15076)

This commit is contained in:
Pieter-Jan Briers
2023-04-03 02:24:55 +02:00
committed by GitHub
parent e037d12899
commit c8e90e561b
26 changed files with 8681 additions and 135 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,34 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Content.Server.Database.Migrations.Postgres
{
public partial class ProfileTraitIndexUnique : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropIndex(
name: "IX_trait_profile_id",
table: "trait");
migrationBuilder.CreateIndex(
name: "IX_trait_profile_id_trait_name",
table: "trait",
columns: new[] { "profile_id", "trait_name" },
unique: true);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropIndex(
name: "IX_trait_profile_id_trait_name",
table: "trait");
migrationBuilder.CreateIndex(
name: "IX_trait_profile_id",
table: "trait",
column: "profile_id");
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,43 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Content.Server.Database.Migrations.Postgres
{
public partial class ServerBanExemption : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<int>(
name: "exempt_flags",
table: "server_ban",
type: "integer",
nullable: false,
defaultValue: 0);
migrationBuilder.CreateTable(
name: "server_ban_exemption",
columns: table => new
{
user_id = table.Column<Guid>(type: "uuid", nullable: false),
flags = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_server_ban_exemption", x => x.user_id);
table.CheckConstraint("FlagsNotZero", "flags != 0");
});
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "server_ban_exemption");
migrationBuilder.DropColumn(
name: "exempt_flags",
table: "server_ban");
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,29 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Content.Server.Database.Migrations.Postgres
{
/// <inheritdoc />
public partial class BanAutoDelete : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<bool>(
name: "auto_delete",
table: "server_ban",
type: "boolean",
nullable: false,
defaultValue: false);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "auto_delete",
table: "server_ban");
}
}
}

View File

@@ -19,7 +19,7 @@ namespace Content.Server.Database.Migrations.Postgres
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "6.0.5")
.HasAnnotation("ProductVersion", "7.0.4")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
@@ -302,8 +302,7 @@ namespace Content.Server.Database.Migrations.Postgres
b.HasKey("Id")
.HasName("PK_admin_rank_flag");
b.HasIndex("AdminRankId")
.HasDatabaseName("IX_admin_rank_flag_admin_rank_id");
b.HasIndex("AdminRankId");
b.HasIndex("Flag", "AdminRankId")
.IsUnique();
@@ -408,9 +407,10 @@ namespace Content.Server.Database.Migrations.Postgres
b.HasIndex("UserId");
b.ToTable("connection_log", (string)null);
b.HasCheckConstraint("AddressNotIPv6MappedIPv4", "NOT inet '::ffff:0.0.0.0/96' >>= address");
b.ToTable("connection_log", null, t =>
{
t.HasCheckConstraint("AddressNotIPv6MappedIPv4", "NOT inet '::ffff:0.0.0.0/96' >>= address");
});
});
modelBuilder.Entity("Content.Server.Database.Job", b =>
@@ -438,8 +438,7 @@ namespace Content.Server.Database.Migrations.Postgres
b.HasKey("Id")
.HasName("PK_job");
b.HasIndex("ProfileId")
.HasDatabaseName("IX_job_profile_id");
b.HasIndex("ProfileId");
b.HasIndex("ProfileId", "JobName")
.IsUnique();
@@ -451,6 +450,37 @@ namespace Content.Server.Database.Migrations.Postgres
b.ToTable("job", (string)null);
});
modelBuilder.Entity("Content.Server.Database.PlayTime", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasColumnName("play_time_id");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<Guid>("PlayerId")
.HasColumnType("uuid")
.HasColumnName("player_id");
b.Property<TimeSpan>("TimeSpent")
.HasColumnType("interval")
.HasColumnName("time_spent");
b.Property<string>("Tracker")
.IsRequired()
.HasColumnType("text")
.HasColumnName("tracker");
b.HasKey("Id")
.HasName("PK_play_time");
b.HasIndex("PlayerId", "Tracker")
.IsUnique();
b.ToTable("play_time", (string)null);
});
modelBuilder.Entity("Content.Server.Database.Player", b =>
{
b.Property<int>("Id")
@@ -501,40 +531,10 @@ namespace Content.Server.Database.Migrations.Postgres
b.HasIndex("UserId")
.IsUnique();
b.ToTable("player", (string)null);
b.HasCheckConstraint("LastSeenAddressNotIPv6MappedIPv4", "NOT inet '::ffff:0.0.0.0/96' >>= last_seen_address");
});
modelBuilder.Entity("Content.Server.Database.PlayTime", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasColumnName("play_time_id");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<Guid>("PlayerId")
.HasColumnType("uuid")
.HasColumnName("player_id");
b.Property<TimeSpan>("TimeSpent")
.HasColumnType("interval")
.HasColumnName("time_spent");
b.Property<string>("Tracker")
.IsRequired()
.HasColumnType("text")
.HasColumnName("tracker");
b.HasKey("Id")
.HasName("PK_play_time");
b.HasIndex("PlayerId", "Tracker")
.IsUnique();
b.ToTable("play_time", (string)null);
b.ToTable("player", null, t =>
{
t.HasCheckConstraint("LastSeenAddressNotIPv6MappedIPv4", "NOT inet '::ffff:0.0.0.0/96' >>= last_seen_address");
});
});
modelBuilder.Entity("Content.Server.Database.Preference", b =>
@@ -729,6 +729,10 @@ namespace Content.Server.Database.Migrations.Postgres
.HasColumnType("inet")
.HasColumnName("address");
b.Property<bool>("AutoDelete")
.HasColumnType("boolean")
.HasColumnName("auto_delete");
b.Property<DateTime>("BanTime")
.HasColumnType("timestamp with time zone")
.HasColumnName("ban_time");
@@ -737,6 +741,10 @@ namespace Content.Server.Database.Migrations.Postgres
.HasColumnType("uuid")
.HasColumnName("banning_admin");
b.Property<int>("ExemptFlags")
.HasColumnType("integer")
.HasColumnName("exempt_flags");
b.Property<DateTime?>("ExpirationTime")
.HasColumnType("timestamp with time zone")
.HasColumnName("expiration_time");
@@ -761,11 +769,32 @@ namespace Content.Server.Database.Migrations.Postgres
b.HasIndex("UserId");
b.ToTable("server_ban", (string)null);
b.ToTable("server_ban", null, t =>
{
t.HasCheckConstraint("AddressNotIPv6MappedIPv4", "NOT inet '::ffff:0.0.0.0/96' >>= address");
b.HasCheckConstraint("AddressNotIPv6MappedIPv4", "NOT inet '::ffff:0.0.0.0/96' >>= address");
t.HasCheckConstraint("HaveEitherAddressOrUserIdOrHWId", "address IS NOT NULL OR user_id IS NOT NULL OR hwid IS NOT NULL");
});
});
b.HasCheckConstraint("HaveEitherAddressOrUserIdOrHWId", "address IS NOT NULL OR user_id IS NOT NULL OR hwid IS NOT NULL");
modelBuilder.Entity("Content.Server.Database.ServerBanExemption", b =>
{
b.Property<Guid>("UserId")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("user_id");
b.Property<int>("Flags")
.HasColumnType("integer")
.HasColumnName("flags");
b.HasKey("UserId")
.HasName("PK_server_ban_exemption");
b.ToTable("server_ban_exemption", null, t =>
{
t.HasCheckConstraint("FlagsNotZero", "flags != 0");
});
});
modelBuilder.Entity("Content.Server.Database.ServerBanHit", b =>
@@ -847,11 +876,12 @@ namespace Content.Server.Database.Migrations.Postgres
b.HasIndex("UserId");
b.ToTable("server_role_ban", (string)null);
b.ToTable("server_role_ban", null, t =>
{
t.HasCheckConstraint("AddressNotIPv6MappedIPv4", "NOT inet '::ffff:0.0.0.0/96' >>= address");
b.HasCheckConstraint("AddressNotIPv6MappedIPv4", "NOT inet '::ffff:0.0.0.0/96' >>= address");
b.HasCheckConstraint("HaveEitherAddressOrUserIdOrHWId", "address IS NOT NULL OR user_id IS NOT NULL OR hwid IS NOT NULL");
t.HasCheckConstraint("HaveEitherAddressOrUserIdOrHWId", "address IS NOT NULL OR user_id IS NOT NULL OR hwid IS NOT NULL");
});
});
modelBuilder.Entity("Content.Server.Database.ServerRoleUnban", b =>
@@ -935,8 +965,8 @@ namespace Content.Server.Database.Migrations.Postgres
b.HasKey("Id")
.HasName("PK_trait");
b.HasIndex("ProfileId")
.HasDatabaseName("IX_trait_profile_id");
b.HasIndex("ProfileId", "TraitName")
.IsUnique();
b.ToTable("trait", (string)null);
});

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,34 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Content.Server.Database.Migrations.Sqlite
{
public partial class ProfileTraitIndexUnique : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropIndex(
name: "IX_trait_profile_id",
table: "trait");
migrationBuilder.CreateIndex(
name: "IX_trait_profile_id_trait_name",
table: "trait",
columns: new[] { "profile_id", "trait_name" },
unique: true);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropIndex(
name: "IX_trait_profile_id_trait_name",
table: "trait");
migrationBuilder.CreateIndex(
name: "IX_trait_profile_id",
table: "trait",
column: "profile_id");
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,43 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Content.Server.Database.Migrations.Sqlite
{
public partial class ServerBanExemption : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<int>(
name: "exempt_flags",
table: "server_ban",
type: "INTEGER",
nullable: false,
defaultValue: 0);
migrationBuilder.CreateTable(
name: "server_ban_exemption",
columns: table => new
{
user_id = table.Column<Guid>(type: "TEXT", nullable: false),
flags = table.Column<int>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_server_ban_exemption", x => x.user_id);
table.CheckConstraint("FlagsNotZero", "flags != 0");
});
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "server_ban_exemption");
migrationBuilder.DropColumn(
name: "exempt_flags",
table: "server_ban");
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,29 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Content.Server.Database.Migrations.Sqlite
{
/// <inheritdoc />
public partial class BanAutoDelete : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<bool>(
name: "auto_delete",
table: "server_ban",
type: "INTEGER",
nullable: false,
defaultValue: false);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "auto_delete",
table: "server_ban");
}
}
}

View File

@@ -15,7 +15,7 @@ namespace Content.Server.Database.Migrations.Sqlite
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "6.0.5");
modelBuilder.HasAnnotation("ProductVersion", "7.0.4");
modelBuilder.Entity("Content.Server.Database.Admin", b =>
{
@@ -278,8 +278,7 @@ namespace Content.Server.Database.Migrations.Sqlite
b.HasKey("Id")
.HasName("PK_admin_rank_flag");
b.HasIndex("AdminRankId")
.HasDatabaseName("IX_admin_rank_flag_admin_rank_id");
b.HasIndex("AdminRankId");
b.HasIndex("Flag", "AdminRankId")
.IsUnique();
@@ -404,8 +403,7 @@ namespace Content.Server.Database.Migrations.Sqlite
b.HasKey("Id")
.HasName("PK_job");
b.HasIndex("ProfileId")
.HasDatabaseName("IX_job_profile_id");
b.HasIndex("ProfileId");
b.HasIndex("ProfileId", "JobName")
.IsUnique();
@@ -417,6 +415,35 @@ namespace Content.Server.Database.Migrations.Sqlite
b.ToTable("job", (string)null);
});
modelBuilder.Entity("Content.Server.Database.PlayTime", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER")
.HasColumnName("play_time_id");
b.Property<Guid>("PlayerId")
.HasColumnType("TEXT")
.HasColumnName("player_id");
b.Property<TimeSpan>("TimeSpent")
.HasColumnType("TEXT")
.HasColumnName("time_spent");
b.Property<string>("Tracker")
.IsRequired()
.HasColumnType("TEXT")
.HasColumnName("tracker");
b.HasKey("Id")
.HasName("PK_play_time");
b.HasIndex("PlayerId", "Tracker")
.IsUnique();
b.ToTable("play_time", (string)null);
});
modelBuilder.Entity("Content.Server.Database.Player", b =>
{
b.Property<int>("Id")
@@ -468,35 +495,6 @@ namespace Content.Server.Database.Migrations.Sqlite
b.ToTable("player", (string)null);
});
modelBuilder.Entity("Content.Server.Database.PlayTime", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER")
.HasColumnName("play_time_id");
b.Property<Guid>("PlayerId")
.HasColumnType("TEXT")
.HasColumnName("player_id");
b.Property<TimeSpan>("TimeSpent")
.HasColumnType("TEXT")
.HasColumnName("time_spent");
b.Property<string>("Tracker")
.IsRequired()
.HasColumnType("TEXT")
.HasColumnName("tracker");
b.HasKey("Id")
.HasName("PK_play_time");
b.HasIndex("PlayerId", "Tracker")
.IsUnique();
b.ToTable("play_time", (string)null);
});
modelBuilder.Entity("Content.Server.Database.Preference", b =>
{
b.Property<int>("Id")
@@ -679,6 +677,10 @@ namespace Content.Server.Database.Migrations.Sqlite
.HasColumnType("TEXT")
.HasColumnName("address");
b.Property<bool>("AutoDelete")
.HasColumnType("INTEGER")
.HasColumnName("auto_delete");
b.Property<DateTime>("BanTime")
.HasColumnType("TEXT")
.HasColumnName("ban_time");
@@ -687,6 +689,10 @@ namespace Content.Server.Database.Migrations.Sqlite
.HasColumnType("TEXT")
.HasColumnName("banning_admin");
b.Property<int>("ExemptFlags")
.HasColumnType("INTEGER")
.HasColumnName("exempt_flags");
b.Property<DateTime?>("ExpirationTime")
.HasColumnType("TEXT")
.HasColumnName("expiration_time");
@@ -711,9 +717,30 @@ namespace Content.Server.Database.Migrations.Sqlite
b.HasIndex("UserId");
b.ToTable("server_ban", (string)null);
b.ToTable("server_ban", null, t =>
{
t.HasCheckConstraint("HaveEitherAddressOrUserIdOrHWId", "address IS NOT NULL OR user_id IS NOT NULL OR hwid IS NOT NULL");
});
});
b.HasCheckConstraint("HaveEitherAddressOrUserIdOrHWId", "address IS NOT NULL OR user_id IS NOT NULL OR hwid IS NOT NULL");
modelBuilder.Entity("Content.Server.Database.ServerBanExemption", b =>
{
b.Property<Guid>("UserId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT")
.HasColumnName("user_id");
b.Property<int>("Flags")
.HasColumnType("INTEGER")
.HasColumnName("flags");
b.HasKey("UserId")
.HasName("PK_server_ban_exemption");
b.ToTable("server_ban_exemption", null, t =>
{
t.HasCheckConstraint("FlagsNotZero", "flags != 0");
});
});
modelBuilder.Entity("Content.Server.Database.ServerBanHit", b =>
@@ -791,9 +818,10 @@ namespace Content.Server.Database.Migrations.Sqlite
b.HasIndex("UserId");
b.ToTable("server_role_ban", (string)null);
b.HasCheckConstraint("HaveEitherAddressOrUserIdOrHWId", "address IS NOT NULL OR user_id IS NOT NULL OR hwid IS NOT NULL");
b.ToTable("server_role_ban", null, t =>
{
t.HasCheckConstraint("HaveEitherAddressOrUserIdOrHWId", "address IS NOT NULL OR user_id IS NOT NULL OR hwid IS NOT NULL");
});
});
modelBuilder.Entity("Content.Server.Database.ServerRoleUnban", b =>
@@ -871,8 +899,8 @@ namespace Content.Server.Database.Migrations.Sqlite
b.HasKey("Id")
.HasName("PK_trait");
b.HasIndex("ProfileId")
.HasDatabaseName("IX_trait_profile_id");
b.HasIndex("ProfileId", "TraitName")
.IsUnique();
b.ToTable("trait", (string)null);
});