tryChangeClientName, LidgrenHandleConnection, handlePendingClient hooks and some other things
This commit is contained in:
@@ -2701,6 +2701,15 @@ namespace Barotrauma.Networking
|
|||||||
c.NameID = nameId;
|
c.NameID = nameId;
|
||||||
newName = Client.SanitizeName(newName);
|
newName = Client.SanitizeName(newName);
|
||||||
if (newName == c.Name && newJob == c.PreferredJob && newTeam == c.PreferredTeam) { return false; }
|
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.PreferredJob = newJob;
|
||||||
c.PreferredTeam = newTeam;
|
c.PreferredTeam = newTeam;
|
||||||
|
|
||||||
|
|||||||
+9
@@ -182,12 +182,21 @@ namespace Barotrauma.Networking
|
|||||||
{
|
{
|
||||||
if (netServer == null) { return; }
|
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)
|
if (connectedClients.Count >= serverSettings.MaxPlayers)
|
||||||
{
|
{
|
||||||
inc.SenderConnection.Deny(DisconnectReason.ServerFull.ToString());
|
inc.SenderConnection.Deny(DisconnectReason.ServerFull.ToString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ignore:
|
||||||
|
|
||||||
if (serverSettings.BanList.IsBanned(inc.SenderConnection.RemoteEndPoint.Address, 0, 0, out string banReason))
|
if (serverSettings.BanList.IsBanned(inc.SenderConnection.RemoteEndPoint.Address, 0, 0, out string banReason))
|
||||||
{
|
{
|
||||||
//IP banned: deny immediately
|
//IP banned: deny immediately
|
||||||
|
|||||||
+9
-2
@@ -30,7 +30,7 @@ namespace Barotrauma.Networking
|
|||||||
public abstract void Close(string msg = null);
|
public abstract void Close(string msg = null);
|
||||||
public abstract void Update(float deltaTime);
|
public abstract void Update(float deltaTime);
|
||||||
|
|
||||||
protected class PendingClient
|
public class PendingClient
|
||||||
{
|
{
|
||||||
public string Name;
|
public string Name;
|
||||||
public int OwnerKey;
|
public int OwnerKey;
|
||||||
@@ -206,6 +206,11 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
protected void UpdatePendingClient(PendingClient pendingClient)
|
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))
|
if (IsPendingClientBanned(pendingClient, out string banReason))
|
||||||
{
|
{
|
||||||
RemovePendingClient(pendingClient, DisconnectReason.Banned, banReason);
|
RemovePendingClient(pendingClient, DisconnectReason.Banned, banReason);
|
||||||
@@ -217,6 +222,8 @@ namespace Barotrauma.Networking
|
|||||||
RemovePendingClient(pendingClient, DisconnectReason.ServerFull, "");
|
RemovePendingClient(pendingClient, DisconnectReason.ServerFull, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ignore:
|
||||||
|
|
||||||
if (pendingClient.InitializationStep == ConnectionInitialization.Success)
|
if (pendingClient.InitializationStep == ConnectionInitialization.Success)
|
||||||
{
|
{
|
||||||
NetworkConnection newConnection = pendingClient.Connection;
|
NetworkConnection newConnection = pendingClient.Connection;
|
||||||
@@ -276,7 +283,7 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
protected virtual void CheckOwnership(PendingClient pendingClient) { }
|
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))
|
if (pendingClients.Contains(pendingClient))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -92,6 +92,8 @@ defaultLib["AIObjectiveRescueAll"] = CreateStatic("AIObjectiveRescueAll")
|
|||||||
defaultLib["AIObjectiveReturn"] = CreateStatic("AIObjectiveReturn")
|
defaultLib["AIObjectiveReturn"] = CreateStatic("AIObjectiveReturn")
|
||||||
defaultLib["CombatMode"] = CreateStatic("AIObjectiveCombat+CombatMode")
|
defaultLib["CombatMode"] = CreateStatic("AIObjectiveCombat+CombatMode")
|
||||||
|
|
||||||
|
defaultLib["DisconnectReason"] = CreateStatic("Networking.DisconnectReason")
|
||||||
|
|
||||||
|
|
||||||
if SERVER then
|
if SERVER then
|
||||||
|
|
||||||
|
|||||||
@@ -166,6 +166,8 @@ RegisterBarotrauma("GameScreen")
|
|||||||
RegisterBarotrauma("GameSession")
|
RegisterBarotrauma("GameSession")
|
||||||
RegisterBarotrauma("CampaignMode")
|
RegisterBarotrauma("CampaignMode")
|
||||||
|
|
||||||
|
RegisterBarotrauma("DebugConsole+Command")
|
||||||
|
|
||||||
RegisterBarotrauma("TextManager")
|
RegisterBarotrauma("TextManager")
|
||||||
|
|
||||||
local descriptor = RegisterBarotrauma("NetLobbyScreen")
|
local descriptor = RegisterBarotrauma("NetLobbyScreen")
|
||||||
@@ -183,6 +185,8 @@ RegisterBarotrauma("Networking.DeliveryMethod")
|
|||||||
RegisterBarotrauma("Networking.NetEntityEvent")
|
RegisterBarotrauma("Networking.NetEntityEvent")
|
||||||
RegisterBarotrauma("Networking.NetEntityEvent+Type")
|
RegisterBarotrauma("Networking.NetEntityEvent+Type")
|
||||||
RegisterBarotrauma("Networking.INetSerializable")
|
RegisterBarotrauma("Networking.INetSerializable")
|
||||||
|
RegisterBarotrauma("Networking.DisconnectReason")
|
||||||
|
LuaUserData.RegisterType("Lidgren.Network.NetIncomingMessage")
|
||||||
|
|
||||||
RegisterBarotrauma("Rand+RandSync")
|
RegisterBarotrauma("Rand+RandSync")
|
||||||
RegisterBarotrauma("Skill")
|
RegisterBarotrauma("Skill")
|
||||||
@@ -218,8 +222,8 @@ AddCallMetaMember(LuaUserData.RegisterType("Microsoft.Xna.Framework.Point"))
|
|||||||
AddCallMetaMember(LuaUserData.RegisterType("Microsoft.Xna.Framework.Rectangle"))
|
AddCallMetaMember(LuaUserData.RegisterType("Microsoft.Xna.Framework.Rectangle"))
|
||||||
|
|
||||||
if SERVER then
|
if SERVER then
|
||||||
|
|
||||||
RegisterBarotrauma("Networking.ServerPeer")
|
RegisterBarotrauma("Networking.ServerPeer")
|
||||||
|
RegisterBarotrauma("Networking.ServerPeer+PendingClient")
|
||||||
|
|
||||||
RegisterBarotrauma("Traitor")
|
RegisterBarotrauma("Traitor")
|
||||||
RegisterBarotrauma("Traitor+TraitorMission")
|
RegisterBarotrauma("Traitor+TraitorMission")
|
||||||
|
|||||||
@@ -433,6 +433,8 @@ namespace Barotrauma
|
|||||||
DebugConsole.Commands.Add(cmd);
|
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 }); });
|
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);
|
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
|
public partial class LuaHook
|
||||||
|
|||||||
@@ -893,7 +893,7 @@ namespace Barotrauma.Networking
|
|||||||
public int MaxPlayers
|
public int MaxPlayers
|
||||||
{
|
{
|
||||||
get { return maxPlayers; }
|
get { return maxPlayers; }
|
||||||
set { maxPlayers = MathHelper.Clamp(value, 1, NetConfig.MaxPlayers); }
|
set { maxPlayers = MathHelper.Clamp(value, 0, NetConfig.MaxPlayers); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<MissionType> AllowedRandomMissionTypes
|
public List<MissionType> AllowedRandomMissionTypes
|
||||||
|
|||||||
Reference in New Issue
Block a user