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


C# MinecraftClient类代码示例

本文整理汇总了C#中MinecraftClient的典型用法代码示例。如果您正苦于以下问题:C# MinecraftClient类的具体用法?C# MinecraftClient怎么用?C# MinecraftClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: EncryptionKeyRequest

        public static void EncryptionKeyRequest(MinecraftClient client, IPacket _packet)
        {
            var packet = (EncryptionKeyRequestPacket)_packet;
            var random = RandomNumberGenerator.Create();
            client.SharedSecret = new byte[16];
            random.GetBytes(client.SharedSecret); // Generate a secure AES key

            if (packet.ServerId != "-") // Online mode
            {
                // Authenticate with minecraft.net
                var data = Encoding.ASCII.GetBytes(packet.ServerId)
                    .Concat(client.SharedSecret)
                    .Concat(packet.PublicKey).ToArray();
                var hash = Cryptography.JavaHexDigest(data);
                var webClient = new WebClient();
                string result = webClient.DownloadString("http://session.minecraft.net/game/joinserver.jsp?user=" +
                    Uri.EscapeUriString(client.Session.Username) +
                    "&sessionId=" + Uri.EscapeUriString(client.Session.SessionId) +
                    "&serverId=" + Uri.EscapeUriString(hash));
                if (result != "OK")
                    LogProvider.Log("Unable to verify session: " + result);
            }

            var parser = new AsnKeyParser(packet.PublicKey);
            var key = parser.ParseRSAPublicKey();

            // Encrypt shared secret and verification token
            var crypto = new RSACryptoServiceProvider();
            crypto.ImportParameters(key);
            var encryptedSharedSecret = crypto.Encrypt(client.SharedSecret, false);
            var encryptedVerification = crypto.Encrypt(packet.VerificationToken, false);
            var response = new EncryptionKeyResponsePacket(encryptedSharedSecret, encryptedVerification);
            client.SendPacket(response);
        }
开发者ID:schwarzeszeux,项目名称:Craft.Net,代码行数:34,代码来源:LoginHandlers.cs

示例2: HandlePacket

 public override void HandlePacket(MinecraftServer Server, ref MinecraftClient Client)
 {
     if (!Client.ReadyToSpawn)
         return;
     Client.Entity.Pitch = Pitch;
     Client.Entity.Yaw = Yaw;
 }
开发者ID:keneo,项目名称:Craft.Net,代码行数:7,代码来源:PlayerLookPacket.cs

示例3: SendPacket

 public override void SendPacket(MinecraftServer server, MinecraftClient client)
 {
     client.SendData(CreateBuffer(
         DataUtility.CreateInt32(EntityId),
         DataUtility.CreateInt16(SlotIndex),
         Item.GetData()));
 }
开发者ID:Imperceptus,项目名称:Craft.Net,代码行数:7,代码来源:EntityEquipmentPacket.cs

示例4: HandlePacket

 public override void HandlePacket(MinecraftServer Server, ref MinecraftClient Client)
 {
     switch (Action)
     {
         case EntityAction.Crouch:
             Client.IsCrouching = true;
             break;
         case EntityAction.Uncrouch:
             Client.IsCrouching = false;
             break;
         case EntityAction.StartSprinting:
             Client.IsSprinting = true;
             break;
         case EntityAction.StopSprinting:
             Client.IsSprinting = false;
             break;
     }
     if (Action != EntityAction.LeaveBed) // NOTE: Does this matter?
     {
         this.EntityId = Client.Entity.Id;
         for (int i = 0; i < 
              Server.GetClientsInWorld(Server.GetClientWorld(Client)).Count(); i++)
         {
             if (Server.Clients [i] != Client)
                 Server.Clients [i].SendPacket(this);
         }
         Server.ProcessSendQueue();
     }
 }
开发者ID:keneo,项目名称:Craft.Net,代码行数:29,代码来源:EntityActionPacket.cs

示例5: EntityAction

 public static void EntityAction(MinecraftClient client, MinecraftServer server, IPacket _packet)
 {
     var packet = (EntityActionPacket)_packet;
     switch (packet.Action)
     {
         case EntityActionPacket.EntityAction.Crouch:
             client.Entity.IsCrouching = true;
             break;
         case EntityActionPacket.EntityAction.Uncrouch:
             client.Entity.IsCrouching = false;
             break;
         case EntityActionPacket.EntityAction.StartSprinting:
             client.Entity.IsSprinting = true;
             break;
         case EntityActionPacket.EntityAction.StopSprinting:
             client.Entity.IsSprinting = false;
             break;
         case EntityActionPacket.EntityAction.LeaveBed:
             client.Entity.LeaveBed();
             break;
     }
     if (packet.Action != EntityActionPacket.EntityAction.LeaveBed) // NOTE: Does this matter?
     {
         // TODO ?
     }
 }
