Crossfire Server, Trunk
cfpython.c File Reference
#include <cfpython.h>
#include <fcntl.h>
#include <stdarg.h>
#include <node.h>
#include <svnversion.h>
+ Include dependency graph for cfpython.c:

Go to the source code of this file.

Data Structures

struct  pycode_cache_entry
 

Macros

#define MAX_COMMANDS   1024
 
#define PYTHON_CACHE_SIZE   256
 
#define PYTHON_DEBUG
 

Functions

static void addConstants (PyObject *module, const char *name, const CFConstant *constants)
 
static PyObject * addReply (PyObject *self, PyObject *args)
 
static void addSimpleConstants (PyObject *module, const char *name, const CFConstant *constants)
 
CF_PLUGIN int cfpython_globalEventListener (int *type,...)
 
static void cfpython_init_types (PyObject *m)
 
static PyObject * cfpython_openpyfile (char *filename)
 
static FILE * cfpython_pyfile_asfile (PyObject *obj)
 
CF_PLUGIN int closePlugin (void)
 
static PyCodeObject * compilePython (char *filename)
 
static PyObject * costStringFromValue (PyObject *self, PyObject *args)
 
static PyObject * createCFObject (PyObject *self, PyObject *args)
 
static PyObject * createCFObjectByName (PyObject *self, PyObject *args)
 
static PyObject * createMap (PyObject *self, PyObject *args)
 
static PyObject * destroyTimer (PyObject *self, PyObject *args)
 
static int do_script (CFPContext *context)
 
CF_PLUGIN int eventListener (int *type,...)
 
static PyObject * findAnimation (PyObject *self, PyObject *args)
 
static PyObject * findFace (PyObject *self, PyObject *args)
 
static PyObject * findPlayer (PyObject *self, PyObject *args)
 
static void freeContext (CFPContext *context)
 
static void freeEventFiles (char **eventFiles)
 
static PyObject * getArchetypes (PyObject *self, PyObject *args)
 
static PyObject * getCFPythonVersion (PyObject *self, PyObject *args)
 
static PyObject * getConfigDirectory (PyObject *self, PyObject *args)
 
static PyObject * getDataDirectory (PyObject *self, PyObject *args)
 
static PyObject * getEvent (PyObject *self, PyObject *args)
 
static char ** getEventFiles (CFPContext *context)
 
static PyObject * getFriendlyList (PyObject *self, PyObject *args)
 
static const char * getGlobalEventPath (int code)
 
static PyObject * getLocalDirectory (PyObject *self, PyObject *args)
 
static PyObject * getMapDirectory (PyObject *self, PyObject *args)
 
static PyObject * getMapHasBeenLoaded (PyObject *self, PyObject *args)
 
static PyObject * getMaps (PyObject *self, PyObject *args)
 
static PyObject * getMonthName (PyObject *self, PyObject *args)
 
static PyObject * getParties (PyObject *self, PyObject *args)
 
static PyObject * getPeriodofdayName (PyObject *self, PyObject *args)
 
static PyObject * getPlayerDirectory (PyObject *self, PyObject *args)
 
static PyObject * getPlayers (PyObject *self, PyObject *args)
 
CF_PLUGIN void * getPluginProperty (int *type,...)
 
static PyObject * getPrivateDictionary (PyObject *self, PyObject *args)
 
static PyObject * getRegions (PyObject *self, PyObject *args)
 
static PyObject * getReturnValue (PyObject *self, PyObject *args)
 
static PyObject * getScriptName (PyObject *self, PyObject *args)
 
static PyObject * getScriptParameters (PyObject *self, PyObject *args)
 
static PyObject * getSeasonName (PyObject *self, PyObject *args)
 
static PyObject * getSharedDictionary (PyObject *self, PyObject *args)
 
static PyObject * getTempDirectory (PyObject *self, PyObject *args)
 
static PyObject * getTime (PyObject *self, PyObject *args)
 
static PyObject * getUniqueDirectory (PyObject *self, PyObject *args)
 
static PyObject * getWeekdayName (PyObject *self, PyObject *args)
 
static PyObject * getWhatIsMessage (PyObject *self, PyObject *args)
 
static PyObject * getWhoAmI (PyObject *self, PyObject *args)
 
static PyObject * getWhoIsActivator (PyObject *self, PyObject *args)
 
static PyObject * getWhoIsThird (PyObject *self, PyObject *args)
 
static void initConstants (PyObject *module)
 
static void initContextStack (void)
 
CF_PLUGIN int initPlugin (const char *iversion, f_plug_api gethooksptr)
 
static PyObject * log_message (PyObject *self, PyObject *args)
 
static void log_python_error (void)
 
static PyObject * matchString (PyObject *self, PyObject *args)
 
static PyObject * npcSay (PyObject *self, PyObject *args)
 
static CFPContextpopContext (void)
 
CF_PLUGIN int postInitPlugin (void)
 
static void pushContext (CFPContext *context)
 
PyObject * PyInit_cjson (void)
 
static PyObject * PyInit_Crossfire (void)
 
static void python_command_function (object *op, const char *params, const char *script)
 
static PyObject * readyMap (PyObject *self, PyObject *args)
 
static PyObject * registerCommand (PyObject *self, PyObject *args)
 
static PyObject * registerGEvent (PyObject *self, PyObject *args)
 
static void set_exception (const char *fmt,...)
 
static PyObject * setPlayerMessage (PyObject *self, PyObject *args)
 
static PyObject * setReturnValue (PyObject *self, PyObject *args)
 
static PyObject * unregisterGEvent (PyObject *self, PyObject *args)
 

Variables

static PyObject * catcher = NULL
 
static PyObject * CFPythonError
 
PyMethodDef CFPythonMethods []
 
CFPContextcontext_stack
 
static PyModuleDef CrossfireModule
 
const CFConstant cstAttackMovement []
 
const CFConstant cstAttackType []
 
const CFConstant cstAttackTypeNumber []
 
const CFConstant cstDirection []
 
const CFConstant cstEventType []
 
const CFConstant cstMessageFlag []
 
const CFConstant cstMove []
 
const CFConstant cstReplyTypes []
 
const CFConstant cstTime []
 
