• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# IPacket类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



IPacket类属于命名空间,在下文中一共展示了IPacket类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: HandleLoginRequestPacket

        public static void HandleLoginRequestPacket(IPacket packet, IRemoteClient client, IMultiplayerServer server)
        {
            var loginRequestPacket = (LoginRequestPacket)packet;
            var remoteClient = (RemoteClient)client;
            if (loginRequestPacket.ProtocolVersion < server.PacketReader.ProtocolVersion)
                remoteClient.QueuePacket(new DisconnectPacket("Client outdated! Use beta 1.7.3."));
            else if (loginRequestPacket.ProtocolVersion > server.PacketReader.ProtocolVersion)
                remoteClient.QueuePacket(new DisconnectPacket("Server outdated! Use beta 1.7.3."));
            else if (server.Worlds.Count == 0)
                remoteClient.QueuePacket(new DisconnectPacket("Server has no worlds configured."));
            else if (!server.PlayerIsWhitelisted(remoteClient.Username) && server.PlayerIsBlacklisted(remoteClient.Username))
                remoteClient.QueuePacket(new DisconnectPacket("You're banned from this server"));
            else if (server.Clients.Count(c => c.Username == client.Username) > 1)
                remoteClient.QueuePacket(new DisconnectPacket("The player with this username is already logged in"));
            else
            {
                remoteClient.LoggedIn = true;
                remoteClient.Entity = new PlayerEntity(remoteClient.Username);
                remoteClient.World = server.Worlds[0];
                remoteClient.ChunkRadius = 2;

                if (!remoteClient.Load())
                    remoteClient.Entity.Position = remoteClient.World.SpawnPoint;
                // Make sure they don't spawn in the ground
                var collision = new Func<bool>(() =>
                {
                    var feet = client.World.GetBlockID((Coordinates3D)client.Entity.Position);
                    var head = client.World.GetBlockID((Coordinates3D)(client.Entity.Position + Vector3.Up));
                    var feetBox = server.BlockRepository.GetBlockProvider(feet).BoundingBox;
                    var headBox = server.BlockRepository.GetBlockProvider(head).BoundingBox;
                    return feetBox != null || headBox != null;
                });
                while (collision())
                    client.Entity.Position += Vector3.Up;

                // Send setup packets
                remoteClient.QueuePacket(new LoginResponsePacket(0, 0, Dimension.Overworld));
                remoteClient.UpdateChunks();
                remoteClient.QueuePacket(new WindowItemsPacket(0, remoteClient.Inventory.GetSlots()));
                remoteClient.QueuePacket(new SpawnPositionPacket((int)remoteClient.Entity.Position.X,
                        (int)remoteClient.Entity.Position.Y, (int)remoteClient.Entity.Position.Z));
                remoteClient.QueuePacket(new SetPlayerPositionPacket(remoteClient.Entity.Position.X,
                        remoteClient.Entity.Position.Y + 1,
                        remoteClient.Entity.Position.Y + remoteClient.Entity.Size.Height + 1,
                        remoteClient.Entity.Position.Z, remoteClient.Entity.Yaw, remoteClient.Entity.Pitch, true));
                remoteClient.QueuePacket(new TimeUpdatePacket(remoteClient.World.Time));

                // Start housekeeping for this client
                var entityManager = server.GetEntityManagerForWorld(remoteClient.World);
                entityManager.SpawnEntity(remoteClient.Entity);
                entityManager.SendEntitiesToClient(remoteClient);
                server.Scheduler.ScheduleEvent("remote.keepalive", remoteClient, TimeSpan.FromSeconds(10), remoteClient.SendKeepAlive);
                server.Scheduler.ScheduleEvent("remote.chunks", remoteClient, TimeSpan.FromSeconds(1), remoteClient.ExpandChunkRadius);

                if (!string.IsNullOrEmpty(Program.ServerConfiguration.MOTD))
                    remoteClient.SendMessage(Program.ServerConfiguration.MOTD);
                if (!Program.ServerConfiguration.Singleplayer)
                    server.SendMessage(ChatColor.Yellow + "{0} joined the server.", remoteClient.Username);
            }
        }
