Esempio n. 1
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];
        }
Esempio n. 2
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;
        }
Esempio n. 3
0
        public userInformation getUserInfo(int userID, bool forceRefresh)
        {
            if (!forceRefresh && _userSessions.ContainsKey(userID)) // Why load it? :)
                return _userSessions[userID].User;

            userInformation returnInfo = new userInformation();
            Database Database = new Database(false, true);
            Database.addParameterWithValue("userid", userID);
            Database.Open();

            if (Database.Ready)
            {
                try
                {
                    DataRow dRow = Database.getRow("SELECT username,password,role,figure,sex,motto,motto_messenger,credits,tickets,film,currentbadge,lastactivity,club_daysleft,club_monthsleft,club_monthsexpired,club_lastupdate,email,dob FROM users WHERE id = @userid");
                    returnInfo.ID = userID;
                    returnInfo.Username = (string)dRow["username"];
                    returnInfo.Password = (string)dRow["password"];
                    returnInfo.Role = (userRole)(int.Parse(dRow["role"].ToString()));
                    returnInfo.Figure = (string)dRow["figure"];
                    returnInfo.Sex = Convert.ToChar(dRow["sex"].ToString());
                    returnInfo.Motto = (string)dRow["motto"];
                    returnInfo.messengerMotto = (string)dRow["motto_messenger"];
                    returnInfo.Credits = (int)dRow["credits"];
                    returnInfo.Tickets = (int)dRow["tickets"];
                    returnInfo.Film = (int)dRow["film"];
                    returnInfo.Badge = (string)dRow["currentbadge"];
                    returnInfo.lastActivity = (DateTime)dRow["lastactivity"];
                    returnInfo.Email = (string)dRow["email"];
                    returnInfo.DateOfBirth = (string)dRow["dob"];
                    returnInfo.clubDaysLeft = (int)dRow["club_daysleft"];
                    returnInfo.clubMonthsLeft = (int)dRow["club_monthsleft"];
                    returnInfo.clubMonthsExpired = (int)dRow["club_monthsexpired"];
                    returnInfo.clubLastUpdate = (DateTime)dRow["club_lastupdate"];
                }
                catch { returnInfo = null; }
            }

            return returnInfo;
        }
Esempio n. 4
0
        public basicUserInformation getBasicUserInfo(int userID)
        {
            basicUserInformation returnInfo = new basicUserInformation();
            Database Database = new Database(false, true);
            Database.addParameterWithValue("userid", userID);
            Database.Open();
            if (Database.Ready)
            {
                try
                {
                    DataRow dRow = Database.getRow("SELECT username,figure,sex,motto,motto_messenger,lastactivity FROM users WHERE id = @userid");
                    returnInfo.ID = userID;
                    returnInfo.Username = (string)dRow["username"];
                    returnInfo.Figure = (string)dRow["figure"];
                    returnInfo.Sex = Convert.ToChar(dRow["sex"].ToString());
                    returnInfo.Motto = (string)dRow["motto"];
                    returnInfo.messengerMotto = (string)dRow["motto_messenger"];
                    returnInfo.lastActivity = (DateTime)dRow["lastactivity"];
                }
                catch { returnInfo = new basicUserInformation(); }
            }

            return returnInfo;
        }
Esempio n. 5
0
        public userAccessInformation getLastAccess(int userID)
        {
            if (_userSessions.ContainsKey(userID))
                return _userSessions[userID].Access;

            Database dbClient = new Database(false, true);
            dbClient.addParameterWithValue("userid", userID);

            dbClient.Open();
            if (dbClient.Ready)
                return userAccessInformation.Parse(dbClient.getRow("SELECT * FROM users_access WHERE userid = @userid ORDER BY moment DESC LIMIT 1"));
            else
                return null;
        }
Esempio n. 6
0
        /// <summary>
        /// Tries to redeem a credit/item voucher for a user session.
        /// </summary>
        /// <param name="Session">The Woodpecker.Sessions.Session object to redeem the voucher with.</param>
        /// <param name="Code">The vouchercode the user entered.</param>
        public void redeemVoucher(ref Session Session, string Code)
        {
            serverMessage Response = new serverMessage();
            Database Database = new Database(false, false);
            Database.addParameterWithValue("code", Code);

            Database.Open();
            if (Database.Ready)
            {
                DataRow dRow = Database.getRow("SELECT type,value FROM users_vouchers WHERE code = @code AND ISNULL(redeemer_userid)");
                if (dRow != null) // Voucher found
                {
                    // Mark voucher as redeemed
                    Database.addParameterWithValue("userid", Session.User.ID);
                    Database.runQuery("UPDATE users_vouchers SET redeemer_userid = @userid WHERE code = @code");
                    Database.Close();

                    string Type = (string)dRow["type"];
                    if (Type == "credits")
                    {
                        int Credits = int.Parse(dRow["value"].ToString());
                        Session.User.Credits += Credits;
                        Session.User.updateValueables();
                        this.logTransaction(Session.User.ID, "win_voucher", Credits);

                        Session.refreshCredits();
                    }
                    else if (Type == "item")
                    {
                        string[] Items = ((string)dRow["value"]).Split(';');

                    }

                    // Success!
                    Response.Initialize(212); // "CT"
                    Session.gameConnection.sendMessage(Response);
                    return;
                }
                else
                {
                    // Error 1! (not found)
                    Response.Initialize(213); // "CU"
                    Response.Append(1);
                }
                Session.gameConnection.sendMessage(Response);
            }
        }
Esempio n. 7
0
        public void openPresent(int presentID, int userID)
        {
            Database dbClient = new Database(false, true);
            dbClient.addParameterWithValue("presentid", presentID);

            dbClient.Open();
            if (dbClient.Ready)
            {
                DataRow dRow = dbClient.getRow(
                    "SELECT salecode,customdata FROM items_presents WHERE presentid = @presentid LIMIT 1;" +
                    "DELETE FROM items_presents WHERE presentid = @presentid LIMIT 1;");
                if (dRow != null) // Present found
                {
                    string saleCode = (string)dRow["salecode"];
                    string customData = null;
                    if(dRow["customdata"] != DBNull.Value)
                        customData = (string)dRow["customdata"];

                    requestSaleShipping(userID, saleCode, false, false, null, customData);
                }
            }
        }
Esempio n. 8
0
 /// <summary>
 /// Refreshes the user amounts for this category if needed.
 /// </summary>
 public void refreshUserCounts()
 {
     if (this.lastUserCountUpdate.AddSeconds(1) < DateTime.Now)
     {
         Database dbClient = new Database(true, true);
         if (dbClient.Ready)
         {
             DataRow dRow = dbClient.getRow("SELECT SUM(visitors_now) AS now,SUM(visitors_max) AS max FROM rooms WHERE category = '" + this.ID + "' ORDER BY visitors_now DESC LIMIT 40");
             if (dRow["now"] != DBNull.Value) // Results
             {
                 this.currentVisitors = int.Parse(dRow["now"].ToString());
                 this.maxVisitors = int.Parse(dRow["max"].ToString());
             }
             else
                 this.maxVisitors = 1;
             this.lastUserCountUpdate = DateTime.Now;
         }
     }
 }
Esempio n. 9
0
        /// <summary>
        /// Returns the messengerBuddy object of a user.
        /// </summary>
        /// <param name="userID">The database ID of the user to get the messengerBuddy object of.</param>
        public messengerBuddy getBuddy(int userID)
        {
            Database Database = new Database(false, true);
            Database.addParameterWithValue("userid", userID);
            Database.Open();
            DataRow dRow = Database.getRow("SELECT id,username,figure,sex,motto_messenger,lastactivity FROM users WHERE id = @userid");

            return messengerBuddy.Parse(dRow);
        }