const CFConstant cstType []
 
CFPContextcurrent_context
 
static int GECodes []
 
static const char * GEPaths []
 
static PyObject * private_data = NULL
 
static pycode_cache_entry pycode_cache [PYTHON_CACHE_SIZE]
 
static command_registration registered_commands [MAX_COMMANDS]
 
static PyObject * shared_data = NULL
 
CF_PLUGIN char SvnRevPlugin [] = SVN_REV
 

Macro Definition Documentation

◆ MAX_COMMANDS

#define MAX_COMMANDS   1024

Definition at line 84 of file cfpython.c.

◆ PYTHON_CACHE_SIZE

#define PYTHON_CACHE_SIZE   256

Number of python scripts to store the bytecode of at a time.

Definition at line 72 of file cfpython.c.

◆ PYTHON_DEBUG

#define PYTHON_DEBUG

Give us some general infos out.

Definition at line 71 of file cfpython.c.

Function Documentation

◆ addConstants()

static void addConstants ( PyObject *  module,
const char *  name,
const CFConstant constants 
)
static

Add constants and a reverse dictionary to get the name from the value. The reverse dictionary will be named '{name}Name'.

Parameters
modulewhere to add the constants to.
nameenum name containing the constants.
constantsconstants to add, the last item must have its values all NULL.

Definition at line 1066 of file cfpython.c.

References autojail::dict, give::name, Ice::tmp, and autojail::value.

Referenced by initConstants().

+ Here is the caller graph for this function:

◆ addReply()

static PyObject* addReply ( PyObject *  self,
PyObject *  args 
)
static

◆ addSimpleConstants()

static void addSimpleConstants ( PyObject *  module,
const char *  name,
const CFConstant constants 
)
static

Do half the job of addConstants. It only sets constants, but not a hashtable to get constant names from values. To be used for collections of constants which are not unique but still are useful for scripts.

Parameters
modulewhere to add the constants to.
nameenum name containing the constants.
constantsconstants to add, the last item must have its values all NULL.

Definition at line 1098 of file cfpython.c.

References give::name, Ice::tmp, and autojail::value.

Referenced by initConstants().

+ Here is the caller graph for this function:

◆ cfpython_globalEventListener()

◆ cfpython_init_types()

static void cfpython_init_types ( PyObject *  m)
static

Set up the various types (map, object, archetype and so on) as well as some constants, and Crossfire.error.

Definition at line 1434 of file cfpython.c.

References CFPythonError, Crossfire_ArchetypeType, Crossfire_MapType, Crossfire_ObjectType, Crossfire_PartyType, Crossfire_PlayerType, Crossfire_RegionType, llevDebug, llevError, llevInfo, llevMonster, and m.

Referenced by initPlugin().

+ Here is the caller graph for this function:

◆ cfpython_openpyfile()

static PyObject* cfpython_openpyfile ( char *  filename)
static

Open a file in the way we need it for compilePython() and postInitPlugin().

Definition at line 859 of file cfpython.c.

References npc_dialog::filename, and CFBank::open().

Referenced by compilePython(), and postInitPlugin().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cfpython_pyfile_asfile()

static FILE* cfpython_pyfile_asfile ( PyObject *  obj)
static

Return a file object from a Python file (as needed for compilePython() and postInitPlugin())

Definition at line 873 of file cfpython.c.

Referenced by compilePython(), and postInitPlugin().

+ Here is the caller graph for this function:

◆ closePlugin()

CF_PLUGIN int closePlugin ( void  )

Close the plugin.

Closes the sqlite database.

Returns
0.

Definition at line 1917 of file cfpython.c.

References c, cf_free_string(), cf_log(), cf_system_unregister_command(), mad_mage_user::file, llevDebug, MAX_COMMANDS, pycode_cache, PYTHON_CACHE_SIZE, and registered_commands.

+ Here is the call graph for this function:

◆ compilePython()

static PyCodeObject* compilePython ( char *  filename)
static

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

Definition at line 917 of file cfpython.c.

References cf_add_string(), cf_free_string(), cf_log(), cfpython_openpyfile(), cfpython_pyfile_asfile(), mad_mage_user::file, npc_dialog::filename, llevDebug, llevError, log_python_error(), pycode_cache, PYTHON_CACHE_SIZE, replace(), sstring, and nlohmann::detail::void().

Referenced by do_script().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ costStringFromValue()

static PyObject* costStringFromValue ( PyObject *  self,
PyObject *  args 
)
static

Definition at line 756 of file cfpython.c.

References make_face_from_files::args, buf, cf_cost_string_from_value(), autojail::value, and nlohmann::detail::void().

+ Here is the call graph for this function:

◆ createCFObject()

static PyObject* createCFObject ( PyObject *  self,
PyObject *  args 
)
static

Definition at line 142 of file cfpython.c.

References make_face_from_files::args, cf_create_object(), Crossfire_Object_wrap(), give::op, and nlohmann::detail::void().

+ Here is the call graph for this function:

◆ createCFObjectByName()

static PyObject* createCFObjectByName ( PyObject *  self,
PyObject *  args 
)
static

Definition at line 152 of file cfpython.c.

References make_face_from_files::args, cf_create_object_by_name(), Crossfire_Object_wrap(), give::op, and nlohmann::detail::void().

+ Here is the call graph for this function:

◆ createMap()

static PyObject* createMap ( PyObject *  self,
PyObject *  args 
)
static

Definition at line 238 of file cfpython.c.

References make_face_from_files::args, cf_get_empty_map(), Crossfire_Map_wrap(), disinfect::map, and nlohmann::detail::void().

+ Here is the call graph for this function:

◆ destroyTimer()

static PyObject* destroyTimer ( PyObject *  self,
PyObject *  args 
)
static

Definition at line 566 of file cfpython.c.

References make_face_from_files::args, cf_timer_destroy(), diamondslots::id, and nlohmann::detail::void().

+ Here is the call graph for this function:

◆ do_script()

static int do_script ( CFPContext context)
static

Definition at line 1036 of file cfpython.c.

References cf_log(), compilePython(), autojail::dict, llevDebug, log_python_error(), pushContext(), and _cfpcontext::script.

