Esempio n. 1
0
//
// Send a message with Python statements potentially embedded in it. For 
//evaluating 
PyObject *PySocket_send(PyObject *self, PyObject *args, PyObject *kwds) {
  static char *kwlist[ ] = { "mssg", "dict", "newline", NULL };
  SOCKET_DATA *me = NULL;
  char      *text = NULL;
  PyObject  *dict = NULL;
  bool    newline = TRUE;

  if(!PyArg_ParseTupleAndKeywords(args, kwds, "s|Ob", kwlist, 
				  &text, &dict, &newline)) {
    PyErr_Format(PyExc_TypeError, "Invalid arguments supplied to Mudsock.send");
    return NULL;
  }

  // is dict None? set it to NULL for expand_to_char
  if(dict == Py_None)
    dict = NULL;

  // make sure the dictionary is a dictionary
  if(!(dict == NULL || PyDict_Check(dict))) {
    PyErr_Format(PyExc_TypeError, "Mudsock.send expects second argument to be a dict object.");
    return NULL;
  }
  
  // make sure we exist
  if( (me = PySocket_AsSocket(self)) == NULL) {
    PyErr_Format(PyExc_TypeError, "Tried to send nonexistent socket.");
    return NULL;
  }

  if(dict != NULL)
    PyDict_SetItemString(dict, "me", self);

  // build our script environment
  BUFFER   *buf = newBuffer(1);
  bufferCat(buf, text);

  // expand out our dynamic descriptions if we have a dictionary supplied
  if(dict != NULL) {
    PyObject *env = restricted_script_dict();
    PyDict_Update(env, dict);

    // do the expansion
    expand_dynamic_descs_dict(buf, env, get_script_locale());
    Py_XDECREF(env);
  }

  if(newline == TRUE)
    bufferCat(buf, "\r\n");
  text_to_buffer(me, bufferString(buf));

  // garbage collection
  deleteBuffer(buf);
  return Py_BuildValue("");
}
Esempio n. 2
0
const char *get_smart_locale(CHAR_DATA *ch) {
  const char *locale = get_script_locale();
  if(locale == NULL && charGetRoom(ch) != NULL)
    locale = get_key_locale(roomGetClass(charGetRoom(ch)));
  return locale;
}