2 * This module handles multiuser chat.
4 * Copyright (c) 1996-2012 by the citadel.org team
6 * This program is open source software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License, version 3.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
22 #include "webserver.h"
25 * Display the screen containing multiuser chat for a room.
31 WC->last_chat_seq = 0;
32 WC->last_chat_user[0] = 0;
34 output_headers(1, 1, 1, 0, 0, 0);
35 do_template("roomchat");
37 serv_puts("RCHT enter");
38 serv_getln(buf, sizeof buf);
45 * Receiving side of the chat window.
46 * This does JavaScript writes to
47 * other divs whenever it refreshes and finds new data.
49 void chat_recv(void) {
53 serv_printf("RCHT poll|%d", WC->last_chat_seq);
54 serv_getln(buf, sizeof buf);
56 WC->last_chat_seq = extract_int(&buf[4], 0);
57 extract_token(cl_user, &buf[4], 2, '|', sizeof cl_user);
59 /* who is speaking ... */
60 if (strcasecmp(cl_user, WC->last_chat_user)) {
62 if (!strcasecmp(cl_user, ChrPtr(WC->wc_fullname))) {
63 wc_printf("<span class=\"chat_myname_class\">");
66 wc_printf("<span class=\"chat_notmyname_class\">");
69 strcpy(WC->last_chat_user, cl_user);
71 wc_printf(": </span>");
74 wc_printf(" ");
77 /* what did they say ... */
78 wc_printf("<span class=\"chat_text_class\">");
79 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
82 wc_printf("<br></span>\n");
88 * This is the sending side of the chat window. The form is designed to transmit asynchronously.
90 void chat_send(void) {
94 begin_ajax_response();
96 if (havebstr("send_this")) {
97 strcpy(send_this, bstr("send_this"));
100 strcpy(send_this, "");
103 if (havebstr("exit_button")) {
104 strcpy(send_this, "/quit");
107 if (!IsEmptyStr(send_this)) {
108 serv_puts("RCHT send");
109 serv_getln(buf, sizeof buf);
111 text_to_server(send_this);
122 void chat_rwho(void) {
125 serv_puts("RCHT rwho");
126 serv_getln(buf, sizeof buf);
128 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
129 if (!strcasecmp(buf, ChrPtr(WC->wc_fullname))) {
130 wc_printf("<span class=\"chat_myname_class\">");
133 wc_printf("<span class=\"chat_notmyname_class\">");
135 wc_printf("<img src=\"static/webcit_icons/essen/16x16/chat.png\">");
137 wc_printf("</span><br>\n");
144 * advise the Citadel server that the user is navigating away from the chat window
146 void chat_exit(void) {
149 serv_puts("RCHT exit");
150 serv_getln(buf, sizeof buf); /* Throw away the server reply */
159 WebcitAddUrlHandler(HKEY("chat"), "", 0, do_chat, 0);
160 WebcitAddUrlHandler(HKEY("chat_recv"), "", 0, chat_recv, AJAX);
161 WebcitAddUrlHandler(HKEY("chat_rwho"), "", 0, chat_rwho, AJAX);
162 WebcitAddUrlHandler(HKEY("chat_exit"), "", 0, chat_exit, AJAX);
163 WebcitAddUrlHandler(HKEY("chat_send"), "", 0, chat_send, 0);
168 SessionDestroyModule_ROOMCHAT
171 /* nothing here anymore */