diff options
author | shennetsind <ind@henn.et> | 2013-07-08 15:34:41 -0300 |
---|---|---|
committer | shennetsind <ind@henn.et> | 2013-07-08 15:34:41 -0300 |
commit | 8f7418ffaffb763e435b29eee5707c66d5615e73 (patch) | |
tree | ea4b44356fd036f4cce16738547684a70fc2dd6f | |
parent | 4f69a9ea0f80e78da61482b2d1143a6e58859fd1 (diff) | |
download | hercules-8f7418ffaffb763e435b29eee5707c66d5615e73.tar.gz hercules-8f7418ffaffb763e435b29eee5707c66d5615e73.tar.bz2 hercules-8f7418ffaffb763e435b29eee5707c66d5615e73.tar.xz hercules-8f7418ffaffb763e435b29eee5707c66d5615e73.zip |
Cygwin Fix for the Hercules SQL Update Check
Also modified the output (i think its sightly improved), also added a console command to skip updates so no need to go add the query yourself 'sql update skip <file name>'
Signed-off-by: shennetsind <ind@henn.et>
-rw-r--r-- | src/char/char.c | 2 | ||||
-rw-r--r-- | src/common/console.c | 16 | ||||
-rw-r--r-- | src/common/console.h | 4 | ||||
-rw-r--r-- | src/common/sql.c | 52 | ||||
-rw-r--r-- | src/common/sql.h | 1 | ||||
-rw-r--r-- | src/login/account_sql.c | 2 | ||||
-rw-r--r-- | src/map/map.c | 1 |
7 files changed, 74 insertions, 4 deletions
diff --git a/src/char/char.c b/src/char/char.c index a941dac14..b38e3e6c0 100644 --- a/src/char/char.c +++ b/src/char/char.c @@ -13,6 +13,7 @@ #include "../common/strlib.h" #include "../common/timer.h" #include "../common/utils.h" +#include "../common/console.h" #include "int_guild.h" #include "int_homun.h" #include "int_mercenary.h" @@ -5022,6 +5023,7 @@ int do_init(int argc, char **argv) { } Sql_HerculesUpdateCheck(sql_handle); + console->setSQL(sql_handle); ShowStatus("The char-server is "CL_GREEN"ready"CL_RESET" (Server is listening on the port %d).\n\n", char_port); diff --git a/src/common/console.c b/src/common/console.c index a9ea0386f..66f8d914a 100644 --- a/src/common/console.c +++ b/src/common/console.c @@ -17,6 +17,7 @@ #include "../common/mutex.h" #include "../common/timer.h" #include "../common/strlib.h" + #include "../common/sql.h" #endif #include <stdio.h> @@ -106,6 +107,13 @@ CPCMD(malloc_usage) { unsigned int val = (unsigned int)iMalloc->usage(); ShowInfo("malloc_usage: %.2f MB\n",(double)(val)/1024); } +CPCMD(skip) { + if( !line ) { + ShowDebug("usage example: sql update skip 2013-02-14--16-15.sql\n"); + return; + } + Sql_HerculesUpdateSkip(console->SQL, line); +} #define CP_DEF_C(x) { #x , NULL , NULL, NULL } #define CP_DEF_C2(x,y) { #x , NULL , #y, NULL } #define CP_DEF_S(x,y) { #x , console_parse_ ## x , #y, NULL } @@ -123,6 +131,9 @@ void console_load_defaults(void) { CP_DEF_S(mem_report,server), CP_DEF_S(malloc_usage,server), CP_DEF_S(exit,server), + CP_DEF_C(sql), + CP_DEF_C2(update,sql), + CP_DEF_S(skip,update), }; unsigned int i, len = ARRAYLENGTH(default_list); struct CParseEntry *cmd; @@ -375,6 +386,9 @@ void console_parse_init(void) { iTimer->add_timer_interval(iTimer->gettick() + 1000, console->parse_timer, 0, 0, 500);/* start listening in 1s; re-try every 0.5s */ } +void console_setSQL(Sql *SQL) { + console->SQL = SQL; +} #endif /* CONSOLE_INPUT */ void console_init (void) { @@ -413,5 +427,7 @@ void console_defaults(void) { console->load_defaults = console_load_defaults; console->parse_list_subs = console_parse_list_subs; console->addCommand = console_parse_create; + console->setSQL = console_setSQL; + console->SQL = NULL; #endif } diff --git a/src/common/console.h b/src/common/console.h index ebce013f7..214a41175 100644 --- a/src/common/console.h +++ b/src/common/console.h @@ -7,6 +7,7 @@ #include "../common/thread.h" #include "../common/mutex.h" #include "../common/spinlock.h" +#include "../common/sql.h" #include "../config/core.h" /** @@ -51,6 +52,8 @@ struct console_interface { unsigned int cmd_count; unsigned int cmd_list_count; /* */ + Sql *SQL; + /* */ void (*parse_init) (void); void (*parse_final) (void); int (*parse_timer) (int tid, unsigned int tick, int id, intptr_t data); @@ -61,6 +64,7 @@ struct console_interface { void (*load_defaults) (void); void (*parse_list_subs) (struct CParseEntry *cmd, unsigned char depth); void (*addCommand) (char *name, CParseFunc func); + void (*setSQL) (Sql *SQL); #endif }; diff --git a/src/common/sql.c b/src/common/sql.c index 441b860da..99482072c 100644 --- a/src/common/sql.c +++ b/src/common/sql.c @@ -1003,18 +1003,21 @@ 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; - + StringBuf buf; + if( !( ifp = fopen("sql-files/upgrades/index.txt", "r") ) ) { ShowError("SQL upgrade index was not found!\n"); return; } + StrBuf->Init(&buf); + 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 */ - if( line[0] == '\n' || ( line[0] == '/' && line[1] == '/' ) )/* skip \n and "//" comments */ + if( line[0] == '\n' || line[0] == '\r' || ( line[0] == '/' && line[1] == '/' ) )/* skip \n, \r and "//" comments */ continue; sprintf(path,"sql-files/upgrades/%s",line); @@ -1034,7 +1037,7 @@ void Sql_HerculesUpdateCheck(Sql* self) { 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); + StrBuf->Printf(&buf,CL_MAGENTA"[SQL]"CL_RESET": -- '"CL_WHITE"%s"CL_RESET"'\n", path); performed++; } } @@ -1045,8 +1048,49 @@ void Sql_HerculesUpdateCheck(Sql* self) { 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"); + ShowSQL("- dected %d new "CL_WHITE"SQL updates"CL_RESET"\n",performed); + ShowMessage("%s",StrBuf->Value(&buf)); + ShowSQL("To manually skip, type: 'sql update skip <file name>'\n"); + } + + StrBuf->Destroy(&buf); +} + +void Sql_HerculesUpdateSkip(Sql* self,const char *filename) { + char path[41];// "sql-files/upgrades/" (19) + "yyyy-mm-dd--hh-mm" (17) + ".sql" (4) + 1 + char timestamp[11];// "1360186680" (10) + 1 + FILE* ifp;/* index fp */ + + if( !self ) { + ShowError("SQL not hooked!\n"); + return; } + + snprintf(path,41,"sql-files/upgrades/%s",filename); + + if( !( ifp = fopen(path, "r") ) ) { + ShowError("Upgrade file '%s' was not found!\n",filename); + return; + } + + fseek (ifp,1,SEEK_SET);/* woo. skip the # */ + + if( fgets(timestamp,sizeof(timestamp),ifp) ) { + 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); + else if( Sql_NumRows(self) == 1 ) { + ShowError("Upgrade '%s' has already been skipped\n",filename); + } else { + if( SQL_ERROR == SQL->Query(self, "INSERT INTO `sql_updates` (`timestamp`,`ignored`) VALUES ('%u','Yes') ", timestampui) ) + Sql_ShowDebug(self); + else { + ShowInfo("SQL Upgrade '%s' successfully skipped\n",filename); + } + } + } + fclose(ifp); + return; } void Sql_Init(void) { diff --git a/src/common/sql.h b/src/common/sql.h index 535990649..da00edf2d 100644 --- a/src/common/sql.h +++ b/src/common/sql.h @@ -281,6 +281,7 @@ void sql_defaults(void); #endif void Sql_HerculesUpdateCheck(Sql* self); +void Sql_HerculesUpdateSkip(Sql* self,const char *filename); #if defined(SQL_REMOVE_SHOWDEBUG) #define SqlStmt_ShowDebug(self) (void)0 diff --git a/src/login/account_sql.c b/src/login/account_sql.c index 14dd8ad9d..53785f39f 100644 --- a/src/login/account_sql.c +++ b/src/login/account_sql.c @@ -8,6 +8,7 @@ #include "../common/sql.h" #include "../common/strlib.h" #include "../common/timer.h" +#include "../common/console.h" #include "account.h" #include <stdlib.h> #include <string.h> @@ -689,4 +690,5 @@ static bool mmo_auth_tosql(AccountDB_SQL* db, const struct mmo_account* acc, boo void account_db_sql_up(AccountDB* self) { AccountDB_SQL* db = (AccountDB_SQL*)self; Sql_HerculesUpdateCheck(db->accounts); + console->setSQL(db->accounts); } diff --git a/src/map/map.c b/src/map/map.c index 31600440d..6ed692cee 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -5509,6 +5509,7 @@ int do_init(int argc, char *argv[]) ShowNotice("Server is running on '"CL_WHITE"PK Mode"CL_RESET"'.\n"); Sql_HerculesUpdateCheck(mmysql_handle); + console->setSQL(mmysql_handle); ShowStatus("Server is '"CL_GREEN"ready"CL_RESET"' and listening on port '"CL_WHITE"%d"CL_RESET"'.\n\n", map_port); |