Add buddy list ..

This commit is contained in:
SilicaAndPina 2020-12-29 23:01:10 +13:00
parent f84db853fe
commit df44358ad7
9 changed files with 279 additions and 18 deletions

View file

@ -17,7 +17,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),PrivateNotes Text(1028), CharId INT, ChatViolations INT,Subscriber TEXT(3), SubscribedUntil INT, Experience INT, Tiredness INT, Hunger INT, Thirst INT, FreeMinutes INT)";
string ExtTable = "CREATE TABLE UserExt(Id INT, X INT, Y INT, LastLogin INT, Money INT, QuestPoints INT, BankBalance BIGINT, ProfilePage Text(1028),PrivateNotes 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))";
@ -33,7 +33,6 @@ namespace HISP.Server
string DeleteOnlineUsers = "DELETE FROM OnlineUsers";
try
{
@ -1412,8 +1411,9 @@ 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,'NO',0,0,1000,1000,1000, 360)";
sqlCommand.CommandText = "INSERT INTO UserExt VALUES(@id,@x,@y,@timestamp,0,0,0,'','',0,0,'NO',0,0,1000,1000,1000, 360)";
sqlCommand.Parameters.AddWithValue("@id", id);
sqlCommand.Parameters.AddWithValue("@timestamp", Convert.ToInt32(new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds()));
sqlCommand.Parameters.AddWithValue("@x", Map.NewUserStartX);
sqlCommand.Parameters.AddWithValue("@y", Map.NewUserStartY);
sqlCommand.Prepare();
@ -1722,6 +1722,7 @@ namespace HISP.Server
}
}
public static void SetPlayerMoney(int money, int id)
{
using (MySqlConnection db = new MySqlConnection(ConnectionString))
@ -2026,6 +2027,52 @@ namespace HISP.Server
}
}
public static int GetPlayerLastLogin(int userId)
{
using (MySqlConnection db = new MySqlConnection(ConnectionString))
{
db.Open();
if (CheckUserExtExists(userId))
{
MySqlCommand sqlCommand = db.CreateCommand();
sqlCommand.CommandText = "SELECT LastLogin FROM UserExt WHERE Id=@id";
sqlCommand.Parameters.AddWithValue("@id", userId);
sqlCommand.Prepare();
int lastLogin = Convert.ToInt32(sqlCommand.ExecuteScalar());
sqlCommand.Dispose();
return lastLogin;
}
else
{
throw new KeyNotFoundException("Id " + userId + " not found in database.");
}
}
}
public static void SetPlayerLastLogin(int lastlogin, int id)
{
using (MySqlConnection db = new MySqlConnection(ConnectionString))
{
db.Open();
if (CheckUserExist(id))
{
MySqlCommand sqlCommand = db.CreateCommand();
sqlCommand.CommandText = "UPDATE UserExt SET LastLogin=@lastlogin WHERE Id=@id";
sqlCommand.Parameters.AddWithValue("@lastlogin", lastlogin);
sqlCommand.Parameters.AddWithValue("@id", id);
sqlCommand.Prepare();
sqlCommand.ExecuteNonQuery();
sqlCommand.Dispose();
}
else
{
throw new KeyNotFoundException("Id " + id + " not found in database.");
}
}
}
public static int GetPlayerMoney(int userId)
{
using (MySqlConnection db = new MySqlConnection(ConnectionString))