Add vote kick

(cherry picked from commit 144e716cdf)
This commit is contained in:
Gustas
2025-11-02 02:57:04 +00:00
committed by hacker
parent aacf0e2b8d
commit ee4403f923
5 changed files with 103 additions and 98 deletions

View File

@@ -57,10 +57,10 @@ namespace OpenRA.Mods.Common.Server
[FluentReference]
const string NoKickGameStarted = "notification-no-kick-game-started";
[FluentReference("admin", "player")]
[TranslationReference("admin", "player")]
const string AdminKicked = "notification-admin-kicked";
[FluentReference("player")]
[TranslationReference("player")]
const string Kicked = "notification-kicked";
[FluentReference("admin", "player")]
@@ -159,37 +159,35 @@ namespace OpenRA.Mods.Common.Server
[FluentReference]
const string YouWereKicked = "notification-you-were-kicked";
[FluentReference]
[TranslationReference]
const string VoteKickDisabled = "notification-vote-kick-disabled";
readonly IDictionary<string, Func<S, Connection, Session.Client, string, bool>> commandHandlers =
new Dictionary<string, Func<S, Connection, Session.Client, string, bool>>
{
{ "state", State },
{ "startgame", StartGame },
{ "slot", Slot },
{ "allow_spectators", AllowSpectators },
{ "spectate", Specate },
{ "slot_close", SlotClose },
{ "slot_open", SlotOpen },
{ "slot_bot", SlotBot },
{ "map", Map },
{ "option", Option },
{ "reset_options", ResetOptions },
{ "assignteams", AssignTeams },
{ "kick", Kick },
{ "vote_kick", VoteKick },
{ "make_admin", MakeAdmin },
{ "make_spectator", MakeSpectator },
{ "name", Name },
{ "faction", Faction },
{ "team", Team },
{ "handicap", Handicap },
{ "spawn", Spawn },
{ "clear_spawn", ClearPlayerSpawn },
{ "color", PlayerColor },
{ "sync_lobby", SyncLobby }
};
readonly IDictionary<string, Func<S, Connection, Session.Client, string, bool>> commandHandlers = new Dictionary<string, Func<S, Connection, Session.Client, string, bool>>
{
{ "state", State },
{ "startgame", StartGame },
{ "slot", Slot },
{ "allow_spectators", AllowSpectators },
{ "spectate", Specate },
{ "slot_close", SlotClose },
{ "slot_open", SlotOpen },
{ "slot_bot", SlotBot },
{ "map", Map },
{ "option", Option },
{ "assignteams", AssignTeams },
{ "kick", Kick },
{ "vote_kick", VoteKick },
{ "make_admin", MakeAdmin },
{ "make_spectator", MakeSpectator },
{ "name", Name },
{ "faction", Faction },
{ "team", Team },
{ "handicap", Handicap },
{ "spawn", Spawn },
{ "clear_spawn", ClearPlayerSpawn },
{ "color", PlayerColor },
{ "sync_lobby", SyncLobby }
};
static bool ValidateSlotCommand(S server, Connection conn, Session.Client client, string arg, bool requiresHost)
{
@@ -873,7 +871,7 @@ namespace OpenRA.Mods.Common.Server
}
Log.Write("server", $"Kicking client {kickClientID}.");
server.SendFluentMessage(AdminKicked, "admin", client.Name, "player", kickClient.Name);
server.SendLocalizedMessage(AdminKicked, Translation.Arguments("admin", client.Name, "player", kickClient.Name));
server.SendOrderTo(kickConn, "ServerError", YouWereKicked);
server.DropClient(kickConn);
@@ -898,13 +896,13 @@ namespace OpenRA.Mods.Common.Server
var split = s.Split(' ');
if (split.Length != 2)
{
server.SendFluentMessageTo(conn, MalformedCommand, new object[] { "command", "vote_kick" });
server.SendLocalizedMessageTo(conn, MalformedCommand, Translation.Arguments("command", "vote_kick"));
return true;
}
if (!server.Settings.EnableVoteKick)
{
server.SendFluentMessageTo(conn, VoteKickDisabled);
server.SendLocalizedMessageTo(conn, VoteKickDisabled);
return true;
}
@@ -913,27 +911,27 @@ namespace OpenRA.Mods.Common.Server
if (kickConn == null)
{
server.SendFluentMessageTo(conn, KickNone);
server.SendLocalizedMessageTo(conn, KickNone);
return true;
}
var kickClient = server.GetClient(kickConn);
if (client == kickClient)
{
server.SendFluentMessageTo(conn, NoKickSelf);
server.SendLocalizedMessageTo(conn, NoKickSelf);
return true;
}
if (!bool.TryParse(split[1], out var vote))
{
server.SendFluentMessageTo(conn, MalformedCommand, new object[] { "command", "vote_kick" });
server.SendLocalizedMessageTo(conn, MalformedCommand, Translation.Arguments("command", "vote_kick"));
return true;
}
if (server.VoteKickTracker.VoteKick(conn, client, kickConn, kickClient, kickClientID, vote))
{
Log.Write("server", $"Kicking client {kickClientID}.");
server.SendFluentMessage(Kicked, "player", kickClient.Name);
server.SendLocalizedMessage(Kicked, Translation.Arguments("player", kickClient.Name));
server.SendOrderTo(kickConn, "ServerError", YouWereKicked);
server.DropClient(kickConn);

View File

@@ -50,10 +50,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic
[FluentReference]
const string Gone = "label-client-state-disconnected";
[FluentReference]
[TranslationReference]
const string KickTooltip = "button-kick-player";
[FluentReference("player")]
[TranslationReference("player")]
const string KickTitle = "dialog-kick.title";
[FluentReference]
@@ -62,28 +62,28 @@ namespace OpenRA.Mods.Common.Widgets.Logic
[FluentReference]
const string KickAccept = "dialog-kick.confirm";
[FluentReference]
[TranslationReference]
const string KickVoteTooltip = "button-vote-kick-player";
[FluentReference("player")]
[TranslationReference("player")]
const string VoteKickTitle = "dialog-vote-kick.title";
[FluentReference]
[TranslationReference]
const string VoteKickPrompt = "dialog-vote-kick.prompt";
[FluentReference("bots")]
[TranslationReference("bots")]
const string VoteKickPromptBreakBots = "dialog-vote-kick.prompt-break-bots";
[FluentReference]
[TranslationReference]
const string VoteKickVoteStart = "dialog-vote-kick.vote-start";
[FluentReference]
[TranslationReference]
const string VoteKickVoteFor = "dialog-vote-kick.vote-for";
[FluentReference]
[TranslationReference]
const string VoteKickVoteAgainst = "dialog-vote-kick.vote-against";
[FluentReference]
[TranslationReference]
const string VoteKickVoteCancel = "dialog-vote-kick.vote-cancel";
[ObjectCreator.UseCtor]
@@ -133,10 +133,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var teamTemplate = playerPanel.Get<ScrollItemWidget>("TEAM_TEMPLATE");
var playerTemplate = playerPanel.Get("PLAYER_TEMPLATE");
var spectatorTemplate = playerPanel.Get("SPECTATOR_TEMPLATE");
var unmuteTooltip = FluentProvider.GetMessage(Unmute);
var muteTooltip = FluentProvider.GetMessage(Mute);
var kickTooltip = FluentProvider.GetMessage(KickTooltip);
var voteKickTooltip = FluentProvider.GetMessage(KickVoteTooltip);
var unmuteTooltip = TranslationProvider.GetString(Unmute);
var muteTooltip = TranslationProvider.GetString(Mute);
var kickTooltip = TranslationProvider.GetString(KickTooltip);
var voteKickTooltip = TranslationProvider.GetString(KickVoteTooltip);
playerPanel.RemoveChildren();
var teams = world.Players.Where(p => !p.NonCombatant && p.Playable)
@@ -159,14 +159,13 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{
ConfirmationDialogs.ButtonPrompt(modData,
title: VoteKickTitle,
titleArguments: Translation.Arguments("player", client.Name),
text: botsCount > 0 ? VoteKickPromptBreakBots : VoteKickPrompt,
titleArguments: new object[] { "player", client.Name },
textArguments: new object[] { "bots", botsCount },
textArguments: Translation.Arguments("bots", botsCount),
onConfirm: () =>
{
orderManager.IssueOrder(Order.Command($"vote_kick {client.Index} {true}"));
hideMenu(false);
closeMenu();
},
confirmText: VoteKickVoteStart,
onCancel: () => hideMenu(false));
@@ -175,33 +174,31 @@ namespace OpenRA.Mods.Common.Widgets.Logic
ConfirmationDialogs.ButtonPrompt(modData,
title: VoteKickTitle,
titleArguments: Translation.Arguments("player", client.Name),
text: botsCount > 0 ? VoteKickPromptBreakBots : VoteKickPrompt,
titleArguments: new object[] { "player", client.Name },
textArguments: new object[] { "bots", botsCount },
textArguments: Translation.Arguments("bots", botsCount),
onConfirm: () =>
{
orderManager.IssueOrder(Order.Command($"vote_kick {client.Index} {true}"));
hideMenu(false);
closeMenu();
},
confirmText: VoteKickVoteFor,
onCancel: () => hideMenu(false),
cancelText: VoteKickVoteCancel,
onOther: () =>
{
Ui.CloseWindow();
orderManager.IssueOrder(Order.Command($"vote_kick {client.Index} {false}"));
hideMenu(false);
closeMenu();
},
otherText: VoteKickVoteAgainst);
otherText: VoteKickVoteAgainst,
onCancel: () => hideMenu(false),
cancelText: VoteKickVoteCancel);
}
else
{
ConfirmationDialogs.ButtonPrompt(modData,
title: KickTitle,
titleArguments: Translation.Arguments("player", client.Name),
text: KickPrompt,
titleArguments: new object[] { "player", client.Name },
onConfirm: () =>
{
orderManager.IssueOrder(Order.Command($"kick {client.Index} {false}"));