diff --git a/TShockAPI/DB/BanManager.cs b/TShockAPI/DB/BanManager.cs index 1fa34de9..dfda68e0 100644 --- a/TShockAPI/DB/BanManager.cs +++ b/TShockAPI/DB/BanManager.cs @@ -44,6 +44,35 @@ namespace TShockAPI.DB "CREATE TABLE IF NOT EXISTS Bans (IP VARCHAR(255) PRIMARY, Name VARCHAR(255), Reason VARCHAR(255));"; com.ExecuteNonQuery(); + + String file = Path.Combine( TShock.SavePath, "bans.txt" ); + if (File.Exists(file)) + { + using (StreamReader sr = new StreamReader(file)) + { + String line; + while ((line = sr.ReadLine()) != null) + { + String[] info = line.Split('|'); + if (TShock.Config.StorageType.ToLower() == "sqlite") + com.CommandText = "INSERT OR IGNORE INTO Bans (IP, Name, Reason) VALUES (@ip, @name, @reason);"; + else if (TShock.Config.StorageType.ToLower() == "mysql") + com.CommandText = "INSERT IGNORE INTO Bans SET IP=@ip, Name=@name, Reason=@reason;"; + com.AddParameter("@ip", info[0].Trim()); + com.AddParameter("@name", info[1].Trim()); + com.AddParameter("@reason", info[2].Trim()); + com.ExecuteNonQuery(); + com.Parameters.Clear(); + } + } + String path = Path.Combine(TShock.SavePath, "old_configs"); + String file2 = Path.Combine(path, "bans.txt"); + if (!Directory.Exists(path)) + System.IO.Directory.CreateDirectory(path); + if (File.Exists(file2)) + File.Delete(file2); + File.Move(file, file2); + } } } diff --git a/TShockAPI/DB/GroupManager.cs b/TShockAPI/DB/GroupManager.cs index 30b0a022..7b15da46 100644 --- a/TShockAPI/DB/GroupManager.cs +++ b/TShockAPI/DB/GroupManager.cs @@ -1,4 +1,5 @@ using System; +using System.IO; using System.Collections.Generic; using System.Linq; using System.Text; @@ -79,6 +80,50 @@ namespace TShockAPI.DB com.ExecuteNonQuery(); com.Parameters.Clear(); + String file = Path.Combine(TShock.SavePath, "groups.txt"); + if (File.Exists(file)) + { + using (StreamReader sr = new StreamReader(file)) + { + String line; + while ((line = sr.ReadLine()) != null) + { + if( !line.Equals("") && !line.Substring( 0,1 ).Equals( "#" ) ) + { + String[] info = line.Split(' '); + if (TShock.Config.StorageType.ToLower() == "sqlite") + com.CommandText = "INSERT OR IGNORE INTO GroupList (GroupName, Commands, OrderBy) VALUES (@groupname, @commands, @order);"; + else if (TShock.Config.StorageType.ToLower() == "mysql") + com.CommandText = "INSERT IGNORE INTO GroupList SET GroupName=@groupname, Commands=@commands, OrderBy=@order;"; + String comms = ""; + int size = info.Length; + int test = 0; + bool hasOrder = int.TryParse(info[info.Length - 1], out test); + if( hasOrder ) + size = info.Length - 1; + for (int i = 1; i < size; i++) + { + if (!comms.Equals("")) + comms = comms + ","; + comms = comms + info[i].Trim(); + } + com.AddParameter("@groupname", info[0].Trim()); + com.AddParameter("@commands", comms); + com.AddParameter("@order", hasOrder ? info[info.Length-1] : "0"); + com.ExecuteNonQuery(); + com.Parameters.Clear(); + } + } + } + String path = Path.Combine(TShock.SavePath, "old_configs"); + String file2 = Path.Combine(path, "groups.txt"); + if (!Directory.Exists(path)) + System.IO.Directory.CreateDirectory(path); + if (File.Exists(file2)) + File.Delete(file2); + File.Move(file, file2); + } + LoadPermisions(); } }