CharacterExists() public method

Does a character of this ID exist?
public CharacterExists ( long id, bool notRaw ) : bool
id long The ID of the supposed character.
notRaw bool Is this not raw?
return bool
        public override void Handle(BinaryReader reader, LuClient client)
        {
            using (var database = new DbUtils())
            {
                // Read packet
                var objectId = reader.ReadInt64();
                var newName = reader.ReadWString(66);

                // Gather info
                var account = database.GetAccount(client.Username);
                var character = database.GetCharacter(objectId, true);

                Console.WriteLine(
                    $"Got character rename request from {client.Username}. Old name: {character.Name}. New name: {newName}");

                using (var bitStream = new WBitStream()) // Create packet
                {
                    // Always write packet header
                    bitStream.WriteHeader(RemoteConnection.Client, (uint) MsgClientCharacterRenameResponse);

                    // Make sure they own the accounta
                    if (
                        !string.Equals(account.Username, character.Name,
                            StringComparison.CurrentCultureIgnoreCase))
                    {
                        Console.WriteLine("Failed to rename character: You can't rename someone else!");
                        bitStream.Write((byte) 0x01); // Fail code
                    }
                    else if (database.CharacterExists(newName)) // Make sure nobody already has that name
                    {
                        bitStream.Write((byte) 0x03); // Code for username taken
                        Console.WriteLine("Failed to rename character: Name already taken.");
                    }
                    else // Good to go!
                    {
                        try
                        {
                            character.Name = newName; // Set their new name
                            database.UpdateCharacter(character); // Update the character
                            bitStream.Write((byte) 0x00); // Success code, everything worked just fine.
                            Console.WriteLine("Successfully renamed character!");
                        }
                        catch (Exception exception)
                        {
                            Console.WriteLine($"Error while trying to rename user - {exception}");
                            bitStream.Write(0x01); // Some error?
                        }
                    }

                    // Send the packet
                    WorldServer.Server.Send(bitStream, WPacketPriority.SystemPriority,
                        WPacketReliability.ReliableOrdered, 0, client.Address, false);
                }
            }
        }
        public static void Command()
        {
            while (!Environment.HasShutdownStarted)
            {
                var input = ReadLine();
                if (string.IsNullOrWhiteSpace(input)) continue;
                var split = input.Split(new[] { ' ' }, 2);
                var cmd = split[0].ToLower();
                var cmdArgs = split.Length > 1 ? split[1].Split(' ') : null;
                using (var database = new DbUtils())
                    switch (cmd)
                    {
                        case "help":
                            WriteLine("addaccount <username> <password>");
                            WriteLine("removeaccount <username>");
                            WriteLine("accountexists <username>");
                            WriteLine("ban <username>");
                            WriteLine("unban <username>");
                            WriteLine("printinfo <a for account, anything else for character> <username> [clipboard]");
                            WriteLine("deletecharacter <username>");
                            break;
                        case "deletecharacter":
                            if (cmdArgs?.Length >= 1)
                            {
                                var name = cmdArgs[0];
                                if (!database.CharacterExists(name))
                                {
                                    WriteLine("Character does not exist.");
                                    continue;
                                }

                                database.DeleteCharacter(database.GetCharacter(name));

                                WriteLine("Success!");
                                continue;
                            }

                            WriteLine("Invalid Arguments");
                            break;
                        case "printinfo":
                            if (cmdArgs?.Length >= 2)
                            {
                                var type = cmdArgs[0];
                                var username = cmdArgs[1];
                                if (type == "a" && !database.AccountExists(username))
                                {
                                    WriteLine("Account does not exist.");
                                    continue;
                                }
                                else if (type != "a" && !database.CharacterExists(username))
                                {
                                    WriteLine("Character does not exist!");
                                    continue;
                                }
                                var account =
                                    JsonConvert.SerializeObject(
                                        (type == "a"
                                            ? (dynamic) database.GetAccount(username)
                                            : (dynamic) database.GetCharacter(username)), Formatting.Indented);
                                WriteLine(account);
                                if (cmdArgs.Length >= 3)
                                    Clipboard.SetText(account);
                                continue;
                            }

                            WriteLine("Invalid Arguments!");
                            break;
                        case "addaccount":
                            if (cmdArgs != null && cmdArgs.Length >= 2)
                            {
                                var username = cmdArgs[0];
                                var password = cmdArgs[1];
                                database.CreateAccount(username, password);

                                WriteLine("Success!");
                                continue;
                            }

                            WriteLine("Invalid Arguments.");
                            break;
                        case "ban":
                            if (cmdArgs?.Length >= 1)
                            {
                                var username = cmdArgs[0];
                                if (!database.AccountExists(username))
                                {
                                    WriteLine("User does not exist.");
                                    continue;
                                }
                                var account = database.GetAccount(username);
                                account.Banned = true;
                                database.UpdateAccount(account);
                                WriteLine("Success!");
                                continue;
                            }

                            WriteLine("Invalid Arguments.");
                            break;
                        case "unban":
                            if (cmdArgs?.Length >= 1)
                            {
                                var username = cmdArgs[0];
                                if (!database.AccountExists(username))
                                {
                                    WriteLine("User does not exist.");
                                    continue;
                                }
                                var account = database.GetAccount(username);
                                account.Banned = false;
                                database.UpdateAccount(account);
                                WriteLine("Success!");
                                continue;
                            }

                            WriteLine("Invalid Arguments.");
                            break;
                        case "removeaccount":
                            if (cmdArgs?.Length >= 1)
                            {
                                var username = cmdArgs[0];
                                if (database.AccountExists(username))
                                {
                                    database.DeleteAccount(database.GetAccount(username));
                                    WriteLine("Success!");
                                    continue;
                                }

                                WriteLine("User does not exist.");
                                continue;
                            }

                            WriteLine("Invalid Arguments.");
                            break;
                        case "accountexists":
                            if (cmdArgs != null && cmdArgs.Length >= 1)
                            {
                                var username = cmdArgs[0];
                                WriteLine(database.AccountExists(username));
                                continue;
                            }

                            WriteLine("Invalid Arguments.");
                            break;
                        default:
                            WriteLine("Unknown command.");
                            break;
                    }
            }
        }
        public override void Handle(BinaryReader reader, LuClient client)
        {
            using (var database = new DbUtils())
            {
                if (!client.Authenticated)
                    return; // You need to have an account and be signed into it to make a character!

                var name = reader.ReadWString(66); // Read the name of the new character
                reader.BaseStream.Position = 74; // Set the position to right after the username
                var name1 = reader.ReadUInt32(); // Read
                var name2 = reader.ReadUInt32(); // FTP
                var name3 = reader.ReadUInt32(); // Names

                // TODO: Implement FTP names

                reader.ReadBytes(9); // Read 9 ... unknown bytes?

                var shirtColor = reader.ReadUInt32(); // Read their choices in appearance
                var shirtStyle = reader.ReadUInt32();
                var pantsColor = reader.ReadUInt32();
                var hairStyle = reader.ReadUInt32();
                var hairColor = reader.ReadUInt32();
                var lh = reader.ReadUInt32();
                var rh = reader.ReadUInt32();
                var eyebrows = reader.ReadUInt32();
                var eyes = reader.ReadUInt32();
                var mouth = reader.ReadUInt32();

                var responseId =
                    (byte) (database.CharacterExists(name) ? 0x04 : 0x00);
                // Generate the respond ID

                var account = database.GetAccount(client.Username);

                if (account.Characters.Count >= 4) // Don't want any cheaters getting more than 4!
                {
                    responseId = 0x04;
                }

                if (responseId == 0x00) // Make sure to actually make it, if the character does not exist.
                {
                    // Create the new character
                    var character = new Character
                    {
                        Name = name,
                        Eyebrows = eyebrows,
                        Eyes = eyes,
                        HairColor = hairColor,
                        HairStyle = hairStyle,
                        Lh = lh,
                        Rh = rh,
                        Mouth = mouth,
                        Name1 = name1,
                        Name2 = name2,
                        Name3 = name3,
                        PantsColor = pantsColor,
                        ShirtColor = shirtColor,
                        ShirtStyle = shirtStyle,
                        // Initialize the other character data
                        Position = ZonePositions.VentureExplorer,
                        Owner = client.Username,
                        MapInstance = 0,
                        MapClone = 0,
                        ZoneId = (ushort) ZoneId.VentureExplorer,
                        Armor = 0,
                        MaxArmor = 0,
                        Health = 4,
                        MaxHealth = 4,
                        Imagination = 0,
                        MaxImagination = 0,
                        GmLevel = 0,
                        Reputation = 0,
                        Items = new List<BackpackItem>(),
                        BackpackSpace = 20,
                        Level = 0,
                        Missions = new List<string>()
                    };

                    character.Items.Add(
                        new BackpackItem
                        {
                            Lot = WorldPackets.FindCharShirtID(shirtColor, shirtStyle),
                            Linked = false,
                            Count = 1,
                            Slot = 0
                        });
                    //character.AddItem(WorldPackets.);

                    database.AddCharacter(character); // Add the character to the database.

                    account.Characters.Add(character.Name); // Add the character to the account
                    database.UpdateAccount(account); // Update the account
                }

                // Output the code
                Console.WriteLine($"Got character create request from {client.Username}. Response Code: {responseId}");

                // Create the response
                using (var bitStream = new WBitStream())
                {
                    bitStream.WriteHeader(RemoteConnection.Client, (uint) MsgClientCharacterCreateResponse);
                    // Always write the packet header.
                    bitStream.Write((responseId)); // Write the response code.
                    WorldServer.Server.Send(bitStream, SystemPriority,
                        ReliableOrdered, 0, client.Address, false); // Send the response.
                }

                if (responseId == 0x00)
                    WorldPackets.SendCharacterListResponse(client.Address, database.GetAccount(client.Username),
                        WorldServer.Server);
                // Send the updated character list.
            }
        }