Skip to content

Commit

Permalink
slight cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
compujuckel committed Nov 23, 2023
1 parent 70cf748 commit ffe7ab8
Show file tree
Hide file tree
Showing 20 changed files with 101 additions and 30 deletions.
4 changes: 3 additions & 1 deletion AssettoServer.Shared/Network/Http/Responses/InfoResponse.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text.Json.Serialization;
using System.Diagnostics.CodeAnalysis;
using System.Text.Json.Serialization;

namespace AssettoServer.Shared.Network.Http.Responses;

Expand Down Expand Up @@ -49,6 +50,7 @@ public class InfoResponse
[JsonPropertyName("timestamp")]
public long Timestamp { get; set; }
[JsonPropertyName("tport")]
[SuppressMessage("ReSharper", "InconsistentNaming")]
public ushort TPort { get; set; }
[JsonPropertyName("track")]
public string? Track { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Numerics;
using System.Diagnostics.CodeAnalysis;
using System.Numerics;

namespace AssettoServer.Shared.Network.Packets.Outgoing;

Expand All @@ -17,6 +18,7 @@ public enum CarStatusFlags
WiperLevel3 = WiperLevel1 | WiperLevel2
}

[SuppressMessage("ReSharper", "InconsistentNaming")]
public readonly struct PositionUpdateOut : IOutgoingNetworkPacket
{
public readonly byte SessionId;
Expand Down
1 change: 1 addition & 0 deletions AssettoServer.Tests/AssettoServer.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\AssettoServer.Shared\AssettoServer.Shared.csproj" />
<ProjectReference Include="..\AssettoServer\AssettoServer.csproj" />
</ItemGroup>

Expand Down
1 change: 1 addition & 0 deletions AssettoServer.Tests/OnlineEventGeneratorTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using AssettoServer.Network.ClientMessages;
// ReSharper disable InconsistentNaming

namespace AssettoServer.Tests;

Expand Down
72 changes: 72 additions & 0 deletions AssettoServer.Tests/TestOnlineEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using System.Numerics;
using System.Text;
using AssettoServer.Network.ClientMessages;
using AssettoServer.Shared.Network.Packets;
using AssettoServer.Shared.Network.Packets.Shared;

namespace AssettoServer.Tests;

[OnlineEvent(Key = "testMessage")]
public class TestOnlineEvent : OnlineEvent<TestOnlineEvent>
{
//[ClientMessageField]
public bool TestBool;

[OnlineEventField]
public byte TestByte;

//[ClientMessageField(Size = 50)]
public string TestString = null!;

[OnlineEventField(Size = 7)]
public int[] TestArray = null!;

[OnlineEventField(Size = 3)]
public long[] TestArrayLong = null!;

//[ClientMessageField(Name = "TestVec2")]
public Vector2 TestVec2;

//[ClientMessageField(Name = "TestVec3")]
public Vector3 TestVec3;

[OnlineEventField(Name = "TestVec4")]
public Vector4 TestVec4;

//[ClientMessageField("TestEnum")]
//public ACServerProtocol TestEnum;

//public partial void ToWriter(ref PacketWriter writer);

public void ToWriter2(ref PacketWriter writer)
{
writer.Write(ACServerProtocol.Extended);
writer.Write(CSPMessageTypeTcp.ClientMessage);
writer.Write(SessionId);
writer.Write(CSPClientMessageType.LuaMessage);
writer.Write(0x61ED42F0);
writer.Write(TestByte);
}

public static void FromReaderStatic(TestOnlineEvent message, PacketReader reader)
{
message.TestArray = reader.ReadArrayFixed<int>(7).ToArray();
message.TestArrayLong = reader.ReadArrayFixed<long>(3).ToArray();
message.TestBool = reader.Read<bool>();
message.TestByte = reader.Read<byte>();
message.TestString = reader.ReadStringFixed(Encoding.UTF8, 50);
}

public static void ToWriterStatic(TestOnlineEvent message, ref PacketWriter writer)
{
writer.Write(ACServerProtocol.Extended);
writer.Write((byte)CSPMessageTypeTcp.ClientMessage);
writer.Write<byte>(message.SessionId);
writer.Write((ushort)CSPClientMessageType.LuaMessage);
writer.Write(PacketType);
writer.Write(message.TestBool);
writer.Write(message.TestByte);
writer.WriteStringFixed(message.TestString, Encoding.UTF8, 50, false);
writer.WriteArrayFixed<int>(message.TestArray, 7, true);
}
}
4 changes: 1 addition & 3 deletions AssettoServer/Network/Http/JsonSourceGenerationContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@ namespace AssettoServer.Network.Http;
[JsonSerializable(typeof(InfoResponse))]
[JsonSerializable(typeof(DetailResponse))]
[JsonSerializable(typeof(EntryListResponse))]
internal partial class JsonSourceGenerationContext : JsonSerializerContext
{
}
internal partial class JsonSourceGenerationContext : JsonSerializerContext;
7 changes: 3 additions & 4 deletions AssettoServer/Network/Http/LuaOutputFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ public override async Task WriteResponseBodyAsync(OutputFormatterWriteContext co
{
var serializer = new JsonSerializer();
await using var sw = context.WriterFactory(context.HttpContext.Response.Body, selectedEncoding);
using var jlw = new JsonLuaWriter(sw) {
CloseOutput = false,
Formatting = Formatting.None
};
using var jlw = new JsonLuaWriter(sw);
jlw.CloseOutput = false;
jlw.Formatting = Formatting.None;

serializer.Serialize(jlw, context.Object);
await sw.FlushAsync();
Expand Down
2 changes: 1 addition & 1 deletion AssettoServer/Network/Udp/UdpPluginServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private void ReceiveLoop(CancellationToken stoppingToken)

SendPacket(new Version{ ProtocolVersion = RequiredProtocolVersion });
SendSessionInfo(-1, true);
_sessionManager.SessionChanged += (manager, args) =>
_sessionManager.SessionChanged += (_, args) =>
{
SendSessionInfo((short)args.NextSession.Configuration.Id, true);
};
Expand Down
1 change: 0 additions & 1 deletion AssettoServer/Server/ACServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Threading;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using AssettoServer.Network.Tcp;
using AssettoServer.Server.Configuration;
Expand Down
1 change: 0 additions & 1 deletion AssettoServer/Server/Ai/AiBehavior.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Reflection;
Expand Down
3 changes: 2 additions & 1 deletion AssettoServer/Server/CSPServerScriptProvider.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Text;
using AssettoServer.Server.Configuration;
using IniParser.Model;
using JetBrains.Annotations;
using Microsoft.AspNetCore.Mvc;
using Serilog;

namespace AssettoServer.Server;

[PublicAPI]
public class CSPServerScriptProvider
{
internal List<Func<IActionResult>> Scripts { get; } = new();
Expand Down
5 changes: 1 addition & 4 deletions AssettoServer/Server/Configuration/IValidateConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,4 @@

namespace AssettoServer.Server.Configuration;

public interface IValidateConfiguration<T> where T : IValidator
{

}
public interface IValidateConfiguration<T> where T : IValidator;
2 changes: 1 addition & 1 deletion AssettoServer/Server/EntryCarAi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public partial class EntryCar
public float AiCorneringSpeedFactor { get; set; }
public float AiCorneringBrakeDistanceFactor { get; set; }
public float AiCorneringBrakeForceFactor { get; set; }
public float AiSplineHeightOffsetMeters { get; set; } = 0;
public float AiSplineHeightOffsetMeters { get; set; }
public int? AiMaxOverbooking { get; set; }
public int AiMinSpawnProtectionTimeMilliseconds { get; set; }
public int AiMaxSpawnProtectionTimeMilliseconds { get; set; }
Expand Down
5 changes: 1 addition & 4 deletions AssettoServer/Server/Plugin/IAssettoServerAutostart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,4 @@

namespace AssettoServer.Server.Plugin;

public interface IAssettoServerAutostart : IHostedService
{

}
public interface IAssettoServerAutostart : IHostedService;
2 changes: 1 addition & 1 deletion AssettoServer/Utils/CountedArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
public class CountedArray<T>
{
public readonly T[] Array;
public int Count { get; private set; } = 0;
public int Count { get; private set; }

public CountedArray(int maxLength)
{
Expand Down
1 change: 1 addition & 0 deletions AssettoServer/Utils/IMappedMemoryOwnerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace AssettoServer.Utils;
[SuppressMessage("ReSharper", "InconsistentNaming")]
public static class IMappedMemoryOwnerExtensions
{
[SuppressMessage("ReSharper", "NotAccessedField.Local")]
private static byte _dummy;

public static void Prefault(this IMappedMemoryOwner self)
Expand Down
2 changes: 1 addition & 1 deletion AssettoServer/Utils/IniFieldAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace AssettoServer.Utils;
[AttributeUsage(AttributeTargets.Property)]
public class IniFieldAttribute : Attribute
{
public readonly string? Section = null;
public readonly string? Section;
public readonly string Key;
public bool IgnoreParsingErrors = false;
public bool Percent = false;
Expand Down
6 changes: 5 additions & 1 deletion AssettoServer/Utils/Luaon.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
using System.IO;
using JetBrains.Annotations;
using Luaon.Json;
using Newtonsoft.Json;

namespace AssettoServer.Utils;

public static class Luaon
{
[PublicAPI]
public static string Serialize(object obj)
{
var serializer = new JsonSerializer();
using var sw = new StringWriter();
using (var jlw = new JsonLuaWriter(sw) { CloseOutput = false, Formatting = Formatting.None })
using (var jlw = new JsonLuaWriter(sw))
{
jlw.CloseOutput = false;
jlw.Formatting = Formatting.None;
serializer.Serialize(jlw, obj);
}
return sw.ToString();
Expand Down
6 changes: 2 additions & 4 deletions AssettoServer/Vendor/JPBotelho/CatmullRom.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Numerics;

// From https://github.com/JPBotelho/Catmull-Rom-Splines, Unity dependencies removed

// ReSharper disable once CheckNamespace
namespace JPBotelho
{
/*
Expand Down Expand Up @@ -263,4 +261,4 @@ public static Vector3 NormalFromTangent(Vector3 tangent)
return Vector3.Normalize(Vector3.Cross(tangent, Vector3.UnitY) / 2);
}
}
}
}
2 changes: 1 addition & 1 deletion RaceChallengePlugin/EntryCarRace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void Reply(string message)
car.Client?.SendPacket(new ChatMessage
{ SessionId = 255, Message = $"{_entryCar.Client?.Name} has challenged you to a race. Flash your hazard lights or send /accept within 10 seconds to accept." });

_ = Task.Delay(10000).ContinueWith(t =>
_ = Task.Delay(10000).ContinueWith(_ =>
{
if (!currentRace.HasStarted)
{
Expand Down

0 comments on commit ffe7ab8

Please sign in to comment.