Merge remote-tracking branch 'origin/general-devel' into oop
This commit is contained in:
commit
f74a0f6a70
9 changed files with 13 additions and 202 deletions
|
|
@ -1371,7 +1371,7 @@ namespace TShockAPI
|
|||
}
|
||||
|
||||
targetGeneralizedName = target.Name;
|
||||
success = TShock.Bans.AddBan2(target.IP, target.Name, target.UUID, target.Account.Name, banReason, false, args.Player.Account.Name,
|
||||
success = TShock.Bans.AddBan(target.IP, target.Name, target.UUID, target.Account.Name, banReason, false, args.Player.Account.Name,
|
||||
banLengthInSeconds == 0 ? "" : DateTime.UtcNow.AddSeconds(banLengthInSeconds).ToString("s"));
|
||||
|
||||
// Since this is an online ban, we need to dc the player and tell them now.
|
||||
|
|
@ -1401,7 +1401,7 @@ namespace TShockAPI
|
|||
Regex r = new Regex(pattern, RegexOptions.IgnoreCase);
|
||||
if (r.IsMatch(args.Parameters[1])) {
|
||||
targetGeneralizedName = "IP: " + args.Parameters[1];
|
||||
success = TShock.Bans.AddBan2(args.Parameters[1], "", "", "", banReason,
|
||||
success = TShock.Bans.AddBan(args.Parameters[1], "", "", "", banReason,
|
||||
false, args.Player.Account.Name, banLengthInSeconds == 0 ? "" : DateTime.UtcNow.AddSeconds(banLengthInSeconds).ToString("s"));
|
||||
if (success && offlineUserAccount != null)
|
||||
{
|
||||
|
|
@ -1449,7 +1449,7 @@ namespace TShockAPI
|
|||
string lastIP = JsonConvert.DeserializeObject<List<string>>(offlineUserAccount.KnownIps).Last();
|
||||
|
||||
success =
|
||||
TShock.Bans.AddBan2(lastIP,
|
||||
TShock.Bans.AddBan(lastIP,
|
||||
"", offlineUserAccount.UUID, offlineUserAccount.Name, banReason, false, args.Player.Account.Name,
|
||||
banLengthInSeconds == 0 ? "" : DateTime.UtcNow.AddSeconds(banLengthInSeconds).ToString("s"));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -516,11 +516,6 @@ namespace TShockAPI
|
|||
[Description("How often in minutes the REST requests bucket is decreased by one. Minimum value is 1 minute.")]
|
||||
public int RESTRequestBucketDecreaseIntervalMinutes = 1;
|
||||
|
||||
/// <summary>RESTLimitOnlyFailedLoginRequests - Whether or not to limit only the max failed login requests, or all login requests.</summary>
|
||||
[Obsolete("This value is no longer used and will be removed next version.")]
|
||||
[Description("Whether we should limit only the max failed login requests, or all login requests.")]
|
||||
public bool RESTLimitOnlyFailedLoginRequests = true;
|
||||
|
||||
/// <summary>ShowBackupAutosaveMessages - Whether or not to show backup auto save messages.</summary>
|
||||
[Description("Show backup autosave messages.")]
|
||||
public bool ShowBackupAutosaveMessages = true;
|
||||
|
|
|
|||
|
|
@ -205,24 +205,7 @@ namespace TShockAPI.DB
|
|||
/// <param name="exceptions">If set to <c>true</c> enable throwing exceptions.</param>
|
||||
/// <param name="banner">Banner.</param>
|
||||
/// <param name="expiration">Expiration date.</param>
|
||||
[Obsolete("Use AddBan2 instead of AddBan.", true)]
|
||||
public bool AddBan(string ip, string name = "", string uuid = "", string reason = "", bool exceptions = false, string banner = "", string expiration = "")
|
||||
{
|
||||
return AddBan2(ip, name, uuid, "", reason, exceptions, banner, expiration);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a ban.
|
||||
/// </summary>
|
||||
/// <returns><c>true</c>, if ban was added, <c>false</c> otherwise.</returns>
|
||||
/// <param name="ip">Ip.</param>
|
||||
/// <param name="name">Name.</param>
|
||||
/// <param name="uuid">UUID.</param>
|
||||
/// <param name="reason">Reason.</param>
|
||||
/// <param name="exceptions">If set to <c>true</c> enable throwing exceptions.</param>
|
||||
/// <param name="banner">Banner.</param>
|
||||
/// <param name="expiration">Expiration date.</param>
|
||||
public bool AddBan2(string ip, string name = "", string uuid = "", string accountName = "", string reason = "", bool exceptions = false, string banner = "", string expiration = "")
|
||||
public bool AddBan(string ip, string name = "", string uuid = "", string accountName = "", string reason = "", bool exceptions = false, string banner = "", string expiration = "")
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
|
|||
|
|
@ -250,30 +250,6 @@ namespace Rests
|
|||
}
|
||||
}
|
||||
|
||||
#region Event
|
||||
[Obsolete("This class will be removed in the next release")]
|
||||
public class RestRequestEventArgs : HandledEventArgs
|
||||
{
|
||||
public RequestEventArgs Request { get; set; }
|
||||
}
|
||||
|
||||
[Obsolete("This method will be removed in the next release")]
|
||||
public static HandlerList<RestRequestEventArgs> RestRequestEvent = new HandlerList<RestRequestEventArgs>();
|
||||
|
||||
private static bool OnRestRequestCall(RequestEventArgs request)
|
||||
{
|
||||
if (RestRequestEvent == null)
|
||||
return false;
|
||||
|
||||
var args = new RestRequestEventArgs
|
||||
{
|
||||
Request = request,
|
||||
};
|
||||
RestRequestEvent.Invoke(null, args);
|
||||
return args.Handled;
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Called when the <see cref="HttpListener"/> receives a request
|
||||
/// </summary>
|
||||
|
|
@ -285,9 +261,6 @@ namespace Rests
|
|||
if (obj == null)
|
||||
throw new NullReferenceException("obj");
|
||||
|
||||
if (OnRestRequestCall(e))
|
||||
return;
|
||||
|
||||
var str = JsonConvert.SerializeObject(obj, Formatting.Indented);
|
||||
var jsonp = e.Request.Parameters["jsonp"];
|
||||
if (!string.IsNullOrWhiteSpace(jsonp))
|
||||
|
|
|
|||
|
|
@ -624,7 +624,7 @@ namespace TShockAPI
|
|||
|
||||
try
|
||||
{
|
||||
TShock.Bans.AddBan2(ip, name, "", "", args.Parameters["reason"], true, args.TokenData.Username);
|
||||
TShock.Bans.AddBan(ip, name, "", "", args.Parameters["reason"], true, args.TokenData.Username);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
|
@ -1001,8 +1001,9 @@ namespace TShockAPI
|
|||
|
||||
TSPlayer player = (TSPlayer)ret;
|
||||
var reason = null == args.Parameters["reason"] ? "Banned via web" : args.Parameters["reason"];
|
||||
TShock.Bans.AddBan2(player.IP, player.Name, "", "", reason);
|
||||
TShock.Bans.AddBan(player.IP, player.Name, "", "", reason);
|
||||
player.Kick(reason, true, false, null, true);
|
||||
TShock.Utils.ForceKick(player, reason, false, true);
|
||||
return RestResponse("Player " + player.Name + " was banned");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1312,27 +1312,6 @@ namespace TShockAPI
|
|||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gives an item to the player. Includes banned item spawn prevention to check if the player can spawn the item.
|
||||
/// </summary>
|
||||
/// <param name="type">The item ID.</param>
|
||||
/// <param name="name">The item name.</param>
|
||||
/// <param name="width">The width of the receiver.</param>
|
||||
/// <param name="height">The height of the receiver.</param>
|
||||
/// <param name="stack">The item stack.</param>
|
||||
/// <param name="prefix">The item prefix.</param>
|
||||
/// <returns>True or false, depending if the item passed the check or not.</returns>
|
||||
[Obsolete("Use the GiveItemCheck overload with fewer parameters.")]
|
||||
public bool GiveItemCheck(int type, string name, int width, int height, int stack, int prefix = 0)
|
||||
{
|
||||
if ((TShock.Itembans.ItemIsBanned(name) && TShock.Config.PreventBannedItemSpawn) &&
|
||||
(TShock.Itembans.ItemIsBanned(name, this) || !TShock.Config.AllowAllowedGroupsToSpawnBannedItems))
|
||||
return false;
|
||||
|
||||
GiveItem(type, name, width, height, stack, prefix);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gives an item to the player.
|
||||
/// </summary>
|
||||
|
|
@ -1345,22 +1324,6 @@ namespace TShockAPI
|
|||
SendData(PacketTypes.ItemDrop, "", itemIndex);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gives an item to the player.
|
||||
/// </summary>
|
||||
/// <param name="type">The item ID.</param>
|
||||
/// <param name="name">The item name. This parameter is unused.</param>
|
||||
/// <param name="width">The width of the receiver.</param>
|
||||
/// <param name="height">The height of the receiver.</param>
|
||||
/// <param name="stack">The item stack.</param>
|
||||
/// <param name="prefix">The item prefix.</param>
|
||||
[Obsolete("Use the GiveItem overload with fewer parameters.")]
|
||||
public virtual void GiveItem(int type, string name, int width, int height, int stack, int prefix = 0)
|
||||
{
|
||||
int itemIndex = Item.NewItem((int)X, (int)Y, width, height, type, stack, true, prefix, true);
|
||||
SendData(PacketTypes.ItemDrop, "", itemIndex);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends an information message to the player.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -475,7 +475,7 @@ namespace TShockAPI
|
|||
{
|
||||
// A user just signed in successfully despite being banned by account name.
|
||||
// We should fix the ban database so that all of their ban info is up to date.
|
||||
Bans.AddBan2(args.Player.IP, args.Player.Name, args.Player.UUID, args.Player.Account.Name,
|
||||
Bans.AddBan(args.Player.IP, args.Player.Name, args.Player.UUID, args.Player.Account.Name,
|
||||
potentialBan.Reason, false, potentialBan.BanningUser, potentialBan.Expiration);
|
||||
|
||||
// And then get rid of them.
|
||||
|
|
@ -886,8 +886,6 @@ namespace TShockAPI
|
|||
Utils.ComputeMaxStyles();
|
||||
Utils.FixChestStacks();
|
||||
|
||||
Utils.UpgradeMotD();
|
||||
|
||||
if (Config.UseServerName)
|
||||
{
|
||||
Main.worldName = Config.ServerName;
|
||||
|
|
@ -1726,16 +1724,6 @@ namespace TShockAPI
|
|||
e.Handled = true;
|
||||
}
|
||||
|
||||
/// <summary>Distance - Determines the distance between two vectors.</summary>
|
||||
/// <param name="value1">value1 - The first vector location.</param>
|
||||
/// <param name="value2">value2 - The second vector location.</param>
|
||||
/// <returns>float - The distance between the two vectors.</returns>
|
||||
[Obsolete("Use TShock.Utils.Distance(Vector2, Vector2) instead.", true)]
|
||||
public static float Distance(Vector2 value1, Vector2 value2)
|
||||
{
|
||||
return Utils.Distance(value1, value2);
|
||||
}
|
||||
|
||||
/// <summary>OnConfigRead - Fired when the config file has been read.</summary>
|
||||
/// <param name="file">file - The config file object.</param>
|
||||
public void OnConfigRead(ConfigFile file)
|
||||
|
|
|
|||
|
|
@ -52,12 +52,6 @@ namespace TShockAPI
|
|||
/// <summary>instance - an instance of the utils class</summary>
|
||||
private static readonly Utils instance = new Utils();
|
||||
|
||||
/// <summary> This regex will look for the old MotD format for colors and replace them with the new chat format. </summary>
|
||||
private Regex motdColorRegex = new Regex(@"\%\s*(?<r>\d{1,3})\s*,\s*(?<g>\d{1,3})\s*,\s*(?<b>\d{1,3})\s*\%(?<text>((?!(\%\s*\d{1,3}\s*,\s*\d{1,3}\s*,\s*\d{1,3}\s*\%)|(\[[a-zA-Z]/[^:]+:[^\]]*\])).)*)");
|
||||
|
||||
/// <summary> Matches the start of a line with our legacy color format</summary>
|
||||
private Regex startOfLineColorRegex = new Regex(@"^\%\s*(?<r>\d{1,3})\s*,\s*(?<g>\d{1,3})\s*,\s*(?<b>\d{1,3})\s*\%");
|
||||
|
||||
/// <summary>Utils - Creates a utilities object.</summary>
|
||||
private Utils() {}
|
||||
|
||||
|
|
@ -409,7 +403,7 @@ namespace TShockAPI
|
|||
/// <returns>name</returns>
|
||||
public string GetBuffName(int id)
|
||||
{
|
||||
return (id > 0 && id < Main.maxBuffTypes) ? Lang.GetBuffName(id) : "null";
|
||||
return (id > 0 && id < Main.maxBuffTypes) ? Lang.GetBuffName(id) : null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -419,7 +413,7 @@ namespace TShockAPI
|
|||
/// <returns>description</returns>
|
||||
public string GetBuffDescription(int id)
|
||||
{
|
||||
return (id > 0 && id < Main.maxBuffTypes) ? Lang.GetBuffDescription(id) : "null";
|
||||
return (id > 0 && id < Main.maxBuffTypes) ? Lang.GetBuffDescription(id) : null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -528,7 +522,7 @@ namespace TShockAPI
|
|||
TShock.Regions.Reload();
|
||||
TShock.Itembans.UpdateItemBans();
|
||||
TShock.ProjectileBans.UpdateBans();
|
||||
TShock.TileBans.UpdateBans();
|
||||
TShock.TileBans.UpdateBans();
|
||||
Hooks.GeneralHooks.OnReloadEvent(player);
|
||||
}
|
||||
|
||||
|
|
@ -548,7 +542,7 @@ namespace TShockAPI
|
|||
string ip = player.IP;
|
||||
string uuid = player.UUID;
|
||||
string playerName = player.Name;
|
||||
TShock.Bans.AddBan2(ip, playerName, uuid, "", reason, false, adminUserName);
|
||||
TShock.Bans.AddBan(ip, playerName, uuid, "", reason, false, adminUserName);
|
||||
player.Disconnect(string.Format("Banned: {0}", reason));
|
||||
string verb = force ? "force " : "";
|
||||
if (string.IsNullOrWhiteSpace(adminUserName))
|
||||
|
|
@ -606,98 +600,11 @@ namespace TShockAPI
|
|||
foo = foo.Replace("%map%", (TShock.Config.UseServerName ? TShock.Config.ServerName : Main.worldName));
|
||||
foo = foo.Replace("%players%", String.Join(",", GetPlayers(false)));
|
||||
|
||||
var legacyColorMatch = startOfLineColorRegex.Match(foo);
|
||||
if (legacyColorMatch.Success)
|
||||
{
|
||||
lineColor = new Color(Int32.Parse(legacyColorMatch.Groups["r"].Value),
|
||||
Int32.Parse(legacyColorMatch.Groups["g"].Value),
|
||||
Int32.Parse(legacyColorMatch.Groups["b"].Value));
|
||||
foo = foo.Replace(legacyColorMatch.Groups[0].Value, "");
|
||||
}
|
||||
|
||||
bool upgraded = false;
|
||||
string newFoo = ReplaceDeprecatedColorCodes(foo, out upgraded);
|
||||
if (upgraded && !containsOldFormat)
|
||||
{
|
||||
TShock.Log.ConsoleInfo($"You are using an old color format in file {file}.");
|
||||
TShock.Log.ConsoleInfo("To send coloured text please use Terraria's inbuilt format of: [c/#hex:text].");
|
||||
TShock.Log.ConsoleInfo("For example: [c/ff00aa:This is a message!].");
|
||||
containsOldFormat = true;
|
||||
}
|
||||
foo = newFoo;
|
||||
|
||||
player.SendMessage(foo, lineColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a string with deprecated %###,###,###% formats replaced with the new chat format colors.
|
||||
/// </summary>
|
||||
/// <param name="input">The input string</param>
|
||||
/// <param name="upgradedFormat">An out parameter that denotes if this line of text was upgraded.</param>
|
||||
/// <returns>A replaced version of the input with the new chat color format.</returns>
|
||||
private string ReplaceDeprecatedColorCodes(string input, out bool upgradedFormat)
|
||||
{
|
||||
String tempString = input;
|
||||
Match match = null;
|
||||
bool uFormat = false;
|
||||
|
||||
while ((match = motdColorRegex.Match(tempString)).Success)
|
||||
{
|
||||
uFormat = true;
|
||||
tempString = tempString.Replace(match.Groups[0].Value, String.Format("[c/{0:X2}{1:X2}{2:X2}:{3}]", Int32.Parse(match.Groups["r"].Value), Int32.Parse(match.Groups["g"].Value), Int32.Parse(match.Groups["b"].Value), match.Groups["text"]));
|
||||
}
|
||||
|
||||
upgradedFormat = uFormat;
|
||||
return tempString;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Upgrades a legacy MotD file to the new terraria chat tags version.
|
||||
/// </summary>
|
||||
public void UpgradeMotD()
|
||||
{
|
||||
string foo = "";
|
||||
StringBuilder motd = new StringBuilder();
|
||||
bool informedOwner = false;
|
||||
using (var tr = new StreamReader(FileTools.MotdPath))
|
||||
{
|
||||
Color lineColor;
|
||||
while ((foo = tr.ReadLine()) != null)
|
||||
{
|
||||
lineColor = Color.White;
|
||||
var legacyColorMatch = startOfLineColorRegex.Match(foo);
|
||||
if (legacyColorMatch.Success)
|
||||
{
|
||||
lineColor = new Color(Int32.Parse(legacyColorMatch.Groups["r"].Value),
|
||||
Int32.Parse(legacyColorMatch.Groups["g"].Value),
|
||||
Int32.Parse(legacyColorMatch.Groups["b"].Value));
|
||||
foo = foo.Replace(legacyColorMatch.Groups[0].Value, "");
|
||||
}
|
||||
|
||||
bool upgraded = false;
|
||||
string newFoo = ReplaceDeprecatedColorCodes(foo, out upgraded);
|
||||
if (!informedOwner && upgraded)
|
||||
{
|
||||
informedOwner = true;
|
||||
TShock.Log.ConsoleInfo("We have upgraded your MotD to the new format. A backup has been created.");
|
||||
}
|
||||
|
||||
if (lineColor != Color.White)
|
||||
motd.Append(String.Format("%{0:d3},{1:d3},{2:d3}%", lineColor.R, lineColor.G, lineColor.B));
|
||||
|
||||
motd.AppendLine(newFoo);
|
||||
}
|
||||
}
|
||||
|
||||
if (informedOwner)
|
||||
{
|
||||
File.Copy(FileTools.MotdPath, String.Format("{0}_{1}.backup", FileTools.MotdPath, DateTime.Now.ToString("ddMMMyy_hhmmss")));
|
||||
File.WriteAllText(FileTools.MotdPath, motd.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a Group from the name of the group
|
||||
/// </summary>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue