"System.Runtime.CompilerServices.Unsafe": "4.5.3"
}
}
- }
+ },
+ ".NETStandard,Version=v2.0/win-x64": {}
}
}
\ No newline at end of file
-using System.Collections.Generic;
+using System;
+using System.Collections.Generic;
using System.Net;
using System.Threading.Tasks;
using Impostor.Api.Innersloth;
/// </remarks>
bool IsHostAuthoritive { get; }
+ /// <summary>
+ /// Gets the mod GUID that the game was registered with through the AMCI.
+ /// </summary>
+ Guid? ModGuid { get; }
+
IClientPlayer? GetClientPlayer(int clientId);
T? FindObjectByNetId<T>(uint netId)
case "bool":
return JsonSerializer.Deserialize<BoolGameFilter>(filterString)
?? throw new InvalidOperationException("Deserialization returned null for BoolGameFilter");
+ case "mod":
+ return JsonSerializer.Deserialize<ModFilter>(filterString)
+ ?? throw new InvalidOperationException("Deserialization returned null for ModFilter");
default:
throw new InvalidOperationException("No type matches subfilter");
}
--- /dev/null
+using System;
+using System.Text.Json.Serialization;
+
+// https://github.com/Innersloth-LLC/AmongUsModdingInformation
+namespace Impostor.Api.Innersloth.GameFilters
+{
+ [Serializable]
+ public class ModFilter : ISubFilter
+ {
+ [JsonPropertyName("FilterType")]
+ public string FilterType { get; } = "mod";
+
+ [JsonPropertyName("AcceptedValues")]
+ public required Guid AcceptedValues { get; set; }
+ }
+}
-using Impostor.Api.Innersloth;
+using Impostor.Api.Innersloth;
using Impostor.Api.Innersloth.GameOptions;
namespace Impostor.Api.Net.Messages.C2S
crossplayFlags = (CrossplayFlags)reader.ReadInt32();
gameFilterOptions = GameFilterOptions.Deserialize(reader);
}
+
+ public static void DeserializeModded(IMessageReader reader, out IGameOptions gameOptions, out CrossplayFlags crossplayFlags, out GameFilterOptions gameFilterOptions, out Guid modGuid)
+ {
+ Deserialize(reader, out gameOptions, out crossplayFlags, out gameFilterOptions);
+ modGuid = new Guid(reader.ReadBytes(16).Span);
+ }
}
}
public const byte QueryPlatformIds = 22;
public const byte QueryLobbyInfo = 23;
public const byte EndGameHostMigration = 24;
+ public const byte HostModdedGame = 25;
public const byte PackedGameDataTo = 26;
private static readonly Dictionary<byte, string> FlagCache;
"Microsoft.Extensions.DependencyInjection.Abstractions": "8.0.0"
}
},
+ "Microsoft.NET.ILLink.Tasks": {
+ "type": "Direct",
+ "requested": "[8.0.30, )",
+ "resolved": "8.0.30",
+ "contentHash": "SfmwuZjUPBTEoBMAsXZ/hWkaEK9oL+Y/UtAx7N6RyWHfcMt9J0ExrNPuOgTyPbCXIyiTBFsxFNrPLEZNPmJcvA=="
+ },
"StyleCop.Analyzers": {
"type": "Direct",
"requested": "[1.2.0-beta.556, )",
"resolved": "4.5.0",
"contentHash": "Xg4G4Indi4dqP1iuAiMSwpiWS54ZghzR644OtsRCm/m/lBMG8dUBhLVN7hLm8NNrNTR+iGbshCPTwrvxZPlm4g=="
}
- }
+ },
+ "net8.0/win-x64": {}
}
}
\ No newline at end of file
{
continue;
}
+ if (game.ModGuid != null)
+ {
+ continue;
+ }
if (!_compatibilityConfig.AllowVersionMixing &&
game.Host != null &&
{
continue;
}
+ if (game.ModGuid != null && !filterSet.Filters.Any(f => f.OptionType == "mod"))
+ {
+ continue;
+ }
var matchesAllFilters = true;
}
}
+ break;
+ case "mod":
+ if (filter.SubFilter is ModFilter modFilter && game.ModGuid != modFilter.AcceptedValues)
+ {
+ matchesAllFilters = false;
+ }
+
break;
}
using Impostor.Api.Config;
using Impostor.Api.Games;
using Impostor.Api.Innersloth;
+using Impostor.Api.Innersloth.GameOptions;
using Impostor.Api.Net;
using Impostor.Api.Net.Custom;
using Impostor.Api.Net.Messages;
{
return false;
}
+
+ if (Player != null && Player.Game.ModGuid != null)
+ {
+ return false;
+ }
if (Player != null && Player.IsHost)
{
switch (flag)
{
case MessageFlags.HostGame:
+ case MessageFlags.HostModdedGame:
{
- // Read game settings.
- Message00HostGameC2S.Deserialize(reader, out var gameOptions, out _, out var gameFilterOptions);
+ IGameOptions gameOptions;
+ GameFilterOptions gameFilterOptions;
+ Guid? modGuid = null;
+
+ if (flag == MessageFlags.HostModdedGame)
+ {
+ Message00HostGameC2S.DeserializeModded(reader, out gameOptions, out _, out gameFilterOptions, out var parsedModGuid);
+ modGuid = parsedModGuid;
+ }
+ else
+ {
+ // Read game settings.
+ Message00HostGameC2S.Deserialize(reader, out gameOptions, out _, out gameFilterOptions);
+ }
// Create game.
- var game = await _gameManager.CreateAsync(this, gameOptions, gameFilterOptions);
+ var game = await _gameManager.CreateAsync(this, gameOptions, gameFilterOptions, modGuid);
if (game == null)
{
return;
}
+ if (modGuid != null)
+ {
+ _logger.LogInformation("Client {Name} ({Id}) hosted a modded game with mod GUID {ModGuid}.", Name, Id, modGuid);
+ }
+
// Code in the packet below will be used in JoinGame.
using (var writer = MessageWriter.Get(MessageType.Reliable))
{
-using System;
+using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
await _eventManager.CallAsync(new GameDestroyedEvent(game));
}
- public async ValueTask<IGame?> CreateAsync(IClient? owner, IGameOptions options, GameFilterOptions filterOptions)
+ public async ValueTask<IGame?> CreateAsync(IClient? owner, IGameOptions options, GameFilterOptions filterOptions, Guid? modGuid = null)
{
if (owner != null && !_gamesCreatedBy.TryAdd(owner, null))
{
return null;
}
- var (success, game) = await TryCreateAsync(options, filterOptions, owner, @event.GameCode);
+ var (success, game) = await TryCreateAsync(options, filterOptions, owner, @event.GameCode, modGuid);
for (var i = 0; i < 10 && !success; i++)
{
- (success, game) = await TryCreateAsync(options, filterOptions, owner);
+ (success, game) = await TryCreateAsync(options, filterOptions, owner, modGuid: modGuid);
}
if (owner != null)
return CreateAsync(null, options, filterOptions);
}
- private async ValueTask<(bool Success, Game? Game)> TryCreateAsync(IGameOptions options, GameFilterOptions filterOptions, IClient? owner, GameCode? desiredGameCode = null)
+ private async ValueTask<(bool Success, Game? Game)> TryCreateAsync(IGameOptions options, GameFilterOptions filterOptions, IClient? owner, GameCode? desiredGameCode = null, Guid? modGuid = null)
{
var gameCode = desiredGameCode ?? _gameCodeFactory.Create();
- var game = ActivatorUtilities.CreateInstance<Game>(_serviceProvider, _publicIp, gameCode, options, filterOptions);
+ var game = modGuid.HasValue
+ ? ActivatorUtilities.CreateInstance<Game>(_serviceProvider, _publicIp, gameCode, options, filterOptions, modGuid.Value)
+ : ActivatorUtilities.CreateInstance<Game>(_serviceProvider, _publicIp, gameCode, options, filterOptions);
if (!_games.TryAdd(gameCode, game))
{
IEventManager eventManager,
ICompatibilityManager compatibilityManager,
IOptions<CompatibilityConfig> compatibilityConfig,
- IOptions<TimeoutConfig> timeoutConfig)
+ IOptions<TimeoutConfig> timeoutConfig,
+ Guid? modGuid = null)
{
_logger = logger;
_serviceProvider = serviceProvider;
GameNet = new GameNet();
Options = options;
FilterOptions = filterOptions;
+ ModGuid = modGuid;
_clientManager = clientManager;
_eventManager = eventManager;
_compatibilityManager = compatibilityManager;
public bool IsHostAuthoritive => Host != null && Host.Client.GameVersion.HasDisableServerAuthorityFlag;
+ public Guid? ModGuid { get; }
+
internal GameNet GameNet { get; }
public bool TryGetPlayer(int id, [MaybeNullWhen(false)] out ClientPlayer player)
-using System.Threading.Tasks;
+using System.Threading.Tasks;
using Impostor.Api.Config;
using Impostor.Api.Innersloth;
using Impostor.Api.Net.Custom;
await base.HandleMessageAsync(reader, messageType);
// Player created a game.
- if (reader.Tag == MessageFlags.HostGame)
+ if (reader.Tag is MessageFlags.HostGame or MessageFlags.HostModdedGame)
{
_createdGame = true;
}
"resolved": "8.0.1",
"contentHash": "X21b8D6z58EG34OMLH955750mFaEaGs5xLGe9Vyi3059Cgb3sk+p2k/JlQXaieEBRrk+SVlFzDei3Q6PdVzJOA=="
},
+ "Microsoft.NET.ILLink.Tasks": {
+ "type": "Direct",
+ "requested": "[8.0.30, )",
+ "resolved": "8.0.30",
+ "contentHash": "SfmwuZjUPBTEoBMAsXZ/hWkaEK9oL+Y/UtAx7N6RyWHfcMt9J0ExrNPuOgTyPbCXIyiTBFsxFNrPLEZNPmJcvA=="
+ },
"Serilog.Extensions.Hosting": {
"type": "Direct",
"requested": "[8.0.0, )",