Merge branch 'h/amf' into general-devel
This commit is contained in:
commit
c65c1ff448
3 changed files with 38 additions and 12 deletions
|
|
@ -2282,6 +2282,14 @@ namespace TShockAPI
|
|||
args.Player.Kick("You have been Bounced.", true, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (name.Trim().StartsWith("tsi:") || name.Trim().StartsWith("tsn:"))
|
||||
{
|
||||
TShock.Log.ConsoleDebug("GetDataHandlers / rejecting player for name prefix starting with tsi: or tsn:.");
|
||||
args.Player.Kick("Illegal name: prefixes tsi: and tsn: are forbidden.", true, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.Player.ReceivedInfo)
|
||||
{
|
||||
// Since Terraria 1.2.3 these character properties can change ingame.
|
||||
|
|
|
|||
|
|
@ -75,36 +75,52 @@ namespace TShockAPI
|
|||
public static readonly TSPlayer All = new TSPlayer("All");
|
||||
|
||||
/// <summary>
|
||||
/// Finds a TSPlayer based on name or ID
|
||||
/// Finds a TSPlayer based on name or ID.
|
||||
/// If the string comes with tsi: or tsn:, we'll only return a list with one element,
|
||||
/// either the player with the matching ID or name, respectively.
|
||||
/// </summary>
|
||||
/// <param name="plr">Player name or ID</param>
|
||||
/// <returns>A list of matching players</returns>
|
||||
public static List<TSPlayer> FindByNameOrID(string plr)
|
||||
public static List<TSPlayer> FindByNameOrID(string search)
|
||||
{
|
||||
var found = new List<TSPlayer>();
|
||||
|
||||
search = search.Trim();
|
||||
|
||||
// tsi: and tsn: are used to disambiguate between usernames and not
|
||||
// and are also both 3 characters to remove them from the search
|
||||
// (the goal was to pick prefixes unlikely to be used by names)
|
||||
// (and not to collide with other prefixes used by other commands)
|
||||
var exactIndexOnly = search.StartsWith("tsi:");
|
||||
var exactNameOnly = search.StartsWith("tsn:");
|
||||
|
||||
if (exactNameOnly || exactIndexOnly)
|
||||
search = search.Remove(0, 4);
|
||||
|
||||
// Avoid errors caused by null search
|
||||
if (plr == null)
|
||||
if (search == null || search == "")
|
||||
return found;
|
||||
|
||||
byte plrID;
|
||||
if (byte.TryParse(plr, out plrID) && plrID < Main.maxPlayers)
|
||||
byte searchID;
|
||||
if (byte.TryParse(search, out searchID) && searchID < Main.maxPlayers)
|
||||
{
|
||||
TSPlayer player = TShock.Players[plrID];
|
||||
TSPlayer player = TShock.Players[searchID];
|
||||
if (player != null && player.Active)
|
||||
{
|
||||
return new List<TSPlayer> { player };
|
||||
if (exactIndexOnly)
|
||||
return new List<TSPlayer> { player };
|
||||
found.Add(player);
|
||||
}
|
||||
}
|
||||
|
||||
string plrLower = plr.ToLower();
|
||||
string searchLower = search.ToLower();
|
||||
foreach (TSPlayer player in TShock.Players)
|
||||
{
|
||||
if (player != null)
|
||||
{
|
||||
// Must be an EXACT match
|
||||
if (player.Name == plr)
|
||||
if ((search == player.Name) && exactNameOnly)
|
||||
return new List<TSPlayer> { player };
|
||||
if (player.Name.ToLower().StartsWith(plrLower))
|
||||
if (player.Name.ToLower().StartsWith(searchLower))
|
||||
found.Add(player);
|
||||
}
|
||||
}
|
||||
|
|
@ -1667,12 +1683,13 @@ namespace TShockAPI
|
|||
/// <param name="matches">An enumerable list with the matches</param>
|
||||
public void SendMultipleMatchError(IEnumerable<object> matches)
|
||||
{
|
||||
SendErrorMessage("More than one match found: ");
|
||||
SendErrorMessage("More than one match found -- unable to decide which is correct: ");
|
||||
|
||||
var lines = PaginationTools.BuildLinesFromTerms(matches.ToArray());
|
||||
lines.ForEach(SendInfoMessage);
|
||||
|
||||
SendErrorMessage("Use \"my query\" for items with spaces.");
|
||||
SendErrorMessage("Use tsi:[number] or tsn:[username] to distinguish between user IDs and usernames.");
|
||||
}
|
||||
|
||||
[Conditional("DEBUG")]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue