/// <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(); }
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; } }
/// <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)"); }
/// <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; }
/// <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"); }
/// <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)"); }
/// <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; }
/// <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); }
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()); } } }
/// <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; } }
/// <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"]); } } }
/// <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; }
/// <summary> /// Returns the amount of favorite rooms a given user has in his/her list as an integer. /// </summary> /// <param name="userID">The database ID of the user to get the favorite room count of.</param> public int getFavoriteRoomCount(int userID) { Database Database = new Database(false, true); Database.addParameterWithValue("userid", userID); Database.Open(); return Database.getInteger("SELECT COUNT(id) FROM rooms_favorites WHERE userid = @userid"); }
/// <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"); }
/// <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"); }
/// <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 }
/// <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"); }
/// <summary> /// Loads all the items this user currently has in her/hand and stores them in the item collection. /// </summary> public void loadHandItems() { this.handItems.Clear(); Database dbClient = new Database(false, true); dbClient.addParameterWithValue("userid", this.userID); dbClient.Open(); if (dbClient.Ready) { foreach (DataRow dItem in dbClient.getTable("SELECT id,definitionid,customdata,teleporterid FROM items WHERE ownerid = @userid AND roomid = '0' ORDER BY id ASC").Rows) { stripItem pItem = new stripItem(); pItem.ID = (int)dItem["id"]; pItem.ownerID = this.userID; pItem.Definition = ObjectTree.Game.Items.getItemDefinition((int)dItem["definitionid"]); if (dItem["customdata"] != DBNull.Value) pItem.customData = (string)dItem["customdata"]; else pItem.customData = null; if (pItem.Definition.Behaviour.isTeleporter) pItem.teleporterID = (int)dItem["teleporterid"]; this.handItems.Add(pItem); } } }
/// <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 }
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(); }
/// <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; }
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]; }
/// <summary> /// Saves all the items in the hand that have been marked for update. (items that are new in the hand etc) /// </summary> public void saveHandItems() { Database dbClient = null; MySqlParameter vchrCustomData = null; foreach (stripItem lItem in this.handItems) { if (lItem.requiresUpdate) { #region Create database connection if (dbClient == null) // No database connection yet { dbClient = new Database(false, true); dbClient.addParameterWithValue("userid", this.userID); vchrCustomData = new MySqlParameter("customdata", MySqlDbType.VarChar); dbClient.addRawParameter(vchrCustomData); dbClient.Open(); if (!dbClient.Ready) // Can't use this database connection for some reason return; } #endregion if (lItem.customData == null) vchrCustomData.Value = DBNull.Value; else vchrCustomData.Value = lItem.customData; dbClient.runQuery("UPDATE items SET ownerid = @userid,roomid = '0',customdata = @customdata WHERE id = '" + lItem.ID + "' LIMIT 1"); } } if (dbClient != null) 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(); }
/// <summary> /// Returns a List of the type roomInformation with all the rooms in a given category. /// </summary> /// <param name="categoryID">The database ID of the category to get the rooms of. </param> /// <param name="orderByVisitorsAmountDescending"></param> /// <returns></returns> public List<roomInformation> getCategoryRooms(int categoryID, bool userFlats) { List<roomInformation> Rooms = new List<roomInformation>(); Database Database = new Database(false, true); Database.addParameterWithValue("category", categoryID); Database.Open(); if (Database.Ready) { DataTable dTable = null; if (userFlats) dTable = Database.getTable("SELECT rooms.*,users.username AS owner FROM rooms LEFT JOIN users ON (rooms.ownerid = users.id) WHERE rooms.category = @category ORDER BY id ASC,visitors_now DESC LIMIT 40"); else dTable = Database.getTable("SELECT * FROM rooms WHERE rooms.category = @category ORDER BY id ASC"); foreach (DataRow dRow in dTable.Rows) { Rooms.Add(roomInformation.Parse(dRow, userFlats)); } } return Rooms; }
/// <summary> /// Deletes a given user flat from the database, /// </summary> /// <param name="roomID">The database ID of the room to delete.</param> public void deleteFlat(int roomID) { Database Database = new Database(false, false); Database.addParameterWithValue("roomid", roomID); Database.Open(); if (Database.Ready) { Database.runQuery("DELETE FROM rooms WHERE id = @roomid LIMIT 1"); Database.runQuery("DELETE FROM rooms_rights WHERE roomid = @roomid"); Database.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(); } }
/// <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(); }
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(); } }
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(); }