예제 #1
0
파일: room_reset.c 프로젝트: KaSt/nereamud
//
// Try running a script on the initiator
bool try_reset_script(RESET_DATA *reset, void *initiator, int initiator_type,
		      const char *locale) {
  PyObject *pyme = NULL;
  PyObject *dict = NULL;
  if(initiator_type == INITIATOR_ROOM)
    pyme = roomGetPyFormBorrowed(initiator);
  else if(initiator_type == INITIATOR_THEN_OBJ)
    pyme = objGetPyFormBorrowed(initiator);
  else if(initiator_type == INITIATOR_THEN_MOB)
    pyme = charGetPyFormBorrowed(initiator);
  else
    return FALSE;

  // build our dictionary and add ourself to it as 'me'
  dict = restricted_script_dict();
  PyDict_SetItemString(dict, "me", pyme);

  // run the script
  run_script(dict, resetGetArg(reset), locale);

  // check to see if we had an error
  if(!last_script_ok())
    log_pyerr("Reset script in locale %s terminated with an error:\r\n%s",
	      locale, resetGetArg(reset));

  // garbage collection and return our outcome
  Py_DECREF(dict);
  return last_script_ok();
}
예제 #2
0
파일: pyevent.c 프로젝트: KaSt/nereamud
//*****************************************************************************
// local functions
//*****************************************************************************
void PyEvent_on_complete(void *owner, PyObject *tuple, const char *arg) {
  PyObject *PyOwner = NULL;
  PyObject   *efunc = NULL;
  PyObject   *edata = NULL;
  char       *otype = NULL;

  // make sure we parse everything before we call the function
  if(PyArg_ParseTuple(tuple, "sOO", &otype, &efunc, &edata)) {
    if(!strcasecmp(otype, "char"))
      PyOwner = charGetPyFormBorrowed(owner);
    else if(!strcasecmp(otype, "room"))
      PyOwner = roomGetPyFormBorrowed(owner);
    else if(!strcasecmp(otype, "obj"))
      PyOwner = objGetPyFormBorrowed(owner);
    else
      PyOwner = Py_None;

    PyObject *ret = PyObject_CallFunction(efunc, "OOs", PyOwner, edata, arg);
    if(ret == NULL)
      log_pyerr("Error finishing Python event");
    Py_XDECREF(ret);
  }

  // decrease the reference on our function and data, as well as our owner
  Py_XDECREF(tuple);
}
예제 #3
0
void expand_dynamic_descs(BUFFER *desc, PyObject *me, CHAR_DATA *ch, 
			  const char *locale) {
  // set up our dictionary
  PyObject *dict = restricted_script_dict();
  PyDict_SetItemString(dict, "me", me);
  PyDict_SetItemString(dict, "ch", charGetPyFormBorrowed(ch));

  // expand the dynamic description
  expand_dynamic_descs_dict(desc, dict, locale);

  // garbage collection
  Py_XDECREF(dict);
}
예제 #4
0
파일: pysocket.c 프로젝트: KaSt/nereamud
PyObject *PySocket_getchar(PySocket *self, void *closure) {
  SOCKET_DATA *sock = PySocket_AsSocket((PyObject *)self);
  if(sock == NULL)
    return NULL;
  else {
    CHAR_DATA *ch = socketGetChar(sock);
    // for the time being, we don't return characters without UIDs... like ones
    // that are being created. We have to redo character generation to allow
    // for characters-in-progress to be referenced
    if(ch == NULL || charGetUID(ch) == NOBODY)
      return Py_BuildValue("O", Py_None);
    return Py_BuildValue("O", charGetPyFormBorrowed(ch));
  }
}
예제 #5
0
PyObject *charGetPyForm(CHAR_DATA *ch) {
  PyObject *pyform = charGetPyFormBorrowed(ch);
  Py_INCREF(pyform);
  return pyform;
}