Esempio n. 1
0
void extenderDoMenu(SOCKET_DATA *sock, OLC_EXTENDER *ext, void *data) {
  LIST           *keys = hashCollect(ext->opt_hash);
  char            *key = NULL;
  OLC_EXT_DATA  *edata = NULL;

  // display each menu item alphabetically
  listSortWith(keys, strcasecmp);
  LIST_ITERATOR *key_i = newListIterator(keys);
  ITERATE_LIST(key, key_i) {
    // display the menu option
    send_to_socket(sock, "{g%s) ", key);

    // then display the information
    edata = hashGet(ext->opt_hash, key);
    if(edata->type == OLCEXT_C)
      edata->menu(sock, data);
    else if(ext->borrow_py != NULL) {
      PyObject *ret = PyObject_CallFunction(edata->pymenu, "OO", 
					    socketGetPyFormBorrowed(sock), 
					    ext->borrow_py(data));
      if(ret == NULL)
	log_pyerr("Error running Python OLC exention menu function: %s", key);
      Py_XDECREF(ret);
    }
  } deleteListIterator(key_i);
Esempio n. 2
0
//*****************************************************************************
// methods in the mudsock module
//*****************************************************************************
PyObject *PySocket_all_sockets(PyObject *self) {
  PyObject        *list = PyList_New(0);
  LIST_ITERATOR *sock_i = newListIterator(socket_list);
  SOCKET_DATA     *sock = NULL;
  ITERATE_LIST(sock, sock_i) {
    PyList_Append(list, socketGetPyFormBorrowed(sock));
  } deleteListIterator(sock_i);
Esempio n. 3
0
void input_handler() {
  LIST_ITERATOR *sock_i = newListIterator(socket_list);
  SOCKET_DATA     *sock = NULL; 

  ITERATE_LIST(sock, sock_i) {
    // Close sockects we are unable to read from, or if we have no handler
    // to take in input
    if ((FD_ISSET(sock->control, &rFd) && !read_from_socket(sock)) ||
	listSize(sock->input_handlers) == 0) {
      close_socket(sock, FALSE);
      continue;
    }

    /* Ok, check for a new command */
    next_cmd_from_buffer(sock);
    
    // are we idling?
    if(!sock->cmd_read)
      sock->idle +=  1.0 / PULSES_PER_SECOND;
    /* Is there a new command pending ? */
    else if (sock->cmd_read) {
      sock->idle = 0.0;
      IH_PAIR *pair = listGet(sock->input_handlers, 0);
      if(pair->python == FALSE) {
	void (* handler)(SOCKET_DATA *, char *) = pair->handler;
	char *cmddup = strdup(bufferString(sock->next_command));
	handler(sock, cmddup);
	free(cmddup);
      }
      else {
	PyObject *arglist = Py_BuildValue("Os", socketGetPyFormBorrowed(sock),
					  bufferString(sock->next_command));
	PyObject *retval  = PyEval_CallObject(pair->handler, arglist);

	// check for an error:
	if(retval == NULL)
	  log_pyerr("Error with a Python input handler");
	
	// garbage collection
	Py_XDECREF(retval);
	Py_XDECREF(arglist);
      }

      // append our last command to the command history. History buffer is
      // 100 commands, so pop off the earliest command if we're going over
      listPut(sock->command_hist, strdup(bufferString(sock->next_command)));
      if(listSize(sock->command_hist) > 100)
	free(listRemoveNum(sock->command_hist, 100));
      bufferClear(sock->next_command);

      // we save whether or not we read a command until our next call to
      // input_handler(), at which time it is reset to FALSE if we didn't read
      // sock->cmd_read = FALSE;
    }

#ifdef MODULE_ALIAS
    // ACK!! this is so yucky, but I can't think of a better way to do it...
    // if this command was put in place by an alias, decrement the alias_queue
    // counter by one. This counter is in place mainly so aliases do not end
    // up calling eachother and making us get stuck in an infinite loop.
    if(sock->player) {
      int alias_queue = charGetAliasesQueued(sock->player);
      if(alias_queue > 0)
	charSetAliasesQueued(sock->player, --alias_queue);
    }
#endif
  } deleteListIterator(sock_i);
}
Esempio n. 4
0
PyObject *socketGetPyForm(SOCKET_DATA *sock) {
  PyObject *pyform = socketGetPyFormBorrowed(sock);
  Py_INCREF(pyform);
  return pyform;
}