mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-22 12:05:51 -04:00
Fix /top10 logins etc
This commit is contained in:
parent
adf174900c
commit
4768db2137
@ -25,28 +25,18 @@ namespace MCGalaxy.Commands.Chatting {
|
||||
public override string name { get { return "Inbox"; } }
|
||||
public override string type { get { return CommandTypes.Chat; } }
|
||||
public override bool SuperUseable { get { return false; } }
|
||||
|
||||
class MailEntry { public string Contents, Timestamp, From; }
|
||||
static object ReadInbox(IDataRecord record, object arg) {
|
||||
MailEntry e = new MailEntry();
|
||||
e.Contents = record.GetText("Contents");
|
||||
e.Timestamp = record.GetText("TimeSent");
|
||||
e.From = record.GetText("PlayerFrom");
|
||||
|
||||
((List<MailEntry>)arg).Add(e); return arg;
|
||||
}
|
||||
const int i_text = 0, i_sent = 1, i_from = 2;
|
||||
|
||||
public override void Use(Player p, string message) {
|
||||
List<MailEntry> entries = new List<MailEntry>();
|
||||
Database.Backend.ReadRows("Inbox" + p.name, "*",
|
||||
entries, ReadInbox, "ORDER BY TimeSent");
|
||||
List<string[]> entries = Database.GetRows("Inbox" + p.name, "Contents,TimeSent,PlayerFrom",
|
||||
"ORDER BY TimeSent");
|
||||
if (entries.Count == 0) {
|
||||
Player.Message(p, "Your inbox is empty."); return;
|
||||
}
|
||||
|
||||
string[] args = message.SplitSpaces(2);
|
||||
if (message.Length == 0) {
|
||||
foreach (MailEntry entry in entries) { Output(p, entry); }
|
||||
foreach (string[] entry in entries) { Output(p, entry); }
|
||||
} else if (IsDeleteCommand(args[0])) {
|
||||
if (args.Length == 1) {
|
||||
Player.Message(p, "You need to provide either \"all\" or a number."); return;
|
||||
@ -61,21 +51,21 @@ namespace MCGalaxy.Commands.Chatting {
|
||||
}
|
||||
}
|
||||
|
||||
static void DeleteByID(Player p, string value, List<MailEntry> entries) {
|
||||
static void DeleteByID(Player p, string value, List<string[]> entries) {
|
||||
int num = 1;
|
||||
if (!CommandParser.GetInt(p, value, "Message number", ref num, 1)) return;
|
||||
|
||||
if (num > entries.Count) {
|
||||
Player.Message(p, "Message #{0} does not exist.", num);
|
||||
} else {
|
||||
MailEntry entry = entries[num - 1];
|
||||
string[] entry = entries[num - 1];
|
||||
Database.Backend.DeleteRows("Inbox" + p.name,
|
||||
"WHERE PlayerFrom=@0 AND TimeSent=@1", entry.From, entry.Timestamp);
|
||||
"WHERE PlayerFrom=@0 AND TimeSent=@1", entry[i_from], entry[i_sent]);
|
||||
Player.Message(p, "Deleted message #{0}", num);
|
||||
}
|
||||
}
|
||||
|
||||
static void OutputByID(Player p, string value, List<MailEntry> entries) {
|
||||
static void OutputByID(Player p, string value, List<string[]> entries) {
|
||||
int num = 1;
|
||||
if (!CommandParser.GetInt(p, value, "Message number", ref num, 1)) return;
|
||||
|
||||
@ -86,12 +76,12 @@ namespace MCGalaxy.Commands.Chatting {
|
||||
}
|
||||
}
|
||||
|
||||
static void Output(Player p, MailEntry entry) {
|
||||
TimeSpan delta = DateTime.Now - DateTime.Parse(entry.Timestamp);
|
||||
string sender = PlayerInfo.GetColoredName(p, entry.From);
|
||||
static void Output(Player p, string[] entry) {
|
||||
TimeSpan delta = DateTime.Now - DateTime.Parse(entry[i_sent]);
|
||||
string sender = PlayerInfo.GetColoredName(p, entry[i_from]);
|
||||
|
||||
Player.Message(p, "From {0} &a{1} ago:", sender, delta.Shorten());
|
||||
Player.Message(p, entry.Contents);
|
||||
Player.Message(p, entry[i_text]);
|
||||
}
|
||||
|
||||
public override void Help(Player p) {
|
||||
|
@ -113,7 +113,7 @@ namespace MCGalaxy.Commands.Fun {
|
||||
|
||||
public override void Help(Player p) {
|
||||
Player.Message(p, "%T/CD set [width] [height] [length]");
|
||||
Player.Message(p, "%HRe-generates the countdown map at given size (default is 32x32x32)");
|
||||
Player.Message(p, "%HRe-generates the countdown map (default is 32x32x32)");
|
||||
Player.Message(p, "%T/CD start <speed> <mode> %H- starts countdown");
|
||||
Player.Message(p, "%H speed can be: slow, normal, fast, extreme or ultimate");
|
||||
Player.Message(p, "%H mode can be: normal or freeze");
|
||||
|
@ -35,7 +35,7 @@ namespace MCGalaxy.SQL {
|
||||
|
||||
static object ReadString(IDataRecord record, object arg) { return record.GetText(0); }
|
||||
public static string ReadString(string table, string column,
|
||||
string modifier = "", params object[] args) {
|
||||
string modifier = "", params object[] args) {
|
||||
return (string)Backend.ReadRows(table, column, null, ReadString, modifier, args);
|
||||
}
|
||||
|
||||
@ -50,7 +50,7 @@ namespace MCGalaxy.SQL {
|
||||
|
||||
internal static object ReadFields(IDataRecord record, object arg) {
|
||||
string[] field = new string[record.FieldCount];
|
||||
for (int i = 0; i < field.Length; i++) { field[i] = record.GetText(i); }
|
||||
for (int i = 0; i < field.Length; i++) { field[i] = record.GetStringValue(i); }
|
||||
((List<string[]>)arg).Add(field);
|
||||
return arg;
|
||||
}
|
||||
@ -107,7 +107,7 @@ namespace MCGalaxy.SQL {
|
||||
return arg;
|
||||
}
|
||||
|
||||
|
||||
|
||||
internal static string GetText(this IDataRecord record, int col) {
|
||||
return record.IsDBNull(col) ? "" : record.GetString(col);
|
||||
}
|
||||
@ -121,15 +121,26 @@ namespace MCGalaxy.SQL {
|
||||
int col = record.GetOrdinal(name);
|
||||
return record.IsDBNull(col) ? 0 : record.GetInt32(col);
|
||||
}
|
||||
|
||||
|
||||
internal static long GetLong(this IDataRecord record, string name) {
|
||||
int col = record.GetOrdinal(name);
|
||||
return record.IsDBNull(col) ? 0 : record.GetInt64(col);
|
||||
}
|
||||
|
||||
internal static DateTime GetDateTime(this IDataRecord record, string name) {
|
||||
string raw = Database.Backend.FastGetDateTime(record, record.GetOrdinal(name));
|
||||
string raw = record.GetStringValue(record.GetOrdinal(name));
|
||||
return DateTime.ParseExact(raw, "yyyy-MM-dd HH:mm:ss", null);
|
||||
}
|
||||
|
||||
internal static string GetStringValue(this IDataRecord record, int col) {
|
||||
if (record.IsDBNull(col)) return "";
|
||||
Type type = record.GetFieldType(col);
|
||||
|
||||
if (type == typeof(string)) return record.GetString(col);
|
||||
if (type == typeof(DateTime)) {
|
||||
return Database.Backend.FastGetDateTime(record, col);
|
||||
}
|
||||
return record.GetValue(col).ToString();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user