开发者ID:ComputeLinux,项目名称:TrueCraft,代码行数:60,代码来源:LoginHandlers.cs


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


示例4: HandleHandshakePacket

 public static void HandleHandshakePacket(IPacket packet, IRemoteClient client, IMultiplayerServer server)
 {
     var handshakePacket = (HandshakePacket) packet;
     var remoteClient = (RemoteClient)client;
     remoteClient.Username = handshakePacket.Username;
     remoteClient.QueuePacket(new HandshakeResponsePacket("-")); // TODO: Implement some form of authentication
 }
开发者ID:Zoxive,项目名称:TrueCraft,代码行数:7,代码来源:LoginHandlers.cs


示例5: Dispatch

 public void Dispatch(ISession client, IPacket packet)
 {
     client.Player.StandState = StandStates.Sitting;
     client.SendLogoutResponce();
     client.LogOut();
     client.SendLogoutComplete();
 }
开发者ID:hazzik,项目名称:uwow2,代码行数:7,代码来源:LogoutRequestDispatcher.cs


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


示例7: HandleUpdateKeyPacket

        public static void HandleUpdateKeyPacket(CoCProxy proxyServer, CoCProxyClient client, IPacket packet)
        {
            var ukPacket = packet as UpdateKeyPacket;

            client.Client.NetworkManager.UpdateCiphers((ulong)client.Client.Seed, ukPacket.Key);
            client.Server.NetworkManager.UpdateCiphers((ulong)client.Client.Seed, ukPacket.Key);
        }
开发者ID:maithanhtan,项目名称:CoCSharp,代码行数:7,代码来源:ProxyPacketHandlers.cs


示例8: WritePacket

        public void WritePacket(IPacket packet)
        {
            try
            {
                uint secs = (uint)packet.Seconds;
                uint usecs = (uint)packet.Microseconds;
                if (header.NanoSecondResolution)
                    usecs = usecs * 1000;
                uint caplen = (uint)packet.Data.Length;
                uint len = (uint)packet.Data.Length;
                byte[] data = packet.Data;

                List<byte> ret = new List<byte>();

                ret.AddRange(BitConverter.GetBytes(secs.ReverseByteOrder(header.ReverseByteOrder)));
                ret.AddRange(BitConverter.GetBytes(usecs.ReverseByteOrder(header.ReverseByteOrder)));
                ret.AddRange(BitConverter.GetBytes(caplen.ReverseByteOrder(header.ReverseByteOrder)));
                ret.AddRange(BitConverter.GetBytes(len.ReverseByteOrder(header.ReverseByteOrder)));
                ret.AddRange(data);
                if (ret.Count > header.MaximumCaptureLength)
                    throw new ArgumentOutOfRangeException(string.Format("[PcapWriter.WritePacket] packet length: {0} is greater than MaximumCaptureLength: {1}", ret.Count, header.MaximumCaptureLength));
                lock (syncRoot)
                {
                    binaryWriter.Write(ret.ToArray());
                }
            }
            catch (Exception exc)
            {
                OnException(exc);
            }
        }         
开发者ID:GemikGmbH,项目名称:PcapngUtils,代码行数:31,代码来源:PcapWriter.cs


示例9: Dispatch

        public void Dispatch(ISession session, IPacket packet)
        {
            BinaryReader reader = packet.CreateReader();
            byte castCount = reader.ReadByte();
            uint spellId = reader.ReadUInt32();
            byte unklags = reader.ReadByte();

            IPacket pkt = WorldPacketFactory.Create(WMSG.SMSG_SPELL_START);
            BinaryWriter writer = pkt.CreateWriter();
            writer.WritePackGuid(session.Player.Guid);
            writer.WritePackGuid(session.Player.Guid);
            writer.Write(castCount);
            writer.Write(spellId);
            writer.Write(0); //cast flags
            writer.Write(0); //ticks count
            writer.Write(0); //targetflags
            session.Send(pkt);

            Thread.Sleep(5000);
            pkt = WorldPacketFactory.Create(WMSG.SMSG_SPELL_GO);
            writer = pkt.CreateWriter();
            writer.WritePackGuid(session.Player.Guid);
            writer.WritePackGuid(session.Player.Guid);
            writer.Write(castCount);
            writer.Write(spellId);
            writer.Write(0); //cast flags
            writer.Write(0); //ticks count
            writer.Write((byte)1); //hit count
            writer.Write(session.Player.Guid);
            writer.Write((byte)0); //miss count
            writer.Write(0); // targetflags
            session.Send(pkt);
        }
