Example #1
0
const char *char_data::get_whoname( )
{
    char buf[MSL] = {'\0'};
    short s1, s2, s3, s4, s5;
    const char *output;

    if ( IS_NPC(this) )
        return "";

    if ( IS_IMMORTAL(this) )
    {
        if ( strcmp(pcdata->who_name,"off") )
            return pcdata->who_name;

        switch ( get_level() )
        {
            case MAX_LEVEL - 0: return "@@l~* CREATOR *~@@N ";
            case MAX_LEVEL - 1: return "@@B-* SUPREME *-@@N ";
            case MAX_LEVEL - 2: return "@@a-=MAJOR GOD=-@@N ";
            case MAX_LEVEL - 3: return "@@a--MINOR GOD--@@N ";
            case MAX_LEVEL - 4: return "@@c - IMMORTAL -@@N ";
        }
    }

    if ( IS_ADEPT(this) )
    {
        if ( strcmp(pcdata->who_name,"off") )
            return pcdata->who_name;

        switch ( get_level("adept") )
        {
            case 1:  return "@@W    Mystic    @@N";
            case 2:  return "@@a   Templar    @@N";
            case 3:  return "@@l Illusionist  @@N";
            case 4:  return "@@e   Crusader   @@N";
            case 5:  return "@@d   Warlock    @@N";
            case 6:  return "@@a   Paladin    @@N";
            case 7:  return "@@r    Ranger    @@N";
            case 8:  return "@@c  Gladiator   @@N";
            case 9:  return "@@l    Shogun    @@N";
            case 10: return "@@e    Shamen    @@N";
            case 11: return "@@r    Druid     @@N";
            case 12: return "@@b  Conjurer    @@N";
            case 13: return "@@l Elementalist @@N";
            case 14: return "@@m  Runemaster  @@N";
            case 15: return "@@d Shadowmaster @@N";
            case 16: return "@@b Beastmaster  @@N";
            case 17: return "@@R   Warlord    @@N";
            case 18: return "@@e  Dragonlord  @@N";
            case 19: return "@@d  Demonlord   @@N";
            case 20: return "@@m  Realm Lord  @@N";
        }
    }

    if ( IS_REMORT(this) )
    {
        s1 = get_level("sor"); s2 = get_level("mon"); s3 = get_level("ass"); s4 = get_level("kni"); s5 = get_level("nec");
        snprintf( buf, MSL, "@@m%2d %2d %2d %2d %2d@@N", s1 <= 0 ? 0 : s1, s2 <= 0 ? 0 : s2, s3 <= 0 ? 0 : s3, s4 <= 0 ? 0 : s4, s5 <= 0 ? 0 : s5 );
        output = str_dup( buf );

        return output;
    }
    else
    {
        s1 = get_level("mag"); s2 = get_level("cle"); s3 = get_level("thi"); s4 = get_level("war"); s5 = get_level("psi");
        snprintf( buf, MSL, "@@b%2d %2d %2d %2d %2d@@N", s1 <= 0 ? 0 : s1, s2 <= 0 ? 0 : s2, s3 <= 0 ? 0 : s3, s4 <= 0 ? 0 : s4, s5 <= 0 ? 0 : s5 );
        output = str_dup( buf );

        return output;
    }

    return "";
}
Example #2
0
void do_note( CHAR_DATA *ch, char *argument )
{
    char buf[MAX_STRING_LENGTH];
    char arg[MAX_INPUT_LENGTH];
    NOTE_DATA *pnote;
    int vnum;
    int anum;

    if ( IS_NPC(ch) )
	return;

    argument = one_argument( argument, arg );
    smash_tilde( argument );

    if ( !str_cmp( arg, "list" ) )
    {
	vnum = 0;
	for ( pnote = note_list; pnote != NULL; pnote = pnote->next )
	{
	    if ( is_note_to( ch, pnote ) )
	    {
		sprintf( buf, "[%3d] %s: %s\n\r",
		    vnum, pnote->sender, pnote->subject );
		send_to_char( buf, ch );
		vnum++;
	    }
	}
	return;
    }

    if ( !str_cmp( arg, "read" ) )
    {
	bool fAll;

	if ( !str_cmp( argument, "all" ) )
	{
	    fAll = TRUE;
	    anum = 0;
	}
	else if ( is_number( argument ) )
	{
	    fAll = FALSE;
	    anum = atoi( argument );
	}
	else
	{
	    send_to_char( "Note read which number?\n\r", ch );
	    return;
	}

	vnum = 0;
	for ( pnote = note_list; pnote != NULL; pnote = pnote->next )
	{
	    if ( is_note_to( ch, pnote ) && ( vnum++ == anum || fAll ) )
	    {
		sprintf( buf, "[%3d] %s: %s\n\r%s\n\rTo: %s\n\r",
		    vnum - 1,
		    pnote->sender,
		    pnote->subject,
		    pnote->date,
		    pnote->to_list
		    );
		send_to_char( buf, ch );
		send_to_char( pnote->text, ch );
		return;
	    }
	}

	send_to_char( "No such note.\n\r", ch );
	return;
    }

    if ( !str_cmp( arg, "+" ) )
    {
	note_attach( ch );
	strcpy( buf, ch->pnote->text );
	if ( strlen(buf) + strlen(argument) >= MAX_STRING_LENGTH - 4 )
	{
	    send_to_char( "Note too long.\n\r", ch );
	    return;
	}

	strcat( buf, argument );
	strcat( buf, "\n\r" );
	free_string( ch->pnote->text );
	ch->pnote->text = str_dup( buf );
	send_to_char( "Ok.\n\r", ch );
	return;
    }

    if ( !str_cmp( arg, "subject" ) )
    {
	note_attach( ch );
	free_string( ch->pnote->subject );
	ch->pnote->subject = str_dup( argument );
	send_to_char( "Ok.\n\r", ch );
	return;
    }

    if ( !str_cmp( arg, "to" ) )
    {
	note_attach( ch );
	free_string( ch->pnote->to_list );
	ch->pnote->to_list = str_dup( argument );
	send_to_char( "Ok.\n\r", ch );
	return;
    }

    if ( !str_cmp( arg, "clear" ) )
    {
	if ( ch->pnote != NULL )
	{
	    free_string( ch->pnote->text );
	    free_string( ch->pnote->subject );
	    free_string( ch->pnote->to_list );
	    free_string( ch->pnote->date );
	    free_string( ch->pnote->sender );
	    ch->pnote->next	= note_free;
	    note_free		= ch->pnote;
	    ch->pnote		= NULL;
	}

	send_to_char( "Ok.\n\r", ch );
	return;
    }

    if ( !str_cmp( arg, "show" ) )
    {
	if ( ch->pnote == NULL )
	{
	    send_to_char( "You have no note in progress.\n\r", ch );
	    return;
	}

	sprintf( buf, "%s: %s\n\rTo: %s\n\r",
	    ch->pnote->sender,
	    ch->pnote->subject,
	    ch->pnote->to_list
	    );
	send_to_char( buf, ch );
	send_to_char( ch->pnote->text, ch );
	return;
    }

    if ( !str_cmp( arg, "post" ) )
    {
	FILE *fp;
	char *strtime;

	if ( ch->pnote == NULL )
	{
	    send_to_char( "You have no note in progress.\n\r", ch );
	    return;
	}

	ch->pnote->next			= NULL;
	strtime				= ctime( &current_time );
	strtime[strlen(strtime)-1]	= '\0';
	ch->pnote->date			= str_dup( strtime );

	if ( note_list == NULL )
	{
	    note_list	= ch->pnote;
	}
	else
	{
	    for ( pnote = note_list; pnote->next != NULL; pnote = pnote->next )
		;
	    pnote->next	= ch->pnote;
	}
	pnote		= ch->pnote;
	ch->pnote	= NULL;

	fclose( fpReserve );
	if ( ( fp = fopen( NOTE_FILE, "a" ) ) == NULL )
	{
	    perror( NOTE_FILE );
	}
	else
	{
	    fprintf( fp, "Sender  %s~\nDate    %s~\nTo      %s~\nSubject %s~\nText\n%s~\n\n",
		pnote->sender,
		pnote->date,
		pnote->to_list,
		pnote->subject,
		pnote->text
		);
	    fclose( fp );
	}
	fpReserve = fopen( NULL_FILE, "r" );

	send_to_char( "Ok.\n\r", ch );
	return;
    }

    if ( !str_cmp( arg, "remove" ) )
    {
	if ( !is_number( argument ) )
	{
	    send_to_char( "Note remove which number?\n\r", ch );
	    return;
	}

	anum = atoi( argument );
	vnum = 0;
	for ( pnote = note_list; pnote != NULL; pnote = pnote->next )
	{
	    if ( is_note_to( ch, pnote ) && vnum++ == anum )
	    {
		note_remove( ch, pnote );
		send_to_char( "Ok.\n\r", ch );
		return;
	    }
	}

	send_to_char( "No such note.\n\r", ch );
	return;
    }

    send_to_char( "Huh?  Type 'help note' for usage.\n\r", ch );
    return;
}
Example #3
0
/////////////// DO FUNCTIONS ///////////////////
void do_kingdom(CHAR_DATA * ch, char *argument)
{
	KINGDOM_DATA *kingdom;
	CHAR_DATA *vch = 0;
	DESCRIPTOR_DATA *d = 0;
	char buf[MAX_STRING_LENGTH];
	char arg1[MAX_STRING_LENGTH];
	char arg2[MAX_STRING_LENGTH];
	char arg3[MAX_STRING_LENGTH];
	long id = 0;
	long i = 0;

	if(IS_NPC(ch))
		return;

	smash_tilde(argument);
	argument = one_argument_case(argument, arg1);
	argument = one_argument_case(argument, arg2);
	strcpy(arg3, argument);

	if(IS_IMMORTAL(ch) && ch->level == MAX_LEVEL)
	{
		if(!str_cmp(arg1, "save"))
		{
			write_kingdoms();
			sprintf(buf,"cp %s %s.bak",KINGDOM_FILE,KINGDOM_FILE);
			system(buf);
			send_to_char("Done, and made backup.\n\r", ch);
			return;
		}

		if(arg1[0] == '\0')
		{
			send_to_char("Syntax: kingdom create\n\r", ch);
			return;
		}

		if(!str_cmp(arg1, "create"))
		{
			create_kingdom();
			write_kingdoms();
			send_to_char("Done.\n\r", ch);
			return;
		}

		if((!is_number(arg1) || !str_cmp(arg1, "help")))
		{
			send_to_char("Syntax: kingdom <id #> <attribute> <value>\n\r", ch);
			send_to_char("        kingdom <id #> delete\n\r", ch);
			send_to_char("\n\r", ch);
			send_to_char("Attributes:\n\r", ch);
			send_to_char("  leader name points pks pds realpoints\n\r", ch);
			send_to_char("  noansiname\n\r", ch);
			send_to_char("\n\r", ch);
		}
		else
		{
			id = atoi(arg1);

			if((kingdom = get_kingdom(id)) == &kingdom_default)
			{
				send_to_char("There is no such kingdom with that ID.\n\r", ch);
				return;
			}

			if(!str_cmp(arg2, "leader"))
			{
				if((vch = get_char_world(ch, arg3)) == 0)
				{
					send_to_char("The leader must be logged on.\n\r", ch);
					return;
				}

				free_string(kingdom->leader);
				kingdom->leader = str_dup(arg3);
				vch->pcdata->kingdom = id;
				send_to_char("Done.\n\r", ch);
				return;
			}

			if(!str_cmp(arg2, "name"))
			{
				free_string(kingdom->name);
				kingdom->name = str_dup(arg3);
				send_to_char("Done.\n\r", ch);
				return;
			}

			if(!str_cmp(arg2, "noansiname"))
			{
				free_string(kingdom->noansiname);
				kingdom->noansiname = str_dup(arg3);
				send_to_char("Done.\n\r", ch);
				return;
			}

			if(!str_cmp(arg2, "delete") && !str_cmp(arg3, "yes"))
			{
				delete_kingdom(kingdom->id);
				return;
			}

			i = atoi(arg3);

			if(!str_cmp(arg2, "points"))
			{
				kingdom->points = i;
				send_to_char("Done.\n\r", ch);
				return;
			}
			if(!str_cmp(arg2, "realpoints"))
			{
				kingdom->realpoints = i;
				send_to_char("Done.\n\r", ch);
				return;
			}
			if(!str_cmp(arg2, "pds"))
			{
				kingdom->pds = i;
				send_to_char("Done.\n\r", ch);
				return;
			}
			if(!str_cmp(arg2, "pks"))
			{
				kingdom->pks = i;
				send_to_char("Done.\n\r", ch);
				return;
			}
			if(!str_cmp(arg2, "assists"))
			{
				kingdom->assists = i;
				send_to_char("Done.\n\r", ch);
				return;
			}
		}
	}

	if(ch->pcdata->kingdom == 0)	// player not in a kingdom
	{
		if(!str_cmp(arg1, "create"))
		{
			if(ch->pcdata->quest < 1000)
			{
				send_to_char("You need 1000 quest points to create a new kingdom.\n\r", ch);
				return;
			}

			if(!arg2 || arg2[0] == '\0' || !arg3 || arg3[0] == '\0')
			{
				send_to_char
					("Syntax (DO NOT MESS THIS UP!): kingdom create \"name WITH ansi\" \"name WITHOUT ansi\"\n\r",
					 ch);
				send_to_char("I suggest you SAY the name a few times to make SURE THE ANSI IS CORRECT.\n\r",
					     ch);
				send_to_char("And if you dont put a final {{x your kingdom will be DELETED.\n\r", ch);
				send_to_char("If your kingdom name has more than one word surround it in QUOTES!\n\r", ch);
				return;
			}

			if(ansistrlen(arg2) > 20 || strlen(arg3) > 20)
			{
				send_to_char("String length is limited to 20 characters!\n\r", ch);
				return;
			}

			kingdom = create_kingdom();
			ch->pcdata->kingdom = kingdom->id;
			ch->pcdata->quest -= 1000;
			free_string(kingdom->leader);
			kingdom->leader = str_dup(ch->name);
			free_string(kingdom->name);
			kingdom->name = str_dup(arg2);
			free_string(kingdom->noansiname);
			kingdom->noansiname = str_dup(arg3);

			kingdom_message(0, "%s has {WCREATED{X The %s Kingdom!", ch->name, kingdom->name);
			write_kingdoms();
			return;
		}

		if(ch->pcdata->kingdom_invite == 0)
		{
			send_to_char("You don't belong to a kingdom.\n\r", ch);
			return;
		}

		// make sure kingdom still exists
		if(get_kingdom(ch->pcdata->kingdom_invite) == &kingdom_default)
		{
			send_to_char("That kingdom was destroyed.\n\r", ch);
			return;
		}

		if(!str_cmp(arg1, "accept"))
		{
			add_member(ch->pcdata->kingdom_invite, ch);
			return;
		}

		if(!str_cmp(arg1, "decline"))
		{
			send_to_char("You decline the kingdom's invitation.\n\r", ch);

			if((vch = get_char_world(ch, get_kingdom(ch->pcdata->kingdom_invite)->leader)) != 0)
			{
				sprintf(buf, "%s has declined your invitation.\n\r", ch->name);
				send_to_char(buf, vch);
			}
			ch->pcdata->kingdom_invite = 0;
			return;
		}

		send_to_char("Type either kingdom accept or kingdom decline.\n\r", ch);
		return;
	}

	kingdom = get_kingdom(ch->pcdata->kingdom);

	if(!str_cmp(arg1, "leave") && !str_cmp(arg2, "for") && !str_cmp(arg3, "good"))
	{
		send_to_char("You leave the kingdom!\n\r", ch);
		remove_member(kingdom->id, ch->name);
		remove_trustee(kingdom->id, ch->name);
		return;
	}

	if(!str_prefix(arg1, "report"))
	{
		long percent;
		char *color;

		buf[0] = '\0';
		sprintf(buf, "%-4s %-12s{X %5s :: %s\n\r",
			"CMBT", "Name", "Hits", "Room" );

		for(d = descriptor_list; d; d = d->next)
		{
			if(d->connected != CON_PLAYING || !(vch = d->character) || vch->pcdata->kingdom != kingdom->id)
				continue;

			percent = (long) ((float) UMAX(1, vch->hit) / (float) UMAX(1, vch->max_hit) * 100);

			if(percent < 10)
				color = "{R";
			else if(percent < 40)
				color = "{B";
			else if(percent < 70)
				color = "{Y";
			else
				color = "{C";

			sprintf(buf + strlen(buf), "%-4s %s%-12s{X %5li :: %s\n\r",
				vch->fighting ? !IS_NPC(vch->fighting) ? "{R(PK){X" : "{r(F){X" : "",
				 color, vch->name, vch->hit, !vch->in_room ? "somewhere" : vch->in_room->name);
		}
		send_to_char(buf, ch);
		return;
	}

	if(!is_trustee(ch, kingdom->id))
	{
		send_to_char("Only leaders and trustees have power to modify their kingdom.\n\r", ch);
		return;
	}

	if(arg1[0] == '\0' || arg2[0] == '\0')
	{
		if(is_leader(ch, kingdom->id) || IS_IMMORTAL(ch))
		{
			send_to_char("Syntax:\n\r", ch);
			send_to_char("        kingdom report\n\r", ch);
			send_to_char("        kingdom invite <player>\n\r", ch);
			send_to_char("        kingdom outcast <member>\n\r", ch);
			send_to_char("        kingdom war <kingdom ID>\n\r", ch);
			send_to_char("        kingdom treaty <kingdom ID>\n\r", ch);
			send_to_char("        kingdom rank <member> <rank>\n\r", ch);
			send_to_char("        kingdom trust <member>\n\r", ch);
			send_to_char("        kingdom recall\n\r", ch);
			send_to_char("\n\r", ch);
		}
		send_to_char("Syntax: kingdom scry <person>\n\r", ch);
		return;
	}

	if(is_leader(ch, kingdom->id))
	{
		if(!str_cmp(arg1, "recall"))
		{
			if(kingdom->points < KINGDOM_RECALL_COST)
			{
				sprintf(buf, "It costs %d kingdom points to set a recall point.\n\r", KINGDOM_RECALL_COST);
				send_to_char(buf, ch);
				return;
			}

			if(ch->in_room == 0)
			{
				send_to_char("You are in a 0 room, eek.\n\r", ch);
				return;
			}

			kingdom->points -= KINGDOM_RECALL_COST;
			kingdom->recall = ch->in_room->vnum;

			kingdom_message(kingdom->id, "{MThe Kingdom Recall has been set to -> [%s]", ch->in_room->name);
			return;
		}

		if(!str_cmp(arg1, "trust"))
		{
			if((vch = get_char_world(ch, arg2)) == 0 || IS_NPC(vch))
			{
				send_to_char("They need to be logged on.\n\r", ch);
				return;
			}

			if(vch->pcdata->kingdom != ch->pcdata->kingdom)
			{
				send_to_char("They aren't in your kingdom!\n\r", ch);
				return;
			}

			arg2[0] = UPPER(arg2[0]);
			if( strstr(kingdom->trustees, arg2) == 0 )
				add_trustee(kingdom->id, vch);
			else
				remove_trustee(kingdom->id, arg2);
			return;
		}

		if(!str_cmp(arg1, "invite"))
		{
			if((vch = get_char_world(ch, arg2)) == 0)
			{
				send_to_char("They aren't logged on.\n\r", ch);
				return;
			}

			if(IS_NPC(vch))
			{
				send_to_char("That's an NPC.\n\r", ch);
				return;
			}

			if(vch->pcdata->kingdom)
			{
				send_to_char("They are already a part of another kingdom!\n\r", ch);
				return;
			}

			vch->pcdata->kingdom_invite = ch->pcdata->kingdom;
			sprintf(buf, "You are invited to join the %s Kingdom by %s.\n\r"
				"Type kingdom accept or kingdom decline.\n\r", kingdom->name, ch->name);
			send_to_char(buf, vch);
			sprintf(buf, "You invite %s to join your glorious kingdom.\n\r", vch->name);
			send_to_char(buf, ch);
			return;
		}

		if(!str_cmp(arg1, "outcast"))
		{
			arg2[0] = UPPER(arg2[0]);
			if( strstr(kingdom->members, arg2) == 0 )
			{
				send_to_char("That person isn't a member!\n\r",ch);
				return;
			}

			if(remove_member(ch->pcdata->kingdom, arg2))
				kingdom_message(0, "%s has been outcasted from the %s Kingdom!", capitalize(arg2), kingdom->name);
			remove_trustee(kingdom->id, arg2);
			return;
		}

		if(!str_cmp(arg1, "treaty"))
		{

			if(kingdom->treaty_pending)
			{
				if(!get_kingdom(kingdom->treaty_pending))
				{
					kingdom->treaty_pending = 0;
					return;
				}

				if(has_treaty(kingdom->id, kingdom->treaty_pending))
				{
					send_to_char("You already have a treaty with them.\n\r", ch);
					return;
				}

				if(!str_cmp(arg2, "accept"))
				{
					add_treaty(kingdom->id, kingdom->treaty_pending);
					kingdom->treaty_pending = 0;
					return;
				}

				if(!str_cmp(arg2, "decline"))
				{
					kingdom_message(kingdom->id, "Your kingdom declines a treaty with the %s Kingdom.",
						get_kingdom(kingdom->treaty_pending)->name);

					kingdom_message(kingdom->treaty_pending, "%s Kingdom has declined your treaty offer.", kingdom->name);
					kingdom->treaty_pending = 0;
					return;
				}

				sprintf(buf, "You have a treaty offer pending with the %s Kingdom.\n\r"
					"Please type kingdom treaty accept or kingdom treaty decline.\n\r",
					get_kingdom(kingdom->treaty_pending)->name);
				send_to_char(buf, ch);
				return;
			}

			if(!is_number(arg2) || get_kingdom(atoi(arg2)) == &kingdom_default)
			{
				send_to_char("There is no such kingdom to make a treaty with.\n\r", ch);
				return;
			}
			i = atoi(arg2);

			if(kingdom->id == i)
			{
				send_to_char("You already have a treaty with yourself, smart one.\n\r", ch);
				return;
			}

			if(is_at_war(kingdom->id, i))
			{
				send_to_char("You are at {RWAR{N with that kingdom!\n\r", ch);
				return;
			}

			if(has_treaty(kingdom->id, i))
			{
				remove_treaty(kingdom->id, i);
				return;
			}

			if(get_kingdom(i)->treaty_pending)
			{
				send_to_char("They are already pending a treaty confirmation.\n\r", ch);
				return;
			}

			get_kingdom(i)->treaty_pending = kingdom->id;
			kingdom_message(i, "The %s Kingdom is asking for a treaty with your kingdom.", kingdom->name);
			kingdom_message(kingdom->id, "You ask the %s Kingdom for a treaty.", get_kingdom(i)->name);
			return;
		}

		if(!str_cmp(arg1, "war"))
		{

			if(!is_number(arg2) || get_kingdom(atoi(arg2)) == &kingdom_default)
			{
				send_to_char("There is no such kingdom to make war with.\n\r", ch);
				return;
			}

			i = atoi(arg2);

			if(i == kingdom->id)
			{
				send_to_char("That wouldn't be a very smart political move.\n\r", ch);
				return;
			}

			if(get_kingdom(i) == &kingdom_default)
			{
				send_to_char("That kingdom doesn't exist.\n\r", ch);
				return;
			}

			if(has_treaty(kingdom->id, i))
			{
				send_to_char("But you have a treaty with them!\n\r", ch);
				return;
			}

			if(is_at_war(kingdom->id, i))
			{
				remove_war(kingdom->id, i);
				return;
			}

			add_war(kingdom->id, i);
			return;
		}

		if(!str_cmp(arg1, "rank"))
		{
			if(!arg3 || arg3[0] == '\0')
			{
				send_to_char("Rank who as what?\n\r", ch);
				return;
			}

			if((vch = get_char_world(ch, arg2)) == 0 || IS_NPC(vch))
			{
				send_to_char("They aren't on at the moment.\n\r", ch);
				return;
			}

			if(vch->pcdata->kingdom != ch->pcdata->kingdom)
			{
				send_to_char("They aren't apart of your kingdom!\n\r", ch);
				return;
			}

			if(ansistrlen(arg3) > 15)
			{
				send_to_char("String length is limited to 20 characters.\n\r", ch);
				return;
			}

			free_string(vch->pcdata->krank);

			if(!str_cmp(arg3, "clear"))
			{
				vch->pcdata->krank = str_dup("");
				return;
			}

			arg3[0] = UPPER(arg3[0]);
			vch->pcdata->krank = str_dup(arg3);
			send_to_char("Done.\n\r", ch);
			return;
		}
	}

	if(!str_cmp(arg1, "scry"))
	{
		if(arg2[0] == '\0')
		{
			send_to_char("You must supply the name of the person.\n\r", ch);
			return;
		}

		if((vch = get_char_world(ch, arg2)) == 0 || IS_NPC(vch))
		{
			send_to_char("They are not online.\n\r", ch);
			return;
		}

		if(kingdom->points < KINGDOM_SCRY_COST)
		{
			sprintf(buf, "It costs %d Kingdom Points to do this.\n\r", KINGDOM_SCRY_COST);
			send_to_char(buf, ch);
			return;
		}

		kingdom_message(kingdom->id, "%s has {cscryed{N %s {C. o O{N ({C%s{N)",
			ch->name, vch->name, vch->in_room == 0 ? "Nowhere" : vch->in_room->name);
		kingdom->points -= KINGDOM_SCRY_COST;
		return;
	}

	// default message
	do_kingdom(ch, "blah");
}
Example #4
0
//////// NON-KINGDOM SPECIFIC CODE ////////
char *str_sep(char *str, char *sep)
{
	char buf[MAX_STRING_LENGTH];
	long addlen = 0;
	long lensep;
	long lenstr;
	long i;
	long k;
	long compare;
	long beginning;

	if(str == 0 || sep == 0)
		return 0;

	lensep = strlen(sep);
	lenstr = strlen(str);

	for(i = 0, compare = 0, beginning = 0; i < lenstr; i++)
	{
		if(LOWER(str[i]) == LOWER(sep[compare]))
		{
			if(compare == 0)
			{
				if( i == 0 )
				{
					beginning = i;
				}
				else
				{
					beginning = i-1; // get rid of space behind name
					addlen = 1;
				}
			}

			if(++compare == lensep)
				break;
		}
		else
		{
			compare = 0;
			beginning = 0;
		}
	}
	lensep += addlen;

	if(compare > 0 && compare == lensep)
	{
		for(i = 0, k = 0; i < lenstr; i++)
		{
			if(i < beginning || i > (beginning + lensep - 1))
				buf[k++] = str[i];
		}
		buf[k] = '\0';

		if(strlen(buf) <= 3)
		{
			log_string(buf);
			return str_dup("");
		}

		return str_dup(buf);
	}

	return 0;
}
Example #5
0
int main(int argc, char *argv[]) {
  TreeNode *tree = NULL;
  TreeModel *backgd_mod = NULL;
  int i, j,
    size = DEFAULT_SIZE, meme_mode = 0, profile_mode = 0, 
    nrestarts = 10, npseudocounts = 5, nsamples = -1, 
    nmostprevalent = -1, tuple_size = -1, nbest = -1, sample_parms = 0,
    nmotifs = DEFAULT_NUMBER, nseqs = -1, do_html = 0, do_bed = 0, 
    suppress_stdout = 0;
  List *msa_name_list = NULL, *pos_examples = NULL, *init_list = NULL, *tmpl;
  List *msas, *motifs;
  SeqSet *seqset = NULL;
  PooledMSA *pmsa = NULL;
  msa_format_type msa_format = UNKNOWN_FORMAT;
  Vector *backgd_mnmod = NULL;
  Hashtable *hash=NULL;
  String *output_prefix = str_new_charstr("phastm.");
  double *has_motif = NULL;
  double prior = PRIOR;
  char c;
  GFF_Set *bedfeats = NULL;

  while ((c = getopt(argc, argv, "t:i:b:sk:md:pn:I:R:P:w:c:SB:o:HDxh")) != -1) {
    switch (c) {
    case 't':
      tree = tr_new_from_file(phast_fopen(optarg, "r"));
      break;
    case 'i':
      msa_format = msa_str_to_format(optarg);
      if (msa_format == UNKNOWN_FORMAT) 
	die("ERROR: bad input format.\n");
      break;
    case 'b':
      backgd_mod = tm_new_from_file(phast_fopen(optarg, "r"), 1);
      break;
    case 's':
      break;
    case 'k':
      size = get_arg_int(optarg);
      break;
    case 'm':
      meme_mode = 1;
      break;
    case 'd':
      pos_examples = get_arg_list(optarg);
      break;
    case 'p':
      profile_mode = 1;
      break;
    case 'n':
      nrestarts = get_arg_int(optarg);
      break;
    case 'I':
      init_list = get_arg_list(optarg);
      break;
    case 'P':
      tmpl = str_list_as_int(get_arg_list(optarg));
      if (lst_size(tmpl) != 2) die("ERROR: bad argument to -P.\n");
      nmostprevalent = lst_get_int(tmpl, 0);
      tuple_size = lst_get_int(tmpl, 1);
      if (!(nmostprevalent > 0 && tuple_size > 0))
	die("ERROR: bad argument nmostprevalent=%i tuple_size=%i\n", 
	    nmostprevalent, tuple_size);
      lst_free(tmpl);
      break;
    case 'R':
      tmpl = str_list_as_int(get_arg_list(optarg));
      if (lst_size(tmpl) != 2) die("ERROR: bad argument to -R.\n");
      nsamples = lst_get_int(tmpl, 0);
      tuple_size = lst_get_int(tmpl, 1);
      if (!(nsamples > 0 && tuple_size > 0))
	die("ERROR nsamples=%i tuple_sizse=%i\n", nsamples, tuple_size);
      lst_free(tmpl);
      break;
    case 'c':
      npseudocounts = get_arg_int(optarg);
      break;
    case 'w':
      nbest = get_arg_int(optarg);
      break;
    case 'S':
      sample_parms = 1;
      break;
    case 'B':
      nmotifs = get_arg_int(optarg);
      break;
    case 'o': 
      str_free(output_prefix);
      output_prefix = str_new_charstr(optarg);
      str_append_char(output_prefix, '.'); 
      break;
    case 'H': 
      do_html = 1;
      break;
    case 'D': 
      do_bed = 1;
      break;
    case 'x':
      suppress_stdout = 1;
      break;
    case 'h':
      usage(argv[0]);
    case '?':
      die("Bad argument.  Try '%s -h'.\n", argv[0]);
    }
  }

  if (optind != argc - 1) 
    die("ERROR: List of alignment files required.  Try '%s -h'.\n", argv[0]);

  if ((nsamples > 0 && nmostprevalent > 0) || 
      (nsamples > 0 && init_list != NULL) || 
      (nmostprevalent > 0 && init_list != NULL)) 
    die("ERROR: -I, -P, and -R are mutually exclusive.");

  set_seed(-1);
    
  msa_name_list = get_arg_list(argv[optind]);

  if (backgd_mod != NULL && tree == NULL) tree = backgd_mod->tree;

  if (tree == NULL && !meme_mode && !profile_mode) 
    die("ERROR: Must specify -t, -m, or -p.\n");

  if ((init_list != NULL || nsamples > 0 || nmostprevalent > 0) && 
      !sample_parms)
    nrestarts = 1;

  if (pos_examples != NULL) {
    hash = hsh_new(lst_size(pos_examples));
    for (i = 0; i < lst_size(pos_examples); i++)
      hsh_put_int(hash, ((String*)lst_get_ptr(pos_examples, i))->chars, 1);
    has_motif = smalloc(lst_size(msa_name_list) * sizeof(double));
  }

  /* open all MSAs */
  msas = lst_new_ptr(lst_size(msa_name_list));
  fprintf(stderr, "Reading alignment(s) ...\n");
  for (i = 0, j = 0; i < lst_size(msa_name_list); i++) {
    String *name = lst_get_ptr(msa_name_list, i);
    FILE *mfile = phast_fopen(name->chars, "r");
    msa_format_type temp_format;
    MSA *msa;
    if (msa_format == UNKNOWN_FORMAT)
      temp_format = msa_format_for_content(mfile, 1);
    else temp_format = msa_format;
    msa = msa_new_from_file_define_format(mfile, temp_format, NULL);
    phast_fclose(mfile);
    if (nseqs == -1) nseqs = msa->nseqs;
    if (!meme_mode &&
        (msa->length - msa_num_gapped_cols(msa, STRIP_ANY_GAPS, -1, -1) < 300 ||
        msa->nseqs != nseqs)) {
      fprintf(stderr, "WARNING: ignoring alignment '%s' -- too few informative sites.\n", name->chars);
      msa_free(msa);
      continue;
    }

    if (msa_alph_has_lowercase(msa)) msa_toupper(msa); 
    msa_remove_N_from_alph(msa); /* Ns can be a problem */
    lst_push_ptr(msas, msa);
    if (has_motif != NULL) {
      int k, hm = (hsh_get_int(hash, name->chars) == 1);
      if (meme_mode) {          /* here need to record at individ seq level */
        has_motif = srealloc(has_motif, 
                             (j + msa->nseqs + 1) * sizeof(double)); /* FIXME */
        for (k = 0; k < msa->nseqs; k++) has_motif[j++] = hm;
      }
      else has_motif[j++] = hm;
    }
  }
  if (!meme_mode) {
    fprintf(stderr, "Extracting and pooling sufficient statistics ...\n");
    pmsa = ss_pooled_from_msas(msas, 1, size, NULL, 0);
    msa_remove_N_from_alph(pmsa->pooled_msa);
  }

  /* obtain individual sequences, if necessary */
  if (nmostprevalent > 0 || nsamples > 0 || meme_mode) {
    if (meme_mode) fprintf(stderr, "Converting to individual sequences ...\n");
    else fprintf(stderr, "Obtaining reference sequences for pre-processing ...\n");
    seqset = mtf_get_seqset(msas, meme_mode ? -1 : 1, 10 * size);
                                /* for now, assume 1st seq is reference */
    msa_remove_N_from_alph(seqset->set); 
  }

  if (nmostprevalent > 0) {
    fprintf(stderr, "Obtaining %d most prevalent %d-tuples ...\n", 
            nmostprevalent, tuple_size);
    init_list = lst_new_ptr(nmostprevalent);
    mtf_get_common_ntuples(seqset, init_list, tuple_size, nmostprevalent);
  }
  else if (nsamples > 0) {
    fprintf(stderr, "Sampling %d %d-tuples ...\n", nsamples, tuple_size);
    init_list = lst_new_ptr(nsamples);
    mtf_sample_ntuples(seqset, init_list, tuple_size, nsamples);
  }

  /* in meme_mode, backgd model can be specified as eq freqs in a .mod file */
  if (meme_mode && backgd_mod != NULL && has_motif == NULL)
    backgd_mnmod = backgd_mod->backgd_freqs;

  /* estimate background model, if necessary */
  else if (backgd_mod == NULL && (!meme_mode || has_motif == NULL)) {
    fprintf(stderr, "Fitting background model%s ...\n", 
            has_motif == NULL ? "" : " (for use in initialization)");
                                /* if discriminative, be clear
                                   backgd isn't really part of the
                                   estimation procedure */
    if (meme_mode) {
      backgd_mnmod = vec_new(strlen(seqset->set->alphabet));
      mtf_estim_backgd_mn(seqset, backgd_mnmod);
    }
    else {
      backgd_mod = tm_new(tr_create_copy(tree), NULL, NULL, F81, 
                          pmsa->pooled_msa->alphabet, 1, 0, NULL, -1);
      tm_fit(backgd_mod, pmsa->pooled_msa, 
             tm_params_init(backgd_mod, .1, 5, 0), 
             -1, OPT_MED_PREC, NULL, 0, NULL);
    }
  }

  /* select subset of init strings, if necessary */
  if (nbest > 0 && init_list != NULL) {
    fprintf(stderr, "Winnowing candidate start strings ...\n");
    tmpl = lst_new_ptr(nbest);
    mtf_winnow_starts(meme_mode ? (void*)seqset : (void*)pmsa,
                      init_list, nbest, tmpl, !meme_mode, size, tree,
                      meme_mode ? (void*)backgd_mnmod : (void*)backgd_mod, 
                      has_motif);
    lst_free(init_list);
    init_list = tmpl;
  }

  /* Now find motifs */
  motifs = mtf_find(meme_mode ? (void*)seqset : (void*)pmsa, 
                    !meme_mode, size, nmotifs, tree,
                    meme_mode ? (void*)backgd_mnmod : (void*)backgd_mod, 
                    has_motif, prior, nrestarts, init_list, sample_parms, 
                    npseudocounts);
     
  fprintf(stderr, "\n\n");
  if (do_bed)
    bedfeats = gff_new_set_init("phast_motif", "0.1b");

  /* generate output */
  for (i = 0; i < lst_size(motifs); i++) {
    Motif *m = lst_get_ptr(motifs, i);

    if (!suppress_stdout) {
      if (lst_size(motifs) > 1) 
        printf("\n**********\nMOTIF #%d\n**********\n\n", i+1);

      mtf_print(stdout, m);
    }

    if (do_html) {
      String *fname = str_dup(output_prefix);
      str_append_int(fname, i+1);
      str_append_charstr(fname, ".html");
      mtf_print_html(phast_fopen(fname->chars, "w+"), m);
      str_free(fname);
    }

    if (do_bed) 
      mtf_add_features(m, bedfeats);
  }
  if (do_html) {
    String *fname = str_dup(output_prefix);
    str_append_charstr(fname, "index.html");
    mtf_print_summary_html(phast_fopen(fname->chars, "w+"), 
                           motifs, output_prefix);
    str_free(fname);
  }
  if (do_bed) {
    String *fname = str_dup(output_prefix);
    str_append_charstr(fname, "bed");
    gff_print_bed(phast_fopen(fname->chars, "w+"),
                  bedfeats, FALSE);
    str_free(fname);
  }

  return 0;
}
Example #6
0
static int rfc1524_mailcap_parse (BODY * a,
                                  char *filename,
                                  char *type, rfc1524_entry * entry, int opt)
{
  FILE *fp;
  char *buf = NULL;
  size_t buflen;
  char *ch;
  char *field;
  int found = FALSE;
  int copiousoutput;
  int composecommand;
  int editcommand;
  int printcommand;
  int btlen;
  int line = 0;

  /* rfc1524 mailcap file is of the format:
   * base/type; command; extradefs
   * type can be * for matching all
   * base with no /type is an implicit wild
   * command contains a %s for the filename to pass, default to pipe on stdin
   * extradefs are of the form:
   *  def1="definition"; def2="define \;";
   * line wraps with a \ at the end of the line
   * # for comments
   */

  /* find length of basetype */
  if ((ch = strchr (type, '/')) == NULL)
    return FALSE;
  btlen = ch - type;

  if ((fp = fopen (filename, "r")) != NULL) {
    while (!found && (buf = mutt_read_line (buf, &buflen, fp, &line)) != NULL) {
      /* ignore comments */
      if (*buf == '#')
        continue;
      debug_print (2, ("mailcap entry: %s\n", buf));

      /* check type */
      ch = get_field (buf);
      if (ascii_strcasecmp (buf, type) && (ascii_strncasecmp (buf, type, btlen) || (buf[btlen] != 0 &&  /* implicit wild */
                                                                                    str_cmp (buf + btlen, "/*"))))  /* wildsubtype */
        continue;

      /* next field is the viewcommand */
      field = ch;
      ch = get_field (ch);
      if (entry)
        entry->command = str_dup (field);

      /* parse the optional fields */
      found = TRUE;
      copiousoutput = FALSE;
      composecommand = FALSE;
      editcommand = FALSE;
      printcommand = FALSE;

      while (ch) {
        field = ch;
        ch = get_field (ch);
        debug_print (2, ("field: %s\n", field));

        if (!ascii_strcasecmp (field, "needsterminal")) {
          if (entry)
            entry->needsterminal = TRUE;
        }
        else if (!ascii_strcasecmp (field, "copiousoutput")) {
          copiousoutput = TRUE;
          if (entry)
            entry->copiousoutput = TRUE;
        }
        else if (!ascii_strncasecmp (field, "composetyped", 12)) {
          /* this compare most occur before compose to match correctly */
          if (get_field_text
              (field + 12, entry ? &entry->composetypecommand : NULL, type,
               filename, line))
            composecommand = TRUE;
        }
        else if (!ascii_strncasecmp (field, "compose", 7)) {
          if (get_field_text
              (field + 7, entry ? &entry->composecommand : NULL, type,
               filename, line))
            composecommand = TRUE;
        }
        else if (!ascii_strncasecmp (field, "print", 5)) {
          if (get_field_text (field + 5, entry ? &entry->printcommand : NULL,
                              type, filename, line))
            printcommand = TRUE;
        }
        else if (!ascii_strncasecmp (field, "edit", 4)) {
          if (get_field_text (field + 4, entry ? &entry->editcommand : NULL,
                              type, filename, line))
            editcommand = TRUE;
        }
        else if (!ascii_strncasecmp (field, "nametemplate", 12)) {
          get_field_text (field + 12, entry ? &entry->nametemplate : NULL,
                          type, filename, line);
        }
        else if (!ascii_strncasecmp (field, "x-convert", 9)) {
          get_field_text (field + 9, entry ? &entry->convert : NULL,
                          type, filename, line);
        }
        else if (!ascii_strncasecmp (field, "test", 4)) {
          /* 
           * This routine executes the given test command to determine
           * if this is the right entry.
           */
          char *test_command = NULL;
          size_t len;

          if (get_field_text (field + 4, &test_command, type, filename, line)
              && test_command) {
            len = str_len (test_command) + STRING;
            mem_realloc (&test_command, len);
            rfc1524_expand_command (a, a->filename, type, test_command, len);
            if (mutt_system (test_command)) {
              /* a non-zero exit code means test failed */
              found = FALSE;
            }
            mem_free (&test_command);
          }
        }
      }                         /* while (ch) */

      if (opt == M_AUTOVIEW) {
        if (!copiousoutput)
          found = FALSE;
      }
      else if (opt == M_COMPOSE) {
        if (!composecommand)
          found = FALSE;
      }
      else if (opt == M_EDIT) {
        if (!editcommand)
          found = FALSE;
      }
      else if (opt == M_PRINT) {
        if (!printcommand)
          found = FALSE;
      }

      if (!found) {
        /* reset */
        if (entry) {
          mem_free (&entry->command);
          mem_free (&entry->composecommand);
          mem_free (&entry->composetypecommand);
          mem_free (&entry->editcommand);
          mem_free (&entry->printcommand);
          mem_free (&entry->nametemplate);
          mem_free (&entry->convert);
          entry->needsterminal = 0;
          entry->copiousoutput = 0;
        }
      }
    }                           /* while (!found && (buf = mutt_read_line ())) */
    fclose (fp);
  }                             /* if ((fp = fopen ())) */
  mem_free (&buf);
  return found;
}
Example #7
0
File: autocomp.c Project: vigna/ne
char *autocomplete(char *p, char *req_msg, const int ext, int * const error) {
	int max_len = 0, min_len = INT_MAX, prefix_len = strlen(p);

	assert(p);

	req_list_init(&rl, (cur_buffer->opt.case_search ? strcmp : strdictcmp), false, false, EXTERNAL_FLAG_CHAR);
	count_scanned = 0;

	search_buff(cur_buffer, p, cur_buffer->encoding, cur_buffer->opt.case_search, false);
	if (stop) {
		req_list_free(&rl);
		free(p);
		return NULL;
	}

	if (ext) {
		buffer *b = (buffer *)buffers.head;
		while (b->b_node.next) {
			if (b != cur_buffer) {
				search_buff(b, p, cur_buffer->encoding, cur_buffer->opt.case_search, true);
				if (stop) {
					req_list_free(&rl);
					free(p);
					return NULL;
				}
			}
			b = (buffer *)b->b_node.next;
		}
 	}

	for(int i = 0; i < rl.cur_entries; i++) {
		const int l = strlen(rl.entries[i]);
		if (max_len < l) max_len = l;
		if (min_len > l) min_len = l;
	}
	/* We compact the table into a vector of char pointers. */
	req_list_finalize(&rl);


	free(p);
	p = NULL;

#ifdef NE_TEST
	/* During tests, we always output the middle entry. */
	if (rl.cur_entries) {
		if (rl.entries[rl.cur_entries/2][strlen(rl.entries[rl.cur_entries/2]) - 1] == EXTERNAL_FLAG_CHAR) rl.entries[rl.cur_entries/2][strlen(rl.entries[rl.cur_entries/2]) - 1] = 0;
		p = str_dup(rl.entries[rl.cur_entries/2]);
	}
	*error = AUTOCOMPLETE_COMPLETED;
	req_list_free(&rl);
	return p;
#endif

	if (rl.cur_entries > 0) {
		qsort(rl.entries, rl.cur_entries, sizeof(char *), strdictcmpp);
		/* Find maximum common prefix. */
		int m = strlen(rl.entries[0]);
		if (rl.entries[0][m-1] == EXTERNAL_FLAG_CHAR) m--;
		for(int i = 1; i < rl.cur_entries; i++) {
			int j;
			for(j = 0; j < m; j++) 
				if (rl.entries[i][j] != rl.entries[0][j]) break;
			m = j;
		}

		/* If we can output more characters than the prefix len, we do so without
			starting the requester. */
		if (m > prefix_len) {
			p = malloc(m + 1);
			strncpy(p, rl.entries[0], m);
			p[m] = 0;
			*error = min_len == m ? AUTOCOMPLETE_COMPLETED : AUTOCOMPLETE_PARTIAL;
		}
		else {
			if (req_msg) print_message(req_msg);
			int result = request_strings(&rl, 0);
			if (result != ERROR) {
				result = result >= 0 ? result : -result - 2;
				/* Delete EXTERNAL_FLAG_CHAR at the end of the strings if necessary. */
				if (rl.entries[result][strlen(rl.entries[result]) - 1] == EXTERNAL_FLAG_CHAR) rl.entries[result][strlen(rl.entries[result]) - 1] = 0;
				p = str_dup(rl.entries[result]);
				*error = AUTOCOMPLETE_COMPLETED;
			}
			else *error = AUTOCOMPLETE_CANCELLED;
			reset_window();
		}
	}
	else *error = AUTOCOMPLETE_NO_MATCH;

	req_list_free(&rl);
	D(fprintf(stderr, "autocomp returning '%s', entries: %d\n", p, rl.cur_entries);)
	return p;