summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorshennetsind <ind@henn.et>2013-02-14 17:04:42 -0200
committershennetsind <ind@henn.et>2013-02-14 17:15:36 -0200
commit810ba40b78087cc6aa7eb9ad3a3e46534393b9e8 (patch)
treee205d88bc02194101fc2a7aa2d80e5d884fe8a9c /src
parent20abc4a94a4bd3a7428c042cc6d1c313272fbc28 (diff)
downloadhercules-810ba40b78087cc6aa7eb9ad3a3e46534393b9e8.tar.gz
hercules-810ba40b78087cc6aa7eb9ad3a3e46534393b9e8.tar.bz2
hercules-810ba40b78087cc6aa7eb9ad3a3e46534393b9e8.tar.xz
hercules-810ba40b78087cc6aa7eb9ad3a3e46534393b9e8.zip
Introducing MySQL DB Update Checker
First version. Signed-off-by: shennetsind <ind@henn.et>
Diffstat (limited to 'src')
-rw-r--r--src/char/char.c1
-rw-r--r--src/common/sql.c47
-rw-r--r--src/common/sql.h2
-rw-r--r--src/login/account.h1
-rw-r--r--src/login/account_sql.c4
-rw-r--r--src/login/login.c4
-rw-r--r--src/map/map.c2
7 files changed, 59 insertions, 2 deletions
diff --git a/src/char/char.c b/src/char/char.c
index 1b5c7898d..f3f93ab01 100644
--- a/src/char/char.c
+++ b/src/char/char.c
@@ -4820,6 +4820,7 @@ int do_init(int argc, char **argv)
char_fd = make_listen_bind(bind_ip, char_port);
ShowStatus("The char-server is "CL_GREEN"ready"CL_RESET" (Server is listening on the port %d).\n\n", char_port);
+ Sql_HerculesUpdateCheck(sql_handle);
if( runflag != CORE_ST_STOP )
{
shutdown_callback = do_shutdown;
diff --git a/src/common/sql.c b/src/common/sql.c
index b842db46d..fdb6e0114 100644
--- a/src/common/sql.c
+++ b/src/common/sql.c
@@ -1016,6 +1016,53 @@ void Sql_inter_server_read(const char* cfgName, bool first) {
return;
}
+void Sql_HerculesUpdateCheck(Sql* self) {
+ char line[22];// "yyyy-mm-dd--hh-mm" (17) + ".sql" (4) + 1
+ FILE* ifp;/* index fp */
+ unsigned int performed = 0;
+
+ if( !( ifp = fopen("sql-files/upgrades/index.txt", "r") ) ) {
+ ShowError("SQL upgrade index was not found!\n");
+ return;
+ }
+
+ while(fgets(line, sizeof(line), ifp)) {
+ char path[41];// "sql-files/upgrades/" (19) + "yyyy-mm-dd--hh-mm" (17) + ".sql" (4) + 1
+ char timestamp[11];// "1360186680" (10) + 1
+ FILE* ufp;/* upgrade fp */
+
+ sprintf(path,"sql-files/upgrades/%s",line);
+
+ if( !( ufp = fopen(path, "r") ) ) {
+ ShowError("SQL upgrade file %s was not found!\n",path);
+ continue;
+ }
+
+ if( fgetc(ufp) != '#' )
+ continue;
+
+ fseek (ufp,1,SEEK_SET);/* woo. skip the # */
+
+ if( fgets(timestamp,sizeof(timestamp),ufp) ) {
+ unsigned int timestampui = atol(timestamp);
+ if( SQL_ERROR == Sql_Query(self, "SELECT 1 FROM `sql_updates` WHERE `timestamp` = '%u' LIMIT 1", timestampui) )
+ Sql_ShowDebug(self);
+ if( Sql_NumRows(self) != 1 ) {
+ ShowSQL("'"CL_WHITE"%s"CL_RESET"' wasn't applied to the database\n",path);
+ performed++;
+ }
+ }
+
+ fclose(ufp);
+ }
+
+ fclose(ifp);
+
+ if( performed ) {
+ ShowSQL("If you did apply these updates or would like to be skip, insert a new entry in your sql_updates table with the timestamp of each file\n");
+ }
+}
+
void Sql_Init(void) {
Sql_inter_server_read("conf/inter-server.conf",true);
}
diff --git a/src/common/sql.h b/src/common/sql.h
index b7159ec90..ebbd1711f 100644
--- a/src/common/sql.h
+++ b/src/common/sql.h
@@ -325,7 +325,7 @@ int SqlStmt_NextRow(SqlStmt* self);
/// Frees the result of the statement execution.
void SqlStmt_FreeResult(SqlStmt* self);
-
+void Sql_HerculesUpdateCheck(Sql* self);
#if defined(SQL_REMOVE_SHOWDEBUG)
#define SqlStmt_ShowDebug(self) (void)0
diff --git a/src/login/account.h b/src/login/account.h
index 1b567be70..adbcb7102 100644
--- a/src/login/account.h
+++ b/src/login/account.h
@@ -152,5 +152,6 @@ struct AccountDB
AccountDBIterator* (*iterator)(AccountDB* self);
};
+void account_db_sql_up(AccountDB* self);
#endif // __ACCOUNT_H_INCLUDED__
diff --git a/src/login/account_sql.c b/src/login/account_sql.c
index 5073941e2..ae80163af 100644
--- a/src/login/account_sql.c
+++ b/src/login/account_sql.c
@@ -678,3 +678,7 @@ static bool mmo_auth_tosql(AccountDB_SQL* db, const struct mmo_account* acc, boo
return result;
}
+void account_db_sql_up(AccountDB* self) {
+ AccountDB_SQL* db = (AccountDB_SQL*)self;
+ Sql_HerculesUpdateCheck(db->accounts);
+} \ No newline at end of file
diff --git a/src/login/login.c b/src/login/login.c
index 7f272e2a4..c7e250040 100644
--- a/src/login/login.c
+++ b/src/login/login.c
@@ -1879,6 +1879,8 @@ int do_init(int argc, char** argv)
ShowStatus("The login-server is "CL_GREEN"ready"CL_RESET" (Server is listening on the port %u).\n\n", login_config.login_port);
login_log(0, "login server", 100, "login server started");
-
+
+ account_db_sql_up(accounts);
+
return 0;
}
diff --git a/src/map/map.c b/src/map/map.c
index 6f9401dad..a42d7abca 100644
--- a/src/map/map.c
+++ b/src/map/map.c
@@ -3939,6 +3939,8 @@ int do_init(int argc, char *argv[])
ShowStatus("Server is '"CL_GREEN"ready"CL_RESET"' and listening on port '"CL_WHITE"%d"CL_RESET"'.\n\n", map_port);
+ Sql_HerculesUpdateCheck(mmysql_handle);
+
if( runflag != CORE_ST_STOP )
{
shutdown_callback = do_shutdown;