From 7a8cc2c2a675d2a69ad952e139c02a95aef83f05 Mon Sep 17 00:00:00 2001 From: SilicaAndPina Date: Thu, 29 Oct 2020 23:08:24 +1300 Subject: [PATCH] no message --- Horse Isle Server/Horse Isle Server/Meta.cs | 2 +- Horse Isle Server/Horse Isle Server/Npc.cs | 12 +++++ .../Horse Isle Server/PacketBuilder.cs | 1 + Horse Isle Server/Horse Isle Server/Server.cs | 47 +++++++++++++++++-- 4 files changed, 56 insertions(+), 6 deletions(-) diff --git a/Horse Isle Server/Horse Isle Server/Meta.cs b/Horse Isle Server/Horse Isle Server/Meta.cs index dc27fb1..e67eb23 100644 --- a/Horse Isle Server/Horse Isle Server/Meta.cs +++ b/Horse Isle Server/Horse Isle Server/Meta.cs @@ -141,7 +141,6 @@ namespace Horse_Isle_Server if (specialTile.ExitX != 0 && specialTile.ExitY != 0) message += Messages.ExitThisPlace + Messages.MetaTerminator; - Logger.DebugPrint(message); return message; } @@ -193,6 +192,7 @@ namespace Horse_Isle_Server { message += Messages.FormatNpcReply(reply.ReplyText, reply.Id); } + message += Messages.BackToMap + Messages.MetaTerminator; return message; } diff --git a/Horse Isle Server/Horse Isle Server/Npc.cs b/Horse Isle Server/Horse Isle Server/Npc.cs index 80c6f8b..deb671d 100644 --- a/Horse Isle Server/Horse Isle Server/Npc.cs +++ b/Horse Isle Server/Horse Isle Server/Npc.cs @@ -72,6 +72,18 @@ namespace Horse_Isle_Server } throw new KeyNotFoundException("Npc reply with " + id + " not found!"); } + public static NpcChat GetNpcChatpoint(NpcEntry npc, int chatpointId) + { + foreach(Npc.NpcChat chatpoint in npc.Chatpoints) + { + if(chatpoint.Id == chatpointId) + { + return chatpoint; + } + } + + throw new KeyNotFoundException("Npc chatpoint id: " + chatpointId + " not found!"); + } public static NpcEntry GetNpcById(int id) { foreach(NpcEntry npc in NpcList) diff --git a/Horse Isle Server/Horse Isle Server/PacketBuilder.cs b/Horse Isle Server/Horse Isle Server/PacketBuilder.cs index 0f6177a..879a07d 100644 --- a/Horse Isle Server/Horse Isle Server/PacketBuilder.cs +++ b/Horse Isle Server/Horse Isle Server/PacketBuilder.cs @@ -35,6 +35,7 @@ namespace Horse_Isle_Server public const byte PACKET_PLAYERINFO = 0x16; public const byte NPC_START_CHAT = 0x14; + public const byte NPC_CONTINUE_CHAT = 0x15; public const byte PLAYERINFO_LEAVE = 0x16; public const byte PLAYERINFO_UPDATE_OR_CREATE = 0x15; diff --git a/Horse Isle Server/Horse Isle Server/Server.cs b/Horse Isle Server/Horse Isle Server/Server.cs index 3e489b0..6493821 100644 --- a/Horse Isle Server/Horse Isle Server/Server.cs +++ b/Horse Isle Server/Horse Isle Server/Server.cs @@ -310,7 +310,7 @@ namespace Horse_Isle_Server return; } byte action = packet[1]; - if(action == PacketBuilder.NPC_START_CHAT) + if (action == PacketBuilder.NPC_START_CHAT) { string packetStr = Encoding.UTF8.GetString(packet); @@ -320,9 +320,9 @@ namespace Horse_Isle_Server { chatId = int.Parse(number); } - catch(InvalidOperationException) + catch (InvalidOperationException) { - Logger.ErrorPrint(sender.LoggedinUser.Username + " Tried to use a transport with id that is NaN."); + Logger.ErrorPrint(sender.LoggedinUser.Username + " Tried to start talking to an NPC with id that is NaN."); return; } @@ -331,9 +331,46 @@ namespace Horse_Isle_Server byte[] metaPacket = PacketBuilder.CreateMetaPacket(metaInfo); sender.SendPacket(metaPacket); } - else + else if (action == PacketBuilder.NPC_CONTINUE_CHAT) { - Logger.ErrorPrint("Unknown npc interaction! - Packet Dump: " + BitConverter.ToString(packet).Replace('-', ' ')); + string packetStr = Encoding.UTF8.GetString(packet); + string number = packetStr.Substring(2, packetStr.Length - 4); + int replyId = 0; + try + { + replyId = int.Parse(number); + } + catch (InvalidOperationException) + { + Logger.ErrorPrint(sender.LoggedinUser.Username + " Tried to reply to an NPC with replyid that is NaN."); + return; + } + + foreach (Npc.NpcEntry npc in Npc.NpcList) + { + foreach (Npc.NpcChat chatpoint in npc.Chatpoints) + { + foreach (Npc.NpcReply reply in chatpoint.Replies) + { + if (reply.Id == replyId) + { + if (reply.GotoChatpoint == -1) + { + UpdateArea(sender); + return; + } + + string metaInfo = Meta.BuildChatpoint(npc,Npc.GetNpcChatpoint(npc, reply.GotoChatpoint)); + byte[] metaPacket = PacketBuilder.CreateMetaPacket(metaInfo); + sender.SendPacket(metaPacket); + return; + + } + } + } + } + Logger.ErrorPrint(sender.LoggedinUser.Username + " Tried to reply with replyid that does not exist."); + } } public static void OnTransportUsed(Client sender, byte[] packet)