mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-24 05:03:34 -04:00
consistency
This commit is contained in:
parent
f355cb7320
commit
8d6064a7aa
@ -46,7 +46,7 @@ namespace MCGalaxy.Commands.Chatting {
|
||||
|
||||
Database.Backend.CreateTable("Inbox" + receiverName, createInbox);
|
||||
Database.Backend.AddRow("Inbox" + receiverName, "PlayerFrom, TimeSent, Contents",
|
||||
senderName, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), message);
|
||||
senderName, DateTime.Now.ToString(Database.DateFormat), message);
|
||||
|
||||
Player receiver = PlayerInfo.FindExact(receiverName);
|
||||
Player.Message(p, "Message sent to {0}%S.",
|
||||
|
@ -127,7 +127,6 @@ namespace MCGalaxy.Commands.Maintenance {
|
||||
MessageDataChanged(p, args[0], args[1], args[2]);
|
||||
}
|
||||
|
||||
const string dateFormat = "yyyy-MM-dd HH:mm:ss";
|
||||
static void SetDate(Player p, string[] args, string column, Player who, Action<DateTime> setter) {
|
||||
if (args.Length < 3) {
|
||||
Player.Message(p, "Dates must be in the format: yyyy-mm-dd hh:mm:ss");
|
||||
@ -135,7 +134,7 @@ namespace MCGalaxy.Commands.Maintenance {
|
||||
}
|
||||
|
||||
DateTime date;
|
||||
if (!DateTime.TryParseExact(args[2], dateFormat, null, 0, out date)) {
|
||||
if (!DateTime.TryParseExact(args[2], Database.DateFormat, null, 0, out date)) {
|
||||
Player.Message(p, "Invalid date. (must be in format: yyyy-mm-dd hh:mm:ss");
|
||||
return;
|
||||
}
|
||||
|
@ -60,9 +60,9 @@ namespace MCGalaxy.SQL {
|
||||
return queryInstance;
|
||||
}
|
||||
|
||||
public override string FastGetDateTime(IDataRecord record, int col) {
|
||||
public override string RawGetDateTime(IDataRecord record, int col) {
|
||||
DateTime date = record.GetDateTime(col);
|
||||
return date.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
return date.ToString(Database.DateFormat);
|
||||
}
|
||||
|
||||
protected internal override void ParseCreate(ref string cmd) {
|
||||
|
@ -56,7 +56,7 @@ namespace MCGalaxy.SQL {
|
||||
return queryInstance;
|
||||
}
|
||||
|
||||
public override string FastGetDateTime(IDataRecord record, int col) {
|
||||
public override string RawGetDateTime(IDataRecord record, int col) {
|
||||
return record.GetString(col); // reader.GetDateTime is extremely slow so avoid it
|
||||
}
|
||||
|
||||
|
@ -161,7 +161,7 @@ namespace MCGalaxy.DB {
|
||||
|
||||
void UpdateTimestamp(IDataRecord record) {
|
||||
// date is in format yyyy-MM-dd hh:mm:ss
|
||||
string date = Database.Backend.FastGetDateTime(record, 1);
|
||||
string date = Database.Backend.RawGetDateTime(record, 1);
|
||||
int year = (date[0] - '0') * 1000 + (date[1] - '0') * 100 + (date[2] - '0') * 10 + (date[3] - '0');
|
||||
int month = (date[5] - '0') * 10 + (date[6] - '0');
|
||||
int day = (date[8] - '0') * 10 + (date[9] - '0');
|
||||
|
@ -27,6 +27,7 @@ namespace MCGalaxy.SQL {
|
||||
public static class Database {
|
||||
public static IDatabaseBackend Backend;
|
||||
public static bool TableExists(string table) { return Backend.TableExists(table); }
|
||||
public const string DateFormat = "yyyy-MM-dd HH:mm:ss";
|
||||
|
||||
static object ReadInt(IDataRecord record, object arg) { return record.GetInt32(0); }
|
||||
public static int CountRows(string table, string modifier = "", params object[] args) {
|
||||
@ -129,7 +130,7 @@ namespace MCGalaxy.SQL {
|
||||
|
||||
internal static DateTime GetDateTime(this IDataRecord record, string name) {
|
||||
string raw = record.GetStringValue(record.GetOrdinal(name));
|
||||
return DateTime.ParseExact(raw, "yyyy-MM-dd HH:mm:ss", null);
|
||||
return DateTime.ParseExact(raw, DateFormat, null);
|
||||
}
|
||||
|
||||
internal static string GetStringValue(this IDataRecord record, int col) {
|
||||
@ -138,7 +139,7 @@ namespace MCGalaxy.SQL {
|
||||
|
||||
if (type == typeof(string)) return record.GetString(col);
|
||||
if (type == typeof(DateTime)) {
|
||||
return Database.Backend.FastGetDateTime(record, col);
|
||||
return Database.Backend.RawGetDateTime(record, col);
|
||||
}
|
||||
return record.GetValue(col).ToString();
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ namespace MCGalaxy.SQL {
|
||||
/// for sql queries with no parameters. </summary>
|
||||
protected internal abstract ParameterisedQuery GetStaticParameterised();
|
||||
|
||||
public abstract string FastGetDateTime(IDataRecord record, int col);
|
||||
public abstract string RawGetDateTime(IDataRecord record, int col);
|
||||
|
||||
protected internal virtual void ParseCreate(ref string cmd) { }
|
||||
|
||||
|
@ -54,7 +54,7 @@ namespace MCGalaxy.DB {
|
||||
p.FirstLogin = DateTime.Now;
|
||||
p.TimesVisited = 1;
|
||||
|
||||
string now = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
string now = DateTime.Now.ToString(Database.DateFormat);
|
||||
Database.Backend.AddRow("Players", "Name, IP, FirstLogin, LastLogin, totalLogin, Title, " +
|
||||
"totalDeaths, Money, totalBlocks, totalKicked, Messages, TimeSpent",
|
||||
p.name, p.ip, now, now, 1, "", 0, 0, 0, 0, 0, (long)p.TotalTime.TotalSeconds);
|
||||
|
@ -69,7 +69,7 @@ namespace MCGalaxy.SQL {
|
||||
value = value.Replace("'", "''");
|
||||
sql.Write("'" + value + "'");
|
||||
} else if (colTypes[col] == typeof(DateTime)) {
|
||||
string date = Database.Backend.FastGetDateTime(record, col);
|
||||
string date = Database.Backend.RawGetDateTime(record, col);
|
||||
sql.Write("'" + date + "'");
|
||||
} else {
|
||||
long value = record.GetInt64(col); // TODO: try to use GetInt32 where possible
|
||||
|
@ -732,7 +732,7 @@ namespace MCGalaxy {
|
||||
try { //opstats patch (since 5.5.11)
|
||||
if (Server.Opstats.CaselessContains(cmd) || (cmd.CaselessEq("review") && message.CaselessEq("next") && Server.reviewlist.Count > 0)) {
|
||||
Database.Backend.AddRow("Opstats", "Time, Name, Cmd, Cmdmsg",
|
||||
DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), name, cmd, message);
|
||||
DateTime.Now.ToString(Database.DateFormat), name, cmd, message);
|
||||
}
|
||||
} catch { }
|
||||
|
||||
|
@ -150,7 +150,7 @@ namespace MCGalaxy {
|
||||
long cuboided = PlayerData.CuboidPacked(TotalDeleted, TotalDrawn);
|
||||
Database.Backend.UpdateRows("Players", "IP=@0, LastLogin=@1, totalLogin=@2, totalDeaths=@3, Money=@4, " +
|
||||
"totalBlocks=@5, totalCuboided=@6, totalKicked=@7, TimeSpent=@8, Messages=@9", "WHERE Name=@10",
|
||||
ip, LastLogin.ToString("yyyy-MM-dd HH:mm:ss"),
|
||||
ip, LastLogin.ToString(Database.DateFormat),
|
||||
TimesVisited, TimesDied, money, blocks,
|
||||
cuboided, TimesBeenKicked, (long)TotalTime.TotalSeconds, TotalMessagesSent, name);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user