Exemplo n.º 1
0
        public static byte[] Create(N3Message messageBody)
        {
            IntPtr pEngine = N3Engine_t.GetInstance();

            if (pEngine == IntPtr.Zero)
            {
                return(null);
            }

            int localDynelInstance = N3EngineClient_t.GetClientInst(pEngine);

            messageBody.Identity = new Identity(IdentityType.SimpleChar, localDynelInstance);

            var message = new Message
            {
                Body   = messageBody,
                Header = new Header
                {
                    MessageId  = BitConverter.ToUInt16(new byte[] { 0xFF, 0xFF }, 0),
                    PacketType = messageBody.PacketType,
                    Unknown    = 0x0001,
                    Sender     = localDynelInstance,
                    Receiver   = 0x02
                }
            };

            using (MemoryStream stream = new MemoryStream())
            {
                _serializer.Serialize(stream, message);
                return(stream.ToArray());
            }
        }
 private void AssertN3Message(N3Message expected, N3Message actual)
 {
     Assert.AreEqual(expected.Identity, actual.Identity);
     Assert.AreEqual(expected.N3MessageType, actual.N3MessageType);
     Assert.AreEqual(expected.PacketType, actual.PacketType);
     Assert.AreEqual(expected.Unknown, actual.Unknown);
 }
Exemplo n.º 3
0
        private static void OnInboundN3Message(N3Message n3Msg)
        {
            if (n3MsgCallbacks.ContainsKey(n3Msg.N3MessageType))
            {
                n3MsgCallbacks[n3Msg.N3MessageType].Invoke(n3Msg);
            }

            N3MessageReceived?.Invoke(null, n3Msg);
        }
Exemplo n.º 4
0
        public static void Send(N3Message message)
        {
            byte[] packet = PacketFactory.Create(message);

            if (packet == null)
            {
                return;
            }

            Send(packet);
        }
Exemplo n.º 5
0
        internal static void OnKnubotAnswerList(N3Message n3Msg)
        {
            KnuBotAnswerListMessage  knubotMsg = (KnuBotAnswerListMessage)n3Msg;
            Dictionary <int, string> options   = new Dictionary <int, string>();

            for (int i = 0; i < knubotMsg.DialogOptions.Length; i++)
            {
                options.Add(i, knubotMsg.DialogOptions[i].Text);
            }

            AnswerListChanged?.Invoke(knubotMsg.Target, options);
        }
Exemplo n.º 6
0
        private static void OnTemplateAction(N3Message n3Msg)
        {
            TemplateActionMessage templateActionMessage = (TemplateActionMessage)n3Msg;

            switch (templateActionMessage.Unknown2)
            {
            case 3:
                Item.OnItemUsed(templateActionMessage.ItemLowId, templateActionMessage.ItemHighId, templateActionMessage.Quality, templateActionMessage.Identity);
                break;

            case 32:
                PerkAction.OnPerkFinished(templateActionMessage.ItemLowId, templateActionMessage.ItemHighId, templateActionMessage.Quality, templateActionMessage.Identity);
                break;
            }
        }
Exemplo n.º 7
0
        private static void OnGenericCmd(N3Message n3Msg)
        {
            GenericCmdMessage genericCmdMessage = (GenericCmdMessage)n3Msg;

            if (genericCmdMessage.User != DynelManager.LocalPlayer.Identity)
            {
                return;
            }

            switch (genericCmdMessage.Action)
            {
            case GenericCmdAction.Use:
                Item.OnUsingItem(genericCmdMessage.Target);
                break;
            }
        }
Exemplo n.º 8
0
        private static void OnCharacterAction(N3Message n3Msg)
        {
            CharacterActionMessage charActionMessage = (CharacterActionMessage)n3Msg;

            switch (charActionMessage.Action)
            {
            case CharacterActionType.LeaveTeam:
                Team.OnMemberLeft(charActionMessage.Target);
                break;

            case CharacterActionType.QueuePerk:
                PerkAction.OnPerkQueued();
                break;
                //case CharacterActionType.TeamKick:
                //    Team.OnMemberLeft(charActionMessage.Target);
                //    break;

                //default:
                //    Chat.WriteLine($"UnhandledCharAction::{charActionMessage.Action}");
                //    break;
            }
        }
Exemplo n.º 9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="numBytes"></param>
        protected override void OnReceive(int numBytes)
        {
            byte[] packet = new byte[numBytes];
            Array.Copy(this.m_readBuffer.Array, this.m_readBuffer.Offset, packet, 0, numBytes);
            PacketReader reader = new PacketReader(packet);

            // TODO: make check here to see if packet starts with 0xDFDF
            reader.ReadBytes(2);

            // Packet type
            short type = reader.PopShort();

            // Unknown?
            reader.PopShort();

            // Packet Length
            reader.PopShort();

            // Sender
            reader.PopInt();

            // Receiver
            reader.PopInt();

            // PacketID
            int id = reader.PopInt();

            switch (type)
            {
            case 0x01:     // SystemMessage
            {
                Program.zoneServer.SystemMessageHandler.Parse(this, packet, id);
                break;
            }

            case 0x05:     // TextMessage
            {
                Program.zoneServer.TextMessageHandler.Parse(this, packet, id);
                break;
            }

            case 0x0A:     // N3Message
            {
                N3Message.Parse(this, packet, id);
                break;
            }

            case 0x0B:     // PingMessage
            {
                break;
            }

            case 0x0E:     // OperatorMessage
            {
                break;
            }

            default:     // UnknownMessage
            {
                // TODO: Handle Unknown Messages
                break;
            }
            }
            reader.Finish();
        }
Exemplo n.º 10
0
 private static void OnCharInPlay(N3Message n3Msg)
 {
     DynelManager.OnCharInPlay(n3Msg.Identity);
 }
Exemplo n.º 11
0
 private static void OnOutboundN3Message(N3Message n3Msg)
 {
     N3MessageSent?.Invoke(null, n3Msg);
 }