/* ************************************************************************ * Message in Who list Part of NirvanaMUD * * Usage: message [remove] * * * * If you want to put a message in your who... here is the code!!! * * + = add this line. * * * * Rodrigo Jose Affonso Magalhaes * * Rio de Janeiro - Brazil * * nirvanamud@hotmail.com * * UIN 24161456 * * * * NirvanaMUD: mud.nlink.com.br 4000 * ************************************************************************ */ file act.informative.c in do_who: #define WHO_FORMAT \ "format: who [minlev[-maxlev]] [-n name] [-c classlist] [-s] [-o] [-q] [-r] [-z]\r\n" ACMD(do_who) { extern struct message_data mess_info; struct descriptor_data *d; struct char_data *tch; char name_search[MAX_INPUT_LENGTH]; + char mess_buf[MAX_STRING_LENGTH]; char mode; size_t i; int low = 0, high = LVL_IMPL, localwho = 0, questwho = 0; int showclass = 0, short_list = 0, outlaws = 0, num_can_see = 0; int who_room = 0; skip_spaces(&argument); strcpy(buf, argument); name_search[0] = '\0'; + *mess_buf = '\0'; while (*buf) { half_chop(buf, arg, buf1); if (isdigit(*arg)) { sscanf(arg, "%d-%d", &low, &high); strcpy(buf, buf1); at the end of do_who: if (short_list && (num_can_see % 4)) send_to_char("\r\n", ch); if (num_can_see == 0) sprintf(buf, "\r\nNo-one at all!\r\n"); else if (num_can_see == 1) sprintf(buf, "\r\nOne lonely character displayed.\r\n"); else sprintf(buf, "\r\n%d characters displayed.\r\n", num_can_see); + if (*mess_info.message && *mess_info.writer && mess_info.time) { + sprintf(mess_buf, "\r\n%sMessage from %s, written on %-20s", + mess_info.message, mess_info.writer, ctime(&mess_info.time)); + strcat(buf, mess_buf); + } send_to_char(buf, ch); } #define USERS_FORMAT \ file act.other.c at the end of file: +ACMD(do_message) { + extern struct message_data mess_info; + extern void write_message_to_file(); + + skip_spaces(&argument); + delete_doubledollar(argument); + + if (IS_NPC(ch)) + send_to_char("The message of the day is fine... go away.\r\n", ch); + else if ((PLR_FLAGGED(ch, PLR_NOTITLE)) || (PLR_FLAGGED(ch, PLR_NOSHOUT))) + send_to_char("You can't post a message -- you shouldn't have abused it!\r\n", ch); + /* Feel free to change the level.*/ + else if (GET_LEVEL(ch) < 20) + send_to_char("You can't change the message yet. Sit here and wait a while.\r\n",ch); + else if (!str_cmp(argument, "remove")) { + mess_info.writer[0] = '\0'; /* ROD WAS HERE!!! 09/04/1999 */ + mess_info.message[0] = '\0'; + mess_info.time = 0; + write_message_to_file(); + send_to_char("Message removed.\r\n",ch); + } + else { + SET_BIT(PLR_FLAGS(ch), PLR_MESSAGING | PLR_WRITING); + send_to_char("Write your message. End with '@' on a new line.\r\n" + "If you want to remove the message just type: message remove.\r\n", ch); + act("$n begins to jot down a message.", TRUE, ch, 0, 0, TO_ROOM); + ch->desc->str = (char **) malloc(sizeof(char *)); + *(ch->desc->str) = NULL; + ch->desc->max_str = MAX_WMOTD_LENGTH; + } +}; + file constants.c look for this: /* PLR_x */ const char *player_bits[] = { "KILLER", "THIEF", "FROZEN", "DONTSET", "WRITING", "MAILING", "CSH", "SITEOK", "NOSHOUT", "NOTITLE", "DELETED", "LOADRM", "!WIZL", "!DEL", "INVST", "CRYO", + "MESSAGING", "\n" }; file db.h look for this: struct char_data* create_char(void); struct char_data *read_mobile(int nr, int type); int real_mobile(int virtual); int vnum_mobile(char *searchname, struct char_data *ch); void clear_char(struct char_data *ch); void reset_char(struct char_data *ch); void free_char(struct char_data *ch); +void read_message_from_file(void); +void write_message_to_file(void); file db.c look for this: struct time_info_data time_info;/* the infomation about the time */ struct weather_data weather_info; /* the infomation about the weather */ struct player_special_data dummy_mob; /* dummy spec area for mobs */ struct reset_q_type reset_q; /* queue of zones to be reset */ +struct message_data mess_info; /* the information about the message */ look for this: if (!mini_mud) { log("Booting houses."); House_boot(); } boot_time = time(0); log("Boot db -- DONE."); } +void write_message_to_file(void) +{ + FILE *message_file; + extern struct message_data mess_info; + struct message_data write_message; + + message_file = fopen("etc/who.motd", "w"); + if(!message_file) { + log("SYSERR: Failed to open file etc/who.motd in write_message_to_file."); + return; + } + if (mess_info.writer) + strcpy(write_message.writer, mess_info.writer); + else { + write_message.writer[0] = '\0'; + write_message.message[0] = '\0'; + mess_info.time = 0; + } + if (mess_info.message) + strcpy(write_message.message, mess_info.message); + else { + write_message.writer[0] = '\0'; + write_message.message[0] = '\0'; + mess_info.time = 0; + } + if (mess_info.time) + write_message.time = mess_info.time; + else { + write_message.writer[0] = '\0'; + write_message.message[0] = '\0'; + mess_info.time = 0; + } + fwrite(&write_message, sizeof(struct message_data), 1, message_file); + fclose(message_file); +} + +void read_message_from_file(void) +{ + extern struct message_data mess_info; + FILE *message_file; + struct message_data read_message; + + message_file = fopen("etc/who.motd", "r"); + if(!message_file) { + log("SYSERR: Failed to open file etc/who.motd in read_message_from_file."); + return; + } + fread(&read_message, sizeof(struct message_data), 1, message_file); + strcpy(mess_info.writer, read_message.writer); + strcpy(mess_info.message, read_message.message); + mess_info.time = read_message.time; + fclose(message_file); +} + in void boot_db(void) look for this: log("Loading help entries."); index_boot(DB_BOOT_HLP); log("Generating player index."); build_player_index(); log("Loading fight messages."); load_messages(); log("Loading social messages."); boot_social_messages(); + log("Loading message of the day for who list."); + read_message_from_file(); + log("Assigning function pointers:"); file interpreter.c look for this: ACMD(do_leave); ACMD(do_levels); ACMD(do_load); ACMD(do_look); +ACMD(do_message); ACMD(do_move); ACMD(do_not_here); ACMD(do_offer); look for this: { "load" , POS_DEAD , do_load , LVL_GOD, 0 }, { "love" , POS_RESTING , do_action , 0, 0 }, + { "message" , POS_DEAD , do_message , 0, 0 }, { "moan" , POS_RESTING , do_action , 0, 0 }, { "motd" , POS_DEAD , do_gen_ps , 0, SCMD_MOTD }, file modify.c in void string_add(struct descriptor_data *d, char *str) look for this: void string_add(struct descriptor_data *d, char *str) { int terminator = 0; extern char *MENU; + extern struct message_data mess_info; + extern void write_message_to_file(void); /* determine if this is the terminal string, and truncate if so */ /* changed to only accept '@' at the beginning of line - J. Elson 1/17/94 */ and this: if (terminator) { if (!d->connected && (PLR_FLAGGED(d->character, PLR_MAILING))) { store_mail(d->mail_to, GET_IDNUM(d->character), *d->str); d->mail_to = 0; free(*d->str); free(d->str); SEND_TO_Q("Message sent!\r\n", d); if (!IS_NPC(d->character)) REMOVE_BIT(PLR_FLAGS(d->character), PLR_MAILING | PLR_WRITING); } + + if (!d->connected && (PLR_FLAGGED(d->character, PLR_MESSAGING))) { + strcpy(mess_info.writer, GET_NAME(d->character)); + strcpy(mess_info.message, *d->str); + mess_info.time = time(0); + write_message_to_file(); + d->mail_to = 0; + free(*d->str); + free(d->str); + SEND_TO_Q("Message posted!\r\n", d); + if (!IS_NPC(d->character)) + REMOVE_BIT(PLR_FLAGS(d->character), PLR_MESSAGING | PLR_WRITING); + } + d->str = NULL; if (d->mail_to >= BOARD_MAGIC) { file structs.h look for this: #define PLR_NOWIZLIST (1 << 12) /* Player shouldn't be on wizlist */ #define PLR_NODELETE (1 << 13) /* Player shouldn't be deleted */ #define PLR_INVSTART (1 << 14) /* Player should enter game wizinvis */ #define PLR_CRYO (1 << 15) /* Player is cryo-saved (purge prog) */ +#define PLR_MESSAGING (1 << 16) /* Player is writing the message of day */ look for this: #define MAX_STRING_LENGTH 8192 #define MAX_INP