IClientPlayer GetClientPlayer(int clientId);
+ /// <summary>
+ /// Syncs the internal <see cref="GameOptionsData"/> to all players.
+ /// Necessary to do if you modified it, otherwise it won't be used.
+ /// </summary>
+ /// <returns></returns>
+ ValueTask SyncSettingsAsync();
+
/// <summary>
/// Send the message to all players.
/// </summary>
{
Console.WriteLine(e.PlayerControl.PlayerInfo.PlayerName + " said " + e.Message);
+ if (e.Message == "test")
+ {
+ e.Game.Options.KillCooldown = 0;
+ e.Game.Options.NumImpostors = 2;
+ e.Game.Options.PlayerSpeedMod = 5;
+
+ await e.Game.SyncSettingsAsync();
+ }
+
await e.PlayerControl.SetNameAsync(e.Message);
await e.PlayerControl.SendChatAsync(e.Message);
}
-using Impostor.Api.Games;
+using System.IO;
+using System.Threading.Tasks;
+using Impostor.Api.Games;
+using Impostor.Api.Innersloth;
using Impostor.Api.Net;
using Impostor.Api.Net.Inner;
+using Impostor.Server.Net.Inner;
namespace Impostor.Server.Net.State
{
- internal partial class Game
+ internal partial class Game : IGame
{
IClientPlayer IGame.Host => Host;
IGameNet IGame.GameNet => GameNet;
+
+ public async ValueTask SyncSettingsAsync()
+ {
+ using (var writer = StartRpc(Host.Character.NetId, RpcCalls.SyncSettings))
+ {
+ // Someone will probably forget to do this, so we include it here.
+ // If this is not done, the host will overwrite changes later with the defaults.
+ Options.IsDefaults = false;
+
+ await using (var memory = new MemoryStream())
+ await using (var writerBin = new BinaryWriter(memory))
+ {
+ Options.Serialize(writerBin, GameOptionsData.LatestVersion);
+ writer.WriteBytesAndSize(memory.ToArray());
+ }
+
+ await FinishRpcAsync(writer);
+ }
+ }
}
}
\ No newline at end of file