Merge remote-tracking branch 'origin/general-devel' into general-devel

This commit is contained in:
Deathmax 2011-12-20 18:50:01 +08:00
commit 4628cb2ae6
6 changed files with 136 additions and 56 deletions

View file

@ -141,9 +141,6 @@ namespace TShockAPI
[Description("This will save the world if Terraria crashes from an unhandled exception.")] [Description("This will save the world if Terraria crashes from an unhandled exception.")]
public bool SaveWorldOnCrash = true; public bool SaveWorldOnCrash = true;
[Description("This is kick players who have custom items in their inventory (via a mod)")]
public bool KickCustomItems = false;
[Description("This will announce a player's location on join")] [Description("This will announce a player's location on join")]
public bool EnableGeoIP = false; public bool EnableGeoIP = false;

View file

@ -27,11 +27,11 @@ namespace TShockAPI.DB
creator.EnsureExists(table); creator.EnsureExists(table);
//Add default groups //Add default groups
AddGroup("default", "canwater,canlava,warp,canbuild"); AddGroup("default", "warp,canbuild");
AddGroup("newadmin", "default", "kick,editspawn,reservedslot"); AddGroup("newadmin", "default", "kick,editspawn,reservedslot");
AddGroup("admin", "newadmin", "ban,unban,whitelist,causeevents,spawnboss,spawnmob,managewarp,time,tp,pvpfun,kill,logs,immunetokick,tphere"); AddGroup("admin", "newadmin", "ban,unban,whitelist,causeevents,spawnboss,spawnmob,managewarp,time,tp,pvpfun,kill,logs,immunetokick,tphere");
AddGroup("trustedadmin", "admin", "maintenance,cfg,butcher,item,heal,immunetoban,ignorecheatdetection,ignoregriefdetection,usebanneditem,manageusers"); AddGroup("trustedadmin", "admin", "maintenance,cfg,butcher,item,heal,immunetoban,ignorecheatdetection,usebanneditem,manageusers");
AddGroup("vip", "default", "canwater,canlava,warp,canbuild,reservedslot"); AddGroup("vip", "default", "reservedslot");
String file = Path.Combine(TShock.SavePath, "groups.txt"); String file = Path.Combine(TShock.SavePath, "groups.txt");
if (File.Exists(file)) if (File.Exists(file))

View file

