Exemple #1
0
bool typex_encryption_test::test()
{
    bool result = false;
    // String containing all possible plaintext characters. BTW: > switches machine in figures mode and < switches it back.
    ustring plain = "qwertyuiopasdfghjkl cbnm>1234567890-/z%x£*() v,.<a";
    // Input to numeric decipherment test.
    ustring plain2 = "bbkddivxafwbkynnhtwdcpjhfnmmgz";
    typex typex_t(TYPEX_SP_02390_UKW, TYPEX_SP_02390_A, TYPEX_SP_02390_B, TYPEX_SP_02390_C, TYPEX_SP_02390_D, TYPEX_SP_02390_E);    
    typex typex_t2(TYPEX_SP_02390_UKW, TYPEX_SP_02390_A, TYPEX_SP_02390_B, TYPEX_SP_02390_C, TYPEX_SP_02390_D, TYPEX_SP_02390_E);        
    vector<pair<char, char> > inv;
    ustring enc_result, dec_result;
    // Expected encryption result of string contained in variable plain.
    ustring result_ref = "hvdngqylgghjokkioxpeqlfemxnwizaomssrmfsvvpuacykucn";
    
    inv.push_back(pair<char, char>('a', 'r'));
    inv.push_back(pair<char, char>('b', 'y'));
    inv.push_back(pair<char, char>('c', 'u'));
    inv.push_back(pair<char, char>('d', 'h'));    
    inv.push_back(pair<char, char>('e', 'q'));
    inv.push_back(pair<char, char>('f', 's'));
    inv.push_back(pair<char, char>('g', 'l'));
    inv.push_back(pair<char, char>('i', 'x'));
    inv.push_back(pair<char, char>('j', 'p'));
    inv.push_back(pair<char, char>('k', 'n'));
    inv.push_back(pair<char, char>('m', 'o'));
    inv.push_back(pair<char, char>('t', 'w'));
    inv.push_back(pair<char, char>('v', 'z'));
    
    typex_t.set_reflector(inv);
    typex_t2.set_reflector(inv);
    
    // Encryption test
    enc_result = typex_t.get_keyboard()->symbols_typed_encrypt(plain);
    
    result = (enc_result == result_ref);
    
    if (!result)
    {
        append_note(enc_result);
        append_note("Typex Encryption Test failed.");
        return result;
    }
    
    append_note(enc_result);
    
    // Numeric decryption test
    append_note("TypeX numeric code decipherment");
    
    dec_result = typex_t2.get_keyboard()->symbols_typed_decrypt(plain2);
    append_note(dec_result);
    
    result = (dec_result == "34872 42789 25470 21346 89035");
    
    return result;
}
Exemple #2
0
bool decipherment_test::test()
{
    bool result = test_case::test();
    ustring decryption_result;
    string ini_name = name + ".ini";

    // first decryption
    result = !machine_enc->save(ini_name);
    
    if (!result)
    {
        append_note("Saving state failed");
        return result;
    }

    append_note("Rotor start positions: " + machine_enc->visualize_all_positions());
    decryption_result = machine_enc->get_keyboard()->symbols_typed_decrypt(spruch);
    append_note(decryption_result);
    append_note("Rotor end positions: " + machine_enc->visualize_all_positions());    

    result = (decryption_result == plain);
    
    if (!result)
    {
        append_note("Decryption one failed");
        return result;
    }    

    // second decryption
    result = !machine_dec->load(ini_name);
    
    if (!result)
    {
        append_note("Loading state failed");
        return result;
    }

    decryption_result = machine_dec->get_keyboard()->symbols_typed_decrypt(spruch);
    result = (decryption_result == plain);
    
    if (!result)
    {
        append_note("Decryption two failed");
        return result;
    }    
    
    return result;
}
Exemple #3
0
/* Save a note in a given board */
void finish_note (BOARD_DATA *board, NOTE_DATA *note)
{
	FILE *fp;
	NOTE_DATA *p;
	char filename[200];
	
	/* The following is done in order to generate unique date_stamps */

	if (last_note_stamp >= current_time)
		note->date_stamp = ++last_note_stamp;
	else
	{
	    note->date_stamp = current_time;
	    last_note_stamp = current_time;
	}
	
	if (board->note_first) /* are there any notes in there now? */
	{
		for (p = board->note_first; p->next; p = p->next )
			; /* empty */
		
		p->next = note;
	}
	else /* nope. empty list. */
		board->note_first = note;

	/* append note to note file */		
	
	xprintf (filename, "%s%s", NOTE_DIR, board->short_name);
	
	fp = fopen (filename, "a");
	if (!fp)
	{
		bug ("Could not open one of the note files in append mode",0);
		board->changed = TRUE; /* set it to TRUE hope it will be OK later? */
		return;
	}
	
	append_note (fp, note);
	fclose (fp);
}
Exemple #4
0
/*
 * Save a single board.
 */
