Fixed
amb1810 - Clientprefs no longer blocks load.
3 * =============================================================================
4 * SourceMod Client Preferences Extension
5 * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
6 * =============================================================================
8 * This program is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, version 3.0, as published by the
10 * Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
20 * As a special exception, AlliedModders LLC gives you permission to link the
21 * code of this program (as well as its derivative works) to "Half-Life 2," the
22 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
23 * by the Valve Corporation. You must obey the GNU General Public License in
24 * all respects for all other code used. Additionally, AlliedModders LLC grants
25 * this exception to all derivative works. AlliedModders LLC defines further
26 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
27 * or <http://www.sourcemod.net/license.php>.
35 void TQueryOp::RunThinkPart()
37 //handler for threaded sql queries
39 if (m_type == Query_Connect)
48 case Query_InsertCookie:
50 g_CookieManager.InsertCookieCallback(m_pCookie, m_insertId);
54 case Query_SelectData:
56 g_CookieManager.ClientConnectCallback(m_client, m_pQuery);
62 g_CookieManager.SelectIdCallback(m_pCookie, m_pQuery);
66 case Query_CreateTable:
82 void TQueryOp::RunThreadPart()
84 if (m_type == Query_Connect)
86 g_ClientPrefs.DatabaseConnect();
90 if (m_database == NULL)
95 m_database->LockForFullAtomicOperation();
97 if (!BindParamsAndRun())
99 g_pSM->LogError(myself, "Failed SQL Query, Error: \"%s\" (Query id %i - client %i)", m_database->GetError(), m_type, m_client);
102 m_insertId = m_database->GetInsertID();
104 m_database->UnlockFromFullAtomicOperation();
108 IDBDriver *TQueryOp::GetDriver()
110 if (m_database == NULL)
115 return m_database->GetDriver();
117 IdentityToken_t *TQueryOp::GetOwner()
119 return myself->GetIdentity();
121 void TQueryOp::Destroy()
126 TQueryOp::TQueryOp(enum querytype type, int client)
134 TQueryOp::TQueryOp(enum querytype type, Cookie *cookie)
142 void TQueryOp::SetDatabase( IDatabase *db )
145 m_database->IncReferenceCount();
148 bool TQueryOp::BindParamsAndRun()
150 if (m_pQuery == NULL)
157 case Query_InsertCookie:
159 m_pQuery->BindParamString(0, m_params.cookie->name, false);
160 m_pQuery->BindParamString(1, m_params.cookie->description, false);
161 m_pQuery->BindParamInt(2, m_params.cookie->access);
166 case Query_SelectData:
168 m_pQuery->BindParamString(0, m_params.steamId, false);
173 case Query_InsertData:
175 m_pQuery->BindParamString(0, m_params.steamId, false);
176 m_pQuery->BindParamInt(1, m_params.cookieId);
177 m_pQuery->BindParamString(2, m_params.data->value, false);
178 m_pQuery->BindParamInt(3, (unsigned int)time(NULL), false);
180 if (driver == DRIVER_MYSQL)
182 m_pQuery->BindParamString(4, m_params.data->value, false);
183 m_pQuery->BindParamInt(5, (unsigned int)time(NULL), false);
191 /* the steamId var was actually used to store the name of the cookie - Save duplicating vars */
192 m_pQuery->BindParamString(0, m_params.steamId, false);
204 return m_pQuery->Execute();
207 void TQueryOp::SetPreparedQuery()
211 case Query_InsertCookie:
213 m_pQuery = g_ClientPrefs.InsertCookieQuery;
217 case Query_SelectData:
219 m_pQuery = g_ClientPrefs.SelectDataQuery;
223 case Query_InsertData:
225 m_pQuery = g_ClientPrefs.InsertDataQuery;
231 m_pQuery = g_ClientPrefs.SelectIdQuery;
243 void TQueryOp::SetCustomPreparedQuery(IPreparedQuery *query)
248 ParamData::~ParamData()
252 g_ClientPrefs.cookieMutex->Lock();
253 cookie->usedInQuery--;
255 if (cookie->shouldDelete && cookie->usedInQuery <= 0)
257 g_ClientPrefs.cookieMutex->Unlock();
262 g_ClientPrefs.cookieMutex->Unlock();
267 /* Data is only ever passed in a client disconnect query and always needs to be deleted */
273 ParamData::ParamData()