chore: apply dotnet format
All checks were successful
Test if Server can be built / build-server (push) Successful in 22s

This commit is contained in:
Timothy Schenk 2023-10-12 09:15:34 +02:00
parent a6b804dfe7
commit 1455bdd75a
29 changed files with 178 additions and 215 deletions

View file

@ -414,6 +414,9 @@ dotnet_naming_rule.parameters_rule.symbols = parameters_group
dotnet_naming_rule.parameters_rule.style = camel_case_style dotnet_naming_rule.parameters_rule.style = camel_case_style
dotnet_naming_rule.parameters_rule.severity = warning dotnet_naming_rule.parameters_rule.severity = warning
# Disable warnings for using LoggerMessage delegates
dotnet_diagnostic.CA1848.severity = none
########################################## ##########################################
# License # License
########################################## ##########################################

View file

@ -1,4 +1,4 @@
namespace Benchmarks; namespace Benchmarks;
using System.Security.Cryptography; using System.Security.Cryptography;
using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Attributes;

View file

@ -1,4 +1,4 @@
using System.Reflection; using System.Reflection;
using BenchmarkDotNet.Running; using BenchmarkDotNet.Running;
BenchmarkRunner.Run(Assembly.GetExecutingAssembly()); BenchmarkRunner.Run(Assembly.GetExecutingAssembly());

View file

@ -1,4 +1,4 @@
namespace Server; namespace Server;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Text; using System.Text;
@ -30,7 +30,9 @@ public class ChannelSession : TcpSession
aes.Key = Key; aes.Key = Key;
aes.IV = Iv; aes.IV = Iv;
aes.Padding = PaddingMode.None; aes.Padding = PaddingMode.None;
#pragma warning disable SEC0026
aes.Mode = CipherMode.ECB; aes.Mode = CipherMode.ECB;
#pragma warning restore SEC0026
this.decryptor = aes.CreateDecryptor(aes.Key, aes.IV); this.decryptor = aes.CreateDecryptor(aes.Key, aes.IV);
this.encryptor = aes.CreateEncryptor(aes.Key, aes.IV); this.encryptor = aes.CreateEncryptor(aes.Key, aes.IV);

View file

@ -1,4 +1,4 @@
namespace Server.Consumers; namespace Server.Consumers;
using MassTransit; using MassTransit;
using Packets; using Packets;

View file

