PennMUSH 1.8.3p11
authorRick L Bird <nveid@yahoo.com>
Fri, 6 May 2011 22:29:13 +0000 (18:29 -0400)
committerRick L Bird <nveid@yahoo.com>
Fri, 6 May 2011 22:29:13 +0000 (18:29 -0400)
Author: talvo@talvo.com <talvo@talvo.com@ba372814-4f39-11de-9ad6-1127a62b9fcd>
Date:   Tue Dec 8 08:55:33 2009 +0000

    IDLE enhancements

Fixes #133
Fixes #132

src/bsd.c

index da360231514ce0665a328ad51330247552b9637f..07d0adcd682df99461d8feb9d1f4629412ef7b3b 100644 (file)
--- a/src/bsd.c
+++ b/src/bsd.c
@@ -404,7 +404,7 @@ sig_atomic_t slave_error = 0;
 #endif
 #endif
 extern pid_t forked_dump_pid;   /**< Process id of forking dump process */
-static void dump_users(DESC *call_by, char *match);
+static void dump_users(DESC * call_by, char *match);
 static const char *time_format_1(long int dt);
 static const char *time_format_2(long int dt);
 
@@ -1531,7 +1531,6 @@ fcache_read(FBLOCK * fb, const char *filename)
       }
     }
   }
-
 #ifdef WIN32
   /* Win32 read code here */
   {
@@ -2585,7 +2584,7 @@ process_commands(void)
   }
 
 static void
-dump_users(DESC *call_by, char *match)
+dump_users(DESC * call_by, char *match)
 {
   DESC *d;
   int count = 0;
@@ -2594,7 +2593,8 @@ dump_users(DESC *call_by, char *match)
   char tbuf2[BUFFER_LEN];
 
   if (!GoodObject(call_by->player)) {
-    do_rawlog(LT_ERR, T("Bogus caller #%d of dump_users"), call_by->player);
+    do_rawlog(LT_ERR, T("Bogus caller #%d of dump_users"),
+              call_by->player);
     return;
   }
   while (*match && *match == ' ')
@@ -2602,14 +2602,15 @@ dump_users(DESC *call_by, char *match)
   now = mudtime;
 
   if (SUPPORT_PUEBLO && (call_by->conn_flags & CONN_HTML)) {
-    queue_newwrite(call_by, (const unsigned char *) "<img xch_mode=html>", 19);
+    queue_newwrite(call_by, (const unsigned char *) "<img xch_mode=html>",
+                   19);
     queue_newwrite(call_by, (const unsigned char *) "<PRE>", 5);
   }
 
   if (poll_msg[0] == '\0')
     strcpy(poll_msg, "Doing");
   snprintf(tbuf2, BUFFER_LEN, "%-16s %10s %6s  %s\n",
-               T("Player Name"), T("On For"), T("Idle"), poll_msg);
+           T("Player Name"), T("On For"), T("Idle"), poll_msg);
   queue_string(call_by, tbuf2);
 
   for (d = descriptor_list; d; d = d->next) {
@@ -2621,29 +2622,30 @@ dump_users(DESC *call_by, char *match)
       continue;
 
     sprintf(tbuf1, "%-16s %10s   %4s%c %s", Name(d->player),
-                  time_format_1(now - d->connected_at),
-                  time_format_2(now - d->last_time),
-                  (Dark(d->player) ? 'D' : (Hidden(d) ? 'H' : ' '))
-                  , d->doing);
+            time_format_1(now - d->connected_at),
+            time_format_2(now - d->last_time),
+            (Dark(d->player) ? 'D' : (Hidden(d) ? 'H' : ' '))
+            , d->doing);
     queue_string(call_by, tbuf1);
     queue_newwrite(call_by, (const unsigned char *) "\r\n", 2);
   }
   switch (count) {
-    case 0:
-      mush_strncpy(tbuf1, T("There are no players connected."), BUFFER_LEN);
-      break;
-    case 1:
-      mush_strncpy(tbuf1, T("There is 1 player connected."), BUFFER_LEN);
-      break;
-    default:
-      snprintf(tbuf1, BUFFER_LEN, T("There are %d players connected."), count);
-      break;
+  case 0:
+    mush_strncpy(tbuf1, T("There are no players connected."), BUFFER_LEN);
+    break;
+  case 1:
+    mush_strncpy(tbuf1, T("There is 1 player connected."), BUFFER_LEN);
+    break;
+  default:
+    snprintf(tbuf1, BUFFER_LEN, T("There are %d players connected."),
+             count);
+    break;
   }
   queue_string(call_by, tbuf1);
   if (SUPPORT_PUEBLO && (call_by->conn_flags & CONN_HTML)) {
     queue_newwrite(call_by, (const unsigned char *) "\n</PRE>\n", 8);
-    queue_newwrite(call_by, (const unsigned char *) "<img xch_mode=purehtml>",
-                   23);
+    queue_newwrite(call_by,
+                   (const unsigned char *) "<img xch_mode=purehtml>", 23);
   } else
     queue_newwrite(call_by, (const unsigned char *) "\r\n", 2);
 }
