ReSharper Code optimization
This commit is contained in:
parent
8b99bfacc0
commit
dfc4325e59
10 changed files with 233 additions and 201 deletions
|
|
@ -1,19 +1,19 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace TShockAPI
|
namespace TShockAPI
|
||||||
{
|
{
|
||||||
public class BanManager
|
public class BanManager
|
||||||
{
|
{
|
||||||
DateTime LastLoad;
|
private DateTime LastLoad;
|
||||||
string Path;
|
private string Path;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// IP - Name - Reason
|
/// IP - Name - Reason
|
||||||
/// </summary>
|
/// </summary>
|
||||||
List<Ban> Bans = new List<Ban>();
|
private List<Ban> Bans = new List<Ban>();
|
||||||
|
|
||||||
public BanManager(string path)
|
public BanManager(string path)
|
||||||
{
|
{
|
||||||
|
|
@ -36,7 +36,10 @@ namespace TShockAPI
|
||||||
EnsureChanges();
|
EnsureChanges();
|
||||||
foreach (var ban in Bans)
|
foreach (var ban in Bans)
|
||||||
{
|
{
|
||||||
if (ban.Name.Equals(name, casesensitive ? StringComparison.Ordinal : StringComparison.InvariantCultureIgnoreCase))
|
if (ban.Name.Equals(name,
|
||||||
|
casesensitive
|
||||||
|
? StringComparison.Ordinal
|
||||||
|
: StringComparison.InvariantCultureIgnoreCase))
|
||||||
return ban;
|
return ban;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
using Terraria;
|
using Terraria;
|
||||||
|
|
||||||
namespace TShockAPI
|
namespace TShockAPI
|
||||||
|
|
@ -11,6 +10,7 @@ namespace TShockAPI
|
||||||
public class Commands
|
public class Commands
|
||||||
{
|
{
|
||||||
public delegate void CommandDelegate(CommandArgs args);
|
public delegate void CommandDelegate(CommandArgs args);
|
||||||
|
|
||||||
public static List<Command> commands = new List<Command>();
|
public static List<Command> commands = new List<Command>();
|
||||||
|
|
||||||
public struct CommandArgs
|
public struct CommandArgs
|
||||||
|
|
@ -22,7 +22,10 @@ namespace TShockAPI
|
||||||
|
|
||||||
public CommandArgs(string message, int x, int y, int id)
|
public CommandArgs(string message, int x, int y, int id)
|
||||||
{
|
{
|
||||||
Message = message; PlayerX = x; PlayerY = y; PlayerID = id;
|
Message = message;
|
||||||
|
PlayerX = x;
|
||||||
|
PlayerY = y;
|
||||||
|
PlayerID = id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -30,7 +33,7 @@ namespace TShockAPI
|
||||||
{
|
{
|
||||||
private string name;
|
private string name;
|
||||||
private string permission;
|
private string permission;
|
||||||
CommandDelegate command;
|
private CommandDelegate command;
|
||||||
|
|
||||||
public Command(string cmdName, string permissionNeeded, CommandDelegate cmd)
|
public Command(string cmdName, string permissionNeeded, CommandDelegate cmd)
|
||||||
{
|
{
|
||||||
|
|
@ -48,8 +51,8 @@ namespace TShockAPI
|
||||||
|
|
||||||
CommandArgs args = new CommandArgs();
|
CommandArgs args = new CommandArgs();
|
||||||
args.Message = msg;
|
args.Message = msg;
|
||||||
args.PlayerX = (int)ply.GetPlayer().position.X;
|
args.PlayerX = (int) ply.GetPlayer().position.X;
|
||||||
args.PlayerY = (int)ply.GetPlayer().position.Y;
|
args.PlayerY = (int) ply.GetPlayer().position.Y;
|
||||||
args.PlayerID = ply.GetPlayerID();
|
args.PlayerID = ply.GetPlayerID();
|
||||||
|
|
||||||
command(args);
|
command(args);
|
||||||
|
|
@ -73,42 +76,42 @@ namespace TShockAPI
|
||||||
|
|
||||||
public static void InitCommands()
|
public static void InitCommands()
|
||||||
{
|
{
|
||||||
commands.Add(new Command("kick", "kick", new CommandDelegate(Kick)));
|
commands.Add(new Command("kick", "kick", Kick));
|
||||||
commands.Add(new Command("ban", "ban", new CommandDelegate(Ban)));
|
commands.Add(new Command("ban", "ban", Ban));
|
||||||
commands.Add(new Command("off", "maintenance", new CommandDelegate(Off)));
|
commands.Add(new Command("off", "maintenance", Off));
|
||||||
commands.Add(new Command("reload", "cfg", new CommandDelegate(Reload)));
|
commands.Add(new Command("reload", "cfg", Reload));
|
||||||
commands.Add(new Command("dropmetor", "causeevents", new CommandDelegate(DropMeteor)));
|
commands.Add(new Command("dropmetor", "causeevents", DropMeteor));
|
||||||
commands.Add(new Command("star", "causeevents", new CommandDelegate(Star)));
|
commands.Add(new Command("star", "causeevents", Star));
|
||||||
commands.Add(new Command("bloodmoon", "causeevents", new CommandDelegate(Bloodmoon)));
|
commands.Add(new Command("bloodmoon", "causeevents", Bloodmoon));
|
||||||
commands.Add(new Command("eater", "spawnboss", new CommandDelegate(Eater)));
|
commands.Add(new Command("eater", "spawnboss", Eater));
|
||||||
commands.Add(new Command("eye", "spawnboss", new CommandDelegate(Eye)));
|
commands.Add(new Command("eye", "spawnboss", Eye));
|
||||||
commands.Add(new Command("skeletron", "spawnboss", new CommandDelegate(Skeletron)));
|
commands.Add(new Command("skeletron", "spawnboss", Skeletron));
|
||||||
commands.Add(new Command("hardcore", "cfg", new CommandDelegate(Hardcore)));
|
commands.Add(new Command("hardcore", "cfg", Hardcore));
|
||||||
commands.Add(new Command("invade", "causeevents", new CommandDelegate(Invade)));
|
commands.Add(new Command("invade", "causeevents", Invade));
|
||||||
commands.Add(new Command("password", "cfg", new CommandDelegate(Password)));
|
commands.Add(new Command("password", "cfg", Password));
|
||||||
commands.Add(new Command("save", "cfg", new CommandDelegate(Save)));
|
commands.Add(new Command("save", "cfg", Save));
|
||||||
commands.Add(new Command("spawn", "tp", new CommandDelegate(Spawn)));
|
commands.Add(new Command("spawn", "tp", Spawn));
|
||||||
commands.Add(new Command("tp", "tp", new CommandDelegate(TP)));
|
commands.Add(new Command("tp", "tp", TP));
|
||||||
commands.Add(new Command("tphere", "tp", new CommandDelegate(TPHere)));
|
commands.Add(new Command("tphere", "tp", TPHere));
|
||||||
commands.Add(new Command("spawnmob", "spawnmob", new CommandDelegate(SpawnMob)));
|
commands.Add(new Command("spawnmob", "spawnmob", SpawnMob));
|
||||||
commands.Add(new Command("butcher", "cheat", new CommandDelegate(Butcher)));
|
commands.Add(new Command("butcher", "cheat", Butcher));
|
||||||
commands.Add(new Command("maxspawns", "cfg", new CommandDelegate(MaxSpawns)));
|
commands.Add(new Command("maxspawns", "cfg", MaxSpawns));
|
||||||
commands.Add(new Command("spawnrate", "cfg", new CommandDelegate(SpawnRate)));
|
commands.Add(new Command("spawnrate", "cfg", SpawnRate));
|
||||||
commands.Add(new Command("time", "cfg", new CommandDelegate(Time)));
|
commands.Add(new Command("time", "cfg", Time));
|
||||||
commands.Add(new Command("help", "", new CommandDelegate(Help)));
|
commands.Add(new Command("help", "", Help));
|
||||||
commands.Add(new Command("slap", "pvpfun", new CommandDelegate(Slap)));
|
commands.Add(new Command("slap", "pvpfun", Slap));
|
||||||
commands.Add(new Command("off-nosave", "maintenance", new CommandDelegate(OffNoSave)));
|
commands.Add(new Command("off-nosave", "maintenance", OffNoSave));
|
||||||
commands.Add(new Command("protectspawn", "editspawn", new CommandDelegate(ProtectSpawn)));
|
commands.Add(new Command("protectspawn", "editspawn", ProtectSpawn));
|
||||||
commands.Add(new Command("debug-config", "cfg", new CommandDelegate(DebugConfiguration)));
|
commands.Add(new Command("debug-config", "cfg", DebugConfiguration));
|
||||||
commands.Add(new Command("playing", "", new CommandDelegate(Playing)));
|
commands.Add(new Command("playing", "", Playing));
|
||||||
commands.Add(new Command("auth", "", new CommandDelegate(AuthToken)));
|
commands.Add(new Command("auth", "", AuthToken));
|
||||||
commands.Add(new Command("me", "", new CommandDelegate(ThirdPerson)));
|
commands.Add(new Command("me", "", ThirdPerson));
|
||||||
if (ConfigurationManager.distributationAgent != "terraria-online")
|
if (ConfigurationManager.distributationAgent != "terraria-online")
|
||||||
{
|
{
|
||||||
commands.Add(new Command("kill", "kill", new CommandDelegate(Kill)));
|
commands.Add(new Command("kill", "kill", Kill));
|
||||||
commands.Add(new Command("item", "cheat", new CommandDelegate(Item)));
|
commands.Add(new Command("item", "cheat", Item));
|
||||||
commands.Add(new Command("give", "cheat", new CommandDelegate(Give)));
|
commands.Add(new Command("give", "cheat", Give));
|
||||||
commands.Add(new Command("heal", "cheat", new CommandDelegate(Heal)));
|
commands.Add(new Command("heal", "cheat", Heal));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -117,7 +120,7 @@ namespace TShockAPI
|
||||||
public static void ThirdPerson(CommandArgs args)
|
public static void ThirdPerson(CommandArgs args)
|
||||||
{
|
{
|
||||||
string msg = args.Message.Remove(0, 3);
|
string msg = args.Message.Remove(0, 3);
|
||||||
Tools.Broadcast("*" + Tools.FindPlayer(args.PlayerID) + " " + msg, new float[] {205, 133, 63 });
|
Tools.Broadcast("*" + Tools.FindPlayer(args.PlayerID) + " " + msg, new float[] {205, 133, 63});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Playing(CommandArgs args)
|
public static void Playing(CommandArgs args)
|
||||||
|
|
@ -134,20 +137,20 @@ namespace TShockAPI
|
||||||
lineOne += "BanCheater : " + ConfigurationManager.banCheater + ", ";
|
lineOne += "BanCheater : " + ConfigurationManager.banCheater + ", ";
|
||||||
lineOne += "KickGriefer : " + ConfigurationManager.kickGriefer + ", ";
|
lineOne += "KickGriefer : " + ConfigurationManager.kickGriefer + ", ";
|
||||||
lineOne += "BanGriefer : " + ConfigurationManager.banGriefer;
|
lineOne += "BanGriefer : " + ConfigurationManager.banGriefer;
|
||||||
Tools.SendMessage(ply, lineOne, new float[] { 255f, 255f, 0f });
|
Tools.SendMessage(ply, lineOne, new[] {255f, 255f, 0f});
|
||||||
string lineTwo = "";
|
string lineTwo = "";
|
||||||
lineTwo += "BanTnt : " + ConfigurationManager.banTnt + ", ";
|
lineTwo += "BanTnt : " + ConfigurationManager.banTnt + ", ";
|
||||||
lineTwo += "KickTnt : " + ConfigurationManager.kickTnt + ", ";
|
lineTwo += "KickTnt : " + ConfigurationManager.kickTnt + ", ";
|
||||||
lineTwo += "BanBoom : " + ConfigurationManager.banBoom + ", ";
|
lineTwo += "BanBoom : " + ConfigurationManager.banBoom + ", ";
|
||||||
lineTwo += "KickBoom : " + ConfigurationManager.kickBoom;
|
lineTwo += "KickBoom : " + ConfigurationManager.kickBoom;
|
||||||
Tools.SendMessage(ply, lineTwo, new float[] { 255f, 255f, 0f });
|
Tools.SendMessage(ply, lineTwo, new[] {255f, 255f, 0f});
|
||||||
string lineThree = "";
|
string lineThree = "";
|
||||||
lineThree += "InvMultiplier : " + ConfigurationManager.invasionMultiplier + ", ";
|
lineThree += "InvMultiplier : " + ConfigurationManager.invasionMultiplier + ", ";
|
||||||
lineThree += "ProtectS : " + ConfigurationManager.spawnProtect + ", ";
|
lineThree += "ProtectS : " + ConfigurationManager.spawnProtect + ", ";
|
||||||
lineThree += "ProtectR : " + ConfigurationManager.spawnProtectRadius + ", ";
|
lineThree += "ProtectR : " + ConfigurationManager.spawnProtectRadius + ", ";
|
||||||
lineThree += "DMS : " + ConfigurationManager.defaultMaxSpawns + ", ";
|
lineThree += "DMS : " + ConfigurationManager.defaultMaxSpawns + ", ";
|
||||||
lineThree += "SpawnRate: " + ConfigurationManager.defaultSpawnRate + ", ";
|
lineThree += "SpawnRate: " + ConfigurationManager.defaultSpawnRate + ", ";
|
||||||
Tools.SendMessage(ply, lineThree, new float[] { 255f, 255f, 0f });
|
Tools.SendMessage(ply, lineThree, new[] {255f, 255f, 0f});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Kick(CommandArgs args)
|
public static void Kick(CommandArgs args)
|
||||||
|
|
@ -163,12 +166,12 @@ namespace TShockAPI
|
||||||
Tools.Broadcast(Tools.FindPlayer(player) + " was kicked by " + Tools.FindPlayer(ply));
|
Tools.Broadcast(Tools.FindPlayer(player) + " was kicked by " + Tools.FindPlayer(ply));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Tools.SendMessage(ply, "You can't kick another admin!", new float[] { 255f, 0f, 0f });
|
Tools.SendMessage(ply, "You can't kick another admin!", new[] {255f, 0f, 0f});
|
||||||
}
|
}
|
||||||
else if (Tools.FindPlayer(plStr) == -2)
|
else if (Tools.FindPlayer(plStr) == -2)
|
||||||
Tools.SendMessage(ply, "More than one player matched!", new float[] { 255f, 0f, 0f });
|
Tools.SendMessage(ply, "More than one player matched!", new[] {255f, 0f, 0f});
|
||||||
else
|
else
|
||||||
Tools.SendMessage(ply, "Invalid player!", new float[] { 255f, 0f, 0f });
|
Tools.SendMessage(ply, "Invalid player!", new[] {255f, 0f, 0f});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Ban(CommandArgs args)
|
public static void Ban(CommandArgs args)
|
||||||
|
|
@ -185,12 +188,12 @@ namespace TShockAPI
|
||||||
Tools.Broadcast(Tools.FindPlayer(adminplr) + " banned " + Tools.FindPlayer(player) + "!");
|
Tools.Broadcast(Tools.FindPlayer(adminplr) + " banned " + Tools.FindPlayer(player) + "!");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Tools.SendMessage(adminplr, "You can't ban another admin!", new float[] { 255f, 0f, 0f });
|
Tools.SendMessage(adminplr, "You can't ban another admin!", new[] {255f, 0f, 0f});
|
||||||
}
|
}
|
||||||
else if (Tools.FindPlayer(plStr) == -2)
|
else if (Tools.FindPlayer(plStr) == -2)
|
||||||
Tools.SendMessage(adminplr, "More than one player matched!", new float[] { 255f, 0f, 0f });
|
Tools.SendMessage(adminplr, "More than one player matched!", new[] {255f, 0f, 0f});
|
||||||
else
|
else
|
||||||
Tools.SendMessage(adminplr, "Invalid player!", new float[] { 255f, 0f, 0f });
|
Tools.SendMessage(adminplr, "Invalid player!", new[] {255f, 0f, 0f});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Off(CommandArgs args)
|
public static void Off(CommandArgs args)
|
||||||
|
|
@ -228,12 +231,12 @@ namespace TShockAPI
|
||||||
int penis56 = 12;
|
int penis56 = 12;
|
||||||
int penis57 = Main.rand.Next(Main.maxTilesX - 50) + 100;
|
int penis57 = Main.rand.Next(Main.maxTilesX - 50) + 100;
|
||||||
penis57 *= 0x10;
|
penis57 *= 0x10;
|
||||||
int penis58 = Main.rand.Next((int)(Main.maxTilesY * 0.05)) * 0x10;
|
int penis58 = Main.rand.Next((int) (Main.maxTilesY*0.05))*0x10;
|
||||||
Microsoft.Xna.Framework.Vector2 vector = new Microsoft.Xna.Framework.Vector2((float)penis57, (float)penis58);
|
Vector2 vector = new Vector2(penis57, penis58);
|
||||||
float speedX = Main.rand.Next(-100, 0x65);
|
float speedX = Main.rand.Next(-100, 0x65);
|
||||||
float speedY = Main.rand.Next(200) + 100;
|
float speedY = Main.rand.Next(200) + 100;
|
||||||
float penis61 = (float)Math.Sqrt((double)((speedX * speedX) + (speedY * speedY)));
|
float penis61 = (float) Math.Sqrt(((speedX*speedX) + (speedY*speedY)));
|
||||||
penis61 = ((float)penis56) / penis61;
|
penis61 = (penis56)/penis61;
|
||||||
speedX *= penis61;
|
speedX *= penis61;
|
||||||
speedY *= penis61;
|
speedY *= penis61;
|
||||||
Projectile.NewProjectile(vector.X, vector.Y, speedX, speedY, 12, 0x3e8, 10f, Main.myPlayer);
|
Projectile.NewProjectile(vector.X, vector.Y, speedX, speedY, 12, 0x3e8, 10f, Main.myPlayer);
|
||||||
|
|
@ -255,7 +258,7 @@ namespace TShockAPI
|
||||||
int x = args.PlayerX;
|
int x = args.PlayerX;
|
||||||
int y = args.PlayerY;
|
int y = args.PlayerY;
|
||||||
int ply = args.PlayerID;
|
int ply = args.PlayerID;
|
||||||
Tools.NewNPC((int)ConfigurationManager.NPCList.WORLD_EATER, x, y, ply);
|
Tools.NewNPC((int) ConfigurationManager.NPCList.WORLD_EATER, x, y, ply);
|
||||||
Tools.Broadcast(Tools.FindPlayer(ply) + " has spawned an eater of worlds!");
|
Tools.Broadcast(Tools.FindPlayer(ply) + " has spawned an eater of worlds!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -264,7 +267,7 @@ namespace TShockAPI
|
||||||
int x = args.PlayerX;
|
int x = args.PlayerX;
|
||||||
int y = args.PlayerY;
|
int y = args.PlayerY;
|
||||||
int ply = args.PlayerID;
|
int ply = args.PlayerID;
|
||||||
Tools.NewNPC((int)ConfigurationManager.NPCList.EYE, x, y, ply);
|
Tools.NewNPC((int) ConfigurationManager.NPCList.EYE, x, y, ply);
|
||||||
Tools.Broadcast(Tools.FindPlayer(ply) + " has spawned an eye!");
|
Tools.Broadcast(Tools.FindPlayer(ply) + " has spawned an eye!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -273,7 +276,7 @@ namespace TShockAPI
|
||||||
int x = args.PlayerX;
|
int x = args.PlayerX;
|
||||||
int y = args.PlayerY;
|
int y = args.PlayerY;
|
||||||
int ply = args.PlayerID;
|
int ply = args.PlayerID;
|
||||||
Tools.NewNPC((int)ConfigurationManager.NPCList.SKELETRON, x, y, ply);
|
Tools.NewNPC((int) ConfigurationManager.NPCList.SKELETRON, x, y, ply);
|
||||||
Tools.Broadcast(Tools.FindPlayer(ply) + " has spawned skeletron!");
|
Tools.Broadcast(Tools.FindPlayer(ply) + " has spawned skeletron!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -322,7 +325,8 @@ namespace TShockAPI
|
||||||
public static void Spawn(CommandArgs args)
|
public static void Spawn(CommandArgs args)
|
||||||
{
|
{
|
||||||
int ply = args.PlayerID;
|
int ply = args.PlayerID;
|
||||||
TShock.Teleport(ply, Main.spawnTileX * 16 + 8 - Main.player[ply].width / 2, Main.spawnTileY * 16 - Main.player[ply].height);
|
TShock.Teleport(ply, Main.spawnTileX*16 + 8 - Main.player[ply].width/2,
|
||||||
|
Main.spawnTileY*16 - Main.player[ply].height);
|
||||||
Tools.SendMessage(ply, "Teleported to your spawnpoint.");
|
Tools.SendMessage(ply, "Teleported to your spawnpoint.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -334,7 +338,10 @@ namespace TShockAPI
|
||||||
if (givenCode == ConfigurationManager.authToken)
|
if (givenCode == ConfigurationManager.authToken)
|
||||||
{
|
{
|
||||||
TextWriter tw = new StreamWriter(FileTools.SaveDir + "users.txt", true);
|
TextWriter tw = new StreamWriter(FileTools.SaveDir + "users.txt", true);
|
||||||
tw.Write("\n" + Tools.GetRealIP(Convert.ToString(Netplay.serverSock[args.PlayerID].tcpClient.Client.RemoteEndPoint)) + " superadmin");
|
tw.Write("\n" +
|
||||||
|
Tools.GetRealIP(
|
||||||
|
Convert.ToString(Netplay.serverSock[args.PlayerID].tcpClient.Client.RemoteEndPoint)) +
|
||||||
|
" superadmin");
|
||||||
Tools.SendMessage(args.PlayerID, "SuperAdmin authenticated. Please re-connect using the same IP.");
|
Tools.SendMessage(args.PlayerID, "SuperAdmin authenticated. Please re-connect using the same IP.");
|
||||||
ConfigurationManager.authToken = 0;
|
ConfigurationManager.authToken = 0;
|
||||||
tw.Close();
|
tw.Close();
|
||||||
|
|
@ -347,11 +354,12 @@ namespace TShockAPI
|
||||||
string player = args.Message.Remove(0, 3).Trim();
|
string player = args.Message.Remove(0, 3).Trim();
|
||||||
if (Tools.FindPlayer(player) != -1 && Tools.FindPlayer(player) != -2 && player != "")
|
if (Tools.FindPlayer(player) != -1 && Tools.FindPlayer(player) != -2 && player != "")
|
||||||
{
|
{
|
||||||
TShock.Teleport(ply, Main.player[Tools.FindPlayer(player)].position.X, Main.player[Tools.FindPlayer(player)].position.Y);
|
TShock.Teleport(ply, Main.player[Tools.FindPlayer(player)].position.X,
|
||||||
|
Main.player[Tools.FindPlayer(player)].position.Y);
|
||||||
Tools.SendMessage(ply, "Teleported to " + player);
|
Tools.SendMessage(ply, "Teleported to " + player);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Tools.SendMessage(ply, "Invalid player!", new float[] { 255f, 0f, 0f });
|
Tools.SendMessage(ply, "Invalid player!", new[] {255f, 0f, 0f});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void TPHere(CommandArgs args)
|
public static void TPHere(CommandArgs args)
|
||||||
|
|
@ -365,7 +373,7 @@ namespace TShockAPI
|
||||||
Tools.SendMessage(ply, "You brought " + player + " here.");
|
Tools.SendMessage(ply, "You brought " + player + " here.");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Tools.SendMessage(ply, "Invalid player!", new float[] { 255f, 0f, 0f });
|
Tools.SendMessage(ply, "Invalid player!", new[] {255f, 0f, 0f});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SpawnMob(CommandArgs args)
|
public static void SpawnMob(CommandArgs args)
|
||||||
|
|
@ -391,16 +399,19 @@ namespace TShockAPI
|
||||||
{
|
{
|
||||||
for (int i = 0; i < amount; i++)
|
for (int i = 0; i < amount; i++)
|
||||||
npcid = NPC.NewNPC(x, y, type, 0);
|
npcid = NPC.NewNPC(x, y, type, 0);
|
||||||
Tools.Broadcast(string.Format("{0} was spawned {1} time(s).", Main.npc[npcid].name, amount)); ;
|
Tools.Broadcast(string.Format("{0} was spawned {1} time(s).", Main.npc[npcid].name, amount));
|
||||||
|
;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Tools.SendMessage(args.PlayerID, "Invalid syntax! Proper syntax: /spawnmob <mob name/id> [amount]", new float[] { 255f, 0f, 0f });
|
Tools.SendMessage(args.PlayerID, "Invalid syntax! Proper syntax: /spawnmob <mob name/id> [amount]",
|
||||||
|
new[] {255f, 0f, 0f});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Item(CommandArgs args)
|
public static void Item(CommandArgs args)
|
||||||
{
|
{
|
||||||
var msgargs = Regex.Split(args.Message, "(?<=^[^\"]*(?:\"[^\"]*\"[^\"]*)*) (?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)")[1];
|
var msgargs =
|
||||||
|
Regex.Split(args.Message, "(?<=^[^\"]*(?:\"[^\"]*\"[^\"]*)*) (?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)")[1];
|
||||||
int ply = args.PlayerID;
|
int ply = args.PlayerID;
|
||||||
bool flag = false;
|
bool flag = false;
|
||||||
if (msgargs.Length >= 2)
|
if (msgargs.Length >= 2)
|
||||||
|
|
@ -418,8 +429,8 @@ namespace TShockAPI
|
||||||
//Main.player[ply].inventory[i].SetDefaults(type);
|
//Main.player[ply].inventory[i].SetDefaults(type);
|
||||||
//Main.player[ply].inventory[i].stack = Main.player[ply].inventory[i].maxStack;
|
//Main.player[ply].inventory[i].stack = Main.player[ply].inventory[i].maxStack;
|
||||||
int id = Terraria.Item.NewItem(0, 0, 0, 0, type, 1, true);
|
int id = Terraria.Item.NewItem(0, 0, 0, 0, type, 1, true);
|
||||||
Main.item[id].position.X = (float)args.PlayerX;
|
Main.item[id].position.X = args.PlayerX;
|
||||||
Main.item[id].position.Y = (float)args.PlayerY;
|
Main.item[id].position.Y = args.PlayerY;
|
||||||
Main.item[id].stack = Main.item[id].maxStack;
|
Main.item[id].stack = Main.item[id].maxStack;
|
||||||
//TShock.SendDataAll(21, -1, "", id);
|
//TShock.SendDataAll(21, -1, "", id);
|
||||||
NetMessage.SendData(21, -1, -1, "", id, 0f, 0f, 0f);
|
NetMessage.SendData(21, -1, -1, "", id, 0f, 0f, 0f);
|
||||||
|
|
@ -430,13 +441,14 @@ namespace TShockAPI
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!flag)
|
if (!flag)
|
||||||
Tools.SendMessage(args.PlayerID, "You don't have free slots!", new float[] { 255f, 0f, 0f });
|
Tools.SendMessage(args.PlayerID, "You don't have free slots!", new[] {255f, 0f, 0f});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Tools.SendMessage(args.PlayerID, "Invalid item type!", new float[] { 255f, 0f, 0f });
|
Tools.SendMessage(args.PlayerID, "Invalid item type!", new[] {255f, 0f, 0f});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Tools.SendMessage(args.PlayerID, "Invalid syntax! Proper syntax: /item <item name/id>", new float[] { 255f, 0f, 0f });
|
Tools.SendMessage(args.PlayerID, "Invalid syntax! Proper syntax: /item <item name/id>",
|
||||||
|
new[] {255f, 0f, 0f});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Give(CommandArgs args)
|
public static void Give(CommandArgs args)
|
||||||
|
|
@ -469,24 +481,28 @@ namespace TShockAPI
|
||||||
Main.item[id].stack = Main.item[id].maxStack;
|
Main.item[id].stack = Main.item[id].maxStack;
|
||||||
//TShock.SendDataAll(21, -1, "", id);
|
//TShock.SendDataAll(21, -1, "", id);
|
||||||
NetMessage.SendData(21, -1, -1, "", id, 0f, 0f, 0f);
|
NetMessage.SendData(21, -1, -1, "", id, 0f, 0f, 0f);
|
||||||
Tools.SendMessage(ply, string.Format("Gave {0} some {1}.", msgargs[2], Main.item[id].name));
|
Tools.SendMessage(ply,
|
||||||
Tools.SendMessage(player, string.Format("{0} gave you some {1}.", Tools.FindPlayer(ply), Main.item[id].name));
|
string.Format("Gave {0} some {1}.", msgargs[2], Main.item[id].name));
|
||||||
|
Tools.SendMessage(player,
|
||||||
|
string.Format("{0} gave you some {1}.", Tools.FindPlayer(ply),
|
||||||
|
Main.item[id].name));
|
||||||
//TShock.UpdateInventories();
|
//TShock.UpdateInventories();
|
||||||
flag = true;
|
flag = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!flag)
|
if (!flag)
|
||||||
Tools.SendMessage(args.PlayerID, "Player does not have free slots!", new float[] { 255f, 0f, 0f });
|
Tools.SendMessage(args.PlayerID, "Player does not have free slots!", new[] {255f, 0f, 0f});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Tools.SendMessage(args.PlayerID, "Invalid player!", new float[] { 255f, 0f, 0f });
|
Tools.SendMessage(args.PlayerID, "Invalid player!", new[] {255f, 0f, 0f});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Tools.SendMessage(args.PlayerID, "Invalid item type!", new float[] { 255f, 0f, 0f });
|
Tools.SendMessage(args.PlayerID, "Invalid item type!", new[] {255f, 0f, 0f});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Tools.SendMessage(args.PlayerID, "Invalid syntax! Proper syntax: /give <item type/id> <player>", new float[] { 255f, 0f, 0f });
|
Tools.SendMessage(args.PlayerID, "Invalid syntax! Proper syntax: /give <item type/id> <player>",
|
||||||
|
new[] {255f, 0f, 0f});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Heal(CommandArgs args)
|
public static void Heal(CommandArgs args)
|
||||||
|
|
@ -502,16 +518,16 @@ namespace TShockAPI
|
||||||
{
|
{
|
||||||
Tools.SendMessage(ply, string.Format("You just healed {0}", (msgargs[1].TrimEnd('"')).TrimStart('"')));
|
Tools.SendMessage(ply, string.Format("You just healed {0}", (msgargs[1].TrimEnd('"')).TrimStart('"')));
|
||||||
Tools.SendMessage(player, string.Format("{0} just healed you!", Tools.FindPlayer(ply)));
|
Tools.SendMessage(player, string.Format("{0} just healed you!", Tools.FindPlayer(ply)));
|
||||||
x = (int)Main.player[player].position.X;
|
x = (int) Main.player[player].position.X;
|
||||||
y = (int)Main.player[player].position.Y;
|
y = (int) Main.player[player].position.Y;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Tools.SendMessage(ply, "You just got healed!");
|
Tools.SendMessage(ply, "You just got healed!");
|
||||||
for (int i = 0; i < 20; i++)
|
for (int i = 0; i < 20; i++)
|
||||||
{
|
{
|
||||||
int itemid = Terraria.Item.NewItem(1, 1, 1, 1, 58);
|
int itemid = Terraria.Item.NewItem(1, 1, 1, 1, 58);
|
||||||
Main.item[itemid].position.X = (float)x;
|
Main.item[itemid].position.X = x;
|
||||||
Main.item[itemid].position.Y = (float)y;
|
Main.item[itemid].position.Y = y;
|
||||||
NetMessage.SendData(21, -1, -1, "", itemid, 0f, 0f, 0f);
|
NetMessage.SendData(21, -1, -1, "", itemid, 0f, 0f, 0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -526,11 +542,11 @@ namespace TShockAPI
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Main.npc[i].StrikeNPC(99999, 90f, 1);
|
Main.npc[i].StrikeNPC(99999, 90f, 1);
|
||||||
NetMessage.SendData(28, -1, -1, "", i, (float)99999, 90f, 1);
|
NetMessage.SendData(28, -1, -1, "", i, 99999, 90f, 1);
|
||||||
killcount++;
|
killcount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Tools.Broadcast("Killed " + killcount.ToString() + " NPCs.");
|
Tools.Broadcast("Killed " + killcount + " NPCs.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void MaxSpawns(CommandArgs args)
|
public static void MaxSpawns(CommandArgs args)
|
||||||
|
|
@ -569,19 +585,19 @@ namespace TShockAPI
|
||||||
cmdlist.Add(commands[j]);
|
cmdlist.Add(commands[j]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (cmdlist.Count > (15 * (page - 1)))
|
if (cmdlist.Count > (15*(page - 1)))
|
||||||
{
|
{
|
||||||
for (int j = (15 * (page - 1)); j < cmdlist.Count; j++)
|
for (int j = (15*(page - 1)); j < cmdlist.Count; j++)
|
||||||
{
|
{
|
||||||
if (i == 3) break;
|
if (i == 3) break;
|
||||||
if (j == cmdlist.Count - 1)
|
if (j == cmdlist.Count - 1)
|
||||||
{
|
{
|
||||||
tempstring += "/" + cmdlist[j].Name() + ", ";
|
tempstring += "/" + cmdlist[j].Name() + ", ";
|
||||||
Tools.SendMessage(ply, tempstring.TrimEnd(new char[] { ' ', ',' }), new float[] { 255f, 255f, 0f });
|
Tools.SendMessage(ply, tempstring.TrimEnd(new[] {' ', ','}), new[] {255f, 255f, 0f});
|
||||||
}
|
}
|
||||||
if ((h - 1) % 5 == 0 && (h - 1) != 0)
|
if ((h - 1)%5 == 0 && (h - 1) != 0)
|
||||||
{
|
{
|
||||||
Tools.SendMessage(ply, tempstring.TrimEnd(new char[] { ' ', ',' }), new float[] { 255f, 255f, 0f });
|
Tools.SendMessage(ply, tempstring.TrimEnd(new[] {' ', ','}), new[] {255f, 255f, 0f});
|
||||||
tempstring = "/" + cmdlist[j].Name() + ", ";
|
tempstring = "/" + cmdlist[j].Name() + ", ";
|
||||||
i++;
|
i++;
|
||||||
h++;
|
h++;
|
||||||
|
|
@ -593,10 +609,12 @@ namespace TShockAPI
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (cmdlist.Count > (15 * page))
|
if (cmdlist.Count > (15*page))
|
||||||
{ Tools.SendMessage(ply, "Type /help " + (page + 1).ToString() + " for more commands.", new float[] { 255f, 0f, 255f }); }
|
{
|
||||||
|
Tools.SendMessage(ply, "Type /help " + (page + 1) + " for more commands.", new[] {255f, 0f, 255f});
|
||||||
|
}
|
||||||
Tools.SendMessage(ply, "Terraria commands:");
|
Tools.SendMessage(ply, "Terraria commands:");
|
||||||
Tools.SendMessage(ply, "/playing, /p, /me", new float[] { 255f, 255f, 0f });
|
Tools.SendMessage(ply, "/playing, /p, /me", new[] {255f, 255f, 0f});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Time(CommandArgs args)
|
public static void Time(CommandArgs args)
|
||||||
|
|
@ -621,10 +639,12 @@ namespace TShockAPI
|
||||||
Tools.Broadcast(Tools.FindPlayer(args.PlayerID) + " set time to night.");
|
Tools.Broadcast(Tools.FindPlayer(args.PlayerID) + " set time to night.");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Tools.SendMessage(args.PlayerID, "Invalid syntax! Proper syntax: /time <day/night>", new float[] { 255f, 0f, 0f });
|
Tools.SendMessage(args.PlayerID, "Invalid syntax! Proper syntax: /time <day/night>",
|
||||||
|
new[] {255f, 0f, 0f});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Tools.SendMessage(args.PlayerID, "Invalid syntax! Proper syntax: /time <day/night>", new float[] { 255f, 0f, 0f });
|
Tools.SendMessage(args.PlayerID, "Invalid syntax! Proper syntax: /time <day/night>",
|
||||||
|
new[] {255f, 0f, 0f});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Kill(CommandArgs args)
|
public static void Kill(CommandArgs args)
|
||||||
|
|
@ -646,16 +666,18 @@ namespace TShockAPI
|
||||||
for (int i = 0; i < msgargs.Length; i++)
|
for (int i = 0; i < msgargs.Length; i++)
|
||||||
msgargs[i] = (msgargs[i].TrimStart('"')).TrimEnd('"');
|
msgargs[i] = (msgargs[i].TrimStart('"')).TrimEnd('"');
|
||||||
if (msgargs.Length == 1)
|
if (msgargs.Length == 1)
|
||||||
Tools.SendMessage(args.PlayerID, "Invalid syntax! Proper syntax: /slap <player> [dmg]", new float[] { 255f, 0f, 0f });
|
Tools.SendMessage(args.PlayerID, "Invalid syntax! Proper syntax: /slap <player> [dmg]",
|
||||||
|
new[] {255f, 0f, 0f});
|
||||||
else if (msgargs.Length == 2)
|
else if (msgargs.Length == 2)
|
||||||
{
|
{
|
||||||
int player = Tools.FindPlayer(msgargs[1]);
|
int player = Tools.FindPlayer(msgargs[1]);
|
||||||
if (player == -1)
|
if (player == -1)
|
||||||
Tools.SendMessage(args.PlayerID, "Invalid player!", new float[] { 255f, 0f, 0f });
|
Tools.SendMessage(args.PlayerID, "Invalid player!", new[] {255f, 0f, 0f});
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
NetMessage.SendData(26, -1, -1, "", player, (float)((new Random()).Next(1, 20)), (float)5, (float)0);
|
NetMessage.SendData(26, -1, -1, "", player, ((new Random()).Next(1, 20)), 5, (float) 0);
|
||||||
Tools.Broadcast(Tools.FindPlayer(args.PlayerID) + " slapped " + Tools.FindPlayer(player) + " for 5 damage.");
|
Tools.Broadcast(Tools.FindPlayer(args.PlayerID) + " slapped " + Tools.FindPlayer(player) +
|
||||||
|
" for 5 damage.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (msgargs.Length == 3)
|
else if (msgargs.Length == 3)
|
||||||
|
|
@ -664,21 +686,24 @@ namespace TShockAPI
|
||||||
int damage = 5;
|
int damage = 5;
|
||||||
int.TryParse(msgargs[2], out damage);
|
int.TryParse(msgargs[2], out damage);
|
||||||
if (player == -1)
|
if (player == -1)
|
||||||
Tools.SendMessage(args.PlayerID, "Invalid player!", new float[] { 255f, 0f, 0f });
|
Tools.SendMessage(args.PlayerID, "Invalid player!", new[] {255f, 0f, 0f});
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
NetMessage.SendData(26, -1, -1, "", player, (float)((new Random()).Next(-1, 1)), (float)damage, (float)0);
|
NetMessage.SendData(26, -1, -1, "", player, ((new Random()).Next(-1, 1)), damage, (float) 0);
|
||||||
Tools.Broadcast(Tools.FindPlayer(args.PlayerID) + " slapped " + Tools.FindPlayer(player) + " for " + damage.ToString() + " damage.");
|
Tools.Broadcast(Tools.FindPlayer(args.PlayerID) + " slapped " + Tools.FindPlayer(player) + " for " +
|
||||||
|
damage + " damage.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Tools.SendMessage(args.PlayerID, "Invalid syntax! Proper syntax: /slap <player> [dmg]", new float[] { 255f, 0f, 0f });
|
Tools.SendMessage(args.PlayerID, "Invalid syntax! Proper syntax: /slap <player> [dmg]",
|
||||||
|
new[] {255f, 0f, 0f});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ProtectSpawn(CommandArgs args)
|
public static void ProtectSpawn(CommandArgs args)
|
||||||
{
|
{
|
||||||
ConfigurationManager.spawnProtect = (ConfigurationManager.spawnProtect == false);
|
ConfigurationManager.spawnProtect = (ConfigurationManager.spawnProtect == false);
|
||||||
Tools.SendMessage(args.PlayerID, "Spawn is now " + (ConfigurationManager.spawnProtect ? "protected" : "open") + ".");
|
Tools.SendMessage(args.PlayerID,
|
||||||
|
"Spawn is now " + (ConfigurationManager.spawnProtect ? "protected" : "open") + ".");
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion Command Methods
|
#endregion Command Methods
|
||||||
|
|
|
||||||
|
|
@ -1,27 +1,20 @@
|
||||||
using System;
|
namespace TShockAPI
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace TShockAPI
|
|
||||||
{
|
{
|
||||||
class ConfigFile
|
internal class ConfigFile
|
||||||
{
|
{
|
||||||
public ConfigFile() { }
|
|
||||||
|
|
||||||
public int InvasionMultiplier = 1;
|
public int InvasionMultiplier = 1;
|
||||||
public int DefaultMaximumSpawns = 4;
|
public int DefaultMaximumSpawns = 4;
|
||||||
public int DefaultSpawnRate = 700;
|
public int DefaultSpawnRate = 700;
|
||||||
public int ServerPort = 7777;
|
public int ServerPort = 7777;
|
||||||
public bool EnableWhitelist = false;
|
public bool EnableWhitelist;
|
||||||
public bool InfiniteInvasion = false;
|
public bool InfiniteInvasion;
|
||||||
public bool AlwaysPvP = false;
|
public bool AlwaysPvP;
|
||||||
public bool KickCheaters = true;
|
public bool KickCheaters = true;
|
||||||
public bool BanCheaters = true;
|
public bool BanCheaters = true;
|
||||||
public bool KickGriefers = true;
|
public bool KickGriefers = true;
|
||||||
public bool BanGriefers = true;
|
public bool BanGriefers = true;
|
||||||
public bool BanKillTileAbusers = false;
|
public bool BanKillTileAbusers;
|
||||||
public bool KickKillTileAbusers = false;
|
public bool KickKillTileAbusers;
|
||||||
public bool BanExplosives = true;
|
public bool BanExplosives = true;
|
||||||
public bool KickExplosives = true;
|
public bool KickExplosives = true;
|
||||||
public bool SpawnProtection = true;
|
public bool SpawnProtection = true;
|
||||||
|
|
|
||||||
|
|
@ -1,41 +1,38 @@
|
||||||
using System;
|
using System.IO;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using Terraria;
|
||||||
|
|
||||||
namespace TShockAPI
|
namespace TShockAPI
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provides all the stupid little variables a home away from home.
|
/// Provides all the stupid little variables a home away from home.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
class ConfigurationManager
|
internal class ConfigurationManager
|
||||||
{
|
{
|
||||||
public static int invasionMultiplier = 1;
|
public static int invasionMultiplier = 1;
|
||||||
public static int defaultMaxSpawns = 4;
|
public static int defaultMaxSpawns = 4;
|
||||||
public static int defaultSpawnRate = 700;
|
public static int defaultSpawnRate = 700;
|
||||||
public static int serverPort = 7777;
|
public static int serverPort = 7777;
|
||||||
public static bool enableWhitelist = false;
|
public static bool enableWhitelist;
|
||||||
public static bool infiniteInvasion = false;
|
public static bool infiniteInvasion;
|
||||||
public static bool permaPvp = false;
|
public static bool permaPvp;
|
||||||
public static int killCount = 0;
|
public static int killCount;
|
||||||
public static bool startedInvasion = false;
|
public static bool startedInvasion;
|
||||||
public static bool kickCheater = true;
|
public static bool kickCheater = true;
|
||||||
public static bool banCheater = true;
|
public static bool banCheater = true;
|
||||||
public static bool kickGriefer = true;
|
public static bool kickGriefer = true;
|
||||||
public static bool banGriefer = true;
|
public static bool banGriefer = true;
|
||||||
public static bool banTnt = false;
|
public static bool banTnt;
|
||||||
public static bool kickTnt = false;
|
public static bool kickTnt;
|
||||||
public static bool banBoom = true;
|
public static bool banBoom = true;
|
||||||
public static bool kickBoom = true;
|
public static bool kickBoom = true;
|
||||||
public static bool spawnProtect = true;
|
public static bool spawnProtect = true;
|
||||||
public static int spawnProtectRadius = 5;
|
public static int spawnProtectRadius = 5;
|
||||||
public static string distributationAgent = "facepunch";
|
public static string distributationAgent = "facepunch";
|
||||||
public static int authToken = 0;
|
public static int authToken;
|
||||||
public static int maxSlots = 8;
|
public static int maxSlots = 8;
|
||||||
|
|
||||||
public enum NPCList : int
|
public enum NPCList
|
||||||
{
|
{
|
||||||
WORLD_EATER = 0,
|
WORLD_EATER = 0,
|
||||||
EYE = 1,
|
EYE = 1,
|
||||||
|
|
@ -67,17 +64,17 @@ namespace TShockAPI
|
||||||
spawnProtectRadius = cfg.SpawnProtectionRadius;
|
spawnProtectRadius = cfg.SpawnProtectionRadius;
|
||||||
distributationAgent = cfg.DistributationAgent;
|
distributationAgent = cfg.DistributationAgent;
|
||||||
maxSlots = cfg.MaxSlots;
|
maxSlots = cfg.MaxSlots;
|
||||||
Terraria.NPC.maxSpawns = defaultMaxSpawns;
|
NPC.maxSpawns = defaultMaxSpawns;
|
||||||
Terraria.NPC.defaultSpawnRate = defaultSpawnRate;
|
NPC.defaultSpawnRate = defaultSpawnRate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void WriteJsonConfiguration()
|
public static void WriteJsonConfiguration()
|
||||||
{
|
{
|
||||||
if (!System.IO.Directory.Exists(FileTools.SaveDir))
|
if (!Directory.Exists(FileTools.SaveDir))
|
||||||
{
|
{
|
||||||
System.IO.Directory.CreateDirectory(FileTools.SaveDir);
|
Directory.CreateDirectory(FileTools.SaveDir);
|
||||||
}
|
}
|
||||||
if (System.IO.File.Exists(FileTools.SaveDir + "config.json"))
|
if (File.Exists(FileTools.SaveDir + "config.json"))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,17 @@
|
||||||
using System;
|
using System.IO;
|
||||||
using System.IO;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using System.Web;
|
|
||||||
using Terraria;
|
using Terraria;
|
||||||
|
|
||||||
namespace TShockAPI
|
namespace TShockAPI
|
||||||
{
|
{
|
||||||
class FileTools
|
internal class FileTools
|
||||||
{
|
{
|
||||||
public static string SaveDir = "./tshock/";
|
public static string SaveDir = "./tshock/";
|
||||||
|
|
||||||
public static void CreateFile(string file)
|
public static void CreateFile(string file)
|
||||||
{
|
{
|
||||||
using (FileStream fs = File.Create(file)) { }
|
using (FileStream fs = File.Create(file))
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -21,7 +20,7 @@ namespace TShockAPI
|
||||||
/// <param name="err">string message</param>
|
/// <param name="err">string message</param>
|
||||||
public static void WriteError(string err)
|
public static void WriteError(string err)
|
||||||
{
|
{
|
||||||
if (System.IO.File.Exists(SaveDir + "errors.txt"))
|
if (File.Exists(SaveDir + "errors.txt"))
|
||||||
{
|
{
|
||||||
TextWriter tw = new StreamWriter(SaveDir + "errors.txt", true);
|
TextWriter tw = new StreamWriter(SaveDir + "errors.txt", true);
|
||||||
tw.WriteLine(err);
|
tw.WriteLine(err);
|
||||||
|
|
@ -29,7 +28,7 @@ namespace TShockAPI
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
FileTools.CreateFile(SaveDir + "errors.txt");
|
CreateFile(SaveDir + "errors.txt");
|
||||||
TextWriter tw = new StreamWriter(SaveDir + "errors.txt", true);
|
TextWriter tw = new StreamWriter(SaveDir + "errors.txt", true);
|
||||||
tw.WriteLine(err);
|
tw.WriteLine(err);
|
||||||
tw.Close();
|
tw.Close();
|
||||||
|
|
@ -41,30 +40,45 @@ namespace TShockAPI
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static void SetupConfig()
|
public static void SetupConfig()
|
||||||
{
|
{
|
||||||
if (!System.IO.Directory.Exists(SaveDir)) { System.IO.Directory.CreateDirectory(SaveDir); }
|
if (!Directory.Exists(SaveDir))
|
||||||
if (!System.IO.File.Exists(SaveDir + "motd.txt"))
|
|
||||||
{
|
{
|
||||||
FileTools.CreateFile(SaveDir + "motd.txt");
|
Directory.CreateDirectory(SaveDir);
|
||||||
|
}
|
||||||
|
if (!File.Exists(SaveDir + "motd.txt"))
|
||||||
|
{
|
||||||
|
CreateFile(SaveDir + "motd.txt");
|
||||||
TextWriter tw = new StreamWriter(SaveDir + "motd.txt");
|
TextWriter tw = new StreamWriter(SaveDir + "motd.txt");
|
||||||
tw.WriteLine("This server is running TShock. Type /help for a list of commands.");
|
tw.WriteLine("This server is running TShock. Type /help for a list of commands.");
|
||||||
tw.WriteLine("%255,000,000%Current map: %map%");
|
tw.WriteLine("%255,000,000%Current map: %map%");
|
||||||
tw.WriteLine("Current players: %players%");
|
tw.WriteLine("Current players: %players%");
|
||||||
tw.Close();
|
tw.Close();
|
||||||
}
|
}
|
||||||
if (!System.IO.File.Exists(SaveDir + "bans.txt")) { FileTools.CreateFile(SaveDir + "bans.txt"); }
|
if (!File.Exists(SaveDir + "bans.txt"))
|
||||||
if (!System.IO.File.Exists(SaveDir + "cheaters.txt")) { FileTools.CreateFile(SaveDir + "cheaters.txt"); }
|
|
||||||
if (!System.IO.File.Exists(SaveDir + "grief.txt")) { FileTools.CreateFile(SaveDir + "grief.txt"); }
|
|
||||||
if (!System.IO.File.Exists(SaveDir + "whitelist.txt")) { FileTools.CreateFile(SaveDir + "whitelist.txt"); }
|
|
||||||
if (!System.IO.File.Exists(SaveDir + "groups.txt"))
|
|
||||||
{
|
{
|
||||||
FileTools.CreateFile(SaveDir + "groups.txt");
|
CreateFile(SaveDir + "bans.txt");
|
||||||
|
}
|
||||||
|
if (!File.Exists(SaveDir + "cheaters.txt"))
|
||||||
|
{
|
||||||
|
CreateFile(SaveDir + "cheaters.txt");
|
||||||
|
}
|
||||||
|
if (!File.Exists(SaveDir + "grief.txt"))
|
||||||
|
{
|
||||||
|
CreateFile(SaveDir + "grief.txt");
|
||||||
|
}
|
||||||
|
if (!File.Exists(SaveDir + "whitelist.txt"))
|
||||||
|
{
|
||||||
|
CreateFile(SaveDir + "whitelist.txt");
|
||||||
|
}
|
||||||
|
if (!File.Exists(SaveDir + "groups.txt"))
|
||||||
|
{
|
||||||
|
CreateFile(SaveDir + "groups.txt");
|
||||||
StreamWriter sw = new StreamWriter(SaveDir + "groups.txt");
|
StreamWriter sw = new StreamWriter(SaveDir + "groups.txt");
|
||||||
sw.Write(Resources.groups);
|
sw.Write(Resources.groups);
|
||||||
sw.Close();
|
sw.Close();
|
||||||
}
|
}
|
||||||
if (!System.IO.File.Exists(SaveDir + "users.txt"))
|
if (!File.Exists(SaveDir + "users.txt"))
|
||||||
{
|
{
|
||||||
FileTools.CreateFile(SaveDir + "users.txt");
|
CreateFile(SaveDir + "users.txt");
|
||||||
StreamWriter sw = new StreamWriter(SaveDir + "users.txt");
|
StreamWriter sw = new StreamWriter(SaveDir + "users.txt");
|
||||||
sw.Write(Resources.users);
|
sw.Write(Resources.users);
|
||||||
sw.Close();
|
sw.Close();
|
||||||
|
|
@ -81,14 +95,21 @@ namespace TShockAPI
|
||||||
/// <returns>true/false</returns>
|
/// <returns>true/false</returns>
|
||||||
public static bool OnWhitelist(string ip)
|
public static bool OnWhitelist(string ip)
|
||||||
{
|
{
|
||||||
if (!ConfigurationManager.enableWhitelist) { return true; }
|
if (!ConfigurationManager.enableWhitelist)
|
||||||
if (!System.IO.File.Exists(SaveDir + "whitelist.txt")) { FileTools.CreateFile(SaveDir + "whitelist.txt"); TextWriter tw = new StreamWriter(SaveDir + "whitelist.txt"); tw.WriteLine("127.0.0.1"); tw.Close(); }
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!File.Exists(SaveDir + "whitelist.txt"))
|
||||||
|
{
|
||||||
|
CreateFile(SaveDir + "whitelist.txt");
|
||||||
|
TextWriter tw = new StreamWriter(SaveDir + "whitelist.txt");
|
||||||
|
tw.WriteLine("127.0.0.1");
|
||||||
|
tw.Close();
|
||||||
|
}
|
||||||
TextReader tr = new StreamReader(SaveDir + "whitelist.txt");
|
TextReader tr = new StreamReader(SaveDir + "whitelist.txt");
|
||||||
string whitelist = tr.ReadToEnd();
|
string whitelist = tr.ReadToEnd();
|
||||||
ip = Tools.GetRealIP(ip);
|
ip = Tools.GetRealIP(ip);
|
||||||
return whitelist.Contains(ip);
|
return whitelist.Contains(ip);
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileTools() { }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,14 +1,12 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace TShockAPI
|
namespace TShockAPI
|
||||||
{
|
{
|
||||||
public class Group
|
public class Group
|
||||||
{
|
{
|
||||||
private string name;
|
private string name;
|
||||||
private Group parent = null;
|
private Group parent;
|
||||||
private List<string> permissions = new List<string>();
|
private List<string> permissions = new List<string>();
|
||||||
private List<string> negatedPermissions = new List<string>();
|
private List<string> negatedPermissions = new List<string>();
|
||||||
|
|
||||||
|
|
@ -20,7 +18,7 @@ namespace TShockAPI
|
||||||
|
|
||||||
public Group()
|
public Group()
|
||||||
{
|
{
|
||||||
throw new System.Exception("Called Group constructor with no parameters");
|
throw new Exception("Called Group constructor with no parameters");
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetName()
|
public string GetName()
|
||||||
|
|
@ -72,7 +70,7 @@ namespace TShockAPI
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public SuperAdminGroup() : base()
|
public SuperAdminGroup()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Linq;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
|
||||||
using System.Threading;
|
|
||||||
|
|
||||||
namespace TShockAPI
|
namespace TShockAPI
|
||||||
{
|
{
|
||||||
|
|
@ -82,7 +78,8 @@ namespace TShockAPI
|
||||||
_logWriter = new StreamWriter(_filename + "." + Process.GetCurrentProcess().Id.ToString(), true);
|
_logWriter = new StreamWriter(_filename + "." + Process.GetCurrentProcess().Id.ToString(), true);
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
String text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture) + " - " + caller + message;
|
String text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture) + " - " + caller +
|
||||||
|
message;
|
||||||
|
|
||||||
Console.WriteLine(text);
|
Console.WriteLine(text);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
// General Information about an assembly is controlled through the following
|
// General Information about an assembly is controlled through the following
|
||||||
// set of attributes. Change these attribute values to modify the information
|
// set of attributes. Change these attribute values to modify the information
|
||||||
// associated with an assembly.
|
// associated with an assembly.
|
||||||
|
|
||||||
[assembly: AssemblyTitle("TShockAPI")]
|
[assembly: AssemblyTitle("TShockAPI")]
|
||||||
[assembly: AssemblyDescription("")]
|
[assembly: AssemblyDescription("")]
|
||||||
[assembly: AssemblyConfiguration("")]
|
[assembly: AssemblyConfiguration("")]
|
||||||
|
|
@ -17,9 +17,11 @@ using System.Runtime.InteropServices;
|
||||||
// Setting ComVisible to false makes the types in this assembly not visible
|
// Setting ComVisible to false makes the types in this assembly not visible
|
||||||
// to COM components. If you need to access a type in this assembly from
|
// to COM components. If you need to access a type in this assembly from
|
||||||
// COM, set the ComVisible attribute to true on that type.
|
// COM, set the ComVisible attribute to true on that type.
|
||||||
|
|
||||||
[assembly: ComVisible(false)]
|
[assembly: ComVisible(false)]
|
||||||
|
|
||||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||||
|
|
||||||
[assembly: Guid("01e38989-993c-410c-9011-487f824a606d")]
|
[assembly: Guid("01e38989-993c-410c-9011-487f824a606d")]
|
||||||
|
|
||||||
// Version information for an assembly consists of the following four values:
|
// Version information for an assembly consists of the following four values:
|
||||||
|
|
@ -32,5 +34,6 @@ using System.Runtime.InteropServices;
|
||||||
// You can specify all the values or you can default the Build and Revision Numbers
|
// You can specify all the values or you can default the Build and Revision Numbers
|
||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
|
|
||||||
[assembly: AssemblyVersion("1.0.0.0")]
|
[assembly: AssemblyVersion("1.0.0.0")]
|
||||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||||
|
|
@ -1,16 +1,14 @@
|
||||||
using System;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
using Terraria;
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace TShockAPI
|
namespace TShockAPI
|
||||||
{
|
{
|
||||||
public class TSPlayer
|
public class TSPlayer
|
||||||
{
|
{
|
||||||
public uint tileThreshold;
|
public uint tileThreshold;
|
||||||
public Dictionary<TShock.Position, Terraria.Tile> tilesDestroyed = new Dictionary<TShock.Position, Terraria.Tile>();
|
public Dictionary<TShock.Position, Tile> tilesDestroyed = new Dictionary<TShock.Position, Tile>();
|
||||||
public bool syncHP = false;
|
public bool syncHP;
|
||||||
public bool syncMP = false;
|
public bool syncMP;
|
||||||
public Group group;
|
public Group group;
|
||||||
|
|
||||||
private int player;
|
private int player;
|
||||||
|
|
@ -20,9 +18,9 @@ namespace TShockAPI
|
||||||
player = ply;
|
player = ply;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Terraria.Player GetPlayer()
|
public Player GetPlayer()
|
||||||
{
|
{
|
||||||
return Terraria.Main.player[player];
|
return Main.player[player];
|
||||||
}
|
}
|
||||||
|
|
||||||
public int GetPlayerID()
|
public int GetPlayerID()
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ using Terraria;
|
||||||
|
|
||||||
namespace TShockAPI
|
namespace TShockAPI
|
||||||
{
|
{
|
||||||
class Tools
|
internal class Tools
|
||||||
{
|
{
|
||||||
private static List<Group> groups = new List<Group>();
|
private static List<Group> groups = new List<Group>();
|
||||||
|
|
||||||
|
|
@ -62,7 +62,7 @@ namespace TShockAPI
|
||||||
/// <param name="min">Minimum bounds of the clamp</param>
|
/// <param name="min">Minimum bounds of the clamp</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static T Clamp<T>(T value, T max, T min)
|
public static T Clamp<T>(T value, T max, T min)
|
||||||
where T : System.IComparable<T>
|
where T : IComparable<T>
|
||||||
{
|
{
|
||||||
T result = value;
|
T result = value;
|
||||||
if (value.CompareTo(max) > 0)
|
if (value.CompareTo(max) > 0)
|
||||||
|
|
@ -216,7 +216,7 @@ namespace TShockAPI
|
||||||
public static void Kick(int ply, string reason)
|
public static void Kick(int ply, string reason)
|
||||||
{
|
{
|
||||||
NetMessage.SendData(0x2, ply, -1, reason, 0x0, 0f, 0f, 0f);
|
NetMessage.SendData(0x2, ply, -1, reason, 0x0, 0f, 0f, 0f);
|
||||||
Log.Info("Kicked " + Tools.FindPlayer(ply) + " for : " + reason);
|
Log.Info("Kicked " + FindPlayer(ply) + " for : " + reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -230,22 +230,22 @@ namespace TShockAPI
|
||||||
while ((foo = tr.ReadLine()) != null)
|
while ((foo = tr.ReadLine()) != null)
|
||||||
{
|
{
|
||||||
foo = foo.Replace("%map%", Main.worldName);
|
foo = foo.Replace("%map%", Main.worldName);
|
||||||
foo = foo.Replace("%players%", Tools.GetPlayers());
|
foo = foo.Replace("%players%", GetPlayers());
|
||||||
if (foo.Substring(0, 1) == "%" && foo.Substring(12, 1) == "%") //Look for a beginning color code.
|
if (foo.Substring(0, 1) == "%" && foo.Substring(12, 1) == "%") //Look for a beginning color code.
|
||||||
{
|
{
|
||||||
string possibleColor = foo.Substring(0, 13);
|
string possibleColor = foo.Substring(0, 13);
|
||||||
foo = foo.Remove(0, 13);
|
foo = foo.Remove(0, 13);
|
||||||
float[] pC = { 0, 0, 0 };
|
float[] pC = {0, 0, 0};
|
||||||
possibleColor = possibleColor.Replace("%", "");
|
possibleColor = possibleColor.Replace("%", "");
|
||||||
string[] pCc = possibleColor.Split(',');
|
string[] pCc = possibleColor.Split(',');
|
||||||
if (pCc.Length == 3)
|
if (pCc.Length == 3)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
pC[0] = Tools.Clamp(Convert.ToInt32(pCc[0]), 255, 0);
|
pC[0] = Clamp(Convert.ToInt32(pCc[0]), 255, 0);
|
||||||
pC[1] = Tools.Clamp(Convert.ToInt32(pCc[1]), 255, 0);
|
pC[1] = Clamp(Convert.ToInt32(pCc[1]), 255, 0);
|
||||||
pC[2] = Tools.Clamp(Convert.ToInt32(pCc[2]), 255, 0);
|
pC[2] = Clamp(Convert.ToInt32(pCc[2]), 255, 0);
|
||||||
Tools.SendMessage(ply, foo, pC);
|
SendMessage(ply, foo, pC);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
|
@ -254,7 +254,7 @@ namespace TShockAPI
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Tools.SendMessage(ply, foo);
|
SendMessage(ply, foo);
|
||||||
}
|
}
|
||||||
tr.Close();
|
tr.Close();
|
||||||
}
|
}
|
||||||
|
|
@ -300,7 +300,7 @@ namespace TShockAPI
|
||||||
}
|
}
|
||||||
if (group == null)
|
if (group == null)
|
||||||
{
|
{
|
||||||
throw new System.Exception("Something in the groups.txt is fucked up");
|
throw new Exception("Something in the groups.txt is fucked up");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -383,8 +383,5 @@ namespace TShockAPI
|
||||||
sr.Close();
|
sr.Close();
|
||||||
return GetGroup("default");
|
return GetGroup("default");
|
||||||
}
|
}
|
||||||
|
|
||||||
public Tools() { }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue