public Task StartAsync(EmbeddedServerOptions options) { if (options.ServerMode == EmbeddedServerMode.None) { throw new Exception(); } m_serverMode = options.ServerMode; m_gameOptions = options.NewGameOptions; if (!System.IO.Directory.Exists(options.SaveGamePath)) { System.IO.Directory.CreateDirectory(options.SaveGamePath); } Guid save = Guid.Empty; m_saveManager = new SaveManager(options.SaveGamePath); if (options.CleanSaveDir) { m_saveManager.DeleteAll(); } else { save = m_saveManager.GetLatestSaveFile(); } CreateEmbeddedServer(options.SaveGamePath, save); var tcs = new TaskCompletionSource <object>(); var serverStartWaitHandle = new AutoResetEvent(false); ThreadPool.RegisterWaitForSingleObject(serverStartWaitHandle, (o, timeout) => { serverStartWaitHandle.Dispose(); if (timeout) { m_serverThread.Abort(); tcs.SetException(new Exception("Timeout waiting for server")); } else { tcs.SetResult(null); } }, null, TimeSpan.FromSeconds(60), true); m_serverThread = new Thread(ServerMain); m_serverThread.Start(serverStartWaitHandle); return(tcs.Task); }
public async Task StartServerAsync(EmbeddedServerOptions options, IProgress<string> prog) { if (options.ServerMode == EmbeddedServerMode.None || m_server != null) return; var server = new EmbeddedServer(); server.StatusChanged += prog.Report; prog.Report("Starting Server"); await server.StartAsync(options); m_server = server; }
public Task StartAsync(EmbeddedServerOptions options) { if (options.ServerMode == EmbeddedServerMode.None) throw new Exception(); m_serverMode = options.ServerMode; m_gameOptions = options.NewGameOptions; if (!System.IO.Directory.Exists(options.SaveGamePath)) System.IO.Directory.CreateDirectory(options.SaveGamePath); Guid save = Guid.Empty; m_saveManager = new SaveManager(options.SaveGamePath); if (options.CleanSaveDir) m_saveManager.DeleteAll(); else save = m_saveManager.GetLatestSaveFile(); CreateEmbeddedServer(options.SaveGamePath, save); var tcs = new TaskCompletionSource<object>(); var serverStartWaitHandle = new AutoResetEvent(false); ThreadPool.RegisterWaitForSingleObject(serverStartWaitHandle, (o, timeout) => { serverStartWaitHandle.Dispose(); if (timeout) { m_serverThread.Abort(); tcs.SetException(new Exception("Timeout waiting for server")); } else { tcs.SetResult(null); } }, null, TimeSpan.FromSeconds(60), true); m_serverThread = new Thread(ServerMain); m_serverThread.Start(serverStartWaitHandle); return tcs.Task; }
public async Task StartServerAsync(EmbeddedServerOptions options, IProgress <string> prog) { if (options.ServerMode == EmbeddedServerMode.None || m_server != null) { return; } var server = new EmbeddedServer(); server.StatusChanged += prog.Report; prog.Report("Starting Server"); await server.StartAsync(options); m_server = server; }
public async Task StartServerAndConnectAsync(EmbeddedServerOptions options, ConnectionType connectionType, IProgress <string> prog) { await StartServerAsync(options, prog); Exception connectException = null; try { await ConnectPlayerAsync(connectionType, prog); } catch (Exception exc) { connectException = exc; } if (connectException != null) { await StopServerAsync(prog); throw new Exception("Failed to connect", connectException); } }
public async Task StartServerAndConnectAsync(EmbeddedServerOptions options, ConnectionType connectionType, IProgress<string> prog) { await StartServerAsync(options, prog); Exception connectException = null; try { await ConnectPlayerAsync(connectionType, prog); } catch (Exception exc) { connectException = exc; } if (connectException != null) { await StopServerAsync(prog); throw new Exception("Failed to connect", connectException); } }