who.h

skylib_mudos_v1/mudlib/secure/handlers/intermud/who.h · 4.5 KB

From the archive skylib_mudos_v1.tar.gz

Download the archive   « Back to the archive contents

// A users reply for a remote online user list
private void who_reply(mixed *packet) {
  int width, bing =0;
  string info, base, ret, *players = ({ }), *creators = ({ }), *cnames=({}), *pnames=({});
  object user;
  mapping play_idle=([]);
  mapping cre_idle=([]); 
  string top, ptop;
  
  if (sizeof(packet) != (S_P + SIZEOF_WHO_REPLY)) {
    packet_invalid(packet);
    return;
  }

  if (!(user = find_player(packet[P_RECIPIENT])))
    return;

  for (int i = 0; i < sizeof(packet[S_P + WHO_REPLY_DATA]); i++) {

    if (!(info = packet[S_P + WHO_REPLY_DATA][i][WHO_DATA_INFO]))
      continue;

    switch (lower_case(info)) {
      default:
          switch (lower_case(info)){
           case "admin": case "senior creator": case "lord": case "high lord":
            creators += ({ packet[S_P + WHO_REPLY_DATA][i][WHO_DATA_SHORT]+
                 "("+lower_case(info)+")" });
            cre_idle +=([( packet[S_P + WHO_REPLY_DATA][i][WHO_DATA_SHORT]) :
             (packet[S_P + WHO_REPLY_DATA][i][WHO_DATA_IDLE]) ]);
             bing = 1;
             break;
           }
         if (bing == 1){
           bing = 0;
           break;
         }
        players += ({ packet[S_P + WHO_REPLY_DATA][i][WHO_DATA_SHORT] });
        play_idle+=([( packet[S_P + WHO_REPLY_DATA][i][WHO_DATA_SHORT]):
            (packet[S_P + WHO_REPLY_DATA][i][WHO_DATA_IDLE]) ]);
        break;
      case "immortal":  case "creator":  case "(lord)":
        creators += ({ packet[S_P + WHO_REPLY_DATA][i][WHO_DATA_SHORT] });
        cre_idle +=([( packet[S_P + WHO_REPLY_DATA][i][WHO_DATA_SHORT]) :
             (packet[S_P + WHO_REPLY_DATA][i][WHO_DATA_IDLE]) ]);

    }
  }

  players = sort_array(map(players, (: CAP($1) :) ), 1);
  creators = sort_array(map(creators, (: CAP($1) :) ), 1);

 
  top="";
  ptop="";
  for( int z=0;z<sizeof(creators);z++)
  {
    top+=creators[z];
    if(cre_idle[lower_case(creators[z]) ]/60>0)
    top+="(idle:"+ cre_idle[lower_case(creators[z]) ]/60+ ")\n";
    else
    top+="\n";      
  }
  for( int z=0;z<sizeof(players);z++)
  {
    ptop+=players[z];
    if(play_idle[lower_case(players[z]) ]/60>0)
    ptop+="(idle:"+ play_idle[lower_case(players[z]) ]/60+ ")\n";
    else
    ptop+="\n";      
  }

  pnames= explode(ptop,"\n");
  cnames= explode(top,"\n");
  width = user -> query_cols();

      ret= sprintf("\n%|*'-'s\n%|*s\n%*'-'|s\n%s%*'-'|s\n%s",
           width, sprintf("=======[ %s ]=======", CAP(packet[P_SOURCE])),
            width, ctime(time()),
            width, "=====[ creators ]====", 
            sprintf("%#-*s\n", width, implode(cnames," \n")),
            width, "=====[ players ]=====",
             sprintf("%#-*s", width, implode(pnames, " \n")));
                                        
  if (sizeof(packet[S_P + WHO_REPLY_DATA]) > 1)
    base = "[ There are " + query_num(sizeof(packet[S_P +
      WHO_REPLY_DATA])) + " people on ]";
  else
    if (sizeof(packet[S_P + WHO_REPLY_DATA]) == 1)
      base = "[ There is one person on ]";
    else
      base = "[ There is no-one on ]";

  ret += sprintf("\n%*'-'|s\n", width, base);
  tell_object(user, ret);

} /* who_reply() */

// A list of our online users
private void who_request(mixed *packet) {
  mixed *reply, *users = ({ });
  string *creators = ({}), *players = ({});

  if (sizeof(packet) != (S_P + SIZEOF_WHO_REQ)) {
    packet_invalid(packet);
    return;
  }

  foreach(object use in users()){        
     if(creatorp(use)){
        if(!use->query_invis())
            creators += ({use->query_name()});
     }else
        players += ({use->query_name()});
  }

  users += map(creators, (: ({ (string)$1,
    (interactive(find_player($1)) ? query_idle(find_player($1)) : 0),
    "creator" }) :));
  users += map(players, (: ({ (string)$1,
    (interactive(find_player($1)) ? query_idle(find_player($1)) : 0),
    "player" }) :));

  reply = packet_allocate(WHO_REPLY_PACKET);
  reply[P_DESTINATION] = packet[P_SOURCE];
  reply[P_RECIPIENT] = packet[P_SENDER];
  reply[S_P + WHO_REPLY_DATA] = users;

  event(users(),"inform", sprintf("IMUD who from %s at %s",
      packet[P_SENDER], packet[P_SOURCE]), "admin");

  if(lower_case(packet[P_SOURCE])=="aoc")
      return 0;

  add_buffer(0, reply);
  send_buffer(0);

} /* who_request() */

int who(string mud) {
  mixed *packet = packet_allocate(WHO_REQ_PACKET);

  if ((shutdown) || (!(mud = mud_exists(mud))))
    return 0;  // Service is unavailable

  packet[P_SENDER]      = TP -> query_name();
  packet[P_DESTINATION] = mud;
  add_buffer(0, packet);
  send_buffer(0);
  return 1;
} /* who() */

Site Stats

Snippets: 1791
Codebases: 571