Esempio n. 1
0
void main( string str) {
  string path;
  object ob;
  object *usr;

  int i;
  int flag;

  string what;
  string who;

  /*  string *words;

      words = explode( str, " " );

      who = words[0]; 
      what = words[1]; */

 sscanf( str, "%s %s", who, what );

  usr = USER_D->query_users();
  flag = 0;
  
  if (strlen(str) > 2) {
    if( (str[strlen(str)-2] == '.') 
	&& (str[strlen(str)-1] == 'c') )
      str = str[..strlen(str)-3];
  }

  path = this_player()->query_env( "cwd" );  

  for( i = 0; i < sizeof( usr ); i++) {
    if( usr[i]->query_name() == who ) {
      flag = 1;
      path = normalize_path( what, path);
      if( !path || path == "" ) {
	write( "Access denied.\n" );
	return;
      }

      /*      write (path + ".c"); */
      /*    write ( path ); */
      if( file_exists( path + ".c") ) {
	ob = clone_object( path );
	  if( ob ) {
	    ob->move(usr[i]->query_player()->query_environment() );
	    usr[i]->query_player()->query_environment()->tell_room( nil, capitalize(article(ob->query_id())) + " " + ob->query_id() + " appears out of nowhere.\n" );
	    write( "You send " + article(ob->query_id() ) + " " + ob->query_id() + " to " + capitalize(who) + ".\n");
	  }
      } else {
	write( "File not found.\n" );
      }
    }
  }
  if (flag == 0){
    write( capitalize(who) + " not found.\n");
  }
}
void create() {
    set_cookie_type();   // Setsn a random type
    set("author", "cyanide");
    set("long", wrap("Definitely the tastiest "+cookie_type+
	" cookie you have ever seen!") );
    set("short", article(cookie_type)+" "+cookie_type+" cookie");
    set("id", ({ "cookie" }) );
Esempio n. 3
0
string living_description (object ob) {
  object *inv;
  int i;
  string a1, a2, tmp, reg, race, raceat, short, gender, genat;
   
  reg = (string)ob->query ("long");
  if (!reg)
    reg = "";
   
  race = (string)ob->query ("race");
  raceat = article (race) + " " + race;
  gender = (string)ob->query ("gender");
  genat = ((viewingOb == ob) ? "You are"
			      : capitalize (subjective (gender)) + " is");
  
  i = sizeof (inv = all_inventory(ob));
  while (i--)
    if (tmp = inv[i]->query ("extra_look")) {
      while (sscanf(tmp, "%s$N%s", a1, a2) > 1)
        tmp = sprintf ("%s%s%s", a1, ob->query ("cap_name"), a2);
      reg += tmp;
    }

  if (stringp (race) && race != "")
    reg = sprintf ("%s%s %s.\n", reg, genat, raceat);
   
#ifndef BLOCK_ATTACK
  if (!Attacking) {
#endif
  inv = filter_array (inv, "can_see2", this_object(), viewingOb);
  i = sizeof (inv);
  if (i) {
    reg = sprintf ("%s %s carrying:\n", reg, genat);
    while (i--) {
      short = (string)inv[i]->query ("short");
      if (short)
	reg = sprintf ("%s  %s%s%s.\n", reg, short,
		(inv[i]->query ("equipped") ? " (equipped)" : ""),
		(inv[i]->query ("wielded") ? " (wielded)" : ""));
    }
  } else
Esempio n. 4
0
void equip_clothing( player *p, std::string clothing )
{
    item article(clothing, 0);
    p->wear_item( &article );
}
Esempio n. 5
0
void Articles::generate_main_pages(
    std::map<std::string,std::string> lang2MainPages
) {

    models::Articles articlesModel;
    models::History historyModel;
    // will be used to store 
    std::vector<int> articleIds;
    for (auto lang2MainPage : lang2MainPages) {

        std::string lang = lang2MainPage.first;
        std::string slug = lang2MainPage.second;
        std::string title = _("Main Page");
        std::string content = _(
            "This is the default main page, you can edit it by "
            "clicking on the button on the right panel"
        );
        
        int resultId = articlesModel.get_id_from_lang_and_slug(
            lang,
            slug
        );

        if (resultId ==  ARTICLE_DOESNT_EXIST_ERROR) {
            resultId = articlesModel.create_from_lang_and_slug(
                lang,
                slug,
                title,
                content
            );
            
            results::Article article(
                resultId,
                lang,
                slug,
                title,
                content
            );

            // TODO add something to say that the article
            // as been created (and not simply that a "version"
            // has been added
            historyModel.add_version(
                article,
                0,
                _("Page generated automatically")
            );
        }
        if (resultId >= 0) {
            articleIds.push_back(resultId);
     
            if (!articlesModel.group_contains_lang(articleIds[0],lang)) {
                // TODO find a better to do this
                // HACK it's highly possible (always?) that the id of the first
                // article we get is also the group id of the main articles
                // should be the case if people don't change the order in config.js
                articlesModel.add_to_group(
                    articleIds[0],
                    resultId
                );
            }

        }
             
    }

    return ;
}
Esempio n. 6
0
void Articles::create_treat() {
    TREAT_PAGE();
    CHECK_PERMISSION_OR_GO_TO_LOGIN();

    forms::articles::Create form;
    form.load(context());

    if (!form.validate()) {
        set_message(_("The form is not valid."));
        go_back_to_previous_page();
        return;
    }
    
    const std::string lang = get_interface_lang();
    const std::string slug = form.slug.value();
    const std::string title = form.title.value();
    const std::string content = form.content.value();
    const std::string summary = form.summary.value();
    // we save in database the articles
    int articleId = articlesModel->create_from_lang_and_slug(
        lang,
        slug,
        title,
        content
    );

    if (articleId <= 0) {
        set_message(_("Error while trying to add the article"));
        go_back_to_previous_page();
        return;
    }
    
    results::Article article(
        articleId,
        lang,
        slug,
        title,
        content
    );

    // TODO add something to say that the article
    // as been created (and not simply that a "version"
    // has been added
    historyModel->add_version(
        article,
        get_current_user_id(),
        summary
    );


    // if save => display newly created articles
    if (form.saveAndView.value()) {
        redirect(
            "/articles/show/" + form.slug.value()
        );

    // if save and continue => turn now in edit mode
    } else if (form.saveAndContinue.value()) {
        redirect(
            "/articles/edit/" + form.slug.value()
        );
    } else {
        go_back_to_previous_page();
    }


}
Esempio n. 7
0
void Articles::edit_treat() {
    TREAT_PAGE();
    CHECK_PERMISSION_OR_GO_TO_LOGIN();

    forms::articles::Edit form;
    form.load(context());

    if (!form.validate()) {
        //TODO add a more precise message
        set_message(_("The form is not valid."));
        go_back_to_previous_page();
        return;
    }

    //TODO check if the last_version_id the form send us
    // is different from what we have in database
    // if so , error message and redirect 
    const int lastVersionId = std::stoi(form.lastVersion.value());
    
    const std::string lang = get_interface_lang();
    const std::string slug = form.slug.value();
    const std::string title = form.title.value();
    const std::string content = form.content.value();
    const std::string summary = form.summary.value();

    // TODO maybe replace this by storing the id in an hidden 
    int articleId = articlesModel->get_id_from_lang_and_slug(
        lang,
        slug
    );
 
    results::Article article(
        articleId,
        lang,
        slug,
        title,
        content
    );
 
 
    if (lastVersionId != historyModel->get_last_version_id_of(articleId)) {
        set_message(_(
            "Error, someone has edited the article while you"
            "were also editing it"
        ));
        int conflictId = articlesModel->save_conflict(article);
        redirect(
            "/articles/show-conflict/" + std::to_string(conflictId)
        );
        return;
    }

    articlesModel->edit_from_lang_and_slug(
        lang,
        slug,
        title,
        content
    );
       

    historyModel->add_version(
        article,
        get_current_user_id(),
        summary
    );

    // we invalidate the cache for this article
    cache().rise(lang+slug);

    // we show the edit articles if the user wants to 
    // save it
    if (form.saveAndView.value()) {
        redirect(
            "/articles/show/" + form.slug.value()
        );
    // we continue in edit mode if the user wants to save and continue
    // to edit
    } else if (form.saveAndContinue.value()) {
        redirect(
            "/articles/edit/" + form.slug.value()
        );
    } else {
        go_back_to_previous_page();
    }
}
Esempio n. 8
0
}

void init()
{
    add_action( "cmd_drink", "drink" );
}

int cmd_drink( string a )
{
    if( !id( a ) )
    {
        notify_fail( "You wish to drink what?\nNB \"drink drink\" will work.\n" );
        return 0;
    }
    write( "You drink your " + query( "name" ) + ".\n" );
    say( sprintf( "%s drinks %s %s.\n",
                  (string)this_player()-> query( "cap_name" ),
                  possessive( this_player() ),
                  query( "name" ),
                ) );
    call_out( "remove", 0 );
    return 1;
}

void set_type( string a )
{
    set( "id", ({ "drink", a }) );
    set( "name", a );
    set( "short", article( a ) + " " + a );
}
Esempio n. 9
0
void Articles::create_treat() {
    TREAT_PAGE();
    LOGIN_REQUIRED();

    forms::articles::Create form;
    form.load(context());

    // if cancel => go back to main page
    if (form.cancel.value()) {
        // TODO most of the time if we are on a create page
        // its because we've clicked on a link to a non-existing
        // page, so it would be better that "cancel" return us to that page
        // maybe by storing the page url in the create form ?
        redirect(
            tatowiki::Config::main_url_from_lang(get_interface_lang())
        );
        go_back_to_previous_page();
        return;
    }

    if (!form.validate()) {
        add_error(_("The form is not valid."));
        go_back_to_previous_page();
        return;
    }

    const std::string lang = get_interface_lang();
    const std::string slug = form.slug.value();
    const std::string title = form.title.value();
    const std::string content = form.content.value();
    const std::string summary = form.summary.value();
    // we save in database the articles
    int articleId = articlesModel->create_from_lang_and_slug(
        lang,
        slug,
        title,
        content
    );

    if (articleId <= 0) {
        add_error(_("Error while trying to add the article"));
        go_back_to_previous_page();
        return;
    }
    
    results::Article article(
        articleId,
        lang,
        slug,
        title,
        content
    );

    // TODO add something to say that the article
    // as been created (and not simply that a "version"
    // has been added
    historyModel->add_version(
        article,
        get_current_user_id(),
        summary
    );


    // if save => display newly created articles
    if (form.saveAndView.value()) {
        redirect(
            "/articles/show/" + form.slug.value()
        );

    // if save and continue => turn now in edit mode
    } else if (form.saveAndContinue.value()) {
        redirect(
            "/articles/edit/" + form.slug.value()
        );
    } else {
        go_back_to_previous_page();
    }


}
Esempio n. 10
0
int cmd_stat (string name) {

	string *coins, *list, *statnames ;
	object ob ;
	string *skillnames ;
	mapping skills ;
	int i, flag ;
	string spouse, tempstr ;
	string subj ;
	mapping stats ;
	int wealth;

	if (!name) {
		return help() ;
	}
	ob = get_object(name);
	if (!ob || !living(ob)) {
		notify_fail("No such living object exists.\n");
		return 0 ;
	}
	subj = capitalize(subjective(ob->query("gender"))) ;
	tempstr = ob->query("race") ;
	if (tempstr) write (subj+" is " + article(tempstr) + " " + tempstr +
		".\n") ;
	spouse = ob->query("spouse") ;
	if (spouse) {
		write (subj+" is married to "+spouse+".\n") ;
	}
	if ((int)ob->query("no_attack")) {
		write (subj+"  is not an attackable object.\n") ;
	}


	flag = ob->query("drunk") ;
	switch (flag) {
		case 1..5 : {
			write (subj+" are a bit tispy.\n") ;
			break ;
		}
		case 6..10 : {
			write (subj+" are somewhat drunk.\n") ;
			break ;
		}
		case 11..15 : {
			write (subj+" are rather drunk.\n") ;
			break ;
		}
		case 16..20 : {
			write (subj+" are completely smashed.\n") ;
			break ;
		}
		case 21..25 : {
			write (subj+" are maximally drunk.\n") ;
			break ;
		}
	}

	write ("Hit points: "+ob->query("hit_points")+" of "+
		ob->query("max_hp")+"\n") ;
	write ("Spell points: "+ob->query("spell_points")+" of "+
		ob->query("max_sp")+"\n") ;
	write ("\n") ;
	stats = ob->query("stat") ;
	if (stats && sizeof(stats)) {
	statnames = keys(stats) ;
	for (i=0;i<sizeof(stats);i++) {
		write (sprintf("%12-s : %d\n",capitalize(statnames[i]),stats[statnames[i]])) ;
	}
	write ("\n") ;
	}

	wealth = ob->query("wealth") ;
	if (!wealth) {
                write (subj+" doesn't have any coins in "+
               possessive(ob->query("gender"))+" purse.\n");
	} else {
 write ("Wealth:"+wealth+" coins.\n");
		}
	
	skills = ob->query_skills() ;
	if (skills && sizeof(skills)) {
	skillnames = keys(skills) ;
	write ("\n") ;
	write (capitalize(possessive(ob->query("gender"))) +
		 " skills are:\n") ;
	list = sort_array(skillnames, "sort_skills", this_object()) ;
	for (i=0;i<sizeof(skills);i++) {
		write (sprintf("%24-s : %d\n",capitalize(list[i]),skills[list[i]])) ;
	}
	}
	return 1 ;
}