@@ -2656,8 +2658,17 @@ do_command(DESC * d, char *command)
 
   depth = 0;
 
-  if (!strcmp(command, IDLE_COMMAND))
+  if (!strncmp(command, IDLE_COMMAND, strlen(IDLE_COMMAND))) {
+    j = strlen(IDLE_COMMAND);
+    if ((int) strlen(command) > j) {
+      if (*(command + j) == ' ')
+        j++;
+      queue_write(d, (unsigned char *) command + j, strlen(command) - j);
+      queue_eol(d);
+    }
     return 1;
+  }
+
 
   (d->cmds)++;
 
@@ -2674,7 +2685,7 @@ do_command(DESC * d, char *command)
     send_prefix(d);
     dump_info(d);
     send_suffix(d);
- } else if (!strncmp(command, PREFIX_COMMAND, strlen(PREFIX_COMMAND))) {
 } else if (!strncmp(command, PREFIX_COMMAND, strlen(PREFIX_COMMAND))) {
     set_userstring(&d->output_prefix, command + strlen(PREFIX_COMMAND));
   } else if (!strncmp(command, SUFFIX_COMMAND, strlen(SUFFIX_COMMAND))) {
     set_userstring(&d->output_suffix, command + strlen(SUFFIX_COMMAND));
@@ -2719,15 +2730,15 @@ do_command(DESC * d, char *command)
     } else {
       j = 0;
       if (!strncmp(command, WHO_COMMAND, strlen(WHO_COMMAND)))
-       j = strlen(WHO_COMMAND);
+        j = strlen(WHO_COMMAND);
       else if (!strncmp(command, DOING_COMMAND, strlen(DOING_COMMAND)))
-       j = strlen(DOING_COMMAND);
+        j = strlen(DOING_COMMAND);
       else if (!strncmp(command, SESSION_COMMAND, strlen(SESSION_COMMAND)))
-       j = strlen(SESSION_COMMAND);
+        j = strlen(SESSION_COMMAND);
       if (j) {
         send_prefix(d);
         dump_users(d, command + j);
-        send_suffix(d); 
+        send_suffix(d);
       } else if (!check_connect(d, command))
         return 0;
     }
@@ -3179,34 +3190,38 @@ player_desc(dbref player)
  * \param flags PEMIT_* flags
  */
 void
