Ejemplo n.º 1
0
Archivo: file.c Proyecto: Elohim/FGmud
/*
 * There is an error in a specific file. Ask the MudOS driver to log the
 * message somewhere.
 */
void smart_log (const char * error_file, int line, const char * what, int flag)
{
    char *buff;
    svalue_t *mret;
    extern int pragmas;

    buff = (char *)
        DMALLOC(strlen(error_file) + strlen(what) + 
                ((pragmas & PRAGMA_ERROR_CONTEXT) ? 100 : 40), TAG_TEMPORARY, "smart_log: 1");

    if (flag)
        sprintf(buff, "/%s line %d: Warning: %s", error_file, line, what);
    else
        sprintf(buff, "/%s line %d: %s", error_file, line, what);

    if (pragmas & PRAGMA_ERROR_CONTEXT) {
        char *ls = strrchr(buff, '\n');
        unsigned char *tmp;
        if (ls) {
            tmp = (unsigned char *)ls + 1;
            while (*tmp && isspace(*tmp)) tmp++;
            if (!*tmp) *ls = 0;
        }
        strcat(buff, show_error_context());
    } else strcat(buff, "\n");

    push_malloced_string(add_slash(error_file));
    copy_and_push_string(buff);
    mret = safe_apply_master_ob(APPLY_LOG_ERROR, 2);
    if (!mret || mret == (svalue_t *)-1) {
        debug_message("%s", buff);
    }
    FREE(buff);
}                               /* smart_log() */
Ejemplo n.º 2
0
void f_mg_get_oid(){
	char id[25];
	bson_oid_t oid;
	bson_oid_gen( &oid );
	bson_oid_to_string(&oid,id);
	copy_and_push_string(id);
}
Ejemplo n.º 3
0
Archivo: file.c Proyecto: Elohim/FGmud
/*
 * Check that a path to a file is valid for read or write.
 * This is done by functions in the master object.
 * The path is always treated as an absolute path, and is returned without
 * a leading '/'.
 * If the path was '/', then '.' is returned.
 * Otherwise, the returned path is temporarily allocated by apply(), which
 * means it will be deallocated at next apply().
 */
