From 50e1c5ba1f405cb8705565bd2a8f670c61e5f929 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sat, 31 Jan 2009 23:42:35 -0500 Subject: [PATCH] Database fallback for clientprefs is now more "intelligent" (bug 3564, r=pred). --- extensions/clientprefs/extension.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/extensions/clientprefs/extension.cpp b/extensions/clientprefs/extension.cpp index 14801b34a..0aa17c78c 100644 --- a/extensions/clientprefs/extension.cpp +++ b/extensions/clientprefs/extension.cpp @@ -46,6 +46,7 @@ CookieTypeHandler g_CookieTypeHandler; HandleType_t g_CookieIterator = 0; CookieIteratorHandler g_CookieIteratorHandler; DbDriver g_DriverType; +static const DatabaseInfo *storage_local = NULL; bool ClientPrefs::SDK_OnLoad(char *error, size_t maxlength, bool late) { @@ -58,6 +59,20 @@ bool ClientPrefs::SDK_OnLoad(char *error, size_t maxlength, bool late) { DBInfo = dbi->FindDatabaseConf("default"); + if (DBInfo == NULL || + (strcmp(DBInfo->host, "localhost") == 0 && + strcmp(DBInfo->database, "sourcemod") == 0 && + strcmp(DBInfo->user, "root") == 0 && + strcmp(DBInfo->pass, "") == 0 && + strcmp(DBInfo->driver, "") == 0)) + { + storage_local = dbi->FindDatabaseConf("storage-local"); + if (DBInfo == NULL) + { + DBInfo = storage_local; + } + } + if (DBInfo == NULL) { snprintf(error, maxlength, "Could not find \"clientprefs\" or \"default\" database configs"); @@ -176,6 +191,14 @@ void ClientPrefs::DatabaseConnect() Database = Driver->Connect(DBInfo, true, error, sizeof(error)); + if (Database == NULL && + DBInfo != storage_local && + storage_local != NULL) + { + DBInfo = storage_local; + Database = Driver->Connect(DBInfo, true, error, sizeof(error)); + } + if (Database == NULL) { g_pSM->LogError(myself, error);