Plugins: Added ClientConnect and ClientDisconnect hooks
This commit is contained in:
parent
96c3590a08
commit
a00a574b4a
4 changed files with 103 additions and 6 deletions
|
@ -23,6 +23,7 @@
|
|||
#include "spawn.h"
|
||||
#include "flashlight.h"
|
||||
#include "weapons.h"
|
||||
#include "plugins.h"
|
||||
|
||||
#define CLASSEXPORT(classname,classa) void classname(void) { spawnfunc_##classa(); }
|
||||
|
||||
|
|
|
@ -14,9 +14,6 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
var int g_plugins_enabled;
|
||||
var int autocvar_sv_plugins = 1;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
string m_strPath;
|
||||
|
@ -156,3 +153,74 @@ Plugin_ParseClientCommand(string msg)
|
|||
|
||||
return rval;
|
||||
}
|
||||
|
||||
/*
|
||||
=================
|
||||
Plugin_PlayerConnect
|
||||
|
||||
Called whenever a new client connect to the game
|
||||
=================
|
||||
*/
|
||||
int
|
||||
Plugin_PlayerConnect(entity cl)
|
||||
{
|
||||
int rval;
|
||||
int tval;
|
||||
int(entity) vFunc;
|
||||
|
||||
if (g_plugins_enabled == 0)
|
||||
return FALSE;
|
||||
|
||||
/* rval = final return value, tval = temporary return value.
|
||||
if at least one of the plugins returns TRUE, then RunClientCommand
|
||||
will not be called by the engine, as it should be */
|
||||
rval = FALSE;
|
||||
tval = FALSE;
|
||||
|
||||
for (int i = 0; i < g_plugincount; i++) {
|
||||
vFunc = externvalue(g_plugindb[i].m_flProgsID, "FMX_PlayerConnect");
|
||||
|
||||
if (vFunc) {
|
||||
tval = vFunc(cl);
|
||||
rval |= tval;
|
||||
}
|
||||
}
|
||||
|
||||
return rval;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
=================
|
||||
Plugin_PlayerDisconnect
|
||||
|
||||
Called whenever a client leaves the game
|
||||
=================
|
||||
*/
|
||||
int
|
||||
Plugin_PlayerDisconnect(entity cl)
|
||||
{
|
||||
int rval;
|
||||
int tval;
|
||||
int(entity) vFunc;
|
||||
|
||||
if (g_plugins_enabled == 0)
|
||||
return FALSE;
|
||||
|
||||
/* rval = final return value, tval = temporary return value.
|
||||
if at least one of the plugins returns TRUE, then RunClientCommand
|
||||
will not be called by the engine, as it should be */
|
||||
rval = FALSE;
|
||||
tval = FALSE;
|
||||
|
||||
for (int i = 0; i < g_plugincount; i++) {
|
||||
vFunc = externvalue(g_plugindb[i].m_flProgsID, "FMX_PlayerDisconnect");
|
||||
|
||||
if (vFunc) {
|
||||
tval = vFunc(cl);
|
||||
rval |= tval;
|
||||
}
|
||||
}
|
||||
|
||||
return rval;
|
||||
}
|
||||
|
|
25
src/server/plugins.h
Normal file
25
src/server/plugins.h
Normal file
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* Copyright (c) 2016-2020 Marco Hladik <marco@icculus.org>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
var int g_plugins_enabled;
|
||||
var int autocvar_sv_plugins = 1;
|
||||
|
||||
void Plugin_Init(void);
|
||||
void Plugin_Shutdown(void);
|
||||
int Plugin_RunClientCommand(void);
|
||||
int Plugin_ParseClientCommand(string msg);
|
||||
int Plugin_PlayerConnect(entity cl);
|
||||
int Plugin_PlayerDisconnect(entity cl);
|
|
@ -208,7 +208,9 @@ void
|
|||
HLGameRules::PlayerConnect(entity pl)
|
||||
{
|
||||
entity a;
|
||||
bprint(PRINT_HIGH, sprintf("%s connected\n", pl.netname));
|
||||
|
||||
if (Plugin_PlayerConnect(pl) == FALSE)
|
||||
bprint(PRINT_HIGH, sprintf("%s connected\n", pl.netname));
|
||||
|
||||
int playercount = 0;
|
||||
for (a = world; (a = find(a, ::classname, "player"));) {
|
||||
|
@ -228,7 +230,8 @@ HLGameRules::PlayerConnect(entity pl)
|
|||
void
|
||||
HLGameRules::PlayerDisconnect(entity pl)
|
||||
{
|
||||
bprint(PRINT_HIGH, sprintf("%s disconnected\n", pl.netname));
|
||||
if (Plugin_PlayerDisconnect(pl) == FALSE)
|
||||
bprint(PRINT_HIGH, sprintf("%s disconnected\n", pl.netname));
|
||||
|
||||
/* Make this unusable */
|
||||
pl.solid = SOLID_NOT;
|
||||
|
@ -236,7 +239,7 @@ HLGameRules::PlayerDisconnect(entity pl)
|
|||
pl.modelindex = 0;
|
||||
pl.health = 0;
|
||||
pl.takedamage = 0;
|
||||
pl.SendFlags = PLAYER_MODELINDEX;
|
||||
pl.SendFlags = -1;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
Loading…
Reference in a new issue