4 * This module handles multiuser chat.
6 * Copyright (c) 1996-2010 by the citadel.org team
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "webserver.h"
27 * Display the screen containing multiuser chat for a room.
33 WC->last_chat_seq = 0;
34 WC->last_chat_user[0] = 0;
36 output_headers(1, 1, 1, 0, 0, 0);
37 do_template("roomchat", NULL);
39 serv_puts("RCHT enter");
40 serv_getln(buf, sizeof buf);
47 * Receiving side of the chat window.
48 * This does JavaScript writes to
49 * other divs whenever it refreshes and finds new data.
51 void chat_recv(void) {
55 serv_printf("RCHT poll|%d", WC->last_chat_seq);
56 serv_getln(buf, sizeof buf);
58 WC->last_chat_seq = extract_int(&buf[4], 0);
59 extract_token(cl_user, &buf[4], 2, '|', sizeof cl_user);
61 /* who is speaking ... */
62 if (strcasecmp(cl_user, WC->last_chat_user)) {
64 if (!strcasecmp(cl_user, ChrPtr(WC->wc_fullname))) {
65 wc_printf("<span class=\"chat_myname_class\">");
68 wc_printf("<span class=\"chat_notmyname_class\">");
71 strcpy(WC->last_chat_user, cl_user);
73 wc_printf(": </span>");
76 wc_printf(" ");
79 /* what did they say ... */
80 wc_printf("<span class=\"chat_text_class\">");
81 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
84 wc_printf("<br></span>\n");
90 * This is the sending side of the chat window. The form is designed to transmit asynchronously.
92 void chat_send(void) {
96 begin_ajax_response();
98 if (havebstr("send_this")) {
99 strcpy(send_this, bstr("send_this"));
102 strcpy(send_this, "");
105 if (havebstr("exit_button")) {
106 strcpy(send_this, "/quit");
109 if (!IsEmptyStr(send_this)) {
110 serv_puts("RCHT send");
111 serv_getln(buf, sizeof buf);
113 text_to_server(send_this);
124 void chat_rwho(void) {
127 serv_puts("RCHT rwho");
128 serv_getln(buf, sizeof buf);
130 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
131 if (!strcasecmp(buf, ChrPtr(WC->wc_fullname))) {
132 wc_printf("<span class=\"chat_myname_class\">");
135 wc_printf("<span class=\"chat_notmyname_class\">");
137 wc_printf("<img src=\"static/citadelchat_16x.gif\">");
139 wc_printf("</span><br>\n");
146 * advise the Citadel server that the user is navigating away from the chat window
148 void chat_exit(void) {
151 serv_puts("RCHT exit");
152 serv_getln(buf, sizeof buf); /* Throw away the server reply */
161 WebcitAddUrlHandler(HKEY("chat"), "", 0, do_chat, 0);
162 WebcitAddUrlHandler(HKEY("chat_recv"), "", 0, chat_recv, AJAX);
163 WebcitAddUrlHandler(HKEY("chat_rwho"), "", 0, chat_rwho, AJAX);
164 WebcitAddUrlHandler(HKEY("chat_exit"), "", 0, chat_exit, AJAX);
165 WebcitAddUrlHandler(HKEY("chat_send"), "", 0, chat_send, 0);
170 SessionDestroyModule_ROOMCHAT
173 /* nothing here anymore */