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


C# PacketReader.ReadFixedLengthAscii方法代码示例

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


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

示例1: HandlePacket

        public override void HandlePacket(Client context, byte flags, byte[] data, uint position, uint size)
        {
            var reader = new PacketReader(data, position, size);

            reader.BaseStream.Seek(0x2C, SeekOrigin.Current);

            var macCount = reader.ReadMagic(0x5E6, 107);
            reader.BaseStream.Seek(0x1C * macCount, SeekOrigin.Current);

            reader.BaseStream.Seek(0x138, SeekOrigin.Current);

            var username = reader.ReadFixedLengthAscii(64);
            var password = reader.ReadFixedLengthAscii(64);

            // What am I doing here even
            using (var db = new PolarisEf())
            {
                var users = from u in db.Players
                            where u.Username.ToLower().Equals(username.ToLower())
                            select u;

                var error = "";
                Player user;

                if (!users.Any())
                {
                    // Check if there is an empty field
                    if (string.IsNullOrWhiteSpace(username) || string.IsNullOrWhiteSpace(password))
                    {
                        error = "Username and password fields must not be empty.";
                        user = null;
                    }
                    // Check for special characters
                    else if (!Regex.IsMatch(username, "^[a-zA-Z0-9 ]*$", RegexOptions.IgnoreCase))
                    {
                        error = "Username must not contain special characters.\nPlease use letters and numbers only.";
                        user = null;
                    }
                    else // We're all good!
                    {
                        // Insert new player into database
                        user = new Player
                        {
                            Username = username.ToLower(),
                            Password = BCrypt.Net.BCrypt.HashPassword(password),
                            Nickname = username.ToLower(),
                            // Since we can't display the nickname prompt yet, just default it to the username
                            SettingsIni = File.ReadAllText("Resources/settings.txt")
                        };
                        db.Players.Add(user);
                        db.SaveChanges();

                        // context.SendPacket(0x11, 0x1e, 0x0, new byte[0x44]); // Request nickname
                    }
                }
                else
                {
                    user = users.First();
                    if (!BCrypt.Net.BCrypt.Verify(password, user.Password))
                    {
                        error = "Incorrect password.";
                        user = null;
                    }
                }

                /* Mystery packet
                var mystery = new PacketWriter();
                mystery.Write((uint)100);
                SendPacket(0x11, 0x49, 0, mystery.ToArray()); */

                // Login response packet

                context.SendPacket(new LoginDataPacket("Polaris Block 1", error, (user == null) ? (uint)0 : (uint)user.PlayerId));

                if (user == null)
                    return;

                // Settings packet
                var settings = new PacketWriter();
                settings.WriteAscii(user.SettingsIni, 0x54AF, 0x100);
                context.SendPacket(0x2B, 2, 4, settings.ToArray());

                context.User = user;

            }

            if (PolarisApp.Config.motd != "")
            {
                context.SendPacket(new SystemMessagePacket(PolarisApp.Config.motd, SystemMessagePacket.MessageType.AdminMessageInstant));
            }
        }
开发者ID:Joslyn-Maddie,项目名称:PolarisServer,代码行数:91,代码来源:Login.cs

示例2: ImportNPCs

        private void ImportNPCs(string[] args, int length, string full, Client client)
        {
            string zone = args[1];
            string folder = args[2];

            var packetList = Directory.GetFiles(folder);
            Array.Sort(packetList);

            List<NPC> newNPCs = new List<NPC>();
            foreach (var path in packetList)
            {
                var data = File.ReadAllBytes(path);
                PacketReader reader = new PacketReader(data);
                PacketHeader header = reader.ReadStruct<PacketHeader>();
                if (header.Type != 0x8 || header.Subtype != 0xC)
                {
                    Logger.WriteWarning("[WRN] File {0} not an NPC spawn packet, skipping.", path);
                    continue;
                }

                NPC newNPC = new NPC();
                newNPC.EntityID = (int)reader.ReadStruct<ObjectHeader>().ID;
                var pos = reader.ReadEntityPosition();
                newNPC.RotX = pos.RotX;
                newNPC.RotY = pos.RotY;
                newNPC.RotZ = pos.RotZ;
                newNPC.RotW = pos.RotW;

                newNPC.PosX = pos.PosX;
                newNPC.PosY = pos.PosY;
                newNPC.PosZ = pos.PosZ;
                reader.ReadInt16();
                newNPC.NPCName = reader.ReadFixedLengthAscii(0x20);
                newNPC.ZoneName = zone;
                newNPCs.Add(newNPC);
                Logger.WriteInternal("[NPC] Adding new NPC {0} to the database for zone {1}", newNPC.NPCName, zone);
            }

            using (var db = new PolarisEf())
            {
                db.NPCs.AddRange(newNPCs);
                db.SaveChanges();
            }
        }
