Пример #1
0
        private static void OnStatLockChanged(int client, PacketReader reader)
        {
            int type  = reader.ReadByte();
            int value = reader.ReadByte();

            OutgoingPackets.OnStatLockChanged(client, type, value);
        }
Пример #2
0
        private static void OnSkillLockChanged(int client, PacketReader reader)
        {
            int        skillID3a    = reader.ReadInt16();
            LockStatus lockStatus3a = (LockStatus)reader.ReadByte();

            OutgoingPackets.OnSkillLockChanged(client, skillID3a, lockStatus3a);
        }
Пример #3
0
        private static void OnDragItemRequested(int client, PacketReader reader)
        {
            int serial7 = reader.ReadInt32();
            int amount7 = reader.ReadInt16();

            OutgoingPackets.OnDragItemRequested(client, serial7, amount7);
        }
Пример #4
0
        private static void OnMoveRequested(int client, PacketReader reader)
        {
            int direction2 = reader.ReadByte() & 0x07;
            int sequence2  = reader.ReadByte();

            OutgoingPackets.OnMoveRequested(client, direction2, sequence2);
        }
Пример #5
0
        private static void OnUnicodeSpeech(int client, PacketReader reader)
        {
            byte   messagetype = reader.ReadByte();
            int    color       = reader.ReadInt16();
            int    font        = reader.ReadInt16();
            string lang        = reader.ReadString(4);
            string text;

            int[] keywords;

            if ((messagetype & 0xC0) != 0)
            {
                int value = reader.ReadInt16();
                int count = (value & 0xFFF0) >> 4;
                int hold  = value & 0xF;

                if (count < 0 || count > 50)
                {
                    return;
                }

                List <int> keyList = new List <int>();

                for (int i = 0; i < count; ++i)
                {
                    int speechID;

                    if ((i & 1) == 0)
                    {
                        hold   <<= 8;
                        hold    |= reader.ReadByte();
                        speechID = hold;
                        hold     = 0;
                    }
                    else
                    {
                        value    = reader.ReadInt16();
                        speechID = (value & 0xFFF0) >> 4;
                        hold     = value & 0xF;
                    }

                    if (!keyList.Contains(speechID))
                    {
                        keyList.Add(speechID);
                    }
                }

                text = reader.ReadStringSafe();

                keywords = keyList.ToArray();
            }
            else
            {
                keywords = new int[0];
                text     = reader.ReadUnicodeStringSafe();
            }
            OutgoingPackets.OnUnicodeSpeech(client, messagetype, color, font, lang, keywords, text);
        }
Пример #6
0
        private static void OnTargetSent(int client, PacketReader reader)
        {
            int  type6c       = reader.ReadByte();
            int  charSerial6c = reader.ReadInt32();
            bool checkCrime6c = reader.ReadByte() == 1;
            int  serial6c     = reader.ReadInt32();
            int  x6c          = reader.ReadUInt16();
            int  y6c          = reader.ReadUInt16();
            int  z6c          = reader.ReadUInt16();
            int  id6c         = reader.ReadUInt16();

            OutgoingPackets.OnTargetSent(client, type6c, checkCrime6c, serial6c, x6c, y6c, z6c, id6c, reader.Data);
        }
Пример #7
0
        private async Task ProcessPacketStream()
        {
            try
            {
                while (IsConnected && (OutgoingPackets.Count != 0 || TcpClient.Available != 0))
                {
                    // Process incoming packets
                    while (IsConnected && TcpClient.Available != 0)
                    {
                        if (ReceivedPacket != null)
                        {
                            ReceivedPacket(this, new PacketEventArgs()
                            {
                                Packet = await Packet.ReadFromStreamAsync(TcpClientStream)
                            });
                        }

                        IncomingPacketReceieved = true;
                        //CanSendPacket = true;
                    }


                    // Send an outgoing packet
                    if (IsConnected && CanSendPacket && OutgoingPackets.Count != 0)
                    {
                        await OutgoingPackets.Dequeue().WriteToStreamAsync(TcpClientStream);

                        OutgoingPacketCooldown.Restart();
                        IncomingPacketReceieved = false;
                        //CanSendPacket = false;
                    }

                    // We've successfully sent or recieved data so the keepalive can be pushed back.
                    Keepalive.Reset();
                }
            }
            catch
            {
                // Lost connection with the server
                // No handling is necessary here as the TCPClient will set Connected to false.
                if (ServerConnectionDropped != null)
                {
                    ServerConnectionDropped(this, new ServerConnectionEventArgs()
                    {
                        Message = "Connection to the server has been lost.", Status = ServerConnectionStatus.Disconnected, Timestamp = DateTime.Now
                    });
                }
            }
        }
