Atrinik Server 2.5
Data Structures | Defines | Functions | Variables
plugins/plugin_python/plugin_python.c File Reference
#include <plugin_python.h>
#include <compile.h>
#include <eval.h>
#include <node.h>

Go to the source code of this file.

Data Structures

struct  cacheentry

Defines

#define PYTHON_CACHE_SIZE   256

Functions

static int cmd_customPython (object *op, char *params)
static void initContextStack ()
static void pushContext (PythonContext *context)
static PythonContextpopContext ()
static void freeContext (PythonContext *context)
static PyObject * Atrinik_LoadObject (PyObject *self, PyObject *args)
static PyObject * Atrinik_ReadyMap (PyObject *self, PyObject *args)
static PyObject * Atrinik_FindPlayer (PyObject *self, PyObject *args)
static PyObject * Atrinik_PlayerExists (PyObject *self, PyObject *args)
static PyObject * Atrinik_WhoAmI (PyObject *self, PyObject *args)
static PyObject * Atrinik_WhoIsActivator (PyObject *self, PyObject *args)
static PyObject * Atrinik_WhoIsOther (PyObject *self, PyObject *args)
static PyObject * Atrinik_WhatIsEvent (PyObject *self, PyObject *args)
static PyObject * Atrinik_GetEventNumber (PyObject *self, PyObject *args)
static PyObject * Atrinik_WhatIsMessage (PyObject *self, PyObject *args)
static PyObject * Atrinik_GetOptions (PyObject *self, PyObject *args)
static PyObject * Atrinik_GetReturnValue (PyObject *self, PyObject *args)
static PyObject * Atrinik_SetReturnValue (PyObject *self, PyObject *args)
static PyObject * Atrinik_GetEventParameters (PyObject *self, PyObject *args)
static PyObject * Atrinik_GetSpellNr (PyObject *self, PyObject *args)
static PyObject * Atrinik_GetSpell (PyObject *self, PyObject *args)
static PyObject * Atrinik_GetSkillNr (PyObject *self, PyObject *args)
static PyObject * Atrinik_RegisterCommand (PyObject *self, PyObject *args)
static PyObject * Atrinik_CreatePathname (PyObject *self, PyObject *args)
static PyObject * Atrinik_GetTime (PyObject *self, PyObject *args)
static PyObject * Atrinik_LocateBeacon (PyObject *self, PyObject *args)
static PyObject * Atrinik_FindParty (PyObject *self, PyObject *args)
static PyObject * Atrinik_CleanupChatString (PyObject *self, PyObject *args)
static PyObject * Atrinik_LOG (PyObject *self, PyObject *args)
static PyObject * Atrinik_DestroyTimer (PyObject *self, PyObject *args)
static PyObject * Atrinik_GetRangeVectorFromMapCoords (PyObject *self, PyObject *args)
static PyObject * Atrinik_CostString (PyObject *self, PyObject *args)
static PyObject * Atrinik_CacheAdd (PyObject *self, PyObject *args)
static PyObject * Atrinik_CacheGet (PyObject *self, PyObject *args)
static PyObject * Atrinik_CacheRemove (PyObject *self, PyObject *args)
static PyObject * Atrinik_GetFirst (PyObject *self, PyObject *args)
static PyObject * Atrinik_CreateMap (PyObject *self, PyObject *args)
static PyObject * Atrinik_CreateObject (PyObject *self, PyObject *args)
static void PyErr_LOG ()
static PyCodeObject * compilePython (char *filename)
static int do_script (PythonContext *context, const char *filename, object *event)
static int handle_event (va_list args)
static int handle_map_event (va_list args)
static int handle_global_event (int event_type, va_list args)
MODULEAPI void * triggerEvent (int *type,...)
MODULEAPI void * getPluginProperty (int *type,...)
MODULEAPI void postinitPlugin ()
static PyObject * module_create (const char *name)
static void module_add_constants (PyObject *module, const char *name, const Atrinik_Constant *consts)
static void module_add_array (PyObject *module, const char *name, void *array, size_t array_size, field_type type)
static PyObject * python_openlogfile (FILE *fp, char *name)
MODULEAPI void initPlugin (struct plugin_hooklist *hooklist)
MODULEAPI void closePlugin ()
static int set_face_field (void *ptr, long face_id)
static int set_animation_field (void *ptr, long anim_id)
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
static PythonContextcontext_stack
PythonContextcurrent_context
static const Atrinik_Constant constants []
static const Atrinik_Constant constants_types []
static const Atrinik_Constant constants_gender []
static const char *const constants_colors [][2]
static PythonCmd CustomCommand [NR_CUSTOM_CMD]
static int NextCustomCommand
static cacheentry python_cache [PYTHON_CACHE_SIZE]
static PyMethodDef AtrinikMethods []

Detailed Description

Atrinik python plugin.

Definition in file plugin_python.c.


Define Documentation

#define PYTHON_CACHE_SIZE   256

Maximum number of cached scripts.

Definition at line 477 of file plugin_python.c.


Function Documentation

static int cmd_customPython ( object op,
char *  params 
) [static]

Run custom command using Python script.

Parameters:
opObject running the command.
paramsCommand parameters.
Returns:
0 on failure, return value of the script otherwise.

Definition at line 1959 of file plugin_python.c.

static PyCodeObject* compilePython ( char *  filename) [static]

Outputs the compiled bytecode for a given python file, using in-memory caching of bytecode.

Definition at line 1465 of file plugin_python.c.

static void freeContext ( PythonContext context) [static]

Free a context.

Parameters:
contextContext to free.

Definition at line 548 of file plugin_python.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.

static int handle_event ( va_list  args) [static]

Handles normal events.

Parameters:
argsList of arguments for context.
Returns:
0 on failure, script's return value otherwise.

Definition at line 1689 of file plugin_python.c.

static int handle_global_event ( int  event_type,
va_list  args 
) [static]

Handles global event.

Parameters:
event_typeThe event ID.
argsList of arguments for context.
Returns:
0.

Definition at line 1784 of file plugin_python.c.

static int handle_map_event ( va_list  args) [static]

Handles map events.

Parameters:
argsList of arguments for context.
Returns:
0 on failure, script's return value otherwise.

Definition at line 1751 of file plugin_python.c.

static void initContextStack ( ) [static]

Initialize the context stack.

Definition at line 502 of file plugin_python.c.

static void module_add_array ( PyObject *  module,
const char *  name,
void *  array,
size_t  array_size,
field_type  type 
) [static]

Construct a list from C array and add it to the specified module.

Parameters:
moduleModule to add to.
nameName of the list.
arrayPointer to the C array.
array_sizeNumber of entries in the C array.
typeType of the entries in the C array.

Definition at line 2087 of file plugin_python.c.

static void module_add_constants ( PyObject *  module,
const char *  name,
const Atrinik_Constant consts 
) [static]

Creates a new module containing integer constants, and adds it to the specified module.

Parameters:
moduleModule to add to.
nameName of the created module.
constantsConstants to add.

Definition at line 2061 of file plugin_python.c.

static PyObject* module_create ( const char *  name) [static]

Create a module.

Parameters:
nameName of the module.
Returns:
The new module created using PyModule_New().

Definition at line 2046 of file plugin_python.c.

static PythonContext* popContext ( ) [static]

Pop the first context from the current context, replacing it by the next one in the list.

Returns:
NULL if there is no current context, the previous current context otherwise.

Definition at line 531 of file plugin_python.c.

static void pushContext ( PythonContext context) [static]

Push context to the context stack and to current context.

Parameters:
contextThe context to push.

Definition at line 511 of file plugin_python.c.

static void PyErr_LOG ( ) [static]

Log a Python exception. Will also send the exception to any online DMs or those with /resetmap command permission.

Definition at line 1425 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.

static PyObject* python_openlogfile ( FILE *  fp,
char *  name 
) [static]

Open a log file in replacement for stdout and stderr.

Parameters:
fpFile pointer.
nameName, for example, <stdout>.
Returns:
The opened log file.

Definition at line 2118 of file plugin_python.c.

static int set_animation_field ( void *  ptr,
long  anim_id 
) [static]

Sets animation field.

Parameters:
ptrPointer to uint16 structure member.
anim_idID of the animation to set.
Returns:
0 on success, -1 on failure.

Definition at line 2243 of file plugin_python.c.

static int set_face_field ( void *  ptr,
long  face_id 
) [static]

Sets face field.

Parameters:
ptrPointer to New_Face structure.
face_idID of the face to set.
Returns:
0 on success, -1 on failure.

Definition at line 2226 of file plugin_python.c.


Variable Documentation

PyObject* AtrinikError

A generic exception that we use for error messages.

Definition at line 48 of file plugin_python.c.

PyMethodDef AtrinikMethods[] [static]

Here is the Python Declaration Table, used by the interpreter to make an interface with the C code.

Definition at line 1384 of file plugin_python.c.

const Atrinik_Constant constants[] [static]

Useful constants

Definition at line 61 of file plugin_python.c.

const char* const constants_colors[][2] [static]
Initial value:
{
    {"COLOR_WHITE", COLOR_WHITE},
    {"COLOR_ORANGE", COLOR_ORANGE},
    {"COLOR_NAVY", COLOR_NAVY},
    {"COLOR_RED", COLOR_RED},
    {"COLOR_GREEN", COLOR_GREEN},
    {"COLOR_BLUE", COLOR_BLUE},
    {"COLOR_GRAY", COLOR_GRAY},
    {"COLOR_BROWN", COLOR_BROWN},
    {"COLOR_PURPLE", COLOR_PURPLE},
    {"COLOR_PINK", COLOR_PINK},
    {"COLOR_YELLOW", COLOR_YELLOW},
    {"COLOR_DK_NAVY", COLOR_DK_NAVY},
    {"COLOR_DK_GREEN", COLOR_DK_GREEN},
    {"COLOR_DK_ORANGE", COLOR_DK_ORANGE},
    {"COLOR_HGOLD", COLOR_HGOLD},
    {"COLOR_DGOLD", COLOR_DGOLD},
    {NULL, NULL}
}

Color constants

Definition at line 449 of file plugin_python.c.

Initial value:
{
    {"NEUTER", GENDER_NEUTER},
    {"MALE", GENDER_MALE},
    {"FEMALE", GENDER_FEMALE},
    {"HERMAPHRODITE", GENDER_HERMAPHRODITE},

    {NULL, 0}
}

Gender constants.

Definition at line 432 of file plugin_python.c.

Game object type constants.

Definition at line 300 of file plugin_python.c.

The context stack.

Definition at line 51 of file plugin_python.c.

Current context.

Definition at line 53 of file plugin_python.c.

PythonCmd CustomCommand[NR_CUSTOM_CMD] [static]

All the custom commands.

Definition at line 472 of file plugin_python.c.

int NextCustomCommand [static]

Contains the index of the next command that needs to be run.

Definition at line 474 of file plugin_python.c.

cacheentry python_cache[PYTHON_CACHE_SIZE] [static]

The Python cache.

Definition at line 496 of file plugin_python.c.