Add distinciton between subscribed and non subscribed users.

This commit is contained in:
SilicaAndPina 2020-12-22 12:54:59 +13:00
parent 7ed2389152
commit 1ed964aacf
4 changed files with 101 additions and 8 deletions

View file

@ -76,6 +76,25 @@
"end_of_meta":"^Z",
"back_to_map":"^M",
"long_full_line":"^L",
"stats_page":{
"stats_bar_format":"^ATPlayer %USERNAME%'s Details^H",
"stats_area_format":"Currently in %AREA%",
"stats_money_format":"<BR>Money: <FONT COLOR='#003300'>$%MONEY%</FONT>",
"stats_freetime_format":"<BR>Today's Free Time Remaining: <B>%FREEMINUTES% minutes.</B>",
"stats_description_format":"<BR>Description: <B>%PLAYERDESC%</B>",
"stats_experience":"<BR>^HExperience: <B>%EXPERIENCE%</B>",
"stats_questpoints":"<BR>Quest Points: <B>%QUESTPOINTS%</B>",
"stats_hunger":"<BR>Hunger: <B>%HUNGER%</B>",
"stats_thisrt":"<BR>Thirst: <B>%THIRST%</B>",
"stats_tiredness":"<BR>Tiredness: <B>%TIRED%</B>",
"stats_gender":"<BR>Gender: <B>%GENDER%</B>",
"stats_equipped":"<BR>%JEWELFORMAT%",
"stats_competion_gear":"<BR>%GEARFORMAT%"
"msg":{
"no_jewelry_equipped":"You have no Jewelry on.",
"no_competition_gear":"^LYou have nothing interesting for special competition gear.",
}
},
"shop":{
"selling":"^LThings I am selling:",
"sell_me":"^LThings you can SELL to me:",

View file

@ -35,6 +35,25 @@ namespace HISP.Player
public Npc.NpcEntry LastTalkedToNpc;
public Shop LastShoppedAt;
public PlayerQuests Quests;
public bool Subscribed
{
get
{
int Timestamp = Convert.ToInt32(new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds());
if(Timestamp > subscribedUntil) // sub expired.
{
Logger.InfoPrint(Username + "'s Subscription expired. (timestamp now: " + Timestamp + " exp date: " + subscribedUntil+" )");
Database.SetUserSubscriptionStatus(this.Id, false);
subscribed = false;
}
return subscribed;
}
set
{
Database.SetUserSubscriptionStatus(this.Id, value);
}
}
public bool Stealth
{
get
@ -46,7 +65,7 @@ namespace HISP.Player
if (value)
Database.RemoveOnlineUser(this.Id);
else
Database.AddOnlineUser(this.Id, this.Administrator, this.Moderator);
Database.AddOnlineUser(this.Id, this.Administrator, this.Moderator, this.Subscribed);
stealth = value;
}
@ -156,6 +175,8 @@ namespace HISP.Player
private int chatViolations;
private int charId;
private int subscribedUntil;
private bool subscribed;
private string profilePage;
private int x;
private bool stealth = false;
@ -225,7 +246,8 @@ namespace HISP.Player
money = Database.GetPlayerMoney(UserId);
bankMoney = Database.GetPlayerBankMoney(UserId);
questPoints = Database.GetPlayerQuestPoints(UserId);
subscribed = Database.IsUserSubscribed(UserId);
subscribedUntil = Database.GetUserSubscriptionExpireDate(UserId);
profilePage = Database.GetPlayerProfile(UserId);
MailBox = new Mailbox(this);

View file

@ -16,7 +16,7 @@ namespace HISP.Server
{
db.Open();
string UserTable = "CREATE TABLE Users(Id INT, Username TEXT(16),Email TEXT(128),Country TEXT(128),SecurityQuestion Text(128),SecurityAnswerHash TEXT(128),Age INT,PassHash TEXT(128), Salt TEXT(128),Gender TEXT(16), Admin TEXT(3), Moderator TEXT(3))";
string ExtTable = "CREATE TABLE UserExt(Id INT, X INT, Y INT, Money INT, QuestPoints INT, BankBalance BIGINT,ProfilePage Text(1028), CharId INT, ChatViolations INT)";
string ExtTable = "CREATE TABLE UserExt(Id INT, X INT, Y INT, Money INT, QuestPoints INT, BankBalance BIGINT,ProfilePage Text(1028), CharId INT, ChatViolations INT,Subscriber TEXT(3), SubscribedUntil INT, Experience INT, Tiredness INT, Hunger INT, Thirst INT, FreeMinutes INT)";
string MailTable = "CREATE TABLE Mailbox(IdTo INT, PlayerFrom TEXT(16),Subject TEXT(128), Message Text(1028), TimeSent INT)";
string BuddyTable = "CREATE TABLE BuddyList(Id INT, IdFriend INT, Pending BOOL)";
string WorldTable = "CREATE TABLE World(Time INT,Day INT, Year INT, Weather TEXT(64))";
@ -24,7 +24,7 @@ namespace HISP.Server
string ShopInventory = "CREATE TABLE ShopInventory(ShopID INT, RandomID INT, ItemID INT)";
string DroppedItems = "CREATE TABLE DroppedItems(X INT, Y INT, RandomID INT, ItemID INT, DespawnTimer INT)";
string TrackedQuest = "CREATE TABLE TrackedQuest(playerId INT, questId INT, timesCompleted INT)";
string OnlineUsers = "CREATE TABLE OnlineUsers(playerId INT, Admin TEXT(3), Moderator TEXT(3))";
string OnlineUsers = "CREATE TABLE OnlineUsers(playerId INT, Admin TEXT(3), Moderator TEXT(3), Subscribed TEXT(3))";
string DeleteOnlineUsers = "DELETE FROM OnlineUsers";
@ -389,6 +389,56 @@ namespace HISP.Server
}
}
public static bool SetUserSubscriptionStatus(int playerId, bool subscribed)
{
using (MySqlConnection db = new MySqlConnection(ConnectionString))
{
db.Open();
MySqlCommand sqlCommand = db.CreateCommand();
sqlCommand.CommandText = "UPDATE userExt SET Subscriber=@subscribed WHERE Id=@playerId";
sqlCommand.Parameters.AddWithValue("@subscribed", subscribed ? "YES" : "NO");
sqlCommand.Parameters.AddWithValue("@playerId", playerId);
sqlCommand.Prepare();
sqlCommand.ExecuteNonQuery();
sqlCommand.Dispose();
return subscribed;
}
}
public static int GetUserSubscriptionExpireDate(int playerId)
{
using (MySqlConnection db = new MySqlConnection(ConnectionString))
{
db.Open();
MySqlCommand sqlCommand = db.CreateCommand();
sqlCommand.CommandText = "SELECT SubscribedUntil FROM userExt WHERE Id=@playerId";
sqlCommand.Parameters.AddWithValue("@playerId", playerId);
sqlCommand.Prepare();
int subscribedUntil = Convert.ToInt32(sqlCommand.ExecuteScalar());
sqlCommand.Dispose();
return subscribedUntil;
}
}
public static bool IsUserSubscribed(int playerId)
{
using (MySqlConnection db = new MySqlConnection(ConnectionString))
{
db.Open();
MySqlCommand sqlCommand = db.CreateCommand();
sqlCommand.CommandText = "SELECT Subscriber FROM userExt WHERE Id=@playerId";
sqlCommand.Parameters.AddWithValue("@playerId", playerId);
sqlCommand.Prepare();
bool subscribed = (string)(sqlCommand.ExecuteScalar()) == "YES";
sqlCommand.Dispose();
return subscribed;
}
}
public static void AddNewTrackedQuest(int playerId, int questId, int timesCompleted)
{
using (MySqlConnection db = new MySqlConnection(ConnectionString))
@ -405,17 +455,18 @@ namespace HISP.Server
sqlCommand.Dispose();
}
}
public static void AddOnlineUser(int playerId, bool Admin, bool Moderator)
public static void AddOnlineUser(int playerId, bool Admin, bool Moderator, bool Subscribed)
{
using (MySqlConnection db = new MySqlConnection(ConnectionString))
{
db.Open();
MySqlCommand sqlCommand = db.CreateCommand();
sqlCommand.CommandText = "INSERT INTO OnlineUsers VALUES(@playerId, @admin, @moderator)";
sqlCommand.CommandText = "INSERT INTO OnlineUsers VALUES(@playerId, @admin, @moderator, @subscribed)";
sqlCommand.Parameters.AddWithValue("@playerId", playerId);
sqlCommand.Parameters.AddWithValue("@admin", Admin ? "YES" : "NO");
sqlCommand.Parameters.AddWithValue("@moderator", Moderator ? "YES" : "NO");
sqlCommand.Parameters.AddWithValue("@subscribed", Subscribed ? "YES" : "NO");
sqlCommand.Prepare();
sqlCommand.ExecuteNonQuery();
sqlCommand.Dispose();
@ -842,7 +893,7 @@ namespace HISP.Server
throw new Exception("Userid " + id + " Allready in userext.");
MySqlCommand sqlCommand = db.CreateCommand();
sqlCommand.CommandText = "INSERT INTO UserExt VALUES(@id,@x,@y,0,0,0,'',0,0)";
sqlCommand.CommandText = "INSERT INTO UserExt VALUES(@id,@x,@y,0,0,0,'',0,0,'NO',0,0,1000,1000,1000, 360)";
sqlCommand.Parameters.AddWithValue("@id", id);
sqlCommand.Parameters.AddWithValue("@x", Map.NewUserStartX);
sqlCommand.Parameters.AddWithValue("@y", Map.NewUserStartY);

View file

@ -65,7 +65,8 @@ namespace HISP.Server
Logger.ErrorPrint(sender.RemoteIp + " Requested user information when not logged in.");
return;
}
Database.AddOnlineUser(sender.LoggedinUser.Id, sender.LoggedinUser.Administrator, sender.LoggedinUser.Moderator);
Database.AddOnlineUser(sender.LoggedinUser.Id, sender.LoggedinUser.Administrator, sender.LoggedinUser.Moderator, sender.LoggedinUser.Subscribed);
Logger.DebugPrint(sender.LoggedinUser.Username + " Requested user information.");
User user = sender.LoggedinUser;