1 // This module implements server commands related to the display and
2 // manipulation of the "Who's online" list.
4 // Copyright (c) 1987-2022 by the citadel.org team
6 // This program is open source software. Use, duplication, or disclosure
7 // is subject to the terms of the GNU General Public License, version 3.
9 #include "../../sysdep.h"
17 #include <sys/types.h>
22 #include <libcitadel.h>
23 #include "../../citadel_defs.h"
24 #include "../../server.h"
25 #include "../../citserver.h"
26 #include "../../support.h"
27 #include "../../config.h"
28 #include "../../control.h"
29 #include "../../user_ops.h"
30 #include "../../database.h"
31 #include "../../msgbase.h"
32 #include "../../ctdl_module.h"
34 // Don't show the names of private rooms unless the viewing
35 // user also knows the rooms.
36 void GenerateRoomDisplay(char *real_room, CitContext *viewed, CitContext *viewer) {
39 strcpy(real_room, viewed->room.QRname);
41 if (viewed->room.QRflags & QR_MAILBOX) {
42 strcpy(real_room, &real_room[11]);
45 if (viewed->room.QRflags & QR_PRIVATE) {
46 CtdlRoomAccess(&viewed->room, &viewer->user, &ra, NULL);
47 if ( (ra & UA_KNOWN) == 0) {
48 strcpy(real_room, " ");
52 if (viewed->cs_flags & CS_CHAT) {
53 while (strlen(real_room) < 14) {
54 strcat(real_room, " ");
56 strcpy(&real_room[14], "<chat>");
62 // display who's online
63 void cmd_rwho(char *argbuf) {
64 struct CitContext *nptr;
68 char room[ROOMNAMELEN];
71 // So that we don't keep the context list locked for a long time
72 // we create a copy of it first
73 nptr = CtdlGetContextArray(&nContexts) ;
75 // Couldn't malloc so we have to bail but stick to the protocol
76 cprintf("%d%c \n", LISTING_FOLLOWS, CtdlCheckExpress() );
81 aide = ( (CC->user.axlevel >= AxAideU) || (CC->internal_pgm) ) ;
82 cprintf("%d%c \n", LISTING_FOLLOWS, CtdlCheckExpress() );
84 for (i=0; i<nContexts; i++) {
88 if (!aide && nptr[i].state == CON_SYS)
91 if (!aide && nptr[i].kill_me != 0)
94 if (nptr[i].cs_flags & CS_POSTING) {
101 GenerateRoomDisplay(room, &nptr[i], CC);
103 if ((aide) && (spoofed)) {
107 if ((nptr[i].cs_flags & CS_STEALTH) && (aide)) {
111 if (((nptr[i].cs_flags&CS_STEALTH)==0) || (aide)) {
113 cprintf("%d|%s|%s|%s|%s|%ld|%s|%s|",
115 (nptr[i].logged_in ? nptr[i].curr_user : NLI),
118 nptr[i].cs_clientname,
119 (long)(nptr[i].lastidle),
124 cprintf("|"); // no spoofed user names anymore
125 cprintf("|"); // no spoofed room names anymore
126 cprintf("|"); // no spoofed host names anymore
128 cprintf("%d\n", nptr[i].logged_in);
132 // release our copy of the context list
135 // Now it's magic time. Before we finish, call any EVT_RWHO hooks
136 // so that external paging modules such as serv_icq can add more
137 // content to the Wholist.
138 PerformSessionHooks(EVT_RWHO);
143 // enter or exit "stealth mode"
144 void cmd_stel(char *cmdbuf) {
147 requested_mode = extract_int(cmdbuf,0);
149 if (CtdlAccessCheck(ac_logged_in)) return;
151 if (requested_mode == 1) {
152 CC->cs_flags = CC->cs_flags | CS_STEALTH;
153 PerformSessionHooks(EVT_STEALTH);
155 if (requested_mode == 0) {
156 CC->cs_flags = CC->cs_flags & ~CS_STEALTH;
157 PerformSessionHooks(EVT_UNSTEALTH);
160 cprintf("%d %d\n", CIT_OK,
161 ((CC->cs_flags & CS_STEALTH) ? 1 : 0) );
165 // Initialization function, called from modules_init.c
166 char *ctdl_module_init_rwho(void) {
168 CtdlRegisterProtoHook(cmd_rwho, "RWHO", "Display who is online");
169 CtdlRegisterProtoHook(cmd_stel, "STEL", "Enter/exit stealth mode");
173 // return our module name for the log