当前位置: 首页>>代码示例>>C#>>正文


C# BinaryWriter.WriteNetwork方法代码示例

本文整理汇总了C#中System.IO.BinaryWriter.WriteNetwork方法的典型用法代码示例。如果您正苦于以下问题:C# BinaryWriter.WriteNetwork方法的具体用法?C# BinaryWriter.WriteNetwork怎么用?C# BinaryWriter.WriteNetwork使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.BinaryWriter的用法示例。


在下文中一共展示了BinaryWriter.WriteNetwork方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateHandshakePacket

        public static byte[] CreateHandshakePacket(string username)
        {
            byte[] buffer;

            BinaryWriter writer = new BinaryWriter(new MemoryStream());

            writer.Write((byte)MCPacketOpcodes.Handshake);
            writer.WriteNetwork(username);

            buffer = new byte[writer.BaseStream.Position];

            writer.BaseStream.Position = 0;
            writer.BaseStream.Read(buffer, 0, buffer.Length);
            writer.Close();
            writer.Dispose();

            return buffer;
        }
开发者ID:Jonyleeson,项目名称:MCBot,代码行数:18,代码来源:MCPackets.cs

示例2: CreateDisconnectPacket

        public static byte[] CreateDisconnectPacket(string message)
        {
            byte[] buffer;

            BinaryWriter writer = new BinaryWriter(new MemoryStream());

            writer.Write((byte)MCPacketOpcodes.Disconnect);
            writer.WriteNetwork(message);

            buffer = new byte[writer.BaseStream.Position];

            writer.BaseStream.Position = 0;
            writer.BaseStream.Read(buffer, 0, buffer.Length);
            writer.Close();
            writer.Dispose();

            return buffer;
        }
开发者ID:Jonyleeson,项目名称:MCBot,代码行数:18,代码来源:MCPackets.cs

示例3: CreateArmAnimationPacket

        public static byte[] CreateArmAnimationPacket(int id, bool animate)
        {
            byte[] buffer;

            BinaryWriter writer = new BinaryWriter(new MemoryStream());

            writer.Write((byte)MCPacketOpcodes.ArmAnimation);
            writer.WriteNetwork(id);
            writer.Write(animate);

            buffer = new byte[writer.BaseStream.Position];

            writer.BaseStream.Position = 0;
            writer.BaseStream.Read(buffer, 0, buffer.Length);
            writer.Close();
            writer.Dispose();

            return buffer;
        }
开发者ID:Jonyleeson,项目名称:MCBot,代码行数:19,代码来源:MCPackets.cs

示例4: CreatePlayerPositionPacket

        public static byte[] CreatePlayerPositionPacket(double x, double y, double stance, double z, bool ground)
        {
            byte[] buffer;

            BinaryWriter writer = new BinaryWriter(new MemoryStream());

            writer.Write((byte)MCPacketOpcodes.PlayerPosition);
            writer.WriteNetwork(x);
            writer.WriteNetwork(y);
            writer.WriteNetwork(stance);
            writer.WriteNetwork(z);
            writer.Write(ground);

            buffer = new byte[writer.BaseStream.Position];

            writer.BaseStream.Position = 0;
            writer.BaseStream.Read(buffer, 0, buffer.Length);
            writer.Close();
            writer.Dispose();

            return buffer;
        }
开发者ID:Jonyleeson,项目名称:MCBot,代码行数:22,代码来源:MCPackets.cs

示例5: CreatePlayerLookPacket

        public static byte[] CreatePlayerLookPacket(float yaw, float pitch, bool ground)
        {
            byte[] buffer;

            BinaryWriter writer = new BinaryWriter(new MemoryStream());

            writer.Write((byte)MCPacketOpcodes.PlayerLook);
            writer.WriteNetwork(yaw);
            writer.WriteNetwork(pitch);
            writer.Write(ground);

            buffer = new byte[writer.BaseStream.Position];

            writer.BaseStream.Position = 0;
            writer.BaseStream.Read(buffer, 0, buffer.Length);
            writer.Close();
            writer.Dispose();

            return buffer;
        }
开发者ID:Jonyleeson,项目名称:MCBot,代码行数:20,代码来源:MCPackets.cs

示例6: CreatePlayerInventoryPacket

        public static byte[] CreatePlayerInventoryPacket(MCInventoryType type, MCItem[] items)
        {
            byte[] buffer;

            BinaryWriter writer = new BinaryWriter(new MemoryStream());

            writer.Write((byte)MCPacketOpcodes.PlayerInventory);
            writer.WriteNetwork((int)type);
            writer.WriteNetwork((short)items.Length);

            foreach (MCItem item in items)
            {
                writer.WriteNetwork((short)item.Type);

                if (item.Type != MCBlockType.None)
                {
                    writer.Write(item.Count);
                    writer.WriteNetwork(item.Health);
                }
            }

            buffer = new byte[writer.BaseStream.Position];

            writer.BaseStream.Position = 0;
            writer.BaseStream.Read(buffer, 0, buffer.Length);
            writer.Close();
            writer.Dispose();

            return buffer;
        }
开发者ID:Jonyleeson,项目名称:MCBot,代码行数:30,代码来源:MCPackets.cs

示例7: CreatePlayerHoldingPacket

        public static byte[] CreatePlayerHoldingPacket(int id, short item)
        {
            byte[] buffer;

            BinaryWriter writer = new BinaryWriter(new MemoryStream());

            writer.Write((byte)MCPacketOpcodes.HoldSwitch);
            writer.WriteNetwork(id);
            writer.WriteNetwork(item);

            buffer = new byte[writer.BaseStream.Position];

            writer.BaseStream.Position = 0;
            writer.BaseStream.Read(buffer, 0, buffer.Length);
            writer.Close();
            writer.Dispose();

            return buffer;
        }
开发者ID:Jonyleeson,项目名称:MCBot,代码行数:19,代码来源:MCPackets.cs

示例8: CreatePlayerDiggingPacket

        public static byte[] CreatePlayerDiggingPacket(byte status, int x, byte y, int z, byte face)
        {
            byte[] buffer;

            BinaryWriter writer = new BinaryWriter(new MemoryStream());

            writer.Write((byte)MCPacketOpcodes.BlockDig);
            writer.Write(status);
            writer.WriteNetwork(x);
            writer.Write(y);
            writer.WriteNetwork(z);
            writer.Write(face);

            buffer = new byte[writer.BaseStream.Position];

            writer.BaseStream.Position = 0;
            writer.BaseStream.Read(buffer, 0, buffer.Length);
            writer.Close();
            writer.Dispose();

            return buffer;
        }
开发者ID:Jonyleeson,项目名称:MCBot,代码行数:22,代码来源:MCPackets.cs

示例9: CreateLoginPacket

        public static byte[] CreateLoginPacket(string username, string password)
        {
            byte[] buffer;

            BinaryWriter writer = new BinaryWriter(new MemoryStream());

            writer.Write((byte)MCPacketOpcodes.Login);
            writer.WriteNetwork(2); // Protocol version
            writer.WriteNetwork(username);
            writer.WriteNetwork(password);

            buffer = new byte[writer.BaseStream.Position];

            writer.BaseStream.Position = 0;
            writer.BaseStream.Read(buffer, 0, buffer.Length);
            writer.Close();
            writer.Dispose();

            return buffer;
        }
开发者ID:Jonyleeson,项目名称:MCBot,代码行数:20,代码来源:MCPackets.cs


注:本文中的System.IO.BinaryWriter.WriteNetwork方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。