Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support port checkers #2210

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
6 changes: 4 additions & 2 deletions NitroxServer/Communication/LiteNetLib/LiteNetLibServer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Buffers;
using System.Buffers;
using System.Threading;
using System.Threading.Tasks;
using LiteNetLib;
Expand All @@ -21,7 +21,9 @@ public class LiteNetLibServer : NitroxServer
public LiteNetLibServer(PacketHandler packetHandler, PlayerManager playerManager, EntitySimulation entitySimulation, ServerConfig serverConfig) : base(packetHandler, playerManager, entitySimulation, serverConfig)
{
listener = new EventBasedNetListener();
server = new NetManager(listener);
PortCheckerSupport portChecker = new PortCheckerSupport();
server = new NetManager(listener, portChecker);
portChecker.netManager = server;
}

public override bool Start()
Expand Down
32 changes: 32 additions & 0 deletions NitroxServer/Communication/LiteNetLib/PortCheckerSupport.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Net;
using LiteNetLib.Layers;
using LiteNetLib;
using System.Collections.Generic;
using LiteNetLib.Utils;
using System.Net.Sockets;
namespace NitroxServer.Communication.LiteNetLib;

public class PortCheckerSupport : PacketLayerBase
{
public static bool active;
public NetManager netManager;
public PortCheckerSupport() : base(0)
{
active = false;
}

public override void ProcessInboundPacket(ref IPEndPoint endPoint, ref byte[] data, ref int length)
{
if (active)
{
Log.Info("Incoming packet");
netManager.SendUnconnectedMessage(data, endPoint);
OhmV-IR marked this conversation as resolved.
Show resolved Hide resolved
}
OhmV-IR marked this conversation as resolved.
Show resolved Hide resolved

}
public override void ProcessOutBoundPacket(ref IPEndPoint endPoint, ref byte[] data, ref int offset, ref int length)
{

}
}
26 changes: 26 additions & 0 deletions NitroxServer/ConsoleCommands/PortCheckerToggleCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using LiteNetLib;
using NitroxModel.DataStructures.GameLogic;
using NitroxServer.Communication.LiteNetLib;
using NitroxServer.ConsoleCommands.Abstract;
using NitroxServer.ConsoleCommands.Abstract.Type;

namespace NitroxServer.ConsoleCommands;
public class PortCheckerToggleCommand : Command
{
public PortCheckerToggleCommand() : base("toggleportchecker", Perms.CONSOLE, "Enable/Disable the port forwarding tester")
{

}

protected override void Execute(CallArgs args)
{
Log.Info("Togggled port checker " + (!PortCheckerSupport.active).ToString());
if (PortCheckerSupport.active)
{
PortCheckerSupport.active = false;
return;
}
PortCheckerSupport.active = true;
return;
OhmV-IR marked this conversation as resolved.
Show resolved Hide resolved
}
}