public static void Run() { var server = new DotNetServer(); var pipe = server.Start(); server.Host((env, respond, error) => { respond(new Tuple <string, IDictionary <string, IEnumerable <string> >, IEnumerable <object> >( "200 OK", new Dictionary <string, IEnumerable <string> >() { { "Content-Type", new string[] { "text/html" } } }, new object[] { Encoding.ASCII.GetBytes("Hello world.") } )); }); Console.WriteLine("Listening on " + server.ListenEndPoint); Console.WriteLine("Press enter to exit."); Console.ReadLine(); pipe.Dispose(); }
public static void Run() { var server = new DotNetServer(); var pipe = server.Start(); String passKey = "071mVGZ9h2d4Va"; server.Host((env, respond, error) => { var path = env["Owin.RequestUri"] as string; var urlParts = path.Substring(1).Split(new[] { '/' }, 15); if (urlParts.Length >= 1) { if (urlParts[0] == "status") { Log.Info("Received a url request - " + urlParts[0]); respond( "200 OK", new Dictionary <string, IList <string> >() { { "Content-Type", new string[] { "text/plain" } } }, new object[] { Encoding.ASCII.GetBytes("Online") } ); return; } else if (urlParts[0] == "validate") { try { String remKey = urlParts[1]; if (File.Exists("License.key")) { if (presets.authorise(remKey, passKey) == true) { respond( "200 OK", new Dictionary <string, IList <string> >() { { "Content-Type", new string[] { "text/plain" } } }, new object[] { Encoding.ASCII.GetBytes("authorised") } ); Log.Info("authorised"); } else { respond( "200 OK", new Dictionary <string, IList <string> >() { { "Content-Type", new string[] { "text/plain" } } }, new object[] { Encoding.ASCII.GetBytes("bad key") } ); Log.Info("bad key"); } } else { respond( "200 OK", new Dictionary <string, IList <string> >() { { "Content-Type", new string[] { "text/plain" } } }, new object[] { Encoding.ASCII.GetBytes("License.key file not found or damaged.") } ); Log.Error("License.key file not found or damaged."); } } catch (Exception e) { respond( "200 OK", new Dictionary <string, IList <string> >() { { "Content-Type", new string[] { "text/plain" } } }, new object[] { Encoding.ASCII.GetBytes("bad request") } ); Log.Info("bad request"); Console.WriteLine(e); } } else if (urlParts[0] == "about") { respond( "200 OK", new Dictionary <string, IList <string> >() { { "Content-Type", new string[] { "text/plain" } } }, new object[] { Encoding.ASCII.GetBytes(presets.getVersion()) } ); } else if (urlParts[0] == "start") { string remKey = urlParts[1]; string layerStart = urlParts[2]; if (presets.authorise(remKey, passKey) == true) { Log.Info("Calling preset.start() for - " + layerStart);//calling if (presets.run(layerStart) == true) { respond( "200 OK", new Dictionary <string, IList <string> >() { { "Content-Type", new string[] { "text/plain" } } }, new object[] { Encoding.ASCII.GetBytes("success") } ); Log.Info("Returned success"); } else { respond( "200 OK", new Dictionary <string, IList <string> >() { { "Content-Type", new string[] { "text/plain" } } }, new object[] { Encoding.ASCII.GetBytes("error") } ); Log.Info("Returned error"); } } else { respond( "200 OK", new Dictionary <string, IList <string> >() { { "Content-Type", new string[] { "text/plain" } } }, new object[] { Encoding.ASCII.GetBytes("authorisation error") } ); Log.Info("authorisation error"); } } else if (urlParts[0] == "stop") { string remKey = urlParts[1]; string layerStop = urlParts[2]; if (presets.authorise(remKey, passKey) == true) { Log.Info("Calling preset.start() for - " + layerStop); //calling if (presets.run(layerStop) == true) { respond( "200 OK", new Dictionary <string, IList <string> >() { { "Content-Type", new string[] { "text/plain" } } }, new object[] { Encoding.ASCII.GetBytes("success") } ); Log.Info("Returned success"); } else { respond( "200 OK", new Dictionary <string, IList <string> >() { { "Content-Type", new string[] { "text/plain" } } }, new object[] { Encoding.ASCII.GetBytes("error") } ); Log.Info("Returned error"); } } else { respond( "200 OK", new Dictionary <string, IList <string> >() { { "Content-Type", new string[] { "text/plain" } } }, new object[] { Encoding.ASCII.GetBytes("authorisation error") } ); Log.Info("authorisation error"); } } else if (urlParts[0] == "new") { string remKey = urlParts[1]; if (presets.authorise(remKey, passKey)) { Log.Info("calling presets.createLayer()"); string NAME = urlParts[2]; string SERVERIP = urlParts[3]; string SERVERRCON = urlParts[4]; //rcon port string SERVERPASS = urlParts[5]; string LAYERUSER = urlParts[6]; string LAYERPASS = urlParts[7]; string LAYERPORT = urlParts[8]; string LAYERGAME = urlParts[9]; string LAYERINITIALS = urlParts[10]; Log.Info("Variables assigned"); presets.createLayer(NAME, SERVERIP, SERVERRCON, SERVERPASS, LAYERUSER, LAYERPASS, LAYERPORT, LAYERGAME, LAYERINITIALS); Log.Info("presets.createLayer() called"); respond( "200 OK", new Dictionary <string, IList <string> >() { { "Content-Type", new string[] { "text/plain" } } }, new object[] { Encoding.ASCII.GetBytes("done") } ); } else { respond( "200 OK", new Dictionary <string, IList <string> >() { { "Content-Type", new string[] { "text/plain" } } }, new object[] { Encoding.ASCII.GetBytes("authorisation error") } ); Log.Info("authorisation error"); } } else if (urlParts[0] == "layerinfo") { } else { respond( "200 OK", new Dictionary <string, IList <string> >() { { "Content-Type", new string[] { "text/plain" } } }, new object[] { Encoding.ASCII.GetBytes("You are not authorised to dance here.") } ); } //break } } ); }
public static void Run() { var server = new DotNetServer(); var pipe = server.Start(); server.Host((env, respond, error) => { var path = env["Owin.RequestUri"] as string; /* * if (path == "/") * respond( * "200 OK", * new Dictionary<string, IList<string>>() * { * { "Content-Type", new string[] { "text/plain" } } * }, * new object[] { Encoding.ASCII.GetBytes("Hello world.") } * ); * else if (path == "/stream") * { * StreamingApp(env, respond, error); * } * else if (path == "/bufferedecho") * { * BufferedEcho(env, respond, error); * } */ var urlParts = path.Substring(1).Split(new[] { '/' }, 2); if (urlParts.Length >= 1) { if (urlParts[0] == "nick") { var steamID = long.Parse(urlParts[1]); var client = Client.Get(steamID); Console.WriteLine(steamID); if (client.GameVersion != 0) { var nickname = client.GamerTag; respond( "200 OK", new Dictionary <string, IList <string> >() { { "Content-Type", new string[] { "text/plain" } } }, new object[] { Encoding.ASCII.GetBytes(nickname) } ); return; } } else if (urlParts[0] == "stats") { var statistics = Client.GetStatistics(); var retString = "[Stats]\r\n"; var totalPlayers = 0; foreach (var stat in statistics) { retString += string.Format("playerState{0}={1}\r\n", stat.StatisticID, stat.StatisticCount); totalPlayers += stat.StatisticCount; } retString += string.Format("totalPlayers={0}\r\n", totalPlayers); retString += "[Lobbies]\r\n"; totalPlayers = 0; foreach (var serverc in MatchServer.Servers) { var cnt = serverc.Value.Sessions.Count(sess => (DateTime.Now - sess.LastTouched).TotalSeconds < 60); //var cnt = serverc.Value.Sessions.Count; retString += string.Format("lobbies{0}={1}\r\n", serverc.Key, cnt); totalPlayers += cnt; } retString += string.Format("totalLobbies={0}", totalPlayers); respond( "200 OK", new Dictionary <string, IList <string> >() { { "Content-Type", new string[] { "text/plain" } } }, new object[] { Encoding.ASCII.GetBytes(retString) } ); return; } else if (urlParts[0] == "clean") { long clientID = 0; var valid = false; if (long.TryParse(urlParts[1], out clientID)) { if (clientID != 0x110000100000002) { var client = Client.Get(clientID); if ((DateTime.UtcNow - client.LastTouched).TotalSeconds < 300) { var state = CIServer.IsUnclean(clientID, null); if (!state) { valid = true; } } } } respond( "200 OK", new Dictionary <string, IList <string> >() { { "Content-Type", new string[] { "text/plain" } } }, new object[] { Encoding.ASCII.GetBytes((valid) ? "valid" : "invalid") } ); return; } else if (urlParts[0] == "cleanExt") { long clientID = 0; var valid = false; var reason = "invalid-id"; if (long.TryParse(urlParts[1], out clientID)) { if (clientID != 0x110000100000002) { var client = Client.Get(clientID); if ((DateTime.UtcNow - client.LastTouched).TotalHours < 6) { var state = CIServer.IsUnclean(clientID, null); if (state) { reason = CIServer.WhyUnclean(clientID); } else { reason = "actually-valid"; valid = true; } } else { reason = "not-registered-at-lsp"; } } else { reason = "00002-IDGEN-error"; } } respond( "200 OK", new Dictionary <string, IList <string> >() { { "Content-Type", new string[] { "text/plain" } } }, new object[] { Encoding.ASCII.GetBytes(((valid) ? "valid" : "invalid") + "\r\n" + reason) } ); return; } else if (urlParts[0] == "pc") { var file = "pc/" + urlParts[1].Replace('\\', '/'); if (!File.Exists(file)) { respond( "200 OK", new Dictionary <string, IList <string> >() { { "Content-Type", new string[] { "text/plain" } } }, new object[] { Encoding.ASCII.GetBytes("Not found!") } ); } else { var stream = File.OpenRead(file); var b = new byte[stream.Length]; stream.Read(b, 0, (int)stream.Length); stream.Close(); respond( "200 OK", new Dictionary <string, IList <string> >() { { "Content-Type", new string[] { "application/octet-stream" } } }, new object[] { b } ); } return; } else if (urlParts[0] == "servers") { var filter = urlParts[1].Replace(".xml", ""); if (filter.Contains("yeQA4reD")) { respond( "200 OK", new Dictionary <string, IList <string> >() { { "Content-Type", new string[] { "text/xml" } } }, new object[] { Encoding.ASCII.GetBytes(ProcessServers(filter)) } ); } else { respond( "200 OK", new Dictionary <string, IList <string> >() { { "Content-Type", new string[] { "text/html" } } }, new object[] { Encoding.ASCII.GetBytes("Invalid") } ); } return; } else { respond( "200 OK", new Dictionary <string, IList <string> >() { { "Content-Type", new string[] { "text/html" } } }, new object[] { Encoding.ASCII.GetBytes("Invalid") } ); } } }); Log.Info("Listening on " + server.ListenEndPoint); }