From 09a0fce73d635c1a1c5ddaa39021f3a7287c8a88 Mon Sep 17 00:00:00 2001 From: SilicaAndPina Date: Wed, 21 Oct 2020 14:13:30 +1300 Subject: [PATCH] Uwu --- DataCollection/gamedata.json | 3 +++ Horse Isle Server/Horse Isle Server/Client.cs | 3 +++ .../Horse Isle Server/Gamedata.cs | 10 +++++++--- .../Horse Isle Server.csproj | 1 + .../Horse Isle Server/Messages.cs | 9 ++++++++- Horse Isle Server/Horse Isle Server/Meta.cs | 8 ++++++++ .../Horse Isle Server/PacketBuilder.cs | 3 ++- Horse Isle Server/Horse Isle Server/Server.cs | 19 ++++++++++++++++++- Horse Isle Server/Horse Isle Server/User.cs | 3 +++ 9 files changed, 53 insertions(+), 6 deletions(-) diff --git a/DataCollection/gamedata.json b/DataCollection/gamedata.json index 0da8c14..09b39ed 100644 --- a/DataCollection/gamedata.json +++ b/DataCollection/gamedata.json @@ -38,6 +38,8 @@ "transport_format":"^LTransport via %METHOD% to %PLACE%^R1^I%ICON%^T4Trip Costs $%COST% one way. ^B1M%XY%^BY%ID%", "exit_this_place":"^X", "end_of_meta":"^Z", + "back_to_map":"^M", + "inventory_format":"^ATYour Inventory^HYou are carrying the following %ITEMCOUNT% different items: (%MAXITEMS% max)", "nearby":{ "players_nearby":"Players Nearby:", "east":"East:", @@ -494,6 +496,7 @@ } }, "item":{ + "max_carryable":40, "item_list":[ { "id": 1, diff --git a/Horse Isle Server/Horse Isle Server/Client.cs b/Horse Isle Server/Horse Isle Server/Client.cs index ef629f7..969e781 100644 --- a/Horse Isle Server/Horse Isle Server/Client.cs +++ b/Horse Isle Server/Horse Isle Server/Client.cs @@ -158,6 +158,9 @@ namespace Horse_Isle_Server case PacketBuilder.PACKET_TRANSPORT: Server.OnTransportUsed(this, Packet); break; + case PacketBuilder.PACKET_INVENTORY: + Server.OnInventoryRequested(this, Packet); + break; default: Logger.ErrorPrint("Unimplemented Packet: " + BitConverter.ToString(Packet).Replace('-', ' ')); break; diff --git a/Horse Isle Server/Horse Isle Server/Gamedata.cs b/Horse Isle Server/Horse Isle Server/Gamedata.cs index 6ae92fc..f86c829 100644 --- a/Horse Isle Server/Horse Isle Server/Gamedata.cs +++ b/Horse Isle Server/Horse Isle Server/Gamedata.cs @@ -4,9 +4,6 @@ using Newtonsoft.Json; namespace Horse_Isle_Server { - - - class Gamedata { @@ -235,6 +232,7 @@ namespace Horse_Isle_Server Messages.DirectChatFormatForSender = gameData.messages.chat.for_sender.dm_format; Messages.ModChatFormatForSender = gameData.messages.chat.for_sender.mod_format; Messages.AdminChatFormatForSender = gameData.messages.chat.for_sender.admin_format; + Messages.PasswordNotice = gameData.messages.chat.password_included; Messages.CapsNotice = gameData.messages.chat.caps_notice; @@ -248,8 +246,10 @@ namespace Horse_Isle_Server Messages.Seperator = gameData.messages.meta.seperator; Messages.TileFormat = gameData.messages.meta.tile_format; Messages.TransportFormat = gameData.messages.meta.transport_format; + Messages.InventoryFormat = gameData.messages.meta.inventory_format; Messages.NothingMessage = gameData.messages.meta.nothing_message; Messages.ExitThisPlace = gameData.messages.meta.exit_this_place; + Messages.BackToMap = gameData.messages.meta.back_to_map; Messages.MetaTerminator = gameData.messages.meta.end_of_meta; Messages.NearbyPlayers = gameData.messages.meta.nearby.players_nearby; @@ -284,6 +284,10 @@ namespace Horse_Isle_Server Server.IdleWarning = gameData.messages.disconnect.client_timeout.warn_after; Server.IdleTimeout = gameData.messages.disconnect.client_timeout.kick_after; + // Inventory + + Inventory.DefaultInventoryMax = gameData.item.max_carryable; + // Swf Messages.WagonCutscene = gameData.transport.wagon_cutscene; Messages.BoatCutscene = gameData.transport.boat_cutscene; diff --git a/Horse Isle Server/Horse Isle Server/Horse Isle Server.csproj b/Horse Isle Server/Horse Isle Server/Horse Isle Server.csproj index 88025c2..480d351 100644 --- a/Horse Isle Server/Horse Isle Server/Horse Isle Server.csproj +++ b/Horse Isle Server/Horse Isle Server/Horse Isle Server.csproj @@ -79,6 +79,7 @@ + diff --git a/Horse Isle Server/Horse Isle Server/Messages.cs b/Horse Isle Server/Horse Isle Server/Messages.cs index 9d3eb3f..480e188 100644 --- a/Horse Isle Server/Horse Isle Server/Messages.cs +++ b/Horse Isle Server/Horse Isle Server/Messages.cs @@ -41,8 +41,8 @@ namespace Horse_Isle_Server public static string AdminChatFormatForSender; public static string ModChatFormatForSender; - public static string ChatViolationMessageFormat; public static int RequiredChatViolations; + public static string ChatViolationMessageFormat; public static string PasswordNotice; public static string CapsNotice; @@ -62,7 +62,10 @@ namespace Horse_Isle_Server public static string TileFormat; public static string NothingMessage; public static string Seperator; + public static string InventoryFormat; + public static string ExitThisPlace; + public static string BackToMap; public static string MetaTerminator; // Disconnect Messages @@ -79,6 +82,10 @@ namespace Horse_Isle_Server return ChatViolationMessageFormat.Replace("%AMOUNT%", RequiredChatViolations.ToString()).Replace("%REASON%", violationReason.Message); } + public static string FormatInventoryMeta(int itemCount, int maxItems) + { + return InventoryFormat.Replace("%ITEMCOUNT%", itemCount.ToString()).Replace("%MAXITEMS%", maxItems.ToString()); + } // Meta public static string FormatTransportMessage(string method, string place, int cost, int id, int x, int y) { diff --git a/Horse Isle Server/Horse Isle Server/Meta.cs b/Horse Isle Server/Horse Isle Server/Meta.cs index bc870b8..85a20d2 100644 --- a/Horse Isle Server/Horse Isle Server/Meta.cs +++ b/Horse Isle Server/Horse Isle Server/Meta.cs @@ -125,6 +125,14 @@ namespace Horse_Isle_Server return message; } + + public static string BuildInventoryInfo(Inventory inv) + { + string message = ""; + message += Messages.FormatInventoryMeta(inv.ItemList.Count, inv.MaxItems); + + return message; + } public static string BuildMetaInfo(int x, int y) { string message = ""; diff --git a/Horse Isle Server/Horse Isle Server/PacketBuilder.cs b/Horse Isle Server/Horse Isle Server/PacketBuilder.cs index da2615c..7714e74 100644 --- a/Horse Isle Server/Horse Isle Server/PacketBuilder.cs +++ b/Horse Isle Server/Horse Isle Server/PacketBuilder.cs @@ -26,6 +26,7 @@ namespace Horse_Isle_Server public const byte PACKET_PLAYSOUND = 0x23; public const byte PACKET_KEEP_ALIVE = 0x7C; public const byte PACKET_PROFILE = 0x18; + public const byte PACKET_INVENTORY = 0x17; public const byte PACKET_TRANSPORT = 0x29; public const byte PACKET_KICK = 0x80; public const byte PACKET_LEAVE = 0x7D; @@ -329,7 +330,7 @@ namespace Horse_Isle_Server return Packet; } - public static byte[] CreatePlaceInfo(string formattedText) + public static byte[] CreateMetaPacket(string formattedText) { byte[] strBytes = Encoding.UTF8.GetBytes(formattedText); diff --git a/Horse Isle Server/Horse Isle Server/Server.cs b/Horse Isle Server/Horse Isle Server/Server.cs index cdb3135..24be539 100644 --- a/Horse Isle Server/Horse Isle Server/Server.cs +++ b/Horse Isle Server/Horse Isle Server/Server.cs @@ -424,6 +424,23 @@ namespace Horse_Isle_Server sender.SendPacket(chatPacketSender); } + public static void OnInventoryRequested(Client sender, byte[] packet) + { + if (!sender.LoggedIn) + { + Logger.ErrorPrint(sender.RemoteIp + " Sent chat packet when not logged in."); + return; + } + + if (packet.Length < 2) + { + Logger.ErrorPrint(sender.RemoteIp + " Sent an invalid chat packet."); + return; + } + + byte[] metaPacket = PacketBuilder.CreateMetaPacket(Meta.BuildInventoryInfo(sender.LoggedinUser.ItemInventory)); + sender.SendPacket(metaPacket); + } public static void OnLoginRequest(Client sender, byte[] packet) { Logger.DebugPrint("Login request received from: " + sender.RemoteIp); @@ -688,7 +705,7 @@ namespace Horse_Isle_Server return; LocationStr = Meta.BuildSpecialTileInfo(specialTile); } - byte[] AreaMessage = PacketBuilder.CreatePlaceInfo(LocationStr); + byte[] AreaMessage = PacketBuilder.CreateMetaPacket(LocationStr); forClient.SendPacket(AreaMessage); } diff --git a/Horse Isle Server/Horse Isle Server/User.cs b/Horse Isle Server/Horse Isle Server/User.cs index 49e1268..b43b30f 100644 --- a/Horse Isle Server/Horse Isle Server/User.cs +++ b/Horse Isle Server/Horse Isle Server/User.cs @@ -29,6 +29,7 @@ namespace Horse_Isle_Server public Mailbox MailBox; public Friends Friends; public string Password; // For chat filter. + public Inventory ItemInventory; public int ChatViolations { get @@ -161,6 +162,8 @@ namespace Horse_Isle_Server NewPlayer = true; } + ItemInventory = new Inventory(); + Id = UserId; Username = Database.GetUsername(UserId);