Referenced by cfpython_globalEventListener(), eventListener(), and python_command_function().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ eventListener()

CF_PLUGIN int eventListener ( int *  type,
  ... 
)

Handles an object-related event. Doesn't do anything.

Parameters
typeignored.
Returns
0.
Todo:
build from current map's path, probably

Definition at line 1876 of file cfpython.c.

References _cfpcontext::activator, make_face_from_files::args, buf, cf_get_maps_directory(), Crossfire_Object_wrap(), do_script(), animate::event, _cfpcontext::event, _cfpcontext::event_code, freeContext(), _cfpcontext::message, _cfpcontext::options, popContext(), _cfpcontext::returnvalue, _cfpcontext::script, _cfpcontext::talk, _cfpcontext::third, is_valid_types_gen::type, and _cfpcontext::who.

+ Here is the call graph for this function:

◆ findAnimation()

static PyObject* findAnimation ( PyObject *  self,
PyObject *  args 
)
static

Definition at line 630 of file cfpython.c.

References make_face_from_files::args, cf_find_animation(), give::name, and nlohmann::detail::void().

+ Here is the call graph for this function:

◆ findFace()

static PyObject* findFace ( PyObject *  self,
PyObject *  args 
)
static

Definition at line 584 of file cfpython.c.

References make_face_from_files::args, cf_find_face(), give::name, and nlohmann::detail::void().

+ Here is the call graph for this function:

◆ findPlayer()

static PyObject* findPlayer ( PyObject *  self,
PyObject *  args 
)
static

Definition at line 206 of file cfpython.c.

References make_face_from_files::args, cf_player_find(), Crossfire_Object_wrap(), pl::ob, and nlohmann::detail::void().

+ Here is the call graph for this function:

◆ freeContext()

static void freeContext ( CFPContext context)
static

Definition at line 848 of file cfpython.c.

References _cfpcontext::activator, _cfpcontext::event, _cfpcontext::third, and _cfpcontext::who.

Referenced by cfpython_globalEventListener(), eventListener(), and python_command_function().

+ Here is the caller graph for this function:

◆ freeEventFiles()

static void freeEventFiles ( char **  eventFiles)
static

Clear the list of event files.

Parameters
eventFileslist as returned by getEventFiles(), will be invalid after this function call.

Definition at line 1613 of file cfpython.c.

Referenced by cfpython_globalEventListener().

+ Here is the caller graph for this function:

◆ getArchetypes()

static PyObject* getArchetypes ( PyObject *  self,
PyObject *  args 
)
static

◆ getCFPythonVersion()

static PyObject* getCFPythonVersion ( PyObject *  self,
PyObject *  args 
)
static

Definition at line 165 of file cfpython.c.

References make_face_from_files::args, and nlohmann::detail::void().

+ Here is the call graph for this function:

◆ getConfigDirectory()

static PyObject* getConfigDirectory ( PyObject *  self,
PyObject *  args 
)
static

Definition at line 269 of file cfpython.c.

References make_face_from_files::args, cf_get_directory(), and nlohmann::detail::void().

+ Here is the call graph for this function:

◆ getDataDirectory()

static PyObject* getDataDirectory ( PyObject *  self,
PyObject *  args 
)
static

Definition at line 287 of file cfpython.c.

References make_face_from_files::args, cf_get_directory(), and nlohmann::detail::void().

+ Here is the call graph for this function:

◆ getEvent()

static PyObject* getEvent ( PyObject *  self,
PyObject *  args 
)
static

Definition at line 351 of file cfpython.c.

References make_face_from_files::args, current_context, _cfpcontext::event, and nlohmann::detail::void().

+ Here is the call graph for this function:

◆ getEventFiles()

static char** getEventFiles ( CFPContext context)
static

Get the list of script files to run for the specified global event context.

Parameters
contextevent context, must have its options field correctly filled.
Returns
list of event files that must be deleted by calling freeEventFiles().

Definition at line 1626 of file cfpython.c.

References cf_get_maps_directory(), cf_log(), closedir(), replace::current, dirent, llevInfo, give::name, NAME_MAX, opendir(), _cfpcontext::options, python_init::path, readdir(), and nlohmann::detail::void().

Referenced by cfpython_globalEventListener().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getFriendlyList()

static PyObject* getFriendlyList ( PyObject *  self,
PyObject *  args 
)
static

◆ getGlobalEventPath()

static const char* getGlobalEventPath ( int  code)
static

Definition at line 1697 of file cfpython.c.

References GECodes, and GEPaths.

Referenced by cfpython_globalEventListener().

+ Here is the caller graph for this function:

◆ getLocalDirectory()

static PyObject* getLocalDirectory ( PyObject *  self,
PyObject *  args 
)
static

Definition at line 275 of file cfpython.c.

References make_face_from_files::args, cf_get_directory(), and nlohmann::detail::void().

+ Here is the call graph for this function:

◆ getMapDirectory()

static PyObject* getMapDirectory ( PyObject *  self,
PyObject *  args 
)
static

Definition at line 251 of file cfpython.c.

References make_face_from_files::args, cf_get_directory(), and nlohmann::detail::void().

+ Here is the call graph for this function:

◆ getMapHasBeenLoaded()

static PyObject* getMapHasBeenLoaded ( PyObject *  self,
PyObject *  args 
)
static

Definition at line 575 of file cfpython.c.

References make_face_from_files::args, cf_map_has_been_loaded(), Crossfire_Map_wrap(), give::name, and nlohmann::detail::void().

+ Here is the call graph for this function:

◆ getMaps()

static PyObject* getMaps ( PyObject *  self,
PyObject *  args 
)
static

◆ getMonthName()

static PyObject* getMonthName ( PyObject *  self,
PyObject *  args 
)
static

Definition at line 648 of file cfpython.c.

References make_face_from_files::args, cf_get_month_name(), and nlohmann::detail::void().

+ Here is the call graph for this function:

◆ getParties()

static PyObject* getParties ( PyObject *  self,
PyObject *  args 
)
static

Definition at line 429 of file cfpython.c.

References make_face_from_files::args, cf_party_get_first(), cf_party_get_next(), Crossfire_Party_wrap(), guildoracle::list, and nlohmann::detail::void().

