merged master into us

This commit is contained in:
Maverick Motherfucker 2011-06-04 13:56:39 -07:00
commit 4907407337
8 changed files with 157 additions and 7 deletions

View file

@ -101,6 +101,7 @@ namespace TShockAPI
commands.Add(new Command("help", "", new CommandDelegate(Help)));
commands.Add(new Command("slap", "pvpfun", new CommandDelegate(Slap)));
commands.Add(new Command("off-nosave", "maintenance", new CommandDelegate(OffNoSave)));
commands.Add(new Command("protectspawn", "cfg", new CommandDelegate(ProtectSpawn)));
}
#region Command Methods
@ -602,6 +603,12 @@ namespace TShockAPI
else
Tools.SendMessage(args.PlayerID, "Invalid syntax! Proper syntax: /slap <player> [dmg]", new float[] { 255f, 0f, 0f });
}
public static void ProtectSpawn(CommandArgs args)
{
ConfigurationManager.spawnProtect = (ConfigurationManager.spawnProtect == false);
Tools.SendMessage(args.PlayerID, "Spawn is now " + (ConfigurationManager.spawnProtect ? "protected" : "open") + ".");
}
#endregion
}
}

View file

@ -23,5 +23,7 @@ namespace TShockAPI
public bool KickKillTileAbusers = false;
public bool BanExplosives = true;
public bool KickExplosives = true;
public bool SpawnProtection = true;
public int SpawnProtectionRadius = 5;
}
}

View file

@ -29,6 +29,8 @@ namespace TShockAPI
public static bool kickTnt = false;
public static bool banBoom = true;
public static bool kickBoom = true;
public static bool spawnProtect = true;
public static int spawnProtectRadius = 5;
public enum NPCList : int
{
@ -58,10 +60,16 @@ namespace TShockAPI
kickTnt = cfg.KickKillTileAbusers;
banBoom = cfg.BanExplosives;
kickBoom = cfg.KickExplosives;
spawnProtect = cfg.SpawnProtection;
spawnProtectRadius = cfg.SpawnProtectionRadius;
}
public static void WriteJsonConfiguration()
{
if (!System.IO.Directory.Exists(FileTools.SaveDir))
{
System.IO.Directory.CreateDirectory(FileTools.SaveDir);
}
if (System.IO.File.Exists(FileTools.SaveDir + "config.json"))
{
return;
@ -87,6 +95,8 @@ namespace TShockAPI
cfg.KickKillTileAbusers = true;
cfg.BanExplosives = true;
cfg.KickExplosives = true;
cfg.SpawnProtection = true;
cfg.SpawnProtectionRadius = 5;
string json = JsonConvert.SerializeObject(cfg, Formatting.Indented);
TextWriter tr = new StreamWriter(FileTools.SaveDir + "config.json");

View file

@ -15,7 +15,7 @@ namespace TShockAPI
public static string saveDir = "./tshock/";
public static Version VersionNum = new Version(1, 5, 0, 1);
public static Version VersionNum = new Version(1, 6, 0, 0);
public static bool shownVersion = false;
@ -104,6 +104,14 @@ namespace TShockAPI
public override void Initialize()
{
try
{
FileTools.SetupConfig();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
Log.Initialize(FileTools.SaveDir + "log.txt", LogLevel.All, true);
Log.Info("Starting...");
GameHooks.OnPreInitialize += OnPreInit;
@ -138,8 +146,6 @@ namespace TShockAPI
NetHooks.OnPreGetData -= GetData;
NetHooks.OnGreetPlayer -= new NetHooks.GreetPlayerD(OnGreetPlayer);
NpcHooks.OnStrikeNpc -= new NpcHooks.StrikeNpcD(NpcHooks_OnStrikeNpc);
ConfigurationManager.WriteJsonConfiguration();
Log.Info("Shutting down...");
}
/*
@ -168,6 +174,18 @@ namespace TShockAPI
byte type = br.ReadByte();
int x = br.ReadInt32();
int y = br.ReadInt32();
byte typetile = br.ReadByte();
if (type == 0 || type == 1)
if (ConfigurationManager.spawnProtect)
if (!players[e.Msg.whoAmI].group.HasPermission("editspawn"))
{
var flag = CheckSpawn(x, y);
if (flag)
{
Tools.SendMessage(e.Msg.whoAmI, "The spawn is protected!", new float[] { 255f, 0f, 0f });
e.Handled = true;
}
}
if (type == 0 && BlacklistTiles[Main.tile[x, y].type] && Main.player[e.Msg.whoAmI].active)
{
@ -192,6 +210,7 @@ namespace TShockAPI
Main.player[e.Msg.whoAmI].hostile = true;
NetMessage.SendData(30, -1, -1, "", e.Msg.whoAmI);
e.Handled = true;
return;
}
else if (e.MsgID == 0x0A) //SendSection
{
@ -304,6 +323,30 @@ namespace TShockAPI
}
}
}
else if (e.MsgID == 0x30)
{
int x;
int y;
byte liquid;
bool lava;
using (var br = new BinaryReader(new MemoryStream(e.Msg.readBuffer, e.Index, e.Length)))
{
x = br.ReadInt32();
y = br.ReadInt32();
liquid = br.ReadByte();
lava = br.ReadBoolean();
}
if (ConfigurationManager.spawnProtect)
if (!players[e.Msg.whoAmI].group.HasPermission("editspawn"))
{
var flag = CheckSpawn(x, y);
if (flag)
{
Tools.SendMessage(e.Msg.whoAmI, "The spawn is protected!", new float[] { 255f, 0f, 0f });
e.Handled = true;
}
}
}
else if (e.MsgID == 0x2C) // KillMe
{
byte id;
@ -640,5 +683,16 @@ namespace TShockAPI
}
return false;
}
public static bool CheckSpawn(int x, int y)
{
Vector2 tile = new Vector2((float)x, (float)y);
Vector2 spawn = new Vector2((float)Main.spawnTileX, (float)Main.spawnTileY);
var distance = Vector2.Distance(spawn, tile);
if (distance > (float)ConfigurationManager.spawnProtectRadius)
return false;
else
return true;
}
}
}

View file

@ -8,11 +8,12 @@
#ALWAYS DECLARE A GROUP'S PARENT BEFORE YOU DECLARE THE GROUP
#currently avaliable permissions: kick ban ignorecheatdetection
#power cfg causeevents spawnboss tp
#maintenance cfg causeevents spawnboss tp
#spawnmob cheat kill pvpfun
#immunetoban immunetokick
#immunetoban immunetokick editspawn
#ignoregriefdetection
default null
newadmin default kick
newadmin default kick editspawn
admin newadmin ban causeevents spawnboss spawnmob tp immunetokick kill
trustedadmin admin ignorecheatdetection power cfg cheat pvpfun ignorecheatdetection immunetoban
trustedadmin admin ignorecheatdetection maintenance cfg cheat pvpfun ignorecheatdetection immunetoban ignoregriefdetection