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 WriteToPacket(WBitStream bitStream, ReplicaPacketType type)
        {
            // Index 1
            if (type == ReplicaPacketType.Construction)
            {
                bitStream.Write(false);
                bitStream.Write(false);
            }

            // Index 2
            if (type == ReplicaPacketType.Construction)
            {
                bitStream.Write(false);
            }
            bitStream.Write(Faction == null ? 0 : 1);
            if(Faction != null) bitStream.Write(Faction.Value);
            bitStream.Write(false);
            if (type == ReplicaPacketType.Construction)
            {
                bitStream.Write(false);
                bitStream.Write(false);
                bitStream.Write(false);
            }
            bitStream.Write(false);
        }
 public void WriteHeader(WBitStream bitStream, ushort remoteConnection, uint packetId)
 {
     bitStream.Write((byte)83);
     bitStream.Write(remoteConnection);
     bitStream.Write(packetId);
     bitStream.Write((byte)0);
 }
Esempio n. 4
0
 /// <summary>
 /// 13
 /// </summary>
 /// <param name="key"></param>
 /// <param name="data"></param>
 public void WriteBytes(string key, WBitStream data)
 {
     BitStream.WriteWString(key, true, false);
     BitStream.Write((byte) 13);
     BitStream.Write(data.GetNumberOfBytesUsed());
     BitStream.Write(data, data.GetNumberOfBytesUsed()*8);
     _keyNumber++;
 }
Esempio n. 5
0
 static void Main(string[] args)
 {
     using (var bitStream = new WBitStream())
     {
         bitStream.WriteWString("WString", false, false);
         bitStream.WriteString("String", 4);
         bitStream.WriteChars("Chars");
     }
     Console.ReadKey(true);
 }
        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 override void WriteToPacket(WBitStream bitStream, ReplicaPacketType type)
        {
            bitStream.Write(Flag);
            if (Flag)
            {
                bitStream.Write(Items.Count);
                foreach (var item in Items)
                {
                    bitStream.Write(item.Id);
                    bitStream.Write(item.Lot);
                    bitStream.Write(false);
                    bitStream.Write(true);
                    bitStream.Write((uint)1);
                    bitStream.Write(true);
                    bitStream.Write(item.Slot);
                    bitStream.Write(true);
                    bitStream.Write((uint)4);
                    bitStream.Write(false);
                    bitStream.Write(false);
                }
            }

            bitStream.Write(false);
        }
 public override void WriteToPacket(WBitStream bitStream, ReplicaPacketType type)
 {
     bitStream.Write(true);
     bitStream.Write((ulong)0);
 }
Esempio n. 9
0
 public Ldf()
 {
     BitStream = new WBitStream();
     _keyNumber = 0;
 }
Esempio n. 10
0
 public void WriteToPacket(WBitStream packet)
 {
     packet.Write(_keyNumber);
     packet.Write(BitStream, BitStream.GetNumberOfBytesUsed()*8);
 }
        public override void WriteToPacket(WBitStream bitStream, ReplicaPacketType type)
        {
            if (type == ReplicaPacketType.Construction)
            {
                bitStream.Write(Flag1);
                if (Flag1)
                {
                    bitStream.Write(Data1.D1);
                    bitStream.Write(Data1.D2);
                    bitStream.Write(Data1.D3);
                }

                bitStream.Write(Flag2);
                if (Flag2)
                {
                    bitStream.Write(Data2.D1);
                    bitStream.Write(Data2.D2);
                    bitStream.Write(Data2.D3);
                    bitStream.Write(Data2.D4);
                    bitStream.Write(Data2.D5);
                    bitStream.Write(Data2.D6);
                    bitStream.Write(Data2.D7);
                }
            }

            bitStream.Write(Flag3);
            if (Flag3)
            {
                bitStream.Write(Data3.D1);
                bitStream.Write(Data3.D2);
            }

            bitStream.Write(Flag4);
            if (Flag4)
            {
                bitStream.Write(Data4.D1);
                bitStream.Write(Data4.D2);
            }

            bitStream.Write(Flag5);
            if (Flag5)
            {
                bitStream.Write(Data5.Flag);
                if (Data5.Flag)
                {
                    bitStream.Write(Data5.D1);
                    bitStream.Write(Data5.D2);
                }
            }

            bitStream.Write(Flag6);
            if (Flag6)
            {
                bitStream.Write(Data6.PosX);
                bitStream.Write(Data6.PosY);
                bitStream.Write(Data6.PosZ);

                bitStream.Write(Data6.RotationX);
                bitStream.Write(Data6.RotationY);
                bitStream.Write(Data6.RotationZ);
                bitStream.Write(Data6.RotationW);

                bitStream.Write(Data6.IsOnGround);
                bitStream.Write(Data6.Unknown1);

                bitStream.Write(Data6.VelocityFlag);
                if (Data6.VelocityFlag)
                {
                    bitStream.Write(Data6.VelocityX);
                    bitStream.Write(Data6.VelocityY);
                    bitStream.Write(Data6.VelocityZ);
                }

                bitStream.Write(Data6.AngularVelocityFlag);
                if (Data6.AngularVelocityFlag)
                {
                    bitStream.Write(Data6.AngularVelocityX);
                    bitStream.Write(Data6.AngularVelocityY);
                    bitStream.Write(Data6.AngularVelocityZ);
                }

                bitStream.Write(Data6.MovingPlatformFlag);
                if (Data6.MovingPlatformFlag)
                {
                    bitStream.Write(Data6.MpUnknown1);
                    bitStream.Write(Data6.MpUnknown2);
                    bitStream.Write(Data6.MpUnknown3);
                    bitStream.Write(Data6.MpUnknown4);
                    bitStream.Write(Data6.MpFlag1);
                    if (Data6.MpFlag1)
                    {
                        bitStream.Write(Data6.MpUnknownD1);
                        bitStream.Write(Data6.MpUnknownD2);
                        bitStream.Write(Data6.MpUnknownD3);
                    }
                }
            }

            if (type == ReplicaPacketType.Serialization)
            {
                bitStream.Write(Flag7);
            }
        }
 public override void WriteToPacket(WBitStream bitStream, ReplicaPacketType type)
 {
     if(type == ReplicaPacketType.Construction) bitStream.Write((uint)0);
 }
        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.
            }
        }
Esempio n. 14
0
        public static WBitStream CreateGameMessage(long objId, ushort messageId)
        {
            var gameMessage = new WBitStream();

            gameMessage.Write(objId);
            gameMessage.Write(messageId);

            return gameMessage;
        }
        public override void WriteToPacket(WBitStream bitStream, ReplicaPacketType type)
        {
            // index 1
            bitStream.Write(IndexOne.Flag);
            if (IndexOne.Flag)
            {
                bitStream.Write(IndexOne.Data.Flag);
                if (IndexOne.Data.Flag) bitStream.Write(IndexOne.Data.VehicleObjectId);
                bitStream.Write(IndexOne.Data.Unknown);
            }

            // Index 2
            bitStream.Write(IndexTwo.Flag);
            if(IndexTwo.Flag) bitStream.Write(IndexTwo.Level);

            // Index 3
            bitStream.Write(IndexThree.Flag);
            if (IndexThree.Flag)
            {
                bitStream.Write(IndexThree.Unknown1);
                bitStream.Write(IndexThree.Unknown2);
            }

            // Index 4
            if (type == ReplicaPacketType.Construction)
            {
                bitStream.Write(IndexFour.Flag1);
                bitStream.Write(IndexFour.Unknown1);
                bitStream.Write(IndexFour.Flag2);
                bitStream.Write(IndexFour.Unknown2);
                bitStream.Write(IndexFour.Flag3);
                bitStream.Write(IndexFour.Unknown3);
                bitStream.Write(IndexFour.Flag4);
                bitStream.Write(IndexFour.Unknown4);

                bitStream.Write(IndexFour.HairColor);
                bitStream.Write(IndexFour.HairStyle);
                bitStream.Write(IndexFour.Unknown5);
                bitStream.Write(IndexFour.ShirtColor);
                bitStream.Write(IndexFour.PantsColor);
                bitStream.Write(IndexFour.Unknown6);
                bitStream.Write(IndexFour.Unknown7);
                bitStream.Write(IndexFour.EyebrowsStyle);
                bitStream.Write(IndexFour.EyesStyle);
                bitStream.Write(IndexFour.MouthStyle);
                bitStream.Write(IndexFour.AccountId);
                bitStream.Write(IndexFour.Llog);
                bitStream.Write(IndexFour.Unknown8);
                bitStream.Write(IndexFour.LegoScore);
                bitStream.Write(IndexFour.FreeToPlay);
                // TODO: Write stats instead of this

                for (var i = 0; i < 27; i++)
                {
                    bitStream.Write((ulong)0);
                }

                bitStream.Write(IndexFour.Flag6);
                bitStream.Write(IndexFour.Flag7);
                if (IndexFour.Flag7) bitStream.WriteWString(IndexFour.LdfText, false, false);
            }

            bitStream.Write(false);
            bitStream.Write(false);
            bitStream.Write(false);
        }
 public abstract void Serialize(WBitStream bitStream);
        private static WBitStream GenXmlData(Character character)
        {
            using(var cdclient = new CdClientDb())
            {
                var xml = "";
                xml += "<?xml version=\"1.0\"?>";

                xml += "<obj v=\"1\">";
                xml += "<buff/>";
                xml += "<skil/>";

                xml += "<inv>";
                xml += "<bag>";
                xml += "<b t=\"0\" m=\"24\"/>";
                xml += "</bag>";

                xml += "<items>";
                xml += "<in>";

                // TODO: Write items

                //foreach (var item in character.Items)
                //{
                //    writer.WriteStartElement("i"); // <i>
                //    writer.WriteAttributeString("l", item.);
                //    writer.WriteEndElement(); // </i>
                //}

                xml += "</in>";
                xml += "</items>";

                xml += "</inv>";

                xml += "<mf/>";

                xml += "<chars cc=\"100\"></char>";

                xml += $"<lvl l=\"{character.Level}\"/>";

                xml += "<flag/>";
                xml += "<pet/>";

                if (character.Missions?.Any() ?? false)
                {
                    xml += "<mis>";
                    xml += "<done>";
                    xml = character.Missions.Select(mission => CharacterMission.FromJson(mission)).Aggregate(xml, (current, missionData) => current + $"<m id=\"{missionData.Id}\" cts=\"{missionData.Timestamp}\" cct=\"{missionData.Count}\"/>");
                    xml += "</done>";
                    xml += "</mis>";
                }

                xml += "<mnt/>";
                xml += "<dest/>";
                xml += "</obj>";
                var bitStream = new WBitStream();
                Console.WriteLine(xml);
                bitStream.WriteChars(xml);

                return bitStream;
            }
        }
        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);
            }
        }
        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.
                                }
                */
            }
        }