From f32ceccdff3bcccc6fdd650c2de34f6e79d2cba5 Mon Sep 17 00:00:00 2001 From: Rick L Bird Date: Fri, 6 May 2011 16:53:08 -0400 Subject: [PATCH] This pertains to Author: talvo@talvo.com Date: Sat Nov 28 23:46:41 2009 +0000 Issue 92, make WHO, DOING and SESSION standard commands However all the code is my own except for dump_users. I basically renamed the old dump_users to cmd_dump_users and we're differiating whats being called from teh command parser using cmd->name as a reference. All queue_string, called_by, and other references change tot he appropriate things for command parser level execution. IssueID #124 --- src/bsd.c | 229 ++++++++++++++++++++++++++++++-------------------- src/command.c | 3 + 2 files changed, 143 insertions(+), 89 deletions(-) diff --git a/src/bsd.c b/src/bsd.c index b8122b9..da36023 100644 --- 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, int doing); +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); @@ -2584,6 +2584,71 @@ process_commands(void) queue_eol(d); \ } +static void +dump_users(DESC *call_by, char *match) +{ + DESC *d; + int count = 0; + time_t now; + char tbuf1[BUFFER_LEN]; + char tbuf2[BUFFER_LEN]; + + if (!GoodObject(call_by->player)) { + do_rawlog(LT_ERR, T("Bogus caller #%d of dump_users"), call_by->player); + return; + } + while (*match && *match == ' ') + match++; + now = mudtime; + + if (SUPPORT_PUEBLO && (call_by->conn_flags & CONN_HTML)) { + queue_newwrite(call_by, (const unsigned char *) "", 19); + queue_newwrite(call_by, (const unsigned char *) "
", 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);
+  queue_string(call_by, tbuf2);
+
+  for (d = descriptor_list; d; d = d->next) {
+    if (!d->connected || !GoodObject(d->player))
+      continue;
+    if (COUNT_ALL || !Hidden(d))
+      count++;
+    if (Hidden(d) || (match && !(string_prefix(Name(d->player), 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);
+    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;
+  }
+  queue_string(call_by, tbuf1);
+  if (SUPPORT_PUEBLO && (call_by->conn_flags & CONN_HTML)) {
+    queue_newwrite(call_by, (const unsigned char *) "\n
\n", 8); + queue_newwrite(call_by, (const unsigned char *) "", + 23); + } else + queue_newwrite(call_by, (const unsigned char *) "\r\n", 2); +} + + int do_command(DESC * d, char *command) { @@ -2609,19 +2674,7 @@ do_command(DESC * d, char *command) send_prefix(d); dump_info(d); send_suffix(d); - } else if (!strncmp(command, WHO_COMMAND, strlen(WHO_COMMAND))) { - send_prefix(d); - dump_users(d, command + strlen(WHO_COMMAND), 0); - send_suffix(d); - } else if (!strncmp(command, DOING_COMMAND, strlen(DOING_COMMAND))) { - send_prefix(d); - dump_users(d, command + strlen(DOING_COMMAND), 1); - send_suffix(d); - } else if (!strncmp(command, SESSION_COMMAND, strlen(SESSION_COMMAND))) { - send_prefix(d); - dump_users(d, command + strlen(SESSION_COMMAND), 2); - 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)); @@ -2664,7 +2717,18 @@ do_command(DESC * d, char *command) strcpy(global_eval_context.ucom, ""); global_eval_context.cplr = NOTHING; } else { - if (!check_connect(d, command)) + j = 0; + if (!strncmp(command, WHO_COMMAND, strlen(WHO_COMMAND))) + j = strlen(WHO_COMMAND); + else if (!strncmp(command, DOING_COMMAND, strlen(DOING_COMMAND))) + j = strlen(DOING_COMMAND); + else if (!strncmp(command, SESSION_COMMAND, strlen(SESSION_COMMAND))) + j = strlen(SESSION_COMMAND); + if (j) { + send_prefix(d); + dump_users(d, command + j); + send_suffix(d); + } else if (!check_connect(d, command)) return 0; } } @@ -3392,23 +3456,32 @@ dump_info(DESC * call_by) queue_string_eol(call_by, "### End INFO"); } -static void -dump_users(DESC * call_by, char *match, int doing) - /* doing: 0 if normal WHO, 1 if DOING, 2 if SESSION */ -{ +COMMAND(cmd_dump_users) { DESC *d; #ifdef COLOREDWHO int tcount = 0; #endif int count = 0; + int doing; time_t now; char tbuf1[BUFFER_LEN]; - char tbuf2[BUFFER_LEN]; int csite; + char *match; + PUEBLOBUFF; - if (!GoodObject(call_by->player)) { + + match = arg_left; + + if(!strcasecmp(cmd->name, "WHO")) + doing = 0; + else if(!strcasecmp(cmd->name, "SESSION")) + doing = 2; + 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"), - call_by->player); + player); return; } while (*match && *match == ' ') @@ -3419,46 +3492,36 @@ dump_users(DESC * call_by, char *match, int doing) * BUT flags are not shown. Privileged WHO does not show @doings. */ - if (SUPPORT_PUEBLO && (call_by->conn_flags & CONN_HTML)) { - queue_newwrite(call_by, (const unsigned char *) "", - 19); - queue_newwrite(call_by, (const unsigned char *) "
", 5);
+  if (SUPPORT_PUEBLO) {
+    PUSE;
+    tag("PRE");
+    PEND;
+    notify_noenter(player, pbuff);
   }
 
-  if ((doing == 1) || !call_by->player || !Priv_Who(call_by->player)) {
+  if ((doing == 1) || !Priv_Who(player)) {
     if (poll_msg[0] == '\0')
       strcpy(poll_msg, "Doing");
-    if (ShowAnsi(call_by->player))
-      snprintf(tbuf2, BUFFER_LEN, "%s%-16s %4s %10s %6s  %s%s\n",
+      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
-      snprintf(tbuf2, BUFFER_LEN, "%-16s %4s %10s %6s  %s\n",
-               T("Player Name"), T("Aff"), T("On For"), T("Idle"),
-               poll_msg);
-    queue_string(call_by, tbuf2);
   } else if (doing == 2) {
-    snprintf(tbuf2, BUFFER_LEN,
-             "%s%-16s %6s %9s %5s %5s Des  Sent    Recv  Pend%s\n",
-             ShowAnsi(call_by->player) ? ANSI_HILITE : "",
-             T("Player Name"), T("Loc #"), T("On For"), T("Idle"),
-             T("Cmds"), ShowAnsi(call_by->player) ? ANSI_END : "");
-    queue_string(call_by, tbuf2);
+    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 {
-    snprintf(tbuf2, BUFFER_LEN, "%s%-16s %6s %9s %5s %5s Des   Host%s\n",
-             ShowAnsi(call_by->player) ? ANSI_HILITE : "",
+    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"), ShowAnsi(call_by->player) ? ANSI_END : "");
-    queue_string(call_by, tbuf2);
+             T("Cmds"), ANSI_END);
   }
 
   for (d = descriptor_list; d; d = d->next) {
     if (d->connected) {
       if (!GoodObject(d->player))
         continue;
-      if (COUNT_ALL || (!Hidden(d) || call_by->player == d->player
-                        || (call_by->player
-                            && Priv_Who(call_by->player)))) {
+      if (COUNT_ALL || (!Hidden(d) || player == d->player
+                        || Priv_Who(player))) {
         count++;
 #ifdef COLOREDWHO
         tcount++;
@@ -3466,18 +3529,16 @@ dump_users(DESC * call_by, char *match, int doing)
       }
       if (match && !(string_prefix(Name(d->player), match)))
         continue;
-      csite = CanSee(call_by->player, d->player);
+      csite = CanSee(player, d->player);
 
-      if (call_by->connected && doing == 0 && call_by->player
-          && Priv_Who(call_by->player)) {
+      if (doing == 0 && player && Priv_Who(player)) {
         if (Hidden(d) && !csite)
           continue;
 
         sprintf(tbuf1, "%-16s %6s %9s %5s  %4d %3d%c  %s",
                 tprintf("%s%s", Name(d->player),
                         InProg(d->player) ? "(P)" : ""),
-                Can_Locate(call_by->player,
-                           d->player) ? unparse_dbref(Location(d->
+                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,
@@ -3496,14 +3557,11 @@ dump_users(DESC * call_by, char *match, int doing)
           tbuf1[71] = '\0';
           strcat(tbuf1, " (Hide)");
         }
-      } else if (call_by->connected && doing == 2 && call_by->player
-                 && Priv_Who(call_by->player)) {
+      } else if (doing == 2 && Priv_Who(player)) {
         sprintf(tbuf1, "%-16s %6s %9s %5s %5d %3d%c %5lu %7lu %5d",
                 tprintf("%s%s", Name(d->player),
                         InProg(d->player) ? "(P)" : ""),
-                Can_Locate(call_by->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,
@@ -3516,8 +3574,7 @@ dump_users(DESC * call_by, char *match, int doing)
                 csite ? d->output_size : 0);
       } else {
         if (!Hidden(d)
-            || call_by->player == d->player ||
-            (call_by->player && Priv_Who(call_by->player) && (doing))) {
+            || player == d->player || (Priv_Who(player) && doing)) {
           snprintf(tbuf1, BUFFER_LEN, "%-16s %4s %10s   %4s%c %s",
                    tprintf("%s%s", Name(d->player),
                            InProg(d->player) ? "(P)" : ""),
@@ -3528,22 +3585,20 @@ dump_users(DESC * call_by, char *match, int doing)
         }
       }
 
-      if (!Hidden(d) || (call_by->player && Priv_Who(call_by->player))) {
+      if (!Hidden(d) || Priv_Who(player)) {
 #ifdef COLOREDWHO
-        if (ShowAnsiColor(call_by->player))
-          queue_string(call_by,
-                       tprintf("%s%s%s%s%s", ANSI_END,
+          notify_format(player,
+                       "%s%s%s%s%s", ANSI_END,
                                (tcount % 2 ? "" : ANSI_HILITE),
                                (tcount % 2 ? ANSI_CYAN : ANSI_WHITE),
-                               tbuf1, ANSI_NORMAL));
+                               tbuf1, ANSI_NORMAL);
+
+#else
+          notify(player, tbuf1);
 
-        else
 #endif
-          queue_string(call_by, tbuf1);
-        queue_newwrite(call_by, (const unsigned char *) "\r\n", 2);
       }
-    } else if (call_by->player && Priv_Who(call_by->player) && doing != 1
-               && (!match || !*match)) {
+    } else if (Priv_Who(player) && doing != 1 && (!match || !*match)) {
 #ifdef COLOREDWHO
       tcount++;
 #endif
@@ -3575,16 +3630,14 @@ dump_users(DESC * call_by, char *match, int doing)
                  d->input_chars, d->output_chars, d->output_size);
       }
 #ifdef COLOREDWHO
-      if (ShowAnsiColor(call_by->player))
-        queue_string(call_by,
-                     tprintf("%s%s%s%s%s", 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
+                             ANSI_NORMAL);
+#else
+        notify(player, tbuf1);
 #endif
-        queue_string(call_by, tbuf1);
-      queue_newwrite(call_by, (const unsigned char *) "\r\n", 2);
     }
   }
   switch (count) {
@@ -3601,21 +3654,19 @@ dump_users(DESC * call_by, char *match, int doing)
   }
 
 #ifdef COLOREDWHO
-  if (ShowAnsiColor(call_by->player))
-    queue_string(call_by,
-                 tprintf("%s%s%s%s%s", ANSI_NORMAL,
-                         (tcount + 1) % 2 ? "" : ANSI_HILITE,
+    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
+                         ANSI_NORMAL);
+#else
+    notify(player, tbuf1);
 #endif
-    queue_string(call_by, tbuf1);
-  if (SUPPORT_PUEBLO && (call_by->conn_flags & CONN_HTML)) {
-    queue_newwrite(call_by, (const unsigned char *) "\n
\n", 8); - queue_newwrite(call_by, - (const unsigned char *) "", 23); - } else - queue_newwrite(call_by, (const unsigned char *) "\r\n", 2); + if (SUPPORT_PUEBLO) { + PUSE; + tag_cancel("PRE"); + PEND; + notify_noenter(player, pbuff); + } + } static const char * diff --git a/src/command.c b/src/command.c index f7a13ca..57b62a5 100644 --- a/src/command.c +++ b/src/command.c @@ -328,6 +328,7 @@ COMLIST commands[] = { {"BRIEF", NULL, cmd_brief, CMD_T_ANY, NULL}, {"DESERT", NULL, cmd_desert, CMD_T_PLAYER | CMD_T_THING, NULL}, {"DISMISS", NULL, cmd_dismiss, CMD_T_PLAYER | CMD_T_THING, NULL}, + {"DOING", NULL, cmd_dump_users, CMD_T_PLAYER, NULL}, {"DROP", NULL, cmd_drop, CMD_T_PLAYER | CMD_T_THING, NULL}, {"EXAMINE", "ALL BRIEF DEBUG MORTAL", cmd_examine, CMD_T_ANY, NULL}, {"EMPTY", NULL, cmd_empty, CMD_T_PLAYER | CMD_T_THING | CMD_T_NOGAGGED, NULL}, @@ -350,6 +351,7 @@ COMLIST commands[] = { CMD_T_NOGAGGED, NULL}, {"POSE", "NOEVAL NOSPACE", cmd_pose, CMD_T_ANY | CMD_T_NOGAGGED, NULL}, {"SCORE", NULL, cmd_score, CMD_T_ANY, NULL}, + {"SESSION", NULL, cmd_dump_users, CMD_T_ANY, NULL}, {"SAY", "NOEVAL", cmd_say, CMD_T_ANY | CMD_T_NOGAGGED, NULL}, {"SEMIPOSE", "NOEVAL", cmd_semipose, CMD_T_ANY | CMD_T_NOGAGGED, NULL}, @@ -364,6 +366,7 @@ COMLIST commands[] = { {"WHISPER", "LIST NOISY SILENT NOEVAL", cmd_whisper, CMD_T_ANY | CMD_T_EQSPLIT | CMD_T_NOGAGGED, NULL}, + {"WHO",NULL, cmd_dump_users, CMD_T_ANY, NULL}, {"WITH", "NOEVAL ROOM", cmd_with, CMD_T_PLAYER | CMD_T_THING | CMD_T_EQSPLIT, NULL}, -- 2.30.2