Пример #1
0
        public override void Handle(User usr)
        {
            string itemCode = getWeapon(usr.rewardEvent.progress);
            int    days     = 3;

            if (!usr.rewardEvent.doneToday)
            {
                usr.rewardEvent.doneToday = true;
                Managers.Item item = Managers.ItemManager.GetItem(itemCode);
                if (item.dinarReward > 0)
                {
                    usr.dinar += (int)item.dinarReward;
                    DB.RunQuery("UPDATE users SET dinar = '" + usr.dinar + "' WHERE id='" + usr.userId + "'");
                }
                else
                {
                    if (itemCode.StartsWith("B"))
                    {
                        Inventory.AddCostume(usr, itemCode, days);
                    }
                    else
                    {
                        Inventory.AddItem(usr, itemCode, days);
                    }
                }
                usr.rewardEvent.progress++;
                usr.send(new SP_LoginEvent(usr, itemCode, days));
                DB.RunQuery("UPDATE users SET loginEventProgress = '" + usr.rewardEvent.progress + "', loginEventToday = '1' WHERE id='" + usr.userId + "'");
            }
            else
            {
                usr.send(new SP_LoginEvent(SP_LoginEvent.ErrorCodes.AlreadyChecked));
            }
        }
Пример #2
0
        public override void Handle(User usr)
        {
            SubCodes subcode  = (SubCodes)int.Parse(getBlock(0));
            int      outboxId = int.Parse(getBlock(1));

            switch (subcode)
            {
            case SubCodes.Delete:
            {
                if (usr.OutboxItems.Count <= 0)
                {
                    return;
                }
                string itemCode = getBlock(4);

                if (Inventory.HasOutboxItem(usr, itemCode))
                {
                    Inventory.RemoveOutBoxItem(usr, outboxId);
                    usr.send(new SP_Outbox(usr));
                }
                break;
            }

            case SubCodes.Activate:
            {
                if (usr.OutboxItems.Count <= 0)
                {
                    return;
                }
                string itemCode = getBlock(4);

                if (Inventory.HasOutboxItem(usr, itemCode))
                {
                    bool found = usr.OutboxItems.Values.Where(r => r.id == outboxId).Count() > 0;
                    if (found)
                    {
                        OutboxItem i    = usr.OutboxItems.Values.Where(r => r.id == outboxId).FirstOrDefault();
                        int        days = i.days;
                        if (Inventory.GetFreeItemSlotCount(usr) > 0)
                        {
                            Managers.Item item = Managers.ItemManager.GetItem(i.itemcode);
                            if (item != null)
                            {
                                Inventory.PerformAddItem(usr, itemCode, days, i.count);
                                Inventory.RemoveOutBoxItem(usr, outboxId);
                                usr.send(new SP_OutboxUse(usr, itemCode));
                                usr.send(new SP_Outbox(usr));
                            }
                        }
                        else
                        {
                            usr.send(new SP_DinarItemBuy(SP_DinarItemBuy.ErrorCodes.InventoryFull));
                        }
                    }
                }
                break;
            }
            }
        }
Пример #3
0
        public override void Handle(User usr)
        {
            if (usr.room != null)
            {
                return;
            }
            bool   Equip        = (getBlock(0) == "0");
            int    Class        = int.Parse(getBlock(1));
            string Code         = getBlock(4);
            int    WhereToPlace = int.Parse(getBlock(5));

            Managers.Item Item = Managers.ItemManager.GetItem(Code);
            if (Item != null && Class >= 0 && Class <= 4)
            {
                if (usr.HasCostume(Code))
                {
                    if (Code.StartsWith("BA"))
                    {
                        usr.costumes_char[Class] = (Equip ? Code : getDefaultClass(Class)) + ",^,^,^,^,^,^,^,^,^,^,^,^,^,^,^,^,^,^,^,^,^,^,^,^,^,^,^,^,^";
                    }
                    else
                    {
                        string[] Placement = usr.costumes_char[Class].Split(new char[] { ',' });
                        Placement[WhereToPlace]  = (Equip ? Code : "^");
                        usr.costumes_char[Class] = string.Join(",", Placement);
                    }

                    string output = usr.costumes_char[Class];

                    usr.send(new SP_CostumeEquip(Class, output));
                    DB.RunQuery("UPDATE users_costumes SET class_" + Class + "='" + output + "' WHERE ownerid='" + usr.userId + "'");
                    usr.send(new SP_CashItemBuy(usr));
                }
                else
                {
                    Log.WriteError(usr.nickname + " tried to equip " + Code + " but he hasn't it!");
                    usr.disconnect();
                }
            }
        }
