- Ban duration can be set in the UI prompt.
- Ban reasons & durations are listed in the banlist menu. - Clients tell the server the reason when kicking/banning another client. - Added GUINumberInput GUIComponent. - Ban duration saving/loading fixes.
This commit is contained in:
@@ -23,23 +23,32 @@ namespace Barotrauma.Networking
|
||||
foreach (BannedPlayer bannedPlayer in bannedPlayers)
|
||||
{
|
||||
GUITextBlock textBlock = new GUITextBlock(
|
||||
new Rectangle(0, 0, 0, 25),
|
||||
new Rectangle(0, 0, 0, 55),
|
||||
bannedPlayer.IP + " (" + bannedPlayer.Name + ")",
|
||||
"",
|
||||
Alignment.Left, Alignment.Left, banFrame);
|
||||
textBlock.Padding = new Vector4(10.0f, 10.0f, 0.0f, 0.0f);
|
||||
Alignment.Left, Alignment.TopLeft, banFrame);
|
||||
textBlock.Padding = new Vector4(10.0f, 10.0f, 10.0f, 10.0f);
|
||||
textBlock.UserData = banFrame;
|
||||
textBlock.ToolTip = bannedPlayer.Reason;
|
||||
|
||||
var removeButton = new GUIButton(new Rectangle(0, 0, 100, 20), "Remove", Alignment.Right | Alignment.CenterY, "", textBlock);
|
||||
var removeButton = new GUIButton(new Rectangle(0, 0, 80, 20), "Remove", Alignment.TopRight, "", textBlock);
|
||||
removeButton.UserData = bannedPlayer;
|
||||
removeButton.OnClicked = RemoveBan;
|
||||
if (bannedPlayer.IP.IndexOf(".x") <= -1)
|
||||
{
|
||||
var rangeBanButton = new GUIButton(new Rectangle(-100, 0, 100, 20), "Ban range", Alignment.Right | Alignment.CenterY, "", textBlock);
|
||||
var rangeBanButton = new GUIButton(new Rectangle(-85, 0, 90, 20), "Ban range", Alignment.TopRight, "", textBlock);
|
||||
rangeBanButton.UserData = bannedPlayer;
|
||||
rangeBanButton.OnClicked = RangeBan;
|
||||
}
|
||||
|
||||
var reasonText = new GUITextBlock(new Rectangle(0, 0, 170, 20),
|
||||
string.IsNullOrEmpty(bannedPlayer.Reason) ? "Reason: none" : ToolBox.LimitString("Reason: " + bannedPlayer.Reason, GUI.SmallFont, 170),
|
||||
"", Alignment.BottomLeft, Alignment.TopLeft, textBlock, false, GUI.SmallFont);
|
||||
reasonText.ToolTip = bannedPlayer.Reason;
|
||||
|
||||
new GUITextBlock(new Rectangle(0, 0, 100, 20),
|
||||
bannedPlayer.ExpirationTime == null ? "Permanent" : "Expires " + bannedPlayer.ExpirationTime.Value.ToString(),
|
||||
"", Alignment.BottomRight, Alignment.TopRight, textBlock, false, GUI.SmallFont);
|
||||
|
||||
}
|
||||
|
||||
return banFrame;
|
||||
|
||||
@@ -1245,9 +1245,9 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
NetOutgoingMessage msg = client.CreateMessage();
|
||||
msg.Write((byte)ClientPacketHeader.SERVER_COMMAND);
|
||||
msg.Write((byte)ClientPermissions.Kick);
|
||||
//TODO: write the reason
|
||||
msg.Write((byte)ClientPermissions.Kick);
|
||||
msg.Write(kickedName);
|
||||
msg.Write(reason);
|
||||
|
||||
client.SendMessage(msg, NetDeliveryMethod.ReliableUnordered);
|
||||
}
|
||||
@@ -1257,8 +1257,8 @@ namespace Barotrauma.Networking
|
||||
NetOutgoingMessage msg = client.CreateMessage();
|
||||
msg.Write((byte)ClientPacketHeader.SERVER_COMMAND);
|
||||
msg.Write((byte)ClientPermissions.Ban);
|
||||
//TODO: write the reason
|
||||
msg.Write(kickedName);
|
||||
msg.Write(reason);
|
||||
|
||||
client.SendMessage(msg, NetDeliveryMethod.ReliableUnordered);
|
||||
}
|
||||
|
||||
@@ -164,25 +164,58 @@ namespace Barotrauma.Networking
|
||||
|
||||
public void CreateKickReasonPrompt(string clientName, bool ban, bool rangeBan = false)
|
||||
{
|
||||
var banReasonPrompt = new GUIMessageBox(ban ? "Reason for the ban?" : "Reason for kicking?", "", new string[] { "OK" }, 400, 250);
|
||||
var textBox = new GUITextBox(new Rectangle(0, 0, 0, 50), Alignment.Center, "", banReasonPrompt.children[0]);
|
||||
textBox.Wrap = true;
|
||||
textBox.MaxTextLength = 100;
|
||||
var banReasonPrompt = new GUIMessageBox(ban ? "Reason for the ban?" : "Reason for kicking?", "", new string[] { "OK", "Cancel" }, 400, 300);
|
||||
var banReasonBox = new GUITextBox(new Rectangle(0, 30, 0, 50), Alignment.TopCenter, "", banReasonPrompt.children[0]);
|
||||
banReasonBox.Wrap = true;
|
||||
banReasonBox.MaxTextLength = 100;
|
||||
|
||||
GUINumberInput durationInputDays = null, durationInputHours = null;
|
||||
GUITickBox permaBanTickBox = null;
|
||||
|
||||
if (ban)
|
||||
{
|
||||
new GUITextBlock(new Rectangle(0, 80, 0, 0), "Duration:", "", banReasonPrompt.children[0]);
|
||||
permaBanTickBox = new GUITickBox(new Rectangle(0, 110, 15, 15), "Permanent", Alignment.TopLeft, banReasonPrompt.children[0]);
|
||||
permaBanTickBox.Selected = true;
|
||||
|
||||
var durationContainer = new GUIFrame(new Rectangle(0, 130, 0, 40), null, banReasonPrompt.children[0]);
|
||||
durationContainer.Visible = false;
|
||||
|
||||
permaBanTickBox.OnSelected += (tickBox) =>
|
||||
{
|
||||
durationContainer.Visible = !tickBox.Selected;
|
||||
return true;
|
||||
};
|
||||
|
||||
new GUITextBlock(new Rectangle(0, 0, 30, 20), "Days:", "", Alignment.TopLeft, Alignment.CenterLeft, durationContainer);
|
||||
durationInputDays = new GUINumberInput(new Rectangle(40, 0, 50, 20), "", 0, 1000, durationContainer);
|
||||
|
||||
new GUITextBlock(new Rectangle(100, 0, 30, 20), "Hours:", "", Alignment.TopLeft, Alignment.CenterLeft, durationContainer);
|
||||
durationInputHours = new GUINumberInput(new Rectangle(150, 0, 50, 20), "", 0, 24, durationContainer);
|
||||
}
|
||||
|
||||
banReasonPrompt.Buttons[0].OnClicked += (btn, userData) =>
|
||||
{
|
||||
if (ban)
|
||||
{
|
||||
//TODO: a way to set ban duration in the prompt
|
||||
BanPlayer(clientName, textBox.Text, ban, null);
|
||||
if (!permaBanTickBox.Selected)
|
||||
{
|
||||
TimeSpan banDuration = new TimeSpan(durationInputDays.Value, durationInputHours.Value, 0, 0);
|
||||
BanPlayer(clientName, banReasonBox.Text, ban, banDuration);
|
||||
}
|
||||
else
|
||||
{
|
||||
BanPlayer(clientName, banReasonBox.Text, ban);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
KickPlayer(clientName, textBox.Text);
|
||||
KickPlayer(clientName, banReasonBox.Text);
|
||||
}
|
||||
return true;
|
||||
};
|
||||
banReasonPrompt.Buttons[0].OnClicked += banReasonPrompt.Close;
|
||||
banReasonPrompt.Buttons[1].OnClicked += banReasonPrompt.Close;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user