public void Open() { SetGame(Game); Status = ServerStatus.Starting; NetworkServer = new Lidgren.Network.NetServer( SetupNetwork(new Lidgren.Network.NetPeerConfiguration("MPTANKS") { ConnectionTimeout = 15, AutoFlushSendQueue = false, Port = Configuration.Port, MaximumConnections = Configuration.MaxPlayers + 4 //so we can gracefully disconnect })); NetworkServer.Start(); Status = ServerStatus.Open; Logger.Info($"Server started on port {Configuration.Port}. Configuration: "); Logger.Info(Configuration); }
//Refresh the entire server public void AutoRestartServer(string name, int port, bool isPublic, string password, bool attemptUPnP, int maxPlayers, Lidgren.Network.NetServer prevserver = null, Lidgren.Network.NetPeerConfiguration prevconfig = null) { List <Client> PreviousClients = new List <Client>(GameMain.Server.ConnectedClients); ushort LastUpdateID = GameMain.NetLobbyScreen.LastUpdateID += 1; Server.DisconnectRestart(); Server = null; Config = new GameSettings("config.xml"); if (Config.WasGameUpdated) { UpdaterUtil.CleanOldFiles(); Config.WasGameUpdated = false; Config.Save("config.xml"); } NilMod = new NilMod(); NilMod.Load(false); NilMod.NilModVPNBanlist = new VPNBanlist(); NilMod.NilModVPNBanlist.LoadVPNBans(); GameScreen = new GameScreen(); //Init(); Submarine.RefreshSavedSubs(); Screen.SelectNull(); NetLobbyScreen = new NetLobbyScreen(); NetLobbyScreen.ServerName = GameMain.NilMod.ServerName; Server = new GameServer(name, port, isPublic, password, attemptUPnP, maxPlayers, prevserver, prevconfig); DefaultServerStartup(); Timing.Accumulator = 0.0; stopwatch.Stop(); stopwatch = Stopwatch.StartNew(); prevTicks = stopwatch.ElapsedTicks; GameMain.Server.AddRestartClients(PreviousClients, LastUpdateID); }
public void AutoRestartServer(string name, int port, bool isPublic, string password, bool attemptUPnP, int maxPlayers, Lidgren.Network.NetServer prevserver = null, Lidgren.Network.NetPeerConfiguration prevconfig = null) { if (Server == null) { return; } List <Client> PreviousClients = new List <Client>(GameMain.Server.ConnectedClients); ushort LastUpdateID = GameMain.NetLobbyScreen.LastUpdateID += 1; GameMain.Server.DisconnectRestart(); GameMain.NetworkMember = null; waitForKeyHit = false; NilMod.Skippedtoserver = true; GameMain.NetLobbyScreen = new NetLobbyScreen(); try { GameMain.NetworkMember = new GameServer(name, port, isPublic, password, attemptUPnP, maxPlayers, prevserver, prevconfig); } catch (Exception e) { DebugConsole.ThrowError("Failed to start server", e); } GameMain.NetLobbyScreen.IsServer = true; GameMain.NetLobbyScreen.DefaultServerStartup(); waitForKeyHit = false; if (GameMain.Server != null) { GameMain.Server.AddRestartClients(PreviousClients, LastUpdateID); } }