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); }
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> /// 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."); }
/// <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."); }
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(); }
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> /// 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> /// 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(); }
/// <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> /// 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"]); } } }
public List<int> getBuddyIDs(int userID) { List<int> buddyIDs = new List<int>(); Database Database = new Database(false, true); Database.addParameterWithValue("userid", userID); Database.Open(); if (Database.Ready) { DataTable dTable = Database.getTable("SELECT id FROM users WHERE id IN(SELECT buddyid FROM messenger_buddylist WHERE userid = @userid AND accepted = '1') OR id IN(SELECT userid FROM messenger_buddylist WHERE buddyid = @userid AND accepted = '1')"); foreach (DataRow dRow in dTable.Rows) { buddyIDs.Add((int)dRow["id"]); } } return buddyIDs; }
/// <summary> /// Initializes the configuration from the 'configuration' table. /// </summary> public static void loadConfiguration() { Logging.Log("Loading configuration from `configuration` table..."); charTable = System.Text.Encoding.GetEncoding("iso-8859-1"); Database Database = new Database(true, true); if (Database.Ready) { DataTable Table = Database.getTable("SELECT configkey,configvalue FROM configuration"); foreach (DataRow Row in Table.Rows) { string Key = (string)Row["configkey"]; if (!configurationValues.ContainsKey(Key)) { string Value = (string)Row["configvalue"]; configurationValues.Add(Key, Value); //Logging.Log(" " + Key + " = \"" + Value + "\""); } } Game.Items.carryItemHelper.setDefaultHandItemTypes(); Logging.Log("Loaded configuration (" + Table.Rows.Count + " entries)"); } else { Logging.Log("Failed to load configuration, because the database wasn't contactable!", Logging.logType.commonWarning); ObjectTree.Application.Stop("failed to load configuration"); } }
/// <summary> /// Returns the messenger buddy requests for a given user ID as an array of messengerBuddyRequest. /// </summary> /// <param name="userID">The database ID of the user to get the messenger buddy requests of.</param> public messengerBuddyRequest[] getBuddyRequests(int userID) { List<messengerBuddyRequest> Requests = new List<messengerBuddyRequest>(); Database Database = new Database(false, true); Database.addParameterWithValue("userid", userID); Database.Open(); if (Database.Ready) { DataTable dTable = Database.getTable("SELECT id,username FROM users WHERE id = (SELECT userid FROM messenger_buddylist WHERE buddyid = @userid AND accepted = '0')"); foreach (DataRow dRow in dTable.Rows) { messengerBuddyRequest Request = new messengerBuddyRequest(); Request.userID = (int)dRow["id"]; Request.Username = (string)dRow["username"]; Requests.Add(Request); } } return Requests.ToArray(); }
/// <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."); }
/// <summary> /// Lists various statistics about the registered users in the textbox on the GUI. /// </summary> public void listUserStats() { Database db = new Database(false, false); DataTable dTable = null; System.Text.StringBuilder sb = new System.Text.StringBuilder(); int Counter = 0; Logging.Log("Listing user statistics...\n"); db.Open(); sb.Append("Role user amounts:\n"); for (int roleID = 0; roleID <= 6; roleID++) { int Count = db.getInteger("SELECT COUNT(id) FROM users WHERE role = '" + roleID + "'"); sb.Append("Role '" + ((userRole)roleID).ToString() + "' has " + Count + " users.\n"); } sb.Append("\n> Top 20 of richest normal users:\n"); dTable = db.getTable("SELECT id,username,credits FROM users WHERE role <= '3' ORDER BY credits DESC LIMIT 20"); foreach (DataRow dRow in dTable.Rows) { Counter++; int userID = (int)dRow["id"]; string Username = (string)dRow["username"]; int Credits = (int)dRow["credits"]; sb.Append(Counter + ") " + Username + " [id: " + userID + "] has " + Credits + " credits.\n"); } Logging.Log(sb.ToString()); Logging.Log("User statistics listed.\n"); db.Close(); }
/// <summary> /// Gets the transactions (credit log) of a user on given user session and sends it to the session's game connection. /// </summary> /// <param name="Session">The Woodpecker.Sessions.Session object to get the transaction for and to send the message to.</param> public void sendTransactions(ref Session Session) { if (Session.User == null) return; serverMessage Message = new serverMessage(209); // "CQ" Database Database = new Database(false, true); Database.addParameterWithValue("userid", Session.User.ID); Database.Open(); if (Database.Ready) { DataTable creditLogData = Database.getTable("SELECT moment,type,activity FROM users_creditlog WHERE userid = @userid LIMIT 50"); foreach (DataRow dRow in creditLogData.Rows) { DateTime Moment = (DateTime)dRow["moment"]; Message.appendTabbedValue(Moment.ToString("dd/MM/yyyy")); Message.appendTabbedValue(Moment.ToString("hh:mm")); Message.appendTabbedValue(dRow["activity"].ToString()); Message.appendTabbedValue("0"); Message.appendTabbedValue(""); Message.Append(dRow["type"].ToString()); Message.appendChar(13); } } Session.gameConnection.sendMessage(Message); }
/// <summary> /// Initializes the sales sold in the catalogue. /// </summary> public void loadSales() { if (this.Sales != null) this.Sales.Clear(); this.Sales = new Dictionary<string, storeCatalogueSale>(); Database dbClient = new Database(true, false); if (dbClient.Ready) { foreach (DataRow dSale in dbClient.getTable("SELECT * FROM store_catalogue_sales").Rows) { storeCatalogueSale pSale = new storeCatalogueSale((string)dSale["salecode"], (int)dSale["price"]); // Create blank sale object bool isPackage = ( (dSale["ispackage"].ToString() == "true") && dSale["package_name"] != DBNull.Value && dSale["package_description"] != DBNull.Value); if (isPackage) { pSale.setPackage((string)dSale["package_name"], (string)dSale["package_description"]); foreach (DataRow dPackageItem in dbClient.getTable("SELECT definitionid,amount,specialspriteid FROM store_catalogue_sales_packages WHERE salecode = '" + pSale.saleCode + "'").Rows) { itemDefinition pItemDefinition = ObjectTree.Game.Items.getItemDefinition((int)dPackageItem["definitionid"]); if (pItemDefinition != null) pSale.addPackageItem(pItemDefinition, (int)dPackageItem["amount"], (int)dPackageItem["specialspriteid"]); } } else { itemDefinition pItemDefinition = ObjectTree.Game.Items.getItemDefinition((int)dSale["item_definitionid"]); if (pItemDefinition != null) pSale.setItem(pItemDefinition, (int)dSale["item_specialspriteid"]); } this.Sales.Add(pSale.saleCode, pSale); } dbClient.Close(); } }
/// <summary> /// Initializes the store catalogue pages. /// </summary> public void loadCataloguePages() { Database dbClient = new Database(true, true); if (!dbClient.Ready) { Logging.Log("Failed to load store catalogue pages, database was not contactable!", Logging.logType.commonError); return; } this.Pages = new Dictionary<string,storeCataloguePage>(); // New collection foreach (DataRow pageData in dbClient.getTable("SELECT * FROM store_catalogue_pages ORDER BY orderid ASC").Rows) { storeCataloguePage pPage = new storeCataloguePage(); pPage.ID = (int)pageData["id"]; pPage.setMinimumAccessRole(ObjectTree.Game.Roles.parseRoleFromString(pageData["minrole"].ToString())); // Set attributes for page foreach(string szAttribute in this.pageAttributes) pPage.setAttribute(szAttribute, pageData[szAttribute]); if (pageData["label_extra_t"] != DBNull.Value) { bool skip = false; string[] extraTypedData = pageData["label_extra_t"].ToString().Split(Environment.NewLine.ToCharArray()); foreach (string szTypedData in extraTypedData) { if (!skip) { string ID = szTypedData.Substring(0, szTypedData.IndexOf(':')); string szData = szTypedData.Substring(ID.ToString().Length + 1); pPage.setAttribute("label_extra_t_" + ID, szData); } skip = !skip; } } pPage.initializeSales(); this.Pages.Add(pPage.getStringAttribute("name_index"), pPage); } }
/// <summary> /// Retrieves all non-read messages of a given user and returns it as a messengerMessage array. /// </summary> /// <param name="userID">The database ID of the user to get the messages for.</param> public messengerMessage[] getMessages(int userID) { List<messengerMessage> Messages = new List<messengerMessage>(); Database Database = new Database(false, true); Database.addParameterWithValue("userid", userID); Database.Open(); if (Database.Ready) { DataTable dTable = Database.getTable("SELECT messageid,senderid,sent,body FROM messenger_messages WHERE receiverid = @userid ORDER BY messageid ASC"); foreach (DataRow dRow in dTable.Rows) { messengerMessage Message = new messengerMessage(); Message.ID = (int)dRow["messageid"]; Message.senderID = (int)dRow["senderid"]; Message.Sent = (DateTime)dRow["sent"]; Message.Body = (string)dRow["body"]; Messages.Add(Message); } } return Messages.ToArray(); }
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 the messenger buddies for a given user ID as an array of messengerBuddy. /// </summary> /// <param name="userID">The database ID of the user to get the messenger buddies of.</param> public messengerBuddy[] getBuddies(int userID) { List<messengerBuddy> Buddies = new List<messengerBuddy>(); Database Database = new Database(false, true); Database.addParameterWithValue("userid", userID); Database.Open(); if (Database.Ready) { DataTable dTable = Database.getTable("SELECT id,username,figure,sex,motto_messenger,lastactivity FROM users WHERE id IN(SELECT buddyid FROM messenger_buddylist WHERE userid = @userid AND accepted = '1') OR id IN(SELECT userid FROM messenger_buddylist WHERE buddyid = @userid AND accepted = '1')"); foreach(DataRow dRow in dTable.Rows) { Buddies.Add(messengerBuddy.Parse(dRow)); } } return Buddies.ToArray(); }