Replaced the 3 ban files with a simple ban manager which stores ip, name and reason.
This commit is contained in:
parent
6c9d9873f0
commit
1caf69998d
5 changed files with 262 additions and 265 deletions
121
TShockAPI/BanManager.cs
Normal file
121
TShockAPI/BanManager.cs
Normal file
|
|
@ -0,0 +1,121 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace TShockAPI
|
||||||
|
{
|
||||||
|
public class BanManager
|
||||||
|
{
|
||||||
|
DateTime LastLoad;
|
||||||
|
string Path;
|
||||||
|
/// <summary>
|
||||||
|
/// IP - Name - Reason
|
||||||
|
/// </summary>
|
||||||
|
List<Ban> Bans = new List<Ban>();
|
||||||
|
|
||||||
|
public BanManager(string path)
|
||||||
|
{
|
||||||
|
Path = path;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Ban GetBanByIp(string ip)
|
||||||
|
{
|
||||||
|
EnsureChanges();
|
||||||
|
foreach (var ban in Bans)
|
||||||
|
{
|
||||||
|
if (ban.IP.Equals(ip))
|
||||||
|
return ban;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Ban GetBanByName(string name, bool casesensitive = true)
|
||||||
|
{
|
||||||
|
EnsureChanges();
|
||||||
|
foreach (var ban in Bans)
|
||||||
|
{
|
||||||
|
if (ban.Name.Equals(name, casesensitive ? StringComparison.Ordinal : StringComparison.InvariantCultureIgnoreCase))
|
||||||
|
return ban;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddBan(string ip, string name = "", string reason = "")
|
||||||
|
{
|
||||||
|
Bans.Add(new Ban(ip, name, reason));
|
||||||
|
SaveBans();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reloads the file if it was changed
|
||||||
|
/// </summary>
|
||||||
|
public void EnsureChanges()
|
||||||
|
{
|
||||||
|
if (new FileInfo(Path).LastWriteTime > LastLoad)
|
||||||
|
LoadBans();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Removes | from the string
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="str"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public string MakeSafe(string str)
|
||||||
|
{
|
||||||
|
return str.Replace("|", " ");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LoadBans()
|
||||||
|
{
|
||||||
|
if (!File.Exists(Path))
|
||||||
|
return;
|
||||||
|
|
||||||
|
Bans.Clear();
|
||||||
|
LastLoad = new FileInfo(Path).LastWriteTime;
|
||||||
|
|
||||||
|
foreach (var line in File.ReadAllLines(Path))
|
||||||
|
{
|
||||||
|
var bansp = line.Split('|');
|
||||||
|
if (bansp.Length != 3)
|
||||||
|
continue;
|
||||||
|
Bans.Add(new Ban(bansp[0], bansp[1], bansp[2]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SaveBans()
|
||||||
|
{
|
||||||
|
var output = new StringBuilder();
|
||||||
|
foreach (var ban in Bans)
|
||||||
|
{
|
||||||
|
output.AppendFormat("{0}|{1}|{2}\r\n", MakeSafe(ban.IP), MakeSafe(ban.Name), MakeSafe(ban.Reason));
|
||||||
|
}
|
||||||
|
|
||||||
|
File.WriteAllText(Path, output.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Ban
|
||||||
|
{
|
||||||
|
public string IP { get; set; }
|
||||||
|
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
public string Reason { get; set; }
|
||||||
|
|
||||||
|
public Ban(string ip, string name, string reason)
|
||||||
|
{
|
||||||
|
IP = ip;
|
||||||
|
Name = name;
|
||||||
|
Reason = reason;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Ban()
|
||||||
|
{
|
||||||
|
IP = string.Empty;
|
||||||
|
Name = string.Empty;
|
||||||
|
Reason = string.Empty;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -171,23 +171,23 @@ namespace TShockAPI
|
||||||
public static void Ban(CommandArgs args)
|
public static void Ban(CommandArgs args)
|
||||||
{
|
{
|
||||||
string plStr = args.Message.Remove(0, 4).Trim();
|
string plStr = args.Message.Remove(0, 4).Trim();
|
||||||
int ply = args.PlayerID;
|
int adminplr = args.PlayerID;
|
||||||
int player = Tools.FindPlayer(plStr);
|
int player = Tools.FindPlayer(plStr);
|
||||||
if (!(player == -1 || player == -2 || plStr == ""))
|
if (!(player == -1 || player == -2 || plStr == ""))
|
||||||
{
|
{
|
||||||
if (!TShock.players[Tools.FindPlayer(plStr)].group.HasPermission("immunetoban"))
|
if (!TShock.players[Tools.FindPlayer(plStr)].group.HasPermission("immunetoban"))
|
||||||
{
|
{
|
||||||
FileTools.WriteBan(player);
|
TShock.Bans.AddBan(Tools.GetPlayerIP(player), Main.player[player].name);
|
||||||
Tools.Kick(player, "You were banned.");
|
Tools.Kick(player, "You were banned.");
|
||||||
Tools.Broadcast(Tools.FindPlayer(ply) + " banned " + Tools.FindPlayer(player) + "!");
|
Tools.Broadcast(Tools.FindPlayer(adminplr) + " banned " + Tools.FindPlayer(player) + "!");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Tools.SendMessage(ply, "You can't ban another admin!", new float[] { 255f, 0f, 0f });
|
Tools.SendMessage(adminplr, "You can't ban another admin!", new float[] { 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(adminplr, "More than one player matched!", new float[] { 255f, 0f, 0f });
|
||||||
else
|
else
|
||||||
Tools.SendMessage(ply, "Invalid player!", new float[] { 255f, 0f, 0f });
|
Tools.SendMessage(adminplr, "Invalid player!", new float[] { 255f, 0f, 0f });
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Off(CommandArgs args)
|
public static void Off(CommandArgs args)
|
||||||
|
|
|
||||||
|
|
@ -1,174 +1,94 @@
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using Terraria;
|
using System.Runtime.InteropServices;
|
||||||
using System.Web;
|
using System.Web;
|
||||||
using System.Runtime.InteropServices;
|
using Terraria;
|
||||||
|
|
||||||
namespace TShockAPI
|
namespace TShockAPI
|
||||||
{
|
{
|
||||||
class FileTools
|
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>
|
}
|
||||||
/// Adds a 'cheater' to cheaters.txt
|
|
||||||
/// </summary>
|
/// <summary>
|
||||||
/// <param name="ply">You should know what this does by now.</param>
|
/// Writes an error message to errors.txt
|
||||||
public static void WriteCheater(int ply)
|
/// </summary>
|
||||||
{
|
/// <param name="err">string message</param>
|
||||||
string ip = Tools.GetRealIP(Convert.ToString(Netplay.serverSock[ply].tcpClient.Client.RemoteEndPoint));
|
public static void WriteError(string err)
|
||||||
string cheaters = "";
|
{
|
||||||
TextReader tr = new StreamReader(SaveDir + "cheaters.txt");
|
if (System.IO.File.Exists(SaveDir + "errors.txt"))
|
||||||
cheaters = tr.ReadToEnd();
|
{
|
||||||
tr.Close();
|
TextWriter tw = new StreamWriter(SaveDir + "errors.txt", true);
|
||||||
if (cheaters.Contains(Main.player[ply].name) && cheaters.Contains(ip)) { return; }
|
tw.WriteLine(err);
|
||||||
TextWriter sw = new StreamWriter(SaveDir + "cheaters.txt", true);
|
tw.Close();
|
||||||
sw.WriteLine("[" + Main.player[ply].name + "] " + "[" + ip + "]");
|
}
|
||||||
sw.Close();
|
else
|
||||||
}
|
{
|
||||||
/// <summary>
|
FileTools.CreateFile(SaveDir + "errors.txt");
|
||||||
/// Writes a 'banned idiot' to the ban list
|
TextWriter tw = new StreamWriter(SaveDir + "errors.txt", true);
|
||||||
/// </summary>
|
tw.WriteLine(err);
|
||||||
/// <param name="ply"></param>
|
tw.Close();
|
||||||
public static void WriteBan(int ply)
|
}
|
||||||
{
|
}
|
||||||
string ip = Tools.GetRealIP(Convert.ToString(Netplay.serverSock[ply].tcpClient.Client.RemoteEndPoint));
|
|
||||||
TextWriter tw = new StreamWriter(SaveDir + "bans.txt", true);
|
/// <summary>
|
||||||
tw.WriteLine("[" + Main.player[ply].name + "] " + "[" + ip + "]");
|
/// Sets up the configuration file for all variables, and creates any missing files.
|
||||||
tw.Close();
|
/// </summary>
|
||||||
}
|
public static void SetupConfig()
|
||||||
/// <summary>
|
{
|
||||||
/// Writes a tnt user to grief.txt
|
if (!System.IO.Directory.Exists(SaveDir)) { System.IO.Directory.CreateDirectory(SaveDir); }
|
||||||
/// </summary>
|
if (!System.IO.File.Exists(SaveDir + "motd.txt"))
|
||||||
/// <param name="ply">int player</param>
|
{
|
||||||
public static void WriteGrief(int ply)
|
FileTools.CreateFile(SaveDir + "motd.txt");
|
||||||
{
|
TextWriter tw = new StreamWriter(SaveDir + "motd.txt");
|
||||||
TextWriter tw = new StreamWriter(SaveDir + "grief.txt", true);
|
tw.WriteLine("This server is running TShock. Type /help for a list of commands.");
|
||||||
tw.WriteLine("[" + Main.player[ply].name + "] [" + Tools.GetRealIP(Netplay.serverSock[ply].tcpClient.Client.RemoteEndPoint.ToString()) + "]");
|
tw.WriteLine("%255,000,000%Current map: %map%");
|
||||||
tw.Close();
|
tw.WriteLine("Current players: %players%");
|
||||||
}
|
tw.Close();
|
||||||
|
}
|
||||||
/// <summary>
|
if (!System.IO.File.Exists(SaveDir + "bans.txt")) { FileTools.CreateFile(SaveDir + "bans.txt"); }
|
||||||
/// Writes an error message to errors.txt
|
if (!System.IO.File.Exists(SaveDir + "cheaters.txt")) { FileTools.CreateFile(SaveDir + "cheaters.txt"); }
|
||||||
/// </summary>
|
if (!System.IO.File.Exists(SaveDir + "grief.txt")) { FileTools.CreateFile(SaveDir + "grief.txt"); }
|
||||||
/// <param name="err">string message</param>
|
if (!System.IO.File.Exists(SaveDir + "whitelist.txt")) { FileTools.CreateFile(SaveDir + "whitelist.txt"); }
|
||||||
public static void WriteError(string err)
|
if (!System.IO.File.Exists(SaveDir + "groups.txt"))
|
||||||
{
|
{
|
||||||
if (System.IO.File.Exists(SaveDir + "errors.txt"))
|
FileTools.CreateFile(SaveDir + "groups.txt");
|
||||||
{
|
StreamWriter sw = new StreamWriter(SaveDir + "groups.txt");
|
||||||
TextWriter tw = new StreamWriter(SaveDir + "errors.txt", true);
|
sw.Write(Resources.groups);
|
||||||
tw.WriteLine(err);
|
sw.Close();
|
||||||
tw.Close();
|
}
|
||||||
}
|
if (!System.IO.File.Exists(SaveDir + "users.txt"))
|
||||||
else
|
{
|
||||||
{
|
FileTools.CreateFile(SaveDir + "users.txt");
|
||||||
FileTools.CreateFile(SaveDir + "errors.txt");
|
StreamWriter sw = new StreamWriter(SaveDir + "users.txt");
|
||||||
TextWriter tw = new StreamWriter(SaveDir + "errors.txt", true);
|
sw.Write(Resources.users);
|
||||||
tw.WriteLine(err);
|
sw.Close();
|
||||||
tw.Close();
|
}
|
||||||
}
|
ConfigurationManager.WriteJsonConfiguration();
|
||||||
}
|
ConfigurationManager.ReadJsonConfiguration();
|
||||||
|
Netplay.serverPort = ConfigurationManager.serverPort;
|
||||||
/// <summary>
|
}
|
||||||
/// Sets up the configuration file for all variables, and creates any missing files.
|
|
||||||
/// </summary>
|
/// <summary>
|
||||||
public static void SetupConfig()
|
/// Tells if a user is on the whitelist
|
||||||
{
|
/// </summary>
|
||||||
if (!System.IO.Directory.Exists(SaveDir)) { System.IO.Directory.CreateDirectory(SaveDir); }
|
/// <param name="ip">string ip of the user</param>
|
||||||
if (!System.IO.File.Exists(SaveDir + "motd.txt"))
|
/// <returns>true/false</returns>
|
||||||
{
|
public static bool OnWhitelist(string ip)
|
||||||
FileTools.CreateFile(SaveDir + "motd.txt");
|
{
|
||||||
TextWriter tw = new StreamWriter(SaveDir + "motd.txt");
|
if (!ConfigurationManager.enableWhitelist) { return true; }
|
||||||
tw.WriteLine("This server is running TShock. Type /help for a list of commands.");
|
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(); }
|
||||||
tw.WriteLine("%255,000,000%Current map: %map%");
|
TextReader tr = new StreamReader(SaveDir + "whitelist.txt");
|
||||||
tw.WriteLine("Current players: %players%");
|
string whitelist = tr.ReadToEnd();
|
||||||
tw.Close();
|
ip = Tools.GetRealIP(ip);
|
||||||
}
|
return whitelist.Contains(ip);
|
||||||
if (!System.IO.File.Exists(SaveDir + "bans.txt")) { FileTools.CreateFile(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"); }
|
public FileTools() { }
|
||||||
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");
|
|
||||||
StreamWriter sw = new StreamWriter(SaveDir + "groups.txt");
|
|
||||||
sw.Write(Resources.groups);
|
|
||||||
sw.Close();
|
|
||||||
}
|
|
||||||
if (!System.IO.File.Exists(SaveDir + "users.txt"))
|
|
||||||
{
|
|
||||||
FileTools.CreateFile(SaveDir + "users.txt");
|
|
||||||
StreamWriter sw = new StreamWriter(SaveDir + "users.txt");
|
|
||||||
sw.Write(Resources.users);
|
|
||||||
sw.Close();
|
|
||||||
}
|
|
||||||
ConfigurationManager.WriteJsonConfiguration();
|
|
||||||
ConfigurationManager.ReadJsonConfiguration();
|
|
||||||
Netplay.serverPort = ConfigurationManager.serverPort;
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Checks if a user is banned
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="p">string ip</param>
|
|
||||||
/// <returns>true/false</returns>
|
|
||||||
public static bool CheckBanned(String p)
|
|
||||||
{
|
|
||||||
String ip = p.Split(':')[0];
|
|
||||||
TextReader tr = new StreamReader(SaveDir + "bans.txt");
|
|
||||||
string banlist = tr.ReadToEnd();
|
|
||||||
tr.Close();
|
|
||||||
banlist = banlist.Trim();
|
|
||||||
if (banlist.Contains(ip))
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Tells if a user is on the whitelist
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="ip">string ip of the user</param>
|
|
||||||
/// <returns>true/false</returns>
|
|
||||||
public static bool OnWhitelist(string ip)
|
|
||||||
{
|
|
||||||
if (!ConfigurationManager.enableWhitelist) { return true; }
|
|
||||||
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(); }
|
|
||||||
TextReader tr = new StreamReader(SaveDir + "whitelist.txt");
|
|
||||||
string whitelist = tr.ReadToEnd();
|
|
||||||
ip = Tools.GetRealIP(ip);
|
|
||||||
return whitelist.Contains(ip);
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Tells if the user is on grief.txt
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="ip"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static bool Checkgrief(String ip)
|
|
||||||
{
|
|
||||||
ip = Tools.GetRealIP(ip);
|
|
||||||
if (!ConfigurationManager.banTnt) { return false; }
|
|
||||||
TextReader tr = new StreamReader(SaveDir + "grief.txt");
|
|
||||||
string list = tr.ReadToEnd();
|
|
||||||
tr.Close();
|
|
||||||
|
|
||||||
return list.Contains(ip);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool CheckCheat(String ip)
|
|
||||||
{
|
|
||||||
ip = Tools.GetRealIP(ip);
|
|
||||||
if (!ConfigurationManager.banCheater) { return false; }
|
|
||||||
TextReader tr = new StreamReader(SaveDir + "cheaters.txt");
|
|
||||||
string trr = tr.ReadToEnd();
|
|
||||||
tr.Close();
|
|
||||||
if (trr.Contains(ip))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public FileTools() { }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -23,6 +23,8 @@ namespace TShockAPI
|
||||||
|
|
||||||
static bool[] BlacklistTiles;
|
static bool[] BlacklistTiles;
|
||||||
|
|
||||||
|
public static BanManager Bans = new BanManager(Path.Combine(saveDir, "bans.txt"));
|
||||||
|
|
||||||
public override Version Version
|
public override Version Version
|
||||||
{
|
{
|
||||||
get { return VersionNum; }
|
get { return VersionNum; }
|
||||||
|
|
@ -127,6 +129,8 @@ namespace TShockAPI
|
||||||
|
|
||||||
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
|
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
|
||||||
|
|
||||||
|
Bans.LoadBans();
|
||||||
|
|
||||||
Log.Info("Hooks initialized");
|
Log.Info("Hooks initialized");
|
||||||
Commands.InitCommands();
|
Commands.InitCommands();
|
||||||
Log.Info("Commands initialized");
|
Log.Info("Commands initialized");
|
||||||
|
|
@ -134,10 +138,14 @@ namespace TShockAPI
|
||||||
|
|
||||||
void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
|
void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
|
||||||
{
|
{
|
||||||
if (Main.worldPathName != null)
|
if (e.IsTerminating)
|
||||||
{
|
{
|
||||||
Main.worldPathName += ".crash";
|
if (Main.worldPathName != null)
|
||||||
WorldGen.saveWorld();
|
{
|
||||||
|
Main.worldPathName += ".crash";
|
||||||
|
WorldGen.saveWorld();
|
||||||
|
}
|
||||||
|
DeInitialize();
|
||||||
}
|
}
|
||||||
Log.Error(e.ExceptionObject.ToString());
|
Log.Error(e.ExceptionObject.ToString());
|
||||||
}
|
}
|
||||||
|
|
@ -148,6 +156,8 @@ namespace TShockAPI
|
||||||
|
|
||||||
public override void DeInitialize()
|
public override void DeInitialize()
|
||||||
{
|
{
|
||||||
|
Bans.SaveBans();
|
||||||
|
|
||||||
GameHooks.OnPreInitialize -= OnPreInit;
|
GameHooks.OnPreInitialize -= OnPreInit;
|
||||||
GameHooks.OnPostInitialize -= OnPostInit;
|
GameHooks.OnPostInitialize -= OnPostInit;
|
||||||
GameHooks.OnUpdate -= new Action<Microsoft.Xna.Framework.GameTime>(OnUpdate);
|
GameHooks.OnUpdate -= new Action<Microsoft.Xna.Framework.GameTime>(OnUpdate);
|
||||||
|
|
@ -258,7 +268,7 @@ namespace TShockAPI
|
||||||
if (players[ply].syncHP)
|
if (players[ply].syncHP)
|
||||||
{
|
{
|
||||||
if (maxLife > Main.player[ply].statLifeMax + 20 || life > maxLife)
|
if (maxLife > Main.player[ply].statLifeMax + 20 || life > maxLife)
|
||||||
Tools.HandleCheater(ply);
|
TShock.Ban(ply, "Cheater");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -279,7 +289,7 @@ namespace TShockAPI
|
||||||
{
|
{
|
||||||
if (players[ply].syncMP)
|
if (players[ply].syncMP)
|
||||||
{
|
{
|
||||||
Tools.HandleCheater(ply);
|
TShock.Ban(ply, "Cheater");
|
||||||
Log.Info(Tools.FindPlayer(ply) +
|
Log.Info(Tools.FindPlayer(ply) +
|
||||||
" had increased max mana by more than 20 or increased mana more than max");
|
" had increased max mana by more than 20 or increased mana more than max");
|
||||||
}
|
}
|
||||||
|
|
@ -300,7 +310,7 @@ namespace TShockAPI
|
||||||
{
|
{
|
||||||
//fuck you faggot
|
//fuck you faggot
|
||||||
Log.Info(Tools.FindPlayer(e.Msg.whoAmI) + " was kicked for trying to fake chat as someone else.");
|
Log.Info(Tools.FindPlayer(e.Msg.whoAmI) + " was kicked for trying to fake chat as someone else.");
|
||||||
Tools.HandleCheater(ply);
|
TShock.Ban(ply, "Faking Chat");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -326,7 +336,7 @@ namespace TShockAPI
|
||||||
{
|
{
|
||||||
int i = e.Msg.whoAmI;
|
int i = e.Msg.whoAmI;
|
||||||
if (ConfigurationManager.banBoom)
|
if (ConfigurationManager.banBoom)
|
||||||
FileTools.WriteGrief((int)i);
|
TShock.Ban(i, "Explosives");
|
||||||
Tools.Kick((int)i, "Explosives were thrown.");
|
Tools.Kick((int)i, "Explosives were thrown.");
|
||||||
Tools.Broadcast(Main.player[i].name + " was " +
|
Tools.Broadcast(Main.player[i].name + " was " +
|
||||||
(ConfigurationManager.banBoom ? "banned" : "kicked") +
|
(ConfigurationManager.banBoom ? "banned" : "kicked") +
|
||||||
|
|
@ -348,7 +358,7 @@ namespace TShockAPI
|
||||||
|
|
||||||
if (id != e.Msg.whoAmI)
|
if (id != e.Msg.whoAmI)
|
||||||
{
|
{
|
||||||
Tools.HandleGriefer(e.Msg.whoAmI);
|
TShock.Ban(e.Msg.whoAmI, "Griefer");
|
||||||
Log.Info(Tools.FindPlayer(e.Msg.whoAmI) +
|
Log.Info(Tools.FindPlayer(e.Msg.whoAmI) +
|
||||||
" was kicked for trying to execute KillMe on someone else.");
|
" was kicked for trying to execute KillMe on someone else.");
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
|
|
@ -391,7 +401,7 @@ namespace TShockAPI
|
||||||
Tools.ShowMOTD(who);
|
Tools.ShowMOTD(who);
|
||||||
if (Main.player[plr].statLifeMax > 400 || Main.player[plr].statManaMax > 200 || Main.player[plr].statLife > 400 || Main.player[plr].statMana > 200 || CheckInventory(plr))
|
if (Main.player[plr].statLifeMax > 400 || Main.player[plr].statManaMax > 200 || Main.player[plr].statLife > 400 || Main.player[plr].statMana > 200 || CheckInventory(plr))
|
||||||
{
|
{
|
||||||
Tools.HandleCheater(plr);
|
TShock.Ban(plr, "Cheater");
|
||||||
}
|
}
|
||||||
if (ConfigurationManager.permaPvp)
|
if (ConfigurationManager.permaPvp)
|
||||||
{
|
{
|
||||||
|
|
@ -444,34 +454,23 @@ namespace TShockAPI
|
||||||
{
|
{
|
||||||
if (Main.netMode != 2) { return; }
|
if (Main.netMode != 2) { return; }
|
||||||
|
|
||||||
int count = 1;
|
if (Tools.activePlayers() + 1 > ConfigurationManager.maxSlots)
|
||||||
for (int i = 0; i < Main.player.Length; i++)
|
|
||||||
count += Main.player[i].active ? 1 : 0;
|
|
||||||
|
|
||||||
if (count > ConfigurationManager.maxSlots)
|
|
||||||
{
|
{
|
||||||
Tools.Kick(ply, "Server is full");
|
Tools.Kick(ply, "Server is full");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string ip = Tools.GetRealIP((Convert.ToString(Netplay.serverSock[ply].tcpClient.Client.RemoteEndPoint)));
|
string ip = Tools.GetRealIP(Netplay.serverSock[ply].tcpClient.Client.RemoteEndPoint.ToString());
|
||||||
if (FileTools.CheckBanned(ip))
|
var ban = Bans.GetBanByIp(ip);
|
||||||
|
if (ban != null)
|
||||||
{
|
{
|
||||||
Tools.Kick(ply, "You are banned.");
|
Tools.Kick(ply, "You are banned: " + ban.Reason);
|
||||||
}
|
}
|
||||||
else if (Tools.FindPlayer(ply).Length > 32)
|
else if (Tools.FindPlayer(ply).Length > 32)
|
||||||
{
|
{
|
||||||
Tools.Kick(ply, "Your name was too long.");
|
Tools.Kick(ply, "Your name was too long.");
|
||||||
Tools.Broadcast(ip + " was kicked because their name exceeded 32 characters.");
|
Tools.Broadcast(ip + " was kicked because their name exceeded 32 characters.");
|
||||||
}
|
}
|
||||||
else if (FileTools.CheckCheat(ip))
|
|
||||||
{
|
|
||||||
Tools.Kick(ply, "You were flagged for cheating.");
|
|
||||||
}
|
|
||||||
else if (FileTools.Checkgrief(ip))
|
|
||||||
{
|
|
||||||
Tools.Kick(ply, "You were flagged for griefing.");
|
|
||||||
}
|
|
||||||
if (!FileTools.OnWhitelist(ip))
|
if (!FileTools.OnWhitelist(ip))
|
||||||
{
|
{
|
||||||
Tools.Kick(ply, "Not on whitelist.");
|
Tools.Kick(ply, "Not on whitelist.");
|
||||||
|
|
@ -513,7 +512,7 @@ namespace TShockAPI
|
||||||
if (ConfigurationManager.kickTnt || ConfigurationManager.banTnt)
|
if (ConfigurationManager.kickTnt || ConfigurationManager.banTnt)
|
||||||
{
|
{
|
||||||
if (ConfigurationManager.banTnt)
|
if (ConfigurationManager.banTnt)
|
||||||
FileTools.WriteGrief((int)i);
|
TShock.Ban((int)i, "Explosives");
|
||||||
Tools.Kick((int)i, "Kill tile abuse detected.");
|
Tools.Kick((int)i, "Kill tile abuse detected.");
|
||||||
Tools.Broadcast(Main.player[i].name + " was " + (ConfigurationManager.banTnt ? "banned" : "kicked") + " for kill tile abuse.");
|
Tools.Broadcast(Main.player[i].name + " was " + (ConfigurationManager.banTnt ? "banned" : "kicked") + " for kill tile abuse.");
|
||||||
RevertKillTile((int)i);
|
RevertKillTile((int)i);
|
||||||
|
|
@ -570,12 +569,6 @@ namespace TShockAPI
|
||||||
|
|
||||||
public static void Teleport(int ply, int x, int y)
|
public static void Teleport(int ply, int x, int y)
|
||||||
{
|
{
|
||||||
/*Main.player[ply].velocity = new Vector2(0, 0);
|
|
||||||
NetMessage.SendData(0x0d, -1, -1, "", ply);
|
|
||||||
Main.player[ply].position.X = x;
|
|
||||||
Main.player[ply].position.Y = y - 0x2a;
|
|
||||||
NetMessage.SendData(0x0d, -1, -1, "", ply);
|
|
||||||
UpdatePlayers();*/
|
|
||||||
Main.player[ply].position.X = (float)x;
|
Main.player[ply].position.X = (float)x;
|
||||||
Main.player[ply].position.Y = (float)y;
|
Main.player[ply].position.Y = (float)y;
|
||||||
NetMessage.SendData(0x0d, -1, ply, "", ply);
|
NetMessage.SendData(0x0d, -1, ply, "", ply);
|
||||||
|
|
@ -585,18 +578,6 @@ namespace TShockAPI
|
||||||
|
|
||||||
public static void Teleport(int ply, float x, float y)
|
public static void Teleport(int ply, float x, float y)
|
||||||
{
|
{
|
||||||
/*Main.player[ply].position.X = x;
|
|
||||||
Main.player[ply].position.Y = y - 0x2a;
|
|
||||||
NetMessage.SendData(0x14, -1, -1, "", 10, x, y);
|
|
||||||
NetMessage.SendData(0x0d, -1, -1, "", ply);
|
|
||||||
int oldx = Main.player[ply].SpawnX;
|
|
||||||
int oldy = Main.player[ply].SpawnY;
|
|
||||||
Main.player[ply].SpawnX = (int)(x / 16);
|
|
||||||
Main.player[ply].SpawnY = (int)((y - 0x2a) / 16);
|
|
||||||
NetMessage.SendData(0xC, -1, -1, "", ply);
|
|
||||||
Main.player[ply].SpawnX = oldx;
|
|
||||||
Main.player[ply].SpawnY = oldy;
|
|
||||||
UpdatePlayers();*/
|
|
||||||
Main.player[ply].position.X = x;
|
Main.player[ply].position.X = x;
|
||||||
Main.player[ply].position.Y = y;
|
Main.player[ply].position.Y = y;
|
||||||
NetMessage.SendData(0x0d, -1, ply, "", ply);
|
NetMessage.SendData(0x0d, -1, ply, "", ply);
|
||||||
|
|
@ -747,6 +728,11 @@ namespace TShockAPI
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void Ban(int plr, string reason = "")
|
||||||
|
{
|
||||||
|
Bans.AddBan(Tools.GetPlayerIP(plr), Main.player[plr].name, reason);
|
||||||
|
}
|
||||||
|
|
||||||
public class Position
|
public class Position
|
||||||
{
|
{
|
||||||
public float X;
|
public float X;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using Terraria;
|
using Terraria;
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace TShockAPI
|
namespace TShockAPI
|
||||||
{
|
{
|
||||||
|
|
@ -19,6 +19,16 @@ namespace TShockAPI
|
||||||
return mess.Split(':')[0];
|
return mess.Split(':')[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the IP from a player index
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="plr">Player Index</param>
|
||||||
|
/// <returns>IP</returns>
|
||||||
|
public static string GetPlayerIP(int plr)
|
||||||
|
{
|
||||||
|
return GetRealIP(Netplay.serverSock[plr].tcpClient.Client.RemoteEndPoint.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Used for some places where a list of players might be used.
|
/// Used for some places where a list of players might be used.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -201,46 +211,6 @@ namespace TShockAPI
|
||||||
Log.Info("Kicked " + Tools.FindPlayer(ply) + " for : " + reason);
|
Log.Info("Kicked " + Tools.FindPlayer(ply) + " for : " + reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Adds someone to cheaters.txt
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="ply">int player</param>
|
|
||||||
public static void HandleCheater(int ply)
|
|
||||||
{
|
|
||||||
if (!TShock.players[ply].group.HasPermission("ignorecheatdetection"))
|
|
||||||
{
|
|
||||||
string cheater = Tools.FindPlayer(ply);
|
|
||||||
string ip = Tools.GetRealIP(Convert.ToString(Netplay.serverSock[ply].tcpClient.Client.RemoteEndPoint));
|
|
||||||
|
|
||||||
FileTools.WriteCheater(ply);
|
|
||||||
if (!ConfigurationManager.kickCheater) { return; }
|
|
||||||
Netplay.serverSock[ply].kill = true;
|
|
||||||
Netplay.serverSock[ply].Reset();
|
|
||||||
NetMessage.syncPlayers();
|
|
||||||
Tools.Broadcast(cheater + " was " + (ConfigurationManager.banCheater ? "banned " : "kicked ") + "for cheating.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Adds someone to griefers.txt
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="ply">int player</param>
|
|
||||||
public static void HandleGriefer(int ply)
|
|
||||||
{
|
|
||||||
if (!TShock.players[ply].group.HasPermission("ignoregriefdetection"))
|
|
||||||
{
|
|
||||||
string cheater = Tools.FindPlayer(ply);
|
|
||||||
string ip = Tools.GetRealIP(Convert.ToString(Netplay.serverSock[ply].tcpClient.Client.RemoteEndPoint));
|
|
||||||
|
|
||||||
FileTools.WriteGrief(ply);
|
|
||||||
if (!ConfigurationManager.kickGriefer) { return; }
|
|
||||||
Netplay.serverSock[ply].kill = true;
|
|
||||||
Netplay.serverSock[ply].Reset();
|
|
||||||
NetMessage.syncPlayers();
|
|
||||||
Tools.Broadcast(cheater + " was " + (ConfigurationManager.banGriefer ? "banned " : "kicked ") + "for griefing.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Shows a MOTD to the player
|
/// Shows a MOTD to the player
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue