Exemplo n.º 1
0
        public static void HandleMigrateCashShop(MapleClient client, InPacket iPacket)
        {
            int accountID;
            int characterID = iPacket.ReadInt();

            if ((accountID = MasterServer.Instance.Shop.Migrations.Validate(client.Host, characterID)) == -1)
            {
                client.Close();

                return;
            }

            using (DatabaseQuery query = Database.Query("SELECT * FROM `accounts` WHERE `account_id` = @account_id", new MySqlParameter("account_id", accountID)))
            {
                query.NextRow();

                client.Account = new Account(query);
            }

            using (DatabaseQuery query = Database.Query("SELECT * FROM `characters` WHERE `character_id` = @character_id", new MySqlParameter("character_id", characterID)))
            {
                query.NextRow();

                client.Character = new Character(client, query);
            }

            client.Character.Initialize(true);
        }
Exemplo n.º 2
0
        public void Buy(MapleClient c, int itemId, short quantity)
        {
            if (quantity <= 0)
            {
                Console.WriteLine($"{c.Player.Name} is buying an invalid amount: { quantity } of itemid: { itemId}");
                c.Close();
                return;
            }
            MapleShopItem item = FindByItemId(itemId);
            MapleItemInformationProvider ii = MapleItemInformationProvider.Instance;

            if (item != null && item.Price > 0 && c.Player.Meso.Value >= item.Price * quantity)
            {
                if (MapleInventoryManipulator.CheckSpace(c, itemId, quantity, ""))
                {
                    if (itemId >= 5000000 && itemId <= 5000100)
                    {
                        if (quantity > 1)
                        {
                            quantity = 1;
                        }
                        int petId = MaplePet.Create(itemId);
                        MapleInventoryManipulator.AddById(c, itemId, quantity, "Pet was purchased.", null, petId);
                    }
                    else if (ii.IsRechargable(itemId))
                    {
                        short rechquantity = ii.GetSlotMax(c, item.ItemId);
                        MapleInventoryManipulator.AddById(c, itemId, rechquantity, "Rechargable item purchased.", null, -1);
                    }
                    else
                    {
                        MapleInventoryManipulator.AddById(c, itemId, quantity, c.Player.Name + " bought " + quantity + " for " + item.Price * quantity + " from shop " + ShopId);
                    }
                    c.Player.GainMeso(-(item.Price * quantity), false);
                    c.Send(PacketCreator.ConfirmShopTransaction(0));
                }
                else
                {
                    c.Send(PacketCreator.ConfirmShopTransaction(3));
                }
            }
        }
Exemplo n.º 3
0
        public static void OnDeleteCharacter(MapleClient c, InPacket p)
        {
            p.Skip(4);
            int charId = p.ReadInt();

            Character target = c.Characters.FindOne((chr) => chr.CharId == charId);

            if (target != default(Character))
            {
                Database.Instance.DeleteCharacter(target);
                c.Characters.Remove(target);

                using (OutPacket packet = new OutPacket(SendOps.DeleteCharacterResult))
                {
                    packet.WriteInt(charId);
                    packet.WriteByte();
                    c.Send(packet);
                }
            }
            else
            {
                c.Close();
            }
        }
Exemplo n.º 4
0
        public static void OnSelectCharacter(MapleClient c, InPacket p)
        {
            int charId = p.ReadInt();

            Character target = c.Characters.FindOne((chr) => chr.CharId == charId);

            if (target != default(Character))
            {
                using (OutPacket packet = new OutPacket(SendOps.SelectCharacterResult))
                {
                    packet.WriteShort();
                    packet.WriteBytes(127, 0, 0, 1); //TODO : non const ip
                    packet.WriteShort(MasterServer.Instance.Channels[c.Channel].Port);
                    packet.WriteInt(charId);
                    packet.WriteByte();

                    c.Send(packet);
                }
            }
            else
            {
                c.Close();
            }
        }
Exemplo n.º 5
0
        public static void OnCheckPassword(MapleClient c, InPacket p)
        {
            string user = p.ReadMapleString().Trim();
            string pass = p.ReadMapleString();

            //byte[] machineId = p.ReadBytes(0x10);
            //int gameRoomCode = p.ReadInt();
            //byte gameStartMode = p.ReadByte();
            //bool adminClient = p.ReadBool();

            byte loginResult = MasterServer.Instance.LoginClient(c, user, pass);

            using (OutPacket packet = new OutPacket(SendOps.CheckPasswordResult))
            {
                packet.WriteByte(loginResult);
                packet.WriteZero(5); //v11 (1) + v12 (4)

                if (loginResult == 0)
                {
                    packet.WriteInt(c.Account.AccountId);
                    packet.WriteByte();
                    packet.WriteBool(c.Account.GM);
                    packet.WriteByte(1);
                    packet.WriteMapleString(c.Account.Username);
                    packet.WriteZero(12);
                }
                else if (loginResult == 2) //TODO : Add packet for this
                {
                    c.Close();
                    return;
                }

                packet.WriteZero(24); //padding
                c.Send(packet);
            }

            if (loginResult != 0)
            {
                return;
            }

            using (OutPacket packet = new OutPacket(SendOps.CheckUserLimitResult, 3))
            {
                packet.WriteByte(4);
                c.Send(packet);
            }

            using (OutPacket packet = new OutPacket(SendOps.WorldInformation))
            {
                byte   worldId = 0;
                string name    = Constants.WorldName;

                packet.WriteByte(worldId);
                packet.WriteMapleString(name);

                packet.WriteByte((byte)MasterServer.Instance.Channels.Length);

                int id = 1;

                foreach (var ch in MasterServer.Instance.Channels)
                {
                    packet.WriteMapleString("{0}-{1}", name, id++);
                    packet.WriteInt(ch.Load);
                    packet.WriteByte(worldId);
                    packet.WriteByte((byte)(id - 1));
                    packet.WriteByte(0x00);
                }

                c.Send(packet);
            }

            using (OutPacket packet = new OutPacket(SendOps.WorldInformation, 3))
            {
                packet.WriteByte(0xff);
                c.Send(packet);
            }
        }
