]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/flash.c
Permit flash to yourself
[empserver] / src / lib / commands / flash.c
index 87a1e605c5ab0b3f965355c15428f08746293ee5..ffdba7a517a733d7a2c2a6a0d7db8ea10e1a5b42 100644 (file)
@@ -38,8 +38,8 @@
 
 #include "commands.h"
 
-static int chat(struct natstr *, struct natstr *, char *);
-static int sendmessage(struct natstr *, struct natstr *, char *, int);
+static int chat(struct natstr *, char *);
+static int sendmessage(struct natstr *, char *, int);
 
 int
 flash(void)
@@ -63,19 +63,20 @@ flash(void)
        }
     } else {
        /* Ok, we are a normal country, can we flash them? */
-       if (to->nat_stat != STAT_GOD && getrel(to, player->cnum) < FRIENDLY) {
+       if (to->nat_stat != STAT_GOD && tocn != player->cnum
+           && getrel(to, player->cnum) < FRIENDLY) {
            pr("%s is not a deity or friendly with us.\n", to->nat_cnam);
            return RET_SYN;
        }
     }
 
-    return chat(us, to, player->comtail[2]);
+    return chat(to, player->comtail[2]);
 }
 
 int
 wall(void)
 {
-    return chat(getnatp(player->cnum), NULL, player->comtail[1]);
+    return chat(NULL, player->comtail[1]);
 }
 
 /*
@@ -85,7 +86,7 @@ wall(void)
  * Return RET_OK.
  */
 static int
-chat(struct natstr *us, struct natstr *to, char *message)
+chat(struct natstr *to, char *message)
 {
     char buf[1024];            /* UTF-8 */
 
@@ -93,15 +94,15 @@ chat(struct natstr *us, struct natstr *to, char *message)
        buf[0] = ':';
        buf[1] = ' ';
        strcpy(buf+2, message);
-       sendmessage(us, to, buf, 1);
+       sendmessage(to, buf, 1);
     } else {
-       sendmessage(us, to, "...", 1);
+       sendmessage(to, "...", 1);
        while (ugetstring("> ", buf)) {
            if (*buf == '.')
                break;
-           sendmessage(us, to, buf, 0);
+           sendmessage(to, buf, 0);
        }
-       sendmessage(us, to, "<EOT>", 0);
+       sendmessage(to, "<EOT>", 0);
     }
     return RET_OK;
 }
@@ -114,7 +115,7 @@ chat(struct natstr *us, struct natstr *to, char *message)
  * verbose if VERBOSE.
  */
 static int
-sendmessage(struct natstr *us, struct natstr *to, char *message, int verbose)
+sendmessage(struct natstr *to, char *message, int verbose)
 {
     struct player *other;
     struct tm *tm;
@@ -127,50 +128,60 @@ sendmessage(struct natstr *us, struct natstr *to, char *message, int verbose)
     for (other = player_next(NULL); other; other = player_next(other)) {
        if (other->state != PS_PLAYING)
            continue;
-       if (player == other)
-           continue;
-       if (to && other->cnum != to->nat_cnum)
-           continue;
-       if (!(wto = getnatp(other->cnum)))
-           continue;
-       if (!to && !player->god && getrel(wto, player->cnum) != ALLIED)
-           continue;
+       if (to) {
+           /* flash */
+           if (other->cnum != to->nat_cnum)
+               continue;
+           wto = to;
+       } else {
+           /* wall */
+           if (player == other)
+               continue;
+           wto = getnatp(other->cnum);
+           if (CANT_HAPPEN(!wto))
+               continue;
+           if (!player->god && getrel(wto, player->cnum) != ALLIED)
+               continue;
+       }
        if (!player->god && !(wto->nat_flags & NF_FLASH)) {
            rejected++;
            continue;
        }
+
        if (verbose)
            if (to)
                pr_flash(other, "FLASH from %s (#%d) @ %02d:%02d%s\n",
-                        us->nat_cnam, us->nat_cnum, tm->tm_hour,
+                        cname(player->cnum), player->cnum, tm->tm_hour,
                         tm->tm_min, message);
            else
                pr_flash(other, "BROADCAST from %s (#%d) @ %02d:%02d%s\n",
-                        us->nat_cnam, us->nat_cnum, tm->tm_hour,
+                        cname(player->cnum), player->cnum, tm->tm_hour,
                         tm->tm_min, message);
 
        else
            pr_flash(other, "%s (#%d): %s\n",
-                    us->nat_cnam, us->nat_cnum, message);
+                    cname(player->cnum), player->cnum, message);
        sent++;
     }
-    
-    if (player->god) {
-       if (to) {
-           if (!sent)
+
+    if (to) {
+       /* flash */
+       if (player->god || to->nat_cnum == player->cnum
+           || getrel(to, player->cnum) == ALLIED) {
+           /* Can see TO logged in anyway, so it's okay to tell */
+           if (rejected)
+               pr("%s is not accepting flashes\n", to->nat_cnam);
+           else if (!sent) {
                pr("%s is not logged on\n", to->nat_cnam);
-       } else if (sent)
-           pr("Broadcast sent to %d players\n", sent);
-       else
-           pr("No-one is logged in\n");
-    }
-    if (to && !player->god && getrel(to, player->cnum) == ALLIED) {
-       /* If they are allied with us, we would normally see that
-        * they are logged in anyway, so just tell us */
-       if (rejected)
-           pr("%s is not accepting flashes\n", to->nat_cnam);
-       else if (!sent) {
-           pr("%s is not logged on\n", to->nat_cnam);
+           }
+       }
+    } else {
+       /* wall */
+       if (player->god) {
+           if (sent)
+               pr("Broadcast sent to %d players\n", sent);
+           else
+               pr("No-one is logged in\n");
        }
     }
     return 0;