Atrinik Server  4.0
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
plugin_python.h File Reference
#include <Python.h>
#include <global.h>
#include <arch.h>
#include <plugin.h>
#include <plugin_hooklist.h>

Go to the source code of this file.

Data Structures

struct  _pythoncontext
 
struct  Atrinik_Constant
 
struct  Atrinik_Object
 
struct  Atrinik_ObjectIterator
 
struct  Atrinik_Map
 
struct  Atrinik_Party
 
struct  Atrinik_Region
 
struct  Atrinik_Player
 
struct  Atrinik_Archetype
 
struct  Atrinik_AttrList
 
struct  python_cache_entry
 
struct  fields_struct
 

Macros

#define GLOBAL_NO_PROTOTYPES
 
#define IS_PY_LEGACY
 
#define PyObject_AsFileDescriptor(op)   (PyFile_AsFile((op)) ? PyFile_AsFile((op))->fd : -1)
 
#define PLUGIN_NAME   "Python"
 
#define PLUGIN_VERSION   "Atrinik Python Plugin 1.0"
 
#define AROUND_ALL   0
 
#define AROUND_WALL   1
 
#define AROUND_BLOCKSVIEW   2
 
#define AROUND_PLAYER_ONLY   4
 
#define INVENTORY_ONLY   0
 
#define INVENTORY_CONTAINERS   1
 
#define INVENTORY_ALL   2
 
#define FREE_AND_COPY_HASH(_sv_, _nv_)
 
#define FREE_AND_CLEAR_HASH(_nv_)
 
#define SET_ANIMATION(ob, newanim)   ob->face = &(*hooks->new_faces)[(*hooks->animations)[ob->animation_id].faces[newanim]]
 
#define NUM_ANIMATIONS(ob)   ((*hooks->animations)[ob->animation_id].num_animations)
 
#define NUM_FACINGS(ob)   ((*hooks->animations)[ob->animation_id].facings)
 
#define emalloc(_size)   hooks->memory_emalloc(_size, __FILE__, __LINE__)
 
#define efree(_ptr)   hooks->memory_efree(_ptr, __FILE__, __LINE__)
 
#define ecalloc(_nmemb, _size)   hooks->memory_ecalloc(_nmemb, _size, __FILE__, __LINE__)
 
#define erealloc(_ptr, _size)   hooks->memory_erealloc(_ptr, _size, __FILE__, __LINE__)
 
#define ereallocz(_ptr, _old_size, _new_size)   hooks->memory_reallocz(_ptr, _old_size, _new_size, __FILE__, __LINE__)
 
#define estrdup(_s)   hooks->string_estrdup(_s, __FILE__, __LINE__)
 
#define estrndup(_s, _n)   hooks->string_estrndup(_s, _n, __FILE__, __LINE__)
 
#define logger_print   hooks->logger_print
 
#define max_time   *hooks->max_time
 
#define RAISE(msg)
 
#define INTRAISE(msg)
 
#define FIELDFLAG_READONLY   1
 
#define FIELDFLAG_PLAYER_READONLY   2
 
#define FIELDFLAG_PLAYER_FIX   4
 
#define OBJ_ITER_TYPE_NONE   0
 
#define OBJ_ITER_TYPE_BELOW   1
 
#define OBJ_ITER_TYPE_ABOVE   2
 
#define OBJ_ITER_TYPE_ONE   3
 
#define NUM_FIELDS   (sizeof(fields) / sizeof(fields[0]))
 
#define OBJEXISTCHECK_INT(ob)
 
#define OBJEXISTCHECK(ob)
 
#define SQUARES_AROUND_ADD(_m, _x, _y)
 
#define Py_BuildBoolean(val)   ((val) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False))
 
#define FOR_ATRINIK_ITERATOR_BEGIN()   for (object *tmp = self->obj; tmp != NULL; ) {
 
#define FOR_ATRINIK_ITERATOR_END()
 
#define PY_CHECK_INT(val, min, max)
 

Typedefs

typedef PyObject *(* PyMethod_NOARGS )(PyObject *self)
 
typedef PyObject *(* PyMethod_VARARGS )(PyObject *self, PyObject *args)
 
typedef PyObject *(* PyMethod_OBJECT )(PyObject *self, PyObject *what)
 
