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);