Пример #8
0
        public void Dispose()
        {
            if (TcpClientStream != null)
            {
                TcpClientStream.Dispose();
                TcpClientStream = null;
            }

            if (TcpClient != null)
            {
                TcpClient.Close();
                TcpClient = null;
            }

            OutgoingPackets.Clear();
        }
Пример #9
0
        private static void OnGumpButtonPressed(int client, PacketReader reader)
        {
            //gump choice, only button & switches are processed
            int serialb1 = reader.ReadInt32();
            int gumpb1   = reader.ReadInt32();
            int buttonb1 = reader.ReadInt32();

            int[] switchvaluesb1 = new int[0];
            if (gumpb1 != 461)
            {
                int switchesb1 = reader.ReadInt32();
                switchvaluesb1 = new int[switchesb1];

                for (int xb1 = 0; xb1 < switchesb1; xb1++)
                {
                    switchvaluesb1[xb1] = reader.ReadInt32();
                }
            }
            OutgoingPackets.OnGumpButtonPressed(client, serialb1, gumpb1, buttonb1, switchvaluesb1);
        }
Пример #10
0
        private static void OnDropItemRequested(int client, PacketReader reader)
        {
            const int oldLen08 = 0x0E;
            const int newLen08 = 0x0F;

            if (reader.Size != oldLen08 && reader.Size != newLen08)
            {
                return;
            }
            int serial8 = reader.ReadInt32();
            int x8      = reader.ReadInt16();
            int y8      = reader.ReadInt16();
            int z8      = reader.ReadSByte();
            int container8;

            if (reader.Size == newLen08)
            {
                reader.ReadByte(); // Grid location
            }
            container8 = reader.ReadInt32();
            OutgoingPackets.OnDropItemRequested(client, serial8, x8, y8, z8, container8);
        }
Пример #11
0
        /// <summary>
        /// Processes the packet stream.
        /// </summary>
        /// <returns>Task.</returns>
        private async Task ProcessPacketStream()
        {
            try
            {
                while (IsConnected && (OutgoingPackets.Count != 0 || TcpClient.Available != 0))
                {
                    while (IsConnected && TcpClient.Available != 0)
                    {
                        ReceivedPacket?.Invoke(this, new PacketEventArgs {
                            Packet = await Packet.ReadFromStreamAsync(TcpClientStream)
                        });

                        IncomingPacketReceieved = true;
                    }


                    if (!IsConnected || !CanSendPacket || OutgoingPackets.Count == 0)
                    {
                        continue;
                    }

                    await OutgoingPackets.Dequeue().WriteToStreamAsync(TcpClientStream);

                    OutgoingPacketCooldown.Restart();
                    IncomingPacketReceieved = false;

                    //// We've successfully sent or recieved data so the keepalive can be pushed back.
                    Keepalive.Reset();
                }
            }
            catch
            {
                // Lost connection with the server
                // No handling is necessary here as the TCPClient will set Connected to false.
                ServerConnectionDropped?.Invoke(this, new ServerConnectionEventArgs {
                    Message = "Connection to the server has been lost.", Status = ServerConnectionStatusEnum.Disconnected, Timestamp = DateTime.Now
                });
            }
        }
Пример #12
0
        private static void OnUseItemRequested(int client, PacketReader reader)
        {
            int serial6 = reader.ReadInt32();

            OutgoingPackets.OnUseItemRequested(client, serial6);
        }
