Plugins: Use our own plugins.txt listing to decide which plugins get loaded...
This commit is contained in:
parent
bb22097203
commit
96c3590a08
2 changed files with 123 additions and 34 deletions
|
@ -32,6 +32,11 @@ void
|
||||||
ChatPlay(int id)
|
ChatPlay(int id)
|
||||||
{
|
{
|
||||||
int r, count, flags;
|
int r, count, flags;
|
||||||
|
|
||||||
|
if (!emitter) {
|
||||||
|
emitter = spawn();
|
||||||
|
}
|
||||||
|
|
||||||
count = tokenizebyseparator(g_table[id].sample, ";");
|
count = tokenizebyseparator(g_table[id].sample, ";");
|
||||||
r = random(0, count);
|
r = random(0, count);
|
||||||
flags = SOUNDFLAG_NOREVERB; /* this should be enough for now */
|
flags = SOUNDFLAG_NOREVERB; /* this should be enough for now */
|
||||||
|
@ -56,17 +61,23 @@ ChatLookUp(string cmd)
|
||||||
return autocvar_chatplug_suppresschat == 1 ? TRUE : FALSE;
|
return autocvar_chatplug_suppresschat == 1 ? TRUE : FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
/* plugin hook */
|
||||||
initents(void)
|
int
|
||||||
|
FMX_ParseClientCommand(string cmd)
|
||||||
{
|
{
|
||||||
/* why waste entity slots? */
|
tokenize(cmd);
|
||||||
if (g_sounds > 0) {
|
switch (argv(0)) {
|
||||||
emitter = spawn();
|
case "say":
|
||||||
|
return ChatLookUp(strtolower(argv(1)));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
init(float prevprogs)
|
FMX_Init(void)
|
||||||
{
|
{
|
||||||
string temp;
|
string temp;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
@ -74,11 +85,11 @@ init(float prevprogs)
|
||||||
filestream chatfile;
|
filestream chatfile;
|
||||||
searchhandle list;
|
searchhandle list;
|
||||||
|
|
||||||
list = search_begin("plugins/chatsounds/*.txt", TRUE, TRUE);
|
/*list = search_begin("plugins/chatsounds/*.txt", TRUE, TRUE);
|
||||||
for (int i = 0; i < search_getsize(list); i++) {
|
for (int i = 0; i < search_getsize(list); i++) {
|
||||||
print(sprintf("Found %s\n", search_getfilename(list, i)));
|
print(sprintf("Found %s\n", search_getfilename(list, i)));
|
||||||
}
|
}
|
||||||
search_end(list);
|
search_end(list);*/
|
||||||
|
|
||||||
chatfile = fopen("chatsounds.txt", FILE_READ);
|
chatfile = fopen("chatsounds.txt", FILE_READ);
|
||||||
|
|
||||||
|
@ -114,18 +125,3 @@ init(float prevprogs)
|
||||||
}
|
}
|
||||||
fclose(chatfile);
|
fclose(chatfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* plugin hook */
|
|
||||||
int
|
|
||||||
FMX_ParseClientCommand(string cmd)
|
|
||||||
{
|
|
||||||
tokenize(cmd);
|
|
||||||
switch (argv(0)) {
|
|
||||||
case "say":
|
|
||||||
return ChatLookUp(strtolower(argv(1)));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
|
@ -17,14 +17,73 @@
|
||||||
var int g_plugins_enabled;
|
var int g_plugins_enabled;
|
||||||
var int autocvar_sv_plugins = 1;
|
var int autocvar_sv_plugins = 1;
|
||||||
|
|
||||||
void Plugin_Init(void)
|
typedef struct
|
||||||
{
|
{
|
||||||
|
string m_strPath;
|
||||||
|
float m_flProgsID;
|
||||||
|
} plugin_t;
|
||||||
|
|
||||||
|
plugin_t *g_plugindb;
|
||||||
|
var int g_plugincount;
|
||||||
|
|
||||||
|
void
|
||||||
|
Plugin_Init(void)
|
||||||
|
{
|
||||||
|
filestream pdb;
|
||||||
|
string tmp;
|
||||||
|
int i;
|
||||||
|
|
||||||
if (autocvar_sv_plugins) {
|
if (autocvar_sv_plugins) {
|
||||||
iprint("Initializing Plugins");
|
iprint("Initializing Plugins");
|
||||||
g_plugins_enabled = 1;
|
g_plugins_enabled = 1;
|
||||||
} else {
|
} else {
|
||||||
g_plugins_enabled = 0;
|
g_plugins_enabled = 0;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pdb = fopen("plugins.txt", FILE_READ);
|
||||||
|
|
||||||
|
if (pdb < 0) {
|
||||||
|
print("^2Plugins^7: No plugins.txt found. Disabling.\n");
|
||||||
|
g_plugins_enabled = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* count valid progs */
|
||||||
|
g_plugincount = 0;
|
||||||
|
while ((tmp = fgets(pdb))) {
|
||||||
|
g_plugincount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_plugindb = memalloc(sizeof(plugin_t) * g_plugincount);
|
||||||
|
fseek(pdb, 0);
|
||||||
|
i = 0;
|
||||||
|
|
||||||
|
while ((tmp = fgets(pdb))) {
|
||||||
|
g_plugindb[i].m_strPath = tmp;
|
||||||
|
g_plugindb[i].m_flProgsID = addprogs(tmp);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(pdb);
|
||||||
|
|
||||||
|
void(void) vFunc;
|
||||||
|
for (i = 0; i < g_plugincount; i++) {
|
||||||
|
vFunc = externvalue(g_plugindb[i].m_flProgsID, "FMX_Init");
|
||||||
|
|
||||||
|
if (vFunc) {
|
||||||
|
vFunc();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
print(sprintf("^1Plugins^7: Initialized %i plugins\n", g_plugincount));
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Plugin_Shutdown(void)
|
||||||
|
{
|
||||||
|
memfree(g_plugindb);
|
||||||
|
g_plugincount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -34,15 +93,32 @@ Plugin_RunClientCommand
|
||||||
Funtion that can interrupt client commands before physics are run
|
Funtion that can interrupt client commands before physics are run
|
||||||
=================
|
=================
|
||||||
*/
|
*/
|
||||||
int Plugin_RunClientCommand(void)
|
int
|
||||||
|
Plugin_RunClientCommand(void)
|
||||||
{
|
{
|
||||||
int(void) vFunc = externvalue(-2, "FMX_RunClientCommand");
|
int rval;
|
||||||
|
int tval;
|
||||||
|
int(void) vFunc;
|
||||||
|
|
||||||
if (vFunc || g_plugins_enabled == 0) {
|
if (g_plugins_enabled == 0)
|
||||||
return vFunc();
|
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_RunClientCommand");
|
||||||
|
|
||||||
|
if (vFunc) {
|
||||||
|
tval = vFunc();
|
||||||
|
rval |= tval;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return FALSE;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -53,13 +129,30 @@ Intercepts 'cmd' calls. We use it to intercept
|
||||||
chat messages and handle distribution ourselves.
|
chat messages and handle distribution ourselves.
|
||||||
=================
|
=================
|
||||||
*/
|
*/
|
||||||
int Plugin_ParseClientCommand(string msg)
|
int
|
||||||
|
Plugin_ParseClientCommand(string msg)
|
||||||
{
|
{
|
||||||
int(string msg) vFunc = externvalue(-2, "FMX_ParseClientCommand");
|
int rval;
|
||||||
|
int tval;
|
||||||
|
int(string msg) vFunc;
|
||||||
|
|
||||||
if (vFunc || g_plugins_enabled == 0) {
|
if (g_plugins_enabled == 0)
|
||||||
return vFunc(msg);
|
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_ParseClientCommand");
|
||||||
|
|
||||||
|
if (vFunc) {
|
||||||
|
tval = vFunc(msg);
|
||||||
|
rval |= tval;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return FALSE;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue