Exemplo n.º 1
0
        public InboundPacket(NetworkStream stream)
        {
            for (int i = 0; i < 8; i++)
                stream.ReadByte();

            byte[] dataSizeRaw = new byte[4];
            for (int i = 0; i < 4; i++)
                dataSizeRaw[i] = (byte)stream.ReadByte();

            byte[] dataSizeBE = new byte[4];
            dataSizeBE[0] = dataSizeRaw[3];
            dataSizeBE[1] = dataSizeRaw[2];
            dataSizeBE[2] = dataSizeRaw[1];
            dataSizeBE[3] = dataSizeRaw[0];

            int dataSize = BitConverter.ToInt32(dataSizeBE, 0);
            for (int i = 0; i < 4; i++)
                stream.ReadByte();

            byte[] dataPacketRaw = new byte[dataSize];

            for (int i = 0; i < dataSize; i++)
                dataPacketRaw[i] = (byte)stream.ReadByte();

            byte[] dataPacketTrimmed = new byte[dataPacketRaw.Length - 3];
            for (int i = 0; i < dataPacketTrimmed.Length; i++)
                dataPacketTrimmed[i] = dataPacketRaw[i];

            Message = System.Text.Encoding.ASCII.GetString(dataPacketTrimmed).Substring(2);
            Prefix = Message.Substring(0, 3);
        }
Exemplo n.º 2
0
 public void Read(NetworkStream stream)
 {
     EntityID = StreamHelper.ReadInt(stream);
     X = (sbyte)stream.ReadByte();
     Y = (sbyte)stream.ReadByte();
     Z = (sbyte)stream.ReadByte();
 }
Exemplo n.º 3
0
 public void Read(NetworkStream stream)
 {
     WindowId = (byte)stream.ReadByte();
     WindowType = (WindowTypes)stream.ReadByte();
     Title = StreamHelper.ReadString(stream);
     Slots = (byte)stream.ReadByte();
 }
Exemplo n.º 4
0
 public static ArrayList Read(NetworkStream stream)
 {
     ArrayList list = new ArrayList();
     for (byte b = (byte)stream.ReadByte(); b != 127; b = (byte)stream.ReadByte())
     {
         int i = (b & 0xe0) >> 5;
         int j = b & 0x1f;
         WatchableObject obj = null;
         switch (i)
         {
             case 0: //Byte
                 obj = new WatchableObject(i, j, (byte)stream.ReadByte());
                 break;
             case 1: //Short
                 obj = new WatchableObject(i, j, StreamHelper.ReadShort(stream));
                 break;
             case 2: //Int
                 obj = new WatchableObject(i, j, StreamHelper.ReadInt(stream));
                 break;
             case 3: //Float
                 obj = new WatchableObject(i, j, StreamHelper.ReadFloat(stream));
                 break;
             case 4: //String
                 obj = new WatchableObject(i, j, StreamHelper.ReadString(stream));
                 break;
             case 5: //Item stack
                 obj = new WatchableObject(i, j, new ItemStack(StreamHelper.ReadShort(stream), stream.ReadByte(), StreamHelper.ReadShort(stream)));
                 break;
         }
         list.Add(obj);
     }
     return list;
 }
Exemplo n.º 5
0
 public void Read(NetworkStream stream)
 {
     a = StreamHelper.ReadInt(stream);
     b = stream.ReadByte();
     c = StreamHelper.ReadInt(stream);
     d = stream.ReadByte();
     e = StreamHelper.ReadInt(stream);
 }
Exemplo n.º 6
0
 public void Read(NetworkStream stream)
 {
     X = StreamHelper.ReadInt(stream);
     Y = StreamHelper.ReadShort(stream);
     Z = StreamHelper.ReadInt(stream);
     Instrument = (InstrumentType)stream.ReadByte();
     Pitch = (byte)stream.ReadByte();
 }
Exemplo n.º 7
0
 public void Read(NetworkStream stream)
 {
     X = StreamHelper.ReadInt(stream);
     Y = stream.ReadByte();
     Z = StreamHelper.ReadInt(stream);
     BlockType = stream.ReadByte();
     Metadata = stream.ReadByte();
 }
