extensions/clientprefs/query.h
author Matt Woodrow <pred@alliedmods.net>
Tue Mar 17 12:29:10 2009 +1300 (2009-03-17)
changeset 2668 a6c7e8d7f8c9
parent 2592 e69a1297edbc
child 3804 90159516acd3
permissions -rw-r--r--
Added GetClientCookieTime native (bug 3736, r=dvander)
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod Client Preferences Extension
     5  * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
     6  * =============================================================================
     7  *
     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.
    11  * 
    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
    15  * details.
    16  *
    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/>.
    19  *
    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>.
    28  *
    29  * Version: $Id$
    30  */
    31 
    32 #ifndef _INCLUDE_SOURCEMOD_CLIENTPREFS_QUERY_H_
    33 #define _INCLUDE_SOURCEMOD_CLIENTPREFS_QUERY_H_
    34 
    35 #include "extension.h"
    36 #include "cookie.h"
    37 #include "sh_string.h"
    38 
    39 enum querytype
    40 {
    41 	Query_InsertCookie = 0,
    42 	Query_SelectData,
    43 	Query_InsertData,
    44 	Query_SelectId,
    45 	Query_Connect,
    46 };
    47 
    48 struct Cookie;
    49 struct CookieData;
    50 #define MAX_NAME_LENGTH 30
    51 
    52 /* This stores all the info required for our param binding until the thread is executed */
    53 struct ParamData
    54 {
    55 	ParamData();
    56 
    57 	~ParamData();
    58 
    59 	/* Contains a name, description and access for InsertCookie queries */
    60 	Cookie *cookie;
    61 	/* A clients steamid - Used for most queries - Doubles as storage for the cookie name*/
    62 	char steamId[MAX_NAME_LENGTH];
    63 
    64 	int cookieId;
    65 	CookieData *data;
    66 };
    67 
    68 class TQueryOp : public IDBThreadOperation
    69 {
    70 public:
    71 	TQueryOp(enum querytype type, int serial);
    72 	TQueryOp(enum querytype type, Cookie *cookie);
    73 	~TQueryOp() {}
    74 
    75 	IDBDriver *GetDriver();
    76 	IdentityToken_t *GetOwner();
    77 
    78 	void SetDatabase(IDatabase *db);
    79 
    80 	void Destroy();
    81 
    82 	void RunThreadPart();
    83 	/* Thread has been cancelled due to driver unloading. Nothing else to do? */
    84 	void CancelThinkPart()	{}
    85 	void RunThinkPart();
    86 
    87 	bool BindParamsAndRun();
    88 
    89 	/* Params to be bound */
    90 	ParamData m_params;
    91 
    92 	inline IDatabase *GetDB()
    93 	{
    94 		return m_database;
    95 	}
    96 
    97 private:
    98 	IDatabase *m_database;
    99 	IQuery *m_pResult;
   100 
   101 	/* Query type */
   102 	enum querytype m_type;
   103 
   104 	/* Data to be passed to the callback */
   105 	int m_serial;
   106 	int m_insertId;
   107 	Cookie *m_pCookie;
   108 };
   109 
   110 
   111 #endif // _INCLUDE_SOURCEMOD_CLIENTPREFS_QUERY_H_