tryChangeClientName, LidgrenHandleConnection, handlePendingClient hooks and some other things
This commit is contained in:
@@ -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))
|
||||
{
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -433,6 +433,8 @@ namespace Barotrauma
|
||||
DebugConsole.Commands.Add(cmd);
|
||||
}
|
||||
|
||||
public List<DebugConsole.Command> 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
|
||||
|
||||
@@ -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<MissionType> AllowedRandomMissionTypes
|
||||
|
||||
Reference in New Issue
Block a user