Skip to content

Commit

Permalink
- bump version
Browse files Browse the repository at this point in the history
- add event handler for car list
  • Loading branch information
compujuckel committed Dec 23, 2023
1 parent 51737e2 commit 34fb41b
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@ public class CarListResponse : IOutgoingNetworkPacket
{
public int PageIndex;
public int EntryCarsCount;
public IEnumerable<IEntryCar<IClient>>? EntryCars;
public required IEnumerable<IEntryCar<IClient>> EntryCars;

public void ToWriter(ref PacketWriter writer)
{
if (EntryCars == null)
throw new ArgumentNullException(nameof(EntryCars));

writer.Write((byte)ACServerProtocol.CarList);
writer.Write((byte)PageIndex);
writer.Write((byte)EntryCarsCount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ internal static OnlineEvent<TMessage>.ToWriterDelegate GenerateWriterMethod<TMes
var elementType = field.Type.GetElementType()!;
var rosType = typeof(ReadOnlySpan<>).MakeGenericType(elementType);
var opImplicit = rosType.GetMethod("op_Implicit",
BindingFlags.Public | BindingFlags.Static, new[] { field.Type })!;
BindingFlags.Public | BindingFlags.Static, [field.Type])!;
emitter.Call(opImplicit);
emitter.LoadConstant(field.Array.Value);
emitter.LoadConstant(i < message.Fields.Count - 1); // padding
Expand Down
8 changes: 7 additions & 1 deletion AssettoServer/Network/Tcp/ACTcpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public class ACTcpClient : IClient
/// <summary>
/// Fires when a slot has been secured for a player and the handshake response is about to be sent.
/// </summary>
public event EventHandler<ACTcpClient, HandshakeAcceptedEventArgs> HandshakeAccepted = null!;
public event EventHandler<ACTcpClient, HandshakeAcceptedEventArgs>? HandshakeAccepted;

/// <summary>
/// Fires when a client has sent the first position update and is visible to other players.
Expand All @@ -123,6 +123,11 @@ public class ACTcpClient : IClient
/// </summary>
public event EventHandler<ACTcpClient, LapCompletedEventArgs>? LapCompleted;

/// <summary>
/// Fires before sending the car list response
/// </summary>
public event EventHandler<ACTcpClient, CarListResponseSendingEventArgs>? CarListResponseSending;

private class ACTcpClientLogEventEnricher : ILogEventEnricher
{
private readonly ACTcpClient _client;
Expand Down Expand Up @@ -660,6 +665,7 @@ private void OnCarListRequest(PacketReader reader)
EntryCars = carsInPage
};

CarListResponseSending?.Invoke(this, new CarListResponseSendingEventArgs(carListResponse));
SendPacket(carListResponse);
}

Expand Down
10 changes: 10 additions & 0 deletions AssettoServer/Server/EventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,13 @@ public LapCompletedEventArgs(LapCompletedOutgoing packet)
Packet = packet;
}
}

public class CarListResponseSendingEventArgs : EventArgs
{
public CarListResponse Packet { get; }

public CarListResponseSendingEventArgs(CarListResponse packet)
{
Packet = packet;
}
}
2 changes: 1 addition & 1 deletion AssettoServer/version.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
"version": "0.0.54"
"version": "0.0.55"
}

0 comments on commit 34fb41b

Please sign in to comment.