Exemplo n.º 8
0
 public void Read(NetworkStream stream)
 {
     Status = stream.ReadByte();
     X = StreamHelper.ReadInt(stream);
     Y = stream.ReadByte();
     Z = StreamHelper.ReadInt(stream);
     FaceType = (Face)stream.ReadByte();
 }
Exemplo n.º 9
0
 public void Read(NetworkStream stream)
 {
     EntityID = StreamHelper.ReadInt(stream);
     Name = StreamHelper.ReadString(stream);
     X = StreamHelper.ReadInt(stream);
     Y = StreamHelper.ReadInt(stream);
     Z = StreamHelper.ReadInt(stream);
     Rotation = (byte)stream.ReadByte();
     Pitch = (byte)stream.ReadByte();
     CurrentItem = StreamHelper.ReadShort(stream);
 }
Exemplo n.º 10
0
 public void Read(NetworkStream stream)
 {
     EntityID = StreamHelper.ReadInt(stream);
     MobType = (byte)stream.ReadByte();
     X = StreamHelper.ReadInt(stream);
     Y = StreamHelper.ReadInt(stream);
     Z = StreamHelper.ReadInt(stream);
     Yaw = (sbyte)stream.ReadByte();
     Pitch = (sbyte)stream.ReadByte();
     Metadata = DataWatcher.Read(stream);
 }
Exemplo n.º 11
0
 public void Read(NetworkStream stream)
 {
     EntityID = StreamHelper.ReadInt(stream);
     ItemID = StreamHelper.ReadShort(stream);
     Count = (byte)stream.ReadByte();
     Secondary = StreamHelper.ReadShort(stream);
     X = StreamHelper.ReadInt(stream);
     Y = StreamHelper.ReadInt(stream);
     Z = StreamHelper.ReadInt(stream);
     Rotation = (byte)stream.ReadByte();
     Pitch = (byte)stream.ReadByte();
     Roll = (byte)stream.ReadByte();
 }
Exemplo n.º 12
0
    public Session(string host, int port, string username, string pw)
    {
      socket = new TcpClient(host, port);
      stream = socket.GetStream();
      ehost = host;
      string[] response = Receive().Split(':');

      string nonce;
      string code;
      if (response.Length > 1)
      {
          code = username + ":" + response[0] + ":" + pw;
          nonce = response[1];
      }
      else
      {
          code = pw;
          nonce = response[0];
      }

      Send(username);
      Send(MD5(MD5(code) + nonce));
      if (stream.ReadByte() != 0)
      {
          throw new IOException("Access denied.");
      }
    }
Exemplo n.º 13
0
 public void Read(NetworkStream stream)
 {
     Name = (byte)stream.ReadByte();
     Length = StreamHelper.ReadShort(stream);
     Items = new ItemStack[Length];
     for (int i = 0; i < Length; i++)
     {
         short primary = StreamHelper.ReadShort(stream);
         if (primary >= 0)
         {
             byte count = (byte)stream.ReadByte();
             short secondary = StreamHelper.ReadShort(stream);
             Items[i] = new ItemStack(primary, count, secondary);
         }
     }
 }
Exemplo n.º 14
0
 public void Read(NetworkStream stream)
 {
     WindowID = (byte)stream.ReadByte();
     Slot = StreamHelper.ReadShort(stream);
     short word0 = StreamHelper.ReadShort(stream);
     if (word0 >= 0)
     {
         byte byte0 = (byte)stream.ReadByte();
         short word1 = StreamHelper.ReadShort(stream);
         Items = new ItemStack(word0, byte0, word1);
     }
     else
     {
         Items = null;
     }
 }
