Adds banned items. Delete groups.txt and run server once.
This commit is contained in:
parent
2807bb70ab
commit
d2c1082c59
9 changed files with 119 additions and 23 deletions
|
|
@ -1383,6 +1383,7 @@ namespace TShockAPI
|
|||
}
|
||||
|
||||
var items = Tools.GetItemByIdOrName(args.Parameters[0]);
|
||||
|
||||
if (items.Count == 0)
|
||||
{
|
||||
args.Player.SendMessage("Invalid item type!", Color.Red);
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ namespace TShockAPI
|
|||
public static readonly string WhitelistPath = Path.Combine(TShock.SavePath, "whitelist.txt");
|
||||
public static readonly string GroupsPath = Path.Combine(TShock.SavePath, "groups.txt");
|
||||
public static readonly string UsersPath = Path.Combine(TShock.SavePath, "users.txt");
|
||||
public static readonly string ItemBansPath = Path.Combine(TShock.SavePath, "itembans.txt");
|
||||
public static readonly string ConfigPath = Path.Combine(TShock.SavePath, "config.json");
|
||||
|
||||
public static void CreateFile(string file)
|
||||
|
|
@ -60,6 +61,7 @@ namespace TShockAPI
|
|||
CreateIfNot(WhitelistPath);
|
||||
CreateIfNot(GroupsPath, Resources.groups);
|
||||
CreateIfNot(UsersPath, Resources.users);
|
||||
CreateIfNot(ItemBansPath, Resources.itembans);
|
||||
|
||||
try
|
||||
{
|
||||
|
|
|
|||
76
TShockAPI/ItemManager.cs
Normal file
76
TShockAPI/ItemManager.cs
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using Terraria;
|
||||
|
||||
namespace TShockAPI
|
||||
{
|
||||
class ItemManager
|
||||
{
|
||||
public static List<ItemBan> BannedItems = new List<ItemBan>();
|
||||
|
||||
public static void LoadBans()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!File.Exists(FileTools.ItemBansPath))
|
||||
return;
|
||||
|
||||
BannedItems.Clear();
|
||||
|
||||
foreach (var line in File.ReadAllLines(FileTools.ItemBansPath))
|
||||
{
|
||||
int ID = -1;
|
||||
if (Int32.TryParse(line, out ID))
|
||||
{
|
||||
if (ID <= Main.item.Length)
|
||||
{
|
||||
var item = Tools.GetItemById(ID);
|
||||
BannedItems.Add(new ItemBan(ID, item.name));
|
||||
Log.Info("Item: " + item.name + " is banned");
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Warn("Invalid ID " + ID);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
public static bool ItemIsBanned(string ID)
|
||||
{
|
||||
foreach (ItemBan item in BannedItems)
|
||||
{
|
||||
if (ID == item.Name)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public class ItemBan
|
||||
{
|
||||
public int ID { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public ItemBan(int id, string name)
|
||||
{
|
||||
ID = id;
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public ItemBan()
|
||||
{
|
||||
ID = -1;
|
||||
Name = string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
18
TShockAPI/Resources.Designer.cs
generated
18
TShockAPI/Resources.Designer.cs
generated
|
|
@ -1,7 +1,7 @@
|
|||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.225
|
||||
// Runtime Version:4.0.30319.1
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
|
|
@ -71,9 +71,9 @@ namespace TShockAPI {
|
|||
///#ALWAYS DECLARE A GROUP'S PARENT BEFORE YOU DECLARE THE GROUP
|
||||
///
|
||||
///#currently avaliable permissions:
|
||||
///#kick ban ignorecheatdetection
|
||||
///#maintenance cfg causeevents spawnboss tp
|
||||
///#spawnmob che [rest of string was truncated]";.
|
||||
///#reservedslot - reserved slot for player
|
||||
///#canwater - allow players to use water
|
||||
///#canlav [rest of string was truncated]";.
|
||||
/// </summary>
|
||||
internal static string groups {
|
||||
get {
|
||||
|
|
@ -81,6 +81,16 @@ namespace TShockAPI {
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to #see https://github.com/TShock/TShock/wiki/Item-List for a list of groups
|
||||
///#List each banned item below this with spaces.
|
||||
/// </summary>
|
||||
internal static string itembans {
|
||||
get {
|
||||
return ResourceManager.GetString("itembans", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to #format
|
||||
///#ip group
|
||||
|
|
|
|||
|
|
@ -1,21 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
TShock, a server mod for Terraria
|
||||
Copyright (C) 2011 The TShock Team
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
|
@ -138,6 +121,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
<data name="groups" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>config\groups.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
|
||||
</data>
|
||||
<data name="itembans" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>config\itembans.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
|
||||
</data>
|
||||
<data name="users" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>config\users.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
|
||||
</data>
|
||||
|
|
|
|||
|
|
@ -105,6 +105,8 @@ namespace TShockAPI
|
|||
|
||||
WarpsManager.ReadAllSettings();
|
||||
|
||||
ItemManager.LoadBans();
|
||||
|
||||
Backups.KeepFor = ConfigurationManager.BackupKeepFor;
|
||||
Backups.Interval = ConfigurationManager.BackupInterval;
|
||||
|
||||
|
|
@ -211,6 +213,18 @@ namespace TShockAPI
|
|||
player.TileThreshold = 0;
|
||||
player.TilesDestroyed.Clear();
|
||||
}
|
||||
|
||||
if (!player.Group.HasPermission("usebanneditem"))
|
||||
{
|
||||
for (int i = 0; i < Main.player[player.Index].inventory.Length; i++)
|
||||
{
|
||||
if (ItemManager.ItemIsBanned(Main.player[player.Index].inventory[i].name))
|
||||
{
|
||||
player.Disconnect("Using banned item: " + Main.player[player.Index].inventory[i].name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,6 +74,7 @@
|
|||
<ItemGroup>
|
||||
<Compile Include="BackupManager.cs" />
|
||||
<Compile Include="BanManager.cs" />
|
||||
<Compile Include="ItemManager.cs" />
|
||||
<Compile Include="Commands.cs" />
|
||||
<Compile Include="ConfigFile.cs" />
|
||||
<Compile Include="ConfigurationManager.cs" />
|
||||
|
|
@ -129,6 +130,9 @@
|
|||
<Install>true</Install>
|
||||
</BootstrapperPackage>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="config\itembans.txt" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
<PreBuildEvent>
|
||||
|
|
@ -139,7 +143,7 @@
|
|||
</PropertyGroup>
|
||||
<ProjectExtensions>
|
||||
<VisualStudio>
|
||||
<UserProperties BuildVersion_IncrementBeforeBuild="False" BuildVersion_StartDate="2011/6/17" BuildVersion_BuildVersioningStyle="None.None.None.MonthAndDayStamp" BuildVersion_BuildAction="Both" BuildVersion_UpdateFileVersion="True" BuildVersion_UpdateAssemblyVersion="True" />
|
||||
<UserProperties BuildVersion_UpdateAssemblyVersion="True" BuildVersion_UpdateFileVersion="True" BuildVersion_BuildAction="Both" BuildVersion_BuildVersioningStyle="None.None.None.MonthAndDayStamp" BuildVersion_StartDate="2011/6/17" BuildVersion_IncrementBeforeBuild="False" />
|
||||
</VisualStudio>
|
||||
</ProjectExtensions>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
|
|
|
|||
|
|
@ -34,9 +34,10 @@
|
|||
#immunetoban - player can't be banned
|
||||
#ignorecheatdetection - allow player to cheat (health/mana cheats)
|
||||
#ignoregriefdetection - allow player to grief (use explosives, water, lava even if they dont have premission to)
|
||||
#usebanneditem - allows player to use banned items
|
||||
|
||||
default null canwater canlava warp
|
||||
vip default reservedslot
|
||||
newadmin default kick editspawn reservedslot
|
||||
admin newadmin ban unban whitelist causeevents spawnboss spawnmob managewarp time tp pvpfun kill logs immunetokick
|
||||
trustedadmin admin maintenance cfg butcher cheat immunetoban ignorecheatdetection ignoregriefdetection
|
||||
trustedadmin admin maintenance cfg butcher cheat immunetoban ignorecheatdetection ignoregriefdetection usebanneditem
|
||||
2
TShockAPI/config/itembans.txt
Normal file
2
TShockAPI/config/itembans.txt
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
#see https://github.com/TShock/TShock/wiki/Item-List for a list of item ids
|
||||
#List each banned item ID below this, with each on a new line
|
||||
Loading…
Add table
Add a link
Reference in a new issue