Crossfire Server, Trunk  1.75.0
cfpython.cpp
Go to the documentation of this file.
1 /*****************************************************************************/
2 /* CFPython - A Python module for Crossfire RPG. */
3 /*****************************************************************************/
4 /* This is the third version of the Crossfire Scripting Engine. */
5 /* The first version used Guile. It was directly integrated in the server */
6 /* code, but since Guile wasn't perceived as an easy-to-learn, easy-to-use */
7 /* language by many, it was dropped in favor of Python. */
8 /* The second version, CFPython 1.0, was included as a plugin and provided */
9 /* just about the same level of functionality the current version has. But */
10 /* it used a rather counter-intuitive, procedural way of presenting things. */
11 /* */
12 /* CFPython 2.0 aims at correcting many of the design flaws crippling the */
13 /* older version. It is also the first plugin to be implemented using the */
14 /* new interface, that doesn't need awkward stuff like the horrible CFParm */
15 /* structure. For the Python writer, things should probably be easier and */
16 /* lead to more readable code: instead of writing "CFPython.getObjectXPos(ob)*/
17 /* he/she now can simply write "ob.X". */
18 /* */
19 /*****************************************************************************/
20 /* Please note that it is still very beta - some of the functions may not */
21 /* work as expected and could even cause the server to crash. */
22 /*****************************************************************************/
23 /* Version history: */
24 /* 0.1 "Ophiuchus" - Initial Alpha release */
25 /* 0.5 "Stalingrad" - Message length overflow corrected. */
26 /* 0.6 "Kharkov" - Message and Write correctly redefined. */
27 /* 0.7 "Koursk" - Setting informations implemented. */
28 /* 1.0a "Petersburg" - Last "old-fashioned" version, never submitted to CVS.*/
29 /* 2.0 "Arkangelsk" - First release of the 2.x series. */
30 /*****************************************************************************/
31 /* Version: 2.0beta8 (also known as "Alexander") */
32 /* Contact: yann.chachkoff@myrealbox.com */
33 /*****************************************************************************/
34 /* That code is placed under the GNU General Public Licence (GPL) */
35 /* (C)2001-2005 by Chachkoff Yann (Feel free to deliver your complaints) */
36 /*****************************************************************************/
37 /* CrossFire, A Multiplayer game for X-windows */
38 /* */
39 /* Copyright (C) 2000 Mark Wedel */
40 /* Copyright (C) 1992 Frank Tore Johansen */
41 /* */
42 /* This program is free software; you can redistribute it and/or modify */
43 /* it under the terms of the GNU General Public License as published by */
44 /* the Free Software Foundation; either version 2 of the License, or */
45 /* (at your option) any later version. */
46 /* */
47 /* This program is distributed in the hope that it will be useful, */
48 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
49 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
50 /* GNU General Public License for more details. */
51 /* */
52 /* You should have received a copy of the GNU General Public License */
53 /* along with this program; if not, write to the Free Software */
54 /* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
55 /* */
56 /*****************************************************************************/
57 
58 /* First let's include the header file needed */
59 
60 #include <cfpython.h>
61 #include <fcntl.h>
62 #include <stdarg.h>
63 // node.h is deprecated in python 3.9, and removed in 3.10 due to a new parser for Python.
64 #ifndef IS_PY3K10
65 #include <node.h>
66 #endif
67 #include <svnversion.h>
68 
70 
71 //#define PYTHON_DEBUG /**< Give us some general infos out. */
72 #define PYTHON_CACHE_SIZE 256
77 struct pycode_cache_entry {
79  PyCodeObject *code;
80  time_t cached_time,
82 };
83 
84 #define MAX_COMMANDS 1024
86 
89 
90 static PyObject *CFPythonError;
91 
93 static void set_exception(const char *fmt, ...) {
94  char buf[1024];
95  va_list arg;
96 
97  va_start(arg, fmt);
98  vsnprintf(buf, sizeof(buf), fmt, arg);
99  va_end(arg);
100 
101  PyErr_SetString(PyExc_ValueError, buf);
102 }
103 
105 
107 
108 static PyObject *shared_data = NULL;
109 
110 static PyObject *private_data = NULL;
111 
112 static CFPContext *popContext(void);
113 static void freeContext(CFPContext *context);
114 static int do_script(CFPContext *context);
115 
116 static PyObject *registerGEvent(PyObject *self, PyObject *args) {
117  int eventcode;
118  (void)self;
119 
120  if (!PyArg_ParseTuple(args, "i", &eventcode))
121  return NULL;
122 
124 
125  Py_INCREF(Py_None);
126  return Py_None;
127 }
128 
129 static PyObject *unregisterGEvent(PyObject *self, PyObject *args) {
130  int eventcode;
131  (void)self;
132 
133  if (!PyArg_ParseTuple(args, "i", &eventcode))
134  return NULL;
135 
137 
138  Py_INCREF(Py_None);
139  return Py_None;
140 }
141 
142 static PyObject *createCFObject(PyObject *self, PyObject *args) {
143  object *op;
144  (void)self;
145  (void)args;
146 
147  op = cf_create_object();
148 
149  return Crossfire_Object_wrap(op);
150 }
151 
152 static PyObject *createCFObjectByName(PyObject *self, PyObject *args) {
153  char *obname;
154  object *op;
155  (void)self;
156 
157  if (!PyArg_ParseTuple(args, "s", &obname))
158  return NULL;
159 
160  op = cf_create_object_by_name(obname);
161 
162  return Crossfire_Object_wrap(op);
163 }
164 
165 static PyObject *getCFPythonVersion(PyObject *self, PyObject *args) {
166  int i = 2044;
167  (void)self;
168  (void)args;
169 
170  return Py_BuildValue("i", i);
171 }
172 
173 static PyObject *getReturnValue(PyObject *self, PyObject *args) {
174  (void)self;
175  (void)args;
176  return Py_BuildValue("i", current_context->returnvalue);
177 }
178 
179 static PyObject *setReturnValue(PyObject *self, PyObject *args) {
180  int i;
181  (void)self;
182 
183  if (!PyArg_ParseTuple(args, "i", &i))
184  return NULL;
186  Py_INCREF(Py_None);
187  return Py_None;
188 }
189 
190 static PyObject *matchString(PyObject *self, PyObject *args) {
191  char *premiere;
192  char *seconde;
193  const char *result;
194  (void)self;
195 
196  if (!PyArg_ParseTuple(args, "ss", &premiere, &seconde))
197  return NULL;
198 
199  result = cf_re_cmp(premiere, seconde);
200  if (result != NULL)
201  return Py_BuildValue("i", 1);
202  else
203  return Py_BuildValue("i", 0);
204 }
205 
206 static PyObject *findPlayer(PyObject *self, PyObject *args) {
207  player *foundpl;
208  char *txt;
209  (void)self;
210 
211  if (!PyArg_ParseTuple(args, "s", &txt))
212  return NULL;
213 
214  foundpl = cf_player_find(txt);
215 
216  if (foundpl != NULL)
217  return Py_BuildValue("O", Crossfire_Object_wrap(foundpl->ob));
218  else {
219  Py_INCREF(Py_None);
220  return Py_None;
221  }
222 }
223 
224 static PyObject *readyMap(PyObject *self, PyObject *args) {
225  char *mapname;
226  mapstruct *map;
227  int flags = 0;
228  (void)self;
229 
230  if (!PyArg_ParseTuple(args, "s|i", &mapname, &flags))
231  return NULL;
232 
233  map = cf_map_get_map(mapname, flags);
234 
235  return Crossfire_Map_wrap(map);
236 }
237 
238 static PyObject *createMap(PyObject *self, PyObject *args) {
239  int sizex, sizey;
240  mapstruct *map;
241  (void)self;
242 
243  if (!PyArg_ParseTuple(args, "ii", &sizex, &sizey))
244  return NULL;
245 
246  map = cf_get_empty_map(sizex, sizey);
247 
248  return Crossfire_Map_wrap(map);
249 }
250 
251 static PyObject *getMapDirectory(PyObject *self, PyObject *args) {
252  (void)self;
253  (void)args;
254  return Py_BuildValue("s", cf_get_directory(0));
255 }
256 
257 static PyObject *getUniqueDirectory(PyObject *self, PyObject *args) {
258  (void)self;
259  (void)args;
260  return Py_BuildValue("s", cf_get_directory(1));
261 }
262 
263 static PyObject *getTempDirectory(PyObject *self, PyObject *args) {
264  (void)self;
265  (void)args;
266  return Py_BuildValue("s", cf_get_directory(2));
267 }
268 
269 static PyObject *getConfigDirectory(PyObject *self, PyObject *args) {
270  (void)self;
271  (void)args;
272  return Py_BuildValue("s", cf_get_directory(3));
273 }
274 
275 static PyObject *getLocalDirectory(PyObject *self, PyObject *args) {
276  (void)self;
277  (void)args;
278  return Py_BuildValue("s", cf_get_directory(4));
279 }
280 
281 static PyObject *getPlayerDirectory(PyObject *self, PyObject *args) {
282  (void)self;
283  (void)args;
284  return Py_BuildValue("s", cf_get_directory(5));
285 }
286 
287 static PyObject *getDataDirectory(PyObject *self, PyObject *args) {
288  (void)self;
289  (void)args;
290  return Py_BuildValue("s", cf_get_directory(6));
291 }
292 
293 static PyObject *getWhoAmI(PyObject *self, PyObject *args) {
294  (void)self;
295  (void)args;
296  if (!current_context->who) {
297  Py_INCREF(Py_None);
298  return Py_None;
299  }
300  Py_INCREF(current_context->who);
301  return current_context->who;
302 }
303 
304 static PyObject *getWhoIsActivator(PyObject *self, PyObject *args) {
305  (void)self;
306  (void)args;
307  if (!current_context->activator) {
308  Py_INCREF(Py_None);
309  return Py_None;
310  }
311  Py_INCREF(current_context->activator);
312  return current_context->activator;
313 }
314 
315 static PyObject *getWhoIsThird(PyObject *self, PyObject *args) {
316  (void)self;
317  (void)args;
318  if (!current_context->third) {
319  Py_INCREF(Py_None);
320  return Py_None;
321  }
322  Py_INCREF(current_context->third);
323  return current_context->third;
324 }
325 
326 static PyObject *getWhatIsMessage(PyObject *self, PyObject *args) {
327  (void)self;
328  (void)args;
329  if (*current_context->message == '\0')
330  return Py_BuildValue("");
331  else
332  return Py_BuildValue("s", current_context->message);
333 }
334 
335 static PyObject *getScriptName(PyObject *self, PyObject *args) {
336  (void)self;
337  (void)args;
338  return Py_BuildValue("s", current_context->script);
339 }
340 
341 static PyObject *getScriptParameters(PyObject *self, PyObject *args) {
342  (void)self;
343  (void)args;
344  if (!*current_context->options) {
345  Py_INCREF(Py_None);
346  return Py_None;
347  }
348  return Py_BuildValue("s", current_context->options);
349 }
350 
351 static PyObject *getEvent(PyObject *self, PyObject *args) {
352  (void)self;
353  (void)args;
354  if (!current_context->event) {
355  Py_INCREF(Py_None);
356  return Py_None;
357  }
358  Py_INCREF(current_context->event);
359  return current_context->event;
360 }
361 
362 static PyObject *getPrivateDictionary(PyObject *self, PyObject *args) {
363  PyObject *data;
364  (void)self;
365  (void)args;
366 
367  data = PyDict_GetItemString(private_data, current_context->script);
368  if (!data) {
369  data = PyDict_New();
370  PyDict_SetItemString(private_data, current_context->script, data);
371  Py_DECREF(data);
372  }
373  Py_INCREF(data);
374  return data;
375 }
376 
377 static PyObject *getSharedDictionary(PyObject *self, PyObject *args) {
378  (void)self;
379  (void)args;
380  Py_INCREF(shared_data);
381  return shared_data;
382 }
383 
384 static PyObject *getArchetypes(PyObject *self, PyObject *args) {
385  PyObject *list;
386  std::vector<archetype *> archs;
387  (void)self;
388  (void)args;
389 
391  list = PyList_New(0);
392  for (auto arch : archs) {
393  PyList_Append(list, Crossfire_Archetype_wrap(arch));
394  }
395  return list;
396 }
397 
398 static PyObject *getPlayers(PyObject *self, PyObject *args) {
399  PyObject *list;
400  std::vector<object *> players;
401  (void)self;
402  (void)args;
403 
405 
406  list = PyList_New(0);
407  for (auto pl : players) {
408  PyList_Append(list, Crossfire_Object_wrap(pl));
409  }
410  return list;
411 }
412 
413 static PyObject *getMaps(PyObject *self, PyObject *args) {
414  PyObject *list;
415  std::vector<mapstruct *> maps;
416  (void)self;
417  (void)args;
418 
420 
421  list = PyList_New(0);
422  for (auto map : maps) {
423  PyList_Append(list, Crossfire_Map_wrap(map));
424  }
425  return list;
426 }
427 
428 static PyObject *getParties(PyObject *self, PyObject *args) {
429  PyObject *list;
430  std::vector<partylist *> parties;
431  (void)self;
432  (void)args;
433 
435  list = PyList_New(0);
436  for (auto party : parties) {
437  PyList_Append(list, Crossfire_Party_wrap(party));
438  }
439  return list;
440 }
441 
442 static PyObject *getRegions(PyObject *self, PyObject *args) {
443  PyObject *list;
444  std::vector<region *> regions;
445  (void)self;
446  (void)args;
447 
449  list = PyList_New(0);
450  for (auto reg : regions) {
451  PyList_Append(list, Crossfire_Region_wrap(reg));
452  }
453  return list;
454 }
455 
456 static PyObject *getFriendlyList(PyObject *self, PyObject *args) {
457  PyObject *list;
458  std::vector<object *> friends;
459  (void)self;
460  (void)args;
461 
463  list = PyList_New(0);
464  for (auto ob : friends) {
465  PyList_Append(list, Crossfire_Object_wrap(ob));
466  }
467  return list;
468 }
469 
470 static void python_command_function(object *op, const char *params, const char *script) {
471  char buf[1024], path[1024];
472  CFPContext *context;
473 
474  snprintf(buf, sizeof(buf), "%s.py", cf_get_maps_directory(script, path, sizeof(path)));
475 
476  context = static_cast<CFPContext *>(malloc(sizeof(CFPContext)));
477  context->message[0] = 0;
478 
479  context->who = Crossfire_Object_wrap(op);
480  context->activator = NULL;
481  context->third = NULL;
482  /* We are not running from an event, so set it to NULL to avoid segfaults. */
483  context->event = NULL;
484  snprintf(context->script, sizeof(context->script), "%s", buf);
485  if (params)
486  snprintf(context->options, sizeof(context->options), "%s", params);
487  else
488  context->options[0] = 0;
489  context->returnvalue = 1; /* Default is "command successful" */
490 
491  if (!do_script(context)) {
492  freeContext(context);
493  return;
494  }
495 
496  context = popContext();
497  freeContext(context);
498 }
499 
500 static PyObject *registerCommand(PyObject *self, PyObject *args) {
501  char *cmdname;
502  char *scriptname;
503  double cmdspeed;
504  int type = COMMAND_TYPE_NORMAL, index;
505  (void)self;
506 
507  if (!PyArg_ParseTuple(args, "ssd|i", &cmdname, &scriptname, &cmdspeed, &type))
508  return NULL;
509 
510  if (cmdspeed < 0) {
511  set_exception("speed must not be negative");
512  return NULL;
513  }
514 
515  if (type < 0 || type > COMMAND_TYPE_WIZARD) {
516  set_exception("type must be between 0 and 2");
517  return NULL;
518  }
519 
520  for (index = 0; index < MAX_COMMANDS; index++) {
521  if (registered_commands[index] == 0) {
522  break;
523  }
524  }
525  if (index == MAX_COMMANDS) {
526  set_exception("too many registered commands");
527  return NULL;
528  }
529 
530  registered_commands[index] = cf_system_register_command_extra(cmdname, scriptname, python_command_function, type, cmdspeed);
531  if (registered_commands[index] == 0) {
532  set_exception("failed to register command (overriding an existing one with a different type?)");
533  return NULL;
534  }
535 
536  Py_INCREF(Py_None);
537  return Py_None;
538 }
539 
540 static PyObject *getTime(PyObject *self, PyObject *args) {
541  PyObject *list;
542  timeofday_t tod;
543  (void)self;
544  (void)args;
545 
546  cf_get_time(&tod);
547 
548  list = PyList_New(0);
549  PyList_Append(list, Py_BuildValue("i", tod.year));
550  PyList_Append(list, Py_BuildValue("i", tod.month));
551  PyList_Append(list, Py_BuildValue("i", tod.day));
552  PyList_Append(list, Py_BuildValue("i", tod.hour));
553  PyList_Append(list, Py_BuildValue("i", tod.minute));
554  PyList_Append(list, Py_BuildValue("i", tod.dayofweek));
555  PyList_Append(list, Py_BuildValue("i", tod.weekofmonth));
556  PyList_Append(list, Py_BuildValue("i", tod.season));
557  PyList_Append(list, Py_BuildValue("i", tod.periodofday));
558 
559  return list;
560 }
561 
562 static PyObject *destroyTimer(PyObject *self, PyObject *args) {
563  int id;
564  (void)self;
565 
566  if (!PyArg_ParseTuple(args, "i", &id))
567  return NULL;
568  return Py_BuildValue("i", cf_timer_destroy(id));
569 }
570 
571 static PyObject *getMapHasBeenLoaded(PyObject *self, PyObject *args) {
572  char *name;
573  (void)self;
574 
575  if (!PyArg_ParseTuple(args, "s", &name))
576  return NULL;
578 }
579 
580 static PyObject *findFace(PyObject *self, PyObject *args) {
581  char *name;
582  (void)self;
583 
584  if (!PyArg_ParseTuple(args, "s", &name))
585  return NULL;
586  return Py_BuildValue("i", cf_find_face(name, 0));
587 }
588 
589 static PyObject *log_message(PyObject *self, PyObject *args) {
590  LogLevel level;
591  int intLevel;
592  char *message;
593  (void)self;
594 
595  if (!PyArg_ParseTuple(args, "is", &intLevel, &message))
596  return NULL;
597 
598  switch (intLevel) {
599  case llevError:
600  level = llevError;
601  break;
602 
603  case llevInfo:
604  level = llevInfo;
605  break;
606 
607  case llevDebug:
608  level = llevDebug;
609  break;
610 
611  case llevMonster:
612  level = llevMonster;
613  break;
614 
615  default:
616  return NULL;
617  }
618  if ((message != NULL) && (message[strlen(message)] == '\n'))
619  cf_log(level, "CFPython: %s", message);
620  else
621  cf_log(level, "CFPython: %s\n", message);
622  Py_INCREF(Py_None);
623  return Py_None;
624 }
625 
626 static PyObject *findAnimation(PyObject *self, PyObject *args) {
627  char *name;
628  (void)self;
629 
630  if (!PyArg_ParseTuple(args, "s", &name))
631  return NULL;
632  return Py_BuildValue("i", cf_find_animation(name));
633 }
634 
635 static PyObject *getSeasonName(PyObject *self, PyObject *args) {
636  int i;
637  (void)self;
638 
639  if (!PyArg_ParseTuple(args, "i", &i))
640  return NULL;
641  return Py_BuildValue("s", cf_get_season_name(i));
642 }
643 
644 static PyObject *getMonthName(PyObject *self, PyObject *args) {
645  int i;
646  (void)self;
647 
648  if (!PyArg_ParseTuple(args, "i", &i))
649  return NULL;
650  return Py_BuildValue("s", cf_get_month_name(i));
651 }
652 
653 static PyObject *getWeekdayName(PyObject *self, PyObject *args) {
654  int i;
655  (void)self;
656 
657  if (!PyArg_ParseTuple(args, "i", &i))
658  return NULL;
659  return Py_BuildValue("s", cf_get_weekday_name(i));
660 }
661 
662 static PyObject *getPeriodofdayName(PyObject *self, PyObject *args) {
663  int i;
664  (void)self;
665 
666  if (!PyArg_ParseTuple(args, "i", &i))
667  return NULL;
668  return Py_BuildValue("s", cf_get_periodofday_name(i));
669 }
670 
671 static PyObject *addReply(PyObject *self, PyObject *args) {
672  char *word, *reply;
673  talk_info *talk;
674  (void)self;
675 
676  if (current_context->talk == NULL) {
677  set_exception("not in a dialog context");
678  return NULL;
679  }
680  talk = current_context->talk;
681 
682  if (!PyArg_ParseTuple(args, "ss", &word, &reply)) {
683  return NULL;
684  }
685 
686  if (talk->replies_count == MAX_REPLIES) {
687  set_exception("too many replies");
688  return NULL;
689  }
690 
691  talk->replies_words[talk->replies_count] = cf_add_string(word);
692  talk->replies[talk->replies_count] = cf_add_string(reply);
693  talk->replies_count++;
694  Py_INCREF(Py_None);
695  return Py_None;
696 
697 }
698 
699 static PyObject *setPlayerMessage(PyObject *self, PyObject *args) {
700  char *message;
701  int type = rt_reply;
702  (void)self;
703 
704  if (current_context->talk == NULL) {
705  set_exception("not in a dialog context");
706  return NULL;
707  }
708 
709  if (!PyArg_ParseTuple(args, "s|i", &message, &type)) {
710  return NULL;
711  }
712 
713  if (current_context->talk->message != NULL)
716  current_context->talk->message_type = static_cast<reply_type>(type);
717 
718  Py_INCREF(Py_None);
719  return Py_None;
720 }
721 
722 static PyObject *npcSay(PyObject *self, PyObject *args) {
723  Crossfire_Object *npc = NULL;
724  char *message, buf[2048];
725  (void)self;
726 
727  if (!PyArg_ParseTuple(args, "O!s", &Crossfire_ObjectType, &npc, &message))
728  return NULL;
729 
730  if (current_context->talk == NULL) {
731  set_exception("not in a dialog context");
732  return NULL;
733  }
734 
736  set_exception("too many NPCs");
737  return NULL;
738  }
739 
740  if (strlen(message) >= sizeof(buf) - 1)
741  cf_log(llevError, "CFPython: warning, too long message in npcSay, will be truncated");
743  snprintf(buf, sizeof(buf), "%s says: %s", npc->obj->name, message);
744 
747 
748  Py_INCREF(Py_None);
749  return Py_None;
750 }
751 
752 static PyObject *costStringFromValue(PyObject *self, PyObject *args) {
753  uint64_t value;
754  char buf[2048];
755  int largest_coin = 0;
756  (void)self;
757 
758  if (!PyArg_ParseTuple(args, "L|i", &value, &largest_coin))
759  return NULL;
760 
761  cf_cost_string_from_value(value, largest_coin, buf, sizeof(buf));
762  return Py_BuildValue("s", buf);
763 }
764 
765 PyMethodDef CFPythonMethods[] = {
766  { "WhoAmI", getWhoAmI, METH_NOARGS, NULL },
767  { "WhoIsActivator", getWhoIsActivator, METH_NOARGS, NULL },
768  { "WhoIsOther", getWhoIsThird, METH_NOARGS, NULL },
769  { "WhatIsMessage", getWhatIsMessage, METH_NOARGS, NULL },
770  { "ScriptName", getScriptName, METH_NOARGS, NULL },
771  { "ScriptParameters", getScriptParameters, METH_NOARGS, NULL },
772  { "WhatIsEvent", getEvent, METH_NOARGS, NULL },
773  { "MapDirectory", getMapDirectory, METH_NOARGS, NULL },
774  { "UniqueDirectory", getUniqueDirectory, METH_NOARGS, NULL },
775  { "TempDirectory", getTempDirectory, METH_NOARGS, NULL },
776  { "ConfigDirectory", getConfigDirectory, METH_NOARGS, NULL },
777  { "LocalDirectory", getLocalDirectory, METH_NOARGS, NULL },
778  { "PlayerDirectory", getPlayerDirectory, METH_NOARGS, NULL },
779  { "DataDirectory", getDataDirectory, METH_NOARGS, NULL },
780  { "ReadyMap", readyMap, METH_VARARGS, NULL },
781  { "CreateMap", createMap, METH_VARARGS, NULL },
782  { "FindPlayer", findPlayer, METH_VARARGS, NULL },
783  { "MatchString", matchString, METH_VARARGS, NULL },
784  { "GetReturnValue", getReturnValue, METH_NOARGS, NULL },
785  { "SetReturnValue", setReturnValue, METH_VARARGS, NULL },
786  { "PluginVersion", getCFPythonVersion, METH_NOARGS, NULL },
787  { "CreateObject", createCFObject, METH_NOARGS, NULL },
788  { "CreateObjectByName", createCFObjectByName, METH_VARARGS, NULL },
789  { "GetPrivateDictionary", getPrivateDictionary, METH_NOARGS, NULL },
790  { "GetSharedDictionary", getSharedDictionary, METH_NOARGS, NULL },
791  { "GetPlayers", getPlayers, METH_NOARGS, NULL },
792  { "GetArchetypes", getArchetypes, METH_NOARGS, NULL },
793  { "GetMaps", getMaps, METH_NOARGS, NULL },
794  { "GetParties", getParties, METH_NOARGS, NULL },
795  { "GetRegions", getRegions, METH_NOARGS, NULL },
796  { "GetFriendlyList", getFriendlyList, METH_NOARGS, NULL },
797  { "RegisterCommand", registerCommand, METH_VARARGS, NULL },
798  { "RegisterGlobalEvent", registerGEvent, METH_VARARGS, NULL },
799  { "UnregisterGlobalEvent", unregisterGEvent, METH_VARARGS, NULL },
800  { "GetTime", getTime, METH_NOARGS, NULL },
801  { "DestroyTimer", destroyTimer, METH_VARARGS, NULL },
802  { "MapHasBeenLoaded", getMapHasBeenLoaded, METH_VARARGS, NULL },
803  { "Log", log_message, METH_VARARGS, NULL },
804  { "FindFace", findFace, METH_VARARGS, NULL },
805  { "FindAnimation", findAnimation, METH_VARARGS, NULL },
806  { "GetSeasonName", getSeasonName, METH_VARARGS, NULL },
807  { "GetMonthName", getMonthName, METH_VARARGS, NULL },
808  { "GetWeekdayName", getWeekdayName, METH_VARARGS, NULL },
809  { "GetPeriodofdayName", getPeriodofdayName, METH_VARARGS, NULL },
810  { "AddReply", addReply, METH_VARARGS, NULL },
811  { "SetPlayerMessage", setPlayerMessage, METH_VARARGS, NULL },
812  { "NPCSay", npcSay, METH_VARARGS, NULL },
813  { "CostStringFromValue", costStringFromValue, METH_VARARGS, NULL },
814  { NULL, NULL, 0, NULL }
815 };
816 
817 static void initContextStack(void) {
818  current_context = NULL;
819  context_stack = NULL;
820 }
821 
822 static void pushContext(CFPContext *context) {
823  if (current_context == NULL) {
824  context_stack = context;
825  context->down = NULL;
826  } else {
827  context->down = current_context;
828  }
829  current_context = context;
830 }
831 
832 static CFPContext *popContext(void) {
833  CFPContext *oldcontext;
834 
835  if (current_context != NULL) {
836  oldcontext = current_context;
838  return oldcontext;
839  }
840  else
841  return NULL;
842 }
843 
844 static void freeContext(CFPContext *context) {
845  Py_XDECREF(context->event);
846  Py_XDECREF(context->third);
847  Py_XDECREF(context->who);
848  Py_XDECREF(context->activator);
849  free(context);
850 }
851 
855 static PyObject* cfpython_openpyfile(char *filename) {
856  PyObject *scriptfile;
857  int fd;
858  fd = open(filename, O_RDONLY);
859  if (fd == -1)
860  return NULL;
861  scriptfile = PyFile_FromFd(fd, filename, "r", -1, NULL, NULL, NULL, 1);
862  return scriptfile;
863 }
864 
869 static FILE* cfpython_pyfile_asfile(PyObject* obj) {
870  return fdopen(PyObject_AsFileDescriptor(obj), "r");
871 }
872 
877 static PyObject *catcher = NULL;
878 
879 #if defined(IS_PY3K9) || defined(IS_PY3K10)
880 
884 static PyObject *io_module = NULL;
885 #endif
886 
893 static void log_python_error(void) {
894 
895  PyErr_Print();
896 
897  if (catcher != NULL) {
898  PyObject *output = PyObject_GetAttrString(catcher, "value"); //get the stdout and stderr from our catchOutErr object
899  PyObject* empty = PyUnicode_FromString("");
900 
901  cf_log_plain(llevError, PyUnicode_AsUTF8(output));
902  Py_DECREF(output);
903 
904  PyObject_SetAttrString(catcher, "value", empty);
905  Py_DECREF(empty);
906  }
907 
908  return;
909 }
910 
911 
913 static PyCodeObject *compilePython(char *filename) {
914  PyObject *scriptfile = NULL;
915  sstring sh_path;
916  struct stat stat_buf;
917  int i;
918  pycode_cache_entry *replace = NULL, *run = NULL;
919 
920  if (stat(filename, &stat_buf)) {
921  cf_log(llevError, "CFPython: script file %s can't be stat'ed\n", filename);
922  return NULL;
923  }
924 
925  sh_path = cf_add_string(filename);
926 
927  /* Search through cache. Four cases:
928  * 1) script in cache, but older than file -> replace cached
929  * 2) script in cache and up to date -> use cached
930  * 3) script not in cache, cache not full -> add to end of cache
931  * 4) script not in cache, cache full -> replace least recently used
932  */
933  for (i = 0; i < PYTHON_CACHE_SIZE; i++) {
934  if (pycode_cache[i].file == NULL) { /* script not in cache, cache not full */
935  replace = &pycode_cache[i]; /* add to end of cache */
936  break;
937  } else if (pycode_cache[i].file == sh_path) {
938  /* script in cache */
939  if (pycode_cache[i].code == NULL || (pycode_cache[i].cached_time < stat_buf.st_mtime)) {
940  /* cache older than file, replace cached */
941  replace = &pycode_cache[i];
942  } else {
943  /* cache uptodate, use cached*/
944  replace = NULL;
945  run = &pycode_cache[i];
946  }
947  break;
948  } else if (replace == NULL || pycode_cache[i].used_time < replace->used_time)
949  /* if we haven't found it yet, set replace to the oldest cache */
950  replace = &pycode_cache[i];
951  }
952 
953  /* replace a specific cache index with the file */
954  if (replace) {
955  Py_XDECREF(replace->code); /* safe to call on NULL */
956  replace->code = NULL;
957 
958  /* Need to replace path string? */
959  if (replace->file != sh_path) {
960  if (replace->file) {
961  cf_free_string(replace->file);
962  }
963  replace->file = cf_add_string(sh_path);
964  }
965 #if defined (IS_PY3K9) || defined(IS_PY3K10)
966  /* With the new parser in 3.10, we need to read the file contents into a buffer, and then pass that string to compile it.
967  * The new parser removes the PyNode functions as well as PyParser_SimpleParseFile,
968  * so the code needed to be completely rewritten to work.
969  *
970  * Python's solution to these changes is to import the io module and use Python's read method to read in the file,
971  * and then convert the bytes object into a c-string for Py_CompileString
972  *
973  * Though, if it is more performant than the previous code, Py_CompileString is
974  * available for all Python 3, so it is possible to simplify all of them to this if we need to.
975  */
976  if (!io_module)
977  io_module = PyImport_ImportModule("io");
978  scriptfile = PyObject_CallMethod(io_module, "open", "ss", filename, "rb");
979  if (!scriptfile) {
980  cf_log(llevDebug, "CFPython: script file %s can't be opened\n", filename);
981  cf_free_string(sh_path);
982  return NULL;
983  }
984  PyObject *source_bytes = PyObject_CallMethod(scriptfile, "read", "");
985  (void)PyObject_CallMethod(scriptfile, "close", "");
986  PyObject *code = Py_CompileString(PyBytes_AsString(source_bytes), filename, Py_file_input);
987  if (code) {
988  replace->code = (PyCodeObject *)code;
989  }
990  if (PyErr_Occurred())
992  else
993  replace->cached_time = stat_buf.st_mtime;
994  run = replace;
995 #else
996  /* Load, parse and compile. Note: because Pyhon may have been built with a
997  * different library than Crossfire, the FILE* it uses may be incompatible.
998  * Therefore we use PyFile to open the file, then convert to FILE* and get
999  * Python's own structure. Messy, but can't be helped... */
1000  if (!(scriptfile = cfpython_openpyfile(filename))) {
1001  cf_log(llevDebug, "CFPython: script file %s can't be opened\n", filename);
1002  cf_free_string(sh_path);
1003  return NULL;
1004  } else {
1005  /* Note: FILE* being opaque, it works, but the actual structure may be different! */
1006  FILE* pyfile = cfpython_pyfile_asfile(scriptfile);
1007  struct _node *n;
1008  if ((n = PyParser_SimpleParseFile(pyfile, filename, Py_file_input))) {
1009  replace->code = PyNode_Compile(n, filename);
1010  PyNode_Free(n);
1011  }
1012  if (PyErr_Occurred())
1013  log_python_error();
1014  else
1015  replace->cached_time = stat_buf.st_mtime;
1016  run = replace;
1017  }
1018 #endif
1019  }
1020 
1021  cf_free_string(sh_path);
1022 
1023  if (scriptfile) {
1024  Py_DECREF(scriptfile);
1025  }
1026 
1027  assert(run != NULL);
1028  run->used_time = time(NULL);
1029  return run->code;
1030 }
1031 
1032 static int do_script(CFPContext *context) {
1033  PyCodeObject *pycode;
1034  PyObject *dict;
1035  PyObject *ret;
1036 
1037 #ifdef PYTHON_DEBUG
1038  cf_log(llevDebug, "CFPython: running script %s\n", context->script);
1039 #endif
1040 
1041  pycode = compilePython(context->script);
1042  if (pycode) {
1043  pushContext(context);
1044  dict = PyDict_New();
1045  PyDict_SetItemString(dict, "__builtins__", PyEval_GetBuiltins());
1046  ret = PyEval_EvalCode((PyObject *)pycode, dict, NULL);
1047  if (PyErr_Occurred()) {
1048  log_python_error();
1049  }
1050  Py_XDECREF(ret);
1051  Py_DECREF(dict);
1052  return 1;
1053  } else
1054  return 0;
1055 }
1056 
1064 static void addConstants(PyObject *module, const char *name, const CFConstant *constants) {
1065  int i = 0;
1066  char tmp[1024];
1067  PyObject *cst;
1068  PyObject *dict;
1069 
1070  snprintf(tmp, sizeof(tmp), "Crossfire_%s", name);
1071 
1072  cst = PyModule_New(tmp);
1073  dict = PyDict_New();
1074 
1075  while (constants[i].name != NULL) {
1076  PyModule_AddIntConstant(cst, (char *)constants[i].name, constants[i].value);
1077  PyDict_SetItem(dict, PyLong_FromLong(constants[i].value), PyUnicode_FromString(constants[i].name));
1078  i++;
1079  }
1080  PyDict_SetItemString(PyModule_GetDict(module), name, cst);
1081 
1082  snprintf(tmp, sizeof(tmp), "%sName", name);
1083  PyDict_SetItemString(PyModule_GetDict(module), tmp, dict);
1084  Py_DECREF(dict);
1085 }
1086 
1096 static void addSimpleConstants(PyObject *module, const char *name, const CFConstant *constants) {
1097  int i = 0;
1098  char tmp[1024];
1099  PyObject *cst;
1100 
1101  snprintf(tmp, sizeof(tmp), "Crossfire_%s", name);
1102 
1103  cst = PyModule_New(tmp);
1104 
1105  while (constants[i].name != NULL) {
1106  PyModule_AddIntConstant(cst, (char *)constants[i].name, constants[i].value);
1107  i++;
1108  }
1109  PyDict_SetItemString(PyModule_GetDict(module), name, cst);
1110 }
1111 
1113  { "NORTH", 1 },
1114  { "NORTHEAST", 2 },
1115  { "EAST", 3 },
1116  { "SOUTHEAST", 4 },
1117  { "SOUTH", 5 },
1118  { "SOUTHWEST", 6 },
1119  { "WEST", 7 },
1120  { "NORTHWEST", 8 },
1121  { NULL, 0 }
1122 };
1123 
1124 const CFConstant cstType[] = {
1125  { "PLAYER", PLAYER },
1126  { "TRANSPORT", TRANSPORT },
1127  { "ROD", ROD },
1128  { "TREASURE", TREASURE },
1129  { "POTION", POTION },
1130  { "FOOD", FOOD },
1131  { "POISON", POISON },
1132  { "BOOK", BOOK },
1133  { "CLOCK", CLOCK },
1134  { "DRAGON_FOCUS", DRAGON_FOCUS },
1135  { "ARROW", ARROW },
1136  { "BOW", BOW },
1137  { "WEAPON", WEAPON },
1138  { "ARMOUR", ARMOUR },
1139  { "PEDESTAL", PEDESTAL },
1140  { "ALTAR", ALTAR },
1141  { "LOCKED_DOOR", LOCKED_DOOR },
1142  { "SPECIAL_KEY", SPECIAL_KEY },
1143  { "MAP", MAP },
1144  { "DOOR", DOOR },
1145  { "KEY", KEY },
1146  { "TIMED_GATE", TIMED_GATE },
1147  { "TRIGGER", TRIGGER },
1148  { "GRIMREAPER", GRIMREAPER },
1149  { "MAGIC_EAR", MAGIC_EAR },
1150  { "TRIGGER_BUTTON", TRIGGER_BUTTON },
1151  { "TRIGGER_ALTAR", TRIGGER_ALTAR },
1152  { "TRIGGER_PEDESTAL", TRIGGER_PEDESTAL },
1153  { "SHIELD", SHIELD },
1154  { "HELMET", HELMET },
1155  { "MONEY", MONEY },
1156  { "CLASS", CLASS },
1157  { "AMULET", AMULET },
1158  { "PLAYERMOVER", PLAYERMOVER },
1159  { "TELEPORTER", TELEPORTER },
1160  { "CREATOR", CREATOR },
1161  { "SKILL", SKILL },
1162  { "EARTHWALL", EARTHWALL },
1163  { "GOLEM", GOLEM },
1164  { "THROWN_OBJ", THROWN_OBJ },
1165  { "BLINDNESS", BLINDNESS },
1166  { "GOD", GOD },
1167  { "DETECTOR", DETECTOR },
1168  { "TRIGGER_MARKER", TRIGGER_MARKER },
1169  { "DEAD_OBJECT", DEAD_OBJECT },
1170  { "DRINK", DRINK },
1171  { "MARKER", MARKER },
1172  { "HOLY_ALTAR", HOLY_ALTAR },
1173  { "PLAYER_CHANGER", PLAYER_CHANGER },
1174  { "BATTLEGROUND", BATTLEGROUND },
1175  { "PEACEMAKER", PEACEMAKER },
1176  { "GEM", GEM },
1177  { "FIREWALL", FIREWALL },
1178  { "CHECK_INV", CHECK_INV },
1179  { "MOOD_FLOOR", MOOD_FLOOR },
1180  { "EXIT", EXIT },
1181  { "ENCOUNTER", ENCOUNTER },
1182  { "SHOP_FLOOR", SHOP_FLOOR },
1183  { "SHOP_MAT", SHOP_MAT },
1184  { "RING", RING },
1185  { "FLOOR", FLOOR },
1186  { "FLESH", FLESH },
1187  { "INORGANIC", INORGANIC },
1188  { "SKILL_TOOL", SKILL_TOOL },
1189  { "LIGHTER", LIGHTER },
1190  { "WALL", WALL },
1191  { "MISC_OBJECT", MISC_OBJECT },
1192  { "MONSTER", MONSTER },
1193  { "LAMP", LAMP },
1194  { "DUPLICATOR", DUPLICATOR },
1195  { "SPELLBOOK", SPELLBOOK },
1196  { "CLOAK", CLOAK },
1197  { "SPINNER", SPINNER },
1198  { "GATE", GATE },
1199  { "BUTTON", BUTTON },
1200  { "CF_HANDLE", CF_HANDLE },
1201  { "HOLE", HOLE },
1202  { "TRAPDOOR", TRAPDOOR },
1203  { "SIGN", SIGN },
1204  { "BOOTS", BOOTS },
1205  { "GLOVES", GLOVES },
1206  { "SPELL", SPELL },
1207  { "SPELL_EFFECT", SPELL_EFFECT },
1208  { "CONVERTER", CONVERTER },
1209  { "BRACERS", BRACERS },
1210  { "POISONING", POISONING },
1211  { "SAVEBED", SAVEBED },
1212  { "WAND", WAND },
1213  { "SCROLL", SCROLL },
1214  { "DIRECTOR", DIRECTOR },
1215  { "GIRDLE", GIRDLE },
1216  { "FORCE", FORCE },
1217  { "POTION_RESIST_EFFECT", POTION_RESIST_EFFECT },
1218  { "EVENT_CONNECTOR", EVENT_CONNECTOR },
1219  { "CLOSE_CON", CLOSE_CON },
1220  { "CONTAINER", CONTAINER },
1221  { "ARMOUR_IMPROVER", ARMOUR_IMPROVER },
1222  { "WEAPON_IMPROVER", WEAPON_IMPROVER },
1223  { "SKILLSCROLL", SKILLSCROLL },
1224  { "DEEP_SWAMP", DEEP_SWAMP },
1225  { "IDENTIFY_ALTAR", IDENTIFY_ALTAR },
1226  { "SHOP_INVENTORY", SHOP_INVENTORY },
1227  { "RUNE", RUNE },
1228  { "TRAP", TRAP },
1229  { "POWER_CRYSTAL", POWER_CRYSTAL },
1230  { "CORPSE", CORPSE },
1231  { "DISEASE", DISEASE },
1232  { "SYMPTOM", SYMPTOM },
1233  { "BUILDER", BUILDER },
1234  { "MATERIAL", MATERIAL },
1235  { "MIMIC", MIMIC },
1236  { "LIGHTABLE", LIGHTABLE },
1237  { NULL, 0 }
1238 };
1239 
1240 const CFConstant cstMove[] = {
1241  { "WALK", MOVE_WALK },
1242  { "FLY_LOW", MOVE_FLY_LOW },
1243  { "FLY_HIGH", MOVE_FLY_HIGH },
1244  { "FLYING", MOVE_FLYING },
1245  { "SWIM", MOVE_SWIM },
1246  { "BOAT", MOVE_BOAT },
1247  { "ALL", MOVE_ALL },
1248  { NULL, 0 }
1249 };
1250 
1252  { "NDI_BLACK", NDI_BLACK },
1253  { "NDI_WHITE", NDI_WHITE },
1254  { "NDI_NAVY", NDI_NAVY },
1255  { "NDI_RED", NDI_RED },
1256  { "NDI_ORANGE", NDI_ORANGE },
1257  { "NDI_BLUE", NDI_BLUE },
1258  { "NDI_DK_ORANGE", NDI_DK_ORANGE },
1259  { "NDI_GREEN", NDI_GREEN },
1260  { "NDI_LT_GREEN", NDI_LT_GREEN },
1261  { "NDI_GREY", NDI_GREY },
1262  { "NDI_BROWN", NDI_BROWN },
1263  { "NDI_GOLD", NDI_GOLD },
1264  { "NDI_TAN", NDI_TAN },
1265  { "NDI_UNIQUE", NDI_UNIQUE },
1266  { "NDI_ALL", NDI_ALL },
1267  { "NDI_ALL_DMS", NDI_ALL_DMS },
1268  { NULL, 0 }
1269 };
1270 
1272  { "PHYSICAL", AT_PHYSICAL },
1273  { "MAGIC", AT_MAGIC },
1274  { "FIRE", AT_FIRE },
1275  { "ELECTRICITY", AT_ELECTRICITY },
1276  { "COLD", AT_COLD },
1277  { "CONFUSION", AT_CONFUSION },
1278  { "ACID", AT_ACID },
1279  { "DRAIN", AT_DRAIN },
1280  { "WEAPONMAGIC", AT_WEAPONMAGIC },
1281  { "GHOSTHIT", AT_GHOSTHIT },
1282  { "POISON", AT_POISON },
1283  { "SLOW", AT_SLOW },
1284  { "PARALYZE", AT_PARALYZE },
1285  { "TURN_UNDEAD", AT_TURN_UNDEAD },
1286  { "FEAR", AT_FEAR },
1287  { "CANCELLATION", AT_CANCELLATION },
1288  { "DEPLETE", AT_DEPLETE },
1289  { "DEATH", AT_DEATH },
1290  { "CHAOS", AT_CHAOS },
1291  { "COUNTERSPELL", AT_COUNTERSPELL },
1292  { "GODPOWER", AT_GODPOWER },
1293  { "HOLYWORD", AT_HOLYWORD },
1294  { "BLIND", AT_BLIND },
1295  { "INTERNAL", AT_INTERNAL },
1296  { "LIFE_STEALING", AT_LIFE_STEALING },
1297  { "DISEASE", AT_DISEASE },
1298  { NULL, 0 }
1299 };
1300 
1302  { "PHYSICAL", ATNR_PHYSICAL },
1303  { "MAGIC", ATNR_MAGIC },
1304  { "FIRE", ATNR_FIRE },
1305  { "ELECTRICITY", ATNR_ELECTRICITY },
1306  { "COLD", ATNR_COLD },
1307  { "CONFUSION", ATNR_CONFUSION },
1308  { "ACID", ATNR_ACID },
1309  { "DRAIN", ATNR_DRAIN },
1310  { "WEAPONMAGIC", ATNR_WEAPONMAGIC },
1311  { "GHOSTHIT", ATNR_GHOSTHIT },
1312  { "POISON", ATNR_POISON },
1313  { "SLOW", ATNR_SLOW },
1314  { "PARALYZE", ATNR_PARALYZE },
1315  { "TURN_UNDEAD", ATNR_TURN_UNDEAD },
1316  { "FEAR", ATNR_FEAR },
1317  { "CANCELLATION", ATNR_CANCELLATION },
1318  { "DEPLETE", ATNR_DEPLETE },
1319  { "DEATH", ATNR_DEATH },
1320  { "CHAOS", ATNR_CHAOS },
1321  { "COUNTERSPELL", ATNR_COUNTERSPELL },
1322  { "GODPOWER", ATNR_GODPOWER },
1323  { "HOLYWORD", ATNR_HOLYWORD },
1324  { "BLIND", ATNR_BLIND },
1325  { "INTERNAL", ATNR_INTERNAL },
1326  { "LIFE_STEALING", ATNR_LIFE_STEALING },
1327  { "DISEASE", ATNR_DISEASE },
1328  { NULL, 0 }
1329 };
1330 
1333  { "APPLY", EVENT_APPLY },
1334  { "ATTACK", EVENT_ATTACKED },
1335  { "ATTACKS", EVENT_ATTACKS },
1336  { "BOUGHT", EVENT_BOUGHT },
1337  { "CLOSE", EVENT_CLOSE },
1338  { "DEATH", EVENT_DEATH },
1339  { "DESTROY", EVENT_DESTROY },
1340  { "DROP", EVENT_DROP },
1341  { "PICKUP", EVENT_PICKUP },
1342  { "SAY", EVENT_SAY },
1343  { "SELLING", EVENT_SELLING },
1344  { "STOP", EVENT_STOP },
1345  { "TIME", EVENT_TIME },
1346  { "THROW", EVENT_THROW },
1347  { "TRIGGER", EVENT_TRIGGER },
1348  { "TIMER", EVENT_TIMER },
1349  { "USER", EVENT_USER },
1350 
1352  { "BORN", EVENT_BORN },
1353  { "CLOCK", EVENT_CLOCK },
1354  { "CRASH", EVENT_CRASH },
1355  { "GKILL", EVENT_GKILL },
1356  { "KICK", EVENT_KICK },
1357  { "LOGIN", EVENT_LOGIN },
1358  { "LOGOUT", EVENT_LOGOUT },
1359  { "MAPENTER", EVENT_MAPENTER },
1360  { "MAPLEAVE", EVENT_MAPLEAVE },
1361  { "MAPLOAD", EVENT_MAPLOAD },
1362  { "MAPREADY", EVENT_MAPREADY },
1363  { "MAPRESET", EVENT_MAPRESET },
1364  { "MAPUNLOAD", EVENT_MAPUNLOAD },
1365  { "MUZZLE", EVENT_MUZZLE },
1366  { "PLAYER_DEATH", EVENT_PLAYER_DEATH },
1367  { "REMOVE", EVENT_REMOVE },
1368  { "SHOUT", EVENT_SHOUT },
1369  { "TELL", EVENT_TELL },
1370  { "GBOUGHT", EVENT_GBOUGHT },
1371  { "GSOLD", EVENT_GSOLD },
1372  { NULL, 0 }
1373 };
1374 
1375 const CFConstant cstTime[] = {
1376  { "HOURS_PER_DAY", HOURS_PER_DAY },
1377  { "DAYS_PER_WEEK", DAYS_PER_WEEK },
1378  { "WEEKS_PER_MONTH", WEEKS_PER_MONTH },
1379  { "MONTHS_PER_YEAR", MONTHS_PER_YEAR },
1380  { "SEASONS_PER_YEAR", SEASONS_PER_YEAR },
1381  { "PERIODS_PER_DAY", PERIODS_PER_DAY },
1382  { NULL, 0 }
1383 };
1384 
1386  { "SAY", rt_say },
1387  { "REPLY", rt_reply },
1388  { "QUESTION", rt_question },
1389  { NULL, 0 }
1390 };
1391 
1393  { "DISTATT", DISTATT },
1394  { "RUNATT", RUNATT },
1395  { "HITRUN", HITRUN },
1396  { "WAITATT", WAITATT },
1397  { "RUSH", RUSH },
1398  { "ALLRUN", ALLRUN },
1399  { "DISTHIT", DISTHIT },
1400  { "WAIT2", WAIT2 },
1401  { "PETMOVE", PETMOVE },
1402  { "CIRCLE1", CIRCLE1 },
1403  { "CIRCLE2", CIRCLE2 },
1404  { "PACEH", PACEH },
1405  { "PACEH2", PACEH2 },
1406  { "RANDO", RANDO },
1407  { "RANDO2", RANDO2 },
1408  { "PACEV", PACEV },
1409  { "PACEV2", PACEV2 },
1410  { NULL, 0 }
1411 };
1412 
1413 static void initConstants(PyObject *module) {
1414  addConstants(module, "Direction", cstDirection);
1415  addConstants(module, "Type", cstType);
1416  addConstants(module, "Move", cstMove);
1417  addConstants(module, "MessageFlag", cstMessageFlag);
1418  addConstants(module, "AttackType", cstAttackType);
1419  addConstants(module, "AttackTypeNumber", cstAttackTypeNumber);
1420  addConstants(module, "EventType", cstEventType);
1421  addSimpleConstants(module, "Time", cstTime);
1422  addSimpleConstants(module, "ReplyType", cstReplyTypes);
1423  addSimpleConstants(module, "AttackMovement", cstAttackMovement);
1424 }
1425 
1426 /*
1427  * Set up the main module and handle misc plugin loading stuff and such.
1428  */
1429 
1434 static void cfpython_init_types(PyObject* m) {
1435  PyObject *d = PyModule_GetDict(m);
1436 
1437  Crossfire_ObjectType.tp_new = PyType_GenericNew;
1438  Crossfire_MapType.tp_new = PyType_GenericNew;
1439  Crossfire_PlayerType.tp_new = PyType_GenericNew;
1440  Crossfire_ArchetypeType.tp_new = PyType_GenericNew;
1441  Crossfire_PartyType.tp_new = PyType_GenericNew;
1442  Crossfire_RegionType.tp_new = PyType_GenericNew;
1443  PyType_Ready(&Crossfire_ObjectType);
1444  PyType_Ready(&Crossfire_MapType);
1445  PyType_Ready(&Crossfire_PlayerType);
1446  PyType_Ready(&Crossfire_ArchetypeType);
1447  PyType_Ready(&Crossfire_PartyType);
1448  PyType_Ready(&Crossfire_RegionType);
1449 
1450  Py_INCREF(&Crossfire_ObjectType);
1451  Py_INCREF(&Crossfire_MapType);
1452  Py_INCREF(&Crossfire_PlayerType);
1453  Py_INCREF(&Crossfire_ArchetypeType);
1454  Py_INCREF(&Crossfire_PartyType);
1455  Py_INCREF(&Crossfire_RegionType);
1456 
1457  PyModule_AddObject(m, "Object", (PyObject *)&Crossfire_ObjectType);
1458  PyModule_AddObject(m, "Map", (PyObject *)&Crossfire_MapType);
1459  PyModule_AddObject(m, "Player", (PyObject *)&Crossfire_PlayerType);
1460  PyModule_AddObject(m, "Archetype", (PyObject *)&Crossfire_ArchetypeType);
1461  PyModule_AddObject(m, "Party", (PyObject *)&Crossfire_PartyType);
1462  PyModule_AddObject(m, "Region", (PyObject *)&Crossfire_RegionType);
1463 
1464  PyModule_AddObject(m, "LogError", Py_BuildValue("i", llevError));
1465  PyModule_AddObject(m, "LogInfo", Py_BuildValue("i", llevInfo));
1466  PyModule_AddObject(m, "LogDebug", Py_BuildValue("i", llevDebug));
1467  PyModule_AddObject(m, "LogMonster", Py_BuildValue("i", llevMonster));
1468 
1469  CFPythonError = PyErr_NewException("Crossfire.error", NULL, NULL);
1470  PyDict_SetItemString(d, "error", CFPythonError);
1471 }
1472 
1473 extern PyObject* PyInit_cjson(void);
1474 
1475 static PyModuleDef CrossfireModule = {
1476  PyModuleDef_HEAD_INIT,
1477  "Crossfire", /* m_name */
1478  NULL, /* m_doc */
1479  -1, /* m_size */
1480  CFPythonMethods, /* m_methods */
1481  NULL, /* m_reload */
1482  NULL, /* m_traverse */
1483  NULL, /* m_clear */
1484  NULL /* m_free */
1485 };
1486 
1487 static PyObject* PyInit_Crossfire(void)
1488 {
1489  PyObject *m = PyModule_Create(&CrossfireModule);
1490  Py_INCREF(m);
1491  return m;
1492 }
1493 
1494 extern "C"
1495 int initPlugin(const char *iversion, f_plug_api gethooksptr) {
1496  PyObject *m;
1497  /* Python code to redirect stdouts/stderr. */
1498  const char *stdOutErr =
1499 "import sys\n\
1500 class CatchOutErr:\n\
1501  def __init__(self):\n\
1502  self.value = ''\n\
1503  def write(self, txt):\n\
1504  self.value += txt\n\
1505 catchOutErr = CatchOutErr()\n\
1506 sys.stdout = catchOutErr\n\
1507 sys.stderr = catchOutErr\n\
1508 ";
1509  (void)iversion;
1510 
1511  for (int c = 0; c < MAX_COMMANDS; c++) {
1512  registered_commands[c] = 0;
1513  }
1514 
1515  cf_init_plugin(gethooksptr);
1516  cf_log(llevDebug, "CFPython 2.0a init\n");
1517 
1518  PyImport_AppendInittab("Crossfire", &PyInit_Crossfire);
1519  PyImport_AppendInittab("cjson", &PyInit_cjson);
1520 
1521  Py_Initialize();
1522 
1523  m = PyImport_ImportModule("Crossfire");
1524 
1526 
1527  initConstants(m);
1528  private_data = PyDict_New();
1529  shared_data = PyDict_New();
1530 
1531  /* Redirect Python's stderr to a special object so it can be put to
1532  * the Crossfire log. */
1533  m = PyImport_AddModule("__main__");
1534  PyRun_SimpleString(stdOutErr);
1535  catcher = PyObject_GetAttrString(m, "catchOutErr");
1536  return 0;
1537 }
1538 
1540  va_list args;
1541  const char *propname;
1542  int size;
1543  char *buf;
1544 
1545  va_start(args, type);
1546  propname = va_arg(args, const char *);
1547  if (!strcmp(propname, "Identification")) {
1548  buf = va_arg(args, char *);
1549  size = va_arg(args, int);
1550  va_end(args);
1551  snprintf(buf, size, PLUGIN_NAME);
1552  return NULL;
1553  } else if (!strcmp(propname, "FullName")) {
1554  buf = va_arg(args, char *);
1555  size = va_arg(args, int);
1556  va_end(args);
1557  snprintf(buf, size, PLUGIN_VERSION);
1558  return NULL;
1559  }
1560  va_end(args);
1561  return NULL;
1562 }
1563 
1564 static int GECodes[] = {
1565  EVENT_BORN,
1566  EVENT_CLOCK,
1568  EVENT_GKILL,
1569  EVENT_LOGIN,
1570  EVENT_LOGOUT,
1574  EVENT_REMOVE,
1575  EVENT_SHOUT,
1576  EVENT_TELL,
1577  EVENT_MUZZLE,
1578  EVENT_KICK,
1580  EVENT_MAPLOAD,
1582  EVENT_GBOUGHT,
1583  EVENT_GSOLD,
1584  0
1585 };
1586 
1587 static const char* GEPaths[] = {
1588  "born",
1589  "clock",
1590  "death",
1591  "gkill",
1592  "login",
1593  "logout",
1594  "mapenter",
1595  "mapleave",
1596  "mapreset",
1597  "remove",
1598  "shout",
1599  "tell",
1600  "muzzle",
1601  "kick",
1602  "mapunload",
1603  "mapload",
1604  "mapready",
1605  "gbought",
1606  "gsold",
1607  NULL
1608 };
1609 
1615 static void freeEventFiles(char **eventFiles) {
1616  assert(eventFiles);
1617  for (int e = 0; eventFiles[e] != NULL; e++) {
1618  free(eventFiles[e]);
1619  }
1620  free(eventFiles);
1621 }
1622 
1628 static char **getEventFiles(CFPContext *context) {
1629  char **eventFiles = NULL;
1630  char name[HUGE_BUF], path[NAME_MAX + 1];
1631 
1632  int allocated = 0, current = 0;
1633  DIR *dp;
1634  struct dirent *d;
1635  struct stat sb;
1636 
1637  snprintf(name, sizeof(name), "python/events/%s/", context->options);
1638  cf_get_maps_directory(name, path, sizeof(path));
1639 
1640  dp = opendir(path);
1641  if (dp == NULL) {
1642  eventFiles = static_cast<char **>(calloc(1, sizeof(eventFiles[0])));
1643  eventFiles[0] = NULL;
1644  return eventFiles;
1645  }
1646 
1647  while ((d = readdir(dp)) != NULL) {
1648  snprintf(name, sizeof(name), "%s%s", path, d->d_name);
1649  stat(name, &sb);
1650  if (S_ISDIR(sb.st_mode)) {
1651  continue;
1652  }
1653  if (strcmp(d->d_name + strlen(d->d_name) - 3, ".py")) {
1654  continue;
1655  }
1656 
1657  if (allocated == current) {
1658  allocated += 10;
1659  eventFiles = static_cast<char **>(realloc(eventFiles, sizeof(char *) * (allocated + 1)));
1660  for (int i = current; i < allocated + 1; i++) {
1661  eventFiles[i] = NULL;
1662  }
1663  }
1664  eventFiles[current] = strdup(name);
1665  current++;
1666  }
1667  (void)closedir(dp);
1668  return eventFiles;
1669 }
1670 
1672  PyObject *scriptfile;
1673  char path[1024];
1674  int i;
1675 
1676  cf_log(llevDebug, "CFPython 2.0a post init\n");
1677  initContextStack();
1678  for (i = 0; GECodes[i] != 0; i++)
1680 
1681  scriptfile = cfpython_openpyfile(cf_get_maps_directory("python/events/python_init.py", path, sizeof(path)));
1682  if (scriptfile != NULL) {
1683  FILE* pyfile = cfpython_pyfile_asfile(scriptfile);
1684  PyRun_SimpleFile(pyfile, cf_get_maps_directory("python/events/python_init.py", path, sizeof(path)));
1685  Py_DECREF(scriptfile);
1686  }
1687 
1688  for (i = 0; i < PYTHON_CACHE_SIZE; i++) {
1689  pycode_cache[i].code = NULL;
1690  pycode_cache[i].file = NULL;
1691  pycode_cache[i].cached_time = 0;
1692  pycode_cache[i].used_time = 0;
1693  }
1694 
1695  return 0;
1696 }
1697 
1698 static const char *getGlobalEventPath(int code) {
1699  for (int i = 0; GECodes[i] != 0; i++) {
1700  if (GECodes[i] == code)
1701  return GEPaths[i];
1702  }
1703  return "";
1704 }
1705 
1707  va_list args;
1708  int rv = 0;
1709  CFPContext *context;
1710  char *buf;
1711  player *pl;
1712  object *op;
1713  context = static_cast<CFPContext *>(calloc(1, sizeof(CFPContext)));
1714  char **files;
1715 
1716  va_start(args, type);
1717  context->event_code = va_arg(args, int);
1718 
1719  context->message[0] = 0;
1720 
1721  rv = context->returnvalue = 0;
1722  switch (context->event_code) {
1723  case EVENT_CRASH:
1724  cf_log(llevDebug, "CFPython: event_crash unimplemented for now\n");
1725  break;
1726 
1727  case EVENT_BORN:
1728  op = va_arg(args, object *);
1729  context->activator = Crossfire_Object_wrap(op);
1730  break;
1731 
1732  case EVENT_PLAYER_DEATH:
1733  op = va_arg(args, object *);
1734  context->who = Crossfire_Object_wrap(op);
1735  op = va_arg(args, object *);
1736  context->activator = Crossfire_Object_wrap(op);
1737  break;
1738 
1739  case EVENT_GKILL:
1740  {
1741  op = va_arg(args, object *);
1742  object* hitter = va_arg(args, object *);
1743  context->who = Crossfire_Object_wrap(op);
1744  context->activator = Crossfire_Object_wrap(hitter);
1745  break;
1746  }
1747 
1748  case EVENT_LOGIN:
1749  pl = va_arg(args, player *);
1750  context->activator = Crossfire_Object_wrap(pl->ob);
1751  buf = va_arg(args, char *);
1752  if (buf != NULL)
1753  snprintf(context->message, sizeof(context->message), "%s", buf);
1754  break;
1755 
1756  case EVENT_LOGOUT:
1757  pl = va_arg(args, player *);
1758  context->activator = Crossfire_Object_wrap(pl->ob);
1759  buf = va_arg(args, char *);
1760  if (buf != NULL)
1761  snprintf(context->message, sizeof(context->message), "%s", buf);
1762  break;
1763 
1764  case EVENT_REMOVE:
1765  op = va_arg(args, object *);
1766  context->activator = Crossfire_Object_wrap(op);
1767  break;
1768 
1769  case EVENT_SHOUT:
1770  op = va_arg(args, object *);
1771  context->activator = Crossfire_Object_wrap(op);
1772  buf = va_arg(args, char *);
1773  if (buf != NULL)
1774  snprintf(context->message, sizeof(context->message), "%s", buf);
1775  break;
1776 
1777  case EVENT_MUZZLE:
1778  op = va_arg(args, object *);
1779  context->activator = Crossfire_Object_wrap(op);
1780  buf = va_arg(args, char *);
1781  if (buf != NULL)
1782  snprintf(context->message, sizeof(context->message), "%s", buf);
1783  break;
1784 
1785  case EVENT_KICK:
1786  op = va_arg(args, object *);
1787  context->activator = Crossfire_Object_wrap(op);
1788  buf = va_arg(args, char *);
1789  if (buf != NULL)
1790  snprintf(context->message, sizeof(context->message), "%s", buf);
1791  break;
1792 
1793  case EVENT_MAPENTER:
1794  op = va_arg(args, object *);
1795  context->activator = Crossfire_Object_wrap(op);
1796  context->who = Crossfire_Map_wrap(va_arg(args, mapstruct *));
1797  break;
1798 
1799  case EVENT_MAPLEAVE:
1800  op = va_arg(args, object *);
1801  context->activator = Crossfire_Object_wrap(op);
1802  context->who = Crossfire_Map_wrap(va_arg(args, mapstruct *));
1803  break;
1804 
1805  case EVENT_CLOCK:
1806  break;
1807 
1808  case EVENT_MAPRESET:
1809  context->who = Crossfire_Map_wrap(va_arg(args, mapstruct *));
1810  break;
1811 
1812  case EVENT_TELL:
1813  op = va_arg(args, object *);
1814  buf = va_arg(args, char *);
1815  context->activator = Crossfire_Object_wrap(op);
1816  if (buf != NULL)
1817  snprintf(context->message, sizeof(context->message), "%s", buf);
1818  op = va_arg(args, object *);
1819  context->third = Crossfire_Object_wrap(op);
1820  break;
1821 
1822  case EVENT_MAPUNLOAD:
1823  context->who = Crossfire_Map_wrap(va_arg(args, mapstruct *));
1824  break;
1825 
1826  case EVENT_MAPLOAD:
1827  context->who = Crossfire_Map_wrap(va_arg(args, mapstruct *));
1828  break;
1829 
1830  case EVENT_GBOUGHT:
1831  // fall through: these have the same arguments
1832  case EVENT_GSOLD:
1833  context->who = Crossfire_Object_wrap(va_arg(args, object *)); // op
1834  context->activator = Crossfire_Object_wrap(va_arg(args, object *)); // pl
1835  break;
1836  }
1837  va_end(args);
1838  context->returnvalue = 0;
1839 
1840  if (context->event_code == EVENT_CLOCK) {
1841  // Ignore EVENT_CLOCK. It is not being used in maps, but nevertheless
1842  // runs python_init.py several times per second even while idling.
1843  freeContext(context);
1844  return rv;
1845  }
1846 
1847  snprintf(context->options, sizeof(context->options), "%s", getGlobalEventPath(context->event_code));
1848  files = getEventFiles(context);
1849  for (int file = 0; files[file] != NULL; file++)
1850  {
1851  CFPContext *copy = static_cast<CFPContext *>(malloc(sizeof(CFPContext)));
1852  (*copy) = (*context);
1853  Py_XINCREF(copy->activator);
1854  Py_XINCREF(copy->event);
1855  Py_XINCREF(copy->third);
1856  Py_XINCREF(copy->who);
1857  strncpy(copy->script, files[file], sizeof(copy->script));
1858 
1859  if (!do_script(copy)) {
1860  freeContext(copy);
1862  return rv;
1863  }
1864 
1865  copy = popContext();
1866  rv = copy->returnvalue;
1867 
1868  freeContext(copy);
1869  }
1871 
1872  /* Invalidate freed map wrapper. */
1873  if (context->event_code == EVENT_MAPUNLOAD)
1875 
1876  free(context);
1877 
1878  return rv;
1879 }
1880 
1881 CF_PLUGIN int eventListener(int *type, ...) {
1882  int rv = 0;
1883  va_list args;
1884  char *buf;
1885  CFPContext *context;
1886  object *event;
1887 
1888  context = static_cast<CFPContext *>(malloc(sizeof(CFPContext)));
1889 
1890  context->message[0] = 0;
1891 
1892  va_start(args, type);
1893 
1894  context->who = Crossfire_Object_wrap(va_arg(args, object *));
1895  context->activator = Crossfire_Object_wrap(va_arg(args, object *));
1896  context->third = Crossfire_Object_wrap(va_arg(args, object *));
1897  buf = va_arg(args, char *);
1898  if (buf != NULL)
1899  snprintf(context->message, sizeof(context->message), "%s", buf);
1900  /* fix = */va_arg(args, int);
1901  event = va_arg(args, object *);
1902  context->talk = va_arg(args, talk_info *);
1903  context->event_code = event->subtype;
1904  context->event = Crossfire_Object_wrap(event);
1905  cf_get_maps_directory(event->slaying, context->script, sizeof(context->script));
1906  snprintf(context->options, sizeof(context->options), "%s", event->name);
1907  context->returnvalue = 0;
1908 
1909  va_end(args);
1910 
1911  if (!do_script(context)) {
1912  freeContext(context);
1913  return rv;
1914  }
1915 
1916  context = popContext();
1917  rv = context->returnvalue;
1918  freeContext(context);
1919  return rv;
1920 }
1921 
1923  int i;
1924 
1925  cf_log(llevDebug, "CFPython 2.0a closing\n");
1926 
1927  for (int c = 0; c < MAX_COMMANDS; c++) {
1928  if (registered_commands[c]) {
1930  }
1931  }
1932 
1933  for (i = 0; i < PYTHON_CACHE_SIZE; i++) {
1934  Py_XDECREF(pycode_cache[i].code);
1935  if (pycode_cache[i].file != NULL)
1936  cf_free_string(pycode_cache[i].file);
1937  }
1938 
1939  Py_Finalize();
1940 
1941  return 0;
1942 }
EVENT_GSOLD
#define EVENT_GSOLD
Player sold object in shop, but global.
Definition: events.h:58
cf_cost_string_from_value
void cf_cost_string_from_value(uint64_t cost, int largest_coin, char *buffer, int length)
Wrapper for cost_string_from_value modified to take a char* and length instead of a StringBuffer.
Definition: plugin_common.cpp:994
CLASS
@ CLASS
Object for applying character class modifications to someone.
Definition: object.h:143
findPlayer
static PyObject * findPlayer(PyObject *self, PyObject *args)
Definition: cfpython.cpp:206
getMonthName
static PyObject * getMonthName(PyObject *self, PyObject *args)
Definition: cfpython.cpp:644
CFPContext::event_code
int event_code
Definition: cfpython.h:101
TRIGGER
@ TRIGGER
Definition: object.h:134
MIMIC
@ MIMIC
Definition: object.h:254
PLAYER
@ PLAYER
Definition: object.h:112
cf_log
void cf_log(LogLevel logLevel, const char *format,...)
Wrapper for LOG().
Definition: plugin_common.cpp:1522
ATNR_PARALYZE
#define ATNR_PARALYZE
Definition: attack.h:61
cstMove
const CFConstant cstMove[]
Definition: cfpython.cpp:1240
pycode_cache_entry::used_time
time_t used_time
Last use of this cache entry.
Definition: cfpython.cpp:81
DAYS_PER_WEEK
#define DAYS_PER_WEEK
Definition: tod.h:16
ATNR_CANCELLATION
#define ATNR_CANCELLATION
Definition: attack.h:64
getCFPythonVersion
static PyObject * getCFPythonVersion(PyObject *self, PyObject *args)
Definition: cfpython.cpp:165
shared_data
static PyObject * shared_data
Definition: cfpython.cpp:108
CF_HANDLE
@ CF_HANDLE
Definition: object.h:213
cf_get_weekday_name
const char * cf_get_weekday_name(int index)
Definition: plugin_common.cpp:1574
Crossfire_Object::obj
PyObject_HEAD object * obj
Definition: cfpython_object.h:34
cf_add_string
sstring cf_add_string(const char *str)
Wrapper for add_string().
Definition: plugin_common.cpp:1167
talk_info::replies
sstring replies[MAX_REPLIES]
Description for replies_words.
Definition: dialog.h:57
MAP
@ MAP
Definition: object.h:130
getSeasonName
static PyObject * getSeasonName(PyObject *self, PyObject *args)
Definition: cfpython.cpp:635
cf_get_directory
const char * cf_get_directory(int id)
Gets a directory Crossfire uses.
Definition: plugin_common.cpp:1130
getLocalDirectory
static PyObject * getLocalDirectory(PyObject *self, PyObject *args)
Definition: cfpython.cpp:275
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
MONSTER
@ MONSTER
A real, living creature.
Definition: object.h:205
BOW
@ BOW
Definition: object.h:123
BRACERS
@ BRACERS
Definition: object.h:222
CLOSE_CON
@ CLOSE_CON
Eneq((at)csd.uu.se): Id for close_container archetype.
Definition: object.h:234
WAITATT
#define WAITATT
Wait for player to approach then hit, move if hit.
Definition: define.h:489
llevError
@ llevError
Error, serious thing.
Definition: logger.h:11
ARMOUR_IMPROVER
@ ARMOUR_IMPROVER
Definition: object.h:237
EVENT_CONNECTOR
@ EVENT_CONNECTOR
Lauwenmark: an invisible object holding a plugin event hook.
Definition: object.h:232
MOVE_ALL
#define MOVE_ALL
Mask of all movement types.
Definition: define.h:398
SYMPTOM
@ SYMPTOM
Definition: object.h:250
WAND
@ WAND
Definition: object.h:225
cf_get_season_name
const char * cf_get_season_name(int index)
Definition: plugin_common.cpp:1556
ALLRUN
#define ALLRUN
Always run, never attack good for sim.
Definition: define.h:491
talk_info::replies_words
sstring replies_words[MAX_REPLIES]
Available reply words.
Definition: dialog.h:56
talk_info::npc_msg_count
int npc_msg_count
How many NPCs reacted to the text being said.
Definition: dialog.h:58
FLESH
@ FLESH
animal 'body parts' -b.t.
Definition: object.h:192
ENCOUNTER
@ ENCOUNTER
Definition: object.h:187
player
One player.
Definition: player.h:105
GLOVES
@ GLOVES
Definition: object.h:218
GIRDLE
@ GIRDLE
Definition: object.h:228
compilePython
static PyCodeObject * compilePython(char *filename)
Outputs the compiled bytecode for a given python file, using in-memory caching of bytecode.
Definition: cfpython.cpp:913
ATNR_ACID
#define ATNR_ACID
Definition: attack.h:55
BUTTON
@ BUTTON
Definition: object.h:212
timeofday_t::year
int year
Definition: tod.h:39
RUNATT
#define RUNATT
Run but attack if player catches up to object.
Definition: define.h:487
AT_ELECTRICITY
#define AT_ELECTRICITY
Definition: attack.h:79
PACEV2
#define PACEV2
The monster will pace as above but the length of the pace area is longer and the monster stops before...
Definition: define.h:520
TRIGGER_PEDESTAL
@ TRIGGER_PEDESTAL
Definition: object.h:139
NDI_GREEN
#define NDI_GREEN
SeaGreen.
Definition: newclient.h:252
KEY
@ KEY
Definition: object.h:132
EVENT_GBOUGHT
#define EVENT_GBOUGHT
Player bought object in shop, but global.
Definition: events.h:57
CFPContext::third
PyObject * third
Definition: cfpython.h:98
Crossfire_Object
Definition: cfpython_object.h:32
timeofday_t::weekofmonth
int weekofmonth
Definition: tod.h:45
c
static event_registration c
Definition: citylife.cpp:422
AT_PHYSICAL
#define AT_PHYSICAL
Definition: attack.h:76
postInitPlugin
CF_PLUGIN int postInitPlugin(void)
Plugin was initialized, now to finish.
Definition: cfpython.cpp:1671
eventListener
CF_PLUGIN int eventListener(int *type,...)
Handles an object-related event.
Definition: cfpython.cpp:1881
SHOP_FLOOR
@ SHOP_FLOOR
Definition: object.h:188
GEM
@ GEM
Definition: object.h:172
cf_create_object_by_name
object * cf_create_object_by_name(const char *name)
Wrapper for create_archetype() and create_archetype_by_object_name().
Definition: plugin_common.cpp:1093
HITRUN
#define HITRUN
Run to then hit player then run away cyclicly.
Definition: define.h:488
HOURS_PER_DAY
#define HOURS_PER_DAY
Definition: tod.h:15
TRAP
@ TRAP
Definition: object.h:246
setPlayerMessage
static PyObject * setPlayerMessage(PyObject *self, PyObject *args)
Definition: cfpython.cpp:699
CFPythonError
static PyObject * CFPythonError
Definition: cfpython.cpp:90
player::ob
object * ob
The object representing the player.
Definition: player.h:177
ARMOUR
@ ARMOUR
Definition: object.h:125
SVN_REV
#define SVN_REV
Definition: svnversion.h:2
popContext
static CFPContext * popContext(void)
Definition: cfpython.cpp:832
WEAPON
@ WEAPON
Definition: object.h:124
TIMED_GATE
@ TIMED_GATE
Definition: object.h:133
timeofday_t
Represents the ingame time.
Definition: tod.h:38
EVENT_TIMER
#define EVENT_TIMER
Timer connected triggered it.
Definition: events.h:35
getPrivateDictionary
static PyObject * getPrivateDictionary(PyObject *self, PyObject *args)
Definition: cfpython.cpp:362
CFPContext::activator
PyObject * activator
Definition: cfpython.h:97
cf_timer_destroy
int cf_timer_destroy(int id)
Destroys specified timer, equivalent of calling cftimer_destroy().
Definition: plugin_common.cpp:1620
ATNR_SLOW
#define ATNR_SLOW
Definition: attack.h:60
time
non standard information is not specified or uptime this means how long since the executable has been started A particular host may have been running a server for quite a long time
Definition: arch-handbook.txt:206
CFAPI_SYSTEM_ARCHETYPES
#define CFAPI_SYSTEM_ARCHETYPES
Definition: plugin.h:287
AMULET
@ AMULET
Definition: object.h:144
CHECK_INV
@ CHECK_INV
b.t.
Definition: object.h:174
getConfigDirectory
static PyObject * getConfigDirectory(PyObject *self, PyObject *args)
Definition: cfpython.cpp:269
initPlugin
int initPlugin(const char *iversion, f_plug_api gethooksptr)
Plugin initialisation function.
Definition: cfpython.cpp:1495
ATNR_GODPOWER
#define ATNR_GODPOWER
Definition: attack.h:69
TREASURE
@ TREASURE
Definition: object.h:115
EVENT_MAPLOAD
#define EVENT_MAPLOAD
A map is loaded (pristine state)
Definition: events.h:48
NDI_ALL_DMS
#define NDI_ALL_DMS
Inform all logged in DMs.
Definition: newclient.h:267
Crossfire_Party_wrap
PyObject * Crossfire_Party_wrap(partylist *what)
Definition: cfpython_party.cpp:61
SKILL
@ SKILL
Also see SKILL_TOOL (74) below.
Definition: object.h:148
flags
static const flag_definition flags[]
Flag mapping.
Definition: gridarta-types-convert.cpp:101
RUNE
@ RUNE
Definition: object.h:245
createCFObject
static PyObject * createCFObject(PyObject *self, PyObject *args)
Definition: cfpython.cpp:142
ATNR_DISEASE
#define ATNR_DISEASE
Definition: attack.h:74
registerCommand
static PyObject * registerCommand(PyObject *self, PyObject *args)
Definition: cfpython.cpp:500
pycode_cache
static pycode_cache_entry pycode_cache[PYTHON_CACHE_SIZE]
Cached compiled scripts.
Definition: cfpython.cpp:88
AT_INTERNAL
#define AT_INTERNAL
Definition: attack.h:99
NDI_RED
#define NDI_RED
Definition: newclient.h:248
CREATOR
@ CREATOR
Definition: object.h:147
EVENT_LOGOUT
#define EVENT_LOGOUT
Player logout.
Definition: events.h:45
NDI_NAVY
#define NDI_NAVY
Definition: newclient.h:247
RANDO
#define RANDO
The monster will go in a random direction until it is stopped by an obstacle, then it chooses another...
Definition: define.h:514
pushContext
static void pushContext(CFPContext *context)
Definition: cfpython.cpp:822
COMMAND_TYPE_NORMAL
#define COMMAND_TYPE_NORMAL
Standard commands.
Definition: commands.h:35
llevMonster
@ llevMonster
Many many details.
Definition: logger.h:14
EVENT_SAY
#define EVENT_SAY
Someone speaks.
Definition: events.h:29
TRANSPORT
@ TRANSPORT
see doc/Developers/objects
Definition: object.h:113
ATNR_PHYSICAL
#define ATNR_PHYSICAL
Definition: attack.h:49
POTION_RESIST_EFFECT
@ POTION_RESIST_EFFECT
A force, holding the effect of a resistance potion.
Definition: object.h:230
FLOOR
@ FLOOR
Floor tile -> native layer 0.
Definition: object.h:191
SIGN
@ SIGN
Definition: object.h:216
CFAPI_SYSTEM_PLAYERS
#define CFAPI_SYSTEM_PLAYERS
Definition: plugin.h:286
NAME_MAX
#define NAME_MAX
NAME_MAX used by random maps may not be defined on pure ansi systems.
Definition: define.h:30
ATNR_TURN_UNDEAD
#define ATNR_TURN_UNDEAD
Definition: attack.h:62
TRIGGER_BUTTON
@ TRIGGER_BUTTON
Definition: object.h:137
getEventFiles
static char ** getEventFiles(CFPContext *context)
Get the list of script files to run for the specified global event context.
Definition: cfpython.cpp:1628
friends
static std::vector< std::pair< object *, tag_t > > friends
List of all friendly objects, object and its count.
Definition: friend.cpp:23
CFPContext::down
CFPContext * down
Definition: cfpython.h:95
Handle_Map_Unload_Hook
void Handle_Map_Unload_Hook(Crossfire_Map *map)
Definition: cfpython_map.cpp:430
NDI_BLUE
#define NDI_BLUE
Actually, it is Dodger Blue.
Definition: newclient.h:250
current_context
CFPContext * current_context
Definition: cfpython.cpp:106
POWER_CRYSTAL
@ POWER_CRYSTAL
Definition: object.h:247
WEEKS_PER_MONTH
#define WEEKS_PER_MONTH
Definition: tod.h:17
AT_LIFE_STEALING
#define AT_LIFE_STEALING
Definition: attack.h:100
buf
StringBuffer * buf
Definition: readable.cpp:1565
HUGE_BUF
#define HUGE_BUF
Used for messages - some can be quite long.
Definition: define.h:37
PACEH
#define PACEH
The monster will pace back and forth until attacked.
Definition: define.h:508
POISONING
@ POISONING
Definition: object.h:223
AT_DEATH
#define AT_DEATH
Definition: attack.h:93
ATNR_CONFUSION
#define ATNR_CONFUSION
Definition: attack.h:54
Crossfire_Object_wrap
PyObject * Crossfire_Object_wrap(object *what)
Python initialized.
Definition: cfpython_object.cpp:1613
cstMessageFlag
const CFConstant cstMessageFlag[]
Definition: cfpython.cpp:1251
ATNR_HOLYWORD
#define ATNR_HOLYWORD
Definition: attack.h:70
name
Plugin animator file specs[Config] name
Definition: animfiles.txt:4
NDI_ORANGE
#define NDI_ORANGE
Definition: newclient.h:249
talk_info::message
sstring message
If not NULL, what the player will be displayed as said.
Definition: dialog.h:53
talk_info::replies_count
int replies_count
How many items in replies_words and replies.
Definition: dialog.h:55
cf_system_get_region_vector
void cf_system_get_region_vector(int property, std::vector< region * > *list)
Definition: plugin_common.cpp:2140
getDataDirectory
static PyObject * getDataDirectory(PyObject *self, PyObject *args)
Definition: cfpython.cpp:287
TRIGGER_MARKER
@ TRIGGER_MARKER
inserts an invisible, weightless force into a player with a specified string WHEN TRIGGERED.
Definition: object.h:158
Crossfire_PlayerType
PyTypeObject Crossfire_PlayerType
ATNR_BLIND
#define ATNR_BLIND
Definition: attack.h:71
CFPContext::who
PyObject * who
Definition: cfpython.h:96
m
static event_registration m
Definition: citylife.cpp:422
getPluginProperty
CF_PLUGIN void * getPluginProperty(int *type,...)
Gets a plugin property.
Definition: cfpython.cpp:1539
AT_CHAOS
#define AT_CHAOS
Definition: attack.h:94
CLOAK
@ CLOAK
Definition: object.h:209
timeofday_t::day
int day
Definition: tod.h:41
pycode_cache_entry::cached_time
time_t cached_time
Time this cache entry was created.
Definition: cfpython.cpp:80
opendir
DIR * opendir(const char *)
EVENT_LOGIN
#define EVENT_LOGIN
Player login.
Definition: events.h:44
HELMET
@ HELMET
Definition: object.h:141
POISON
@ POISON
Definition: object.h:118
files
the server will also quite happily load unpacked files as long as they have the right file which is convenient if you want to edit your maps and archetypes live It also contains a few files
Definition: server-directories.txt:53
setReturnValue
static PyObject * setReturnValue(PyObject *self, PyObject *args)
Definition: cfpython.cpp:179
cf_log_plain
void cf_log_plain(LogLevel logLevel, const char *message)
Wrapper for LOG() that uses directly a buffer, without format.
Definition: plugin_common.cpp:1542
EVENT_STOP
#define EVENT_STOP
Thrown object stopped.
Definition: events.h:31
EVENT_CLOCK
#define EVENT_CLOCK
Global time event.
Definition: events.h:40
getArchetypes
static PyObject * getArchetypes(PyObject *self, PyObject *args)
Definition: cfpython.cpp:384
DEEP_SWAMP
@ DEEP_SWAMP
Definition: object.h:241
MARKER
@ MARKER
inserts an invisible, weightless force into a player with a specified string.
Definition: object.h:163
getMapHasBeenLoaded
static PyObject * getMapHasBeenLoaded(PyObject *self, PyObject *args)
Definition: cfpython.cpp:571
GEPaths
static const char * GEPaths[]
Definition: cfpython.cpp:1587
EVENT_PICKUP
#define EVENT_PICKUP
Object picked up.
Definition: events.h:28
EVENT_CRASH
#define EVENT_CRASH
Triggered when the server crashes.
Definition: events.h:41
getMapDirectory
static PyObject * getMapDirectory(PyObject *self, PyObject *args)
Definition: cfpython.cpp:251
SAVEBED
@ SAVEBED
Definition: object.h:224
EVENT_SELLING
#define EVENT_SELLING
Object is being sold by another one.
Definition: events.h:30
AT_COLD
#define AT_COLD
Definition: attack.h:80
CF_PLUGIN
#define CF_PLUGIN
Definition: plugin_common.h:38
SEASONS_PER_YEAR
#define SEASONS_PER_YEAR
Definition: tod.h:19
LIGHTABLE
@ LIGHTABLE
Definition: object.h:255
POTION
@ POTION
Definition: object.h:116
timeofday_t::periodofday
int periodofday
Definition: tod.h:47
MOVE_WALK
#define MOVE_WALK
Object walks.
Definition: define.h:392
cf_find_face
int cf_find_face(const char *name, int error)
Wrapper for find_face().
Definition: plugin_common.cpp:1510
BUILDER
@ BUILDER
Generic item builder, see subtypes below.
Definition: object.h:251
output
**Media tags please refer to the protocol file in doc Developers protocol Quick for your pleasure an example[/b][i] This is an old full of dirt and partially destroyed[hand] My dear as you two years i had to leave quickly Words have come to me of powerful magic scrolls discovered in an old temple by my uncle I have moved to study them I not forgot your knowledge in ancient languages I need your help for[print][b] Some parts of document are to damaged to be readable[/b][arcane] Arghis[color=Red] k h[color=dark slate blue] ark[color=#004000] fido[/color][hand] please come as fast as possible my friend[print][b] The bottom of letter seems deliberatly shredded What is but not limited book signs rules Media tags are made of with inside them the name of tag and optional parameters for the tag Unlike html or there is no notion of opening and closing tag A client not able to understand a tag is supposed to ignore it when server is communicating with and old client that does not understand a a specific extended it will issue a classical message output
Definition: media-tags.txt:36
EVENT_DROP
#define EVENT_DROP
Object dropped on the floor.
Definition: events.h:27
findFace
static PyObject * findFace(PyObject *self, PyObject *args)
Definition: cfpython.cpp:580
EVENT_TRIGGER
#define EVENT_TRIGGER
Button pushed, lever pulled, etc.
Definition: events.h:34
f_plug_api
void(* f_plug_api)(int *type,...)
General API function.
Definition: plugin.h:79
EVENT_MAPENTER
#define EVENT_MAPENTER
A player entered a map.
Definition: events.h:46
cstDirection
const CFConstant cstDirection[]
Definition: cfpython.cpp:1112
CFPContext
Definition: cfpython.h:94
npcSay
static PyObject * npcSay(PyObject *self, PyObject *args)
Definition: cfpython.cpp:722
cf_system_unregister_global_event
void cf_system_unregister_global_event(int event, const char *name)
Definition: plugin_common.cpp:1109
cf_get_month_name
const char * cf_get_month_name(int index)
Definition: plugin_common.cpp:1565
cf_init_plugin
int cf_init_plugin(f_plug_api getHooks)
Definition: plugin_common.cpp:146
ROD
@ ROD
Definition: object.h:114
CONTAINER
@ CONTAINER
Definition: object.h:236
INORGANIC
@ INORGANIC
metals, minerals, dragon scales
Definition: object.h:193
readdir
struct dirent * readdir(DIR *)
cf_get_empty_map
mapstruct * cf_get_empty_map(int sizex, int sizey)
Wrapper for get_empty_map().
Definition: plugin_common.cpp:948
LOCKED_DOOR
@ LOCKED_DOOR
Definition: object.h:128
PLAYERMOVER
@ PLAYERMOVER
Definition: object.h:145
PLUGIN_NAME
#define PLUGIN_NAME
Definition: cfanim.h:32
unregisterGEvent
static PyObject * unregisterGEvent(PyObject *self, PyObject *args)
Definition: cfpython.cpp:129
EVENT_MAPRESET
#define EVENT_MAPRESET
A map is resetting.
Definition: events.h:50
cfpython.h
pycode_cache_entry::code
PyCodeObject * code
Compiled code, NULL if there was an error.
Definition: cfpython.cpp:79
addSimpleConstants
static void addSimpleConstants(PyObject *module, const char *name, const CFConstant *constants)
Do half the job of addConstants.
Definition: cfpython.cpp:1096
SPECIAL_KEY
@ SPECIAL_KEY
Definition: object.h:129
MOVE_FLYING
#define MOVE_FLYING
Combo of fly_low and fly_high.
Definition: define.h:395
HOLE
@ HOLE
Definition: object.h:214
costStringFromValue
static PyObject * costStringFromValue(PyObject *self, PyObject *args)
Definition: cfpython.cpp:752
PEACEMAKER
@ PEACEMAKER
Object owned by a player which can convert a monster into a peaceful being incapable of attack.
Definition: object.h:169
MAX_NPC
#define MAX_NPC
How many NPCs maximum will reply to the player.
Definition: dialog.h:45
CIRCLE2
#define CIRCLE2
Same as CIRCLE1 but a larger circle is used.
Definition: define.h:507
SvnRevPlugin
CF_PLUGIN char SvnRevPlugin[]
Definition: cfpython.cpp:69
do_script
static int do_script(CFPContext *context)
Definition: cfpython.cpp:1032
getSharedDictionary
static PyObject * getSharedDictionary(PyObject *self, PyObject *args)
Definition: cfpython.cpp:377
EVENT_BORN
#define EVENT_BORN
A new character has been created.
Definition: events.h:39
CONVERTER
@ CONVERTER
Definition: object.h:221
message
TIPS on SURVIVING Crossfire is populated with a wealth of different monsters These monsters can have varying immunities and attack types In some of them can be quite a bit smarter than others It will be important for new players to learn the abilities of different monsters and learn just how much it will take to kill them This section discusses how monsters can interact with players Most monsters in the game are out to mindlessly kill and destroy the players These monsters will help boost a player s after he kills them When fighting a large amount of monsters in a single attempt to find a narrower hallway so that you are not being attacked from all sides Charging into a room full of Beholders for instance would not be open the door and fight them one at a time For there are several maps designed for them Find these areas and clear them out All throughout these a player can find signs and books which they can read by stepping onto them and hitting A to apply the book sign These messages will help the player to learn the system One more always keep an eye on your food If your food drops to your character will soon so BE CAREFUL ! NPCs Non Player Character are special monsters which have intelligence Players may be able to interact with these monsters to help solve puzzles and find items of interest To speak with a monster you suspect to be a simply move to an adjacent square to them and push the double ie Enter your message
Definition: survival-guide.txt:34
GECodes
static int GECodes[]
Definition: cfpython.cpp:1564
EVENT_MAPUNLOAD
#define EVENT_MAPUNLOAD
A map is freed (includes swapping out)
Definition: events.h:51
SKILLSCROLL
@ SKILLSCROLL
can add a skill to player's inventory -bt.
Definition: object.h:239
createMap
static PyObject * createMap(PyObject *self, PyObject *args)
Definition: cfpython.cpp:238
set_exception
static void set_exception(const char *fmt,...)
Set up an Python exception object.
Definition: cfpython.cpp:93
ATNR_DRAIN
#define ATNR_DRAIN
Definition: attack.h:56
catcher
static PyObject * catcher
A Python object receiving the contents of Python's stderr, and used to output to the Crossfire log in...
Definition: cfpython.cpp:877
NDI_GOLD
#define NDI_GOLD
Definition: newclient.h:257
Crossfire_Archetype_wrap
PyObject * Crossfire_Archetype_wrap(archetype *what)
Definition: cfpython_archetype.cpp:62
DRAGON_FOCUS
@ DRAGON_FOCUS
Used during character creation.
Definition: object.h:121
rt_say
@ rt_say
Basic sentence.
Definition: dialog.h:8
LAMP
@ LAMP
Lamp.
Definition: object.h:206
getFriendlyList
static PyObject * getFriendlyList(PyObject *self, PyObject *args)
Definition: cfpython.cpp:456
timeofday_t::dayofweek
int dayofweek
Definition: tod.h:42
GOLEM
@ GOLEM
Definition: object.h:150
registered_commands
static command_registration registered_commands[MAX_COMMANDS]
Definition: cfpython.cpp:85
ATNR_COUNTERSPELL
#define ATNR_COUNTERSPELL
Definition: attack.h:68
closePlugin
CF_PLUGIN int closePlugin(void)
Close the plugin.
Definition: cfpython.cpp:1922
getPlayers
static PyObject * getPlayers(PyObject *self, PyObject *args)
Definition: cfpython.cpp:398
EVENT_USER
#define EVENT_USER
User-defined event.
Definition: events.h:36
MOOD_FLOOR
@ MOOD_FLOOR
b.t.
Definition: object.h:175
CFAPI_SYSTEM_MAPS
#define CFAPI_SYSTEM_MAPS
Definition: plugin.h:285
ATNR_POISON
#define ATNR_POISON
Definition: attack.h:59
ARROW
@ ARROW
Definition: object.h:122
EVENT_THROW
#define EVENT_THROW
Object is thrown.
Definition: events.h:33
ATNR_DEATH
#define ATNR_DEATH
Definition: attack.h:66
rt_reply
@ rt_reply
Reply to something.
Definition: dialog.h:9
PACEV
#define PACEV
The monster will pace back and forth until attacked.
Definition: define.h:518
BOOK
@ BOOK
Definition: object.h:119
CFPContext::message
char message[1024]
Definition: cfpython.h:100
Crossfire_Region_wrap
PyObject * Crossfire_Region_wrap(region *what)
Definition: cfpython_region.cpp:72
timeofday_t::month
int month
Definition: tod.h:40
RING
@ RING
Definition: object.h:190
CFAPI_SYSTEM_REGIONS
#define CFAPI_SYSTEM_REGIONS
Definition: plugin.h:288
EVENT_SHOUT
#define EVENT_SHOUT
A player 'shout' something.
Definition: events.h:55
BLINDNESS
@ BLINDNESS
Definition: object.h:152
timeofday_t::season
int season
Definition: tod.h:46
NDI_BLACK
#define NDI_BLACK
Definition: newclient.h:245
getUniqueDirectory
static PyObject * getUniqueDirectory(PyObject *self, PyObject *args)
Definition: cfpython.cpp:257
matchString
static PyObject * matchString(PyObject *self, PyObject *args)
Definition: cfpython.cpp:190
CLOCK
@ CLOCK
Definition: object.h:120
cf_free_string
void cf_free_string(sstring str)
Wrapper for free_string().
Definition: plugin_common.cpp:1182
cstTime
const CFConstant cstTime[]
Definition: cfpython.cpp:1375
d
How to Install a Crossfire Server on you must install a python script engine on your computer Python is the default script engine of Crossfire You can find the python engine you have only to install them The VisualC Crossfire settings are for d
Definition: INSTALL_WIN32.txt:13
SHOP_MAT
@ SHOP_MAT
Definition: object.h:189
EVENT_BOUGHT
#define EVENT_BOUGHT
Object is being bought by player.
Definition: events.h:23
COMMAND_TYPE_WIZARD
#define COMMAND_TYPE_WIZARD
Wizard-only commands.
Definition: commands.h:39
path
pluglist shows those as well as a short text describing each the list will simply appear empty The keyword for the Python plugin is Python plugout< keyword > Unloads a given identified by its _keyword_ So if you want to unload the Python you need to do plugout Python plugin< libname > Loads a given whose _filename_ is libname So in the case of you d have to do a plugin cfpython so Note that all filenames are relative to the default plugin path(SHARE/plugins). Console messages. ----------------- When Crossfire starts
destroyTimer
static PyObject * destroyTimer(PyObject *self, PyObject *args)
Definition: cfpython.cpp:562
CFPContext::talk
struct talk_info * talk
Definition: cfpython.h:105
MOVE_FLY_LOW
#define MOVE_FLY_LOW
Low flying object.
Definition: define.h:393
EVENT_PLAYER_DEATH
#define EVENT_PLAYER_DEATH
Global Death event
Definition: events.h:53
ATNR_FIRE
#define ATNR_FIRE
Definition: attack.h:51
cfpython_pyfile_asfile
static FILE * cfpython_pyfile_asfile(PyObject *obj)
Return a file object from a Python file (as needed for compilePython() and postInitPlugin())
Definition: cfpython.cpp:869
cstType
const CFConstant cstType[]
Definition: cfpython.cpp:1124
cf_system_register_command_extra
command_registration cf_system_register_command_extra(const char *name, const char *extra, command_function_extra func, uint8_t command_type, float time)
Definition: plugin_common.cpp:2103
EXIT
@ EXIT
Definition: object.h:186
getPlayerDirectory
static PyObject * getPlayerDirectory(PyObject *self, PyObject *args)
Definition: cfpython.cpp:281
MAGIC_EAR
@ MAGIC_EAR
Definition: object.h:136
MONTHS_PER_YEAR
#define MONTHS_PER_YEAR
Definition: tod.h:18
getWeekdayName
static PyObject * getWeekdayName(PyObject *self, PyObject *args)
Definition: cfpython.cpp:653
PLUGIN_VERSION
#define PLUGIN_VERSION
Definition: cfanim.h:33
getMaps
static PyObject * getMaps(PyObject *self, PyObject *args)
Definition: cfpython.cpp:413
cstReplyTypes
const CFConstant cstReplyTypes[]
Definition: cfpython.cpp:1385
cf_system_get_object_vector
void cf_system_get_object_vector(int property, std::vector< object * > *list)
Definition: plugin_common.cpp:2116
replace
void replace(const char *src, const char *key, const char *replacement, char *result, size_t resultsize)
Replace in string src all occurrences of key by replacement.
Definition: utils.cpp:327
reply_type
reply_type
Various kind of messages a player or NPC can say.
Definition: dialog.h:7
cf_system_register_global_event
void cf_system_register_global_event(int event, const char *name, f_plug_event hook)
Definition: plugin_common.cpp:1102
llevInfo
@ llevInfo
Information.
Definition: logger.h:12
talk_info::message_type
reply_type message_type
A reply_type value for message.
Definition: dialog.h:54
cfpython_openpyfile
static PyObject * cfpython_openpyfile(char *filename)
Open a file in the way we need it for compilePython() and postInitPlugin().
Definition: cfpython.cpp:855
getTempDirectory
static PyObject * getTempDirectory(PyObject *self, PyObject *args)
Definition: cfpython.cpp:263
pycode_cache_entry::file
sstring file
Script full path.
Definition: cfpython.cpp:78
NDI_UNIQUE
#define NDI_UNIQUE
Print immediately, don't buffer.
Definition: newclient.h:265
EVENT_MUZZLE
#define EVENT_MUZZLE
A player was Muzzled (no_shout set).
Definition: events.h:52
cf_find_animation
int cf_find_animation(const char *txt)
Wrapper for find_animation().
Definition: plugin_common.cpp:1498
maps
this information may not reflect the current implementation This brief document is meant to describe the operation of the crossfire as well as the form of the data The metaserver listens on port for tcp and on port for udp packets The server sends updates to the metaserver via udp The metaserver only does basic checking on the data that server sends It trusts the server for the ip name it provides The metaserver does add the ip address and also tracks the idle time(time since last packet received). The client gets its information from the metaserver through connecting by means of tcp. The client should retrieve http the body s content type is text plain The current metaserver implementation is in Perl But the metaserver could be in any language perl is fast enough for the amount of data that is being exchanged The response includes zero or more server entries Each entry begins with the line START_SERVER_DATA and ends with the line END_SERVER_DATA Between these lines key value pairs("key=value") may be present. The entries are sent in arbitrary order. A client should apply some ordering when displaying the entries to the user. TODO b additional information outside BEGIN_SERVER_DATA END_SERVER_DATA maps
Definition: arch-handbook.txt:189
object::slaying
sstring slaying
Which race to do double damage to.
Definition: object.h:327
MAX_COMMANDS
#define MAX_COMMANDS
Definition: cfpython.cpp:84
AT_BLIND
#define AT_BLIND
Definition: attack.h:98
getReturnValue
static PyObject * getReturnValue(PyObject *self, PyObject *args)
Definition: cfpython.cpp:173
CFPythonMethods
PyMethodDef CFPythonMethods[]
Definition: cfpython.cpp:765
EVENT_TELL
#define EVENT_TELL
A player 'tell' something.
Definition: events.h:56
ATNR_CHAOS
#define ATNR_CHAOS
Definition: attack.h:67
EVENT_DEATH
#define EVENT_DEATH
Player or monster dead.
Definition: events.h:25
object::name
sstring name
The name of the object, obviously...
Definition: object.h:319
BATTLEGROUND
@ BATTLEGROUND
battleground, by Andreas Vogl
Definition: object.h:168
Crossfire_PartyType
PyTypeObject Crossfire_PartyType
AT_SLOW
#define AT_SLOW
Definition: attack.h:87
CFAPI_SYSTEM_FRIENDLY_LIST
#define CFAPI_SYSTEM_FRIENDLY_LIST
Definition: plugin.h:290
CFConstant
Definition: cfpython.h:108
MAX_REPLIES
#define MAX_REPLIES
How many NPC replies maximum to tell the player.
Definition: dialog.h:43
players
std::vector< archetype * > players
Definition: player.cpp:501
AT_TURN_UNDEAD
#define AT_TURN_UNDEAD
Definition: attack.h:89
cf_get_periodofday_name
const char * cf_get_periodofday_name(int index)
Definition: plugin_common.cpp:1583
getWhatIsMessage
static PyObject * getWhatIsMessage(PyObject *self, PyObject *args)
Definition: cfpython.cpp:326
GRIMREAPER
@ GRIMREAPER
Definition: object.h:135
getScriptName
static PyObject * getScriptName(PyObject *self, PyObject *args)
Definition: cfpython.cpp:335
ATNR_DEPLETE
#define ATNR_DEPLETE
Definition: attack.h:65
timeofday_t::minute
int minute
Definition: tod.h:44
CrossfireModule
static PyModuleDef CrossfireModule
Definition: cfpython.cpp:1475
EARTHWALL
@ EARTHWALL
Definition: object.h:149
python_command_function
static void python_command_function(object *op, const char *params, const char *script)
Definition: cfpython.cpp:470
DUPLICATOR
@ DUPLICATOR
Duplicator/multiplier object.
Definition: object.h:207
DISEASE
@ DISEASE
Definition: object.h:249
FIREWALL
@ FIREWALL
Definition: object.h:173
TRIGGER_ALTAR
@ TRIGGER_ALTAR
Definition: object.h:138
getGlobalEventPath
static const char * getGlobalEventPath(int code)
Definition: cfpython.cpp:1698
PLAYER_CHANGER
@ PLAYER_CHANGER
Definition: object.h:167
mapstruct
This is a game-map.
Definition: map.h:315
cf_system_get_map_vector
void cf_system_get_map_vector(int property, std::vector< mapstruct * > *list)
Definition: plugin_common.cpp:2122
createCFObjectByName
static PyObject * createCFObjectByName(PyObject *self, PyObject *args)
Definition: cfpython.cpp:152
cstAttackType
const CFConstant cstAttackType[]
Definition: cfpython.cpp:1271
sstring
const typedef char * sstring
Definition: sstring.h:2
LIGHTER
@ LIGHTER
Definition: object.h:195
rt_question
@ rt_question
Asking a question.
Definition: dialog.h:10
PERIODS_PER_DAY
#define PERIODS_PER_DAY
Definition: tod.h:20
NDI_ALL
#define NDI_ALL
Inform all players of this message.
Definition: newclient.h:266
cstAttackTypeNumber
const CFConstant cstAttackTypeNumber[]
Definition: cfpython.cpp:1301
AT_DEPLETE
#define AT_DEPLETE
Definition: attack.h:92
Crossfire_ArchetypeType
PyTypeObject Crossfire_ArchetypeType
cf_map_has_been_loaded
mapstruct * cf_map_has_been_loaded(const char *name)
Wrapper for has_been_loaded().
Definition: plugin_common.cpp:961
MATERIAL
@ MATERIAL
Material for building.
Definition: object.h:253
EVENT_TIME
#define EVENT_TIME
Triggered each time the object can react/move.
Definition: events.h:32
cf_re_cmp
const char * cf_re_cmp(const char *str, const char *regexp)
Wrapper for re_cmp().
Definition: plugin_common.cpp:1143
EVENT_MAPLEAVE
#define EVENT_MAPLEAVE
A player left a map.
Definition: events.h:47
SPINNER
@ SPINNER
Definition: object.h:210
getRegions
static PyObject * getRegions(PyObject *self, PyObject *args)
Definition: cfpython.cpp:442
AT_WEAPONMAGIC
#define AT_WEAPONMAGIC
Definition: attack.h:84
SPELL_EFFECT
@ SPELL_EFFECT
Definition: object.h:220
readyMap
static PyObject * readyMap(PyObject *self, PyObject *args)
Definition: cfpython.cpp:224
SKILL_TOOL
@ SKILL_TOOL
Allows the use of a skill.
Definition: object.h:194
getParties
static PyObject * getParties(PyObject *self, PyObject *args)
Definition: cfpython.cpp:428
timeofday_t::hour
int hour
Definition: tod.h:43
ATNR_MAGIC
#define ATNR_MAGIC
Definition: attack.h:50
SHOP_INVENTORY
@ SHOP_INVENTORY
Mark Wedel (mark@pyramid.com) Shop inventories.
Definition: object.h:243
NDI_WHITE
#define NDI_WHITE
Definition: newclient.h:246
PEDESTAL
@ PEDESTAL
Definition: object.h:126
cf_create_object
object * cf_create_object(void)
Wrapper for object_new().
Definition: plugin_common.cpp:1081
cf_get_maps_directory
char * cf_get_maps_directory(const char *name, char *buf, int size)
Wrapper for create_pathname().
Definition: plugin_common.cpp:1069
NDI_BROWN
#define NDI_BROWN
Sienna.
Definition: newclient.h:256
talk_info
Structure used to build up dialog information when a player says something.
Definition: dialog.h:50
NDI_TAN
#define NDI_TAN
Khaki.
Definition: newclient.h:258
EVENT_REMOVE
#define EVENT_REMOVE
A Player character has been removed.
Definition: events.h:54
freeEventFiles
static void freeEventFiles(char **eventFiles)
Clear the list of event files.
Definition: cfpython.cpp:1615
cfpython_init_types
static void cfpython_init_types(PyObject *m)
Set up the various types (map, object, archetype and so on) as well as some constants,...
Definition: cfpython.cpp:1434
regions
static std::unordered_map< std::string, Region * > regions
All defined regions.
Definition: cfcitybell.cpp:42
CFPContext::event
PyObject * event
Definition: cfpython.h:99
NDI_DK_ORANGE
#define NDI_DK_ORANGE
DarkOrange2.
Definition: newclient.h:251
addReply
static PyObject * addReply(PyObject *self, PyObject *args)
Definition: cfpython.cpp:671
level
int level
Definition: readable.cpp:1563
pycode_cache_entry
One compiled script, cached in memory.
Definition: cfpython.cpp:77
initConstants
static void initConstants(PyObject *module)
Definition: cfpython.cpp:1413
data
====Textual A command containing textual data has data fields separated by one ASCII space character. word::A sequence of ASCII characters that does not contain the space or nul character. This is to distinguish it from the _string_, which may contain space characters. Not to be confused with a machine word. int::A _word_ containing the textual representation of an integer. Not to be confused with any of the binary integers in the following section. Otherwise known as the "string value of integer data". Must be parsed, e.g. using `atoi()` to get the actual integer value. string::A sequence of ASCII characters. This must only appear at the end of a command, since spaces are used to separate fields of a textual message.=====Binary All multi-byte integers are transmitted in network byte order(MSB first). int8::1-byte(8-bit) integer int16::2-byte(16-bit) integer int32::4-byte(32-bit) integer lstring::A length-prefixed string, which consists of an `int8` followed by that many bytes of the actual string. This is used to transmit a string(that may contain spaces) in the middle of binary data. l2string::Like _lstring_, but is prefixed with an `int16` to support longer strings Implementation Notes ~~~~~~~~~~~~~~~~~~~~ - Typical implementations read two bytes to determine the length of the subsequent read for the actual message, then read and parse the data from each message according to the commands described below. To send a message, the sender builds the message in a buffer, counts the length of the message, sends the length, and finally sends the actual message. TIP:Incorrectly transmitting or receiving the `length` field can lead to apparent "no response" issues as the client or server blocks to read the entire length of the message. - Since the protocol is highly interactive, it may be useful to set `TCP_NODELAY` on both the client and server. - If you are using a language with a buffered output stream, remember to flush the stream after a complete message. - If the connection is lost(which will also happen if the output buffer overflowing), the player is saved and the server cleans up. This does open up some abuses, but there is no perfect solution here. - The server only reads data from the socket if the player has an action. This isn 't really good, since many of the commands below might not be actual commands for the player. The alternative is to look at the data, and if it is a player command and there isn 't time, store it away to be processed later. But this increases complexity, in that the server must start buffering the commands. Fortunately, for now, there are few such client commands. Commands -------- In the documentation below, `S->C` represents a message to the client from the server, and `C->S` represents a message to the server from the client. Commands are documented in a brief format like:C->S:version< csval >[scval[vinfo]] Fields are enclosed like `< this >`. Optional fields are denoted like `[this]`. Spaces that appear in the command are literal, i.e. the<< _version > > command above uses spaces to separate its fields, but the command below does not:C->S:accountlogin< name >< password > As described in<< _messages > >, if a command contains data, then the command is separated from the data by a literal space. Many of the commands below refer to 'object tags'. Whenever the server creates an object, it creates a unique tag for that object(starting at 1 when the server is first run, and ever increasing.) Tags are unique, but are not consistent between runs. Thus, the client can not store tags when it exits and hope to re-use them when it joins the server at a later time - tags are only valid for the current connection. The protocol commands are broken into various sections which based somewhat on what the commands are for(ie, item related commands, map commands, image commands, etc.) In this way, all the commands related to similar functionality is in the same place. Initialization ~~~~~~~~~~~~~~ version ^^^^^^^ C->S:version< csval >[scval[vinfo]] S->C:version< csval >[scval[vinfo]] Used by the client and server to exchange which version of the Crossfire protocol they understand. Neither send this in response to the other - they should both send this shortly after a connection is established. csval::int, version level of C->S communications scval::int, version level of S->C communications vinfo::string, that is purely for informative that general client/server info(ie, javaclient, x11client, winclient, sinix server, etc). It is purely of interest of server admins who can see what type of clients people are using.=====Version ID If a new command is added to the protocol in the C->S direction, then the version number in csval will get increased. Likewise, the same is true for the scval. The version are currently integers, in the form ABCD. A=1, and will likely for quite a while. This will only really change if needed from rollover of B. B represents major protocol changes - if B mismatches, the clients will be totally unusable. Such an example would be change of map or item sending commands(either new commands or new format.) C represents more minor but still significant changes - clients might still work together, but some features that used to work may now fail due to the mismatch. An example may be a change in the meaning of some field in some command - providing the field is the same size, it still should be decoded properly, but the meaning won 't be processed properly. D represents very minor changes or new commands. Things should work no worse if D does not match, however if they do match, some new features might be included. An example of the would be the C->S mark command to mark items. Server not understanding this just means that the server can not process it, and will ignore it.=====Handling As far as the client is concerned, its _scval_ must be at least equal to the server, and its _csval_ should not be newer than the server. The server does not care about the version command it receives right now - all it currently does is log mismatches. In theory, the server should keep track of what the client has, and adjust the commands it sends respectively in the S->C direction. The server is resilant enough that it won 't crash with a version mismatch(however, client may end up sending commands that the server just ignores). It is really up to the client to enforce versioning and quit if the versions don 't match. NOTE:Since all packets have the length as the first 2 bytes, all that either the client or server needs to be able to do is look at the first string and see if it understands it. If not, it knows how many bytes it can skip. As such, exact version matches should not be necessary for proper operation - however, both the client and server needs to be coded to handle such cases.=====History _scval_ and _vinfo_ were added in version 1020. Before then, there was only one version sent in the version command. NOTE:For the most part, this has been obsoleted by the setup command which always return status and whether it understood the command or not. However there are still some cases where using this versioning is useful - an example it the addition of the requestinfo/replyinfo commands - the client wants to wait for acknowledge of all the replyinfo commands it has issued before sending the addme command. However, if the server doesn 't understand these options, the client will never get a response. With the versioning, the client can look at the version and know if it should wait for a response or if the server will never send back. setup ^^^^^ C->S, S->C:setup< option1 >< value1 >< option2 >< value2 > ... Sent by the client to request protocol option changes. This can be at any point during the life of a connection, but usually sent at least once right after the<< _version > > command. The server responds with a message in the same format confirming what configuration options were set. The server only sends a setup command in response to one from the client. The sc_version should be updated in the server if commands have been obsoleted such that old clients may not be able to play. option::word, name of configuration option value::word, value of configuration option. May need further parsing according to the setup options below=====Setup Options There are really 2 set of setup commands here:. Those that control preferences of the client(how big is the map, what faceset to use, etc). . Those that describe capabilities of the client(client supports this protocol command or that) .Setup Options[options="autowidth,header"]|===========================|Command|Description|beat|Ask the server to enable heartbeat support. When heartbeat is enabled, the client must send the server a command every three seconds. If no commands need to be sent, use the `beat` no-op command. Clients that do not contact the server within the interval are assumed to have a temporary connection failure.|bot(0/1 value)|If set to 1, the client will not be considered a player when updating information to the metaserver. This is to avoid having a server with many bots appear more crowded than others.|darkness(0/1 value)|If set to 1(default), the server will send darkness information in the map protocol commands. If 0, the server will not include darkness, thus saving a minor amount of bandwidth. Since the client is free to ignore the darkness information, this does not allow the client to cheat. In the case of the old 'map' protocol command, turning darkness off will result in the masking faces not getting sent to the client.|extended_stats(0/1 value)|If set to 1, the server will send the CS_STAT_RACE_xxx and CS_STAT_BASE_xxx values too, so the client can display various status related to statistics. Default is 0.|facecache(0/1)|Determines if the client is caching images(1) or wants the images sent to it without caching them(0). Default is 0. This replaces the setfacemode command.|faceset(8 bit)|Faceset the client wishes to use. If the faceset is not valid, the server returns the faceset the client will be using(default 0).|loginmethod(8 bit)|Client sends this to server to note login support. This is basically used as a subset of the csversion/scversion to find out what level of login support the server and client support. Current defined values:0:no advanced support - only legacy login method 1:account based login(described more below) 2:new character creation support This list may grow - for example, advanced character creation could become a feature.|map2cmd:(1)|This indicates client support for the map2 protocol command. See the map2 protocol details above for the main differences. Obsolete:This is the only supported mode now, but many clients use it as a sanity check for protocol versions, so the server still replies. It doesn 't do anything with the data|mapsize(int x) X(int y)|Sets the map size to x X y. Note the spaces here are only for clarity - there should be no spaces when actually sent(it should be 11x11 or 25x25). The default map size unless changed is 11x11. The minimum map size the server will allow is 9x9(no technical reason this could be smaller, but I don 't think the game would be smaller). The maximum map size supported in the current protocol is 63x63. However, each server can have its maximum map size sent to most any value. If the client sends an invalid mapsize command or a mapsize of 0x0, the server will respond with a mapsize that is the maximum size the server supports. Thus, if the client wants to know the maximum map size, it can just do a 'mapsize 0x0' or 'mapsize' and it will get the maximum size back. The server will constrain the provided mapsize x &y to the configured minumum and maximums. For example, if the maximum map size is 25x25, the minimum map size is 9x9, and the client sends a 31x7 mapsize request, the mapsize will be set to 25x9 and the server will send back a mapsize 25x9 setup command. When the values are valid, the server will send back a mapsize XxY setup command. Note that this is from its parsed values, so it may not match stringwise with what the client sent, but will match 0 wise. For example, the client may send a 'mapsize 025X025' command, in which case the server will respond with a 'mapsize 25x25' command - the data is functionally the same. The server will send an updated map view when this command is sent.|notifications(int value)|Value indicating what notifications the client accepts. It is incremental, a value means "all notifications till this level". The following levels are supported:1:quest-related notifications("addquest" and "updquest") 2:knowledge-related notifications("addknowledge") 3:character status flags(overloaded, blind,...)|num_look_objects(int value)|The maximum number of objects shown in the ground view. If more objects are present, fake objects are created for selecting the previous/next group of items. Defaults to 50 if not set. The server may adjust the given value to a suitable one data
Definition: protocol.txt:379
DEAD_OBJECT
@ DEAD_OBJECT
Definition: object.h:161
ATNR_WEAPONMAGIC
#define ATNR_WEAPONMAGIC
Definition: attack.h:57
DIRECTOR
@ DIRECTOR
Definition: object.h:227
getWhoIsThird
static PyObject * getWhoIsThird(PyObject *self, PyObject *args)
Definition: cfpython.cpp:315
CORPSE
@ CORPSE
Definition: object.h:248
getScriptParameters
static PyObject * getScriptParameters(PyObject *self, PyObject *args)
Definition: cfpython.cpp:341
talk_info::npc_msgs
sstring npc_msgs[MAX_NPC]
What the NPCs will say.
Definition: dialog.h:59
Crossfire_RegionType
PyTypeObject Crossfire_RegionType
cf_system_get_archetype_vector
void cf_system_get_archetype_vector(int property, std::vector< archetype * > *list)
Definition: plugin_common.cpp:2128
cf_player_find
player * cf_player_find(const char *plname)
Wrapper for find_player_partial_name().
Definition: plugin_common.cpp:825
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
cf_system_unregister_command
void cf_system_unregister_command(command_registration command)
Definition: plugin_common.cpp:2111
AT_FEAR
#define AT_FEAR
Definition: attack.h:90
FOOD
@ FOOD
Definition: object.h:117
AT_GODPOWER
#define AT_GODPOWER
Definition: attack.h:96
CFPContext::options
char options[1024]
Definition: cfpython.h:103
PYTHON_CACHE_SIZE
#define PYTHON_CACHE_SIZE
Number of python scripts to store the bytecode of at a time.
Definition: cfpython.cpp:72
CFAPI_SYSTEM_PARTIES
#define CFAPI_SYSTEM_PARTIES
Definition: plugin.h:289
MOVE_BOAT
#define MOVE_BOAT
Boats/sailing.
Definition: define.h:397
MOVE_FLY_HIGH
#define MOVE_FLY_HIGH
High flying object.
Definition: define.h:394
context_stack
CFPContext * context_stack
Definition: cfpython.cpp:104
EVENT_ATTACKED
#define EVENT_ATTACKED
Object attacked, with weapon or spell.
Definition: events.h:21
EVENT_MAPREADY
#define EVENT_MAPREADY
A map is ready, either first load or after reload.
Definition: events.h:49
ALTAR
@ ALTAR
Definition: object.h:127
DOOR
@ DOOR
Definition: object.h:131
EVENT_CLOSE
#define EVENT_CLOSE
Container closed.
Definition: events.h:24
command_registration
uint64_t command_registration
Identifier when registering a command.
Definition: commands.h:32
AT_CONFUSION
#define AT_CONFUSION
Definition: attack.h:81
cf_map_get_map
mapstruct * cf_map_get_map(const char *name, int flags)
Wrapper for ready_map_name().
Definition: plugin_common.cpp:935
WAIT2
#define WAIT2
Monster does not try to move towards player if far.
Definition: define.h:493
DRINK
@ DRINK
Definition: object.h:162
code
Crossfire Architecture the general intention is to enhance the enjoyability and playability of CF In this code
Definition: arch-handbook.txt:14
ATNR_GHOSTHIT
#define ATNR_GHOSTHIT
Definition: attack.h:58
cf_system_get_party_vector
void cf_system_get_party_vector(int property, std::vector< partylist * > *list)
Definition: plugin_common.cpp:2134
WALL
@ WALL
Wall.
Definition: object.h:196
ATNR_COLD
#define ATNR_COLD
Definition: attack.h:53
WEAPON_IMPROVER
@ WEAPON_IMPROVER
Definition: object.h:238
SCROLL
@ SCROLL
Definition: object.h:226
AT_CANCELLATION
#define AT_CANCELLATION
Definition: attack.h:91
DISTHIT
#define DISTHIT
Attack from a distance if hit as recommended by Frank.
Definition: define.h:492
RUSH
#define RUSH
Rush toward player blindly, similiar to dumb monster.
Definition: define.h:490
PETMOVE
#define PETMOVE
If the upper four bits of attack_movement are set to this number, the monster follows a player until ...
Definition: define.h:495
registerGEvent
static PyObject * registerGEvent(PyObject *self, PyObject *args)
Definition: cfpython.cpp:116
cstAttackMovement
const CFConstant cstAttackMovement[]
Definition: cfpython.cpp:1392
list
How to Install a Crossfire Server on you must install a python script engine on your computer Python is the default script engine of Crossfire You can find the python engine you have only to install them The VisualC Crossfire settings are for but you habe then to change the pathes in the VC settings Go in Settings C and Settings Link and change the optional include and libs path to the new python installation path o except the maps ! You must download a map package and install them the share folder Its must look like doubleclick on crossfire32 dsw There are projects in your libcross lib and plugin_python You need to compile all Easiest way is to select the plugin_python ReleaseLog as active this will compile all others too Then in Visual C press< F7 > to compile If you don t have an appropriate compiler you can try to get the the VC copies the crossfire32 exe in the crossfire folder and the plugin_python dll in the crossfire share plugins folder we will remove it when we get time for it o Last showing lots of weird write to the Crossfire mailing list
Definition: INSTALL_WIN32.txt:50
LogLevel
LogLevel
Log levels for the LOG() function.
Definition: logger.h:10
MOVE_SWIM
#define MOVE_SWIM
Swimming object.
Definition: define.h:396
DISTATT
#define DISTATT
Move toward a player if far, but maintain some space, attack from a distance - good for missile users...
Definition: define.h:485
log_message
static PyObject * log_message(PyObject *self, PyObject *args)
Definition: cfpython.cpp:589
CFPContext::script
char script[1024]
Definition: cfpython.h:102
EVENT_ATTACKS
#define EVENT_ATTACKS
Weapon or arrow hitting something.
Definition: events.h:22
svnversion.h
BOOTS
@ BOOTS
Definition: object.h:217
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
IDENTIFY_ALTAR
@ IDENTIFY_ALTAR
Definition: object.h:242
SPELL
@ SPELL
Definition: object.h:219
AT_GHOSTHIT
#define AT_GHOSTHIT
Definition: attack.h:85
EVENT_DESTROY
#define EVENT_DESTROY
Object destroyed (includes map reset/swapout)
Definition: events.h:26
getWhoAmI
static PyObject * getWhoAmI(PyObject *self, PyObject *args)
Definition: cfpython.cpp:293
closedir
int closedir(DIR *)
log_python_error
static void log_python_error(void)
Trace a Python error to the Crossfire log.
Definition: cfpython.cpp:893
getTime
static PyObject * getTime(PyObject *self, PyObject *args)
Definition: cfpython.cpp:540
EVENT_GKILL
#define EVENT_GKILL
Triggered when anything got killed by anyone.
Definition: events.h:42
addConstants
static void addConstants(PyObject *module, const char *name, const CFConstant *constants)
Add constants and a reverse dictionary to get the name from the value.
Definition: cfpython.cpp:1064
SHIELD
@ SHIELD
Definition: object.h:140
CIRCLE1
#define CIRCLE1
If the upper four bits of move_type / attack_movement are set to this number, the monster will move i...
Definition: define.h:503
TELEPORTER
@ TELEPORTER
Definition: object.h:146
Crossfire_Map_wrap
PyObject * Crossfire_Map_wrap(mapstruct *what)
Definition: cfpython_map.cpp:435
private_data
static PyObject * private_data
Definition: cfpython.cpp:110
ATNR_LIFE_STEALING
#define ATNR_LIFE_STEALING
Definition: attack.h:73
PACEH2
#define PACEH2
The monster will pace as above but the length of the pace area is longer and the monster stops before...
Definition: define.h:510
Crossfire_Map
Definition: cfpython_map.h:32
THROWN_OBJ
@ THROWN_OBJ
Definition: object.h:151
NDI_GREY
#define NDI_GREY
Definition: newclient.h:255
SPELLBOOK
@ SPELLBOOK
Definition: object.h:208
Crossfire_ObjectType
PyTypeObject Crossfire_ObjectType
getPeriodofdayName
static PyObject * getPeriodofdayName(PyObject *self, PyObject *args)
Definition: cfpython.cpp:662
CFPContext::returnvalue
int returnvalue
Definition: cfpython.h:104
EVENT_KICK
#define EVENT_KICK
A player was Kicked by a DM
Definition: events.h:43
cstEventType
const CFConstant cstEventType[]
Definition: cfpython.cpp:1331
PyInit_cjson
PyObject * PyInit_cjson(void)
Definition: cjson.cpp:1165
cfpython_globalEventListener
CF_PLUGIN int cfpython_globalEventListener(int *type,...)
Definition: cfpython.cpp:1706
FORCE
@ FORCE
Definition: object.h:229
HOLY_ALTAR
@ HOLY_ALTAR
Definition: object.h:166
TRAPDOOR
@ TRAPDOOR
Definition: object.h:215
AT_DRAIN
#define AT_DRAIN
Definition: attack.h:83
getWhoIsActivator
static PyObject * getWhoIsActivator(PyObject *self, PyObject *args)
Definition: cfpython.cpp:304
DETECTOR
@ DETECTOR
peterm: detector is an object which notices the presense of another object and is triggered like butt...
Definition: object.h:154
NDI_LT_GREEN
#define NDI_LT_GREEN
DarkSeaGreen, which is actually paler than seagreen - also background color.
Definition: newclient.h:253
PyInit_Crossfire
static PyObject * PyInit_Crossfire(void)
Definition: cfpython.cpp:1487
initContextStack
static void initContextStack(void)
Definition: cfpython.cpp:817
cf_get_time
void cf_get_time(timeofday_t *tod)
Definition: plugin_common.cpp:1549
GOD
@ GOD
Definition: object.h:153
llevDebug
@ llevDebug
Only for debugging purposes.
Definition: logger.h:13
MISC_OBJECT
@ MISC_OBJECT
misc.
Definition: object.h:198
MONEY
@ MONEY
Definition: object.h:142
findAnimation
static PyObject * findAnimation(PyObject *self, PyObject *args)
Definition: cfpython.cpp:626
RANDO2
#define RANDO2
Constantly move in a different random direction.
Definition: define.h:517
is_valid_types_gen.type
list type
Definition: is_valid_types_gen.py:25
GATE
@ GATE
Definition: object.h:211
EVENT_APPLY
#define EVENT_APPLY
Object applied-unapplied.
Definition: events.h:20
getEvent
static PyObject * getEvent(PyObject *self, PyObject *args)
Definition: cfpython.cpp:351
freeContext
static void freeContext(CFPContext *context)
Definition: cfpython.cpp:844
ATNR_FEAR
#define ATNR_FEAR
Definition: attack.h:63
Crossfire_MapType
PyTypeObject Crossfire_MapType
AT_FIRE
#define AT_FIRE
Definition: attack.h:78