tryChangeClientName, LidgrenHandleConnection, handlePendingClient hooks and some other things

This commit is contained in:
Evil Factory
2021-12-28 12:37:51 -03:00
parent 71e39f1422
commit e6d170329a
7 changed files with 57 additions and 5 deletions
@@ -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;
@@ -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
@@ -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))
{