public static void DisplaySearchResults(TSPlayer Player, List<object> Results, int Page) { if (Results[0] is Item) Player.SendInfoMessage("Item Search:"); else if (Results[0] is NPC) Player.SendInfoMessage("NPC Search:"); var sb = new StringBuilder(); if (Results.Count > (8 * (Page - 1))) { for (int j = (8 * (Page - 1)); j < (8 * Page); j++) { if (sb.Length != 0) sb.Append(" | "); if (Results[j] is Item) sb.Append(((Item)Results[j]).netID).Append(": ").Append(((Item)Results[j]).name); else if (Results[j] is NPC) sb.Append(((NPC)Results[j]).netID).Append(": ").Append(((NPC)Results[j]).name); if (j == Results.Count - 1) { Player.SendMessage(sb.ToString(), Color.MediumSeaGreen); break; } if ((j + 1) % 2 == 0) { Player.SendMessage(sb.ToString(), Color.MediumSeaGreen); sb.Clear(); } } } if (Results.Count > (8 * Page)) { Player.SendMessage(string.Format("Type /spage {0} for more Results.", (Page + 1)), Color.Yellow); } }
/// <summary> /// Shows a file to the user. /// </summary> /// <param name="ply">int player</param> /// <param name="file">string filename reletave to savedir</param> //Todo: Fix this public static void ShowFileToUser(TSPlayer player, string file) { string foo = ""; using (var tr = new StreamReader(Path.Combine(TShock.SavePath, file))) { while ((foo = tr.ReadLine()) != null) { foo = foo.Replace("%map%", Main.worldName); foo = foo.Replace("%players%", GetPlayers()); if (foo.Substring(0, 1) == "%" && foo.Substring(12, 1) == "%") //Look for a beginning color code. { string possibleColor = foo.Substring(0, 13); foo = foo.Remove(0, 13); float[] pC = { 0, 0, 0 }; possibleColor = possibleColor.Replace("%", ""); string[] pCc = possibleColor.Split(','); if (pCc.Length == 3) { try { player.SendMessage(foo, (byte)Convert.ToInt32(pCc[0]), (byte)Convert.ToInt32(pCc[1]), (byte)Convert.ToInt32(pCc[2])); continue; } catch (Exception e) { Log.Error(e.ToString()); } } } player.SendMessage(foo); } } }
public static bool CheckTilePermission(TSPlayer player, int tileX, int tileY) { if (!player.Group.HasPermission(Permissions.canbuild)) { player.SendMessage("You do not have permission to build!", Color.Red); return(true); } if (!player.Group.HasPermission(Permissions.editspawn) && !TShock.Regions.CanBuild(tileX, tileY, player) && TShock.Regions.InArea(tileX, tileY)) { player.SendMessage("Region protected from changes.", Color.Red); return(true); } if (TShock.Config.DisableBuild) { if (!player.Group.HasPermission(Permissions.editspawn)) { player.SendMessage("World protected from changes.", Color.Red); return(true); } } if (TShock.Config.SpawnProtection) { if (!player.Group.HasPermission(Permissions.editspawn)) { var flag = TShock.CheckSpawn(tileX, tileY); if (flag) { player.SendMessage("Spawn protected from changes.", Color.Red); return(true); } } } return(false); }
private void NotifyAdministrator(TSPlayer player, string[] changes) { player.SendMessage("The server is out of date. Latest version: ", Color.Red); for (int j = 0; j < changes.Length; j++) { player.SendMessage(changes[j], Color.Red); } }
private static void NotifyAdministrator(TSPlayer player, string[] changes) { player.SendMessage("The server is out of date.", Color.Red); for (int j = 0; j < changes.Length; j++) { player.SendMessage(changes[j], Color.Red); } }
/// <summary> /// Shows a file to the user. /// </summary> /// <param name="player">TSPlayer player</param> /// <param name="file">string filename reletave to savedir</param> public void ShowFileToUser(TSPlayer player, string file) { string foo = ""; using (var tr = new StreamReader(Path.Combine(TShock.SavePath, file))) { while ((foo = tr.ReadLine()) != null) { if (string.IsNullOrWhiteSpace(foo)) { continue; } foo = foo.Replace("%map%", (TShock.Config.UseServerName ? TShock.Config.ServerName : Main.worldName)); foo = foo.Replace("%players%", String.Join(",", GetPlayers(false))); Regex reg = new Regex("%\\s*(?<r>\\d{1,3})\\s*,\\s*(?<g>\\d{1,3})\\s*,\\s*(?<b>\\d{1,3})\\s*%"); var matches = reg.Matches(foo); Color c = Color.White; foreach (Match match in matches) { byte r, g, b; if (byte.TryParse(match.Groups["r"].Value, out r) && byte.TryParse(match.Groups["g"].Value, out g) && byte.TryParse(match.Groups["b"].Value, out b)) { c = new Color(r, g, b); } foo = foo.Remove(match.Index, match.Length); } player.SendMessage(foo, c); } } }
private void NotifyAdministrator(TSPlayer player, string[] changes) { player.SendMessage("您现在使用的版本为 TshockCn beta 5 (Tshock 4.3.12)\r\n正在检测服务器版本是否有更新,请稍后!\r\n少女祈祷中...\r\n检测成功,请注意版本信息!: ", Color.Red); for (int j = 0; j < changes.Length; j++) { player.SendMessage(changes[j], Color.Red); } }
public void GetBalance(TSPlayer player) { BankManager manager = new BankManager(TShock.DB); var account = manager.GetBalance(player.UserAccountName); player.SendMessage(string.Format("Your account has a balance of: {0}", account.Amount), Color.Green); }
public static void Success(TSPlayer to, string message) { if (to is TSServerPlayer) { to.SendSuccessMessage(message); return; } to.SendMessage(message, Color.MediumSeaGreen); }
public static void Info(TSPlayer to, string message) { if (to is TSServerPlayer) { to.SendInfoMessage(message); return; } to.SendMessage(message, Color.Yellow); }
public static void Error(TSPlayer to, string message) { if (to is TSServerPlayer) { to.SendErrorMessage(message); return; } to.SendMessage(message, Color.OrangeRed); }
public void Deposit(TSPlayer player, int amount) { if (!CheckInRegion(player)) { return; } BankManager manager = new BankManager(TShock.DB); var account = manager.GetBalance(player.UserAccountName); //// piggy back on the raffle manager to get shards //RaffleManager raffleManager = new RaffleManager(TShock.DB); //var shards = raffleManager.GetServerPointAccounts(player.UserAccountName); try { var ePlayer = ServerPointSystem.ServerPointSystem.EPRPlayers.Single(p => p.TSPlayer == player); if (ePlayer.DisplayAccount < amount) { player.SendMessage("You do not have the required shards.", Color.Red); } else { manager.Deposit(player.UserAccountName, amount); ServerPointSystem.EPREvents.PointOperate(ePlayer, -amount, ServerPointSystem.PointOperateReason.Deduct); //ServerPointSystem.ServerPointSystem.Deduct(new CommandArgs("deduct", player, new List<string>() //{ // player.UserAccountName, // amount.ToString() //})); player.SendMessage("You have successfully deposited into your account.", Color.Green); } } catch (Exception ex) { player.SendMessage("Could not deposit at this time.", Color.Red); } }
public static bool HackedInventory(TSPlayer player) { bool check = false; Item[] inventory = player.TPlayer.inventory; Item[] armor = player.TPlayer.armor; for (int i = 0; i < NetItem.maxNetInventory; i++) { if (i < 49) { Item item = new Item(); if (inventory[i] != null && inventory[i].netID != 0) { item.netDefaults(inventory[i].netID); item.Prefix(inventory[i].prefix); item.AffixName(); if (inventory[i].stack > item.maxStack) { check = true; player.SendMessage(String.Format("Stack cheat detected. Remove item {0} ({1}) and then rejoin", item.name, inventory[i].stack), Color.Cyan); } } } else { Item item = new Item(); if (armor[i - 48] != null && armor[i - 48].netID != 0) { item.netDefaults(armor[i - 48].netID); item.Prefix(armor[i - 48].prefix); item.AffixName(); if (armor[i - 48].stack > item.maxStack) { check = true; player.SendMessage(String.Format("Stack cheat detected. Remove armor {0} ({1}) and then rejoin", item.name, armor[i - 48].stack), Color.Cyan); } } } } return(check); }
public virtual void SetPvP(bool pvp) { if (TPlayer.hostile != pvp) { LastPvpChange = DateTime.UtcNow; TPlayer.hostile = pvp; All.SendMessage(string.Format("{0} has {1} PvP!", Name, pvp ? "enabled" : "disabled"), Main.teamColor[Team]); } //Broadcast anyways to keep players synced NetMessage.SendData((int)PacketTypes.TogglePvp, -1, -1, "", Index); }
public void giveItems(TSPlayer ply) { foreach (KitItem i in items) { Item item = TShock.Utils.GetItemById(i.id); int amount = Math.Min(item.maxStack, i.amt); if (item != null) ply.GiveItem(item.type, item.name, item.width, item.height, amount); } ply.SendMessage(String.Format("{0} kit given. Enjoy!", name), Color.Green); }
public static void communicate(int what, TSPlayer to, string parameter) { switch(what) { case InvalidSyntax: to.SendMessage("Invalid syntax. Proper syntax: " + Commands.SLASH_COMMAND + " " + parameter, Color.Red); break; case NoPermission: to.SendMessage("No permissions for box: " + parameter, Color.Red); break; case BoxNotFound: to.SendMessage("Box not found: " + parameter, Color.Red); break; case PlayerNotFound: to.SendMessage("Player not found: " + parameter, Color.Red); break; case GroupNotFound: to.SendMessage("Group not found: " + parameter, Color.Red); break; case TypeForMore: to.SendMessage("Type " + Commands.SLASH_COMMAND + " list " + parameter + " for more boxes."); break; case CustomError: to.SendMessage(parameter, Color.Red); break; case CustomSuccess: to.SendMessage(parameter, Color.LightGreen); break; case CustomInfo: to.SendMessage(parameter, Color.Azure); break; case CustomWarning: to.SendMessage(parameter, Color.Yellow); break; } }
private object PlayerKill(RestVerbs verbs, IParameterCollection parameters) { var ret = PlayerFind(parameters); if (ret is RestObject) { return(ret); } TSPlayer player = (TSPlayer)ret; player.DamagePlayer(999999); var from = string.IsNullOrWhiteSpace(parameters["from"]) ? "Server Admin" : parameters["from"]; player.SendMessage(string.Format("{0} just killed you!", from)); return(RestResponse("Player " + player.Name + " was killed")); }
private object PlayerSetMute(IParameterCollection parameters, bool mute) { var ret = PlayerFind(parameters); if (ret is RestObject) { return(ret); } TSPlayer player = (TSPlayer)ret; player.mute = mute; var verb = mute ? "muted" : "unmuted"; player.SendMessage("You have been remotely " + verb); return(RestResponse("Player " + player.Name + " was " + verb)); }
public void Withdraw(TSPlayer player, int amount) { if (!CheckInRegion(player)) { return; } BankManager manager = new BankManager(TShock.DB); var account = manager.GetBalance(player.UserAccountName); if (account.Amount - amount < 0) { player.SendMessage("You do not have enough to withdraw that amount.", Color.Red); } else { try { var ePlayer = ServerPointSystem.ServerPointSystem.EPRPlayers.Single(p => p.TSPlayer == player); manager.Withdraw(player.UserAccountName, amount); ServerPointSystem.EPREvents.PointOperate(ePlayer, amount, ServerPointSystem.PointOperateReason.Award); //ServerPointSystem.ServerPointSystem.Award(new CommandArgs("award", player, new List<string>() //{ // player.Name, // amount.ToString() //})); player.SendMessage("You have successfully withdrawn from your account.", Color.Green); } catch (Exception ex) { player.SendMessage("Could not withdraw shards at this time.", Color.Red); } } }
public void giveItems( TSPlayer ply) { foreach( KitItem i in items ) { List<Item> itemList = TShock.Utils.GetItemByIdOrName(i.id); if (itemList.Count == 0) { Log.ConsoleError(String.Format("The specified item does not exist: {0}", i.id) ); continue; } else if( itemList.Count > 1 ) { Log.ConsoleError(String.Format("The specified item has multiple entries: {0}.\n Using the first item.", i.id)); } Item item = itemList[0]; int amount = Math.Min(item.maxStack, i.amt); if( item != null ) ply.GiveItem(item.type, item.name, item.width, item.height, amount); } ply.SendMessage( String.Format("{0} kit given. Enjoy!", name), Color.Green ); }
private bool TryGetProtectionInfo(TSPlayer player, DPoint tileLocation, bool sendFailureMessages = true) { Tile tile = TerrariaUtils.Tiles[tileLocation]; if (!tile.active()) return false; ProtectionEntry protection = null; // Only need the first enumerated entry as we don't need the protections of adjacent blocks. foreach (ProtectionEntry enumProtection in this.ProtectionManager.EnumerateProtectionEntries(tileLocation)) { protection = enumProtection; break; } BlockType blockType = (BlockType)TerrariaUtils.Tiles[tileLocation].type; if (protection == null) { if (sendFailureMessages) player.SendErrorMessage($"This {TerrariaUtils.Tiles.GetBlockTypeName(blockType)} is not protected by Protector at all."); return false; } bool canViewExtendedInfo = ( player.Group.HasPermission(ProtectorPlugin.ViewAllProtections_Permission) || protection.Owner == player.User.ID || protection.IsSharedWithPlayer(player) ); if (!canViewExtendedInfo) { player.SendMessage($"This {TerrariaUtils.Tiles.GetBlockTypeName(blockType)} is protected and not shared with you.", Color.LightGray); player.SendWarningMessage("You are not permitted to get more information about this protection."); return true; } string ownerName; if (protection.Owner == -1) ownerName = "{Server}"; else ownerName = GetUserName(protection.Owner); player.SendMessage($"This {TerrariaUtils.Tiles.GetBlockTypeName(blockType)} is protected. The owner is {TShock.Utils.ColorTag(ownerName, Color.Red)}.", Color.LightGray); string creationTimeFormat = "unknown"; if (protection.TimeOfCreation != DateTime.MinValue) creationTimeFormat = "{0:MM/dd/yy, h:mm tt} UTC ({1} ago)"; player.SendMessage( string.Format( CultureInfo.InvariantCulture, "Protection created On: " + creationTimeFormat, protection.TimeOfCreation, (DateTime.UtcNow - protection.TimeOfCreation).ToLongString() ), Color.LightGray ); if (blockType == BlockType.Chest || blockType == BlockType.Dresser) { if (protection.RefillChestData != null) { RefillChestMetadata refillChest = protection.RefillChestData; if (refillChest.RefillTime != TimeSpan.Zero) player.SendMessage($"This is a refill chest with a timer set to {TShock.Utils.ColorTag(refillChest.RefillTime.ToLongString(), Color.Red)}.", Color.LightGray); else player.SendMessage("This is a refill chest without a timer.", Color.LightGray); if (refillChest.OneLootPerPlayer || refillChest.RemainingLoots != -1) { StringBuilder messageBuilder = new StringBuilder(); messageBuilder.Append("It can only be looted "); if (refillChest.OneLootPerPlayer) messageBuilder.Append("one time by each player"); if (refillChest.RemainingLoots != -1) { if (messageBuilder.Length > 0) messageBuilder.Append(" and "); messageBuilder.Append(TShock.Utils.ColorTag(refillChest.RemainingLoots.ToString(), Color.Red)); messageBuilder.Append(" more times in total"); } if (refillChest.Looters != null) { messageBuilder.Append(" and was looted "); messageBuilder.Append(TShock.Utils.ColorTag(refillChest.Looters.Count.ToString(), Color.Red)); messageBuilder.Append(" times until now"); } messageBuilder.Append('.'); player.SendMessage(messageBuilder.ToString(), Color.LightGray); } } else if (protection.BankChestKey != BankChestDataKey.Invalid) { BankChestDataKey bankChestKey = protection.BankChestKey; player.SendMessage($"This is a bank chest instance with the number {bankChestKey.BankChestIndex}.", Color.LightGray); } else if (protection.TradeChestData != null) { Item sellItem = new Item(); sellItem.netDefaults(protection.TradeChestData.ItemToSellId); sellItem.stack = protection.TradeChestData.ItemToSellAmount; Item payItem = new Item(); payItem.netDefaults(protection.TradeChestData.ItemToPayId); payItem.stack = protection.TradeChestData.ItemToPayAmount; player.SendMessage($"This is a trade chest. It's selling {TShock.Utils.ItemTag(sellItem)} for {TShock.Utils.ItemTag(payItem)}", Color.LightGray); } IChest chest = this.ChestManager.ChestFromLocation(protection.TileLocation); if (chest.IsWorldChest) player.SendMessage($"It is stored as part of the world data (id: {TShock.Utils.ColorTag(chest.Index.ToString(), Color.Red)}).", Color.LightGray); else player.SendMessage($"It is {TShock.Utils.ColorTag("not", Color.Red)} stored as part of the world data.", Color.LightGray); } if (ProtectionManager.IsShareableBlockType(blockType)) { if (protection.IsSharedWithEveryone) { player.SendMessage("Protection is shared with everyone.", Color.LightGray); } else { StringBuilder sharedListBuilder = new StringBuilder(); if (protection.SharedUsers != null) { for (int i = 0; i < protection.SharedUsers.Count; i++) { if (i > 0) sharedListBuilder.Append(", "); TShockAPI.DB.User tsUser = TShock.Users.GetUserByID(protection.SharedUsers[i]); if (tsUser != null) sharedListBuilder.Append(tsUser.Name); } } if (sharedListBuilder.Length == 0 && protection.SharedGroups == null) { player.SendMessage($"Protection is {TShock.Utils.ColorTag("not", Color.Red)} shared with users or groups.", Color.LightGray); } else { if (sharedListBuilder.Length > 0) player.SendMessage($"Shared with users: {TShock.Utils.ColorTag(sharedListBuilder.ToString(), Color.Red)}", Color.LightGray); else player.SendMessage($"Protection is {TShock.Utils.ColorTag("not", Color.Red)} shared with users.", Color.LightGray); if (protection.SharedGroups != null) player.SendMessage($"Shared with groups: {TShock.Utils.ColorTag(protection.SharedGroups.ToString(), Color.Red)}", Color.LightGray); else player.SendMessage($"Protection is {TShock.Utils.ColorTag("not", Color.Red)} shared with groups.", Color.LightGray); } } } if (protection.TradeChestData != null && protection.TradeChestData.TransactionJournal.Count > 0) { player.SendMessage($"Trade Chest Journal (Last {protection.TradeChestData.TransactionJournal.Count} Transactions)", Color.LightYellow); protection.TradeChestData.TransactionJournal.ForEach(entry => { string entryText = entry.Item1; DateTime entryTime = entry.Item2; TimeSpan timeSpan = DateTime.UtcNow - entryTime; player.SendMessage($"{entryText} {timeSpan.ToLongString()} ago.", Color.LightGray); }); } return true; }
/// <summary>HackedInventory - Checks to see if a user has a hacked inventory. In addition, messages players the result.</summary> /// <param name="player">player - The TSPlayer object.</param> /// <returns>bool - True if the player has a hacked inventory.</returns> public static bool HackedInventory(TSPlayer player) { bool check = false; Item[] inventory = player.TPlayer.inventory; Item[] armor = player.TPlayer.armor; Item[] dye = player.TPlayer.dye; Item[] miscEquips = player.TPlayer.miscEquips; Item[] miscDyes = player.TPlayer.miscDyes; Item[] piggy = player.TPlayer.bank.item; Item[] safe = player.TPlayer.bank2.item; Item trash = player.TPlayer.trashItem; for (int i = 0; i < NetItem.MaxInventory; i++) { if (i < NetItem.InventorySlots) { //0-58 Item item = new Item(); if (inventory[i] != null && inventory[i].netID != 0) { item.netDefaults(inventory[i].netID); item.Prefix(inventory[i].prefix); item.AffixName(); if (inventory[i].stack > item.maxStack) { check = true; player.SendMessage( String.Format("Stack cheat detected. Remove item {0} ({1}) and then rejoin", item.name, inventory[i].stack), Color.Cyan); } } } else if (i < NetItem.InventorySlots + NetItem.ArmorSlots) { //59-78 Item item = new Item(); var index = i - NetItem.InventorySlots; if (armor[index] != null && armor[index].netID != 0) { item.netDefaults(armor[index].netID); item.Prefix(armor[index].prefix); item.AffixName(); if (armor[index].stack > item.maxStack) { check = true; player.SendMessage( String.Format("Stack cheat detected. Remove armor {0} ({1}) and then rejoin", item.name, armor[index].stack), Color.Cyan); } } } else if (i < NetItem.InventorySlots + NetItem.ArmorSlots + NetItem.DyeSlots) { //79-88 Item item = new Item(); var index = i - (NetItem.InventorySlots + NetItem.ArmorSlots); if (dye[index] != null && dye[index].netID != 0) { item.netDefaults(dye[index].netID); item.Prefix(dye[index].prefix); item.AffixName(); if (dye[index].stack > item.maxStack) { check = true; player.SendMessage( String.Format("Stack cheat detected. Remove dye {0} ({1}) and then rejoin", item.name, dye[index].stack), Color.Cyan); } } } else if (i < NetItem.InventorySlots + NetItem.ArmorSlots + NetItem.DyeSlots + NetItem.MiscEquipSlots) { //89-93 Item item = new Item(); var index = i - (NetItem.InventorySlots + NetItem.ArmorSlots + NetItem.DyeSlots); if (miscEquips[index] != null && miscEquips[index].netID != 0) { item.netDefaults(miscEquips[index].netID); item.Prefix(miscEquips[index].prefix); item.AffixName(); if (miscEquips[index].stack > item.maxStack) { check = true; player.SendMessage( String.Format("Stack cheat detected. Remove item {0} ({1}) and then rejoin", item.name, miscEquips[index].stack), Color.Cyan); } } } else if (i < NetItem.InventorySlots + NetItem.ArmorSlots + NetItem.DyeSlots + NetItem.MiscEquipSlots + NetItem.MiscDyeSlots) { //93-98 Item item = new Item(); var index = i - (NetItem.InventorySlots + NetItem.ArmorSlots + NetItem.DyeSlots + NetItem.MiscEquipSlots); if (miscDyes[index] != null && miscDyes[index].netID != 0) { item.netDefaults(miscDyes[index].netID); item.Prefix(miscDyes[index].prefix); item.AffixName(); if (miscDyes[index].stack > item.maxStack) { check = true; player.SendMessage( String.Format("Stack cheat detected. Remove item dye {0} ({1}) and then rejoin", item.name, miscDyes[index].stack), Color.Cyan); } } } else if (i < NetItem.InventorySlots + NetItem.ArmorSlots + NetItem.DyeSlots + NetItem.MiscEquipSlots + NetItem.MiscDyeSlots + NetItem.PiggySlots) { //98-138 Item item = new Item(); var index = i - (NetItem.InventorySlots + NetItem.ArmorSlots + NetItem.DyeSlots + NetItem.MiscEquipSlots + NetItem.MiscDyeSlots); if (piggy[index] != null && piggy[index].netID != 0) { item.netDefaults(piggy[index].netID); item.Prefix(piggy[index].prefix); item.AffixName(); if (piggy[index].stack > item.maxStack) { check = true; player.SendMessage( String.Format("Stack cheat detected. Remove Piggy-bank item {0} ({1}) and then rejoin", item.name, piggy[index].stack), Color.Cyan); } } } else if (i < NetItem.InventorySlots + NetItem.ArmorSlots + NetItem.DyeSlots + NetItem.MiscEquipSlots + NetItem.MiscDyeSlots + NetItem.PiggySlots + NetItem.SafeSlots) { //138-178 Item item = new Item(); var index = i - (NetItem.InventorySlots + NetItem.ArmorSlots + NetItem.DyeSlots + NetItem.MiscEquipSlots + NetItem.MiscDyeSlots + NetItem.PiggySlots); if (safe[index] != null && safe[index].netID != 0) { item.netDefaults(safe[index].netID); item.Prefix(safe[index].prefix); item.AffixName(); if (safe[index].stack > item.maxStack) { check = true; player.SendMessage( String.Format("Stack cheat detected. Remove Safe item {0} ({1}) and then rejoin", item.name, safe[index].stack), Color.Cyan); } } } else { Item item = new Item(); if (trash != null && trash.netID != 0) { item.netDefaults(trash.netID); item.Prefix(trash.prefix); item.AffixName(); if (trash.stack > item.maxStack) { check = true; player.SendMessage( String.Format("Stack cheat detected. Remove trash item {0} ({1}) and then rejoin", item.name, trash.stack), Color.Cyan); } } } } return check; }
private void Whisper(TSPlayer sender, string[] Message) { TSPlayer target = null; for (int i = 0; i < TShock.Players.Length; i++) { if (Message[1] == TShock.Players.ElementAt(i).Name) { target = TShock.Players.ElementAt(i); break; } else if (TShock.Players.ElementAt(i + 1) == null) break; } if (target == null) { sender.SendMessage("Den Spieler " + Message[1] + " gibt es nicht"); return; } Message[0] = ""; Message[1] = ""; String finalmessage = String.Join(" ", Message); sender.SendMessage("Message send to " + target.Name + " " + finalmessage); target.SendMessage("Message from " + sender.Name + " " + finalmessage); }
private bool TryGetProtectionInfo(TSPlayer player, DPoint tileLocation, bool sendFailureMessages = true) { Tile tile = TerrariaUtils.Tiles[tileLocation]; if (!tile.active()) return false; ProtectionEntry protection = null; // Only need the first enumerated entry as we don't need the protections of adjacent blocks. foreach (ProtectionEntry enumProtection in this.ProtectionManager.EnumerateProtectionEntries(tileLocation)) { protection = enumProtection; break; } BlockType blockType = (BlockType)TerrariaUtils.Tiles[tileLocation].type; if (protection == null) { if (sendFailureMessages) { player.SendErrorMessage(string.Format( "This {0} is not protected by Protector at all.", TerrariaUtils.Tiles.GetBlockTypeName(blockType) )); } return false; } bool canViewExtendedInfo = ( player.Group.HasPermission(ProtectorPlugin.ViewAllProtections_Permission) || protection.Owner == player.User.ID || protection.IsSharedWithPlayer(player) ); if (!canViewExtendedInfo) { player.SendMessage(string.Format( "This {0} is protected and not shared with you.", TerrariaUtils.Tiles.GetBlockTypeName(blockType) ), Color.LightGray); player.SendWarningMessage("You are not permitted to get more information about this protection."); return true; } string ownerName; if (protection.Owner == -1) { ownerName = "{Server}"; } else { TShockAPI.DB.User tsUser = TShock.Users.GetUserByID(protection.Owner); if (tsUser != null) ownerName = tsUser.Name; else ownerName = string.Concat("{deleted user id: ", protection.Owner, "}"); } player.SendMessage(string.Format( "This {0} is protected. The owner is {1}.", TerrariaUtils.Tiles.GetBlockTypeName(blockType), ownerName ), Color.LightGray); string creationTimeFormat = "Protection created On: unknown"; if (protection.TimeOfCreation != DateTime.MinValue) creationTimeFormat = "Protection created On: {0:MM/dd/yy, h:mm tt} UTC ({1} ago)"; player.SendMessage( string.Format( CultureInfo.InvariantCulture, creationTimeFormat, protection.TimeOfCreation, (DateTime.UtcNow - protection.TimeOfCreation).ToLongString() ), Color.LightGray ); if (blockType == BlockType.Chest || blockType == BlockType.Dresser) { if (protection.RefillChestData != null) { RefillChestMetadata refillChest = protection.RefillChestData; if (refillChest.RefillTime != TimeSpan.Zero) player.SendMessage(string.Format("This is a refill chest with a timer set to {0}.", refillChest.RefillTime.ToLongString()), Color.LightGray); else player.SendMessage("This is a refill chest without a timer.", Color.LightGray); if (refillChest.OneLootPerPlayer || refillChest.RemainingLoots != -1) { StringBuilder messageBuilder = new StringBuilder(); if (refillChest.OneLootPerPlayer) messageBuilder.Append("one time by each player"); if (refillChest.RemainingLoots != -1) { if (messageBuilder.Length > 0) messageBuilder.Append(" and "); messageBuilder.Append(refillChest.RemainingLoots); messageBuilder.Append(" more times in total"); } if (refillChest.Looters != null) { messageBuilder.Append(" and was looted "); messageBuilder.Append(refillChest.Looters.Count); messageBuilder.Append(" times until now"); } messageBuilder.Insert(0, "It can only be looted "); messageBuilder.Append('.'); player.SendMessage(messageBuilder.ToString(), Color.LightGray); } } else if (protection.BankChestKey != BankChestDataKey.Invalid) { BankChestDataKey bankChestKey = protection.BankChestKey; player.SendMessage( string.Format("This is a bank chest instance with the number {0}.", bankChestKey.BankChestIndex), Color.LightGray ); } } if (ProtectionManager.IsShareableBlockType(blockType)) { if (protection.IsSharedWithEveryone) { player.SendMessage("Protection is shared with everyone.", Color.LightGray); return true; } StringBuilder sharedListBuilder = new StringBuilder(); if (protection.SharedUsers != null) { for (int i = 0; i < protection.SharedUsers.Count; i++) { if (i > 0) sharedListBuilder.Append(", "); TShockAPI.DB.User tsUser = TShock.Users.GetUserByID(protection.SharedUsers[i]); if (tsUser != null) sharedListBuilder.Append(tsUser.Name); } } if (sharedListBuilder.Length == 0 && protection.SharedGroups == null) { player.SendMessage("Protection is not shared with users or groups.", Color.LightGray); return true; } if (sharedListBuilder.Length > 0) player.SendMessage("Shared with users: " + sharedListBuilder, Color.LightGray); else player.SendMessage("Protection is not shared with users.", Color.LightGray); if (protection.SharedGroups != null) player.SendMessage("Shared with groups: " + protection.SharedGroups.ToString(), Color.LightGray); else player.SendMessage("Protection is not shared with groups.", Color.LightGray); } return true; }
public static bool HackedInventory(TSPlayer player) { bool check = false; Item[] inventory = player.TPlayer.inventory; Item[] armor = player.TPlayer.armor; for (int i = 0; i < NetItem.maxNetInventory; i++) { if (i < 49) { Item item = new Item(); if (inventory[i] != null && inventory[i].netID != 0) { item.netDefaults(inventory[i].netID); item.Prefix(inventory[i].prefix); item.AffixName(); if (inventory[i].stack > item.maxStack) { check = true; player.SendMessage( String.Format("Stack cheat detected. Remove item {0} ({1}) and then rejoin", item.name, inventory[i].stack), Color.Cyan); } } } else { Item item = new Item(); if (armor[i - 48] != null && armor[i - 48].netID != 0) { item.netDefaults(armor[i - 48].netID); item.Prefix(armor[i - 48].prefix); item.AffixName(); if (armor[i - 48].stack > item.maxStack) { check = true; player.SendMessage( String.Format("Stack cheat detected. Remove armor {0} ({1}) and then rejoin", item.name, armor[i - 48].stack), Color.Cyan); } } } } return check; }
public bool Run(string msg, TSPlayer ply, List<string> parms) { if (!ply.Group.HasPermission(Permission)) return false; try { command(new CommandArgs(msg, ply, parms)); } catch (Exception e) { ply.SendMessage("Command failed, check logs for more details."); Log.Error(e.ToString()); } return true; }
public static bool CheckInventory(TSPlayer player) { PlayerData playerData = player.PlayerData; bool check = true; if (player.TPlayer.statLifeMax > playerData.maxHealth) { player.SendMessage("Error: Your max health exceeded (" + playerData.maxHealth + ") which is stored on server", Color.Cyan); check = false; } if (player.TPlayer.statManaMax > playerData.maxMana) { player.SendMessage("Error: Your max mana exceeded (" + playerData.maxMana + ") which is stored on server", Color.Cyan); check = false; } Item[] inventory = player.TPlayer.inventory; Item[] armor = player.TPlayer.armor; for (int i = 0; i < NetItem.maxNetInventory; i++) { if (i < 49) { Item item = new Item(); Item serverItem = new Item(); if (inventory[i] != null && inventory[i].netID != 0) { if (playerData.inventory[i].netID != inventory[i].netID) { item.netDefaults(inventory[i].netID); item.Prefix(inventory[i].prefix); item.AffixName(); player.SendMessage("Error: Your item (" + item.name + ") needs to be deleted.", Color.Cyan); check = false; } else if (playerData.inventory[i].prefix != inventory[i].prefix) { item.netDefaults(inventory[i].netID); item.Prefix(inventory[i].prefix); item.AffixName(); player.SendMessage("Error: Your item (" + item.name + ") needs to be deleted.", Color.Cyan); check = false; } else if (inventory[i].stack > playerData.inventory[i].stack) { item.netDefaults(inventory[i].netID); item.Prefix(inventory[i].prefix); item.AffixName(); player.SendMessage("Error: Your item (" + item.name + ") (" + inventory[i].stack + ") needs to have it's stack decreased to (" + playerData.inventory[i].stack + ").", Color.Cyan); check = false; } } } else { Item item = new Item(); Item serverItem = new Item(); if (armor[i - 48] != null && armor[i - 48].netID != 0) { if (playerData.inventory[i].netID != armor[i - 48].netID) { item.netDefaults(armor[i - 48].netID); item.Prefix(armor[i - 48].prefix); item.AffixName(); player.SendMessage("Error: Your armor (" + item.name + ") needs to be deleted.", Color.Cyan); check = false; } else if (playerData.inventory[i].prefix != armor[i - 48].prefix) { item.netDefaults(armor[i - 48].netID); item.Prefix(armor[i - 48].prefix); item.AffixName(); player.SendMessage("Error: Your armor (" + item.name + ") needs to be deleted.", Color.Cyan); check = false; } else if (armor[i - 48].stack > playerData.inventory[i].stack) { item.netDefaults(armor[i - 48].netID); item.Prefix(armor[i - 48].prefix); item.AffixName(); player.SendMessage("Error: Your armor (" + item.name + ") (" + inventory[i].stack + ") needs to have it's stack decreased to (" + playerData.inventory[i].stack + ").", Color.Cyan); check = false; } } } } return(check); }
private void ShowMOTD(TSPlayer player) { try { string filetoshow = Path.Combine(SavePath, getConfig.motd.file); foreach (var group in getConfig.motd.groups) { if (group.Key == player.Group.Name) { filetoshow = Path.Combine(SavePath, group.Value); } } TSUtils.CheckFile(filetoshow); var file = File.ReadAllLines(filetoshow); var messages = TSUtils.ReplaceVariables(file, player); foreach (var msg in messages) { if (msg.Key.StartsWith("%command%") && msg.Key.EndsWith("%")) { string docmd = msg.Key.Split('%')[2]; if (!docmd.StartsWith("/")) docmd = "/" + docmd; Commands.HandleCommand(player, docmd); continue; } else player.SendMessage(msg.Key, msg.Value); } } catch (Exception ex) { Log.ConsoleError("Something when wrong when showing {0} a motd. Check the logs.".SFormat(player.Name)); Log.Error(ex.ToString()); } }
public static void SendPage( TSPlayer player, int pageNumber, IEnumerable dataToPaginate, int dataToPaginateCount, Settings settings = null ) { if (settings == null) settings = new Settings(); if (dataToPaginateCount == 0) { if (settings.NothingToDisplayString != null) player.SendMessage(settings.NothingToDisplayString, settings.HeaderTextColor); return; } int pageCount = ((dataToPaginateCount - 1) / settings.MaxLinesPerPage) + 1; if (settings.PageLimit > 0 && pageCount > settings.PageLimit) pageCount = settings.PageLimit; if (pageNumber > pageCount) pageNumber = pageCount; if (settings.IncludeHeader) player.SendMessage(string.Format(settings.HeaderFormat, pageNumber, pageCount), settings.HeaderTextColor); int listOffset = (pageNumber - 1) * settings.MaxLinesPerPage; int offsetCounter = 0; int lineCounter = 0; foreach (object lineData in dataToPaginate) { if (lineData == null) continue; if (offsetCounter++ < listOffset) continue; if (lineCounter++ == settings.MaxLinesPerPage) break; string lineMessage; Color lineColor = settings.LineTextColor; if (lineData is Tuple<string,Color>) { var lineFormat = (Tuple<string,Color>)lineData; lineMessage = lineFormat.Item1; lineColor = lineFormat.Item2; } else if (settings.LineFormatter != null) { try { Tuple<string,Color> lineFormat = settings.LineFormatter(lineData, offsetCounter, pageNumber); if (lineFormat == null) continue; lineMessage = lineFormat.Item1; lineColor = lineFormat.Item2; } catch (Exception ex) { throw new InvalidOperationException( "The method referenced by LineFormatter has thrown an exception. See inner exception for details.", ex ); } } else { lineMessage = lineData.ToString(); } if (lineMessage != null) player.SendMessage(lineMessage, lineColor); } if (lineCounter == 0) { if (settings.NothingToDisplayString != null) player.SendMessage(settings.NothingToDisplayString, settings.HeaderTextColor); } else if (settings.IncludeFooter && pageNumber + 1 <= pageCount) { player.SendMessage(string.Format(settings.FooterFormat, pageNumber + 1, pageNumber, pageCount), settings.FooterTextColor); } }
public bool HandleChestGetContents(TSPlayer player, DPoint location, bool skipInteractions) { if (this.IsDisposed) return false; if (!skipInteractions && base.HandleChestGetContents(player, location)) return true; bool isDummyChest = (location.X == 0); if (isDummyChest) return true; if (!TerrariaUtils.Tiles[location].active()) return true; if (this.Config.LoginRequiredForChestUsage && !player.IsLoggedIn) { player.SendErrorMessage("You have to be logged in to make use of chests."); return true; } if (this.Config.DungeonChestProtection && !NPC.downedBoss3 && !player.Group.HasPermission(ProtectorPlugin.ProtectionMaster_Permission)) { ChestKind kind = TerrariaUtils.Tiles.GuessChestKind(location); if (kind == ChestKind.DungeonChest || kind == ChestKind.HardmodeDungeonChest) { player.SendErrorMessage("Skeletron has not been defeated yet."); return true; } } ProtectionEntry protection = null; // Only need the first enumerated entry as we don't need the protections of adjacent blocks. foreach (ProtectionEntry enumProtection in this.ProtectionManager.EnumerateProtectionEntries(location)) { protection = enumProtection; break; } DPoint chestLocation = TerrariaUtils.Tiles.MeasureObject(location).OriginTileLocation; IChest chest = this.ChestManager.ChestFromLocation(chestLocation, player); if (chest == null) return true; if (this.IsChestInUse(player, chest)) { player.SendErrorMessage("Another player is already viewing the content of this chest."); return true; } if (protection != null) { bool isTradeChest = (protection.TradeChestData != null); if (!this.ProtectionManager.CheckProtectionAccess(protection, player)) { if (isTradeChest) this.InitTrade(player, chest, protection); else player.SendErrorMessage("This chest is protected."); return true; } if (isTradeChest) { Item sellItem = new Item(); sellItem.netDefaults(protection.TradeChestData.ItemToSellId); sellItem.stack = protection.TradeChestData.ItemToSellAmount; Item payItem = new Item(); payItem.netDefaults(protection.TradeChestData.ItemToPayId); payItem.stack = protection.TradeChestData.ItemToPayAmount; player.SendMessage($"This is a trade chest selling {TShock.Utils.ItemTag(sellItem)} for {TShock.Utils.ItemTag(payItem)}", Color.OrangeRed); player.SendMessage("You have access to it, so you can modify it any time.", Color.LightGray); } if (protection.RefillChestData != null) { RefillChestMetadata refillChest = protection.RefillChestData; if (this.CheckRefillChestLootability(refillChest, player)) { if (refillChest.OneLootPerPlayer) player.SendMessage("You can loot this chest a single time only.", Color.OrangeRed); } else { return true; } if (refillChest.RefillTime != TimeSpan.Zero) { lock (this.ChestManager.RefillTimers) { if (this.ChestManager.RefillTimers.IsTimerRunning(refillChest.RefillTimer)) { TimeSpan timeLeft = (refillChest.RefillStartTime + refillChest.RefillTime) - DateTime.Now; player.SendMessage($"This chest will refill in {timeLeft.ToLongString()}.", Color.OrangeRed); } else { player.SendMessage("This chest will refill its content.", Color.OrangeRed); } } } else { player.SendMessage("This chest will refill its content.", Color.OrangeRed); } } } lock (ChestManager.DummyChest) { Main.chest[ChestManager.DummyChestIndex] = ChestManager.DummyChest; if (chest.IsWorldChest) { ChestManager.DummyChest.name = chest.Name; player.TPlayer.chest = chest.Index; } else { player.TPlayer.chest = -1; } for (int i = 0; i < Chest.maxItems; i++) { ChestManager.DummyChest.item[i] = chest.Items[i].ToItem(); player.SendData(PacketTypes.ChestItem, string.Empty, ChestManager.DummyChestIndex, i); } ChestManager.DummyChest.x = chestLocation.X; ChestManager.DummyChest.y = chestLocation.Y; player.SendData(PacketTypes.ChestOpen, string.Empty, ChestManager.DummyChestIndex); ChestManager.DummyChest.x = 0; } DPoint oldChestLocation; if (this.PlayerIndexChestDictionary.TryGetValue(player.Index, out oldChestLocation)) { this.PlayerIndexChestDictionary.Remove(player.Index); this.ChestPlayerIndexDictionary.Remove(oldChestLocation); } if (!chest.IsWorldChest) { this.PlayerIndexChestDictionary[player.Index] = chestLocation; this.ChestPlayerIndexDictionary[chestLocation] = player.Index; } return false; }
private void InitTrade(TSPlayer player, IChest chest, ProtectionEntry protection) { TradeChestMetadata tradeChestData = protection.TradeChestData; Item sellItem = new Item(); sellItem.netDefaults(tradeChestData.ItemToSellId); sellItem.stack = tradeChestData.ItemToSellAmount; Item payItem = new Item(); payItem.netDefaults(tradeChestData.ItemToPayId); payItem.stack = tradeChestData.ItemToPayAmount; player.SendMessage($"This is a trade chest owned by {TShock.Utils.ColorTag(GetUserName(protection.Owner), Color.Red)}.", Color.LightGray); Inventory chestInventory = new Inventory(chest.Items, specificPrefixes: false); int stock = chestInventory.Amount(sellItem.netID); if (stock < sellItem.stack) { player.SendMessage($"It was trading {TShock.Utils.ItemTag(sellItem)} for {TShock.Utils.ItemTag(payItem)} but it is out of stock.", Color.LightGray); return; } player.SendMessage($"Click again to purchase {TShock.Utils.ItemTag(sellItem)} for {TShock.Utils.ItemTag(payItem)}", Color.LightGray); CommandInteraction interaction = this.StartOrResetCommandInteraction(player); interaction.ChestOpenCallback += (playerLocal, chestLocation) => { bool complete; bool wasThisChestHit = (chestLocation == chest.Location); if (wasThisChestHit) { // this is important to check, otherwise players could use trade chests to easily duplicate items if (!this.IsChestInUse(playerLocal, chest)) this.PerformTrade(player, protection, chestInventory, sellItem, payItem); else player.SendErrorMessage("Another player is currently viewing the content of this chest."); complete = false; } else { this.HandleChestGetContents(playerLocal, chestLocation, skipInteractions: true); complete = true; } playerLocal.SendTileSquare(chest.Location); return new CommandInteractionResult {IsHandled = true, IsInteractionCompleted = complete}; }; }
public void ReportBattle(TSPlayer player) { if (Active) EventEnd = DateTime.Now; player.SendMessage(string.Format("Encounter: {0} - {1}", Name, Utils.FormatTime(EventEnd - EventStart)), Color.LightGreen); long total = Players.Sum(p => p.DamageGiven); double seconds = (EventEnd - EventStart).TotalSeconds; if (seconds <= 0) seconds = 1; foreach (Player plr in Players.OrderByDescending(p => p.DamageGiven)) { player.SendMessage(string.Format("{0}: {1:n0} ({2:n2}%) - {3:n2}dps", plr.Name, plr.DamageGiven, plr.DamageGiven * 100.0 / total, plr.DamageGiven / seconds), Color.LightGreen); } if(LastHit > 0) player.SendMessage(string.Format("Last hit: {0} for {1:n0} damage.", Main.player[LastPlayerHit].name, LastHit), Color.Green); }
public static bool HandleCommand(TSPlayer player, string text) { string cmdText = text.Remove(0, 1); var args = Commands.ParseParameters(cmdText); if (args.Count < 1) return false; string cmdName = args[0]; args.RemoveAt(0); Command cmd = null; foreach (Command command in Commands.ChatCommands) { if (command.Name.Equals(cmdName)) { cmd = command; } } if (cmd == null) { return false; } if (!cmd.CanRun(player)) { Tools.SendLogs(string.Format("{0} tried to execute {1}", player.Name, cmd.Name), Color.Red); player.SendMessage("You do not have access to that command.", Color.Red); } else { Tools.SendLogs(string.Format("{0} executed: /{1}", player.Name, cmdText), Color.Red); cmd.Run(cmdText, player, args); } return true; }
public bool HasPermissionToBuildInRegion(TSPlayer ply) { if (!ply.IsLoggedIn) { if (!ply.HasBeenNaggedAboutLoggingIn) { ply.SendMessage("You must be logged in to take advantage of protected regions.", Color.Red); ply.HasBeenNaggedAboutLoggingIn = true; } return false; } if (!DisableBuild) { return true; } return AllowedIDs.Contains(ply.UserID) || AllowedGroups.Contains(ply.Group.Name) || Owner == ply.UserAccountName || ply.Group.HasPermission("manageregion"); }
public static void ShowFile(TSCommand command, string chat, TSPlayer player) { try { String filetoshow = Path.Combine(SavePath, command.file); foreach (var group in command.groups) { if (group.Key == player.Group.Name) { filetoshow = Path.Combine(SavePath, group.Value); } } Dictionary<string, Color> displayLines = new Dictionary<string, Color>(); TSUtils.CheckFile(filetoshow); var file = File.ReadAllLines(filetoshow); var messages = TSUtils.ReplaceVariables(file, player); int page = 0; if (chat.Contains(" ")) { var data = chat.Split(' '); if (int.TryParse(data[1], out page)) page--; else player.SendMessage(string.Format("Invalid page number ({0})", data[1]), Color.Red); } TSUtils.Paginate(TSUtils.GetPaginationHeader(command.name, command.command, page + 1, (messages.Count / 6) + 1), messages, page, player); } catch (Exception ex) { Log.ConsoleError("Something when wrong when showing {0} \"{1}\". Check the Logs.".SFormat(player.Name, command.command)); Log.Error(ex.ToString()); } }
public static bool CheckInventory(TSPlayer player) { PlayerData playerData = player.PlayerData; bool check = true; if (player.TPlayer.statLifeMax > playerData.maxHealth) { player.SendMessage("Error: Your max health exceeded (" + playerData.maxHealth + ") which is stored on server", Color.Cyan); check = false; } Item[] inventory = player.TPlayer.inventory; Item[] armor = player.TPlayer.armor; for (int i = 0; i < NetItem.maxNetInventory; i++) { if (i < 49) { Item item = new Item(); Item serverItem = new Item(); if (inventory[i] != null && inventory[i].netID != 0) { if (playerData.inventory[i].netID != inventory[i].netID) { item.netDefaults(inventory[i].netID); item.Prefix(inventory[i].prefix); item.AffixName(); player.SendMessage(player.IgnoreActionsForInventory = "Your item (" + item.name + ") needs to be deleted.", Color.Cyan); check = false; } else if (playerData.inventory[i].prefix != inventory[i].prefix) { item.netDefaults(inventory[i].netID); item.Prefix(inventory[i].prefix); item.AffixName(); player.SendMessage(player.IgnoreActionsForInventory = "Your item (" + item.name + ") needs to be deleted.", Color.Cyan); check = false; } else if (inventory[i].stack > playerData.inventory[i].stack) { item.netDefaults(inventory[i].netID); item.Prefix(inventory[i].prefix); item.AffixName(); player.SendMessage( player.IgnoreActionsForInventory = "Your item (" + item.name + ") (" + inventory[i].stack + ") needs to have it's stack decreased to (" + playerData.inventory[i].stack + ").", Color.Cyan); check = false; } } } else { Item item = new Item(); Item serverItem = new Item(); if (armor[i - 48] != null && armor[i - 48].netID != 0) { if (playerData.inventory[i].netID != armor[i - 48].netID) { item.netDefaults(armor[i - 48].netID); item.Prefix(armor[i - 48].prefix); item.AffixName(); player.SendMessage(player.IgnoreActionsForInventory = "Your armor (" + item.name + ") needs to be deleted.", Color.Cyan); check = false; } else if (playerData.inventory[i].prefix != armor[i - 48].prefix) { item.netDefaults(armor[i - 48].netID); item.Prefix(armor[i - 48].prefix); item.AffixName(); player.SendMessage(player.IgnoreActionsForInventory = "Your armor (" + item.name + ") needs to be deleted.", Color.Cyan); check = false; } else if (armor[i - 48].stack > playerData.inventory[i].stack) { item.netDefaults(armor[i - 48].netID); item.Prefix(armor[i - 48].prefix); item.AffixName(); player.SendMessage( player.IgnoreActionsForInventory = "Your armor (" + item.name + ") (" + inventory[i].stack + ") needs to have it's stack decreased to (" + playerData.inventory[i].stack + ").", Color.Cyan); check = false; } } } } return check; }
public static bool HandleCommand(TSPlayer player, string text) { string cmdText = text.Remove(0, 1); var args = ParseParameters(cmdText); if (args.Count < 1) return false; string cmdName = args[0]; args.RemoveAt(0); Command cmd = ChatCommands.FirstOrDefault(c => c.HasAlias(cmdName)); if (cmd == null) { player.SendMessage("Invalid Command Entered. Type /help for a list of valid Commands.", Color.Red); return true; } if (!cmd.CanRun(player)) { TShock.Utils.SendLogs(string.Format("{0} tried to execute {1}", player.Name, cmd.Name), Color.Red); player.SendMessage("You do not have access to that command.", Color.Red); } else { if (cmd.DoLog) TShock.Utils.SendLogs(string.Format("{0} executed: /{1}", player.Name, cmdText), Color.Red); cmd.Run(cmdText, player, args); } return true; }
public static bool CheckTilePermission( TSPlayer player, int tileX, int tileY, byte tileType, byte actionType ) { if (!player.Group.HasPermission(Permissions.canbuild)) { if (TShock.Config.AllowIce && actionType != 1) { foreach (Point p in player.IceTiles) { if (p.X == tileX && p.Y == tileY && (Main.tile[p.X, p.Y].type == 0 || Main.tile[p.X, p.Y].type == 127)) { player.IceTiles.Remove(p); return false; } } if (((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) - player.BPm) > 2000){ player.SendMessage("You do not have permission to build!", Color.Red); player.BPm=DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; } return true; } if (TShock.Config.AllowIce && actionType == 1 && tileType == 127) { player.IceTiles.Add(new Point(tileX, tileY)); return false; } if (((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) - player.BPm) > 2000){ player.SendMessage("You do not have permission to build!", Color.Red); player.BPm=DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; } return true; } if (!player.Group.HasPermission(Permissions.editspawn) && !Regions.CanBuild(tileX, tileY, player) && Regions.InArea(tileX, tileY)) { if (((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) - player.RPm) > 2000){ player.SendMessage("Region protected from changes.", Color.Red); player.RPm=DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; } return true; } if (Config.DisableBuild) { if (!player.Group.HasPermission(Permissions.editspawn)) { if (((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) - player.WPm) > 2000){ player.SendMessage("World protected from changes.", Color.Red); player.WPm=DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; } return true; } } if (Config.SpawnProtection) { if (!player.Group.HasPermission(Permissions.editspawn)) { var flag = CheckSpawn(tileX, tileY); if (flag) { if (((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) - player.SPm) > 2000){ player.SendMessage("Spawn protected from changes.", Color.Red); player.SPm=DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; } return true; } } } return false; }
public static void SendPage( TSPlayer player, int pageNumber, IEnumerable dataToPaginate, int dataToPaginateCount, Settings settings = null) { if (settings == null) { settings = new Settings(); } if (dataToPaginateCount == 0) { if (settings.NothingToDisplayString != null) { if (!player.RealPlayer) { player.SendSuccessMessage(settings.NothingToDisplayString); } else { player.SendMessage(settings.NothingToDisplayString, settings.HeaderTextColor); } } return; } int pageCount = ((dataToPaginateCount - 1) / settings.MaxLinesPerPage) + 1; if (settings.PageLimit > 0 && pageCount > settings.PageLimit) { pageCount = settings.PageLimit; } if (pageNumber > pageCount) { pageNumber = pageCount; } if (settings.IncludeHeader) { if (!player.RealPlayer) { player.SendSuccessMessage(string.Format(settings.HeaderFormat, pageNumber, pageCount)); } else { player.SendMessage(string.Format(settings.HeaderFormat, pageNumber, pageCount), settings.HeaderTextColor); } } int listOffset = (pageNumber - 1) * settings.MaxLinesPerPage; int offsetCounter = 0; int lineCounter = 0; foreach (object lineData in dataToPaginate) { if (lineData == null) { continue; } if (offsetCounter++ < listOffset) { continue; } if (lineCounter++ == settings.MaxLinesPerPage) { break; } string lineMessage; Color lineColor = settings.LineTextColor; if (lineData is Tuple <string, Color> ) { var lineFormat = (Tuple <string, Color>)lineData; lineMessage = lineFormat.Item1; lineColor = lineFormat.Item2; } else if (settings.LineFormatter != null) { try { Tuple <string, Color> lineFormat = settings.LineFormatter(lineData, offsetCounter, pageNumber); if (lineFormat == null) { continue; } lineMessage = lineFormat.Item1; lineColor = lineFormat.Item2; } catch (Exception ex) { throw new InvalidOperationException( "The method referenced by LineFormatter has thrown an exception. See inner exception for details.", ex); } } else { lineMessage = lineData.ToString(); } if (lineMessage != null) { if (!player.RealPlayer) { player.SendInfoMessage(lineMessage); } else { player.SendMessage(lineMessage, lineColor); } } } if (lineCounter == 0) { if (settings.NothingToDisplayString != null) { if (!player.RealPlayer) { player.SendSuccessMessage(settings.NothingToDisplayString); } else { player.SendMessage(settings.NothingToDisplayString, settings.HeaderTextColor); } } } else if (settings.IncludeFooter && pageNumber + 1 <= pageCount) { if (!player.RealPlayer) { player.SendInfoMessage(string.Format(settings.FooterFormat, pageNumber + 1, pageNumber, pageCount)); } else { player.SendMessage(string.Format(settings.FooterFormat, pageNumber + 1, pageNumber, pageCount), settings.FooterTextColor); } } }
public static bool CheckTilePermission(TSPlayer player, int tileX, int tileY) { if (!player.Group.HasPermission(Permissions.canbuild)) { if (((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) - player.BPm) > 2000){ player.SendMessage("You do not have permission to build!", Color.Red); player.BPm=DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; } return true; } if (!player.Group.HasPermission(Permissions.editspawn) && !Regions.CanBuild(tileX, tileY, player) && Regions.InArea(tileX, tileY)) { if (((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) - player.RPm) > 2000){ player.SendMessage("Region protected from changes.", Color.Red); player.RPm=DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; } return true; } if (Config.DisableBuild) { if (!player.Group.HasPermission(Permissions.editspawn)) { if (((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) - player.WPm) > 2000){ player.SendMessage("World protected from changes.", Color.Red); player.WPm=DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; } return true; } } if (Config.SpawnProtection) { if (!player.Group.HasPermission(Permissions.editspawn)) { var flag = CheckSpawn(tileX, tileY); if (flag) { if (((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) - player.SPm) > 1000){ player.SendMessage("Spawn protected from changes.", Color.Red); player.SPm=DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; } return true; } } } return false; }