[ScryMUD] SVN Commit Info r875 - trunk/mud/grrmud/server

scrymud at wanfear.com scrymud at wanfear.com
Mon Feb 12 22:58:22 PST 2007


Author: eroper
Date: 2007-02-12 22:58:21 -0800 (Mon, 12 Feb 2007)
New Revision: 875

Modified:
   trunk/mud/grrmud/server/command3.cc
Log:
"who" output is now nicely columnized.


Modified: trunk/mud/grrmud/server/command3.cc
===================================================================
--- trunk/mud/grrmud/server/command3.cc	2007-02-12 07:32:27 UTC (rev 874)
+++ trunk/mud/grrmud/server/command3.cc	2007-02-13 06:58:21 UTC (rev 875)
@@ -40,6 +40,9 @@
 #include <PtrArray.h>
 #include "load_wld.h"
 
+#include <string>
+#include <sstream>
+#include <iomanip>
 
 // Logs things generated by the 'bug' or 'typo' command.
 ofstream bug_log("./log/bug_log");
@@ -2591,90 +2594,84 @@
 
 
 int who(critter& pc) {
+
    Cell<critter*> cll(pc_list);
    critter* ptr;
-   String buf(100);
-   int visible_player_count = 0;
+   int visible_player_count = 0;//only count players visible to pc
+   bool is_cloaked = false;
+   std::stringstream buf;
 
    mudlog.log(TRC, "In who..\n");
 
-   show("These people are actively playing:\n", pc);
+   buf << "These people are actively playing:" << std::endl;
 
-   while ((ptr = cll.next())) {
-      if ((!detect(pc.SEE_BIT, ptr->VIS_BIT)) &&
-          (ptr->isImmort())) {
+   while ( ( ptr = cll.next() ) ) {
+
+      if ( ( !detect( pc.SEE_BIT, ptr->VIS_BIT ) ) && ( ptr->isImmort() ) ) {
          continue;
-      }//if
+      }
 
-      if ((ptr->getMode() ==  MODE_LOGGING_IN) && (!pc.isImmort())) {
+      if ( (ptr->getMode() ==  MODE_LOGGING_IN) && ( !pc.isImmort() ) ) {
          continue;
       }
 
-      String class_str;
-      String lvl_str;
-      String rp_str;
-      String afk_str;
-
-      //only count visible players
       ++visible_player_count;
 
-      int can_detect = FALSE;
-      if (ptr->isImmort()) {
-         if (pc.isImmort() && (pc.getImmLevel() >= ptr->getImmLevel())) {
-            can_detect = TRUE;
+      bool can_detect = false;
+
+      if ( ptr->isImmort() ) {
+
+         if ( pc.isImmort() && ( pc.getImmLevel() >= ptr->getImmLevel() ) ) {
+            can_detect = true;
          }
          else {
-            can_detect = FALSE;
+            can_detect = false;
          }
-      }//
-      else if (pc.isImmort()) {
-         can_detect = TRUE;
-      }
+      }//if _PTR_ isImmort()
+      else if ( pc.isImmort() ) {
+         can_detect = true;
+      }//if _PC_ isImmort()
       else {
-         //neither are immorts
-         can_detect = FALSE;
-      }
+         can_detect = false;
+      }//neither are immorts
 
-      if (ptr->isCloaked() && !can_detect && (ptr != &pc)) {
-         class_str = "Cloaked";
-         lvl_str = "??";
+      buf << "["
+         << ( ptr->isRolePlaying() ? "r" : "-" )
+         << ( ptr->isAFK() ? "a" : "-" )
+         << "]";
+
+      is_cloaked = ( ptr->isCloaked() && !can_detect && (ptr != &pc) );
+
+      if ( is_cloaked ) {
+         buf << std::setw(12) << "cloaked" << " |???| ";
       }
       else {
-         class_str = get_class_name(ptr->CLASS);
-         if (ptr->isImmort()) {
-            Sprintf(lvl_str, "IMM-%i", ptr->getImmLevel());
+         buf << std::setw(12) << get_class_name(ptr->getClass()) << " |";
+
+         if ( ptr->isImmort() ) {
+            buf << "i" << std::setw(2) << ptr->getImmLevel();
          }
-         else if (ptr->isRemort()) {
-            Sprintf(lvl_str, "RMT-%i", ptr->LEVEL);
+         else if ( ptr->isRemort() ) {
+            buf << "r" << std::setw(2) << ptr->getLevel();
          }
          else {
-            lvl_str = ptr->LEVEL;
+            buf << std::setw(3) << ptr->getLevel();
          }
-      }//else
 
-      if (ptr->isRolePlaying()) {
-          rp_str = "[RolePlaying]";
-      }
-      else {
-          rp_str = "";
-      }
+         buf << "| ";
+      }//not cloaked
 
-      if (ptr->isAFK()) {
-         afk_str = "[AFK]";
-      }
-      else {
-         afk_str = "";
-      }
+      const String *tmp_str = ptr->getName(pc.SEE_BIT); //I couldn't get this casted correctly while embedded below
+      buf << (const char*)(*tmp_str) << (const char*)ptr->short_desc << std::endl;
 
-      Sprintf(buf, "%S%S ^0%P45%S(%S) %S%S\n",
-              ptr->getName(pc.SEE_BIT), &(ptr->short_desc),
-              &class_str, &lvl_str, &rp_str, &afk_str);
-      show(buf, pc);
    }//while
-   Sprintf(buf, "\nThere are currently %i people actively playing.\n",
-           visible_player_count);
-   pc.show(buf);
+
+   buf << "There are currently " << visible_player_count << " people playing." << std::endl << std::endl;
+
+   pc.show( buf.str().c_str() );
+
    mudlog.log(TRC, "Done with who.\n");
+
    return 0;
 }//who
 




More information about the ScryMUD mailing list