Add temp banning to servers

This commit is contained in:
ScottNZ
2013-06-29 10:58:37 +12:00
parent 6cd69f5c05
commit a6e5a0b53f
11 changed files with 247 additions and 30 deletions

View File

@@ -380,6 +380,7 @@
<Compile Include="Widgets\BuildPaletteWidget.cs" />
<Compile Include="Widgets\LogicTickerWidget.cs" />
<Compile Include="Widgets\Logic\IngameMenuLogic.cs" />
<Compile Include="Widgets\Logic\KickClientLogic.cs" />
<Compile Include="Widgets\Logic\ModBrowserLogic.cs" />
<Compile Include="Widgets\Logic\ColorPickerLogic.cs" />
<Compile Include="Widgets\Logic\ConnectionLogic.cs" />

View File

@@ -413,25 +413,44 @@ namespace OpenRA.Mods.RA.Server
{ "kick",
s =>
{
if (!client.IsAdmin)
{
server.SendOrderTo(conn, "Message", "Only the host can kick players");
return true;
}
int clientID;
int.TryParse(s, out clientID);
var split = s.Split(' ');
if (split.Length < 2)
{
server.SendOrderTo(conn, "Message", "Malformed kick command");
return true;
}
var connToKick = server.conns.SingleOrDefault( c => server.GetClient(c) != null && server.GetClient(c).Index == clientID);
if (connToKick == null)
int kickClientID;
int.TryParse(split[0], out kickClientID);
var kickConn = server.conns.SingleOrDefault(c => server.GetClient(c) != null && server.GetClient(c).Index == kickClientID);
if (kickConn == null)
{
server.SendOrderTo(conn, "Message", "Noone in that slot.");
return true;
}
server.SendOrderTo(connToKick, "ServerError", "You have been kicked from the server");
server.DropClient(connToKick);
var kickConnIP = server.GetClient(kickConn).IpAddress;
Log.Write("server", "Kicking client {0} as requested", kickClientID);
server.SendOrderTo(kickConn, "ServerError", "You have been kicked from the server");
server.DropClient(kickConn);
bool tempBan;
bool.TryParse(split[1], out tempBan);
if (tempBan)
{
Log.Write("server", "Temporarily banning client {0} ({1}) as requested", kickClientID, kickConnIP);
server.TempBans.Add(kickConnIP);
}
server.SyncLobbyInfo();
return true;
}},

View File

@@ -0,0 +1,37 @@
#region Copyright & License Information
/*
* Copyright 2007-2013 The OpenRA Developers (see AUTHORS)
* 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. For more information,
* see COPYING.
*/
#endregion
using System;
using OpenRA.Widgets;
namespace OpenRA.Mods.RA.Widgets.Logic
{
class KickClientLogic
{
[ObjectCreator.UseCtor]
public KickClientLogic(Widget widget, string clientName, Action<bool> okPressed)
{
widget.Get<LabelWidget>("TITLE").GetText = () => "Kick {0}?".F(clientName);
var tempBan = false;
var preventRejoiningCheckbox = widget.Get<CheckboxWidget>("PREVENT_REJOINING_CHECKBOX");
preventRejoiningCheckbox.IsChecked = () => tempBan;
preventRejoiningCheckbox.OnClick = () => tempBan ^= true;
widget.Get<ButtonWidget>("OK_BUTTON").OnClick = () =>
{
widget.Parent.RemoveChild(widget);
okPressed(tempBan);
};
widget.Get<ButtonWidget>("CANCEL_BUTTON").OnClick = () => widget.Parent.RemoveChild(widget);
}
}
}

View File

@@ -20,8 +20,9 @@ namespace OpenRA.Mods.RA.Widgets.Logic
{
public class LobbyLogic
{
Widget lobby;
Widget EditablePlayerTemplate, NonEditablePlayerTemplate, EmptySlotTemplate,
EditableSpectatorTemplate, NonEditableSpectatorTemplate, NewSpectatorTemplate;
EditableSpectatorTemplate, NonEditableSpectatorTemplate, NewSpectatorTemplate;
ScrollPanelWidget chatPanel;
Widget chatTemplate;
@@ -85,7 +86,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
internal LobbyLogic(Widget widget, World world, OrderManager orderManager,
Action onExit, Action onStart, bool addBots)
{
var lobby = widget;
lobby = widget;
this.orderManager = orderManager;
this.OnGameStart = () => { CloseWindow(); onStart(); };
this.onExit = onExit;
@@ -425,7 +426,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
LobbyUtils.SetupClientWidget(template, slot, client, orderManager, client.Bot == null);
LobbyUtils.SetupNameWidget(template, slot, client);
LobbyUtils.SetupKickWidget(template, slot, client, orderManager);
LobbyUtils.SetupKickWidget(template, slot, client, orderManager, lobby);
LobbyUtils.SetupColorWidget(template, slot, client);
LobbyUtils.SetupFactionWidget(template, slot, client, CountryNames);
LobbyUtils.SetupTeamWidget(template, slot, client);
@@ -467,7 +468,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
template = NonEditableSpectatorTemplate.Clone();
LobbyUtils.SetupNameWidget(template, null, client);
LobbyUtils.SetupKickWidget(template, null, client, orderManager);
LobbyUtils.SetupKickWidget(template, null, client, orderManager, lobby);
}
LobbyUtils.SetupClientWidget(template, null, c, orderManager, true);

View File

@@ -262,12 +262,17 @@ namespace OpenRA.Mods.RA.Widgets.Logic
slot.IsVisible = () => false;
}
public static void SetupKickWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager)
public static void SetupKickWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager, Widget lobby)
{
var button = parent.Get<ButtonWidget>("KICK");
button.IsVisible = () => Game.IsHost && c.Index != orderManager.LocalClient.Index;
button.IsDisabled = () => orderManager.LocalClient.IsReady;
button.OnClick = () => orderManager.IssueOrder(Order.Command("kick " + c.Index));
Action<bool> okPressed = tempBan => orderManager.IssueOrder(Order.Command("kick {0} {1}".F(c.Index, tempBan)));
button.OnClick = () => Game.LoadWidget(null, "KICK_CLIENT_DIALOG", lobby, new WidgetArgs
{
{ "clientName", c.Name },
{ "okPressed", okPressed }
});
}
public static void SetupEditableColorWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager, ColorPreviewManagerWidget colorPreview)