@ -25,6 +25,7 @@ using Terraria;
using TShockAPI.Net; using TShockAPI.Net;
using System.IO.Streams; using System.IO.Streams;
using System.Net;
namespace TShockAPI namespace TShockAPI
{ {
@ -210,7 +211,30 @@ namespace TShockAPI
return true; return true;
} }
args.Player.Difficulty = difficulty; args.Player.Difficulty = difficulty;
args.TPlayer.name = name;
args.Player.ReceivedInfo = true; args.Player.ReceivedInfo = true;
NetMessage.SendData((int)PacketTypes.TimeSet, -1, -1, "", 0, 0, Main.sunModY, Main.moonModY);
if (TShock.Config.EnableGeoIP && TShock.Geo != null)
{
var code = TShock.Geo.TryGetCountryCode(IPAddress.Parse(args.Player.IP));
args.Player.Country = code == null ? "N/A" : MaxMind.GeoIPCountry.GetCountryNameByCode(code);
if (code == "A1")
if (TShock.Config.KickProxyUsers)
TShock.Utils.Kick(args.Player, "Proxies are not allowed");
Log.Info(string.Format("{0} ({1}) from '{2}' group from '{3}' joined.", args.Player.Name, args.Player.IP, args.Player.Group.Name, args.Player.Country));
TShock.Utils.Broadcast(args.Player.Name + " has joined from the " + args.Player.Country, Color.Yellow);
}
else
{
Log.Info(string.Format("{0} ({1}) from '{2}' group joined.", args.Player.Name, args.Player.IP, args.Player.Group.Name));
TShock.Utils.Broadcast(args.Player.Name + " has joined", Color.Yellow);
}
if (TShock.Config.DisplayIPToAdmins)
TShock.Utils.SendLogs(string.Format("{0} has joined. IP: {1}", args.Player.Name, args.Player.IP), Color.Blue);
return false; return false;
} }
@ -230,6 +254,12 @@ namespace TShockAPI
return true; return true;
} }
if (TShock.Config.AlwaysPvP && !args.TPlayer.hostile)
{
args.Player.SendTileSquare(tileX, tileY);
return true;
}
var tiles = new NetTile[size, size]; var tiles = new NetTile[size, size];
for (int x = 0; x < size; x++) for (int x = 0; x < size; x++)
@ -440,6 +470,12 @@ namespace TShockAPI
} }
} }
if (TShock.Config.AlwaysPvP && !args.TPlayer.hostile)
{
args.Player.SendTileSquare(tileX, tileY);
return true;
}
if (TShock.CheckTilePermission(args.Player, tileX, tileY)) if (TShock.CheckTilePermission(args.Player, tileX, tileY))
{ {
args.Player.SendTileSquare(tileX, tileY); args.Player.SendTileSquare(tileX, tileY);
@ -468,17 +504,24 @@ namespace TShockAPI
int id = args.Data.ReadByte(); int id = args.Data.ReadByte();
bool pvp = args.Data.ReadBoolean(); bool pvp = args.Data.ReadBoolean();
long seconds = (long)(DateTime.UtcNow - args.Player.LastPvpChange).TotalSeconds; if (id != args.Player.Index)
if (TShock.Config.PvpThrottle > 0 && seconds < TShock.Config.PvpThrottle)
{ {
args.Player.SendMessage(string.Format("You cannot change pvp status for {0} seconds", TShock.Config.PvpThrottle - seconds), 255, 0, 0); return true;
args.Player.SetPvP(id != args.Player.Index || TShock.Config.AlwaysPvP ? true : args.TPlayer.hostile);
} }
else
if (args.TPlayer.hostile != pvp)
{ {
args.Player.SetPvP(id != args.Player.Index || TShock.Config.AlwaysPvP ? true : pvp); long seconds = (long)(DateTime.UtcNow - args.Player.LastPvpChange).TotalSeconds;
if (TShock.Config.PvpThrottle > 0 && seconds < TShock.Config.PvpThrottle)
{
TSPlayer.All.SendMessage(string.Format("{0} has {1} PvP!", args.Player.Name, pvp ? "enabled" : "disabled"), Main.teamColor[args.Player.Team]);
}
args.Player.LastPvpChange = DateTime.UtcNow;
} }
args.TPlayer.hostile = pvp;
NetMessage.SendData((int)PacketTypes.TogglePvp, -1, -1, "", args.Player.Index);
return true; return true;
} }
@ -505,14 +548,25 @@ namespace TShockAPI
} }
} }
if (TShock.CheckPlayerCollision((int)(pos.X / 16f), (int)(pos.Y / 16f))) //NoClipping or possible errors if (!pos.Equals(args.Player.LastNetPosition))
{ {
args.Player.SendMessage("You got stuck in a solid object! Sent you to the spawn point.", Color.Red); float distance = Vector2.Distance(new Vector2((pos.X / 16f), (pos.Y / 16f)), new Vector2(Main.spawnTileX, Main.spawnTileY));
args.Player.SendTileSquare((int)(pos.X / 16f), (int)(pos.X / 16f)); if (TShock.Config.AlwaysPvP && !args.TPlayer.hostile && distance > 6f)
args.Player.Spawn(); {
return true; args.Player.SendMessage("PvP is forced! Enable PvP else you can't do anything!", Color.Red);
args.Player.Spawn();
return true;
}
if (TShock.CheckPlayerCollision((int)(pos.X / 16f), (int)(pos.Y / 16f))) //NoClipping or possible errors
{
args.Player.SendMessage("You got stuck in a solid object! Sent you to the spawn point.", Color.Red);
args.Player.SendTileSquare((int)(pos.X / 16f), (int)(pos.X / 16f));
args.Player.Spawn();
return true;
}
} }
args.Player.LastNetPosition = pos;
return false; return false;
} }
@ -545,6 +599,12 @@ namespace TShockAPI
return true; return true;
} }
if (TShock.Config.AlwaysPvP && !args.TPlayer.hostile)
{
args.Player.SendData(PacketTypes.ProjectileNew, "", index);
return true;
}
if (TShock.CheckProjectilePermission(args.Player, index, type)) if (TShock.CheckProjectilePermission(args.Player, index, type))
{ {
args.Player.LastThreat = DateTime.UtcNow; args.Player.LastThreat = DateTime.UtcNow;
@ -580,6 +640,12 @@ namespace TShockAPI
return true; return true;
} }
if (TShock.Config.AlwaysPvP && !args.TPlayer.hostile)
{
args.Player.SendData(PacketTypes.ProjectileNew, "", index);
return true;
}
if (TShock.CheckProjectilePermission(args.Player, index, type)) if (TShock.CheckProjectilePermission(args.Player, index, type))
{ {
args.Player.LastThreat = DateTime.UtcNow; args.Player.LastThreat = DateTime.UtcNow;
@ -630,6 +696,12 @@ namespace TShockAPI
if (tileX < 0 || tileX >= Main.maxTilesX || tileY < 0 || tileY >= Main.maxTilesY) if (tileX < 0 || tileX >= Main.maxTilesX || tileY < 0 || tileY >= Main.maxTilesY)
return false; return false;
if (TShock.Config.AlwaysPvP && !args.TPlayer.hostile)
{
args.Player.SendTileSquare(tileX, tileY);
return true;
}
if ((DateTime.UtcNow - args.Player.LastThreat).TotalMilliseconds < 5000) if ((DateTime.UtcNow - args.Player.LastThreat).TotalMilliseconds < 5000)
{ {
args.Player.SendTileSquare(tileX, tileY); args.Player.SendTileSquare(tileX, tileY);
@ -679,6 +751,12 @@ namespace TShockAPI
if (tileX < 0 || tileX >= Main.maxTilesX || tileY < 0 || tileY >= Main.maxTilesY) if (tileX < 0 || tileX >= Main.maxTilesX || tileY < 0 || tileY >= Main.maxTilesY)
return false; return false;
if (TShock.Config.AlwaysPvP && !args.TPlayer.hostile)
{
args.Player.SendTileSquare(tileX, tileY);
return true;
}
if (Main.tile[tileX, tileY].type != 0x15 && (!TShock.Utils.MaxChests() && Main.tile[tileX, tileY].type != 0)) //Chest if (Main.tile[tileX, tileY].type != 0x15 && (!TShock.Utils.MaxChests() && Main.tile[tileX, tileY].type != 0)) //Chest
{ {
args.Player.SendTileSquare(tileX, tileY); args.Player.SendTileSquare(tileX, tileY);
@ -730,6 +808,11 @@ namespace TShockAPI
var x = args.Data.ReadInt32(); var x = args.Data.ReadInt32();
var y = args.Data.ReadInt32(); var y = args.Data.ReadInt32();
if (TShock.Config.AlwaysPvP && !args.TPlayer.hostile)
{
return true;
}
if (TShock.Config.RangeChecks && ((Math.Abs(args.Player.TileX - x) > 32) || (Math.Abs(args.Player.TileY - y) > 32))) if (TShock.Config.RangeChecks && ((Math.Abs(args.Player.TileX - x) > 32) || (Math.Abs(args.Player.TileY - y) > 32)))
{ {
return true; return true;
@ -750,6 +833,12 @@ namespace TShockAPI
return false; return false;
} }
if (TShock.Config.AlwaysPvP && !args.TPlayer.hostile)
{
args.Player.SendData(PacketTypes.ChestItem, "", id, slot);
return true;
}
Item item = new Item(); Item item = new Item();
item.netDefaults(type); item.netDefaults(type);
if (stacks > item.maxStack || TShock.Itembans.ItemIsBanned(item.name)) if (stacks > item.maxStack || TShock.Itembans.ItemIsBanned(item.name))
@ -818,6 +907,11 @@ namespace TShockAPI
var type = args.Data.ReadInt8(); var type = args.Data.ReadInt8();
var time = args.Data.ReadInt16(); var time = args.Data.ReadInt16();
if (TShock.Config.AlwaysPvP && !args.TPlayer.hostile)
{
args.Player.SendData(PacketTypes.PlayerBuff, "", id);
return true;
}
if (!TShock.Players[id].TPlayer.hostile) if (!TShock.Players[id].TPlayer.hostile)
{ {
args.Player.SendData(PacketTypes.PlayerBuff, "", id); args.Player.SendData(PacketTypes.PlayerBuff, "", id);
@ -869,6 +963,13 @@ namespace TShockAPI
args.Player.SendData(PacketTypes.ItemDrop, "", id); args.Player.SendData(PacketTypes.ItemDrop, "", id);
return true; return true;
} }
if (TShock.Config.AlwaysPvP && !args.TPlayer.hostile)
{
args.Player.SendData(PacketTypes.ItemDrop, "", id);
return true;
}
return false; return false;
} }
@ -908,6 +1009,13 @@ namespace TShockAPI
return true; return true;
} }
if (TShock.Config.AlwaysPvP && !args.TPlayer.hostile)
{
args.Player.SendData(PacketTypes.PlayerHp, "", id);
args.Player.SendData(PacketTypes.PlayerUpdate, "", id);
return true;
}
if (TShock.Config.RangeChecks && ((Math.Abs(args.Player.TileX - TShock.Players[id].TileX) > 128) || (Math.Abs(args.Player.TileY - TShock.Players[id].TileY) > 128))) if (TShock.Config.RangeChecks && ((Math.Abs(args.Player.TileX - TShock.Players[id].TileX) > 128) || (Math.Abs(args.Player.TileY - TShock.Players[id].TileY) > 128)))
{ {
args.Player.SendData(PacketTypes.PlayerHp, "", id); args.Player.SendData(PacketTypes.PlayerHp, "", id);
@ -942,6 +1050,12 @@ namespace TShockAPI
return true; return true;
} }
if (TShock.Config.AlwaysPvP && !args.TPlayer.hostile)
{
args.Player.SendData(PacketTypes.NpcUpdate, "", id);
return true;
}
if (Main.npc[id].townNPC && !args.Player.Group.HasPermission(Permissions.movenpc)) if (Main.npc[id].townNPC && !args.Player.Group.HasPermission(Permissions.movenpc))
{ {
args.Player.SendData(PacketTypes.NpcUpdate, "", id); args.Player.SendData(PacketTypes.NpcUpdate, "", id);

View file

@ -37,7 +37,7 @@ namespace TShockAPI
public Group Group { get; set; } public Group Group { get; set; }
public bool ReceivedInfo { get; set; } public bool ReceivedInfo { get; set; }
public int Index { get; protected set; } public int Index { get; protected set; }
public DateTime LastPvpChange { get; protected set; } public DateTime LastPvpChange;
public Point[] TempPoints = new Point[2]; public Point[] TempPoints = new Point[2];
public int AwaitingTempPoint { get; set; } public int AwaitingTempPoint { get; set; }
public bool AwaitingName { get; set; } public bool AwaitingName { get; set; }
@ -49,6 +49,7 @@ namespace TShockAPI
public TSPlayer LastWhisper; public TSPlayer LastWhisper;
public int LoginAttempts { get; set; } public int LoginAttempts { get; set; }
public Vector2 TeleportCoords = new Vector2(-1, -1); public Vector2 TeleportCoords = new Vector2(-1, -1);
public Vector2 LastNetPosition = Vector2.Zero;
public string UserAccountName { get; set; } public string UserAccountName { get; set; }
public bool HasBeenSpammedWithBuildMessage; public bool HasBeenSpammedWithBuildMessage;
public bool IsLoggedIn; public bool IsLoggedIn;
@ -262,7 +263,8 @@ namespace TShockAPI
{ {
try try
{ {
SendData(PacketTypes.TileSendSquare, "", size, (x - (size / 2)), (y - (size / 2))); int num = (size - 1) / 2;
SendData(PacketTypes.TileSendSquare, "", size, (float)(x - num), (float)(y - num));
return true; return true;
} }
catch (Exception ex) catch (Exception ex)
@ -306,18 +308,6 @@ namespace TShockAPI
NetMessage.SendData((int)PacketTypes.PlayerDamage, -1, -1, "", Index, ((new Random()).Next(-1, 1)), damage, (float)0); NetMessage.SendData((int)PacketTypes.PlayerDamage, -1, -1, "", Index, ((new Random()).Next(-1, 1)), damage, (float)0);
} }
public virtual void SetPvP(bool pvp)
{
if (TPlayer.hostile != pvp)
{
LastPvpChange = DateTime.UtcNow;
TPlayer.hostile = pvp;
All.SendMessage(string.Format("{0} has {1} PvP!", Name, pvp ? "enabled" : "disabled"), Main.teamColor[Team]);
}
//Broadcast anyways to keep players synced
NetMessage.SendData((int)PacketTypes.TogglePvp, -1, -1, "", Index);
}
public virtual void SetTeam(int team) public virtual void SetTeam(int team)
{ {
Main.player[Index].team = team; Main.player[Index].team = team;

View file

@ -715,36 +715,17 @@ namespace TShockAPI
return; return;
} }
NetMessage.SendData((int)PacketTypes.TimeSet, -1, -1, "", 0, 0, Main.sunModY, Main.moonModY);
NetMessage.syncPlayers();
if (Config.EnableGeoIP && Geo != null)
{
var code = Geo.TryGetCountryCode(IPAddress.Parse(player.IP));
player.Country = code == null ? "N/A" : MaxMind.GeoIPCountry.GetCountryNameByCode(code);
if (code == "A1")
if (TShock.Config.KickProxyUsers)
TShock.Utils.Kick(player, "Proxies are not allowed");
Log.Info(string.Format("{0} ({1}) from '{2}' group from '{3}' joined.", player.Name, player.IP, player.Group.Name, player.Country));
TShock.Utils.Broadcast(player.Name + " has joined from the " + player.Country, Color.Yellow);
}
else
{
Log.Info(string.Format("{0} ({1}) from '{2}' group joined.", player.Name, player.IP, player.Group.Name));
TShock.Utils.Broadcast(player.Name + " has joined", Color.Yellow);
}
TShock.Utils.ShowFileToUser(player, "motd.txt"); TShock.Utils.ShowFileToUser(player, "motd.txt");
if (HackedHealth(player)) if (HackedHealth(player))
{ {
TShock.Utils.HandleCheater(player, "Health/Mana cheat detected. Please use a different character."); TShock.Utils.HandleCheater(player, "Health/Mana cheat detected. Please use a different character.");
} }
NetMessage.syncPlayers();
if (Config.AlwaysPvP) if (Config.AlwaysPvP)
{ {
player.SetPvP(true); player.SendMessage("PvP is forced! Enable PvP else you can't move or do anything!", Color.Red);
player.SendMessage(
"PvP is forced! Enable PvP else you can't deal damage to other people. (People can kill you)",
Color.Red);
} }
if (player.Group.HasPermission(Permissions.causeevents) && Config.InfiniteInvasion) if (player.Group.HasPermission(Permissions.causeevents) && Config.InfiniteInvasion)
{ {
@ -756,8 +737,6 @@ namespace TShockAPI
player.Teleport((int)pos.X, (int)pos.Y); player.Teleport((int)pos.X, (int)pos.Y);
player.SendTileSquare((int)pos.X, (int)pos.Y); player.SendTileSquare((int)pos.X, (int)pos.Y);
} }
if (Config.DisplayIPToAdmins)
Utils.SendLogs(string.Format("{0} has joined. IP: {1}", player.Name, player.IP), Color.Blue);
e.Handled = true; e.Handled = true;
} }