Database fallback for clientprefs is now more "intelligent" (bug 3564, r=pred).
authorDavid Anderson <dvander@alliedmods.net>
Sat Jan 31 23:42:35 2009 -0500 (2009-01-31)
changeset 2550a2c8eec6dc22
parent 2549 8d2974380f78
child 2551 2803ef800ce4
Database fallback for clientprefs is now more "intelligent" (bug 3564, r=pred).
extensions/clientprefs/extension.cpp
     1.1 --- a/extensions/clientprefs/extension.cpp	Sat Jan 31 22:46:34 2009 -0500
     1.2 +++ b/extensions/clientprefs/extension.cpp	Sat Jan 31 23:42:35 2009 -0500
     1.3 @@ -46,6 +46,7 @@
     1.4  HandleType_t g_CookieIterator = 0;
     1.5  CookieIteratorHandler g_CookieIteratorHandler;
     1.6  DbDriver g_DriverType;
     1.7 +static const DatabaseInfo *storage_local = NULL;
     1.8  
     1.9  bool ClientPrefs::SDK_OnLoad(char *error, size_t maxlength, bool late)
    1.10  {
    1.11 @@ -58,6 +59,20 @@
    1.12  	{
    1.13  		DBInfo = dbi->FindDatabaseConf("default");
    1.14  
    1.15 +		if (DBInfo == NULL ||
    1.16 +			(strcmp(DBInfo->host, "localhost") == 0 &&
    1.17 +			 strcmp(DBInfo->database, "sourcemod") == 0 && 
    1.18 +			 strcmp(DBInfo->user, "root") == 0 &&
    1.19 +			 strcmp(DBInfo->pass, "") == 0 &&
    1.20 +			 strcmp(DBInfo->driver, "") == 0))
    1.21 +		{
    1.22 +			storage_local = dbi->FindDatabaseConf("storage-local");
    1.23 +			if (DBInfo == NULL)
    1.24 +			{
    1.25 +				DBInfo = storage_local;
    1.26 +			}
    1.27 +		}
    1.28 +
    1.29  		if (DBInfo == NULL)
    1.30  		{
    1.31  			snprintf(error, maxlength, "Could not find \"clientprefs\" or \"default\" database configs");
    1.32 @@ -176,6 +191,14 @@
    1.33  
    1.34  	Database = Driver->Connect(DBInfo, true, error, sizeof(error));
    1.35  
    1.36 +	if (Database == NULL &&
    1.37 +		DBInfo != storage_local &&
    1.38 +		storage_local != NULL)
    1.39 +	{
    1.40 +		DBInfo = storage_local;
    1.41 +		Database = Driver->Connect(DBInfo, true, error, sizeof(error));
    1.42 +	}
    1.43 +
    1.44  	if (Database == NULL)
    1.45  	{
    1.46  		g_pSM->LogError(myself, error);