using UnityEngine; namespace Northbound { /// /// Central port configuration for the project /// public class GamePortConfig : MonoBehaviour { [Header("Port Configuration")] [Tooltip("The main network port for the game")] [SerializeField] private ushort gamePort = 40445; public static ushort Port => Instance != null ? Instance.gamePort : (ushort)40445; public static GamePortConfig Instance { get; private set; } private void Awake() { if (Instance != null && Instance != this) { Destroy(gameObject); return; } Instance = this; DontDestroyOnLoad(gameObject); Debug.Log("[GamePortConfig] Using port: " + gamePort + ""); } [ContextMenu("Log Port Configuration")] public void LogPortConfig() { Debug.Log("=== GAME PORT CONFIGURATION ==="); Debug.Log("Game Port: " + gamePort); Debug.Log("Port Type: TCP (and UDP if enabled)"); Debug.Log("Use this port for:"); Debug.Log(" - Router Port Forwarding"); Debug.Log(" - Windows Firewall rules"); Debug.Log(" - Port testing tools"); Debug.Log(" - Teammate connections"); Debug.Log("=============================="); } [ContextMenu("Generate Router Port Forwarding Info")] public void GeneratePortForwardingInfo() { Debug.Log("=== ROUTER PORT FORWARDING SETTINGS ==="); Debug.Log(""); Debug.Log("EXTERNAL PORT: " + gamePort); Debug.Log("INTERNAL PORT: " + gamePort); Debug.Log("PROTOCOL: TCP"); Debug.Log("INTERNAL IP: [Your computer's local IP]"); Debug.Log(""); Debug.Log("Steps:"); Debug.Log("1. Open Command Prompt, run 'ipconfig'"); Debug.Log("2. Find 'IPv4 Address' (e.g., 192.168.1.50)"); Debug.Log("3. Login to router (http://192.168.1.1)"); Debug.Log("4. Find Port Forwarding section"); Debug.Log("5. Add rule with above settings"); Debug.Log("6. Use your IPv4 as Internal IP"); Debug.Log("7. Save and restart router"); Debug.Log(""); Debug.Log("Test port at: https://www.yougetsignal.com/tools/open-ports/"); Debug.Log("======================================="); } [ContextMenu("Generate Firewall Rules")] public void GenerateFirewallRules() { Debug.Log("=== WINDOWS FIREWALL RULES ==="); Debug.Log(""); Debug.Log("Run PowerShell as Administrator, then:"); Debug.Log(""); Debug.Log("# Allow port " + gamePort); Debug.Log("netsh advfirewall firewall add rule name=\"Unity Port " + gamePort + "\" dir=in action=allow protocol=TCP localport=" + gamePort + " enable=yes profile=any"); Debug.Log(""); Debug.Log("# Allow Unity Editor"); Debug.Log("netsh advfirewall firewall add rule name=\"Unity Editor\" dir=in action=allow program=\"%ProgramFiles%\\Unity\\Hub\\Editor\\*\\Unity.exe\" enable=yes profile=any"); Debug.Log(""); Debug.Log("# Allow your game build"); Debug.Log("netsh advfirewall firewall add rule name=\"Northbound Game\" dir=in action=allow program=\"D:\\Northbound\\Build\\Northbound.exe\" enable=yes profile=any"); Debug.Log(""); Debug.Log("Note: Update the game path to your actual build location!"); Debug.Log("==============================="); } [ContextMenu("Copy Port to Clipboard")] public void CopyPortToClipboard() { GUIUtility.systemCopyBuffer = gamePort.ToString(); Debug.Log("Copied port " + gamePort + " to clipboard"); } } }