const char *check_valid_path (const char * path, object_t * call_object, const char * const  call_fun, int writeflg)
{
    svalue_t *v;

    if(!master_ob && !call_object){
    	//early startup, ignore security
    	extern svalue_t apply_ret_value;
        free_svalue(&apply_ret_value, "check_valid_path");
        apply_ret_value.type = T_STRING;
        apply_ret_value.subtype = STRING_MALLOC;
        path = apply_ret_value.u.string = string_copy(path, "check_valid_path");
    	return path;
    }

    if (call_object == 0 || call_object->flags & O_DESTRUCTED)
        return 0;

#ifdef WIN32
    {
        char *p;
        
        for(p=path; *p; p++) if (*p == '\\') *p='/';
    }
#endif

    copy_and_push_string(path);
    push_object(call_object);
    push_constant_string(call_fun);
    if (writeflg)
        v = apply_master_ob(APPLY_VALID_WRITE, 3);
    else
        v = apply_master_ob(APPLY_VALID_READ, 3);

    if (v == (svalue_t *)-1)
        v = 0;
    
    if (v && v->type == T_NUMBER && v->u.number == 0) return 0;
    if (v && v->type == T_STRING) {
        path = v->u.string;
    } else {
        extern svalue_t apply_ret_value;
        
        free_svalue(&apply_ret_value, "check_valid_path");
        apply_ret_value.type = T_STRING;
        apply_ret_value.subtype = STRING_MALLOC;
        path = apply_ret_value.u.string = string_copy(path, "check_valid_path");
    }
    
    if (path[0] == '/')
        path++;
    if (path[0] == '\0')
        path = ".";
    if (legal_path(path))
        return path;

    return 0;
}
Ejemplo n.º 4
0
void f_utf8_to(){
  struct translation *newt = get_translator((char *)sp->u.string);
  pop_stack();
  if(!newt)
    error("unknown encoding");
  char *text = (char *)sp->u.string;
  char *translated = translate_easy(newt->outgoing, text);
  pop_stack();
  copy_and_push_string(translated);
}
Ejemplo n.º 5
0
Archivo: async.c Proyecto: Elohim/FGmud
void handle_db_exec(struct request *req){
	free_svalue(&req->tmp, "handle_db_exec");
	int val = req->ret;
	if(val == -1){
		copy_and_push_string(req->path);
	}
	else
		push_number(val);
	set_eval(max_cost);
	safe_call_efun_callback(req->fun, 1);
}
Ejemplo n.º 6
0
static const char *author_for_file (const char * file)
{
    svalue_t *ret;
    static char buff[50];

    copy_and_push_string(file);
    ret = apply_master_ob(APPLY_AUTHOR_FILE, 1);
    if (ret == 0 || ret == (svalue_t*)-1 || ret->type != T_STRING)
	return 0;
    strcpy(buff, ret->u.string);
    return buff;
}
Ejemplo n.º 7
0
void f_arr_to_str(){
  static struct translation *newt = 0;
  if(!newt){
    newt = get_translator("UTF-32");
  }
  int len = sp->u.arr->size;
  int *in = (int *)DMALLOC(sizeof(int)*(len+1), TAG_TEMPORARY, "f_arr_to_str");
  char *trans;
  in[len] = 0;
  while(len--)
    in[len] = sp->u.arr->item[len].u.number;

  trans = translate(newt->incoming, (char *)in, (sp->u.arr->size+1)*4, &len);
  FREE(in);
  pop_stack();
  copy_and_push_string(trans);
}
Ejemplo n.º 8
0
void f_add_a() {
   const char *str = sp->u.string;
   char *ret;
   char *p;
   char first;
   int len;
   int an;

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

   // If *str is 0, it was only spaces.  Return "a ".
   if( *str == 0 ) {
      pop_stack();
      copy_and_push_string( "a " );
      return;
   }

   len = strlen( str );
// Don't add anything if it already begins with a or an.
   if( !strncasecmp( str, "a ", 2 ) || !strncasecmp( str, "an ", 3 ) ) {
      return;
   }

   first = *str;
   an = 0;

   // Some special cases.
   // If it begins with "us", check the following letter.
   // "a use", "a usurper", "a user", but "an usher".
   if( !strncasecmp( str, "us", 2 ) ) {
      first = str[2];
      an = 1;
   }

   // "hour*" gets "an".
   if( !strncasecmp( str, "hour", 4 ) ) {
      first = 'o';
   }

   switch( first ) {
      case 'a':
      case 'e':
      case 'i':
      case 'o':
      case 'u':
      case 'A':
      case 'E':
      case 'I':
      case 'O':
      case 'U':
         an = !an;
         break;
      default:
         break;
   }

   if( an ) {  // Add an.
      if( len + 3 > max_string_length ) {
         free_string_svalue( sp );
         error( "add_a() exceeded max string length.\n" );
      }
      ret = new_string( len + 3, "f_add_a" );
      memcpy( ret, "an ", 3 );
      p = ret + 3;
   }
   else {      // Add a.
      if( len + 2 > max_string_length ) {
         free_string_svalue( sp );
         error( "add_a() exceeded max string length.\n" );
      }
      ret = new_string( len + 2, "f_add_a" );
      memcpy( ret, "a ", 2 );
      p = ret + 2;
   }

   // Add the rest of the string.
   memcpy( p, str, len + 1 );    // + 1: get the \0.
   free_string_svalue( sp );
   sp->type = T_STRING;
   sp->subtype = STRING_MALLOC;
   sp->u.string = ret;
}
Ejemplo n.º 9
0
int reference_allowed(object_t * referee, object_t * referrer_obj, const char * referrer_name) 
{
    int invis = 0;
    int referee_creator = 0;
    svalue_t *v;
    svalue_t *item;
    array_t *vec;
    const char *referee_name = NULL;
    object_t *playtester_handler = NULL;
    object_t *player_handler = NULL;
    int referrer_playtester = 0;
    int referrer_match = 0; 
    int playtester_match = 0;
    int i;
    int size;
    int ret = 0; 
   
    /* Check to see whether we're invisible */ 
    v = apply("query_invis", referee, 0, ORIGIN_EFUN);

    if (v && v->type == T_NUMBER) {
        invis = v->u.number;
    }
    /* And if we're a creator. */ 
    v = apply("query_creator", referee, 0, ORIGIN_EFUN);

    if ( v && v->type == T_NUMBER) {
        referee_creator = v->u.number;
    }
    
    /* If we're not invisible, or not a creator, or currently in a 
       reference allowed call, then we can see them. */ 
    if (!invis || !referee_creator || _in_reference_allowed) {
        return 1;
    }

    _in_reference_allowed = 1;
    
    if (referrer_obj && referee == referrer_obj) {
        _in_reference_allowed = 0;
        return 1;
    }
    
    /* Determine the names of these guys.
     * We might need to make copies of these strings? apply()
     * has a few oddities. 
     */ 

    v = apply("query_name", referee, 0, ORIGIN_EFUN);

    if (v && v->type == T_STRING) {
        referee_name = v->u.string;
    }
    
    if (referrer_obj && !referrer_name) { 
        v = apply("query_name", referrer_obj, 0, ORIGIN_EFUN);

        if (v && v->type == T_STRING) { 
            referrer_name = v->u.string;    
        }
    }
    
    if (!referee_name || !referrer_name) {
        _in_reference_allowed = 0;
        return 1;
    }

    playtester_handler = find_object(PLAYTESTER_HANDLER);
    
    if ( playtester_handler ) { 
        copy_and_push_string(referrer_name);
        v = apply("query_playtester", playtester_handler, 1, ORIGIN_EFUN);
        
        if (v && v->type == T_NUMBER) { 
            referrer_playtester =  v->u.number;
        }
    }

    v = apply( "query_allowed", referee, 0, ORIGIN_EFUN);

    if (v && v->type == T_ARRAY) {
        vec = v->u.arr;
        size = vec->size;
        /* Iterate through the allowed array. */ 
        for (i = 0; i < size; i++) {
            item = vec->item + i;

            if (strcmp(referrer_name, item->u.string) == 0) { 
                referrer_match = 1;
                
                /* If they're not a playtester, then bail as soon as 
                 * we make this match. */ 
                if (!referrer_playtester) {
                    break;
                }
            }

            if (referrer_playtester && 
                strcmp("playtesters", item->u.string) == 0) { 
                playtester_match = 1;
                
                /* If we've already made a referrer match, then time
                 * to bail now. */ 
                if (referrer_match) {
                    break;
                }
            }
        }
    }
    
    /* If we found a match, then they are allowed so bail. */ 
    if ( referrer_match || playtester_match ) {
        _in_reference_allowed = 0;
        return 1;
    }

    switch(invis) { 
        case 3:
            /* Check for High Lord Invis. */ 

            copy_and_push_string(referrer_name);
            v = apply("high_programmer", master_ob, 1, ORIGIN_EFUN);
            
            if (v && v->type == T_NUMBER) {
                ret = v->u.number;
            }
        break;
        
        case 2:
            /* Check for Lord Invis */

                      copy_and_push_string(referrer_name);
            v = apply("query_lord", master_ob, 1, ORIGIN_EFUN);
            
            if (v && v->type == T_NUMBER) {
                ret = v->u.number;
            }
        break;

        case 1: { 
            /* Creator Invis */ 
            if (referrer_obj) {
                v = apply("query_creator", referrer_obj, 0, ORIGIN_EFUN);

                if (v && v->type == T_NUMBER) {
                    ret = v->u.number;
                }
            }
            else {
                player_handler = find_object(PLAYER_HANDLER);
                copy_and_push_string(referrer_name);
                v = apply("test_creator", player_handler, 1, ORIGIN_EFUN);

                if (v && v->type == T_NUMBER) {
                    ret = v->u.number;
                }
            }
        }
        break;

        default:
            /* A normal player.
             * Shouldn't we do this somewhere else? */
            
            ret = 1;
        break;
    }

    _in_reference_allowed = 0;
    return ret;
}
Ejemplo n.º 10
0
/* Hideous mangling of C code by Taffyd. */ 
void query_multiple_short(svalue_t * arg, const char * type, int no_dollars, int quiet, int dark, int num_arg) { 
    char m[] = "$M$";
    char s[] = "_short";
    char default_function[] = "a_short";
    char separator[] = ", ";
    char andsep[] = " and ";
    int mlen = strlen(m);
    int slen = strlen(s);
    int seplen = strlen( separator );
    int andlen = strlen( andsep );

    array_t *arr = arg->u.arr;
    svalue_t *sv;
    svalue_t *v;
    int size = arr->size;
    int i;
    int len;
    int total_len;
    char *str, *res;
    object_t *ob;
    char *fun; 

    if (!size) {
        str = new_string(0, "f_query_multiple_short");
        str[0] = '\0';
        pop_n_elems(num_arg);
        push_malloced_string(str);
        return; 
    }
    
    /* 
    if (no_dollars && sizeof(args) && objectp(args[0]) && undefinedp(dark) && 
        this_player() && environment(this_player())) {
        dark = this_player()->check_dark(environment(this_player())->query_light());
        if (dark) {
        return "some objects you cannot make out";
        }
    } */ 

    if (no_dollars && arr->item->type == T_OBJECT && !dark && command_giver &&
        command_giver->super) { 
        call_origin = ORIGIN_EFUN;
        if(!apply_low("query_light", command_giver->super, 0))
            push_number(0);
        v = apply("check_dark", command_giver, 1, ORIGIN_EFUN);
        
        if (v && v->type == T_NUMBER && v->u.number) {
            pop_n_elems(num_arg);
            copy_and_push_string("some objects you cannot make out"); 
            return;
        }
    }

    /* If we don't have a type parameter, then use default_function */ 
    /* We need to free this value with FREE_MSTR() */ 

    if ( !type ) { 
        len = strlen( default_function );
        fun = new_string( len, "f_query_multiple_short");
        fun[len] = '\0';
        strncpy( fun, default_function, len );
    }
    else { 
        len = strlen( type ) + slen;
        fun = new_string( len, "f_query_multiple_short");
        fun[len] = '\0';
        strncpy( fun, type, len );
        strncpy( fun + strlen( type ), s, slen);
    }
   
    /* Check to see if there are any non-objects in the array. */ 
    for (i = 0; i < size; i++) {
        if ((arr->item + i)->type != T_OBJECT) {
            break;
        }
    }

    /* The array consists only of objects, and will use the $M$ 
       expansion code. */ 
    if (i == size && !no_dollars) {
        str = new_string(max_string_length, "f_query_multiple_short");
        str[max_string_length]= '\0';
        strncpy(str, m, mlen);
        total_len = mlen;

        for ( i = 0; i < size; i++ ) {
            sv = (arr->item + i);
            push_number(quiet);
            v = apply(fun, sv->u.ob, 1, ORIGIN_EFUN);

            if (!v || v->type != T_STRING) {
                continue;                
            }
            if(total_len + SVALUE_STRLEN(v) > max_string_length - mlen)
                continue;
            strncpy(str + total_len, v->u.string, (len = SVALUE_STRLEN(v)));
            total_len += len;
        }

        strncpy(str + total_len, m, mlen);
        total_len += mlen;

        res = new_string( total_len, "f_query_multiple_short" );
        res[ total_len ] = '\0';
        memcpy(res, str, total_len);

        /* Clean up our temporary buffer. */ 

        FREE_MSTR(str);
        FREE_MSTR(fun);

        pop_n_elems(num_arg);
        push_malloced_string(res);
        return;
    }

    /* This is a mixed array, so we don't use $M$ format.  Instead, we 
       do as much $a_short$ conversion as we can etc.  */ 

    str = new_string(max_string_length, "f_query_multiple_short");
    str[max_string_length]= '\0';
    total_len = 0;

    for ( i = 0; i < size; i++ ) {
        sv = (arr->item + i);
    
        switch(sv->type) {
            case T_STRING:
                len = SVALUE_STRLEN(sv);
                if(total_len + len < max_string_length){
                    strncpy(str + total_len, sv->u.string, len);
                    total_len += len;
                }
                break;
            case T_OBJECT:
                push_number(quiet);
                v = apply(fun, sv->u.ob, 1, ORIGIN_EFUN);

                if (!v || v->type != T_STRING) {
                    continue;                
                }

                if(total_len + SVALUE_STRLEN(v) < max_string_length){
                    strncpy(str + total_len, v->u.string, 
                            (len = SVALUE_STRLEN(v)));
                    total_len += len;
                }

                break;
            case T_ARRAY:
              /* Does anyone use this? */ 
              /* args[ i ] = "$"+ type +"_short:"+ file_name( args[ i ][ 1 ] ) +"$"; */ 
            default:    
                /* Get the next element. */ 
                continue;            
                break;
        }
        
        if ( len && size > 1 ) {
            if ( i < size - 2 ) {
                if(total_len+seplen < max_string_length){
                    strncpy( str + total_len, separator, seplen );
                    total_len += seplen;
                }
            }
            else { 
                if ( i < size - 1 ) {    
                    if(total_len+andlen < max_string_length){
                        strncpy( str + total_len, andsep, andlen );
                        total_len += andlen;
                    }
                }
            }
        }
    }

    FREE_MSTR(fun);

    res = new_string(total_len, "f_query_multiple_short");
    res[total_len] = '\0';
    memcpy(res, str, total_len);

    FREE_MSTR(str);

    /* Ok, now that we have cleaned up here we have to decide what to do
       with it. If nodollars is 0, then we need to pass it to an object
       for conversion. */ 

    if (no_dollars) { 
        if (command_giver) { 
            /* We need to call on this_player(). */ 
            push_malloced_string(res);
            v = apply("convert_message", command_giver, 1, ORIGIN_EFUN);
            
            if (v && v->type == T_STRING) { 
                pop_n_elems(num_arg);
                share_and_push_string(v->u.string);
            }
            else { 
                pop_n_elems(num_arg);
                push_undefined();
            }
            
        }
        else {
            /* We need to find /global/player. */ 
            /* Does this work? Seems not to. */ 
            ob = find_object("/global/player");
            
            if (ob) {
                push_malloced_string(res);
                v = apply("convert_message", ob, 1, ORIGIN_EFUN);
                
                /* Return the result! */ 
                if (v && v->type == T_STRING) { 
                    pop_n_elems(num_arg);
                    share_and_push_string(v->u.string);
                }
                else { 
                    pop_n_elems(num_arg);
                    push_undefined();
                }
            }
            else { 
                pop_n_elems(num_arg);
                push_undefined();
            }
        }

    }
    else { 
        pop_n_elems(num_arg);
        push_malloced_string(res);
    }
} /* query_multiple_short() */
Ejemplo n.º 11
0
static int user_parser (char * buff)
{
    char verb_buff[MAX_VERB_BUFF];
    sentence_t *s;
    char *p;
    int length;
    char *user_verb = 0;
    int where;
    int save_illegal_sentence_action;

    debug(d_flag, ("cmd [/%s]: %s\n", command_giver->obname, buff));

    /* strip trailing spaces. */
    for (p = buff + strlen(buff) - 1; p >= buff; p--) {
	if (*p != ' ')
	    break;
	*p = '\0';
    }
    if (buff[0] == '\0')
	return 0;
    length = p - buff + 1;
    p = strchr(buff, ' ');
    if (p == 0) {
	user_verb = findstring(buff);
    } else {
	*p = '\0';
	user_verb = findstring(buff);
	*p = ' ';
	length = p - buff;
    }
    if (!user_verb) {
	/* either an xverb or a verb without a specific add_action */
	user_verb = buff;
    }
    /*
     * copy user_verb into a static character buffer to be pointed to by
     * last_verb.
     */
    strncpy(verb_buff, user_verb, MAX_VERB_BUFF - 1);
    if (p) {
	int pos;

	pos = p - buff;
	if (pos < MAX_VERB_BUFF) {
	    verb_buff[pos] = '\0';
	}
    }

    save_illegal_sentence_action = illegal_sentence_action;
    illegal_sentence_action = 0;
    for (s = command_giver->sent; s; s = s->next) {
	svalue_t *ret;
	object_t *command_object;

	if (s->flags & (V_NOSPACE | V_SHORT)) {
	    if (strncmp(buff, s->verb, strlen(s->verb)) != 0)
		continue;
	} else {
	    /* note: if was add_action(blah, "") then accept it */
	    if (s->verb[0] && (user_verb != s->verb))
		continue;
	}
	/*
	 * Now we have found a special sentence !
	 */

	if (!(s->flags & V_FUNCTION))
	    debug(d_flag, ("Local command %s on /%s",
			   s->function.s, s->ob->obname));

	if (s->flags & V_NOSPACE) {
	    int l1 = strlen(s->verb);
	    int l2 = strlen(verb_buff);

	    if (l1 < l2)
		last_verb = verb_buff + l1;
	    else
		last_verb = "";
	} else {
	    if (!s->verb[0] || (s->flags & V_SHORT))
		last_verb = verb_buff;
	    else
		last_verb = s->verb;
	}
	/*
	 * If the function is static and not defined by current object, then
	 * it will fail. If this is called directly from user input, then
	 * the origin is the driver and it will be allowed.
	 */
	where = (current_object ? ORIGIN_EFUN : ORIGIN_DRIVER);

	/*
	 * Remember the object, to update moves.
	 */
	command_object = s->ob;
	save_command_giver(command_giver);
	if (s->flags & V_NOSPACE) {
	    copy_and_push_string(&buff[strlen(s->verb)]);
	} else if (buff[length] == ' ') {
	    copy_and_push_string(&buff[length + 1]);
	} else {
	    push_undefined();
	}
	if (s->flags & V_FUNCTION) {
	    ret = call_function_pointer(s->function.f, 1);
	} else {
	    if (s->function.s[0] == APPLY___INIT_SPECIAL_CHAR)
		error("Illegal function name.\n");
	    ret = apply(s->function.s, s->ob, 1, where);
	}
	/* s may be dangling at this point */

	restore_command_giver();

	last_verb = 0;

	/* was this the right verb? */
	if (ret == 0) {
	    /* is it still around?  Otherwise, ignore this ...
	       it moved somewhere or dested itself */
	    if (s == command_giver->sent) {
		char buf[256];
		if (s->flags & V_FUNCTION) {
		    sprintf(buf, "Verb '%s' bound to uncallable function pointer.\n", s->verb);
		    error(buf);
		} else {
		    sprintf(buf, "Function for verb '%s' not found.\n",
			    s->verb);
		    error(buf);
		}
	    }
	}

	if (ret && (ret->type != T_NUMBER || ret->u.number != 0)) {
#ifdef PACKAGE_MUDLIB_STATS
	    if (command_giver && command_giver->interactive
#ifndef NO_WIZARDS
		&& !(command_giver->flags & O_IS_WIZARD)
#endif
		)
		add_moves(&command_object->stats, 1);
#endif
	    if (!illegal_sentence_action)
		illegal_sentence_action = save_illegal_sentence_action;
	    return 1;
	}
	if (illegal_sentence_action) {
	    switch (illegal_sentence_action) {
	    case 1:
		error("Illegal to call remove_action() [caller was /%s] from a verb returning zero.\n", illegal_sentence_ob->obname);
	    case 2:
		error("Illegal to move or destruct an object (/%s) defining actions from a verb function which returns zero.\n", illegal_sentence_ob->obname);
	    }
	}
    }
    notify_no_command();
    illegal_sentence_action = save_illegal_sentence_action;

    return 0;
}