typedef PyObject *(* PyMethod_VARARGS_KEYWORDS )(PyObject *self, PyObject *args, PyObject *keywds)
 
typedef struct _pythoncontext PythonContext
 
typedef struct Atrinik_Object Atrinik_Object
 
typedef struct
Atrinik_ObjectIterator 
Atrinik_ObjectIterator
 
typedef struct python_cache_entry python_cache_entry
 

Enumerations

enum  field_type {
  FIELDTYPE_SHSTR, FIELDTYPE_CSTR, FIELDTYPE_CARY, FIELDTYPE_UINT8,
  FIELDTYPE_INT8, FIELDTYPE_UINT16, FIELDTYPE_INT16, FIELDTYPE_UINT32,
  FIELDTYPE_INT32, FIELDTYPE_UINT64, FIELDTYPE_INT64, FIELDTYPE_FLOAT,
  FIELDTYPE_DOUBLE, FIELDTYPE_OBJECT, FIELDTYPE_OBJECT2, FIELDTYPE_MAP,
  FIELDTYPE_OBJECTREF, FIELDTYPE_REGION, FIELDTYPE_PARTY, FIELDTYPE_ARCH,
  FIELDTYPE_PLAYER, FIELDTYPE_FACE, FIELDTYPE_ANIMATION, FIELDTYPE_BOOLEAN,
  FIELDTYPE_LIST, FIELDTYPE_CMD_PERMISSIONS, FIELDTYPE_FACTIONS, FIELDTYPE_CONNECTION,
  FIELDTYPE_TREASURELIST, FIELDTYPE_OBJECT_ITERATOR, FIELDTYPE_PACKETS, FIELDTYPE_PACKET
}
 

Functions

PyObject * wrap_object (object *what)
 
PyObject * wrap_object_iterator (object *what)
 
int Atrinik_Object_init (PyObject *module)
 
PyObject * wrap_map (mapstruct *map)
 
int Atrinik_Map_init (PyObject *module)
 
PyObject * wrap_party (party_struct *party)
 
int Atrinik_Party_init (PyObject *module)
 
PyObject * wrap_region (region_struct *region)
 
int Atrinik_Region_init (PyObject *module)
 
PyObject * wrap_player (player *pl)
 
int Atrinik_Player_init (PyObject *module)
 
PyObject * wrap_archetype (archetype_t *at)
 
int Atrinik_Archetype_init (PyObject *module)
 
PyObject * wrap_attr_list (void *ptr, size_t offset, field_type field)
 
int Atrinik_AttrList_init (PyObject *module)
 
int generic_field_setter (fields_struct *field, void *ptr, PyObject *value)
 
PyObject * generic_field_getter (fields_struct *field, void *ptr)
 
PyObject * generic_rich_compare (int op, int result)
 
int python_call_int (PyObject *callable, PyObject *arglist)
 

Variables

struct plugin_hooklist * hooks
 
PyObject * AtrinikError
 
PythonContextcurrent_context
 
PyTypeObject Atrinik_ObjectType
 
PyTypeObject Atrinik_ObjectIteratorType
 
PyTypeObject Atrinik_MapType
 
PyTypeObject Atrinik_PartyType
 
PyTypeObject Atrinik_RegionType
 
PyTypeObject Atrinik_PlayerType
 
PyTypeObject Atrinik_ArchetypeType
 
PyTypeObject Atrinik_AttrListType
 

Detailed Description

Python plugin related header file.

Author
Alex Tokar
Yann Chachkoff

Definition in file plugin_python.h.

Macro Definition Documentation

#define FOR_ATRINIK_ITERATOR_BEGIN ( )    for (object *tmp = self->obj; tmp != NULL; ) {

Begins iterating an Atrinik.Object.ObjectIterator object instance.

Definition at line 586 of file plugin_python.h.

#define FOR_ATRINIK_ITERATOR_END ( )
Value:
if (self->iter_type == OBJ_ITER_TYPE_BELOW) { \
tmp = tmp->below; \
} else if (self->iter_type == OBJ_ITER_TYPE_ABOVE) { \
tmp = tmp->above; \
} else { \
break; \
} \
}
#define OBJ_ITER_TYPE_BELOW
#define OBJ_ITER_TYPE_ABOVE

Ends iterating an Atrinik.Object.ObjectIterator object instance.

