📄 act_comm.c
字号:
/***************************************************************************
* Original Diku Mud copyright (C) 1990, 1991 by Sebastian Hammer, *
* Michael Seifert, Hans Henrik St{rfeldt, Tom Madsen, and Katja Nyboe. *
* *
* Merc Diku Mud improvments copyright (C) 1992, 1993 by Michael *
* Chastain, Michael Quan, and Mitchell Tse. *
* *
* In order to use any part of this Merc Diku Mud, you must comply with *
* both the original Diku license in 'license.doc' as well the Merc *
* license in 'license.txt'. In particular, you may not remove either of *
* these copyright notices. *
* *
* Much time and thought has gone into this software and you are *
* benefitting. We hope that you share your changes too. What goes *
* around, comes around. *
***************************************************************************/
#if defined(macintosh)
#include <types.h>
#else
#include <sys/types.h>
#endif
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "merc.h"
/*
* Local functions.
*/
bool is_note_to args( ( CHAR_DATA *ch, NOTE_DATA *pnote ) );
void note_attach args( ( CHAR_DATA *ch ) );
void note_remove args( ( CHAR_DATA *ch, NOTE_DATA *pnote ) );
void talk_channel args( ( CHAR_DATA *ch, char *argument,
int channel, const char *verb ) );
void note_delete args( ( NOTE_DATA *pnote ) );
bool is_note_to( CHAR_DATA *ch, NOTE_DATA *pnote )
{
if ( !str_cmp( ch->name, pnote->sender ) )
return TRUE;
if ( is_name( "all", pnote->to_list ) )
return TRUE;
if ( IS_HERO(ch) && is_name( "immortal", pnote->to_list ) )
return TRUE;
if ( is_name( ch->name, pnote->to_list ) )
return TRUE;
return FALSE;
}
void note_attach( CHAR_DATA *ch )
{
NOTE_DATA *pnote;
if ( ch->pnote != NULL )
return;
if ( note_free == NULL )
{
pnote = alloc_perm( sizeof(*ch->pnote) );
}
else
{
pnote = note_free;
note_free = note_free->next;
}
pnote->next = NULL;
pnote->sender = str_dup( ch->name );
pnote->date = str_dup( "" );
pnote->to_list = str_dup( "" );
pnote->subject = str_dup( "" );
pnote->text = str_dup( "" );
ch->pnote = pnote;
return;
}
void note_remove( CHAR_DATA *ch, NOTE_DATA *pnote )
{
char to_new[MAX_INPUT_LENGTH];
char to_one[MAX_INPUT_LENGTH];
FILE *fp;
NOTE_DATA *prev;
char *to_list;
/*
* Build a new to_list.
* Strip out this recipient.
*/
to_new[0] = '\0';
to_list = pnote->to_list;
while ( *to_list != '\0' )
{
to_list = one_argument( to_list, to_one );
if ( to_one[0] != '\0' && str_cmp( ch->name, to_one ) )
{
strcat( to_new, " " );
strcat( to_new, to_one );
}
}
/*
* Just a simple recipient removal?
*/
if ( str_cmp( ch->name, pnote->sender ) && to_new[0] != '\0' )
{
free_string( pnote->to_list );
pnote->to_list = str_dup( to_new + 1 );
return;
}
/*
* Remove note from linked list.
*/
if ( pnote == note_list )
{
note_list = pnote->next;
}
else
{
for ( prev = note_list; prev != NULL; prev = prev->next )
{
if ( prev->next == pnote )
break;
}
if ( prev == NULL )
{
bug( "Note_remove: pnote not found.", 0 );
return;
}
prev->next = pnote->next;
}
free_string( pnote->text );
free_string( pnote->subject );
free_string( pnote->to_list );
free_string( pnote->date );
free_string( pnote->sender );
pnote->next = note_free;
note_free = pnote;
/*
* Rewrite entire list.
*/
fclose( fpReserve );
if ( ( fp = fopen( NOTE_FILE, "w" ) ) == NULL )
{
perror( NOTE_FILE );
}
else
{
for ( pnote = note_list; pnote != NULL; pnote = pnote->next )
{
fprintf( fp, "Sender %s~\n", pnote->sender );
fprintf( fp, "Date %s~\n", pnote->date );
fprintf( fp, "Stamp %ld\n", pnote->date_stamp );
// fprintf( fp, "Stamp %d\n", pnote->date_stamp );
fprintf( fp, "To %s~\n", pnote->to_list );
fprintf( fp, "Subject %s~\n", pnote->subject );
fprintf( fp, "Text\n%s~\n\n", pnote->text );
}
fclose( fp );
}
fpReserve = fopen( NULL_FILE, "r" );
return;
}
/* Date stamp idea comes from Alander of ROM */
void do_note( CHAR_DATA *ch, char *argument )
{
char buf[MAX_STRING_LENGTH];
char buf1[MAX_STRING_LENGTH];
char arg[MAX_INPUT_LENGTH];
NOTE_DATA *pnote;
int vnum;
int anum;
if ( IS_NPC(ch) )
return;
buf1[0] = '\0';
argument = one_argument( argument, arg );
smash_tilde( argument );
if ( arg[0] == '\0' )
{
do_note( ch, "read" );
return;
}
if ( !str_cmp( arg, "list" ) )
{
vnum = 0;
for ( pnote = note_list; pnote != NULL; pnote = pnote->next )
{
if ( is_note_to( ch, pnote ) )
{
sprintf( buf, "[%3d%s] %s: %s\n\r",
vnum,
(pnote->date_stamp > ch->last_note
&& str_cmp( pnote->sender, ch->name ) ) ? "N" : " ",
pnote->sender, pnote->subject );
strcat( buf1, buf );
vnum++;
}
}
send_to_char( buf1, ch );
return;
}
if ( !str_cmp( 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;
for ( pnote = note_list; pnote != NULL; pnote = pnote->next )
{
if ( is_note_to( ch, pnote )
&& str_cmp( ch->name, pnote->sender )
&& ch->last_note < pnote->date_stamp )
{
sprintf( buf, "[%3d] %s: %s\n\r%s\n\rTo: %s\n\r",
vnum,
pnote->sender,
pnote->subject,
pnote->date,
pnote->to_list );
strcat( buf1, buf );
strcat( buf1, pnote->text );
ch->last_note = UMAX( ch->last_note, pnote->date_stamp );
send_to_char( buf1, ch );
return;
}
else
vnum++;
}
send_to_char( "You have no unread notes.\n\r", ch );
return;
}
else if ( is_number( argument ) )
{
fAll = FALSE;
anum = atoi( argument );
}
else
{
send_to_char( "Note read which number?\n\r", ch );
return;
}
vnum = 0;
for ( pnote = note_list; pnote != NULL; pnote = pnote->next )
{
if ( is_note_to( ch, pnote ) && ( vnum++ == anum || fAll ) )
{
sprintf( buf, "[%3d] %s: %s\n\r%s\n\rTo: %s\n\r",
vnum - 1,
pnote->sender,
pnote->subject,
pnote->date,
pnote->to_list
);
strcat( buf1, buf );
strcat( buf1, pnote->text );
send_to_char( buf1, ch );
ch->last_note = UMAX( ch->last_note, pnote->date_stamp );
return;
}
}
send_to_char( "No such note.\n\r", ch );
return;
}
if ( !str_cmp( arg, "+" ) )
{
note_attach( ch );
strcpy( buf, ch->pnote->text );
if ( strlen(buf) + strlen(argument) >= MAX_STRING_LENGTH - 200 )
{
send_to_char( "Note too long.\n\r", ch );
return;
}
strcat( buf, argument );
strcat( buf, "\n\r" );
free_string( ch->pnote->text );
ch->pnote->text = str_dup( buf );
send_to_char( "Ok.\n\r", ch );
return;
}
if ( !str_cmp( arg, "subject" ) )
{
note_attach( ch );
free_string( ch->pnote->subject );
ch->pnote->subject = str_dup( argument );
send_to_char( "Ok.\n\r", ch );
return;
}
if ( !str_cmp( arg, "to" ) )
{
note_attach( ch );
free_string( ch->pnote->to_list );
ch->pnote->to_list = str_dup( argument );
send_to_char( "Ok.\n\r", ch );
return;
}
if ( !str_cmp( arg, "clear" ) )
{
if ( ch->pnote != NULL )
{
free_string( ch->pnote->text );
free_string( ch->pnote->subject );
free_string( ch->pnote->to_list );
free_string( ch->pnote->date );
free_string( ch->pnote->sender );
ch->pnote->next = note_free;
note_free = ch->pnote;
ch->pnote = NULL;
}
send_to_char( "Ok.\n\r", ch );
return;
}
if ( !str_cmp( arg, "show" ) )
{
if ( ch->pnote == NULL )
{
send_to_char( "You have no note in progress.\n\r", ch );
return;
}
sprintf( buf, "%s: %s\n\rTo: %s\n\r",
ch->pnote->sender,
ch->pnote->subject,
ch->pnote->to_list
);
send_to_char( buf, ch );
send_to_char( ch->pnote->text, ch );
return;
}
if ( !str_cmp( arg, "post" ) || !str_prefix( arg, "send" ) )
{
FILE *fp;
char *strtime;
if ( ch->pnote == NULL )
{
send_to_char( "You have no note in progress.\n\r", ch );
return;
}
if ( !str_cmp( ch->pnote->to_list, "" ) )
{
send_to_char(
"You need to provide a recipient (name, all, or immortal).\n\r",
ch );
return;
}
if ( !str_cmp( ch->pnote->subject, "" ) )
{
send_to_char( "You need to provide a subject.\n\r", ch );
return;
}
ch->pnote->next = NULL;
strtime = ctime( ¤t_time );
strtime[strlen(strtime)-1] = '\0';
ch->pnote->date = str_dup( strtime );
ch->pnote->date_stamp = current_time;
if ( note_list == NULL )
{
note_list = ch->pnote;
}
else
{
for ( pnote = note_list; pnote->next != NULL; pnote = pnote->next )
;
pnote->next = ch->pnote;
}
pnote = ch->pnote;
ch->pnote = NULL;
fclose( fpReserve );
if ( ( fp = fopen( NOTE_FILE, "a" ) ) == NULL )
{
perror( NOTE_FILE );
}
else
{
fprintf( fp, "Sender %s~\n", pnote->sender );
fprintf( fp, "Date %s~\n", pnote->date );
fprintf( fp, "Stamp %ld\n", pnote->date_stamp );
// fprintf( fp, "Stamp %d\n", pnote->date_stamp );
fprintf( fp, "To %s~\n", pnote->to_list );
fprintf( fp, "Subject %s~\n", pnote->subject );
fprintf( fp, "Text\n%s~\n\n", pnote->text );
fclose( fp );
}
fpReserve = fopen( NULL_FILE, "r" );
send_to_char( "Ok.\n\r", ch );
return;
}
if ( !str_cmp( arg, "remove" ) )
{
if ( !is_number( argument ) )
{
send_to_char( "Note remove which number?\n\r", ch );
return;
}
anum = atoi( argument );
vnum = 0;
for ( pnote = note_list; pnote != NULL; pnote = pnote->next )
{
if ( is_note_to( ch, pnote ) && vnum++ == anum )
{
note_remove( ch, pnote );
send_to_char( "Ok.\n\r", ch );
return;
}
}
send_to_char( "No such note.\n\r", ch );
return;
}
send_to_char( "Huh? Type 'help note' for usage.\n\r", ch );
return;
}
/*
* Generic channel function.
*/
void talk_channel( CHAR_DATA *ch, char *argument, int channel, const char *verb )
{
char buf[MAX_STRING_LENGTH];
DESCRIPTOR_DATA *d;
int position;
if ( argument[0] == '\0' )
{
sprintf( buf, "%s what?\n\r", verb );
buf[0] = UPPER(buf[0]);
return;
}
if ( !IS_NPC(ch) && IS_SET(ch->act, PLR_SILENCE) )
{
sprintf( buf, "You can't %s.\n\r", verb );
send_to_char( buf, ch );
return;
}
REMOVE_BIT(ch->deaf, channel);
switch ( channel )
{
default:
sprintf( buf, "You %s '%s'.\n\r", verb, argument );
send_to_char( buf, ch );
sprintf( buf, "$n %ss '$t'.", verb );
break;
case CHANNEL_IMMTALK:
sprintf( buf, "$n: $t." );
position = ch->position;
ch->position = POS_STANDING;
act( buf, ch, argument, NULL, TO_CHAR );
ch->position = position;
break;
}
for ( d = descriptor_list; d != NULL; d = d->next )
{
CHAR_DATA *och;
CHAR_DATA *vch;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -