Re: [CODE] Porting from other Mud code bases...

From: Peter Ajamian (peter@pajamian.dhs.org)
Date: 10/07/00


Please send your replies to the mailing list and do not email me in
person...

Thomas Burns wrote:
<Original post snipped to avoid bouncing from too many lines>

Note: the code I include here is mailer code, it may or may not work.

It looks like if you want the best of both worlds you would want to keep
CircleMUDs' editor while adding in the ability to send the same message
to multiple recipients.  It would also appear that you might want to
have the ability to send mail from anywhere, this is easy to do simply
by changing the postmaster_send_mail procedure to an ACMD(do_mail).

Simply allow multiple names to be specified on the command line as
follows...
    mail peter john terry graham
would send the mail to all of those recipients.

You'll need to store the recipients names in some
manner when composing the mudmail so that after the mudmail is complete
you can send it individually to all the names on the list, this is
relatively easy.  You simply add a variable to struct descriptor_data as
follows...
  char *mail_list; /* List of recipients for MudMail */

Then change postmaster_send_mail as follows...

- void postmaster_send_mail(struct char_data * ch, struct char_data
*mailman,
-                         int cmd, char *arg)
+ ACMD(do_mail)
{
- long recipient;
- char buf[256], **write;
+ char **write;

  if (GET_LEVEL(ch) < MIN_MAIL_LEVEL) {
-   sprintf(buf, "$n tells you, 'Sorry, you have to be level %d to send
mail!'",
+   sprintf(buf, "Sorry, you have to be level %d to send mail!\r\n",
            MIN_MAIL_LEVEL);
-   act(buf, FALSE, mailman, 0, ch, TO_VICT);
+   send_to_char(buf, ch);
    return;
  }
- one_argument(arg, buf);

- if (!*buf) {                  /* you'll get no argument from me! */
+ if (!*argument) {                  /* you'll get no argument from me!
*/
-   act("$n tells you, 'You need to specify an addressee!'",
-       FALSE, mailman, 0, ch, TO_VICT);
+   send_to_char("You need to specify an addressee!\r\n", ch);
    return;
  }
  if (GET_GOLD(ch) < STAMP_PRICE) {
-   sprintf(buf, "$n tells you, 'A stamp costs %d coins.'\r\n"
-           "$n tells you, '...which I see you can't afford.'",
STAMP_PRICE);
-   act(buf, FALSE, mailman, 0, ch, TO_VICT);
+   sprintf(buf, "A stamp costs %d coins.\r\n"
+           "...which I see you can't afford.\r\n", STAMP_PRICE);
+   send_to_char(buf, ch);
    return;
  }
- if ((recipient = get_id_by_name(buf)) < 0) {
-   act("$n tells you, 'No one by that name is registered here!'",
-       FALSE, mailman, 0, ch, TO_VICT);
-   return;
+ ch->desc->mail_list = str_dup(argument);
+ for (nameptr = strtok(argument, " "); nameptr; nameptr = strtok(NULL,
" ") {
+   if (get_id_by_name(nameptr) < 0) {
+     sprintf(buf, "No one by the name %s is registered here!\r\n",
nameptr);
+     return;
+   }
  }
  act("$n starts to write some mail.", TRUE, ch, 0, 0, TO_ROOM);
- sprintf(buf, "$n tells you, 'I'll take %d coins for the stamp.'\r\n"
-      "$n tells you, 'Write your message, use @ on a new line when
done.'",
+ sprintf(buf, "That'll be %d coins for the stamp.\r\n"
+      "Write your message, use @ on a new line when done.\r\n",
          STAMP_PRICE);

- act(buf, FALSE, mailman, 0, ch, TO_VICT);
+ send_to_char(buf, ch);
  GET_GOLD(ch) -= STAMP_PRICE;
  SET_BIT(PLR_FLAGS(ch), PLR_MAILING);  /* string_write() sets writing.
*/

  /* Start writing! */
  CREATE(write, char *, 1);
- string_write(ch->desc, write, MAX_MAIL_SIZE, recipient, NULL);
+ string_write(ch->desc, write, MAX_MAIL_SIZE, 0, NULL);
}

Then you'll need to parse the line again when the message is finished
and send a copy of the mail to each recipient...

/* Add user input to the 'current' string (as defined by d->str) */
void string_add(struct descriptor_data *d, char *str)
{
  int terminator;
+ char *name_ptr;
+ long id;

  /* determine if this is the terminal string, and truncate if so */

  /* ... */

  if (terminator) {
    if (STATE(d) == CON_PLAYING && (PLR_FLAGGED(d->character,
PLR_MAILING))) {
+     if (d->mail_to) {
      store_mail(d->mail_to, GET_IDNUM(d->character), *d->str);
      d->mail_to = 0;
+     } else {
+       for (name_ptr = strtok(d->mail_list, " "); name_ptr; name_ptr =
strtok(NULL, " ")) {
+         if (STATE(d) == CON_PLAYING && (PLR_FLAGGED(d->character,
PLR_MAILING))) {
+           if ((idnum = get_id_by_name(name_ptr)) < 0)
+             mudlog(blah blah (invalid name, should be valid because we
already checked it before));
+           else
+             store_mail(idnum, GET_IDNUM(d->character), *d->str);
+         }
+         free(d->mail_list);
+         d->mail_list = NULL;
+     }
      free(*d->str);
      free(d->str);

And of course, don't forget to change the listing in interpreter.c and
remove all references to the old postmaster_send_mail function.

Regards, Peter


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     |  http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html  |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 04/10/01 PDT