Beispiel #1
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;
        }
        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);
        }
Beispiel #3
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
        }
Beispiel #4
0
        /// <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");
        }
Beispiel #5
0
        /// <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();
        }
Beispiel #6
0
        /// <summary>
        /// Retrieves the database ID of a user, when only the username is known.
        /// </summary>
        /// <param name="Username">The username of the user to get the user ID of.</param>
        public int getUserID(string Username)
        {
            Database Database = new Database(false, true);
            Database.addParameterWithValue("username", Username);
            Database.Open();

            return Database.getInteger("SELECT id FROM users WHERE username = @username");
        }
        private void _launchBird(int[] receiverIDs, messengerMessage pMessage)
        {
            Database Database = new Database(false, false);
            Database.addParameterWithValue("senderid", pMessage.senderID);
            Database.addParameterWithValue("sent", pMessage.Sent);
            Database.addParameterWithValue("body", pMessage.Body);
            Database.Open();
            if (Database.Ready)
            {
                //DateTime now = DateTime.Now;
                //Woodpecker.Core.Logging.Log("Start: " + now.ToString("hh:mm:ss:fff"));
                foreach (int receiverID in receiverIDs)
                {
                    if (ObjectTree.Game.Users.userIsLoggedIn(receiverID)) // Receiver is logged in, retrieve the next message ID, write the message in the database & send it to the receiver
                    {
                        int messageID = Database.getInteger("SELECT MAX(messageid) + 1 FROM messenger_messages WHERE receiverid = '" + receiverID + "' LIMIT 1");
                        Database.runQuery("INSERT INTO messenger_messages(receiverid,messageid,senderid,sent,body) VALUES ('" + receiverID + "','" + messageID + "',@senderid,@sent,@body)");

                        serverMessage Message = new serverMessage(134); // "BF"
                        Message.appendWired(1);
                        pMessage.ID = messageID;
                        Message.Append(pMessage.ToString());
                        ObjectTree.Game.Users.trySendGameMessage(receiverID, Message);
                    }
                    else // Receiver is not online, no need for getting our hands on the next message ID etc
                    {
                        Database.runQuery(
                        "INSERT INTO messenger_messages(receiverid,messageid,senderid,sent,body) " +
                        "SELECT " +
                            "'" + receiverID + "'," +
                            "(MAX(messageid) + 1)," +
                            "@senderid," +
                            "@sent," +
                            "@body " +
                       "FROM messenger_messages WHERE receiverid = '" + receiverID + "' LIMIT 1");
                    }
                }
                //now = DateTime.Now;
                //Woodpecker.Core.Logging.Log("Stop: " + now.ToString("hh:mm:ss:fff"));

                Database.Close();
            }
        }