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