Esempio n. 1
0
        protected override bool StartNetworkServer()
        {
            var bindAddr = NetworkHelper.GetLocalIP(AddressFamily.InterNetwork);

            if (!string.IsNullOrWhiteSpace(Config["Bindaddr"]))
            {
                bindAddr = IPAddress.Parse(Config["Bindaddr"]);
            }

            var networkConfig = new NetworkServerConfig
            {
                BindEndPoint     = new IPEndPoint(bindAddr, Config["SvPort"]),
                MaxClientsPerIp  = Math.Clamp(Config["SvMaxClientsPerIP"], 1, MaxClients),
                MaxClients       = Math.Clamp(Config["SvMaxClients"], 1, MaxClients),
                ConnectionConfig = new ConnectionConfig
                {
                    Timeout = Config["ConnTimeout"]
                }
            };

            if (!NetworkServer.Open(networkConfig))
            {
                Debug.Error("server", $"couldn't open socket. port {networkConfig.BindEndPoint.Port} might already be in use");
                return(false);
            }

            NetworkServer.ClientConnected    += ClientConnected;
            NetworkServer.ClientDisconnected += ClientDisconnected;
            Debug.Log("server", $"network server running at: {networkConfig.BindEndPoint}");
            return(true);
        }
Esempio n. 2
0
        protected override bool StartNetworkServer()
        {
            var bindAddr = NetworkCore.GetLocalIP(AddressFamily.InterNetwork);

            if (!string.IsNullOrWhiteSpace(Config["Bindaddr"]))
            {
                bindAddr = IPAddress.Parse(Config["Bindaddr"]);
            }

            var networkConfig = new NetworkServerConfig
            {
                LocalEndPoint   = new IPEndPoint(bindAddr, Config["SvPort"]),
                MaxClientsPerIp = Config["SvMaxClientsPerIP"],
                MaxClients      = Config["SvMaxClients"]
            };

            if (!NetworkServer.Open(networkConfig))
            {
                Debug.Error("server", $"couldn't open socket. port {networkConfig.LocalEndPoint.Port} might already be in use");
                return(false);
            }

            Debug.Log("server", $"network server running at: {networkConfig.LocalEndPoint}");
            return(true);
        }
Esempio n. 3
0
 /// <summary>
 ///     Creates a Network Listener that can be started with .Start
 /// </summary>
 /// <param name="refreshMillis">Main Loop Delay</param>
 /// <param name="config">Path to NetworkConfig file</param>
 /// <param name="multiThread">flag to enable multithreading</param>
 /// <param name="noUpdateCheck">flag to disable checking for updates</param>
 public NetworkListener(int refreshMillis, string config = "", bool multiThread = true,
                        bool noUpdateCheck = false)
 {
     _noUpdateCheck = noUpdateCheck;
     LoadConfig(NetworkServerConfig.Load(config));
     _multiThread    = multiThread;
     RefreshMillis   = refreshMillis;
     DebugNetworking = false;
 }
Esempio n. 4
0
 private void LoadConfig(NetworkServerConfig conf)
 {
     Config = conf;
 }