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


C# PacketWriter.WriteUtf16方法代码示例

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


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

示例1: HandlePacket

        public override void HandlePacket(Client context, byte flags, byte[] data, uint position, uint size)
        {
            if (context.Character == null)
                return;

            var reader = new PacketReader(data, position, size);
            reader.BaseStream.Seek(0xC, SeekOrigin.Begin);
            var channel = reader.ReadUInt32();
            var message = reader.ReadUtf16(0x9D3F, 0x44);

            if (message.StartsWith(PolarisApp.Config.CommandPrefix))
            {
                var valid = false;

                // Iterate commands
                foreach (var command in PolarisApp.ConsoleSystem.Commands)
                {
                    var full = message.Substring(1); // Strip the command chars
                    var args = full.Split(' ');

                    if (command.Names.Any(name => args[0].ToLower() == name.ToLower()))
                    {
                        command.Run(args, args.Length, full, context);
                        valid = true;
                        Logger.WriteCommand(null, "[CMD] {0} issued command {1}", context.User.Username, full);
                    }

                    if (valid)
                        break;
                }

                if (!valid)
                    Logger.WriteClient(context, "[CMD] {0} - Command not found", message.Split(' ')[0].Trim('\r'));
            }
            else
            {
                Logger.Write("[CHT] <{0}> <{1}>", context.Character.Name, message);

                var writer = new PacketWriter();
                writer.WritePlayerHeader((uint) context.User.PlayerId);
                writer.Write(channel);
                writer.WriteUtf16(message, 0x9D3F, 0x44);

                data = writer.ToArray();

                foreach (var c in Server.Instance.Clients)
                {
                    if (c.Character == null || c.CurrentZone != context.CurrentZone)
                        continue;

                    c.SendPacket(0x07, 0x00, 0x44, data);
                }
            }
        }
开发者ID:Zenohate,项目名称:PolarisServer,代码行数:54,代码来源:ChatHandler.cs

示例2: 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(0x114, 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
                var resp = new PacketWriter();
                resp.Write((uint)((user == null) ? 1 : 0)); // Status flag: 0=success, 1=error
                resp.WriteUtf16(error, 0x8BA4, 0xB6);

                if (user == null)
                {
                    for (var i = 0; i < 0xEC; i++)
                        resp.Write((byte)0);
                    context.SendPacket(0x11, 1, 4, resp.ToArray());
                    return;
                }

                resp.Write((uint)user.PlayerId); // Player ID
                resp.Write((uint)0); // Unknown
                resp.Write((uint)0); // Unknown
                resp.WriteFixedLengthUtf16("B001-DarkFox", 0x20);
                for (var i = 0; i < 0xBC; i++)
                    resp.Write((byte)0);

                context.SendPacket(0x11, 1, 4, resp.ToArray());

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

                context.User = user;

            }
//.........这里部分代码省略.........
开发者ID:Zenohate,项目名称:PolarisServer,代码行数:101,代码来源:Login.cs


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