Example #1
0
void hcontrol_build_house(struct char_data * ch, char *arg)
{
  char arg1[MAX_INPUT_LENGTH];
  struct house_control_rec temp_house;
  int virt_house, real_house, real_atrium, virt_atrium, exit_num;
  long owner;

  if (num_of_houses >= MAX_HOUSES) {
    send_to_char("Max houses already defined.\r\n", ch);
    return;
  }

  /* first arg: house's vnum */
  arg = one_argument(arg, arg1);
  if (!*arg1) {
    send_to_char(HCONTROL_FORMAT, ch);
    return;
  }
  virt_house = atoi(arg1);
  if ((real_house = real_room(virt_house)) < 0) {
    send_to_char("No such room exists.\r\n", ch);
    return;
  }
  if ((find_house(virt_house)) >= 0) {
    send_to_char("House already exists.\r\n", ch);
    return;
  }

  /* second arg: direction of house's exit */
  arg = one_argument(arg, arg1);
  if (!*arg1) {
    send_to_char(HCONTROL_FORMAT, ch);
    return;
  }
  if ((exit_num = search_block(arg1, dirs, FALSE)) < 0) {
    sprintf(buf, "'%s' is not a valid direction.\r\n", arg1);
    send_to_char(buf, ch);
    return;
  }
  if (TOROOM(real_house, exit_num) == NOWHERE) {
    sprintf(buf, "There is no exit %s from room %d.\r\n", dirs[exit_num],
	    virt_house);
    send_to_char(buf, ch);
    return;
  }

  real_atrium = TOROOM(real_house, exit_num);
  virt_atrium = world[real_atrium].number;

  if (TOROOM(real_atrium, rev_dir[exit_num]) != real_house) {
    send_to_char("A house's exit must be a two-way door.\r\n", ch);
    return;
  }

  /* third arg: player's name */
  arg = one_argument(arg, arg1);
  if (!*arg1) {
    send_to_char(HCONTROL_FORMAT, ch);
    return;
  }
  if ((owner = get_id_by_name(arg1)) < 0) {
    sprintf(buf, "Unknown player '%s'.\r\n", arg1);
    send_to_char(buf, ch);
    return;
  }

  temp_house.mode = HOUSE_PRIVATE;
  temp_house.vnum = virt_house;
  temp_house.atrium = virt_atrium;
  temp_house.exit_num = exit_num;
  temp_house.built_on = time(0);
  temp_house.last_payment = 0;
  temp_house.owner = owner;
  temp_house.num_of_guests = 0;

  house_control[num_of_houses++] = temp_house;

  SET_BIT_AR(ROOM_FLAGS(real_house), ROOM_HOUSE);
  SET_BIT_AR(ROOM_FLAGS(real_house), ROOM_PRIVATE);
  SET_BIT_AR(ROOM_FLAGS(real_atrium), ROOM_ATRIUM);
  House_crashsave(virt_house);

  send_to_char("House built.  Mazel tov!\r\n", ch);
  House_save_control();
}
Example #2
0
void do_ban( CHAR_DATA* ch, const char* argument)
{
    char arg1[MAX_INPUT_LENGTH];
    char arg2[MAX_INPUT_LENGTH];
    char arg3[MAX_INPUT_LENGTH];
    char arg4[MAX_INPUT_LENGTH];
    char *temp;
    BAN_DATA *pban;
    int value = 0, btime;

    if( IS_NPC( ch ) )   /* Don't want mobs banning sites ;) */
    {
        send_to_char( "Monsters are too dumb to do that!\r\n", ch );
        return;
    }

    if( !ch->desc )   /* No desc means no go :) */
    {
        bug( "%s", "do_ban: no descriptor" );
        return;
    }

    set_char_color( AT_IMMORT, ch );
    argument = one_argument( argument, arg1 );
    argument = one_argument( argument, arg2 );
    argument = one_argument( argument, arg3 );
    argument = one_argument( argument, arg4 );

    /*
     * Do we have a time duration for the ban?
     */

    if( arg4[0] != '\0' && is_number( arg4 ) )
        btime = atoi( arg4 );
    else
        btime = -1;


    /*
     * -1 is default, but no reason the time should be greater than 1000
     * * or less than 1, after all if it is greater than 1000 you are talking
     * * around 3 years.
     */

    if( btime != -1 && ( btime < 1 || btime > 1000 ) )
    {
        send_to_char( "Time value is -1 (forever) or from 1 to 1000.\r\n", ch );
        return;
    }

    /*
     * Need to be carefull with sub-states or everything will get messed up.
     */

    switch ( ch->substate )
    {
    default:
        bug( "%s", "do_ban: illegal substate" );
        return;
    case SUB_RESTRICTED:
        send_to_char( "You cannot use this command from within another command.\r\n", ch );
        return;
    case SUB_NONE:
        ch->tempnum = SUB_NONE;
        break;

    /*
     * Returning to end the editing of the note
     */

    case SUB_BAN_DESC:
        add_ban( ch, "", "", 0, 0 );
        return;
    }
    if( arg1[0] == '\0' )
        goto syntax_message;

    /*
     * If no args are sent after the class/site/race, show the current banned
     * * items.  Shaddai
     */

    if( !str_cmp( arg1, "site" ) )
    {
        if( arg2[0] == '\0' )
        {
            show_bans( ch, BAN_SITE );
            return;
        }

        /*
         * Are they high enough to ban sites?
         */

        if( get_trust( ch ) < sysdata.ban_site_level )
        {
            ch_printf( ch, "You must be %d level to add bans.\r\n", sysdata.ban_site_level );
            return;
        }
        if( arg3[0] == '\0' )
            goto syntax_message;
        if( !add_ban( ch, arg2, arg3, btime, BAN_SITE ) )
            return;
    }
    else if( !str_cmp( arg1, "race" ) )
    {
        if( arg2[0] == '\0' )
        {
            show_bans( ch, BAN_RACE );
            return;
        }

        /*
         * Are they high enough level to ban races?
         */

        if( get_trust( ch ) < sysdata.ban_race_level )
        {
            ch_printf( ch, "You must be %d level to add bans.\r\n", sysdata.ban_race_level );
            return;
        }
        if( arg3[0] == '\0' )
            goto syntax_message;
        if( !add_ban( ch, arg2, arg3, btime, BAN_RACE ) )
            return;
    }
    else if( !str_cmp( arg1, "class" ) )
    {
        if( arg2[0] == '\0' )
        {
            show_bans( ch, BAN_CLASS );
            return;
        }

        /*
         * Are they high enough to ban classes?
         */

        if( get_trust( ch ) < sysdata.ban_class_level )
        {
            ch_printf( ch, "You must be %d level to add bans.\r\n", sysdata.ban_class_level );
            return;
        }
        if( arg3[0] == '\0' )
            goto syntax_message;
        if( !add_ban( ch, arg2, arg3, btime, BAN_CLASS ) )
            return;
    }
    else if( !str_cmp( arg1, "show" ) )
    {

        /*
         * This will show the note attached to a ban
         */

        if( arg2[0] == '\0' || arg3[0] == '\0' )
            goto syntax_message;
        temp = arg3;
        if( arg3[0] == '#' ) /* Use #1 to show the first ban */
        {
            temp = arg3;
            temp++;
            if( !is_number( temp ) )
            {
                send_to_char( "Which ban # to show?\r\n", ch );
                return;
            }
            value = atoi( temp );
            if( value < 1 )
            {
                send_to_char( "You must specify a number greater than 0.\r\n", ch );
                return;
            }
        }
        if( !str_cmp( arg2, "site" ) )
        {
            pban = first_ban;
            if( temp[0] == '*' )
                temp++;
            if( temp[strlen( temp ) - 1] == '*' )
                temp[strlen( temp ) - 1] = '\0';
        }
        else if( !str_cmp( arg2, "class" ) )
            pban = first_ban_class;
        else if( !str_cmp( arg2, "race" ) )
            pban = first_ban_race;
        else
            goto syntax_message;
        for( ; pban; pban = pban->next )
            if( value == 1 || !str_cmp( pban->name, temp ) )
                break;
            else if( value > 1 )
                value--;

        if( !pban )
        {
            send_to_char( "No such ban.\r\n", ch );
            return;
        }
        ch_printf( ch, "Banned by: %s\r\n", pban->ban_by );
        send_to_char( pban->note, ch );
        return;
    }
    else
        goto syntax_message;
    return;

    /* Catch all syntax message, make sure that return stays above this or you
     * will get the syntax message everytime you issue the command even if it
     * is a valid one.  Shaddai
     */

syntax_message:
    send_to_char( "Syntax: ban site  <address> <type> <duration>\r\n", ch );
    send_to_char( "Syntax: ban race  <race>    <type> <duration>\r\n", ch );
    send_to_char( "Syntax: ban class <class>   <type> <duration>\r\n", ch );
    send_to_char( "Syntax: ban show  <field>   <number>\r\n", ch );
    send_to_char( "Ban site lists current bans.\r\n", ch );
    send_to_char( "Duration is the length of the ban in days.\r\n", ch );
    send_to_char( "Type can be:  newbie, mortal, all, warn or level.\r\n", ch );
    send_to_char( "In ban show, the <field> is site, race or class,", ch );
    send_to_char( "  and the <number> is the ban number.\r\n", ch );
    return;
}
Example #3
0
/*
 *  Sets the warn flag on bans.
 */
void do_warn( CHAR_DATA* ch, const char* argument)
{
    char arg1[MAX_STRING_LENGTH];
    char arg2[MAX_STRING_LENGTH];
    char *name;
    int count = -1, type;
    BAN_DATA *pban;

    /*
     * Don't want mobs or link-deads doing this.
     */

    if( IS_NPC( ch ) )
    {
        send_to_char( "Monsters are too dumb to do that!\r\n", ch );
        return;
    }

    if( !ch->desc )
    {
        bug( "%s", "do_warn: no descriptor" );
        return;
    }

    argument = one_argument( argument, arg1 );
    argument = one_argument( argument, arg2 );

    if( arg1[0] == '\0' || arg2[0] == '\0' )
        goto syntax_message;

    if( arg2[0] == '#' )
    {
        name = arg2;
        name++;
        if( !is_number( name ) )
            goto syntax_message;
        count = atoi( name );
        if( count < 1 )
        {
            send_to_char( "The number has to be above 0.\r\n", ch );
            return;
        }
    }

    /*
     *  We simply set up which ban list we will be looking at here.
     */
    if( !str_cmp( arg1, "class" ) )
        type = BAN_CLASS;
    else if( !str_cmp( arg1, "race" ) )
        type = BAN_RACE;
    else if( !str_cmp( arg1, "site" ) )
        type = BAN_SITE;
    else
        type = -1;


    if( type == BAN_CLASS )
    {
        pban = first_ban_class;
        arg2[0] = toupper( arg2[0] );
    }
    else if( type == BAN_RACE )
    {
        pban = first_ban_race;
        arg2[0] = toupper( arg2[0] );
    }
    else if( type == BAN_SITE )
    {
        pban = first_ban;
    }
    else
        goto syntax_message;
    for( ; pban && count != 0; count--, pban = pban->next )
        if( count == -1 && !str_cmp( pban->name, arg2 ) )
            break;
    if( pban )
    {
        /*
         * If it is just a warn delete it, otherwise remove the warn flag.
         */

        if( pban->warn )
        {
            if( pban->level == BAN_WARN )
            {
                dispose_ban( pban, type );
                send_to_char( "Warn has been deleted.\r\n", ch );
            }
            else
            {
                pban->warn = FALSE;
                send_to_char( "Warn turned off.\r\n", ch );
            }
        }
        else
        {
            pban->warn = TRUE;
            send_to_char( "Warn turned on.\r\n", ch );
        }
        save_banlist(  );
    }
    else
    {
        ch_printf( ch, "%s was not found in the ban list.\r\n", arg2 );
        return;
    }
    return;
    /*
     * The above return has to stay in!
     */
syntax_message:
    send_to_char( "Syntax: warn class <field>\r\n", ch );
    send_to_char( "Syntax: warn race  <field>\r\n", ch );
    send_to_char( "Syntax: warn site  <field>\r\n", ch );
    send_to_char( "Field is either #(ban_number) or the site/class/race.\r\n", ch );
    send_to_char( "Example:  warn class #1\r\n", ch );
    return;
}
Example #4
0
//Command Status: Installed, fairly well tested, near completetion.
void do_prayer( CHAR_DATA *ch, char *argument )
{
    char                    arg[MIL];
    AFFECT_DATA             af;

    one_argument( argument, arg );

    if ( IS_NPC( ch ) )
        return;

    if ( IS_AFFECTED( ch, AFF_CHARM ) )
        return;

    if ( !arg || arg[0] == '\0' ) {
        send_to_char( "Syntax: Prayer start\r\nSyntax: Prayer stop\r\n", ch );
        return;
    }

    if ( !IS_AWAKE( ch ) ) {
        send_to_char( "You cant pray while asleep.", ch );
        return;
    }

    if ( ch->position == POS_MEDITATING ) {
        send_to_char( "You are already meditating!\r\n", ch );
        return;
    }

    if ( IS_AFFECTED( ch, AFF_PRAYER ) && !str_cmp( arg, "start" ) ) {
        send_to_char( "But you're already praying.\r\n", ch );
        return;
    }

    if ( !str_cmp( arg, "start" ) ) {
        if ( can_use_skill( ch, number_percent(  ), gsn_prayer ) ) {
            if ( ch->fighting ) {
                send_to_char( "You cannot start a prayer during combat.\r\n", ch );
                return;
            }
            send_to_char( "You close your eyes and begin to pray.\r\n", ch );
            af.type = gsn_prayer;
            af.location = APPLY_NONE;
            af.modifier = 0;
            af.level = ch->level;
            af.duration = -1;
            af.bitvector = meb( AFF_PRAYER );
            affect_to_char( ch, &af );
            learn_from_success( ch, gsn_prayer );
        }
        else {
            send_to_char( "You can't seem to concentrate enough to properly pray.\r\n", ch );
            learn_from_failure( ch, gsn_prayer );
        }
        return;
    }

    if ( !str_cmp( arg, "stop" ) ) {
        if ( !IS_AFFECTED( ch, AFF_PRAYER ) ) {
            send_to_char( "But you're not praying.\r\n", ch );
            return;
        }

        if ( ch->position != POS_STANDING )
            set_position( ch, POS_STANDING );

        send_to_char( "You come to an end in your prayer and slowly open your eyes.\r\n", ch );
        affect_strip( ch, gsn_prayer );
        xREMOVE_BIT( ch->affected_by, AFF_PRAYER );
        return;
    }
}
Example #5
0
/**
 * przekazywanie pieniêdzy
 */
bool money_from_char_to_char( CHAR_DATA *ch, CHAR_DATA *victim, long int amount, int nomination )
{
    char buf [ MAX_INPUT_LENGTH ];
    int multiplier = RATTING_NONE;

    switch ( nomination )
    {
        case NOMINATION_COPPER:
            if ( ch->copper < amount )
            {
                send_to_char( "Przecie¿ nie masz a¿ tylu miedzianych monet.\n\r", ch );
                return FALSE;
            }
            ch->copper -= amount;
            victim->copper += amount;
            multiplier = RATTING_COPPER;
            break;
        case NOMINATION_SILVER:
            if ( ch->silver < amount )
            {
                send_to_char( "Przecie¿ nie masz a¿ tylu srebrnych monet.\n\r", ch );
                return FALSE;
            }
            ch->silver -= amount;
            victim->silver += amount;
            multiplier = RATTING_SILVER;
            break;
        case NOMINATION_GOLD:
            if ( ch->gold < amount )
            {
                send_to_char( "Przecie¿ nie masz a¿ tylu z³otych monet.\n\r", ch );
                return FALSE;
            }
            ch->gold -= amount;
            victim->gold += amount;
            multiplier = RATTING_GOLD;
            break;
        case NOMINATION_MITHRIL:
            if ( ch-> mithril < amount )
            {
                send_to_char( "Przecie¿ nie masz a¿ tylu mithrilowych monet.\n\r", ch );
                return FALSE;
            }
            ch->mithril -= amount;
            victim->mithril += amount;
            multiplier = RATTING_MITHRIL;
            break;
        default:
            send_to_char( "Ale o co chodzi z tymi wszystkimi monetami?\n\r", ch );
            return FALSE;
    }

    sprintf ( buf, "$n daje ci %s.", money_string_simple( amount, nomination, TRUE ) );
    act( buf, ch, NULL, victim, TO_VICT );
    
    act( "$n daje $X trochê monet.", ch, NULL, victim, TO_NOTVICT );
    
    sprintf ( buf, "Dajesz $X %s.", money_string_simple( amount, nomination, TRUE ) );
    act( buf, ch, NULL, victim, TO_CHAR );

    amount *= multiplier;

    append_file_format_daily
        (
         ch,
         MONEY_LOG_FILE,
         "-> S: %d %d (%d) - da³ kasê postaci %s",
         money_count_copper( ch ) + amount,
         money_count_copper( ch ),
         -amount,
         IS_NPC( victim ) ? victim->short_descr : victim->name
        );

    append_file_format_daily
        (
         victim,
         MONEY_LOG_FILE,
         "-> S: %d %d (%d) - dosta³ kasê od postaci %s",
         money_count_copper( victim ) - amount,
         money_count_copper( victim ),
         amount,
         IS_NPC( ch ) ? ch->short_descr : ch->name
        );
    return TRUE;
}
Example #6
0
/*
 * Stampa su scermo la scacchiera in grande
 */
void show_board( CHAR_DATA *ch, CHESSBOARD_DATA *board )
{
	char	buf[MSL*2];
	int		x;
	int		y;

	if ( !ch )
	{
		send_log( NULL, LOG_BUG, "show_board: ch passato è NULL" );
		return;
	}

	if ( !board )
	{
		send_log( NULL, LOG_BUG, "show_board: board passata è NULL" );
		return;
	}

	send_to_char( ch, "&W     1      2      3      4      5      6      7      8\r\n" );

	buf[0] = '\0';
	for ( x = 0;  x < 8;  x++ )
	{
		/* Prima linea */
		sprintf( buf+strlen(buf), "  " );
		for ( y = 0;  y < 8;  y++ )
		{
			if ( (x%2) == 0 )
				strcat( buf, (y%2 == 0) ? WHITE_BACK : BLACK_BACK );
			else
				strcat( buf, (y%2 == 0) ? BLACK_BACK : WHITE_BACK );
			strcat( buf, table_pieces[PIECE_NONE].wgraph1 );
		}
		sprintf( buf+strlen(buf), "%s\r\n", BLACK_BACK );

		/* Seconda linea */
		sprintf( buf+strlen(buf), "&W%c ", 'A' + x );
		for ( y = 0;  y < 8;  y++ )
		{
			if ( (x%2) == 0 )
				strcat( buf, (y%2 == 0) ? WHITE_BACK : BLACK_BACK );
			else
				strcat( buf, (y%2 == 0) ? BLACK_BACK : WHITE_BACK );
			strcat( buf, (board->color[x][y] == COLOR_WHITE) ? WHITE_FORE : BLACK_FORE );
			strcat( buf, (board->color[x][y] == COLOR_WHITE) ? table_pieces[board->piece[x][y]].wgraph1 : table_pieces[board->piece[x][y]].bgraph1 );
		}
		sprintf( buf+strlen(buf), "%s\r\n", BLACK_BACK );

		/* Terza linea */
		sprintf( buf+strlen(buf), "  " );
		for ( y = 0;  y < 8;  y++ )
		{
			if ( (x%2) == 0 )
				strcat( buf, (y%2 == 0) ? WHITE_BACK : BLACK_BACK );
			else
				strcat( buf, (y%2 == 0) ? BLACK_BACK : WHITE_BACK );
			strcat( buf, (board->color[x][y] == COLOR_WHITE) ? WHITE_FORE : BLACK_FORE );
			strcat( buf, (board->color[x][y] == COLOR_WHITE) ? table_pieces[board->piece[x][y]].wgraph2 : table_pieces[board->piece[x][y]].bgraph2 );
		}
		sprintf( buf+strlen(buf), "%s\r\n", BLACK_BACK );
	}

	ch_printf( ch, "%s&w", buf );
}
Example #7
0
/*
 * Controlla e ritorna il tipo di mossa effettuata
 */