Exemplo n.º 6
0
        public static void Drop(MapleClient c, MapleInventoryType type, byte srcSlot, short quantity)
        {
            MapleItemInformationProvider ii = MapleItemInformationProvider.Instance;

            if (srcSlot > 127)
            {
                type = MapleInventoryType.Equipped;
            }
            IMapleItem source = c.Player.Inventorys[type.Value].Inventory[srcSlot];

            if (quantity > ii.GetSlotMax(c, source.ItemId))
            {
                //try
                //{
                //    c.getChannelServer().getWorldInterface().broadcastGMMessage(c.Player.getName(), PacketCreator.serverNotice(0, c.Player.getName() + " is dropping more than slotMax.").getBytes());
                //}
                //catch (Throwable u)
                //{
                //}
            }
            if (quantity < 0 || quantity == 0 && !ii.IsThrowingStar(source.ItemId) && !ii.IsBullet(source.ItemId))
            {
                //String message = "Dropping " + quantity + " " + (source == null ? "?" : source.ItemId) + " (" +type.name() + "/" + srcSlot + ")";
                //log.info(MapleClient.getLogMessage(c, message));
                c.Close(); // disconnect the client as is inventory is inconsistent with the serverside inventory
                return;
            }
            Point dropPos = c.Player.Position;

            if (quantity < source.Quantity && !ii.IsThrowingStar(source.ItemId) && !ii.IsBullet(source.ItemId))
            {
                IMapleItem target = source.Copy();
                target.Quantity  = quantity;
                source.Quantity -= quantity;
                c.Send(PacketCreator.DropInventoryItemUpdate(type, source));
                bool weddingRing = source.ItemId == 1112804;
                bool liRing      = source.ItemId == 1112405;
                if (weddingRing)
                {
                    c.Player.Map.disappearingItemDrop(c.Player, c.Player, target, dropPos);
                }
                else if (liRing)
                {
                    c.Player.Map.disappearingItemDrop(c.Player, c.Player, target, dropPos);
                }
                else if (c.Player.Map.Everlast)
                {
                    if (ii.IsDropRestricted(target.ItemId))
                    {
                        c.Player.Map.disappearingItemDrop(c.Player, c.Player, target, dropPos);
                    }
                    else
                    {
                        c.Player.Map.spawnItemDrop(c.Player, c.Player, target, dropPos, true, false);
                    }
                }
                else
                {
                    if (ii.IsDropRestricted(target.ItemId))
                    {
                        c.Player.Map.disappearingItemDrop(c.Player, c.Player, target, dropPos);
                    }
                    else
                    {
                        c.Player.Map.spawnItemDrop(c.Player, c.Player, target, dropPos, true, false);
                    }
                }
            }
            else
            {
                c.Player.Inventorys[type.Value].RemoveSlot(srcSlot);
                c.Send(PacketCreator.DropInventoryItem(srcSlot > 127 ? MapleInventoryType.Equip : type, srcSlot));
                bool liRing = source.ItemId == 1112405;
                if (srcSlot > 127)
                {
                    c.Player.EquipChanged();
                }
                if (c.Player.Map.Everlast)
                {
                    if (ii.IsDropRestricted(source.ItemId))
                    {
                        c.Player.Map.disappearingItemDrop(c.Player, c.Player, source, dropPos);
                    }
                    else
                    {
                        c.Player.Map.spawnItemDrop(c.Player, c.Player, source, dropPos, true, false);
                        if (liRing)
                        {
                            c.Player.Map.disappearingItemDrop(c.Player, c.Player, source, dropPos);
                        }
                        else
                        {
                            c.Player.Map.spawnItemDrop(c.Player, c.Player, source, dropPos, true, true);
                        }
                    }
                }
                else
                {
                    if (ii.IsDropRestricted(source.ItemId))
                    {
                        c.Player.Map.disappearingItemDrop(c.Player, c.Player, source, dropPos);
                    }
                    else
                    {
                        if (liRing)
                        {
                            c.Player.Map.disappearingItemDrop(c.Player, c.Player, source, dropPos);
                        }
                        else
                        {
                            c.Player.Map.spawnItemDrop(c.Player, c.Player, source, dropPos, true, true);
                        }
                    }
                }
            }
        }