4 typedef struct UserStateStruct {
17 void DestroyUserStruct(void *vUser)
19 UserStateStruct *User = (UserStateStruct*) vUser;
20 FreeStrBuf(&User->UserName);
21 FreeStrBuf(&User->Room);
22 FreeStrBuf(&User->Host);
23 FreeStrBuf(&User->RealRoom);
24 FreeStrBuf(&User->RealHost);
28 int CompareUserStruct(const void *VUser1, const void *VUser2)
30 const UserStateStruct *User1 = (UserStateStruct*) GetSearchPayload(VUser1);
31 const UserStateStruct *User2 = (UserStateStruct*) GetSearchPayload(VUser2);
33 if (User1->Idle != User2->Idle)
34 return User1->Idle > User2->Idle;
35 return strcasecmp(ChrPtr(User1->UserName),
36 ChrPtr(User2->UserName));
40 int GetWholistSection(HashList *List, time_t now, StrBuf *Buf, const char *FilterName, long FNLen)
43 UserStateStruct *User, *OldUser;
49 StrBuf_ServGetln(Buf);
50 if (GetServerStatus(Buf, NULL) == 1) {
51 while (BufLen = StrBuf_ServGetln(Buf),
53 ((BufLen != 3) || strcmp(ChrPtr(Buf), "000"))))
58 User = (UserStateStruct*) malloc(sizeof(UserStateStruct));
59 User->Session = StrBufExtractNext_int(Buf, &Pos, '|');
61 User->UserName = NewStrBufPlain(NULL, BufLen);
62 StrBufExtract_NextToken(User->UserName, Buf, &Pos, '|');
64 User->Room = NewStrBufPlain(NULL, BufLen);
65 StrBufExtract_NextToken(User->Room, Buf, &Pos, '|');
67 User->Host = NewStrBufPlain(NULL, BufLen);
68 StrBufExtract_NextToken(User->Host, Buf, &Pos, '|');
70 StrBufSkip_NTokenS(Buf, &Pos, '|', 1);
72 User->LastActive = StrBufExtractNext_long(Buf, &Pos, '|');
73 StrBufSkip_NTokenS(Buf, &Pos, '|', 3);
75 User->RealRoom = NewStrBufPlain(NULL, BufLen);
76 StrBufExtract_NextToken(User->RealRoom, Buf, &Pos, '|');
78 User->RealHost = NewStrBufPlain(NULL, BufLen);
79 StrBufExtract_NextToken(User->RealHost, Buf, &Pos, '|');
81 User->Idle = (now - User->LastActive) > 900L;
82 User->IdleSince = (now - User->LastActive) / 60;
83 User->SessionCount = 1;
85 if (FilterName == NULL) {
90 OldUser->SessionCount++;
92 if (User->Session == WCC->ctdl_pid)
93 OldUser->Session = User->Session;
95 OldUser->Idle = User->Idle;
96 OldUser->LastActive = User->LastActive;
98 DestroyUserStruct(User);
102 SKEY(User->UserName),
103 User, DestroyUserStruct);
106 if (strcmp(FilterName, ChrPtr(User->UserName)) == 0)
109 SKEY(User->UserName),
110 User, DestroyUserStruct);
114 DestroyUserStruct(User);
118 if (FilterName == NULL)
119 SortByPayload(List, CompareUserStruct);
130 void terminate_session(void)
134 serv_printf("TERM %s", bstr("which_session"));
135 serv_getln(buf, sizeof buf);
141 * Change your session info (fake roomname and hostname)
147 output_headers(1, 0, 0, 0, 0, 0);
148 if (havebstr("change_room_name_button")) {
149 serv_printf("RCHG %s", bstr("fake_roomname"));
150 serv_getln(buf, sizeof buf);
152 } else if (havebstr("change_host_name_button")) {
153 serv_printf("HCHG %s", bstr("fake_hostname"));
154 serv_getln(buf, sizeof buf);
156 } else if (havebstr("change_user_name_button")) {
157 serv_printf("UCHG %s", bstr("fake_username"));
158 serv_getln(buf, sizeof buf);
160 } else if (havebstr("cancel_button")) {
163 do_template("who_edit");
168 void _terminate_session(void) {
173 HashList *GetWholistHash(StrBuf *Target, WCTemplputParams *TP)
176 const char *ch = NULL;
179 StrBuf *FilterNameStr = NULL;
187 StrBuf_ServGetln(Buf);
188 if (GetServerStatus(Buf, NULL) == 2) {
189 const char *pos = ChrPtr(Buf) + 4;
190 now = StrBufExtractNext_long(Buf, &pos, '|');
195 if (HaveTemplateTokenString(NULL, TP, 2, &ch, &len))
197 FilterNameStr = NewStrBuf();
198 GetTemplateTokenString(FilterNameStr, TP, 2, &ch, &len);
202 List = NewHash(HashUniq, NULL);
203 GetWholistSection(List, now, Buf, ch, len);
205 FreeStrBuf(&FilterNameStr);
210 void DeleteWholistHash(HashList **KillMe)
215 void tmplput_who_username(StrBuf *Target, WCTemplputParams *TP)
217 UserStateStruct *User = (UserStateStruct*) CTX;
218 StrBufAppendTemplate(Target, TP, User->UserName, 0);
221 void tmplput_who_room(StrBuf *Target, WCTemplputParams *TP)
223 UserStateStruct *User = (UserStateStruct*) CTX;
224 StrBufAppendTemplate(Target, TP, User->Room, 0);
227 void tmplput_who_host(StrBuf *Target, WCTemplputParams *TP)
229 UserStateStruct *User = (UserStateStruct*) CTX;
230 StrBufAppendTemplate(Target, TP, User->Host, 0);
233 void tmplput_who_realroom(StrBuf *Target, WCTemplputParams *TP)
235 UserStateStruct *User = (UserStateStruct*) CTX;
236 StrBufAppendTemplate(Target, TP, User->RealRoom, 0);
238 int conditional_who_realroom(StrBuf *Target, WCTemplputParams *TP)
240 UserStateStruct *User = (UserStateStruct*) CTX;
241 return StrLength(User->RealRoom) > 0;
244 void tmplput_who_realhost(StrBuf *Target, WCTemplputParams *TP)
246 UserStateStruct *User = (UserStateStruct*) CTX;
247 StrBufAppendTemplate(Target, TP, User->RealHost, 0);
249 int conditional_who_realhost(StrBuf *Target, WCTemplputParams *TP)
251 UserStateStruct *User = (UserStateStruct*) CTX;
252 return StrLength(User->RealHost) > 0;
255 void tmplput_who_lastactive(StrBuf *Target, WCTemplputParams *TP)
257 UserStateStruct *User = (UserStateStruct*) CTX;
258 StrBufAppendPrintf(Target, "%d", User->LastActive);
261 void tmplput_who_idlesince(StrBuf *Target, WCTemplputParams *TP)
263 UserStateStruct *User = (UserStateStruct*) CTX;
264 StrBufAppendPrintf(Target, "%d", User->IdleSince);
267 void tmplput_who_session(StrBuf *Target, WCTemplputParams *TP)
269 UserStateStruct *User = (UserStateStruct*) CTX;
270 StrBufAppendPrintf(Target, "%d", User->Session);
273 int conditional_who_idle(StrBuf *Target, WCTemplputParams *TP)
275 UserStateStruct *User = (UserStateStruct*) CTX;
279 int conditional_who_nsessions(StrBuf *Target, WCTemplputParams *TP)
281 UserStateStruct *User = (UserStateStruct*) CTX;
282 return User->SessionCount;
285 void tmplput_who_nsessions(StrBuf *Target, WCTemplputParams *TP)
287 UserStateStruct *User = (UserStateStruct*) CTX;
288 StrBufAppendPrintf(Target, "%d", User->SessionCount);
291 int conditional_who_isme(StrBuf *Target, WCTemplputParams *TP)
293 UserStateStruct *User = (UserStateStruct*) CTX;
294 return (User->Session == WC->ctdl_pid);
303 WebcitAddUrlHandler(HKEY("terminate_session"), "", 0, _terminate_session, 0);
304 WebcitAddUrlHandler(HKEY("edit_me"), "", 0, edit_me, 0);
306 RegisterIterator("WHOLIST", 1, NULL, GetWholistHash, NULL, DeleteWholistHash, CTX_WHO, CTX_NONE, IT_NOFLAG);
308 RegisterNamespace("WHO:NAME", 0, 1, tmplput_who_username, NULL, CTX_WHO);
309 RegisterNamespace("WHO:ROOM", 0, 1, tmplput_who_room, NULL, CTX_WHO);
310 RegisterNamespace("WHO:HOST", 0, 1, tmplput_who_host, NULL, CTX_WHO);
311 RegisterNamespace("WHO:REALROOM", 0, 1, tmplput_who_realroom, NULL, CTX_WHO);
312 RegisterNamespace("WHO:REALHOST", 0, 1, tmplput_who_realhost, NULL, CTX_WHO);
313 RegisterNamespace("WHO:LASTACTIVE", 0, 1, tmplput_who_lastactive, NULL, CTX_WHO);
314 RegisterNamespace("WHO:IDLESINCE", 0, 1, tmplput_who_idlesince, NULL, CTX_WHO);
315 RegisterNamespace("WHO:SESSION", 0, 1, tmplput_who_session, NULL, CTX_WHO);
316 RegisterNamespace("WHO:NSESSIONS", 0, 1, tmplput_who_nsessions, NULL, CTX_WHO);
317 RegisterNamespace("WHO:NSESSIONS", 0, 1, tmplput_who_nsessions, NULL, CTX_WHO);
319 RegisterConditional(HKEY("WHO:IDLE"), 1, conditional_who_idle, CTX_WHO);
320 RegisterConditional(HKEY("WHO:NSESSIONS"), 1, conditional_who_nsessions, CTX_WHO);
321 RegisterConditional(HKEY("WHO:ISME"), 1, conditional_who_isme, CTX_WHO);
322 RegisterConditional(HKEY("WHO:REALROOM"), 1, conditional_who_realroom, CTX_WHO);
323 RegisterConditional(HKEY("WHO:REALHOST"), 1, conditional_who_realhost, CTX_WHO);