Esempio n. 1
0
void clear_socket(SOCKET_DATA *sock_new, int sock)
{
  if(sock_new->page_string)    free(sock_new->page_string);
  if(sock_new->text_editor)    deleteBuffer(sock_new->text_editor);
  if(sock_new->outbuf)         deleteBuffer(sock_new->outbuf);
  if(sock_new->next_command)   deleteBuffer(sock_new->next_command);
  if(sock_new->iac_sequence)   deleteBuffer(sock_new->iac_sequence);
  if(sock_new->input_handlers) deleteListWith(sock_new->input_handlers, deleteInputHandler);
  if(sock_new->auxiliary)      deleteAuxiliaryData(sock_new->auxiliary);
  if(sock_new->input)          deleteListWith(sock_new->input, free);
  if(sock_new->command_hist)   deleteListWith(sock_new->command_hist, free);

  bzero(sock_new, sizeof(*sock_new));
  sock_new->auxiliary = newAuxiliaryData(AUXILIARY_TYPE_SOCKET);
  sock_new->input_handlers = newList();
  sock_new->input          = newList();
  sock_new->command_hist   = newList();
  sock_new->control        = sock;
  sock_new->lookup_status  = TSTATE_LOOKUP;
  sock_new->uid            = next_sock_uid++;

  sock_new->text_editor    = newBuffer(1);
  sock_new->outbuf         = newBuffer(MAX_OUTPUT);
  sock_new->next_command   = newBuffer(1);
  sock_new->iac_sequence   = newBuffer(1);
}
Esempio n. 2
0
void           deleteReset      (RESET_DATA *reset) {
  // delete all that are attached to us
  deleteListWith(reset->in,   deleteReset);
  deleteListWith(reset->on,   deleteReset);
  deleteListWith(reset->then, deleteReset);
  deleteBuffer(reset->arg);
  free(reset);
}
Esempio n. 3
0
//*****************************************************************************
//
// SOCKET MAINTENANCE
//
// Functions below this point are mainly concerned with the upkeep and
// maintenance of sockets (making sure they are initialized, garbage collected, 
// getting their addresses, etc...)
//
//*****************************************************************************
void deleteSocket(SOCKET_DATA *sock) {
  if(sock->hostname)      free(sock->hostname);
  if(sock->page_string)   free(sock->page_string);
  if(sock->text_editor)   deleteBuffer(sock->text_editor);
  if(sock->outbuf)        deleteBuffer(sock->outbuf);
  if(sock->next_command)  deleteBuffer(sock->next_command);
  if(sock->iac_sequence)  deleteBuffer(sock->iac_sequence);
  if(sock->input_handlers)deleteListWith(sock->input_handlers,deleteInputHandler);
  if(sock->input)         deleteListWith(sock->input, free);
  if(sock->command_hist)  deleteListWith(sock->command_hist, free);
  if(sock->auxiliary)     deleteAuxiliaryData(sock->auxiliary);
  free(sock);
}
Esempio n. 4
0
void resetListCopyTo(RESET_LIST *from, RESET_LIST *to) {
  if(to->resets)   deleteListWith(to->resets, deleteReset);
  if(from->resets) to->resets = listCopyWith(from->resets, resetCopy);
  else             to->resets = newList();
  if(to->key)      free(to->key);
  to->key =        strdupsafe(from->key);
}
Esempio n. 5
0
//
// free a token from memory
void deleteParseToken(PARSE_TOKEN *arg) {
  if(arg->token_list)
    deleteListWith(arg->token_list, deleteParseToken);
  if(arg->flavor)
    free(arg->flavor);
  free(arg);
}
Esempio n. 6
0
const char *raceGetList(bool pc_only) {
  static char buf[MAX_BUFFER];
  LIST       *name_list = newList();
  HASH_ITERATOR *race_i = newHashIterator(race_table);
  const char      *name = NULL;
  RACE_DATA       *data = NULL;

  // collect all of our names
  ITERATE_HASH(name, data, race_i) {
    if(pc_only && data->pc_ok == FALSE) continue;
    listPutWith(name_list, strdup(name), strcmp);
  }
  deleteHashIterator(race_i);

  // print all the names to our buffer
  char *new_name = NULL; // gotta use a new name ptr.. can't free const
  int i = 0;
  while( (new_name = listPop(name_list)) != NULL) {
    i += snprintf(buf+i, MAX_BUFFER-i, "%s%s",
		  new_name, (listSize(name_list) > 0 ? ", " : ""));
    free(new_name);
  }

  // delete our list of names and return the buffer
  deleteListWith(name_list, free);
  return buf;
}
Esempio n. 7
0
// initialize rooms for use. This must be called AFTER 
PyMODINIT_FUNC
init_PyRoom(void) {
    PyObject* module = NULL;

    // add all of the basic getsetters
    PyRoom_addGetSetter("vnum",  PyRoom_getvnum,   NULL, "The room's vnum");
    PyRoom_addGetSetter("chars", PyRoom_getchars,  NULL, "chars in the room");
    PyRoom_addGetSetter("objs",  PyRoom_getobjs,   NULL, "objects in the room");
    PyRoom_addGetSetter("contents",PyRoom_getobjs, NULL, "objects in the room");

    // add all of the basic methods
    PyRoom_addMethod("attach", PyRoom_attach, METH_VARARGS,
		     "attach a new script to the room.");
    PyRoom_addMethod("detach", PyRoom_detach, METH_VARARGS,
		     "detach a script from the room, by vnum.");
    PyRoom_addMethod("close", PyRoom_close, METH_VARARGS,
		     "close a door in the specified direction.");
    PyRoom_addMethod("open", PyRoom_open, METH_VARARGS,
		     "open a door in the specified direction. Also unlocks.");
    PyRoom_addMethod("lock", PyRoom_lock, METH_VARARGS,
		     "lock a door in the specified direction. Also closes.");
    PyRoom_addMethod("unlock", PyRoom_unlock, METH_VARARGS,
		     "unlocks a door in the specified direction.");
    PyRoom_addMethod("send", PyRoom_send, METH_VARARGS,
		     "send a message to everyone in the room.");

    // add in all the getsetters and methods
    makePyType(&PyRoom_Type, pyroom_getsetters, pyroom_methods);
    deleteListWith(pyroom_getsetters, free); pyroom_getsetters = NULL;
    deleteListWith(pyroom_methods,    free); pyroom_methods    = NULL;

    // make sure the room class is ready to be made
    if (PyType_Ready(&PyRoom_Type) < 0)
        return;

    // initialize the module
    module = Py_InitModule3("room", room_module_methods,
			    "The room module, for all MUD room-related stuff.");

    // make sure the module parsed OK
    if (module == NULL)
      return;

    // add the Room class to the room module
    PyModule_AddObject(module, "Room", (PyObject *)&PyRoom_Type);
    Py_INCREF(&PyRoom_Type);
}
Esempio n. 8
0
void deleteTriggerAuxData(TRIGGER_AUX_DATA *data) {
  deleteListWith(data->triggers, free);
  if(data->pyform && data->pyform->ob_refcnt > 1)
    log_string("LEAK: Memory leak (%d refcnt) on someone or something's pyform",
	       (int)data->pyform->ob_refcnt);
  Py_XDECREF(data->pyform);
  free(data);
}
Esempio n. 9
0
void           resetCopyTo      (RESET_DATA *from, RESET_DATA *to) {
  // first, delete everything attached to us
  deleteListWith(to->in,   deleteReset);
  deleteListWith(to->on,   deleteReset);
  deleteListWith(to->then, deleteReset);

  to->in   = listCopyWith(from->in,   resetCopy);
  to->on   = listCopyWith(from->on,   resetCopy);
  to->then = listCopyWith(from->then, resetCopy);

  resetSetType(to,        resetGetType(from));
  resetSetTimes(to,       resetGetTimes(from));
  resetSetChance(to,      resetGetChance(from));
  resetSetMax(to,         resetGetMax(from));
  resetSetRoomMax(to,     resetGetRoomMax(from));
  resetSetArg(to,         resetGetArg(from));
}
Esempio n. 10
0
void save_help_olc(HELP_OLC *data) {
  // first, remove our old helpfile from disc
  LIST    *kwds = parse_keywords(data->old_keywords);
  char *primary = listGet(kwds, 0);
  if(primary && *primary)
    remove_help(primary);
  deleteListWith(kwds, free);

  // now, add our new one
  add_help(data->keywords, bufferString(data->info), data->user_groups,
	   data->related, TRUE);
}
Esempio n. 11
0
//
// run all of the resets for a specified room
void do_resets(ROOM_DATA *room) {
  // first apply all of our prototype resets
  LIST            *protos = parse_keywords(roomGetPrototypes(room));
  LIST_ITERATOR  *proto_i = newListIterator(protos);
  char             *proto = NULL;
  RESET_LIST        *list = NULL;

  // try to run each parent reset, and finally our own
  ITERATE_LIST(proto, proto_i) {
    if((list = worldGetType(gameworld, "reset", proto)) != NULL)
      resetRunOn(resetListGetResets(list), room, INITIATOR_ROOM, get_key_locale(proto));
  } deleteListIterator(proto_i);
  deleteListWith(protos, free);
}
Esempio n. 12
0
int  bedit_chooser(SOCKET_DATA *sock, BITVECTOR *vector, const char *option) {
  if(!isdigit(*option)) 
    return MENU_CHOICE_INVALID;
  else {
    int choice = atoi(option);
    if(choice < 0 || choice >= bitvectorSize(vector))
      return MENU_CHOICE_INVALID;
    else {
      LIST *bits = bitvectorListBits(vector);
      char  *bit = listGet(bits, choice);
      bitToggle(vector, bit);
      deleteListWith(bits, free);
      return MENU_NOCHOICE;
    }
  }
}
Esempio n. 13
0
//
// builds up a list of variables out of the token list, and arguments. If we
// encounter an error and we need to show it to the looker, do so.
LIST *compose_variable_list(CHAR_DATA *looker, LIST *tokens, char *args,
			    char *err_buf) {
  LIST      *variables = newList();
  LIST_ITERATOR *tok_i = newListIterator(tokens);
  PARSE_TOKEN     *tok = NULL;
  bool           error = FALSE;
  bool  optional_found = FALSE;

  // go through our list of tokens, and try dealing with the args
  ITERATE_LIST(tok, tok_i) {
    PARSE_VAR *var = NULL;

    // did we just encounter an optional value?
    if(tok->type == PARSE_TOKEN_OPTIONAL) {
      optional_found = TRUE;
      continue;
    }
    
    // can we still use tokens to process stuff?
    if(*args != '\0')
      var = use_one_parse_token(looker, tok, &args, &error, err_buf);
    // we haven't found an "optional" marker yet - this isn't allowed
    else if(optional_found == FALSE)
      error = TRUE;
    // we have found an "optional" marker. Just break out of the loop
    else 
      break;

    // if use of the token returned a new variable, append it
    if(var != NULL)
      listQueue(variables, var);
    // if we enountered an error, tell the person if neccessary
    else if(error == TRUE) {
      deleteListWith(variables, deleteParseVar);
      variables = NULL;
      break;
    }
  } deleteListIterator(tok_i);
Esempio n. 14
0
//
// breaks up a format string into its parts and returns a list of them
LIST *decompose_parse_format(const char *format) {
  const char  *fmt = format; 
  bool       error = FALSE;
  LIST *token_list = newList();

  // try to parse all of our format down into tokens
  while(*fmt != '\0' && !error) {
    PARSE_TOKEN *token = parse_one_token(&fmt);

    // did the token parse OK?
    if(token != NULL)
      listQueue(token_list, token);
    else
      error = TRUE;
  }

  // did we encounter an error?
  if(error == TRUE) {
    deleteListWith(token_list, deleteParseToken);
    token_list = NULL;
  }

  return token_list;
}
Esempio n. 15
0
void triggerAuxDataCopyTo(TRIGGER_AUX_DATA *from, TRIGGER_AUX_DATA *to) {
  deleteListWith(to->triggers, free);
  to->triggers = listCopyWith(from->triggers, strdup);
}
Esempio n. 16
0
//*****************************************************************************
// bitvector editing functions
//*****************************************************************************
void bedit_menu   (SOCKET_DATA *sock, BITVECTOR *vector) {
  LIST *bits = bitvectorListBits(vector);
  send_to_socket(sock, "{wCurrent bits: {c%s\r\n", bitvectorGetBits(vector));
  olc_display_list(sock, bits, 3);
  deleteListWith(bits, free);
}
Esempio n. 17
0
void deleteResetList(RESET_LIST *list) {
  if(list->resets) deleteListWith(list->resets, deleteReset);
  if(list->key)    free(list->key);
  free(list);
}
Esempio n. 18
0
PyObject *py_gen_do_trigs(PyObject *self, PyObject *args, PyObject *kwds) {
  static char *kwlist[] ={ "type","ch","obj","room","exit","cmd","arg","opts",NULL };
  char       *type = NULL;
  char        *cmd = NULL;
  char        *arg = NULL;
  PyObject   *pych = NULL;
  PyObject  *pyobj = NULL;
  PyObject *pyroom = NULL;
  PyObject *pyexit = NULL;
  PyObject *pyopts = NULL;
  LIST       *opts = NULL;
  CHAR_DATA    *ch = NULL;
  OBJ_DATA    *obj = NULL;
  ROOM_DATA  *room = NULL;
  EXIT_DATA  *exit = NULL;
  void         *me = NULL;
  int      me_type = -1;
  bool        fail = FALSE;

  // first, parse all of our arguments
  if(!PyArg_ParseTupleAndKeywords(args, kwds, "s|OOOOssO", kwlist, 
				  &type, &pych, &pyobj, &pyroom, &pyexit,
				  &cmd, &arg, &pyopts)) {
    PyErr_Format(PyExc_TypeError, "do_trigs supplied invalid arguments.");
    return NULL;
  }

  // make sure we exist, and are of a valid type
  if(PyChar_Check(self)) {
    me = PyChar_AsChar(self);
    me_type = TRIGVAR_CHAR;
  }
  else if(PyObj_Check(self)) {
    me = PyObj_AsObj(self);
    me_type = TRIGVAR_OBJ;
  }
  else if(PyRoom_Check(self)) {
    me = PyRoom_AsRoom(self);
    me_type = TRIGVAR_ROOM;
  }

  // did we find a character?
  if(me == NULL) {
    PyErr_Format(PyExc_TypeError,"do_trigs owner does not exist.");
    return NULL;
  }

  // make sure ch is of the specified type
  if(pych!=NULL && (!PyChar_Check(pych) || (ch=PyChar_AsChar(pych)) == NULL)){
    PyErr_Format(PyExc_TypeError,"do_trigs expects ch to be character.");
    return NULL;
  }

  // make sure obj is of the specified type
  if(pyobj!=NULL && (!PyObj_Check(pyobj) || (obj=PyObj_AsObj(pyobj)) == NULL)){
    PyErr_Format(PyExc_TypeError,"do_trigs expects obj to be object.");
    return NULL;
  }

  // make sure room is of the specified type
  if(pyroom!=NULL&&(!PyRoom_Check(pyroom)||(room=PyRoom_AsRoom(pyroom))==NULL)){
    PyErr_Format(PyExc_TypeError,"do_trigs expects room to be room.");
    return NULL;
  }

  // make sure exit is of the specified type
  if(pyexit!=NULL&&(!PyExit_Check(pyexit)||(exit=PyExit_AsExit(pyexit))==NULL)){
    PyErr_Format(PyExc_TypeError,"do_trigs expects exit to be an exit.");
    return NULL;
  }

  // parse opts
  if(pyopts != NULL && !PyDict_Check(pyopts)) {
    PyErr_Format(PyExc_TypeError,"do_trigs expects opts to be a dict.");
    return NULL;
  }
  else if(pyopts != NULL) {
    PyObject  *pairs = PyDict_Items(pyopts);
    int            i = 0;
    opts             = newList();
    // go through each pair and add it to the pyopts list
    for(; i < PyList_Size(pairs); i++) {
      PyObject  *pair = PyList_GetItem(pairs, i);
      PyObject *pykey = PyTuple_GetItem(pair, 0);
      PyObject *pyval = PyTuple_GetItem(pair, 1);
      OPT_VAR    *opt = NULL;
      char       *key = NULL;

      // make sure the key is a string
      if(PyString_Check(pykey))
	key = PyString_AsString(pykey);
      else {
	PyErr_Format(PyExc_TypeError, "do_trigs opt keys must be strings.");
	fail = TRUE;
	break;
      }

      // check to make sure the val is a valid type
      if(PyChar_Check(pyval)) {
	CHAR_DATA *val = PyChar_AsChar(pyval);
	if(val != NULL)
	  opt = newOptVar(key, val, TRIGVAR_CHAR);
	else {
	  PyErr_Format(PyExc_TypeError,"%s opt provided nonexistent char.",key);
	  fail = TRUE;
	  break;
	}
      }
      else if(PyObj_Check(pyval)) {
	OBJ_DATA *val = PyObj_AsObj(pyval);
	if(val != NULL)
	  opt = newOptVar(key, val, TRIGVAR_OBJ);
	else {
	  PyErr_Format(PyExc_TypeError,"%s opt provided nonexistent obj.", key);
	  fail = TRUE;
	  break;
	}
      }
      else if(PyRoom_Check(pyval)) {
	ROOM_DATA *val = PyRoom_AsRoom(pyval);
	if(val != NULL)
	  opt = newOptVar(key, val, TRIGVAR_ROOM);
	else {
	  PyErr_Format(PyExc_TypeError,"%s opt provided nonexistent room.",key);
	  fail = TRUE;
	  break;
	}
      }
      else {
	PyErr_Format(PyExc_TypeError,"%s opt provided invalid value.",key);
	fail = TRUE;
	break;
      }

      // append the opt to the opt list
      listPut(opts, opt);
    }
    Py_DECREF(pairs);
  }

  // did everything succeed?
  if(fail == FALSE)
    gen_do_trigs(me,me_type,type,ch,obj,room,exit,cmd,arg,opts);

  // garbage collection
  if(opts != NULL)
    deleteListWith(opts, deleteOptVar);

  if(fail == TRUE)
    return NULL;
  return Py_BuildValue("");
}