Definition at line 592 of file plugin_python.h.

#define FREE_AND_CLEAR_HASH (   _nv_)
Value:
{ \
if (_nv_) \
{ \
hooks->free_string_shared(_nv_); \
_nv_ = NULL; \
} \
}
struct plugin_hooklist * hooks
Definition: plugin_arena.c:160

Free old hash and add a reference to the new one.

Parameters
<em>sv</em>Pointer to shared string.
<em>nv</em>String to add reference to. Must be a shared string.

Definition at line 169 of file plugin_python.h.

#define FREE_AND_COPY_HASH (   _sv_,
  _nv_ 
)
Value:
{ \
if (_sv_) \
{ \
hooks->free_string_shared(_sv_); \
} \
\
_sv_ = hooks->add_string(_nv_); \
}
struct plugin_hooklist * hooks
Definition: plugin_arena.c:160

Free old shared string and add new string.

Parameters
<em>sv</em>Shared string.
<em>nv</em>String to copy to the shared string.

Definition at line 153 of file plugin_python.h.

#define INTRAISE (   msg)
Value:
{ \
PyErr_SetString(PyExc_TypeError, (msg)); \
return -1; \
}

Raise an error using AtrinikError, and return -1.

Definition at line 227 of file plugin_python.h.

#define IS_PY_LEGACY

This is for allowing both python 3 and python 2.

Definition at line 55 of file plugin_python.h.

#define NUM_FIELDS   (sizeof(fields) / sizeof(fields[0]))

Get number of fields in the fields array.

Returns
Number of fields.

Definition at line 542 of file plugin_python.h.

#define OBJEXISTCHECK (   ob)
Value:
{ \
if (!(ob) || !(ob)->obj || (ob)->obj->count != (ob)->count || OBJECT_FREE((ob)->obj)) \
{ \
PyErr_SetString(PyExc_ReferenceError, "Atrinik object no longer exists."); \
return NULL; \
} \
}
Definition: object.h:94
#define OBJECT_FREE(_ob_)
Definition: object.h:554
tag_t count
Definition: object.h:142

Definition at line 553 of file plugin_python.h.

#define OBJEXISTCHECK_INT (   ob)
Value:
{ \
if (!(ob) || !(ob)->obj || (ob)->obj->count != (ob)->count || OBJECT_FREE((ob)->obj)) \
{ \
PyErr_SetString(PyExc_ReferenceError, "Atrinik object no longer exists."); \
return -1; \
} \
}
Definition: object.h:94
#define OBJECT_FREE(_ob_)
Definition: object.h:554
tag_t count
Definition: object.h:142

Definition at line 544 of file plugin_python.h.

#define PLUGIN_NAME   "Python"

Name of the plugin.

Definition at line 76 of file plugin_python.h.

#define PLUGIN_VERSION   "Atrinik Python Plugin 1.0"

Name of the plugin, and its version.

Definition at line 78 of file plugin_python.h.

#define Py_BuildBoolean (   val)    ((val) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False))

Returns Py_True (increasing its reference) if 'val' is non-NULL, otherwise returns Py_False (increasing its reference).

Definition at line 579 of file plugin_python.h.

#define PY_CHECK_INT (   val,
  min,
  max 
)
Value:
if (val < min || val > max) { \
PyErr_Format(PyExc_OverflowError, \
"Invalid integer value for parameter '"STRINGIFY(val)"': " \
"%zd, must be %zd to %zd.", (Py_ssize_t) val, \
(Py_ssize_t) min, (Py_ssize_t) max); \
return NULL; \
}

Definition at line 602 of file plugin_python.h.

#define RAISE (   msg)
Value:
{ \
PyErr_SetString(AtrinikError, (msg)); \
return NULL; \
}
PyObject * AtrinikError
Definition: plugin_python.c:55

Raise an error using AtrinikError, and return NULL.

Definition at line 221 of file plugin_python.h.

#define SQUARES_AROUND_ADD (   _m,
  _x,
  _y 
)
Value:
{ \
PyObject *tuple = PyTuple_New(3); \
\
PyTuple_SET_ITEM(tuple, 0, wrap_map((_m))); \
PyTuple_SET_ITEM(tuple, 1, Py_BuildValue("i", (_x))); \
PyTuple_SET_ITEM(tuple, 2, Py_BuildValue("i", (_y))); \
PyList_Append(list, tuple); \
}
PyObject * wrap_map(mapstruct *map)
Definition: atrinik_map.c:1139

