using System;
using System.Data;
using System.Collections.Generic;
using Woodpecker.Storage;
using Woodpecker.Specialized.Text;
using Woodpecker.Game.Users.Roles;
namespace Woodpecker.Game.Users
{
///
/// Contains detailed information about a user. This class extends basicUserInformation.
///
public sealed class userInformation : basicUserInformation
{
#region Fields
///
/// The ID of the session this user is currently using.
///
public uint sessionID;
///
/// The role/rank of this user as a value of the Woodpecker.Game.Users.userRole enum.
///
public userRole Role;
///
/// The amount of credits that this user currently has.
///
public int Credits;
///
/// The amount of tickets that this user currently has.
///
public int Tickets;
///
/// The amount of film for the camera that this user currently has.
///
public int Film;
///
/// The current badge of this user. If blank, then no badge is used.
///
public string Badge;
#region Habbo Club (credits to Joeh for the 'work out days' method)
///
/// The amount of pending Habbo Club days.
///
public int clubDaysLeft;
///
/// The amount of pending Habbo Club months.
///
public int clubMonthsLeft;
///
/// The amount of expired Habbo Club months.
///
public int clubMonthsExpired;
///
/// A DateTime object representing the last time the club days etc were worked out.
///
public DateTime clubLastUpdate;
///
/// True if the user has atleast one club day left.
///
public bool hasClub
{
get { return this.clubDaysLeft > 0; }
}
///
/// True if the user has atleast 11 months of Habbo Club.
///
public bool hasGoldClub
{
get { return this.clubMonthsExpired >= 11; }
}
#endregion
///
/// The email address of this user.
///
public string Email;
///
/// The date of birth this user filled in during registration.
///
public string DateOfBirth;
///
/// A hashed copy of the password the user filled in during registration.
///
public string Password;
///
/// The SSO ticket assigned to the account upon opening the client.
///
public string SSO;
#endregion
#region Methods
///
/// Returns a boolean indicating if this user has access to a certain FUSE right.
///
/// The FUSE right to check.
public bool hasFuseRight(string Right)
{
return Engine.Game.Roles.roleHasRight(this.Role, this.hasClub, Right);
}
///
/// Creates the user details string for use with message 5. ('@E')
///
public override string ToString()
{
fuseStringBuilder FSB = new fuseStringBuilder();
FSB.appendClosedValue(this.sessionID.ToString());
FSB.appendClosedValue(this.Username);
FSB.appendClosedValue(this.Figure);
FSB.appendClosedValue(this.Sex.ToString());
FSB.appendClosedValue(this.Motto);
FSB.appendWired(this.Tickets);
FSB.appendClosedValue(null); // Pool figure
FSB.appendWired(this.Film);
return FSB.ToString();
}
///
/// Updates the 'users' table with all information from this userInformation object.
///
public void fUpdate()
{
Database Database = new Database(false, true);
Database.addParameterWithValue("userid", this.ID);
Database.addParameterWithValue("password", this.Password);
Database.addParameterWithValue("role", ((int)this.Role).ToString());
Database.addParameterWithValue("figure", this.Figure);
Database.addParameterWithValue("sex", this.Sex);
Database.addParameterWithValue("motto", this.Motto);
Database.addParameterWithValue("credits", this.Credits);
Database.addParameterWithValue("tickets", this.Tickets);
Database.addParameterWithValue("film", this.Film);
Database.addParameterWithValue("email", this.Email);
Database.Open();
if (Database.Ready)
{
Database.runQuery("UPDATE users SET password = @password,role = @role,figure = @figure,sex = @sex,motto = @motto,credits = @credits,tickets = @tickets,film = @film,email = @email WHERE id = @userid");
}
}
///
/// Updates credits/tickets/film of the user into the database.
///
public void updateValueables()
{
Database Database = new Database(false, true);
Database.addParameterWithValue("userid", this.ID);
Database.addParameterWithValue("credits", this.Credits);
Database.addParameterWithValue("tickets", this.Tickets);
Database.addParameterWithValue("film", this.Film);
Database.Open();
if (Database.Ready)
{
Database.runQuery("UPDATE users SET credits = @credits,tickets = @tickets,film = @film WHERE id = @userid");
}
}
///
/// Updates the appearance details (figure, sex, motto, messenger motto and current badge) of this user in the database.
///
public void updateAppearanceDetails()
{
Database Database = new Database(false, true);
Database.addParameterWithValue("userid", this.ID);
Database.addParameterWithValue("figure", this.Figure);
Database.addParameterWithValue("sex", this.Sex.ToString());
Database.addParameterWithValue("motto", this.Motto);
Database.addParameterWithValue("motto_messenger", messengerMotto);
Database.addParameterWithValue("currentbadge", this.Badge);
Database.Open();
if (Database.Ready)
{
Database.runQuery("UPDATE users SET figure = @figure,sex = @sex,motto = @motto,motto_messenger = @motto_messenger,currentbadge = @currentbadge WHERE id = @userid");
}
}
///
/// Updates the personal details (password and email address) of this user in the database.
///
public void updatePersonalDetails()
{
Database Database = new Database(false, true);
Database.addParameterWithValue("userid", this.ID);
Database.addParameterWithValue("password", this.Password);
Database.addParameterWithValue("email", this.Email);
Database.Open();
if (Database.Ready)
{
Database.runQuery("UPDATE users SET password = @password,email = @email WHERE id = @userid");
}
}
///
/// Works out the remaining club days, months etc.
///
public void updateClub(bool forceUpdate)
{
if (this.hasClub && (forceUpdate || this.clubLastUpdate < DateTime.Now.AddDays(-1))) // User is still saved as club, and the last check hasn't been done today
{
#region Update months/days etc
TimeSpan ts = DateTime.Now.Subtract(this.clubLastUpdate);
for (int i = 1; i <= ts.Days; i++)
{
this.clubDaysLeft--;
if (this.clubDaysLeft <= 0) // Current month expired
{
this.clubDaysLeft = 0;
this.clubMonthsExpired++;
if (this.clubMonthsLeft > 0) // Next month on stack
{
this.clubMonthsLeft--;
this.clubDaysLeft = 31;
// Purchase club present
}
}
}
if (this.clubDaysLeft == 0) // Club expired
this.Figure = Core.Configuration.getConfigurationValue("users.figure.default"); // Reset default figure
this.clubLastUpdate = DateTime.Now;
Database Database = new Database(false, true);
Database.addParameterWithValue("userid", this.ID);
Database.addParameterWithValue("figure", this.Figure);
Database.addParameterWithValue("club_daysleft", this.clubDaysLeft);
Database.addParameterWithValue("club_monthsleft", this.clubMonthsLeft);
Database.addParameterWithValue("club_monthsexpired", this.clubMonthsExpired);
Database.addParameterWithValue("club_lastupdate", this.clubLastUpdate);
Database.Open();
if (Database.Ready)
Database.runQuery("UPDATE users SET figure = @figure,club_daysleft = @club_daysleft,club_monthsleft = @club_monthsleft,club_monthsexpired = @club_monthsexpired,club_lastupdate = @club_lastupdate WHERE id = @userid LIMIT 1");
#endregion
}
}
#endregion
}
}