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.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
16 #include "webserver.h"
19 * Display the screen containing multiuser chat for a room.
25 WC->last_chat_seq = 0;
26 WC->last_chat_user[0] = 0;
28 output_headers(1, 1, 1, 0, 0, 0);
29 do_template("roomchat");
31 serv_puts("RCHT enter");
32 serv_getln(buf, sizeof buf);
39 * Receiving side of the chat window.
40 * This does JavaScript writes to
41 * other divs whenever it refreshes and finds new data.
43 void chat_recv(void) {
47 serv_printf("RCHT poll|%d", WC->last_chat_seq);
48 serv_getln(buf, sizeof buf);
50 WC->last_chat_seq = extract_int(&buf[4], 0);
51 extract_token(cl_user, &buf[4], 2, '|', sizeof cl_user);
53 /* who is speaking ... */
54 if (strcasecmp(cl_user, WC->last_chat_user)) {
56 if (!strcasecmp(cl_user, ChrPtr(WC->wc_fullname))) {
57 wc_printf("<span class=\"chat_myname_class\">");
60 wc_printf("<span class=\"chat_notmyname_class\">");
63 strcpy(WC->last_chat_user, cl_user);
65 wc_printf(": </span>");
68 wc_printf(" ");
71 /* what did they say ... */
72 wc_printf("<span class=\"chat_text_class\">");
73 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
76 wc_printf("<br></span>\n");
82 * This is the sending side of the chat window. The form is designed to transmit asynchronously.
84 void chat_send(void) {
88 begin_ajax_response();
90 if (havebstr("send_this")) {
91 strcpy(send_this, bstr("send_this"));
94 strcpy(send_this, "");
97 if (havebstr("exit_button")) {
98 strcpy(send_this, "/quit");
101 if (!IsEmptyStr(send_this)) {
102 serv_puts("RCHT send");
103 serv_getln(buf, sizeof buf);
105 text_to_server(send_this);
116 void chat_rwho(void) {
119 serv_puts("RCHT rwho");
120 serv_getln(buf, sizeof buf);
122 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
123 if (!strcasecmp(buf, ChrPtr(WC->wc_fullname))) {
124 wc_printf("<span class=\"chat_myname_class\">");
127 wc_printf("<span class=\"chat_notmyname_class\">");
129 wc_printf("<img src=\"static/webcit_icons/essen/16x16/chat.png\">");
131 wc_printf("</span><br>\n");
138 * advise the Citadel server that the user is navigating away from the chat window
140 void chat_exit(void) {
143 serv_puts("RCHT exit");
144 serv_getln(buf, sizeof buf); /* Throw away the server reply */
153 WebcitAddUrlHandler(HKEY("chat"), "", 0, do_chat, 0);
154 WebcitAddUrlHandler(HKEY("chat_recv"), "", 0, chat_recv, AJAX);
155 WebcitAddUrlHandler(HKEY("chat_rwho"), "", 0, chat_rwho, AJAX);
156 WebcitAddUrlHandler(HKEY("chat_exit"), "", 0, chat_exit, AJAX);
157 WebcitAddUrlHandler(HKEY("chat_send"), "", 0, chat_send, 0);
162 SessionDestroyModule_ROOMCHAT
165 /* nothing here anymore */