2 * This module implements server commands related to the display and
3 * manipulation of the "Who's online" list.
5 * Copyright (c) 1987-2019 by the citadel.org team
7 * This program is open source software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 3.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
25 #include <sys/types.h>
27 #if TIME_WITH_SYS_TIME
28 # include <sys/time.h>
32 # include <sys/time.h>
41 #include <libcitadel.h>
44 #include "citserver.h"
53 #include "ctdl_module.h"
55 /* Don't show the names of private rooms unless the viewing
56 * user also knows the rooms.
58 void GenerateRoomDisplay(char *real_room,
64 strcpy(real_room, viewed->room.QRname);
65 if (viewed->room.QRflags & QR_MAILBOX) {
66 strcpy(real_room, &real_room[11]);
68 if (viewed->room.QRflags & QR_PRIVATE) {
69 CtdlRoomAccess(&viewed->room, &viewer->user, &ra, NULL);
70 if ( (ra & UA_KNOWN) == 0) {
71 strcpy(real_room, " ");
75 if (viewed->cs_flags & CS_CHAT) {
76 while (strlen(real_room) < 14) {
77 strcat(real_room, " ");
79 strcpy(&real_room[14], "<chat>");
87 * display who's online
89 void cmd_rwho(char *argbuf) {
90 struct CitContext *nptr;
94 char real_room[ROOMNAMELEN], room[ROOMNAMELEN];
97 /* So that we don't keep the context list locked for a long time
98 * we create a copy of it first
100 nptr = CtdlGetContextArray(&nContexts) ;
103 /* Couldn't malloc so we have to bail but stick to the protocol */
104 cprintf("%d%c \n", LISTING_FOLLOWS, CtdlCheckExpress() );
109 aide = ( (CC->user.axlevel >= AxAideU) || (CC->internal_pgm) ) ;
110 cprintf("%d%c \n", LISTING_FOLLOWS, CtdlCheckExpress() );
112 for (i=0; i<nContexts; i++) {
116 if (!aide && nptr[i].state == CON_SYS)
119 if (!aide && nptr[i].kill_me != 0)
122 if (nptr[i].cs_flags & CS_POSTING) {
129 GenerateRoomDisplay(real_room, &nptr[i], CC);
131 if ((aide) && (spoofed)) {
135 if ((nptr[i].cs_flags & CS_STEALTH) && (aide)) {
139 if (((nptr[i].cs_flags&CS_STEALTH)==0) || (aide)) {
141 cprintf("%d|%s|%s|%s|%s|%ld|%s|%s|",
142 nptr[i].cs_pid, nptr[i].curr_user, room,
143 nptr[i].cs_host, nptr[i].cs_clientname,
144 (long)(nptr[i].lastidle),
145 nptr[i].lastcmdname, flags
148 cprintf("|"); // no spoofed user names anymore
149 cprintf("|"); // no spoofed room names anymore
150 cprintf("|"); // no spoofed host names anymore
152 cprintf("%d\n", nptr[i].logged_in);
156 /* release our copy of the context list */
159 /* Now it's magic time. Before we finish, call any EVT_RWHO hooks
160 * so that external paging modules such as serv_icq can add more
161 * content to the Wholist.
163 PerformSessionHooks(EVT_RWHO);
169 * enter or exit "stealth mode"
171 void cmd_stel(char *cmdbuf)
175 requested_mode = extract_int(cmdbuf,0);
177 if (CtdlAccessCheck(ac_logged_in)) return;
179 if (requested_mode == 1) {
180 CC->cs_flags = CC->cs_flags | CS_STEALTH;
181 PerformSessionHooks(EVT_STEALTH);
183 if (requested_mode == 0) {
184 CC->cs_flags = CC->cs_flags & ~CS_STEALTH;
185 PerformSessionHooks(EVT_UNSTEALTH);
188 cprintf("%d %d\n", CIT_OK,
189 ((CC->cs_flags & CS_STEALTH) ? 1 : 0) );
193 CTDL_MODULE_INIT(rwho)
197 CtdlRegisterProtoHook(cmd_rwho, "RWHO", "Display who is online");
198 CtdlRegisterProtoHook(cmd_stel, "STEL", "Enter/exit stealth mode");
199 //CtdlRegisterSessionHook(dead_io_check, EVT_TIMER, PRIO_QUEUE + 50);
203 /* return our module name for the log */