int is_valid_move( CHAR_DATA *ch, CHESSBOARD_DATA *board, int x, int y, int dx, int dy )
{
	if ( !ch )
	{
		send_log( NULL, LOG_BUG, "is_valid_move: ch è NULL" );
		return MOVE_INVALID;
	}

	if ( !board )
	{
		send_log( NULL, LOG_BUG, "is_valid_move: board è NULL" );
		return MOVE_INVALID;
	}

	if ( x < 0 || y < 0 || x >= 8 || y >= 8 )
	{
		send_log( NULL, LOG_BUG, "is_valid_move: coordinate passate errate: x=%d y =%d", x, y );
		return MOVE_INVALID;
	}

	if ( dx < 0 || dy < 0 || dx >= 8 || dy >= 8 )
	{
		send_log( NULL, LOG_BUG, "is_valid_move: coordinate passate errate: dx=%d dy =%d", dx, dy );
		return MOVE_OFFBOARD;
	}

	if ( board->piece[x][y] == PIECE_NONE )
	{
		send_to_char( ch, "Non trovo nessun pezzo in quella casella.\r\n" );
		return MOVE_INVALID;
	}

	if ( x == dx && y == dy )
	{
		send_to_char( ch, "La sorgente e l'arrivo della mossa sono identiche.\r\n" );
		return MOVE_INVALID;
	}

	if ( (board->color[x][y] == COLOR_WHITE && ch == board->player1)
	  || (board->color[x][y] == COLOR_BLACK && ch == board->player2) )
	{
		send_to_char( ch, "Sto cercando di muovere un pezzo che non è del mio colore.\r\n" );
		return MOVE_WRONGCOLOR;
	}

	switch ( board->piece[x][y] )
	{
	  default:
		send_log( NULL, LOG_BUG, "is_valid_move():chess.c invaild piece: %d", board->piece[x][y] );
		send_to_char( ch, "-> Mossa sbagliata, avverti i Coder <-" );
		return MOVE_INVALID;
		break;

	  case PIECE_PAWN:
		if ( board->color[x][y] == COLOR_WHITE && dx == x+2 && x == 1 && dy == y
		  && board->piece[dx][dy] == PIECE_NONE && board->piece[x+1][dy] == PIECE_NONE )
			return MOVE_OK;
		if ( board->color[x][y] == COLOR_BLACK && dx == x-2 && x == 6 && dy == y
		  && board->piece[dx][dy] == PIECE_NONE && board->piece[x-1][dy] == PIECE_NONE )
			return MOVE_OK;

		if ( (board->color[x][y] == COLOR_WHITE && dx != x+1)
		  || (board->color[x][y] == COLOR_BLACK && dx != x-1) )
		{
			send_to_char( ch, "Debbo muovere il pedone di un passo per volta, solo dalle caselle di partenza del pedone è consentito una mossa da 2.\r\n" );
			return MOVE_INVALID;
		}

		if ( dy != y && dy != y-1 && dy != y+1 )
		{
			send_to_char( ch, "Debbo muovere il pedone sempre in avanti, oppure in diagonale di una casella quando può fare gambetto.\r\n" );
			return MOVE_INVALID;
		}

		if ( dy == y )
		{
			if ( board->piece[dx][dy] == PIECE_NONE )
				return MOVE_OK;
			if ( SAME_COLOR(x, y, dx, dy) )
			{
				send_to_char( ch, "Non posso muovere dove c'è un'altro pezzo del mio stesso colore.\r\n" );
				return MOVE_SAMECOLOR;
			}

			send_to_char( ch, "Non posso eseguire questa mossa.\r\n" );
			return MOVE_BLOCKED;
		}
		else
		{
			if ( board->piece[dx][dy] == PIECE_NONE )
			{
				/* (FF) (bb) Bisognerebbe gestire anche il gambetto */
				send_to_char( ch, "Non c'è nessun pezzo da mangiare in quella casella.\r\n" );
				return MOVE_INVALID;
			}
			if ( SAME_COLOR(x, y, dx, dy) )
			{
				send_to_char( ch, "Non posso mangiare un pezzo del mio stesso colore.\r\n" );
				return MOVE_SAMECOLOR;
			}
			if ( board->piece[dx][dy] != PIECE_KING )
				return MOVE_TAKEN;

			send_to_char( ch, "Non posso fare questa mossa.\r\n" );
			return MOVE_INVALID;
		}
		break;

	  case PIECE_ROOK:
	  {
		int cnt;

		if ( dx != x && dy != y )
		{
			send_to_char( ch, "Devo muovere la torre verticalmente o orizzontalmente dalla propria posizione.\r\n" );
			return MOVE_INVALID;
		}

		if ( dx == x )
		{
			for ( cnt = y;  cnt != dy; )
			{
				if ( cnt != y && board->piece[x][cnt] != PIECE_NONE )
				{
					send_to_char( ch, "Non posso spostare la torre fino a lì, qualche pezzo blocca la strada" );
					return MOVE_BLOCKED;
				}
				if ( dy > y )
					cnt++;
				else
					cnt--;
			}
		}
		else if ( dy == y )
		{
			for ( cnt = x;  cnt != dx; )
			{
				if ( cnt != x && board->piece[cnt][y] != PIECE_NONE )
				{
					send_to_char( ch, "Non posso spostare la torre fino a lì, qualche pezzo blocca la strada" );
					return MOVE_BLOCKED;
				}
				if ( dx > x )
					cnt++;
				else
					cnt--;
			}
		}

		if ( board->piece[dx][dy] == PIECE_NONE )
			return MOVE_OK;

		if ( SAME_COLOR(x, y, dx, dy) )
		{
			send_to_char( ch, "Non posso mangiare un pezzo del mio stesso colore.\r\n" );
			return MOVE_SAMECOLOR;
		}

		return MOVE_TAKEN;
	  }
	  break;

	  case PIECE_KNIGHT:
		if ( (dx == x - 2 && dy == y - 1)
		  || (dx == x - 2 && dy == y + 1)
		  || (dx == x - 1 && dy == y - 2)
		  || (dx == x - 1 && dy == y + 2)
		  || (dx == x + 1 && dy == y - 2)
		  || (dx == x + 1 && dy == y + 2)
		  || (dx == x + 2 && dy == y - 1)
		  || (dx == x + 2 && dy == y + 1) )
		{
			if ( board->piece[dx][dy] == PIECE_NONE )
				return MOVE_OK;
			if ( SAME_COLOR(x, y, dx, dy) )
			{
				send_to_char( ch, "Non posso mangiare un pezzo del mio stesso colore.\r\n" );
				return MOVE_SAMECOLOR;
			}

			return MOVE_TAKEN;
		}
		send_to_char( ch, "Devo posso muovere il mio cavallo così.\r\n" );
		return MOVE_INVALID;
		break;

	  case PIECE_BISHOP:
	  {
		int	l;
		int	m;
		int	blocked = FALSE;

		if ( dx == x || dy == y )
		{
			send_to_char( ch, "Devo muovere l'alfiere diagonalmente dalla sua posizione.\r\n" );
			return MOVE_INVALID;
		}

		l = x;
		m = y;

		while ( 1 )
		{
			if ( dx > x )
				l++;
			else
				l--;

			if ( dy > y )
				m++;
			else
				m--;

			if ( l > 7 || m > 7 || l < 0 || m < 0 )
			{
				send_to_char( ch, "Non posso uscire dalla scacchiera.\r\n" );
				return MOVE_INVALID;
			}
			if ( l == dx && m == dy )
				break;

			if ( board->piece[l][m] != PIECE_NONE )
				blocked = TRUE;
		}

		if ( l != dx || m != dy )
		{
			send_to_char( ch, "Devo muovere l'alfiere diagonalmente dalla sua posizione.\r\n" );
			return MOVE_INVALID;
		}

		if ( blocked )
		{
			send_to_char( ch, "Non posso spostare il mio alfiere lì, qualche pezzo blocca la strada" );
			return MOVE_BLOCKED;
		}

		if ( board->piece[dx][dy] == PIECE_NONE )
			return MOVE_OK;

		if ( SAME_COLOR(x, y, dx, dy) )
		{
			send_to_char( ch, "Non posso mangaire un pezzo del mio stesso colore.\r\n" );
			return MOVE_SAMECOLOR;
		}

		return MOVE_TAKEN;
	  }
	  break;

	  case PIECE_QUEEN:
	  {
		int l;
		int m;
		int blocked = FALSE;

		l = x;
		m = y;

		while ( 1 )
		{
			if ( dx > x )
				l++;
			else if ( dx < x )
				l--;

			if ( dy > y )
				m++;
			else if ( dy < y )
				m--;

			if ( l > 7 || m > 7 || l < 0 || m < 0 )
			{
				send_to_char( ch, "Non posso muovere fuori dalla scacchiera.\r\n" );
				return MOVE_INVALID;
			}
			if ( l == dx && m == dy )
				break;

			if ( board->piece[l][m] != PIECE_NONE )
				blocked = TRUE;
		}

		if ( l != dx || m != dy )
		{
			send_to_char( ch, "Devo muovere la regina orizzonalmente, verticalmente o in diagonale dalla sua posizione.\r\n" );
			return MOVE_INVALID;
		}

		if ( blocked )
		{
			send_to_char( ch, "Non posso spostare la mia regina lì, qualche pezzo blocca la strada" );
			return MOVE_BLOCKED;
		}

		if ( board->piece[dx][dy] == PIECE_NONE )
			return MOVE_OK;

		if ( SAME_COLOR (x, y, dx, dy) )
		{
			send_to_char( ch, "Non posso mangiare un pezzo del mio stesso colore.\r\n" );
			return MOVE_SAMECOLOR;
		}

		return MOVE_TAKEN;
	  }
	  break;

	  case PIECE_KING:
	  {
		int		sp;
		int		spc;
		int		sk;
		int		skc;
		bool	incheck = FALSE;;

		if ( dx > x+1 || dx < x-1 || dy > y+1 || dy < y-1 )
		{
			send_to_char( ch, "Posso muovere il re di un solo passo attorno a sè, non oltre.\r\n" );
			return MOVE_INVALID;
		}

		if ( SAME_COLOR(x, y, dx, dy) )
		{
			send_to_char( ch, "Non posso mangiare un pezzo del mio stesso colore.\r\n" );
			return MOVE_SAMECOLOR;
		}

		sk	= board->piece[x][y];
		skc = board->color[x][y];
		sp	= board->piece[dx][dy];
		spc	= board->color[dx][dy];
		board->piece[x][y] = PIECE_NONE;
		board->piece[x][y] = COLOR_NONE;
		board->piece[dx][dy] = sk;
		board->color[dx][dy] = skc;

		if ( king_in_check(board, sk, skc) > 0 )
			incheck = TRUE;

		board->piece[x][y]	 = sk;
		board->color[x][y]	 = skc;
		board->piece[dx][dy] = sp;
		board->color[dx][dy] = spc;

		if ( incheck )
		{
			send_to_char( ch, "Non posso muovere il re in quella casella, sarebbe sotto scacco.\r\n" );
			return MOVE_CHECK;
		}

		if ( board->piece[dx][dy] == PIECE_NONE )
			return MOVE_OK;

		return MOVE_TAKEN;
	  }
	  break;
	}

	send_log( NULL, LOG_BUG, "is_valid_move: shouldn't get here" );
	send_to_char( ch, "-> Mossa sbagliata, avverti i Coder <-" );
	return MOVE_INVALID;
}
Example #8
0
void build_save_rooms()
{
     ROOM_INDEX_DATA *pRoomIndex;
     EXTRA_DESCR_DATA *pEd;
     int d;
     EXIT_DATA *pexit;
     int locks=0;

     if (Pointer==NULL)  /* Start */
      {
       if (CurSaveArea->first_area_room==NULL)
	{
	 Section++;
	 return;
	}
       send_to_char("Saving rooms.\n",CurSaveChar);
       fprintf(SaveFile,"#ROOMS\n");
       Pointer=CurSaveArea->first_area_room;
      }

     pRoomIndex=Pointer->data;
     
     fprintf(SaveFile,"#%i\n",pRoomIndex->vnum);
     fprintf(SaveFile,"%s~\n",pRoomIndex->name);
     fprintf(SaveFile,"%s~\n",pRoomIndex->description);
     fprintf(SaveFile,"%i %i\n",pRoomIndex->room_flags,pRoomIndex->sector_type);

     /* Now do doors. */
     for (d=0;d<6;d++)
      {
       if (pRoomIndex->exit[d] )
       {
	 
	 fprintf(SaveFile,"D%i\n",d);
	 pexit=pRoomIndex->exit[d];
	 fprintf(SaveFile,"%s~\n",pexit->description);
	 fprintf(SaveFile,"%s~\n",pexit->keyword);
	 /* Deal with locks */
	 /* -S- Mod: Filter out EX_LOCKED and EX_CLOSED and save exit_info */
	 locks=pexit->exit_info;
	 if ( IS_SET( locks, EX_CLOSED ) )
	    REMOVE_BIT( locks, EX_CLOSED );
	 if ( IS_SET( locks, EX_LOCKED ) )
	    REMOVE_BIT( locks, EX_LOCKED );
	 
	 #if 0 
	 /* BUG: before, an isdoor OR pickproof flag alone would give locks=1 */
	 if (pexit->exit_info & EX_ISDOOR)
	  locks++;
	 if (pexit->exit_info & EX_PICKPROOF)
	  locks++;
         #endif
     
     	 fprintf(SaveFile,"%i %i %i\n",locks,pexit->key,pexit->vnum);
	}
       }

     /* Now do extra descripts.. */
	 
     pEd=pRoomIndex->first_exdesc;
     while (pEd)
      {
       fprintf(SaveFile,"E\n");
       fprintf(SaveFile,"%s~\n",pEd->keyword);
       fprintf(SaveFile,"%s~\n",pEd->description);
       pEd=pEd->next;
      }

     /* End of one room */
     fprintf(SaveFile,"S\n");

     Pointer=Pointer->next;
     if (Pointer==NULL) /* End */
      {
       fprintf(SaveFile,"#0\n");
       Section++;
      }
      return;
}
void show_char_to_char(struct char_data *i, struct char_data *ch, int mode)
{
    char buffer[MAX_STRING_LENGTH];
    int j, found, percent;
    struct obj_data *tmp_obj;

    if (mode == 0) {

        if (IS_AFFECTED(i, AFF_HIDE) || !CAN_SEE(ch,i)) {
            if (IS_AFFECTED(ch, AFF_SENSE_LIFE))
                send_to_char("You sense a hidden life form in the room.\n\r", ch);
            return;
        }

        if (!(i->player.long_descr)||(GET_POS(i) != i->specials.default_pos)) {
            /* A player char or a mobile without long descr, or not in default pos. */
            if (!IS_NPC(i)) {
                strcpy(buffer,GET_NAME(i));
                strcat(buffer," ");
                strcat(buffer,GET_TITLE(i));
            } else {
                strcpy(buffer, i->player.short_descr);
                CAP(buffer);
            }

            if ( IS_AFFECTED(i,AFF_INVISIBLE))
                strcat(buffer," (invisible)");

            switch(GET_POS(i)) {
            case POSITION_STUNNED  :
                strcat(buffer," is lying here, stunned.");
                break;
            case POSITION_INCAP    :
                strcat(buffer," is lying here, incapacitated.");
                break;
            case POSITION_MORTALLYW:
                strcat(buffer," is lying here, mortally wounded.");
                break;
            case POSITION_DEAD     :
                strcat(buffer," is lying here, dead.");
                break;
            case POSITION_STANDING :
                strcat(buffer," is standing here.");
                break;
            case POSITION_SITTING  :
                strcat(buffer," is sitting here.");
                break;
            case POSITION_RESTING  :
                strcat(buffer," is resting here.");
                break;
            case POSITION_SLEEPING :
                strcat(buffer," is sleeping here.");
                break;
            case POSITION_FIGHTING :
                if (i->specials.fighting) {

                    strcat(buffer," is here, fighting ");
                    if (i->specials.fighting == ch)
                        strcat(buffer," YOU!");
                    else {
                        if (i->in_room == i->specials.fighting->in_room)
                            if (IS_NPC(i->specials.fighting))
                                strcat(buffer, i->specials.fighting->player.short_descr);
                            else
                                strcat(buffer, GET_NAME(i->specials.fighting));
                        else
                            strcat(buffer, "someone who has already left.");
                    }
                } else /* NIL fighting pointer */
                    strcat(buffer," is here struggling with thin air.");
                break;
            default :
                strcat(buffer," is floating here.");
                break;
            }
            if (IS_AFFECTED(ch, AFF_DETECT_EVIL)) {
                if (IS_EVIL(i))
                    strcat(buffer, " (Red Aura)");
            }

            strcat(buffer,"\n\r");
            send_to_char(buffer, ch);
        }
        else  /* npc with long */
        {
            if (IS_AFFECTED(i,AFF_INVISIBLE))
                strcpy(buffer,"*");
            else
                *buffer = '\0';

            if (IS_AFFECTED(ch, AFF_DETECT_EVIL)) {
                if (IS_EVIL(i))
                    strcat(buffer, " (Red Aura)");
            }

            strcat(buffer, i->player.long_descr);

            send_to_char(buffer, ch);
        }

        if (IS_AFFECTED(i,AFF_SANCTUARY))
            act("$n glows with a bright light!", FALSE, i, 0, ch, TO_VICT);

    } else if (mode == 1) {

        if (i->player.description)
            send_to_char(i->player.description, ch);
        else {
            act("You see nothing special about $m.", FALSE, i, 0, ch, TO_VICT);
        }

        /* Show a character to another */

        if (GET_MAX_HIT(i) > 0)
            percent = (100*GET_HIT(i))/GET_MAX_HIT(i);
        else
            percent = -1; /* How could MAX_HIT be < 1?? */

        if (IS_NPC(i))
            strcpy(buffer, i->player.short_descr);
        else
            strcpy(buffer, GET_NAME(i));

        if (percent >= 100)
            strcat(buffer, " is in an excellent condition.\n\r");
        else if (percent >= 90)
            strcat(buffer, " has a few scratches.\n\r");
        else if (percent >= 75)
            strcat(buffer, " has some small wounds and bruises.\n\r");
        else if (percent >= 50)
            strcat(buffer, " has quite a few wounds.\n\r");
        else if (percent >= 30)
            strcat(buffer, " has some big nasty wounds and scratches.\n\r");
        else if (percent >= 15)
            strcat(buffer, " looks pretty hurt.\n\r");
        else if (percent >= 0)
            strcat(buffer, " is in an awful condition.\n\r");
        else
            strcat(buffer, " is bleeding awfully from big wounds.\n\r");

        send_to_char(buffer, ch);

        found = FALSE;
        for (j=0; j< MAX_WEAR; j++) {
            if (i->equipment[j]) {
                if (CAN_SEE_OBJ(ch,i->equipment[j])) {
                    found = TRUE;
                }
            }
        }
        if (found) {
            act("\n\r$n is using:", FALSE, i, 0, ch, TO_VICT);
            for (j=0; j< MAX_WEAR; j++) {
                if (i->equipment[j]) {
                    if (CAN_SEE_OBJ(ch,i->equipment[j])) {
                        send_to_char(where[j],ch);
                        show_obj_to_char(i->equipment[j],ch,1);
                    }
                }
            }
        }
        if ((GET_CLASS(ch) == CLASS_THIEF) && (ch != i)) {
            found = FALSE;
            send_to_char("\n\rYou attempt to peek at the inventory:\n\r", ch);
            for(tmp_obj = i->carrying; tmp_obj; tmp_obj = tmp_obj->next_content) {
                if (CAN_SEE_OBJ(ch, tmp_obj) && (number(0,20) < GET_LEVEL(ch))) {
                    show_obj_to_char(tmp_obj, ch, 1);
                    found = TRUE;
                }
            }
            if (!found)
                send_to_char("You can't see anything.\n\r", ch);
        }

    } else if (mode == 2) {

        /* Lists inventory */
        act("$n is carrying:", FALSE, i, 0, ch, TO_VICT);
        list_obj_to_char(i->carrying,ch,1,TRUE);
    }
}
Example #10
0
void build_save_mobs()
{
     MOB_INDEX_DATA *pMobIndex;
     MPROG_DATA* mprg;
     int finish_progs;
     
     if (Pointer==NULL)  /* Start */
      {
       if (CurSaveArea->first_area_mobile==NULL)
	{
	 Section++;
	 return;
	}
       send_to_char("Saving mobs.\n",CurSaveChar);
       fprintf(SaveFile,"#MOBILES\n");
       Pointer=CurSaveArea->first_area_mobile;
      }

     pMobIndex=Pointer->data;
     fprintf(SaveFile,"#%i\n",pMobIndex->vnum);
     fprintf(SaveFile,"%s~\n",pMobIndex->player_name);
     fprintf(SaveFile,"%s~\n",pMobIndex->short_descr);
     fprintf(SaveFile,"%s~\n",pMobIndex->long_descr);
     fprintf(SaveFile,"%s~\n",pMobIndex->description);
     fprintf(SaveFile,"%i %i %i S\n",pMobIndex->act,
			 pMobIndex->affected_by,pMobIndex->alignment);
     fprintf(SaveFile,"%i %i\n",pMobIndex->level,pMobIndex->sex);
     fprintf(SaveFile,"%i %i %i\n",pMobIndex->ac_mod, pMobIndex->hr_mod,
			 pMobIndex->dr_mod);

     /* Save in Envy format.... */
/*     fprintf(Envy,"#%i\n",((pMobIndex->vnum)+offset) );      */
/*     fprintf(Envy,"%s~\n",pMobIndex->player_name);           */
/*     fprintf(Envy,"%s~\n",pMobIndex->short_descr);           */
/*     fprintf(Envy,"%s~\n",pMobIndex->long_descr);   	       */
/*     fprintf(Envy,"%s~\n",pMobIndex->description);           */
/*     fprintf(Envy,"%i %i %i S\n",pMobIndex->act,             */
/*			 pMobIndex->affected_by,pMobIndex->alignment); */
/*     fprintf(Envy,"%i 0 0 0d0+0 0d0+0\n0 0\n0 0       */
/*     		%i\n",convert(pMobIndex->level),pMobIndex->sex);   */
     

   /* Write out new details - clan, class, race and skills
    * The '!' signifies new section to load_mobiles() in db.c
    */
    

   fprintf( SaveFile, "! %i %i %i %i %i %i %i\n",
      pMobIndex->class, 
      pMobIndex->clan, 
      pMobIndex->race,
      pMobIndex->position,
      pMobIndex->skills,
      pMobIndex->cast,
      pMobIndex->def );
     
     
     mprg=pMobIndex->first_mprog;
     finish_progs=0;
     while (mprg)
      {
       if (mprg->filename == NULL)
	{
	 fprintf(SaveFile,">%s ",mprog_type_to_name(mprg->type));
	 fprintf(SaveFile,"%s~\n",mprg->arglist);
	 fprintf(SaveFile,"%s~\n",mprg->comlist);
	 finish_progs=1;
	}
       mprg=mprg->next;
      }
     if (finish_progs)
     {
       fprintf(SaveFile,"|\n");
     }


     Pointer=Pointer->next;
     if (Pointer==NULL) /* End */
      {
       fprintf(SaveFile,"#0\n");
       Section++;
      }
      return;
}
Example #11
0
void build_save_objects()
{
     OBJ_INDEX_DATA *pObject;
     AFFECT_DATA * pAf;
     EXTRA_DESCR_DATA *pEd;
     int val0,val1,val2,val3;

     if (Pointer==NULL)  /* Start */
      {
       if (CurSaveArea->first_area_object==NULL)
	{
	 Section++;
	 return;
	}
       send_to_char("Saving objects.\n",CurSaveChar);
       fprintf(SaveFile,"#OBJECTS\n");
       Pointer=CurSaveArea->first_area_object;
      }

     pObject=Pointer->data;
     
     fprintf(SaveFile,"#%i\n",pObject->vnum);
     fprintf(SaveFile,"%s~\n",pObject->name);
     fprintf(SaveFile,"%s~\n",pObject->short_descr);
     fprintf(SaveFile,"%s~\n",pObject->description);
     fprintf(SaveFile,"%i %i %i %i\n",pObject->item_type,pObject->extra_flags,
					pObject->wear_flags,pObject->item_apply);

     /* Check for pills, potions, scrolls, staffs and wands.  */
     val0=pObject->value[0];
     val1=pObject->value[1];
     val2=pObject->value[2];
     val3=pObject->value[3];
	switch ( pObject->item_type )
	{
	case ITEM_PILL:
	case ITEM_POTION:
	case ITEM_SCROLL:
	 val1=val1<0 ? -1 : skill_table[val1].slot;
	 val2=val2<0 ? -1 : skill_table[val2].slot;
	 val3=val3<0 ? -1 : skill_table[val3].slot;
	    break;

	case ITEM_STAFF:
	case ITEM_WAND:
	 val3=val3<0 ? -1 : skill_table[val3].slot;
	    break;
	}
     fprintf(SaveFile,"%i %i %i %i\n",val0,val1,val2,val3);
     fprintf(SaveFile,"%i\n",pObject->weight);
     
     
     pAf=pObject->first_apply;
     while (pAf)
      {
       fprintf(SaveFile,"A\n");
       fprintf(SaveFile,"%i %i\n",pAf->location,pAf->modifier);
       pAf=pAf->next;
      }

     pEd=pObject->first_exdesc;
     while (pEd)
      {
       fprintf(SaveFile,"E\n");
       fprintf(SaveFile,"%s~\n",pEd->keyword);
       fprintf(SaveFile,"%s~\n",pEd->description);
       pEd=pEd->next;
      }

       if ( ( pObject->level > 1 ) && (pObject->level < 130 ) )
       {
         fprintf(SaveFile, "L\n");
         fprintf(SaveFile,"%d\n",pObject->level);
       }
       else
       {
         fprintf(SaveFile, "L\n");
         fprintf(SaveFile,"%d\n", 1);
       }

      /* Now for Envy... taken from my OLC :P */

     Pointer=Pointer->next;
     if (Pointer==NULL) /* End */
      {
       fprintf(SaveFile,"#0\n");
       Section++;
      }
     
     return;
}
Example #12
0
File: alias.C Project: SinaC/OldMud
/* does aliasing and other fun stuff */
void substitute_alias(DESCRIPTOR_DATA *d, const char *argument)
{   
  CHAR_DATA *ch;
  char buf[MAX_STRING_LENGTH],prefix[MAX_INPUT_LENGTH],name[MAX_INPUT_LENGTH];
  const char *point;
  char* lines;
  int alias;

  ch = d->original ? d->original : d->character;

  /* check for prefix */
  if (ch->prefix[0] != '\0' && str_prefix("prefix",argument)) {
    if (strlen(ch->prefix) + strlen(argument) > MAX_INPUT_LENGTH)
      send_to_char("Line to long, prefix not processed.\r\n",ch);
    else {
      sprintf(prefix,"%s %s",ch->prefix,argument);
      argument = prefix;
    }
  }
    
  if ( IS_NPC(ch) 
       || ch->pcdata->alias[0] == NULL
       || !str_prefix("alias",argument) || !str_prefix("una",argument) 
       || !str_prefix("prefix",argument)) {
    interpret(d->character,argument);
    return;
  }
    
   
  strcpy(buf,argument);

  for (alias = 0; alias < MAX_ALIAS; alias++)	{ /* go through the aliases */
    if (ch->pcdata->alias[alias] == NULL)
      break;

    if (!str_prefix(ch->pcdata->alias[alias],argument)) {
      point = one_argument(argument,name);
      if (!strcmp(ch->pcdata->alias[alias],name)) {
	buf[0] = '\0';
	strcat(buf,ch->pcdata->alias_sub[alias]);
	if (*point != 0) {
	  strcat(buf," ");		
	  strcat(buf,point);
	}
	break;
      }
      if (strlen(buf) > MAX_INPUT_LENGTH) {
	send_to_char("Alias substitution too long. Truncated.\r\n",ch);
	buf[MAX_INPUT_LENGTH -1] = '\0';
      }
    }
  }

  /* ';' is now command separator... By Oxtal 1997*/

  if ( (lines = strchr(buf,';')) == NULL ) 
    interpret(d->character,buf); // A single command : just play it
  else {    
    // Process 1st cmd; delay others
    char *sep;
    int lineslen;      

    *lines = 0; // Truncate buf; lines = rest and lineslen... its length!
    lines++;
    lineslen = strlen(lines);

    // replace ; by LF
    for (sep = strchr(lines,';'); sep != NULL; sep = strchr(sep,';'))
      *sep = '\n';
      
    // Just put lines into the desc. buffer!
    if ( lineslen + strlen(d->inbuf) + 1 >= sizeof(d->inbuf) - 10 ) { 
      send_to_char("Do you know that you've just failed to crash the mud?\n\r",ch);
      return; // That's for spam's kings
    } 
    else {
      memmove(d->inbuf+lineslen+1,d->inbuf,strlen(d->inbuf)+1);
      memcpy(d->inbuf,lines,lineslen);
      d->inbuf[lineslen] = '\n';
      //send_to_charf(ch,"Buf %s\n\r",d->inbuf);
    }
      
    // Then play 1st cmd
    interpret(d->character,buf);
  }
}
Example #13
0
File: alias.C Project: SinaC/OldMud
void do_alias(CHAR_DATA *ch, const char *argument)
{
  CHAR_DATA *rch;
  char arg[MAX_INPUT_LENGTH],buf[MAX_STRING_LENGTH];
  // Modified by SinaC 2001  int  before
  unsigned int pos;

  //  smash_tilde(argument);

  if (ch->desc == NULL)
    rch = ch;
  else
    rch = ch->desc->original ? ch->desc->original : ch;

  if (IS_NPC(rch))
    return;

  argument = one_argument(argument,arg);
    

  if (arg[0] == '\0') {

    if (rch->pcdata->alias[0] == NULL) {
      send_to_char("You have no aliases defined.\n\r",ch);
      return;
    }
    send_to_char("Your current aliases are:\n\r",ch);

    for (pos = 0; pos < MAX_ALIAS; pos++) {
      if (rch->pcdata->alias[pos] == NULL
	  ||	rch->pcdata->alias_sub[pos] == NULL)
	break;

      sprintf(buf,"    %s:  %s\n\r",rch->pcdata->alias[pos],
	      rch->pcdata->alias_sub[pos]);
      send_to_char(buf,ch);
    }
    return;
  }

  if (!str_prefix("una",arg) || !str_cmp("alias",arg)) {
    send_to_char("Sorry, that word is reserved.\n\r",ch);
    return;
  }

  if (argument[0] == '\0') {
    for (pos = 0; pos < MAX_ALIAS; pos++) {
      if (rch->pcdata->alias[pos] == NULL
	  ||	rch->pcdata->alias_sub[pos] == NULL)
	break;

      if (!str_cmp(arg,rch->pcdata->alias[pos])) {
	sprintf(buf,"%s aliases to '%s'.\n\r",rch->pcdata->alias[pos],
		rch->pcdata->alias_sub[pos]);
	send_to_char(buf,ch);
	return;
      }
    }

    send_to_char("That alias is not defined.\n\r",ch);
    return;
  }

  // Added by SinaC 2000
  for ( pos = 0; pos < strlen(arg); pos++ )
    if ( arg[pos]=='\'' || arg[pos]=='"' ) { 
      send_to_char("Aliases with that kind of character are not allowed!\n\r", ch);
      return;
    }
  /*
  for ( pos = 0; pos < strlen(argument); pos++ )
    if ( argument[pos]=='\'' || argument[pos]=='"' ) {  
      send_to_char("Aliases with that kind of character are not allowed!\n\r", ch);
      return;
    }
  */

  if (!str_prefix(argument,"delete") || !str_prefix(argument,"prefix")) {
    send_to_char("That shall not be done!\n\r",ch);
    return;
  }

  for (pos = 0; pos < MAX_ALIAS; pos++) {
    if (rch->pcdata->alias[pos] == NULL)
      break;

    if (!str_cmp(arg,rch->pcdata->alias[pos])) {/* redefine an alias */
      rch->pcdata->alias_sub[pos] = str_dup(argument);
      sprintf(buf,"%s is now realiased to '%s'.\n\r",arg,argument);
      send_to_char(buf,ch);
      return;
    }
  }

  if (pos >= MAX_ALIAS) {
    send_to_char("Sorry, you have reached the alias limit.\n\r",ch);
    return;
  }
  
  /* make a new alias */
  rch->pcdata->alias[pos]		= str_dup(arg);
  rch->pcdata->alias_sub[pos]	= str_dup(argument);
  sprintf(buf,"%s is now aliased to '%s'.\n\r",arg,argument);
  send_to_char(buf,ch);
}
Example #14
0
File: alias.C Project: SinaC/OldMud
void do_alia(CHAR_DATA *ch, const char *argument)
{
  send_to_char("I'm sorry, alias must be entered in full.\n\r",ch);
  return;
}
Example #15
0
/*
 * Invia i messaggi delle mosse ai giocatori e a quelli della stanza
 */