Helper macro for the object.SquaresAround() Python function.

Definition at line 565 of file plugin_python.h.

Typedef Documentation

The Atrinik_Object structure.

The Atrinik_ObjectIterator structure.

typedef PyObject*(* PyMethod_NOARGS)(PyObject *self)
Parameters
selfSelf object for methods; module object for module functions.

Definition at line 84 of file plugin_python.h.

typedef PyObject*(* PyMethod_OBJECT)(PyObject *self, PyObject *what)

Parameters
selfSelf object for methods; module object for module functions.
whatThe object.

Definition at line 98 of file plugin_python.h.

typedef PyObject*(* PyMethod_VARARGS)(PyObject *self, PyObject *args)

Parameters
selfSelf object for methods; module object for module functions.
argsArguments.

Definition at line 91 of file plugin_python.h.

typedef PyObject*(* PyMethod_VARARGS_KEYWORDS)(PyObject *self, PyObject *args, PyObject *keywds)

Parameters
selfSelf object for methods; module object for module functions.
argsArguments.
keywdsKeyword arguments.

Definition at line 105 of file plugin_python.h.

One cache entry.

typedef struct _pythoncontext PythonContext

The Python event context.

Enumeration Type Documentation

enum field_type

Types used in objects and maps structs.

Enumerator
FIELDTYPE_SHSTR 

Pointer to shared string.

FIELDTYPE_CSTR 

Pointer to C string.

FIELDTYPE_CARY 

C string (array directly in struct).

FIELDTYPE_UINT8 

Unsigned int8.

FIELDTYPE_INT8 

Signed int8.

FIELDTYPE_UINT16 

Unsigned int16.

FIELDTYPE_INT16 

Signed int16.

FIELDTYPE_UINT32 

Unsigned int32.

FIELDTYPE_INT32 

Signed int32.

FIELDTYPE_UINT64 

Unsigned int64.

FIELDTYPE_INT64 

Signed int64.

FIELDTYPE_FLOAT 

Float.

FIELDTYPE_DOUBLE 

Double.

FIELDTYPE_OBJECT 

Pointer to object.

FIELDTYPE_OBJECT2 

Object.

FIELDTYPE_MAP 

Pointer to map.

FIELDTYPE_OBJECTREF 

Object pointer + tag.

FIELDTYPE_REGION 

Pointer to region.

FIELDTYPE_PARTY 

Pointer to a party.

FIELDTYPE_ARCH 

Pointer to an archetype.

FIELDTYPE_PLAYER 

Pointer to a player.

FIELDTYPE_FACE 

Face pointer.

FIELDTYPE_ANIMATION 

Animation ID. The field is actually uint16, but the result is a tuple containing the animation name and the animation ID.

FIELDTYPE_BOOLEAN 

uint8 that only accepts True/False.

FIELDTYPE_LIST 

AttrList field type; the field is an array.

FIELDTYPE_CMD_PERMISSIONS 

Player's command permissions.

FIELDTYPE_FACTIONS 

Player's faction reputations.

FIELDTYPE_CONNECTION 

Object's connection value.

FIELDTYPE_TREASURELIST 

Treasure list.

FIELDTYPE_OBJECT_ITERATOR 

Object iterator.

FIELDTYPE_PACKETS 

Packets.

FIELDTYPE_PACKET 

Single packet.

Definition at line 275 of file plugin_python.h.

Function Documentation

int Atrinik_Archetype_init ( PyObject *  module)

Initialize the archetype wrapper.

Parameters
moduleThe Atrinik Python module.
Returns
1 on success, 0 on failure.

Definition at line 187 of file atrinik_archetype.c.

int Atrinik_AttrList_init ( PyObject *  module)

Initializes the AttrList module.

Parameters
moduleThe main Atrinik module.
Returns
1 on success, 0 on failure.

Definition at line 784 of file attr_list.c.

int Atrinik_Map_init ( PyObject *  module)

Initialize the map wrapper.

Parameters
moduleThe Atrinik Python module.
Returns
1 on success, 0 on failure.

