// Called from the Dispose method of the base class protected override void Dispose(bool disposing) { _server?.Stop(); _viewManager?.Dispose(); _server = null; _viewManager = null; }
public void Dispose() { if (_server != null) { _server?.Stop(); _server.StatusChanged -= this.OnStatusChange; } _server = null; }
public MainWindow() { InitializeComponent(); server = new HttpAsyncHost(new CasterHttpHandler()); server.StartAsync("localhost", 2083); timer.Interval = new TimeSpan(0, 0, 5); timer.Tick += Timer_Tick; timer.Start(); }
static void Main(string[] args) { // Parse the commandline arguments: var configValues = ConfigurationDictionary.Parse(args); // Require at least one "bind" value: List <string> bindUriPrefixes; if (!configValues.TryGetValue("bind", out bindUriPrefixes) || bindUriPrefixes.Count == 0) { Console.Error.WriteLine("Require at least one bind=http://ip:port/ argument."); return; } // Configurable number of accept requests active at one time per CPU core: int accepts = 4; string acceptsString; if (configValues.TryGetSingleValue("accepts", out acceptsString)) { if (!Int32.TryParse(acceptsString, out accepts)) { accepts = 4; } } else { accepts = 4; } // Create an HTTP host and start it: var handler = new APIHttpAsyncHandler(); var host = new HttpAsyncHost(handler, accepts); host.SetConfiguration(configValues); host.Run(bindUriPrefixes.ToArray()); }
public ViewManager(HttpAsyncHost server) { _server = server; _server.StatusChanged += this.OnStatusChange; _components = new Container(); _notifyIcon = new NotifyIcon(_components) { ContextMenuStrip = new ContextMenuStrip(), Icon = Icons.AppPausedIcon, Text = "CasterUIAutomation: Starting Up...", Visible = true, }; _notifyIcon.ContextMenuStrip.Opening += ContextMenuStrip_Opening; _notifyIcon.DoubleClick += notifyIcon_DoubleClick; _notifyIcon.MouseUp += notifyIcon_MouseUp; _hiddenWindow = new System.Windows.Window(); _hiddenWindow.Hide(); StartServer(); }
static void Main() { ServerStarted = DateTime.Now; if (File.Exists("MOTD.txt")) { MOTD = Encoding.Default.GetBytes($"<pre>\n{File.ReadAllText("MOTD.txt").InsertHrefInUrls()}\n</pre>"); } Console.Write("Initializing Bancho"); if (IsDebug) { Console.Write(" in debug mode"); } Console.WriteLine(".."); Process.GetCurrentProcess().PriorityBoostEnabled = true; Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.RealTime; Thread.CurrentThread.Priority = ThreadPriority.Highest; Console.CursorVisible = false; Console.Title = (IsDebug?"[DEBUG] ":"") + "osu!Bancho"; GeoUtil.Initialize(); if (!File.Exists("config.ini")) { File.WriteAllText("config.ini", IniFile.DefaultIni); } IniFile ini = new IniFile("config.ini"); Bancho.IsRestricted = ini.GetValue("Bancho", "Restricted", false); CultureInfo = CultureInfo.CreateSpecificCulture("en-GB"); Console.WriteLine("Initializing Database.."); var connectionString = new MySqlConnectionStringBuilder { ConnectionTimeout = ini.GetValue("DatabaseConnection", "ConnectionTimeout", 10u), Database = ini.GetValue("DatabaseConnection", "Database", "osu!"), DefaultCommandTimeout = ini.GetValue("DatabaseConnection", "CommandTimeout", 30u), Logging = false, MaximumPoolSize = ini.GetValue("DatabaseConnection", "MaximumPoolSize", 250u), MinimumPoolSize = ini.GetValue("DatabaseConnection", "MinimumPoolSize", 10u), Password = ini.GetValue("DatabaseConnection", "Password", ""), Pooling = true, Port = ini.GetValue("DatabaseConnection", "Port", 3306u), Server = ini.GetValue("DatabaseConnection", "Server", "127.0.0.1"), UserID = ini.GetValue("DatabaseConnection", "User", "root"), AllowZeroDateTime = true, ConvertZeroDateTime = true, }; _databaseManager = new DatabaseManager(connectionString.ToString()); if (!_databaseManager.IsConnected()) { Console.Error.WriteLine("Failed to connect to the specified MySQL server."); Console.ReadKey(true); Environment.Exit(1); } workerTimer = new Timer( (state) => { foreach (Player player in PlayerManager.Players .Where(player => (Environment.TickCount - player.LastPacketTime) >= 80000)) { PlayerManager.DisconnectPlayer(player, DisconnectReason.Timeout); } try { UpdateOnlineNow(); } catch (Exception e) { Debug.WriteLine("Can't update onlines_now: " + e.Message); } }, null, 0, 15000); #if DEBUG Debug.Listeners.Add(new ConsoleTraceListener()); #endif Console.WriteLine("Initializing IRC.."); irc = new IrcManager(); irc.Start(); var port = ini.GetValue("Bancho", "Port", 80); Console.WriteLine($"Initializing HTTP in port {port.ToString()}.."); HttpAsyncHost http = new HttpAsyncHost(IsDebug? 1 : 120); http.Run("http://+:" + port.ToString() + "/"); Console.ReadLine(); }
/// <summary> /// /// </summary> protected GameHttpHost(IHttpAsyncHandler handler) { listenUrls = new List <string>(); httpListener = new HttpAsyncHost(handler, 16); }
public STAApplicationContext() { _server = new HttpAsyncHost(new CasterHttpHandler()); _viewManager = new ViewManager(_server); }
static void Main(string[] args) { try { Console.CancelKeyPress += OnCancelKeyPress; try { HandlerManager.Init(Assembly.GetExecutingAssembly()); } catch (Exception ex) { TraceLog.WriteError("Application_Start error:{0}", ex); } HttpAsyncHandler.PageListen["/"] = OnService;//default page HttpAsyncHandler.PageListen["/default.ashx"] = OnService; var listenUrls = new List <string>(); var httpListener = new HttpAsyncHost(HttpAsyncHandler.Default, 16); var section = ConfigManager.Configger.GetFirstOrAddConfig <ProtocolSection>(); var httpHost = section.HttpHost; var httpPort = section.HttpPort; var httpName = section.HttpName; if (!string.IsNullOrEmpty(httpHost)) { var hosts = httpHost.Split(','); foreach (var point in hosts) { var addressList = point.Split(':'); string host = addressList[0]; int port = httpPort; if (addressList.Length > 1) { int.TryParse(addressList[1], out port); } string address = host.StartsWith("http", StringComparison.InvariantCultureIgnoreCase) ? host : "http://" + host; if (listenUrls.Count == 0) { listenUrls.Add(string.Format("{0}:{1}/", address, port)); } listenUrls.Add(string.Format("{0}:{1}/{2}/", address, port, httpName)); } } httpListener.Run(listenUrls.ToArray()); foreach (var listenUrl in listenUrls) { TraceLog.WriteLine("{0} Http service:{1} is started.", DateTime.Now.ToString("HH:mm:ss"), listenUrl.TrimEnd('/')); } if (httpListener.Error != null) { throw httpListener.Error; } TraceLog.WriteLine("{0} AccountServer has started successfully!", DateTime.Now.ToString("HH:mm:ss")); } catch (Exception ex) { TraceLog.WriteLine("{0} AccountServer failed to start!", DateTime.Now.ToString("HH:mm:ss")); TraceLog.WriteError("Start Error:{0}", ex); } try { TraceLog.WriteLine("# Server exit command \"Ctrl+C\" or \"Ctrl+Break\"."); RunWait().Wait(); } finally { runCompleteEvent.Set(); } }
static void Main(string[] args) { var host = new HttpAsyncHost(null); host.Run("http://+/"); }