forked from haithun/CoD4X17a_testing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin_com.c
129 lines (104 loc) · 4.31 KB
/
plugin_com.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
===========================================================================
Copyright (C) 2010-2013 Ninja and TheKelm of the IceOps-Team
This file is part of CoD4X17a-Server source code.
CoD4X17a-Server source code is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
CoD4X17a-Server source code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
===========================================================================
*/
#include "plugin_handler.h"
P_P_F qboolean Plugin_IsLoaded(char *name){
int pID,i;
//Identify the calling plugin
pID = PHandler_CallerID();
if(pID<0){
Com_Printf("^1Plugin_IsLoaded: Error! Called from an unknown plugin!\n");
return qfalse;
}
for(i=0;i<MAX_PLUGINS;++i){
if(pluginFunctions.plugins[i].loaded){
if(Q_strncmp(pluginFunctions.plugins[i].name,name,sizeof(pluginFunctions.plugins[i].name))==0){
return pluginFunctions.plugins[i].enabled;
}
}
}
return qfalse;
}
P_P_F version_t *Plugin_GetVersion(char *name)
{
static pluginInfo_t info;
int pID,i;
//Identify the calling plugin
pID = PHandler_CallerID();
if(pID<0){
Com_Printf("^1Plugin_GetVersion: Error! Called from an unknown plugin!\n");
return NULL;
}
for(i=0;i<MAX_PLUGINS;++i){
if(pluginFunctions.plugins[i].loaded){
if(Q_strncmp(pluginFunctions.plugins[i].name,name,sizeof(pluginFunctions.plugins[i].name))==0){
(*pluginFunctions.plugins[i].OnInfoRequest)(&info);
return &(info.pluginVersion);
}
}
}
return NULL;
}
P_P_F qboolean Plugin_ExportFunction(char *name, void *(*function)()){
int pID,i;
//Identify the calling plugin
pID = PHandler_CallerID();
if(pID<0){
Com_Printf("^1Plugin_ExportFunction: Error! Called from an unknown plugin!\n");
return qfalse;
}
if(pluginFunctions.plugins[pID].enabled==qfalse){
Com_Printf("^3WARNING^7: Plugin_ExportFunction called from a disabled plugin!\n");
return qfalse;
}
if(name==NULL || function==NULL){
Com_DPrintf("Plugin_ExportFunction: Error - NULL argument! Plugin ID: %d.\n",pID);
return qfalse; // Null argument!
}
// Check if a function with that name is not already exported by this plugin
for(i=0;i<pluginFunctions.plugins[pID].exports;++i){
if(strncmp(pluginFunctions.plugins[pID].exportedFunctions[i].name,name,PLUGIN_COM_MAXNAMELEN)!=0){
Com_Printf("^3WARNING^7: Plugin of ID %d tried to export function \"%s\" twice.\n",pID,name);
return qfalse;
}
}
//Register the function
pluginFunctions.plugins[pID].exportedFunctions[pluginFunctions.plugins[pID].exports].function = function;
Q_strncpyz(pluginFunctions.plugins[pID].exportedFunctions[pluginFunctions.plugins[pID].exports].name,name,PLUGIN_COM_MAXNAMELEN);
++pluginFunctions.plugins[pID].exports;
return qtrue;
}
P_P_F void *Plugin_ImportFunction(char *pluginName, char *name){
int pID,i,j;
//Identify the calling plugin
pID = PHandler_CallerID();
if(pID<0){
Com_Printf("^1Plugin_ImportFunction: Error! Called from an unknown plugin!\n");
return NULL;
}
for(i=0;i<MAX_PLUGINS;++i){
if(strncmp(pluginFunctions.plugins[i].name,pluginName,20)==0){
for(j=0;j<pluginFunctions.plugins[i].exports;++j){
if(strncmp(pluginFunctions.plugins[i].exportedFunctions[j].name,name,PLUGIN_COM_MAXNAMELEN)==0){
Com_DPrintf("^2Notice:^7 Plugin #%d imported plugin's #%d function \"%s\"\n.",pID,i,name);
return pluginFunctions.plugins[i].exportedFunctions[j].function;
}
}
return NULL;
}
}
return NULL;
}