Crossfire Server, Trunk
cfpython.h
Go to the documentation of this file.
1
/*****************************************************************************/
2
/* CFPython - A Python module for Crossfire RPG. */
3
/* Version: 2.0beta8 (also known as "Alexander") */
4
/* Contact: yann.chachkoff@myrealbox.com */
5
/*****************************************************************************/
6
/* That code is placed under the GNU General Public Licence (GPL) */
7
/* (C)2001-2005 by Chachkoff Yann (Feel free to deliver your complaints) */
8
/*****************************************************************************/
9
/* CrossFire, A Multiplayer game for X-windows */
10
/* */
11
/* Copyright (C) 2000 Mark Wedel */
12
/* Copyright (C) 1992 Frank Tore Johansen */
13
/* */
14
/* This program is free software; you can redistribute it and/or modify */
15
/* it under the terms of the GNU General Public License as published by */
16
/* the Free Software Foundation; either version 2 of the License, or */
17
/* (at your option) any later version. */
18
/* */
19
/* This program is distributed in the hope that it will be useful, */
20
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
21
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
22
/* GNU General Public License for more details. */
23
/* */
24
/* You should have received a copy of the GNU General Public License */
25
/* along with this program; if not, write to the Free Software */
26
/* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
27
/* */
28
/*****************************************************************************/
29
#ifndef PLUGIN_PYTHON_H
30
#define PLUGIN_PYTHON_H
31
32
/* First the required header files - only the CF module interface and Python */
33
#ifdef WIN32
34
#ifdef _DEBUG
35
#undef _DEBUG
36
#include <Python.h>
37
#define _DEBUG
38
#else
39
#include <Python.h>
40
#endif
41
#else
/* WIN32 */
42
#include <Python.h>
43
#endif
44
45
/* This is for allowing specific features of Python 3
46
* For example, Python 3.8 changes the typecasting on some stuff we use,
47
* so make a check for that.
48
*/
49
#if PY_MAJOR_VERSION >= 3
50
# if PY_MINOR_VERSION >= 3
51
# define IS_PY3K3
52
# endif
53
# if PY_MINOR_VERSION >= 8
54
# define IS_PY3K8
55
# endif
56
# if PY_MINOR_VERSION >= 10
57
# define IS_PY3K10
58
# endif
59
#endif
60
61
/* Handle Bytes vs. String */
62
#define CF_IS_PYSTR(cfpy_obj) (PyUnicode_Check(cfpy_obj))
63
64
#include <
plugin.h
>
65
66
#undef MODULEAPI
67
#ifdef WIN32
68
# ifdef PYTHON_PLUGIN_EXPORTS
69
# define MODULEAPI __declspec(dllexport)
70
# else
71
# define MODULEAPI __declspec(dllimport)
72
# endif
73
#else
74
#ifdef HAVE_VISIBILITY
75
# define MODULEAPI __attribute__((visibility("default")))
76
#else
77
# define MODULEAPI
78
#endif
79
#endif
80
81
#define PLUGIN_NAME "Python"
82
#define PLUGIN_VERSION "CFPython Plugin 2.0a13 (Fido)"
83
84
#include <
plugin_common.h
>
85
#include <
cfpython_object.h
>
86
#include <
cfpython_map.h
>
87
#include <
cfpython_archetype.h
>
88
#include <
cfpython_party.h
>
89
#include <
cfpython_region.h
>
90
91
typedef
struct
_cfpcontext
{
92
struct
_cfpcontext
*
down
;
93
PyObject *
who
;
94
PyObject *
activator
;
95
PyObject *
third
;
96
PyObject *
event
;
97
char
message
[1024];
98
int
event_code
;
99
char
script
[1024];
100
char
options
[1024];
101
int
returnvalue
;
102
struct
talk_info
*
talk
;
103
}
CFPContext
;
104
105
typedef
struct
{
106
const
char
*
name
;
107
const
int
value
;
108
}
CFConstant
;
109
110
extern
f_plug_api
gethook
;
111
112
extern
CFPContext
*
context_stack
;
113
114
extern
CFPContext
*
current_context
;
115
116
extern
PyMethodDef
CFPythonMethods
[];
117
extern
const
CFConstant
cstDirection
[];
118
extern
const
CFConstant
cstType
[];
119
extern
const
CFConstant
cstMove
[];
120
extern
const
CFConstant
cstMessageFlag
[];
121
extern
const
CFConstant
cstAttackType
[];
122
extern
const
CFConstant
cstAttackTypeNumber
[];
123
extern
const
CFConstant
cstEventType
[];
124
extern
const
CFConstant
cstTime
[];
125
extern
const
CFConstant
cstReplyTypes
[];
126
extern
const
CFConstant
cstAttackMovement
[];
127
128
#include <
cfpython_proto.h
>
129
146
#if PY_VERSION_HEX == 0x030503F0
147
#define CF_PYTHON_OBJECT(NAME, DEALLOC, CONVERT, HASH, FLAGS, DOC, CMP, METHODS, GETSET, BASE, OBNEW) \
148
PyTypeObject Crossfire_ ## NAME ## Type = { \
149
/* See http://bugs.python.org/issue4385 */
\
150
PyVarObject_HEAD_INIT(NULL, 0) \
151
"Crossfire." #NAME,
/* tp_name*/
\
152
sizeof(Crossfire_ ## NAME),
/* tp_basicsize*/
\
153
0,
/* tp_itemsize*/
\
154
DEALLOC,
/* tp_dealloc*/
\
155
(printfunc)NULL,
/* tp_print*/
\
156
NULL,
/* tp_getattr*/
\
157
NULL,
/* tp_setattr*/
\
158
NULL,
/* tp_reserved */
\
159
NULL,
/* tp_repr*/
\
160
CONVERT,
/* tp_as_number*/
\
161
NULL,
/* tp_as_sequence*/
\
162
NULL,
/* tp_as_mapping*/
\
163
HASH,
/* tp_hash */
\
164
NULL,
/* tp_call*/
\
165
NULL,
/* tp_str*/
\
166
PyObject_GenericGetAttr,
/* tp_getattro*/
\
167
PyObject_GenericSetAttr,
/* tp_setattro*/
\
168
NULL,
/* tp_as_buffer*/
\
169
FLAGS,
/* tp_flags*/
\
170
DOC,
/* tp_doc */
\
171
NULL,
/* tp_traverse */
\
172
NULL,
/* tp_clear */
\
173
CMP,
/* tp_richcompare */
\
174
0,
/* tp_weaklistoffset */
\
175
NULL,
/* tp_iter */
\
176
NULL,
/* tp_iternext */
\
177
METHODS,
/* tp_methods */
\
178
NULL,
/* tp_members */
\
179
GETSET,
/* tp_getset */
\
180
BASE,
/* tp_base */
\
181
NULL,
/* tp_dict */
\
182
NULL,
/* tp_descr_get */
\
183
NULL,
/* tp_descr_set */
\
184
0,
/* tp_dictoffset */
\
185
NULL,
/* tp_init */
\
186
NULL,
/* tp_alloc */
\
187
OBNEW,
/* tp_new */
\
188
NULL,
/* tp_free */
\
189
NULL,
/* tp_is_gc */
\
190
NULL,
/* tp_bases */
\
191
NULL,
/* tp_mro */
\
192
NULL,
/* tp_cache */
\
193
NULL,
/* tp_subclasses */
\
194
NULL,
/* tp_weaklist */
\
195
NULL,
/* tp_del */
\
196
0,
/* tp_version_tag */
\
197
NULL
/* tp_finalize */
\
198
}
199
#else
200
#define CF_PYTHON_OBJECT(NAME, DEALLOC, CONVERT, HASH, FLAGS, DOC, CMP, METHODS, GETSET, BASE, OBNEW) \
201
PyTypeObject Crossfire_ ## NAME ## Type = { \
202
/* See http://bugs.python.org/issue4385 */
\
203
PyVarObject_HEAD_INIT(NULL, 0) \
204
"Crossfire." #NAME,
/* tp_name*/
\
205
sizeof(Crossfire_ ## NAME),
/* tp_basicsize*/
\
206
0,
/* tp_itemsize*/
\
207
DEALLOC,
/* tp_dealloc*/
\
208
(printfunc)NULL,
/* tp_print*/
\
209
NULL,
/* tp_getattr*/
\
210
NULL,
/* tp_setattr*/
\
211
NULL,
/* tp_reserved */
\
212
NULL,
/* tp_repr*/
\
213
CONVERT,
/* tp_as_number*/
\
214
NULL,
/* tp_as_sequence*/
\
215
NULL,
/* tp_as_mapping*/
\
216
HASH,
/* tp_hash */
\
217
NULL,
/* tp_call*/
\
218
NULL,
/* tp_str*/
\
219
PyObject_GenericGetAttr,
/* tp_getattro*/
\
220
PyObject_GenericSetAttr,
/* tp_setattro*/
\
221
NULL,
/* tp_as_buffer*/
\
222
FLAGS,
/* tp_flags*/
\
223
DOC,
/* tp_doc */
\
224
NULL,
/* tp_traverse */
\
225
NULL,
/* tp_clear */
\
226
CMP,
/* tp_richcompare */
\
227
0,
/* tp_weaklistoffset */
\
228
NULL,
/* tp_iter */
\
229
NULL,
/* tp_iternext */
\
230
METHODS,
/* tp_methods */
\
231
NULL,
/* tp_members */
\
232
GETSET,
/* tp_getset */
\
233
BASE,
/* tp_base */
\
234
NULL,
/* tp_dict */
\
235
NULL,
/* tp_descr_get */
\
236
NULL,
/* tp_descr_set */
\
237
0,
/* tp_dictoffset */
\
238
NULL,
/* tp_init */
\
239
NULL,
/* tp_alloc */
\
240
OBNEW,
/* tp_new */
\
241
NULL,
/* tp_free */
\
242
NULL,
/* tp_is_gc */
\
243
NULL,
/* tp_bases */
\
244
NULL,
/* tp_mro */
\
245
NULL,
/* tp_cache */
\
246
NULL,
/* tp_subclasses */
\
247
NULL,
/* tp_weaklist */
\
248
NULL,
/* tp_del */
\
249
}
250
#endif
251
258
#if PY_VERSION_HEX == 0x030503F0
259
#define CF_PYTHON_NUMBER_METHODS(NAME, LONG) \
260
static PyNumberMethods NAME ## Convert = { \
261
NULL,
/* binaryfunc nb_add; */
/* __add__ */
\
262
NULL,
/* binaryfunc nb_subtract; */
/* __sub__ */
\
263
NULL,
/* binaryfunc nb_multiply; */
/* __mul__ */
\
264
NULL,
/* binaryfunc nb_remainder; */
/* __mod__ */
\
265
NULL,
/* binaryfunc nb_divmod; */
/* __divmod__ */
\
266
NULL,
/* ternaryfunc nb_power; */
/* __pow__ */
\
267
NULL,
/* unaryfunc nb_negative; */
/* __neg__ */
\
268
NULL,
/* unaryfunc nb_positive; */
/* __pos__ */
\
269
NULL,
/* unaryfunc nb_absolute; */
/* __abs__ */
\
270
NULL,
/* inquiry nb_bool; */
/* __bool__ */
\
271
NULL,
/* unaryfunc nb_invert; */
/* __invert__ */
\
272
NULL,
/* binaryfunc nb_lshift; */
/* __lshift__ */
\
273
NULL,
/* binaryfunc nb_rshift; */
/* __rshift__ */
\
274
NULL,
/* binaryfunc nb_and; */
/* __and__ */
\
275
NULL,
/* binaryfunc nb_xor; */
/* __xor__ */
\
276
NULL,
/* binaryfunc nb_or; */
/* __or__ */
\
277
/* This is not a typo. For Py3k it should be Crossfire_Map_Long \
278
* and NOT Crossfire_Map_Int. \
279
*/
\
280
LONG,
/* unaryfunc nb_int; */
/* __int__ */
\
281
NULL,
/* void *nb_reserved; */
\
282
NULL,
/* unaryfunc nb_float; */
/* __float__ */
\
283
NULL,
/* binaryfunc nb_inplace_add; */
\
284
NULL,
/* binaryfunc nb_inplace_subtract; */
\
285
NULL,
/* binaryfunc nb_inplace_multiply; */
\
286
NULL,
/* binaryfunc nb_inplace_remainder; */
\
287
NULL,
/* ternaryfunc nb_inplace_power; */
\
288
NULL,
/* binaryfunc nb_inplace_lshift; */
\
289
NULL,
/* binaryfunc nb_inplace_rshift; */
\
290
NULL,
/* binaryfunc nb_inplace_and; */
\
291
NULL,
/* binaryfunc nb_inplace_xor; */
\
292
NULL,
/* binaryfunc nb_inplace_or; */
\
293
\
294
NULL,
/* binaryfunc nb_floor_divide; */
\
295
NULL,
/* binaryfunc nb_true_divide; */
\
296
NULL,
/* binaryfunc nb_inplace_floor_divide; */
\
297
NULL,
/* binaryfunc nb_inplace_true_divide; */
\
298
NULL,
/* unaryfunc nb_index; */
\
299
NULL,
/* binaryfunc nb_matrix_multiply; */
\
300
NULL
/* binaryfunc nb_inplace_matrix_multiply; */
\
301
}
302
#else
303
#define CF_PYTHON_NUMBER_METHODS(NAME, LONG) \
304
static PyNumberMethods NAME ## Convert = { \
305
NULL,
/* binaryfunc nb_add; */
/* __add__ */
\
306
NULL,
/* binaryfunc nb_subtract; */
/* __sub__ */
\
307
NULL,
/* binaryfunc nb_multiply; */
/* __mul__ */
\
308
NULL,
/* binaryfunc nb_remainder; */
/* __mod__ */
\
309
NULL,
/* binaryfunc nb_divmod; */
/* __divmod__ */
\
310
NULL,
/* ternaryfunc nb_power; */
/* __pow__ */
\
311
NULL,
/* unaryfunc nb_negative; */
/* __neg__ */
\
312
NULL,
/* unaryfunc nb_positive; */
/* __pos__ */
\
313
NULL,
/* unaryfunc nb_absolute; */
/* __abs__ */
\
314
NULL,
/* inquiry nb_bool; */
/* __bool__ */
\
315
NULL,
/* unaryfunc nb_invert; */
/* __invert__ */
\
316
NULL,
/* binaryfunc nb_lshift; */
/* __lshift__ */
\
317
NULL,
/* binaryfunc nb_rshift; */
/* __rshift__ */
\
318
NULL,
/* binaryfunc nb_and; */
/* __and__ */
\
319
NULL,
/* binaryfunc nb_xor; */
/* __xor__ */
\
320
NULL,
/* binaryfunc nb_or; */
/* __or__ */
\
321
/* This is not a typo. For Py3k it should be Crossfire_Map_Long \
322
* and NOT Crossfire_Map_Int. \
323
*/
\
324
LONG,
/* unaryfunc nb_int; */
/* __int__ */
\
325
NULL,
/* void *nb_reserved; */
\
326
NULL,
/* unaryfunc nb_float; */
/* __float__ */
\
327
NULL,
/* binaryfunc nb_inplace_add; */
\
328
NULL,
/* binaryfunc nb_inplace_subtract; */
\
329
NULL,
/* binaryfunc nb_inplace_multiply; */
\
330
NULL,
/* binaryfunc nb_inplace_remainder; */
\
331
NULL,
/* ternaryfunc nb_inplace_power; */
\
332
NULL,
/* binaryfunc nb_inplace_lshift; */
\
333
NULL,
/* binaryfunc nb_inplace_rshift; */
\
334
NULL,
/* binaryfunc nb_inplace_and; */
\
335
NULL,
/* binaryfunc nb_inplace_xor; */
\
336
NULL,
/* binaryfunc nb_inplace_or; */
\
337
\
338
NULL,
/* binaryfunc nb_floor_divide; */
\
339
NULL,
/* binaryfunc nb_true_divide; */
\
340
NULL,
/* binaryfunc nb_inplace_floor_divide; */
\
341
NULL,
/* binaryfunc nb_inplace_true_divide; */
\
342
NULL
/* unaryfunc nb_index; */
\
343
}
344
#endif
345
346
#endif
/* PLUGIN_PYTHON_H */
_cfpcontext::message
char message[1024]
Definition:
cfpython.h:97
_cfpcontext::third
PyObject * third
Definition:
cfpython.h:95
cstReplyTypes
const CFConstant cstReplyTypes[]
Definition:
cfpython.c:1385
_cfpcontext::event_code
int event_code
Definition:
cfpython.h:98
CFPContext
struct _cfpcontext CFPContext
cfpython_party.h
CFConstant::value
const int value
Definition:
cfpython.h:107
cfpython_region.h
cstDirection
const CFConstant cstDirection[]
Definition:
cfpython.c:1114
plugin.h
_cfpcontext::returnvalue
int returnvalue
Definition:
cfpython.h:101
_cfpcontext::event
PyObject * event
Definition:
cfpython.h:96
cstEventType
const CFConstant cstEventType[]
Definition:
cfpython.c:1333
CFConstant::name
const char * name
Definition:
cfpython.h:106
cstMove
const CFConstant cstMove[]
Definition:
cfpython.c:1242
_cfpcontext::down
struct _cfpcontext * down
Definition:
cfpython.h:92
_cfpcontext::who
PyObject * who
Definition:
cfpython.h:93
f_plug_api
void(* f_plug_api)(int *type,...)
Definition:
plugin.h:81
current_context
CFPContext * current_context
Definition:
cfpython.c:106
cstType
const CFConstant cstType[]
Definition:
cfpython.c:1126
cstTime
const CFConstant cstTime[]
Definition:
cfpython.c:1375
context_stack
CFPContext * context_stack
Definition:
cfpython.c:104
_cfpcontext::script
char script[1024]
Definition:
cfpython.h:99
cfpython_object.h
_cfpcontext::talk
struct talk_info * talk
Definition:
cfpython.h:102
cstAttackType
const CFConstant cstAttackType[]
Definition:
cfpython.c:1273
cstAttackTypeNumber
const CFConstant cstAttackTypeNumber[]
Definition:
cfpython.c:1303
CFConstant
Definition:
cfpython.h:105
_cfpcontext::activator
PyObject * activator
Definition:
cfpython.h:94
plugin_common.h
CFPythonMethods
PyMethodDef CFPythonMethods[]
Definition:
cfpython.c:769
cstMessageFlag
const CFConstant cstMessageFlag[]
Definition:
cfpython.c:1253
talk_info
Definition:
dialog.h:51
cfpython_archetype.h
gethook
f_plug_api gethook
Definition:
cfnewspaper.c:41
_cfpcontext
Definition:
cfpython.h:91
cstAttackMovement
const CFConstant cstAttackMovement[]
Definition:
cfpython.c:1392
cfpython_proto.h
_cfpcontext::options
char options[1024]
Definition:
cfpython.h:100
cfpython_map.h
crossfire-crossfire-server
plugins
cfpython
include
cfpython.h
Generated by
1.8.17