Пример #4
0
        public override void Handle(User usr)
        {
            int           equip_int   = int.Parse(getBlock(0));
            EquipmentType equip       = (EquipmentType)equip_int;
            int           Class       = int.Parse(getBlock(1));
            string        type        = getBlock(2);
            int           inventoryid = int.Parse(getBlock(3));
            string        itemcode    = getBlock(4);
            int           targetSlot  = int.Parse(getBlock(5));

            bool defaultWeapon = usr.IsWhitelistedWeapon(itemcode);

            if (usr.room != null && usr.IsAlive())
            {
                return;
            }

            //if (usr.room != null && usr.room.mode == (int)RoomMode.FFA && usr.room.ffa != null && usr.room.ffa.isGunGame)
            //{
            //    usr.send(new SP_CustomMessageBox("You cannot equip any item in Gun Game mode."));
            //    return;
            //}

            if (usr.HasItem(itemcode) || defaultWeapon || itemcode.Contains("-"))
            {
                Managers.Item item = Managers.ItemManager.GetItem(itemcode);

                if (targetSlot >= 4)
                {
                    int      t          = targetSlot - 4;
                    string[] SplitSlots = usr.AvailableSlots.Split(new char[] { ',' });
                    if (SplitSlots[t] != "T")
                    {
                        return;
                    }
                }

                switch (equip)
                {
                case EquipmentType.Equip:
                {
                    if (item == null)
                    {
                        return;
                    }
                    if (!item.UseableBranch(Class))
                    {
                        Log.WriteError(usr.nickname + " tried to equip " + item.Name + " in the class " + Class + " [NOT ALLOWED!]");
                        usr.disconnect();
                        return;
                    }

/*
 *                          if (!item.UseableSlot(targetSlot))
 *                          {
 *                              Log.WriteError(usr.nickname + " tried to equip " + item.Name + " in the slot " + targetSlot + " [NOT ALLOWED!]");  // >--- Fallo en slot 7
 *                              usr.disconnect();
 *                              return;
 *                          }
 */
                    if (type == "I")
                    {
                        itemcode = Inventory.calculateInventory(inventoryid);
                    }

                    if (targetSlot < 0 || targetSlot > 8)
                    {
                        Log.WriteDebug("User " + usr.nickname + " tried to equip slot " + targetSlot);
                        usr.disconnect();
                        return;
                    }

                    bool alreadyEquipped = (usr.equipment[Class, targetSlot] == itemcode);

                    if (!alreadyEquipped)
                    {
                        /* Skip if is already equipped to another check */
                        for (int i = 0; i < 8; i++)
                        {
                            if (usr.equipment[Class, i] == itemcode)
                            {
                                alreadyEquipped = true;
                                break;
                            }
                        }
                    }

                    if (!alreadyEquipped)
                    {
                        usr.equipment[Class, targetSlot] = itemcode;
                        usr.LoadRetails();
                    }
                    else
                    {
                        usr.send(new SP_Itemequipment(SP_Itemequipment.ErrorCodes.AlreadyEquipped));
                    }

                    break;
                }

                case EquipmentType.Unequip:
                {
                    targetSlot = int.Parse(getBlock(3));

                    if (targetSlot < 0 || targetSlot > 8)
                    {
                        Log.WriteDebug("User " + usr.nickname + " tried to unequip slot " + targetSlot);
                        usr.disconnect();
                        return;
                    }

                    if (usr.equipment[Class, targetSlot] != "^")
                    {
                        usr.equipment[Class, targetSlot] = "^";
                        usr.LoadRetails();
                    }

                    break;
                }

                case EquipmentType.SixSlot:
                {
                    if (itemcode.Contains("-"))         // When equipping 2 items
                    {
                        if (targetSlot != 5)
                        {
                            return;                          // Double item only on 6th slot
                        }
                        string[] codeInfo = itemcode.Split('-');

                        if (!usr.HasItem(codeInfo[0]) || !usr.HasItem(codeInfo[1]) || !Inventory.isPXItem(codeInfo[0]) || !Inventory.isPXItem(codeInfo[1]))
                        {
                            return;
                        }

                        int index1 = usr.GetItemIndex(codeInfo[0]);
                        int index2 = usr.GetItemIndex(codeInfo[1]);

                        itemcode = Inventory.calculateInventory(index1) + "-" + Inventory.calculateInventory(index2);
                    }
                    else         // When unequipping one of two px
                    {
                        if (!Inventory.isPXItem(itemcode))
                        {
                            return;
                        }
                        int itemIndex = usr.GetItemIndex(itemcode);

                        itemcode = Inventory.calculateInventory(itemIndex);
                    }

                    usr.equipment[Class, 5] = itemcode;
                    break;
                }
                }

                string equipmentString = usr.GetEquipment(Class);
                usr.send(new SP_Itemequipment(Class, equipmentString));
                DB.RunQuery("UPDATE equipment SET class" + Class + "='" + equipmentString + "' WHERE ownerid='" + usr.userId + "'");
            }
            else
            {
                // Cheat Engine / ArtMoney or whatever?
                Log.WriteError(usr.nickname + " tried to equip " + itemcode + " but he haven't it!");
                usr.disconnect();
            }
        }
Пример #5
0
        private TcpPacket AnalyzePacket(byte[] data)
        {
            ushort    signature = data[0];
            ushort    length    = Generic.ByteToUShort(data, 1); // 3 = Header
            ushort    packetId  = Generic.ByteToUShort(data, 3);
            TcpPacket packet    = (TcpPacket)packetId;

            if (data.Length == length + 3)              // + 3 equals to the header
            {
                if (packet == TcpPacket.Authentication) //>---  22039
                {
                    if (this.usr == null)
                    {
                        this.connectionId = Generic.ByteToUShort(data, 7); // Sent on 24832 (last block)
                        Log.WriteLine("> -- TCP-108 connectionId: " + connectionId);
                        this.usr = Managers.UserManager.GetUser(this.connectionId);

                        if (this.usr == null)
                        {
                            disconnect("No valid p2s user");
                            return(packet);
                        }

                        this.usr.tcpClient = this;
                    }
                }
                else if (packet == TcpPacket.HackShield)
                {
                    /* Just handle */
                }
                else if (packet == TcpPacket.ClientHearthBeat)
                {
                    usr.heartBeatTime = Generic.timestamp + 60;
                }
                else if (packet == TcpPacket.UpdatePlayerStatus || packet == TcpPacket.Bullet || packet == TcpPacket.Explosion || packet == TcpPacket.HackInfo ||
                         packet == TcpPacket.ObjectMove || packet == TcpPacket.PlayerEmotion || packet == TcpPacket.PlayerRoll || packet == TcpPacket.UpdateVehicleStatus ||
                         packet == TcpPacket.SwitchWeapon || packet == TcpPacket.ThrowGranadeRocket || packet == TcpPacket.WeaponExplosion ||
                         packet == TcpPacket.WeaponZoom || packet == TcpPacket.TextChat)
                {
                    if (usr != null && usr.room != null)
                    {
                        if (usr.room.gameactive && (usr.room.users.Count > 1 || usr.room.spectators.Count > 0))
                        {
                            byte playerSlot = (byte)data[9];

                            if (playerSlot == usr.roomslot && usr.IsAlive())
                            {
                                if (packet == TcpPacket.ThrowGranadeRocket)
                                {
                                    Managers.Item item = Managers.ItemManager.GetItemByID(usr.weapon);

                                    if (item != null)
                                    {
                                        bool snowFight   = usr.room.new_mode == 6 && usr.room.new_mode_sub == 2; //>--- 6=snowFight
                                        bool grenadeOnly = usr.room.new_mode == 4;                               //>--- Solo granadas

                                        if (!snowFight)
                                        {
                                            if (item.UseableBranch(4) && (item.UseableSlot(2) || item.UseableSlot(5) || item.UseableSlot(7)))
                                            {
                                                usr.throwRockets++;
                                            }
                                            else if (item.UseableSlot(3) || item.UseableBranch(4))
                                            {
                                                usr.throwNades++;
                                            }
                                        }

                                        if ((usr.throwNades >= 100 || usr.throwRockets >= 100) && !grenadeOnly) //>--- Cambio 10 nades y 50 rockets por 100
                                        {
                                            Log.WriteError("User " + usr.nickname + " throw more than " + (usr.throwRockets >= 100 ? "100 rockets" : "10 nades"));
                                            usr.disconnect();
                                            return(packet);
                                        }
                                    }
                                }

                                SendToRoom(data);
                            }
                        }
                    }
                }
                else
                {
                    Log.WriteError("Unhandled TCP Packet (" + packetId + ") " + usr.nickname + " " + usr.room.id);
                }
            }
            return(packet);
        }
