GetCharacter() public method

Gets a character from their ID.
public GetCharacter ( long id, bool notRaw = false ) : Character
id long The character ID.
notRaw bool Is this not raw?
return ImaginationServer.Common.Data.Character
        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);
                }
            }
        }
        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);
                }
            }
        }
コード例 #3
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;
                    }
            }
        }
コード例 #4
0
        public override void Handle(BinaryReader reader, LuClient client)
        {
            using (var database = new DbUtils())
            {
                if (!client.Authenticated) return;

                var zone = (ZoneId) reader.ReadUInt16();
                var instance = reader.ReadUInt16();
                var clone = reader.ReadInt32();

                Console.WriteLine(
                    $"Got clientside level load complete packet from {client.Username}. Zone: {zone}, Instance: {instance}, Clone: {clone}.");

                var account = database.GetAccount(client.Username);
                var character = database.GetCharacter(account.SelectedCharacter);

                using (var bitStream = new WBitStream())
                {
                    bitStream.WriteHeader(RemoteConnection.Client, (uint) MsgClientCreateCharacter);

                    using (var ldf = new Ldf())
                    {
                        // TODO: Improve LDF code here
                        ldf.WriteS64("accountID", account.Id);
                        ldf.WriteS32("chatmode", 0);
                        ldf.WriteBool("editor_enabled", false);
                        ldf.WriteS32("editor_level", 0);
                        ldf.WriteBool("freetrial", false);
                        ldf.WriteS32("gmlevel", character.GmLevel);
                        ldf.WriteBool("legoclub", true);
                        var levelid = character.ZoneId + (((long) character.MapInstance) << 16) +
                                      (((long) character.MapClone) << 32);
                        ldf.WriteS64("levelid", levelid);
                        ldf.WriteWString("name", character.Name);
                        ldf.WriteId("objid", Character.GetObjectId(character));
                        ldf.WriteFloat("position.x", character.Position[0]);
                        ldf.WriteFloat("position.y", character.Position[1]);
                        ldf.WriteFloat("position.z", character.Position[2]);
                        ldf.WriteS64("reputation", character.Reputation);
                        ldf.WriteS32("template", 1);
                        using (var xmlData = GenXmlData(character)) ldf.WriteBytes("xmlData", xmlData);

                        bitStream.Write(ldf.GetSize() + 1);
                        bitStream.Write((byte) 0);
                        ldf.WriteToPacket(bitStream);
                        WorldServer.Server.Send(bitStream, WPacketPriority.SystemPriority,
                            WPacketReliability.ReliableOrdered, 0, client.Address, false);
                        File.WriteAllBytes("Temp/" + character.Name + ".world_2a.bin", bitStream.GetBytes());
                    }
                }

                WorldServer.Server.SendGameMessage(client.Address, Character.GetObjectId(character), 1642);
                WorldServer.Server.SendGameMessage(client.Address, Character.GetObjectId(character), 509);
                using (var gameMessage = LuServer.CreateGameMessage(Character.GetObjectId(character), 472))
                {
                    gameMessage.Write((uint) 185);
                    gameMessage.Write((byte) 0);
                    WorldServer.Server.Send(gameMessage, WPacketPriority.SystemPriority,
                        WPacketReliability.ReliableOrdered, 0, client.Address, false);
                }

                var playerObject = new PlayerObject(Character.GetObjectId(character), character.Name);
                playerObject.Construct(WorldServer.Server, client.Address);
            }
        }
コード例 #5
0
        public override void Handle(BinaryReader reader, LuClient client)
        {
            using (var database = new DbUtils())
            {
                var objectId = reader.ReadInt64(); // Read the object ID.
                Console.WriteLine("Received Login Request from {0} - ObjectID = {1}", client.Address, objectId);

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

                if (!string.Equals(character.Owner, account.Username, StringComparison.CurrentCultureIgnoreCase))
                    // Make sure they selected their own character
                {
                    Console.WriteLine("USER {0} SENT OBJECT ID THAT IS NOT ONE OF THEIR CHARACTER'S!!!", client.Username);
                    // TODO: Kick user
                    return;
                }

                account.SelectedCharacter = character.Name;
                database.UpdateAccount(account);

                client.OutOfChar = true;

                Console.WriteLine("User has selected character {0}. Sending them to zone {1}.", character.Name,
                    character.ZoneId);

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

                    bitStream.Write(character.ZoneId); // Write the zone id
                    bitStream.Write(character.MapInstance); // Write the map instance
                    bitStream.Write(character.MapClone); // Write the map clone
                    for (var i = 0; i < 4; i++)
                        bitStream.Write(ZoneChecksums.Checksums[(ZoneId)character.ZoneId][i]); // Write the checksum
                    bitStream.Write((ushort)0); // ???
                    for (var i = 0; i < 3; i++) bitStream.Write(character.Position[i]); // Write the position
                    bitStream.Write((uint)0); // Supposed to be 4, if in battle...

                    // Send the packet
                    WorldServer.Server.Send(bitStream, WPacketPriority.SystemPriority,
                        WPacketReliability.ReliableOrdered, 0, client.Address, false);

                    Console.WriteLine(
                        $"Sent world info to client - ZoneId = {character.ZoneId}, Map Instance = {character.MapInstance}, Map Clone = {character.MapClone}");
                }

                // commented to make world single server
                /*
                                using (var bitStream = new WBitStream()) // Create the redirect packet
                                {
                                    bitStream.WriteHeader(RemoteConnection.Client, (uint)MsgClientTransferToWorld);
                                    // Always write the header.
                                    bitStream.WriteString("127.0.0.1", 33);
                                    // Write the IP to redirect to (TODO: Make this the broadcast IP)
                                    bitStream.Write(2006);
                                    // Write the port of the server.
                                    bitStream.Write((byte)0);
                                    // Don't say that this was a mythran dimensional shift, because it wasn't.

                                    WorldServer.Server.Send(bitStream, WPacketPriority.SystemPriority,
                                        WPacketReliability.ReliableOrdered, 0, client.Address, false); // Send the redirect packet.
                                }
                */
            }
        }