diff --git a/MCGalaxy/Commands/Chat/CmdInbox.cs b/MCGalaxy/Commands/Chat/CmdInbox.cs index 85a2dbde3..9018860c3 100644 --- a/MCGalaxy/Commands/Chat/CmdInbox.cs +++ b/MCGalaxy/Commands/Chat/CmdInbox.cs @@ -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)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 entries = new List(); - Database.Backend.ReadRows("Inbox" + p.name, "*", - entries, ReadInbox, "ORDER BY TimeSent"); + List 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 entries) { + static void DeleteByID(Player p, string value, List 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 entries) { + static void OutputByID(Player p, string value, List 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) { diff --git a/MCGalaxy/Commands/Fun/CmdCountdown.cs b/MCGalaxy/Commands/Fun/CmdCountdown.cs index 0f542bc4c..09e516544 100644 --- a/MCGalaxy/Commands/Fun/CmdCountdown.cs +++ b/MCGalaxy/Commands/Fun/CmdCountdown.cs @@ -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 %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"); diff --git a/MCGalaxy/Database/Database.cs b/MCGalaxy/Database/Database.cs index b44a99a15..1aa4dd2fc 100644 --- a/MCGalaxy/Database/Database.cs +++ b/MCGalaxy/Database/Database.cs @@ -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)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(); + } } } \ No newline at end of file