Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions AssettoServer.sln
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TagModePlugin", "TagModePlu
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FastTravelPlugin", "FastTravelPlugin\FastTravelPlugin.csproj", "{022C75A2-8B36-44F5-B99C-AF577A0192FD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TrafficAiPlugin", "TrafficAiPlugin\TrafficAiPlugin.csproj", "{F20A785C-686A-40A4-8821-28627BA6FA48}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TrafficAiPlugin.Shared", "TrafficAiPlugin.Shared\TrafficAiPlugin.Shared.csproj", "{18EE29A8-AA8F-47AD-849B-AD5D04C5A069}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -129,6 +133,14 @@ Global
{022C75A2-8B36-44F5-B99C-AF577A0192FD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{022C75A2-8B36-44F5-B99C-AF577A0192FD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{022C75A2-8B36-44F5-B99C-AF577A0192FD}.Release|Any CPU.Build.0 = Release|Any CPU
{F20A785C-686A-40A4-8821-28627BA6FA48}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F20A785C-686A-40A4-8821-28627BA6FA48}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F20A785C-686A-40A4-8821-28627BA6FA48}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F20A785C-686A-40A4-8821-28627BA6FA48}.Release|Any CPU.Build.0 = Release|Any CPU
{18EE29A8-AA8F-47AD-849B-AD5D04C5A069}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{18EE29A8-AA8F-47AD-849B-AD5D04C5A069}.Debug|Any CPU.Build.0 = Debug|Any CPU
{18EE29A8-AA8F-47AD-849B-AD5D04C5A069}.Release|Any CPU.ActiveCfg = Release|Any CPU
{18EE29A8-AA8F-47AD-849B-AD5D04C5A069}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
2 changes: 0 additions & 2 deletions AssettoServer/AssettoServer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,6 @@
</ItemGroup>

<ItemGroup>
<None Remove="Server\Ai\ai_debug.lua" />
<EmbeddedResource Include="Server\Ai\ai_debug.lua" />
<None Remove="Server\Lua\assettoserver.lua" />
<EmbeddedResource Include="Server\Lua\assettoserver.lua" />
<None Remove="Assets\logo_42.png" />
Expand Down
38 changes: 0 additions & 38 deletions AssettoServer/Commands/Modules/AiTrafficModule.cs

This file was deleted.

13 changes: 0 additions & 13 deletions AssettoServer/Commands/Modules/GeneralModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,4 @@ public async Task ShowLegalNotice()
Reply(line);
}
}

[Command("resetcar"), RequireConnectedPlayer]
public void ResetCarAsync()
{
if (_configuration.Extra is { EnableClientMessages: true, EnableCarReset: true, MinimumCSPVersion: >= CSPVersion.V0_2_8, EnableAi: true })
{
Reply(Client!.EntryCar.TryResetPosition()
? "Position successfully reset"
: "Couldn't reset position");
}
else
Reply("Reset is not enabled on this server");
}
}
7 changes: 0 additions & 7 deletions AssettoServer/Network/CSPClientMessageHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public CSPClientMessageHandler(CSPClientMessageTypeManager cspClientMessageTypeM

cspClientMessageTypeManager.RegisterOnlineEvent<CollisionUpdatePacket>((_, _) => { });
cspClientMessageTypeManager.RegisterOnlineEvent<TeleportCarPacket>((_, _) => { });
cspClientMessageTypeManager.RegisterOnlineEvent<RequestResetPacket>(OnResetCar);
cspClientMessageTypeManager.RegisterOnlineEvent<LuaReadyPacket>(OnLuaReady);
}

Expand Down Expand Up @@ -201,12 +200,6 @@ private void OnAdminPenaltyOut(ACTcpClient sender, PacketReader reader)
}
}

private void OnResetCar(ACTcpClient sender, RequestResetPacket packet)
{
if (!_configuration.Extra.EnableCarReset) return;
sender.EntryCar.TryResetPosition();
}

private void OnLuaReady(ACTcpClient sender, LuaReadyPacket packet)
{
sender.FireLuaReady();
Expand Down
12 changes: 0 additions & 12 deletions AssettoServer/Network/Tcp/ACTcpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -433,9 +433,6 @@ private async Task ReceiveLoopAsync()
CSPVersion = cspVersion;
}

// Gracefully despawn AI cars
EntryCar.SetAiOverbooking(0);

if (_configuration.Server.CheckAdminPassword(handshakeRequest.Password))
IsAdministrator = true;

Expand Down Expand Up @@ -872,15 +869,6 @@ private async Task SendFirstUpdateAsync()

batched.Packets.Add(new P2PUpdate { SessionId = car.SessionId, P2PCount = car.Status.P2PCount });
batched.Packets.Add(new BallastUpdate { SessionId = car.SessionId, BallastKg = car.Ballast, Restrictor = car.Restrictor });

if (_configuration.Extra.AiParams.HideAiCars)
{
batched.Packets.Add(new CSPCarVisibilityUpdate
{
SessionId = car.SessionId,
Visible = car.AiControlled ? CSPCarVisibility.Invisible : CSPCarVisibility.Visible
});
}
}

if (EntryCar.FixedSetup != null
Expand Down
49 changes: 19 additions & 30 deletions AssettoServer/Server/ACServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Collections.Generic;
using System.Reflection;
using AssettoServer.Server.Configuration;
using AssettoServer.Server.Ai.Splines;
using AssettoServer.Network.Udp;
using AssettoServer.Server.Blacklist;
using AssettoServer.Server.GeoParams;
using AssettoServer.Server.Whitelist;
Expand Down Expand Up @@ -42,8 +42,7 @@ public ACServer(
ChecksumManager checksumManager,
CSPFeatureManager cspFeatureManager,
CSPServerScriptProvider cspServerScriptProvider,
IHostApplicationLifetime applicationLifetime,
AiSpline? aiSpline = null)
IHostApplicationLifetime applicationLifetime)
{
Log.Information("Starting server");

Expand Down Expand Up @@ -86,17 +85,8 @@ public ACServer(

using var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("AssettoServer.Server.Lua.assettoserver.lua")!;
cspServerScriptProvider.AddScript(stream, "assettoserver.lua");

if (_configuration.Extra.EnableCarReset)
{
if (!_configuration.Extra.EnableClientMessages || _configuration.CSPTrackOptions.MinimumCSPVersion < CSPVersion.V0_2_8 || aiSpline == null)
{
throw new ConfigurationException(
"Reset car: Minimum required CSP version of 0.2.8 (3424); Requires enabled client messages; Requires working AI spline");
}
}
}

protected override Task ExecuteAsync(CancellationToken stoppingToken)
{
Log.Information("Starting HTTP server on port {HttpPort}", _configuration.Server.HttpPort);
Expand Down Expand Up @@ -183,26 +173,25 @@ private void MainLoop(CancellationToken stoppingToken)
}
}

if (fromCar.AiControlled || fromCar.HasUpdateToSend)
if (!fromCar.HasUpdateToSend) continue;

fromCar.HasUpdateToSend = false;

for (int j = 0; j < _entryCarManager.EntryCars.Length; j++)
{
fromCar.HasUpdateToSend = false;
var toCar = _entryCarManager.EntryCars[j];
var toClient = toCar.Client;
if (toCar == fromCar
|| toClient == null || !toClient.HasSentFirstUpdate || !toClient.HasUdpEndpoint
|| !fromCar.GetPositionUpdateForCar(toCar, out var update)) continue;

for (int j = 0; j < _entryCarManager.EntryCars.Length; j++)
if (toClient.SupportsCSPCustomUpdate)
{
var toCar = _entryCarManager.EntryCars[j];
var toClient = toCar.Client;
if (toCar == fromCar
|| toClient == null || !toClient.HasSentFirstUpdate || toClient.UdpEndpoint == null
|| !fromCar.GetPositionUpdateForCar(toCar, out var update)) continue;

if (toClient.SupportsCSPCustomUpdate || fromCar.AiControlled)
{
positionUpdates[toCar].Add(update);
}
else
{
toClient.SendPacketUdp(in update);
}
positionUpdates[toCar].Add(update);
}
else
{
toClient.SendPacketUdp(in update);
}
}
}
Expand Down
40 changes: 1 addition & 39 deletions AssettoServer/Server/Ai/AiModule.cs
Original file line number Diff line number Diff line change
@@ -1,39 +1 @@
using AssettoServer.Server.Ai.Splines;
using AssettoServer.Server.Configuration;
using AssettoServer.Server.OpenSlotFilters;
using Autofac;
using Microsoft.Extensions.Hosting;

namespace AssettoServer.Server.Ai;

public class AiModule : Module
{
private readonly ACServerConfiguration _configuration;

public AiModule(ACServerConfiguration configuration)
{
_configuration = configuration;
}

protected override void Load(ContainerBuilder builder)
{
builder.RegisterType<AiState>().AsSelf();

if (_configuration.Extra.EnableAi)
{
builder.RegisterType<AiBehavior>().AsSelf().As<IHostedService>().SingleInstance();
builder.RegisterType<AiUpdater>().AsSelf().SingleInstance().AutoActivate();
builder.RegisterType<AiSlotFilter>().As<IOpenSlotFilter>();

if (_configuration.Extra.AiParams.HourlyTrafficDensity != null)
{
builder.RegisterType<DynamicTrafficDensity>().As<IHostedService>().SingleInstance();
}

builder.RegisterType<AiSplineWriter>().AsSelf();
builder.RegisterType<FastLaneParser>().AsSelf();
builder.RegisterType<AiSplineLocator>().AsSelf();
builder.Register((AiSplineLocator locator) => locator.Locate()).AsSelf().SingleInstance();
}
}
}

26 changes: 0 additions & 26 deletions AssettoServer/Server/Ai/AiUpdater.cs

This file was deleted.

21 changes: 0 additions & 21 deletions AssettoServer/Server/Configuration/ACServerConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,27 +276,6 @@ private void ApplyConfigurationFixes()
Server.MaxClients = EntryList.Cars.Count;
}

if (Extra is { EnableAi: true, AiParams.AutoAssignTrafficCars: true })
{
foreach (var entry in EntryList.Cars)
{
if (entry.Model.Contains("traffic"))
{
entry.AiMode = AiMode.Fixed;
}
}
}

if (Extra.AiParams.AiPerPlayerTargetCount == 0)
{
Extra.AiParams.AiPerPlayerTargetCount = EntryList.Cars.Count(c => c.AiMode != AiMode.None);
}

if (Extra.AiParams.MaxAiTargetCount == 0)
{
Extra.AiParams.MaxAiTargetCount = EntryList.Cars.Count(c => c.AiMode != AiMode.Fixed) * Extra.AiParams.AiPerPlayerTargetCount;
}

var filteredServerName = ServerDetailsIdRegex().Replace(Server.Name, "");
if (filteredServerName != Server.Name)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,6 @@ public ACServerConfigurationValidator()
extra.RuleFor(x => x.WhitelistUserGroup).NotEmpty();
extra.RuleFor(x => x.AdminUserGroup).NotEmpty();
extra.RuleFor(x => x.VoteKickMinimumConnectedPlayers).GreaterThanOrEqualTo((ushort)3);

extra.RuleFor(x => x.AiParams).ChildRules(aiParams =>
{
aiParams.RuleFor(ai => ai.MinSpawnDistancePoints).LessThanOrEqualTo(ai => ai.MaxSpawnDistancePoints);
aiParams.RuleFor(ai => ai.MinAiSafetyDistanceMeters).LessThanOrEqualTo(ai => ai.MaxAiSafetyDistanceMeters);
aiParams.RuleFor(ai => ai.MinSpawnProtectionTimeSeconds).LessThanOrEqualTo(ai => ai.MaxSpawnProtectionTimeSeconds);
aiParams.RuleFor(ai => ai.MinCollisionStopTimeSeconds).LessThanOrEqualTo(ai => ai.MaxCollisionStopTimeSeconds);
aiParams.RuleFor(ai => ai.MaxSpeedVariationPercent).InclusiveBetween(0, 1);
aiParams.RuleFor(ai => ai.DefaultAcceleration).GreaterThan(0);
aiParams.RuleFor(ai => ai.DefaultDeceleration).GreaterThan(0);
aiParams.RuleFor(ai => ai.NamePrefix).NotNull();
aiParams.RuleFor(ai => ai.IgnoreObstaclesAfterSeconds).GreaterThanOrEqualTo(0);
aiParams.RuleFor(ai => ai.HourlyTrafficDensity)
.Must(htd => htd?.Count == 24)
.When(ai => ai.HourlyTrafficDensity != null)
.WithMessage("HourlyTrafficDensity must have exactly 24 entries");
aiParams.RuleFor(ai => ai.CarSpecificOverrides).NotNull();
aiParams.RuleFor(ai => ai.AiBehaviorUpdateIntervalHz).GreaterThan(0);
aiParams.RuleFor(ai => ai.LaneCountSpecificOverrides).NotNull();
aiParams.RuleForEach(ai => ai.LaneCountSpecificOverrides).ChildRules(overrides =>
{
overrides.RuleFor(o => o.Key).GreaterThan(0);
overrides.RuleFor(o => o.Value.MinAiSafetyDistanceMeters).LessThanOrEqualTo(o => o.Value.MaxAiSafetyDistanceMeters);
});
});
});

RuleFor(cfg => cfg.Server).ChildRules(server =>
Expand Down
Loading