From: Pasi Kallinen Date: Mon, 4 Jan 2016 17:52:34 +0000 (+0200) Subject: Add SIMPLE_MAIL compile-time option for public servers X-Git-Tag: NetHack-3.6.1_RC01~1072 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=89e4d5e9faa5aa420631185d019293592897d727;p=nethack Add SIMPLE_MAIL compile-time option for public servers --- diff --git a/include/unixconf.h b/include/unixconf.h index bc6984eec..751895ba9 100644 --- a/include/unixconf.h +++ b/include/unixconf.h @@ -191,7 +191,16 @@ #endif #endif +/* If SIMPLE_MAIL is defined, the mail spool file format is + "sender:message", one mail per line, and mails are + read within game, from demon-delivered mail scrolls */ +/* #define SIMPLE_MAIL */ + +#ifndef MAILCKFREQ +/* How often mail spool file is checked for new messages, in turns */ #define MAILCKFREQ 50 +#endif + #endif /* MAIL */ /* diff --git a/src/mail.c b/src/mail.c index fb9c07c50..ec31393a4 100644 --- a/src/mail.c +++ b/src/mail.c @@ -5,6 +5,10 @@ #include "hack.h" #ifdef MAIL +#ifdef SIMPLE_MAIL +# include +# include +#endif /* SIMPLE_MAIL */ #include "mail.h" /* @@ -498,6 +502,64 @@ ckmailstatus() } } +#ifdef SIMPLE_MAIL +void +read_simplemail() +{ + FILE* mb = fopen(mailbox, "r"); + char curline[102], *msg; + boolean seen_one_already = FALSE; + struct flock fl = { 0 }; + + fl.l_type = F_RDLCK; + fl.l_whence = SEEK_SET; + fl.l_start = 0; + fl.l_len = 0; + + if (!mb) + goto bail; + + /* Allow this call to block. */ + if (fcntl (fileno (mb), F_SETLKW, &fl) == -1) + goto bail; + + errno = 0; + while (fgets(curline, 102, mb) != NULL) { + fl.l_type = F_UNLCK; + fcntl (fileno(mb), F_UNLCK, &fl); + + pline("There is a%s message on this scroll.", + seen_one_already ? "nother" : ""); + + msg = strchr(curline, ':'); + + if (!msg) + goto bail; + + *msg = '\0'; + msg++; + + pline("This message is from '%s'.", curline); + + msg[strlen(msg) - 1] = '\0'; /* kill newline */ + pline ("It reads: \"%s\".", msg); + + seen_one_already = TRUE; + errno = 0; + + fl.l_type = F_RDLCK; + fcntl(fileno(mb), F_SETLKW, &fl); + } + + fl.l_type = F_UNLCK; + fcntl(fileno(mb), F_UNLCK, &fl); + fclose(mb); + unlink(mailbox); +bail: + pline("It appears to be all gibberish."); /* bail out _professionally_ */ +} +#endif /* SIMPLE_MAIL */ + /*ARGSUSED*/ void readmail(otmp) @@ -505,7 +567,12 @@ struct obj *otmp UNUSED; { #ifdef DEF_MAILREADER /* This implies that UNIX is defined */ register const char *mr = 0; - +#endif /* DEF_MAILREADER */ +#ifdef SIMPLE_MAIL + read_simplemail(); + return; +#endif /* SIMPLE_MAIL */ +#ifdef DEF_MAILREADER /* This implies that UNIX is defined */ display_nhwindow(WIN_MESSAGE, FALSE); if (!(mr = nh_getenv("MAILREADER"))) mr = DEF_MAILREADER;