void save_board( BOARD_DATA *board )
{
    FILE      *fp;
    char       strsave	[ MAX_INPUT_LENGTH ];
    NOTE_DATA *note;

    fclose( fpReserve );

    sprintf( strsave, "%s%s", NOTE_DIR, board->short_name );

    if ( !( fp = fopen( strsave, "w" ) ) )
    {
	perror( board->short_name );
    }
    else
    {
	for ( note = board->note_first; note; note = note->next )
	    append_note( fp, note );
	fclose( fp );
    }
    fpReserve = fopen( NULL_FILE, "r" );
    return;
}
Exemple #5
0
/* save a single board */
static void save_board (BOARD_DATA *board)
{
	FILE *fp;
	char filename[200];
	char buf[200];
	NOTE_DATA *note;
	
	xprintf (filename, "%s%s", NOTE_DIR, board->short_name);
	
	fp = fopen (filename, "w");
	if (!fp)
	{
		xprintf (buf, "Error writing to: %s", filename);
		bug (buf, 0);
	}
	else
	{
		for (note = board->note_first; note ; note = note->next)
			append_note (fp, note);
			
		fclose (fp);
	}
}
Exemple #6
0
void parse_note( CHAR_DATA *ch, char *argument, int type )
{
    BUFFER *buffer;
    char buf[MAX_STRING_LENGTH], query[MSL];
    char arg[MAX_INPUT_LENGTH];
    MYSQL_RES *res;
    MYSQL_ROW row;
    char *list_name;
    int vnum;
    int anum;

    switch(type)
    {
	default:
	    return;
        case NOTE_NOTE:
	    list_name = "notes";
            break;
        case NOTE_IDEA:
	    list_name = "ideas";
            break;
        case NOTE_PENALTY:
	    list_name = "penalties";
            break;
        case NOTE_NEWS:
	    list_name = "news";
            break;
        case NOTE_CHANGES:
	    list_name = "changes";
            break;
    }

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

    if ( arg[0] == '\0' || !str_prefix( arg, "read" ) )
    {
        bool fAll;

        if ( !str_cmp( argument, "all" ) )
        {
            fAll = TRUE;
            anum = 0;
        }

        else if ( argument[0] == '\0' || !str_prefix(argument, "next"))
        /* read next unread note */
        {
            vnum = 0;
	    sprintf(query,"SELECT * FROM notes WHERE type=%d ORDER BY timestamp ASC",type);
	    res	= one_query_res(query);
            while((row=mysql_fetch_row(res)))
            {
                if (!hide_note(ch,row))
                {
                    sprintf( buf, "[%3d] %s: %s\n\r%s\n\rTo: %s\n\r",
                        vnum, row[1], row[4], row[2], row[3]);
                    send_to_char( buf, ch );
                    page_to_char( row[5], ch );
                    update_read(ch,atol(row[6]),atoi(row[0]));
		    mysql_free_result(res);
                    return;
                }
		else if(is_note_to(ch,row[1],row[3]))
		    vnum++;
            }
	    sprintf(buf,"You have no unread %s.\n\r",list_name);
	    send_to_char(buf,ch);
	    mysql_free_result(res);
            return;
        }

        else if ( is_number( argument ) )
        {
            fAll = FALSE;
            anum = atoi( argument );
        }
        else
        {
            send_to_char( "Read which number?\n\r", ch );
            return;
        }

        vnum = 0;
	sprintf(query,"SELECT * FROM notes WHERE type=%d ORDER BY timestamp ASC",type);
	res	= one_query_res(query);
        while((row=mysql_fetch_row(res)))
        {
            if (is_note_to(ch,row[1],row[3]) && (vnum++ == anum))
            {
                sprintf( buf, "[%3d] %s: %s\n\r%s\n\rTo: %s\n\r",
                        anum, row[1], row[4], row[2], row[3]);
                send_to_char( buf, ch );
                page_to_char( row[5], ch );
		update_read(ch,atol(row[6]),atoi(row[0]));
		mysql_free_result(res);
                return;
            }
        }

	sprintf(buf,"There aren't that many %s.\n\r",list_name);
	send_to_char(buf,ch);
	mysql_free_result(res);
        return;
    }

    if ( !str_prefix( arg, "list" ) )
    {
	vnum = 0;
	sprintf(query,"SELECT * FROM notes WHERE type=%d ORDER BY timestamp ASC",type);
	res	= one_query_res(query);

        while((row=mysql_fetch_row(res)))
	{
	    if (is_note_to(ch,row[1],row[3]))
	    {
		sprintf( buf, "[%3d%s] %s: %s\n\r",
		    vnum, hide_note(ch,row) ? " " : "N",
		    row[1], row[4]);
		send_to_char( buf, ch );
		vnum++;
	    }
	}
	if (!vnum)
	{
	    switch(type)
	    {
		case NOTE_NOTE:	
		    send_to_char("There are no notes for you.\n\r",ch);
		    break;
		case NOTE_IDEA:
		    send_to_char("There are no ideas for you.\n\r",ch);
		    break;
		case NOTE_PENALTY:
		    send_to_char("There are no penalties for you.\n\r",ch);
		    break;
		case NOTE_NEWS:
		    send_to_char("There is no news for you.\n\r",ch);
		    break;
		case NOTE_CHANGES:
		    send_to_char("There are no changes for you.\n\r",ch);
		    break;
	    }
	}
	mysql_free_result(res);
	return;
    }

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


        anum = atoi( argument );
        vnum = 0;
	sprintf(query,"SELECT * FROM notes WHERE type=%d ORDER BY timestamp ASC",type);
	res	= one_query_res(query);
        while((row=mysql_fetch_row(res)))
	{
            if (!str_cmp(ch->true_name, row[1]) && vnum++ == anum )
            {
                sprintf(query,"DELETE FROM notes WHERE timestamp=%s AND sender=\"%s\"", row[6], row[1]);
		one_query(query);
                send_to_char( "Ok.\n\r", ch );
		mysql_free_result(res);
                return;
            }
        }

	send_to_char("You must provide the number of a note you have written to remove.\n\r",ch);
	mysql_free_result(res);
        return;
    }

    if ( !str_prefix( arg, "delete" ) && get_trust(ch) >= MAX_LEVEL - 2)
    {
        if ( !is_number( argument ) )
            return send_to_char( "Note delete which number?\n\r", ch );

        anum = atoi( argument );
        vnum = 0;
        sprintf(query,"SELECT * FROM notes WHERE type=%d ORDER BY timestamp ASC",type);
	res	= one_query_res(query);
        while((row=mysql_fetch_row(res)))
	{
            if ( is_note_to( ch,row[1],row[3] ) && vnum++ == anum )
            {
                sprintf(query,"DELETE FROM notes WHERE timestamp=%s AND sender=\"%s\"", row[6], row[1]);
		one_query(query);
		send_to_char("Ok.\n\r",ch);
		mysql_free_result(res);
		return;
            }
        }

 	sprintf(buf,"There aren't that many %s.\n\r",list_name);
	send_to_char(buf,ch);
	mysql_free_result(res);
        return;
    }

    /* below this point only certain people can edit notes */
    if ((type == NOTE_NEWS && !IS_TRUSTED(ch,ANGEL))
    ||  (type == NOTE_CHANGES && !IS_TRUSTED(ch,CREATOR)))
    {
	sprintf(buf,"You aren't high enough level to write %s.",list_name);
	send_to_char(buf,ch);
	return;
    }

    if ( !str_cmp( arg, "+" ) )
    {
	note_attach( ch,type );
	if (ch->pnote->type != type)
	    return send_to_char("You already have a different note in progress.\n\r",ch);

	if (strlen(ch->pnote->text)+strlen(argument) >= 4096)
	    return send_to_char( "Note too long.\n\r", ch );

 	buffer = new_buf();

	add_buf(buffer,ch->pnote->text);
	add_buf(buffer,argument);
	add_buf(buffer,"\n\r");
	free_pstring( ch->pnote->text );
	ch->pnote->text = palloc_string( buf_string(buffer) );
	free_buf(buffer);
	send_to_char( "Ok.\n\r", ch );
	return;
    }

    if (!str_cmp(arg,"-"))
    {
 	int len;
	bool found = FALSE;

	note_attach(ch,type);
        if (ch->pnote->type != type)
            return send_to_char("You already have a different note in progress.\n\r",ch);

	if (ch->pnote->text == NULL || ch->pnote->text[0] == '\0')
	    return send_to_char("No lines left to remove.\n\r",ch);

	strcpy(buf,ch->pnote->text);

	for (len = strlen(buf); len > 0; len--)
 	{
	    if (buf[len] == '\r')
	    {
		if (!found)  /* back it up */
		{
		    if (len > 0)
			len--;
		    found = TRUE;
		}
		else /* found the second one */
		{
		    buf[len + 1] = '\0';
		    free_pstring(ch->pnote->text);
		    ch->pnote->text = palloc_string(buf);
		    return;
		}
	    }
	}
	buf[0] = '\0';
	free_pstring(ch->pnote->text);
	ch->pnote->text = palloc_string(buf);
	return;
    }

    if ( !str_prefix( arg, "subject" ) )
    {
	note_attach( ch,type );
        if (ch->pnote->type != type)
            return send_to_char("You already have a different note in progress.\n\r",ch);

	free_pstring( ch->pnote->subject );
	ch->pnote->subject = palloc_string( argument );
	send_to_char( "Ok.\n\r", ch );
	return;
    }

    if ( !str_prefix( arg, "to" ) )
    {
	note_attach( ch,type );
        if (ch->pnote->type != type)
            return send_to_char("You already have a different note in progress.\n\r",ch);

	if (is_name("all", argument)
	&& !IS_IMMORTAL(ch)
	&& !IS_HEROIMM(ch)
	&& !(ch->pcdata->induct == CABAL_LEADER))
		return	send_to_char("Sorry, you can't do that!\n\r",ch);
	if (is_number(argument) && !IS_IMMORTAL(ch))
		return send_to_char("You can't do that.\n\r",ch);	
	free_pstring( ch->pnote->to_list );
	ch->pnote->to_list = palloc_string( argument );
	send_to_char( "Ok.\n\r", ch );
	return;
	}

    if ( !str_prefix( arg, "clear" ) )
    {
	if ( ch->pnote != NULL )
	{
	    free_note(ch->pnote);
	    ch->pnote = NULL;
	}

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

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

	if (ch->pnote->type != type)
	    return send_to_char("You aren't working on that kind of note.\n\r",ch);

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

    if ( !str_prefix( arg, "post" ) || !str_prefix(arg, "send"))
    {
	char *strtime;

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

        if (ch->pnote->type != type)
            return send_to_char("You aren't working on that kind of note.\n\r",ch);

	if (!str_cmp(ch->pnote->to_list,""))
	    return send_to_char("You need to provide a recipient (name, all, or immortal).\n\r", ch);

	if (!str_cmp(ch->pnote->subject,""))
	    return send_to_char("You need to provide a subject.\n\r",ch);
	if (is_affected_prof(ch, "note_written") && !IS_IMMORTAL(ch))
	    return send_to_char("You have written a note too recently.\n\r",ch);
	ch->pnote->next			= NULL;
	strtime				= ctime( &current_time );
	strtime[strlen(strtime)-1]	= '\0';
	ch->pnote->date			= palloc_string( strtime );
	ch->pnote->date_stamp		= current_time;

	append_note(ch->pnote);
	ch->pnote = NULL;
	send_to_char("Note sent.\n\r",ch);
	add_prof_affect(ch, "note_written", 4, TRUE);
	return;
    }

    send_to_char( "You can't do that.\n\r", ch );
    return;
}
Exemple #7
0
/*
 * Snarf a board.
 */
