mirror of
https://github.com/islehorse/HISP.git
synced 2025-04-06 21:25:42 +12:00
Add DataFixerUpper
This commit is contained in:
parent
3105689753
commit
e42b0bf782
7 changed files with 1031 additions and 877 deletions
|
@ -31,5 +31,5 @@ using System.Runtime.InteropServices;
|
||||||
// You can specify all the values or you can default the Build and Revision Numbers
|
// You can specify all the values or you can default the Build and Revision Numbers
|
||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("1.7.11.0")]
|
[assembly: AssemblyVersion("1.7.20.0")]
|
||||||
[assembly: AssemblyFileVersion("1.7.11.0")]
|
[assembly: AssemblyFileVersion("1.7.20.0")]
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
Package: hisp
|
Package: hisp
|
||||||
Version: 1.7.11
|
Version: 1.7.20
|
||||||
Depends: coreutils,systemd,mariadb-server,libsqlite3-dev,zlib1g-dev,libicu-dev,libkrb5-dev
|
Depends: coreutils,systemd,mariadb-server,libsqlite3-dev,zlib1g-dev,libicu-dev,libkrb5-dev
|
||||||
Maintainer: Li
|
Maintainer: Li
|
||||||
Homepage: https://islehorse.com
|
Homepage: https://islehorse.com
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -30,5 +30,5 @@ using System.Runtime.InteropServices;
|
||||||
//
|
//
|
||||||
// You can specify all the values or you can default the Build and Revision Numbers
|
// You can specify all the values or you can default the Build and Revision Numbers
|
||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
[assembly: AssemblyVersion("1.7.11.0")]
|
[assembly: AssemblyVersion("1.7.20.0")]
|
||||||
[assembly: AssemblyFileVersion("1.7.11.0")]
|
[assembly: AssemblyFileVersion("1.7.20.0")]
|
||||||
|
|
63
HorseIsleServer/LibHISP/Server/DataFixerUpper.cs
Normal file
63
HorseIsleServer/LibHISP/Server/DataFixerUpper.cs
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace HISP.Server
|
||||||
|
{
|
||||||
|
static class DataFixerUpper
|
||||||
|
{
|
||||||
|
private static void fixupVersion1_0()
|
||||||
|
{
|
||||||
|
// Add total logins column to UserExt
|
||||||
|
Database.TryExecuteSqlQuery("ALTER TABLE UserExt ADD COLUMN TotalLogins INT;");
|
||||||
|
Database.TryExecuteSqlQuery("UPDATE UserExt SET TotalLogins=0;");
|
||||||
|
|
||||||
|
// Add New column to OnlineUsers.
|
||||||
|
Database.TryExecuteSqlQuery("ALTER TABLE OnlineUsers ADD COLUMN New TEXT(3);");
|
||||||
|
Database.TryExecuteSqlQuery("UPDATE OnlineUsers SET New=\"NO\";");
|
||||||
|
|
||||||
|
// Alter sizes
|
||||||
|
Database.TryExecuteSqlQuery("ALTER TABLE UserExt CHANGE COLUMN ProfilePage ProfilePage TEXT(4000);");
|
||||||
|
Database.TryExecuteSqlQuery("ALTER TABLE UserExt CHANGE COLUMN PrivateNotes PrivateNotes TEXT(65535);");
|
||||||
|
Database.TryExecuteSqlQuery("ALTER TABLE MailBox CHANGE COLUMN Subject Subject TEXT(100);");
|
||||||
|
Database.TryExecuteSqlQuery("ALTER TABLE MailBox CHANGE COLUMN Message Message TEXT(65535);");
|
||||||
|
Database.TryExecuteSqlQuery("ALTER TABLE Horses CHANGE COLUMN description description TEXT(4000);");
|
||||||
|
Database.TryExecuteSqlQuery("ALTER TABLE WildHorse CHANGE COLUMN description description TEXT(4000);");
|
||||||
|
Database.TryExecuteSqlQuery("ALTER TABLE Ranches CHANGE COLUMN title title TEXT(50);");
|
||||||
|
Database.TryExecuteSqlQuery("ALTER TABLE Ranches CHANGE COLUMN description description TEXT(250);");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void fixupVersion1_1()
|
||||||
|
{
|
||||||
|
// Add data column to shop to ShopInventory
|
||||||
|
Database.TryExecuteSqlQuery("ALTER TABLE ShopInventory ADD COLUMN Data INT;");
|
||||||
|
Database.TryExecuteSqlQuery("UPDATE ShopInventory SET Data=0;");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void fixupVersion1_7_20()
|
||||||
|
{
|
||||||
|
// Add LastLoadedInVersion column to World.
|
||||||
|
Database.TryExecuteSqlQuery("ALTER TABLE World ADD COLUMN LastLoadedInVersion TEXT(64)");
|
||||||
|
Database.TryExecuteSqlQuery("UPDATE World SET LastLoadedInVersion=\"v1.7.20\";");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void FixUpDb()
|
||||||
|
{
|
||||||
|
string lastVersionStr = Database.GetLastLoadedVersion();
|
||||||
|
string currentVersionStr = ServerVersion.GetVersionString();
|
||||||
|
|
||||||
|
int lastVersion = Convert.ToInt32(Int32.Parse(lastVersionStr.ToLower().Replace("v", "").Replace(".", "")));
|
||||||
|
int currentVersion = Convert.ToInt32(Int32.Parse(currentVersionStr.ToLower().Replace("v", "").Replace(".", "")));
|
||||||
|
|
||||||
|
if(currentVersion > lastVersion)
|
||||||
|
{
|
||||||
|
Logger.WarnPrint("Migrating Database from " + lastVersionStr + " to " + currentVersionStr);
|
||||||
|
|
||||||
|
if (lastVersion <= 10) fixupVersion1_0();
|
||||||
|
if (lastVersion <= 11) fixupVersion1_1();
|
||||||
|
if (lastVersion <= 1720) fixupVersion1_7_20();
|
||||||
|
|
||||||
|
Database.SetLastLoadedVersion(ServerVersion.GetVersionString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -46,6 +46,24 @@ namespace HISP.Server
|
||||||
SqliteConnection.ClearAllPools();
|
SqliteConnection.ClearAllPools();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool TryExecuteSqlQuery(string query)
|
||||||
|
{
|
||||||
|
using (DbConnection db = connectDb())
|
||||||
|
{
|
||||||
|
db.Open();
|
||||||
|
DbCommand sqlCommand = db.CreateCommand();
|
||||||
|
sqlCommand.CommandText = query;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
sqlCommand.ExecuteNonQuery();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
public static void OpenDatabase()
|
public static void OpenDatabase()
|
||||||
{
|
{
|
||||||
if (!ConfigReader.SqlLite)
|
if (!ConfigReader.SqlLite)
|
||||||
|
@ -53,7 +71,8 @@ namespace HISP.Server
|
||||||
else
|
else
|
||||||
ConnectionString = "Data Source=\"" + ConfigReader.DatabaseName + ".db\";";
|
ConnectionString = "Data Source=\"" + ConfigReader.DatabaseName + ".db\";";
|
||||||
|
|
||||||
|
DataFixerUpper.FixUpDb();
|
||||||
|
|
||||||
using (DbConnection db = connectDb())
|
using (DbConnection db = connectDb())
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -74,7 +93,7 @@ namespace HISP.Server
|
||||||
string MailTable = "CREATE TABLE IF NOT EXISTS Mailbox(RandomId INT, IdTo INT, IdFrom INT, Subject TEXT(100), Message Text(65535), TimeSent INT, BeenRead TEXT(3))";
|
string MailTable = "CREATE TABLE IF NOT EXISTS Mailbox(RandomId INT, IdTo INT, IdFrom INT, Subject TEXT(100), Message Text(65535), TimeSent INT, BeenRead TEXT(3))";
|
||||||
string BuddyTable = "CREATE TABLE IF NOT EXISTS BuddyList(Id INT, IdFriend INT)";
|
string BuddyTable = "CREATE TABLE IF NOT EXISTS BuddyList(Id INT, IdFriend INT)";
|
||||||
string MessageQueue = "CREATE TABLE IF NOT EXISTS MessageQueue(Id INT, Message TEXT(1028))";
|
string MessageQueue = "CREATE TABLE IF NOT EXISTS MessageQueue(Id INT, Message TEXT(1028))";
|
||||||
string WorldTable = "CREATE TABLE World(Time INT, Day INT, Year INT, StartTime INT)";
|
string WorldTable = "CREATE TABLE IF NOT EXISTS World(Time INT, Day INT, Year INT, StartTime INT, LastLoadedInVersion TEXT(64))";
|
||||||
string WeatherTable = "CREATE TABLE IF NOT EXISTS Weather(Area TEXT(1028), Weather TEXT(64))";
|
string WeatherTable = "CREATE TABLE IF NOT EXISTS Weather(Area TEXT(1028), Weather TEXT(64))";
|
||||||
string InventoryTable = "CREATE TABLE IF NOT EXISTS Inventory(PlayerID INT, RandomID INT, ItemID INT, Data INT)";
|
string InventoryTable = "CREATE TABLE IF NOT EXISTS Inventory(PlayerID INT, RandomID INT, ItemID INT, Data INT)";
|
||||||
string ShopInventory = "CREATE TABLE IF NOT EXISTS ShopInventory(ShopID INT, RandomID INT, ItemID INT, Data INT)";
|
string ShopInventory = "CREATE TABLE IF NOT EXISTS ShopInventory(ShopID INT, RandomID INT, ItemID INT, Data INT)";
|
||||||
|
@ -550,18 +569,16 @@ namespace HISP.Server
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
DbCommand sqlCommand = db.CreateCommand();
|
DbCommand sqlCommand = db.CreateCommand();
|
||||||
sqlCommand.CommandText = WorldTable;
|
sqlCommand.CommandText = WorldTable;
|
||||||
sqlCommand.ExecuteNonQuery();
|
sqlCommand.ExecuteNonQuery();
|
||||||
|
|
||||||
sqlCommand = db.CreateCommand();
|
sqlCommand = db.CreateCommand();
|
||||||
sqlCommand.CommandText = "INSERT INTO World VALUES(0,0,0,@startDate)";
|
sqlCommand.CommandText = "INSERT INTO World VALUES(0,0,0,@startDate,@version)";
|
||||||
addWithValue(sqlCommand, "@startDate", (int)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds);
|
addWithValue(sqlCommand, "@startDate", (UInt32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds);
|
||||||
|
addWithValue(sqlCommand, "@version", ServerVersion.GetVersionString());
|
||||||
sqlCommand.Prepare();
|
sqlCommand.Prepare();
|
||||||
sqlCommand.ExecuteNonQuery();
|
sqlCommand.ExecuteNonQuery();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
@ -2598,6 +2615,80 @@ namespace HISP.Server
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public static void SetLastLoadedVersion(string version)
|
||||||
|
{
|
||||||
|
using (DbConnection db = connectDb())
|
||||||
|
{
|
||||||
|
db.Open();
|
||||||
|
DbCommand sqlCommand = db.CreateCommand();
|
||||||
|
sqlCommand.CommandText = "UPDATE World SET LastLoadedInVersion=@version";
|
||||||
|
addWithValue(sqlCommand, "@version", version);
|
||||||
|
sqlCommand.Prepare();
|
||||||
|
sqlCommand.ExecuteNonQuery();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tests if the game was previously loaded in 1.0
|
||||||
|
public static bool TestFor1_0()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (DbConnection db = connectDb())
|
||||||
|
{
|
||||||
|
db.Open();
|
||||||
|
DbCommand sqlCommand = db.CreateCommand();
|
||||||
|
sqlCommand.CommandText = "SELECT TotalLogins FROM UserExt LIMIT 1;";
|
||||||
|
sqlCommand.ExecuteNonQuery();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
//Tests if game was previously loaded in v1.1
|
||||||
|
public static bool TestFor1_1()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (DbConnection db = connectDb())
|
||||||
|
{
|
||||||
|
db.Open();
|
||||||
|
DbCommand sqlCommand = db.CreateCommand();
|
||||||
|
sqlCommand.CommandText = "SELECT Data FROM ShopInventory LIMIT 1;";
|
||||||
|
sqlCommand.ExecuteNonQuery();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string GetLastLoadedVersion()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (DbConnection db = connectDb())
|
||||||
|
{
|
||||||
|
db.Open();
|
||||||
|
DbCommand sqlCommand = db.CreateCommand();
|
||||||
|
sqlCommand.CommandText = "SELECT LastLoadedInVersion FROM World";
|
||||||
|
string lastVersion = sqlCommand.ExecuteScalar().ToString();
|
||||||
|
|
||||||
|
return lastVersion;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception) // table not found? must have been before v1.7.20.
|
||||||
|
{
|
||||||
|
if (TestFor1_0()) return "v1.0";
|
||||||
|
if (TestFor1_1()) return "v1.1";
|
||||||
|
return "v1.7.20";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void SetStartTime(int startTime)
|
public static void SetStartTime(int startTime)
|
||||||
{
|
{
|
||||||
|
|
|
@ -31,5 +31,5 @@ using System.Runtime.InteropServices;
|
||||||
// You can specify all the values or you can default the Build and Revision Numbers
|
// You can specify all the values or you can default the Build and Revision Numbers
|
||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("1.7.11.0")]
|
[assembly: AssemblyVersion("1.7.20.0")]
|
||||||
[assembly: AssemblyFileVersion("1.7.11.0")]
|
[assembly: AssemblyFileVersion("1.7.20.0")]
|
||||||
|
|
Loading…
Add table
Reference in a new issue