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.severity = warning
# Disable warnings for using LoggerMessage delegates
dotnet_diagnostic.CA1848.severity = none
##########################################
# License
##########################################

View file

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

View file

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

View file

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

View file

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

View file

@ -1,10 +1,10 @@
namespace Server.DB.Documents;
namespace Server.DB.Documents;
public class Character
{
public byte ServerId { get; set; }
public Guid AccountId { get; set; }
public Account Account { get; set; } = null!;
public Account Account { get; set; }
public Guid Id { get; set; }
public ushort MapId { 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
{

View file

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

View file

@ -1,17 +1,13 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Server.DB.Migrations
{
namespace Server.DB.Migrations;
using Microsoft.EntityFrameworkCore.Migrations;
/// <inheritdoc />
public partial class Initial : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
protected override void Up(MigrationBuilder migrationBuilder) => migrationBuilder.CreateTable(
name: "Accounts",
columns: table => new
{
@ -22,17 +18,9 @@ namespace Server.DB.Migrations
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);
});
}
constraints: table => table.PrimaryKey("PK_Accounts", x => x.Id));
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
protected override void Down(MigrationBuilder migrationBuilder) => migrationBuilder.DropTable(
name: "Accounts");
}
}
}

View file

@ -1,10 +1,8 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Server.DB.Migrations
{
namespace Server.DB.Migrations;
using Microsoft.EntityFrameworkCore.Migrations;
/// <inheritdoc />
public partial class CharacterDataDraft : Migration
{
@ -97,7 +95,7 @@ namespace Server.DB.Migrations
table: "Accounts",
type: "bytea",
nullable: false,
defaultValue: new byte[0],
defaultValue: Array.Empty<byte>(),
oldClrType: typeof(byte[]),
oldType: "bytea",
oldNullable: true);
@ -107,7 +105,7 @@ namespace Server.DB.Migrations
table: "Accounts",
type: "bytea",
nullable: false,
defaultValue: new byte[0],
defaultValue: Array.Empty<byte>(),
oldClrType: typeof(byte[]),
oldType: "bytea",
oldNullable: true);
@ -123,4 +121,3 @@ namespace Server.DB.Migrations
oldNullable: true);
}
}
}

View file

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

View file

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

View file

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

View file

@ -1,4 +1,4 @@
namespace Server.PacketHandlers;
namespace Server.PacketHandlers;
using System.Security.Cryptography;
using System.Text;
@ -33,10 +33,12 @@ public class LoginHandler : IPacketHandler<LoginInfoPacket>
// 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."
var argon2Id = new Argon2id(Encoding.ASCII.GetBytes(packet.Password));
argon2Id.MemorySize = 1024 * 19;
argon2Id.Iterations = 2;
argon2Id.DegreeOfParallelism = 1;
var argon2Id = new Argon2id(Encoding.ASCII.GetBytes(packet.Password))
{
MemorySize = 1024 * 19,
Iterations = 2,
DegreeOfParallelism = 1
};
if (account == null)
{
if (this.configuration.GetSection("Testing").GetValue<bool>("CreateAccountOnLogin"))
@ -44,13 +46,13 @@ public class LoginHandler : IPacketHandler<LoginInfoPacket>
argon2Id.Salt = RandomNumberGenerator.GetBytes(16);
var finalAccount =
await this.wonderkingContext.Accounts.AddAsync(new Account(packet.Username, Array.Empty<byte>(), "",
0, argon2Id.Salt));
await this.wonderkingContext.SaveChangesAsync();
0, argon2Id.Salt)).ConfigureAwait(true);
await this.wonderkingContext.SaveChangesAsync().ConfigureAwait(true);
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);
loginResponseReason = LoginResponseReason.Ok;
await this.wonderkingContext.SaveChangesAsync();
await this.wonderkingContext.SaveChangesAsync().ConfigureAwait(true);
}
else
{
@ -62,7 +64,7 @@ public class LoginHandler : IPacketHandler<LoginInfoPacket>
{
argon2Id.Salt = account.Salt;
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.Ok
: LoginResponseReason.WrongPassword;

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,4 +1,4 @@
#pragma warning disable AV1500
#pragma warning disable AV1500
using System.Net;
using System.Reflection;
using MassTransit;
@ -38,8 +38,8 @@ using var host = builder.Build();
await using (var scope = host.Services.CreateAsyncScope())
{
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

View file

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

View file

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

View file

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

View file

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