login logout logs

This commit is contained in:
hydrant
2021-04-19 12:17:56 +02:00
parent 06de6ef1a4
commit f0b2eca560
8 changed files with 2211 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text;
namespace ReallifeGamemode.Database.Entities.Logs
{
public class LoginLogoutLogEntry
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public long Id { get; set; }
public string Username { get; set; }
public string SocialClubName { get; set; }
public User User { get; set; }
public long PlayerId { get; set; }
public string IpAddress { get; set; }
public bool LoginLogout { get; set; }
public DateTime Time { get; set; }
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,48 @@
using System;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
namespace ReallifeGamemode.Database.Migrations
{
public partial class LoginLogoutLogs : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "LoginLogoutLogs",
columns: table => new
{
Id = table.Column<long>(nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
Username = table.Column<string>(nullable: true),
SocialClubName = table.Column<string>(nullable: true),
UserId = table.Column<int>(nullable: true),
PlayerId = table.Column<long>(nullable: false),
IpAddress = table.Column<string>(nullable: true),
LoginLogout = table.Column<bool>(nullable: false),
Time = table.Column<DateTime>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_LoginLogoutLogs", x => x.Id);
table.ForeignKey(
name: "FK_LoginLogoutLogs_Users_UserId",
column: x => x.UserId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateIndex(
name: "IX_LoginLogoutLogs_UserId",
table: "LoginLogoutLogs",
column: "UserId");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "LoginLogoutLogs");
}
}
}

View File

@@ -872,6 +872,40 @@ namespace ReallifeGamemode.Database.Migrations
b.ToTable("DeathLogs");
});
modelBuilder.Entity("ReallifeGamemode.Database.Entities.Logs.LoginLogoutLogEntry", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint");
b.Property<string>("IpAddress")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<bool>("LoginLogout")
.HasColumnType("tinyint(1)");
b.Property<long>("PlayerId")
.HasColumnType("bigint");
b.Property<string>("SocialClubName")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<DateTime>("Time")
.HasColumnType("datetime(6)");
b.Property<int?>("UserId")
.HasColumnType("int");
b.Property<string>("Username")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("LoginLogoutLogs");
});
modelBuilder.Entity("ReallifeGamemode.Database.Entities.News", b =>
{
b.Property<int>("Id")
@@ -1898,6 +1932,13 @@ namespace ReallifeGamemode.Database.Migrations
.IsRequired();
});
modelBuilder.Entity("ReallifeGamemode.Database.Entities.Logs.LoginLogoutLogEntry", b =>
{
b.HasOne("ReallifeGamemode.Database.Entities.User", "User")
.WithMany()
.HasForeignKey("UserId");
});
modelBuilder.Entity("ReallifeGamemode.Database.Entities.News", b =>
{
b.HasOne("ReallifeGamemode.Database.Entities.User", "User")

View File

@@ -98,6 +98,7 @@ namespace ReallifeGamemode.Database.Models
public DbSet<Entities.Logs.BankAccountTransactionHistory> BankAccountTransactionLogs { get; set; }
public DbSet<Entities.Logs.Death> DeathLogs { get; set; }
public DbSet<Entities.Logs.CommandLogEntry> CommandLogs { get; set; }
public DbSet<Entities.Logs.LoginLogoutLogEntry> LoginLogoutLogs { get; set; }
//Saves
public DbSet<Entities.ATM> ATMs { get; set; }

View File

@@ -17,6 +17,7 @@ using ReallifeGamemode.Server.Report;
using ReallifeGamemode.Server.Factions.Medic;
using ReallifeGamemode.Server.Inventory.Interfaces;
using ReallifeGamemode.Server.Inventory;
using ReallifeGamemode.Database.Entities.Logs;
/**
* @overview Life of German Reallife - Event Login (Login.cs)
@@ -40,6 +41,19 @@ namespace ReallifeGamemode.Server.Events
return;
}
var logEntry = new LoginLogoutLogEntry()
{
LoginLogout = false,
User = user,
PlayerId = player.Handle.Value,
Username = player.Name,
SocialClubName = player.SocialClubName,
IpAddress = player.Address,
Time = DateTime.Now,
};
saveUser.LoginLogoutLogs.Add(logEntry);
if (type == DisconnectionType.Left)
{
NAPI.Util.ConsoleOutput(player.Name + " left");

View File

@@ -13,6 +13,7 @@ using ReallifeGamemode.Database.Entities;
using System;
using System.Collections.Generic;
using ReallifeGamemode.Server.Inventory.Interfaces;
using ReallifeGamemode.Database.Entities.Logs;
/**
* @overview Life of German Reallife - Event Login (Login.cs)
@@ -56,6 +57,20 @@ namespace ReallifeGamemode.Server.Events
return;
}
var logEntry = new LoginLogoutLogEntry()
{
IpAddress = player.Address,
User = user,
PlayerId = player.Handle.Value,
SocialClubName = player.SocialClubName,
Username = player.Name,
LoginLogout = true,
Time = DateTime.Now
};
dbContext.LoginLogoutLogs.Add(logEntry);
dbContext.SaveChanges();
player.SetData("dbId", user.Id);
player.Name = username;
player.TriggerEvent("SERVER:Login_Success");

View File

@@ -6,6 +6,7 @@ using ReallifeGamemode.Database.Models;
using ReallifeGamemode.Server.Extensions;
using ReallifeGamemode.Server.Util;
using System;
using ReallifeGamemode.Database.Entities.Logs;
/**
* @overview Life of German Reallife - Event Register (Register.cs)
@@ -51,7 +52,20 @@ namespace ReallifeGamemode.Server.Events
}
};
var logEntry = new LoginLogoutLogEntry()
{
IpAddress = player.Address,
User = user,
PlayerId = player.Handle.Value,
SocialClubName = player.SocialClubName,
Username = player.Name,
LoginLogout = true,
Time = DateTime.Now
};
dbContext.Users.Add(user);
dbContext.LoginLogoutLogs.Add(logEntry);
dbContext.SaveChanges();
player.SetData("dbId", user.Id);