void board_move_messages( CHAR_DATA *ch, int ret, char *extra )
{
	CHESSBOARD_DATA *board;
	CHAR_DATA		*opp;

	if ( !ch )
	{
		send_log( NULL, LOG_BUG, "board_move_messages: ch passato è NULL" );
		return;
	}

	if ( ret < 0 || ret >= MAX_MOVE )
	{
		send_log( NULL, LOG_BUG, "board_move_messages: ret passato errato: %d", ret );
		return;
	}

	if ( IS_MOB(ch) )
	{
		send_to_char( ch, "I mob non possono giocare a scacchi.\r\n" );
		return;
	}

	board = get_chessboard( ch );
	if ( !board )
	{
		send_to_char( ch, "Non sto giocando a nessuna partita di scacchi.\r\n" );
		return;
	}

	if ( ch == board->player1 )
		opp = board->player2;
	else
		opp = board->player1;

	if ( !opp )
	{
		send_log( NULL, LOG_BUG, "board_move_messages: %s non ha nessun avversario", ch->name );
		return;
	}

	show_board( ch, board );
	show_board( opp, board );

	switch ( ret )
	{
	  case MOVE_OK:
		ch_printf( ch, "Muovo, %s.\r\n", extra );
		act( AT_ACTION, "$n muove, $t.\r\n", ch, extra, NULL, TO_ROOM );
		break;
	  case MOVE_CASTLE:
		ch_printf( ch, "Arrocco, %s.\r\n", extra );
		act( AT_ACTION, "$n arrocca, $t.", ch, extra, NULL, TO_ROOM );
		break;
	  case MOVE_PROMOTE:
		ch_printf( ch, "Promuovo un pedone a %s.\r\n", extra );
		act( AT_ACTION, "$n promuove un pedone a $t.", ch, extra, NULL, TO_ROOM );
		break;
	  case MOVE_INVALID:
		send_to_char( ch, "Non posso effettuare questa mossa.\r\n" );
		break;
	  case MOVE_BLOCKED:
		send_to_char( ch, "Sono bloccato in quella direzione.\r\n" );
		break;
	  case MOVE_TAKEN:
		send_to_char( ch, "Hai catturato un pezzo nemico!\r\n" );
		act( AT_ACTION, "$n muove, $t, e cattura uno dei tuoi pezzi!", ch, extra, NULL, TO_ROOM );
		break;
	  case MOVE_OFFBOARD:
		send_to_char( ch, "Questa mossa mi porterebbe fuori la scacchiera.\r\n" );
		break;
	  case MOVE_SAMECOLOR:
		send_to_char( ch, "Uno dei miei stessi pezzi mi blocca la via.\r\n" );
		break;
	  case MOVE_CHECK:
		act( AT_ACTION, "Con questa mossa metto sotto scacco il re di $N.\r\n", ch, NULL, opp, TO_CHAR );
		act( AT_ACTION, "$n prova una mossa e il re di $N è sotto scacco.", ch, NULL, opp, TO_NOVICT );
		act( AT_ACTION, "$n prova una mossa e il tuo re è sotto scacco.", ch, NULL, opp, TO_VICT );
		break;
	  case MOVE_WRONGCOLOR:
		send_to_char( ch, "Questo non è uno dei miei pezzi.\r\n" );
		break;
	  case MOVE_INCHECK:
		send_to_char( ch, "Con questa mossa il mio re sarebbe sotto scacco, non posso eseguirla.\r\n" );
		break;
	}
}
Example #16
0
void do_look(struct char_data *ch, char *argument, int cmd)
{
    char buffer[MAX_STRING_LENGTH];
    char arg1[MAX_STRING_LENGTH];
    char arg2[MAX_STRING_LENGTH];
    int keyword_no;
    int j, bits, temp;
    bool found;
    struct obj_data *tmp_object, *found_object;
    struct char_data *tmp_char;
    char *tmp_desc;
    static char *keywords[]= {
        "north",
        "east",
        "south",
        "west",
        "up",
        "down",
        "in",
        "at",
        "",  /* Look at '' case */
        "\n"
    };

    if (!ch->desc)
        return;

    if (GET_POS(ch) < POSITION_SLEEPING)
        send_to_char("You can't see anything but stars!\n\r", ch);
    else if (GET_POS(ch) == POSITION_SLEEPING)
        send_to_char("You can't see anything, you're sleeping!\n\r", ch);
    else if ( IS_AFFECTED(ch, AFF_BLIND) )
        send_to_char("You can't see a damn thing, you're blinded!\n\r", ch);
    else if ( IS_DARK(ch->in_room) )
        send_to_char("It is pitch black...\n\r", ch);
    else {
        argument_split_2(argument,arg1,arg2);
        keyword_no = search_block(arg1, keywords, FALSE); /* Partiel Match */

        if ((keyword_no == -1) && *arg1) {
            keyword_no = 7;
            strcpy(arg2, arg1); /* Let arg2 become the target object (arg1) */
        }

        found = FALSE;
        tmp_object = 0;
        tmp_char	 = 0;
        tmp_desc	 = 0;

        switch(keyword_no) {
        /* look <dir> */
        case 0 :
        case 1 :
        case 2 :
        case 3 :
        case 4 :
        case 5 : {

            if (EXIT(ch, keyword_no)) {

                if (EXIT(ch, keyword_no)->general_description) {
                    send_to_char(EXIT(ch, keyword_no)->
                                 general_description, ch);
                } else {
                    send_to_char("You see nothing special.\n\r", ch);
                }

                if (IS_SET(EXIT(ch, keyword_no)->exit_info, EX_CLOSED) &&
                        (EXIT(ch, keyword_no)->keyword)) {
                    sprintf(buffer, "The %s is closed.\n\r",
                            fname(EXIT(ch, keyword_no)->keyword));
                    send_to_char(buffer, ch);
                }	else {
                    if (IS_SET(EXIT(ch, keyword_no)->exit_info, EX_ISDOOR) &&
                            EXIT(ch, keyword_no)->keyword) {
                        sprintf(buffer, "The %s is open.\n\r",
                                fname(EXIT(ch, keyword_no)->keyword));
                        send_to_char(buffer, ch);
                    }
                }
            } else {
                send_to_char("Nothing special there...\n\r", ch);
            }
        }
        break;

        /* look 'in'	*/
        case 6: {
            if (*arg2) {
                /* Item carried */

                bits = generic_find(arg2, FIND_OBJ_INV | FIND_OBJ_ROOM |
                                    FIND_OBJ_EQUIP, ch, &tmp_char, &tmp_object);

                if (bits) { /* Found something */
                    if (GET_ITEM_TYPE(tmp_object)== ITEM_DRINKCON)
                    {
                        if (tmp_object->obj_flags.value[1] <= 0) {
                            act("It is empty.", FALSE, ch, 0, 0, TO_CHAR);
                        } else {
                            temp=((tmp_object->obj_flags.value[1]*3)/tmp_object->obj_flags.value[0]);
                            sprintf(buffer,"It's %sfull of a %s liquid.\n\r",
                                    fullness[temp],color_liquid[tmp_object->obj_flags.value[2]]);
                            send_to_char(buffer, ch);
                        }
                    } else if (GET_ITEM_TYPE(tmp_object) == ITEM_CONTAINER) {
                        if (!IS_SET(tmp_object->obj_flags.value[1],CONT_CLOSED)) {
                            send_to_char(fname(tmp_object->name), ch);
                            switch (bits) {
                            case FIND_OBJ_INV :
                                send_to_char(" (carried) : \n\r", ch);
                                break;
                            case FIND_OBJ_ROOM :
                                send_to_char(" (here) : \n\r", ch);
                                break;
                            case FIND_OBJ_EQUIP :
                                send_to_char(" (used) : \n\r", ch);
                                break;
                            }
                            list_obj_to_char(tmp_object->contains, ch, 2, TRUE);
                        }
                        else
                            send_to_char("It is closed.\n\r", ch);
                    } else {
                        send_to_char("That is not a container.\n\r", ch);
                    }
                } else { /* wrong argument */
                    send_to_char("You do not see that item here.\n\r", ch);
                }
            } else { /* no argument */
                send_to_char("Look in what?!\n\r", ch);
            }
        }
        break;

        /* look 'at'	*/
        case 7 : {


            if (*arg2) {

                bits = generic_find(arg2, FIND_OBJ_INV | FIND_OBJ_ROOM |
                                    FIND_OBJ_EQUIP | FIND_CHAR_ROOM, ch, &tmp_char, &found_object);

                if (tmp_char) {
                    show_char_to_char(tmp_char, ch, 1);
                    if (ch != tmp_char) {
                        act("$n looks at you.", TRUE, ch, 0, tmp_char, TO_VICT);
                        act("$n looks at $N.", TRUE, ch, 0, tmp_char, TO_NOTVICT);
                    }
                    return;
                }


                /* Search for Extra Descriptions in room and items */

                /* Extra description in room?? */
                if (!found) {
                    tmp_desc = find_ex_description(arg2,
                                                   world[ch->in_room].ex_description);
                    if (tmp_desc) {
                        page_string(ch->desc, tmp_desc, 0);
                        return; /* RETURN SINCE IT WAS A ROOM DESCRIPTION */
                        /* Old system was: found = TRUE; */
                    }
                }

                /* Search for extra descriptions in items */

                /* Equipment Used */

                if (!found) {
                    for (j = 0; j< MAX_WEAR && !found; j++) {
                        if (ch->equipment[j]) {
                            if (CAN_SEE_OBJ(ch,ch->equipment[j])) {
                                tmp_desc = find_ex_description(arg2,
                                                               ch->equipment[j]->ex_description);
                                if (tmp_desc) {
                                    page_string(ch->desc, tmp_desc, 1);
                                    found = TRUE;
                                }
                            }
                        }
                    }
                }

                /* In inventory */

                if (!found) {
                    for(tmp_object = ch->carrying;
                            tmp_object && !found;
                            tmp_object = tmp_object->next_content) {
                        if CAN_SEE_OBJ(ch, tmp_object) {
                            tmp_desc = find_ex_description(arg2,
                                                           tmp_object->ex_description);
                            if (tmp_desc) {
                                page_string(ch->desc, tmp_desc, 1);
                                found = TRUE;
                            }
                        }
                    }
                }

                /* Object In room */

                if (!found) {
                    for(tmp_object = world[ch->in_room].contents;
                            tmp_object && !found;
                            tmp_object = tmp_object->next_content) {
                        if CAN_SEE_OBJ(ch, tmp_object) {
                            tmp_desc = find_ex_description(arg2,
                                                           tmp_object->ex_description);
                            if (tmp_desc) {
                                page_string(ch->desc, tmp_desc, 1);
                                found = TRUE;
                            }
                        }
                    }
                }
                /* wrong argument */

                if (bits) { /* If an object was found */
                    if (!found)
                        show_obj_to_char(found_object, ch, 5); /* Show no-description */
                    else
                        show_obj_to_char(found_object, ch, 6); /* Find hum, glow etc */
                } else if (!found) {
                    send_to_char("You do not see that here.\n\r", ch);
                }
            } else {
                /* no argument */

                send_to_char("Look at what?\n\r", ch);
            }
        }
Example #17
0
/*
 * Comando per gestire il gioco degli scacchi
 */
void do_chess( CHAR_DATA *ch, char *argument )
{
	CHESSBOARD_DATA *board;
	char			 arg[MIL];

	if ( !ch )
	{
		send_log( NULL, LOG_BUG, "do_chess: ch è NULL" );
		return;
	}

	if ( IS_MOB(ch) )
	{
		send_to_char( ch, "I mob non possono giocare a scacchi.\r\n" );
		return;
	}

	board = get_chessboard( ch );

	if ( !VALID_STR(argument) || is_name(argument, "sintassi aiuto syntax help ?") )
	{
		char	*cmd;

		cmd = translate_command( ch, "chess" );
		ch_printf( ch, "&YSintassi gioco&w:  %s inizio|smetto|partecipo|forfeit\r\n", cmd );
		ch_printf( ch, "&YSintassi info&w:   %s pezzi\r\n", cmd );
		ch_printf( ch, "&YSintassi mosse&w:  %s muovo <sorgente> <destinazione> [comandi opzionali]\r\n", cmd );
		ch_printf( ch, "&YSintassi extra&w:  %s arrocco|promuovo\r\n", cmd );

		if ( !VALID_STR(argument) && board )
		{
			send_to_char( ch, "\r\n" );
			show_status( ch, board );
			send_to_char( ch, "\r\n" );
			show_board( ch, board );
		}

		return;
	}

	argument = one_argument( argument, arg );

	if ( is_name_prefix(arg, "inizio inizia comincio comincia cominciare start") )
	{
		CHESSBOARD_DATA *newboard;

		if ( board )
		{
			send_to_char( ch, "Sto già partecipando ad una partita di scacchi.\r\n" );
			return;
		}

		CREATE( newboard, CHESSBOARD_DATA, 1 );
		init_board( newboard );
		newboard->player1	= ch;
		newboard->turn		= ch;

		LINK( newboard, first_chessboard, last_chessboard, next, prev );
		top_chessboard++;

		send_to_char( ch, "Inizio una nuova partita di scacchi.\r\n" );
		return;
	}

	if ( is_name_prefix(arg, "partecipa partecipo join") )
	{
		CHESSBOARD_DATA *vboard = NULL;
		CHAR_DATA		*vch;
		char			 arg2[MIL];

		if ( board )
		{
			send_to_char( ch, "Sto già partecipando ad una partita di scacchi.\r\n" );
			return;
		}

		argument = one_argument( argument, arg2 );
		if ( !VALID_STR(arg2) )
		{
			send_to_char( ch, "Con chi devo partecipare ad una partita di scacchi?\r\n" );
			return;
		}

		vch = get_player_room( ch, arg2, TRUE );
		if ( !vch )
		{
			ch_printf( ch, "Non vedo nessun %s nella stanza.\r\n", arg2 );
			return;
		}

		vboard = get_chessboard( vch );
		if ( !vboard )
		{
			send_to_char( ch, "Non sta giocando a scacchi.\r\n" );
			return;
		}

		if ( vboard->player2 )
		{
			send_to_char( ch, "Questa scacchiera ha già due giocatori.\r\n" );
			return;
		}

		vboard->player2 = ch;
		vboard->turn	= vboard->player2;

		send_to_char( ch, "Mi unisco alla partita, è il mio turno.\r\n" );
		ch_printf( vboard->player1, "%s si unisce alla tua partita.\r\n", ch->name );
		return;
	}

	if ( is_name_prefix(arg, "pezzi pieces") )
	{
		int		x;	/* contatore dei colori */
		int		y;	/* contatore dei pezzi */

		for ( x = 0;  x < COLOR_NONE;  x++ )
		{
			if ( x == COLOR_BLACK )
				send_to_char( ch, "\r\n\r\nPezzi neri:\r\n" );
			else
				send_to_char( ch, "Pezzi bianchi:\r\n" );

			for ( y = PIECE_PAWN;  y < PIECE_NONE;  y++ )
				ch_printf( ch, "%-7s", table_pieces[y].name );

			send_to_char( ch, "\r\n" );
			for ( y = PIECE_PAWN;  y < PIECE_NONE;  y++ )
				send_to_char( ch, (x == COLOR_WHITE) ? table_pieces[y].wgraph1 : table_pieces[y].bgraph1 );

			send_to_char( ch, "\r\n" );
			for ( y = PIECE_PAWN;  y < PIECE_NONE;  y++ )
				send_to_char( ch, (x == COLOR_WHITE) ? table_pieces[y].wgraph2 : table_pieces[y].bgraph2 );
		}
		send_to_char( ch, "\r\n" );
		return;
	}

	if ( !board )
	{
		send_to_char( ch, "Non ho iniziato o non sto partecipando a nessuna partita di scacchi.\r\n" );
		return;
	}

	if ( is_name_prefix(arg, "smetto fermo stop") )
	{
		free_chessboard( board );
		return;
	}

	if ( is_name_prefix(arg, "forfeit") )
	{
		send_to_char( ch, "Dò forfeit così perdendo.\r\n" );
		free_chessboard( board );
		return;
	}

	if ( !board->player1 || !board->player2 )
	{
		send_to_char( ch, "C'è solo un giocatore.\r\n" );
		return;
	}

	if ( board->moves < 0 )
	{
		send_to_char( ch, "Il gioco non è ancora iniziato.\r\n" );
		return;
	}

	if ( is_name_prefix(arg, "promuovo promuovi promote") )
	{
		int		piece = board->piece[board->lastx][board->lasty];
		char	extra[MIL];

		if ( !((piece == PIECE_PAWN && board->player1 == ch)
		  ||   (piece == PIECE_PAWN && board->player2 == ch)) )
		{
			send_to_char( ch, "Non posso promuovere questo pezzo.\r\n" );
			return;
		}

		if ( (piece == PIECE_PAWN && board->lastx != 0)
		  || (piece == PIECE_PAWN && board->lastx != 7) )
		{
			send_to_char( ch, "Puoi promuovere solamente i pedoni che hanno raggiunto l'altro lato della scacchiera.\r\n" );
			return;
		}

		if ( !VALID_STR(argument) )
		{
			send_to_char( ch, "Vorrei promuovere il pedone in che cosa?\r\n" );
			return;
		}

		if		( is_name_prefix(argument, "regina queen"  ) )	piece = PIECE_QUEEN;
		else if ( is_name_prefix(argument, "alfiere bishop") )	piece = PIECE_BISHOP;
		else if ( is_name_prefix(argument, "cavallo knight") )	piece = PIECE_KNIGHT;
		else if ( is_name_prefix(argument, "torre rook"	   ) )	piece = PIECE_ROOK;
		else
		{
			ch_printf( ch, "Non posso promuoverlo a %s.\r\n", argument );
			return;
		}

		board->piece[board->lastx][board->lasty] = piece;
		sprintf( extra, "%s (%c%d)", table_pieces[piece].name, board->lastx+'a', board->lasty+1 );
		board_move_messages( ch, MOVE_PROMOTE, extra );
		return;
	}

	if ( board->turn != ch )
	{
		send_to_char( ch, "Non è il mio turno.\r\n" );
		return;
	}

	if ( is_name_prefix(arg, "arrocco") )
	{
		int 	myx;
		int 	rooky;
		int 	kdy;
		int		rdy;
		bool	fRookShort;

		if ( king_in_check(board, PIECE_KING, (board->player1 == ch) ? COLOR_BLACK : COLOR_WHITE) > 0 )
		{
			send_to_char( ch, "Non posso eseguire un arrocco mentre sono sotto scacco.\r\n" );
			return;
		}

		if ( (board->player1 == ch && HAS_BIT(board->flags1, CHESSFLAG_MOVEDKING))
		  || (board->player2 == ch && HAS_BIT(board->flags2, CHESSFLAG_MOVEDKING)) )
		{
			send_to_char( ch, "Non posso effettuare un arrocco quando ho già mosso il mio re.\r\n" );
			return;
		}
		myx = (board->player1 == ch) ? 7 : 0;

		if ( !VALID_STR(argument) )
		{
			ch_printf( ch, "Utilizzo: %s arrocco corto|lungo\r\n", translate_command(ch, "chess") );
			return;
		}

		if ( is_name_prefix(argument, "corto short") )
			fRookShort = TRUE;
		else if ( is_name_prefix(argument, "lungo long") )
			fRookShort = FALSE;
		else
		{
			send_command( ch, "chess arrocco", CO );
			return;
		}

		if ( (board->player1 == ch && HAS_BIT(board->flags1, fRookShort ? CHESSFLAG_MOVEDKROOK : CHESSFLAG_MOVEDQROOK))
		  || (board->player2 == ch && HAS_BIT(board->flags2, fRookShort ? CHESSFLAG_MOVEDKROOK : CHESSFLAG_MOVEDQROOK)) )
		{
			ch_printf( ch, "Non posso effettuare l'arrocco %s perchè ho già mosso la torre prima.\r\n",
				fRookShort ? "corto" : "lungo" );
			return;
		}
		rooky = fRookShort ? 7 : 0;

		if ( ( fRookShort && (board->piece[myx][6] != PIECE_NONE || board->piece[myx][5] != PIECE_NONE))
		  || (!fRookShort && (board->piece[myx][1] != PIECE_NONE || board->piece[myx][2] != PIECE_NONE || board->piece[myx][3] != PIECE_NONE)) )
		{
			send_to_char( ch, "L'arrocco è bloccato dalla presenza di pezzi tra il re e la torre.\r\n" );
			return;
		}

		/* castling succeeded */
		if ( fRookShort )
		{
			kdy = 6;
			rdy = 5;
		}
		else
		{
			kdy = 2;
			rdy = 3;
		}

/* (FF) (TT) (RR) (bb) ricordo che una qualsiasi delle caselle, in cui avveniva l'arrocco
 *	non dovevano essere sotto scacco, mi sa che qui non è così, o forse ricordo sbagliato */

		/* check for 'move across check' rule */
		board->piece[myx][rdy] = board->piece[myx][4];
		board->piece[myx][4] = PIECE_NONE;

		if ( king_in_check(board, board->piece[myx][rdy], board->color[myx][rdy]) > 0 )
		{
			send_to_char( ch, "Il mio re si troverebbe sotto scacco dopo l'arrocco.\r\n" );

			board->piece[myx][4] = board->piece[myx][rdy];
			board->piece[myx][rdy] = PIECE_NONE;
			return;
		}

		board->piece[myx][kdy] = board->piece[myx][rdy];
		board->piece[myx][rdy] = board->piece[myx][rooky];
		board->piece[myx][rooky] = PIECE_NONE;

		/* check for 'check' after castled */
		if ( king_in_check(board, board->piece[myx][kdy], board->color[myx][kdy]) > 0 )
		{
			send_to_char( ch, "Il mio re si troverebbe sotto scacco dopo l'arrocco.\r\n" );

			board->piece[myx][4] = board->piece[myx][kdy];
			board->piece[myx][kdy] = PIECE_NONE;
			board->piece[myx][rooky] = board->piece[myx][rdy];
			board->piece[myx][rdy] = PIECE_NONE;
			return;
		}

		/* Basta indicare che è stato mosso il re per evitare un altro arrocco */
		if ( board->player1 == ch )
			SET_BIT( board->flags1, CHESSFLAG_MOVEDKING );
		else
			SET_BIT( board->flags2, CHESSFLAG_MOVEDKING );

		board_move_stuff( board );
		board_move_messages( ch, MOVE_CASTLE, rooky == 7 ? "corto" : "lungo" );
	}

	if ( is_name_prefix(arg, "muovo move") )
	{
		char	coord1[MIL];
		char	coord2[MIL];
		char	extra[MIL];
		int		x, y, dx, dy;
		int		ret;

		if ( !VALID_STR(argument) )
		{
			ch_printf( ch, "Utilizzo: %s muovo <sorgente> <destinazione>\r\n", translate_command(ch, "chess") );
			return;
		}

		argument = one_argument( argument, coord1 );
		argument = one_argument( argument, coord2 );

		if ( !VALID_STR(coord1) || !VALID_STR(coord2) )
		{
			ch_printf( ch, "Utilizzo: %s muovo <sorgente> <destinazione>\r\n", translate_command(ch, "chess") );
			return;
		}

		get_coord( coord1, &x, &y );
		get_coord( coord2, &dx, &dy );

		if ( x < 0 || x >= 8 || dx < 0 || dx >= 8
		  || y < 0 || y >= 8 || dy < 0 || dy >= 8 )
		{
			send_to_char( ch, "Mossa non valida, utilizza a-h e 1-8 (esempio: a4 b4).\r\n" );
			return;
		}

		extra[0] = '\0';

		ret = is_valid_move( ch, board, x, y, dx, dy );
		if ( ret == MOVE_OK || ret == MOVE_TAKEN )
		{
			int	piece;
			int	color;
			int	destpiece;
			int	destcolor;

			piece	  = board->piece[x][y];
			color	  = board->color[x][y];
			destpiece = board->piece[dx][dy];
			destcolor = board->color[dx][dy];

			board->piece[dx][dy] = piece;
			board->color[dx][dy] = color;
			board->piece[x][y] = PIECE_NONE;
			board->color[x][y] = COLOR_NONE;

			if ( king_in_check(board, PIECE_KING, board->color[dx][dy]) > 0 )
			{
				board->piece[dx][dy] = destpiece;
				board->color[dx][dy] = destcolor;
				board->piece[x][y]	 = piece;
				board->color[x][y]	 = color;
				ret = MOVE_INCHECK;
			}
			else
			{
				if ( destpiece == PIECE_NONE )
					sprintf( extra, "%c%d (%s) alle coordinate %c%d", x+'a', y+1, table_pieces[piece].name, y+'a', dy+1 );
				else
					sprintf( extra, "%c%d (%s) alle coordinate %c%d (%s)", x+'a', y+1, table_pieces[piece].name, y+'a', dy+1, table_pieces[destpiece].name );

				board_move_stuff( board );
				board->lastx = dx;
				board->lasty = dy;

				/* Imposta le flag per evitare gli arrocchi */
				if ( piece == PIECE_ROOK )
				{
					if ( color == COLOR_WHITE )
					{
						if ( y == 0 && x == 0 )
							SET_BIT( board->flags1, CHESSFLAG_MOVEDKROOK );
						else if ( y == 0 && x == 7 )
							SET_BIT( board->flags1, CHESSFLAG_MOVEDQROOK );
					}
					else
					{
						if ( y == 7 && x == 0 )
							SET_BIT( board->flags2, CHESSFLAG_MOVEDKROOK );
						else if ( y == 7 && x == 7 )
							SET_BIT( board->flags2, CHESSFLAG_MOVEDQROOK );
					}
				}
				else if ( piece == PIECE_KING )
				{
					if ( color == COLOR_WHITE )
						SET_BIT( board->flags1, CHESSFLAG_MOVEDKING );
					else
						SET_BIT( board->flags2, CHESSFLAG_MOVEDKING );
				}
			}

			board_move_messages( ch, ret, extra );
		}

		/* Così qui gestisce i comandi opzionali, come il promote */
		if ( VALID_STR(argument) )
		{
			do_chess( ch, argument );
			return;
		}
		return;
	}

	send_command( ch, "chess aiuto", CO );
}
Example #18
0
void Crash_listrent(struct char_data * ch, char *name)
{
  FILE *fl;
  char fname[MAX_INPUT_LENGTH];
  char buf[MAX_STRING_LENGTH];
  char input[MAX_INPUT_LENGTH + 1];
  char tag[MAX_INPUT_LENGTH + 1];
  char tag_arguments[MAX_INPUT_LENGTH + 1];
  char *p;
  struct obj_data *obj;
  int val = 0;
  time_t rent_time;
  int d;
  int h;
  int m;

  if (!get_filename(name, fname, CRASH_FILE)) {
    return;
  }
  if (!(fl = fopen(fname, "r"))) {
    sprintf(buf, "%s has no rent file.\r\n", name);
    send_to_char(buf, ch);
    return;
  }

  sprintf(buf, "%s\r\n", fname);
  while (get_line(fl, input)) {
    parse_pline(input, tag, tag_arguments);
    while ((p = strrchr(tag_arguments, '\n')) != NULL) {
      *p = '\0';
    }

    val = atoi(tag_arguments);
    switch (tag[0]) {
      case 'o':
      case 'O':
        if (strcasecmp(tag, "obj_number") == 0) {
          if (real_object(val) > -1) {
            obj = read_object_q(val, VIRTUAL);
            sprintf(buf, "%s [%5d] %-20s\r\n", buf, val, obj->short_description);
            extract_obj_q(obj);
          }
        }
        break;
      case 'r':
      case 'R':
        if (strcasecmp(tag, "rent_version") == 0) {
          sprintf(buf, "%sVersion: %d\r\n", buf, val);
        } else if (strcasecmp(tag, "rent_time") == 0) {
          rent_time = time(0) - val;
          d = rent_time / 86400;
          h = (rent_time / 3600) % 24;
          m = (rent_time / 60) % 60;
          sprintf(buf, "%sRented %d day%s, %d hour%s, %d minute%s ago.\r\n", buf, d, ((d == 1) ? "" : "s"), h, ((h == 1) ? "" : "s"), m, ((m == 1) ? "" : "s"));
        } else if (strcasecmp(tag, "rent_type") == 0)
          switch (val) {
            case RENT_RENTED:
              sprintf(buf, "%sType: Rent\r\n", buf);
              break;
            case RENT_CRASH:
              sprintf(buf, "%sType: Crash\r\n", buf);
              break;
            case RENT_CRYO:
              sprintf(buf, "%sType: Cryo\r\n", buf);
              break;
            case RENT_TIMEDOUT:
            case RENT_FORCED:
              sprintf(buf, "%sType: TimedOut\r\n", buf);
              break;
            case RENT_CAMPED:
              sprintf(buf, "%sType: Camped\r\n", buf);
              break;
            default:
              sprintf(buf, "%sType: Undef\r\n", buf);
              break;
          }
        break;
    }
  }
  page_string(ch->desc, buf, 1);
  fclose(fl);
}
Example #19
0
/*
 * stampa al pg il suo stato attuale di gioco
 */
void show_status( CHAR_DATA *ch, CHESSBOARD_DATA *board )
{
	if ( !ch )
	{
		send_log( NULL, LOG_BUG, "print_status: ch passato è NULL" );
		return;
	}

	if ( !board )
	{
		send_to_char( ch, "Non sto giocando a nessuna partita di scacchi.\r\n" );
		return;
	}

	if ( !board->player1 )
		send_to_char( ch, "Non ho nessun giocatore per i pezzi neri con cui gareggiare.\r\n" );
	else if ( board->player1 == ch )
		send_to_char( ch, "Sono io il giocatore dei pezzi neri.\r\n" );
	else
		ch_printf( ch, "%s è il giocatore che tiene i pezzi neri.\r\n", board->player1->name );

	if ( king_in_possible_checkmate(board, PIECE_KING, COLOR_BLACK) )
		send_to_char( ch, "Il re nero potrebbe essere sotto scacco matto.\r\n" );
	else if ( king_in_check(board, PIECE_KING, COLOR_BLACK) > 0 )
		send_to_char( ch, "Il re nero è sotto scacco.\r\n" );

	if ( !board->player2 )
		send_to_char( ch, "Non ho nessun giocatore per i pezzi bianchi con cui gareggiare.\r\n" );
	else if ( board->player2 == ch )
		send_to_char( ch, "Sono io il giocatore dei pezzi bianchi.\r\n" );
	else
		ch_printf( ch, "%s è il giocatore che tiene i pezzi bianchi.\r\n", board->player2->name );

	if ( king_in_possible_checkmate(board, PIECE_KING, COLOR_WHITE) )
		send_to_char( ch, "Il re bianco potrebbe essere sotto scacco matto.\r\n" );
	else if ( king_in_check(board, PIECE_KING, COLOR_WHITE) > 0 )
		send_to_char( ch, "Il re bianco è sotto scacco.\r\n" );

	if ( !board->player2 || !board->player1 )
		return;

	if ( board->moves < 0 )
		send_to_char( ch, "Il gioco non è ancora iniziato.\r\n" );
	else
		ch_printf( ch, "%d turni.\r\n", board->moves );

	if ( board->turn == ch )
		send_to_char( ch, "E' il mio turno.\r\n" );
	else
		ch_printf( ch, "E' il turno di %s.\r\n", board->turn->name );
}
Example #20
0
void load_text(struct char_data * ch)
{
  FILE *fil = NULL;
  char fname[MAX_INPUT_LENGTH];
  struct alias *al;
  int i, cnt;

  void free_alias(struct alias * a);

  if (IS_NPC(ch))
    return;

  if (!get_filename(GET_NAME(ch), fname, ETEXT_FILE))
    return;

  if (!(fil = fopen(fname, "r"))) {
    if (errno != ENOENT) { /* if it fails, NOT because of no file */
      sprintf(buf1, "SYSERR: READING TEXT FILE %s (5)", fname);
      perror(buf1);
      send_to_char("\r\n***** NOTICE - THERE WAS A PROBLEM READING YOUR ALIAS FILE *****\r\n", ch);
      return;
    }
    return;
  }

  while ((al = GET_ALIASES(ch)) != NULL) { /* get rid of alias multiplying problem */
    GET_ALIASES(ch) = (GET_ALIASES(ch))->next;
    free_alias(al);
  }

  cnt = 200; /* security counter to make memory alloc bombing impossible :) */
  fscanf(fil, "%d\n", &i); /* get first type */
  while (i != -1 && cnt != 0) {
    CREATE(al, struct alias, 1);
    al->type = i;
    fgets(buf, MAX_INPUT_LENGTH, fil);
    buf[strlen(buf) - 1] = '\0';
    al->alias = strdup(buf);
    fgets(buf, MAX_INPUT_LENGTH, fil);
    buf[strlen(buf) - 1] = '\0';
    al->replacement = strdup(buf);
    al->next = ch->player_specials->aliases;
    ch->player_specials->aliases = al;
    fscanf(fil, "%d\n", &i);
    cnt--;
  }
  /* aliases has been loaded */
  if (WHOSPEC(ch)) {
    FREE(WHOSPEC(ch));
  }
  if (POOFIN(ch)) {
    FREE(POOFIN(ch));
  }
  if (POOFOUT(ch)) {
    FREE(POOFOUT(ch));
  }
  if (WHOSTR(ch)) {
    FREE(WHOSTR(ch));
  }
  if (NAMECOLOR(ch)) {
    FREE(NAMECOLOR(ch));
  }

  fgets(buf, MAX_INPUT_LENGTH, fil);
  buf[strlen(buf) - 1] = '\0';
  if (str_cmp("!UNUSED!", buf)) {
    WHOSPEC(ch) = strdup(buf);
  }
  fgets(buf, SMALL_BUFSIZE, fil);
  buf[strlen(buf) - 1] = '\0';
  if (str_cmp("!UNUSED!", buf)) {
    POOFIN(ch) = strdup(buf);
  }
  fgets(buf, SMALL_BUFSIZE, fil);
  buf[strlen(buf) - 1] = '\0';
  if (str_cmp("!UNUSED!", buf)) {
    POOFOUT(ch) = strdup(buf);
  }
  fgets(buf, MAX_INPUT_LENGTH, fil);
  buf[strlen(buf) - 1] = '\0';
  if (str_cmp("!UNUSED!", buf)) {
    WHOSTR(ch) = strdup(buf);
  }
  if (fgets(buf, SMALL_BUFSIZE, fil) > (char*) NULL) {
    buf[strlen(buf) - 1] = '\0';
    if (str_cmp("!UNUSED!", buf)) {
      NAMECOLOR(ch) = strdup(buf);
    }
  }

  if (cnt == 0) {
    send_to_char("Undetermined error when reading your alias file ...\r\n", ch);
    sprintf(buf, "ERROR when reading %s's alias file.", GET_NAME(ch));
    mudlog(buf, 'W', COM_IMMORT, TRUE);
    plog(buf, ch, 0);
  }
  fclose(fil);
  return;
}
Example #21
0
/* Display a nicely formatted map with a legend */
static void perform_map( struct char_data *ch, char *argument, bool worldmap )
{
  int size = DEFAULT_MAP_SIZE;
  int centre, x, y, min, max;
  char arg1[MAX_INPUT_LENGTH], arg2[MAX_INPUT_LENGTH], buf[MAX_STRING_LENGTH], buf1[MAX_STRING_LENGTH], buf2[MAX_STRING_LENGTH];
  int count = 0;
  int ew_size=0, ns_size=0;
  int mapshape = MAP_CIRCLE;

  two_arguments( argument, arg1 , arg2 );
  if(*arg1)
  {
    size = atoi(arg1);
  }
  if (*arg2)
  {
    if (is_abbrev(arg2, "normal")) worldmap=FALSE;
    else if (is_abbrev(arg2, "world")) worldmap=TRUE;
    else {
      send_to_char(ch, "Usage: \tymap <distance> [ normal | world ]\tn");
      return;
    }
  }

  if(size<0) {
    size = -size;
    mapshape = MAP_RECTANGLE;
  }
  size = URANGE(1,size,MAX_MAP_SIZE);

  centre = MAX_MAP/2;

  if(worldmap) {
    min = centre - 2*size;
    max = centre + 2*size;
  } else {
    min = centre - size;
    max = centre + size;
  }

  /* Blank the map */
  for (x = 0; x < MAX_MAP; ++x)
      for (y = 0; y < MAX_MAP; ++y)
           map[x][y]= (!(y%2) && !worldmap) ? DOOR_NONE : SECT_EMPTY;

  /* starts the mapping with the centre room */
  MapArea(IN_ROOM(ch), ch, centre, centre, min, max, ns_size/2, ew_size/2, worldmap);

  /* marks the center, where ch is */
  map[centre][centre] = SECT_HERE;

  /* Feel free to put your own MUD name or header in here */
  send_to_char(ch, " \tY-\tytbaMUD Map System\tY-\tn\r\n"
                   "\tD  .-.__--.,--.__.-.\tn\r\n" );

  count += sprintf(buf + count, "\tn\tn\tn%s Up\\\\", door_info[NUM_DOOR_TYPES + DOOR_UP].disp);
  count += sprintf(buf + count, "\tn\tn\tn%s Down\\\\", door_info[NUM_DOOR_TYPES + DOOR_DOWN].disp);
  count += sprintf(buf + count, "\tn%s You\\\\", map_info[SECT_HERE].disp);
  count += sprintf(buf + count, "\tn%s Inside\\\\", map_info[SECT_INSIDE].disp);
  count += sprintf(buf + count, "\tn%s City\\\\", map_info[SECT_CITY].disp);
  count += sprintf(buf + count, "\tn%s Field\\\\", map_info[SECT_FIELD].disp);
  count += sprintf(buf + count, "\tn%s Forest\\\\", map_info[SECT_FOREST].disp);
  count += sprintf(buf + count, "\tn%s Hills\\\\", map_info[SECT_HILLS].disp);
  count += sprintf(buf + count, "\tn%s Mountain\\\\", map_info[SECT_MOUNTAIN].disp);
  count += sprintf(buf + count, "\tn%s Swim\\\\", map_info[SECT_WATER_SWIM].disp);
  count += sprintf(buf + count, "\tn%s Boat\\\\", map_info[SECT_WATER_NOSWIM].disp);
  count += sprintf(buf + count, "\tn%s Flying\\\\", map_info[SECT_FLYING].disp);
  count += sprintf(buf + count, "\tn%s Underwater\\\\", map_info[SECT_UNDERWATER].disp);

  strcpy(buf, strfrmt(buf, LEGEND_WIDTH, CANVAS_HEIGHT + 2, FALSE, TRUE, TRUE));

  /* Start with an empty column */
  strcpy(buf1, strfrmt("",0, CANVAS_HEIGHT + 2, FALSE, FALSE, TRUE));

  /* Paste the legend */
  strcpy(buf2, strpaste(buf1, buf, "\tD | \tn"));

  /* Set up the map */
  memset(buf, ' ', CANVAS_WIDTH);
  count = (CANVAS_WIDTH);
  if(worldmap)
    count += sprintf(buf + count , "\r\n%s", WorldMap(centre, size, mapshape, MAP_NORMAL));
  else
    count += sprintf(buf + count , "\r\n%s", StringMap(centre, size));
  memset(buf + count, ' ', CANVAS_WIDTH);
  strcpy(buf + count + CANVAS_WIDTH, "\r\n");
  /* Paste it on */
  strcpy(buf2, strpaste(buf2, buf, "\tD | \tn"));
  /* Paste on the right border */
  strcpy(buf2, strpaste(buf2, buf1, "  "));
  /* Print it all out */
  send_to_char(ch, "%s", buf2);

  send_to_char(ch, "\tD `.-.__--.,-.__.-.-'\tn\r\n");
  return;
}
Example #22
0
/* return values:
 0 - successful load, keep char in rent room.
 1 - load failure or load of crash items -- put char in temple.
 2 - rented equipment lost (no $)
 */
int Crash_load(struct char_data * ch)
{
  void Crash_save(struct char_data * ch, int type);
  FILE *fl;
  char fname[MAX_STRING_LENGTH];
  char buf[MAX_STRING_LENGTH];
  char input[MAX_INPUT_LENGTH + 1];
  char tag[MAX_INPUT_LENGTH + 1];
  char tag_arguments[MAX_INPUT_LENGTH + 1];
  int val;
  struct obj_data *tmpobj = NULL;
  struct obj_data *tmpobj2;
  struct obj_data *next_obj;
  int found_begin = 0;
  int affect_counter = 0;
  int found;
  char *p;
  struct corpse_obj_save *crash_load_stack = NULL;
  struct corpse_obj_save *temp_stack = NULL;
  struct corpse_obj_save *temp_stack_next = NULL;
  int chg;
  int ovnum = 0;
  int j;

  if (!get_filename(GET_NAME(ch), fname, CRASH_FILE)) {
    return 1;
  }
  if (!(fl = fopen(fname, "r"))) {
    if (errno != ENOENT) { /* if it fails, NOT because of no file */
      sprintf(buf1, "SYSERR: READING OBJECT FILE %s (5)", fname);
      perror(buf1);
      send_to_char("\r\n********************* NOTICE *********************\r\n"
          "There was a problem loading your objects from disk.\r\n"
          "Contact a God for assistance.\r\n", ch);
    }
    sprintf(buf, "%s entering game with no equipment.", GET_NAME(ch));
    mudlog(buf, 'R', COM_IMMORT, TRUE);
    plog(buf, ch, 0);
    return 1;
  }

  while (get_line(fl, input)) {
    parse_pline(input, tag, tag_arguments);
    while ((p = strrchr(tag_arguments, '\n')) != NULL) {
      *p = '\0';
    }

    val = atoi(tag_arguments);
    switch (tag[4]) {
      case 'a':
      case 'A':
        if (strcasecmp(tag, "obj_affect_loc") == 0 && affect_counter < MAX_OBJ_AFFECT) {
          tmpobj->affected[affect_counter].location = val;
        } else if (strcasecmp(tag, "obj_affect_mod") == 0 && affect_counter < MAX_OBJ_AFFECT) {
          tmpobj->affected[affect_counter].modifier = val;
          affect_counter++;
        } else {
          sprintf(buf, "Unknown Rent-File Tag: %s", tag);
          stderr_log(buf);
        }
        break;
      case 'b':
      case 'B':
        if (strcasecmp(tag, "obj_begin") == 0) {
          if (found_begin) {
            send_to_char("\r\n********************* NOTICE *********************\r\n"
                "There was a problem loading your objects from disk.\r\n"
                "Contact a God for assistance.\r\n", ch);
            return 1;
          }
          found_begin = 1;
        } else if (strcasecmp(tag, "obj_bitvector") == 0) {
          GET_OBJ_BITV(tmpobj) = asciiflag_conv(tag_arguments);
        } else if (strcasecmp(tag, "obj_bitvector2") == 0) {
          GET_OBJ_BITV2(tmpobj) = asciiflag_conv(tag_arguments);
        } else {
          sprintf(buf, "Unknown Rent-File Tag: %s", tag);
          stderr_log(buf);
        }
        break;
      case 'e':
      case 'E':
        if (strcasecmp(tag, "obj_extra_flags") == 0) {
          GET_OBJ_EXTRA(tmpobj) = asciiflag_conv(tag_arguments);
        } else if (strcasecmp(tag, "obj_end") == 0) {
          if (ovnum >= 0) {
            if (!found_begin) {
              send_to_char("\r\n********************* NOTICE *********************\r\n"
                  "There was a problem loading your objects from disk.\r\n"
                  "Contact a God for assistance.\r\n", ch);
              return 1;
            }
            found_begin = 0;
            affect_counter = 0;

            CREATE(crash_load_stack, struct corpse_obj_save, 1);
            crash_load_stack->level = 0;
            crash_load_stack->prev = NULL;

            for (tmpobj2 = ch->carrying, found = 0; tmpobj2 && !found; tmpobj2 = next_obj) {
              next_obj = tmpobj2->next_content;
              if (tmpobj2->objnum == tmpobj->inobj) {
                obj_to_obj(tmpobj, tmpobj2);
                found = 1;
              }
              if (tmpobj2->contains) {
                crash_load_stack->next_obj = next_obj;
                CREATE(temp_stack, struct corpse_obj_save, 1);
                temp_stack->level = crash_load_stack->level + 1;
                temp_stack->prev = crash_load_stack;
                crash_load_stack = temp_stack;
                next_obj = tmpobj2->contains;
                if (tmpobj2 == next_obj) {
                  /* infinite loop */
                  next_obj = NULL;
                  continue;
                }
              } else if (next_obj == NULL && crash_load_stack->level > 0) {
                temp_stack = crash_load_stack;
                crash_load_stack = crash_load_stack->prev;
                FREE(temp_stack);
                next_obj = crash_load_stack->next_obj;
              }
            }
            for (temp_stack = crash_load_stack; temp_stack; temp_stack = temp_stack_next) {
              temp_stack_next = temp_stack->prev;
              FREE(temp_stack);
            }
            if (!found) {
              obj_to_char(tmpobj, ch);
            }
          } else {
            extract_obj(tmpobj);
            found_begin = 0;
            affect_counter = 0;
            ovnum = 0;
          }
        } else {
Example #23
0
/**
 * dzielenie siê pieniêdzmi
 */
void money_split( CHAR_DATA *ch, long int amount, int nomination, bool show_message, bool is_split_all, bool is_autosplit )
{
    int multiplier = RATTING_NONE;
    CHAR_DATA *gch;
    long int members = 0, share, extra;
    char buf[ MAX_INPUT_LENGTH ];
    char buf_amount[ MAX_INPUT_LENGTH ];

    switch ( nomination )
    {
        case NOMINATION_COPPER:
            if ( ch->copper < amount )
            {
                if ( show_message || is_autosplit )
                {
                    send_to_char( "Nie masz tylu miedzianych monet.\n\r", ch );
                }
                return;
            }
            break;
        case NOMINATION_SILVER:
            if ( ch->silver < amount )
            {
                if ( show_message || is_autosplit )
                {
                    send_to_char( "Nie masz tylu srebrnych monet.\n\r", ch );
                }
                return;
            }
            break;
        case NOMINATION_GOLD:
            if ( ch->gold < amount )
            {
                if ( show_message || is_autosplit )
                {
                    send_to_char( "Nie masz tylu zlotych monet.\n\r", ch );
                }
                return;
            }
            break;
        case NOMINATION_MITHRIL:
            if ( ch->mithril < amount )
            {
                if ( show_message || is_autosplit )
                {
                    send_to_char( "Nie masz tylu mithrilowych monet.\n\r", ch );
                }
                return;
            }
            break;
    } 

    for ( gch = ch->in_room->people; gch != NULL; gch = gch->next_in_room )
    {
        if ( can_see( ch, gch ) && is_same_group( gch, ch ) && !IS_AFFECTED( gch, AFF_CHARM ) )
        {
            members++;
        }
    }

    if ( members < 2 )
    {
        if ( show_message && ! is_autosplit )
        {
            send_to_char( "Dzielisz siê piêniedzmi sam ze sob±.\n\r", ch );
        }
        return;
    }

    if ( amount < members )
    {
        if ( show_message && ! is_split_all && ! is_autosplit )
        {
            send_to_char( "Nawet siê nie trud¼ <&sk±pcu/sk±pa kobieto/sk±pirad³o>.\n\r", ch );
        }
        return;
    }

    share = amount;
    share /= members;
    if ( share < 1 )
    {
        share = 0;
    }

    extra = amount;
    extra %= members;
    if ( extra < 1 )
    {
        extra = 0;
    }

    if ( share < 1 )
    {
        if ( show_message && ! is_split_all && ! is_autosplit )
        {
            send_to_char( "Nawet siê nie trud¼ <&sk±pcu/sk±pa kobieto/sk±pirad³o>.\n\r", ch );
        }
        return;
    }

    append_file_format_daily
        (
         ch,
         MONEY_LOG_FILE,
         "-> S: before split /%d/%d/%d/%d/",
         ch->copper,
         ch->silver,
         ch->gold,
         ch->mithril
        );

    switch ( nomination )
    {
        case NOMINATION_COPPER:
            ch->copper += share + extra - amount;
            multiplier = RATTING_COPPER;
            break;
        case NOMINATION_SILVER:
            ch->silver += share + extra - amount;
            multiplier = RATTING_SILVER;
            break;
        case NOMINATION_GOLD:
            ch->gold += share + extra - amount;
            multiplier = RATTING_GOLD;
            break;
        case NOMINATION_MITHRIL:
            ch->mithril += share + extra - amount;
            multiplier = RATTING_MITHRIL;
            break;
    } 

    append_file_format_daily
        (
         ch,
         MONEY_LOG_FILE,
         "-> S: %ld %ld (%ld) - splitn±³ kasê w wysoko¶ci %s (%d/%d) nominal: %d /%d/%d/%d/%d/",
         money_count_copper( ch ) + ( extra + share - amount ) * multiplier,
         money_count_copper( ch ),
         ( share + extra - amount ) * multiplier,
         money_string_simple( amount, nomination, FALSE ),
         share,
         extra,
         nomination,
         ch->copper,
         ch->silver,
         ch->gold,
         ch->mithril
        );

    if ( show_message || is_autosplit )
    {
        sprintf ( buf_amount, "%s", money_string_simple ( amount, nomination, TRUE ) );
        sprintf( buf, "Rozdzielasz %s. Dostajesz %s.\n\r", buf_amount,  money_string_simple ( share + extra, nomination, TRUE ) );
        send_to_char( buf, ch );
        sprintf ( buf, "%s rozdziela %s. Dostajesz swoj± czê¶æ, %s.\n\r", ch->name, buf_amount, money_string_simple ( share, nomination, TRUE) );
    }

    for ( gch = ch->in_room->people; gch != NULL; gch = gch->next_in_room )
    {
        if ( gch != ch && can_see( ch, gch ) && is_same_group( gch, ch ) && !IS_AFFECTED( gch, AFF_CHARM ) )
        {
            if ( show_message || is_autosplit )
            {
                /* act( buf, ch, NULL, gch, TO_VICT );*/
                send_to_char( buf, gch );
            }
            append_file_format_daily
                (
                 gch,
                 MONEY_LOG_FILE,
                 "-> S: %ld %ld (%ld) - dosta³ kasê ze splita od %s",
                 money_count_copper( gch ) - share * multiplier,
                 money_count_copper( gch ),
                 share * multiplier,
                 ch->name
                );
            switch ( nomination )
            {
                case NOMINATION_COPPER:
                    gch->copper += share;
                    break;
                case NOMINATION_SILVER:
                    gch->silver += share;
                    break;
                case NOMINATION_GOLD:
                    gch->gold += share;
                    break;
                case NOMINATION_MITHRIL:
                    gch->mithril += share;
                    break;
            }
        }
    }
}
Example #24
0
void oedit_parse(struct descriptor_data *d, char *arg)
{
  int number, max_val, min_val;
  char *oldtext = NULL;
  struct board_info *tmp;
  struct obj_data *obj;
  obj_rnum robj;

  switch (OLC_MODE(d)) {

  case OEDIT_CONFIRM_SAVESTRING:
    switch (*arg) {
    case 'y':
    case 'Y':
      oedit_save_internally(d);
      mudlog(CMP, MAX(LVL_BUILDER, GET_INVIS_LEV(d->character)), TRUE, 
              "OLC: %s edits obj %d", GET_NAME(d->character), OLC_NUM(d));
      if (CONFIG_OLC_SAVE) {
      oedit_save_to_disk(real_zone_by_thing(OLC_NUM(d)));
      write_to_output(d, "Object saved to disk.\r\n");
      } else
      write_to_output(d, "Object saved to memory.\r\n");
      if (GET_OBJ_TYPE(OLC_OBJ(d)) == ITEM_BOARD) {
        if ((tmp=locate_board(GET_OBJ_VNUM(OLC_OBJ(d)))) != NULL) {
          save_board(tmp);
        } else {
          tmp = create_new_board(GET_OBJ_VNUM(OLC_OBJ(d)));
          BOARD_NEXT(tmp) = bboards;
          bboards = tmp;
        }
      }
      /* Fall through. */
    case 'n':
    case 'N':
      cleanup_olc(d, CLEANUP_ALL);
      return;
    case 'a': /* abort quit */
    case 'A': 
      oedit_disp_menu(d);
      return;
    default:
      write_to_output(d, "Invalid choice!\r\n");
      write_to_output(d, "Do you wish to save your changes? : \r\n");
      return;
    }

  case OEDIT_MAIN_MENU:
    /*
     * Throw us out to whichever edit mode based on user input.
     */
    switch (*arg) {
    case 'q':
    case 'Q':
      if (STATE(d) != CON_IEDIT) {
      if (OLC_VAL(d)) {	/* Something has been modified. */
        write_to_output(d, "Do you wish to save your changes? : ");
	OLC_MODE(d) = OEDIT_CONFIRM_SAVESTRING;
      } else
	cleanup_olc(d, CLEANUP_ALL);
      } else {
        send_to_char(d->character, "\r\nCommitting iedit changes.\r\n");
        obj = OLC_IOBJ(d);
        *obj = *(OLC_OBJ(d));
        GET_ID(obj) = max_obj_id++;
        /* find_obj helper */
        add_to_lookup_table(GET_ID(obj), (void *)obj);
        if (GET_OBJ_VNUM(obj) != NOTHING) {
          /* remove any old scripts */
          if (SCRIPT(obj)) {
            extract_script(obj, OBJ_TRIGGER);
            SCRIPT(obj) = NULL;
          }

          free_proto_script(obj, OBJ_TRIGGER);
          robj = real_object(GET_OBJ_VNUM(obj));
          copy_proto_script(&obj_proto[robj], obj, OBJ_TRIGGER);
          assign_triggers(obj, OBJ_TRIGGER);
        }
        SET_BIT_AR(GET_OBJ_EXTRA(obj), ITEM_UNIQUE_SAVE);
  /* Xap - ought to save the old pointer, free after assignment I suppose */
        mudlog(CMP, MAX(LVL_BUILDER, GET_INVIS_LEV(d->character)), TRUE,
               "OLC: %s iedit a unique #%d", GET_NAME(d->character), GET_OBJ_VNUM(obj));
        if (d->character) {
          REMOVE_BIT_AR(PLR_FLAGS(d->character), PLR_WRITING);
          STATE(d) = CON_PLAYING;
          act("$n stops using OLC.", TRUE, d->character, 0, 0, TO_ROOM);
        }
        free(d->olc);
        d->olc = NULL;
      }
      return;
    case '1':
      write_to_output(d, "Enter namelist : ");
      OLC_MODE(d) = OEDIT_EDIT_NAMELIST;
      break;
    case '2':
      write_to_output(d, "Enter short desc : ");
      OLC_MODE(d) = OEDIT_SHORTDESC;
      break;
    case '3':
      write_to_output(d, "Enter long desc :-\r\n| ");
      OLC_MODE(d) = OEDIT_LONGDESC;
      break;
    case '4':
      OLC_MODE(d) = OEDIT_ACTDESC;
      send_editor_help(d);
      write_to_output(d, "Enter action description:\r\n\r\n");
      if (OLC_OBJ(d)->action_description) {
	write_to_output(d, "%s", OLC_OBJ(d)->action_description);
	oldtext = strdup(OLC_OBJ(d)->action_description);
      }
      string_write(d, &OLC_OBJ(d)->action_description, MAX_MESSAGE_LENGTH, 0, oldtext);
      OLC_VAL(d) = 1;
      break;
    case '5':
      oedit_disp_type_menu(d);
      OLC_MODE(d) = OEDIT_TYPE;
      break;
    case '6':
      oedit_disp_extra_menu(d);
      OLC_MODE(d) = OEDIT_EXTRAS;
      break;
    case '7':
      oedit_disp_wear_menu(d);
      OLC_MODE(d) = OEDIT_WEAR;
      break;
    case '8':
      write_to_output(d, "Enter weight : ");
      OLC_MODE(d) = OEDIT_WEIGHT;
      break;
    case '9':
      write_to_output(d, "Enter cost : ");
      OLC_MODE(d) = OEDIT_COST;
      break;
    case 'a':
    case 'A':
      write_to_output(d, "Enter cost per day : ");
      OLC_MODE(d) = OEDIT_COSTPERDAY;
      break;
    case 'b':
    case 'B':
      write_to_output(d, "Enter timer : ");
      OLC_MODE(d) = OEDIT_TIMER;
      break;
    case 'c':
    case 'C':
      /*
       * Clear any old values  
       */
      GET_OBJ_VAL(OLC_OBJ(d), 0) = 0;
      GET_OBJ_VAL(OLC_OBJ(d), 1) = 0;
      GET_OBJ_VAL(OLC_OBJ(d), 2) = 0;
      GET_OBJ_VAL(OLC_OBJ(d), 3) = 0;
      OLC_VAL(d) = 1;
      oedit_disp_val1_menu(d);
      break;
    case 'd':
    case 'D':
      oedit_disp_prompt_apply_menu(d);
      break;
    case 'e':
    case 'E':
      /*
       * If extra descriptions don't exist.
       */
      if (OLC_OBJ(d)->ex_description == NULL) {
	CREATE(OLC_OBJ(d)->ex_description, struct extra_descr_data, 1);
	OLC_OBJ(d)->ex_description->next = NULL;
      }
      OLC_DESC(d) = OLC_OBJ(d)->ex_description;
      oedit_disp_extradesc_menu(d);
      break;
    case 'm':
    case 'M':
      write_to_output(d, "Enter new minimum level: ");
      OLC_MODE(d) = OEDIT_LEVEL;
      break;
    case 'p':
    case 'P':
      oedit_disp_perm_menu(d);
      OLC_MODE(d) = OEDIT_PERM;
      break;
    case 's':
    case 'S':
      if (STATE(d) != CON_IEDIT) {
      OLC_SCRIPT_EDIT_MODE(d) = SCRIPT_MAIN_MENU;
      dg_script_menu(d);
      } else {
        write_to_output(d, "\r\nScripts cannot be modified on individual objects.\r\nEnter choice : ");
      }
      return;
    default:
      oedit_disp_menu(d);
      break;
    }
    return;			/*
				 * end of OEDIT_MAIN_MENU 
				 */

  case OLC_SCRIPT_EDIT:
    if (dg_script_edit_parse(d, arg)) return;
    break;


  case OEDIT_EDIT_NAMELIST:
    if (!genolc_checkstring(d, arg))
      break;
    if (OLC_OBJ(d)->name)
      free(OLC_OBJ(d)->name);
    OLC_OBJ(d)->name = str_udup(arg);
    break;

  case OEDIT_SHORTDESC:
    if (!genolc_checkstring(d, arg))
      break;
    if (OLC_OBJ(d)->short_description)
      free(OLC_OBJ(d)->short_description);
    OLC_OBJ(d)->short_description = str_udup(arg);
    break;

  case OEDIT_LONGDESC:
    if (!genolc_checkstring(d, arg))
      break;
    if (OLC_OBJ(d)->description)
      free(OLC_OBJ(d)->description);
    OLC_OBJ(d)->description = str_udup(arg);
    break;

  case OEDIT_TYPE:
    number = atoi(arg);
    if ((number < 1) || (number >= NUM_ITEM_TYPES)) {
      write_to_output(d, "Invalid choice, try again : ");
      return;
    } else
      GET_OBJ_TYPE(OLC_OBJ(d)) = number;
    /* what's the boundschecking worth if we don't do this ? -- Welcor */
    GET_OBJ_VAL(OLC_OBJ(d), 0) = GET_OBJ_VAL(OLC_OBJ(d), 1) =
      GET_OBJ_VAL(OLC_OBJ(d), 2) = GET_OBJ_VAL(OLC_OBJ(d), 3) = 0;
    break;

  case OEDIT_EXTRAS:
    number = atoi(arg);
    if ((number < 0) || (number > NUM_ITEM_FLAGS)) {
      oedit_disp_extra_menu(d);
      return;
    } else if (number == 0)
      break;
    else {
      TOGGLE_BIT_AR(GET_OBJ_EXTRA(OLC_OBJ(d)), number - 1);
      oedit_disp_extra_menu(d);
      return;
    }

  case OEDIT_WEAR:
    number = atoi(arg);
    if ((number < 0) || (number > NUM_ITEM_WEARS)) {
      write_to_output(d, "That's not a valid choice!\r\n");
      oedit_disp_wear_menu(d);
      return;
    } else if (number == 0)	/* Quit. */
      break;
    else {
      TOGGLE_BIT_AR(GET_OBJ_WEAR(OLC_OBJ(d)), (number - 1));
      oedit_disp_wear_menu(d);
      return;
    }

  case OEDIT_WEIGHT:
    GET_OBJ_WEIGHT(OLC_OBJ(d)) = LIMIT(atoi(arg), 0, MAX_OBJ_WEIGHT);
    break;

  case OEDIT_COST:
    GET_OBJ_COST(OLC_OBJ(d)) = LIMIT(atoi(arg), 0, MAX_OBJ_COST);
    break;

  case OEDIT_COSTPERDAY:
    GET_OBJ_RENT(OLC_OBJ(d)) = LIMIT(atoi(arg), 0, MAX_OBJ_RENT);
    break;

  case OEDIT_TIMER:
    switch (GET_OBJ_TYPE(OLC_OBJ(d))) { 
      case ITEM_PORTAL: 
        GET_OBJ_TIMER(OLC_OBJ(d)) = LIMIT(atoi(arg), -1, MAX_OBJ_TIMER); 
        break; 
      default: 
        GET_OBJ_TIMER(OLC_OBJ(d)) = LIMIT(atoi(arg), 0, MAX_OBJ_TIMER); 
        break; 
    } 
    break; 

  case OEDIT_LEVEL:
    GET_OBJ_LEVEL(OLC_OBJ(d)) = LIMIT(atoi(arg), 0, LVL_IMPL);
    break;

  case OEDIT_PERM:
    if ((number = atoi(arg)) == 0)
      break;
    if (number > 0 && number <= NUM_AFF_FLAGS) {
      /* Setting AFF_CHARM on objects like this is dangerous. */
      if (number != AFF_CHARM) {
        TOGGLE_BIT_AR(GET_OBJ_PERM(OLC_OBJ(d)), number);
      }
    } 
    oedit_disp_perm_menu(d);
    return;

  case OEDIT_VALUE_1:
    /*
     * Lucky, I don't need to check any of these for out of range values.
     * Hmm, I'm not so sure - Rv  
     */
    switch (GET_OBJ_TYPE(OLC_OBJ(d))) {
      case ITEM_WEAPON:
	GET_OBJ_VAL(OLC_OBJ(d), 0) = MIN(MAX(atoi(arg), -50), 50);
	break;
      case ITEM_CONTAINER:
        GET_OBJ_VAL(OLC_OBJ(d), 0) = LIMIT(atoi(arg), -1, MAX_CONTAINER_SIZE); 
        break;
      default:
    GET_OBJ_VAL(OLC_OBJ(d), 0) = atoi(arg);
    }
    /*
     * proceed to menu 2 
     */
    oedit_disp_val2_menu(d);
    return;
  case OEDIT_VALUE_2:
    /*
     * Here, I do need to check for out of range values.
     */
    number = atoi(arg);
    switch (GET_OBJ_TYPE(OLC_OBJ(d))) {
    case ITEM_SCROLL:
    case ITEM_POTION:
      if (number == 0 || number == -1)
	GET_OBJ_VAL(OLC_OBJ(d), 1) = -1;
      else
        GET_OBJ_VAL(OLC_OBJ(d), 1) = LIMIT(number, 1, NUM_SPELLS-1);
	oedit_disp_val3_menu(d);
      break;
    case ITEM_CONTAINER:
    case ITEM_VEHICLE:
    case ITEM_HATCH:
    case ITEM_WINDOW:
    case ITEM_PORTAL:
      /*
       * Needs some special handling since we are dealing with flag values
       * here.
       */
      if (number < 0 || number > 4)
	oedit_disp_container_flags_menu(d);
      else if (number != 0) {
        TOGGLE_BIT(GET_OBJ_VAL(OLC_OBJ(d), 1), 1 << (number - 1));
        OLC_VAL(d) = 1;
	oedit_disp_val2_menu(d);
      } else
	oedit_disp_val3_menu(d);
      break;
    case ITEM_WEAPON:
      GET_OBJ_VAL(OLC_OBJ(d), 1) = LIMIT(number, 1, MAX_WEAPON_NDICE); 
      oedit_disp_val3_menu(d);
      break;

    default:
      GET_OBJ_VAL(OLC_OBJ(d), 1) = number;
      oedit_disp_val3_menu(d);
    }
    return;

  case OEDIT_VALUE_3:
    number = atoi(arg);
    /*
     * Quick'n'easy error checking.
     */
    switch (GET_OBJ_TYPE(OLC_OBJ(d))) {
    case ITEM_SCROLL:
    case ITEM_POTION:
      if (number == 0 || number == -1) {
	GET_OBJ_VAL(OLC_OBJ(d), 2) = -1;
        oedit_disp_val4_menu(d);
	return;
      }
      min_val = 1;
      max_val = NUM_SPELLS - 1;
      break;
    case ITEM_WEAPON:
      min_val = 1;
      max_val = MAX_WEAPON_SDICE;
      break;
    case ITEM_WAND:
    case ITEM_STAFF:
      min_val = 0;
      max_val = 20;
      break;
    case ITEM_DRINKCON:
    case ITEM_FOUNTAIN:
      min_val = 0;
      max_val = NUM_LIQ_TYPES - 1;
      break;
    case ITEM_KEY:
      min_val = 0;
      max_val = 32099;
      break;
    default:
      min_val = -32000;
      max_val = 32000;
    }
    GET_OBJ_VAL(OLC_OBJ(d), 2) = LIMIT(number, min_val, max_val);
    oedit_disp_val4_menu(d);
    return;

  case OEDIT_VALUE_4:
    number = atoi(arg);
    switch (GET_OBJ_TYPE(OLC_OBJ(d))) {
    case ITEM_SCROLL:
    case ITEM_POTION:
      if (number == 0 || number == -1) {
        GET_OBJ_VAL(OLC_OBJ(d), 3) = -1;
        oedit_disp_menu(d);
        return;
      }
      min_val = 1;
      max_val = NUM_SPELLS - 1;
      break;
    case ITEM_WAND:
    case ITEM_STAFF:
      min_val = 1;
      max_val = NUM_SPELLS - 1;
      break;
    case ITEM_WEAPON:
      min_val = 0;
      max_val = NUM_ATTACK_TYPES - 1;
      break;
    default:
      min_val = -32000;
      max_val = 32000;
      break;
    }
    GET_OBJ_VAL(OLC_OBJ(d), 3) = LIMIT(number, min_val, max_val);
    break;

  case OEDIT_PROMPT_APPLY:
    if ((number = atoi(arg)) == 0)
      break;
    else if (number < 0 || number > MAX_OBJ_AFFECT) {
      oedit_disp_prompt_apply_menu(d);
      return;
    }
    OLC_VAL(d) = number - 1;
    OLC_MODE(d) = OEDIT_APPLY;
    oedit_disp_apply_menu(d);
    return;

  case OEDIT_APPLY:
    if ((number = atoi(arg)) == 0) {
      OLC_OBJ(d)->affected[OLC_VAL(d)].location = 0;
      OLC_OBJ(d)->affected[OLC_VAL(d)].modifier = 0;
      oedit_disp_prompt_apply_menu(d);
    } else if (number < 0 || number >= NUM_APPLIES)
      oedit_disp_apply_menu(d);
    else {
      int counter;

      /* add in check here if already applied.. deny builders another */
      if (GET_LEVEL(d->character) < LVL_IMPL) {
        for (counter = 0; counter < MAX_OBJ_AFFECT; counter++) {
          if (OLC_OBJ(d)->affected[counter].location == number) {
            write_to_output(d, "Object already has that apply.");
            return;
          }
        }
      }

      OLC_OBJ(d)->affected[OLC_VAL(d)].location = number;
      write_to_output(d, "Modifier : ");
      OLC_MODE(d) = OEDIT_APPLYMOD;
    }
    return;

  case OEDIT_APPLYMOD:
    OLC_OBJ(d)->affected[OLC_VAL(d)].modifier = atoi(arg);
    oedit_disp_prompt_apply_menu(d);
    return;

  case OEDIT_EXTRADESC_KEY:
    if (genolc_checkstring(d, arg)) {
      if (OLC_DESC(d)->keyword)
        free(OLC_DESC(d)->keyword);
      OLC_DESC(d)->keyword = str_udup(arg);
    }
    oedit_disp_extradesc_menu(d);
    return;

  case OEDIT_EXTRADESC_MENU:
    switch ((number = atoi(arg))) {
    case 0:
      if (!OLC_DESC(d)->keyword || !OLC_DESC(d)->description) {
        struct extra_descr_data *temp;

	if (OLC_DESC(d)->keyword)
	  free(OLC_DESC(d)->keyword);
	if (OLC_DESC(d)->description)
	  free(OLC_DESC(d)->description);

	/*
	 * Clean up pointers  
	 */
	REMOVE_FROM_LIST(OLC_DESC(d), OLC_OBJ(d)->ex_description, next);
	free(OLC_DESC(d));
	OLC_DESC(d) = NULL;
      }
    break;

    case 1:
      OLC_MODE(d) = OEDIT_EXTRADESC_KEY;
      write_to_output(d, "Enter keywords, separated by spaces :-\r\n| ");
      return;

    case 2:
      OLC_MODE(d) = OEDIT_EXTRADESC_DESCRIPTION;
      send_editor_help(d);
      write_to_output(d, "Enter the extra description:\r\n\r\n");
      if (OLC_DESC(d)->description) {
	write_to_output(d, "%s", OLC_DESC(d)->description);
	oldtext = strdup(OLC_DESC(d)->description);
      }
      string_write(d, &OLC_DESC(d)->description, MAX_MESSAGE_LENGTH, 0, oldtext);
      OLC_VAL(d) = 1;
      return;

    case 3:
      /*
       * Only go to the next description if this one is finished.
       */
      if (OLC_DESC(d)->keyword && OLC_DESC(d)->description) {
	struct extra_descr_data *new_extra;

	if (OLC_DESC(d)->next)
	  OLC_DESC(d) = OLC_DESC(d)->next;
	else {	/* Make new extra description and attach at end. */
	  CREATE(new_extra, struct extra_descr_data, 1);
	  OLC_DESC(d)->next = new_extra;
	  OLC_DESC(d) = OLC_DESC(d)->next;
	}
      }
      /*
       * No break - drop into default case.
       */
    default:
      oedit_disp_extradesc_menu(d);
      return;
    }
    break;
  default:
    mudlog(BRF, LVL_BUILDER, TRUE, "SYSERR: OLC: Reached default case in oedit_parse()!");
    write_to_output(d, "Oops...\r\n");
    break;
  }
Example #25
0
File: news.c Project: bkero/Smaug
/* olc editnews command */
void do_editnews( CHAR_DATA *ch, char *argument )
{
  char arg[MAX_INPUT_LENGTH];

  if(IS_NPC(ch) || !IS_IMMORTAL(ch))
  {
    send_to_char( "Huh?\n\r", ch );
    return;
  }

  set_char_color( AT_GREEN, ch );

  switch( ch->substate )
  {
       default:
         break;

       case SUB_NEWS_POST:
       {
         NEWS *news = NULL;

         news = ch->dest_buf;
         STRFREE(news->post);
         news->post = copy_buffer(ch);
         stop_editing( ch );
         ch->substate = ch->tempnum;
         renumber_news();
         save_news();
         return;
       }
       break;

       case SUB_NEWS_EDIT:
       {
         NEWS *news = NULL;

         news = ch->dest_buf;
         STRFREE(news->post);
         news->post = copy_buffer(ch);
         stop_editing( ch );
         ch->substate = ch->tempnum;
         renumber_news();
         save_news();
         return;
       }
       break;
  }

  argument = one_argument(argument, arg);

  if(arg[0] == '\0' )
  {
    send_to_char( "Syntax: editnews addtype <name>\n\r"
                  "        editnews addnews <type> <subject>\n\r"
                  "        editnews removetype <number>\n\r"
                  "        editnews removenews <type> <number>\n\r"
                  "        editnews edittype <field> <value>\n\r"
                  "        editnews editnews <type> <number> <new subject [optional]>\n\r"
                  " Fields being one of the following:\n\r"
                  " name header cmd_name level\n\r", ch);
    return;
  }

  if( !str_cmp(arg, "save"))
  {
    renumber_news();
    save_news();
    send_to_char( "News saved.\n\r", ch );
    return;
  }

  if(!str_cmp(arg, "addtype"))
  {
    NEWS_TYPE *type = NULL;

    if(argument[0] == '\0')
    {
      send_to_char("Syntax: editnews addtype <name>\n\r", ch);
      return;
    }

    if(top_news_type >= NEWS_MAX_TYPES)
    {
      send_to_char("There are too many news types.\n\r", ch);
      return;
    }

    CREATE(type, NEWS_TYPE, 1);
    type->name              = STRALLOC(argument);
    type->cmd_name          = STRALLOC(argument);
    type->vnum              = top_news_type++;
    type->level		    = -1;

    news_command_table[type->vnum] = STRALLOC(type->cmd_name);

    LINK(type, first_news_type, last_news_type, next, prev);
    ch_printf( ch, "Newstype '%s' created.\n\r", argument );
    return;
  }

  if(!str_cmp(arg, "removetype"))
  {
    NEWS_TYPE *type = NULL;

    if(argument[0] == '\0')
    {
      send_to_char("Syntax: editnews removetype <name>\n\r", ch);
      return;
    }

    if((type = figure_type(argument)) == NULL)
    {
      send_to_char("Invaild newstype.\n\r", ch);
      return;
    }

    UNLINK(type, first_news_type, last_news_type, next, prev);
    if(type->name)
     STRFREE(type->name);
    if(type->header)
     STRFREE(type->header);
    if(type->cmd_name)
     STRFREE(type->cmd_name);
    if(news_command_table[type->vnum])
     STRFREE(news_command_table[type->vnum]);
    if(news_command_table[type->level])
     STRFREE(news_command_table[type->level]);
    {
      NEWS *news = NULL;
      void *next;

      for(news = type->first_news; news; news = next)
      {
        next = news->next;
        UNLINK( news, type->first_news, type->last_news, next, prev );
        if(news->name)
         STRFREE(news->name);
        if(news->title)
         STRFREE(news->title);
        if(news->date)
         STRFREE( news->date );
        if(news->post)
         STRFREE( news->post );
        DISPOSE(news);
      }
    }
    DISPOSE(type);
    top_news_type--;
    renumber_news();
    save_news();
    ch_printf( ch, "Newstype '%s' removed.\n\r", argument );
    return;
  }

  if(!str_cmp(arg, "edittype"))
  {
    char arg2[MAX_INPUT_LENGTH];
    char arg3[MAX_INPUT_LENGTH];
    NEWS_TYPE *type = NULL;

    argument = one_argument(argument, arg2);
    argument = one_argument(argument, arg3);
    if(arg2[0] == '\0' || arg3[0] == '\0')
    {
      send_to_char("Syntax: editnews edittype <type> <field> <value>\n\r", ch);
      send_to_char("Fields being one of the following:\n\r"
                   "name header cmd_name level\n\r", ch );
      return;
    }

    if((type = figure_type(arg2)) == NULL)
    {
      send_to_char("Invalid newstype.\n\r", ch);
      return;
    }

    if(!str_cmp(arg3, "cmd_name"))
    {
      type->cmd_name  = STRALLOC(argument);
      news_command_table[type->vnum] = STRALLOC(type->cmd_name);
      send_to_char("Cmd_name set.\n\r", ch);
      save_news();
      return;
    }
    else if(!str_cmp(arg3, "name"))
    {
      type->name           = STRALLOC(argument);
      send_to_char("Name set.\n\r", ch);
      save_news();
      return;
    }
    else if(!str_cmp(arg3, "level"))
    {
      if ( argument[0] == '\0' )
      {
	ch_printf( ch, "%d\n\r", type->level );
	return;
      }
      else
	type->level = atoi(argument);
      send_to_char("Level set.\n\r", ch);
      save_news();
      return;
    }
    else
    {
      send_to_char("Syntax: editnews edittype <type> <field> <value>\n\r", ch);
      send_to_char("Fields being one of the following:\n\r"
                   "name header cmd_name level\n\r", ch );
      return;
    }
  }

  if( !str_cmp(arg, "addnews" ))
  {
    char arg[MAX_INPUT_LENGTH];
    NEWS_TYPE *type = NULL;
    NEWS *news = NULL;

    argument = one_argument(argument, arg);

    if(arg[0] == '\0' || argument[0] == '\0')
    {
      send_to_char( "Syntax: editnews addnews <type> <subject>\n\r", ch );
      return;
    }

    if((type = figure_type(arg)) == NULL)
    {
      send_to_char("Invaild newstype. Use 'newstypes' to get a valid listing.\n\r", ch);
      return;
    }

    CREATE( news, NEWS, 1 );
    news->title   = STRALLOC(argument);
    news->name    = STRALLOC(ch->name);
    news->date    = STRALLOC(stamp_time( ));
    news->post    = STRALLOC("");

    /* pop character into a writing buffer */
    if( ch->substate == SUB_REPEATCMD )
       ch->tempnum = SUB_REPEATCMD;
    else
       ch->tempnum = SUB_NONE;

    ch->substate = SUB_NEWS_POST;
    ch->dest_buf = news;
    start_editing( ch, news->post );
    LINK(news, type->first_news, type->last_news, next, prev);
    return;
  }

  if( !str_cmp(arg, "editnews"))
  {
    char arg2[MAX_INPUT_LENGTH];
    char arg3[MAX_INPUT_LENGTH];
    NEWS *news = NULL;
    NEWS_TYPE *type = NULL;

    argument = one_argument(argument, arg2);
    argument = one_argument(argument, arg3);
    if(arg2[0] == '\0')
    {
      send_to_char( "Syntax: editnews editnews <type> <number> <new subject [optional]>\n\r", ch );
      return;
    }

    /* changed for new -newstype- indexing - 5/5/02 */
    if((type = figure_type(arg2)) == NULL)
    {
      send_to_char("Invalid newstype. Use 'newstypes' to get a valid listing.\n\r", ch);
      return;
    }

    if((news = grab_news(type, arg3)) == NULL)
    {
      pager_printf_color(ch, "That's not a valid news number.\n\rUse '%s' to view the valid numbers.\n\r", type->cmd_name );
      return;
    }

    /* a changed title */
    if( argument[0] != '\0' )
      news->title   = STRALLOC( argument );

    /* new date news was edited */
    news->date      = STRALLOC(stamp_time( ));
    /* pop character into a writing buffer */
    if( ch->substate == SUB_REPEATCMD )
       ch->tempnum = SUB_REPEATCMD;
    else
       ch->tempnum = SUB_NONE;

    ch->substate = SUB_NEWS_EDIT;
    ch->dest_buf = news;
    start_editing( ch, news->post );
    return;
  }

  if( !str_cmp(arg, "removenews"))
  {
    char arg2[MAX_INPUT_LENGTH];
    NEWS *news = NULL;
    NEWS_TYPE *type = NULL;

    argument = one_argument(argument, arg2);
    if(argument[0] == '\0' || arg2[0] == '\0')
    {
      send_to_char("Syntax: editnews remove <number>\n\r", ch );
      return;
    }

    /* changed for new -newstype- indexing - 5/5/02 */
    if((type = figure_type(arg2)) == NULL)
    {
      send_to_char("Invalid newstype. Use 'newstypes' to get a valid listing.\n\r", ch);
      return;
    }

    if((news = grab_news(type, argument)) == NULL)
    {
      send_to_char( "Type 'news' to gain a list of the news numbers.\n\r", ch );
      return;
    }

    UNLINK( news, type->first_news, type->last_news, next, prev );
   if(news->name)
    STRFREE( news->name );
   if(news->title)
    STRFREE( news->title );
   if(news->date)
    STRFREE( news->date );
   if(news->post)
    STRFREE( news->post );
    DISPOSE( news );
    renumber_news();
    save_news();
    send_to_char("News item removed.\n\r", ch );
    return;
  }
}
Example #26
0
void cast_bless( byte level, struct char_data *ch, char *arg, int type,
  struct char_data *tar_ch, struct obj_data *tar_obj )
{
	struct affected_type af;

  switch (type) {
    case SPELL_TYPE_SPELL:
			if (tar_obj) {        /* It's an object */
				if ( IS_SET(tar_obj->obj_flags.extra_flags, ITEM_BLESS) ) {
					send_to_char("Nothing seems to happen.\n\r", ch);
					return;
				}
				spell_bless(level,ch,0,tar_obj);

			} else {              /* Then it is a PC | NPC */

				if ( affected_by_spell(tar_ch, SPELL_BLESS) ||
					(GET_POS(tar_ch) == POSITION_FIGHTING)) {
					send_to_char("Nothing seems to happen.\n\r", ch);
					return;
				} 
				spell_bless(level,ch,tar_ch,0);
			}
			break;
	 case SPELL_TYPE_POTION:
   		if ( affected_by_spell(ch, SPELL_BLESS) ||
				(GET_POS(ch) == POSITION_FIGHTING))
				return;
			spell_bless(level,ch,ch,0);
         break;
    case SPELL_TYPE_SCROLL:
			if (tar_obj) {        /* It's an object */
				if ( IS_SET(tar_obj->obj_flags.extra_flags, ITEM_BLESS) )
					return;
				spell_bless(level,ch,0,tar_obj);

			} else {              /* Then it is a PC | NPC */

				if (!tar_ch) tar_ch = ch;
				
				if ( affected_by_spell(tar_ch, SPELL_BLESS) ||
					(GET_POS(tar_ch) == POSITION_FIGHTING))
					return;
				spell_bless(level,ch,tar_ch,0);
			}
			break;
    case SPELL_TYPE_WAND:
			if (tar_obj) {        /* It's an object */
				if ( IS_SET(tar_obj->obj_flags.extra_flags, ITEM_BLESS) )
					return;
				spell_bless(level,ch,0,tar_obj);

			} else {              /* Then it is a PC | NPC */

				if ( affected_by_spell(tar_ch, SPELL_BLESS) ||
					(GET_POS(tar_ch) == POSITION_FIGHTING))
					return;
				spell_bless(level,ch,tar_ch,0);
			}
			break;
    default : 
         log("Serious screw-up in bless!");
         break;
	}
}
Example #27
0
void do_allow( CHAR_DATA* ch, const char* argument)
{
    BAN_DATA *pban;
    char arg1[MAX_INPUT_LENGTH];
    char arg2[MAX_INPUT_LENGTH];
    char *temp = NULL;
    bool fMatch = FALSE;
    int value = 0;

    if( IS_NPC( ch ) )   /* No mobs allowing sites */
    {
        send_to_char( "Monsters are too dumb to do that!\r\n", ch );
        return;
    }

    if( !ch->desc )   /* No desc is a bad thing */
    {
        bug( "%s", "do_allow: no descriptor" );
        return;
    }

    argument = one_argument( argument, arg1 );
    argument = one_argument( argument, arg2 );

    set_char_color( AT_IMMORT, ch );

    if( arg1[0] == '\0' || arg2[0] == '\0' )
        goto syntax_message;
    if( arg2[0] == '#' ) /* Use #1 to ban the first ban in the list specified */
    {
        temp = arg2;
        temp++;
        if( !is_number( temp ) )
        {
            send_to_char( "Which ban # to allow?\r\n", ch );
            return;
        }
        value = atoi( temp );
    }
    if( !str_cmp( arg1, "site" ) )
    {
        if( !value )
        {
            if( strlen( arg2 ) < 2 )
            {
                send_to_char( "You have to have at least 2 chars for a ban\r\n", ch );
                send_to_char( "If you are trying to allow by number use #\r\n", ch );
                return;
            }

            temp = arg2;
            if( arg2[0] == '*' )
                temp++;
            if( temp[strlen( temp ) - 1] == '*' )
                temp[strlen( temp ) - 1] = '\0';
        }

        for( pban = first_ban; pban; pban = pban->next )
        {
            /*
             * Need to make sure we dispose properly of the ban_data
             * * Or memory problems will be created.
             * * Shaddai
             */

            if( value == 1 || !str_cmp( pban->name, temp ) )
            {
                fMatch = TRUE;
                dispose_ban( pban, BAN_SITE );
                break;
            }
            if( value > 1 )
                value--;
        }
    }
    else if( !str_cmp( arg1, "race" ) )
    {

        arg2[0] = toupper( arg2[0] );
        for( pban = first_ban_race; pban; pban = pban->next )
        {
            /*
             * Need to make sure we dispose properly of the ban_data
             * * Or memory problems will be created.
             * * Shaddai
             */

            if( value == 1 || !str_cmp( pban->name, arg2 ) )
            {
                fMatch = TRUE;
                dispose_ban( pban, BAN_RACE );
                break;
            }
            if( value > 1 )
                value--;
        }
    }
    else if( !str_cmp( arg1, "class" ) )
    {

        arg2[0] = toupper( arg2[0] );
        for( pban = first_ban_class; pban; pban = pban->next )
        {
            /*
             * Need to make sure we dispose properly of the ban_data
             * * Or memory problems will be created.
             * * Shaddai
             */

            if( value == 1 || !str_cmp( pban->name, arg2 ) )
            {
                fMatch = TRUE;
                dispose_ban( pban, BAN_CLASS );
                break;
            }
            if( value > 1 )
                value--;
        }
    }
    else
        goto syntax_message;

    if( fMatch )
    {
        save_banlist(  );
        ch_printf( ch, "%s is now allowed.\r\n", arg2 );
    }
    else
        ch_printf( ch, "%s was not banned.\r\n", arg2 );
    return;

    /*
     *  Make sure that return above stays in!
     */

syntax_message:
    send_to_char( "Syntax: allow site  <address>\r\n", ch );
    send_to_char( "Syntax: allow race  <race>\r\n", ch );
    send_to_char( "Syntax: allow class <class>\r\n", ch );
    return;
}
Example #28
0
/* toss $n $dice $table for $face */
void
char__do_toss (CHAR_DATA * ch, char *argument, int cmd)
{
    register short int nArg = 0;
    register short int nDiceArg = 0;
    register short int nTableArg = 0;
    register short int nFaceArg = 0;
    register short int nFacet = 0;
    register short int nMaxFacet = 0;
    size_t nIndex = 0;
    register int nCount = 0;

    char *p = NULL;
    char buf[AVG_STRING_LENGTH * 10] = "";
    char arg[5][AVG_STRING_LENGTH / 5] = { "", "", "", "", "" };
    char key[AVG_STRING_LENGTH] = "";
    char strFacet[AVG_STRING_LENGTH] = "";
    char strFacetList[AVG_STRING_LENGTH] = "";
    OBJ_DATA *dice = NULL;
    OBJ_DATA *table = NULL;

    nArg =
        sscanf (argument, "%s %s %s %s %s", arg[0], arg[1], arg[2], arg[3],
                arg[4]);

    if (nArg <= 0)
    {
        send_to_char ("Toss what?\n", ch);
        return;
    }

    nCount = strtol (arg[0], &p, 10);
    if (errno == ERANGE || nCount == 0 || strlen (p) != 0)
    {
        nCount = 0;
    }
    else
    {
        nDiceArg = 1;
    }

    switch (nArg - nDiceArg)
    {
    case 3:
        nFaceArg = (strcmp ("for", arg[nDiceArg + 1]) == 0) ? nDiceArg + 2 : -1;
        break;
    case 4:
        nFaceArg = (strcmp ("for", arg[nDiceArg + 2]) == 0) ? nDiceArg + 3 : -1;	/* NO BREAK HERE goes to next case */
    case 2:
        nTableArg = nDiceArg + 1;
        break;
    default:
        break;
    }

    if (nFaceArg < 0)
    {
        send_to_char ("Toss them how?\n", ch);
        return;
    }

    if (!(dice = get_obj_in_dark (ch, arg[nDiceArg], ch->right_hand)) &&
            !(dice = get_obj_in_dark (ch, arg[nDiceArg], ch->left_hand)))
    {
        sprintf (buf, "You don't have a '%s'.\n", arg[nDiceArg]);
        send_to_char (buf, ch);
        return;
    }
    if (dice->obj_flags.type_flag != ITEM_TOSSABLE
            && dice->obj_flags.type_flag != ITEM_MONEY)
    {
        send_to_char ("Did you mean to #6throw#0 that object?\n", ch);
        return;
    }

    if (dice->count > 12 && (nCount == 0 || nCount > 12))
    {
        send_to_char ("You can't toss that many at once.\n", ch);
        return;
    }

    if (nTableArg && arg[nTableArg][0] &&
            (!(table = get_obj_in_list_vis (ch, arg[nTableArg], ch->room->contents))
             || !IS_TABLE(table)))
    {
        sprintf (buf, "You don't see any furniture like '%s'.\n",
                 arg[nTableArg]);
        send_to_char (buf, ch);
        return;
    }

    obj_from_char (&dice, nCount);

    if (dice->obj_flags.type_flag == ITEM_MONEY)
    {
        strcpy (key, " obverse reverse ");
        nMaxFacet = 2;
    }
    else if (dice->desc_keys)
    {
        sprintf (key, " %s ", dice->desc_keys);
    }
    else
    {
        strcpy (key,
                " one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen twenty ");
    }

    if (nFaceArg && dice->o.od.value[1])
    {
        /*
           nFacet = strtol(arg[nFaceArg],&p,10);
           if ( errno == ERANGE || nFacet == 0 || strlen(p) != 0 ) {
           strcpy(strFacet,strstr(key,arg[nFaceArg]));
           if () {
           }
           else {
           nFacet = 0;
           }
           }
           else {
           }
         */

    }
    nMaxFacet = (nMaxFacet) ? nMaxFacet : dice->o.od.value[0];
    for (nCount = 0; nCount < dice->count; nCount++)
    {

        nFacet = number (1, nMaxFacet);

        for (nIndex = 0; nIndex < strlen (key); nIndex++)
        {
            if (key[nIndex] == ' ' && --nFacet <= 0)
                break;
        }

        sscanf (key + nIndex + 1, "%s %s", strFacet, buf);
        sprintf (strFacetList + strlen (strFacetList), "#6%s%s#0%s",
                 (nMaxFacet == 2) ? "the " : "a ", strFacet,
                 (nCount ==
                  dice->count - 2) ? " and " : ((nCount !=
                                                dice->count - 1) ? ", " : ""));
    }

    sprintf (buf, "You toss $p onto %s%s%s%s. The upright face%s show%s: %s.\n",
             (nTableArg) ? "$P" : "the ground",
             (nFaceArg) ? ", trying for #6a " : "",
             (nFaceArg) ? arg[nFaceArg] : "", (nFaceArg) ? "#0" : "",
             (nCount > 1) ? "s" : "", (nCount > 1) ? "" : "s", strFacetList);
    act (buf, true, ch, dice, table, TO_CHAR | _ACT_FORMAT);

    sprintf (buf, "$n tosses $p onto %s. The upright face%s show%s: %s.\n",
             (nTableArg) ? "$P" : "the ground", (nCount > 1) ? "s" : "",
             (nCount > 1) ? "" : "s", strFacetList);
    act (buf, true, ch, dice, table, TO_ROOM | _ACT_FORMAT);

    if (nTableArg)
    {
        obj_to_obj (dice, table);
    }
    else
    {
        obj_to_room (dice, ch->in_room);
    }
}
Example #29
0
/*
 *  This actually puts the new ban into the proper linked list and
 *  initializes its data.  Shaddai
 */
int add_ban( CHAR_DATA * ch, const char *arg1, const char *arg2, int btime, int type )
{
    char arg[MAX_STRING_LENGTH];
    char buf[MAX_STRING_LENGTH];
    BAN_DATA *pban, *temp;
    struct tm *tms;
    char *name;
    int level, i, value;

    /*
     * Should we check to see if they have dropped link sometime in between
     * * writing the note and now?  Not sure but for right now we won't since
     * * do_ban checks for that.  Shaddai
     */

    switch ( ch->substate )
    {
    default:
        bug( "%s", "add_ban: illegal substate" );
        return 0;

    case SUB_RESTRICTED:
        send_to_char( "You cannot use this command from within another command.\r\n", ch );
        return 0;

    case SUB_NONE:
    {
        one_argument( arg1, arg );
        smash_tilde( arg );  /* Make sure the immortals don't put a ~ in it. */

        if( arg[0] == '\0' || arg2[0] == '\0' )
            return 0;

        if( is_number( arg2 ) )
        {
            level = atoi( arg2 );
            if( level < 0 || level > LEVEL_SUPREME )
            {
                ch_printf( ch, "Level range is from 0 to %d.\r\n", LEVEL_SUPREME );
                return 0;
            }
        }
        else if( !str_cmp( arg2, "all" ) )
            level = LEVEL_SUPREME;
        else if( !str_cmp( arg2, "newbie" ) )
            level = 1;
        else if( !str_cmp( arg2, "mortal" ) )
            level = LEVEL_AVATAR;
        else if( !str_cmp( arg2, "warn" ) )
            level = BAN_WARN;
        else
        {
            bug( "%s", "Bad string for flag in add_ban." );
            return 0;
        }

        switch ( type )
        {
        case BAN_CLASS:
            if( arg[0] == '\0' )
                return 0;
            if( is_number( arg ) )
                value = atoi( arg );
            else
            {
                for( i = 0; i < MAX_CLASS; i++ )
                    if( !str_cmp( class_table[i]->who_name, arg ) )
                        break;
                value = i;
            }
            if( value < 0 || value >= MAX_CLASS )
            {
                send_to_char( "Unknown class.\r\n", ch );
                return 0;
            }
            for( temp = first_ban_class; temp; temp = temp->next )
            {
                if( temp->flag == value )
                {
                    if( temp->level == level )
                    {
                        send_to_char( "That entry already exists.\r\n", ch );
                        return 0;
                    }
                    else
                    {
                        temp->level = level;
                        if( temp->level == BAN_WARN )
                            temp->warn = TRUE;
                        snprintf( buf, MAX_STRING_LENGTH, "%24.24s", ctime( &current_time ) );
                        temp->ban_time = str_dup( buf );
                        if( btime > 0 )
                        {
                            temp->duration = btime;
                            tms = localtime( &current_time );
                            tms->tm_mday += btime;
                            temp->unban_date = mktime( tms );
                        }
                        else
                        {
                            temp->duration = -1;
                            temp->unban_date = -1;
                        }
                        if( temp->ban_by )
                            DISPOSE( temp->ban_by );
                        temp->ban_by = str_dup( ch->name );
                        send_to_char( "Updated entry.\r\n", ch );
                        return 1;
                    }
                }
            }
            CREATE( pban, BAN_DATA, 1 );
            pban->name = str_dup( class_table[value]->who_name );
            pban->flag = value;
            pban->level = level;
            pban->ban_by = str_dup( ch->name );
            LINK( pban, first_ban_class, last_ban_class, next, prev );
            break;

        case BAN_RACE:
            if( is_number( arg ) )
                value = atoi( arg );
            else
            {
                for( i = 0; i < MAX_RACE; i++ )
                    if( !str_cmp( race_table[i]->race_name, arg ) )
                        break;
                value = i;
            }
            if( value < 0 || value >= MAX_RACE )
            {
                send_to_char( "Unknown race.\r\n", ch );
                return 0;
            }
            for( temp = first_ban_race; temp; temp = temp->next )
            {
                if( temp->flag == value )
                {
                    if( temp->level == level )
                    {
                        send_to_char( "That entry already exists.\r\n", ch );
                        return 0;
                    }
                    else
                    {
                        temp->level = level;
                        if( temp->level == BAN_WARN )
                            temp->warn = TRUE;
                        snprintf( buf, MAX_STRING_LENGTH, "%24.24s", ctime( &current_time ) );
                        temp->ban_time = str_dup( buf );
                        if( btime > 0 )
                        {
                            temp->duration = btime;
                            tms = localtime( &current_time );
                            tms->tm_mday += btime;
                            temp->unban_date = mktime( tms );
                        }
                        else
                        {
                            temp->duration = -1;
                            temp->unban_date = -1;
                        }
                        if( temp->ban_by )
                            DISPOSE( temp->ban_by );
                        temp->ban_by = str_dup( ch->name );
                        send_to_char( "Updated entry.\r\n", ch );
                        return 1;
                    }
                }
            }
            CREATE( pban, BAN_DATA, 1 );
            pban->name = str_dup( race_table[value]->race_name );
            pban->flag = value;
            pban->level = level;
            pban->ban_by = str_dup( ch->name );
            LINK( pban, first_ban_race, last_ban_race, next, prev );
            break;

        case BAN_SITE:
        {
            bool prefix = FALSE, suffix = FALSE, user_name = FALSE;
            char *temp_host = NULL, *temp_user = NULL;
            size_t x;

            for( x = 0; x < strlen( arg ); x++ )
            {
                if( arg[x] == '@' )
                {
                    user_name = TRUE;
                    temp_host = str_dup( &arg[x + 1] );
                    arg[x] = '\0';
                    temp_user = str_dup( arg );
                    break;
                }
            }
            if( !user_name )
                name = arg;
            else
                name = temp_host;

            if( !name ) /* Double check to make sure name isnt null */
            {
                /*
                 * Free this stuff if its there
                 */
                if( user_name )
                {
                    DISPOSE( temp_host );
                    DISPOSE( temp_user );
                }
                send_to_char( "Name was null.\r\n", ch );
                return 0;
            }

            if( name[0] == '*' )
            {
                prefix = TRUE;
                name++;
            }

            if( name[strlen( name ) - 1] == '*' )
            {
                suffix = TRUE;
                name[strlen( name ) - 1] = '\0';
            }
            for( temp = first_ban; temp; temp = temp->next )
            {
                if( !str_cmp( temp->name, name ) )
                {
                    if( temp->level == level && ( prefix && temp->prefix ) && ( suffix && temp->suffix ) )
                    {
                        /*
                         * Free this stuff if its there
                         */
                        if( user_name )
                        {
                            DISPOSE( temp_host );
                            DISPOSE( temp_user );
                        }
                        send_to_char( "That entry already exists.\r\n", ch );
                        return 0;
                    }
                    else
                    {
                        temp->suffix = suffix;
                        temp->prefix = prefix;
                        if( temp->level == BAN_WARN )
                            temp->warn = TRUE;
                        temp->level = level;
                        snprintf( buf, MAX_STRING_LENGTH, "%24.24s", ctime( &current_time ) );
                        temp->ban_time = str_dup( buf );
                        if( btime > 0 )
                        {
                            temp->duration = btime;
                            tms = localtime( &current_time );
                            tms->tm_mday += btime;
                            temp->unban_date = mktime( tms );
                        }
                        else
                        {
                            temp->duration = -1;
                            temp->unban_date = -1;
                        }
                        if( temp->ban_by )
                            DISPOSE( temp->ban_by );
                        if( user_name )
                        {
                            DISPOSE( temp_host );
                            DISPOSE( temp_user );
                        }
                        temp->ban_by = str_dup( ch->name );
                        send_to_char( "Updated entry.\r\n", ch );
                        return 1;
                    }
                }
            }
            CREATE( pban, BAN_DATA, 1 );
            pban->ban_by = str_dup( ch->name );
            pban->suffix = suffix;
            pban->prefix = prefix;
            pban->name = str_dup( name );
            pban->level = level;
            LINK( pban, first_ban, last_ban, next, prev );
            if( user_name )
            {
                DISPOSE( temp_host );
                DISPOSE( temp_user );
            }
            break;
        }
        default:
            bug( "Bad type in add_ban: %d.", type );
            return 0;
        }
        snprintf( buf, MAX_STRING_LENGTH, "%24.24s", ctime( &current_time ) );
        pban->ban_time = str_dup( buf );
        if( btime > 0 )
        {
            pban->duration = btime;
            tms = localtime( &current_time );
            tms->tm_mday += btime;
            pban->unban_date = mktime( tms );
        }
        else
        {
            pban->duration = -1;
            pban->unban_date = -1;
        }
        if( pban->level == BAN_WARN )
            pban->warn = TRUE;
        ch->substate = SUB_BAN_DESC;
        ch->dest_buf = pban;
        if( !pban->note )
            pban->note = STRALLOC( "" );;
        start_editing( ch, pban->note );
        return 1;
    }
    case SUB_BAN_DESC:
        pban = ( BAN_DATA * ) ch->dest_buf;
        if( !pban )
        {
            bug( "%s", "do_ban: sub_ban_desc: NULL ch->dest_buf" );
            ch->substate = SUB_NONE;
            return 0;
        }
        if( pban->note )
            STRFREE( pban->note );
        pban->note = copy_buffer( ch );
        stop_editing( ch );
        ch->substate = ch->tempnum;
        save_banlist(  );
        if( pban->duration > 0 )
        {
            ch_printf( ch, "%s banned for %d days.\r\n", pban->name, pban->duration );
        }
        else
        {
            ch_printf( ch, "%s banned forever.\r\n", pban->name );
        }
        return 1;
    }
}
Example #30
0
/*  Warm reboot stuff, gotta make sure to thank Erwin for this :) */
void do_hotboot( CHAR_DATA * ch, const char *argument )
{
   FILE *fp;
   CHAR_DATA *victim = NULL;
   DESCRIPTOR_DATA *d, *de_next;
   char buf[100], buf2[100], buf3[100];
   extern int control;
   int count = 0;
   bool found = FALSE;

   for( d = first_descriptor; d; d = d->next )
   {
      if( ( d->connected == CON_PLAYING
            || d->connected == CON_EDITING )
          && ( victim = d->character ) != NULL && !IS_NPC( victim )
          && victim->in_room && victim->fighting && victim->top_level >= 1 && victim->top_level <= MAX_LEVEL )
      {
         found = TRUE;
         count++;
      }
   }

   if( found )
   {
      ch_printf( ch, "Cannot hotboot at this time. There are %d combats in progress.\r\n", count );
      return;
   }

   found = FALSE;
   for( d = first_descriptor; d; d = d->next )
   {
      if( d->connected == CON_EDITING && d->character )
      {
         found = TRUE;
         break;
      }
   }

   if( found )
   {
      send_to_char( "Cannot hotboot at this time. Someone is using the line editor.\r\n", ch );
      return;
   }

   sprintf( log_buf, "Hotboot initiated by %s.", ch->name );
   log_string( log_buf );

   fp = fopen( HOTBOOT_FILE, "w" );

   if( !fp )
   {
      send_to_char( "Hotboot file not writeable, aborted.\r\n", ch );
      bug( "Could not write to hotboot file: %s. Hotboot aborted.", HOTBOOT_FILE );
      perror( "do_copyover:fopen" );
      return;
   }

   /*
    * And this one here will save the status of all objects and mobs in the game.
    * * This really should ONLY ever be used here. The less we do stuff like this the better.
    */
   save_world( ch );

#ifdef OLC_SHUTTLE
   {
      SHUTTLE_DATA *tshuttle;

      for( tshuttle = first_shuttle; tshuttle; tshuttle = tshuttle->next )
         save_shuttle( tshuttle );
   }
#endif

   log_string( "Saving player files and connection states...." );
   if( ch && ch->desc )
      write_to_descriptor( ch->desc, "\033[0m", 0 );
   sprintf( buf, "\r\nYou feel a great disturbance in the Force." );
   /*
    * For each playing descriptor, save its state 
    */
   for( d = first_descriptor; d; d = de_next )
   {
      CHAR_DATA *och = CH( d );

      de_next = d->next;   /* We delete from the list , so need to save this */
      if( !d->character || d->connected < CON_PLAYING )  /* drop those logging on */
      {
         write_to_descriptor( d, "\r\nSorry, we are rebooting. Come back in a few minutes.\r\n", 0 );
         close_socket( d, FALSE );  /* throw'em out */
      }
      else
      {
/* 			For test purposes
			flush_buffer(d, TRUE);*/
         fprintf( fp, "%d %d %d %d %d %s %s\n", d->can_compress, d->descriptor, och->in_room->vnum, d->port, d->idle, och->name, d->host );
         /*
          * One of two places this gets changed 
          */
         och->pcdata->hotboot = TRUE;
         save_char_obj( och );
         write_to_descriptor( d, buf, 0 );
         compressEnd( d );
      }
   }

   fprintf( fp, "%s", "-1" );
   FCLOSE( fp );

#ifdef IMC
   imc_hotboot(  );
#endif

   /*
    * added this in case there's a need to debug the contents of the various files 
    */
   if( argument && !str_cmp( argument, "debug" ) )
   {
      log_string( "Hotboot debug - Aborting before execl" );
      return;
   }

   log_string( "Executing hotboot...." );

   /*
    * exec - descriptors are inherited 
    */
   snprintf( buf, 100, "%d", port );
   snprintf( buf2, 100, "%d", control );
#ifdef IMC
   if( this_imcmud )
      snprintf( buf3, 100, "%d", this_imcmud->desc );
   else
      strncpy( buf3, "-1", 100 );
#else
   strncpy( buf3, "-1", 100 );
#endif

   dlclose( sysdata.dlHandle );
   execl( EXE_FILE, "swreality", buf, "hotboot", buf2, buf3, ( char * )NULL );

   /*
    * Failed - sucessful exec will not return 
    */
   perror( "do_hotboot: execl" );
   sysdata.dlHandle = dlopen( NULL, RTLD_LAZY );
   if( !sysdata.dlHandle )
   {
	bug( "%s", "FATAL ERROR: Unable to reopen system executable handle!" );
	exit( 1 );
   }
   bug( "%s", "Hotboot execution failed!!" );
   send_to_char( "Hotboot FAILED!\r\n", ch );
}