Option to supply a reason for banning/kicking, logic for handling question prompts in the debug console
This commit is contained in:
@@ -29,6 +29,7 @@ namespace Barotrauma.Networking
|
||||
Alignment.Left, Alignment.Left, banFrame);
|
||||
textBlock.Padding = new Vector4(10.0f, 10.0f, 0.0f, 0.0f);
|
||||
textBlock.UserData = banFrame;
|
||||
textBlock.ToolTip = bannedPlayer.Reason;
|
||||
|
||||
var removeButton = new GUIButton(new Rectangle(0, 0, 100, 20), "Remove", Alignment.Right | Alignment.CenterY, "", textBlock);
|
||||
removeButton.UserData = bannedPlayer;
|
||||
|
||||
@@ -565,26 +565,23 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
string disconnectMsg = inc.ReadString();
|
||||
|
||||
switch (disconnectMsg)
|
||||
if (disconnectMsg.Contains("You have been disconnected") ||
|
||||
disconnectMsg.Contains("You have been banned") ||
|
||||
disconnectMsg.Contains("You have been kicked") ||
|
||||
disconnectMsg == "The server has been shut down")
|
||||
{
|
||||
case "The server has been shut down":
|
||||
case "You have been banned from the server":
|
||||
case "You have been kicked from the server":
|
||||
case "You have been disconnected because of excessive desync":
|
||||
case "You have been disconnected because syncing your client with the server took too long.":
|
||||
var msgBox = new GUIMessageBox("CONNECTION LOST", disconnectMsg);
|
||||
msgBox.Buttons[0].OnClicked += ReturnToServerList;
|
||||
break;
|
||||
default:
|
||||
reconnectBox = new GUIMessageBox(
|
||||
"CONNECTION LOST",
|
||||
"You have been disconnected from the server. Reconnecting...", new string[0]);
|
||||
|
||||
connected = false;
|
||||
ConnectToServer(serverIP);
|
||||
break;
|
||||
var msgBox = new GUIMessageBox("CONNECTION LOST", disconnectMsg);
|
||||
msgBox.Buttons[0].OnClicked += ReturnToServerList;
|
||||
}
|
||||
else
|
||||
{
|
||||
reconnectBox = new GUIMessageBox(
|
||||
"CONNECTION LOST",
|
||||
"You have been disconnected from the server. Reconnecting...", new string[0]);
|
||||
|
||||
connected = false;
|
||||
ConnectToServer(serverIP);
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -1244,7 +1241,7 @@ namespace Barotrauma.Networking
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void KickPlayer(string kickedName, bool ban, bool range = false)
|
||||
public override void KickPlayer(string kickedName, string reason, bool ban, bool range = false)
|
||||
{
|
||||
NetOutgoingMessage msg = client.CreateMessage();
|
||||
msg.Write((byte)ClientPacketHeader.SERVER_COMMAND);
|
||||
|
||||
@@ -161,5 +161,20 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
banReasonPrompt.Buttons[0].OnClicked += (btn, userData) =>
|
||||
{
|
||||
KickPlayer(clientName, textBox.Text, ban, rangeBan);
|
||||
return true;
|
||||
};
|
||||
banReasonPrompt.Buttons[0].OnClicked += banReasonPrompt.Close;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -893,49 +893,22 @@ namespace Barotrauma
|
||||
|
||||
public bool KickPlayer(GUIButton button, object userData)
|
||||
{
|
||||
if (userData == null) return false;
|
||||
|
||||
if (GameMain.Server != null)
|
||||
{
|
||||
GameMain.Server.KickPlayer(userData.ToString(), false);
|
||||
}
|
||||
else if (GameMain.Client != null && GameMain.Client.HasPermission(ClientPermissions.Kick))
|
||||
{
|
||||
GameMain.Client.KickPlayer(userData.ToString(), false);
|
||||
}
|
||||
|
||||
if (userData == null || GameMain.NetworkMember == null) return false;
|
||||
GameMain.NetworkMember.CreateKickReasonPrompt(userData.ToString(), false);
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool BanPlayer(GUIButton button, object userData)
|
||||
{
|
||||
if (userData == null) return false;
|
||||
|
||||
if (GameMain.Server != null)
|
||||
{
|
||||
GameMain.Server.KickPlayer(userData.ToString(), true);
|
||||
}
|
||||
else if (GameMain.Client != null && GameMain.Client.HasPermission(ClientPermissions.Ban))
|
||||
{
|
||||
GameMain.Client.KickPlayer(userData.ToString(), true);
|
||||
}
|
||||
|
||||
if (userData == null || GameMain.NetworkMember == null) return false;
|
||||
GameMain.NetworkMember.CreateKickReasonPrompt(userData.ToString(), true);
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool BanPlayerRange(GUIButton button, object userData)
|
||||
{
|
||||
if (userData == null) return false;
|
||||
|
||||
if (GameMain.Server != null)
|
||||
{
|
||||
GameMain.Server.KickPlayer(userData.ToString(), true, true);
|
||||
}
|
||||
else if (GameMain.Client != null && GameMain.Client.HasPermission(ClientPermissions.Ban))
|
||||
{
|
||||
GameMain.Client.KickPlayer(userData.ToString(), true, true);
|
||||
}
|
||||
|
||||
if (userData == null || GameMain.NetworkMember == null) return false;
|
||||
GameMain.NetworkMember.CreateKickReasonPrompt(userData.ToString(), true, true);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user