sourcemm/sample_mm/SamplePlugin.h
author David Anderson <dvander@alliedmods.net>
Fri Oct 21 07:22:37 2005 +0000 (2005-10-21)
changeset 142 40e1fc972412
parent 140 800dc9ba92c5
child 152 179336f55ff6
permissions -rw-r--r--
Sample usage of new listener API
     1 /* ======== sample_mm ========
     2 * Copyright (C) 2004-2005 Metamod:Source Development Team
     3 * No warranties of any kind
     4 *
     5 * License: zlib/libpng
     6 *
     7 * Author(s): David "BAILOPAN" Anderson
     8 * ============================
     9 */
    10 
    11 #ifndef _INCLUDE_SAMPLEPLUGIN_H
    12 #define _INCLUDE_SAMPLEPLUGIN_H
    13 
    14 #include <ISmmPlugin.h>
    15 #include <sourcehook/sourcehook.h>
    16 #include <igameevents.h>
    17 
    18 #define SAMPLE_VERSION	"1.10"
    19 
    20 class SamplePlugin : public ISmmPlugin, public IMetamodListener
    21 {
    22 public:
    23 	bool Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool late);
    24 	bool Unload(char *error, size_t maxlen);
    25 	void AllPluginsLoaded();
    26 	bool Pause(char *error, size_t maxlen)
    27 	{
    28 		return true;
    29 	}
    30 	bool Unpause(char *error, size_t maxlen)
    31 	{
    32 		return true;
    33 	}
    34 public:
    35 	int GetApiVersion() { return PLAPI_VERSION; }
    36 public:
    37 	const char *GetAuthor()
    38 	{
    39 		return "BAILOPAN";
    40 	}
    41 	const char *GetName()
    42 	{
    43 		return "Sample Plugin";
    44 	}
    45 	const char *GetDescription()
    46 	{
    47 		return "Sample plugin that hooks basic things";
    48 	}
    49 	const char *GetURL()
    50 	{
    51 		return "http://www.sourcemm.net/";
    52 	}
    53 	const char *GetLicense()
    54 	{
    55 		return "zlib/libpng";
    56 	}
    57 	const char *GetVersion()
    58 	{
    59 		return SAMPLE_VERSION;
    60 	}
    61 	const char *GetDate()
    62 	{
    63 		return __DATE__;
    64 	}
    65 	const char *GetLogTag()
    66 	{
    67 		return "SAMPLE";
    68 	}
    69 public:
    70 	//These functions are from IServerPluginCallbacks
    71 	//Note, the parameters might be a little different to match the actual calls!
    72 
    73 	//Called on LevelInit.  Server plugins only have pMapName
    74 	bool LevelInit(const char *pMapName, char const *pMapEntities, char const *pOldLevel, char const *pLandmarkName, bool loadGame, bool background);
    75 
    76 	//Called on ServerActivate.  Same definition as server plugins
    77 	void ServerActivate(edict_t *pEdictList, int edictCount, int clientMax);
    78 
    79 	//Called on a game tick.  Same definition as server plugins
    80 	void GameFrame(bool simulating);
    81 
    82 	//Called on level shutdown.  Same definition as server plugins 
    83 	void LevelShutdown(void);
    84 
    85 	//Client is activate (whatever that means).  We get an extra parameter...
    86 	// "If bLoadGame is true, don't spawn the player because its state is already setup."
    87 	void ClientActive(edict_t *pEntity, bool bLoadGame);
    88 
    89 	//Client disconnects - same as server plugins
    90 	void ClientDisconnect(edict_t *pEntity);
    91 
    92 	//Client is put in server - same as server plugins
    93 	void ClientPutInServer(edict_t *pEntity, char const *playername);
    94 
    95 	//Sets the client index - same as server plugins
    96 	void SetCommandClient(int index);
    97 
    98 	//Called on client settings changed (duh) - same as server plugins
    99 	void ClientSettingsChanged(edict_t *pEdict);
   100 
   101 	//Called on client connect.  Unlike server plugins, we return whether the 
   102 	// connection is allowed rather than set it through a pointer in the first parameter.
   103 	// You can still supercede the GameDLL through RETURN_META_VALUE(MRES_SUPERCEDE, true/false)
   104 	bool ClientConnect(edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen);
   105 
   106 	//Called when a client uses a command.  Unlike server plugins, it's void.
   107 	// You can still supercede the gamedll through RETURN_META(MRES_SUPERCEDE).
   108 	void ClientCommand(edict_t *pEntity);
   109 
   110 	//From IMetamodListener
   111 	virtual void OnLevelShutdown();
   112 
   113 private:
   114 	IGameEventManager2 *m_GameEventManager;	
   115 	IVEngineServer *m_Engine;
   116 	IServerGameDLL *m_ServerDll;
   117 	IServerGameClients *m_ServerClients;
   118 	SourceHook::CallClass<IVEngineServer> *m_Engine_CC;
   119 };
   120 
   121 extern SamplePlugin g_SamplePlugin;
   122 PLUGIN_GLOBALVARS();
   123 
   124 bool FireEvent_Handler(IGameEvent *event, bool bDontBroadcast);
   125 
   126 #endif //_INCLUDE_SAMPLEPLUGIN_H