示例#1
0
        private void SpawnClone(string[] args, int length, string full, Client client)
        {
            // Temporary haxifications to pull your own connection
            string name       = args[1].Trim('\"');
            string playerName = args[2].Trim('\"');
            float  x          = float.Parse(args[3]);
            float  y          = float.Parse(args[4]);
            float  z          = float.Parse(args[5]);

            if (client == null)
            {
                int  ID          = 0;
                bool foundPlayer = false;

                // Find the player
                ID = Helper.FindPlayerByUsername(name);
                if (ID != -1)
                {
                    foundPlayer = true;
                }

                // Couldn't find the username
                if (!foundPlayer)
                {
                    Logger.WriteError("[CMD] Could not find user " + name);
                    return;
                }

                client = PolarisApp.Instance.server.Clients[ID];
            }

            // Default coordinates
            if (x == 0)
            {
                x = -0.417969f;
            }
            if (y == 0)
            {
                y = 0.000031f;
            }
            if (z == 0)
            {
                z = 134.375f;
            }

            var fakePlayer = new Database.Player();

            fakePlayer.Username = name;
            fakePlayer.Nickname = playerName;
            fakePlayer.PlayerID = 12345678 + new Random().Next();

            var fakeChar = new Character();

            fakeChar.CharacterID = 12345678 + new Random().Next();
            fakeChar.Player      = fakePlayer;
            fakeChar.Name        = playerName;

            fakeChar.Looks = client.Character.Looks;
            fakeChar.Jobs  = client.Character.Jobs;

            var fakePacket = new Packets.CharacterSpawnPacket(fakeChar);

            fakePacket.Position.facingAngle = 0f;
            fakePacket.Position.x           = x;
            fakePacket.Position.y           = y;
            fakePacket.Position.z           = z;
            fakePacket.IsItMe = false;
            client.SendPacket(fakePacket);

            Logger.WriteCommand(client, "[CMD] Spawned a clone of {0} named {1}", name, playerName);
        }
示例#2
0
        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));
            }
        }
示例#3
0
        private void SpawnClone(string[] args, int length, string full, Client client)
        {
            // Temporary haxifications to pull your own connection
            var name = args[1].Trim('\"');
            var playerName = args[2].Trim('\"');
            var x = float.Parse(args[3]);
            var y = float.Parse(args[4]);
            var z = float.Parse(args[5]);

            if (client == null)
            {
                var foundPlayer = false;

                // Find the player
                var id = Helper.FindPlayerByUsername(name);
                if (id != -1)
                    foundPlayer = true;

                // Couldn't find the username
                if (!foundPlayer)
                {
                    Logger.WriteError("[CMD] Could not find user " + name);
                    return;
                }

                client = PolarisApp.Instance.Server.Clients[id];
            }

            // Default coordinates
            if (x == 0)
                x = -0.417969f;
            if (y == 0)
                y = 0.000031f;
            if (z == 0)
                z = 134.375f;

            var fakePlayer = new Player
            {
                Username = name,
                Nickname = playerName,
                PlayerId = (12345678 + new Random().Next())
            };

            var fakeChar = new Character
            {
                CharacterId = 12345678 + new Random().Next(),
                Player = fakePlayer,
                Name = playerName,
                Looks = client.Character.Looks,
                Jobs = client.Character.Jobs
            };

            var fakePacket = new CharacterSpawnPacket(fakeChar, new PSOLocation(0f, 1f, 0f, 0f, x, y, z))
            {
                IsItMe = false
            };
            client.SendPacket(fakePacket);

            Logger.WriteCommand(client, "[CMD] Spawned a clone of {0} named {1}", name, playerName);
        }