Exemple #1
0
        public override void OnResponse(ref HTTPRequestStruct rq, ref HTTPResponseStruct rp)
        {
            string path = this.Folder + "\\" + rq.URL.Replace("/", "\\");

            if (Directory.Exists(path))
            {
                if (File.Exists(path + "default.htm"))
                {
                    path += "\\default.htm";
                }
                else if (File.Exists(path + "index.html"))
                {
                    path += "\\index.html";
                }
                else
                {
                    string[] dirs  = Directory.GetDirectories(path);
                    string[] files = Directory.GetFiles(path);

                    string bodyStr = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n";
                    bodyStr += "<HTML><HEAD>\n";
                    bodyStr += "<META http-equiv=Content-Type content=\"text/html; charset=windows-1252\">\n";
                    bodyStr += "</HEAD>\n";
                    bodyStr += "<BODY><p>Folder listing, to do not see this add a 'default.htm' document\n<p>\n";
                    for (int i = 0; i < dirs.Length; i++)
                    {
                        bodyStr += "<br><a href = \"" + rq.URL + Path.GetFileName(dirs[i]) + "/\">[" + Path.GetFileName(dirs[i]) + "]</a>\n";
                    }
                    for (int i = 0; i < files.Length; i++)
                    {
                        bodyStr += "<br><a href = \"" + rq.URL + Path.GetFileName(files[i]) + "\">" + Path.GetFileName(files[i]) + "</a>\n";
                    }
                    bodyStr += "</BODY></HTML>\n";

                    rp.BodyData = Encoding.ASCII.GetBytes(bodyStr);
                    return;
                }
            }

            if (File.Exists(path))
            {
                RegistryKey rk = Registry.ClassesRoot.OpenSubKey(Path.GetExtension(path), true);

                // Get the data from a specified item in the key.
                String s = (String)rk.GetValue("Content Type");

                // Open the stream and read it back.
                rp.fs = File.Open(path, FileMode.Open);
                if (s != "")
                {
                    rp.Headers["Content-type"] = s;
                }
            }
            else
            {
                rp.status = (int)RespState.NOT_FOUND;

                string bodyStr = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n";
                bodyStr += "<HTML><HEAD>\n";
                bodyStr += "<META http-equiv=Content-Type content=\"text/html; charset=windows-1252\">\n";
                bodyStr += "</HEAD>\n";
                bodyStr += "<BODY>File not found!!</BODY></HTML>\n";

                rp.BodyData = Encoding.ASCII.GetBytes(bodyStr);
            }
        }
Exemple #2
0
        public override void OnResponse(ref HTTPRequestStruct rq, ref HTTPResponseStruct rp)
        {
            string URL  = rq.URL;
            string data = URL.Substring(1, URL.Length - 1);

            Console.WriteLine("[HTTP] RECV " + data);
            StringBuilder sendString = new StringBuilder();

            try
            {
                AvatarPhotoDataReturn[] AvatarArray = new AvatarPhotoDataReturn[RoomManager.getRoom(Convert.ToInt32(data))._Users.Count + RoomManager.getRoom(Convert.ToInt32(data))._Bots.Count];
                int i = 0;
                foreach (ConnectedUser usr in RoomManager.getRoom(Convert.ToInt32(data))._Users.Values)
                {
                    AvatarPhotoDataReturn avatars = new AvatarPhotoDataReturn();

                    avatars.C   = usr._Figure;
                    avatars.X   = usr._Room_X;
                    avatars.Y   = usr._Room_Y;
                    avatars.D   = usr._Room_Dir;
                    avatars.Dr  = usr._Drink;
                    avatars.S   = usr._Room_Sit;
                    avatars.Brb = usr._Brb;
                    if (usr._Room_X != usr._Room_X_Target || usr._Room_Y != usr._Room_Y_Target)
                    {
                        avatars.W = 1;
                    }
                    else
                    {
                        avatars.W = 0;
                    }

                    AvatarArray[i] = avatars;
                    i++;
                }

                foreach (JabboServerCMD.Core.Instances.Room.Users.RoomBot bot in RoomManager.getRoom(Convert.ToInt32(data))._Bots.Values)
                {
                    AvatarPhotoDataReturn avatars = new AvatarPhotoDataReturn();

                    avatars.C   = bot._MyFigure;
                    avatars.X   = bot._MyX;
                    avatars.Y   = bot._MyY;
                    avatars.D   = bot._MyZ;
                    avatars.Dr  = "";
                    avatars.S   = bot._Sit;
                    avatars.Brb = 0;
                    if (bot._MyX != bot.targetX || bot._MyY != bot.targetY)
                    {
                        avatars.W = 1;
                    }
                    else
                    {
                        avatars.W = 0;
                    }

                    AvatarArray[i] = avatars;
                    i++;
                }

                sendString.Append(JsonConvert.SerializeObject(AvatarArray));
            }
            catch
            {
                sendString.Append("error");
            }

            rp.BodyData = Encoding.ASCII.GetBytes(sendString.ToString());
            return;
        }
