Resolve lobby option notifications client-side.
This commit is contained in:
@@ -112,18 +112,12 @@ namespace OpenRA.Mods.Common.Server
|
||||
[FluentReference]
|
||||
const string InvalidConfigurationCommand = "notification-invalid-configuration-command";
|
||||
|
||||
[FluentReference("option")]
|
||||
const string OptionLocked = "notification-option-locked";
|
||||
|
||||
[FluentReference("player", "map")]
|
||||
const string ChangedMap = "notification-changed-map";
|
||||
|
||||
[FluentReference]
|
||||
const string MapBotsDisabled = "notification-map-bots-disabled";
|
||||
|
||||
[FluentReference("player", "name", "value")]
|
||||
const string ValueChanged = "notification-option-changed";
|
||||
|
||||
[FluentReference]
|
||||
const string NoMoveSpectators = "notification-admin-move-spectators";
|
||||
|
||||
@@ -722,18 +716,12 @@ namespace OpenRA.Mods.Common.Server
|
||||
|
||||
var split = s.Split(' ');
|
||||
if (split.Length < 2 || !options.TryGetValue(split[0], out var option) ||
|
||||
!option.Values.ContainsKey(split[1]))
|
||||
option.IsLocked || !option.Values.ContainsKey(split[1]))
|
||||
{
|
||||
server.SendFluentMessageTo(conn, InvalidConfigurationCommand);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (option.IsLocked)
|
||||
{
|
||||
server.SendFluentMessageTo(conn, OptionLocked, ["option", option.Name]);
|
||||
return true;
|
||||
}
|
||||
|
||||
var oo = server.LobbyInfo.GlobalSettings.LobbyOptions[option.Id];
|
||||
if (oo.Value == split[1])
|
||||
return true;
|
||||
@@ -747,8 +735,6 @@ namespace OpenRA.Mods.Common.Server
|
||||
oo.Value = oo.PreferredValue = split[1];
|
||||
|
||||
server.SyncLobbyGlobalSettings();
|
||||
server.SendFluentMessage(ValueChanged, "player", client.Name, "name", option.Name, "value", option.Label(split[1]));
|
||||
|
||||
foreach (var c in server.LobbyInfo.Clients)
|
||||
c.State = Session.ClientState.NotReady;
|
||||
|
||||
@@ -768,28 +754,16 @@ namespace OpenRA.Mods.Common.Server
|
||||
return true;
|
||||
}
|
||||
|
||||
var allOptions = server.Map.PlayerActorInfo.TraitInfos<ILobbyOptions>()
|
||||
server.LobbyInfo.GlobalSettings.LobbyOptions = 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.SendFluentMessage(ValueChanged,
|
||||
"player", client.Name,
|
||||
"name", o.Name,
|
||||
"value", o.Label(o.DefaultValue));
|
||||
|
||||
options[o.Id] = new Session.LobbyOptionState
|
||||
.SelectMany(t => t.LobbyOptions(server.Map))
|
||||
.ToDictionary(o => o.Id, o => 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)
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright (c) The OpenRA Developers and Contributors
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version. For more
|
||||
* information, see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Linq;
|
||||
using OpenRA.Network;
|
||||
using OpenRA.Server;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Server
|
||||
{
|
||||
public class LobbySettingsNotification : ServerTrait, IClientJoined
|
||||
{
|
||||
[FluentReference("name", "value")]
|
||||
const string NotificationLobbyOption = "notification-lobby-option";
|
||||
|
||||
public void ClientJoined(OpenRA.Server.Server server, Connection conn)
|
||||
{
|
||||
lock (server.LobbyInfo)
|
||||
{
|
||||
var defaults = new Session.Global();
|
||||
LobbyCommands.LoadMapSettings(server, defaults, server.Map);
|
||||
|
||||
var options = server.Map.PlayerActorInfo.TraitInfos<ILobbyOptions>()
|
||||
.Concat(server.Map.WorldActorInfo.TraitInfos<ILobbyOptions>())
|
||||
.SelectMany(t => t.LobbyOptions(server.Map))
|
||||
.ToDictionary(o => o.Id, o => o);
|
||||
|
||||
foreach (var kv in server.LobbyInfo.GlobalSettings.LobbyOptions)
|
||||
if (!defaults.LobbyOptions.TryGetValue(kv.Key, out var def) || kv.Value.Value != def.Value)
|
||||
if (options.TryGetValue(kv.Key, out var option))
|
||||
server.SendFluentMessageTo(conn, NotificationLobbyOption, ["name", option.Name, "value", option.Values[kv.Value.Value]]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -60,6 +60,12 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
[FluentReference]
|
||||
const string ChatDisabled = "label-chat-disabled";
|
||||
|
||||
[FluentReference("name", "value")]
|
||||
const string OptionValue = "notification-lobby-option";
|
||||
|
||||
[FluentReference("name", "value")]
|
||||
const string OptionChanged = "notification-lobby-option-changed";
|
||||
|
||||
static readonly Action DoNothing = () => { };
|
||||
|
||||
readonly ModData modData;
|
||||
@@ -108,6 +114,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
bool resetOptionsButtonEnabled;
|
||||
bool mapAvailable;
|
||||
Dictionary<int, SpawnOccupant> spawnOccupants = [];
|
||||
Dictionary<string, Session.LobbyOptionState> lobbyOptions = [];
|
||||
|
||||
readonly string chatLineSound;
|
||||
readonly string playerJoinedSound;
|
||||
@@ -672,6 +679,15 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
var missionData = map.WorldActorInfo.TraitInfoOrDefault<MissionDataInfo>();
|
||||
if (missionData != null && !string.IsNullOrEmpty(missionData.Briefing))
|
||||
TextNotificationsManager.AddSystemLine(missionData.Briefing.Replace("\\n", "\n"));
|
||||
|
||||
var allOptions = map.PlayerActorInfo.TraitInfos<ILobbyOptions>()
|
||||
.Concat(map.WorldActorInfo.TraitInfos<ILobbyOptions>())
|
||||
.SelectMany(t => t.LobbyOptions(map));
|
||||
|
||||
lobbyOptions = orderManager.LobbyInfo.GlobalSettings.LobbyOptions;
|
||||
foreach (var o in allOptions)
|
||||
if (lobbyOptions.TryGetValue(o.Id, out var s) && s.Value != o.DefaultValue)
|
||||
TextNotificationsManager.AddSystemLine(OptionValue, "name", o.Name, "value", o.Label(s.Value));
|
||||
}
|
||||
|
||||
void UpdateCurrentMap()
|
||||
@@ -959,6 +975,22 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
.OrderBy(o => o.DisplayOrder)
|
||||
.ToArray();
|
||||
|
||||
var updated = orderManager.LobbyInfo.GlobalSettings.LobbyOptions;
|
||||
foreach (var o in mapOptions)
|
||||
{
|
||||
var value = o.DefaultValue;
|
||||
if (lobbyOptions.TryGetValue(o.Id, out var oo))
|
||||
value = oo.Value;
|
||||
|
||||
var updatedValue = o.DefaultValue;
|
||||
if (updated.TryGetValue(o.Id, out var uo))
|
||||
updatedValue = uo.Value;
|
||||
|
||||
if (updatedValue != value)
|
||||
TextNotificationsManager.AddSystemLine(OptionChanged, "name", o.Name, "value", o.Label(updatedValue));
|
||||
}
|
||||
|
||||
lobbyOptions = updated;
|
||||
resetOptionsButtonEnabled = mapOptions.Any(o => o.DefaultValue != serverOptions[o.Id].Value);
|
||||
}
|
||||
|
||||
|
||||
@@ -186,7 +186,6 @@ ServerTraits:
|
||||
SkirmishLogic
|
||||
PlayerPinger
|
||||
MasterServerPinger
|
||||
LobbySettingsNotification
|
||||
|
||||
ChromeMetrics:
|
||||
common|metrics.yaml
|
||||
|
||||
@@ -29,7 +29,6 @@ notification-unknown-map = Map was not found on server.
|
||||
notification-searching-map = Searching for map on the Resource Center...
|
||||
notification-admin-change-configuration = Only the host can change the configuration.
|
||||
notification-changed-map = { $player } changed the map to { $map }.
|
||||
notification-option-changed = { $player } changed { $name } to { $value }.
|
||||
notification-you-were-kicked = You have been kicked from the server.
|
||||
notification-admin-kicked = { $admin } kicked { $player } from the server.
|
||||
notification-kicked = { $player } was kicked from the server.
|
||||
@@ -57,7 +56,6 @@ notification-you-were-banned = You have been banned from the server.
|
||||
notification-you-were-temp-banned = You have been temporarily banned from the server.
|
||||
notification-game-full = The game is full.
|
||||
notification-new-admin = { $player } is now the admin.
|
||||
notification-option-locked = { $option } cannot be changed.
|
||||
notification-invalid-configuration-command = Invalid configuration command.
|
||||
notification-admin-option = Only the host can set that option.
|
||||
notification-error-number-teams = Could not parse the number of teams: { $raw }.
|
||||
@@ -83,9 +81,6 @@ notification-requires-authentication = Server requires players to have an OpenRA
|
||||
notification-no-permission-to-join = You do not have permission to join this server.
|
||||
notification-slot-closed = Your slot was closed by the host.
|
||||
|
||||
## LobbySettingsNotification
|
||||
notification-lobby-option = { $name }: { $value }.
|
||||
|
||||
## ServerOrders, UnitOrders
|
||||
notification-joined = { $player } has joined the game.
|
||||
notification-lobby-disconnected = { $player } has left.
|
||||
@@ -207,6 +202,10 @@ label-chat-availability =
|
||||
## LobbyLogic, ServerListLogic
|
||||
label-bot-player = AI Player
|
||||
|
||||
## LobbyLogic
|
||||
notification-lobby-option = { $name }: { $value }.
|
||||
notification-lobby-option-changed = { $name } changed to { $value }.
|
||||
|
||||
## IngameMenuLogic
|
||||
menu-ingame =
|
||||
.leave = Leave
|
||||
|
||||
@@ -183,7 +183,6 @@ ServerTraits:
|
||||
SkirmishLogic
|
||||
PlayerPinger
|
||||
MasterServerPinger
|
||||
LobbySettingsNotification
|
||||
|
||||
ChromeMetrics:
|
||||
common|metrics.yaml
|
||||
|
||||
@@ -217,7 +217,6 @@ ServerTraits:
|
||||
SkirmishLogic
|
||||
PlayerPinger
|
||||
MasterServerPinger
|
||||
LobbySettingsNotification
|
||||
|
||||
ChromeMetrics:
|
||||
common|metrics.yaml
|
||||
|
||||
@@ -216,7 +216,6 @@ ServerTraits:
|
||||
SkirmishLogic
|
||||
PlayerPinger
|
||||
MasterServerPinger
|
||||
LobbySettingsNotification
|
||||
|
||||
ChromeMetrics:
|
||||
common|metrics.yaml
|
||||
|
||||
Reference in New Issue
Block a user