Пример #13
0
        public static void ProcessPacket(int client, byte[] packet)
        {
            switch (packet[0])
            {
            case 0x00:
                break;

            case 0x01:
                break;

            case 0x02:     //request walk
                int direction2 = packet[1] & 0x07;
                int sequence2  = packet[2];
                OutgoingPackets.OnMoveRequested(client, direction2, sequence2);
                return;

            case 0x03:
                break;

            case 0x04:
                break;

            case 0x05:
                break;

            case 0x06:     //double click object
                int serial6 = packet[1] << 24 | packet[2] << 16 | packet[3] << 8 | packet[4];
                OutgoingPackets.OnUseItemRequested(client, serial6);
                return;

            case 0x07:     //drag item
                int serial7 = packet[1] << 24 | packet[2] << 16 | packet[3] << 8 | packet[4];
                int amount7 = packet[5] << 8 | packet[6];
                OutgoingPackets.OnDragItemRequested(client, serial7, amount7);
                return;

            case 0x08:     //drop item
                const int oldLen08 = 0x0E;
                const int newLen08 = 0x0F;
                if (packet.Length != oldLen08 && packet.Length != newLen08)
                {
                    break;
                }
                int serial8 = packet[1] << 24 | packet[2] << 16 | packet[3] << 8 | packet[4];
                int x8      = packet[5] << 8 | packet[6];
                int y8      = packet[7] << 8 | packet[8];
                int z8      = (sbyte)packet[9];
                int container8;
                if (packet.Length == oldLen08)
                {
                    container8 = packet[10] << 24 | packet[11] << 16 | packet[12] << 8 | packet[13];
                }
                else
                {
                    container8 = packet[11] << 24 | packet[12] << 16 | packet[13] << 8 | packet[14];
                }
                OutgoingPackets.OnDropItemRequested(client, serial8, x8, y8, z8, container8);
                return;

            case 0x09:
                break;

            case 0x0A:
                break;

            case 0x0B:
                break;

            case 0x0C:
                break;

            case 0x0D:
                break;

            case 0x0E:
                break;

            case 0x0F:
                break;

            case 0x10:
                break;

            case 0x11:
                break;

            case 0x12:     //use skill
                return;

            case 0x13:     //equip item request
                return;

            case 0x14:
                break;

            case 0x15:
                break;

            case 0x16:
                break;

            case 0x17:
                break;

            case 0x18:
                break;

            case 0x19:
                break;

            case 0x1A:
                break;

            case 0x1B:
                break;

            case 0x1C:
                break;

            case 0x1D:
                break;

            case 0x1E:
                break;

            case 0x1F:
                break;

            case 0x20:
                break;

            case 0x21:
                break;

            case 0x22:
                break;

            case 0x23:
                break;

            case 0x24:
                break;

            case 0x25:
                break;

            case 0x26:
                break;

            case 0x27:
                break;

            case 0x28:
                break;

            case 0x29:
                break;

            case 0x2A:
                break;

            case 0x2B:
                break;

            case 0x2C:
                break;

            case 0x2D:
                break;

            case 0x2E:
                break;

            case 0x2F:
                break;

            case 0x30:
                break;

            case 0x31:
                break;

            case 0x32:
                break;

            case 0x33:
                break;

            case 0x34:
                break;

            case 0x35:
                break;

            case 0x36:
                break;

            case 0x37:
                break;

            case 0x38:
                break;

            case 0x39:
                break;

            case 0x3A:     //change skill lock
                int        skillID3a    = packet[3] << 8 | packet[4];
                LockStatus lockStatus3a = (LockStatus)packet[5];
                OutgoingPackets.OnSkillLockChanged(client, skillID3a, lockStatus3a);
                return;

            case 0x3B:
                break;

            case 0x3C:
                break;

            case 0x3D:
                break;

            case 0x3E:
                break;

            case 0x3F:
                break;

            case 0x40:
                break;

            case 0x41:
                break;

            case 0x42:
                break;

            case 0x43:
                break;

            case 0x44:
                break;

            case 0x45:
                break;

            case 0x46:
                break;

            case 0x47:
                break;

            case 0x48:
                break;

            case 0x49:
                break;

            case 0x4A:
                break;

            case 0x4B:
                break;

            case 0x4C:
                break;

            case 0x4D:
                break;

            case 0x4E:
                break;

            case 0x4F:
                break;

            case 0x50:
                break;

            case 0x51:
                break;

            case 0x52:
                break;

            case 0x53:
                break;

            case 0x54:
                break;

            case 0x55:
                break;

            case 0x56:
                break;

            case 0x57:
                break;

            case 0x58:
                break;

            case 0x59:
                break;

            case 0x5A:
                break;

            case 0x5B:
                break;

            case 0x5C:
                break;

            case 0x5D:
                break;

            case 0x5E:
                break;

            case 0x5F:
                break;

            case 0x60:
                break;

            case 0x61:
                break;

            case 0x62:
                break;

            case 0x63:
                break;

            case 0x64:
                break;

            case 0x65:
                break;

            case 0x66:
                break;

            case 0x67:
                break;

            case 0x68:
                break;

            case 0x69:
                break;

            case 0x6A:
                break;

            case 0x6B:
                break;

            case 0x6C:
                int type6c = packet[1];
                //int charSerial6c = packet[2] << 24 | packet[3] << 16 | packet[4] << 8 | packet[5];
                bool checkCrime6c = packet[6] == 1;
                int  serial6c     = packet[7] << 24 | packet[8] << 16 | packet[9] << 8 | packet[10];
                int  x6c          = (short)(packet[11] << 8 | packet[12]);
                int  y6c          = (short)(packet[13] << 8 | packet[14]);
                int  z6c          = (short)(packet[15] << 8 | packet[16]);
                int  id6c         = packet[17] << 8 | packet[18];
                OutgoingPackets.OnTargetSent(client, type6c, checkCrime6c, serial6c, x6c, y6c, z6c, id6c, packet);
                return;

            case 0x6D:
                break;

            case 0x6E:
                break;

            case 0x6F:
                break;

            case 0x70:
                break;

            case 0x71:
                break;

            case 0x72:
                break;

            case 0x73:
                break;

            case 0x74:
                break;

            case 0x75:
                break;

            case 0x76:
                break;

            case 0x77:
                break;

            case 0x78:
                break;

            case 0x79:
                break;

            case 0x7A:
                break;

            case 0x7B:
                break;

            case 0x7C:
                break;

            case 0x7D:
                break;

            case 0x7E:
                break;

            case 0x7F:
                break;

            case 0x80:
                break;

            case 0x81:
                break;

            case 0x82:
                break;

            case 0x83:
                break;

            case 0x84:
                break;

            case 0x85:
                break;

            case 0x86:
                break;

            case 0x87:
                break;

            case 0x88:
                break;

            case 0x89:
                break;

            case 0x8A:
                break;

            case 0x8B:
                break;

            case 0x8C:
                break;

            case 0x8D:
                break;

            case 0x8E:
                break;

            case 0x8F:
                break;

            case 0x90:
                break;

            case 0x91:
                break;

            case 0x92:
                break;

            case 0x93:
                break;

            case 0x94:
                break;

            case 0x95:
                break;

            case 0x96:
                break;

            case 0x97:
                break;

            case 0x98:
                break;

            case 0x99:
                break;

            case 0x9A:
                break;

            case 0x9B:
                break;

            case 0x9C:
                break;

            case 0x9D:
                break;

            case 0x9E:
                break;

            case 0x9F:
                break;

            case 0xA0:
                break;

            case 0xA1:
                break;

            case 0xA2:
                break;

            case 0xA3:
                break;

            case 0xA4:
                break;

            case 0xA5:
                break;

            case 0xA6:
                break;

            case 0xA7:
                break;

            case 0xA8:
                break;

            case 0xA9:
                break;

            case 0xAA:
                break;

            case 0xAB:
                break;

            case 0xAC:
                break;

            case 0xAD:
                break;

            case 0xAE:
                break;

            case 0xAF:
                break;

            case 0xB0:
                break;

            case 0xB1:     //gump choice, only button & switches are processed
                int   serialb1       = packet[3] << 24 | packet[4] << 16 | packet[5] << 8 | packet[6];
                int   gumpb1         = packet[7] << 24 | packet[8] << 16 | packet[9] << 8 | packet[10];
                int   buttonb1       = packet[11] << 24 | packet[12] << 16 | packet[13] << 8 | packet[14];
                int[] switchvaluesb1 = new int[0];
                if (gumpb1 != 461)
                {
                    int switchesb1 = packet[15] << 24 | packet[16] << 16 | packet[17] << 8 | packet[18];
                    switchvaluesb1 = new int[switchesb1];
                    int offsetb1 = 19;
                    for (int xb1 = 0; xb1 < switchesb1; xb1++)
                    {
                        switchvaluesb1[xb1] = packet[offsetb1] << 24 | packet[offsetb1 + 1] << 16 | packet[offsetb1 + 2] << 8 | packet[offsetb1 + 3];
                        offsetb1           += 4;
                    }
                }
                OutgoingPackets.OnGumpButtonPressed(client, serialb1, gumpb1, buttonb1, switchvaluesb1);
                return;

            case 0xB2:
                break;

            case 0xB3:
                break;

            case 0xB4:
                break;

            case 0xB5:
                break;

            case 0xB6:
                break;

            case 0xB7:
                break;

            case 0xB8:
                break;

            case 0xB9:
                break;

            case 0xBA:
                break;

            case 0xBB:
                break;

            case 0xBC:
                break;

            case 0xBD:
                break;

            case 0xBE:
                break;

            case 0xBF:     //misc commands
                int commandbf = packet[3] << 8 | packet[4];

                /*if (commandbf == 0x13) //context menu request
                 * {
                 *  return;
                 * }
                 * else if (commandbf == 0x15) //context menu click
                 * {
                 *  return;
                 * }*/
                /*if (commandbf == 0x0C)
                 *  break;*/
                if (commandbf == 0x1A)     //change stat lock
                {
                    OutgoingPackets.OnStatLockChanged(client, packet[5], packet[6]);
                    return;
                }
                return;

            case 0xC0:
                break;

            case 0xC1:
                break;

            case 0xC2:
                break;

            case 0xC3:
                break;

            case 0xC4:
                break;

            case 0xC5:
                break;

            case 0xC6:
                break;

            case 0xC7:
                break;

            case 0xC8:
                break;

            case 0xC9:
                break;

            case 0xCA:
                break;

            case 0xCB:
                break;

            case 0xCC:
                break;

            case 0xCD:
                break;

            case 0xCE:
                break;

            case 0xCF:
                break;

            case 0xD0:
                break;

            case 0xD1:
                break;

            case 0xD2:
                break;

            case 0xD3:
                break;

            case 0xD4:
                break;

            case 0xD5:
                break;

            case 0xD6:
                break;

            case 0xD7:
                break;

            case 0xD8:
                break;

            case 0xD9:
                break;

            case 0xDA:
                break;

            case 0xDB:
                break;

            case 0xDC:
                break;

            case 0xDD:
                break;

            case 0xDE:
                break;

            case 0xDF:
                break;

            case 0xE0:
                break;

            case 0xE1:
                break;

            case 0xE2:
                break;

            case 0xE3:
                break;

            case 0xE4:
                break;

            case 0xE5:
                break;

            case 0xE6:
                break;

            case 0xE7:
                break;

            case 0xE8:
                break;

            case 0xE9:
                break;

            case 0xEA:
                break;

            case 0xEB:
                break;

            case 0xEC:
                break;

            case 0xED:
                break;

            case 0xEE:
                break;

            case 0xEF:
                break;

            case 0xF0:
                break;

            case 0xF1:
                break;

            case 0xF2:
                break;

            default:
                break;
            }
            Log.LogDataMessage(client, packet, "+++ Outgoing packet:\r\n");
        }
Пример #14
0
 public void SendPacket(Packet packet)
 {
     OutgoingPackets.Enqueue(packet);
 }