]> git.pond.sub.org Git - empserver/blobdiff - src/lib/subs/wu.c
Indented with src/scripts/indent-emp.
[empserver] / src / lib / subs / wu.c
index 6f516db2e4bf3daaddfd61f0c3423d94f72ffe36..18b5d3255f7716d7eb44e67b8866362aa9575685 100644 (file)
 #include "player.h"
 #include "prototypes.h"
 
-static struct  telstr last_tel[MAXNOC];
+static struct telstr last_tel[MAXNOC];
 
 void
 clear_telegram_is_new(natid to)
 {
-       last_tel[to].tel_type = 0;
-       last_tel[to].tel_from = 0;
-       last_tel[to].tel_date = 0;
+    last_tel[to].tel_type = 0;
+    last_tel[to].tel_from = 0;
+    last_tel[to].tel_date = 0;
 }
 
 /*
@@ -60,135 +60,131 @@ clear_telegram_is_new(natid to)
  */
 
 static int
-telegram_is_new (natid to, struct telstr *tel)
+telegram_is_new(natid to, struct telstr *tel)
 {
-       extern  int     update_pending;
-       int is_new = 0;
+    extern int update_pending;
+    int is_new = 0;
 
-       is_new |= tel->tel_type != last_tel[to].tel_type;
-       is_new |= tel->tel_from != last_tel[to].tel_from;
-       is_new |= !update_pending && /* sometimes updates take a long time */
-                 abs (tel->tel_date - last_tel[to].tel_date) > TEL_SECONDS;
-       
-       last_tel[to].tel_type = tel->tel_type;
-       last_tel[to].tel_from = tel->tel_from;
-       last_tel[to].tel_date = tel->tel_date;
+    is_new |= tel->tel_type != last_tel[to].tel_type;
+    is_new |= tel->tel_from != last_tel[to].tel_from;
+    is_new |= !update_pending &&       /* sometimes updates take a long time */
+       abs(tel->tel_date - last_tel[to].tel_date) > TEL_SECONDS;
 
-       return is_new;
+    last_tel[to].tel_type = tel->tel_type;
+    last_tel[to].tel_from = tel->tel_from;
+    last_tel[to].tel_date = tel->tel_date;
+
+    return is_new;
 }
 
 /*VARARGS*/
 int
 wu(natid from, natid to, s_char *format, ...)
 {
-       struct natstr *np;
-       va_list ap;
-       s_char  buf[4096];
-       extern  int     update_pending;
-
-       va_start(ap, format);
-       (void) vsprintf(buf, format, ap);
-       va_end(ap);
-       np = getnatp(from);
-       if (update_pending)
-               return typed_wu(from, to, buf, TEL_UPDATE);
-       else if (np->nat_stat & STAT_GOD)
-               return typed_wu(from, to, buf, TEL_BULLETIN);
-       else
-               return typed_wu(from, to, buf, TEL_NORM);
+    struct natstr *np;
+    va_list ap;
+    s_char buf[4096];
+    extern int update_pending;
+
+    va_start(ap, format);
+    (void)vsprintf(buf, format, ap);
+    va_end(ap);
+    np = getnatp(from);
+    if (update_pending)
+       return typed_wu(from, to, buf, TEL_UPDATE);
+    else if (np->nat_stat & STAT_GOD)
+       return typed_wu(from, to, buf, TEL_BULLETIN);
+    else
+       return typed_wu(from, to, buf, TEL_NORM);
 }
 
 int
 typed_wu(natid from, natid to, s_char *message, int type)
 {
-       register s_char *bp;
-       int     len;
-       struct  telstr tel;
-       struct  natstr *np;
+    register s_char *bp;
+    int len;
+    struct telstr tel;
+    struct natstr *np;
 #if !defined(_WIN32)
-       struct  iovec iov[2];
+    struct iovec iov[2];
 #endif
-       int     fd;
-       s_char  box[1024];
-       int     notify = 0;
-       int     new_tele = 0;
-       struct player *other;
-
-       if (type == TEL_ANNOUNCE)
-               strcpy(box, annfil);
-       else
-               mailbox(box, to);
-
-       if (type != TEL_ANNOUNCE)
-               if ((np = getnatp(to)) == 0 ||
-                   ((np->nat_stat & STAT_NORM) == 0 &&
-                    (np->nat_stat & STAT_SANCT) == 0)) {
-                       return -1;
-               }
-
+    int fd;
+    s_char box[1024];
+    int notify = 0;
+    int new_tele = 0;
+    struct player *other;
+
+    if (type == TEL_ANNOUNCE)
+       strcpy(box, annfil);
+    else
+       mailbox(box, to);
+
+    if (type != TEL_ANNOUNCE)
+       if ((np = getnatp(to)) == 0 ||
+           ((np->nat_stat & STAT_NORM) == 0 &&
+            (np->nat_stat & STAT_SANCT) == 0)) {
+           return -1;
+       }
 #if !defined(_WIN32)
-       if ((fd = open(box, O_WRONLY|O_APPEND, 0)) < 0) {
+    if ((fd = open(box, O_WRONLY | O_APPEND, 0)) < 0) {
 #else
-       if ((fd = open(box, O_WRONLY|O_APPEND|O_BINARY, 0)) < 0) {
+    if ((fd = open(box, O_WRONLY | O_APPEND | O_BINARY, 0)) < 0) {
 #endif
-               logerror("telegram 'open' of %s (#%d) failed", box, to);
-               return -1;
-       }
-       tel.tel_from = from;
-       (void) time(&tel.tel_date);
-       bp = message;
-       while (*bp++)
-               ;
-       len = bp - message;
-       if (len >= MAXTELSIZE)
-               len = (MAXTELSIZE - 1);
-       message[len] = 0;
-       tel.tel_length = len;
-       tel.tel_type = type;
+       logerror("telegram 'open' of %s (#%d) failed", box, to);
+       return -1;
+    }
+    tel.tel_from = from;
+    (void)time(&tel.tel_date);
+    bp = message;
+    while (*bp++) ;
+    len = bp - message;
+    if (len >= MAXTELSIZE)
+       len = (MAXTELSIZE - 1);
+    message[len] = 0;
+    tel.tel_length = len;
+    tel.tel_type = type;
 #if !defined(_WIN32)
-       iov[0].iov_base = (caddr_t) &tel;
-       iov[0].iov_len = sizeof(tel);
-       iov[1].iov_base = message;
-       iov[1].iov_len = len;
-       if (writev(fd, iov, 2) < (int)(iov[0].iov_len + iov[1].iov_len)) {
+    iov[0].iov_base = (caddr_t)&tel;
+    iov[0].iov_len = sizeof(tel);
+    iov[1].iov_base = message;
+    iov[1].iov_len = len;
+    if (writev(fd, iov, 2) < (int)(iov[0].iov_len + iov[1].iov_len)) {
 #else
     if ((write(fd, &tel, sizeof(tel)) != sizeof(tel)) ||
-            (write(fd, message, len) != len)) {
+       (write(fd, message, len) != len)) {
 #endif
-               logerror("telegram 'write' to #%d failed", to);
-       } else if (type == TEL_ANNOUNCE) {
-               for (to=0; NULL != (np = getnatp(to)); to++) {
-                       if (!(np->nat_stat & STAT_NORM) &&
-                           !(np->nat_stat & STAT_SANCT))
-                               continue;
-                       if (!player->god && (getrejects(from,np) & REJ_ANNO))
-                               continue;
-                       notify = (np->nat_ann == 0);
-                       np->nat_ann++;
-                       putnat(np);
-                       if (notify)
-                               player_wakeup_all(to);                  
-               }
-       } else {
-               notify = (np->nat_tgms == 0);
-               new_tele = telegram_is_new(to, &tel);
-               np->nat_tgms += new_tele || notify;
-               putnat(np);
-
-               if (new_tele && np->nat_flags & NF_INFORM) {
-                       if (NULL != (other = getplayer(to))) {
-                               if (np->nat_tgms == 1)
-                                       pr_inform(other, "[new tele]\n");
-                               else
-                                       pr_inform(other, "[%d new teles]\n",
-                                                 np->nat_tgms);
-                               player_wakeup_all(to);
-                       }
-               } else if (notify)
-                       player_wakeup_all(to);
+       logerror("telegram 'write' to #%d failed", to);
+    } else if (type == TEL_ANNOUNCE) {
+       for (to = 0; NULL != (np = getnatp(to)); to++) {
+           if (!(np->nat_stat & STAT_NORM) &&
+               !(np->nat_stat & STAT_SANCT))
+               continue;
+           if (!player->god && (getrejects(from, np) & REJ_ANNO))
+               continue;
+           notify = (np->nat_ann == 0);
+           np->nat_ann++;
+           putnat(np);
+           if (notify)
+               player_wakeup_all(to);
        }
-
-       close(fd);
-       return 0;
+    } else {
+       notify = (np->nat_tgms == 0);
+       new_tele = telegram_is_new(to, &tel);
+       np->nat_tgms += new_tele || notify;
+       putnat(np);
+
+       if (new_tele && np->nat_flags & NF_INFORM) {
+           if (NULL != (other = getplayer(to))) {
+               if (np->nat_tgms == 1)
+                   pr_inform(other, "[new tele]\n");
+               else
+                   pr_inform(other, "[%d new teles]\n", np->nat_tgms);
+               player_wakeup_all(to);
+           }
+       } else if (notify)
+           player_wakeup_all(to);
+    }
+
+    close(fd);
+    return 0;
 }
-