DeleteCharacter() 공개 메소드

Removes a character from the database, and its owner account.
public DeleteCharacter ( Character character ) : void
character ImaginationServer.Common.Data.Character The character to delete.
리턴 void
        public override void Handle(BinaryReader reader, LuClient client)
        {
            using (var database = new DbUtils())
            {
                if (!client.Authenticated) return;

                var id = reader.ReadInt64(); // The object id of the characte
                Console.WriteLine(id);

                var character = database.GetCharacter(id, true); // Retrieve the character from the database

                Console.WriteLine($"{client.Username} requested to delete their character {character.Name}.");

                using (var bitStream = new WBitStream()) // Create the new bitstream
                {
                    bitStream.WriteHeader(RemoteConnection.Client, (uint) MsgClientDeleteCharacterResponse);
                        // Always write the packet header!
                    if (!string.Equals(character.Owner, client.Username,
                        StringComparison.CurrentCultureIgnoreCase)) // You can't delete someone else's character!
                    {
                        bitStream.Write((byte) 0x02); // Maybe that's the fail code?
                        Console.WriteLine("Failed: Can't delete someone else's character!");
                    }
                    else // Good to go, that's their character, they can delete it if they want.
                    {
                        database.DeleteCharacter(character); // Remove the character from the Redis database
                        bitStream.Write((byte) 0x01); // Success code
                        Console.WriteLine("Successfully deleted character.");
                    }

                    // Send the packet
                    WorldServer.Server.Send(bitStream, SystemPriority, ReliableOrdered, 0, client.Address, false);
                }
            }
        }
예제 #2
0
        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;
                    }
            }
        }