Bans and Groups now convert from txt to db items.

Just put bans.txt and groups.txt in the tShock folder( where they already exist i believe ) and run the server.  It moves the files to tShock/old_configs in case you want to keep them.
This commit is contained in:
Zack Piispanen 2011-07-17 15:17:28 -04:00
parent 77998470bc
commit f08b94c8f8
2 changed files with 74 additions and 0 deletions

View file

@ -44,6 +44,35 @@ namespace TShockAPI.DB
"CREATE TABLE IF NOT EXISTS Bans (IP VARCHAR(255) PRIMARY, Name VARCHAR(255), Reason VARCHAR(255));"; "CREATE TABLE IF NOT EXISTS Bans (IP VARCHAR(255) PRIMARY, Name VARCHAR(255), Reason VARCHAR(255));";
com.ExecuteNonQuery(); 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);
}
} }
} }

View file

@ -1,4 +1,5 @@
using System; using System;
using System.IO;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -79,6 +80,50 @@ namespace TShockAPI.DB
com.ExecuteNonQuery(); com.ExecuteNonQuery();
com.Parameters.Clear(); 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(); LoadPermisions();
} }
} }