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;
|
||||
}
|
||||
|
||||
|
||||
@@ -141,7 +141,6 @@ namespace Barotrauma
|
||||
#endif
|
||||
default:
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
return true; //command found
|
||||
}
|
||||
|
||||
@@ -32,6 +32,10 @@ namespace Barotrauma
|
||||
|
||||
public static List<ColoredText> Messages = new List<ColoredText>();
|
||||
|
||||
private delegate void QuestionCallback(string answer);
|
||||
private static QuestionCallback activeQuestionCallback;
|
||||
private static GUIComponent activeQuestionText;
|
||||
|
||||
private static string[] SplitCommand(string command)
|
||||
{
|
||||
command = command.Trim();
|
||||
@@ -41,7 +45,7 @@ namespace Barotrauma
|
||||
bool inQuotes = false;
|
||||
string piece = "";
|
||||
|
||||
for (int i=0;i<command.Length;i++)
|
||||
for (int i = 0; i < command.Length; i++)
|
||||
{
|
||||
if (command[i] == '\\')
|
||||
{
|
||||
@@ -71,6 +75,15 @@ namespace Barotrauma
|
||||
public static void ExecuteCommand(string command, GameMain game)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(command)) return;
|
||||
|
||||
if (activeQuestionCallback != null)
|
||||
{
|
||||
activeQuestionText = null;
|
||||
activeQuestionCallback(command);
|
||||
activeQuestionCallback = null;
|
||||
return;
|
||||
}
|
||||
|
||||
string[] commands = SplitCommand(command);
|
||||
|
||||
if (!commands[0].ToLowerInvariant().Equals("admin"))
|
||||
@@ -95,7 +108,7 @@ namespace Barotrauma
|
||||
DebugConsole.NewMessage("***************", Color.Cyan);
|
||||
foreach (Client c in GameMain.Server.ConnectedClients)
|
||||
{
|
||||
DebugConsole.NewMessage("- " + c.ID.ToString() + ": " + c.name + ", " + c.Connection.RemoteEndPoint.Address.ToString(),Color.Cyan);
|
||||
DebugConsole.NewMessage("- " + c.ID.ToString() + ": " + c.name + ", " + c.Connection.RemoteEndPoint.Address.ToString(), Color.Cyan);
|
||||
}
|
||||
DebugConsole.NewMessage("***************", Color.Cyan);
|
||||
break;
|
||||
@@ -107,7 +120,7 @@ namespace Barotrauma
|
||||
NewMessage("load [submarine name]: load a submarine", Color.Cyan);
|
||||
NewMessage("save [submarine name]: save the current submarine using the specified name", Color.Cyan);
|
||||
|
||||
NewMessage(" ", Color.Cyan);
|
||||
NewMessage(" ", Color.Cyan);
|
||||
|
||||
NewMessage("spawn [creaturename] [near/inside/outside]: spawn a creature at a random spawnpoint (use the second parameter to only select spawnpoints near/inside/outside the submarine)", Color.Cyan);
|
||||
NewMessage("spawnitem [itemname] [cursor/inventory]: spawn an item at the position of the cursor, in the inventory of the controlled character or at a random spawnpoint if the last parameter is omitted", Color.Cyan);
|
||||
@@ -135,7 +148,7 @@ namespace Barotrauma
|
||||
NewMessage("killmonsters: immediately kills all AI-controlled enemies in the level", Color.Cyan);
|
||||
|
||||
NewMessage(" ", Color.Cyan);
|
||||
|
||||
|
||||
NewMessage("fixwalls: fixes all the walls", Color.Cyan);
|
||||
NewMessage("fixitems: fixes every item/device in the sub", Color.Cyan);
|
||||
NewMessage("oxygen: replenishes the oxygen in every room to 100%", Color.Cyan);
|
||||
@@ -148,7 +161,7 @@ namespace Barotrauma
|
||||
NewMessage("banip [IP address]: ban the IP address from the server", Color.Cyan);
|
||||
NewMessage("debugdraw: toggles the \"debug draw mode\"", Color.Cyan);
|
||||
NewMessage("netstats: toggles the visibility of the network statistics panel", Color.Cyan);
|
||||
|
||||
|
||||
break;
|
||||
case "createfilelist":
|
||||
UpdaterUtil.SaveFileList("filelist.xml");
|
||||
@@ -208,7 +221,7 @@ namespace Barotrauma
|
||||
|
||||
if (spawnPoint != null) spawnPosition = spawnPoint.WorldPosition;
|
||||
|
||||
if (commands[1].ToLowerInvariant()=="human")
|
||||
if (commands[1].ToLowerInvariant() == "human")
|
||||
{
|
||||
spawnedCharacter = Character.Create(Character.HumanConfigFile, spawnPosition);
|
||||
|
||||
@@ -228,15 +241,15 @@ namespace Barotrauma
|
||||
else
|
||||
{
|
||||
spawnedCharacter = Character.Create(
|
||||
"Content/Characters/"
|
||||
+ commands[1].First().ToString().ToUpper() + commands[1].Substring(1)
|
||||
"Content/Characters/"
|
||||
+ commands[1].First().ToString().ToUpper() + commands[1].Substring(1)
|
||||
+ "/" + commands[1].ToLower() + ".xml", spawnPosition);
|
||||
}
|
||||
|
||||
break;
|
||||
case "spawnitem":
|
||||
if (commands.Length < 2) return;
|
||||
|
||||
|
||||
Vector2? spawnPos = null;
|
||||
Inventory spawnInventory = null;
|
||||
|
||||
@@ -261,7 +274,7 @@ namespace Barotrauma
|
||||
var itemPrefab = MapEntityPrefab.list.Find(ip => ip.Name.ToLowerInvariant() == itemName) as ItemPrefab;
|
||||
if (itemPrefab == null)
|
||||
{
|
||||
ThrowError("Item \""+itemName+"\" not found!");
|
||||
ThrowError("Item \"" + itemName + "\" not found!");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -302,48 +315,63 @@ namespace Barotrauma
|
||||
}
|
||||
break;*/
|
||||
case "kick":
|
||||
if (GameMain.NetworkMember == null || commands.Length < 2) break;
|
||||
GameMain.NetworkMember.KickPlayer(string.Join(" ", commands.Skip(1)), false);
|
||||
if (GameMain.NetworkMember != null && commands.Length >= 2)
|
||||
{
|
||||
string playerName = string.Join(" ", commands.Skip(1));
|
||||
|
||||
ShowQuestionPrompt("Reason for kicking \"" + playerName + "\"?", (answer) =>
|
||||
{
|
||||
GameMain.NetworkMember.KickPlayer(playerName, answer, false);
|
||||
});
|
||||
}
|
||||
break;
|
||||
case "kickid":
|
||||
if (GameMain.Server == null || commands.Length < 2) break;
|
||||
|
||||
{
|
||||
int id = 0;
|
||||
int.TryParse(commands[1], out id);
|
||||
GameMain.Server.KickPlayer(id, false);
|
||||
}
|
||||
break;
|
||||
case "banid":
|
||||
if (GameMain.Server == null || commands.Length < 2) break;
|
||||
|
||||
if (GameMain.Server != null && commands.Length >= 2)
|
||||
{
|
||||
bool ban = commands[0].ToLowerInvariant() == "banid";
|
||||
|
||||
int id = 0;
|
||||
int.TryParse(commands[1], out id);
|
||||
GameMain.Server.KickPlayer(id, true);
|
||||
}
|
||||
|
||||
break;
|
||||
case "ban":
|
||||
if (GameMain.NetworkMember == null || commands.Length < 2) break;
|
||||
GameMain.NetworkMember.KickPlayer(string.Join(" ", commands.Skip(1)), true);
|
||||
|
||||
break;
|
||||
case "banip":
|
||||
{
|
||||
if (GameMain.Server == null || commands.Length < 2) break;
|
||||
|
||||
var client = GameMain.Server.ConnectedClients.Find(c => c.Connection.RemoteEndPoint.Address.ToString() == commands[1]);
|
||||
var client = GameMain.Server.ConnectedClients.Find(c => c.ID == id);
|
||||
if (client == null)
|
||||
{
|
||||
GameMain.Server.BanList.BanPlayer("Unnamed", commands[1]);
|
||||
ThrowError("Client id \"" + id + "\" not found.");
|
||||
return;
|
||||
}
|
||||
else
|
||||
|
||||
ShowQuestionPrompt(ban ? "Reason for banning \"" + client.name + "\"?" : "Reason for kicking \"" + client.name + "\"?", (answer) =>
|
||||
{
|
||||
GameMain.Server.KickClient(client, true);
|
||||
}
|
||||
}
|
||||
GameMain.Server.KickPlayer(client.name, answer, ban);
|
||||
});
|
||||
}
|
||||
break;
|
||||
case "ban":
|
||||
if (GameMain.NetworkMember != null || commands.Length >= 2)
|
||||
{
|
||||
string clientName = string.Join(" ", commands.Skip(1));
|
||||
ShowQuestionPrompt("Reason for banning \"" + clientName + "\"?", (answer) =>
|
||||
{
|
||||
GameMain.NetworkMember.KickPlayer(clientName, answer, true);
|
||||
});
|
||||
}
|
||||
break;
|
||||
case "banip":
|
||||
if (GameMain.Server != null || commands.Length >= 2)
|
||||
{
|
||||
ShowQuestionPrompt("Reason for banning the ip \"" + commands[1] + "\"?", (answer) =>
|
||||
{
|
||||
var client = GameMain.Server.ConnectedClients.Find(c => c.Connection.RemoteEndPoint.Address.ToString() == commands[1]);
|
||||
if (client == null)
|
||||
{
|
||||
GameMain.Server.BanList.BanPlayer("Unnamed", commands[1], answer);
|
||||
}
|
||||
else
|
||||
{
|
||||
GameMain.Server.KickClient(client, answer, true);
|
||||
}
|
||||
});
|
||||
}
|
||||
break;
|
||||
case "teleportcharacter":
|
||||
case "teleport":
|
||||
@@ -367,6 +395,7 @@ namespace Barotrauma
|
||||
if (Submarine.MainSub == null) return;
|
||||
|
||||
Submarine.MainSub.GodMode = !Submarine.MainSub.GodMode;
|
||||
NewMessage(Submarine.MainSub.GodMode ? "Godmode on" : "Godmode off", Color.White);
|
||||
break;
|
||||
case "lockx":
|
||||
Submarine.LockX = !Submarine.LockX;
|
||||
@@ -441,8 +470,12 @@ namespace Barotrauma
|
||||
break;
|
||||
case "editwater":
|
||||
case "water":
|
||||
if (GameMain.Client == null) Hull.EditWater = !Hull.EditWater;
|
||||
|
||||
if (GameMain.Client == null)
|
||||
{
|
||||
Hull.EditWater = !Hull.EditWater;
|
||||
NewMessage(Hull.EditWater ? "Water editing on" : "Water editing off", Color.White);
|
||||
}
|
||||
|
||||
break;
|
||||
case "explosion":
|
||||
Vector2 explosionPos = GameMain.GameScreen.Cam.ScreenToWorld(PlayerInput.MousePosition);
|
||||
@@ -453,7 +486,11 @@ namespace Barotrauma
|
||||
new Explosion(range, force, damage, damage).Explode(explosionPos);
|
||||
break;
|
||||
case "fire":
|
||||
if (GameMain.Client == null) Hull.EditFire = !Hull.EditFire;
|
||||
if (GameMain.Client == null)
|
||||
{
|
||||
Hull.EditFire = !Hull.EditFire;
|
||||
NewMessage(Hull.EditWater ? "Fire spawning on" : "Fire spawning off", Color.White);
|
||||
}
|
||||
|
||||
break;
|
||||
case "fixitems":
|
||||
@@ -604,9 +641,27 @@ namespace Barotrauma
|
||||
}
|
||||
|
||||
selectedIndex = listBox.children.Count;
|
||||
|
||||
if (activeQuestionText != null)
|
||||
{
|
||||
//make sure the active question stays at the bottom of the list
|
||||
listBox.children.Remove(activeQuestionText);
|
||||
listBox.children.Add(activeQuestionText);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private static void ShowQuestionPrompt(string question, QuestionCallback onAnswered)
|
||||
{
|
||||
NewMessage(" >>" + question, Color.Cyan);
|
||||
activeQuestionCallback += onAnswered;
|
||||
if (listBox != null && listBox.children.Count > 0)
|
||||
{
|
||||
activeQuestionText = listBox.children[listBox.children.Count - 1];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void Log(string message)
|
||||
{
|
||||
if (GameSettings.VerboseLogging) NewMessage(message, Color.Gray);
|
||||
|
||||
@@ -3,7 +3,6 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Barotrauma.Networking
|
||||
{
|
||||
@@ -11,11 +10,12 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
public string Name;
|
||||
public string IP;
|
||||
public string Reason;
|
||||
|
||||
public bool CompareTo(string ipCompare)
|
||||
{
|
||||
int rangeBanIndex = IP.IndexOf(".x");
|
||||
if (rangeBanIndex<=-1)
|
||||
if (rangeBanIndex <= -1)
|
||||
{
|
||||
return ipCompare == IP;
|
||||
}
|
||||
@@ -26,10 +26,11 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
}
|
||||
|
||||
public BannedPlayer(string name, string ip)
|
||||
public BannedPlayer(string name, string ip, string reason)
|
||||
{
|
||||
this.Name = name;
|
||||
this.IP = ip;
|
||||
this.Reason = reason;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,21 +62,24 @@ namespace Barotrauma.Networking
|
||||
string[] separatedLine = line.Split(',');
|
||||
if (separatedLine.Length < 2) continue;
|
||||
|
||||
string name = String.Join(",", separatedLine.Take(separatedLine.Length - 1));
|
||||
string ip = separatedLine.Last();
|
||||
string name = separatedLine[0];
|
||||
string ip = separatedLine[1];
|
||||
string reason = separatedLine.Length > 2 ? string.Join(",", separatedLine.Skip(2)) : "";
|
||||
|
||||
bannedPlayers.Add(new BannedPlayer(name, ip));
|
||||
bannedPlayers.Add(new BannedPlayer(name, ip,reason));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void BanPlayer(string name, string ip)
|
||||
public void BanPlayer(string name, string ip, string reason)
|
||||
{
|
||||
if (bannedPlayers.Any(bp => bp.IP == ip)) return;
|
||||
|
||||
System.Diagnostics.Debug.Assert(!name.Contains(','));
|
||||
|
||||
DebugConsole.Log("Banned " + name);
|
||||
|
||||
bannedPlayers.Add(new BannedPlayer(name, ip));
|
||||
bannedPlayers.Add(new BannedPlayer(name, ip, reason));
|
||||
Save();
|
||||
}
|
||||
|
||||
@@ -131,7 +135,9 @@ namespace Barotrauma.Networking
|
||||
|
||||
foreach (BannedPlayer banned in bannedPlayers)
|
||||
{
|
||||
lines.Add(banned.Name + "," + banned.IP);
|
||||
string line = banned.Name + "," + banned.IP;
|
||||
if (!string.IsNullOrWhiteSpace(banned.Reason)) line += "," + banned.Reason;
|
||||
lines.Add(line);
|
||||
}
|
||||
|
||||
try
|
||||
|
||||
@@ -172,7 +172,7 @@ namespace Barotrauma.Networking
|
||||
if (c.ChatSpamCount > 3)
|
||||
{
|
||||
//kick for spamming too much
|
||||
GameMain.Server.KickClient(c);
|
||||
GameMain.Server.KickClient(c, "You have been kicked by the spam filter.");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -531,7 +531,7 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
if (banList.IsBanned(inc.SenderEndPoint.Address.ToString()))
|
||||
{
|
||||
KickClient(inc.SenderConnection, true);
|
||||
KickClient(inc.SenderConnection, "You have been banned from the server.", true);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -727,8 +727,8 @@ namespace Barotrauma.Networking
|
||||
|
||||
private void ClientReadServerCommand(NetIncomingMessage inc)
|
||||
{
|
||||
Client c = ConnectedClients.Find(x => x.Connection == inc.SenderConnection);
|
||||
if (c == null)
|
||||
Client sender = ConnectedClients.Find(x => x.Connection == inc.SenderConnection);
|
||||
if (sender == null)
|
||||
{
|
||||
inc.SenderConnection.Disconnect("You're not a connected client.");
|
||||
return;
|
||||
@@ -745,9 +745,9 @@ namespace Barotrauma.Networking
|
||||
return;
|
||||
}
|
||||
|
||||
if (!c.HasPermission(command))
|
||||
if (!sender.HasPermission(command))
|
||||
{
|
||||
Log("Client \""+c.name+"\" sent a server command \""+command+"\". Permission denied.", ServerLog.MessageType.ServerMessage);
|
||||
Log("Client \""+sender.name+"\" sent a server command \""+command+"\". Permission denied.", ServerLog.MessageType.ServerMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -755,26 +755,26 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
case ClientPermissions.Kick:
|
||||
string kickedName = inc.ReadString();
|
||||
var kickedClient = connectedClients.Find(cl => cl != c && cl.name == kickedName);
|
||||
var kickedClient = connectedClients.Find(cl => cl != sender && cl.name == kickedName);
|
||||
if (kickedClient != null)
|
||||
{
|
||||
Log("Client \"" + c.name + "\" kicked \"" + kickedClient.name + "\".", ServerLog.MessageType.ServerMessage);
|
||||
KickClient(kickedClient, false, false);
|
||||
Log("Client \"" + sender.name + "\" kicked \"" + kickedClient.name + "\".", ServerLog.MessageType.ServerMessage);
|
||||
KickClient(kickedClient, "Kicked by " + sender.name, false, false);
|
||||
}
|
||||
break;
|
||||
case ClientPermissions.Ban:
|
||||
string bannedName = inc.ReadString();
|
||||
var bannedClient = connectedClients.Find(cl => cl != c && cl.name == bannedName);
|
||||
var bannedClient = connectedClients.Find(cl => cl != sender && cl.name == bannedName);
|
||||
if (bannedClient != null)
|
||||
{
|
||||
Log("Client \"" + c.name + "\" banned \"" + bannedClient.name + "\".", ServerLog.MessageType.ServerMessage);
|
||||
KickClient(bannedClient, true, false);
|
||||
Log("Client \"" + sender.name + "\" banned \"" + bannedClient.name + "\".", ServerLog.MessageType.ServerMessage);
|
||||
KickClient(bannedClient, "Banned by " + sender.name, true, false);
|
||||
}
|
||||
break;
|
||||
case ClientPermissions.EndRound:
|
||||
if (gameStarted)
|
||||
{
|
||||
Log("Client \"" + c.name + "\" ended the round.", ServerLog.MessageType.ServerMessage);
|
||||
Log("Client \"" + sender.name + "\" ended the round.", ServerLog.MessageType.ServerMessage);
|
||||
EndGame();
|
||||
}
|
||||
break;
|
||||
@@ -1416,7 +1416,7 @@ namespace Barotrauma.Networking
|
||||
yield return CoroutineStatus.Success;
|
||||
}
|
||||
|
||||
public override void KickPlayer(string playerName, bool ban, bool range=false)
|
||||
public override void KickPlayer(string playerName, string reason, bool ban, bool range = false)
|
||||
{
|
||||
playerName = playerName.ToLowerInvariant();
|
||||
|
||||
@@ -1424,17 +1424,10 @@ namespace Barotrauma.Networking
|
||||
c.name.ToLowerInvariant() == playerName ||
|
||||
(c.Character != null && c.Character.Name.ToLowerInvariant() == playerName));
|
||||
|
||||
KickClient(client, ban, range);
|
||||
KickClient(client, reason, ban, range);
|
||||
}
|
||||
|
||||
public void KickPlayer(int id,bool ban,bool range=false)
|
||||
{
|
||||
Client client = connectedClients.Find(c => c.ID == id);
|
||||
|
||||
KickClient(client, ban, range);
|
||||
}
|
||||
|
||||
public void KickClient(NetConnection conn, bool ban = false, bool range = false)
|
||||
|
||||
public void KickClient(NetConnection conn, string reason, bool ban = false, bool range = false)
|
||||
{
|
||||
Client client = connectedClients.Find(c => c.Connection == conn);
|
||||
if (client == null)
|
||||
@@ -1444,30 +1437,34 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
if (!banList.IsBanned(conn.RemoteEndPoint.Address.ToString()))
|
||||
{
|
||||
banList.BanPlayer("Unnamed", conn.RemoteEndPoint.Address.ToString());
|
||||
banList.BanPlayer("Unnamed", conn.RemoteEndPoint.Address.ToString(), reason);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
KickClient(client, ban, range);
|
||||
KickClient(client, reason, ban, range);
|
||||
}
|
||||
}
|
||||
|
||||
public void KickClient(Client client, bool ban = false, bool range = false)
|
||||
public void KickClient(Client client, string reason, bool ban = false, bool range = false)
|
||||
{
|
||||
if (client == null) return;
|
||||
|
||||
if (ban)
|
||||
{
|
||||
DisconnectClient(client, client.name + " has been banned from the server", "You have been banned from the server");
|
||||
string msg = "You have been banned from the server.";
|
||||
if (!string.IsNullOrWhiteSpace(reason)) msg += "\nReason: " + reason;
|
||||
DisconnectClient(client, client.name + " has been banned from the server.", msg);
|
||||
string ip = client.Connection.RemoteEndPoint.Address.ToString();
|
||||
if (range) { ip = banList.ToRange(ip); }
|
||||
banList.BanPlayer(client.name, ip);
|
||||
banList.BanPlayer(client.name, ip, reason);
|
||||
}
|
||||
else
|
||||
{
|
||||
DisconnectClient(client, client.name + " has been kicked from the server", "You have been kicked from the server");
|
||||
string msg = "You have been kicked from the server.";
|
||||
if (!string.IsNullOrWhiteSpace(reason)) msg += "\nReason: " + reason;
|
||||
DisconnectClient(client, client.name + " has been kicked from the server.", msg);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1781,14 +1778,14 @@ namespace Barotrauma.Networking
|
||||
if (server.Connections.Count == 0|| connectedClients.Count == 0) return;
|
||||
|
||||
Client.UpdateKickVotes(connectedClients);
|
||||
|
||||
|
||||
var clientsToKick = connectedClients.FindAll(c => c.KickVoteCount >= connectedClients.Count * KickVoteRequiredRatio);
|
||||
foreach (Client c in clientsToKick)
|
||||
{
|
||||
SendChatMessage(c.name+" has been kicked from the server.", ChatMessageType.Server, null);
|
||||
KickClient(c);
|
||||
SendChatMessage(c.name + " has been kicked from the server.", ChatMessageType.Server, null);
|
||||
KickClient(c, "Kicked by vote");
|
||||
}
|
||||
|
||||
|
||||
GameMain.NetLobbyScreen.LastUpdateID++;
|
||||
|
||||
NetOutgoingMessage msg = server.CreateMessage();
|
||||
|
||||
@@ -102,7 +102,7 @@ namespace Barotrauma.Networking
|
||||
if (unauthClient.failedAttempts > 3)
|
||||
{
|
||||
//disconnect and ban after too many failed attempts
|
||||
banList.BanPlayer("Unnamed", unauthClient.Connection.RemoteEndPoint.Address.ToString());
|
||||
banList.BanPlayer("Unnamed", unauthClient.Connection.RemoteEndPoint.Address.ToString(), "Too many failed login attempts.");
|
||||
DisconnectUnauthClient(inc, unauthClient, "Too many failed login attempts. You have been automatically banned from the server.");
|
||||
|
||||
Log(inc.SenderConnection.RemoteEndPoint.Address.ToString() + " has been banned from the server (too many wrong passwords)", ServerLog.MessageType.Error);
|
||||
|
||||
@@ -191,7 +191,7 @@ namespace Barotrauma.Networking
|
||||
#endif
|
||||
}
|
||||
|
||||
public virtual void KickPlayer(string kickedName, bool ban, bool range = false) { }
|
||||
public virtual void KickPlayer(string kickedName, string reason, bool ban, bool range = false) { }
|
||||
|
||||
public virtual void Update(float deltaTime)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user