开发者ID:hazzik,项目名称:uwow2,代码行数:33,代码来源:CastSpellDispatcher.cs


示例10: Dispatch

        public void Dispatch(ISession session, IPacket packet)
        {
            BinaryReader r = packet.CreateReader();
            uint unk1 = r.ReadUInt32();

            session.SendRealmSplitPkt(unk1);
        }
开发者ID:hazzik,项目名称:uwow2,代码行数:7,代码来源:RealmSplitDispatcher.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)
            {
                // TODO
            }
        }
开发者ID:ammaraskar,项目名称:Craft.Net,代码行数:35,代码来源:LoginHandlers.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: SendMessage

        public IAckPacket SendMessage(IPacket packet)
        {
            var packetBytes = packet.GetBytes();
            var responseBytes = _crazyradioDriver.SendData(packetBytes);

            return new AckPacket(responseBytes);
        }
开发者ID:chungInShing,项目名称:CrazyflieDotNet,代码行数:7,代码来源:CrazyflieMessenger.cs


示例14: Dispatch

        public void Dispatch(ISession session, IPacket packet)
        {
            BinaryReader reader = packet.CreateReader();
            var type = (MessageType) reader.ReadUInt32();
            uint language = reader.ReadUInt32();
            string channel = type == MessageType.Channel || type == MessageType.Whisper
                                 ? reader.ReadCString()
                                 : string.Empty;
            string message = reader.ReadCString();

            var pkt = WorldPacketFactory.Create(WMSG.SMSG_MESSAGECHAT);
            var writer = pkt.CreateWriter();
            writer.Write((byte)type);
            writer.Write((uint)0);
            writer.Write(session.Player.Guid);
            writer.Write(0);
            /*
            if (target != null)
                writer.WritePascalString(target);
            */
            writer.Write((ulong)0);
            writer.WritePascalString(message);
            writer.Write((byte)0);

            var players = ObjectManager.GetPlayersNear(session.Player);
            foreach (var player in players)
            {
                player.Session.Send(pkt);
            }

            Console.WriteLine("{0} {1} {2} {3}", type, language, channel, message);
        }
开发者ID:hazzik,项目名称:uwow2,代码行数:32,代码来源:MessageChat.cs


示例15: Dispatch

        public void Dispatch(ISession session, IPacket packet)
        {
            BinaryReader reader = packet.CreateReader();
            int guildId = reader.ReadInt32();
            var guild = new Guild
                            {
                                Id = guildId,
                                Name = "guild"
                            };

            IPacketBuilder responce = WorldPacketFactory.Build(
                WMSG.SMSG_GUILD_QUERY_RESPONSE,
                writer =>
                    {
                        writer.Write(guild.Id);
                        writer.WriteCString(guild.Name);
                        foreach (GuildRank rank in guild.Ranks)
                            writer.WriteCString(rank.Name);
                        for (int i = 0; i < 10 - guild.Ranks.Count; i++)
                            writer.WriteCString(string.Empty);
                        writer.Write(guild.Tabard.EmblemStyle);
                        writer.Write(guild.Tabard.EmblemColor);
                        writer.Write(guild.Tabard.BorderStyle);
                        writer.Write(guild.Tabard.BorderColor);
                        writer.Write(guild.Tabard.BackgroundColor);
                        writer.Write(0); // NEW 3.0.2
                    });
            session.Send(responce);
        }
开发者ID:hazzik,项目名称:uwow2,代码行数:29,代码来源:GuildQuery.cs