+ Here is the call graph for this function:

◆ getPeriodofdayName()

static PyObject* getPeriodofdayName ( PyObject *  self,
PyObject *  args 
)
static

Definition at line 666 of file cfpython.c.

References make_face_from_files::args, cf_get_periodofday_name(), and nlohmann::detail::void().

+ Here is the call graph for this function:

◆ getPlayerDirectory()

static PyObject* getPlayerDirectory ( PyObject *  self,
PyObject *  args 
)
static

Definition at line 281 of file cfpython.c.

References make_face_from_files::args, cf_get_directory(), and nlohmann::detail::void().

+ Here is the call graph for this function:

◆ getPlayers()

static PyObject* getPlayers ( PyObject *  self,
PyObject *  args 
)
static

◆ getPluginProperty()

CF_PLUGIN void* getPluginProperty ( int *  type,
  ... 
)

Gets a plugin property.

Parameters
typeignored.
Returns
  • the name, if asked for 'Identification'.
  • the version, if asked for 'FullName'.
  • NULL else.

Definition at line 1541 of file cfpython.c.

References make_face_from_files::args, buf, PLUGIN_NAME, PLUGIN_VERSION, and is_valid_types_gen::type.

◆ getPrivateDictionary()

static PyObject* getPrivateDictionary ( PyObject *  self,
PyObject *  args 
)
static

Definition at line 362 of file cfpython.c.

References make_face_from_files::args, current_context, navar-midane_time::data, private_data, _cfpcontext::script, and nlohmann::detail::void().

+ Here is the call graph for this function:

◆ getRegions()

static PyObject* getRegions ( PyObject *  self,
PyObject *  args 
)
static

Definition at line 444 of file cfpython.c.

References make_face_from_files::args, cf_region_get_first(), cf_region_get_next(), Crossfire_Region_wrap(), guildoracle::list, and nlohmann::detail::void().

+ Here is the call graph for this function:

◆ getReturnValue()

static PyObject* getReturnValue ( PyObject *  self,
PyObject *  args 
)
static

Definition at line 173 of file cfpython.c.

References make_face_from_files::args, current_context, _cfpcontext::returnvalue, and nlohmann::detail::void().

+ Here is the call graph for this function:

◆ getScriptName()

static PyObject* getScriptName ( PyObject *  self,
PyObject *  args 
)
static

Definition at line 335 of file cfpython.c.

References make_face_from_files::args, current_context, _cfpcontext::script, and nlohmann::detail::void().

+ Here is the call graph for this function:

◆ getScriptParameters()

static PyObject* getScriptParameters ( PyObject *  self,
PyObject *  args 
)
static

Definition at line 341 of file cfpython.c.

References make_face_from_files::args, current_context, _cfpcontext::options, and nlohmann::detail::void().

+ Here is the call graph for this function:

◆ getSeasonName()

static PyObject* getSeasonName ( PyObject *  self,
PyObject *  args 
)
static

Definition at line 639 of file cfpython.c.

References make_face_from_files::args, cf_get_season_name(), and nlohmann::detail::void().

+ Here is the call graph for this function:

◆ getSharedDictionary()

static PyObject* getSharedDictionary ( PyObject *  self,
PyObject *  args 
)
static

Definition at line 377 of file cfpython.c.

References make_face_from_files::args, shared_data, and nlohmann::detail::void().

+ Here is the call graph for this function:

◆ getTempDirectory()

static PyObject* getTempDirectory ( PyObject *  self,
PyObject *  args 
)
static

Definition at line 263 of file cfpython.c.

References make_face_from_files::args, cf_get_directory(), and nlohmann::detail::void().

+ Here is the call graph for this function:

◆ getTime()

static PyObject* getTime ( PyObject *  self,
PyObject *  args 
)
static

◆ getUniqueDirectory()

static PyObject* getUniqueDirectory ( PyObject *  self,
PyObject *  args 
)
static

Definition at line 257 of file cfpython.c.

References make_face_from_files::args, cf_get_directory(), and nlohmann::detail::void().

+ Here is the call graph for this function:

◆ getWeekdayName()

static PyObject* getWeekdayName ( PyObject *  self,
PyObject *  args 
)
static

Definition at line 657 of file cfpython.c.

References make_face_from_files::args, cf_get_weekday_name(), and nlohmann::detail::void().

+ Here is the call graph for this function:

◆ getWhatIsMessage()

static PyObject* getWhatIsMessage ( PyObject *  self,
PyObject *  args 
)
static

Definition at line 326 of file cfpython.c.

References make_face_from_files::args, current_context, _cfpcontext::message, and nlohmann::detail::void().

+ Here is the call graph for this function:

◆ getWhoAmI()

static PyObject* getWhoAmI ( PyObject *  self,
PyObject *  args 
)
static

Definition at line 293 of file cfpython.c.

References make_face_from_files::args, current_context, nlohmann::detail::void(), and _cfpcontext::who.

+ Here is the call graph for this function:

◆ getWhoIsActivator()

static PyObject* getWhoIsActivator ( PyObject *  self,
PyObject *  args 
)
static

Definition at line 304 of file cfpython.c.

References _cfpcontext::activator, make_face_from_files::args, current_context, and nlohmann::detail::void().

+ Here is the call graph for this function:

◆ getWhoIsThird()

static PyObject* getWhoIsThird ( PyObject *  self,
PyObject *  args 
)
static

Definition at line 315 of file cfpython.c.

References make_face_from_files::args, current_context, _cfpcontext::third, and nlohmann::detail::void().

+ Here is the call graph for this function:

◆ initConstants()

static void initConstants ( PyObject *  module)
static

Definition at line 1413 of file cfpython.c.

References addConstants(), addSimpleConstants(), cstAttackMovement, cstAttackType, cstAttackTypeNumber, cstDirection, cstEventType, cstMessageFlag, cstMove, cstReplyTypes, cstTime, and cstType.

Referenced by initPlugin().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ initContextStack()

static void initContextStack ( void  )
static

Definition at line 821 of file cfpython.c.

References context_stack, and current_context.

Referenced by postInitPlugin().

+ Here is the caller graph for this function:

◆ initPlugin()

