diff --git a/configs/databases.cfg b/configs/databases.cfg index 22643aa9..072c27f7 100644 --- a/configs/databases.cfg +++ b/configs/databases.cfg @@ -21,7 +21,7 @@ "clientprefs" { - "driver" "default" + "driver" "sqlite" "host" "localhost" "database" "clientprefs-sqlite" "user" "root" diff --git a/extensions/clientprefs/extension.cpp b/extensions/clientprefs/extension.cpp index 023d9cac..4db8d876 100644 --- a/extensions/clientprefs/extension.cpp +++ b/extensions/clientprefs/extension.cpp @@ -92,10 +92,69 @@ bool ClientPrefs::SDK_OnLoad(char *error, size_t maxlength, bool late) if (strcmp(identifier, "sqlite") == 0) { driver = DRIVER_SQLITE; + + TQueryOp *op = new TQueryOp( + Database, + "CREATE TABLE sm_cookies IF NOT EXISTS \ + ( \ + id INTEGER PRIMARY KEY AUTOINCREMENT, \ + name varchar(30) NOT NULL UNIQUE, \ + description varchar(255), \ + access INTEGER \ + )", + Query_CreateTable, + 0); + + dbi->AddToThreadQueue(op, PrioQueue_Normal); + + op = new TQueryOp( + Database, + "CREATE TABLE sm_cookie_cache IF NOT EXISTS \ + ( \ + player varchar(65) NOT NULL, \ + cookie_id int(10) NOT NULL, \ + value varchar(100), \ + timestamp int, \ + PRIMARY KEY (player, cookie_id) \ + )", + Query_CreateTable, + 0); + + dbi->AddToThreadQueue(op, PrioQueue_Normal); } else if (strcmp(identifier, "mysql") == 0) { driver = DRIVER_MYSQL; + + TQueryOp *op = new TQueryOp( + Database, + "CREATE TABLE sm_cookies IF NOT EXISTS \ + ( \ + id INTEGER unsigned NOT NULL auto_increment, \ + name varchar(30) NOT NULL UNIQUE, \ + description varchar(255), \ + access INTEGER, \ + PRIMARY KEY (id) \ + )", + Query_CreateTable, + 0); + + dbi->AddToThreadQueue(op, PrioQueue_Normal); + + op = new TQueryOp( + Database, + "CREATE TABLE sm_cookie_cache IF NOT EXISTS \ + ( \ + player varchar(65) NOT NULL, \ + cookie_id int(10) NOT NULL, \ + value varchar(100), \ + timestamp int NOT NULL, \ + PRIMARY KEY (player, cookie_id) \ + )", + Query_CreateTable, + 0); + + dbi->AddToThreadQueue(op, PrioQueue_Normal); } else { @@ -103,6 +162,8 @@ bool ClientPrefs::SDK_OnLoad(char *error, size_t maxlength, bool late) return false; } + + sharesys->AddNatives(myself, g_ClientPrefNatives); sharesys->RegisterLibrary(myself, "clientprefs"); g_CookieManager.cookieDataLoadedForward = forwards->CreateForward("OnClientCookiesCached", ET_Ignore, 1, NULL, Param_Cell); diff --git a/extensions/clientprefs/extension.h b/extensions/clientprefs/extension.h index 330ce3c9..0cecc49f 100644 --- a/extensions/clientprefs/extension.h +++ b/extensions/clientprefs/extension.h @@ -40,13 +40,13 @@ #include "sh_list.h" #include "cookie.h" #include "menus.h" +#include "query.h" #define DRIVER_MYSQL 1 #define DRIVER_SQLITE 0 #define MAX_TRANSLATE_PARAMS 32 - /** * @brief Sample implementation of the SDK Extension. * Note: Uncomment one of the pre-defined virtual functions in order to use it. diff --git a/extensions/clientprefs/query.h b/extensions/clientprefs/query.h index 3dc733a5..80f21072 100644 --- a/extensions/clientprefs/query.h +++ b/extensions/clientprefs/query.h @@ -42,6 +42,7 @@ enum querytype Query_SelectData, Query_InsertData, Query_SelectId, + Query_CreateTable, }; class TQueryOp : public IDBThreadOperation