Moved all GetData checks to GetDataHandlers
Fixed GetBanByName not working
This commit is contained in:
parent
8d1377c7cf
commit
f3be17a911
3 changed files with 596 additions and 554 deletions
|
|
@ -20,10 +20,8 @@ using System.Collections.Generic;
|
|||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Content;
|
||||
using StreamBinary;
|
||||
using Terraria;
|
||||
using TerrariaAPI;
|
||||
using TerrariaAPI.Hooks;
|
||||
|
|
@ -41,13 +39,8 @@ namespace TShockAPI
|
|||
|
||||
public static readonly string VersionCodename = "Forgot to increase the version.";
|
||||
|
||||
private static bool[] BlacklistTiles;
|
||||
|
||||
public static BanManager Bans = new BanManager(Path.Combine(SavePath, "bans.txt"));
|
||||
|
||||
delegate bool HandleGetDataD(MemoryStream data, GetDataEventArgs e);
|
||||
Dictionary<byte, HandleGetDataD> GetDataFuncs;
|
||||
|
||||
public override Version Version
|
||||
{
|
||||
get { return VersionNum; }
|
||||
|
|
@ -68,73 +61,9 @@ namespace TShockAPI
|
|||
get { return "The administration modification of the future."; }
|
||||
}
|
||||
|
||||
static TShock()
|
||||
{
|
||||
//Tools.LoadGroups();
|
||||
|
||||
#region Blacklisted tiles
|
||||
|
||||
BlacklistTiles = new bool[0x80];
|
||||
BlacklistTiles[0] = true;
|
||||
BlacklistTiles[1] = true;
|
||||
BlacklistTiles[2] = true;
|
||||
BlacklistTiles[6] = true;
|
||||
BlacklistTiles[7] = true;
|
||||
BlacklistTiles[8] = true;
|
||||
BlacklistTiles[9] = true;
|
||||
BlacklistTiles[22] = true;
|
||||
BlacklistTiles[23] = true;
|
||||
BlacklistTiles[25] = true;
|
||||
BlacklistTiles[30] = true;
|
||||
BlacklistTiles[37] = true;
|
||||
BlacklistTiles[38] = true;
|
||||
BlacklistTiles[39] = true;
|
||||
BlacklistTiles[40] = true;
|
||||
BlacklistTiles[41] = true;
|
||||
BlacklistTiles[43] = true;
|
||||
BlacklistTiles[44] = true;
|
||||
BlacklistTiles[45] = true;
|
||||
BlacklistTiles[46] = true;
|
||||
BlacklistTiles[47] = true;
|
||||
BlacklistTiles[53] = true;
|
||||
BlacklistTiles[54] = true;
|
||||
BlacklistTiles[56] = true;
|
||||
BlacklistTiles[57] = true;
|
||||
BlacklistTiles[58] = true;
|
||||
BlacklistTiles[59] = true;
|
||||
BlacklistTiles[60] = true;
|
||||
BlacklistTiles[63] = true;
|
||||
BlacklistTiles[64] = true;
|
||||
BlacklistTiles[65] = true;
|
||||
BlacklistTiles[66] = true;
|
||||
BlacklistTiles[67] = true;
|
||||
BlacklistTiles[68] = true;
|
||||
BlacklistTiles[70] = true;
|
||||
BlacklistTiles[75] = true;
|
||||
BlacklistTiles[76] = true;
|
||||
|
||||
#endregion Blacklisted tiles
|
||||
}
|
||||
|
||||
public TShock(Main game)
|
||||
: base(game)
|
||||
{
|
||||
|
||||
GetDataFuncs = new Dictionary<byte, HandleGetDataD>
|
||||
{
|
||||
{(byte)PacketTypes.PlayerInfo, HandlePlayerInfo},
|
||||
{(byte)PacketTypes.TileSendSection, HandleSendSection},
|
||||
{(byte)PacketTypes.PlayerUpdate, HandlePlayerUpdate},
|
||||
{(byte)PacketTypes.Tile, HandleTile},
|
||||
{(byte)PacketTypes.TileSendSquare, HandleSendTileSquare},
|
||||
{(byte)PacketTypes.NPCUpdate, HandleNpcUpdate},
|
||||
{(byte)PacketTypes.PlayerDamage, HandlePlayerDamage},
|
||||
{(byte)PacketTypes.ProjectileNew, HandleProjectileNew},
|
||||
{(byte)PacketTypes.TogglePVP, HandleTogglePvp},
|
||||
{(byte)PacketTypes.TileKill, HandleTileKill},
|
||||
{(byte)PacketTypes.PlayerKillMe, HandlePlayerKillMe},
|
||||
{(byte)PacketTypes.LiquidSet, HandleLiquidSet},
|
||||
};
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
|
|
@ -150,13 +79,13 @@ namespace TShockAPI
|
|||
|
||||
GameHooks.PostInitialize += OnPostInit;
|
||||
GameHooks.Update += OnUpdate;
|
||||
ServerHooks.Chat += OnChat;
|
||||
ServerHooks.Join += OnJoin;
|
||||
ServerHooks.Leave += OnLeave;
|
||||
ServerHooks.Chat += OnChat;
|
||||
ServerHooks.Command += ServerHooks_OnCommand;
|
||||
NetHooks.GetData += GetData;
|
||||
NetHooks.GreetPlayer += OnGreetPlayer;
|
||||
NpcHooks.StrikeNpc += NpcHooks_OnStrikeNpc;
|
||||
ServerHooks.Command += ServerHooks_OnCommand;
|
||||
|
||||
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
|
||||
Log.Info("Hooks initialized");
|
||||
|
|
@ -164,6 +93,9 @@ namespace TShockAPI
|
|||
Bans.LoadBans();
|
||||
Log.Info("Bans initialized");
|
||||
|
||||
GetDataHandlers.InitGetDataHandler();
|
||||
Log.Info("Get data handlers initialized");
|
||||
|
||||
Commands.InitCommands();
|
||||
Log.Info("Commands initialized");
|
||||
|
||||
|
|
@ -175,9 +107,9 @@ namespace TShockAPI
|
|||
Bans.SaveBans();
|
||||
GameHooks.PostInitialize -= OnPostInit;
|
||||
GameHooks.Update -= OnUpdate;
|
||||
ServerHooks.Chat -= OnChat;
|
||||
ServerHooks.Join -= OnJoin;
|
||||
ServerHooks.Leave -= OnLeave;
|
||||
ServerHooks.Chat -= OnChat;
|
||||
ServerHooks.Command -= ServerHooks_OnCommand;
|
||||
NetHooks.GetData -= GetData;
|
||||
NetHooks.GreetPlayer -= OnGreetPlayer;
|
||||
|
|
@ -203,11 +135,151 @@ namespace TShockAPI
|
|||
Log.Error(e.ExceptionObject.ToString());
|
||||
}
|
||||
|
||||
private void HandleCommandLine(string[] parms)
|
||||
{
|
||||
for (int i = 0; i < parms.Length; i++)
|
||||
{
|
||||
if (parms[i].ToLower() == "-ip")
|
||||
{
|
||||
IPAddress ip;
|
||||
if (IPAddress.TryParse(parms[++i], out ip))
|
||||
{
|
||||
Netplay.serverListenIP = ip;
|
||||
Console.Write("Using IP: {0}", ip);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Bad IP: {0}", parms[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Hooks:
|
||||
*
|
||||
*/
|
||||
|
||||
private void OnPostInit()
|
||||
{
|
||||
if (!File.Exists(Path.Combine(SavePath, "auth.lck")))
|
||||
{
|
||||
var r = new Random((int)DateTime.Now.ToBinary());
|
||||
ConfigurationManager.AuthToken = r.Next(100000, 10000000);
|
||||
Console.WriteLine("TShock Notice: To become SuperAdmin, join the game and type /auth " +
|
||||
ConfigurationManager.AuthToken);
|
||||
Console.WriteLine("This token will only display ONCE. This only works ONCE. If you don't use it and the server goes down, delete auth.lck.");
|
||||
FileTools.CreateFile(Path.Combine(SavePath, "auth.lck"));
|
||||
}
|
||||
}
|
||||
|
||||
private void OnUpdate(GameTime time)
|
||||
{
|
||||
UpdateManager.UpdateProcedureCheck();
|
||||
foreach (TSPlayer player in TShock.Players)
|
||||
{
|
||||
if (player != null && player.Active)
|
||||
{
|
||||
if (player.TileThreshold >= 20)
|
||||
{
|
||||
if (Tools.HandleTntUser(player, "Kill tile abuse detected."))
|
||||
{
|
||||
RevertKillTile(player);
|
||||
player.TileThreshold = 0;
|
||||
player.TilesDestroyed.Clear();
|
||||
}
|
||||
else if (player.TileThreshold > 0)
|
||||
{
|
||||
player.TileThreshold = 0;
|
||||
player.TilesDestroyed.Clear();
|
||||
}
|
||||
|
||||
}
|
||||
else if (player.TileThreshold > 0)
|
||||
{
|
||||
player.TileThreshold = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnJoin(int ply, HandledEventArgs handler)
|
||||
{
|
||||
if (Main.netMode != 2 || handler.Handled)
|
||||
return;
|
||||
|
||||
var player = new TSPlayer(ply);
|
||||
player.Group = Tools.GetGroupForIP(player.IP);
|
||||
|
||||
if (Tools.ActivePlayers() + 1 > ConfigurationManager.MaxSlots &&
|
||||
!player.Group.HasPermission("reservedslot"))
|
||||
{
|
||||
Tools.ForceKick(player, "Server is full");
|
||||
handler.Handled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
var ban = Bans.GetBanByIp(player.IP);
|
||||
if (ban != null)
|
||||
{
|
||||
Tools.ForceKick(player, string.Format("You are banned: {0}", ban.Reason));
|
||||
handler.Handled = true;
|
||||
}
|
||||
else if (!FileTools.OnWhitelist(player.IP))
|
||||
{
|
||||
Tools.ForceKick(player, "Not on whitelist.");
|
||||
handler.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
Players[ply] = player;
|
||||
Netplay.serverSock[ply].spamCheck = ConfigurationManager.SpamChecks;
|
||||
}
|
||||
|
||||
private void OnLeave(int ply)
|
||||
{
|
||||
if (Main.netMode != 2)
|
||||
return;
|
||||
|
||||
var tsplr = Players[ply];
|
||||
if (tsplr != null && tsplr.ReceivedInfo)
|
||||
Log.Info(string.Format("{0} left.", tsplr.Name));
|
||||
|
||||
Players[ply] = null;
|
||||
}
|
||||
|
||||
private void OnChat(messageBuffer msg, int ply, string text, HandledEventArgs e)
|
||||
{
|
||||
if (Main.netMode != 2)
|
||||
return;
|
||||
|
||||
if (msg.whoAmI != ply)
|
||||
{
|
||||
e.Handled = Tools.HandleGriefer(Players[ply], "Faking Chat");
|
||||
return;
|
||||
}
|
||||
|
||||
var tsplr = Players[msg.whoAmI];
|
||||
|
||||
if (tsplr.Group.HasPermission("adminchat") && !text.StartsWith("/"))
|
||||
{
|
||||
Tools.Broadcast(ConfigurationManager.AdminChatPrefix + "<" + tsplr.Name + "> " + text,
|
||||
(byte)ConfigurationManager.AdminChatRGB[0], (byte)ConfigurationManager.AdminChatRGB[1], (byte)ConfigurationManager.AdminChatRGB[2]);
|
||||
e.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (text.StartsWith("/"))
|
||||
{
|
||||
if (Commands.HandleCommand(tsplr, text))
|
||||
e.Handled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Info(string.Format("{0} said: {1}", tsplr.Name, text));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// When a server command is run.
|
||||
/// </summary>
|
||||
|
|
@ -255,363 +327,31 @@ namespace TShockAPI
|
|||
|
||||
}
|
||||
|
||||
private void NpcHooks_OnStrikeNpc(NpcStrikeEventArgs e)
|
||||
{
|
||||
if (ConfigurationManager.InfiniteInvasion)
|
||||
{
|
||||
IncrementKills();
|
||||
if (Main.invasionSize < 10)
|
||||
{
|
||||
Main.invasionSize = 20000000;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void GetData(GetDataEventArgs e)
|
||||
{
|
||||
if (!Players[e.Msg.whoAmI].ConnectionAlive)
|
||||
PacketTypes type = (PacketTypes) e.MsgID;
|
||||
TSPlayer player = Players[e.Msg.whoAmI];
|
||||
|
||||
if (!player.ConnectionAlive)
|
||||
return;
|
||||
|
||||
if (Main.verboseNetplay)
|
||||
Debug.WriteLine("{0:X} ({2}): {3} ({1:XX})", e.Msg.whoAmI, e.MsgID, Main.player[e.Msg.whoAmI].dead ? "dead " : "alive", MsgNames[e.MsgID]);
|
||||
Debug.WriteLine("{0:X} ({2}): {3} ({1:XX})", player.Index, (byte) type, player.TPlayer.dead ? "dead " : "alive", type.ToString());
|
||||
|
||||
HandleGetDataD func;
|
||||
if (GetDataFuncs.TryGetValue(e.MsgID, out func))
|
||||
using (var data = new MemoryStream(e.Msg.readBuffer, e.Index, e.Length))
|
||||
{
|
||||
using (var data = new MemoryStream(e.Msg.readBuffer, e.Index, e.Length))
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
e.Handled = func(data, e);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex.ToString());
|
||||
}
|
||||
if (GetDataHandlers.HandlerGetData(type, player, data))
|
||||
e.Handled = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool HandlePlayerInfo(MemoryStream data, GetDataEventArgs e)
|
||||
{
|
||||
var player = Players[e.Msg.whoAmI];
|
||||
if (player == null)
|
||||
{
|
||||
Tools.ForceKick(new TSPlayer(e.Msg.whoAmI), "Player doesn't exist");
|
||||
return true;
|
||||
}
|
||||
var ban = Bans.GetBanByName(player.Name);
|
||||
if (ban != null)
|
||||
{
|
||||
Tools.ForceKick(player, string.Format("You are banned: {0}", ban.Reason));
|
||||
return true;
|
||||
}
|
||||
byte hair = e.Msg.readBuffer[e.Index + 1];
|
||||
if (hair > 0x10)
|
||||
{
|
||||
Tools.ForceKick(player, "Hair crash exploit.");
|
||||
return true;
|
||||
}
|
||||
|
||||
string name = Encoding.ASCII.GetString(e.Msg.readBuffer, e.Index + 23, (e.Length - (e.Index + 23)) + e.Index - 1);
|
||||
if (name.Length > 32)
|
||||
{
|
||||
Tools.ForceKick(player, "Name exceeded 32 characters.");
|
||||
return true;
|
||||
}
|
||||
if (name.Trim().Length == 0)
|
||||
{
|
||||
Tools.ForceKick(player, "Empty Name.");
|
||||
return true;
|
||||
}
|
||||
if (player.ReceivedInfo)
|
||||
{
|
||||
return Tools.HandleGriefer(Players[e.Msg.whoAmI], "Sent client info more than once");
|
||||
}
|
||||
|
||||
player.ReceivedInfo = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool HandleSendTileSquare(MemoryStream data, GetDataEventArgs e)
|
||||
{
|
||||
short size = data.ReadInt16();
|
||||
int x = data.ReadInt32();
|
||||
int y = data.ReadInt32();
|
||||
int plyX = Math.Abs((int)Main.player[e.Msg.whoAmI].position.X / 16);
|
||||
int plyY = Math.Abs((int)Main.player[e.Msg.whoAmI].position.Y / 16);
|
||||
int tileX = Math.Abs(x);
|
||||
int tileY = Math.Abs(y);
|
||||
if (size > 5 || (ConfigurationManager.RangeChecks && (Math.Abs(plyX - tileX) > 32 || Math.Abs(plyY - tileY) > 32)))
|
||||
{
|
||||
Log.Debug(string.Format("SendTileSquare(PlyXY:{0}_{1}, TileXY:{2}_{3}, Result:{4}_{5}, Size:{6})",
|
||||
plyX, plyY,
|
||||
tileX, tileY,
|
||||
Math.Abs(plyX - tileX), Math.Abs(plyY - tileY),
|
||||
size
|
||||
));
|
||||
return Tools.HandleGriefer(Players[e.Msg.whoAmI], "Send Tile Square Abuse");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool HandleTile(MemoryStream data, GetDataEventArgs e)
|
||||
{
|
||||
byte type = data.ReadInt8();
|
||||
int x = data.ReadInt32();
|
||||
int y = data.ReadInt32();
|
||||
byte tiletype = data.ReadInt8();
|
||||
if (type == 1 || type == 3)
|
||||
{
|
||||
int plyX = Math.Abs((int)Main.player[e.Msg.whoAmI].position.X / 16);
|
||||
int plyY = Math.Abs((int)Main.player[e.Msg.whoAmI].position.Y / 16);
|
||||
int tileX = Math.Abs(x);
|
||||
int tileY = Math.Abs(y);
|
||||
|
||||
if (Players[e.Msg.whoAmI].TPlayer.selectedItem == 0x72) //Dirt Rod
|
||||
{
|
||||
return Tools.Kick(Players[e.Msg.whoAmI], "Using dirt rod");
|
||||
}
|
||||
|
||||
if (ConfigurationManager.RangeChecks && ((Math.Abs(plyX - tileX) > 32) || (Math.Abs(plyY - tileY) > 32)))
|
||||
{
|
||||
Log.Debug(string.Format("TilePlaced(PlyXY:{0}_{1}, TileXY:{2}_{3}, Result:{4}_{5}, Type:{6})",
|
||||
plyX, plyY,
|
||||
tileX, tileY,
|
||||
Math.Abs(plyX - tileX), Math.Abs(plyY - tileY),
|
||||
tiletype
|
||||
));
|
||||
return Tools.HandleGriefer(Players[e.Msg.whoAmI], "Placing impossible to place blocks.");
|
||||
}
|
||||
}
|
||||
if (ConfigurationManager.DisableBuild)
|
||||
{
|
||||
if (!Players[e.Msg.whoAmI].Group.HasPermission("editspawn"))
|
||||
{
|
||||
Players[e.Msg.whoAmI].SendMessage("World protected from changes.", Color.Red);
|
||||
RevertPlayerChanges(e.Msg.whoAmI, x, y);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (ConfigurationManager.SpawnProtect)
|
||||
{
|
||||
if (!Players[e.Msg.whoAmI].Group.HasPermission("editspawn"))
|
||||
{
|
||||
var flag = CheckSpawn(x, y);
|
||||
if (flag)
|
||||
{
|
||||
Players[e.Msg.whoAmI].SendMessage("Spawn protected from changes.", Color.Red);
|
||||
RevertPlayerChanges(e.Msg.whoAmI, x, y);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (type == 0 && BlacklistTiles[Main.tile[x, y].type] && Main.player[e.Msg.whoAmI].active)
|
||||
{
|
||||
Players[e.Msg.whoAmI].TileThreshold++;
|
||||
var coords = new Vector2(x, y);
|
||||
if (!Players[e.Msg.whoAmI].TilesDestroyed.ContainsKey(coords))
|
||||
Players[e.Msg.whoAmI].TilesDestroyed.Add(coords, Main.tile[x, y]);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void RevertPlayerChanges(int player, int x, int y)
|
||||
{
|
||||
NetMessage.SendData(20, player, -1, "", 10, (float)(x - 5), (float)(y - 5), 0f);
|
||||
}
|
||||
|
||||
bool HandleTogglePvp(MemoryStream data, GetDataEventArgs e)
|
||||
{
|
||||
int id = data.ReadByte();
|
||||
bool pvp = data.ReadBoolean();
|
||||
|
||||
Main.player[e.Msg.whoAmI].hostile = pvp;
|
||||
if (id != e.Msg.whoAmI)
|
||||
Main.player[e.Msg.whoAmI].hostile = true;
|
||||
if (ConfigurationManager.PermaPvp)
|
||||
Main.player[e.Msg.whoAmI].hostile = true;
|
||||
NetMessage.SendData(30, -1, -1, "", e.Msg.whoAmI);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool HandleSendSection(MemoryStream data, GetDataEventArgs e)
|
||||
{
|
||||
return Tools.HandleGriefer(Players[e.Msg.whoAmI], "SendSection abuse.");
|
||||
}
|
||||
|
||||
bool HandleNpcUpdate(MemoryStream data, GetDataEventArgs e)
|
||||
{
|
||||
return Tools.HandleGriefer(Players[e.Msg.whoAmI], "Spawn NPC abuse");
|
||||
}
|
||||
|
||||
bool HandlePlayerUpdate(MemoryStream data, GetDataEventArgs e)
|
||||
{
|
||||
byte plr = data.ReadInt8();
|
||||
byte control = data.ReadInt8();
|
||||
byte item = data.ReadInt8();
|
||||
float posx = data.ReadSingle();
|
||||
float posy = data.ReadSingle();
|
||||
float velx = data.ReadSingle();
|
||||
float vely = data.ReadSingle();
|
||||
|
||||
if (Main.verboseNetplay)
|
||||
Debug.WriteLine("Update: {{{0},{1}}} {{{2}, {3}}}", (int)posx, (int)posy, (int)velx, (int)vely);
|
||||
|
||||
if (plr != e.Msg.whoAmI)
|
||||
{
|
||||
return Tools.HandleGriefer(Players[e.Msg.whoAmI], "Update Player abuse");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool HandleProjectileNew(MemoryStream data, GetDataEventArgs e)
|
||||
{
|
||||
short ident = data.ReadInt16();
|
||||
float posx = data.ReadSingle();
|
||||
float posy = data.ReadSingle();
|
||||
float velx = data.ReadSingle();
|
||||
float vely = data.ReadSingle();
|
||||
float knockback = data.ReadSingle();
|
||||
short dmg = data.ReadInt16();
|
||||
byte owner = data.ReadInt8();
|
||||
byte type = data.ReadInt8();
|
||||
|
||||
if (type == 29 || type == 28 || type == 37)
|
||||
{
|
||||
var plr = Main.player[e.Msg.whoAmI];
|
||||
Log.Debug(string.Format("Explosive(PlyXY:{0}_{1}, Type:{2})",
|
||||
(int)(plr.position.X / 16),
|
||||
(int)(plr.position.Y / 16),
|
||||
type
|
||||
));
|
||||
return Tools.HandleExplosivesUser(Players[e.Msg.whoAmI], "Throwing an explosive device.");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool HandlePlayerKillMe(MemoryStream data, GetDataEventArgs e)
|
||||
{
|
||||
byte id = data.ReadInt8();
|
||||
byte hitdirection = data.ReadInt8();
|
||||
short dmg = data.ReadInt16();
|
||||
bool pvp = data.ReadBoolean();
|
||||
|
||||
if (id != e.Msg.whoAmI)
|
||||
{
|
||||
return Tools.HandleGriefer(Players[e.Msg.whoAmI], "Trying to execute KillMe on someone else.");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool HandlePlayerDamage(MemoryStream data, GetDataEventArgs e)
|
||||
{
|
||||
byte playerid = data.ReadInt8();
|
||||
byte direction = data.ReadInt8();
|
||||
Int16 damage = data.ReadInt16();
|
||||
byte pvp = data.ReadInt8();
|
||||
|
||||
return !Main.player[playerid].hostile;
|
||||
}
|
||||
|
||||
bool HandleLiquidSet(MemoryStream data, GetDataEventArgs e)
|
||||
{
|
||||
int x = data.ReadInt32();
|
||||
int y = data.ReadInt32();
|
||||
byte liquid = data.ReadInt8();
|
||||
bool lava = data.ReadBoolean();
|
||||
|
||||
//The liquid was picked up.
|
||||
if (liquid == 0)
|
||||
return false;
|
||||
|
||||
int plyX = Math.Abs((int)Main.player[e.Msg.whoAmI].position.X / 16);
|
||||
int plyY = Math.Abs((int)Main.player[e.Msg.whoAmI].position.Y / 16);
|
||||
int tileX = Math.Abs(x);
|
||||
int tileY = Math.Abs(y);
|
||||
|
||||
bool bucket = false;
|
||||
for (int i = 0; i < 44; i++)
|
||||
{
|
||||
if (Main.player[e.Msg.whoAmI].inventory[i].type >= 205 && Main.player[e.Msg.whoAmI].inventory[i].type <= 207)
|
||||
{
|
||||
bucket = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (lava && !Players[e.Msg.whoAmI].Group.HasPermission("canlava"))
|
||||
{
|
||||
Players[e.Msg.whoAmI].SendMessage("You do not have permission to use lava", Color.Red);
|
||||
Tools.SendLogs(string.Format("{0} tried using lava", Main.player[e.Msg.whoAmI].name), Color.Red);
|
||||
|
||||
return true;
|
||||
}
|
||||
if (!lava && !Players[e.Msg.whoAmI].Group.HasPermission("canwater"))
|
||||
{
|
||||
Players[e.Msg.whoAmI].SendMessage("You do not have permission to use water", Color.Red);
|
||||
Tools.SendLogs(string.Format("{0} tried using water", Main.player[e.Msg.whoAmI].name), Color.Red);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!bucket)
|
||||
{
|
||||
Log.Debug(string.Format("{0}(PlyXY:{1}_{2}, TileXY:{3}_{4}, Result:{5}_{6}, Amount:{7})",
|
||||
lava ? "Lava" : "Water",
|
||||
plyX, plyY,
|
||||
tileX, tileY,
|
||||
Math.Abs(plyX - tileX), Math.Abs(plyY - tileY),
|
||||
liquid
|
||||
));
|
||||
return Tools.HandleGriefer(Players[e.Msg.whoAmI], "Manipulating liquid without bucket."); ;
|
||||
}
|
||||
if (ConfigurationManager.RangeChecks && ((Math.Abs(plyX - tileX) > 32) || (Math.Abs(plyY - tileY) > 32)))
|
||||
{
|
||||
Log.Debug(string.Format("Liquid(PlyXY:{0}_{1}, TileXY:{2}_{3}, Result:{4}_{5}, Amount:{6})",
|
||||
plyX, plyY,
|
||||
tileX, tileY,
|
||||
Math.Abs(plyX - tileX), Math.Abs(plyY - tileY),
|
||||
liquid
|
||||
));
|
||||
return Tools.HandleGriefer(Players[e.Msg.whoAmI], "Placing impossible to place liquid."); ;
|
||||
}
|
||||
|
||||
if (ConfigurationManager.SpawnProtect)
|
||||
{
|
||||
if (!Players[e.Msg.whoAmI].Group.HasPermission("editspawn"))
|
||||
{
|
||||
var flag = CheckSpawn(x, y);
|
||||
if (flag)
|
||||
{
|
||||
Players[e.Msg.whoAmI].SendMessage("The spawn is protected!", Color.Red);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool HandleTileKill(MemoryStream data, GetDataEventArgs e)
|
||||
{
|
||||
int tilex = data.ReadInt32();
|
||||
int tiley = data.ReadInt32();
|
||||
if (tilex < 0 || tilex >= Main.maxTilesX || tiley < 0 || tiley >= Main.maxTilesY)
|
||||
return false;
|
||||
|
||||
if (Main.tile[tilex, tiley].type != 0x15) //Chest
|
||||
{
|
||||
Log.Debug(string.Format("TileKill(TileXY:{0}_{1}, Type:{2})",
|
||||
tilex, tiley,
|
||||
Main.tile[tilex, tiley].type
|
||||
));
|
||||
Tools.ForceKick(Players[e.Msg.whoAmI], string.Format("Tile Kill abuse ({0})", Main.tile[tilex, tiley].type));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void OnGreetPlayer(int who, HandledEventArgs e)
|
||||
{
|
||||
if (Main.netMode != 2)
|
||||
|
|
@ -637,144 +377,14 @@ namespace TShockAPI
|
|||
e.Handled = true;
|
||||
}
|
||||
|
||||
private void OnChat(messageBuffer msg, int ply, string text, HandledEventArgs e)
|
||||
private void NpcHooks_OnStrikeNpc(NpcStrikeEventArgs e)
|
||||
{
|
||||
if (Main.netMode != 2)
|
||||
return;
|
||||
|
||||
if (msg.whoAmI != ply)
|
||||
if (ConfigurationManager.InfiniteInvasion)
|
||||
{
|
||||
e.Handled = Tools.HandleGriefer(Players[ply], "Faking Chat");
|
||||
return;
|
||||
}
|
||||
|
||||
var tsplr = Players[msg.whoAmI];
|
||||
|
||||
if (tsplr.Group.HasPermission("adminchat") && !text.StartsWith("/"))
|
||||
{
|
||||
Tools.Broadcast(ConfigurationManager.AdminChatPrefix + "<" + tsplr.Name + "> " + text,
|
||||
(byte)ConfigurationManager.AdminChatRGB[0], (byte)ConfigurationManager.AdminChatRGB[1], (byte)ConfigurationManager.AdminChatRGB[2]);
|
||||
e.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (text.StartsWith("/"))
|
||||
{
|
||||
if (Commands.HandleCommand(tsplr, text))
|
||||
e.Handled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Info(string.Format("{0} said: {1}", tsplr.Name, text));
|
||||
}
|
||||
}
|
||||
|
||||
private void OnJoin(int ply, HandledEventArgs handler)
|
||||
{
|
||||
if (Main.netMode != 2)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var player = new TSPlayer(ply);
|
||||
player.Group = Tools.GetGroupForIP(player.IP);
|
||||
|
||||
if (Tools.ActivePlayers() + 1 > ConfigurationManager.MaxSlots &&
|
||||
!player.Group.HasPermission("reservedslot"))
|
||||
{
|
||||
Tools.ForceKick(player, "Server is full");
|
||||
handler.Handled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
var ban = Bans.GetBanByIp(player.IP);
|
||||
if (ban != null)
|
||||
IncrementKills();
|
||||
if (Main.invasionSize < 10)
|
||||
{
|
||||
Tools.ForceKick(player, string.Format("You are banned: {0}", ban.Reason));
|
||||
handler.Handled = true;
|
||||
}
|
||||
else if (!FileTools.OnWhitelist(player.IP))
|
||||
{
|
||||
Tools.ForceKick(player, "Not on whitelist.");
|
||||
handler.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
Players[ply] = player;
|
||||
Netplay.serverSock[ply].spamCheck = ConfigurationManager.SpamChecks;
|
||||
}
|
||||
|
||||
private void OnLeave(int ply)
|
||||
{
|
||||
if (Main.netMode != 2)
|
||||
return;
|
||||
|
||||
var tsplr = Players[ply];
|
||||
if (tsplr != null && tsplr.ReceivedInfo)
|
||||
Log.Info(string.Format("{0} left.", tsplr.Name));
|
||||
|
||||
Players[ply] = null;
|
||||
}
|
||||
|
||||
private void OnPostInit()
|
||||
{
|
||||
if (!File.Exists(Path.Combine(SavePath, "auth.lck")))
|
||||
{
|
||||
var r = new Random((int)DateTime.Now.ToBinary());
|
||||
ConfigurationManager.AuthToken = r.Next(100000, 10000000);
|
||||
Console.WriteLine("TShock Notice: To become SuperAdmin, join the game and type /auth " +
|
||||
ConfigurationManager.AuthToken);
|
||||
Console.WriteLine("This token will only display ONCE. This only works ONCE. If you don't use it and the server goes down, delete auth.lck.");
|
||||
FileTools.CreateFile(Path.Combine(SavePath, "auth.lck"));
|
||||
}
|
||||
}
|
||||
|
||||
void HandleCommandLine(string[] parms)
|
||||
{
|
||||
for (int i = 0; i < parms.Length; i++)
|
||||
{
|
||||
if (parms[i].ToLower() == "-ip")
|
||||
{
|
||||
IPAddress ip;
|
||||
if (IPAddress.TryParse(parms[++i], out ip))
|
||||
{
|
||||
Netplay.serverListenIP = ip;
|
||||
Console.Write("Using IP: {0}", ip);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Bad IP: {0}", parms[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnUpdate(GameTime time)
|
||||
{
|
||||
UpdateManager.UpdateProcedureCheck();
|
||||
foreach (TSPlayer player in TShock.Players)
|
||||
{
|
||||
if (player != null && player.Active)
|
||||
{
|
||||
if (player.TileThreshold >= 20)
|
||||
{
|
||||
if (Tools.HandleTntUser(player, "Kill tile abuse detected."))
|
||||
{
|
||||
RevertKillTile(player);
|
||||
player.TileThreshold = 0;
|
||||
player.TilesDestroyed.Clear();
|
||||
}
|
||||
else if (player.TileThreshold > 0)
|
||||
{
|
||||
player.TileThreshold = 0;
|
||||
player.TilesDestroyed.Clear();
|
||||
}
|
||||
|
||||
}
|
||||
else if (player.TileThreshold > 0)
|
||||
{
|
||||
player.TileThreshold = 0;
|
||||
}
|
||||
Main.invasionSize = 20000000;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -881,6 +491,11 @@ namespace TShockAPI
|
|||
NetMessage.SendData(26, -1, -1, "", player.Index, ((new Random()).Next(-1, 1)), damage, (float)0);
|
||||
}
|
||||
|
||||
public static void SendTileSquare(TSPlayer player, int x, int y, int size = 10)
|
||||
{
|
||||
NetMessage.SendData(20, player.Index, -1, "", size, (float)(x - (size / 2)), (float)(y - (size / 2)), 0f);
|
||||
}
|
||||
|
||||
//TODO : Notify the player if there is more than one match. (or do we want a First() kinda thing?)
|
||||
public static int GetNPCID(string name, bool exact = false)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue