Add a button to reset lobby options to default.

This commit is contained in:
Paul Chote
2023-11-11 22:56:21 +00:00
committed by Gustas
parent 9a3c39878d
commit 9d174cd87d
6 changed files with 86 additions and 1 deletions

View File

@@ -177,6 +177,7 @@ namespace OpenRA.Mods.Common.Server
{ "slot_bot", SlotBot },
{ "map", Map },
{ "option", Option },
{ "reset_options", ResetOptions },
{ "assignteams", AssignTeams },
{ "kick", Kick },
{ "vote_kick", VoteKick },
@@ -744,6 +745,49 @@ namespace OpenRA.Mods.Common.Server
}
}
static bool ResetOptions(S server, Connection conn, Session.Client client, string s)
{
lock (server.LobbyInfo)
{
if (!client.IsAdmin)
{
server.SendLocalizedMessageTo(conn, NotAdmin);
return true;
}
var allOptions = server.Map.PlayerActorInfo.TraitInfos<ILobbyOptions>()
.Concat(server.Map.WorldActorInfo.TraitInfos<ILobbyOptions>())
.SelectMany(t => t.LobbyOptions(server.Map));
var options = new Dictionary<string, Session.LobbyOptionState>();
foreach (var o in allOptions)
{
if (o.DefaultValue != server.LobbyInfo.GlobalSettings.LobbyOptions[o.Id].Value)
server.SendLocalizedMessage(ValueChanged, Translation.Arguments(
"player", client.Name,
"name", o.Name,
"value", o.Label(o.DefaultValue)));
options[o.Id] = new Session.LobbyOptionState
{
IsLocked = o.IsLocked,
Value = o.DefaultValue,
PreferredValue = o.DefaultValue
};
}
server.LobbyInfo.GlobalSettings.LobbyOptions = options;
server.SyncLobbyGlobalSettings();
foreach (var c in server.LobbyInfo.Clients)
c.State = Session.ClientState.NotReady;
server.SyncLobbyClients();
return true;
}
}
static bool AssignTeams(S server, Connection conn, Session.Client client, string raw)
{
lock (server.LobbyInfo)