예제 #1
0
        public override byte[] HandleCommand(URLParser _Parameters)
        {
            string command = _Parameters.Get("command");
            string resource = _Parameters.Get("res");

            Settings settings = new Settings();
            try
            {
                settings.Width = int.Parse(_Parameters.Get("width"));
            }
            catch { }
            try
            {
                settings.Height = int.Parse(_Parameters.Get("height"));
            }
            catch { }
            try
            {
                settings.Detail = int.Parse(_Parameters.Get("mip"));
            }
            catch { }

            if (command.ToLower() != null)
            {

            }
            return new byte[] { };
        }
예제 #2
0
        static void listen()
        {
            while (true)
            {
                try
                {
                    HttpListenerContext context = listener.GetContext();
                    //check username/password
                    if (context.User != null && context.User.Identity is HttpListenerBasicIdentity)
                    {
                        HttpListenerBasicIdentity identity = (HttpListenerBasicIdentity)context.User.Identity;
                        if (identity.Name != "Roeny" && identity.Password != "Baloony") continue;
                    }
                    HttpListenerResponse response = context.Response;
                    URLParser parser = new URLParser(context.Request.Url.Query);
                    byte[] buffer;
                    string iface = parser.Get("interface");
                    if (iface == interface1.Name)
                    {
                        buffer = interface1.HandleCommand(parser);
                    }
                    else if (iface == interface2.Name)
                    {
                        buffer = interface2.HandleCommand(parser);
                    }
                    else if (iface == interface3.Name)
                    {
                        buffer = interface3.HandleCommand(parser);
                    }
                    else
                    {//default
                        buffer = interface2.HandleCommand(parser);
                    }

                    response.ContentLength64 = buffer.Length;
                    System.IO.Stream output = response.OutputStream;
                    output.Write(buffer, 0, buffer.Length);
                    // You must close the output stream.
                    output.Close();
                }
                catch (Exception ex) { Console.WriteLine(ex.Message); }
            }
        }
예제 #3
0
 public abstract byte[] HandleCommand(URLParser _Parameters);
예제 #4
0
        public override byte[] HandleCommand(URLParser _Parameters)
        {
            string command = _Parameters.Get("command");
            string resource = _Parameters.Get("res");

            Settings settings = new Settings();
            //find scene
            settings.SceneName = _Parameters.Get("scene");
            Scene scene = Scene.GetScene(settings.SceneName);

            try
            {
                settings.Width = int.Parse(_Parameters.Get("width"));
            }
            catch { }
            try
            {
                settings.Height = int.Parse(_Parameters.Get("height"));
            }
            catch { }
            try
            {
                settings.Detail = int.Parse(_Parameters.Get("mip"));
            }
            catch { }

            if (command.ToLower() != null)
            {
                foreach (Scene.ClickableRegion reg in scene.ClickablePoints)
                {
                    if (reg.Target == command)
                    {
                        reg.Pressed = !reg.Pressed;
                        Console.WriteLine("{0} -> {1}", reg.Target, reg.Pressed);
                        return new byte[] { (byte)(reg.Pressed ? '1' : '0') };
                    }
                }
            }
            switch (resource)
            {
                case "background":
                    return scene.GetImageResized(settings.Width / settings.Detail, settings.Height / settings.Detail);
                case "lampon":
                    return System.IO.File.ReadAllBytes("on.png");
                case "lampoff":
                    return System.IO.File.ReadAllBytes("off.png");
                case "lamploading":
                    return System.IO.File.ReadAllBytes("loading.gif");
                default:
                    string Areas = "";
                    foreach (Scene.ClickableRegion p in scene.ClickablePoints)
                    {
                        Areas += string.Format("<img href=\"javascript:;\" src=\"{0}\" onclick=\"toggleLight(\'{1}\'); return false;\" id=\"light_{1}\" style=\"position: absolute; left:{2}%; top:{3}%; width:{4}%; width:{5}%; z-index: 3; display: block\" />",
                            p.Pressed ? "?res=lampon" : "?res=lampoff", p.Target.Trim(),
                            (p.X - p.Radius / 2) * 100, (p.Y - p.Radius / 2) * 100, p.Radius * 100, p.Radius * 100);
                        Areas += "\n";
                    }
                    string backgroundname = "?res=background";
                    backgroundname += "&scene=" + settings.SceneName;
                    backgroundname += "&width=" + settings.Width + "&height=" + settings.Height + "&mip=" + settings.Detail;//add settings needed to generate a background image

                    string response = System.IO.File.ReadAllText("interface3.htm");
                    response = response.Replace("<<<<AREAS>>>>", Areas);
                    response = response.Replace("<<<<BGNAME>>>>", backgroundname);
                    return System.Text.Encoding.ASCII.GetBytes(response);
            }
            return null;
        }