Exemplo n.º 15
0
        public void Read(NetworkStream stream)
        {
            Unknown1 = StreamHelper.ReadDouble(stream);
            Unknown2 = StreamHelper.ReadDouble(stream);
            Unknown3 = StreamHelper.ReadDouble(stream);
            Unknown4 = StreamHelper.ReadFloat(stream);
            Count = StreamHelper.ReadInt(stream);
            Unknown5 = new HashSet<ChunkPosition>();

            for (int i = 0; i < Count; i++)
            {
                Unknown5.Add(new ChunkPosition(
                    stream.ReadByte() + (int)Unknown1,
                    stream.ReadByte() + (int)Unknown2,
                    stream.ReadByte() + (int)Unknown3));
            }
        }
Exemplo n.º 16
0
 public void Read(NetworkStream stream)
 {
     EntityID = StreamHelper.ReadInt(stream);
     VehicleType = (byte)stream.ReadByte();
     X = StreamHelper.ReadInt(stream);
     Y = StreamHelper.ReadInt(stream);
     Z = StreamHelper.ReadInt(stream);
 }
Exemplo n.º 17
0
 public void Read(NetworkStream stream)
 {
     this.Version = StreamHelper.ReadInt(stream); //entity id
     this.Username = StreamHelper.ReadString(stream); //server name
     this.ServerPassword = StreamHelper.ReadString(stream); //motd
     this.MapSeed = StreamHelper.ReadLong(stream); //map seed
     this.Dimension = (byte)stream.ReadByte(); //dimension
 }
Exemplo n.º 18
0
 public void Read(NetworkStream stream)
 {
     X = StreamHelper.ReadDouble(stream);
     Y = StreamHelper.ReadDouble(stream);
     Stance = StreamHelper.ReadDouble(stream);
     Z = StreamHelper.ReadDouble(stream);
     OnGround = stream.ReadByte() != 0;
 }
        public WebSocketFrame Read(NetworkStream stream)
        {
            // read the first byte. If the connection has been terminated abnormally then this would return an FF and we should exit
            byte byte1 = (byte)stream.ReadByte();

            // this condition will happen if the connection has terminated unexpectedly
            if (!stream.DataAvailable && byte1 == 0xFF)
            {
                return new WebSocketFrame(true, WebSocketOpCode.ConnectionClose, new byte[0], false);
            }

            // process first byte
            byte finBitFlag = 0x80;
            byte opCodeFlag = 0x0F;
            bool isFinBitSet = (byte1 & finBitFlag) == finBitFlag;
            WebSocketOpCode opCode = (WebSocketOpCode)(byte1 & opCodeFlag);

            // read and process second byte
            byte byte2 = (byte)stream.ReadByte();
            byte maskFlag = 0x80;
            bool isMaskBitSet = (byte2 & maskFlag) == maskFlag;
            uint len = ReadLength(byte2, stream);
            byte[] decodedPayload;

            // use the masking key to decode the data if needed
            if (isMaskBitSet)
            {
                const int maskKeyLen = 4;
                byte[] maskKey = BinaryReaderWriter.ReadExactly(maskKeyLen, stream);
                byte[] encodedPayload = BinaryReaderWriter.ReadExactly((int)len, stream);
                decodedPayload = new byte[len];

                // apply the mask key
                for (int i = 0; i < encodedPayload.Length; i++)
                {
                    decodedPayload[i] = (Byte)(encodedPayload[i] ^ maskKey[i % maskKeyLen]);
                }
            }
            else
            {
                decodedPayload = BinaryReaderWriter.ReadExactly((int)len, stream);
            }

            WebSocketFrame frame = new WebSocketFrame(isFinBitSet, opCode, decodedPayload, true);
            return frame;
        }
Exemplo n.º 20
0
 public void Read(NetworkStream stream)
 {
     ID = StreamHelper.ReadInt(stream);
     X = (byte)stream.ReadByte();
     Y = StreamHelper.ReadInt(stream);
     Z = (byte)stream.ReadByte();
     short word0 = StreamHelper.ReadShort(stream);
     if (word0 >= 0)
     {
         byte byte0 = (byte)stream.ReadByte();
         short word1 = StreamHelper.ReadShort(stream);
         Direction = new ItemStack((int)word0, (int)byte0, (int)word1);
     }
     else
     {
         Direction = null;
     }
 }
