mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-24 05:03:34 -04:00
Do a Database.TableExists check when deleting and renaming level portals/mbs/zone tables.
This commit is contained in:
parent
5ace7cd08c
commit
6e1dcc72f1
@ -24,7 +24,7 @@ namespace MCGalaxy {
|
|||||||
|
|
||||||
public static class LevelActions {
|
public static class LevelActions {
|
||||||
|
|
||||||
/// <summary> Renames the .lvl (and related) files and database tables.
|
/// <summary> Renames the .lvl (and related) files and database tables.
|
||||||
/// Does not perform any unloading. </summary>
|
/// Does not perform any unloading. </summary>
|
||||||
public static void Rename(string src, string dst) {
|
public static void Rename(string src, string dst) {
|
||||||
File.Move(LevelInfo.LevelPath(src), LevelInfo.LevelPath(dst));
|
File.Move(LevelInfo.LevelPath(src), LevelInfo.LevelPath(dst));
|
||||||
@ -57,19 +57,18 @@ namespace MCGalaxy {
|
|||||||
|
|
||||||
//safe against SQL injections because foundLevel is being checked and,
|
//safe against SQL injections because foundLevel is being checked and,
|
||||||
//newName is being split and partly checked on illegal characters reserved for Windows.
|
//newName is being split and partly checked on illegal characters reserved for Windows.
|
||||||
if (Server.useMySQL)
|
string syntax = Server.useMySQL
|
||||||
Database.Execute(String.Format("RENAME TABLE `Block{0}` TO `Block{1}`, " +
|
? "RENAME TABLE `{2}{0}` TO `{2}{1}`" : "ALTER TABLE `{2}{0}` RENAME TO `{2}{1}`";
|
||||||
"`Portals{0}` TO `Portals{1}`, " +
|
Database.Execute(String.Format(syntax, src, dst, "Blocks"));
|
||||||
"`Messages{0}` TO `Messages{1}`, " +
|
|
||||||
"`Zone{0}` TO `Zone{1}`", src, dst));
|
object locker = ThreadSafeCache.DBCache.Get(src);
|
||||||
else {
|
lock (locker) {
|
||||||
using (BulkTransaction helper = SQLiteBulkTransaction.Create()) { // ensures that it's either all work, or none work.
|
if (Database.TableExists("Portals" + src))
|
||||||
helper.Execute(String.Format("ALTER TABLE `Block{0}` RENAME TO `Block{1}`", src, dst));
|
Database.Execute(String.Format(syntax, src, dst, "Portals"));
|
||||||
helper.Execute(String.Format("ALTER TABLE `Portals{0}` RENAME TO `Portals{1}`", src, dst));
|
if (Database.TableExists("Messages" + src))
|
||||||
helper.Execute(String.Format("ALTER TABLE `Messages{0}` RENAME TO `Messages{1}`", src, dst));
|
Database.Execute(String.Format(syntax, src, dst, "Messages"));
|
||||||
helper.Execute(String.Format("ALTER TABLE `Zone{0}` RENAME TO `Zone{1}`", src, dst));
|
if (Database.TableExists("Zone" + src))
|
||||||
helper.Commit();
|
Database.Execute(String.Format(syntax, src, dst, "Zone"));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,13 +97,13 @@ namespace MCGalaxy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary> Deletes the .lvl (and related) files and database tables.
|
/// <summary> Deletes the .lvl (and related) files and database tables.
|
||||||
/// Unloads a level (if present) which exactly matches name. </summary>
|
/// Unloads a level (if present) which exactly matches name. </summary>
|
||||||
public static void Delete(string name) {
|
public static void Delete(string name) {
|
||||||
Level lvl = LevelInfo.FindExact(name);
|
Level lvl = LevelInfo.FindExact(name);
|
||||||
if (lvl != null) lvl.Unload();
|
if (lvl != null) lvl.Unload();
|
||||||
|
|
||||||
if (!Directory.Exists("levels/deleted"))
|
if (!Directory.Exists("levels/deleted"))
|
||||||
Directory.CreateDirectory("levels/deleted");
|
Directory.CreateDirectory("levels/deleted");
|
||||||
|
|
||||||
if (File.Exists("levels/deleted/" + name + ".lvl")) {
|
if (File.Exists("levels/deleted/" + name + ".lvl")) {
|
||||||
@ -128,9 +127,12 @@ namespace MCGalaxy {
|
|||||||
Database.Execute("DROP TABLE `Block" + name + "`");
|
Database.Execute("DROP TABLE `Block" + name + "`");
|
||||||
object locker = ThreadSafeCache.DBCache.Get(name);
|
object locker = ThreadSafeCache.DBCache.Get(name);
|
||||||
lock (locker) {
|
lock (locker) {
|
||||||
Database.Execute("DROP TABLE `Portals" + name + "`");
|
if (Database.TableExists("Portals" + name))
|
||||||
Database.Execute("DROP TABLE `Messages" + name + "`");
|
Database.Execute("DROP TABLE `Portals" + name + "`");
|
||||||
Database.Execute("DROP TABLE `Zone" + name + "`");
|
if (Database.TableExists("Messages" + name))
|
||||||
|
Database.Execute("DROP TABLE `Messages" + name + "`");
|
||||||
|
if (Database.TableExists("Zone" + name))
|
||||||
|
Database.Execute("DROP TABLE `Zone" + name + "`");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ namespace MCGalaxy.BlockPhysics {
|
|||||||
|
|
||||||
public bool HasWait {
|
public bool HasWait {
|
||||||
get { return (Raw & TypeBitsMask) == Wait
|
get { return (Raw & TypeBitsMask) == Wait
|
||||||
|| ((Raw >> 3) & TypeBitsMask) == Wait);
|
|| ((Raw >> 3) & TypeBitsMask) == Wait;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user