Allow game presets to disallow latejoining (#1816)
* Allow game presets to disallow latejoining * Update Content.Server/GameTicking/GameTicker.cs Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com> Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
2bdf359289
commit
944ce2cc92
@@ -26,6 +26,7 @@ namespace Content.Client.GameTicking
|
||||
|
||||
[ViewVariables] public bool AreWeReady { get; private set; }
|
||||
[ViewVariables] public bool IsGameStarted { get; private set; }
|
||||
[ViewVariables] public bool DisallowedLateJoin { get; private set; }
|
||||
[ViewVariables] public string ServerInfoBlob { get; private set; }
|
||||
[ViewVariables] public DateTime StartTime { get; private set; }
|
||||
[ViewVariables] public bool Paused { get; private set; }
|
||||
@@ -34,6 +35,7 @@ namespace Content.Client.GameTicking
|
||||
public event Action InfoBlobUpdated;
|
||||
public event Action LobbyStatusUpdated;
|
||||
public event Action LobbyReadyUpdated;
|
||||
public event Action LobbyLateJoinStatusUpdated;
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
@@ -50,11 +52,17 @@ namespace Content.Client.GameTicking
|
||||
{
|
||||
IoCManager.Resolve<IClyde>().RequestWindowAttention();
|
||||
});
|
||||
_netManager.RegisterNetMessage<MsgTickerLateJoinStatus>(nameof(MsgTickerLateJoinStatus), LateJoinStatus);
|
||||
|
||||
Ready = new Dictionary<NetSessionId, bool>();
|
||||
_initialized = true;
|
||||
}
|
||||
|
||||
private void LateJoinStatus(MsgTickerLateJoinStatus message)
|
||||
{
|
||||
DisallowedLateJoin = message.Disallowed;
|
||||
LobbyLateJoinStatusUpdated?.Invoke();
|
||||
}
|
||||
|
||||
|
||||
private void JoinLobby(MsgTickerJoinLobby message)
|
||||
|
||||
@@ -9,6 +9,7 @@ namespace Content.Client.Interfaces
|
||||
bool IsGameStarted { get; }
|
||||
string ServerInfoBlob { get; }
|
||||
bool AreWeReady { get; }
|
||||
bool DisallowedLateJoin { get; }
|
||||
DateTime StartTime { get; }
|
||||
bool Paused { get; }
|
||||
Dictionary<NetSessionId, bool> Ready { get; }
|
||||
@@ -17,5 +18,6 @@ namespace Content.Client.Interfaces
|
||||
event Action InfoBlobUpdated;
|
||||
event Action LobbyStatusUpdated;
|
||||
event Action LobbyReadyUpdated;
|
||||
event Action LobbyLateJoinStatusUpdated;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,6 +101,7 @@ namespace Content.Client.State
|
||||
_clientGameTicker.InfoBlobUpdated += UpdateLobbyUi;
|
||||
_clientGameTicker.LobbyStatusUpdated += LobbyStatusUpdated;
|
||||
_clientGameTicker.LobbyReadyUpdated += LobbyReadyUpdated;
|
||||
_clientGameTicker.LobbyLateJoinStatusUpdated += LobbyLateJoinStatusUpdated;
|
||||
}
|
||||
|
||||
public override void Shutdown()
|
||||
@@ -109,6 +110,7 @@ namespace Content.Client.State
|
||||
_clientGameTicker.InfoBlobUpdated -= UpdateLobbyUi;
|
||||
_clientGameTicker.LobbyStatusUpdated -= LobbyStatusUpdated;
|
||||
_clientGameTicker.LobbyReadyUpdated -= LobbyReadyUpdated;
|
||||
_clientGameTicker.LobbyLateJoinStatusUpdated -= LobbyLateJoinStatusUpdated;
|
||||
|
||||
_clientGameTicker.Ready.Clear();
|
||||
|
||||
@@ -173,6 +175,11 @@ namespace Content.Client.State
|
||||
UpdateLobbyUi();
|
||||
}
|
||||
|
||||
private void LobbyLateJoinStatusUpdated()
|
||||
{
|
||||
_lobby.ReadyButton.Disabled = _clientGameTicker.DisallowedLateJoin;
|
||||
}
|
||||
|
||||
private void UpdateLobbyUi()
|
||||
{
|
||||
if (_lobby == null)
|
||||
@@ -191,6 +198,7 @@ namespace Content.Client.State
|
||||
_lobby.StartTime.Text = "";
|
||||
_lobby.ReadyButton.Text = Loc.GetString("Ready Up");
|
||||
_lobby.ReadyButton.ToggleMode = true;
|
||||
_lobby.ReadyButton.Disabled = false;
|
||||
_lobby.ReadyButton.Pressed = _clientGameTicker.AreWeReady;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ namespace Content.Server.GameTicking
|
||||
public abstract bool Start(IReadOnlyList<IPlayerSession> readyPlayers, bool force = false);
|
||||
public virtual string ModeTitle => "Sandbox";
|
||||
public virtual string Description => "Secret!";
|
||||
public virtual bool DisallowLateJoin => false;
|
||||
public Dictionary<string, HumanoidCharacterProfile> readyProfiles;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,9 @@ namespace Content.Server.GameTicking.GamePresets
|
||||
public int MinPlayers { get; set; } = 5;
|
||||
public int MinTraitors { get; set; } = 2;
|
||||
public int PlayersPerTraitor { get; set; } = 5;
|
||||
|
||||
public override bool DisallowLateJoin => true;
|
||||
|
||||
private static string TraitorID = "SuspicionTraitor";
|
||||
private static string InnocentID = "SuspicionInnocent";
|
||||
|
||||
|
||||
@@ -94,6 +94,8 @@ namespace Content.Server.GameTicking
|
||||
[ViewVariables] private GameRunLevel _runLevel;
|
||||
[ViewVariables(VVAccess.ReadWrite)] private GridCoordinates _spawnPoint;
|
||||
|
||||
[ViewVariables] private bool DisallowLateJoin { get; set; } = false;
|
||||
|
||||
[ViewVariables] private bool LobbyEnabled => _configurationManager.GetCVar<bool>("game.lobbyenabled");
|
||||
|
||||
[ViewVariables] private bool _updateOnRoundEnd;
|
||||
@@ -142,6 +144,7 @@ namespace Content.Server.GameTicking
|
||||
_netManager.RegisterNetMessage<MsgTickerLobbyReady>(nameof(MsgTickerLobbyReady));
|
||||
_netManager.RegisterNetMessage<MsgRoundEndMessage>(nameof(MsgRoundEndMessage));
|
||||
_netManager.RegisterNetMessage<MsgRequestWindowAttention>(nameof(MsgRequestWindowAttention));
|
||||
_netManager.RegisterNetMessage<MsgTickerLateJoinStatus>(nameof(MsgTickerLateJoinStatus));
|
||||
|
||||
SetStartPreset(_configurationManager.GetCVar<string>("game.defaultpreset"));
|
||||
|
||||
@@ -285,6 +288,8 @@ namespace Content.Server.GameTicking
|
||||
// Time to start the preset.
|
||||
var preset = MakeGamePreset(profiles);
|
||||
|
||||
DisallowLateJoin |= preset.DisallowLateJoin;
|
||||
|
||||
if (!preset.Start(assignedJobs.Keys.ToList(), force))
|
||||
{
|
||||
SetStartPreset(_configurationManager.GetCVar<string>("game.fallbackpreset"));
|
||||
@@ -300,6 +305,13 @@ namespace Content.Server.GameTicking
|
||||
_roundStartTimeSpan = IoCManager.Resolve<IGameTiming>().RealTime;
|
||||
_sendStatusToAll();
|
||||
ReqWindowAttentionAll();
|
||||
UpdateLateJoinStatus();
|
||||
}
|
||||
|
||||
private void UpdateLateJoinStatus()
|
||||
{
|
||||
var msg = new MsgTickerLateJoinStatus(null) {Disallowed = DisallowLateJoin};
|
||||
_netManager.ServerSendToAll(msg);
|
||||
}
|
||||
|
||||
private void SendServerMessage(string message)
|
||||
@@ -405,7 +417,7 @@ namespace Content.Server.GameTicking
|
||||
|
||||
foreach (var rule in _gameRules)
|
||||
{
|
||||
if (rule.GetType().Equals(t))
|
||||
if (rule.GetType().IsAssignableFrom(t))
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -646,6 +658,7 @@ namespace Content.Server.GameTicking
|
||||
|
||||
_spawnedPositions.Clear();
|
||||
_manifest.Clear();
|
||||
DisallowLateJoin = false;
|
||||
}
|
||||
|
||||
private void _preRoundSetup()
|
||||
@@ -776,6 +789,12 @@ namespace Content.Server.GameTicking
|
||||
string jobId = null,
|
||||
bool lateJoin = true)
|
||||
{
|
||||
if (lateJoin && DisallowLateJoin)
|
||||
{
|
||||
MakeObserve(session);
|
||||
return;
|
||||
}
|
||||
|
||||
_playerJoinGame(session);
|
||||
|
||||
var data = session.ContentData();
|
||||
|
||||
@@ -54,6 +54,31 @@ namespace Content.Shared
|
||||
}
|
||||
}
|
||||
|
||||
protected class MsgTickerLateJoinStatus : NetMessage
|
||||
{
|
||||
#region REQUIRED
|
||||
|
||||
public const MsgGroups GROUP = MsgGroups.Command;
|
||||
public const string NAME = nameof(MsgTickerLateJoinStatus);
|
||||
|
||||
public bool Disallowed { get; set; }
|
||||
|
||||
public MsgTickerLateJoinStatus(INetChannel channel) : base(NAME, GROUP) { }
|
||||
|
||||
#endregion
|
||||
|
||||
public override void ReadFromBuffer(NetIncomingMessage buffer)
|
||||
{
|
||||
Disallowed = buffer.ReadBoolean();
|
||||
}
|
||||
|
||||
public override void WriteToBuffer(NetOutgoingMessage buffer)
|
||||
{
|
||||
buffer.Write(Disallowed);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected class MsgTickerLobbyStatus : NetMessage
|
||||
{
|
||||
#region REQUIRED
|
||||
|
||||
Reference in New Issue
Block a user