Fixed build for real.
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
40 case Query_InsertCookie:
42 g_CookieManager.InsertCookieCallback(m_pCookie, m_insertId);
46 case Query_SelectData:
48 g_CookieManager.ClientConnectCallback(m_serial, m_pResult);
54 g_CookieManager.SelectIdCallback(m_pCookie, m_pResult);
70 void TQueryOp::RunThreadPart()
72 if (m_type == Query_Connect)
74 g_ClientPrefs.DatabaseConnect();
78 assert(m_database != NULL);
79 /* I don't think this is needed anymore... keeping for now. */
80 m_database->LockForFullAtomicOperation();
81 if (!BindParamsAndRun())
83 g_pSM->LogError(myself,
84 "Failed SQL Query, Error: \"%s\" (Query id %i - serial %i)",
85 m_database->GetError(),
90 m_database->UnlockFromFullAtomicOperation();
93 IDBDriver *TQueryOp::GetDriver()
95 return m_database->GetDriver();
98 IdentityToken_t *TQueryOp::GetOwner()
100 return myself->GetIdentity();
103 void TQueryOp::Destroy()
105 if (m_pResult != NULL)
107 m_pResult->Destroy();
112 TQueryOp::TQueryOp(enum querytype type, int serial)
121 TQueryOp::TQueryOp(enum querytype type, Cookie *cookie)
131 void TQueryOp::SetDatabase(IDatabase *db)
134 m_database->IncReferenceCount();
137 bool TQueryOp::BindParamsAndRun()
144 case Query_InsertCookie:
146 char safe_name[MAX_NAME_LENGTH*2 + 1];
147 char safe_desc[MAX_DESC_LENGTH*2 + 1];
149 m_database->QuoteString(m_params.cookie->name,
153 m_database->QuoteString(m_params.cookie->description,
158 if (g_DriverType == Driver_MySQL)
162 "INSERT IGNORE INTO sm_cookies (name, description, access) \
163 VALUES (\"%s\", \"%s\", %d)",
166 m_params.cookie->access);
168 else if (g_DriverType == Driver_SQLite)
172 "INSERT OR IGNORE INTO sm_cookies (name, description, access) \
173 VALUES ('%s', '%s', %d)",
176 m_params.cookie->access);
179 if (!m_database->DoSimpleQuery(query))
184 m_insertId = m_database->GetInsertID();
189 case Query_SelectData:
193 m_database->QuoteString(m_params.steamId, safe_str, sizeof(safe_str), &ignore);
197 "SELECT sm_cookies.name, sm_cookie_cache.value, sm_cookies.description, \
198 sm_cookies.access, sm_cookie_cache.timestamp \
200 JOIN sm_cookie_cache \
201 ON sm_cookies.id = sm_cookie_cache.cookie_id \
202 WHERE player = '%s'",
205 m_pResult = m_database->DoQuery(query);
207 return (m_pResult != NULL);
210 case Query_InsertData:
213 char safe_val[MAX_VALUE_LENGTH*2 + 1];
215 m_database->QuoteString(m_params.steamId,
219 m_database->QuoteString(m_params.data->value,
224 if (g_DriverType == Driver_MySQL)
228 "INSERT INTO sm_cookie_cache (player, cookie_id, value, timestamp) \
229 VALUES (\"%s\", %d, \"%s\", %d) \
230 ON DUPLICATE KEY UPDATE \
231 value = \"%s\", timestamp = %d",
235 (unsigned int)m_params.data->timestamp,
237 (unsigned int)m_params.data->timestamp);
239 else if (g_DriverType == Driver_SQLite)
243 "INSERT OR REPLACE INTO sm_cookie_cache \
244 (player, cookie_id, value, timestamp) \
245 VALUES ('%s', %d, '%s', %d)",
249 (unsigned int)m_params.data->timestamp);
252 if (!m_database->DoSimpleQuery(query))
257 m_insertId = m_database->GetInsertID();
264 char safe_name[MAX_NAME_LENGTH*2 + 1];
266 /* the steamId var was actually used to store the name of the cookie - Save duplicating vars */
267 m_database->QuoteString(m_params.steamId,
274 "SELECT id FROM sm_cookies WHERE name = '%s'",
277 m_pResult = m_database->DoQuery(query);
279 return (m_pResult != NULL);
294 querytype TQueryOp::PullQueryType()
299 int TQueryOp::PullQuerySerial()
304 ParamData::~ParamData()
308 g_ClientPrefs.cookieMutex->Lock();
309 cookie->usedInQuery--;
311 if (cookie->shouldDelete && cookie->usedInQuery <= 0)
313 g_ClientPrefs.cookieMutex->Unlock();
319 g_ClientPrefs.cookieMutex->Unlock();
325 /* Data is only ever passed in a client disconnect query and always needs to be deleted */
331 ParamData::ParamData()