Command Logs
This commit is contained in:
19
ReallifeGamemode.Database/Entities/Logs/CommandLogEntry.cs
Normal file
19
ReallifeGamemode.Database/Entities/Logs/CommandLogEntry.cs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace ReallifeGamemode.Database.Entities.Logs
|
||||||
|
{
|
||||||
|
public class CommandLogEntry
|
||||||
|
{
|
||||||
|
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||||
|
public long Id { get; set; }
|
||||||
|
|
||||||
|
public User User { get; set; }
|
||||||
|
|
||||||
|
public string Command { get; set; }
|
||||||
|
|
||||||
|
public DateTime Time { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
2010
ReallifeGamemode.Database/Migrations/20210419090246_CommandLogs.Designer.cs
generated
Normal file
2010
ReallifeGamemode.Database/Migrations/20210419090246_CommandLogs.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,44 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
namespace ReallifeGamemode.Database.Migrations
|
||||||
|
{
|
||||||
|
public partial class CommandLogs : Migration
|
||||||
|
{
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "CommandLogs",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<long>(nullable: false)
|
||||||
|
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
||||||
|
UserId = table.Column<int>(nullable: true),
|
||||||
|
Command = table.Column<string>(nullable: true),
|
||||||
|
Time = table.Column<DateTime>(nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_CommandLogs", x => x.Id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_CommandLogs_Users_UserId",
|
||||||
|
column: x => x.UserId,
|
||||||
|
principalTable: "Users",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Restrict);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_CommandLogs_UserId",
|
||||||
|
table: "CommandLogs",
|
||||||
|
column: "UserId");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "CommandLogs");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -797,6 +797,28 @@ namespace ReallifeGamemode.Database.Migrations
|
|||||||
b.ToTable("BankAccountTransactionLogs");
|
b.ToTable("BankAccountTransactionLogs");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("ReallifeGamemode.Database.Entities.Logs.CommandLogEntry", b =>
|
||||||
|
{
|
||||||
|
b.Property<long>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.Property<string>("Command")
|
||||||
|
.HasColumnType("longtext CHARACTER SET utf8mb4");
|
||||||
|
|
||||||
|
b.Property<DateTime>("Time")
|
||||||
|
.HasColumnType("datetime(6)");
|
||||||
|
|
||||||
|
b.Property<int?>("UserId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("UserId");
|
||||||
|
|
||||||
|
b.ToTable("CommandLogs");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("ReallifeGamemode.Database.Entities.Logs.Death", b =>
|
modelBuilder.Entity("ReallifeGamemode.Database.Entities.Logs.Death", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
@@ -1856,6 +1878,13 @@ namespace ReallifeGamemode.Database.Migrations
|
|||||||
.HasForeignKey("UserId");
|
.HasForeignKey("UserId");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("ReallifeGamemode.Database.Entities.Logs.CommandLogEntry", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("ReallifeGamemode.Database.Entities.User", "User")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("UserId");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("ReallifeGamemode.Database.Entities.Logs.Death", b =>
|
modelBuilder.Entity("ReallifeGamemode.Database.Entities.Logs.Death", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("ReallifeGamemode.Database.Entities.User", "Killer")
|
b.HasOne("ReallifeGamemode.Database.Entities.User", "Killer")
|
||||||
|
|||||||
@@ -97,6 +97,7 @@ namespace ReallifeGamemode.Database.Models
|
|||||||
//public DbSet<Logs.Ban> BanLogs { get; set; }
|
//public DbSet<Logs.Ban> BanLogs { get; set; }
|
||||||
public DbSet<Entities.Logs.BankAccountTransactionHistory> BankAccountTransactionLogs { get; set; }
|
public DbSet<Entities.Logs.BankAccountTransactionHistory> BankAccountTransactionLogs { get; set; }
|
||||||
public DbSet<Entities.Logs.Death> DeathLogs { get; set; }
|
public DbSet<Entities.Logs.Death> DeathLogs { get; set; }
|
||||||
|
public DbSet<Entities.Logs.CommandLogEntry> CommandLogs { get; set; }
|
||||||
|
|
||||||
//Saves
|
//Saves
|
||||||
public DbSet<Entities.ATM> ATMs { get; set; }
|
public DbSet<Entities.ATM> ATMs { get; set; }
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ using ReallifeGamemode.Server.Types;
|
|||||||
using ReallifeGamemode.Server.Common;
|
using ReallifeGamemode.Server.Common;
|
||||||
using ReallifeGamemode.Server.Log;
|
using ReallifeGamemode.Server.Log;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using ReallifeGamemode.Database.Entities.Logs;
|
||||||
|
using ReallifeGamemode.Server.Core.Extensions;
|
||||||
|
|
||||||
namespace ReallifeGamemode.Server.Core.Commands
|
namespace ReallifeGamemode.Server.Core.Commands
|
||||||
{
|
{
|
||||||
@@ -33,6 +35,18 @@ namespace ReallifeGamemode.Server.Core.Commands
|
|||||||
|
|
||||||
logger.LogInformation("Player '{Name}' executed command '{command}'", player.Name, command);
|
logger.LogInformation("Player '{Name}' executed command '{command}'", player.Name, command);
|
||||||
|
|
||||||
|
using var dbContext = Main.GetDbContext();
|
||||||
|
|
||||||
|
var commandLogEntry = new CommandLogEntry()
|
||||||
|
{
|
||||||
|
Command = "/" + string.Join(' ', args),
|
||||||
|
Time = DateTime.Now,
|
||||||
|
User = player.GetUser(dbContext)
|
||||||
|
};
|
||||||
|
|
||||||
|
dbContext.CommandLogs.Add(commandLogEntry);
|
||||||
|
dbContext.SaveChanges();
|
||||||
|
|
||||||
if (legacyCommands.Contains(command))
|
if (legacyCommands.Contains(command))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user