开发者ID:ammaraskar,项目名称:Craft.Net,代码行数:26,代码来源:PlayerMovementHandlers.cs

示例6: SendPacket

 public override void SendPacket(MinecraftServer server, MinecraftClient client)
 {
     byte[] payload = new byte[] { PacketId, (byte)EntityIds.Length };
     foreach (int id in EntityIds)
         payload = payload.Concat(DataUtility.CreateInt32(id)).ToArray();
     client.SendData(payload);
 }
开发者ID:pdelvo,项目名称:Craft.Net,代码行数:7,代码来源:DestroyEntityPacket.cs

示例7: AddChunk

        private static void AddChunk(MinecraftClient client, int x, int z, ushort primaryBitMap, ushort addBitMap, bool lightIncluded, bool groundUp, byte[] data)
        {
            var coordinates = new Coordinates2D(x, z);
            var relativePosition = GetRelativeChunkPosition(coordinates);
            var chunk = new Chunk(relativePosition);
            var sectionCount = GetSectionCount(primaryBitMap);

            // Run through the sections
            // TODO: Support block IDs >255
            for (int y = 0; y < 16; y++)
            {
                if ((primaryBitMap & (1 << y)) > 0)
                {
                    // Blocks
                    Array.Copy(data, y * BlockDataLength, chunk.Sections[y].Blocks, 0, BlockDataLength);
                    // Metadata
                    Array.Copy(data, (BlockDataLength * sectionCount) + (y * NibbleDataLength),
                        chunk.Sections[y].Metadata.Data, 0, NibbleDataLength);
                    // Light
                    Array.Copy(data, ((BlockDataLength + NibbleDataLength) * sectionCount) + (y * NibbleDataLength),
                        chunk.Sections[y].BlockLight.Data, 0, NibbleDataLength);
                    // Sky light
                    if (lightIncluded)
                    {
                        Array.Copy(data, ((BlockDataLength + NibbleDataLength + NibbleDataLength) * sectionCount) + (y * NibbleDataLength),
                            chunk.Sections[y].SkyLight.Data, 0, NibbleDataLength);
                    }
                }
            }
            if (groundUp)
                Array.Copy(data, data.Length - chunk.Biomes.Length, chunk.Biomes, 0, chunk.Biomes.Length);
            client.World.SetChunk(coordinates, chunk);
            //client.OnChunkRecieved(new ChunkRecievedEventArgs(position, new ReadOnlyChunk(chunk)));
        }
开发者ID:kaltinril,项目名称:Craft.Net,代码行数:34,代码来源:WorldHandlers.cs

示例8: EncryptionKeyResponse

 public static void EncryptionKeyResponse(MinecraftClient client, IPacket _packet)
 {
     // Enable encryption
     client.Stream = new MinecraftStream(new AesStream(new BufferedStream(client.NetworkStream), client.SharedSecret));
     client.SendPacket(new ClientStatusPacket(ClientStatusPacket.ClientStatus.InitialSpawn));
     LogProvider.Log("Logged in.");
 }
开发者ID:schwarzeszeux,项目名称:Craft.Net,代码行数:7,代码来源:LoginHandlers.cs

示例9: SendPacket

        public override void SendPacket(MinecraftServer server, MinecraftClient client)
        {
            // TODO: Refactor like mad
            var buffer = new List<byte>();
            buffer.Add(PacketId);
            buffer.AddRange(DataUtility.CreateInt32(Item.Id));
            if (Item.Item.Empty)
                buffer.AddRange(DataUtility.CreateInt16(-1));
            else
            {
                buffer.AddRange(DataUtility.CreateInt16((short)Item.Item.Id)); // TODO: Make slots use signed shorts
                buffer.Add(Item.Item.Count);
                buffer.AddRange(DataUtility.CreateInt16((short)Item.Item.Metadata));
                buffer.AddRange(DataUtility.CreateInt16(-1)); // TODO: Nbt appears to be sent here
            }

            buffer.AddRange(DataUtility.CreateAbsoluteInteger(Item.Position.X));
            buffer.AddRange(DataUtility.CreateAbsoluteInteger(Item.Position.Y));
            buffer.AddRange(DataUtility.CreateAbsoluteInteger(Item.Position.Z));
            buffer.AddRange(DataUtility.CreatePackedByte(Item.Pitch));
            buffer.AddRange(DataUtility.CreatePackedByte(Item.Pitch));
            buffer.AddRange(DataUtility.CreatePackedByte(Item.Yaw));

            client.SendData(buffer.ToArray());
        }
