Fix /clones not including online player latest IPs

This commit is contained in:
UnknownShadow200 2017-03-04 21:02:47 +11:00
parent 4df2aaf752
commit 96e8351a08
3 changed files with 18 additions and 7 deletions

View File

@ -40,6 +40,11 @@ namespace MCGalaxy.Commands {
}
List<string> accounts = PlayerInfo.FindAccounts(message);
// in older versions it was possible for your name to appear multiple times in DB
if (p != null) {
while (accounts.CaselessRemove(p.name)) { }
}
if (accounts.Count == 0) {
Player.Message(p, "No players last played with the given IP.");
} else {

View File

@ -107,6 +107,7 @@ namespace MCGalaxy {
InitPlayerStats(playerDb);
} else {
LoadPlayerStats(playerDb);
//save(); // update IP and total logins in the DB
}
Server.Background.QueueOnce(ShowAltsTask, name, TimeSpan.Zero);
@ -223,11 +224,8 @@ namespace MCGalaxy {
if (p == null || p.ip == "127.0.0.1" || p.disconnected) return;
List<string> alts = PlayerInfo.FindAccounts(p.ip);
// Remove online accounts from the list of accounts on the IP
for (int i = alts.Count - 1; i >= 0; i--) {
if (PlayerInfo.FindExact(alts[i]) == null) continue;
alts.RemoveAt(i);
}
// in older versions it was possible for your name to appear multiple times in DB
while (alts.CaselessRemove(p.name)) { }
if (alts.Count == 0) return;
LevelPermission adminChatRank = CommandOtherPerms.FindPerm("adminchat", LevelPermission.Admin);

View File

@ -160,8 +160,8 @@ namespace MCGalaxy {
return row == null ? null : row["Name"].ToString();
}
/// <summary> Retrieves from the database the names of all players whose
/// last IP address matches the given IP address. </summary>
/// <summary> Retrieves names of all players whose IP address matches the given IP address. </summary>
/// <remarks> This is current IP for online players, last IP for offline players from the database. </remarks>
public static List<string> FindAccounts(string ip) {
DataTable clones = Database.Backend.GetRows("Players", "Name", "WHERE IP=@0", ip);
List<string> alts = new List<string>();
@ -171,6 +171,14 @@ namespace MCGalaxy {
if (!alts.CaselessContains(name))
alts.Add(name);
}
Player[] players = PlayerInfo.Online.Items;
foreach (Player p in players) {
if (p.ip != ip) continue;
if (!alts.CaselessContains(p.name))
alts.Add(p.name);
}
clones.Dispose();
return alts;
}