public ReadBytesOrThrow ( int count ) : byte[] | ||
count | int | The number of bytes to read |
Résultat | byte[] |
protected override void Parse(EndianBinaryReader r) { int length = ReadVarInt(r); if(length != 256) throw new ProtocolException("Expected 256 bytes key got " + length); SharedKey = r.ReadBytesOrThrow(length); length = ReadVarInt(r); if(length != 256) throw new ProtocolException("Expected 256 bytes test got " + length); Test = r.ReadBytesOrThrow(length); DebugGotAll(r); }
internal NoteData(Class elfClass, long sectionOffset, Func<EndianBinaryReader> readerSource) { reader = readerSource(); reader.BaseStream.Seek(sectionOffset, SeekOrigin.Begin); var nameSize = ReadSize(); var descriptionSize = ReadSize(); Type = ReadField(); int remainder; var fields = Math.DivRem(nameSize, FieldSize, out remainder); var alignedNameSize = FieldSize*(remainder > 0 ? fields + 1 : fields); var name = reader.ReadBytesOrThrow(alignedNameSize); Name = Encoding.ASCII.GetString(name, 0, nameSize - 1); // minus one to omit terminating NUL Description = reader.ReadBytesOrThrow((int)descriptionSize - 1); }
protected override void Parse(EndianBinaryReader r) { ServerID = ReadString8(r); int length = ReadVarInt(r); if (length != 294) { throw new InvalidDataException("Public key size mismatch"); } PublicKey = r.ReadBytesOrThrow(length); length = ReadVarInt(r); if(length != 4) throw new InvalidDataException("Public key size mismatch"); VerifyToken = r.ReadBytesOrThrow(length); DebugGotAll(r); }
protected override void Parse(EndianBinaryReader r) { int columnCount = r.ReadInt16(); int compressedLength = r.ReadInt32(); Unknown = r.ReadBoolean(); CompressedChunkColumns = r.ReadBytesOrThrow(compressedLength); ColumnMeta = new UItem[columnCount]; for (int n = 0; n < columnCount; n++) { ColumnMeta [n] = new UItem(r); } }
protected override void Parse(EndianBinaryReader r) { EID = ReadVarInt(r); PlayerUUID = new Guid(r.ReadBytesOrThrow(16)); Position = ReadAbsInt(r); Yaw = r.ReadSByte() * Math.PI / 128; Pitch = r.ReadSByte() * Math.PI / 128; CurrentItem = r.ReadInt16(); try { Meta = Metadata.Read(r); } catch (Exception) { Console.WriteLine("BadMeta: " + BitConverter.ToString(PacketBuffer)); } Debug.WriteLine("Parsed " + this); }
/// <summary> /// Minecraft protocol encoded string /// </summary> public static string ReadString8(EndianBinaryReader r) { int length = ReadVarInt(r); byte[] buffer = r.ReadBytesOrThrow(length); string message = Encoding.UTF8.GetString(buffer); return message; }
//Only parsed so we can block it protected override void Parse(EndianBinaryReader r) { //Console.WriteLine("Player List Item:"); //Console.WriteLine(BitConverter.ToString(PacketBuffer)); return; //Ignore the data, we just want to block the package #if !DEBUG #else #pragma warning disable 162 Action = (Actions)ReadVarInt(r); int count = ReadVarInt(r); Players = new List<PlayerItem>(count); switch (Action) { case Actions.AddPlayer: for (int n = 0; n < count; n++) { var i = new PlayerItem(); i.UUID = new Guid(r.ReadBytesOrThrow(16)); i.Name = ReadString8(r); int props = ReadVarInt(r); for (int p = 0; p < props; p++) { string name = ReadString8(r); string value = ReadString8(r); bool signed = r.ReadBoolean(); if (signed) { string sign = ReadString8(r); } throw new NotImplementedException(); } i.Gamemode = (GameMode)ReadVarInt(r); i.Ping = ReadVarInt(r); Players.Add(i); } break; case Actions.UpdateGamemode: for (int n = 0; n < count; n++) { var i = new PlayerItem(); i.UUID = new Guid(r.ReadBytesOrThrow(16)); i.Gamemode = (GameMode)ReadVarInt(r); Players.Add(i); } break; case Actions.UpdateLatency: for (int n = 0; n < count; n++) { var i = new PlayerItem(); i.UUID = new Guid(r.ReadBytesOrThrow(16)); i.Ping = ReadVarInt(r); Players.Add(i); } break; case Actions.RemovePlayer: for (int n = 0; n < count; n++) { var i = new PlayerItem(); i.UUID = new Guid(r.ReadBytesOrThrow(16)); Players.Add(i); } break; default: throw new NotImplementedException("Action: " + Action); } #pragma warning restore 162 #endif }