-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestPlugin.cpp
More file actions
179 lines (133 loc) · 3.76 KB
/
TestPlugin.cpp
File metadata and controls
179 lines (133 loc) · 3.76 KB
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
168
169
170
171
172
173
174
175
176
177
178
179
//#include "qcommon/qcommon.h"
#include "qcommon\q_shared.h"
#include "TestPlugin.h"
///////////////////////////////COMMANDS
pluginImport_t *trap = NULL;
int Q_stricmpn(const char *s1, const char *s2, int n) {
int c1, c2;
// bk001129 - moved in 1.17 fix not in id codebase
if (s1 == NULL) {
if (s2 == NULL)
return 0;
else
return -1;
}
else if (s2 == NULL)
return 1;
do {
c1 = *s1++;
c2 = *s2++;
if (!n--) {
return 0; // strings are equal until end point
}
if (c1 != c2) {
if (c1 >= 'a' && c1 <= 'z') {
c1 -= ('a' - 'A');
}
if (c2 >= 'a' && c2 <= 'z') {
c2 -= ('a' - 'A');
}
if (c1 != c2) {
return c1 < c2 ? -1 : 1;
}
}
} while (c1);
return 0; // strings are equal
}
int Q_stricmp(const char *s1, const char *s2) {
return (s1 && s2) ? Q_stricmpn(s1, s2, 99999) : -1;
}
typedef struct svcmd_s {
const char *name;
void(*func)(void);
qboolean dedicated;
} svcmd_t;
void TestFunction(void){
Com_Printf("TESTING");
}
int svcmdcmp(const void *a, const void *b) {
return Q_stricmp((const char *)a, ((svcmd_t*)b)->name);
}
/* This array MUST be sorted correctly by alphabetical name field */
svcmd_t commands[] = {
{ "testplugin", TestFunction},
};
static const size_t numCommands = ARRAY_LEN(commands);
qboolean ConsoleCommand(void) {
char cmd[MAX_TOKEN_CHARS] = { 0 };
svcmd_t *command = NULL;
trap->Argv(0, cmd, sizeof(cmd));
command = (svcmd_t *)bsearch(cmd, commands, numCommands, sizeof(commands[0]), svcmdcmp);
if (!command)
return qfalse;
command->func();
return qtrue;
}
//////////////////////////////////
plugininfo_t *G_InitPlugin(int levelTime){
//trap->AddCommand("testplugin", TestFunction);
}
void G_ShutdownPlugin(int restart){
trap->Print("Shutdown\n");
}
char *ClientConnect(int clientNum, qboolean firstTime, qboolean isBot){
trap->Print("CLIENT CONNECTING....\n");
return NULL;
}
int ClientBegin(int clientNum, qboolean allowTeamReset){
trap->Print("CLIENT BEGIN\n");
}
qboolean *ClientUserinfoChanged(int clientNum){
trap->Print("USER INFO CHANGED\n");
return qtrue;
}
void *ClientDisconnect(int clientNum){
trap->Print("CLIENT DISCONNECT\n");
}
int *ClientCommand(int clientNum){
trap->Print("Client Command\n");
}
void *ClientThink(int clientNum, usercmd_t *ucmd) {
//trap->Print("Client Think\n");
}
void *RunFrame(int levelTime) {
//trap->Print("Frame");
}
void QDECL CallFunction(int cmd, int numargs, va_list *args);
Q_EXPORT plugininfo_t* QDECL GetPluginAPI(int apiVersion, pluginImport_t *import)
{
plugininfo_t *ge = (plugininfo_t*)malloc(sizeof(plugininfo_t));
ge->name = "Plugin for SABER SERVER";
ge->author = "EpicLoyd";
ge->version = "1.0";
ge->usegamelibrary = qtrue;
assert(import);
trap = import;
Com_Printf = trap->Print;
Com_Error = trap->Error;
ge->export = (pluginExport_t*)malloc(sizeof(pluginExport_t));
if (apiVersion != PLUGIN_API_VERSION) {
trap->Print("Mismatched PLUGIN_API_VERSION: expected %i, got %i\n", PLUGIN_API_VERSION, apiVersion);
return NULL;
}
ge->export->InitPlugin = G_InitPlugin;
ge->export->ShutDownPlugin = G_ShutdownPlugin;
ge->export->ClientConnect = ClientConnect;
ge->export->ClientBegin = ClientBegin;
ge->export->ClientCommand = ClientCommand;
ge->export->ClientDisconnect = ClientDisconnect;
ge->export->ClientThink = ClientThink;
ge->export->ClientUserinfoChanged = ClientUserinfoChanged;
ge->export->ConsoleCommand = ConsoleCommand;
ge->export->RunFrame = RunFrame;
ge->export->Call = CallFunction;
return ge;
}
void QDECL CallFunction(int cmd, int numargs, va_list *args){
trap->Print("TEST SECONDARY ENTRY argsnum: %d\n", numargs);
char *nigra = NULL;
for (int i = 0; i < numargs; i++){
nigra = va_arg(*args, char*);
Com_Printf("AJAJJAJAJ: %s \n", nigra);
}
}