CF_PLUGIN int initPlugin ( const char *  iversion,
f_plug_api  gethooksptr 
)

Plugin initialisation function.

Parameters
iversionserver version.
gethooksptrfunction to get the hooks.
Returns
0

Main plugin entry point.

Parameters
iversionserver version.
gethooksptrfunction to get hooks from.
Returns
always 0.

Definition at line 1494 of file cfpython.c.

References c, catcher, cf_init_plugin(), cf_log(), cfpython_init_types(), init_map_assoc_table(), init_object_assoc_table(), initConstants(), llevDebug, m, MAX_COMMANDS, private_data, PyInit_cjson(), PyInit_Crossfire(), registered_commands, shared_data, and nlohmann::detail::void().

+ Here is the call graph for this function:

◆ log_message()

static PyObject* log_message ( PyObject *  self,
PyObject *  args 
)
static

Definition at line 593 of file cfpython.c.

References make_face_from_files::args, cf_log(), level, llevDebug, llevError, llevInfo, llevMonster, diamondslots::message, and nlohmann::detail::void().

+ Here is the call graph for this function:

◆ log_python_error()

static void log_python_error ( void  )
static

Trace a Python error to the Crossfire log. This uses code from: http://stackoverflow.com/questions/4307187/how-to-catch-python-stdout-in-c-code See also in initPlugin() the parts about stdOutErr.

Definition at line 897 of file cfpython.c.

References catcher, cf_log_plain(), and llevError.

Referenced by compilePython(), and do_script().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ matchString()

static PyObject* matchString ( PyObject *  self,
PyObject *  args 
)
static

Definition at line 190 of file cfpython.c.

References make_face_from_files::args, cf_re_cmp(), rotate-tower::result, and nlohmann::detail::void().

+ Here is the call graph for this function:

◆ npcSay()

static PyObject* npcSay ( PyObject *  self,
PyObject *  args 
)
static

◆ popContext()

static CFPContext * popContext ( void  )
static

Definition at line 836 of file cfpython.c.

References current_context, and _cfpcontext::down.

Referenced by cfpython_globalEventListener(), eventListener(), and python_command_function().

+ Here is the caller graph for this function:

◆ postInitPlugin()

CF_PLUGIN int postInitPlugin ( void  )

◆ pushContext()

static void pushContext ( CFPContext context)
static

Definition at line 826 of file cfpython.c.

References context_stack, current_context, and _cfpcontext::down.

Referenced by do_script().

+ Here is the caller graph for this function:

◆ PyInit_cjson()

PyObject* PyInit_cjson ( void  )

Definition at line 1185 of file cjson.c.

References cjsonModule, initcjson_shared(), and m.

Referenced by initPlugin().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ PyInit_Crossfire()

static PyObject* PyInit_Crossfire ( void  )
static

Definition at line 1487 of file cfpython.c.

References CrossfireModule, and m.

Referenced by initPlugin().

+ Here is the caller graph for this function:

◆ python_command_function()

static void python_command_function ( object op,
const char *  params,
const char *  script 
)
static

◆ readyMap()

static PyObject* readyMap ( PyObject *  self,
PyObject *  args 
)
static

Definition at line 224 of file cfpython.c.

References make_face_from_files::args, cf_map_get_map(), Crossfire_Map_wrap(), flags, disinfect::map, guild_questpoints_apply::mapname, and nlohmann::detail::void().

+ Here is the call graph for this function:

◆ registerCommand()

static PyObject* registerCommand ( PyObject *  self,
PyObject *  args 
)
static

◆ registerGEvent()

static PyObject* registerGEvent ( PyObject *  self,
PyObject *  args 
)
static

Definition at line 116 of file cfpython.c.

References make_face_from_files::args, cf_system_register_global_event(), cfpython_globalEventListener(), PLUGIN_NAME, and nlohmann::detail::void().

+ Here is the call graph for this function:

◆ set_exception()

static void set_exception ( const char *  fmt,
  ... 
)
static

Set up an Python exception object.

Definition at line 93 of file cfpython.c.

References buf.

Referenced by addReply(), npcSay(), registerCommand(), and setPlayerMessage().

+ Here is the caller graph for this function:

◆ setPlayerMessage()

static PyObject* setPlayerMessage ( PyObject *  self,
PyObject *  args 
)
static

◆ setReturnValue()

static PyObject* setReturnValue ( PyObject *  self,
PyObject *  args 
)
static

Definition at line 179 of file cfpython.c.

References make_face_from_files::args, current_context, _cfpcontext::returnvalue, and nlohmann::detail::void().

+ Here is the call graph for this function:

◆ unregisterGEvent()

static PyObject* unregisterGEvent ( PyObject *  self,
PyObject *  args 
)
static

Definition at line 129 of file cfpython.c.

References make_face_from_files::args, cf_system_unregister_global_event(), EVENT_TELL, PLUGIN_NAME, and nlohmann::detail::void().

+ Here is the call graph for this function:

Variable Documentation

◆ catcher

PyObject* catcher = NULL
static

A Python object receiving the contents of Python's stderr, and used to output to the Crossfire log instead of stderr.

Definition at line 881 of file cfpython.c.

Referenced by initPlugin(), and log_python_error().

◆ CFPythonError

PyObject* CFPythonError
static

Definition at line 90 of file cfpython.c.

Referenced by cfpython_init_types().

◆ CFPythonMethods

PyMethodDef CFPythonMethods[]

Definition at line 769 of file cfpython.c.

Referenced by main().

◆ context_stack

CFPContext* context_stack

Definition at line 104 of file cfpython.c.

Referenced by initContextStack(), and pushContext().

◆ CrossfireModule

PyModuleDef CrossfireModule
static
Initial value:
= {
PyModuleDef_HEAD_INIT,
"Crossfire",
NULL,
-1,
NULL,
NULL,
NULL,
NULL
}

Definition at line 1475 of file cfpython.c.

Referenced by PyInit_Crossfire().

◆ cstAttackMovement

const CFConstant cstAttackMovement[]
Initial value:
= {
{ "DISTATT", DISTATT },
{ "RUNATT", RUNATT },
{ "HITRUN", HITRUN },
{ "WAITATT", WAITATT },
{ "RUSH", RUSH },
{ "ALLRUN", ALLRUN },
{ "DISTHIT", DISTHIT },
{ "WAIT2", WAIT2 },
{ "PETMOVE", PETMOVE },
{ "CIRCLE1", CIRCLE1 },
{ "CIRCLE2", CIRCLE2 },
{ "PACEH", PACEH },
{ "PACEH2", PACEH2 },
{ "RANDO", RANDO },
{ "RANDO2", RANDO2 },
{ "PACEV", PACEV },
{ "PACEV2", PACEV2 },
{ NULL, 0 }
}

Definition at line 1392 of file cfpython.c.

Referenced by initConstants(), and main().

◆ cstAttackType

const CFConstant cstAttackType[]
Initial value:
= {
{ "PHYSICAL", AT_PHYSICAL },
{ "MAGIC", AT_MAGIC },
{ "FIRE", AT_FIRE },
{ "ELECTRICITY", AT_ELECTRICITY },
{ "COLD", AT_COLD },
{ "CONFUSION", AT_CONFUSION },
{ "ACID", AT_ACID },
{ "DRAIN", AT_DRAIN },
{ "WEAPONMAGIC", AT_WEAPONMAGIC },
{ "GHOSTHIT", AT_GHOSTHIT },
{ "POISON", AT_POISON },
{ "SLOW", AT_SLOW },
{ "PARALYZE", AT_PARALYZE },
{ "TURN_UNDEAD", AT_TURN_UNDEAD },
{ "FEAR", AT_FEAR },
{ "CANCELLATION", AT_CANCELLATION },
{ "DEPLETE", AT_DEPLETE },
{ "DEATH", AT_DEATH },
{ "CHAOS", AT_CHAOS },
{ "COUNTERSPELL", AT_COUNTERSPELL },
{ "GODPOWER", AT_GODPOWER },
{ "HOLYWORD", AT_HOLYWORD },
{ "BLIND", AT_BLIND },
{ "INTERNAL", AT_INTERNAL },
{ "LIFE_STEALING", AT_LIFE_STEALING },
{ "DISEASE", AT_DISEASE },
{ NULL, 0 }
}

Definition at line 1273 of file cfpython.c.

Referenced by initConstants(), and main().

◆ cstAttackTypeNumber

const CFConstant cstAttackTypeNumber[]
Initial value:
= {
{ "PHYSICAL", ATNR_PHYSICAL },
{ "MAGIC", ATNR_MAGIC },
{ "FIRE", ATNR_FIRE },
{ "ELECTRICITY", ATNR_ELECTRICITY },
{ "COLD", ATNR_COLD },
{ "CONFUSION", ATNR_CONFUSION },
{ "ACID", ATNR_ACID },
{ "DRAIN", ATNR_DRAIN },
{ "WEAPONMAGIC", ATNR_WEAPONMAGIC },
{ "GHOSTHIT", ATNR_GHOSTHIT },
{ "POISON", ATNR_POISON },
{ "SLOW", ATNR_SLOW },
{ "PARALYZE", ATNR_PARALYZE },
{ "TURN_UNDEAD", ATNR_TURN_UNDEAD },
{ "FEAR", ATNR_FEAR },
{ "CANCELLATION", ATNR_CANCELLATION },
{ "DEPLETE", ATNR_DEPLETE },
{ "DEATH", ATNR_DEATH },
{ "CHAOS", ATNR_CHAOS },
{ "COUNTERSPELL", ATNR_COUNTERSPELL },
{ "GODPOWER", ATNR_GODPOWER },
{ "HOLYWORD", ATNR_HOLYWORD },
{ "BLIND", ATNR_BLIND },
{ "INTERNAL", ATNR_INTERNAL },
{ "LIFE_STEALING", ATNR_LIFE_STEALING },
{ "DISEASE", ATNR_DISEASE },
{ NULL, 0 }
}

Definition at line 1303 of file cfpython.c.

Referenced by initConstants(), and main().

◆ cstDirection

const CFConstant cstDirection[]
Initial value:
= {
{ "NORTH", 1 },
{ "NORTHEAST", 2 },
{ "EAST", 3 },
{ "SOUTHEAST", 4 },
{ "SOUTH", 5 },
{ "SOUTHWEST", 6 },
{ "WEST", 7 },
{ "NORTHWEST", 8 },
{ NULL, 0 }
}

Definition at line 1114 of file cfpython.c.

Referenced by initConstants(), and main().

◆ cstEventType

const CFConstant cstEventType[]

Definition at line 1333 of file cfpython.c.

Referenced by initConstants(), and main().

◆ cstMessageFlag

const CFConstant cstMessageFlag[]
Initial value:
= {
{ "NDI_BLACK", NDI_BLACK },
{ "NDI_WHITE", NDI_WHITE },
{ "NDI_NAVY", NDI_NAVY },
{ "NDI_RED", NDI_RED },
{ "NDI_ORANGE", NDI_ORANGE },
{ "NDI_BLUE", NDI_BLUE },
{ "NDI_DK_ORANGE", NDI_DK_ORANGE },
{ "NDI_GREEN", NDI_GREEN },
{ "NDI_LT_GREEN", NDI_LT_GREEN },
{ "NDI_GREY", NDI_GREY },
{ "NDI_BROWN", NDI_BROWN },
{ "NDI_GOLD", NDI_GOLD },
{ "NDI_TAN", NDI_TAN },
{ "NDI_UNIQUE", NDI_UNIQUE },
{ "NDI_ALL", NDI_ALL },
{ "NDI_ALL_DMS", NDI_ALL_DMS },
{ NULL, 0 }
}

Definition at line 1253 of file cfpython.c.

Referenced by initConstants(), and main().

◆ cstMove

const CFConstant cstMove[]
Initial value:
= {
{ "WALK", MOVE_WALK },
{ "FLY_LOW", MOVE_FLY_LOW },
{ "FLY_HIGH", MOVE_FLY_HIGH },
{ "FLYING", MOVE_FLYING },
{ "SWIM", MOVE_SWIM },
{ "BOAT", MOVE_BOAT },
{ "ALL", MOVE_ALL },
{ NULL, 0 }
}

Definition at line 1242 of file cfpython.c.

