Ejemplo n.º 1
0
        public stripItem createPresent(int receivingUserID, string saleCode, string Note, string customData)
        {
            int definitionID = ObjectTree.Game.Items.getRandomPresentBoxDefinitionID();
            if (definitionID != 1)
            {
                stripItem presentBoxItem = ObjectTree.Game.Items.createItemInstance(definitionID, receivingUserID, "!" + Note);

                Database dbClient = new Database(false, true);
                dbClient.addParameterWithValue("itemid", presentBoxItem.ID);
                dbClient.addParameterWithValue("salecode", saleCode);
                if (customData == "")
                    dbClient.addParameterWithValue("customdata", DBNull.Value);
                else
                    dbClient.addParameterWithValue("customdata", customData);

                dbClient.Open();
                if (dbClient.Ready)
                    dbClient.runQuery("INSERT INTO items_presents VALUES (@itemid,@salecode,@customdata)");

                return presentBoxItem;
            }
            else
            {
                Logging.Log("Failed to create presentbox for sale '" + saleCode + "', one of the present box definitions is missing!", Logging.logType.commonError);
                return null;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Accepts a buddy request and notifies the sender (if online) and the receiver.
        /// </summary>
        /// <param name="Session">The Woodpecker.Sessions.Session object of the user that accepts the request.</param>
        /// <param name="senderID">The database ID of the user that sent the request.</param>
        public void acceptBuddyRequest(ref Session Session, int senderID)
        {
            Database Database = new Database(false, false);
            Database.addParameterWithValue("userid", Session.User.ID);
            Database.addParameterWithValue("senderid", senderID);
            Database.Open();

            if (Database.findsResult("SELECT userid FROM messenger_buddylist WHERE userid = @senderid AND buddyid = @userid AND accepted = '0' LIMIT 1"))
            {
                Database.runQuery("UPDATE messenger_buddylist SET accepted = '1' WHERE userid = @senderid AND buddyid = @userid LIMIT 1");
                Database.Close();

                serverMessage Message = new serverMessage();
                if (ObjectTree.Game.Users.userIsLoggedIn(senderID)) // Sender is online!
                {
                    Message.Initialize(137); // "BI"
                    Message.Append(getBuddy(Session.User.ID).ToString());
                    ObjectTree.Game.Users.trySendGameMessage(senderID, Message);
                }

                Message.Initialize(137); // "BI"
                Message.Append(getBuddy(senderID).ToString());
                Session.gameConnection.sendMessage(Message);
            }
            else
                Database.Close();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Inserts room rights in a given room for a given user.
        /// </summary>
        /// <param name="roomID">The database ID of the room to assign the user rights to.</param>
        /// <param name="userID">The database ID of the user that gets the rights.</param>
        public void addRoomRights(int roomID, int userID)
        {
            Database Database = new Database(false, true);
            Database.addParameterWithValue("roomid", roomID);
            Database.addParameterWithValue("userid", userID);
            Database.Open();

            Database.runQuery("INSERT INTO rooms_rights(roomid,userid) VALUES (@roomid,@userid)");
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Adds a given room to a given user's favorite room list.
        /// </summary>
        /// <param name="userID">The database ID of the user to modify the list for.</param>
        /// <param name="roomID">The database ID of the room to add to the user's favorite list.</param>
        public void addFavoriteRoom(int userID, int roomID)
        {
            Database Database = new Database(false, true);
            Database.addParameterWithValue("userid", userID);
            Database.addParameterWithValue("roomid", roomID);
            Database.Open();

            if (Database.Ready)
                Database.runQuery("INSERT INTO rooms_favorites(userid,roomid) VALUES (@userid,@roomid)");
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Updates the last activity datetime in the database and this object to the current time.
        /// </summary>
        public void updateLastActivity()
        {
            Database Database = new Database(false, true);
            Database.addParameterWithValue("userid", this.ID);
            Database.Open();
            if (Database.Ready)
                Database.runQuery("UPDATE users SET lastactivity = NOW() WHERE id = @userid");

            this.lastActivity = DateTime.Now;
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Returns a boolean that indicates if a given IP address is present in the 'connections_blacklist' table of the database.
 /// </summary>
 /// <param name="IP">The IP address to check.</param>
 public bool ipIsBlacklisted(string IP)
 {
     Database Database = new Database(false, true);
     Database.addParameterWithValue("ip", IP);
     Database.Open();
     if (Database.Ready)
         return Database.findsResult("SELECT ip FROM connections_blacklist WHERE ip = @ip");
     else
         return false;
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Deletes a messenger message of a user, with only the message ID given.
        /// </summary>
        /// <param name="userID">The database ID of the user to delete the message of.</param>
        /// <param name="messageID">The ID of the message to delete.</param>
        public void markMessageAsRead(int userID, int messageID)
        {
            Database Database = new Database(false, true);
            Database.addParameterWithValue("userid", userID);
            Database.addParameterWithValue("messageid", messageID);
            Database.Open();

            if (Database.Ready)
                Database.runQuery("DELETE FROM messenger_messages WHERE receiverid = @userid AND messageid = @messageid LIMIT 1");
        }
Ejemplo n.º 8
0
        public void loadRoles()
        {
            Logging.Log("Initializing user roles...");
            Database Database = new Database(true, false);
            DataTable dTable = new DataTable();
            if (Database.Ready)
            {
                for (int roleID = 0; roleID <= 6; roleID++)
                {
                    userRole Role = (userRole)roleID;
                    //Logging.Log("Role '" + Role.ToString() + "'");

                    // Role rights
                    List<string> tmpList = new List<string>();
                    dTable = Database.getTable("SELECT fuseright FROM users_roles_fuserights WHERE minrole <= '" + roleID + "'");

                    foreach (DataRow dRow in dTable.Rows)
                    {
                        string Right = (string)dRow["fuseright"];
                        tmpList.Add(Right);
                        //Logging.Log("   - FUSE right: " + Right);
                    }
                    this.roleRights.Add(Role, tmpList);

                    // Role badges
                    tmpList = new List<string>();
                    dTable = Database.getTable("SELECT badge FROM users_roles_badges WHERE minrole <= '" + roleID + "'");
                    foreach (DataRow dRow in dTable.Rows)
                    {
                        string Badge = (string)dRow["badge"];
                        tmpList.Add(Badge);
                        //Logging.Log("   - Badge: " + Badge);
                    }
                    this.roleBadges.Add(Role, tmpList);

                    //ObjectTree.Application.GUI.logSacredText(null);
                }

                //Logging.Log("FUSE rights for users with Club subscription:");
                // Club rights
                dTable = Database.getTable("SELECT fuseright FROM users_club_fuserights");
                foreach (DataRow dRow in dTable.Rows)
                {
                    string Right = (string)dRow["fuseright"];
                    this.clubRights.Add(Right);
                    //Logging.Log("- " + Right);
                }
                //ObjectTree.Application.GUI.logSacredText(null);

                Logging.Log("Initialized user roles.");
            }
            else
                Logging.Log("Failed to initialize user roles, database was not contactable!", Logging.logType.commonWarning);
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Adds a given IP address to the connection blacklist, thus refusing future connections (both game and MUS) from that IP address.
 /// </summary>
 /// <param name="IP">The IP address to add to the blacklist.</param>
 public void blackListIpAddress(string IP)
 {
     Database Database = new Database(false, true);
     Database.addParameterWithValue("ip", IP);
     Database.Open();
     if (Database.Ready)
     {
         Database.runQuery("INSERT INTO connections_blacklist(ip,added) VALUES (@ip, CURDATE())");
         Logging.Log("Blacklisted IP address '" + IP + "' for whatever reason.", Logging.logType.connectionBlacklistEvent);
     }
     else
         Logging.Log("Failed to add IP address '" + IP + "' to the connection blacklist, the database was not contactable.", Logging.logType.commonError);
 }
Ejemplo n.º 10
0
 public void addPrivateBadgesToList(int userID, userRole Role, ref List<string> lBadges)
 {
     Database db = new Database(false, true);
     db.addParameterWithValue("userid", userID);
     db.Open();
     if (db.Ready)
     {
         DataTable dTable = db.getTable("SELECT badge FROM users_badges WHERE userid = @userid");
         foreach (DataRow dRow in dTable.Rows)
         {
             lBadges.Add(dRow["badge"].ToString());
         }
     }
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Inserts a new row with the current access details into the database's 'users_access' table.
        /// </summary>
        public void Update()
        {
            Database dbClient = new Database(false, true);
            dbClient.addParameterWithValue("userid", this.userID);
            dbClient.addParameterWithValue("sessionid", this.sessionID);
            dbClient.addParameterWithValue("ip", this.IP);
            dbClient.addParameterWithValue("machineid", this.machineID);

            dbClient.Open();
            if (dbClient.Ready)
            {
                dbClient.runQuery("INSERT INTO users_access VALUES (@userid,@sessionid,NOW(),@ip,@machineid)");
                this.lastUpdate = DateTime.Now;
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Initialize the sale codes of the sales that are sold on this page and puts them in the correct order.
        /// </summary>
        public void initializeSales()
        {
            if (this.saleCodes != null)
                this.saleCodes.Clear();
            this._szObj = null;
            this.saleCodes = new List<string>();

            Database dbClient = new Database(false, true);
            dbClient.addParameterWithValue("pageid", this.ID);
            dbClient.Open();

            if (dbClient.Ready)
            {
                foreach (DataRow dRow in dbClient.getTable("SELECT salecode FROM store_catalogue_sales WHERE pageid = @pageid ORDER BY orderid ASC").Rows)
                {
                    this.saleCodes.Add((string)dRow["salecode"]);
                }
            }
        }
Ejemplo n.º 13
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.º 14
0
        /// <summary>
        /// Wipes the current collection of external texts and re-loads them from the database.
        /// </summary>
        public void loadEntries()
        {
            if (this.Texts != null)
                this.Texts.Clear(); // Wipe old entries
            this.Texts = new Dictionary<string, string>();

            Logging.Log("Loading external_texts entries...");
            Database dbClient = new Database(true, true);
            if (!dbClient.Ready)
            {
                Logging.Log("Failed to initialize external_texts! Database was not contactable!", Logging.logType.commonError);
                return;
            }

            foreach (DataRow dEntry in dbClient.getTable("SELECT * FROM external_texts").Rows)
            {
                string extKey = (string)dEntry["extkey"];
                string extValue = (string)dEntry["extvalue"];

                this.Texts.Add(extKey, extValue);
            }
            Logging.Log("Loaded " + this.Texts.Count + " external_texts entries.");
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Tries to find a room with a given ID. If the room is found, a full roomInformation object is created and returned. If the room is not found, then null is returned.
        /// </summary>
        /// <param name="roomID">The database ID of the room to get the information of.</param>
        public roomInformation getRoomInformation(int roomID)
        {
            if (_Rooms.ContainsKey(roomID)) // Why load it? :)
                return _Rooms[roomID].Information;

            Database Database = new Database(false, true);
            Database.addParameterWithValue("roomid", roomID);
            Database.Open();

            if (Database.Ready)
            {
                DataRow dRow = Database.getRow("SELECT rooms.*,users.username AS owner FROM rooms LEFT JOIN users ON rooms.ownerid = users.id WHERE rooms.id = @roomid LIMIT 1");
                return roomInformation.Parse(dRow, true);
            }
            else
                return null;
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Updates the current amount of visitors in a given room instance in the database.
        /// </summary>
        /// <param name="roomID">The database ID of the room to update.</param>
        /// <param name="userAmount">The up to date amount of users in the instance of the given room.</param>
        public void updateRoomUserAmount(int roomID, int userAmount)
        {
            Database Database = new Database(false, true);
            Database.addParameterWithValue("roomid", roomID);
            Database.addParameterWithValue("useramount", userAmount);
            Database.Open();

            if (Database.Ready)
                Database.runQuery("UPDATE rooms SET visitors_now = @useramount WHERE id = @roomid LIMIT 1");
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Returns a boolean indicating if a given user owns a given room.
        /// </summary>
        /// <param name="userID">The database ID of the user to check.</param>
        /// <param name="roomID">The database ID of the room to check.</param>
        public bool userOwnsRoom(int userID, int roomID)
        {
            Database Database = new Database(false, true);
            Database.addParameterWithValue("userid", userID);
            Database.addParameterWithValue("roomid", roomID);
            Database.Open();

            return Database.findsResult("SELECT id FROM rooms WHERE id = @roomid AND ownerid = @userid LIMIT 1");
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Removes roomrights for a given user in a given room.
        /// </summary>
        /// <param name="roomID">The database ID of the room to remove the rights for the user of.</param>
        /// <param name="userID">The database ID of the user that gets the rights removed.</param>
        public void removeRoomRights(int roomID, int userID)
        {
            Database Database = new Database(false, true);
            Database.addParameterWithValue("roomid", roomID);
            Database.addParameterWithValue("userid", userID);
            Database.Open();

            Database.runQuery("DELETE FROM rooms_rights WHERE roomid = @roomid AND userid = @userid LIMIT 1");
            // TODO: refresh in room instance
        }
Ejemplo n.º 19
0
 /// <summary>
 /// Resets the amount of users for every room in the database to 0.
 /// </summary>
 public void resetRoomUserAmounts()
 {
     Database Database = new Database(true, true);
     if (Database.Ready)
     {
         Database.runQuery("UPDATE rooms SET visitors_now = '0'");
         Logging.Log("Current visitor amounts of rooms set to 0.");
     }
 }
Ejemplo n.º 20
0
        public roomInformation[] getFlatsForUser(userInformation User)
        {
            List<roomInformation> Rooms = new List<roomInformation>();
            Database Database = new Database(false, true);
            Database.addParameterWithValue("ownerid", User.ID);
            Database.Open();

            if (Database.Ready)
            {
                DataTable dTable = Database.getTable("SELECT rooms.*,users.username AS owner FROM rooms LEFT JOIN users ON (rooms.ownerid = users.id) WHERE ownerid = @ownerid");
                foreach (DataRow dRow in dTable.Rows)
                {
                    Rooms.Add(roomInformation.ParseFlat(dRow));
                }
            }

            return Rooms.ToArray();
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Removes a given room to a given user's favorite room list.
        /// </summary>
        /// <param name="userID">The database ID of the user to modify the list for.</param>
        /// <param name="roomID">The database ID of the room to remove to the user's favorite list.</param>
        public void removeFavoriteRoom(int userID, int roomID)
        {
            Database Database = new Database(false, true);
            Database.addParameterWithValue("userid", userID);
            Database.addParameterWithValue("roomid", roomID);
            Database.Open();

            if (Database.Ready)
                Database.runQuery("DELETE FROM rooms_favorites WHERE userid = @userid AND roomid = @roomid LIMIT 1");
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Initializes the room models and stores them in a persistent collection object for further reference.
        /// </summary>
        public void initRoomModels()
        {
            Logging.Log("Initializing room models...");
            _Models.Clear();

            Database dbClient = new Database(true, true);
            if (dbClient.Ready)
            {
                foreach (DataRow dRow in dbClient.getTable("SELECT * FROM rooms_models").Rows)
                {
                    roomModel pModel = roomModel.Parse(dRow);
                    if (pModel != null)
                        _Models.Add(pModel.typeName, pModel);
                }
            }
            Logging.Log("Initialized " + _Models.Count + " room models.");
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Initializes the room category informations and stores them in a persistent collection object for further reference.
        /// </summary>
        public void initRoomCategories()
        {
            Logging.Log("Initializing room categories...");
            _Categories.Clear();

            Database dbClient = new Database(true, true);
            if (dbClient.Ready)
            {
                foreach (DataRow dRow in dbClient.getTable("SELECT * FROM rooms_categories ORDER BY orderid ASC").Rows)
                {
                    roomCategoryInformation pCategory = roomCategoryInformation.Parse(dRow);
                    if (pCategory != null)
                        _Categories.Add(pCategory.ID, pCategory);
                }
            }
            Logging.Log("Initialized " + _Categories.Count + " room categories.");
        }
Ejemplo n.º 24
0
        public roomModel getModel(string Type)
        {
            if (!_Models.ContainsKey(Type)) // Not initialized yet
            {
                Database Database = new Database(false, true);
                Database.addParameterWithValue("modeltype", Type);
                Database.Open();

                if (Database.Ready)
                {
                    DataRow dRow = Database.getRow("SELECT * FROM rooms_models WHERE modeltype = @modeltype");
                    if (dRow != null)
                    {
                        roomModel New = roomModel.Parse(dRow);
                        if (New == null || dRow["modeltype"].ToString() != Type) // Not found / invalid case
                        {
                            Logging.Log("Room model '" + Type + "' was found but contained invalid data.", Logging.logType.commonWarning);
                            return null;
                        }
                        else
                            _Models.Add(Type, New);
                    }
                    else
                    {
                        Logging.Log("The requested room model '" + Type + "' was not found in the 'rooms_models' table of the database!", Logging.logType.commonWarning);
                        return null;
                    }
                }

                Logging.Log("Room model '" + Type + "' is initialized and added to cache.", Logging.logType.roomInstanceEvent);
            }

            return _Models[Type];
        }
        private void saveItemDefinition(itemDefinition pDefinition)
        {
            Database dbClient = new Database(false, false);
            dbClient.addParameterWithValue("definitionid", pDefinition.ID);
            dbClient.addParameterWithValue("directoryid", pDefinition.directoryID);
            dbClient.addParameterWithValue("sprite", pDefinition.Sprite);
            dbClient.addParameterWithValue("color", pDefinition.Color);
            dbClient.addParameterWithValue("length", pDefinition.Length);
            dbClient.addParameterWithValue("width", pDefinition.Width);
            dbClient.addParameterWithValue("topheight", pDefinition.topHeight);
            dbClient.addParameterWithValue("behaviour", pDefinition.Behaviour.ToString());

            dbClient.Open();
            if (dbClient.Ready)
            {
                dbClient.runQuery("DELETE FROM items_definitions WHERE id = @definitionid LIMIT 1"); // Drop old definition
                dbClient.runQuery( // Insert new/edited definition
                    "INSERT INTO items_definitions " +
                    "VALUES " +
                    "(@definitionid,@directoryid,@sprite,@color,@length,@width,@topheight,@behaviour)");
                dbClient.Close();
            }
        }
        private void deleteItemDefinition(int ID)
        {
            Database dbClient = new Database(false, false);
            dbClient.addParameterWithValue("definitionid", ID);

            dbClient.Open();
            if (dbClient.Ready)
            {
                dbClient.runQuery("DELETE FROM items_definitions WHERE id = @definitionid LIMIT 1"); // Drop definition
                dbClient.runQuery("DELETE FROM store_catalogue_sales WHERE item_definitionid = @definitionid"); // Drop single-item sales with this item definition
                dbClient.runQuery("DELETE FROM store_catalogue_sales_packages WHERE definitionid = @definitionid"); // Drop this item definition from packages
                dbClient.Close();
            }
        }
        private void displayItemDefinitions()
        {
            this.boxEditor.Enabled = false;
            this.lvItemDefinitions.Items.Clear();
            ObjectTree.Game.Items.loadDefinitions();

            if (this.tsModifySearchDefinitionText.Text == "")
            {
                foreach (itemDefinition lDefinition in ObjectTree.Game.Items.getItemDefinitionCollection().Values)
                {
                    this.addItemDefinitionToList(lDefinition);
                }
            }
            else
            {
                Database dbClient = new Database(false, true);
                dbClient.addParameterWithValue("criteria", "%" + this.tsModifySearchDefinitionText.Text + "%");
                dbClient.Open();

                if (dbClient.Ready)
                {
                    foreach (DataRow dRow in dbClient.getTable("SELECT id FROM items_definitions WHERE sprite LIKE @criteria ORDER BY id ASC").Rows)
                    {
                        int ID = (int)dRow["id"];
                        this.addItemDefinitionToList(ObjectTree.Game.Items.getItemDefinition(ID));
                    }
                }
            }
            this.lvItemDefinitions.Refresh();
        }
Ejemplo n.º 28
0
        public roomInformation[] getUserFlatsSearchResult(string Criteria)
        {
            List<roomInformation> Rooms = new List<roomInformation>();
            Database Database = new Database(false, false);
            Database.addParameterWithValue("criteria", "%" + Criteria); // Only search for rooms with names starting with the criteria
            Database.addParameterWithValue("owner", Criteria); // Also search for rooms who's ownername is equal to the criteria
            Database.Open();

            if (Database.Ready)
            {
                DataTable dTable = Database.getTable("SELECT rooms.*,users.username AS owner FROM rooms LEFT JOIN users ON (rooms.ownerid = users.id) WHERE rooms.ownerid > 0 AND (users.username = @owner OR rooms.roomname LIKE @criteria) ORDER BY visitors_now DESC LIMIT 30");
                foreach (DataRow dRow in dTable.Rows)
                {
                    Rooms.Add(roomInformation.ParseFlat(dRow));
                }
            }
            Database.Close();

            return Rooms.ToArray();
        }
        private void tsModifyAddDefinition_Click(object sender, EventArgs e)
        {
            itemDefinition newDefinition = new itemDefinition();
            Database dbClient = new Database(true, true);
            newDefinition.ID = dbClient.getInteger("SELECT MAX(id) + 1 FROM items_definitions");
            displayItemDefinition(newDefinition);

            displayMessageBox("Fill in the details for this new item definition below and click the button to save.", MessageBoxIcon.Information);
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Returns the total amount of existing user flats that a given user has created.
        /// </summary>
        /// <param name="userID">The database ID of the user to get the room count of.</param>
        /// <returns></returns>
        public int getUserRoomCount(int userID)
        {
            Database Database = new Database(false, true);
            Database.addParameterWithValue("userid", userID);
            Database.Open();

            if (Database.Ready)
                return Database.getInteger("SELECT COUNT(id) FROM rooms WHERE ownerid = @ownerid");
            else
                return int.MaxValue; // Never make a room in this case
        }