开发者ID:mattkloc,项目名称:PolarisServer,代码行数:44,代码来源:ConsoleSystem.cs

示例3: ImportObjects

        private void ImportObjects(string[] args, int length, string full, Client client)
        {
            string zone = args[1];
            string folder = args[2];

            var packetList = Directory.GetFiles(folder);
            Array.Sort(packetList);

            List<GameObject> newObjects = new List<GameObject>();
            foreach (var path in packetList)
            {
                var data = File.ReadAllBytes(path);
                PacketReader reader = new PacketReader(data);
                PacketHeader header = reader.ReadStruct<PacketHeader>();
                if (header.Type != 0x8 || header.Subtype != 0xB)
                {
                    Logger.WriteWarning("[WRN] File {0} not an Object spawn packet, skipping.", path);
                    continue;
                }

                GameObject newObj = new GameObject();
                newObj.ObjectID = (int)reader.ReadStruct<ObjectHeader>().ID;
                var pos = reader.ReadEntityPosition();
                newObj.RotX = pos.RotX;
                newObj.RotY = pos.RotY;
                newObj.RotZ = pos.RotZ;
                newObj.RotW = pos.RotW;

                newObj.PosX = pos.PosX;
                newObj.PosY = pos.PosY;
                newObj.PosZ = pos.PosZ;
                reader.ReadInt16();
                newObj.ObjectName = reader.ReadFixedLengthAscii(0x2C);
                var objHeader = reader.ReadStruct<ObjectHeader>(); // Seems to always be blank...
                if (objHeader.ID != 0)
                    Logger.WriteWarning("[OBJ] It seems object {0} has a nonzero objHeader! ({1}) Investigate.", newObj.ObjectName, objHeader.ID);
                newObj.ZoneName = zone;
                var thingCount = reader.ReadUInt32();
                newObj.ObjectFlags = new byte[thingCount * 4];
                for (int i = 0; i < thingCount; i++)
                {
                    Buffer.BlockCopy(BitConverter.GetBytes(reader.ReadUInt32()), 0, newObj.ObjectFlags, i * 4, 4); // This should work
                }
                newObjects.Add(newObj);
                Logger.WriteInternal("[OBJ] Adding new Object {0} to the database for zone {1}", newObj.ObjectName, zone);
            }

            using (var db = new PolarisEf())
            {
                db.GameObjects.AddRange(newObjects);
                db.SaveChanges();
            }
        }
开发者ID:mattkloc,项目名称:PolarisServer,代码行数:53,代码来源:ConsoleSystem.cs

示例4: FromPacketBin

        internal static PSOObject FromPacketBin(byte[] v)
        {
            PacketReader reader = new PacketReader(v);
            PSOObject obj = new PSOObject();
            reader.ReadStruct<PacketHeader>(); //Skip over header
            obj.Header = reader.ReadStruct<ObjectHeader>();
            obj.Position = reader.ReadEntityPosition();
            reader.ReadUInt16(); // Seek 2
            obj.Name = reader.ReadFixedLengthAscii(0x34);
            obj.ThingFlag = reader.ReadUInt32();
            uint thingCount = reader.ReadUInt32();
            obj.Things = new PSOObjectThing[thingCount];
            for (int i = 0; i < thingCount; i++)
            {
                obj.Things[i] = reader.ReadStruct<PSOObjectThing>();
            }

            return obj;
        }
开发者ID:ChowZenki,项目名称:PolarisServer,代码行数:19,代码来源:PSOObject.cs


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