Example #1
0
        public void HandleMessage(Client.Client sender, PacketReader stream)
        {
            if (sender == null)
            {
                throw new ArgumentNullException(nameof(sender));
            }

            try
            {
                if (sender.TryGetControlledNpc(out NpcInst npc))
                {
                    sender.RemoveControl();

                    if (_CharacterService.TryGetMapping(npc, out CharacterMapping mapping))
                    {
                        mapping.Character.RemoveMapping();
                        mapping.Character.Save();
                    }

                    npc.Despawn();
                }
            }
            catch (Exception e)
            {
                _Log.Error($"Something went wrong while handling a '{SupportedMessage}' script message. Disconnecting the client to get back into a defined state. Exception:  {e}");
                sender.Disconnect();
            }
        }