Exemplo n.º 1
0
Arquivo: types.c Projeto: adk9/ohm
inline basetype_t*
get_type_alias(basetype_t *type)
{
    if (is_alias(type->ohm_type) && type->elems)
        return get_type_alias(type->elems[0]);
    return type;
}
Exemplo n.º 2
0
char	*replace_by_alias(char *str, t_alias *list)
{
  char	*new_str;
  char	*word;
  int	save;
  int	x;

  x = -1;
  if ((new_str = copy_str(str)) == NULL)
    return (NULL);
  while (new_str[++x])
    {
      if (new_str[x] != ';' && new_str[x] != ' ' && new_str[x] != '\t' &&
	  new_str[x] != '|' && new_str[x] != '&')
	{
	  save = x;
	  if ((word = get_a_word(new_str, &x)) && is_alias(&word, list))
	    {
	      if ((new_str = replace_word(word, new_str, save, &x)) == NULL)
		return (NULL);
	    }
	  else if (word)
	    free(word);
	}
    }
  return (new_str);
}
Exemplo n.º 3
0
Arquivo: types.c Projeto: adk9/ohm
inline basetype_t*
get_type_ptr(basetype_t *type)
{
    if ((is_ptr(type->ohm_type) || is_alias(type->ohm_type))
        && type->elems)
        return get_type_ptr(type->elems[0]);
    return type;
}
Exemplo n.º 4
0
Arquivo: types.c Projeto: adk9/ohm
inline unsigned int
get_type_nelem(basetype_t *type)
{
    if (!type)
        return 0;

    if (is_alias(type->ohm_type) && type->elems && type->elems[0])
        return get_type_nelem(type->elems[0]);

    return type->nelem;
}
Exemplo n.º 5
0
Arquivo: types.c Projeto: adk9/ohm
inline size_t
get_type_size(basetype_t *type)
{
    if (!type)
        return 0;

    if (is_alias(type->ohm_type) && type->elems && type->elems[0])
        return get_type_size(type->elems[0]);

    return type->size;
}
Exemplo n.º 6
0
void
command_interpreter (CHAR_DATA * ch, char *argument)
{
	char buf[MAX_STRING_LENGTH];
	char *command_args, *p, *social_args;
	int cmd_level = 0;
	int i = 0, echo = 1;
	AFFECTED_TYPE *craft_affect = NULL;
	AFFECTED_TYPE *af;
	ALIAS_DATA *alias;
	extern int second_affect_active;

	if (!ch)
		return;

	*buf = '\0';

	p = argument;

	while (*p == ' ')
		p++;

	if (strchr (p, '%'))
	{
		send_to_char ("Input with the '%' character is not permitted.\n", ch);
		return;
	}

	if (strchr (p, '#') && IS_MORTAL (ch) && strncmp (p, "ge", 2) != 0
		&& strncmp (p, "buy", 3) != 0)
	{
		send_to_char ("Input with the '#' character is not permitted.\n", ch);
		return;
	}

	if (IS_MORTAL (ch) && strchr (p, '$'))
	{
		send_to_char ("Input with the '$' character is not permitted.\n", ch);
		return;
	}

	std::multimap<int, room_prog>::iterator it;
	if (IS_NPC(ch))
		it = mob_prog_list.find(ch->mob->nVirtual); 
	if (IS_NPC(ch) && !get_second_affect (ch, SA_DOANYWAY, 0) && it != mob_prog_list.end())
	{
		if (m_prog(ch, p))
		{
			return;
		}
	}
	std::pair<std::multimap<int, room_prog>::iterator, std::multimap<int, room_prog>::iterator> pair;

	if (ch->right_hand && !get_second_affect (ch, SA_DOANYWAY, 0))
	{
		pair = obj_prog_list.equal_range(ch->right_hand->nVirtual);
		for (it = pair.first; it != pair.second; it++)
		{
			if (it->second.type != 1 && it->second.type != 3 && it->second.type != 5)
				continue;
			if (o_prog(ch, p, it->second))
				return;
		}
	}
	if (ch->left_hand && !get_second_affect (ch, SA_DOANYWAY, 0))
	{
		pair = obj_prog_list.equal_range(ch->left_hand->nVirtual);
		for (it = pair.first; it != pair.second; it++)
		{
			if (it->second.type != 1 && it->second.type != 3 && it->second.type != 5)
				continue;
			if (o_prog(ch, p, it->second))
				return;
		}
	}
	for (OBJ_DATA *tobj = ch->equip; tobj; tobj = tobj->next_content)
	{
		if (get_second_affect (ch, SA_DOANYWAY, 0))
			break;

		pair = obj_prog_list.equal_range(tobj->nVirtual);
		for (it = pair.first; it != pair.second; it++)
		{
			if (it->second.type != 2 && it->second.type != 3 && it->second.type != 5)
				continue;
			if (o_prog(ch, p, it->second))
				return;
		}

	}

	/* this is where it crashes on the hour - Grommit */

	if (!ch->room )
	{
		std::ostringstream stream;
		stream << "Error in command_interpreter:commands.cpp. Command \"" << 
			argument << "\" called by \"" << ch->tname << "\" with null room. Previously in "
			<< (ch->last_room) << " entering null room from the " << (dirs[ch->from_dir]) << ".";

		system_log(stream.str().c_str(),true);
		return;
	}

	/* end grommit diagnostics to avoid segfaulting on the below for loop */

	for (OBJ_DATA *tobj = ch->room->contents; tobj; tobj = tobj->next_content)
	{
		if (get_second_affect (ch, SA_DOANYWAY, 0))
			break;

		pair = obj_prog_list.equal_range(tobj->nVirtual);
		for (it = pair.first; it != pair.second; it++)
		{
			if (it->second.type != 4 && it->second.type != 5)
				continue;
			if (o_prog(ch, p, it->second))
				return;
		}

	}

	for (CHAR_DATA *temp_char = ch->room->people; temp_char; temp_char = temp_char->next_in_room)
	{
		if (get_second_affect (ch, SA_DOANYWAY, 0))
			break;

		if (temp_char == ch)
			continue;

		if (!IS_NPC(temp_char))
			continue;

		pair = mob_prog_list.equal_range(temp_char->mob->nVirtual);

		for (it = pair.first; it != pair.second; ++it)
		{
			if (m_prog(ch, p, it->second))
				return;
		}
	}

	if (ch->room && ch->room->prg && !get_second_affect(ch, SA_DOANYWAY, 0) && r_program (ch, p))
	{
		if (!IS_NPC (ch)
			|| (ch->desc && (ch->pc && str_cmp (ch->pc->account_name, "Guest"))))
		{
			player_log (ch, "[RPROG]", p);
		}
		if (!IS_SET (commands[i].flags, C_NWT))
			show_to_watchers (ch, argument);
		return;
	}
	if (get_second_affect(ch, SA_DOANYWAY, 0))
		remove_second_affect(get_second_affect(ch, SA_DOANYWAY, 0));

	if (!IS_MORTAL (ch) && !str_cmp (argument, "sho wl"))
	{
		send_to_char
			("Heh heh. Glad I added in this check, aren't we? No shouting for you.\n",
			ch);
		return;
	}

	if (ch->desc)
	{
		last_descriptor = ch->desc;
		sprintf (full_last_command, "Last Command Issued, by %s [%d]: %s",
			ch->tname, ch->in_room, argument);
		sprintf (last_command, "%s", argument);
	}

	social_args = argument;

	command_args = one_argument (argument, buf);

	if (!*buf)
		return;

	while (*command_args == ' ')
		command_args++;

	if (ch->pc && !GET_FLAG (ch, FLAG_ALIASING))
	{

		if ((alias = is_alias (ch, buf)))
		{

			ch->flags |= FLAG_ALIASING;

			while (alias)
			{

				command_interpreter (ch, alias->line);

				if (ch->deleted)
					return;

				alias = alias->next_line;
			}

			ch->flags &= ~FLAG_ALIASING;

			return;
		}
	}

	for (i = 1; *commands[i].command; i++)
		if (is_abbrev (buf, commands[i].command))
			break;

	if ((craft_affect = is_craft_command (ch, argument)))
		i = 0;

	if (IS_SET (commands[i].flags, C_IMP)) {
		cmd_level = 6;
	}
	else if (IS_SET (commands[i].flags, C_LV5)) {
		cmd_level = 5;
	}
	else if (IS_SET (commands[i].flags, C_LV4)) {
		cmd_level = 4;
	}
	else if (IS_SET (commands[i].flags, C_LV3)) {
		cmd_level = 3;
	}
	else if (IS_SET (commands[i].flags, C_LV2)) {
		cmd_level = 2;
	}
	else if (IS_SET (commands[i].flags, C_LV1)) {
		cmd_level = 1;
	}

	if (IS_SET (commands[i].flags, C_GDE)
		&& (IS_NPC (ch) || (!ch->pc->is_guide && !ch->pc->level)))
	{
		send_to_char ("Eh?\n\r", ch);
		return;
	}
	/* 
	Need to pass the CHAR_DATA pointer for the person who made the command and modify
	the following line to test the commanding char's trust against the trust level for
	the command.  - Methuselah
	*/

	if ((!*commands[i].command) 
		|| (cmd_level > GET_TRUST (ch)))
	{
		if (!social (ch, argument))
		{
			echo = number (1, 9);
			if (echo == 1)
				send_to_char ("Eh?\n\r", ch);
			else if (echo == 2)
				send_to_char ("Huh?\n\r", ch);
			else if (echo == 3)
				send_to_char ("I'm afraid that just isn't possible...\n\r", ch);
			else if (echo == 4)
				send_to_char ("I don't recognize that command.\n\r", ch);
			else if (echo == 5)
				send_to_char ("What?\n\r", ch);
			else if (echo == 6)
				send_to_char
				("Perhaps you should try typing it a different way?\n\r", ch);
			else if (echo == 7)
				send_to_char
				("Try checking your typing - I don't recognize it.\n\r", ch);
			else if (echo == 8)
				send_to_char
				("That isn't a recognized command, craft, or social.\n\r", ch);
			else
				send_to_char ("Hmm?\n\r", ch);
		}
		else
		{
			if (!IS_SET (commands[i].flags, C_NWT))
				show_to_watchers (ch, argument);
		}
		return;
	}

	if (ch->stun)
	{
		send_to_char ("You're still reeling.\n", ch);
		return;
	}

	if (ch->roundtime)
	{
		sprintf (buf, "You'll need to wait another %d seconds.\n",
			ch->roundtime);
		send_to_char (buf, ch);
		return;
	}

	if (IS_SET (commands[i].flags, C_WLK) &&
		(ch->moves || GET_FLAG (ch, FLAG_LEAVING)
		|| GET_FLAG (ch, FLAG_ENTERING)))
	{
		send_to_char ("Stop traveling first.\n\r", ch);
		return;
	}

	if (IS_SET (commands[i].flags, C_MNT) && IS_RIDER (ch))
	{
		send_to_char ("Get off your mount first.\n", ch);
		return;
	}

	if (commands[i].min_position > GET_POS (ch))
	{
		switch (GET_POS (ch))
		{
		case DEAD:
			if (IS_MORTAL (ch))
			{
				send_to_char ("You are dead.  You can't do that.\n\r", ch);
				return;
			}
		case UNCON:
		case MORT:
			send_to_char ("You're seriously wounded and unconscious.\n\r", ch);
			return;

		case STUN:
			send_to_char ("You're too stunned to do that.\n\r", ch);
			return;

		case SLEEP:
			send_to_char ("You can't do that while sleeping.\n\r", ch);
			return;

		case REST:
			send_to_char ("You can't do that while lying down.\n\r", ch);
			return;

		case SIT:
			send_to_char ("You can't do that while sitting.\n\r", ch);
			return;

		case FIGHT:
			send_to_char ("No way! You are fighting for your life!\n\r", ch);
			return;
		}

		return;
	}

	if (!IS_NPC (ch) && ch->pc->create_state == STATE_DIED &&
		!IS_SET (commands[i].flags, C_DOA))
	{
		send_to_char ("You can't do that when you're dead.\n\r", ch);
		return;
	}

	if (!IS_SET (commands[i].flags, C_BLD) && is_blind (ch))
	{
		if (get_equip (ch, WEAR_BLINDFOLD))
			send_to_char ("You can't do that while blindfolded.\n\r", ch);
		else
			send_to_char ("You can't do that while blind.\n\r", ch);
		return;
	}

	if ((af = get_affect (ch, MAGIC_AFFECT_PARALYSIS)) &&
		!IS_SET (commands[i].flags, C_PAR) && IS_MORTAL (ch))
	{
		send_to_char ("You can't move.\n", ch);
		return;
	}

	if (IS_SUBDUEE (ch) && !IS_SET (commands[i].flags, C_SUB) && !cmd_level)
	{
		act ("$N won't let you.", false, ch, 0, ch->subdue, TO_CHAR);
		return;
	}

	/* Most commands break delays */

	if (ch->delay && !IS_SET (commands[i].flags, C_DEL))
		break_delay (ch);

	/* Send this command to the log */
	if (!second_affect_active && (!IS_NPC (ch) || ch->desc))
	{
		if (IS_SET (commands[i].flags, C_NLG))
			;
		else if (i > 0)
		{			/* Log craft commands separately. */
			if (!str_cmp (commands[i].command, "."))
				player_log (ch, "say", command_args);
			else if (!str_cmp (commands[i].command, ","))
				player_log (ch, "emote", command_args);
			else if (!str_cmp (commands[i].command, ":"))
				player_log (ch, "emote", command_args);
			else if (!str_cmp (commands[i].command, ";"))
				player_log (ch, "wiznet", command_args);
			else
				player_log (ch, commands[i].command, command_args);
		}
	}

	if (IS_MORTAL (ch) && get_affect (ch, MAGIC_HIDDEN) &&
		!IS_SET (commands[i].flags, C_HID) &&
		skill_level (ch, SKILL_SNEAK, 0) < number (1, MAX(100, skill_level(ch, SKILL_SNEAK, 0))) &&
		would_reveal (ch))
	{
		remove_affect_type (ch, MAGIC_HIDDEN);
		act ("$n reveals $mself.", true, ch, 0, 0, TO_ROOM | _ACT_FORMAT);
		act ("Your actions have compromised your concealment.", true, ch, 0, 0,
			TO_CHAR);
	}

	/* Execute command */

	if (!IS_SET (commands[i].flags, C_NWT))
		show_to_watchers (ch, social_args);

	if (!i)			/* craft_command */
		craft_command (ch, command_args, craft_affect);
	else

		(*commands[i].proc) (ch, command_args, 0);

	last_descriptor = NULL;
}
Exemplo n.º 7
0
Arquivo: files.c Projeto: Schala/mhxd
static void
hxd_scandir (struct htlc_conn *htlc, const char *path)
{
	DIR *dir;
	struct dirent *de;
	struct hl_filelist_hdr **fhdrs = 0;
	u_int16_t count = 0, maxcount = 0;
	struct stat sb;
	int is_link;
	char pathbuf[MAXPATHLEN];
	u_int16_t nlen;
#if defined(CONFIG_ICONV)
	char *out_p;
	size_t out_len;
#endif
	if (!(dir = opendir(path))) {
		snd_strerror(htlc, errno);
		return;
	}
	while ((de = readdir(dir))) {
		if (skip_match(de->d_name))
			continue;
		if (count >= maxcount) {
			maxcount += 16;
			fhdrs = xrealloc(fhdrs, sizeof(struct hl_filelist_hdr *) * maxcount);
		}
		nlen = (u_int16_t)strlen(de->d_name);
		snprintf(pathbuf, sizeof(pathbuf), "%s/%s", path, de->d_name);
		fhdrs[count] = xmalloc(SIZEOF_HL_FILELIST_HDR + nlen);
		fhdrs[count]->type = HTLS_DATA_FILE_LIST;
		fhdrs[count]->len = (SIZEOF_HL_FILELIST_HDR - 4) + nlen;
		fhdrs[count]->unknown = 0;
		fhdrs[count]->encoding = 0;
		fhdrs[count]->fnlen = htons(nlen);
#if defined(CONFIG_ICONV)
		if (hxd_cfg.text.client_encoding[0] && hxd_cfg.text.server_encoding[0]) {
			out_len = convbuf(hxd_cfg.text.client_encoding,
					  hxd_cfg.text.server_encoding,
					  de->d_name, (size_t)nlen, &out_p);
			if (out_len) {
				if (out_len > (size_t)nlen)
					out_len = (size_t)nlen;
				memcpy(fhdrs[count]->fname, out_p, out_len);
				xfree(out_p);
			} else {
				memcpy(fhdrs[count]->fname, de->d_name, nlen);
			}
		} else
#endif
			memcpy(fhdrs[count]->fname, de->d_name, nlen);
#ifdef HAVE_CORESERVICES
		resolve_alias_path(pathbuf, pathbuf);
#endif
		if (SYS_lstat(pathbuf, &sb)) {
broken_alias:
			fhdrs[count]->fsize = 0;
			fhdrs[count]->ftype = htonl(0x616c6973);	/* 'alis' */
			fhdrs[count]->fcreator = 0;
			count++;
			continue;
		}
#ifdef HAVE_CORESERVICES
		if (is_alias(pathbuf, &is_link))
			goto broken_alias;
#else
		if (S_ISLNK(sb.st_mode)) {
			is_link = 1;
			if (stat(pathbuf, &sb))
				goto broken_alias;
		} else {
			is_link = 0;
		}
#endif
		if (S_ISDIR(sb.st_mode)) {
			u_int32_t ndirs = 0;
			DIR *subdir;
			struct dirent *subde;
			if ((subdir = opendir(pathbuf))) {
				while ((subde = readdir(subdir)))
					if (!skip_match(subde->d_name))
						ndirs++;
				closedir(subdir);
			}
			fhdrs[count]->fsize = htonl(ndirs);
			fhdrs[count]->ftype = htonl(0x666c6472);	/* 'fldr' */
			fhdrs[count]->fcreator = 0;
		} else {
			u_int32_t size = sb.st_size;
#if defined(CONFIG_HFS)
			if (hxd_cfg.operation.hfs) {
				size += resource_len(pathbuf);
				type_creator((u_int8_t *)&fhdrs[count]->ftype, pathbuf);
			} else {
				fhdrs[count]->ftype = 0;
				fhdrs[count]->fcreator = 0;
			}
#else
			fhdrs[count]->ftype = 0;
			fhdrs[count]->fcreator = 0;
#endif
			fhdrs[count]->fsize = htonl(size);
		}
		count++;
	}
	closedir(dir);
	if (fhdrs)
		fh_sort(fhdrs, count);
	hlwrite_dhdrs(htlc, count, (struct hl_data_hdr **)fhdrs);
	while (count) {
		count--;
		xfree(fhdrs[count]);
	}
	if (fhdrs)
		xfree(fhdrs);
}
Exemplo n.º 8
0
Arquivo: hfs.c Projeto: asvitkine/phxd
void
type_creator (u_int8_t *buf, const char *path)
{
   char infopath[MAXPATHLEN];
   struct stat sb;
   u_int8_t is_link = 0;

#ifdef HAVE_CORESERVICES
   if (!resolve_alias_path(path, infopath) || mac_errno)
      return;

   if (is_alias(infopath, &is_link) || mac_errno)
      return;

   if (is_link)
      strcpy(buf, "alis");
   else {
      char type[5], creator[5];
      if (!mac_get_type(infopath, type, creator) && !mac_errno) {
         memcpy(buf, type, 4);
         memcpy(buf + 4, creator, 4);
      }
   }

   if (memcmp(buf, "????????", 8))
      return;
#endif
      

   if (!finderinfo_path(infopath, path, &sb)) {
      int r, f;

      f = open(infopath, O_RDONLY);
      if (f < 0)
         goto use_suffix;
      switch (cfg.fork) {
         default:
         case HFS_FORK_CAP:
            r = read(f, buf, 8);
            if (r != 8 || !(*(u_int32_t *)(&buf[0])) || !(*(u_int32_t *)(&buf[4])))
               r = 0;
            break;
         case HFS_FORK_NETATALK:
         case HFS_FORK_DOUBLE:
            {
               struct hfs_dbl_hdr dbl;
               int i;

               r = read(f, &dbl, SIZEOF_HFS_DBL_HDR);
               if (r != SIZEOF_HFS_DBL_HDR) {
                  r = -1;
                  break;
               }
               if (ntohs(dbl.entries) > HFS_HDR_MAX)
                  dbl.entries = htons(HFS_HDR_MAX);
               r = read(f, &dbl.descrs, SIZEOF_HFS_HDR_DESCR * ntohs(dbl.entries));
               if (r != SIZEOF_HFS_HDR_DESCR * ntohs(dbl.entries)) {
                  r = -1;
                  break;
               }
               for (i = 0; i < ntohs(dbl.entries); i++) {
                  struct hfs_hdr_descr *descr = (struct hfs_hdr_descr *)(&dbl.descrs[SIZEOF_HFS_HDR_DESCR * i]);
                  if (ntohl(descr->id) == HFS_HDR_FINFO) {
                     if (lseek(f, ntohl(descr->offset), SEEK_SET) != (off_t)ntohl(descr->offset))
                        continue;
                     r = 8;
                     r = read(f, buf, 8);
                     break;
                  }
               }
            }
            break;
      }
      close(f);
      if (r == 8)
         return;
   }

use_suffix:
   suffix_type_creator(buf, path);
}