-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathplugin_handler.h
167 lines (128 loc) · 4.7 KB
/
plugin_handler.h
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*
===========================================================================
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/>
===========================================================================
*/
#ifndef PLUGIN_HANDLER_H
#define PLUGIN_HANDLER_H
/*==========================================*
* *
* Plugin Handler's header *
* *
* Contains all necessary prototypes *
* and types for using the Plugin Handler. *
* *
*==========================================*/
#define MAX_PLUGINS 25 // Maximum number of loaded plugins, hardcoded for better performance
typedef void convariable_t; //For plugins
#define P_P_F __attribute__((__noinline__)) __attribute__((__cdecl__))
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <dlfcn.h>
#include <execinfo.h>
#include "cmd.h" // xcommand_t
#include "sys_net.h" // netadr
#include "msg.h" // msg_t
#include "g_shared.h" // level
#include "qcommon_io.h" // Com_Printf
#include "server.h" // client_t
#include "sys_net.h" // Tcp stuff
#include "plugins/plugin_declarations.h"
#include "plugin_events.h"
#define PLUGIN_MAX_MALLOCS 50
#define PLUGIN_MAX_SOCKETS 4
// plugins com
#define PLUGIN_COM_MAXNAMELEN 28 // Max 27 chars + \0
#define PLUGIN_MAX_EXPORTS 50 // Maximum count of exported functions, each takes 32B of mem = 1kB per plugin
// ----------------------------//
// Plugin Handler's own types //
// ----------------------------//
enum {
PLUGIN_UNKNOWN = -1
};
typedef struct{
char name[32];
xcommand_t xcommand;
}pluginCmd_t;
typedef struct{
size_t size;
void *ptr;
}pluginMem_t;
typedef struct{
char name[PLUGIN_COM_MAXNAMELEN];
void *(*function)();
}pluginExport_t;
typedef struct{
int sock;
netadr_t remote;
qboolean (*packetEventHandler)(netadr_t *from, msg_t* msg);
}pluginTcpClientSocket_t;
typedef struct{
int (*OnInit)(); // Initialization function
void (*OnInfoRequest)(); // Info gathering function
void (*OnEvent[PLUGINS_ITEMCOUNT])();
void (*OnUnload)(); // De-initialization function
pluginCmd_t cmd[20];
pluginCmd_t scriptFunction[32];
pluginCmd_t scriptMethod[32];
int cmds;
int scriptfunctions;
int scriptmethods;
char name[20];
pluginMem_t memory[PLUGIN_MAX_MALLOCS];
pluginTcpClientSocket_t sockets[PLUGIN_MAX_SOCKETS];
pluginExport_t exportedFunctions[PLUGIN_MAX_EXPORTS];
int exports;
size_t usedMem;
int mallocs;
qboolean loaded;
qboolean enabled;
void *lib_handle;
void *lib_start;
long lib_size;
}plugin_t;
typedef struct{
plugin_t plugins[MAX_PLUGINS];
int loadedPlugins;
qboolean enabled;
qboolean initializing_plugin;
}pluginWrapper_t;
extern pluginWrapper_t pluginFunctions; // defined in plugin_handler.c
// --------------------------------//
// Plugin Handler's own functions //
// --------------------------------//
void PHandler_Load(char*,size_t);
void PHandler_Unload(int id);
void PHandler_Event(int, ...);
void PHandler_Init();
void *PHandler_Malloc(int,size_t);
void PHandler_Free(int,void *);
void PHandler_FreeAll(int);
void PHandler_Error(int,int, char *);
qboolean PHandler_TcpConnect(int,const char *,int);
int PHandler_TcpGetData(int, int, void*, int);
qboolean PHandler_TcpSendData(int,int, void*, int);
void PHandler_TcpCloseConnection(int,int);
int PHandler_CallerID();
void PHandler_ChatPrintf(int,char *,...);
void PHandler_CmdExecute_f( void ); // fake server command for use in plugin commands
// --------------------------------------//
// Plugin Handler's own server commands //
// --------------------------------------//
void PHandler_LoadPlugin_f( void );
void PHandler_UnLoadPlugin_f( void );
void PHandler_PluginList_f( void );
void PHandler_PluginInfo_f( void );
#endif /*PLUGIN_HANDLER_H*/