Ejemplo n.º 1
0
        /// <summary>
        /// Returns the favorite rooms of a given user as a string.
        /// </summary>
        /// <param name="User">The userInformation object of the user to retrieve the favorite rooms for.</param>
        public string getFavoriteRooms(userInformation User)
        {
            int           guestRoomCount = 0;
            StringBuilder Rooms          = new StringBuilder();

            Database Database = new Database(false, true);

            Database.addParameterWithValue("userid", User.ID);
            Database.Open();
            DataTable dTable = Database.getTable("SELECT rooms.*,users.username AS owner FROM rooms LEFT JOIN users ON rooms.ownerid = users.id WHERE rooms.id IN (SELECT roomid FROM rooms_favorites WHERE userid = @userid) ORDER BY rooms.id DESC LIMIT 30"); // User flats first

            foreach (DataRow dRow in dTable.Rows)
            {
                roomInformation Room = roomInformation.Parse(dRow, true);
                if (Room.isUserFlat)
                {
                    guestRoomCount++;
                }

                Rooms.Append(Room.ToString(User));
            }

            fuseStringBuilder FSB = new fuseStringBuilder();

            FSB.appendWired(guestRoomCount);
            FSB.Append(Rooms.ToString());

            return(FSB.ToString());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Parses all required fields from a given System.Data.DataRow object to a full roomInformation object.
        /// </summary>
        /// <param name="dRow">The System.Data.DataRow object containing the required fields.</param>
        public static roomInformation Parse(DataRow dRow, bool parseOwnerName)
        {
            if (dRow == null)
            {
                return(null);
            }
            else
            {
                roomInformation Room = new roomInformation();
                Room.ID         = (int)dRow["id"];
                Room.ownerID    = (int)dRow["ownerid"];
                Room.categoryID = (int)dRow["category"];
                if (parseOwnerName && dRow["owner"] != DBNull.Value)
                {
                    Room.Owner = (string)dRow["owner"];
                }
                Room.Name        = (string)dRow["roomname"];
                Room.Description = (string)dRow["description"];
                Room.modelType   = (string)dRow["modeltype"];
                if (dRow["ccts"] != DBNull.Value)
                {
                    Room.CCTs = (string)dRow["ccts"];
                }
                Room.Wallpaper       = int.Parse(dRow["wallpaper"].ToString());
                Room.Floor           = int.Parse(dRow["floor"].ToString());
                Room.accessType      = (roomAccessType)int.Parse(dRow["accesstype"].ToString());
                Room.showOwner       = (dRow["showname"].ToString() == "true");
                Room.superUsers      = (dRow["superusers"].ToString() == "true");
                Room.Password        = (string)dRow["password"];
                Room.currentVisitors = int.Parse(dRow["visitors_now"].ToString());
                Room.maxVisitors     = int.Parse(dRow["visitors_max"].ToString());

                return(Room);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 29 - "@]"
        /// </summary>
        public void CREATEFLAT()
        {
            if (ObjectTree.Game.Rooms.getUserRoomCount(Session.User.ID) >= Configuration.getNumericConfigurationValue("users.rooms.maxroomsperuser"))
            {
                Session.gameConnection.sendLocalizedError("Error creating a private room");
                return;
            }

            Response.Initialize(59); // "@{"

            string[] Settings = Request.Content.Split('/');
            roomInformation newRoom = new roomInformation();
            newRoom.ownerID = Session.User.ID;
            newRoom.Name = Settings[2];
            newRoom.modelType = Settings[3];
            stringFunctions.filterVulnerableStuff(ref newRoom.Name, true);

            // Verify room model
            roomModel testModel = ObjectTree.Game.Rooms.getModel(newRoom.modelType);
            if (testModel == null
                || testModel.userType == roomModelUserType.PublicSpaceModel
                || testModel.userType == roomModelUserType.UserFlatSpecialModel && !Session.User.hasFuseRight("fuse_use_special_room_layouts"))
                return; // Model does not exist, model is for public spaces only or model requires certain FUSE right and user does not has this fuse right

            newRoom.accessType = (roomAccessType)Enum.Parse(typeof(roomAccessType), Settings[4]);
            newRoom.showOwner = (Settings[5] == "1");

            int newRoomID = ObjectTree.Game.Rooms.createFlat(newRoom);
            Response.Append(newRoomID);
            Response.appendChar(13);
            Response.Append(newRoom.Name);

            sendResponse();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 152 - "BX"
        /// </summary>
        public void GETFLATCAT()
        {
            int             roomID = Request.getNextWiredParameter();
            roomInformation Room   = Engine.Game.Rooms.getRoomInformation(roomID);

            Response.Initialize(222); // "C^"
            if (Room != null)
            {
                Response.appendWired(Room.ID);
                Response.appendWired(Room.categoryID);
            }
            sendResponse();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 24 - "@X"
        /// </summary>
        public void UPDATEFLAT()
        {
            string[] Details = Request.Content.Split('/');
            int      roomID  = int.Parse(Details[0]);

            roomInformation Room = Engine.Game.Rooms.getRoomInformation(roomID);

            if (Room != null && Room.ownerID == Session.User.ID)
            {
                stringFunctions.filterVulnerableStuff(ref Details[1], true);
                Room.Name       = Details[1];
                Room.accessType = (roomAccessType)Enum.Parse(typeof(roomAccessType), Details[2]);
                Room.showOwner  = (Details[3] == "1");
                Room.updateSettings();
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 19 - "@S"
        /// </summary>
        public void ADD_FAVORITE_ROOM()
        {
            if (Engine.Game.Rooms.getFavoriteRoomCount(Session.User.ID) < Configuration.getNumericConfigurationValue("users.favoriterooms.max"))
            {
                int[] Parameters = Request.getWiredParameters();
                int   roomID     = Parameters[1];

                roomInformation Room = Engine.Game.Rooms.getRoomInformation(roomID);
                if (Room != null && Engine.Game.Rooms.getRoomCategory(Room.categoryID).userRoleHasAccess(Session.User.Role)) // Room exist and user has access to room
                {
                    Engine.Game.Rooms.addFavoriteRoom(Session.User.ID, roomID);
                }
            }
            else
            {
                Session.gameConnection.sendLocalizedError("nav_error_toomanyfavrooms");
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Creates a new user flat room by writing the given details in the 'rooms' table of the database. The new room's ID is returned upon success.
        /// </summary>
        /// <param name="Details">The Woodpecker.Game.Rooms.roomInformation object containing the details of the new room.</param>
        public int createFlat(roomInformation Details)
        {
            int roomID = 0;
            Database Database = new Database(false, false);
            Database.addParameterWithValue("roomname", Details.Name);
            Database.addParameterWithValue("ownerid", Details.ownerID);
            Database.addParameterWithValue("modeltype", Details.modelType);
            Database.addParameterWithValue("accesstype", ((int)Details.accessType).ToString());
            Database.addParameterWithValue("showname", Details.showOwner.ToString().ToLower());
            Database.Open();

            if (Database.Ready)
            {
                Database.runQuery("INSERT INTO rooms(ownerid,roomname,modeltype,showname,accesstype) VALUES (@ownerid,@roomname,@modeltype,@showname,@accesstype)");
                roomID = Database.getInteger("SELECT MAX(id) FROM rooms WHERE ownerid = @ownerid LIMIT 1");
                Database.Close();
            }

            return roomID;
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Creates a new user flat room by writing the given details in the 'rooms' table of the database. The new room's ID is returned upon success.
        /// </summary>
        /// <param name="Details">The Woodpecker.Game.Rooms.roomInformation object containing the details of the new room.</param>
        public int createFlat(roomInformation Details)
        {
            int      roomID   = 0;
            Database Database = new Database(false, false);

            Database.addParameterWithValue("roomname", Details.Name);
            Database.addParameterWithValue("ownerid", Details.ownerID);
            Database.addParameterWithValue("modeltype", Details.modelType);
            Database.addParameterWithValue("accesstype", ((int)Details.accessType).ToString());
            Database.addParameterWithValue("showname", Details.showOwner.ToString().ToLower());
            Database.Open();

            if (Database.Ready)
            {
                Database.runQuery("INSERT INTO rooms(ownerid,roomname,modeltype,showname,accesstype) VALUES (@ownerid,@roomname,@modeltype,@showname,@accesstype)");
                roomID = Database.getInteger("SELECT MAX(id) FROM rooms WHERE ownerid = @ownerid LIMIT 1");
                Database.Close();
            }

            return(roomID);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 153 - "BY"
        /// </summary>
        public void SETFLATCAT()
        {
            int[] Parameters = Request.getWiredParameters();
            int   roomID     = Parameters[0];
            int   categoryID = Parameters[1];

            roomCategoryInformation newCategory = Engine.Game.Rooms.getRoomCategory(categoryID);

            if (newCategory != null && newCategory.userRoleCanPutFlat(Session.User.Role)) // Valid category
            {
                roomInformation Room = Engine.Game.Rooms.getRoomInformation(roomID);
                if (Room != null && Room.ownerID == Session.User.ID && Room.categoryID != newCategory.ID) // Valid change
                {
                    Room.categoryID = newCategory.ID;
                    Room.updateSettings();
                    if (Engine.Game.Rooms.roomInstanceRunning(roomID))
                    {
                        Engine.Game.Rooms.getRoomInstance(roomID).Information = Room;
                    }
                }
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Parses all required fields for a user flat (guestroom) from a given System.Data.DataRow object to a flat-only roomInformation object.
        /// </summary>
        /// <param name="dRow">The System.Data.DataRow object containing the required fields.</param>
        public static roomInformation ParseFlat(DataRow dRow)
        {
            if (dRow == null)
            {
                return(null);
            }
            else
            {
                roomInformation Room = new roomInformation();
                Room.ID      = (int)dRow["id"];
                Room.ownerID = (int)dRow["ownerid"];
                Room.Owner   = (string)dRow["owner"];

                Room.Name            = (string)dRow["roomname"];
                Room.Description     = (string)dRow["description"];
                Room.accessType      = (roomAccessType)int.Parse(dRow["accesstype"].ToString());
                Room.currentVisitors = int.Parse(dRow["visitors_now"].ToString());
                Room.maxVisitors     = int.Parse(dRow["visitors_max"].ToString());

                return(Room);
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 29 - "@]"
        /// </summary>
        public void CREATEFLAT()
        {
            if (Engine.Game.Rooms.getUserRoomCount(Session.User.ID) >= Configuration.getNumericConfigurationValue("users.rooms.maxroomsperuser"))
            {
                Session.gameConnection.sendLocalizedError("Error creating a private room");
                return;
            }

            Response.Initialize(59); // "@{"

            string[]        Settings = Request.Content.Split('/');
            roomInformation newRoom  = new roomInformation();

            newRoom.ownerID   = Session.User.ID;
            newRoom.Name      = Settings[2];
            newRoom.modelType = Settings[3];
            stringFunctions.filterVulnerableStuff(ref newRoom.Name, true);

            // Verify room model
            roomModel testModel = Engine.Game.Rooms.getModel(newRoom.modelType);

            if (testModel == null ||
                testModel.userType == roomModelUserType.PublicSpaceModel ||
                testModel.userType == roomModelUserType.UserFlatSpecialModel && !Session.User.hasFuseRight("fuse_use_special_room_layouts"))
            {
                return; // Model does not exist, model is for public spaces only or model requires certain FUSE right and user does not has this fuse right
            }
            newRoom.accessType = (roomAccessType)Enum.Parse(typeof(roomAccessType), Settings[4]);
            newRoom.showOwner  = (Settings[5] == "1");

            int newRoomID = Engine.Game.Rooms.createFlat(newRoom);

            Response.Append(newRoomID);
            Response.appendChar(13);
            Response.Append(newRoom.Name);

            sendResponse();
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 21 - "@U"
        /// </summary>
        public void GETFLATINFO()
        {
            int             roomID = int.Parse(Request.Content);
            roomInformation Room   = Engine.Game.Rooms.getRoomInformation(roomID);

            if (Room == null || !Room.isUserFlat) // Room is not found / not valid
            {
                return;
            }

            Response.Initialize(54); // "@v"

            Response.appendWired(Room.superUsers);
            Response.appendWired((int)Room.accessType);
            Response.appendWired(roomID);

            if (Room.showOwner || Room.ownerID == Session.User.ID || Session.User.hasFuseRight("fuse_see_all_roomowners"))
            {
                Response.appendClosedValue(Room.Owner);
            }
            else
            {
                Response.appendClosedValue("-");
            }

            Response.appendClosedValue(Room.modelType);
            Response.appendClosedValue(Room.Name);
            Response.appendClosedValue(Room.Description);

            roomCategoryInformation Category = Engine.Game.Rooms.getRoomCategory(Room.categoryID);

            Response.appendWired(Room.showOwner);
            Response.appendWired(Category != null && Category.allowTrading);
            Response.appendWired(Room.currentVisitors);
            Response.appendWired(Room.maxVisitors);

            sendResponse();
        }
Ejemplo n.º 13
0
        /// <summary>
        /// 57 - "@y"
        /// </summary>
        public void TRYFLAT()
        {
            int    roomID        = 0;
            string givenPassword = null;

            if (Request.Content.Contains("/"))
            {
                string[] Details = Request.Content.Split('/');
                roomID        = int.Parse(Details[0]);
                givenPassword = Details[1];
            }
            else
            {
                roomID = int.Parse(Request.Content);
            }

            roomInformation Room = Engine.Game.Rooms.getRoomInformation(roomID);

            if (Room == null)
            {
                return;
            }

            if (Session.authenticatedTeleporter > 0)
            {
                if (roomID != Session.authenticatedFlat)
                {
                    return; // Attempting to enter different flat via authenticated teleporter
                }
            }
            else
            {
                if (Room.accessType != roomAccessType.open && Room.ownerID != Session.User.ID && !Session.User.hasFuseRight("fuse_enter_locked_rooms")) // Can't override checks
                {
                    if (Room.accessType == roomAccessType.password)                                                                                     // Passworded room
                    {
                        if (givenPassword != Room.Password)                                                                                             // Incorrect password given
                        {
                            Session.gameConnection.sendLocalizedError("Incorrect flat password");
                            return;
                        }
                    }
                    else // Doorbell
                    {
                        int messageID = 131; // "BC" (no answer)
                        if (Engine.Game.Rooms.roomInstanceRunning(roomID))
                        {
                            roomInstance Instance = Engine.Game.Rooms.getRoomInstance(roomID);
                            if (Instance.castDoorbellUser(Session.User.Username))
                            {
                                messageID = 91; // "A["
                                Instance.registerSession(Session.ID);
                                Session.waitingFlat = roomID;
                            }
                        }

                        Response.Initialize(messageID);
                        sendResponse();
                        return; // Wait for the eventual response
                    }
                }
                Session.authenticatedFlat = roomID;
            }

            Response.Initialize(41); // "@i"
            sendResponse();
        }
Ejemplo n.º 14
0
        /// <summary>
        /// 25 - "@Y"
        /// </summary>
        public void SETFLATINFO()
        {
            int roomID = 0;

            if (Request.Content[0] == '/') // Create room
            {
                roomID = int.Parse(Request.Content.Split('/')[1]);
            }
            else
            {
                roomID = int.Parse(Request.Content.Split('/')[0]);
            }

            roomInformation Room = Engine.Game.Rooms.getRoomInformation(roomID);

            if (Room != null && Room.ownerID == Session.User.ID) // Allowed to edit!
            {
                string[] Settings = Request.Content.Split(Convert.ToChar(13));
                for (int i = 1; i < Settings.Length; i++)
                {
                    int    keyLength = Settings[i].IndexOf('=');
                    string Key       = Settings[i].Substring(0, keyLength);
                    string Value     = Settings[i].Substring(keyLength + 1);

                    switch (Key)
                    {
                    case "description":
                    {
                        stringFunctions.filterVulnerableStuff(ref Value, true);
                        Room.Description = Value;
                    }
                    break;

                    case "allsuperuser":
                    {
                        Room.superUsers = (Value == "1");
                    }
                    break;

                    case "maxvisitors":
                    {
                        Room.maxVisitors = int.Parse(Value);
                        if (Room.maxVisitors < 10 || Room.maxVisitors > 50)
                        {
                            Room.maxVisitors = 25;
                        }
                    }
                    break;

                    case "password":
                    {
                        stringFunctions.filterVulnerableStuff(ref Value, false);
                        Room.Password = Value;
                    }
                    break;

                    default:     // Hax
                        return;
                    }
                }
                Room.updateSettings();
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Parses all required fields for a user flat (guestroom) from a given System.Data.DataRow object to a flat-only roomInformation object.
        /// </summary>
        /// <param name="dRow">The System.Data.DataRow object containing the required fields.</param>
        public static roomInformation ParseFlat(DataRow dRow)
        {
            if (dRow == null)
                return null;
            else
            {
                roomInformation Room = new roomInformation();
                Room.ID = (int)dRow["id"];
                Room.ownerID = (int)dRow["ownerid"];
                Room.Owner = (string)dRow["owner"];

                Room.Name = (string)dRow["roomname"];
                Room.Description = (string)dRow["description"];
                Room.accessType = (roomAccessType)int.Parse(dRow["accesstype"].ToString());
                Room.currentVisitors = int.Parse(dRow["visitors_now"].ToString());
                Room.maxVisitors = int.Parse(dRow["visitors_max"].ToString());

                return Room;
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Parses all required fields from a given System.Data.DataRow object to a full roomInformation object.
        /// </summary>
        /// <param name="dRow">The System.Data.DataRow object containing the required fields.</param>
        public static roomInformation Parse(DataRow dRow, bool parseOwnerName)
        {
            if (dRow == null)
                return null;
            else
            {
                roomInformation Room = new roomInformation();
                Room.ID = (int)dRow["id"];
                Room.ownerID = (int)dRow["ownerid"];
                Room.categoryID = (int)dRow["category"];
                if(parseOwnerName && dRow["owner"] != DBNull.Value)
                    Room.Owner = (string)dRow["owner"];
                Room.Name = (string)dRow["roomname"];
                Room.Description = (string)dRow["description"];
                Room.modelType = (string)dRow["modeltype"];
                if(dRow["ccts"] != DBNull.Value)
                    Room.CCTs = (string)dRow["ccts"];
                Room.Wallpaper = int.Parse(dRow["wallpaper"].ToString());
                Room.Floor = int.Parse(dRow["floor"].ToString());
                Room.accessType = (roomAccessType)int.Parse(dRow["accesstype"].ToString());
                Room.showOwner = (dRow["showname"].ToString() == "true");
                Room.superUsers = (dRow["superusers"].ToString() == "true");
                Room.Password = (string)dRow["password"];
                Room.currentVisitors = int.Parse(dRow["visitors_now"].ToString());
                Room.maxVisitors = int.Parse(dRow["visitors_max"].ToString());

                return Room;
            }
        }