extensions/clientprefs/extension.h
author Ruben Gonzalez <drifter01620@gmail.com>
Thu May 22 09:49:27 2014 -0400 (2014-05-22)
changeset 4378 568f4497ef4a
parent 4344 c445c3266192
permissions -rw-r--r--
Update CS:GO team score gamedata.
     1 /**
     2  * vim: set ts=4 sw=4 tw=99 noet:
     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_EXTENSION_PROPER_H_
    33 #define _INCLUDE_SOURCEMOD_EXTENSION_PROPER_H_
    34 
    35 #include <stdlib.h>
    36 #include <stdarg.h>
    37 #include "smsdk_ext.h"
    38 #include "sh_list.h"
    39 
    40 #include <am-thread-utils.h>
    41 #include <am-refcounting.h>
    42 
    43 char * UTIL_strncpy(char * destination, const char * source, size_t num);
    44 
    45 #include "cookie.h"
    46 #include "menus.h"
    47 #include "query.h"
    48 
    49 enum DbDriver
    50 {
    51 	Driver_MySQL,
    52 	Driver_SQLite
    53 };
    54 
    55 #define MAX_TRANSLATE_PARAMS		32
    56 
    57 class TQueryOp;
    58 
    59 /**
    60  * @brief Sample implementation of the SDK Extension.
    61  * Note: Uncomment one of the pre-defined virtual functions in order to use it.
    62  */
    63 class ClientPrefs : public SDKExtension
    64 {
    65 public:
    66 	ClientPrefs();
    67 public:
    68 	/**
    69 	 * @brief This is called after the initial loading sequence has been processed.
    70 	 *
    71 	 * @param error		Error message buffer.
    72 	 * @param maxlength	Size of error message buffer.
    73 	 * @param late		Whether or not the module was loaded after map load.
    74 	 * @return			True to succeed loading, false to fail.
    75 	 */
    76 	virtual bool SDK_OnLoad(char *error, size_t maxlength, bool late);
    77 
    78 	virtual void SDK_OnDependenciesDropped();
    79 
    80 	/**
    81 	 * @brief This is called once all known extensions have been loaded.
    82 	 * Note: It is is a good idea to add natives here, if any are provided.
    83 	 */
    84 	virtual void SDK_OnAllLoaded();
    85 
    86 	virtual bool QueryInterfaceDrop(SMInterface *pInterface);
    87 
    88 	virtual void NotifyInterfaceDrop(SMInterface *pInterface);
    89 
    90 	const char *GetExtensionVerString();
    91 	const char *GetExtensionDateString();
    92 
    93 	virtual void OnCoreMapStart(edict_t *pEdictList, int edictCount, int clientMax);
    94 	
    95 	void DatabaseConnect();
    96 
    97 	bool AddQueryToQueue(TQueryOp *query);
    98 	void ProcessQueryCache();
    99 	
   100 	void AttemptReconnection();
   101 	void CatchLateLoadClients();
   102 	void ClearQueryCache(int serial);
   103 
   104 	/**
   105 	 * @brief Called when the pause state is changed.
   106 	 */
   107 	//virtual void SDK_OnPauseChange(bool paused);
   108 
   109 	/**
   110 	 * @brief this is called when Core wants to know if your extension is working.
   111 	 *
   112 	 * @param error		Error message buffer.
   113 	 * @param maxlength	Size of error message buffer.
   114 	 * @return			True if working, false otherwise.
   115 	 */
   116 	//virtual bool QueryRunning(char *error, size_t maxlength);
   117 public:
   118 #if defined SMEXT_CONF_METAMOD
   119 	/**
   120 	 * @brief Called when Metamod is attached, before the extension version is called.
   121 	 *
   122 	 * @param error			Error buffer.
   123 	 * @param maxlength		Maximum size of error buffer.
   124 	 * @param late			Whether or not Metamod considers this a late load.
   125 	 * @return				True to succeed, false to fail.
   126 	 */
   127 	//virtual bool SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlength, bool late);
   128 
   129 	/**
   130 	 * @brief Called when Metamod is detaching, after the extension version is called.
   131 	 * NOTE: By default this is blocked unless sent from SourceMod.
   132 	 *
   133 	 * @param error			Error buffer.
   134 	 * @param maxlength		Maximum size of error buffer.
   135 	 * @return				True to succeed, false to fail.
   136 	 */
   137 	//virtual bool SDK_OnMetamodUnload(char *error, size_t maxlength);
   138 
   139 	/**
   140 	 * @brief Called when Metamod's pause state is changing.
   141 	 * NOTE: By default this is blocked unless sent from SourceMod.
   142 	 *
   143 	 * @param paused		Pause state being set.
   144 	 * @param error			Error buffer.
   145 	 * @param maxlength		Maximum size of error buffer.
   146 	 * @return				True to succeed, false to fail.
   147 	 */
   148 	//virtual bool SDK_OnMetamodPauseChange(bool paused, char *error, size_t maxlength);
   149 #endif
   150 public:
   151 	IdentityToken_t *GetIdentity() const;
   152 public:
   153 	IDBDriver *Driver;
   154 	ke::Ref<IDatabase> Database;
   155 	IPhraseCollection *phrases;
   156 	const DatabaseInfo *DBInfo;
   157 
   158 	bool databaseLoading;
   159 
   160 private:
   161 	SourceHook::List<TQueryOp *> cachedQueries;
   162 	ke::Mutex queryLock;
   163 	IdentityToken_t *identity;
   164 };
   165 
   166 class CookieTypeHandler : public IHandleTypeDispatch
   167 {
   168 public:
   169 	void OnHandleDestroy(HandleType_t type, void *object)
   170 	{
   171 		/* No delete needed since Cookies are persistent */
   172 	}
   173 };
   174 
   175 class CookieIteratorHandler : public IHandleTypeDispatch
   176 {
   177 public:
   178 	void OnHandleDestroy(HandleType_t type, void *object)
   179 	{
   180 		delete (SourceHook::List<Cookie *>::iterator *)object;
   181 	}
   182 };
   183 
   184 size_t IsAuthIdConnected(char *authID);
   185 
   186 extern sp_nativeinfo_t g_ClientPrefNatives[];
   187 
   188 extern ClientPrefs g_ClientPrefs;
   189 extern HandleType_t g_CookieType;
   190 extern CookieTypeHandler g_CookieTypeHandler;
   191 
   192 extern HandleType_t g_CookieIterator;
   193 extern CookieIteratorHandler g_CookieIteratorHandler;
   194 
   195 bool Translate(char *buffer, 
   196 				   size_t maxlength,
   197 				   const char *format,
   198 				   unsigned int numparams,
   199 				   size_t *pOutLength,
   200 				   ...);
   201 
   202 extern DbDriver g_DriverType;
   203 
   204 #endif // _INCLUDE_SOURCEMOD_EXTENSION_PROPER_H_
   205