public ActionResult Create(SubCodes model) { try { if (Convert.ToString(Session["userType"]) == "3") { ViewBag.Code = new SelectList(context.DelayCode, "DelayCodeId", "DelayName"); // TODO: Add insert logic here if (ModelState.IsValid) { context.SubCodes.Add(model); context.SaveChanges(); return(RedirectToAction("Index", "Config")); } else { return(RedirectToAction("Index")); } } else { return(RedirectToAction("Index", "Home")); } } catch { return(View()); } }
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; } } }
//Добавить строку подтаблицы public void AddRow(TablRow row) { SubNums.Add(row.Num, row); if (!row.Code.IsEmpty()) { SubCodes.Add(row.Code, row); } Subs.Add(row); }
//Добавить строку подтаблицы public void AddRow(TablRow row, bool addIndices) //Добавлять индексирование по полям Code и Num { row.Parent = this; SubList.Add(row); if (addIndices) { SubNums.Add(row.Num, row); if (!row.Code.IsEmpty()) { SubCodes.Add(row.Code, row); } } }
public ActionResult Edit(int id, SubCodes model) { try { // TODO: Add update logic here if (ModelState.IsValid) { context.Entry(model).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); return(RedirectToAction("Index", "Config")); } else { return(View()); } } catch { return(View()); } }
public void addSubCode(DDBuilder c) { SubCodes.Add(c); }
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; } }