@ -1,4 +1,4 @@
namespace Server.DB.Documents; namespace Server.DB.Documents;
public class Account public class Account
{ {

View file

@ -1,10 +1,10 @@
namespace Server.DB.Documents; namespace Server.DB.Documents;
public class Character public class Character
{ {
public byte ServerId { get; set; } public byte ServerId { get; set; }
public Guid AccountId { get; set; } public Guid AccountId { get; set; }
public Account Account { get; set; } = null!; public Account Account { get; set; }
public Guid Id { get; set; } public Guid Id { get; set; }
public ushort MapId { get; set; } public ushort MapId { get; set; }
public string Name { get; set; } public string Name { get; set; }

View file

@ -1,4 +1,4 @@
namespace Server.DB.Documents; namespace Server.DB.Documents;
public enum Gender : byte public enum Gender : byte
{ {

View file

@ -1,4 +1,4 @@
namespace Server.DB.Documents; namespace Server.DB.Documents;
public enum PvPLevel : byte public enum PvPLevel : byte
{ {

View file

@ -1,38 +1,26 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable #nullable disable
namespace Server.DB.Migrations namespace Server.DB.Migrations;
using Microsoft.EntityFrameworkCore.Migrations;
/// <inheritdoc />
public partial class Initial : Migration
{ {
/// <inheritdoc /> /// <inheritdoc />
public partial class Initial : Migration protected override void Up(MigrationBuilder migrationBuilder) => migrationBuilder.CreateTable(
{ name: "Accounts",
/// <inheritdoc /> columns: table => new
protected override void Up(MigrationBuilder migrationBuilder) {
{ Id = table.Column<Guid>(type: "uuid", nullable: false),
migrationBuilder.CreateTable( Username = table.Column<string>(type: "varchar(20)", nullable: false),
name: "Accounts", Password = table.Column<byte[]>(type: "bytea", nullable: false),
columns: table => new Email = table.Column<string>(type: "text", nullable: false),
{ PermissionLevel = table.Column<byte>(type: "smallint", nullable: false),
Id = table.Column<Guid>(type: "uuid", nullable: false), Salt = table.Column<byte[]>(type: "bytea", nullable: false)
Username = table.Column<string>(type: "varchar(20)", nullable: false), },
Password = table.Column<byte[]>(type: "bytea", nullable: false), constraints: table => table.PrimaryKey("PK_Accounts", x => x.Id));
Email = table.Column<string>(type: "text", nullable: false),
PermissionLevel = table.Column<byte>(type: "smallint", nullable: false),
Salt = table.Column<byte[]>(type: "bytea", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Accounts", x => x.Id);
});
}
/// <inheritdoc /> /// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder) protected override void Down(MigrationBuilder migrationBuilder) => migrationBuilder.DropTable(
{ name: "Accounts");
migrationBuilder.DropTable(
name: "Accounts");
}
}
} }

View file

@ -1,126 +1,123 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable #nullable disable
namespace Server.DB.Migrations namespace Server.DB.Migrations;
using Microsoft.EntityFrameworkCore.Migrations;
/// <inheritdoc />
public partial class CharacterDataDraft : Migration
{ {
/// <inheritdoc /> /// <inheritdoc />
public partial class CharacterDataDraft : Migration protected override void Up(MigrationBuilder migrationBuilder)
{ {
/// <inheritdoc /> migrationBuilder.AlterColumn<string>(
protected override void Up(MigrationBuilder migrationBuilder) name: "Username",
{ table: "Accounts",
migrationBuilder.AlterColumn<string>( type: "varchar(20)",
name: "Username", nullable: true,
table: "Accounts", oldClrType: typeof(string),
type: "varchar(20)", oldType: "varchar(20)");
nullable: true,
oldClrType: typeof(string),
oldType: "varchar(20)");
migrationBuilder.AlterColumn<byte[]>( migrationBuilder.AlterColumn<byte[]>(
name: "Salt", name: "Salt",
table: "Accounts", table: "Accounts",
type: "bytea", type: "bytea",
nullable: true, nullable: true,
oldClrType: typeof(byte[]), oldClrType: typeof(byte[]),
oldType: "bytea"); oldType: "bytea");
migrationBuilder.AlterColumn<byte[]>( migrationBuilder.AlterColumn<byte[]>(
name: "Password", name: "Password",
table: "Accounts", table: "Accounts",
type: "bytea", type: "bytea",
nullable: true, nullable: true,
oldClrType: typeof(byte[]), oldClrType: typeof(byte[]),
oldType: "bytea"); oldType: "bytea");
migrationBuilder.AlterColumn<string>( migrationBuilder.AlterColumn<string>(
name: "Email", name: "Email",
table: "Accounts", table: "Accounts",
type: "text", type: "text",
nullable: true, nullable: true,
oldClrType: typeof(string), oldClrType: typeof(string),
oldType: "text"); oldType: "text");
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
name: "Characters", name: "Characters",
columns: table => new columns: table => new
{ {
Id = table.Column<Guid>(type: "uuid", nullable: false), Id = table.Column<Guid>(type: "uuid", nullable: false),
ServerId = table.Column<byte>(type: "smallint", nullable: false), ServerId = table.Column<byte>(type: "smallint", nullable: false),
AccountId = table.Column<Guid>(type: "uuid", nullable: false), AccountId = table.Column<Guid>(type: "uuid", nullable: false),
MapId = table.Column<int>(type: "integer", nullable: false), MapId = table.Column<int>(type: "integer", nullable: false),
Name = table.Column<string>(type: "varchar(20)", nullable: true), Name = table.Column<string>(type: "varchar(20)", nullable: true),
LastXCoordinate = table.Column<short>(type: "smallint", nullable: false), LastXCoordinate = table.Column<short>(type: "smallint", nullable: false),
LastYCoordinate = table.Column<short>(type: "smallint", nullable: false), LastYCoordinate = table.Column<short>(type: "smallint", nullable: false),
PvPLevel = table.Column<byte>(type: "smallint", nullable: false), PvPLevel = table.Column<byte>(type: "smallint", nullable: false),
Gender = table.Column<byte>(type: "smallint", nullable: false), Gender = table.Column<byte>(type: "smallint", nullable: false),
Experience = table.Column<long>(type: "bigint", nullable: false), Experience = table.Column<long>(type: "bigint", nullable: false),
Level = table.Column<byte>(type: "smallint", nullable: false) Level = table.Column<byte>(type: "smallint", nullable: false)
}, },
constraints: table => constraints: table =>
{ {
table.PrimaryKey("PK_Characters", x => x.Id); table.PrimaryKey("PK_Characters", x => x.Id);
table.ForeignKey( table.ForeignKey(
name: "FK_Characters_Accounts_AccountId", name: "FK_Characters_Accounts_AccountId",
column: x => x.AccountId, column: x => x.AccountId,
principalTable: "Accounts", principalTable: "Accounts",
principalColumn: "Id", principalColumn: "Id",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
}); });
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "IX_Characters_AccountId", name: "IX_Characters_AccountId",
table: "Characters", table: "Characters",
column: "AccountId"); column: "AccountId");
} }
/// <inheritdoc /> /// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder) protected override void Down(MigrationBuilder migrationBuilder)
{ {
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "Characters"); name: "Characters");
migrationBuilder.AlterColumn<string>( migrationBuilder.AlterColumn<string>(
name: "Username", name: "Username",
table: "Accounts", table: "Accounts",
type: "varchar(20)", type: "varchar(20)",
nullable: false, nullable: false,
defaultValue: "", defaultValue: "",
oldClrType: typeof(string), oldClrType: typeof(string),
oldType: "varchar(20)", oldType: "varchar(20)",
oldNullable: true); oldNullable: true);
migrationBuilder.AlterColumn<byte[]>( migrationBuilder.AlterColumn<byte[]>(
name: "Salt", name: "Salt",
table: "Accounts", table: "Accounts",
type: "bytea", type: "bytea",
nullable: false, nullable: false,
defaultValue: new byte[0], defaultValue: Array.Empty<byte>(),
oldClrType: typeof(byte[]), oldClrType: typeof(byte[]),
oldType: "bytea", oldType: "bytea",
oldNullable: true); oldNullable: true);
migrationBuilder.AlterColumn<byte[]>( migrationBuilder.AlterColumn<byte[]>(
name: "Password", name: "Password",
table: "Accounts", table: "Accounts",
type: "bytea", type: "bytea",
nullable: false, nullable: false,
defaultValue: new byte[0], defaultValue: Array.Empty<byte>(),
oldClrType: typeof(byte[]), oldClrType: typeof(byte[]),
oldType: "bytea", oldType: "bytea",
oldNullable: true); oldNullable: true);
migrationBuilder.AlterColumn<string>( migrationBuilder.AlterColumn<string>(
name: "Email", name: "Email",
table: "Accounts", table: "Accounts",
type: "text", type: "text",
nullable: false, nullable: false,
defaultValue: "", defaultValue: "",
oldClrType: typeof(string), oldClrType: typeof(string),
oldType: "text", oldType: "text",
oldNullable: true); oldNullable: true);
}
} }
} }

View file

@ -1,4 +1,4 @@
namespace Server.DB; namespace Server.DB;
using Documents; using Documents;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;

View file

@ -1,4 +1,4 @@
namespace Server.PacketHandlers; namespace Server.PacketHandlers;
using DB; using DB;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;

View file

@ -1,4 +1,4 @@
namespace Server.PacketHandlers; namespace Server.PacketHandlers;
using JetBrains.Annotations; using JetBrains.Annotations;
using NetCoreServer; using NetCoreServer;

View file

@ -1,4 +1,4 @@
namespace Server.PacketHandlers; namespace Server.PacketHandlers;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Text; using System.Text;
@ -33,10 +33,12 @@ public class LoginHandler : IPacketHandler<LoginInfoPacket>
// https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Chea1t_Sheet.html#argon2id // https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Chea1t_Sheet.html#argon2id
// "Use Argon2id with a minimum configuration of 19 MiB of memory, an iteration count of 2, and 1 degree of parallelism." // "Use Argon2id with a minimum configuration of 19 MiB of memory, an iteration count of 2, and 1 degree of parallelism."
var argon2Id = new Argon2id(Encoding.ASCII.GetBytes(packet.Password)); var argon2Id = new Argon2id(Encoding.ASCII.GetBytes(packet.Password))
argon2Id.MemorySize = 1024 * 19; {
argon2Id.Iterations = 2; MemorySize = 1024 * 19,
argon2Id.DegreeOfParallelism = 1; Iterations = 2,
DegreeOfParallelism = 1
};
if (account == null) if (account == null)
{ {
if (this.configuration.GetSection("Testing").GetValue<bool>("CreateAccountOnLogin")) if (this.configuration.GetSection("Testing").GetValue<bool>("CreateAccountOnLogin"))
@ -44,13 +46,13 @@ public class LoginHandler : IPacketHandler<LoginInfoPacket>
argon2Id.Salt = RandomNumberGenerator.GetBytes(16); argon2Id.Salt = RandomNumberGenerator.GetBytes(16);
var finalAccount = var finalAccount =
await this.wonderkingContext.Accounts.AddAsync(new Account(packet.Username, Array.Empty<byte>(), "", await this.wonderkingContext.Accounts.AddAsync(new Account(packet.Username, Array.Empty<byte>(), "",
0, argon2Id.Salt)); 0, argon2Id.Salt)).ConfigureAwait(true);
await this.wonderkingContext.SaveChangesAsync(); await this.wonderkingContext.SaveChangesAsync().ConfigureAwait(true);
argon2Id.AssociatedData = finalAccount.Entity.Id.ToByteArray(); argon2Id.AssociatedData = finalAccount.Entity.Id.ToByteArray();
finalAccount.Entity.Password = await argon2Id.GetBytesAsync(16); finalAccount.Entity.Password = await argon2Id.GetBytesAsync(16).ConfigureAwait(true);
this.wonderkingContext.Accounts.Update(finalAccount.Entity); this.wonderkingContext.Accounts.Update(finalAccount.Entity);
loginResponseReason = LoginResponseReason.Ok; loginResponseReason = LoginResponseReason.Ok;
await this.wonderkingContext.SaveChangesAsync(); await this.wonderkingContext.SaveChangesAsync().ConfigureAwait(true);
} }
else else
{ {
@ -62,7 +64,7 @@ public class LoginHandler : IPacketHandler<LoginInfoPacket>
{ {
argon2Id.Salt = account.Salt; argon2Id.Salt = account.Salt;
argon2Id.AssociatedData = account.Id.ToByteArray(); argon2Id.AssociatedData = account.Id.ToByteArray();
var tempPasswordBytes = await argon2Id.GetBytesAsync(16); var tempPasswordBytes = await argon2Id.GetBytesAsync(16).ConfigureAwait(true);
loginResponseReason = tempPasswordBytes.SequenceEqual(account.Password) loginResponseReason = tempPasswordBytes.SequenceEqual(account.Password)
? LoginResponseReason.Ok ? LoginResponseReason.Ok
: LoginResponseReason.WrongPassword; : LoginResponseReason.WrongPassword;

View file

@ -1,4 +1,4 @@
namespace Server.Packets; namespace Server.Packets;
using JetBrains.Annotations; using JetBrains.Annotations;

View file

@ -1,4 +1,4 @@
namespace Server.Packets.Incoming; namespace Server.Packets.Incoming;
[PacketId(OperationCode.ChannelSelection)] [PacketId(OperationCode.ChannelSelection)]
public class ChannelSelectionPacket : IPacket public class ChannelSelectionPacket : IPacket

View file

@ -1,4 +1,4 @@
namespace Server.Packets.Incoming; namespace Server.Packets.Incoming;
using System.Text; using System.Text;

View file

@ -1,4 +1,4 @@
namespace Server.Packets; namespace Server.Packets;
public enum OperationCode : ushort public enum OperationCode : ushort
{ {

View file

@ -1,4 +1,4 @@
namespace Server.Packets.Outgoing; namespace Server.Packets.Outgoing;
[PacketId(OperationCode.LoginResponse)] [PacketId(OperationCode.LoginResponse)]
public class LoginResponsePacket : IPacket public class LoginResponsePacket : IPacket

View file

@ -1,4 +1,4 @@
namespace Server.Packets.Outgoing; namespace Server.Packets.Outgoing;
public enum LoginResponseReason : byte public enum LoginResponseReason : byte
{ {

View file

@ -1,4 +1,4 @@
namespace Server.Packets.Outgoing; namespace Server.Packets.Outgoing;
public struct ServerChannelData public struct ServerChannelData
{ {

View file

@ -1,4 +1,4 @@
namespace Server.Packets; namespace Server.Packets;
[AttributeUsage(AttributeTargets.Class, Inherited = false)] [AttributeUsage(AttributeTargets.Class, Inherited = false)]
public class PacketIdAttribute : Attribute public class PacketIdAttribute : Attribute

View file

@ -1,4 +1,4 @@
namespace Server.Packets; namespace Server.Packets;
using MassTransit; using MassTransit;

View file

@ -1,4 +1,4 @@
#pragma warning disable AV1500 #pragma warning disable AV1500
using System.Net; using System.Net;
using System.Reflection; using System.Reflection;
using MassTransit; using MassTransit;
@ -38,8 +38,8 @@ using var host = builder.Build();
await using (var scope = host.Services.CreateAsyncScope()) await using (var scope = host.Services.CreateAsyncScope())
{ {
var db = scope.ServiceProvider.GetRequiredService<WonderkingContext>(); var db = scope.ServiceProvider.GetRequiredService<WonderkingContext>();
await db.Database.MigrateAsync(); await db.Database.MigrateAsync().ConfigureAwait(true);
} }
await host.RunAsync(); await host.RunAsync().ConfigureAwait(true);
#pragma warning restore AV1500 #pragma warning restore AV1500

View file

@ -1,4 +1,4 @@
namespace Server.Services; namespace Server.Services;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Collections.Immutable; using System.Collections.Immutable;
@ -12,8 +12,8 @@ using Microsoft.VisualBasic.CompilerServices;
using Newtonsoft.Json; using Newtonsoft.Json;
using PacketHandlers; using PacketHandlers;
using Packets; using Packets;
using static DotNext.Metaprogramming.CodeGenerator;
using static DotNext.Linq.Expressions.ExpressionBuilder; using static DotNext.Linq.Expressions.ExpressionBuilder;
using static DotNext.Metaprogramming.CodeGenerator;
public class PacketDistributorService : IHostedService public class PacketDistributorService : IHostedService
{ {
@ -79,11 +79,8 @@ public class PacketDistributorService : IHostedService
.ToDictionary(type => type.GetCustomAttribute<PacketIdAttribute>().Code); .ToDictionary(type => type.GetCustomAttribute<PacketIdAttribute>().Code);
if (packetsWithId is not { Count: 0 }) if (packetsWithId is not { Count: 0 })
{ {
packetsWithId.AsParallel().ForAll(packet => packetsWithId.AsParallel().ForAll(packet => this.logger.LogTrace("Packet with ID: {PacketID} has been added as {PacketName}", packet.Key,
{ packet.Value.FullName));
this.logger.LogTrace("Packet with ID: {PacketID} has been added as {PacketName}", packet.Key,
packet.Value.FullName);
});
return packetsWithId; return packetsWithId;
} }
@ -99,16 +96,13 @@ public class PacketDistributorService : IHostedService
i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IPacketHandler<>))).ToDictionary(type => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IPacketHandler<>))).ToDictionary(type =>
type.GetInterfaces().First(t => type.GetInterfaces().First(t =>
t is { IsGenericType: true } && t.GetGenericTypeDefinition() == typeof(IPacketHandler<>)) t is { IsGenericType: true } && t.GetGenericTypeDefinition() == typeof(IPacketHandler<>))
.GetGenericArguments().First().GetCustomAttribute<PacketIdAttribute>()!.Code); .GetGenericArguments().First().GetCustomAttribute<PacketIdAttribute>().Code);
if (packetHandlersWithId is not { Count: 0 }) if (packetHandlersWithId is not { Count: 0 })
{ {
packetHandlersWithId.AsParallel().ForAll(packetHandler => packetHandlersWithId.AsParallel().ForAll(packetHandler => this.logger.LogTrace("PacketHandler with ID: {PacketID} has been added as {PacketName}",
{
this.logger.LogTrace("PacketHandler with ID: {PacketID} has been added as {PacketName}",
packetHandler.Key, packetHandler.Key,
packetHandler.Value.FullName); packetHandler.Value.FullName));
});
return packetHandlersWithId; return packetHandlersWithId;
} }

View file

@ -1,4 +1,4 @@
namespace Server.Services; namespace Server.Services;
using System.Net; using System.Net;
using System.Net.Sockets; using System.Net.Sockets;

View file

@ -1,22 +1,10 @@
using System;
using System.Linq;
using Nuke.Common; using Nuke.Common;
using Nuke.Common.CI;
using Nuke.Common.CI.GitHubActions;
using Nuke.Common.Execution;
using Nuke.Common.Git; using Nuke.Common.Git;
using Nuke.Common.IO; using Nuke.Common.IO;
using Nuke.Common.ProjectModel;
using Nuke.Common.Tooling;
using Nuke.Common.Tools.CodeMetrics;
using Nuke.Common.Tools.Docker; using Nuke.Common.Tools.Docker;
using Nuke.Common.Tools.DotNet; using Nuke.Common.Tools.DotNet;
using Nuke.Common.Tools.SonarScanner; using Nuke.Common.Tools.SonarScanner;
using Nuke.Common.Utilities.Collections;
using Serilog; using Serilog;
using static Nuke.Common.EnvironmentInfo;
using static Nuke.Common.IO.FileSystemTasks;
using static Nuke.Common.IO.PathConstruction;
class Build : NukeBuild class Build : NukeBuild
{ {
@ -42,16 +30,10 @@ class Build : NukeBuild
Target Clean => _ => _ Target Clean => _ => _
.Before(Restore) .Before(Restore)
.Executes(() => .Executes(() => DotNetTasks.DotNetClean());
{
DotNetTasks.DotNetClean();
});
Target Restore => _ => _ Target Restore => _ => _
.Executes(() => .Executes(() => DotNetTasks.DotNetRestore());
{
DotNetTasks.DotNetRestore();
});
Target Compile => _ => _ Target Compile => _ => _
.DependsOn(Clean) .DependsOn(Clean)

View file

@ -1,6 +1,4 @@
using System;
using System.ComponentModel; using System.ComponentModel;
using System.Linq;
using Nuke.Common.Tooling; using Nuke.Common.Tooling;
[TypeConverter(typeof(TypeConverter<Configuration>))] [TypeConverter(typeof(TypeConverter<Configuration>))]
@ -9,8 +7,5 @@ public class Configuration : Enumeration
public static Configuration Debug { get; } = new() { Value = nameof(Debug) }; public static Configuration Debug { get; } = new() { Value = nameof(Debug) };
public static Configuration Release { get; } = new() { Value = nameof(Release) }; public static Configuration Release { get; } = new() { Value = nameof(Release) };
public static implicit operator string(Configuration configuration) public static implicit operator string(Configuration configuration) => configuration.Value;
{
return configuration.Value;
}
} }