示例16: OnReadPacket

 private void OnReadPacket(IPacket packet)
 {
     Contract.Requires<ArgumentNullException>(packet != null, "packet cannot be null");
     CommonDelegates.ReadPacketEventDelegate handler = OnReadPacketEvent;
     if (handler != null)
         handler(this.headersWithInterface.Last(), packet);
 }
开发者ID:GemikGmbH,项目名称:PcapngUtils,代码行数:7,代码来源:PcapNGReader.cs


示例17: CreateData

        public static byte[] CreateData(IPacket packet)
        {
            if (packet == null)
                throw new ArgumentNullException("packet");

            var content = packet.GetContent();
            var idLengthContent = new byte[content.Length + PacketIdFieldWidth + ContentLengthFieldWidth];

            idLengthContent[0] = (byte)packet.Id;

            var contentLength = BitConverter.GetBytes(content.Length);
            idLengthContent[1] = contentLength[0]; // Not in the mood for a for loop
            idLengthContent[2] = contentLength[1];
            idLengthContent[3] = contentLength[2];
            idLengthContent[4] = contentLength[3];

            for (int i = (PacketIdFieldWidth + ContentLengthFieldWidth); i < idLengthContent.Length; ++i)
                idLengthContent[i] = content[i - (PacketIdFieldWidth + ContentLengthFieldWidth)];

            byte[] checksum;
            using (var provider = new Crc32())
                checksum = provider.ComputeHash(idLengthContent, 0, idLengthContent.Length);

            using (var ms = new MemoryStream())
            {
                ms.Write(checksum, 0, ChecksumWidth);
                ms.Write(idLengthContent, 0, idLengthContent.Length);
                return ms.ToArray();
            }
        }
开发者ID:nikeee,项目名称:NetDiscovery,代码行数:30,代码来源:PacketHandler.cs


示例18: SendPacket

        public async Task SendPacket(IPacket packet, Stream netStream)
        {
            var ms = new MemoryStream();
            var bw = new BinaryWriter(ms);

            if (packet is IAutoSerializePacket)
                (packet as IAutoSerializePacket).AutoSerialize(bw);
            else
            {
                bw.Write(packet.ID);
                packet.SerializePacket(bw);
            }

            bw.Flush();

            // Copy ms -> redirect writer to new ms -> prepend packet size prefix -> append packet paylod
            FinalizePacket(ref bw);
            ms.Dispose(); // Dispose of expired ms, writer's basestream is created in FinalizePacket
            ms = bw.BaseStream as MemoryStream;
            // this here failed? ye wait a moment
            await netStream.WriteAsync(ms.ToArray(), 0, (int)ms.Length);

            if (OnPacketSent != null)
                OnPacketSent(null, new PacketEventArgs(null, packet, (int)ms.Length));

            ms.Dispose();
            bw.Dispose();

        }
开发者ID:Numbers11,项目名称:uNet,代码行数:29,代码来源:PacketProcessor.cs


示例19: HandleOwnHomeDataPacket

 public static void HandleOwnHomeDataPacket(CoCProxy proxyServer, CoCProxyClient client, IPacket packet)
 {
     var ohPacket = packet as OwnHomeDataPacket;
     client.Client.Username = ohPacket.Avatar.Username;
     client.Client.UserID = ohPacket.UserID;
     client.Client.Home = ohPacket.Home;
 }
开发者ID:maithanhtan,项目名称:CoCSharp,代码行数:7,代码来源:ProxyPacketHandlers.cs


示例20: KeepAlive

 public static void KeepAlive(MinecraftClient client, MinecraftServer server, IPacket _packet)
 {
     var packet = (KeepAlivePacket)_packet;
     // TODO: Confirm value validity
     client.LastKeepAlive = DateTime.Now;
     client.Ping = (short)(client.LastKeepAlive - client.LastKeepAliveSent).TotalMilliseconds;
 }
开发者ID:skirmish,项目名称:Craft.Net,代码行数:7,代码来源:PacketHandlers.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# IPacketGCMsg类代码示例发布时间:2022-05-24
下一篇:
C# IPackageTree类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap