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


C# MinecraftClient.SendPacket方法代码示例

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


在下文中一共展示了MinecraftClient.SendPacket方法的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: Handshake

 public static void Handshake(MinecraftClient client, MinecraftServer server, IPacket _packet)
 {
     var packet = (HandshakePacket)_packet;
     if (packet.ProtocolVersion < PacketReader.ProtocolVersion)
     {
         client.SendPacket(new DisconnectPacket("Outdated client!"));
         return;
     }
     if (packet.ProtocolVersion > PacketReader.ProtocolVersion)
     {
         client.SendPacket(new DisconnectPacket("Outdated server!"));
         return;
     }
     if (server.Clients.Any(c => c.Username == packet.Username))
     {
         client.SendPacket(new DisconnectPacket(""));
         return;
     }
     client.Username = packet.Username;
     client.Hostname = packet.ServerHostname + ":" + packet.ServerPort;
     if (server.Settings.OnlineMode)
         client.AuthenticationHash = CreateHash();
     else
         client.AuthenticationHash = "-";
     if (server.Settings.EnableEncryption)
         client.SendPacket(CreateEncryptionRequest(client, server));
     else
         server.LogInPlayer(client);
 }
开发者ID:cpancake,项目名称:Craft.Net,代码行数:29,代码来源:LoginHandlers.cs

示例3: HandlePacket

        public override void HandlePacket(MinecraftServer server, MinecraftClient client)
        {
            switch (ClientStatus)
            {
                case 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);
                    break;
                case ClientStatus.Respawn:
                    var world = client.World;
                    client.Entity.Position = new Vector3(
                        client.Entity.SpawnPoint.X,
                        client.Entity.SpawnPoint.Y + PlayerEntity.Height,
                        client.Entity.SpawnPoint.Z);
                    client.Entity.Health = client.Entity.MaxHealth;
                    client.Entity.Food = 20;
                    client.Entity.FoodSaturation = 20;
                    server.EntityManager.SpawnEntity(world, client.Entity);
                    client.SendPacket(new UpdateHealthPacket(client.Entity.Health, client.Entity.Food, client.Entity.FoodSaturation));
                    client.SendPacket(new RespawnPacket(Dimension.Overworld, server.Settings.Difficulty,
                        client.Entity.GameMode, world.LevelType));
                    client.SendPacket(new PlayerPositionAndLookPacket(
                                  client.Entity.Position, client.Entity.Yaw, client.Entity.Pitch, true));
                    server.ProcessSendQueue();
                    break;
                default:
                    throw new InvalidOperationException();
            }
        }
开发者ID:Imperceptus,项目名称:Craft.Net,代码行数:51,代码来源:ClientStatusPacket.cs

示例4: 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

示例5: 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

示例6: HandlePacket

        public override void HandlePacket(MinecraftServer Server, ref MinecraftClient Client)
        {
            Client.SharedKey = Server.CryptoServiceProvider.Decrypt(SharedSecret, false);

            Client.Encrypter = Cryptography.GenerateAES(Client.SharedKey).CreateEncryptor();

            Client.Decrypter = Cryptography.GenerateAES(Client.SharedKey).CreateDecryptor();

            Client.SendPacket(new EncryptionKeyResponsePacket());
            Server.ProcessSendQueue();
        }
开发者ID:keneo,项目名称:Craft.Net,代码行数:11,代码来源:EncryptionKeyResponsePacket.cs

示例7: PlayerPositionAndLook

 public static void PlayerPositionAndLook(MinecraftClient client, IPacket _packet)
 {
     var packet = (PlayerPositionAndLookPacket)_packet;
     client._position = new Vector3(packet.X, packet.Stance, packet.Z);
     if (!client.IsSpawned)
     {
         client.IsSpawned = true;
         client.OnInitialSpawn(new EntitySpawnEventArgs(client.Position, client.EntityId));
     }
     
     client.SendPacket(new PlayerPositionPacket(packet.X, packet.Stance, packet.Z, packet.Y, true));
 }
开发者ID:seaboy1234,项目名称:Craft.Net,代码行数:12,代码来源:EntityHandlers.cs

示例8: HandlePacket

        public override void HandlePacket(MinecraftServer server, MinecraftClient client)
        {
            if (ProtocolVersion < MinecraftServer.ProtocolVersion)
            {
                client.SendPacket(new DisconnectPacket("Outdated client!"));
                server.ProcessSendQueue();
                return;
            }
            if (ProtocolVersion > MinecraftServer.ProtocolVersion)
            {
                client.SendPacket(new DisconnectPacket("Outdated server!"));
                server.ProcessSendQueue();
                return;
            }
            if (server.Clients.Count(c => c.Username == Username) != 0)
            {
                client.SendPacket(new DisconnectPacket("You are already logged in!"));
                server.ProcessSendQueue();
                return;
            }
            client.Username = Username;
            client.Hostname = Hostname + ":" + Port.ToString();
            // Respond with encryption request
            if (server.OnlineMode)
                client.AuthenticationHash = CreateHash();
            else
                client.AuthenticationHash = "-";
            if (server.EncryptionEnabled)
            {
                var keyRequest =
                    new EncryptionKeyRequestPacket(client.AuthenticationHash,
                                                   server.ServerKey);
                client.SendPacket(keyRequest);
                server.ProcessSendQueue();
            }
            else
                server.LogInPlayer(client);

            client.StartWorkers();
        }
开发者ID:pdelvo,项目名称:Craft.Net,代码行数:40,代码来源:HandshakePacket.cs

示例9: PlayerPositionAndLook

 public static void PlayerPositionAndLook(MinecraftClient client, IPacket _packet)
 {
     var packet = (PlayerPositionAndLookPacket)_packet;
     if (Math.Abs(packet.X) < 0.01 && Math.Abs(packet.X) > 0)
         return; // Sometimes the vanilla server sends weird position updates like this
     client._position = new Vector3(packet.X, packet.Y, packet.Z);
     if (!client.IsSpawned)
     {
         client.IsSpawned = true;
         client.OnInitialSpawn(new EntitySpawnEventArgs(client.Position, client.EntityId));
     }
     client.SendPacket(new PlayerPositionPacket(client.Position.X, client.Position.Y, client.Position.Z, client.Position.Y - 1.62, true));
 }
开发者ID:kaltinril,项目名称:Craft.Net,代码行数:13,代码来源:EntityHandlers.cs

示例10: HandlePacket

        public override void HandlePacket(MinecraftServer server, MinecraftClient client)
        {
            client.SharedKey = server.CryptoServiceProvider.Decrypt(SharedSecret, false);

            client.Encrypter = new BufferedBlockCipher(new CfbBlockCipher(new AesFastEngine(), 8));
            client.Encrypter.Init(true,
                                  new ParametersWithIV(new KeyParameter(client.SharedKey), client.SharedKey, 0, 16));

            client.Decrypter = new BufferedBlockCipher(new CfbBlockCipher(new AesFastEngine(), 8));
            client.Decrypter.Init(false,
                                  new ParametersWithIV(new KeyParameter(client.SharedKey), client.SharedKey, 0, 16));

            client.SendPacket(new EncryptionKeyResponsePacket());
            server.ProcessSendQueue();
        }
开发者ID:Imperceptus,项目名称:Craft.Net,代码行数:15,代码来源:EncryptionKeyResponsePacket.cs

示例11: 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)
            {
                var world = client.World;
                client.Entity.Position = new Vector3(
                    client.Entity.SpawnPoint.X,
                    // FIXME: This seems to drop the player camera from half the height of a login spawn
                    client.Entity.SpawnPoint.Y,
                    client.Entity.SpawnPoint.Z);
                client.Entity.Health = client.Entity.MaxHealth;
                client.Entity.Food = 20;
                client.Entity.FoodSaturation = 20;
                server.EntityManager.SpawnEntity(world, client.Entity);
                client.SendPacket(new UpdateHealthPacket(client.Entity.Health, client.Entity.Food, client.Entity.FoodSaturation));
                client.SendPacket(new RespawnPacket(Dimension.Overworld, server.Settings.Difficulty, client.Entity.GameMode, World.Height, world.LevelType));
                client.SendPacket(new PlayerPositionAndLookPacket(client.Entity.Position.X, client.Entity.Position.Y, client.Entity.Position.Z,
                    client.Entity.Position.Y + PlayerEntity.Height, client.Entity.Yaw, client.Entity.Pitch, true));
            }
        }
开发者ID:seaboy1234,项目名称:Craft.Net,代码行数:48,代码来源:LoginHandlers.cs

示例12: HandlePacket

 public override void HandlePacket(MinecraftServer server, MinecraftClient client)
 {
     if (!client.ReadyToSpawn)
         return;
     client.Entity.Position = new Vector3(X, Y, Z);
     if (client.Entity.Position.DistanceTo(client.Entity.OldPosition) >
         client.MaxMoveDistance)
     {
         client.SendPacket(new DisconnectPacket("Hacking: You moved too fast!"));
         server.ProcessSendQueue();
         return;
     }
     client.UpdateChunksAsync();
     server.ProcessSendQueue();
     server.EntityManager.UpdateEntity(client.Entity);
 }
开发者ID:pdelvo,项目名称:Craft.Net,代码行数:16,代码来源:PlayerPositionPacket.cs

示例13: HandlePacket

 public override void HandlePacket(MinecraftServer Server, ref MinecraftClient Client)
 {
     if (!Client.ReadyToSpawn)
         return;
     Client.Entity.Position = new Vector3(X, Y, Z);
     if (Client.Entity.Position.DistanceTo(Client.Entity.OldPosition) > 
         Client.MaxMoveDistance)
     {
         Client.SendPacket(new DisconnectPacket("Hacking: You moved too fast!"));
         Server.ProcessSendQueue();
         return;
     }
     Client.UpdateChunksAsync();
     Server.GetClientWorld(Client).EntityManager.UpdateEntity(Client.Entity);
     Server.ProcessSendQueue();
 }
开发者ID:keneo,项目名称:Craft.Net,代码行数:16,代码来源:PlayerPositionPacket.cs

示例14: HandlePacket

 public override void HandlePacket(MinecraftServer server, MinecraftClient client)
 {
     if (client.Entity.Position.DistanceTo(Position) > 6) // TODO: Use client.Reach
         return;
     var item = client.Entity.Inventory[client.Entity.SelectedSlot];
     if (item != null && item.Id == 0xFFFF)
         item.Id = 0;
     if (item != null)
     {
         item.Item.OnItemUsed(server.GetClientWorld(client), Position, AdjustByDirection(Direction), CursorPosition, client.Entity);
         if (client.Entity.GameMode != GameMode.Creative)
             client.Entity.Inventory[client.Entity.SelectedSlot].Count--;
     }
     else
     {
         client.SendPacket(new DisconnectPacket("Unrecognized item!"));
         server.ProcessSendQueue();
     }
 }
开发者ID:pdelvo,项目名称:Craft.Net,代码行数:19,代码来源:BlockPlacementPacket.cs

示例15: 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
                if (!client.Session.OnlineMode)
                    throw new AuthenticationException("Server is in online mode, but client is in offline mode.");
                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.SelectedProfile.Name) +
                    "&sessionId=" + Uri.EscapeUriString(client.Session.SessionId) +
                    "&serverId=" + Uri.EscapeUriString(hash));
                if (result != "OK")
                {
                    // TODO
                }
            }

            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);
            client.FlushPackets();
            client.NetworkManager.BaseStream = new AesStream(client.NetworkStream, client.SharedSecret);
        }
开发者ID:Bitterholz,项目名称:Craft.Net,代码行数:40,代码来源:LoginHandlers.cs


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