diff --git a/Benchmarks/Benchmarks.csproj b/Benchmarks/Benchmarks.csproj
index 3d08c42..405cb70 100644
--- a/Benchmarks/Benchmarks.csproj
+++ b/Benchmarks/Benchmarks.csproj
@@ -1,15 +1,15 @@
-
- Exe
- enable
- enable
- default
- net7.0
-
+
+ Exe
+ enable
+ enable
+ default
+ net7.0
+
-
-
-
+
+
+
diff --git a/Benchmarks/BinaryConversionBenchmarks.cs b/Benchmarks/BinaryConversionBenchmarks.cs
index 56c86b2..ed55306 100644
--- a/Benchmarks/BinaryConversionBenchmarks.cs
+++ b/Benchmarks/BinaryConversionBenchmarks.cs
@@ -21,29 +21,24 @@ public class BinaryConversionBenchmarks
[GlobalSetup]
public void Setup()
{
- data = RandomNumberGenerator.GetBytes(4000);
- offset = RandomNumberGenerator.GetInt32(0, 3500);
+ this.data = RandomNumberGenerator.GetBytes(4000);
+ this.offset = RandomNumberGenerator.GetInt32(0, 3500);
}
[Benchmark]
- public Int16 BitConverterTest()
- {
- return BitConverter.ToInt16(data, offset);
- }
+ public short BitConverterTest() => BitConverter.ToInt16(this.data, this.offset);
[Benchmark]
- public Int16 BinaryReader()
+ public short BinaryReader()
{
- using MemoryStream ms = new MemoryStream(data);
- using BinaryReader reader = new BinaryReader(ms);
- reader.BaseStream.Position = offset;
+ using var ms = new MemoryStream(this.data);
+ using var reader = new BinaryReader(ms);
+ reader.BaseStream.Position = this.offset;
return reader.ReadInt16();
}
[Benchmark]
- public Int16 BinaryPrimitives()
- {
- return System.Buffers.Binary.BinaryPrimitives.ReadInt16LittleEndian(
- new ArraySegment(data, offset, sizeof(short)));
- }
-}
\ No newline at end of file
+ public short BinaryPrimitives() =>
+ System.Buffers.Binary.BinaryPrimitives.ReadInt16LittleEndian(
+ new ArraySegment(this.data, this.offset, sizeof(short)));
+}
diff --git a/Benchmarks/Program.cs b/Benchmarks/Program.cs
index 2e87545..824e2d0 100644
--- a/Benchmarks/Program.cs
+++ b/Benchmarks/Program.cs
@@ -5,8 +5,5 @@ namespace Benchmarks;
internal class Program
{
- public static void Main(string[] args)
- {
- BenchmarkRunner.Run(Assembly.GetExecutingAssembly());
- }
-}
\ No newline at end of file
+ public static void Main(string[] args) => BenchmarkRunner.Run(Assembly.GetExecutingAssembly());
+}
diff --git a/Server/AuthSession.cs b/Server/AuthSession.cs
index f66a697..c0a7a23 100644
--- a/Server/AuthSession.cs
+++ b/Server/AuthSession.cs
@@ -15,26 +15,30 @@ public class AuthSession : TcpSession
public AuthSession(TcpServer
server, IMediator mediator, ILogger logger) : base(server)
{
- _mediator = mediator;
- _logger = logger;
+ this._mediator = mediator;
+ this._logger = logger;
}
public override long Send(byte[] buffer)
{
- _logger.LogInformation("Data being sent is: {Data}", BitConverter.ToString(buffer));
+ this._logger.LogInformation("Data being sent is: {Data}", BitConverter.ToString(buffer));
return base.Send(buffer);
}
public void Send(IPacket packet)
{
var type = packet.GetType();
- _logger.LogTrace("Packet of type {Type} is being serialized", type.Name);
+ this._logger.LogTrace("Packet of type {Type} is being serialized", type.Name);
var packetIdAttribute = type.GetCustomAttribute();
- if (packetIdAttribute == null) return;
+ if (packetIdAttribute == null)
+ {
+ return;
+ }
+
var opcode = packetIdAttribute.Code;
Span packetData = packet.Serialize();
- ushort length = (ushort)(packetData.Length + 8);
+ var length = (ushort)(packetData.Length + 8);
Span buffer = stackalloc byte[length];
buffer.Clear();
@@ -42,20 +46,20 @@ public class AuthSession : TcpSession
var bytesOfLength = BitConverter.GetBytes(length);
var bytesOfOpcode = BitConverter.GetBytes((ushort)opcode);
- for (int i = 0; i < bytesOfLength.Length || i < 2; i++)
+ for (var i = 0; i < bytesOfLength.Length || i < 2; i++)
{
buffer[i] = bytesOfLength[i];
}
- for (int i = 0; i < bytesOfOpcode.Length || i < 2; i++)
+ for (var i = 0; i < bytesOfOpcode.Length || i < 2; i++)
{
buffer[2 + i] = bytesOfOpcode[i];
}
- _logger.LogTrace("Packet data being parsed is: {Data}", BitConverter.ToString(packetData.ToArray()));
- _logger.LogTrace("Packet being parsed is: {Data}", BitConverter.ToString(buffer.ToArray()));
+ this._logger.LogTrace("Packet data being parsed is: {Data}", BitConverter.ToString(packetData.ToArray()));
+ this._logger.LogTrace("Packet being parsed is: {Data}", BitConverter.ToString(buffer.ToArray()));
- Send(buffer);
+ this.Send(buffer);
}
protected override void OnReceived(byte[] buffer, long offset, long size)
@@ -64,7 +68,7 @@ public class AuthSession : TcpSession
Span decryptedBuffer = new byte[size];
// xor every value after the first 8 bytes
- var dataBuffer = Decrypt(new ArraySegment(buffer, 8, (int)size - 8).ToArray());
+ var dataBuffer = this.Decrypt(new ArraySegment(buffer, 8, (int)size - 8).ToArray());
Console.WriteLine("Length " + BitConverter.ToUInt16(buffer, 0));
var opCode = BitConverter.ToUInt16(buffer.ToArray(), 2);
@@ -76,21 +80,20 @@ public class AuthSession : TcpSession
Console.WriteLine("Full buffer: " + Encoding.ASCII.GetString(dataBuffer.ToArray()));
- RawPacket rawPacket = new RawPacket((OperationCode)opCode, dataBuffer, clientAliveTime, buffer[0],
- buffer[3],
- Id, this);
- Task.Run(() => _mediator.Send(rawPacket));
- _logger.LogInformation("Connection from: {@RemoteEndpoint}", Socket.RemoteEndPoint?.ToString());
+ var rawPacket = new RawPacket((OperationCode)opCode, dataBuffer, clientAliveTime, buffer[0],
+ buffer[3], this.Id, this);
+ Task.Run(() => this._mediator.Send(rawPacket));
+ this._logger.LogInformation("Connection from: {@RemoteEndpoint}", this.Socket.RemoteEndPoint?.ToString());
base.OnReceived(decryptedBuffer.ToArray(), offset, decryptedBuffer.Length);
}
private byte[] Decrypt(byte[] buffer)
{
- for (int i = 0; i < buffer.Length; ++i)
+ for (var i = 0; i < buffer.Length; ++i)
{
buffer[i] = (byte)(buffer[i] ^ i ^ (3 * (0xFE - i)));
}
return buffer;
}
-}
\ No newline at end of file
+}
diff --git a/Server/ChannelSession.cs b/Server/ChannelSession.cs
index c29b67c..8fbb53f 100644
--- a/Server/ChannelSession.cs
+++ b/Server/ChannelSession.cs
@@ -15,31 +15,33 @@ public class ChannelSession : TcpSession
.Reverse().ToArray();
private static readonly byte[] IV = new byte[]
- { 0xfe, 220, 0xba, 0x98, 0x76, 0x54, 50, 0x10, 15, 30, 0x2d, 60, 0x4b, 90, 0x69, 120 }.Reverse().ToArray();
+ {
+ 0xfe, 220, 0xba, 0x98, 0x76, 0x54, 50, 0x10, 15, 30, 0x2d, 60, 0x4b, 90, 0x69, 120
+ }.Reverse().ToArray();
private readonly ICryptoTransform _encryptor;
private readonly ICryptoTransform _decryptor;
public ChannelSession(TcpServer server, IMediator mediator, ILogger logger) : base(server)
{
- _mediator = mediator;
- _logger = logger;
+ this._mediator = mediator;
+ this._logger = logger;
var aes = Aes.Create();
aes.Key = Key;
aes.IV = IV;
aes.Padding = PaddingMode.None;
aes.Mode = CipherMode.ECB;
- _decryptor = aes.CreateDecryptor(aes.Key, aes.IV);
- _encryptor = aes.CreateEncryptor(aes.Key, aes.IV);
+ this._decryptor = aes.CreateDecryptor(aes.Key, aes.IV);
+ this._encryptor = aes.CreateEncryptor(aes.Key, aes.IV);
}
protected override void OnReceived(byte[] buffer, long offset, long size)
{
try
{
- using (var ms = new MemoryStream(Decrypt(buffer)))
- using (var cs = new CryptoStream(ms, _decryptor, CryptoStreamMode.Read))
+ using (var ms = new MemoryStream(this.Decrypt(buffer)))
+ using (var cs = new CryptoStream(ms, this._decryptor, CryptoStreamMode.Read))
{
cs.Read(buffer);
}
@@ -48,18 +50,18 @@ public class ChannelSession : TcpSession
}
catch (CryptographicException ex)
{
- _logger.LogError("An error has occured while decrypting: {ErrorMessage}", ex.Message);
- _logger.LogError("Default buffer message: {Message}", Encoding.ASCII.GetString(buffer));
+ this._logger.LogError("An error has occured while decrypting: {ErrorMessage}", ex.Message);
+ this._logger.LogError("Default buffer message: {Message}", Encoding.ASCII.GetString(buffer));
}
}
private byte[] Decrypt(byte[] buffer)
{
- for (int i = 0; i < buffer.Length; ++i)
+ for (var i = 0; i < buffer.Length; ++i)
{
buffer[i] = (byte)(buffer[i] ^ i ^ (3 * (0xFE - i)));
}
return buffer;
}
-}
\ No newline at end of file
+}
diff --git a/Server/Consumers/PacketConsumer.cs b/Server/Consumers/PacketConsumer.cs
index 0e67305..4c8a9fa 100644
--- a/Server/Consumers/PacketConsumer.cs
+++ b/Server/Consumers/PacketConsumer.cs
@@ -8,14 +8,11 @@ public class PacketConsumer : IConsumer
{
private readonly PacketDistributorService _distributorService;
- public PacketConsumer(PacketDistributorService distributorService)
- {
- _distributorService = distributorService;
- }
+ public PacketConsumer(PacketDistributorService distributorService) => this._distributorService = distributorService;
public Task Consume(ConsumeContext context)
{
- _distributorService.AddPacket(context.Message);
+ this._distributorService.AddPacket(context.Message);
return Task.CompletedTask;
}
-}
\ No newline at end of file
+}
diff --git a/Server/DB/Documents/Account.cs b/Server/DB/Documents/Account.cs
index ef4a464..f301c81 100644
--- a/Server/DB/Documents/Account.cs
+++ b/Server/DB/Documents/Account.cs
@@ -6,14 +6,14 @@ public class Account : CouchDocument
{
public Account(string username, string password, string email, byte permissionLevel)
{
- Username = username;
- Password = password;
- Email = email;
- PermissionLevel = permissionLevel;
+ this.Username = username;
+ this.Password = password;
+ this.Email = email;
+ this.PermissionLevel = permissionLevel;
}
public string Username { get; private set; }
public string Password { get; private set; }
public string Email { get; private set; }
public byte PermissionLevel { get; private set; }
-}
\ No newline at end of file
+}
diff --git a/Server/DB/WonderkingContext.cs b/Server/DB/WonderkingContext.cs
index 7274cda..5d12a12 100644
--- a/Server/DB/WonderkingContext.cs
+++ b/Server/DB/WonderkingContext.cs
@@ -11,4 +11,4 @@ public class WonderkingContext : CouchContext
public WonderkingContext(CouchOptions options) : base(options)
{
}
-}
\ No newline at end of file
+}
diff --git a/Server/PacketHandlers/IPacketHandler.cs b/Server/PacketHandlers/IPacketHandler.cs
index c0f4bd8..66c195a 100644
--- a/Server/PacketHandlers/IPacketHandler.cs
+++ b/Server/PacketHandlers/IPacketHandler.cs
@@ -6,4 +6,4 @@ namespace Server.PacketHandlers;
public interface IPacketHandler where T : IPacket
{
public Task HandleAsync(T packet, TcpSession session);
-}
\ No newline at end of file
+}
diff --git a/Server/PacketHandlers/LoginInfoHandler.cs b/Server/PacketHandlers/LoginInfoHandler.cs
index 0f37d7f..682649a 100644
--- a/Server/PacketHandlers/LoginInfoHandler.cs
+++ b/Server/PacketHandlers/LoginInfoHandler.cs
@@ -16,46 +16,39 @@ public class LoginHandler : IPacketHandler
public LoginHandler(ILogger logger, WonderkingContext wonderkingContext, IConfiguration configuration)
{
- _logger = logger;
- _wonderkingContext = wonderkingContext;
- _configuration = configuration;
+ this._logger = logger;
+ this._wonderkingContext = wonderkingContext;
+ this._configuration = configuration;
}
public async Task HandleAsync(LoginInfoPacket packet, TcpSession session)
{
- _logger.LogInformation("Login data: Username {Username} & Password {Password}", packet.Username,
+ this._logger.LogInformation("Login data: Username {Username} & Password {Password}", packet.Username,
packet.Password);
- var account = _wonderkingContext.Accounts.FirstOrDefault(a => a.Username == packet.Username);
+ var account = this._wonderkingContext.Accounts.FirstOrDefault(a => a.Username == packet.Username);
if (account == null)
{
- if (_configuration.GetSection("Testing").GetValue("CreateAccountOnLogin"))
+ if (this._configuration.GetSection("Testing").GetValue("CreateAccountOnLogin"))
{
- var result = _wonderkingContext.Accounts.AddAsync(new Account(packet.Username, packet.Password, "", 0));
+ var result =
+ this._wonderkingContext.Accounts.AddAsync(new Account(packet.Username, packet.Password, "", 0));
await result;
}
else
{
// TODO: Send Message that account does not exist
- _logger.LogInformation("Requested account for user: {Username} does not exist", packet.Username);
+ this._logger.LogInformation("Requested account for user: {Username} does not exist", packet.Username);
}
}
var loginResponsePacket = new LoginResponsePacket
{
LoginResponseReason = LoginResponseReason.OK,
- ChannelData = new[]
- {
- new ServerChannelData
- {
- ChannelId = 0,
- LoadPercentage = 200,
- ServerId = 0
- }
- },
+ ChannelData = new[] { new ServerChannelData { ChannelId = 0, LoadPercentage = 200, ServerId = 0 } },
UnknownFlag = 1,
IsGameMaster = true
};
var sess = session as AuthSession;
sess.Send(loginResponsePacket);
}
-}
\ No newline at end of file
+}
diff --git a/Server/Packets/IPacket.cs b/Server/Packets/IPacket.cs
index 8a2c68c..b5f465b 100644
--- a/Server/Packets/IPacket.cs
+++ b/Server/Packets/IPacket.cs
@@ -2,6 +2,6 @@
public interface IPacket
{
- public void Deserialize( byte[] data);
+ public void Deserialize(byte[] data);
public byte[] Serialize();
-}
\ No newline at end of file
+}
diff --git a/Server/Packets/Incoming/LoginInfoPacket.cs b/Server/Packets/Incoming/LoginInfoPacket.cs
index a79f48f..a155f44 100644
--- a/Server/Packets/Incoming/LoginInfoPacket.cs
+++ b/Server/Packets/Incoming/LoginInfoPacket.cs
@@ -11,25 +11,25 @@ public class LoginInfoPacket : IPacket
public void Deserialize(byte[] data)
{
- Username = Encoding.ASCII.GetString(data, 0, 20);
- Password = Encoding.ASCII.GetString(data, 20, 31);
+ this.Username = Encoding.ASCII.GetString(data, 0, 20);
+ this.Password = Encoding.ASCII.GetString(data, 20, 31);
}
public byte[] Serialize()
{
Span dataSpan = stackalloc byte[20 + 31];
- var usernameBytes = Encoding.ASCII.GetBytes(Username);
- var passwordBytes = Encoding.ASCII.GetBytes(Password);
- for (int i = 0; i < 20 || i < Username.Length; i++)
+ var usernameBytes = Encoding.ASCII.GetBytes(this.Username);
+ var passwordBytes = Encoding.ASCII.GetBytes(this.Password);
+ for (var i = 0; i < 20 || i < this.Username.Length; i++)
{
dataSpan[i] = usernameBytes[i];
}
- for (int i = 0; i < 31 || i < Password.Length; i++)
+ for (var i = 0; i < 31 || i < this.Password.Length; i++)
{
dataSpan[20 + i] = passwordBytes[i];
}
return dataSpan.ToArray();
}
-}
\ No newline at end of file
+}
diff --git a/Server/Packets/OperationCode.cs b/Server/Packets/OperationCode.cs
index 483628f..c3099f2 100644
--- a/Server/Packets/OperationCode.cs
+++ b/Server/Packets/OperationCode.cs
@@ -4,4 +4,4 @@ public enum OperationCode : ushort
{
LoginInfo = 11,
LoginResponse = 12
-}
\ No newline at end of file
+}
diff --git a/Server/Packets/Outgoing/LoginResponsePacket.cs b/Server/Packets/Outgoing/LoginResponsePacket.cs
index 204a5e4..f8888a5 100644
--- a/Server/Packets/Outgoing/LoginResponsePacket.cs
+++ b/Server/Packets/Outgoing/LoginResponsePacket.cs
@@ -11,42 +11,42 @@ public class LoginResponsePacket : IPacket
public void Deserialize(byte[] data)
{
- LoginResponseReason = (LoginResponseReason)data[0];
- UnknownFlag = data[1];
- IsGameMaster = BitConverter.ToBoolean(data, 2);
+ this.LoginResponseReason = (LoginResponseReason)data[0];
+ this.UnknownFlag = data[1];
+ this.IsGameMaster = BitConverter.ToBoolean(data, 2);
var channelAmount = BitConverter.ToUInt16(data, 3);
var sizeOfServerChannelData = 5;
- ChannelData = Enumerable.Repeat(0, channelAmount).Select(i => new ServerChannelData
+ this.ChannelData = Enumerable.Repeat(0, channelAmount).Select(i => new ServerChannelData
{
- ServerId = BitConverter.ToUInt16(data, 5 + 0 + i * sizeOfServerChannelData),
- ChannelId = BitConverter.ToUInt16(data, 5 + 2 + i * sizeOfServerChannelData),
- LoadPercentage = data[5 + 4 + i * sizeOfServerChannelData]
+ ServerId = BitConverter.ToUInt16(data, 5 + 0 + (i * sizeOfServerChannelData)),
+ ChannelId = BitConverter.ToUInt16(data, 5 + 2 + (i * sizeOfServerChannelData)),
+ LoadPercentage = data[5 + 4 + (i * sizeOfServerChannelData)]
}).ToArray();
}
public byte[] Serialize()
{
var sizeOfServerChannelData = 5;
- Span dataSpan = stackalloc byte[5 + ChannelData.Length * sizeOfServerChannelData];
+ Span dataSpan = stackalloc byte[5 + (this.ChannelData.Length * sizeOfServerChannelData)];
dataSpan.Clear();
- dataSpan[0] = (byte)LoginResponseReason;
- dataSpan[1] = UnknownFlag;
- dataSpan[2] = BitConverter.GetBytes(IsGameMaster)[0];
- var bytesOfChannelAmount = BitConverter.GetBytes((ushort)ChannelData.Length);
+ dataSpan[0] = (byte)this.LoginResponseReason;
+ dataSpan[1] = this.UnknownFlag;
+ dataSpan[2] = BitConverter.GetBytes(this.IsGameMaster)[0];
+ var bytesOfChannelAmount = BitConverter.GetBytes((ushort)this.ChannelData.Length);
dataSpan[3] = bytesOfChannelAmount[0];
dataSpan[4] = bytesOfChannelAmount[1];
- for (var i = 0; i < ChannelData.Length; i++)
+ for (var i = 0; i < this.ChannelData.Length; i++)
{
- var bytesOfServerId = BitConverter.GetBytes(ChannelData[i].ServerId);
- var bytesOfChannelId = BitConverter.GetBytes(ChannelData[i].ChannelId);
- dataSpan[5 + 0 + i * sizeOfServerChannelData] = bytesOfServerId[0];
- dataSpan[5 + 1 + i * sizeOfServerChannelData] = bytesOfServerId[1];
- dataSpan[5 + 2 + i * sizeOfServerChannelData] = bytesOfChannelId[0];
- dataSpan[5 + 3 + i * sizeOfServerChannelData] = bytesOfChannelId[1];
- dataSpan[5 + 4 + i * sizeOfServerChannelData] = ChannelData[i].LoadPercentage;
+ var bytesOfServerId = BitConverter.GetBytes(this.ChannelData[i].ServerId);
+ var bytesOfChannelId = BitConverter.GetBytes(this.ChannelData[i].ChannelId);
+ dataSpan[5 + 0 + (i * sizeOfServerChannelData)] = bytesOfServerId[0];
+ dataSpan[5 + 1 + (i * sizeOfServerChannelData)] = bytesOfServerId[1];
+ dataSpan[5 + 2 + (i * sizeOfServerChannelData)] = bytesOfChannelId[0];
+ dataSpan[5 + 3 + (i * sizeOfServerChannelData)] = bytesOfChannelId[1];
+ dataSpan[5 + 4 + (i * sizeOfServerChannelData)] = this.ChannelData[i].LoadPercentage;
}
return dataSpan.ToArray();
}
-}
\ No newline at end of file
+}
diff --git a/Server/Packets/Outgoing/LoginResponseReason.cs b/Server/Packets/Outgoing/LoginResponseReason.cs
index 65731b9..f06b4ec 100644
--- a/Server/Packets/Outgoing/LoginResponseReason.cs
+++ b/Server/Packets/Outgoing/LoginResponseReason.cs
@@ -15,5 +15,5 @@ public enum LoginResponseReason : byte
ServerNotFoundOrDBProblem,
LockedDuePayment,
UserDeletedBigpoint,
- NoMoreTries,
-}
\ No newline at end of file
+ NoMoreTries
+}
diff --git a/Server/Packets/Outgoing/ServerChannelData.cs b/Server/Packets/Outgoing/ServerChannelData.cs
index 0e61d0b..c6d1692 100644
--- a/Server/Packets/Outgoing/ServerChannelData.cs
+++ b/Server/Packets/Outgoing/ServerChannelData.cs
@@ -5,4 +5,4 @@ public struct ServerChannelData
public ushort ServerId;
public ushort ChannelId;
public byte LoadPercentage;
-}
\ No newline at end of file
+}
diff --git a/Server/Packets/PacketId.cs b/Server/Packets/PacketId.cs
index 46a3874..2dd4b9e 100644
--- a/Server/Packets/PacketId.cs
+++ b/Server/Packets/PacketId.cs
@@ -1,12 +1,8 @@
namespace Server.Packets;
-
public class PacketId : Attribute
{
public readonly OperationCode Code;
- public PacketId(OperationCode code)
- {
- Code = code;
- }
-}
\ No newline at end of file
+ public PacketId(OperationCode code) => this.Code = code;
+}
diff --git a/Server/Packets/RawPacket.cs b/Server/Packets/RawPacket.cs
index e235615..3beeed1 100644
--- a/Server/Packets/RawPacket.cs
+++ b/Server/Packets/RawPacket.cs
@@ -17,18 +17,18 @@ public class RawPacket
public RawPacket(OperationCode operationCode, byte[] messageBody, uint aliveTime, byte unknownValue2,
byte unknownValue, Guid sessionId, AuthSession session)
{
- MessageBody = messageBody;
- UnknownValue2 = unknownValue2;
- UnknownValue = unknownValue;
- SessionId = sessionId;
- Session = session;
- OperationCode = operationCode;
+ this.MessageBody = messageBody;
+ this.UnknownValue2 = unknownValue2;
+ this.UnknownValue = unknownValue;
+ this.SessionId = sessionId;
+ this.Session = session;
+ this.OperationCode = operationCode;
/*
* 20s = 5
* 15s = 4
* 10s = 3
* client alive time * 5s => uptime
*/
- ClientAliveTime = TimeSpan.FromSeconds(5 * aliveTime);
+ this.ClientAliveTime = TimeSpan.FromSeconds(5 * aliveTime);
}
-}
\ No newline at end of file
+}
diff --git a/Server/Program.cs b/Server/Program.cs
index f414f2b..84b64ba 100644
--- a/Server/Program.cs
+++ b/Server/Program.cs
@@ -10,7 +10,7 @@ using Server.DB;
using Server.Services;
var builder = Host.CreateApplicationBuilder();
-var configurationRoot = builder.Configuration.AddJsonFile("settings.json", optional: false, reloadOnChange: true)
+var configurationRoot = builder.Configuration.AddJsonFile("settings.json", false, true)
.AddEnvironmentVariables().Build();
builder.Services.AddLogging();
builder.Logging.AddFile("Logs/Server-{Date}.log", LogLevel.Trace);
@@ -34,5 +34,5 @@ builder.Services.AddHostedService(provider => new Wonderki
provider.GetService>() ?? throw new InvalidOperationException(),
provider.GetService() ?? throw new InvalidOperationException()));
-using IHost host = builder.Build();
-await host.RunAsync();
\ No newline at end of file
+using var host = builder.Build();
+await host.RunAsync();
diff --git a/Server/Server.csproj b/Server/Server.csproj
index 5c2b228..3ac59e2 100644
--- a/Server/Server.csproj
+++ b/Server/Server.csproj
@@ -1,78 +1,78 @@
-
- Exe
- net7.0
- enable
- enable
- Linux
- Server
- default
-
+
+ Exe
+ net7.0
+ enable
+ enable
+ Linux
+ Server
+ default
+
-
-
- .dockerignore
-
-
+
+
+ .dockerignore
+
+
-
-
-
-
- all
- runtime; build; native; contentfiles; analyzers; buildtransitive
-
-
- all
- runtime; build; native; contentfiles; analyzers; buildtransitive
-
-
-
-
- all
- runtime; build; native; contentfiles; analyzers; buildtransitive
-
-
-
-
-
-
-
-
-
- all
- runtime; build; native; contentfiles; analyzers; buildtransitive
-
-
-
-
- all
- runtime; build; native; contentfiles; analyzers; buildtransitive
-
-
- all
- runtime; build; native; contentfiles; analyzers; buildtransitive
-
-
- all
- runtime; build; native; contentfiles; analyzers; buildtransitive
-
-
- all
- runtime; build; native; contentfiles; analyzers; buildtransitive
-
-
- all
- runtime; build; native; contentfiles; analyzers; buildtransitive
-
-
-
+
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
+
+
+
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
-
-
-
- PreserveNewest
-
-
+
+
+
+ PreserveNewest
+
+
diff --git a/Server/Services/PacketDistributorService.cs b/Server/Services/PacketDistributorService.cs
index e88f739..b3dda7f 100644
--- a/Server/Services/PacketDistributorService.cs
+++ b/Server/Services/PacketDistributorService.cs
@@ -21,15 +21,15 @@ public class PacketDistributorService : IHostedService
public PacketDistributorService(ILogger logger, IServiceProvider serviceProvider)
{
- _concurrentQueue = new ConcurrentQueue();
- _logger = logger;
- _serviceProvider = serviceProvider;
- _packetHandlers = new Dictionary();
- _packetsTypes = new Dictionary();
+ this._concurrentQueue = new ConcurrentQueue();
+ this._logger = logger;
+ this._serviceProvider = serviceProvider;
+ this._packetHandlers = new Dictionary();
+ this._packetsTypes = new Dictionary();
var executingAssembly = Assembly.GetExecutingAssembly();
- _packetsTypes = GetPacketsWithId(executingAssembly);
- _packetHandlers = GetAllPacketHandlersWithId(executingAssembly);
+ this._packetsTypes = this.GetPacketsWithId(executingAssembly);
+ this._packetHandlers = this.GetAllPacketHandlersWithId(executingAssembly);
}
private Dictionary GetPacketsWithId(Assembly executingAssembly)
@@ -42,13 +42,13 @@ public class PacketDistributorService : IHostedService
{
packetsWithId.AsParallel().ForAll(packet =>
{
- _logger.LogTrace("Packet with ID: {PacketID} has been added as {PacketName}", packet.Key,
+ this._logger.LogTrace("Packet with ID: {PacketID} has been added as {PacketName}", packet.Key,
packet.Value.FullName);
});
return packetsWithId;
}
- _logger.LogCritical("No Packets have been found");
+ this._logger.LogCritical("No Packets have been found");
throw new IncompleteInitialization();
}
@@ -65,34 +65,32 @@ public class PacketDistributorService : IHostedService
{
packetHandlersWithId.AsParallel().ForAll(packetHandler =>
{
- _logger.LogTrace("PacketHandler with ID: {PacketID} has been added as {PacketName}", packetHandler.Key,
+ this._logger.LogTrace("PacketHandler with ID: {PacketID} has been added as {PacketName}",
+ packetHandler.Key,
packetHandler.Value.FullName);
});
return packetHandlersWithId;
}
- _logger.LogCritical("No PacketHandlers have been found");
+ this._logger.LogCritical("No PacketHandlers have been found");
throw new IncompleteInitialization();
}
- public Task StartAsync(CancellationToken cancellationToken)
- {
- return Task.CompletedTask;
- }
+ public Task StartAsync(CancellationToken cancellationToken) => Task.CompletedTask;
public void AddPacket(RawPacket rawPacket)
{
- _concurrentQueue.Enqueue(rawPacket);
- Task.Run(() => DequeueRawPacketAsync());
- _logger.LogInformation("Packet with ID: {MessageOperationCode} has been received",
+ this._concurrentQueue.Enqueue(rawPacket);
+ Task.Run(() => this.DequeueRawPacketAsync());
+ this._logger.LogInformation("Packet with ID: {MessageOperationCode} has been received",
rawPacket.OperationCode);
}
private async Task DequeueRawPacketAsync()
{
- if (_concurrentQueue.TryDequeue(out var item))
+ if (this._concurrentQueue.TryDequeue(out var item))
{
- Task.Run(() => { InvokePacketHandler(item); });
+ Task.Run(() => { this.InvokePacketHandler(item); });
}
else
{
@@ -102,24 +100,21 @@ public class PacketDistributorService : IHostedService
private void InvokePacketHandler(RawPacket? item)
{
- _logger.LogTrace("[{TempId}] Packet with ID: {MessageOperationCode} is being dequeued",
+ this._logger.LogTrace("[{TempId}] Packet with ID: {MessageOperationCode} is being dequeued",
item.Session.Id, item.OperationCode);
- var packetType = _packetsTypes[item.OperationCode];
+ var packetType = this._packetsTypes[item.OperationCode];
var packet = (IPacket)Activator.CreateInstance(packetType)!;
packet.Deserialize(item.MessageBody);
var packetHandler =
- ActivatorUtilities.GetServiceOrCreateInstance(_serviceProvider,
- _packetHandlers[item.OperationCode]);
+ ActivatorUtilities.GetServiceOrCreateInstance(this._serviceProvider,
+ this._packetHandlers[item.OperationCode]);
packetHandler.GetType().GetMethod("HandleAsync")
- ?.Invoke(packetHandler, new Object[] { packet, item.Session });
- _logger.LogDebug("Packet data {PacketData}", JsonConvert.SerializeObject(packet));
- _logger.LogTrace("[{TempId}] Packet with ID: {MessageOperationCode} has finished",
+ ?.Invoke(packetHandler, new object[] { packet, item.Session });
+ this._logger.LogDebug("Packet data {PacketData}", JsonConvert.SerializeObject(packet));
+ this._logger.LogTrace("[{TempId}] Packet with ID: {MessageOperationCode} has finished",
item.Session.Id,
item.OperationCode);
}
- public Task StopAsync(CancellationToken cancellationToken)
- {
- return Task.CompletedTask;
- }
-}
\ No newline at end of file
+ public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
+}
diff --git a/Server/Services/WonderkingAuthServer.cs b/Server/Services/WonderkingAuthServer.cs
index 882b14b..80c2b59 100644
--- a/Server/Services/WonderkingAuthServer.cs
+++ b/Server/Services/WonderkingAuthServer.cs
@@ -15,51 +15,48 @@ public class WonderkingAuthServer : TcpServer, IHostedService
public WonderkingAuthServer(IPAddress address, int port, ILogger logger,
IServiceProvider serviceProvider) : base(address, port)
{
- _logger = logger;
- _serviceProvider = serviceProvider;
+ this._logger = logger;
+ this._serviceProvider = serviceProvider;
}
protected override TcpSession CreateSession() =>
- ActivatorUtilities.CreateInstance(_serviceProvider,this);
+ ActivatorUtilities.CreateInstance(this._serviceProvider, this);
protected override void OnStarting()
{
- _logger.LogInformation("Starting");
+ this._logger.LogInformation("Starting");
base.OnStarting();
}
protected override void OnStarted()
{
- _logger.LogInformation("Started");
+ this._logger.LogInformation("Started");
base.OnStarted();
}
protected override void OnStopping()
{
- _logger.LogInformation("Stopping");
+ this._logger.LogInformation("Stopping");
base.OnStopping();
}
protected override void OnStopped()
{
- _logger.LogInformation("Stopped");
+ this._logger.LogInformation("Stopped");
base.OnStopped();
}
- protected override void OnError(SocketError error)
- {
- _logger.LogError("An error has occured {Error}", error);
- }
+ protected override void OnError(SocketError error) => this._logger.LogError("An error has occured {Error}", error);
public Task StartAsync(CancellationToken cancellationToken)
{
- Start();
+ this.Start();
return Task.CompletedTask;
}
public Task StopAsync(CancellationToken cancellationToken)
{
- Stop();
+ this.Stop();
return Task.CompletedTask;
}
-}
\ No newline at end of file
+}