开发者ID:Imperceptus,项目名称:Craft.Net,代码行数:25,代码来源:SpawnDroppedItemPacket.cs

示例10: ClientStatus

        public static void ClientStatus(MinecraftClient client, MinecraftServer server, IPacket _packet)
        {
            var packet = (ClientStatusPacket)_packet;
            if (packet.Status == ClientStatusPacket.ClientStatus.InitialSpawn)
            {
                // Create a hash for session verification
                SHA1 sha1 = SHA1.Create();
                AsnKeyBuilder.AsnMessage encodedKey = AsnKeyBuilder.PublicKeyToX509(server.ServerKey);
                byte[] shaData = Encoding.UTF8.GetBytes(client.AuthenticationHash)
                    .Concat(client.SharedKey)
                    .Concat(encodedKey.GetBytes()).ToArray();
                string hash = Cryptography.JavaHexDigest(shaData);

                // Talk to session.minecraft.net
                if (server.Settings.OnlineMode)
                {
                    var webClient = new WebClient();
                    var webReader = new StreamReader(webClient.OpenRead(
                        new Uri(string.Format(sessionCheckUri, client.Username, hash))));
                    string response = webReader.ReadToEnd();
                    webReader.Close();
                    if (response != "YES")
                    {
                        client.SendPacket(new DisconnectPacket("Failed to verify username!"));
                        return;
                    }
                }

                server.LogInPlayer(client);
            }
            else if (packet.Status == ClientStatusPacket.ClientStatus.Respawn)
            {
                // TODO
            }
        }
开发者ID:ammaraskar,项目名称:Craft.Net,代码行数:35,代码来源:LoginHandlers.cs

示例11: SendPacket

 public override void SendPacket(MinecraftServer server, MinecraftClient client)
 {
     client.SendData(CreateBuffer(
         DataUtility.CreateInt32((int)SpawnPosition.X),
         DataUtility.CreateInt32((int)SpawnPosition.Y),
         DataUtility.CreateInt32((int)SpawnPosition.Z)));
 }
开发者ID:Imperceptus,项目名称:Craft.Net,代码行数:7,代码来源:SpawnPositionPacket.cs

示例12: BlockChange

 public static void BlockChange(MinecraftClient client, IPacket _packet)
 {
   var packet = (BlockChangePacket)_packet;
   var position = new Coordinates3D(packet.X, packet.Y, packet.Z);
   client.World.SetBlockId(position, (short)packet.BlockType);
   client.World.SetMetadata(position, packet.BlockMetadata);
 }
开发者ID:Booser,项目名称:Craft.Net,代码行数:7,代码来源:WorldHandlers.cs

示例13: SendPacket

 public override void SendPacket(MinecraftServer server, MinecraftClient client)
 {
     client.SendData(CreateBuffer(
         DataUtility.CreateString(PlayerName),
         DataUtility.CreateBoolean(Online),
         DataUtility.CreateInt16(Ping)));
 }
开发者ID:Imperceptus,项目名称:Craft.Net,代码行数:7,代码来源:PlayerListItemPacket.cs

示例14: HandlePacket

 public override void HandlePacket(MinecraftServer server, MinecraftClient client)
 {
     if (!client.ReadyToSpawn)
         return;
     client.Entity.Pitch = Pitch;
     client.Entity.Yaw = Yaw;
 }
开发者ID:Imperceptus,项目名称:Craft.Net,代码行数:7,代码来源:PlayerLookPacket.cs

示例15: ChatMessage

        public static void ChatMessage(MinecraftClient client, IPacket _packet)
        {
            var packet = (ChatMessagePacket)_packet;
            LogProvider.Log(packet.Message, LogImportance.High);

            client.OnChatMessage(new ChatMessageEventArgs(packet.Message, RemoveChatCodes(packet.Message)));
        }
开发者ID:seaboy1234,项目名称:Craft.Net,代码行数:7,代码来源:ChatHandler.cs


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