mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-23 04:32:50 -04:00
Fix last commit to work
This commit is contained in:
parent
f876118fa5
commit
2275533601
@ -22,7 +22,7 @@ using MCGalaxy.Maths;
|
||||
using MCGalaxy.SQL;
|
||||
|
||||
namespace MCGalaxy.Blocks.Extended {
|
||||
public static class MessageBlock {
|
||||
public static class MessageBlock {
|
||||
|
||||
public static bool Handle(Player p, ushort x, ushort y, ushort z, bool alwaysRepeat) {
|
||||
if (!p.level.hasMessageBlocks) return false;
|
||||
|
@ -29,9 +29,9 @@ namespace MCGalaxy.Commands.Chatting {
|
||||
class MailEntry { public string Contents, Timestamp, From; }
|
||||
static object ReadInbox(IDataRecord record, object arg) {
|
||||
MailEntry e = new MailEntry();
|
||||
e.Contents = record.GetString("Contents");
|
||||
e.Timestamp = record.GetString("TimeSent");
|
||||
e.From = record.GetString("PlayerFrom");
|
||||
e.Contents = record.GetText("Contents");
|
||||
e.Timestamp = record.GetText("TimeSent");
|
||||
e.From = record.GetText("PlayerFrom");
|
||||
|
||||
((List<MailEntry>)arg).Add(e); return arg;
|
||||
}
|
||||
|
@ -53,9 +53,9 @@ namespace MCGalaxy.Commands.Info {
|
||||
|
||||
Player.Message(p, "&a{0}:", stat.Title());
|
||||
for (int i = 0; i < stats.Count; i++) {
|
||||
string name = PlayerInfo.GetColoredName(p, stats[i][0]);
|
||||
string value = stat.Formatter(stats[i][1]);
|
||||
Player.Message(p, "{0}) {1} %S- {2}", offset + (i + 1), name, value);
|
||||
string name = PlayerInfo.GetColoredName(p, stats[i][0]);
|
||||
string value = stat.Formatter(stats[i][1]);
|
||||
Player.Message(p, "{0}) {1} %S- {2}", offset + (i + 1), name, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -204,10 +204,6 @@ namespace MCGalaxy.SQL {
|
||||
return new MySqlCommand(query, (MySqlConnection)conn);
|
||||
}
|
||||
|
||||
protected override DbDataAdapter CreateDataAdapter(string query, IDbConnection conn) {
|
||||
return new MySqlDataAdapter(query, (MySqlConnection)conn);
|
||||
}
|
||||
|
||||
protected override IDbDataParameter CreateParameter() {
|
||||
return new MySqlParameter();
|
||||
}
|
||||
|
@ -68,8 +68,8 @@ namespace MCGalaxy.SQL {
|
||||
|
||||
public override List<string> AllTables() {
|
||||
const string syntax = "SELECT name from sqlite_master WHERE type='table'";
|
||||
List<string> tables = Database.GetStrings(syntax);
|
||||
|
||||
List<string> tables = Database.GetStrings(syntax);
|
||||
|
||||
// exclude sqlite built-in database tables
|
||||
for (int i = tables.Count - 1; i >= 0; i--) {
|
||||
if (tables[i].StartsWith("sqlite_")) tables.RemoveAt(i);
|
||||
@ -79,7 +79,7 @@ namespace MCGalaxy.SQL {
|
||||
|
||||
static object IterateColumnNames(IDataRecord record, object arg) {
|
||||
List<string> columns = (List<string>)arg;
|
||||
columns.Add(record.GetString("name"));
|
||||
columns.Add(record.GetText("name"));
|
||||
return arg;
|
||||
}
|
||||
|
||||
@ -186,10 +186,6 @@ namespace MCGalaxy.SQL {
|
||||
|
||||
protected override IDbCommand CreateCommand(string query, IDbConnection conn) {
|
||||
return new SQLiteCommand(query, (SQLiteConnection)conn);
|
||||
}
|
||||
|
||||
protected override DbDataAdapter CreateDataAdapter(string query, IDbConnection conn) {
|
||||
return new SQLiteDataAdapter(query, (SQLiteConnection)conn);
|
||||
}
|
||||
|
||||
protected override IDbDataParameter CreateParameter() {
|
||||
|
@ -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.GetString(i); }
|
||||
for (int i = 0; i < field.Length; i++) { field[i] = record.GetString(i); }
|
||||
((List<string[]>)arg).Add(field);
|
||||
return arg;
|
||||
}
|
||||
@ -108,16 +108,19 @@ namespace MCGalaxy.SQL {
|
||||
}
|
||||
|
||||
|
||||
internal static string GetString(this IDataRecord record, string name) {
|
||||
return record.GetString(record.GetOrdinal(name));
|
||||
internal static string GetText(this IDataRecord record, string name) {
|
||||
int i = record.GetOrdinal(name);
|
||||
return record.IsDBNull(i) ? "" : record.GetString(i);
|
||||
}
|
||||
|
||||
internal static int GetInt32(this IDataRecord record, string name) {
|
||||
return record.GetInt32(record.GetOrdinal(name));
|
||||
internal static int GetInt(this IDataRecord record, string name) {
|
||||
int i = record.GetOrdinal(name);
|
||||
return record.IsDBNull(i) ? 0 : record.GetInt32(i);
|
||||
}
|
||||
|
||||
internal static long GetInt64(this IDataRecord record, string name) {
|
||||
return record.GetInt64(record.GetOrdinal(name));
|
||||
internal static long GetLong(this IDataRecord record, string name) {
|
||||
int i = record.GetOrdinal(name);
|
||||
return record.IsDBNull(i) ? 0 : record.GetInt64(i);
|
||||
}
|
||||
|
||||
internal static DateTime GetDateTime(this IDataRecord record, string name) {
|
||||
|
@ -29,8 +29,7 @@ namespace MCGalaxy.SQL {
|
||||
protected abstract bool MultipleSchema { get; }
|
||||
|
||||
protected abstract IDbConnection CreateConnection(string connString);
|
||||
protected abstract IDbCommand CreateCommand(string query, IDbConnection conn);
|
||||
protected abstract DbDataAdapter CreateDataAdapter(string query, IDbConnection conn);
|
||||
protected abstract IDbCommand CreateCommand(string query, IDbConnection conn);
|
||||
protected abstract IDbDataParameter CreateParameter();
|
||||
|
||||
|
||||
|
@ -90,42 +90,42 @@ namespace MCGalaxy.DB {
|
||||
}
|
||||
|
||||
internal static PlayerData Parse(IDataRecord record) {
|
||||
PlayerData data = new PlayerData();
|
||||
data.Name = record.GetString("Name");
|
||||
data.IP = record.GetString("IP");
|
||||
data.DatabaseID = record.GetInt32("ID");
|
||||
PlayerData data = new PlayerData();
|
||||
data.Name = record.GetText("Name");
|
||||
data.IP = record.GetText("IP");
|
||||
data.DatabaseID = record.GetInt("ID");
|
||||
|
||||
// Backwards compatibility with old format
|
||||
string rawTime = record.GetString(ColumnTimeSpent);
|
||||
string rawTime = record.GetText(ColumnTimeSpent);
|
||||
try {
|
||||
long secs = long.Parse(rawTime);
|
||||
data.TotalTime = TimeSpan.FromSeconds(secs);
|
||||
} catch {
|
||||
data.TotalTime = rawTime.ParseDBTime();
|
||||
data.TotalTime = rawTime.ParseOldDBTimeSpent();
|
||||
}
|
||||
|
||||
data.FirstLogin = record.GetDateTime(ColumnFirstLogin);
|
||||
data.LastLogin = record.GetDateTime(ColumnLastLogin);
|
||||
|
||||
data.Title = record.GetString(ColumnTitle);
|
||||
data.Title = record.GetText(ColumnTitle);
|
||||
data.Title = data.Title.Cp437ToUnicode();
|
||||
data.TitleColor = ParseCol(record.GetString(ColumnTColor));
|
||||
data.Color = ParseCol(record.GetString(ColumnColor));
|
||||
data.TitleColor = ParseCol(record.GetText(ColumnTColor));
|
||||
data.Color = ParseCol(record.GetText(ColumnColor));
|
||||
|
||||
data.Money = record.GetInt32(ColumnMoney);
|
||||
data.Deaths = record.GetInt32(ColumnDeaths);
|
||||
data.Logins = record.GetInt32(ColumnLogins);
|
||||
data.Kicks = record.GetInt32(ColumnKicked);
|
||||
data.Messages = record.GetInt32(ColumnMessages);
|
||||
data.Money = record.GetInt(ColumnMoney);
|
||||
data.Deaths = record.GetInt(ColumnDeaths);
|
||||
data.Logins = record.GetInt(ColumnLogins);
|
||||
data.Kicks = record.GetInt(ColumnKicked);
|
||||
data.Messages = record.GetInt(ColumnMessages);
|
||||
|
||||
long blocks = record.GetInt64(ColumnTotalBlocks);
|
||||
long cuboided = record.GetInt64(ColumnTotalCuboided);
|
||||
long blocks = record.GetLong(ColumnTotalBlocks);
|
||||
long cuboided = record.GetLong(ColumnTotalCuboided);
|
||||
data.TotalModified = blocks & LowerBitsMask;
|
||||
data.TotalPlaced = blocks >> LowerBits;
|
||||
data.TotalDrawn = cuboided & LowerBitsMask;
|
||||
data.TotalDeleted = cuboided >> LowerBits;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
internal static object Read(IDataRecord record, object arg) { return Parse(record); }
|
||||
|
||||
internal static long ParseLong(string value) {
|
||||
|
@ -36,7 +36,7 @@ namespace MCGalaxy.Eco {
|
||||
|
||||
static object ListOld(IDataRecord record, object arg) {
|
||||
EcoStats stats = ParseStats(record);
|
||||
stats.__unused = record.GetInt32("money");
|
||||
stats.__unused = record.GetInt("money");
|
||||
((List<EcoStats>)arg).Add(stats);
|
||||
return arg;
|
||||
}
|
||||
@ -80,13 +80,13 @@ namespace MCGalaxy.Eco {
|
||||
|
||||
static EcoStats ParseStats(IDataRecord record) {
|
||||
EcoStats stats;
|
||||
stats.Player = record.GetString("player");
|
||||
stats.Payment = Parse(record.GetString("payment"));
|
||||
stats.Purchase = Parse(record.GetString("purchase"));
|
||||
stats.Salary = Parse(record.GetString("salary"));
|
||||
stats.Fine = Parse(record.GetString("fine"));
|
||||
stats.Player = record.GetText("player");
|
||||
stats.Payment = Parse(record.GetText("payment"));
|
||||
stats.Purchase = Parse(record.GetText("purchase"));
|
||||
stats.Salary = Parse(record.GetText("salary"));
|
||||
stats.Fine = Parse(record.GetText("fine"));
|
||||
|
||||
stats.TotalSpent = record.GetInt32("total");
|
||||
stats.TotalSpent = record.GetInt("total");
|
||||
stats.__unused = 0;
|
||||
return stats;
|
||||
}
|
||||
|
@ -117,16 +117,16 @@ namespace MCGalaxy.Games {
|
||||
"{0} transplanted {1}'s living brain" };
|
||||
|
||||
public static List<string> LoadInfectMessages() {
|
||||
List<string> msgs = new List<string>();
|
||||
List<string> msgs = new List<string>();
|
||||
try {
|
||||
if (!File.Exists("text/infectmessages.txt")) {
|
||||
if (!File.Exists("text/infectmessages.txt")) {
|
||||
File.WriteAllLines("text/infectmessages.txt", defMessages);
|
||||
}
|
||||
}
|
||||
msgs = Utils.ReadAllLinesList("text/infectmessages.txt");
|
||||
} catch (Exception ex) {
|
||||
Logger.LogError(ex);
|
||||
}
|
||||
|
||||
|
||||
if (msgs.Count == 0) msgs = new List<string>(defMessages);
|
||||
return msgs;
|
||||
}
|
||||
|
@ -103,10 +103,10 @@ namespace MCGalaxy.Games {
|
||||
|
||||
static object ReadStats(IDataRecord record, object arg) {
|
||||
ZombieStats stats;
|
||||
stats.TotalRounds = record.GetInt32("TotalRounds");
|
||||
stats.MaxRounds = record.GetInt32("MaxRounds");
|
||||
stats.TotalInfected = record.GetInt32("TotalInfected");
|
||||
stats.MaxInfected = record.GetInt32("MaxInfected");
|
||||
stats.TotalRounds = record.GetInt("TotalRounds");
|
||||
stats.MaxRounds = record.GetInt("MaxRounds");
|
||||
stats.TotalInfected = record.GetInt("TotalInfected");
|
||||
stats.MaxInfected = record.GetInt("MaxInfected");
|
||||
return stats;
|
||||
}
|
||||
|
||||
|
@ -43,14 +43,14 @@ namespace MCGalaxy {
|
||||
|
||||
static object ListZones(IDataRecord record, object arg) {
|
||||
Zone z = new Zone();
|
||||
z.MinX = (ushort)record.GetInt32("SmallX");
|
||||
z.MinY = (ushort)record.GetInt32("SmallY");
|
||||
z.MinX = (ushort)record.GetInt32("SmallZ");
|
||||
z.MinX = (ushort)record.GetInt("SmallX");
|
||||
z.MinY = (ushort)record.GetInt("SmallY");
|
||||
z.MinX = (ushort)record.GetInt("SmallZ");
|
||||
|
||||
z.MaxX = (ushort)record.GetInt32("BigX");
|
||||
z.MaxY = (ushort)record.GetInt32("BigY");
|
||||
z.MaxX = (ushort)record.GetInt32("BigZ");
|
||||
z.Config.Name = record.GetString("Owner");
|
||||
z.MaxX = (ushort)record.GetInt("BigX");
|
||||
z.MaxY = (ushort)record.GetInt("BigY");
|
||||
z.MaxX = (ushort)record.GetInt("BigZ");
|
||||
z.Config.Name = record.GetText("Owner");
|
||||
|
||||
((List<Zone>)arg).Add(z);
|
||||
return arg;
|
||||
|
@ -214,8 +214,8 @@ namespace MCGalaxy {
|
||||
|
||||
void GetPlayerStats() {
|
||||
object raw = Database.Backend.ReadRows("Players", "*",
|
||||
null, PlayerData.Read,
|
||||
"WHERE Name=@0", name);
|
||||
null, PlayerData.Read,
|
||||
"WHERE Name=@0", name);
|
||||
if (raw == null) {
|
||||
PlayerData.Create(this);
|
||||
Chat.MessageFrom(this, "λNICK %Shas connected for the first time!");
|
||||
|
@ -237,7 +237,7 @@ namespace MCGalaxy.Tasks {
|
||||
playerCount++;
|
||||
try {
|
||||
int id = record.GetInt32(0);
|
||||
TimeSpan span = record.GetString(1).ParseDBTime();
|
||||
TimeSpan span = record.GetString(1).ParseOldDBTimeSpent();
|
||||
|
||||
playerIds.Add(id);
|
||||
playerSeconds.Add((long)span.TotalSeconds);
|
||||
@ -256,7 +256,7 @@ namespace MCGalaxy.Tasks {
|
||||
idParam.Value = playerIds[i];
|
||||
secsParam.Value = playerSeconds[i];
|
||||
|
||||
using (IDbCommand cmd = bulk.CreateCommand("UPDATE Players SET TimeSpent = @1 WHERE ID = @0")) {
|
||||
using (IDbCommand cmd = bulk.CreateCommand("UPDATE Players SET TimeSpent=@1 WHERE ID=@0")) {
|
||||
cmd.Parameters.Add(idParam);
|
||||
cmd.Parameters.Add(secsParam);
|
||||
cmd.ExecuteNonQuery();
|
||||
|
@ -21,7 +21,7 @@ using System.Collections.Generic;
|
||||
namespace MCGalaxy {
|
||||
public static class DateExts {
|
||||
|
||||
public static TimeSpan ParseDBTime(this string value) {
|
||||
public static TimeSpan ParseOldDBTimeSpent(this string value) {
|
||||
string[] parts = value.SplitSpaces();
|
||||
return new TimeSpan(int.Parse(parts[0]), int.Parse(parts[1]),
|
||||
int.Parse(parts[2]), int.Parse(parts[3]));
|
||||
|
Loading…
x
Reference in New Issue
Block a user