Пример #6
0
        public override void Handle(User usr)
        {
            if (blocks.Length < 17 || blocks[18] != "dnjfhr^")
            {
                usr.disconnect();
            }
            int userId = int.Parse(getBlock(1));

            if (userId > 0)
            {
                /* Blocks changes on the other WarRock Version */
                int    ticketId = int.Parse(getBlock(0));
                string username = getBlock(3);
                string nickname = getBlock(4);

                if (username.Length > 0 && username.Length <= 16 && ticketId >= 0 && userId >= 0)
                {
                    DataTable dt = DB.RunReader("SELECT * FROM users WHERE username='******' AND id='" + userId + "'");
                    if (dt.Rows.Count > 0)
                    {
                        try
                        {
                            DataRow userInformation = dt.Rows[0];
                            int     dbTicketId      = 0;
                            int.TryParse(userInformation["ticketid"].ToString(), out dbTicketId);
                            if (dbTicketId == ticketId && dbTicketId != -1 || Configs.Server.Debug)
                            {
                                usr.userId   = userId;
                                usr.username = userInformation["username"].ToString();
                                usr.nickname = userInformation["nickname"].ToString();
                                usr.exp      = int.Parse(userInformation["exp"].ToString());
                                usr.dinar    = Convert.ToInt32(userInformation["dinar"].ToString());
                                usr.kills    = int.Parse(userInformation["kills"].ToString());
                                usr.deaths   = int.Parse(userInformation["deaths"].ToString());
                                usr.premium  = byte.Parse(userInformation["premium"].ToString());
                                uint.TryParse(userInformation["premiumExpire"].ToString(), out usr.premiumExpire);
                                usr.cash         = int.Parse(userInformation["cash"].ToString());
                                usr.rank         = int.Parse(userInformation["rank"].ToString());
                                usr.coupons      = int.Parse(userInformation["coupons"].ToString());
                                usr.todaycoupons = int.Parse(userInformation["todaycoupon"].ToString());
                                usr.clanId       = int.Parse(userInformation["clanID"].ToString());
                                usr.headshots    = int.Parse(userInformation["headshots"].ToString());
                                uint.TryParse(userInformation["mutedExpire"].ToString(), out usr.mutedexpire);
                                usr.firstlogin          = int.Parse(userInformation["firstlogin"].ToString());
                                usr.country             = userInformation["country"].ToString();
                                usr.coupontime          = int.Parse(userInformation["coupontime"].ToString());
                                usr.storageInventoryMax = usr.rank > 2 ? 24 : 12;
                                uint.TryParse(userInformation["donationexpire"].ToString(), out usr.donationexpire);
                                int randombox = 0;
                                int.TryParse(userInformation["randombox"].ToString(), out randombox);
                                usr.RandomBoxToday = (randombox == 1);

                                usr.rewardEvent.doneToday = int.Parse(userInformation["loginEventToday"].ToString()) == 1;

                                int.TryParse(userInformation["loginEventProgress"].ToString(), out usr.rewardEvent.progress);

                                int.TryParse(userInformation["killcount"].ToString(), out usr.eventcount);

                                ushort.TryParse(userInformation["wonMatchs"].ToString(), out usr.wonMatchs);
                                ushort.TryParse(userInformation["lostMatchs"].ToString(), out usr.lostMatchs);

                                int lastjoin = 0;
                                int.TryParse(userInformation["lastjoin"].ToString(), out lastjoin);

                                if (string.Compare(userInformation["retailcode"].ToString(), "null", true) != 0)
                                {
                                    usr.retail = userInformation["retailcode"].ToString();
                                    int.TryParse(userInformation["retailclass"].ToString(), out usr.retailclass);
                                }

                                string chat_color = userInformation["chat_color"].ToString();

                                if (chat_color != "" && chat_color.Length >= 6)
                                {
                                    usr.chatColor = Generic.ConvertHexToRGB(chat_color);
                                }

                                usr.ticketId = ticketId;

                                if (usr.rank > 0)
                                {
                                    string LastDayStats = userInformation["Lastdaystats"].ToString();;

                                    string today = DateTime.Now.ToString("dd-MM-yyyy");

                                    if (LastDayStats == today)
                                    {
                                        usr.dailystats = true;
                                    }

                                    if (usr.dinar < 0)
                                    {
                                        usr.dinar = 0;
                                    }
                                    if (usr.cash < 0)
                                    {
                                        usr.cash = 0;
                                    }

                                    if (usr.rank < 5)
                                    {
                                        Country c = Program.ipLookup.getCountry(usr.IP);
                                        usr.country = c.getCode();
                                    }

                                    /* Clan Part */

                                    usr.clan = Managers.ClanManager.GetClan(usr.clanId);

                                    if (usr.clan != null)
                                    {
                                        if (usr.clan.clanRank(usr) != 9)
                                        {
                                            if (usr.clan.ClanUsers.ContainsKey(usr.userId))
                                            {
                                                ClanUsers c = (ClanUsers)usr.clan.ClanUsers[usr.userId];
                                                if (usr.exp.ToString() != c.EXP)
                                                {
                                                    c.EXP = usr.exp.ToString();
                                                }

                                                if (string.Compare(usr.nickname, nickname, true) == 0)
                                                {
                                                    c.nickname = usr.nickname;
                                                }
                                            }

                                            if (!usr.clan.Users.ContainsKey(usr.userId))
                                            {
                                                usr.clan.Users.TryAdd(usr.userId, usr);
                                            }
                                        }
                                        else
                                        {
                                            if (usr.clan.pendingUsers.ContainsKey(usr.userId))
                                            {
                                                ClanPendingUsers c = (ClanPendingUsers)usr.clan.pendingUsers[usr.userId];
                                                if (usr.exp.ToString() != c.EXP)
                                                {
                                                    c.EXP = usr.exp.ToString();
                                                }

                                                if (string.Compare(usr.nickname, nickname, true) == 0)
                                                {
                                                    c.nickname = usr.nickname;
                                                }
                                            }
                                        }
                                    }
                                    else
                                    {
                                        if (usr.clanId != -1)
                                        {
                                            DB.RunQuery("UPDATE users SET clanid='-1', clanrank='0' WHERE id='" + userId + "'");
                                        }
                                    }

                                    usr.accesslevel = (usr.rank > 2 ? 3 : 0);

                                    #region Equipment Reset System
                                    for (int Class = 0; Class < 5; Class++) //>--- Equipo por defecto
                                    {
                                        for (int Slot = 0; Slot < 8; Slot++)
                                        {
                                            if (Slot == (int)User.Slots.Hands)
                                            {
                                                usr.equipment[Class, Slot] = "DA02"; //Knuckle
                                            }
                                            else if (Slot == (int)User.Slots.HandGun)
                                            {
                                                usr.equipment[Class, Slot] = "DB01"; //Colt
                                            }
                                            else if (Slot == (int)User.Slots.Weapon1)
                                            {
                                                switch (Class)
                                                {
                                                case (int)User.Classes.Engeneer:
                                                case (int)User.Classes.Medic:
                                                    usr.equipment[Class, Slot] = "DF01";     // MP7
                                                    break;

                                                case (int)User.Classes.Sniper:
                                                    usr.equipment[Class, Slot] = "DG05";     // DG_M24
                                                    break;

                                                case (int)User.Classes.Assault:
                                                    usr.equipment[Class, Slot] = "DC02";     // K2
                                                    break;

                                                case (int)User.Classes.Heavy:
                                                    usr.equipment[Class, Slot] = "DJ01";     // DJ_PZF_3
                                                    break;
                                                }
                                            }
                                            else if (Slot == (int)User.Slots.equipment)
                                            {
                                                switch (Class)
                                                {
                                                case (int)User.Classes.Engeneer:
                                                    usr.equipment[Class, Slot] = "DR01";     // Spanner
                                                    break;

                                                case (int)User.Classes.Medic:
                                                    usr.equipment[Class, Slot] = "DQ01";     // Medic Kit 1
                                                    break;

                                                case (int)User.Classes.Sniper:
                                                case (int)User.Classes.Assault:
                                                    usr.equipment[Class, Slot] = "DN01";     // Grenade
                                                    break;

                                                case (int)User.Classes.Heavy:
                                                    usr.equipment[Class, Slot] = "DL01";     // Mine
                                                    break;
                                                }
                                            }
                                            else
                                            {
                                                usr.equipment[Class, Slot] = "^";
                                            }
                                        }
                                    }
                                    #endregion

                                    int wrtime = Generic.WarRockDateTime;

                                    DataTable eq = DB.RunReader("SELECT class0, class1, class2, class3, class4, inventory, storage FROM equipment WHERE ownerid='" + usr.userId + "'");
                                    if (eq.Rows.Count > 0)
                                    {
                                        DataRow row = eq.Rows[0];
                                        usr.inventory        = row["inventory"].ToString().Split(',');
                                        usr.storageInventory = row["storage"].ToString().Split(',');

                                        for (int i = 0; i < usr.inventory.Length; i++)
                                        {
                                            string str = usr.inventory[i];
                                            string v   = str.Split('-')[0];

                                            usr.inventory[i] = "^";

                                            if (str != "^" && v.Length == 4)
                                            {
                                                usr.inventory[i] = str;
                                            }
                                        }

                                        bool tosave = false;

                                        for (int i = 0; i < usr.inventory.Length; i++)
                                        {
                                            if (usr.inventory[i] != "^")
                                            {
                                                try
                                                {
                                                    string[] weaponData = usr.inventory[i].Split('-');
                                                    string   code       = weaponData[0];
                                                    if (code.Length == 4)
                                                    {
                                                        int time = 0;
                                                        int.TryParse(weaponData[3], out time);
                                                        if (time < wrtime)
                                                        {
                                                            usr.expiredItems.Add(code);
                                                            usr.inventory[i] = "^";
                                                            tosave           = true;
                                                        }
                                                    }
                                                }
                                                catch { }
                                            }
                                        }

                                        if (tosave)
                                        {
                                            DB.RunQuery("UPDATE equipment SET inventory='" + Inventory.Itemlist(usr) + "' WHERE ownerid='" + usr.userId + "'");
                                        }

                                        string[] equipment = new string[] { row["class0"].ToString(), row["class1"].ToString(), row["class2"].ToString(), row["class3"].ToString(), row["class4"].ToString() };

                                        bool forcesave = false;

                                        string[] SplitSlots = usr.AvailableSlots.Split(new char[] { ',' });
                                        for (int i = 0; i < 5; i++)
                                        {
                                            string[] fetchItem = equipment[i].Split(',');
                                            for (int j = 0; j < 8; j++)
                                            {
                                                string inventoryCode = fetchItem[j];

                                                string dbCode = fetchItem[j];

                                                try
                                                {
                                                    Managers.Item item = null;
                                                    if (!dbCode.Contains("-"))
                                                    {
                                                        dbCode = dbCode.StartsWith("I") ? usr.GetItemByID(dbCode) : dbCode;
                                                        item   = Managers.ItemManager.GetItem(dbCode);
                                                    }

                                                    bool sixSlot = false;

                                                    if (inventoryCode != "^")
                                                    {
                                                        if (inventoryCode.StartsWith("I") && inventoryCode.Contains("-"))
                                                        {
                                                            string[] splitItems = inventoryCode.Split('-');
                                                            if (usr.HasItem(splitItems[0]) && usr.HasItem(splitItems[1]))
                                                            {
                                                                sixSlot = true;
                                                            }
                                                        }

                                                        bool reset = true;

                                                        bool HasItem = false;

                                                        if (!inventoryCode.Contains("-"))
                                                        {
                                                            HasItem = usr.HasItem(inventoryCode);
                                                        }

                                                        if (usr.IsWhitelistedWeapon(inventoryCode) || HasItem || sixSlot)
                                                        {
                                                            usr.equipment[i, j] = inventoryCode;
                                                            reset = false;
                                                        }

                                                        if (j >= 4)
                                                        {
                                                            int t = j - 4;
                                                            reset = !(SplitSlots[t] == "T" && inventoryCode != usr.retail);
                                                        }

                                                        if (item != null)
                                                        {
                                                            //reset = (!item.UseableSlot(j) || !item.UseableBranch(i) && i != 7); //>---  +++ SLOT 7 Restriccion
                                                            reset = (!item.UseableSlot(j) || !item.UseableBranch(i));
                                                        }

                                                        if (reset)
                                                        {
                                                            usr.equipment[i, j] = "^";
                                                            forcesave           = true;
                                                        }
                                                    }
                                                    else
                                                    {
                                                        usr.equipment[i, j] = "^";
                                                    }
                                                }
                                                catch (Exception ex)
                                                {
                                                    Log.WriteError("Error loading: " + dbCode);
                                                }
                                            }
                                        }

                                        if (forcesave)
                                        {
                                            usr.SaveEquipment();
                                        }
                                    }

                                    DataTable skin = DB.RunReader("SELECT class_0, class_1, class_2, class_3, class_4, inventory FROM users_costumes WHERE ownerid='" + usr.userId + "'");
                                    if (skin.Rows.Count > 0)
                                    {
                                        DataRow  row    = skin.Rows[0];
                                        string[] myskin = new string[] { row["class_0"].ToString(), row["class_1"].ToString(), row["class_2"].ToString(), row["class_3"].ToString(), row["class_4"].ToString() };
                                        for (int i = 0; i < 5; i++)
                                        {
                                            usr.costumes_char[i] = myskin[i];
                                        }

                                        usr.costume = row["inventory"].ToString().Split(',');

                                        bool forcesave = false;

                                        for (int i = 0; i < usr.costume.Length; i++)
                                        {
                                            if (usr.costume[i] != "^")
                                            {
                                                try
                                                {
                                                    string[] costumeData = usr.costume[i].Split('-');
                                                    string   code        = costumeData[0];
                                                    if (code.Length == 4)
                                                    {
                                                        int time = 0;
                                                        int.TryParse(costumeData[3], out time);
                                                        if (time < wrtime)
                                                        {
                                                            usr.expiredItems.Add(code);
                                                            usr.costume[i] = "^";
                                                            forcesave      = true;
                                                        }
                                                    }
                                                }
                                                catch { }
                                            }
                                        }

                                        if (forcesave)
                                        {
                                            DB.RunQuery("UPDATE users_costumes SET inventory='" + Inventory.Costumelist(usr) + "' WHERE ownerid='" + usr.userId + "'");
                                        }
                                    }
                                    else
                                    {
                                        DB.RunQuery("INSERT INTO users_costumes (ownerid) VALUES ('" + usr.userId + "')");
                                    }

                                    int inventoryLength        = usr.inventory.Length;
                                    int costumeInventoryLength = usr.costume.Length;
                                    int storageInventoryLength = usr.storageInventory.Length;

                                    if (inventoryLength < Configs.Server.Player.MaxInventorySlot)
                                    {
                                        Array.Resize(ref usr.inventory, Configs.Server.Player.MaxInventorySlot);
                                        for (int i = inventoryLength; i < Configs.Server.Player.MaxInventorySlot; i++)
                                        {
                                            usr.inventory[i] = "^";
                                        }
                                        DB.RunQuery("UPDATE equipment SET inventory='" + Inventory.Itemlist(usr) + "' WHERE ownerid='" + usr.userId + "'");
                                    }

                                    if (costumeInventoryLength < Configs.Server.Player.MaxCostumeSlot)
                                    {
                                        Array.Resize(ref usr.costume, Configs.Server.Player.MaxCostumeSlot);
                                        for (int i = costumeInventoryLength; i < Configs.Server.Player.MaxCostumeSlot; i++)
                                        {
                                            usr.costume[i] = "^";
                                        }
                                        DB.RunQuery("UPDATE users_costumes SET inventory='" + Inventory.Costumelist(usr) + "' WHERE ownerid='" + usr.userId + "'");
                                    }

                                    if (storageInventoryLength < usr.storageInventoryMax)
                                    {
                                        Array.Resize(ref usr.storageInventory, usr.storageInventoryMax);
                                        for (int i = storageInventoryLength; i < usr.storageInventoryMax; i++)
                                        {
                                            usr.storageInventory[i] = "^";
                                        }
                                        DB.RunQuery("UPDATE equipment SET stoarge='" + Inventory.Storage(usr) + "' WHERE ownerid='" + usr.userId + "'");
                                    }

                                    usr.CheckForCostume();
                                    usr.LoadInboxItems();
                                    usr.LoadRetails();
                                    //usr.send(new SP_KillCount(SP_KillCount.ActionType.Hide)); // Clear previously data
                                    if (Managers.UserManager.addUser(usr)) // Do not add after packet send
                                    {
                                        #region Random Weapon Login

                                        int eventId = 1;

                                        if (!usr.CheckForEvent(eventId) && Configs.Server.LoginEvent.enabled)
                                        {
                                            if (Inventory.GetFreeItemSlotCount(usr) > 0)
                                            {
                                                string[]      randomItems = Configs.Server.LoginEvent.items;
                                                int           index       = Generic.random(0, randomItems.Length - 1);
                                                string        item        = randomItems[index];
                                                Managers.Item i           = Managers.ItemManager.GetItem(item);
                                                if (i != null)
                                                {
                                                    int days = new Random().Next(Configs.Server.LoginEvent.MinDays, Configs.Server.LoginEvent.MaxDays);
                                                    Inventory.AddItem(usr, item, days);
                                                    usr.AddEvent(eventId);
                                                    usr.send(new SP_CustomMessageBox("You've obtained " + i.Name + " for " + days + " day(s)."));
                                                }
                                                else
                                                {
                                                    Log.WriteError(item + " is not a valid item @ log in event!");
                                                }
                                            }
                                        }

                                        #endregion

                                        usr.send(new SP_CharacterInfo(usr));

                                        Managers.UserManager.UpdateUserlist(usr);

                                        if (usr.expiredItems.Count > 0)
                                        {
                                            const int b      = 30;
                                            int       length = (int)Math.Ceiling((decimal)usr.expiredItems.Count / b);
                                            for (int i = 0; i < length; i++)
                                            {
                                                usr.send(new SP_UpdateInventory(usr, usr.expiredItems.Skip(i * b).Take(b).ToList()));
                                            }
                                            usr.expiredItems.Clear();
                                        }

                                        if (usr.expiredCostumes.Count > 0)
                                        {
                                            const int b      = 30;
                                            int       length = (int)Math.Ceiling((decimal)usr.expiredCostumes.Count / b);
                                            for (int i = 0; i < length; i++)
                                            {
                                                usr.send(new SP_UpdateInventory(usr, usr.expiredCostumes.Skip(i * b).Take(b).ToList()));
                                            }
                                            usr.expiredCostumes.Clear();
                                        }

                                        usr.PremiumTimeLeft();
                                        usr.PingTime = DateTime.Now;
                                        usr.send(new SP_PingInformation(usr));
                                        usr.LoadOutboxItems();
                                        usr.send(new SP_StorageInventoryList(usr));

                                        usr.send(new SP_MyRank(usr));

                                        usr.LoadFriends();

                                        if (usr.rank == 2) // Donator
                                        {
                                            DateTime             now  = DateTime.Now;
                                            DateTime             dexp = new DateTime(1970, 1, 1, 0, 0, 0, 0).AddSeconds(usr.donationexpire);
                                            TimeSpan             ts   = dexp - now;
                                            System.Drawing.Color c    = System.Drawing.Color.FromArgb(15, 192, 252);

                                            usr.send(new SP_ColoredChat(Configs.Server.SystemName + " >> Your donator status will expire in " + ((int)Math.Round(ts.TotalDays) - 1) + " days", SP_ColoredChat.ChatType.Normal, c));
                                        }

                                        if (usr.firstlogin == 2)
                                        {
                                            usr.CheckForFirstLogin();
                                            usr.send(new SP_UpdateInventory(usr, null));
                                        }
                                        else if (lastjoin <= (Generic.timestamp - (60 * 86400)))
                                        {
                                            usr.ComeBackReward();
                                            usr.send(new SP_UpdateInventory(usr, null));
                                        }

                                        foreach (TempItem i in usr.InBoxItems)
                                        {
                                            string days = "day(s)";
                                            if (i.days >= 3600)
                                            {
                                                days = "One use / Permanent";
                                            }
                                            usr.send(new SP_Chat("SYSTEM", SP_Chat.ChatType.Room_ToAll, "SYSTEM >> You've got " + i.name + " for " + i.days + " " + days + "!", 998, "NULL"));
                                        }

                                        usr.sessionStart = Generic.timestamp;

                                        //usr.send(new SP_CustomMessageBox("We're sorry to disturb your game guys, but we're actually trying to fix an important issue, we apologize for the issue."));

                                        usr.send(new SP_AntiCheat(usr));
                                        usr.AntiCheatTick = (uint)(Generic.timestamp + Configs.Server.AntiCheat.routinetick);
                                    }
                                    else
                                    {
                                        // User already connected (?)
                                        Log.WriteError(usr.nickname + " > logged in but couldn't be added to the stuck");
                                        usr.disconnect();
                                    }
                                }
                                else
                                {
                                    // Logging while banned BOT (?)
                                    Log.WriteError(usr.nickname + " > logged in as banned user");
                                    usr.disconnect();
                                }
                            }
                            else
                            {
                                // Invalid Ticket ID
                                Log.WriteError(username + " tried to login with wrong ticket id!");
                            }
                        }
                        catch (Exception e)
                        {
                            // Error parsing user info
                            Console.WriteLine(e);
                            Log.WriteError("Error parsing user information for user " + username);
                        }
                    }
                    else
                    {
                        // No user data found
                        Log.WriteError("No user data found for user " + username);
                        usr.disconnect();
                    }
                }
                else
                {
                    // Invalid packet data
                    Log.WriteError(username + " -> error with " + (username.Length == 0 ? " username length" : " Ticket ID"));
                    usr.disconnect();
                }

                DB.RunQuery("UPDATE users SET ticketid='-1' WHERE id='" + usr.userId + "'");
            }
            else
            {
                // Invalid request
                Log.WriteError(usr.nickname + " > logged in - invalid request");
                usr.disconnect();
            }
        }
