mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-19 04:07:10 -04:00
Move some methods from PlayerInfo to PlayerDB and add a few more comments
This commit is contained in:
parent
ad64bb5ffd
commit
ccbbb62bcc
@ -16,6 +16,7 @@
|
|||||||
permissions and limitations under the Licenses.
|
permissions and limitations under the Licenses.
|
||||||
*/
|
*/
|
||||||
using System;
|
using System;
|
||||||
|
using MCGalaxy.DB;
|
||||||
|
|
||||||
namespace MCGalaxy.Commands.Info {
|
namespace MCGalaxy.Commands.Info {
|
||||||
public sealed class CmdBanInfo : Command2 {
|
public sealed class CmdBanInfo : Command2 {
|
||||||
@ -41,7 +42,7 @@ namespace MCGalaxy.Commands.Info {
|
|||||||
bool permaBanned = Group.BannedRank.Players.Contains(plName);
|
bool permaBanned = Group.BannedRank.Players.Contains(plName);
|
||||||
bool isBanned = permaBanned || tempExpiry >= DateTime.UtcNow;
|
bool isBanned = permaBanned || tempExpiry >= DateTime.UtcNow;
|
||||||
string msg = nick;
|
string msg = nick;
|
||||||
string ip = PlayerInfo.FindIP(plName);
|
string ip = PlayerDB.FindIP(plName);
|
||||||
bool ipBanned = ip != null && Server.bannedIP.Contains(ip);
|
bool ipBanned = ip != null && Server.bannedIP.Contains(ip);
|
||||||
|
|
||||||
if (!ipBanned && isBanned) msg += " &Sis &CBANNED";
|
if (!ipBanned && isBanned) msg += " &Sis &CBANNED";
|
||||||
|
@ -133,12 +133,12 @@ namespace MCGalaxy.Commands.Info {
|
|||||||
while (map.Length > 0 && Char.IsNumber(map[map.Length - 1])) {
|
while (map.Length > 0 && Char.IsNumber(map[map.Length - 1])) {
|
||||||
// If the server does not have account with +, we have to account for the
|
// If the server does not have account with +, we have to account for the
|
||||||
// that say Player123's second level is Player1232, and the realm owner is Player123
|
// that say Player123's second level is Player1232, and the realm owner is Player123
|
||||||
name = plus ? null : PlayerInfo.FindName(map);
|
name = plus ? null : PlayerDB.FindName(map);
|
||||||
if (name != null) break;
|
if (name != null) break;
|
||||||
map = map.Substring(0, map.Length - 1);
|
map = map.Substring(0, map.Length - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (name == null) name = PlayerInfo.FindName(map);
|
if (name == null) name = PlayerDB.FindName(map);
|
||||||
if (name != null && !LevelInfo.IsRealmOwner(name, origMap)) return null;
|
if (name != null && !LevelInfo.IsRealmOwner(name, origMap)) return null;
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ namespace MCGalaxy.Commands.Maintenance {
|
|||||||
p.Message("\"{0}\" must be offline to use &T/InfoSwap", name); return null;
|
p.Message("\"{0}\" must be offline to use &T/InfoSwap", name); return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
string match = PlayerInfo.FindName(name);
|
string match = PlayerDB.FindName(name);
|
||||||
if (match == null) {
|
if (match == null) {
|
||||||
p.Message("\"{0}\" was not found in the database.", name); return null;
|
p.Message("\"{0}\" was not found in the database.", name); return null;
|
||||||
}
|
}
|
||||||
|
@ -195,7 +195,7 @@ namespace MCGalaxy.Commands.Moderation {
|
|||||||
// TryParse returns "0.0.0.123" for "123", we do not want that behaviour
|
// TryParse returns "0.0.0.123" for "123", we do not want that behaviour
|
||||||
if (IPAddress.TryParse(message, out ip) && message.Split('.').Length == 4) {
|
if (IPAddress.TryParse(message, out ip) && message.Split('.').Length == 4) {
|
||||||
string account = Server.Config.ClassicubeAccountPlus ? message + "+" : message;
|
string account = Server.Config.ClassicubeAccountPlus ? message + "+" : message;
|
||||||
if (PlayerInfo.FindName(account) == null) return message;
|
if (PlayerDB.FindName(account) == null) return message;
|
||||||
|
|
||||||
// Some classicube.net accounts can be parsed as valid IPs, so warn in this case.
|
// Some classicube.net accounts can be parsed as valid IPs, so warn in this case.
|
||||||
p.Message("Note: \"{0}\" is both an IP and an account name. "
|
p.Message("Note: \"{0}\" is both an IP and an account name. "
|
||||||
@ -209,7 +209,7 @@ namespace MCGalaxy.Commands.Moderation {
|
|||||||
|
|
||||||
p.Message("Searching PlayerDB..");
|
p.Message("Searching PlayerDB..");
|
||||||
string dbIP;
|
string dbIP;
|
||||||
name = PlayerInfo.FindOfflineIPMatches(p, message, out dbIP);
|
name = PlayerDB.FindOfflineIPMatches(p, message, out dbIP);
|
||||||
return dbIP;
|
return dbIP;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using MCGalaxy.Commands;
|
using MCGalaxy.Commands;
|
||||||
using MCGalaxy.Commands.Moderation;
|
using MCGalaxy.Commands.Moderation;
|
||||||
|
using MCGalaxy.DB;
|
||||||
using MCGalaxy.Events;
|
using MCGalaxy.Events;
|
||||||
using MCGalaxy.Tasks;
|
using MCGalaxy.Tasks;
|
||||||
|
|
||||||
@ -139,7 +140,7 @@ namespace MCGalaxy.Core {
|
|||||||
Ban.UnbanPlayer(e.Actor, e.Target, e.Reason);
|
Ban.UnbanPlayer(e.Actor, e.Target, e.Reason);
|
||||||
ModActionCmd.ChangeRank(e.Target, Group.BannedRank, Group.DefaultRank, who, false);
|
ModActionCmd.ChangeRank(e.Target, Group.BannedRank, Group.DefaultRank, who, false);
|
||||||
|
|
||||||
string ip = PlayerInfo.FindIP(e.Target);
|
string ip = PlayerDB.FindIP(e.Target);
|
||||||
if (ip != null && Server.bannedIP.Contains(ip)) {
|
if (ip != null && Server.bannedIP.Contains(ip)) {
|
||||||
e.Actor.Message("NOTE: Their IP is still banned.");
|
e.Actor.Message("NOTE: Their IP is still banned.");
|
||||||
}
|
}
|
||||||
|
@ -92,6 +92,30 @@ namespace MCGalaxy.DB {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static PlayerData FindData(string name) {
|
||||||
|
string suffix = Database.Backend.CaselessWhereSuffix;
|
||||||
|
object raw = Database.ReadRows("Players", "*", null, PlayerData.Read,
|
||||||
|
"WHERE Name=@0" + suffix, name);
|
||||||
|
return (PlayerData)raw;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string FindName(string name) {
|
||||||
|
string suffix = Database.Backend.CaselessWhereSuffix;
|
||||||
|
return Database.ReadString("Players", "Name", "WHERE Name=@0" + suffix, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string FindIP(string name) {
|
||||||
|
string suffix = Database.Backend.CaselessWhereSuffix;
|
||||||
|
return Database.ReadString("Players", "IP", "WHERE Name=@0" + suffix, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string FindOfflineIPMatches(Player p, string name, out string ip) {
|
||||||
|
string[] match = PlayerDB.MatchValues(p, name, "Name,IP");
|
||||||
|
ip = match == null ? null : match[1];
|
||||||
|
return match == null ? null : match[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void Update(string name, string column, string value) {
|
public static void Update(string name, string column, string value) {
|
||||||
Database.UpdateRows("Players", column + "=@1", "WHERE Name=@0", name, value);
|
Database.UpdateRows("Players", column + "=@1", "WHERE Name=@0", name, value);
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,7 @@ namespace MCGalaxy {
|
|||||||
return col.Length > 0 ? col : p.group.Color;
|
return col.Length > 0 ? col : p.group.Color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary> Returns the number of non-hidden players that are currently online </summary>
|
||||||
public static int NonHiddenCount() {
|
public static int NonHiddenCount() {
|
||||||
Player[] players = Online.Items;
|
Player[] players = Online.Items;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
@ -56,23 +57,27 @@ namespace MCGalaxy {
|
|||||||
}
|
}
|
||||||
return uniqueIPs.Count;
|
return uniqueIPs.Count;
|
||||||
}
|
}
|
||||||
|
// TODO: remove _useless parameter. but this breaks backwards compatibility with plugins
|
||||||
|
|
||||||
public static Player FindMatches(Player pl, string name, bool onlyCanSee = true) {
|
/// <summary> Matches given name against the names of all online players that the given player can see </summary>
|
||||||
int matches; return FindMatches(pl, name, out matches, onlyCanSee);
|
/// <returns> A Player instance if exactly one match was found </returns>
|
||||||
|
public static Player FindMatches(Player pl, string name, bool _useless = false) {
|
||||||
|
int matches; return FindMatches(pl, name, out matches);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Player FindMatches(Player pl, string name,
|
/// <summary> Matches given name against the names of all online players that the given player can see </summary>
|
||||||
out int matches, bool onlyCanSee = true) {
|
/// <param name="matches"> Outputs the number of matching players </param>
|
||||||
|
/// <returns> A Player instance if exactly one match was found </returns>
|
||||||
|
public static Player FindMatches(Player pl, string name, out int matches, bool _useless = false) {
|
||||||
matches = 0;
|
matches = 0;
|
||||||
if (!Formatter.ValidName(pl, name, "player")) return null;
|
if (!Formatter.ValidName(pl, name, "player")) return null;
|
||||||
|
|
||||||
// Try to exactly match name first (because names have + at end)
|
// Try to exactly match name first (because names have + at end)
|
||||||
Player exact = FindExact(name);
|
Player exact = FindExact(name);
|
||||||
if (exact != null) { matches = 1; return exact; }
|
if (exact != null && pl.CanSee(exact)) { matches = 1; return exact; }
|
||||||
|
|
||||||
return Matcher.Find(pl, name, out matches, Online.Items,
|
return Matcher.Find(pl, name, out matches, Online.Items,
|
||||||
p => pl.CanSee(p) || !onlyCanSee,
|
p => pl.CanSee(p), p => p.name, "online players");
|
||||||
p => p.name, "online players");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string FindMatchesPreferOnline(Player p, string name) {
|
public static string FindMatchesPreferOnline(Player p, string name) {
|
||||||
@ -97,31 +102,7 @@ namespace MCGalaxy {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static PlayerData FindData(string name) {
|
|
||||||
string suffix = Database.Backend.CaselessWhereSuffix;
|
|
||||||
object raw = Database.ReadRows("Players", "*", null, PlayerData.Read,
|
|
||||||
"WHERE Name=@0" + suffix, name);
|
|
||||||
return (PlayerData)raw;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string FindName(string name) {
|
|
||||||
string suffix = Database.Backend.CaselessWhereSuffix;
|
|
||||||
return Database.ReadString("Players", "Name", "WHERE Name=@0" + suffix, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string FindIP(string name) {
|
|
||||||
string suffix = Database.Backend.CaselessWhereSuffix;
|
|
||||||
return Database.ReadString("Players", "IP", "WHERE Name=@0" + suffix, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string FindOfflineIPMatches(Player p, string name, out string ip) {
|
|
||||||
string[] match = PlayerDB.MatchValues(p, name, "Name,IP");
|
|
||||||
ip = match == null ? null : match[1];
|
|
||||||
return match == null ? null : match[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static object ReadAccounts(IDataRecord record, object arg) {
|
static object ReadAccounts(IDataRecord record, object arg) {
|
||||||
List<string> names = (List<string>)arg;
|
List<string> names = (List<string>)arg;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user