From c690e3f3a45baccb44c7adf8cf200f585b3a381e Mon Sep 17 00:00:00 2001 From: SilicaAndPina Date: Mon, 28 Dec 2020 22:18:08 +1300 Subject: [PATCH] implement basic player list.. more later --- DataCollection/gamedata.json | 36 +++++++++ .../Horse Isle Server/Game/Messages.cs | 49 +++++++++++- .../Horse Isle Server/Game/Meta.cs | 19 +++++ .../Horse Isle Server/Player/Friends.cs | 4 + .../Horse Isle Server/Server/GameClient.cs | 3 + .../Horse Isle Server/Server/GameDataJson.cs | 13 ++++ .../Horse Isle Server/Server/GameServer.cs | 78 ++++++++++++++++++- .../Horse Isle Server/Server/PacketBuilder.cs | 7 +- 8 files changed, 203 insertions(+), 6 deletions(-) diff --git a/DataCollection/gamedata.json b/DataCollection/gamedata.json index 872efba..40634b0 100644 --- a/DataCollection/gamedata.json +++ b/DataCollection/gamedata.json @@ -118,6 +118,42 @@ "completed":"COMPLETED", "footer_format":"
You have completed %TOTALCOMPLETED% of %TOTALQUESTS% total adventures (%TOTALPERCENT%%)
You have earned %YOURQP%qp of %MAXQP%qp total (%QPERCENT%%)
(qp = quest points, they are a score of difficulty for each adventure)", }, + "player_list":{ + "playerlist_header":"^ATLists of Players Online^H", + "select_from_following":"Select from the following Player Lists:", + "list_of_buddies_format":"^T4List of all buddies(%AMOUNT% on):^D35|VIEW BUDDIES^R1", + "list_of_players_nearby":"^T4List of nearby players:^D36|VIEW NEARBY^R1", + "list_of_all_players_format":"^T4List of all players online(%AMOUNT% on):^D37|VIEW ALL ONLINE^R1", + "list_of_all_players_alphabetically":"^T4List of all players alphabetically:^D40|VIEW ALL ONLINE^R1", + "map_all_buddies_format":"^T4Show all of your buddies on map:^B1M%BUDDYXYLIST%^R1", + "map_all_players_format":"^T4Show all players online on map:^B1M%ALLXYLIST%^R1", + "abuse_report":"^R1^T4If you witness a rule violation:^D28c1|ABUSE REPORT^R1", + }, + "misc_stats":{ + "no_stats_recorded":"
None Yet.", + "stat_format":"%STAT% (%COUNT%)
", + "pirate_treasures":"Pirate Treasures", + "travels":"Travels", + "horse_captures":"Horse Captures", + "crafts":"Crafts", + "wishes":"Wishes", + "trainer":"Trainer", + "arena_loss":"Arena Loss", + "trades":"Trades", + "horse_leases":"Horse Leases", + "auto_sell":"Auto Sell", + "pegasus_team_up":"Pegasus Team up", + "horse_giveaway_win":"Horse Giveaway Wins", + "real_time_quiz_win":"Real Time Quiz Wins", + "real_time_riddle":"Real Time Riddles", + "real_time_isle_cards_win":"Real Time Isle Cards Win", + "sold_horse_to_pawneer":"Sold Horse To Pawneer", + "water_balloon_win":"Water Balloon Wins", + "unicorn_team_up":"Unicorn Team up", + "pot_of_gold":"Pot Of Gold", + "game_update_reset":"Game Updates / Resets", + "unipeg_team_up":"UniPeg Team up" + }, "stats_page":{ "stats_bar_format":"^ATPlayer %USERNAME%'s Details^H", "stats_area_format":"Currently %AREA%", diff --git a/Horse Isle Server/Horse Isle Server/Game/Messages.cs b/Horse Isle Server/Horse Isle Server/Game/Messages.cs index db33f4f..0707ea0 100644 --- a/Horse Isle Server/Horse Isle Server/Game/Messages.cs +++ b/Horse Isle Server/Horse Isle Server/Game/Messages.cs @@ -1,5 +1,6 @@ using HISP.Server; using System; +using System.Drawing; namespace HISP.Game { @@ -80,10 +81,12 @@ namespace HISP.Game public static string PrivateNotesMetaFormat; // Hay Pile + public static string HasPitchforkMeta; public static string NoPitchforkMeta; // Chat + public static string GlobalChatFormat; public static string AdsChatFormat; public static string BuddyChatFormat; @@ -218,6 +221,17 @@ namespace HISP.Game public static string BeatHighscoreFormat; public static string BeatBestTimeFormat; + // Player List + public static string PlayerListHeader; + public static string PlayerListSelectFromFollowing; + public static string PlayerListOfBuddiesFormat; + public static string PlayerListOfNearby; + public static string PlayerListOfPlayersFormat; + public static string PlayerListOfPlayersAlphabetically; + public static string PlayerListMapAllBuddiesForamt; + public static string PlayerListMapAllPlayersFormat; + public static string PlayerListAbuseReport; + // Meta public static string IsleFormat; @@ -567,8 +581,35 @@ namespace HISP.Game return GrabItemFormat.Replace("%ICONID%",iconid.ToString()).Replace("%ITEMNAME%", name).Replace("%RANDOMID%", randomid.ToString()); } + public static string FormatPlayerBuddyList(int amount) + { + return PlayerListOfBuddiesFormat.Replace("%AMOUNT%", amount.ToString("N0")); + } + public static string FormatPlayerList(int amount) + { + return PlayerListOfPlayersFormat.Replace("%AMOUNT%", amount.ToString("N0")); + } - public static string FormatTransportMessage(string method, string place, int cost, int id, int x, int y) + public static string FormatMapAllBuddiesList(string buddyxys) + { + return PlayerListMapAllBuddiesForamt.Replace("%BUDDYXYLIST%", buddyxys); + } + + public static string FormatMapAllPlayersList(string playerxys) + { + return PlayerListMapAllPlayersFormat.Replace("%ALLXYLIST%", playerxys); + } + + public static string FormatMapLocations(Point[] xys) + { + string allXys = ""; + foreach(Point xy in xys) + { + allXys += FormatMapLocation(xy.X, xy.Y); + } + return allXys; + } + public static string FormatMapLocation(int x, int y) { string xy = ""; xy += (char)(((x - 4) / 64) + 20); @@ -576,6 +617,12 @@ namespace HISP.Game xy += (char)(((y - 1) / 64) + 20); xy += (char)(((y - 1) % 64) + 20); + return xy; + } + + public static string FormatTransportMessage(string method, string place, int cost, int id, int x, int y) + { + string xy = FormatMapLocation(x, y); int iconId = 253; if(method == "WAGON") diff --git a/Horse Isle Server/Horse Isle Server/Game/Meta.cs b/Horse Isle Server/Horse Isle Server/Game/Meta.cs index 3b3b862..918b927 100644 --- a/Horse Isle Server/Horse Isle Server/Game/Meta.cs +++ b/Horse Isle Server/Horse Isle Server/Game/Meta.cs @@ -469,6 +469,25 @@ namespace HISP.Game return message; } + public static string BuildPlayerList(User user) + { + string message = ""; + message += Messages.PlayerListHeader; + message += Messages.PlayerListSelectFromFollowing; + message += Messages.FormatPlayerBuddyList(user.Friends.Count); + message += Messages.PlayerListOfNearby; + message += Messages.FormatPlayerList(GameServer.GetNumberOfPlayers() - 1); + message += Messages.PlayerListOfPlayersAlphabetically; + + message += Messages.FormatMapAllBuddiesList(Messages.FormatMapLocations(GameServer.GetAllBuddyLocations(user))); + message += Messages.FormatMapAllPlayersList(Messages.FormatMapLocations(GameServer.GetAllPlayerLocations(user))); + + message += Messages.PlayerListAbuseReport; + message += Messages.BackToMap; + message += Messages.MetaTerminator; + + return message; + } public static string BuildInventoryInfo(PlayerInventory inv) { string message = ""; diff --git a/Horse Isle Server/Horse Isle Server/Player/Friends.cs b/Horse Isle Server/Horse Isle Server/Player/Friends.cs index 3899be9..5c2649b 100644 --- a/Horse Isle Server/Horse Isle Server/Player/Friends.cs +++ b/Horse Isle Server/Horse Isle Server/Player/Friends.cs @@ -28,13 +28,17 @@ namespace HISP.Player } } + + public void AddFriend(User userToFriend) { bool pendingRequest = Database.IsPendingBuddyRequestExist(baseUser.Id, userToFriend.Id); if (pendingRequest) { Database.AcceptBuddyRequest(baseUser.Id, userToFriend.Id); + List.Add(userToFriend.Id); + userToFriend.Friends.List.Add(baseUser.Id); } else { diff --git a/Horse Isle Server/Horse Isle Server/Server/GameClient.cs b/Horse Isle Server/Horse Isle Server/Server/GameClient.cs index c05274d..56bb1d7 100644 --- a/Horse Isle Server/Horse Isle Server/Server/GameClient.cs +++ b/Horse Isle Server/Horse Isle Server/Server/GameClient.cs @@ -200,6 +200,9 @@ namespace HISP.Server case PacketBuilder.PACKET_MOVE: GameServer.OnMovementPacket(this, Packet); break; + case PacketBuilder.PACKET_PLAYERINFO: + GameServer.OnPlayerInfoPacket(this, Packet); + break; case PacketBuilder.PACKET_PLAYER: GameServer.OnProfilePacket(this, Packet); break; diff --git a/Horse Isle Server/Horse Isle Server/Server/GameDataJson.cs b/Horse Isle Server/Horse Isle Server/Server/GameDataJson.cs index 419120e..4ac0817 100644 --- a/Horse Isle Server/Horse Isle Server/Server/GameDataJson.cs +++ b/Horse Isle Server/Horse Isle Server/Server/GameDataJson.cs @@ -550,6 +550,19 @@ namespace HISP.Server Messages.Brought5ButInventoryFull = gameData.messages.shop.brought_5_but_inv_full; Messages.Brought25ButInventoryFull = gameData.messages.shop.brought_25_but_inv_full; + // Player List + + Messages.PlayerListHeader = gameData.messages.meta.player_list.playerlist_header; + Messages.PlayerListSelectFromFollowing = gameData.messages.meta.player_list.select_from_following; + Messages.PlayerListOfBuddiesFormat = gameData.messages.meta.player_list.list_of_buddies_format; + Messages.PlayerListOfNearby = gameData.messages.meta.player_list.list_of_players_nearby; + Messages.PlayerListOfPlayersFormat = gameData.messages.meta.player_list.list_of_all_players_format; + Messages.PlayerListOfPlayersAlphabetically = gameData.messages.meta.player_list.list_of_all_players_alphabetically; + Messages.PlayerListMapAllBuddiesForamt = gameData.messages.meta.player_list.map_all_buddies_format; + Messages.PlayerListMapAllPlayersFormat = gameData.messages.meta.player_list.map_all_players_format; + Messages.PlayerListAbuseReport = gameData.messages.meta.player_list.abuse_report; + + // Consume Messages.ConsumeItemFormat = gameData.messages.consume.consumed_item_format; diff --git a/Horse Isle Server/Horse Isle Server/Server/GameServer.cs b/Horse Isle Server/Horse Isle Server/Server/GameServer.cs index 0c7ab9f..c7528c4 100644 --- a/Horse Isle Server/Horse Isle Server/Server/GameServer.cs +++ b/Horse Isle Server/Horse Isle Server/Server/GameServer.cs @@ -10,6 +10,7 @@ using HISP.Game; using HISP.Security; using HISP.Game.Chat; using HISP.Player.Equips; +using System.Drawing; namespace HISP.Server { @@ -124,6 +125,30 @@ namespace HISP.Server } + } + + public static void OnPlayerInfoPacket(GameClient sender, byte[] packet) + { + if (!sender.LoggedIn) + { + Logger.ErrorPrint(sender.RemoteIp + " Requests player info when not logged in."); + return; + } + if(packet.Length < 3) + { + Logger.ErrorPrint(sender.LoggedinUser.Username + " Sent playerinfo packet of wrong size"); + } + + byte method = packet[1]; + switch(method) + { + case PacketBuilder.PLAYERINFO_PLAYER_LIST: + sender.LoggedinUser.MetaPriority = true; + byte[] metaPacket = PacketBuilder.CreateMetaPacket(Meta.BuildPlayerList(sender.LoggedinUser)); + sender.SendPacket(metaPacket); + break; + } + } public static void OnDynamicButtonPressed(GameClient sender, byte[] packet) { @@ -150,18 +175,22 @@ namespace HISP.Server switch(buttonId) { case 3: + sender.LoggedinUser.MetaPriority = true; byte[] metaPacket = PacketBuilder.CreateMetaPacket(Meta.BuildQuestLog(sender.LoggedinUser)); sender.SendPacket(metaPacket); break; case 21: + sender.LoggedinUser.MetaPriority = true; metaPacket = PacketBuilder.CreateMetaPacket(Meta.BuildPrivateNotes(sender.LoggedinUser)); sender.SendPacket(metaPacket); break; case 20: + sender.LoggedinUser.MetaPriority = true; metaPacket = PacketBuilder.CreateMetaPacket(Meta.BuildMinigameRankingsForUser(sender.LoggedinUser)); sender.SendPacket(metaPacket); break; case 24: + sender.LoggedinUser.MetaPriority = true; metaPacket = PacketBuilder.CreateMetaPacket(Meta.BuildAwardList(sender.LoggedinUser)); sender.SendPacket(metaPacket); break; @@ -576,15 +605,17 @@ namespace HISP.Server return; } } - else if (method == PacketBuilder.PLAYERINFO_HIGHSCORES_LIST) + else if (method == PacketBuilder.PROFILE_HIGHSCORES_LIST) { + sender.LoggedinUser.MetaPriority = true; string packetStr = Encoding.UTF8.GetString(packet); string gameName = packetStr.Substring(2, packetStr.Length - 4); byte[] metaTag = PacketBuilder.CreateMetaPacket(Meta.BuildTopHighscores(gameName)); sender.SendPacket(metaTag); } - else if (method == PacketBuilder.PLAYERINFO_BESTTIMES_LIST) + else if (method == PacketBuilder.PROFILE_BESTTIMES_LIST) { + sender.LoggedinUser.MetaPriority = true; string packetStr = Encoding.UTF8.GetString(packet); string gameName = packetStr.Substring(2, packetStr.Length - 4); byte[] metaTag = PacketBuilder.CreateMetaPacket(Meta.BuildTopTimes(gameName)); @@ -1977,6 +2008,49 @@ namespace HISP.Server return count; } + public static Point[] GetAllBuddyLocations(User caller) + { + List allLocations = new List(); + + foreach (GameClient client in ConnectedClients) + { + if (client.LoggedIn) + { + + if (!caller.Friends.List.Contains(client.LoggedinUser.Id)) + continue; + + + if (!client.LoggedinUser.Stealth) + allLocations.Add(new Point(client.LoggedinUser.X, client.LoggedinUser.Y)); + + } + } + + return allLocations.ToArray(); + } + + public static Point[] GetAllPlayerLocations(User caller) + { + List allLocations = new List(); + + foreach (GameClient client in ConnectedClients) + { + if (client.LoggedIn) + { + + if (client.LoggedinUser.Id == caller.Id) + continue; + + if (!client.LoggedinUser.Stealth) + allLocations.Add(new Point(client.LoggedinUser.X, client.LoggedinUser.Y)); + + } + + + } + return allLocations.ToArray(); + } public static int GetNumberOfPlayersListeningToAdsChat() { int count = 0; diff --git a/Horse Isle Server/Horse Isle Server/Server/PacketBuilder.cs b/Horse Isle Server/Horse Isle Server/Server/PacketBuilder.cs index 5be7100..15a67be 100644 --- a/Horse Isle Server/Horse Isle Server/Server/PacketBuilder.cs +++ b/Horse Isle Server/Horse Isle Server/Server/PacketBuilder.cs @@ -29,7 +29,6 @@ namespace HISP.Server public const byte PACKET_KEEP_ALIVE = 0x7C; public const byte PACKET_DYNAMIC_BUTTON = 0x45; public const byte PACKET_DYNAMIC_INPUT = 0x46; - public const byte PACKET_PLAYER = 0x18; public const byte PACKET_INVENTORY = 0x17; public const byte PACKET_TRANSPORT = 0x29; @@ -53,8 +52,10 @@ namespace HISP.Server public const byte PLAYERINFO_LEAVE = 0x16; public const byte PLAYERINFO_UPDATE_OR_CREATE = 0x15; - public const byte PLAYERINFO_HIGHSCORES_LIST = 0x51; - public const byte PLAYERINFO_BESTTIMES_LIST = 0x52; + public const byte PLAYERINFO_PLAYER_LIST = 0x14; + + public const byte PROFILE_HIGHSCORES_LIST = 0x51; + public const byte PROFILE_BESTTIMES_LIST = 0x52; public const byte VIEW_PROFILE = 0x14; public const byte SAVE_PROFILE = 0x15;