-do_pemit_port(dbref player, const char *pc, const char *message, int flags) {
-       DESC *d;
-       int port;
-
-       if (!Site(player)) {
-               notify(player, T("Permission denied."));
-               return;
-       }
-
-       port = atoi(pc);
-       if (port <= 0) {
-               notify(player, T("That's not a port number."));
-               return;
-       }
-
-       if (!*message) {
-               return;
-       }
-
-       d = port_desc(port);
-       if (!d) {
-               notify(player, T("That port is not active."));
-               return;
-       }
-
-       if (!(flags & PEMIT_SILENT))
-               notify_format(player, T("You pemit \"%s\" to %s."), message, (d->connected ? Name(d->player) : T("a connecting player")));
-       queue_string_eol(d, message);
+do_pemit_port(dbref player, const char *pc, const char *message, int flags)
+{
+  DESC *d;
+  int port;
+
+  if (!Site(player)) {
+    notify(player, T("Permission denied."));
+    return;
+  }
+
+  port = atoi(pc);
+  if (port <= 0) {
+    notify(player, T("That's not a port number."));
+    return;
+  }
+
+  if (!*message) {
+    return;
+  }
+
+  d = port_desc(port);
+  if (!d) {
+    notify(player, T("That port is not active."));
+    return;
+  }
+
+  if (!(flags & PEMIT_SILENT))
+    notify_format(player, T("You pemit \"%s\" to %s."), message,
+                  (d->
+                   connected ? Name(d->
+                                    player) : T("a connecting player")));
+  queue_string_eol(d, message);
 
 }
 
@@ -3456,7 +3471,8 @@ dump_info(DESC * call_by)
   queue_string_eol(call_by, "### End INFO");
 }
 