void load_board( BOARD_DATA *board )
{
    FILE      *fp;
    FILE      *fpArch;
    NOTE_DATA *pnotelast;
    char       strsave	[ MAX_INPUT_LENGTH ];

    sprintf( strsave, "%s%s", NOTE_DIR, board->short_name );

    if ( !( fp = fopen( strsave, "r" ) ) )
	return;	    
    	    
    pnotelast = NULL;
    for ( ; ; )
    {
	NOTE_DATA *pnote;
	int        letter;
	int        stat;

	do
	{
	    letter = getc( fp );
	    if ( feof( fp ) )
	    {
		fclose( fp );
		return;
	    }
	}
	while ( isspace( letter ) );
	ungetc( letter, fp );

	pnote		  = (NOTE_DATA *) alloc_mem( sizeof( *pnote ) );

	if ( str_cmp( fread_word( fp, &stat ), "sender" ) )
	    break;
	pnote->sender     = fread_string( fp, &stat );

	if ( str_cmp( fread_word( fp, &stat ), "date" ) )
	    break;
	pnote->date       = fread_string( fp, &stat );

	if ( str_cmp( fread_word( fp, &stat ), "stamp" ) )
	    break;
	pnote->date_stamp = fread_number( fp, &stat );

	if ( str_cmp( fread_word( fp, &stat ), "expire" ) )
	    break;
	pnote->expire     = fread_number( fp, &stat );

	if ( str_cmp( fread_word( fp, &stat ), "to" ) )
	    break;
	pnote->to_list    = fread_string( fp, &stat );

	if ( str_cmp( fread_word( fp, &stat ), "subject" ) )
	    break;
	pnote->subject    = fread_string( fp, &stat );

	if ( str_cmp( fread_word( fp, &stat ), "text" ) )
	    break;
	pnote->text       = fread_string( fp, &stat );

	pnote->next = NULL;


        /*
	 * Should this note be archived right now?
	 */
        if ( pnote->expire < current_time )
        {
	    sprintf( strsave, "%s%s.old", NOTE_DIR, board->short_name );

	    if ( !( fpArch = fopen( strsave, "a" ) ) )
		bug( "Load_board: couldn't open arch boards for writing.", 0 );
	    else
	    {
		append_note( fpArch, pnote );
		fclose( fpArch );
	    }

	    free_note( pnote );
	    board->changed = TRUE;
	    continue;
        }

        if ( !board->note_first )
	    board->note_first	= pnote;
	else
	    pnotelast->next	= pnote;

        pnotelast		= pnote;
    }

    strcpy( strArea, board->short_name );
    fpArea = fp;

    bug( "Load_board: bad key word.", 0 );
    return;
}
Exemple #8
0
/* Load a single board */
static void load_board (BOARD_DATA *board)
{
	FILE *fp, *fp_archive;
	NOTE_DATA *last_note;
	char filename[200];
	
	xprintf (filename, "%s%s", NOTE_DIR, board->short_name);
	
	fp = fopen (filename, "r");
	
	/* Silently return */
	if (!fp)
		return;		
		
	/* Start note fetching. copy of db.c:load_notes() */

    last_note = NULL;

    for ( ; ; )
    {
        NOTE_DATA *pnote;
        char letter;

        do
        {
            letter = getc( fp );
            if ( feof(fp) )
            {
                fclose( fp );
                return;
            }
        }
        while ( isspace(letter) );
        ungetc( letter, fp );

        pnote             = alloc_perm( sizeof(*pnote) );

        if ( str_cmp( fread_word( fp ), "sender" ) )
            break;
        pnote->sender     = fread_string( fp );

        if ( str_cmp( fread_word( fp ), "date" ) )
            break;
        pnote->date       = fread_string( fp );

        if ( str_cmp( fread_word( fp ), "stamp" ) )
            break;
        pnote->date_stamp = fread_number( fp );

        if ( str_cmp( fread_word( fp ), "expire" ) )
            break;
        pnote->expire = fread_number( fp );

        if ( str_cmp( fread_word( fp ), "to" ) )
            break;
        pnote->to_list    = fread_string( fp );

        if ( str_cmp( fread_word( fp ), "subject" ) )
            break;
        pnote->subject    = fread_string( fp );

        if ( str_cmp( fread_word( fp ), "text" ) )
            break;
        pnote->text       = fread_string( fp );
        
        pnote->next = NULL; /* jic */
        
        /* Should this note be archived right now ? */
        
        if (pnote->expire < current_time)
        {
			char archive_name[200];

			xprintf (archive_name, "%s%s.old", NOTE_DIR, board->short_name);
			fp_archive = fopen (archive_name, "a");
			if (!fp_archive)
				bug ("Could not open archive boards for writing",0);
			else
			{
				append_note (fp_archive, pnote);
				fclose (fp_archive); /* it might be more efficient to close this later */
			}

			free_note (pnote);
			board->changed = TRUE;
			continue;
			
        }
        

        if ( board->note_first == NULL )
            board->note_first = pnote;
        else
            last_note->next     = pnote;

        last_note         = pnote;
    }

    bug( "Load_notes: bad key word.", 0 );
    return; /* just return */
}
void parse_note ( Creature *ch, const char *argument, int type )
{
	BUFFER *buffer;
	char buf[MAX_STRING_LENGTH];
	char arg[MAX_INPUT_LENGTH];
	NOTE_DATA *pnote;
	NOTE_DATA **list;
	const char *list_name;
	int vnum;
	int anum;

	if ( IS_NPC ( ch ) )
	{ return; }

	switch ( type ) {
		default:
			return;
		case NOTE_NOTE:
			list = &note_list;
			list_name = "notes";
			break;
		case NOTE_IDEA:
			list = &idea_list;
			list_name = "ideas";
			break;
		case NOTE_PENALTY:
			list = &penalty_list;
			list_name = "penalties";
			break;
		case NOTE_NEWS:
			list = &news_list;
			list_name = "news";
			break;
		case NOTE_CHANGES:
			list = &changes_list;
			list_name = "changes";
			break;
	}

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

	if ( arg[0] == '\0' || !str_prefix ( arg, "read" ) ) {
		bool fAll;

		if ( SameString ( argument, "all" ) ) {
			fAll = TRUE;
			anum = 0;
		}

		else if ( argument[0] == '\0' || !str_prefix ( argument, "next" ) )
			/* read next unread note */
		{
			vnum = 0;
			for ( pnote = *list; pnote != NULL; pnote = pnote->next ) {
				if ( !hide_note ( ch, pnote ) ) {
					sprintf ( buf, "[%3d] %s: %s\n\r%s\n\rTo: %s\n\r",
							  vnum,
							  pnote->sender,
							  pnote->subject,
							  pnote->date,
							  pnote->to_list );
					writeBuffer ( buf, ch );
					writePage ( pnote->text, ch );
					update_read ( ch, pnote );
					return;
				} else if ( is_note_to ( ch, pnote ) )
				{ vnum++; }
			}
			snprintf ( buf, sizeof ( buf ), "You have no unread %s.\n\r", list_name );
			writeBuffer ( buf, ch );
			return;
		}

		else if ( is_number ( argument ) ) {
			fAll = FALSE;
			anum = atoi ( argument );
		} else {
			writeBuffer ( "Read which number?\n\r", ch );
			return;
		}

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

		snprintf ( buf, sizeof ( buf ), "There aren't that many %s.\n\r", list_name );
		writeBuffer ( buf, ch );
		return;
	}

	if ( !str_prefix ( arg, "list" ) ) {
		vnum = 0;
		for ( pnote = *list; pnote != NULL; pnote = pnote->next ) {
			if ( is_note_to ( ch, pnote ) ) {
				sprintf ( buf, "[%3d%s] %s: %s\n\r",
						  vnum, hide_note ( ch, pnote ) ? " " : "N",
						  pnote->sender, pnote->subject );
				writeBuffer ( buf, ch );
				vnum++;
			}
		}
		if ( !vnum ) {
			switch ( type ) {
				case NOTE_NOTE:
					writeBuffer ( "There are no notes for you.\n\r", ch );
					break;
				case NOTE_IDEA:
					writeBuffer ( "There are no ideas for you.\n\r", ch );
					break;
				case NOTE_PENALTY:
					writeBuffer ( "There are no penalties for you.\n\r", ch );
					break;
				case NOTE_NEWS:
					writeBuffer ( "There is no news for you.\n\r", ch );
					break;
				case NOTE_CHANGES:
					writeBuffer ( "There are no changes for you.\n\r", ch );
					break;
			}
		}
		return;
	}

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

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

		snprintf ( buf, sizeof ( buf ), "There aren't that many %s.", list_name );
		writeBuffer ( buf, ch );
		return;
	}

	if ( !str_prefix ( arg, "delete" ) && get_trust ( ch ) >= MAX_LEVEL - 1 ) {
		if ( !is_number ( argument ) ) {
			writeBuffer ( "Note delete which number?\n\r", ch );
			return;
		}

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

		snprintf ( buf, sizeof ( buf ), "There aren't that many %s.", list_name );
		writeBuffer ( buf, ch );
		return;
	}

	if ( !str_prefix ( arg, "catchup" ) ) {
		switch ( type ) {
			case NOTE_NOTE:
				ch->pcdata->last_note = current_time;
				break;
			case NOTE_IDEA:
				ch->pcdata->last_idea = current_time;
				break;
			case NOTE_PENALTY:
				ch->pcdata->last_penalty = current_time;
				break;
			case NOTE_NEWS:
				ch->pcdata->last_news = current_time;
				break;
			case NOTE_CHANGES:
				ch->pcdata->last_changes = current_time;
				break;
		}
		return;
	}

	/* below this point only certain people can edit notes */
	if ( ( type == NOTE_NEWS && !IS_TRUSTED ( ch, ANGEL ) )
			||  ( type == NOTE_CHANGES && !IS_TRUSTED ( ch, CREATOR ) ) ) {
		snprintf ( buf, sizeof ( buf ), "You aren't high enough level to write %s.", list_name );
		writeBuffer ( buf, ch );
		return;
	}

	if ( SameString ( arg, "+" ) ) {
		note_attach ( ch, type );
		if ( ch->pnote->type != type ) {
			writeBuffer (
				"You already have a different note in progress.\n\r", ch );
			return;
		}

		if ( strlen ( ch->pnote->text ) + strlen ( argument ) >= 4096 ) {
			writeBuffer ( "Note too long.\n\r", ch );
			return;
		}

		buffer = new_buf();

		add_buf ( buffer, ch->pnote->text );
		add_buf ( buffer, argument );
		add_buf ( buffer, "\n\r" );
		PURGE_DATA ( ch->pnote->text );
		ch->pnote->text = assign_string ( buf_string ( buffer ) );
		recycle_buf ( buffer );
		writeBuffer ( "Ok.\n\r", ch );
		return;
	}

	if ( SameString ( arg, "-" ) ) {
		int len;
		bool found = FALSE;

		note_attach ( ch, type );
		if ( ch->pnote->type != type ) {
			writeBuffer (
				"You already have a different note in progress.\n\r", ch );
			return;
		}

		if ( ch->pnote->text == NULL || ch->pnote->text[0] == '\0' ) {
			writeBuffer ( "No lines left to remove.\n\r", ch );
			return;
		}

		strcpy ( buf, ch->pnote->text );

		for ( len = strlen ( buf ); len > 0; len-- ) {
			if ( buf[len] == '\r' ) {
				if ( !found ) { /* back it up */
					if ( len > 0 )
					{ len--; }
					found = TRUE;
				} else { /* found the second one */
					buf[len + 1] = '\0';
					PURGE_DATA ( ch->pnote->text );
					ch->pnote->text = assign_string ( buf );
					return;
				}
			}
		}
		buf[0] = '\0';
		PURGE_DATA ( ch->pnote->text );
		ch->pnote->text = assign_string ( buf );
		return;
	}

	if ( !str_prefix ( arg, "subject" ) ) {
		note_attach ( ch, type );
		if ( ch->pnote->type != type ) {
			writeBuffer (
				"You already have a different note in progress.\n\r", ch );
			return;
		}

		PURGE_DATA ( ch->pnote->subject );
		ch->pnote->subject = assign_string ( argument );
		writeBuffer ( "Ok.\n\r", ch );
		return;
	}

	if ( !str_prefix ( arg, "to" ) ) {
		note_attach ( ch, type );
		if ( ch->pnote->type != type ) {
			writeBuffer (
				"You already have a different note in progress.\n\r", ch );
			return;
		}
		PURGE_DATA ( ch->pnote->to_list );
		ch->pnote->to_list = assign_string ( argument );
		writeBuffer ( "Ok.\n\r", ch );
		return;
	}

	if ( !str_prefix ( arg, "clear" ) ) {
		if ( ch->pnote != NULL ) {
			recycle_note ( ch->pnote );
			ch->pnote = NULL;
		}

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

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

		if ( ch->pnote->type != type ) {
			writeBuffer ( "You aren't working on that kind of note.\n\r", ch );
			return;
		}

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

	if ( !str_prefix ( arg, "post" ) || !str_prefix ( arg, "send" ) ) {
		char *strtime;

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

		if ( ch->pnote->type != type ) {
			writeBuffer ( "You aren't working on that kind of note.\n\r", ch );
			return;
		}

		if ( SameString ( ch->pnote->to_list, "" ) ) {
			writeBuffer (
				"You need to provide a recipient (name, all, or immortal).\n\r",
				ch );
			return;
		}

		if ( SameString ( ch->pnote->subject, "" ) ) {
			writeBuffer ( "You need to provide a subject.\n\r", ch );
			return;
		}

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

		append_note ( ch->pnote );
		ch->pnote = NULL;
		return;
	}

	writeBuffer ( "You can't do that.\n\r", ch );
	return;
}