Exemple #3
0
 public abstract void OnResponse(ref HTTPRequestStruct rq, ref HTTPResponseStruct rp);
Exemple #4
0
 public abstract void OnResponse(ref HTTPRequestStruct rq, ref HTTPResponseStruct rp);
Exemple #5
0
        public override void OnResponse(ref HTTPRequestStruct rq, ref HTTPResponseStruct rp)
        {
            string URL = rq.URL;
            string data = URL.Substring(1, URL.Length - 1);
            Console.WriteLine("[HTTP] RECV " + data);
            StringBuilder sendString = new StringBuilder();

            try
            {
                AvatarPhotoDataReturn[] AvatarArray = new AvatarPhotoDataReturn[RoomManager.getRoom(Convert.ToInt32(data))._Users.Count + RoomManager.getRoom(Convert.ToInt32(data))._Bots.Count];
                int i = 0;
                foreach (ConnectedUser usr in RoomManager.getRoom(Convert.ToInt32(data))._Users.Values)
                {
                    AvatarPhotoDataReturn avatars = new AvatarPhotoDataReturn();

                    avatars.C = usr._Figure;
                    avatars.X = usr._Room_X;
                    avatars.Y = usr._Room_Y;
                    avatars.D = usr._Room_Dir;
                    avatars.Dr = usr._Drink;
                    avatars.S = usr._Room_Sit;
                    avatars.Brb = usr._Brb;
                    if (usr._Room_X != usr._Room_X_Target || usr._Room_Y != usr._Room_Y_Target)
                    {
                        avatars.W = 1;
                    }
                    else
                    {
                        avatars.W = 0;
                    }

                    AvatarArray[i] = avatars;
                    i++;
                }

                foreach (JabboServerCMD.Core.Instances.Room.Users.RoomBot bot in RoomManager.getRoom(Convert.ToInt32(data))._Bots.Values)
                {
                    AvatarPhotoDataReturn avatars = new AvatarPhotoDataReturn();

                    avatars.C = bot._MyFigure;
                    avatars.X = bot._MyX;
                    avatars.Y = bot._MyY;
                    avatars.D = bot._MyZ;
                    avatars.Dr = "";
                    avatars.S = bot._Sit;
                    avatars.Brb = 0;
                    if (bot._MyX != bot.targetX || bot._MyY != bot.targetY)
                    {
                        avatars.W = 1;
                    }
                    else
                    {
                        avatars.W = 0;
                    }

                    AvatarArray[i] = avatars;
                    i++;
                }

                sendString.Append(JsonConvert.SerializeObject(AvatarArray));
            }
            catch
            {
                sendString.Append("error");
            }

            rp.BodyData = Encoding.ASCII.GetBytes(sendString.ToString());
            return;
        }