Use sleep(10) instead of sleep(3) to reduce CPU usage slightly, also add AddColumn to IDatabaseBackend.

This commit is contained in:
UnknownShadow200 2016-09-05 22:04:04 +10:00
parent 8a27ec99bc
commit bf291fa062
8 changed files with 33 additions and 12 deletions

View File

@ -45,7 +45,7 @@ namespace MCGalaxy.Commands {
}
string targetName = PlayerInfo.GetColoredName(p, target);
Player.Message(p, "Economy stats for {0}%S:", targetName);
Player.Message(p, "Economy stats for {0}%S:", targetName);
Player.Message(p, " Current balance: &f{0} &3{1}", money, Server.moneys);
Economy.EcoStats ecos = Economy.RetrieveStats(target);

View File

@ -59,12 +59,12 @@ namespace MCGalaxy.Commands {
Player.Message(p, "Cannot /infoswap for a player ranked equal or higher to yours."); return;
}
Swap(src, dst); Swap(dst, src);
SetData(src, dst.Name); SetData(dst, src.Name);
SwapGroups(src, dst, srcGroup, dstGroup);
}
const string format = "yyyy-MM-dd HH:mm:ss";
void Swap(PlayerData src, PlayerData dst) {
void SetData(PlayerData src, string dstName) {
string first = src.FirstLogin.ToString(format);
string last = src.LastLogin.ToString(format);
const string syntax = "UPDATE Players SET totalBlocks=@0, totalCuboided=@1" +
@ -75,7 +75,7 @@ namespace MCGalaxy.Commands {
long cuboided = PlayerData.CuboidPacked(src.TotalDeleted, src.TotalDrawn);
Database.Execute(syntax, blocks, cuboided, src.Color, src.Deaths,
first, src.IP, src.Kicks, last, src.Logins,
src.Money, src.Title, src.TitleColor, src.TotalTime, dst.Name);
src.Money, src.Title, src.TitleColor, src.TotalTime, dstName);
}
void SwapGroups(PlayerData src, PlayerData dst, Group srcGroup, Group dstGroup) {

View File

@ -37,7 +37,7 @@ namespace MCGalaxy.Commands {
void DoRide(Player p) {
while (p.onTrain) {
Thread.Sleep(3);
Thread.Sleep(10);
ushort x = (ushort)(p.pos[0] / 32);
ushort y = (ushort)(p.pos[1] / 32);
ushort z = (ushort)(p.pos[2] / 32);
@ -74,7 +74,7 @@ namespace MCGalaxy.Commands {
goto skip;
}
Thread.Sleep(3);
Thread.Sleep(10);
p.trainGrab = false;
skip:
;

View File

@ -53,6 +53,11 @@ namespace MCGalaxy.SQL {
/// <summary> Removes all entries from the given table. </summary>
public abstract void ClearTable(string table);
/// <summary> Adds a new coloumn to the given table. </summary>
/// <remarks> Note colAfter is only a hint - some database backends ignore this. </remarks>
public abstract void AddColumn(string table, string column,
string colype, string colAfter);
/// <summary> Inserts/Copies all the rows from the source table into the destination table. </summary>
/// <remarks> Note: This may work incorrectly if the tables have different schema. </remarks>
public virtual void CopyAllRows(string srcTable, string dstTable) {

View File

@ -63,5 +63,14 @@ namespace MCGalaxy.SQL {
string syntax = "TRUNCATE TABLE `" + table + "`";
Database.Execute(syntax);
}
public override void AddColumn(string table, string column,
string colType, string colAfter) {
string syntax = "ALTER TABLE `" + table + "` ADD COLUMN "
+ column + " " + colType;
if (colAfter != "") syntax += " AFTER " + colAfter;
Database.Execute(syntax);
}
}
}

View File

@ -47,7 +47,7 @@ namespace MCGalaxy.SQL {
public override bool TableExists(string table) {
using (DataTable results = GetRows("sqlite_master", "name",
"WHERE type='table' AND name=@0", table)) {
"WHERE type='table' AND name=@0", table)) {
return results.Rows.Count > 0;
}
}
@ -61,5 +61,12 @@ namespace MCGalaxy.SQL {
string syntax = "DELETE FROM `" + table + "`";
Database.Execute(syntax);
}
public override void AddColumn(string table, string column,
string colType, string colAfter) {
string syntax = "ALTER TABLE `" + table + "` ADD COLUMN "
+ column + " " + colType;
Database.Execute(syntax);
}
}
}

View File

@ -88,22 +88,22 @@ SELECT Time, Name, Cmd, Cmdmsg FROM Playercmds WHERE {0};";
// Check if the color column exists.
DataTable colorExists = Database.Fill("SHOW COLUMNS FROM Players WHERE `Field`='color'");
if (colorExists.Rows.Count == 0)
Database.Execute("ALTER TABLE Players ADD COLUMN color VARCHAR(6) AFTER totalKicked");
Database.Backend.AddColumn("Players", "color", "VARCHAR(6)", "totalKicked");
colorExists.Dispose();
DataTable tcolorExists = Database.Fill("SHOW COLUMNS FROM Players WHERE `Field`='title_color'");
if (tcolorExists.Rows.Count == 0)
Database.Execute("ALTER TABLE Players ADD COLUMN title_color VARCHAR(6) AFTER color");
Database.Backend.AddColumn("Players", "title_color", "VARCHAR(6)", "color");
tcolorExists.Dispose();
DataTable timespent = Database.Fill("SHOW COLUMNS FROM Players WHERE `Field`='TimeSpent'");
if (timespent.Rows.Count == 0)
Database.Execute("ALTER TABLE Players ADD COLUMN TimeSpent VARCHAR(20) AFTER totalKicked");
Database.Backend.AddColumn("Players", "TimeSpent", "VARCHAR(20)", "totalKicked");
timespent.Dispose();
DataTable totalCuboided = Database.Fill("SHOW COLUMNS FROM Players WHERE `Field`='totalCuboided'");
if (totalCuboided.Rows.Count == 0)
Database.Execute("ALTER TABLE Players ADD COLUMN totalCuboided BIGINT AFTER totalBlocks");
Database.Backend.AddColumn("Players", "totalCuboided", "BIGINT", "totalBlocks");
totalCuboided.Dispose();
}
}

View File

@ -26,7 +26,7 @@ namespace MCGalaxy {
void DoLocationChecks() {
while (true) {
Player[] players = PlayerInfo.Online.Items;
Thread.Sleep(players.Length == 0 ? 16 : 3);
Thread.Sleep(players.Length == 0 ? 20 : 10);
players = PlayerInfo.Online.Items;
for (int i = 0; i < players.Length; i++) {