Exemple #1
0
        private void ParseIncomingPacket(NetworkMessage msg)
        {
            int      x, y, id;
            byte     z, stack, number, Color;
            Location location;
            string   message, name;
            byte     PacketType = msg.GetByte();

            switch (PacketType)
            {
            case 0xF3:

                uint   Len           = msg.GetUInt32();
                byte[] incommingData = new byte[Len];
                for (int k = 0; k < Len; k++)
                {
                    incommingData[k] = msg.GetByte();
                }
                if (IncommingPacket != null)
                {
                    IncommingPacket.Invoke(incommingData);
                }
                break;

            case 0xB4:

                Color   = msg.GetByte();
                message = msg.GetString();
                if (message.ToLower().Contains("you see"))
                {
                    message += "\n  [ID] = " + client.Memory.ReadInt32(client.Addresses.Client.LastSeendId).ToString();
                }
                ForwardTextPacket(Color, message);
                break;

            case 0x6A:
                x      = msg.GetUInt16();
                y      = msg.GetUInt16();
                z      = msg.GetByte();
                stack  = msg.GetByte();
                stack -= 1;
                id     = msg.GetUInt16();
                Item i = new Item(client, id);

                if (TileAddThing != null)
                {
                    TileAddThing.Invoke(new Location(x, y, z), stack, id);
                }
                break;

            case 0x6D:
                Location FromLoc, ToLocation;
                byte     stackOrder;
                FromLoc    = msg.GetLocation();
                stackOrder = msg.GetByte();

                ToLocation = msg.GetLocation();
                if (CreateMovePacket != null)
                {
                    CreateMovePacket.Invoke(FromLoc, stackOrder, ToLocation);
                }
                break;

            case 0x84:
                Location loc   = msg.GetLocation();
                byte     color = msg.GetByte();
                message          = msg.GetString();
                client.StatusBar = message + " " + color.ToString() + " " + loc.ToString();
                break;
            }
        }
Exemple #2
0
 public NetworkMessage(NetworkMessage msg)
     : this(msg.Data)
 {
     this.position = msg.position;
 }
Exemple #3
0
        private void BeginRead(IAsyncResult ar)
        {
            NamedPipeServerStream pipe = ar.AsyncState as NamedPipeServerStream;
            int length = pipe.EndRead(ar);

            try
            {
                if (length > 1)
                {
                    byte[] tmpBytes = new byte[length];
                    Array.Copy(buffer, 0, tmpBytes, 0, length);
                    NetworkMessage msg = new NetworkMessage(tmpBytes);

                    msg.Position = 0;
                    UInt16         packLen = msg.GetUInt16();
                    PipePacketType type    = (PipePacketType)msg.GetByte();


                    switch (type)
                    {
                    case PipePacketType.RecivedOutgoingPacket:
                        byte[] buf = new byte[msg.Data.Length - 3];
                        Array.Copy(msg.Data, 3, buf, 0, buf.Length);
                        HookProxy_OutgoingPacket(buf);
                        break;

                    case PipePacketType.RecivedIncommingPacket:


                        byte[] buf2 = new byte[msg.Data.Length - 3];
                        Array.Copy(msg.Data, 3, buf2, 0, buf2.Length);

                        if (IncommingPacket != null)
                        {
                            IncommingPacket.Invoke(buf2);
                        }
                        break;

                    case PipePacketType.ParsedPacket:
                        ParseIncomingPacket(msg);
                        break;

                    case PipePacketType.ConnectionStatusChanged:
                        System.Windows.Forms.MessageBox.Show(msg.GetUInt32().ToString());
                        break;

                    case PipePacketType.FullIncommingPacket:

                        if (IncommingPacket != null)
                        {
                            byte[] data = new byte[msg.Data.Length - 3];
                            Array.Copy(msg.Data, 3, data, 0, msg.Data.Length - 3);
                            IncommingPacket.Invoke(data);
                        }
                        break;

                    case  PipePacketType.test:
                        uint adr = msg.GetUInt32();
                        System.Windows.Forms.MessageBox.Show(adr.ToString("X"));
                        break;
                    }
                }
                pipe.BeginRead(buffer, 0, buffer.Length, new AsyncCallback(BeginRead), pipe);
            }
            catch (Exception ex)
            {
                pipe.BeginRead(buffer, 0, buffer.Length, new AsyncCallback(BeginRead), pipe);
            }
        }