Definition at line 1086 of file atrinik_map.c.

int Atrinik_Object_init ( PyObject *  module)

Initialize the Atrinik.Object module.

Parameters
moduleThe Atrinik.Object module.
Returns
1 on success, 0 on failure.

Definition at line 3034 of file atrinik_object.c.

int Atrinik_Party_init ( PyObject *  module)

Initialize the party wrapper.

Parameters
moduleThe Atrinik Python module.
Returns
1 on success, 0 on failure.

Definition at line 360 of file atrinik_party.c.

int Atrinik_Player_init ( PyObject *  module)

Initialize the Atrinik.Player module.

Parameters
moduleThe Atrinik Python module.
Returns
1 on success, 0 on failure.

Definition at line 1183 of file atrinik_player.c.

int Atrinik_Region_init ( PyObject *  module)

Initialize the region wrapper.

Parameters
moduleThe Atrinik Python module.
Returns
1 on success, 0 on failure.

Definition at line 196 of file atrinik_region.c.

PyObject* generic_field_getter ( fields_struct field,
void *  ptr 
)

A generic field getter for all interfaces.

Parameters
typeType of the field.
field_ptrField pointer.
field_ptr2Field pointer for extra data.
Returns
Python object containing value of field_ptr (and field_ptr2, if applicable).

Definition at line 3126 of file plugin_python.c.

int generic_field_setter ( fields_struct field,
void *  ptr,
PyObject *  value 
)

A generic field setter for all interfaces.

Parameters
typeType of the field.
[out]field_ptrField pointer.
valueValue to set for the field pointer.
Returns
0 on success, -1 on failure.

Definition at line 2688 of file plugin_python.c.

PyObject* generic_rich_compare ( int  op,
int  result 
)

Generic rich comparison function.

Parameters
op
result
Returns

Definition at line 3263 of file plugin_python.c.

int python_call_int ( PyObject *  callable,
PyObject *  arglist 
)

Call a function defined in Python script with the specified arguments.

Parameters
callableWhat to call.
arglistArguments to call the function with. Will have reference decreased.
Returns
Integer value the function returned.

Definition at line 3301 of file plugin_python.c.

PyObject* wrap_archetype ( archetype_t at)

Utility method to wrap an archetype.

Parameters
whatArchetype to wrap.
Returns
Python object wrapping the real archetype.

Definition at line 224 of file atrinik_archetype.c.

PyObject* wrap_attr_list ( void *  ptr,
size_t  offset,
field_type  field 
)

Creates a new AttrList wrapping an array.

Parameters
ptrPointer to the structure the array is in.
offsetWhere the array is in the structure.
fieldType of the array being handled; for example, FIELDTYPE_FACTIONS.
Returns
The new wrapper object.

Definition at line 810 of file attr_list.c.

PyObject* wrap_map ( mapstruct what)

Utility method to wrap a map.

Parameters
whatMap to wrap.
Returns
Python object wrapping the real map.

Definition at line 1139 of file atrinik_map.c.

PyObject* wrap_object ( object what)

Utility method to wrap an object.

Parameters
whatObject to wrap.
Returns
Python object wrapping the real object.

Definition at line 3095 of file atrinik_object.c.

PyObject* wrap_object_iterator ( object what)

Utility method to wrap an object inside an object iterator.

Parameters
whatObject to wrap.
Returns
Atrinik.Object.ObjectIterator instance wrapping the object.

Definition at line 3119 of file atrinik_object.c.

PyObject* wrap_party ( party_struct what)

Utility method to wrap a party.

Parameters
whatParty to wrap.
Returns
Python object wrapping the real party.

Definition at line 396 of file atrinik_party.c.

PyObject* wrap_player ( player pl)

Utility method to wrap a player.

Parameters
whatPlayer to wrap.
Returns
Python object wrapping the real player.

Definition at line 1219 of file atrinik_player.c.

PyObject* wrap_region ( region_struct what)

Utility method to wrap a region.

Parameters
whatRegion to wrap.
Returns
Python object wrapping the real region.

Definition at line 232 of file atrinik_region.c.

Variable Documentation

PyObject* AtrinikError

A generic exception that we use for error messages.

Definition at line 55 of file plugin_python.c.

PythonContext* current_context

Current context.

Definition at line 60 of file plugin_python.c.