Exemplo n.º 21
0
        /// <summary>
        /// Reads the text from the server/client
        /// </summary>
        /// <returns>
        /// The text.
        /// </returns>
        /// <param name='io'>
        /// Network stream for reading from the server/client.
        /// </param>
        public static String ReadTextTcp(NetworkStream io)
        {
            String line = "";
            char ch;

            while((ch = (char)io.ReadByte()) != 0)
                line += ch;

            return line;
        }
Exemplo n.º 22
0
 public static byte[] BytesFill(NetworkStream Stream)
 {
     List<byte> Bytes = new List<byte>();
     while (true)
     {
         int b = Stream.ReadByte();
         if (b == -1) break;
         Bytes.Add((byte)b);
     }
     return Bytes.ToArray();
 }
Exemplo n.º 23
0
        public void Read(NetworkStream stream)
        {
            X = StreamHelper.ReadInt(stream);
            Y = StreamHelper.ReadShort(stream);
            Z = StreamHelper.ReadInt(stream);
            XSize = stream.ReadByte() + 1;
            YSize = stream.ReadByte() + 1;
            ZSize = stream.ReadByte() + 1;
            int i = StreamHelper.ReadInt(stream);
            byte[] buffer = new byte[i];
            buffer = StreamHelper.ReadBytes(stream, i);
            Chunk = new byte[(XSize * YSize * ZSize * 5) / 2];

            using (Stream file = new MemoryStream(buffer))
            using (Stream gzip = new Ionic.Zlib.ZlibStream(file, Ionic.Zlib.CompressionMode.Decompress))
            using (MemoryStream memoryStream = new MemoryStream())
            {
                CopyStream(gzip, memoryStream);
                Chunk = memoryStream.ToArray();
            }
        }
Exemplo n.º 24
0
 public static byte Read(Socket sock)
 {
     try
     {
         NetworkStream str = new NetworkStream(sock);
         return (byte)str.ReadByte();
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         return 0;
     }
 }
Exemplo n.º 25
0
 public Session(string host, int port, string username, string pw)
 {
   socket = new TcpClient(host, port);
   stream = socket.GetStream();
   ehost = host;
   string ts = Receive();
   Send(username);
   Send(MD5(MD5(pw) + ts));
   if (stream.ReadByte() != 0)
   {
     throw new IOException("Access denied.");
   }
 }
Exemplo n.º 26
0
        public static string GetNetworkPath(System.Net.Sockets.NetworkStream nstm, string host)
        {
#if VARIABLE_NETWORK_PATHS
            nstm.WriteByte((byte)'d'); // Get current directory.

            if ((int)'+' != nstm.ReadByte())
            {
                throw new Exception("GetNetworkPath failure (service didn't report success)");
            }

            return(LocalPathToNetworkPath(XContent.ReceiveXString(nstm, null), host));
#else
            return(LocalPathToNetworkPath(_netpath, host));
#endif
        }
Exemplo n.º 27
0
 internal static String readSmallString(NetworkStream stream)
 {
     byte size = (byte)stream.ReadByte();
     String s = "";
     for (int i = 0; i < size; i++ ) {
         s += Convert.ToChar((byte)stream.ReadByte());
     }
     return s;
 }
Exemplo n.º 28
0
 internal static int readInt(NetworkStream stream)
 {
     return (stream.ReadByte() << 24) | (stream.ReadByte() << 16) | (stream.ReadByte() << 8) | (stream.ReadByte());
 }
Exemplo n.º 29
0
 internal static float readFloat(NetworkStream stream)
 {
     return BitConverter.ToSingle(new byte[] { (byte)stream.ReadByte(), (byte)stream.ReadByte(), (byte)stream.ReadByte(), (byte)stream.ReadByte() }, 0);
 }
Exemplo n.º 30
0
 internal static byte readByte(NetworkStream stream)
 {
     return (byte)stream.ReadByte();
 }
Exemplo n.º 31
0
 public static Packet readPacket(NetworkStream stream)
 {
     byte packetId = (byte)stream.ReadByte();
     return readPacket(stream, packetId);
 }