-COMMAND(cmd_dump_users) {
+COMMAND(cmd_dump_users)
+{
   DESC *d;
 #ifdef COLOREDWHO
   int tcount = 0;
@@ -3472,16 +3488,15 @@ COMMAND(cmd_dump_users) {
 
   match = arg_left;
 
-  if(!strcasecmp(cmd->name, "WHO"))
+  if (!strcasecmp(cmd->name, "WHO"))
     doing = 0;
else if(!strcasecmp(cmd->name, "SESSION"))
 else if (!strcasecmp(cmd->name, "SESSION"))
     doing = 2;
else /* Otherwise.. whatever is called us give them the doing */
-   doing = 3;
 else                          /* Otherwise.. whatever is called us give them the doing */
+    doing = 3;
+
   if (!GoodObject(player)) {
-    do_rawlog(LT_ERR, T("Bogus caller #%d of dump_users"),
-              player);
+    do_rawlog(LT_ERR, T("Bogus caller #%d of dump_users"), player);
     return;
   }
   while (*match && *match == ' ')
@@ -3502,18 +3517,19 @@ COMMAND(cmd_dump_users) {
   if ((doing == 1) || !Priv_Who(player)) {
     if (poll_msg[0] == '\0')
       strcpy(poll_msg, "Doing");
-      notify_format(player,  "%s%-16s %4s %10s %6s  %s%s",
-               ANSI_HILITE, T("Player Name"), T("Aff"), T("On For"),
-               T("Idle"), poll_msg, ANSI_END);
+    notify_format(player, "%s%-16s %4s %10s %6s  %s%s",
+                  ANSI_HILITE, T("Player Name"), T("Aff"), T("On For"),
+                  T("Idle"), poll_msg, ANSI_END);
   } else if (doing == 2) {
-    notify_format(player, "%s%-16s %6s %9s %5s %5s Des  Sent    Recv  Pend%s",
-             ANSI_HILITE, T("Player Name"), T("Loc #"), T("On For"), T("Idle"),
-             T("Cmds"), ANSI_END);
+    notify_format(player,
+                  "%s%-16s %6s %9s %5s %5s Des  Sent    Recv  Pend%s",
+                  ANSI_HILITE, T("Player Name"), T("Loc #"), T("On For"),
+                  T("Idle"), T("Cmds"), ANSI_END);
   } else {
     notify_format(player, "%s%-16s %6s %9s %5s %5s Des   Host%s",
-             ANSI_HILITE,
-             T("Player Name"), T("Loc #"), T("On For"), T("Idle"),
-             T("Cmds"), ANSI_END);
+                  ANSI_HILITE,
+                  T("Player Name"), T("Loc #"), T("On For"), T("Idle"),
+                  T("Cmds"), ANSI_END);
   }
 
   for (d = descriptor_list; d; d = d->next) {
@@ -3538,8 +3554,9 @@ COMMAND(cmd_dump_users) {
         sprintf(tbuf1, "%-16s %6s %9s %5s  %4d %3d%c  %s",
                 tprintf("%s%s", Name(d->player),
                         InProg(d->player) ? "(P)" : ""),
-                Can_Locate(player, d->player) ? unparse_dbref(Location(d->
-                                                               player)) :
+                Can_Locate(player,
+                           d->
+                           player) ? unparse_dbref(Location(d->player)) :
                 "#-1", time_format_1(now - d->connected_at),
                 time_format_2(now - d->last_time), csite ? d->cmds : 0,
                 csite ? d->descriptor : 0,
@@ -3561,7 +3578,9 @@ COMMAND(cmd_dump_users) {
         sprintf(tbuf1, "%-16s %6s %9s %5s %5d %3d%c %5lu %7lu %5d",
                 tprintf("%s%s", Name(d->player),
                         InProg(d->player) ? "(P)" : ""),
-                Can_Locate(player, d->player) ? unparse_dbref(Location(d->player)) :
+                Can_Locate(player,
+                           d->player) ? unparse_dbref(Location(d->
+                                                               player)) :
                 "#-1", time_format_1(now - d->connected_at),
                 time_format_2(now - d->last_time), csite ? d->cmds : 0,
                 csite ? d->descriptor : 0,
@@ -3587,14 +3606,14 @@ COMMAND(cmd_dump_users) {
 
       if (!Hidden(d) || Priv_Who(player)) {
 #ifdef COLOREDWHO
-          notify_format(player,
-                       "%s%s%s%s%s", ANSI_END,
-                               (tcount % 2 ? "" : ANSI_HILITE),
-                               (tcount % 2 ? ANSI_CYAN : ANSI_WHITE),
-                               tbuf1, ANSI_NORMAL);
+        notify_format(player,
+                      "%s%s%s%s%s", ANSI_END,
+                      (tcount % 2 ? "" : ANSI_HILITE),
+                      (tcount % 2 ? ANSI_CYAN : ANSI_WHITE),
+                      tbuf1, ANSI_NORMAL);
 
 #else
-          notify(player, tbuf1);
+        notify(player, tbuf1);
 
 #endif
       }
@@ -3630,13 +3649,13 @@ COMMAND(cmd_dump_users) {
                  d->input_chars, d->output_chars, d->output_size);
       }
 #ifdef COLOREDWHO
-        notify_format(player,
-                     "%s%s%s%s%s", ANSI_NORMAL,
-                             tcount % 2 ? "" : ANSI_HILITE,
-                             tcount % 2 ? ANSI_CYAN : ANSI_WHITE, tbuf1,
-                             ANSI_NORMAL);
+      notify_format(player,
+                    "%s%s%s%s%s", ANSI_NORMAL,
+                    tcount % 2 ? "" : ANSI_HILITE,
+                    tcount % 2 ? ANSI_CYAN : ANSI_WHITE, tbuf1,
+                    ANSI_NORMAL);
 #else
-        notify(player, tbuf1);
+      notify(player, tbuf1);
 #endif
     }
   }
@@ -3654,11 +3673,12 @@ COMMAND(cmd_dump_users) {
   }
 
 #ifdef COLOREDWHO
-    notify_format(player, "%s%s%s%s%s", ANSI_NORMAL, (tcount + 1) % 2 ? "" : ANSI_HILITE,
-                         (tcount + 1) % 2 ? ANSI_CYAN : ANSI_WHITE, tbuf1,
-                         ANSI_NORMAL);
+  notify_format(player, "%s%s%s%s%s", ANSI_NORMAL,
+                (tcount + 1) % 2 ? "" : ANSI_HILITE,
+                (tcount + 1) % 2 ? ANSI_CYAN : ANSI_WHITE, tbuf1,
+                ANSI_NORMAL);
 #else
-    notify(player, tbuf1);
+  notify(player, tbuf1);
 #endif
   if (SUPPORT_PUEBLO) {
     PUSE;
@@ -4161,8 +4181,8 @@ FUNCTION(fun_nwho)
       return;
     }
 
-  if (!Priv_Who(executor))
-    powered = 0;
+    if (!Priv_Who(executor))
+      powered = 0;
   }
 
   DESC_ITER_CONN(d) {
@@ -4187,7 +4207,7 @@ FUNCTION(fun_lwho)
 
   if (!(strchr(called_as, 'M') != NULL) && Priv_Who(executor))
     powered = 1;
+
   first = 1;
   if (!xwho && nargs && args[0] && *args[0]) {
     if (!powered) {
@@ -4205,7 +4225,7 @@ FUNCTION(fun_lwho)
       safe_str(T(e_perm), buff, bp);
       return;
     }
-  if (!Priv_Who(executor))
+    if (!Priv_Who(executor))
       powered = 0;
   } else
     victim = executor;
@@ -4481,9 +4501,11 @@ FUNCTION(fun_zwho)
     safe_str(T(e_perm), buff, bp);
     return;
   }
-  if ((getlock(zone, Zone_Lock) == TRUE_BOOLEXP) ||
-      (IsPlayer(zone)
-       && !(has_flag_by_name(zone, "SHARED", TYPE_PLAYER)))) {
+  if ((getlock(zone, Zone_Lock) == TRUE_BOOLEXP) || (IsPlayer(zone)
+                                                     &&
+                                                     !(has_flag_by_name
+                                                       (zone, "SHARED",
+                                                        TYPE_PLAYER)))) {
     safe_str(T("#-1 INVALID ZONE."), buff, bp);
     return;
   }
@@ -4772,49 +4794,51 @@ FUNCTION(fun_lports)
 
   if (nargs && args[0] && *args[0]) {
     /* An argument was given. Find the victim and adjust perms */
-    if ((victim = noisy_match_result(executor, args[0], NOTYPE, MAT_EVERYTHING)) == NOTHING) {
+    if ((victim =
+         noisy_match_result(executor, args[0], NOTYPE,
+                            MAT_EVERYTHING)) == NOTHING) {
       safe_str(T(e_notvis), buff, bp);
       return;
     }
 
-  if (!Priv_Who(executor)) 
+    if (!Priv_Who(executor))
       powered = 0;
   }
 
 
   if (nargs > 1 && args[1] && *args[1]) {
-               if (string_prefix("all", args[1])) {
-                       offline = online = 1;
-               } else if (strlen(args[1]) < 2) {
-                       safe_str(T("#-1 INVALID SECOND ARGUMENT"), buff, bp);
-                       return;
-               } else if (string_prefix("online", args[1])) {
-                       online = 1;
-                       offline = 0;
-               } else if (string_prefix("offline", args[1])) {
-                       online = 0;
-                       offline = 1;
-               } else {
-                       safe_str(T("#-1 INVALID SECOND ARGUMENT"), buff, bp);
-                       return;
-               }
-               if (offline && !powered) {
-                       safe_str(T("#-1 PERMISSION DENIED"), buff, bp);
-                       return;
-               }
-       }
-
-       DESC_ITER(d) {
-               if ((d->connected && !online) || (!d->connected && !offline))
-                       continue;
-               if (!powered && (d->connected && Hidden(d)))
-                       continue;
-               if (first)
-                       first = 0;
-               else
-                       safe_chr(' ', buff, bp);
-               safe_integer(d->descriptor, buff, bp);
-       }
+    if (string_prefix("all", args[1])) {
+      offline = online = 1;
+    } else if (strlen(args[1]) < 2) {
+      safe_str(T("#-1 INVALID SECOND ARGUMENT"), buff, bp);
+      return;
+    } else if (string_prefix("online", args[1])) {
+      online = 1;
+      offline = 0;
+    } else if (string_prefix("offline", args[1])) {
+      online = 0;
+      offline = 1;
+    } else {
+      safe_str(T("#-1 INVALID SECOND ARGUMENT"), buff, bp);
+      return;
+    }
+    if (offline && !powered) {
+      safe_str(T("#-1 PERMISSION DENIED"), buff, bp);
+      return;
+    }
+  }
+
+  DESC_ITER(d) {
+    if ((d->connected && !online) || (!d->connected && !offline))
+      continue;
+    if (!powered && (d->connected && Hidden(d)))
+      continue;
+    if (first)
+      first = 0;
+    else
+      safe_chr(' ', buff, bp);
+    safe_integer(d->descriptor, buff, bp);
+  }
 }
 
 /* ARGSUSED */