public override void Handle(User usr) { Subtype type = (Subtype)int.Parse(getBlock(0)); switch (type) { case Subtype.CheckForDuplicate: { string name = getBlock(1).Replace(" ", ""); if (name.Length > 4) { ClanManager.CheckForDuplicate(usr, name); } break; } case Subtype.AddClan: { string name = getBlock(1).Replace(" ", ""); if (name.Length > 4) { ClanManager.AddClan(usr, name); } break; } case Subtype.ApplyClan: { int clanId = int.Parse(getBlock(1)); if (clanId > 0) { string time = DateTime.Now.ToString("dd/MM/yyyy"); Clan clan = ClanManager.GetClan(clanId); if (clan != null) { if (clan.ClanUsers.Count >= clan.maxUsers) { return; } ClanPendingUsers pending = new ClanPendingUsers(usr.userId, usr.nickname, usr.exp.ToString(), time); clan.pendingUsers.TryAdd(usr.userId, pending); usr.clan = clan; usr.send(new SP_Clan(SP_Clan.ClanCodes.ApplyClan)); if (usr.clan != null) { DB.RunQuery("UPDATE clans_invite SET clanid='" + clanId + "' WHERE userid='" + usr.userId + "'"); } else { DB.RunQuery("INSERT INTO clans_invite (userid, clanid) VALUES ('" + usr.userId + "', '" + clanId + "')"); } DB.RunQuery("UPDATE users SET clanrank='9', clanid='" + clanId + "' WHERE id='" + usr.userId + "'"); } } break; } case Subtype.LeaveClan: { if (usr.clan != null) { Clan clan = usr.clan; if (clan.pendingUsers.ContainsKey(usr.userId)) { ClanPendingUsers u; clan.pendingUsers.TryRemove(usr.userId, out u); } int clanrank = clan.clanRank(usr); if (clanrank == 2) { foreach (User u in clan.GetUsers()) { u.clan = null; } ClanManager.RemoveClan(usr); DB.RunQuery("UPDATE users SET clanid='-1', clanrank='0' WHERE clanid='" + clan.id + "'"); DB.RunQuery("DELETE FROM clans WHERE id='" + clan.id + "'"); } else { usr.clan = null; if (clanrank == 9) { ClanPendingUsers u; clan.pendingUsers.TryRemove(usr.userId, out u); } else { ClanUsers u; clan.ClanUsers.TryRemove(usr.userId, out u); } usr.send(new SP_Clan(SP_Clan.ClanCodes.LeaveClan)); DB.RunQuery("UPDATE users SET clanid='-1', clanrank='0' WHERE id='" + usr.userId + "'"); DB.RunQuery("UPDATE clans SET count='" + usr.clan.ClanUsers.Count + "' WHERE id='" + usr.clan.id + "'"); } } break; } case Subtype.MyClan: { if (usr.clan == null) { return; } usr.send(new SP_Clan.MyClanInformation(usr)); break; } case Subtype.Members: { if (usr.clan == null) { return; } int page = int.Parse(getBlock(1)); int clanrank = usr.clan.clanRank(usr); if (page == 1) { usr.send(new SP_Clan.UserList.NormalUser(usr.clan)); } else if (page == 2 && (clanrank == 1 || clanrank == 2)) { usr.send(new SP_Clan.UserList.Pending(usr)); } break; } case Subtype.SearchClan: { int t = int.Parse(getBlock(1)); SearchType subtype = (SearchType)t; int page = int.Parse(getBlock(1)); string key = getBlock(2); List <Clan> list = new List <Clan>(); switch (subtype) { case SearchType.Name: { list = new List <Clan>(ClanManager.Clans.Values.Where(c => c != null && c.name.ToLower().Contains(key.ToLower())).ToArray()); break; } case SearchType.Master: { list = new List <Clan>(ClanManager.Clans.Values.Where(c => c != null && c.Master.ToLower().Contains(key.ToLower())).ToArray()); break; } default: { list = new List <Clan>(ClanManager.Clans.Values.Where(c => c != null && (c.Master.ToLower().Contains(key.ToLower()) || c.name.ToLower().Contains(key.ToLower()))).ToArray()); break; } } if (key.Length >= 3) { usr.send(new SP_Clan.SearchClan(list)); } else { usr.send(new SP_Clan.CheckClan(SP_Clan.CheckClan.ErrorCodes.NotFound)); } break; } case Subtype.ClanInfo: { int clanId = int.Parse(getBlock(1)); if (clanId > 0) { Clan clan = ClanManager.GetClan(clanId); if (clan != null) { usr.send(new SP_Clan.UserList.NormalUser(usr, clan)); } } break; } case Subtype.ChangeAnnDec: { if (usr.clan == null) { return; } int clanrank = usr.clan.clanRank(usr); if (clanrank < 1 || clanrank == 9 || usr.clan == null) { return; } string Message = DB.Stripslash(getBlock(2)); bool description = getBlock(1) == "0"; if (description) { usr.clan.Description = Message; } else { usr.clan.Announcment = Message; } // Send query after to let the server be lagfree DB.RunQuery("UPDATE clans SET description='" + usr.clan.Description + "', announcment='" + usr.clan.Announcment + "' WHERE id='" + usr.clan.id + "'"); break; } case Subtype.JoinAction: { if (usr.clan == null) { return; } int subtype = int.Parse(getBlock(1)); int userId = int.Parse(getBlock(2)); Clan clan = usr.clan; switch (subtype) { case 0: // Accept Join { if (clan.ClanUsers.Count >= clan.maxUsers) { usr.send(new SP_Chat("SYSTEM", SP_Chat.ChatType.Whisper, "SYSTEM >> No more slot available for the clan, please expand if is possible", usr.sessionId, usr.nickname)); return; } string time = DateTime.Now.ToString("dd/MM/yyyy"); DataTable dt = DB.RunReader("SELECT * FROM users WHERE id='" + userId + "'"); if (dt.Rows.Count > 0) { DataRow row = dt.Rows[0]; DB.RunQuery("DELETE FROM clans_invite WHERE userid='" + userId + "'"); DB.RunQuery("UPDATE clans SET count='" + clan.ClanUsers.Count + "' WHERE id='" + clan.id + "'"); DB.RunQuery("UPDATE users SET clanid='" + clan.id + "', clanrank='0', clanjoindate='" + time + "' WHERE id='" + userId + "'"); if (clan.pendingUsers.ContainsKey(userId)) { ClanPendingUsers u; clan.pendingUsers.TryRemove(userId, out u); } ClanUsers c = new ClanUsers(userId, row["nickname"].ToString(), row["exp"].ToString(), time, 0); clan.ClanUsers.TryAdd(userId, c); } User user = UserManager.GetUser(userId); if (user != null) { user.clan = clan; clan.Users.TryAdd(userId, user); } ClanPendingUsers cc; if (clan.pendingUsers.ContainsKey(userId)) { clan.pendingUsers.TryRemove(userId, out cc); } break; } case 1: // Refuse Join { DB.RunQuery("DELETE FROM clans_invite WHERE userid='" + userId + "'"); DB.RunQuery("UPDATE users SET clanid='-1', clanrank='0' WHERE id='" + userId + "'"); User u = UserManager.GetUser(userId); if (u != null) { u.clan = null; } ClanPendingUsers c; if (clan.pendingUsers.ContainsKey(userId)) { clan.pendingUsers.TryRemove(userId, out c); } break; } } DB.RunQuery("DELETE FROM clans_invite WHERE userid='" + userId + "'"); usr.send(new SP_Clan.UserList.Pending(subtype, userId)); break; } case Subtype.RankAction: { if (usr.clan == null) { return; } int subtype = int.Parse(getBlock(1)); int userId = int.Parse(getBlock(2)); int clanrank = usr.clan.clanRank(usr); if (clanrank >= 1) { clanrank = 0; switch (subtype) { case 0: { clanrank = 1; DB.RunQuery("UPDATE users SET clanrank='1' WHERE id='" + userId + "'"); break; } case 1: { clanrank = 0; DB.RunQuery("UPDATE users SET clanrank='0' WHERE id='" + userId + "'"); break; } case 2: { DB.RunQuery("UPDATE users SET clanid='-1', clanrank='0' WHERE id='" + userId + "'"); DB.RunQuery("UPDATE clans SET count='" + usr.clan.ClanUsers.Count + "' WHERE id='" + usr.clan.id + "'"); User u2; ClanUsers u; usr.clan.Users.TryRemove(userId, out u2); usr.clan.ClanUsers.TryRemove(userId, out u); break; } } if (subtype != 2) { usr.clan.ClanUsers.Values.Where(s => s.id == userId).First().clanrank = clanrank; } else { User u = UserManager.GetUser(userId); if (u != null) { u.clan = null; } } usr.send(new SP_Clan.Change(subtype, userId)); } break; } case Subtype.Promote: { if (usr.clan == null) { return; } int userId = int.Parse(getBlock(1)); Clan clan = usr.clan; if (clan != null) { DataTable dt = DB.RunReader("SELECT * FROM users WHERE id='" + userId + "'"); if (dt.Rows.Count > 0) { DataRow row = dt.Rows[0]; if (userId != usr.userId) { DB.RunQuery("UPDATE users SET clanrank='0' WHERE id='" + usr.userId + "'"); DB.RunQuery("UPDATE users SET clanrank='2' WHERE id='" + userId + "'"); clan.Master = row["nickname"].ToString(); clan.MasterEXP = row["exp"].ToString(); clan.ClanUsers.Values.Where(r => string.Compare(r.nickname, clan.Master, true) == 0).First().clanrank = 2; clan.ClanUsers.Values.Where(r => string.Compare(r.nickname, usr.nickname, true) == 0).First().clanrank = 0; byte[] buffer = (new SP_Chat("ClanSystem", SP_Chat.ChatType.Clan, "ClanSystem >> " + usr.nickname + " passed master to " + clan.Master + " :/", (uint)clan.id, "NULL")).GetBytes(); foreach (User u in clan.Users.Values) { u.sendBuffer(buffer); } usr.send(new SP_Clan.Change()); } } } break; } case Subtype.NickChange: { if (usr.clan == null) { return; } string newNick = getBlock(1); Clan c = ClanManager.GetClanByName(newNick); if (usr.clan != null) { if (c == null) { if (usr.HasItem("CB02")) //>--- CHG_CLANNICK { DB.RunQuery("UPDATE clans SET name='" + newNick + "' WHERE id='" + usr.clan.id + "'"); c.name = newNick; usr.deleteItem("CB02"); usr.send(new SP_Clan.Change(usr, true)); } } else { usr.send(new SP_Chat("SYSTEM", SP_Chat.ChatType.Whisper, "SYSTEM >> A clan has already this name, please choose another one", usr.sessionId, usr.nickname)); } } break; } case Subtype.MarkChange: { if (usr.clan == null) { return; } uint iconID = uint.Parse(getBlock(1)); if (usr.HasItem("CB54") && usr.clan != null) //>--- CHG_CLANMARK { DB.RunQuery("UPDATE clans SET iconid='" + iconID + "' WHERE id='" + usr.clan.id + "'"); usr.clan.iconid = iconID; usr.deleteItem("CB54"); usr.send(new SP_Clan.Change(usr, false)); } break; } case Subtype.DisbandClan: { if (usr.clan == null) { return; } ClanManager.RemoveClan(usr); break; } case Subtype.NewSearchClan: { int page = int.Parse(getBlock(1)); int sortType = int.Parse(getBlock(2)); List <Clan> clans = new List <Clan>(); switch (sortType) { case 0: // By rank desc { clans = ClanManager.Clans.Values.OrderByDescending(r => r.exp).Skip(page * 10).Take(10).ToList(); break; } case 1: // By rank asc { clans = ClanManager.Clans.Values.OrderBy(r => r.exp).Skip(page * 10).Take(10).ToList(); break; } } usr.send(new SP_Clan.SearchClan(page, sortType, clans)); break; } default: { Log.WriteError("Unknown Clan Subtype " + (int)Subtype.DisbandClan); break; } } }
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(); } }
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; } }