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

From: Peter Ajamian (
Date: 10/07/00

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

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
    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
  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
-                         int cmd, char *arg)
+ ACMD(do_mail)
- long recipient;
- char buf[256], **write;
+ char **write;

-   sprintf(buf, "$n tells you, 'Sorry, you have to be level %d to send
+   sprintf(buf, "Sorry, you have to be level %d to send mail!\r\n",
-   act(buf, FALSE, mailman, 0, ch, TO_VICT);
+   send_to_char(buf, ch);
- 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);
  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.'",
-   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);
- 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",
+     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
+ sprintf(buf, "That'll be %d coins for the stamp.\r\n"
+      "Write your message, use @ on a new line when done.\r\n",

- act(buf, FALSE, mailman, 0, ch, TO_VICT);
+ send_to_char(buf, ch);
  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,
+     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,
+           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;
+     }

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:  |
     |  |

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