mirror of
https://github.com/islehorse/HISP.git
synced 2025-04-19 19:29:15 +12:00
Add buddy list ..
This commit is contained in:
parent
f84db853fe
commit
df44358ad7
9 changed files with 279 additions and 18 deletions
|
@ -244,6 +244,7 @@ namespace HISP.Game
|
|||
public static string BuddyListOfflineBuddys;
|
||||
public static string BuddyListOfflineBuddyEntryFormat;
|
||||
|
||||
public static string PlayerListIconFormat;
|
||||
public static string PlayerListIconInformation;
|
||||
|
||||
// Meta
|
||||
|
@ -280,10 +281,14 @@ namespace HISP.Game
|
|||
// Click
|
||||
public static string NothingInterestingHere;
|
||||
|
||||
public static string FormatOnlineBuddyEntry(int iconId, string username, int userId, int time, int x, int y)
|
||||
public static string FormatIconFormat(int iconId)
|
||||
{
|
||||
return PlayerListIconFormat.Replace("%ICON%", iconId.ToString());
|
||||
}
|
||||
public static string FormatOnlineBuddyEntry(string iconFormat, string username, int userId, int time, int x, int y)
|
||||
{
|
||||
string xy = FormatMapLocation(x, y);
|
||||
return BuddyListOnlineBuddyEntryFormat.Replace("%ICON%", iconId.ToString()).Replace("%USERNAME%", username).Replace("%TIME%", time.ToString("N0")).Replace("%PLAYERID%", userId.ToString()).Replace("%MAPXY%", xy);
|
||||
return BuddyListOnlineBuddyEntryFormat.Replace("%ICONFORMAT%", iconFormat).Replace("%USERNAME%", username).Replace("%TIME%", time.ToString("N0")).Replace("%PLAYERID%", userId.ToString()).Replace("%MAPXY%", xy);
|
||||
}
|
||||
public static string FormatOfflineBuddyEntry(string username, int userId, int time)
|
||||
{
|
||||
|
|
|
@ -417,10 +417,52 @@ namespace HISP.Game
|
|||
try
|
||||
{
|
||||
User friend = GameServer.GetUserById(id);
|
||||
message += Messages.FormatOnlineBuddyEntry()
|
||||
int icon = -1;
|
||||
if (friend.NewPlayer)
|
||||
icon = Messages.NewUserIcon;
|
||||
if (friend.Subscribed)
|
||||
{
|
||||
int months = (DateTime.UtcNow.Month - friend.SubscribedUntil.Month) + 12 * (DateTime.UtcNow.Year - friend.SubscribedUntil.Year);
|
||||
if (months <= 1)
|
||||
icon = Messages.MonthSubscriptionIcon;
|
||||
else if (months <= 3)
|
||||
icon = Messages.ThreeMonthSubscripitionIcon;
|
||||
else
|
||||
icon = Messages.YearSubscriptionIcon;
|
||||
}
|
||||
if (friend.Moderator)
|
||||
icon = Messages.ModeratorIcon;
|
||||
if (friend.Administrator)
|
||||
icon = Messages.AdminIcon;
|
||||
|
||||
string iconFormat = "";
|
||||
if (icon != -1)
|
||||
iconFormat = Messages.FormatIconFormat(icon);
|
||||
message += Messages.FormatOnlineBuddyEntry(iconFormat, friend.Username, friend.Id, (DateTime.UtcNow - friend.LoginTime).Minutes, friend.X, friend.Y);
|
||||
|
||||
}
|
||||
catch (KeyNotFoundException) { };
|
||||
catch (KeyNotFoundException) { }
|
||||
|
||||
}
|
||||
message += Messages.BuddyListOfflineBuddys;
|
||||
|
||||
foreach(int id in user.Friends.List.ToArray())
|
||||
{
|
||||
if (GameServer.IsUserOnline(id))
|
||||
continue;
|
||||
|
||||
message += Messages.BuddyListOfflineBuddys;
|
||||
string username = Database.GetUsername(id);
|
||||
int minutes = (DateTime.UtcNow - Converters.UnixTimeStampToDateTime(Database.GetPlayerLastLogin(id))).Minutes;
|
||||
|
||||
message += Messages.FormatOfflineBuddyEntry(username, id, minutes);
|
||||
}
|
||||
|
||||
message += Messages.PlayerListIconInformation;
|
||||
message += Messages.BackToMap;
|
||||
message += Messages.MetaTerminator;
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
public static string BuildSpecialTileInfo(User user, World.SpecialTile specialTile)
|
||||
|
|
|
@ -42,16 +42,19 @@ namespace HISP.Player
|
|||
public Highscore Highscores;
|
||||
public Award Awards;
|
||||
public DateTime LoginTime;
|
||||
|
||||
public DateTime SubscribedUntil
|
||||
{
|
||||
get
|
||||
{
|
||||
return Converters.UnixTimeStampToDateTime(subscribedUntil);
|
||||
}
|
||||
}
|
||||
public int FreeMinutes
|
||||
{
|
||||
get
|
||||
{
|
||||
int freeTime = Database.GetFreeTime(Id);
|
||||
if(freeTime > 360)
|
||||
{
|
||||
Database.SetFreeTime(Id, 360);
|
||||
return 360;
|
||||
}
|
||||
return freeTime;
|
||||
}
|
||||
set
|
||||
|
|
|
@ -34,6 +34,14 @@ namespace HISP.Server
|
|||
return arr;
|
||||
}
|
||||
|
||||
public static DateTime UnixTimeStampToDateTime(double unixTimeStamp)
|
||||
{
|
||||
// Unix timestamp is seconds past epoch
|
||||
System.DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
|
||||
dtDateTime = dtDateTime.AddSeconds(unixTimeStamp).ToLocalTime();
|
||||
return dtDateTime;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -571,10 +571,11 @@ namespace HISP.Server
|
|||
|
||||
Messages.BuddyListHeader = gameData.messages.meta.player_list.online_buddy_header;
|
||||
Messages.BuddyListOnlineBuddyEntryFormat = gameData.messages.meta.player_list.online_buddy_format;
|
||||
Messages.BuddyListOfflineBuddys = gameData.messages.meta.offline_buddys;
|
||||
Messages.BuddyListOfflineBuddyEntryFormat = gameData.messages.player_list.offline_buddy_format;
|
||||
Messages.BuddyListOfflineBuddys = gameData.messages.meta.player_list.offline_buddys;
|
||||
Messages.BuddyListOfflineBuddyEntryFormat = gameData.messages.meta.player_list.offline_buddy_format;
|
||||
|
||||
Messages.PlayerListIconInformation = gameData.messages.player_list.icon_info;
|
||||
Messages.PlayerListIconFormat = gameData.messages.meta.player_list.icon_format;
|
||||
Messages.PlayerListIconInformation = gameData.messages.meta.player_list.icon_info;
|
||||
// Consume
|
||||
|
||||
Messages.ConsumeItemFormat = gameData.messages.consume.consumed_item_format;
|
||||
|
|
|
@ -194,6 +194,11 @@ namespace HISP.Server
|
|||
metaPacket = PacketBuilder.CreateMetaPacket(Meta.BuildAwardList(sender.LoggedinUser));
|
||||
sender.SendPacket(metaPacket);
|
||||
break;
|
||||
case 35:
|
||||
sender.LoggedinUser.MetaPriority = true;
|
||||
metaPacket = PacketBuilder.CreateMetaPacket(Meta.BuildBuddyList(sender.LoggedinUser));
|
||||
sender.SendPacket(metaPacket);
|
||||
break;
|
||||
default:
|
||||
Logger.ErrorPrint("Dynamic button #" + buttonId + " unknown...");
|
||||
break;
|
||||
|
@ -1899,11 +1904,14 @@ namespace HISP.Server
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
public static void OnDisconnect(GameClient sender)
|
||||
{
|
||||
connectedClients.Remove(sender);
|
||||
if (sender.LoggedIn)
|
||||
{
|
||||
Database.SetPlayerLastLogin(Convert.ToInt32(new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds()), sender.LoggedinUser.Id); // Set last login date
|
||||
|
||||
Database.RemoveOnlineUser(sender.LoggedinUser.Id);
|
||||
// Send disconnect message
|
||||
byte[] logoutMessageBytes = PacketBuilder.CreateChat(Messages.FormatLogoutMessage(sender.LoggedinUser.Username), PacketBuilder.CHAT_BOTTOM_LEFT);
|
||||
|
@ -1926,6 +1934,19 @@ namespace HISP.Server
|
|||
* Get(Some Information)
|
||||
*/
|
||||
|
||||
|
||||
public static bool IsUserOnline(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
GetUserById(id);
|
||||
return true;
|
||||
}
|
||||
catch (KeyNotFoundException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public static User[] GetUsersUsersInIsle(World.Isle isle, bool includeStealth = false, bool includeMuted = false)
|
||||
{
|
||||
List<User> usersInIsle = new List<User>();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue