static int Main(string[] args) { Console.Title = "MiniBillingServer by Syinea V1.0"; Console.WriteLine("Visit: https://facebook.com/syinea"); Console.WriteLine("for more information and updates"); Console.WriteLine(""); Console.WriteLine("Visit: Official Coder "); Console.WriteLine("https://github.com/florian0"); try { Http.HttpServer server = new Http.HttpServer(); Model.BindingConfiguration bindcfg = new Model.BindingConfiguration("Settings/config.ini"); Console.WriteLine(""); Console.WriteLine("You should set billing server address to this one: "); Console.WriteLine(""); Console.WriteLine("http://" + bindcfg.Address + ":" + bindcfg.Port + @"/"); Console.WriteLine(""); Console.WriteLine("Mini Billing Server modified by Syinea"); Console.WriteLine(""); Console.WriteLine("-------------------------------------------------------------------"); server.Prefixes.Add("http://" + bindcfg.Address + ":" + bindcfg.Port + "/"); server.Handlers.Add(new Handlers.ServerStateHandler()); server.Handlers.Add(new Handlers.SilkDataCallHandler()); Model.SilkDB.Instance.Init(); server.Start(); } catch (FileNotFoundException ex) { Console.WriteLine("[Exception] {0}", ex.Message); Console.WriteLine(CheckConfigIssue()); Console.Read(); return(-1); } Console.Read(); return(0); }
static void StartBillingServer() { Be_Config _Config = Config.cfg; Http.HttpServer server = new Http.HttpServer(); Console.WriteLine(""); Console.WriteLine("You should set billing server address to this one: "); Console.WriteLine(""); Console.WriteLine("http://" + _Config.Listen_Address + ":" + _Config.Listen_Port + @"/"); Console.WriteLine(""); Console.WriteLine("-------------------------------------------------------------------"); server.Prefixes.Add("http://" + _Config.Listen_Address + ":" + _Config.Listen_Port + "/"); server.Handlers.Add(new Handlers.ServerStateHandler()); server.Handlers.Add(new Handlers.SilkDataCallHandler()); Model.SilkDB.Instance.Init(); server.Start(); }
private static void worker(object state) { HttpServer server = (HttpServer)state; Console.WriteLine("Working running"); while (server.m_listener.IsListening) { HttpListenerContext context = server.m_listener.GetContext(); Console.WriteLine("> {0}", context.Request.Url.ToString()); bool handled = false; try { foreach (IHttpHandler handler in server.Handlers) { if (handler.Handle(context)) { handled = true; break; } } } catch (AccessDeniedException ex) { // Access Denied // Send Status 403 Console.WriteLine("[Access-denied] {0} from {1}", ex.Context.Request.Url.ToString(), ex.Context.Request.RemoteEndPoint.ToString()); string responseString = "<HTML><BODY>Access denied</BODY></HTML>"; byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString); HttpListenerResponse response = context.Response; // Get a response stream and write the response to it. response.ContentLength64 = buffer.Length; response.StatusCode = 403; response.StatusDescription = "Access denied"; System.IO.Stream output = response.OutputStream; output.Write(buffer, 0, buffer.Length); // You must close the output stream. output.Close(); continue; } // Check is the request was handled if (!handled) { // Unhandler Request Handler // Send Status 500 Console.WriteLine("Unhandled Request!"); string responseString = "<HTML><BODY>Unhandled Request</BODY></HTML>"; byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString); HttpListenerResponse response = context.Response; // Get a response stream and write the response to it. response.ContentLength64 = buffer.Length; response.StatusCode = 500; response.StatusDescription = "Internal Server error"; System.IO.Stream output = response.OutputStream; output.Write(buffer, 0, buffer.Length); // You must close the output stream. output.Close(); } } }