Referenced by initConstants(), and main().

◆ cstReplyTypes

const CFConstant cstReplyTypes[]
Initial value:
= {
{ "SAY", rt_say },
{ "REPLY", rt_reply },
{ "QUESTION", rt_question },
{ NULL, 0 }
}

Definition at line 1385 of file cfpython.c.

Referenced by initConstants(), and main().

◆ cstTime

const CFConstant cstTime[]
Initial value:
= {
{ "HOURS_PER_DAY", HOURS_PER_DAY },
{ "DAYS_PER_WEEK", DAYS_PER_WEEK },
{ "WEEKS_PER_MONTH", WEEKS_PER_MONTH },
{ "MONTHS_PER_YEAR", MONTHS_PER_YEAR },
{ "SEASONS_PER_YEAR", SEASONS_PER_YEAR },
{ "PERIODS_PER_DAY", PERIODS_PER_DAY },
{ NULL, 0 }
}

Definition at line 1375 of file cfpython.c.

Referenced by initConstants(), and main().

◆ cstType

const CFConstant cstType[]

Definition at line 1126 of file cfpython.c.

Referenced by initConstants(), and main().

◆ current_context

◆ GECodes

◆ GEPaths

const char* GEPaths[]
static
Initial value:
= {
"born",
"clock",
"death",
"gkill",
"login",
"logout",
"mapenter",
"mapleave",
"mapreset",
"remove",
"shout",
"tell",
"muzzle",
"kick",
"mapunload",
"mapload",
"mapready",
NULL
}

Definition at line 1587 of file cfpython.c.

Referenced by getGlobalEventPath().

◆ private_data

PyObject* private_data = NULL
static

Definition at line 110 of file cfpython.c.

Referenced by getPrivateDictionary(), and initPlugin().

◆ pycode_cache

pycode_cache_entry pycode_cache[PYTHON_CACHE_SIZE]
static

Cached compiled scripts.

Definition at line 88 of file cfpython.c.

Referenced by closePlugin(), compilePython(), and postInitPlugin().

◆ registered_commands

command_registration registered_commands[MAX_COMMANDS]
static

Definition at line 85 of file cfpython.c.

Referenced by closePlugin(), initPlugin(), and registerCommand().

◆ shared_data

PyObject* shared_data = NULL
static

Definition at line 108 of file cfpython.c.

Referenced by getSharedDictionary(), and initPlugin().

◆ SvnRevPlugin

CF_PLUGIN char SvnRevPlugin[] = SVN_REV

Definition at line 69 of file cfpython.c.

ATNR_PARALYZE
#define ATNR_PARALYZE
Definition: attack.h:61
DAYS_PER_WEEK
#define DAYS_PER_WEEK
Definition: tod.h:16
ATNR_CANCELLATION
#define ATNR_CANCELLATION
Definition: attack.h:64
AT_POISON
#define AT_POISON
Definition: attack.h:86
ATNR_INTERNAL
#define ATNR_INTERNAL
Definition: attack.h:72
AT_MAGIC
#define AT_MAGIC
Definition: attack.h:77
WAITATT
#define WAITATT
Definition: define.h:495
MOVE_ALL
#define MOVE_ALL
Definition: define.h:398
ALLRUN
#define ALLRUN
Definition: define.h:497
ATNR_ACID
#define ATNR_ACID
Definition: attack.h:55
RUNATT
#define RUNATT
Definition: define.h:493
AT_ELECTRICITY
#define AT_ELECTRICITY
Definition: attack.h:79
PACEV2
#define PACEV2
Definition: define.h:526
NDI_GREEN
#define NDI_GREEN
Definition: newclient.h:249
AT_PHYSICAL
#define AT_PHYSICAL
Definition: attack.h:76
HITRUN
#define HITRUN
Definition: define.h:494
HOURS_PER_DAY
#define HOURS_PER_DAY
Definition: tod.h:15
ATNR_SLOW
#define ATNR_SLOW
Definition: attack.h:60
ATNR_GODPOWER
#define ATNR_GODPOWER
Definition: attack.h:69
EVENT_MAPLOAD
#define EVENT_MAPLOAD
Definition: events.h:47
NDI_ALL_DMS
#define NDI_ALL_DMS
Definition: newclient.h:264
ATNR_DISEASE
#define ATNR_DISEASE
Definition: attack.h:74
AT_INTERNAL
#define AT_INTERNAL
Definition: attack.h:99
NDI_RED
#define NDI_RED
Definition: newclient.h:245
EVENT_LOGOUT
#define EVENT_LOGOUT
Definition: events.h:44
NDI_NAVY
#define NDI_NAVY
Definition: newclient.h:244
RANDO
#define RANDO
Definition: define.h:520
ATNR_PHYSICAL
#define ATNR_PHYSICAL
Definition: attack.h:49
ATNR_TURN_UNDEAD
#define ATNR_TURN_UNDEAD
Definition: attack.h:62
NDI_BLUE
#define NDI_BLUE
Definition: newclient.h:247
WEEKS_PER_MONTH
#define WEEKS_PER_MONTH
Definition: tod.h:17
AT_LIFE_STEALING
#define AT_LIFE_STEALING
Definition: attack.h:100
PACEH
#define PACEH
Definition: define.h:514
AT_DEATH
#define AT_DEATH
Definition: attack.h:93
ATNR_CONFUSION
#define ATNR_CONFUSION
Definition: attack.h:54
ATNR_HOLYWORD
#define ATNR_HOLYWORD
Definition: attack.h:70
NDI_ORANGE
#define NDI_ORANGE
Definition: newclient.h:246
ATNR_BLIND
#define ATNR_BLIND
Definition: attack.h:71
AT_CHAOS
#define AT_CHAOS
Definition: attack.h:94
EVENT_LOGIN
#define EVENT_LOGIN
Definition: events.h:43
EVENT_CLOCK
#define EVENT_CLOCK
Definition: events.h:39
AT_COLD
#define AT_COLD
Definition: attack.h:80
SEASONS_PER_YEAR
#define SEASONS_PER_YEAR
Definition: tod.h:19
MOVE_WALK
#define MOVE_WALK
Definition: define.h:392
EVENT_MAPENTER
#define EVENT_MAPENTER
Definition: events.h:45
EVENT_MAPRESET
#define EVENT_MAPRESET
Definition: events.h:49
MOVE_FLYING
#define MOVE_FLYING
Definition: define.h:395
CIRCLE2
#define CIRCLE2
Definition: define.h:513
EVENT_BORN
#define EVENT_BORN
Definition: events.h:38
EVENT_MAPUNLOAD
#define EVENT_MAPUNLOAD
Definition: events.h:50
ATNR_DRAIN
#define ATNR_DRAIN
Definition: attack.h:56
NDI_GOLD
#define NDI_GOLD
Definition: newclient.h:254
rt_say
@ rt_say
Definition: dialog.h:10
ATNR_COUNTERSPELL
#define ATNR_COUNTERSPELL
Definition: attack.h:68
ATNR_POISON
#define ATNR_POISON
Definition: attack.h:59
ATNR_DEATH
#define ATNR_DEATH
Definition: attack.h:66
rt_reply
@ rt_reply
Definition: dialog.h:11
PACEV
#define PACEV
Definition: define.h:524
EVENT_SHOUT
#define EVENT_SHOUT
Definition: events.h:54
NDI_BLACK
#define NDI_BLACK
Definition: newclient.h:242
MOVE_FLY_LOW
#define MOVE_FLY_LOW
Definition: define.h:393
EVENT_PLAYER_DEATH
#define EVENT_PLAYER_DEATH
Definition: events.h:52
ATNR_FIRE
#define ATNR_FIRE
Definition: attack.h:51
MONTHS_PER_YEAR
#define MONTHS_PER_YEAR
Definition: tod.h:18
NDI_UNIQUE
#define NDI_UNIQUE
Definition: newclient.h:262
EVENT_MUZZLE
#define EVENT_MUZZLE
Definition: events.h:51
AT_BLIND
#define AT_BLIND
Definition: attack.h:98
EVENT_TELL
#define EVENT_TELL
Definition: events.h:55
ATNR_CHAOS
#define ATNR_CHAOS
Definition: attack.h:67
AT_SLOW
#define AT_SLOW
Definition: attack.h:87
AT_TURN_UNDEAD
#define AT_TURN_UNDEAD
Definition: attack.h:89
ATNR_DEPLETE
#define ATNR_DEPLETE
Definition: attack.h:65
rt_question
@ rt_question
Definition: dialog.h:12
PERIODS_PER_DAY
#define PERIODS_PER_DAY
Definition: tod.h:20
NDI_ALL
#define NDI_ALL
Definition: newclient.h:263
AT_DEPLETE
#define AT_DEPLETE
Definition: attack.h:92
EVENT_MAPLEAVE
#define EVENT_MAPLEAVE
Definition: events.h:46
AT_WEAPONMAGIC
#define AT_WEAPONMAGIC
Definition: attack.h:84
ATNR_MAGIC
#define ATNR_MAGIC
Definition: attack.h:50
NDI_WHITE
#define NDI_WHITE
Definition: newclient.h:243
NDI_BROWN
#define NDI_BROWN
Definition: newclient.h:253
NDI_TAN
#define NDI_TAN
Definition: newclient.h:255
EVENT_REMOVE
#define EVENT_REMOVE
Definition: events.h:53
NDI_DK_ORANGE
#define NDI_DK_ORANGE
Definition: newclient.h:248
ATNR_WEAPONMAGIC
#define ATNR_WEAPONMAGIC
Definition: attack.h:57
AT_COUNTERSPELL
#define AT_COUNTERSPELL
Definition: attack.h:95
AT_DISEASE
#define AT_DISEASE
Definition: attack.h:102
AT_ACID
#define AT_ACID
Definition: attack.h:82
AT_FEAR
#define AT_FEAR
Definition: attack.h:90
AT_GODPOWER
#define AT_GODPOWER
Definition: attack.h:96
MOVE_BOAT
#define MOVE_BOAT
Definition: define.h:397
MOVE_FLY_HIGH
#define MOVE_FLY_HIGH
Definition: define.h:394
EVENT_MAPREADY
#define EVENT_MAPREADY
Definition: events.h:48
AT_CONFUSION
#define AT_CONFUSION
Definition: attack.h:81
WAIT2
#define WAIT2
Definition: define.h:499
ATNR_GHOSTHIT
#define ATNR_GHOSTHIT
Definition: attack.h:58
ATNR_COLD
#define ATNR_COLD
Definition: attack.h:53
AT_CANCELLATION
#define AT_CANCELLATION
Definition: attack.h:91
CFPythonMethods
PyMethodDef CFPythonMethods[]
Definition: cfpython.c:769
DISTHIT
#define DISTHIT
Definition: define.h:498
RUSH
#define RUSH
Definition: define.h:496
PETMOVE
#define PETMOVE
Definition: define.h:501
MOVE_SWIM
#define MOVE_SWIM
Definition: define.h:396
DISTATT
#define DISTATT
Definition: define.h:491
AT_PARALYZE
#define AT_PARALYZE
Definition: attack.h:88
ATNR_ELECTRICITY
#define ATNR_ELECTRICITY
Definition: attack.h:52
AT_HOLYWORD
#define AT_HOLYWORD
Definition: attack.h:97
AT_GHOSTHIT
#define AT_GHOSTHIT
Definition: attack.h:85
EVENT_GKILL
#define EVENT_GKILL
Definition: events.h:41
CIRCLE1
#define CIRCLE1
Definition: define.h:509
ATNR_LIFE_STEALING
#define ATNR_LIFE_STEALING
Definition: attack.h:73
PACEH2
#define PACEH2
Definition: define.h:516
NDI_GREY
#define NDI_GREY
Definition: newclient.h:252
EVENT_KICK
#define EVENT_KICK
Definition: events.h:42
AT_DRAIN
#define AT_DRAIN
Definition: attack.h:83
NDI_LT_GREEN
#define NDI_LT_GREEN
Definition: newclient.h:250
RANDO2
#define RANDO2
Definition: define.h:523
ATNR_FEAR
#define ATNR_FEAR
Definition: attack.h:63
AT_FIRE
#define AT_FIRE
Definition: attack.h:78