1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
|
/*
* This module handles multiuser chat.
*
* Copyright (c) 1996-2012 by the citadel.org team
*
* This program is open source software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "webcit.h"
#include "webserver.h"
/*
* Display the screen containing multiuser chat for a room.
*/
void do_chat(void)
{
char buf[256];
WC->last_chat_seq = 0;
WC->last_chat_user[0] = 0;
output_headers(1, 1, 1, 0, 0, 0);
do_template("roomchat");
serv_puts("RCHT enter");
serv_getln(buf, sizeof buf);
wDumpContent(1);
}
/*
* Receiving side of the chat window.
* This does JavaScript writes to
* other divs whenever it refreshes and finds new data.
*/
void chat_recv(void) {
char buf[SIZ];
char cl_user[SIZ];
serv_printf("RCHT poll|%d", WC->last_chat_seq);
serv_getln(buf, sizeof buf);
if (buf[0] == '1') {
WC->last_chat_seq = extract_int(&buf[4], 0);
extract_token(cl_user, &buf[4], 2, '|', sizeof cl_user);
/* who is speaking ... */
if (strcasecmp(cl_user, WC->last_chat_user)) {
wc_printf("<br>\n");
if (!strcasecmp(cl_user, ChrPtr(WC->wc_fullname))) {
wc_printf("<span class=\"chat_myname_class\">");
}
else {
wc_printf("<span class=\"chat_notmyname_class\">");
}
escputs(cl_user);
strcpy(WC->last_chat_user, cl_user);
wc_printf(": </span>");
}
else {
wc_printf(" ");
}
/* what did they say ... */
wc_printf("<span class=\"chat_text_class\">");
while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
escputs(buf);
}
wc_printf("<br></span>\n");
}
}
/*
* This is the sending side of the chat window. The form is designed to transmit asynchronously.
*/
void chat_send(void) {
char send_this[SIZ];
char buf[SIZ];
begin_ajax_response();
if (havebstr("send_this")) {
strcpy(send_this, bstr("send_this"));
}
else {
strcpy(send_this, "");
}
if (havebstr("exit_button")) {
strcpy(send_this, "/quit");
}
if (!IsEmptyStr(send_this)) {
serv_puts("RCHT send");
serv_getln(buf, sizeof buf);
if (buf[0] == '4') {
text_to_server(send_this);
serv_puts("000");
}
}
end_ajax_response();
}
/*
* wholist for chat
*/
void chat_rwho(void) {
char buf[1024];
serv_puts("RCHT rwho");
serv_getln(buf, sizeof buf);
if (buf[0] == '1') {
while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
if (!strcasecmp(buf, ChrPtr(WC->wc_fullname))) {
wc_printf("<span class=\"chat_myname_class\">");
}
else {
wc_printf("<span class=\"chat_notmyname_class\">");
}
wc_printf("<img src=\"static/webcit_icons/essen/16x16/chat.png\">");
escputs(buf);
wc_printf("</span><br>\n");
}
}
}
/*
* advise the Citadel server that the user is navigating away from the chat window
*/
void chat_exit(void) {
char buf[1024];
serv_puts("RCHT exit");
serv_getln(buf, sizeof buf); /* Throw away the server reply */
}
void
InitModule_ROOMCHAT
(void)
{
WebcitAddUrlHandler(HKEY("chat"), "", 0, do_chat, 0);
WebcitAddUrlHandler(HKEY("chat_recv"), "", 0, chat_recv, AJAX);
WebcitAddUrlHandler(HKEY("chat_rwho"), "", 0, chat_rwho, AJAX);
WebcitAddUrlHandler(HKEY("chat_exit"), "", 0, chat_exit, AJAX);
WebcitAddUrlHandler(HKEY("chat_send"), "", 0, chat_send, 0);
}
void
SessionDestroyModule_ROOMCHAT
(wcsession *sess)
{
/* nothing here anymore */
}
|