/* states for new note system, to be inserted in nanny() =========================================================================== This snippet was written by Erwin S. Andreasen, 4u2@aabc.dk. You may use this code freely, as long as you retain my name in all of the files. You also have to mail me telling that you are using it. I am giving this, hopefully useful, piece of source code to you for free, and all I require from you is some feedback. Please mail me if you find any bugs or have any new ideas or just comments. All my snippets are publically available at: http://login.dknet.dk/~ea/ If you do not have WWW access, try ftp'ing to login.dknet.dk and examine the /pub/ea directory. =========================================================================== */ /* ch MUST be PC here; have nwrite check for PC status! */ /* This code is extra case's in nanny () */ case CON_NOTE_TO: if (!ch->pcdata->in_progress) { d->connected = CON_PLAYING; bug ("nanny: In CON_NOTE_TO, but no note in progress",0); break; } strcpy (buf, argument); smash_tilde (buf); /* change ~ to - as we save this field as a string later */ switch (ch->pcdata->board->force_type) { case DEF_NORMAL: /* default field */ if (!buf[0]) /* empty string? */ { ch->pcdata->in_progress->to_list = str_dup (ch->pcdata->board->names); sprintf (buf, "Assumed default recipient: &@%s&*\n\r", ch->pcdata->board->names); write_to_buffer (d, buf, 0); } else ch->pcdata->in_progress->to_list = str_dup (buf); break; case DEF_INCLUDE: /* forced default */ if (!is_name (ch->pcdata->board->names, buf)) { strcat (buf, " "); strcat (buf, ch->pcdata->board->names); ch->pcdata->in_progress->to_list = str_dup(buf); sprintf (buf, "\n\rYou did not specify %s as recipient, so it was automatically added.\n\r" "&@&yNew To&* : %s\n\r", ch->pcdata->board->names, ch->pcdata->in_progress->to_list); write_to_buffer (d, buf, 0); } else ch->pcdata->in_progress->to_list = str_dup (buf); break; case DEF_EXCLUDE: /* forced exclude */ if (is_name (ch->pcdata->board->names, buf)) { sprintf (buf, "You are not allowed to send notes to %s on this board. Try again.\n\r" "&y&@To&*: ", ch->pcdata->board->names); write_to_buffer (d, buf, 0); return; /* return from nanny, not changing to the next state! */ } else ch->pcdata->in_progress->to_list = str_dup (buf); break; } write_to_buffer (d, "\n\r&y&@Subject&*: ", 0); d->connected = CON_NOTE_SUBJECT; break; /* to */ case CON_NOTE_SUBJECT: if (!ch->pcdata->in_progress) { d->connected = CON_PLAYING; bug ("nanny: In CON_NOTE_SUBJECT, but no note in progress",0); break; } strcpy (buf, argument); smash_tilde (buf); /* change ~ to - as we save this field as a string later */ /* Do not allow empty subjects */ if (!buf[0]) { write_to_buffer (d, "Please find a meaningful subject!\n\r",0); write_to_buffer (d, "&y&@Subject&*: ", 0); } else if (strlen(buf)>60) { write_to_buffer (d, "No, no. This is just the Subject. You're note writing the note yet. Twit.\n\r",0); } else /* advance to next stage */ { ch->pcdata->in_progress->subject = str_dup(buf); if (IS_IMMORTAL(ch)) /* immortals get to choose number of expire days */ { sprintf (buf,"\n\rHow many days do you want this note to expire in?\n\r" "Press Enter for default value for this board, &@%d&* days.\n\r" "&@&yExpire&*: ", ch->pcdata->board->purge_days); write_to_buffer (d, buf, 0); d->connected = CON_NOTE_EXPIRE; } else { write_to_buffer (d, "\n\rEnter text. Type &@~&* or &@END&* on an empty line to end note.\n\r" "=======================================================\n\r",0); d->connected = CON_NOTE_TEXT; } } break; /* subject */ case CON_NOTE_EXPIRE: { time_t expire; int days; if (!ch->pcdata->in_progress) { d->connected = CON_PLAYING; bug ("nanny: In CON_NOTE_EXPIRE, but no note in progress",0); break; } /* Numeric argument. no tilde smashing */ strcpy (buf, argument); if (!buf[0]) /* assume default expire */ days = ch->pcdata->board->purge_days; else /* use this expire */ if (!is_number(buf)) { write_to_buffer (d,"Write the number of days!\n\r",0); write_to_buffer (d,"&@&yExpire&*: ",0); return; } else { days = atoi (buf); if (days <= 0) { write_to_buffer (d, "This is a positive MUD. Use positive numbers only! :)\n\r",0); write_to_buffer (d,"&@&yExpire&*: ",0); return; } } expire = current_time + (days*24L*3600L); /* 24 hours, 3600 seconds */ ch->pcdata->in_progress->expire = expire; /* note that ctime returnx XXX\n so we only need to add an \r */ sprintf (buf, "This note will expire %s\r",ctime(&expire)); write_to_buffer (d,buf,0); write_to_buffer (d, "\n\rEnter text. Type &@~&* or &@END&* on an empty line to end note.\n\r" "=======================================================\n\r",0); d->connected = CON_NOTE_TEXT; break; } /* expire */ case CON_NOTE_TEXT: { char letter[MAX_STRING_LENGTH]; if (!ch->pcdata->in_progress) { d->connected = CON_PLAYING; bug ("nanny: In CON_NOTE_TEXT, but no note in progress",0); break; } /* First, check for EndOfNote marker */ strcpy (buf, argument); if ((!str_cmp(buf, "~")) || (!str_cmp(buf, "END"))) { write_to_buffer (d, "\n\r(&@C&*)ontinue, (&@V&*)iew, (&@P&*)ost or (&@F&*)orget it?\n\r",0); d->connected = CON_NOTE_FINISH; return; } smash_tilde (buf); /* smash it now */ /* Check for too long lines. Do not allow lines longer than 75 chars */ if (strlen (buf) > MAX_LINE_LENGTH) { write_to_buffer (d, "Too long line rejected. Do NOT go over 75 characters!\n\r",0); return; } /* Not end of note. Copy current text into temp buffer, add new line, and copy back */ /* How would the system react to strcpy( , NULL) ? */ if (ch->pcdata->in_progress->text) { strcpy (letter, ch->pcdata->in_progress->text); free_string (ch->pcdata->in_progress->text); ch->pcdata->in_progress->text = NULL; /* be sure we don't free it twice */ } else strcpy (letter, ""); /* Check for overflow */ if ((strlen(letter) + strlen (buf)) > MAX_NOTE_TEXT) { /* Note too long, take appropriate steps */ write_to_buffer (d, "Note too long. Autosplitting <TO BE IMPLEMENTED\n\r", 0); free_note (ch->pcdata->in_progress); d->connected = CON_PLAYING; return; } /* Add new line to the buffer */ strcat (letter, buf); strcat (letter, "\r\n"); /* new line. \r first to make note files better readable */ /* allocate dynamically */ ch->pcdata->in_progress->text = str_dup (letter); break; } /* con_note_text */ case CON_NOTE_FINISH: if (!ch->pcdata->in_progress) { d->connected = CON_PLAYING; bug ("nanny: In CON_NOTE_FINISH, but no note in progress",0); break; } switch (tolower(argument[0])) { case 'c': /* keep writing */ write_to_buffer (d,"Continuing note...\n\r",0); d->connected = CON_NOTE_TEXT; break; case 'v': /* view note so far */ if (ch->pcdata->in_progress->text) { write_to_buffer (d,"&gText of your note so far:&*\n\r",0); write_to_buffer (d, ch->pcdata->in_progress->text, 0); } else write_to_buffer (d,"You haven't written a thing!\n\r",0); write_to_buffer (d, "\n\r(&@C&*)ontinue, (&@V&*)iew, (&@P&*)ost or (&@F&*)orget it?\n\r",0); break; case 'p': /* post note */ finish_note (ch->pcdata->board, ch->pcdata->in_progress); write_to_buffer (d, "Note posted.\n\r",0); d->connected = CON_PLAYING; /* remove AFK status */ ch->pcdata->in_progress = NULL; break; case 'f': write_to_buffer (d, "Note cancelled!\n\r",0); free_note (ch->pcdata->in_progress); ch->pcdata->in_progress = NULL; d->connected = CON_PLAYING; /* remove afk status */ break; default: /* invalid response */ write_to_buffer (d, "Huh? Valid answers are:\n\r",0); write_to_buffer (d, "\n\r(&@C&*)ontinue, (&@V&*)iew, (&@P&*)ost or (&@F&*)orget it?\n\r",0); } break;