diff --git a/Barotrauma/BarotraumaServer/ServerSource/Networking/GameServer.cs b/Barotrauma/BarotraumaServer/ServerSource/Networking/GameServer.cs index 3502069f4..c3460a580 100644 --- a/Barotrauma/BarotraumaServer/ServerSource/Networking/GameServer.cs +++ b/Barotrauma/BarotraumaServer/ServerSource/Networking/GameServer.cs @@ -2701,6 +2701,15 @@ namespace Barotrauma.Networking c.NameID = nameId; newName = Client.SanitizeName(newName); if (newName == c.Name && newJob == c.PreferredJob && newTeam == c.PreferredTeam) { return false; } + + var result = new LuaResult(GameMain.Lua.hook.Call("tryChangeClientName", c, newName, newJob, newTeam)); + + if (!result.IsNull()) + { + LastClientListUpdateID++; + return result.Bool(); + } + c.PreferredJob = newJob; c.PreferredTeam = newTeam; diff --git a/Barotrauma/BarotraumaServer/ServerSource/Networking/Primitives/Peers/Server/LidgrenServerPeer.cs b/Barotrauma/BarotraumaServer/ServerSource/Networking/Primitives/Peers/Server/LidgrenServerPeer.cs index f373add21..5f25a11b5 100644 --- a/Barotrauma/BarotraumaServer/ServerSource/Networking/Primitives/Peers/Server/LidgrenServerPeer.cs +++ b/Barotrauma/BarotraumaServer/ServerSource/Networking/Primitives/Peers/Server/LidgrenServerPeer.cs @@ -181,13 +181,22 @@ namespace Barotrauma.Networking private void HandleConnection(NetIncomingMessage inc) { if (netServer == null) { return; } - + + var result = new LuaResult(GameMain.Lua.hook.Call("LidgrenHandleConnection", inc)); + if (!result.IsNull()) + if (result.Bool()) + goto ignore; + else + return; + if (connectedClients.Count >= serverSettings.MaxPlayers) { inc.SenderConnection.Deny(DisconnectReason.ServerFull.ToString()); return; } + ignore: + if (serverSettings.BanList.IsBanned(inc.SenderConnection.RemoteEndPoint.Address, 0, 0, out string banReason)) { //IP banned: deny immediately diff --git a/Barotrauma/BarotraumaServer/ServerSource/Networking/Primitives/Peers/Server/ServerPeer.cs b/Barotrauma/BarotraumaServer/ServerSource/Networking/Primitives/Peers/Server/ServerPeer.cs index 546ba9543..ebe1a4ac5 100644 --- a/Barotrauma/BarotraumaServer/ServerSource/Networking/Primitives/Peers/Server/ServerPeer.cs +++ b/Barotrauma/BarotraumaServer/ServerSource/Networking/Primitives/Peers/Server/ServerPeer.cs @@ -30,7 +30,7 @@ namespace Barotrauma.Networking public abstract void Close(string msg = null); public abstract void Update(float deltaTime); - protected class PendingClient + public class PendingClient { public string Name; public int OwnerKey; @@ -206,6 +206,11 @@ namespace Barotrauma.Networking protected void UpdatePendingClient(PendingClient pendingClient) { + var result = new LuaResult(GameMain.Lua.hook.Call("handlePendingClient", pendingClient)); + + if (result.Bool()) + goto ignore; + if (IsPendingClientBanned(pendingClient, out string banReason)) { RemovePendingClient(pendingClient, DisconnectReason.Banned, banReason); @@ -217,6 +222,8 @@ namespace Barotrauma.Networking RemovePendingClient(pendingClient, DisconnectReason.ServerFull, ""); } + ignore: + if (pendingClient.InitializationStep == ConnectionInitialization.Success) { NetworkConnection newConnection = pendingClient.Connection; @@ -276,7 +283,7 @@ namespace Barotrauma.Networking protected virtual void CheckOwnership(PendingClient pendingClient) { } - protected void RemovePendingClient(PendingClient pendingClient, DisconnectReason reason, string msg) + public void RemovePendingClient(PendingClient pendingClient, DisconnectReason reason, string msg) { if (pendingClients.Contains(pendingClient)) { diff --git a/Barotrauma/BarotraumaShared/Lua/DefaultLib.lua b/Barotrauma/BarotraumaShared/Lua/DefaultLib.lua index ae6615aa0..5b1e87e1b 100644 --- a/Barotrauma/BarotraumaShared/Lua/DefaultLib.lua +++ b/Barotrauma/BarotraumaShared/Lua/DefaultLib.lua @@ -92,6 +92,8 @@ defaultLib["AIObjectiveRescueAll"] = CreateStatic("AIObjectiveRescueAll") defaultLib["AIObjectiveReturn"] = CreateStatic("AIObjectiveReturn") defaultLib["CombatMode"] = CreateStatic("AIObjectiveCombat+CombatMode") +defaultLib["DisconnectReason"] = CreateStatic("Networking.DisconnectReason") + if SERVER then diff --git a/Barotrauma/BarotraumaShared/Lua/DefaultRegister.lua b/Barotrauma/BarotraumaShared/Lua/DefaultRegister.lua index 7a2e7f4ca..e49dd3e69 100644 --- a/Barotrauma/BarotraumaShared/Lua/DefaultRegister.lua +++ b/Barotrauma/BarotraumaShared/Lua/DefaultRegister.lua @@ -166,6 +166,8 @@ RegisterBarotrauma("GameScreen") RegisterBarotrauma("GameSession") RegisterBarotrauma("CampaignMode") +RegisterBarotrauma("DebugConsole+Command") + RegisterBarotrauma("TextManager") local descriptor = RegisterBarotrauma("NetLobbyScreen") @@ -183,6 +185,8 @@ RegisterBarotrauma("Networking.DeliveryMethod") RegisterBarotrauma("Networking.NetEntityEvent") RegisterBarotrauma("Networking.NetEntityEvent+Type") RegisterBarotrauma("Networking.INetSerializable") +RegisterBarotrauma("Networking.DisconnectReason") +LuaUserData.RegisterType("Lidgren.Network.NetIncomingMessage") RegisterBarotrauma("Rand+RandSync") RegisterBarotrauma("Skill") @@ -218,8 +222,8 @@ AddCallMetaMember(LuaUserData.RegisterType("Microsoft.Xna.Framework.Point")) AddCallMetaMember(LuaUserData.RegisterType("Microsoft.Xna.Framework.Rectangle")) if SERVER then - RegisterBarotrauma("Networking.ServerPeer") +RegisterBarotrauma("Networking.ServerPeer+PendingClient") RegisterBarotrauma("Traitor") RegisterBarotrauma("Traitor+TraitorMission") diff --git a/Barotrauma/BarotraumaShared/SharedSource/Lua/LuaClasses.cs b/Barotrauma/BarotraumaShared/SharedSource/Lua/LuaClasses.cs index 8d838b7d4..06e58a7a3 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Lua/LuaClasses.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Lua/LuaClasses.cs @@ -433,6 +433,8 @@ namespace Barotrauma DebugConsole.Commands.Add(cmd); } + public List Commands => DebugConsole.Commands; + public void AssignOnExecute(string names, object onExecute) => DebugConsole.AssignOnExecute(names, (string[] a) => { env.CallFunction(onExecute, new object[] { a }); }); @@ -751,6 +753,25 @@ namespace Barotrauma { GameMain.NetworkMember.CreateEntityEvent(entity, extraData); } + +#if SERVER + public void UpdateClientPermissions(Client client) + { + GameMain.Server.UpdateClientPermissions(client); + } + + public void RemovePendingClient(ServerPeer.PendingClient pendingClient, DisconnectReason reason, string msg) + { + GameMain.Server.ServerPeer.RemovePendingClient(pendingClient, reason, msg); + } +#endif + + + public ushort LastClientListUpdateID + { + get { return GameMain.NetworkMember.LastClientListUpdateID; } + set { GameMain.NetworkMember.LastClientListUpdateID = value; } + } } public partial class LuaHook diff --git a/Barotrauma/BarotraumaShared/SharedSource/Networking/ServerSettings.cs b/Barotrauma/BarotraumaShared/SharedSource/Networking/ServerSettings.cs index 02f2cb829..8bb1e4f26 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Networking/ServerSettings.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Networking/ServerSettings.cs @@ -893,7 +893,7 @@ namespace Barotrauma.Networking public int MaxPlayers { get { return maxPlayers; } - set { maxPlayers = MathHelper.Clamp(value, 1, NetConfig.MaxPlayers); } + set { maxPlayers = MathHelper.Clamp(value, 0, NetConfig.MaxPlayers); } } public List AllowedRandomMissionTypes