From: AeonLucid Date: Sun, 25 Oct 2020 00:16:19 +0000 (+0200) Subject: Add sync options method X-Git-Tag: v1.2.2~96^2~1 X-Git-Url: https://git.deb.at/?a=commitdiff_plain;h=110af2b88f0271f6c7a853291d252640dc54455f;p=rhonda%2Fimpostor.git Add sync options method --- diff --git a/src/Impostor.Api/Games/IGame.cs b/src/Impostor.Api/Games/IGame.cs index 17f67f1..1460adc 100644 --- a/src/Impostor.Api/Games/IGame.cs +++ b/src/Impostor.Api/Games/IGame.cs @@ -34,6 +34,13 @@ namespace Impostor.Api.Games IClientPlayer GetClientPlayer(int clientId); + /// + /// Syncs the internal to all players. + /// Necessary to do if you modified it, otherwise it won't be used. + /// + /// + ValueTask SyncSettingsAsync(); + /// /// Send the message to all players. /// diff --git a/src/Impostor.Plugins.Example/Handlers/PlayerEventListener.cs b/src/Impostor.Plugins.Example/Handlers/PlayerEventListener.cs index 9d16229..eaaf833 100644 --- a/src/Impostor.Plugins.Example/Handlers/PlayerEventListener.cs +++ b/src/Impostor.Plugins.Example/Handlers/PlayerEventListener.cs @@ -24,6 +24,15 @@ namespace Impostor.Plugins.Example.Handlers { 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); } diff --git a/src/Impostor.Server/Net/State/Game.Api.cs b/src/Impostor.Server/Net/State/Game.Api.cs index 0a764e3..2a5ec4a 100644 --- a/src/Impostor.Server/Net/State/Game.Api.cs +++ b/src/Impostor.Server/Net/State/Game.Api.cs @@ -1,13 +1,36 @@ -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