Пример #7
0
        public override void Handle(User usr)
        {
            if (usr.room != null)
            {
                return;
            }
            SubCodes opcode = (SubCodes)int.Parse(getBlock(0));

            switch (opcode)
            {
            case SubCodes.OnItemShopOpen:
            {
                usr.RefreshCash();
                break;
            }

            case SubCodes.OnItemBuy:
            {
                string itemcode = getBlock(6).ToUpper();
                int    period   = int.Parse(getBlock(3));

                ushort days = (ushort)Inventory.GetDaysFromPeriod(period);

                Item item = ItemManager.GetItem(itemcode);
                if (item != null)
                {
                    if (days > 0)
                    {
                        if (item.Buyable || Configs.Server.ItemShop.hiddenItems.Contains(itemcode))
                        {
                            int inventorySlot = Inventory.GetFreeItemSlotCount(usr);
                            if (inventorySlot > 0)
                            {
                                uint price = (uint)item.GetCashPrice(period);

                                usr.RefreshCash();

                                if (price > 0)
                                {
                                    bool px_item = (itemcode.ToLower().StartsWith("cz") || itemcode.ToLower().StartsWith("cb"));         //>--- PremiumUsersOnly
                                    int  result  = (int)(usr.cash - price);
                                    if (item.Premium && usr.premium < 1)
                                    {
                                        usr.send(new SP_DinarItemBuy(SP_DinarItemBuy.ErrorCodes.PremiumUsersOnly));
                                    }

                                    /*else if (usr.level < item.Level && usr.rank < 2) // >--- Comentado en origen
                                     * {
                                     *  usr.send(new SP_DinarItemBuy(SP_DinarItemBuy.ErrorCodes.LevelLow));
                                     * }*/
                                    else if (item.accruable && Inventory.GetEAItem(usr, item.Code) >= item.maxAccrueCount)
                                    {
                                        usr.send(new SP_DinarItemBuy(SP_DinarItemBuy.ErrorCodes.CannotBeBougth));
                                    }
                                    else if (result < 0)
                                    {
                                        usr.send(new SP_DinarItemBuy(SP_DinarItemBuy.ErrorCodes.NotEnoughDinar));
                                    }
                                    else
                                    {
                                        if (px_item)
                                        {
                                            days = 3600;
                                        }

                                        ushort count = 1;

                                        if (item.accruable)
                                        {
                                            ushort d = (ushort)item.GetEACount(period);
                                            if (d >= 1)
                                            {
                                                count = d;
                                            }
                                        }

                                        switch (itemcode)
                                        {
                                        case "CB53":             //>--- CHG_CLANEXTEND
                                        {
                                            if (usr.clan == null || usr.clan.maxUsers >= 100)
                                            {
                                                usr.send(new SP_DinarItemBuy(SP_DinarItemBuy.ErrorCodes.CannotBeBougth));
                                                return;
                                            }
                                            usr.clan.maxUsers += 20;
                                            usr.send(new SP_Chat(Configs.Server.SystemName, SP_Chat.ChatType.Clan, Configs.Server.SystemName + " >> Clan expanded, please re-open clan tab to see changes.", 999, Configs.Server.SystemName));
                                            usr.send(new SP_DinarItemBuy(usr, itemcode));
                                            usr.send(new SP_Clan.MyClanInformation(usr));
                                            DB.RunQuery("UPDATE clans SET maxusers='" + usr.clan.maxUsers + "' WHERE id='" + usr.clan.id + "'");
                                            return;
                                        }

                                        default:
                                        {
                                            if ((itemcode.StartsWith("CZ") || itemcode.StartsWith("CC") || itemcode.StartsWith("CR") || itemcode.StartsWith("CB")) && !itemcode.StartsWith("CC0") && itemcode != "CC38")
                                            {
                                                days = 3600;
                                            }
                                            Inventory.AddOutBoxItem(usr, itemcode, (ushort)days, count);
                                            break;
                                        }
                                        }
                                        //DB.RunQuery("INSERT INTO purchases_logs (userid, log, timestamp) VALUES ('" + usr.userId + "', '" + usr.nickname + " bought " + item.Name + " for " + days + " days [" + price + " Cash - Game]', '" + Generic.timestamp + "')");

                                        usr.cash = result;

                                        DB.RunQuery("UPDATE users SET cash=" + result + " WHERE id='" + usr.userId + "'");
                                        usr.send(new SP_CashItemBuy(usr));
                                        usr.send(new SP_OutboxSend(usr));
                                    }
                                }
                                else
                                {
                                    usr.send(new SP_DinarItemBuy(SP_DinarItemBuy.ErrorCodes.CannotBeBougth));
                                }
                            }
                            else
                            {
                                usr.send(new SP_DinarItemBuy(SP_DinarItemBuy.ErrorCodes.InventoryFull));
                            }
                        }
                        else
                        {
                            usr.send(new SP_DinarItemBuy(SP_DinarItemBuy.ErrorCodes.NoLongerValid));
                        }
                    }
                    else
                    {
                        usr.send(new SP_DinarItemBuy(SP_DinarItemBuy.ErrorCodes.NoLongerValid));
                    }
                }
                break;
            }

            case SubCodes.Storage:
            {
                usr.send(new SP_CustomMessageBox("The storage system has been disabled because it's useless."));
                return;

                /* atm it has some few bugs but working and itself it's useless*/

                /*
                 * int action = int.Parse(getBlock(1));
                 *
                 * switch(action)
                 * {
                 *  case 2: // Move to storage box
                 *      {
                 *          string itemCode = getBlock(3);
                 *          int invIndex = int.Parse(getBlock(2));
                 *          string[] data = usr.inventory[invIndex].Split('-');
                 *          if(data[0] == itemCode)
                 *          {
                 *              int emptyIndex = Array.IndexOf(usr.storageInventory, "^");
                 *              if(emptyIndex >= 0 && emptyIndex < usr.storageInventoryMax)
                 *              {
                 *                  usr.storageInventory[emptyIndex] = usr.inventory[invIndex];
                 *                  usr.inventory[invIndex] = "^";
                 *
                 *                  string invCode = Inventory.calculateInventory(invIndex);
                 *
                 *                  for (int i = 0; i < 5; i++)
                 *                  {
                 *                      for (int j = 0; j < 8; j++)
                 *                      {
                 *                          if (usr.equipment[i, j] == "I" + invCode || usr.equipment[i, j] == itemCode)
                 *                          {
                 *                              usr.equipment[i, j] = "^";
                 *                          }
                 *                          else if (usr.equipment[i, j].Contains("-"))
                 *                          {
                 *                              string[] multipleSlot = usr.equipment[i, j].Split('-');
                 *                              if (multipleSlot[0] == "I" + invCode)
                 *                              {
                 *                                  usr.equipment[i, j] = multipleSlot[1];
                 *                              }
                 *                              else if (multipleSlot[1] == "I" + invCode)
                 *                              {
                 *                                  usr.equipment[i, j] = multipleSlot[0];
                 *                              }
                 *                          }
                 *                      }
                 *                  }
                 *
                 *                  usr.SaveEquipment();
                 *
                 *                  usr.send(new SP_StorageInventoryUpdate(usr, action, invIndex, itemCode));
                 *
                 *                  usr.send(new SP_UpdateInventory(usr, null));
                 *
                 *                  DB.RunQuery("UPDATE equipment SET inventory = '" + Inventory.Itemlist(usr) + "', storage = '" + Inventory.Storage(usr) + "' WHERE ownerid = '" + usr.userId + "'");
                 *              }
                 *              else
                 *              {
                 *                  usr.send(new SP_StorageInventoryUpdate(SP_StorageInventoryUpdate.ErrorCode.NoStorageFreeSpace));
                 *              }
                 *          }
                 *          break;
                 *      }
                 *  case 3: // Move to inventory
                 *      {
                 *          string itemCode = getBlock(3);
                 *          int invIndex = int.Parse(getBlock(2));
                 *          int wrTime = Generic.WarRockDateTime;
                 *          string[] data = usr.storageInventory[invIndex].Split('-');
                 *          if (data[0] == itemCode)
                 *          {
                 *              int time = int.Parse(data[3]);
                 *              if (time > wrTime)
                 *              {
                 *                  if (usr.HasItem(itemCode))
                 *                  {
                 *                      usr.storageInventory[invIndex] = "^";
                 *
                 *                      int inventoryIndex = usr.GetItemIndex(itemCode);
                 *
                 *                      string[] inventoryString = usr.inventory[inventoryIndex].Split('-');
                 *
                 *                      DateTime dtStored = DateTime.ParseExact(inventoryString[3], "yyMMddHH", null);
                 *
                 *                      TimeSpan ts = dtStored - DateTime.Now;
                 *
                 *                      Inventory.AddItem(usr, itemCode, (int)ts.TotalDays);
                 *
                 *                      usr.send(new SP_StorageInventoryUpdate(usr, action, invIndex, itemCode));
                 *                  }
                 *                  else
                 *                  {
                 *                      int emptyIndex = Array.IndexOf(usr.inventory, "^");
                 *                      if (emptyIndex >= 0)
                 *                      {
                 *                          usr.inventory[emptyIndex] = usr.storageInventory[invIndex];
                 *                          usr.storageInventory[invIndex] = "^";
                 *
                 *                          usr.send(new SP_StorageInventoryUpdate(usr, action, invIndex, itemCode));
                 *                      }
                 *                      else
                 *                      {
                 *                          usr.send(new SP_StorageInventoryUpdate(SP_StorageInventoryUpdate.ErrorCode.NoInventoryFreeSpace));
                 *                      }
                 *                  }
                 *              }
                 *              else
                 *              {
                 *                  usr.storageInventory[invIndex] = "^";
                 *
                 *                  usr.send(new SP_StorageInventoryList(usr));
                 *              }
                 *              DB.RunQuery("UPDATE equipment SET inventory = '" + Inventory.Itemlist(usr) + "', storage = '" + Inventory.Storage(usr) + "' WHERE ownerid = '" + usr.userId + "'");
                 *          }
                 *          break;
                 *      }
                 *  case 4: // Remove all expired items
                 *      {
                 *          int wrTime = Generic.WarRockDateTime;
                 *          for (int i = 0; i < usr.storageInventory.Length; i++)
                 *          {
                 *              try
                 *              {
                 *                  string data = usr.storageInventory[i];
                 *                  if (data != "^")
                 *                  {
                 *                      string[] split = data.Split('-');
                 *                      int time = int.Parse(split[3]);
                 *                      if (time < wrTime)
                 *                      {
                 *                          usr.storageInventory[i] = "^";
                 *                      }
                 *                  }
                 *              }
                 *              catch { }
                 *          }
                 *
                 *
                 *          usr.send(new SP_StorageInventoryList(usr));
                 *          DB.RunQuery("UPDATE equipment SET inventory = '" + Inventory.Itemlist(usr) + "', storage = '" + Inventory.Storage(usr) + "' WHERE ownerid = '" + usr.userId + "'");
                 *          break;
                 *      }
                 * }
                 *
                 * break;
                 */
            }

            case SubCodes.OnItemUse:
            {
                string itemcode = getBlock(4);
                if (!usr.HasItem(itemcode))
                {
                    return;
                }

                //Log.WriteLine("CashItemBuy-299 INCOMING PACKET :: " + string.Join(" ", getAllBlocks));

                if (PackageManager.AddItem(usr, itemcode))
                {
                    usr.send(new SP_UseItem(usr, itemcode));
                }
                else
                {
                    switch (itemcode)
                    {
                    case "CB01":             // Change Nickname
                    {
                        string nickname = getBlock(5);
                        if (!Generic.IsAlphaNumeric(nickname))
                        {
                            return;
                        }

                        DataTable dt = DB.RunReader("SELECT * FROM users WHERE nickname='" + nickname + "'");

                        if (dt.Rows.Count == 0)
                        {
                            DB.RunQuery("INSERT INTO changenick_logs (userId, oldnick, newnick, date, timestamp) VALUES ('" + usr.userId + "', '" + usr.nickname + "', '" + nickname + "', '" + Generic.currentDate + "', '" + Generic.timestamp + "')");

                            Log.WriteLine("---" + usr.nickname + " is now known as " + nickname + "---");

                            usr.nickname = nickname;
                            DB.RunQuery("UPDATE users SET nickname='" + usr.nickname + "' WHERE id='" + usr.userId + "'");
                            usr.deleteItem(itemcode);
                            usr.send(new SP_CashItemUse(usr, itemcode));

                            int clanrank = usr.clan.clanRank(usr);
                            switch (clanrank)
                            {
                            default:
                            {
                                ClanUsers cu = usr.clan.GetUser(usr.userId);
                                if (cu != null)
                                {
                                    cu.EXP      = usr.exp.ToString();
                                    cu.nickname = usr.nickname;
                                }
                                break;
                            }

                            case 9:
                            {
                                ClanPendingUsers cu = usr.clan.getPendingUser(usr.userId);
                                if (cu != null)
                                {
                                    cu.EXP      = usr.exp.ToString();
                                    cu.nickname = usr.nickname;
                                }
                                break;
                            }
                            }
                        }
                        break;
                    }

                    case "CB03":             // Kill / Death Reset
                    {
                        usr.kills = usr.deaths = 0;
                        DB.RunQuery("UPDATE users SET kills = '" + usr.kills + "', deaths = '" + usr.deaths + "' WHERE id='" + usr.userId + "'");
                        usr.deleteItem(itemcode);
                        usr.send(new SP_CashItemUse(usr, itemcode));
                        break;
                    }

                    case "CZ73":             // Ham Radio
                    {
                        string message = getBlock(5);

                        Inventory.DecreaseEAItem(usr, itemcode);

                        string[] m = message.Split(' ');

                        for (int i = 0; i < m.Length; i++)
                        {
                            m[i] = WordFilterManager.Replace(m[i]);
                        }

                        message = string.Join(" ", m);

                        usr.send(new SP_CashItemUse(usr, "CB03"));
                        usr.AddAdminCPLog(usr.nickname + " sent message " + message.Replace((char)0x1D, (char)0x20) + " [HAM_RADIO]");
                        UserManager.sendToServer(new SP_Chat(usr.nickname, SP_Chat.ChatType.Notice1, message, 0, usr.nickname));
                        break;
                    }

                    case "CC56":             // Random Box 1
                    case "CC57":             // Random Box 2
                    case "CC36":             // Random Box 3
                    case "CC37":             // Random Box 4
                    {
                        Item boxItem = ItemManager.GetItem(itemcode);

                        if (boxItem != null)
                        {
                            List <PackageItem> randomItems = boxItem.packageItems;

                            if (randomItems.Count > 0)
                            {
                                if (Inventory.GetFreeItemSlotCount(usr) > 0)
                                {
                                    int index = Generic.random(0, randomItems.Count - 1);
                                    if (index == 0 && Generic.random(100, 1000) > 200)
                                    {
                                        index = Generic.random(1, randomItems.Count - 1);
                                    }
                                    PackageItem   item = randomItems[index];
                                    Managers.Item i    = Managers.ItemManager.GetItem(item.item);
                                    if (i != null)
                                    {
                                        int days = item.days;
                                        Inventory.AddItem(usr, item.item, days);
                                        Inventory.DecreaseEAItem(usr, itemcode);
                                        usr.send(new SP_WinItem(usr, item.item, days));
                                    }
                                    else
                                    {
                                        Log.WriteError(item + " is not a valid item @ random box!");
                                    }
                                }
                            }
                        }

                        break;
                    }

                    case "CZ99":             // Random Box
                    {
                        if (Inventory.GetFreeItemSlotCount(usr) > 0)
                        {
                            string[]      randomItems = Configs.Server.RandomBoxEvent.items;
                            int           index       = Generic.random(0, randomItems.Length - 1);
                            string        item        = randomItems[index];
                            Managers.Item i           = Managers.ItemManager.GetItem(item);
                            if (i != null)
                            {
                                int days = new Random().Next(Configs.Server.RandomBoxEvent.MinDays, Configs.Server.RandomBoxEvent.MaxDays);
                                if (item.ToUpper().StartsWith("B"))
                                {
                                    Inventory.AddCostume(usr, item, days);
                                }
                                else
                                {
                                    Inventory.AddItem(usr, item, days);
                                }

                                Inventory.DecreaseEAItem(usr, itemcode);
                                usr.send(new SP_WinItem(usr, item, days));
                            }
                            else
                            {
                                Log.WriteError(item + " is not a valid item @ random box event!");
                            }
                        }
                        break;
                    }

                    case "CR16":             // Attendance Box
                    {
                        if (Inventory.GetFreeItemSlotCount(usr) > 0)
                        {
                            string[]      randomItems = Configs.Server.ItemShop.attendanceBox;
                            int           index       = Generic.random(0, randomItems.Length - 1);
                            string        item        = randomItems[index];
                            Managers.Item i           = Managers.ItemManager.GetItem(item);
                            if (i != null)
                            {
                                int days = new Random().Next(3, 14);
                                if (item.ToUpper().StartsWith("B"))
                                {
                                    Inventory.AddCostume(usr, item, days);
                                }
                                else
                                {
                                    Inventory.AddItem(usr, item, days);
                                }

                                Inventory.DecreaseEAItem(usr, itemcode);
                                usr.send(new SP_WinItem(usr, item, days));
                            }
                            else
                            {
                                Log.WriteError(item + " is not a valid item @ attendance box box event!");
                            }
                        }
                        break;
                    }

                    case "CR05":             // WarRock Gift Box
                    {
                        if (Inventory.GetFreeItemSlotCount(usr) > 0)
                        {
                            string[]      randomItems = Configs.Server.ChristmasBoxEvent.items;
                            int           index       = Generic.random(0, randomItems.Length - 1);
                            string        item        = randomItems[index];
                            Managers.Item i           = Managers.ItemManager.GetItem(item);
                            if (i != null)
                            {
                                int days = new Random().Next(Configs.Server.ChristmasBoxEvent.MinDays, Configs.Server.ChristmasBoxEvent.MaxDays);
                                if (item.ToUpper().StartsWith("B"))
                                {
                                    Inventory.AddCostume(usr, item, days);
                                }
                                else
                                {
                                    Inventory.AddItem(usr, item, days);
                                }

                                Inventory.DecreaseEAItem(usr, itemcode);
                                usr.send(new SP_WinItem(usr, item, days));
                            }
                            else
                            {
                                Log.WriteError(item + " is not a valid item @ random box event!");
                            }
                        }
                        break;
                    }
                    }
                    break;
                }
            }
            break;
            }
        }