Skip to content

Commit be41336

Browse files
committed
fix usage of EntryCar.Reset()
1 parent 437ed95 commit be41336

File tree

2 files changed

+29
-18
lines changed

2 files changed

+29
-18
lines changed

AssettoServer/Server/EntryCar.cs

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33
using System.Collections.Generic;
44
using System.Numerics;
55
using System.Threading.Tasks;
6-
using AssettoServer.Network.ClientMessages;
76
using AssettoServer.Server.Ai;
87
using AssettoServer.Server.Ai.Splines;
98
using AssettoServer.Server.Configuration;
10-
using AssettoServer.Server.Configuration.Extra;
119
using AssettoServer.Shared.Model;
1210
using AssettoServer.Shared.Network.Packets.Incoming;
1311
using AssettoServer.Shared.Network.Packets.Outgoing;
@@ -21,7 +19,7 @@ namespace AssettoServer.Server;
2119
public partial class EntryCar : IEntryCar<ACTcpClient>
2220
{
2321
public ACTcpClient? Client { get; internal set; }
24-
public CarStatus Status { get; private set; } = new CarStatus();
22+
public CarStatus Status { get; private set; } = new();
2523

2624
public bool ForceLights { get; internal set; }
2725

@@ -102,34 +100,25 @@ public EntryCar(string model, string? skin, byte sessionId, Func<EntryCar, AiSta
102100
AiPakSequenceIds = new byte[entryCarManager.EntryCars.Length];
103101
LastSeenAiState = new AiState[entryCarManager.EntryCars.Length];
104102
LastSeenAiSpawn = new byte[entryCarManager.EntryCars.Length];
105-
103+
106104
Logger = new LoggerConfiguration()
107105
.MinimumLevel.Debug()
108106
.Enrich.With(new EntryCarLogEventEnricher(this))
109107
.WriteTo.Logger(Log.Logger)
110108
.CreateLogger();
111-
109+
110+
_sessionManager.SessionChanged += OnSessionChanged;
111+
112112
AiInit();
113113
}
114114

115-
internal void Reset()
115+
private void OnSessionChanged(SessionManager sender, SessionChangedEventArgs args)
116116
{
117-
ResetInvoked?.Invoke(this, EventArgs.Empty);
118-
IsSpectator = false;
119-
SpectatorMode = 0;
120-
LastActiveTime = 0;
121-
HasUpdateToSend = false;
122-
TimeOffset = 0;
123-
LastRemoteTimestamp = 0;
124-
LastPingTime = 0;
125-
Ping = 0;
126-
ForceLights = false;
127117
Status = new CarStatus
128118
{
129119
P2PCount = (short)(_configuration.Extra.EnableUnlimitedP2P ? 99 : 15),
130120
MandatoryPit = _configuration.Server.PitWindowStart < _configuration.Server.PitWindowEnd,
131121
};
132-
TargetCar = null;
133122

134123
Client?.SendPacket(new P2PUpdate
135124
{
@@ -144,6 +133,29 @@ internal void Reset()
144133
});
145134
}
146135

136+
/// <summary>
137+
/// Only call this function to do a clean reset of this EntryCar, e.g. when a player disconnects
138+
/// </summary>
139+
internal void Reset()
140+
{
141+
ResetInvoked?.Invoke(this, EventArgs.Empty);
142+
IsSpectator = false;
143+
SpectatorMode = 0;
144+
LastActiveTime = 0;
145+
HasUpdateToSend = false;
146+
TimeOffset = 0;
147+
LastRemoteTimestamp = 0;
148+
LastPingTime = 0;
149+
Ping = 0;
150+
ForceLights = false;
151+
Status = new CarStatus
152+
{
153+
P2PCount = (short)(_configuration.Extra.EnableUnlimitedP2P ? 99 : 15),
154+
MandatoryPit = _configuration.Server.PitWindowStart < _configuration.Server.PitWindowEnd,
155+
};
156+
TargetCar = null;
157+
}
158+
147159
internal void SetActive()
148160
{
149161
LastActiveTime = _sessionManager.ServerTimeMilliseconds;

AssettoServer/Server/SessionManager.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,6 @@ public void SetSession(int sessionId)
372372
foreach (var entryCar in _entryCarManager.EntryCars)
373373
{
374374
CurrentSession.Results?.Add(entryCar.SessionId, new EntryCarResult(entryCar.Client));
375-
entryCar.Reset();
376375
}
377376

378377
var sessionLength = CurrentSession.Configuration switch

0 commit comments

Comments
 (0)