Atrinik Server 2.5
Data Structures | Defines | Typedefs | Enumerations | Functions | Variables
plugins/plugin_python/include/plugin_python.h File Reference
#include <Python.h>
#include <plugin.h>
#include <timers.h>

Go to the source code of this file.

Data Structures

struct  _pythoncontext
struct  Atrinik_Constant
struct  Atrinik_Object
struct  Atrinik_Map
struct  Atrinik_Party
struct  Atrinik_Region
struct  Atrinik_Player
struct  Atrinik_Archetype
struct  Atrinik_AttrList
struct  PythonCmdStruct
struct  fields_struct

Defines

#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 LOG   hooks->LOG
#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 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 NR_CUSTOM_CMD   1024
#define OBJEXISTCHECK_INT(ob)
#define OBJEXISTCHECK(ob)
#define SQUARES_AROUND_ADD(_m, _x, _y)
#define Py_ReturnBoolean(val)

Typedefs

typedef struct _pythoncontext PythonContext
typedef struct Atrinik_Object Atrinik_Object
typedef struct PythonCmdStruct PythonCmd

Enumerations

enum  field_type {
  FIELDTYPE_SHSTR, FIELDTYPE_CSTR, FIELDTYPE_CARY, FIELDTYPE_UINT8,
  FIELDTYPE_SINT8, FIELDTYPE_UINT16, FIELDTYPE_SINT16, FIELDTYPE_UINT32,
  FIELDTYPE_SINT32, FIELDTYPE_UINT64, FIELDTYPE_SINT64, FIELDTYPE_FLOAT,
  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_KNOWN_SPELLS, FIELDTYPE_CMD_PERMISSIONS, FIELDTYPE_FACTIONS
}

Functions

PyObject * wrap_object (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 *region)
int Atrinik_Region_init (PyObject *module)
PyObject * wrap_player (player *pl)
int Atrinik_Player_init (PyObject *module)
PyObject * wrap_archetype (archetype *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_hooklisthooks
PyObject * AtrinikError
PythonContextcurrent_context
PyTypeObject Atrinik_ObjectType
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.

Definition in file plugin_python.h.


Define Documentation

#define FREE_AND_CLEAR_HASH (   _nv_)
Value:
{                                        \
    if (_nv_)                            \
    {                                    \
        hooks->free_string_shared(_nv_); \
        _nv_ = NULL;                     \
    }                                    \
}

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

Parameters:
_sv_Pointer to shared string.
_nv_String to add reference to. Must be a shared string.

Definition at line 126 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_);      \
}

Free old shared string and add new string.

Parameters:
_sv_Shared string.
_nv_String to copy to the shared string.

Definition at line 113 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 151 of file plugin_python.h.

#define IS_PY_LEGACY

This is for allowing both python 3 and python 2.

Definition at line 44 of file plugin_python.h.

#define LOG   hooks->LOG

Logs a message to stderr, or to file, and/or even to socket. Or discards the message if it is of no importance, and none have asked to hear messages of that logLevel.

See include/logger.h for possible logLevels. Messages with llevSystem and llevError are always printed, regardless of debug mode.

Additionally, llevError message will cause the server to exit.

Parameters:
logLevelLog level of the message
formatFormat specifiers
...Arguments for the format

Definition at line 104 of file plugin_python.h.

#define NR_CUSTOM_CMD   1024

Number of custom commands to allow.

Definition at line 437 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 434 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 at line 448 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 at line 439 of file plugin_python.h.

#define PLUGIN_NAME   "Python"

Name of the plugin.

Definition at line 65 of file plugin_python.h.

#define PLUGIN_VERSION   "Atrinik Python Plugin 1.0"

Name of the plugin, and its version.

Definition at line 67 of file plugin_python.h.

#define Py_ReturnBoolean (   val)
Value:
{ \
    if ((val)) \
    { \
        Py_INCREF(Py_True); \
        return Py_True; \
    } \
    else \
    { \
        Py_INCREF(Py_False); \
        return Py_False; \
    } \
}

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

Definition at line 472 of file plugin_python.h.

#define RAISE (   msg)
Value:
{                                         \
    PyErr_SetString(AtrinikError, (msg)); \
    return NULL;                          \
}

Raise an error using AtrinikError, and return NULL.

Definition at line 145 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); \
}

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

Definition at line 459 of file plugin_python.h.


Typedef Documentation

The Atrinik_Object structure.

typedef struct PythonCmdStruct PythonCmd

This structure is used to define one Python-implemented command.

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_SINT8 

Signed int8.

FIELDTYPE_UINT16 

Unsigned int16.

FIELDTYPE_SINT16 

Signed int16.

FIELDTYPE_UINT32 

Unsigned int32.

FIELDTYPE_SINT32 

Signed int32.

FIELDTYPE_UINT64 

Unsigned int64.

FIELDTYPE_SINT64 

Signed int64.

FIELDTYPE_FLOAT 

Float.

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_KNOWN_SPELLS 

Player's known spells array.

FIELDTYPE_CMD_PERMISSIONS 

Player's command permissions.

FIELDTYPE_FACTIONS 

Player's faction reputations.

Definition at line 201 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 165 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 589 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 694 of file atrinik_map.c.

int Atrinik_Object_init ( PyObject *  module)

Initialize the object wrapper.

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

Definition at line 2438 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 315 of file atrinik_party.c.

int Atrinik_Player_init ( PyObject *  module)

Initialize the player wrapper.

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

Definition at line 647 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 168 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 2724 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 2261 of file plugin_python.c.

PyObject* generic_rich_compare ( int  op,
int  result 
)

Generic rich comparison function.

Parameters:
op
result
Returns:

Definition at line 2822 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 2856 of file plugin_python.c.

PyObject* wrap_archetype ( archetype at)

Utility method to wrap an archetype.

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

Definition at line 200 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_KNOWN_SPELLS.
Returns:
The new wrapper object.

Definition at line 611 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 741 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 2492 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 350 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 682 of file atrinik_player.c.

PyObject* wrap_region ( region what)

Utility method to wrap a region.

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

Definition at line 203 of file atrinik_region.c.


Variable Documentation

PyObject* AtrinikError

A generic exception that we use for error messages.

Definition at line 48 of file plugin_python.c.

Current context.

Definition at line 53 of file plugin_python.c.