4 * Functions which implement the chat and paging facilities.
10 * display the form for paging (x-messaging) another user
12 void display_page(void)
16 strcpy(recp, bstr("recp"));
18 output_headers(1, 1, 2, 0, 0, 0, 0);
19 wprintf("<div id=\"banner\">\n"
20 "<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>"
21 "<SPAN CLASS=\"titlebar\">");
22 wprintf(_("Send instant message"));
24 "</TD></TR></TABLE>\n"
25 "</div>\n<div id=\"content\">\n"
28 wprintf("<div id=\"fix_scrollbar_bug\">"
29 "<table border=0 width=100%% bgcolor=\"#ffffff\"><tr><td>\n");
31 wprintf(_("Send an instant message to: "));
35 wprintf("<FORM METHOD=\"POST\" ACTION=\"/page_user\">\n");
37 wprintf("<TABLE border=0 width=100%%><TR><TD>\n");
39 wprintf("<INPUT TYPE=\"hidden\" NAME=\"recp\" VALUE=\"");
43 wprintf("<INPUT TYPE=\"hidden\" NAME=\"closewin\" VALUE=\"");
44 escputs(bstr("closewin"));
47 wprintf(_("Enter message text:"));
50 wprintf("<TEXTAREA NAME=\"msgtext\" wrap=soft ROWS=5 COLS=40 "
51 "WIDTH=40></TEXTAREA>\n");
53 wprintf("</TD></TR></TABLE><br />\n");
55 wprintf("<INPUT TYPE=\"submit\" NAME=\"send_button\" VALUE=\"%s\">", _("Send message"));
56 wprintf("<br /><A HREF=\"javascript:window.close();\"%s</A>\n", _("Cancel"));
58 wprintf("</FORM></CENTER>\n");
59 wprintf("</td></tr></table></div>\n");
72 output_headers(1, 1, 2, 0, 0, 0, 0);
73 wprintf("<div id=\"banner\">\n"
74 "<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>"
75 "<SPAN CLASS=\"titlebar\">");
76 wprintf(_("Add or edit an event"));
78 "</TD></TR></TABLE>\n"
79 "</div>\n<div id=\"content\">\n"
82 strcpy(recp, bstr("recp"));
83 strcpy(closewin, bstr("closewin"));
85 if (strlen(bstr("send_button")) == 0) {
87 wprintf(_("Message was not sent."));
88 wprintf("</EM><br />\n");
90 serv_printf("SEXP %s|-", recp);
91 serv_getln(buf, sizeof buf);
94 text_to_server(bstr("msgtext"), 0);
97 wprintf(_("Message has been sent to "));
99 wprintf(".</EM><br />\n");
102 wprintf("<EM>%s</EM><br />\n", &buf[4]);
106 if (!strcasecmp(closewin, "yes")) {
107 wprintf("<CENTER><A HREF=\"javascript:window.close();\">");
108 wprintf(_("[ close window ]"));
109 wprintf("</A></CENTER>\n");
124 /* First, check to make sure we're still allowed in this room. */
125 serv_printf("GOTO %s", WC->wc_roomname);
126 serv_getln(buf, sizeof buf);
128 smart_goto("_BASEROOM_");
132 /* If the chat socket is still open from a previous chat,
133 * close it -- because it might be stale or in the wrong room.
135 if (WC->chat_sock < 0) {
136 close(WC->chat_sock);
137 WC->chat_sock = (-1);
140 /* WebCit Chat works by having transmit, receive, and refresh
141 * frames. Load the frameset.
143 do_template("chatframeset");
151 void page_popup(void)
156 while (serv_puts("GEXP"), serv_getln(buf, sizeof buf), buf[0]=='1') {
158 extract_token(pagefrom, &buf[4], 3, '|', sizeof pagefrom);
160 wprintf("<table border=1 bgcolor=\"#880000\"><tr><td>");
161 wprintf("<span class=\"titlebar\">");
162 wprintf(_("Instant message from "));
164 wprintf("</span></td></tr><tr><td><font color=\"#FFFFFF\">");
166 wprintf("</font></td></tr>"
167 "<tr><td><div align=center><font color=\"#FFFFFF\">"
168 "<a href=\"javascript:hide_page_popup()\">");
169 wprintf(_("[ close window ]"));
176 WC->HaveInstantMessages = 0;
182 * Support function for chat -- make sure the chat socket is connected
185 int setup_chat_socket(void) {
188 int good_chatmode = 0;
190 if (WC->chat_sock < 0) {
192 if (!strcasecmp(ctdlhost, "uds")) {
193 /* unix domain socket */
194 sprintf(buf, "%s/citadel.socket", ctdlport);
195 WC->chat_sock = uds_connectsock(buf);
199 WC->chat_sock = tcp_connectsock(ctdlhost, ctdlport);
202 if (WC->chat_sock < 0) {
206 /* Temporarily swap the serv and chat sockets during chat talk */
208 WC->serv_sock = WC->chat_sock;
211 serv_getln(buf, sizeof buf);
213 serv_printf("USER %s", WC->wc_username);
214 serv_getln(buf, sizeof buf);
216 serv_printf("PASS %s", WC->wc_password);
217 serv_getln(buf, sizeof buf);
219 serv_printf("GOTO %s", WC->wc_roomname);
220 serv_getln(buf, sizeof buf);
223 serv_getln(buf, sizeof buf);
232 /* Unswap the sockets. */
234 WC->serv_sock = WC->chat_sock;
237 if (!good_chatmode) close(WC->serv_sock);
246 * Receiving side of the chat window. This is implemented in a
247 * tiny hidden IFRAME that just does JavaScript writes to
248 * other frames whenever it refreshes and finds new data.
250 void chat_recv(void) {
254 int end_chat_now = 0;
258 char *output_data = NULL;
260 output_headers(0, 0, 0, 0, 0, 0, 0);
262 wprintf("Content-type: text/html; charset=utf-8\n");
266 "<meta http-equiv=\"refresh\" content=\"3\" />\n"
269 "<body bgcolor=\"#FFFFFF\">\n"
272 if (setup_chat_socket() != 0) {
273 wprintf(_("An error occurred while setting up the chat socket."));
274 wprintf("</BODY></HTML>\n");
280 * See if there is any chat data waiting.
282 output_data = strdup("");
285 pf.fd = WC->chat_sock;
288 if (poll(&pf, 1, 1) > 0) if (pf.revents & POLLIN) {
291 /* Temporarily swap the serv and chat sockets during chat talk */
293 WC->serv_sock = WC->chat_sock;
296 serv_getln(buf, sizeof buf);
298 if (!strcmp(buf, "000")) {
300 strcat(buf, _("Now exiting chat mode."));
304 /* Unswap the sockets. */
306 WC->serv_sock = WC->chat_sock;
309 /* Append our output data */
310 output_data = realloc(output_data, strlen(output_data) + strlen(buf) + 4);
311 strcat(output_data, buf);
312 strcat(output_data, "\n");
315 } while ( (got_data) && (!end_chat_now) );
318 close(WC->chat_sock);
319 WC->chat_sock = (-1);
320 wprintf("<IMG SRC=\"/static/blank.gif\" onLoad=\"parent.window.close();\">\n");
323 if (strlen(output_data) > 0) {
325 if (output_data[strlen(output_data)-1] == '\n') {
326 output_data[strlen(output_data)-1] = 0;
329 /* Output our fun to the other frame. */
330 wprintf("<IMG SRC=\"/static/blank.gif\" WIDTH=1 HEIGHT=1\n"
334 for (i=0; i<num_tokens(output_data, '\n'); ++i) {
335 extract_token(buf, output_data, i, '\n', sizeof buf);
336 extract_token(cl_user, buf, 0, '|', sizeof cl_user);
337 extract_token(cl_text, buf, 1, '|', sizeof cl_text);
339 if (strcasecmp(cl_text, "NOOP")) {
341 wprintf("parent.chat_transcript.document.write('");
343 if (strcasecmp(cl_user, WC->last_chat_user)) {
344 wprintf("<TABLE border=0 WIDTH=100%% "
345 "CELLSPACING=1 CELLPADDING=0 "
346 "BGCOLOR="#FFFFFF">"
347 "<TR><TD></TR></TD></TABLE>"
352 wprintf("<TABLE border=0 WIDTH=100%% "
353 "CELLSPACING=0 CELLPADDING=0 "
354 "BGCOLOR="#EEEEEE">");
358 if (!strcasecmp(cl_user, ":")) {
362 if (strcasecmp(cl_user, WC->last_chat_user)) {
365 if (!strcasecmp(cl_user, WC->wc_username)) {
366 wprintf("<FONT COLOR="#FF0000">");
369 wprintf("<FONT COLOR="#0000FF">");
373 wprintf("</FONT>: </B>");
376 wprintf(" ");
379 if (!strcasecmp(cl_user, ":")) {
383 wprintf("</TD></TR></TABLE>");
386 strcpy(WC->last_chat_user, cl_user);
390 wprintf("parent.chat_transcript.scrollTo(999999,999999);\">\n");
395 wprintf("</BODY></HTML>\n");
401 * sending side of the chat window
403 void chat_send(void) {
408 output_headers(0, 0, 0, 0, 0, 0, 0);
409 wprintf("Content-type: text/html; charset=utf-8\n");
412 "<BODY onLoad=\"document.chatsendform.send_this.focus();\" >"
415 if (bstr("send_this") != NULL) {
416 strcpy(send_this, bstr("send_this"));
419 strcpy(send_this, "");
422 if (strlen(bstr("help_button")) > 0) {
423 strcpy(send_this, "/help");
426 if (strlen(bstr("list_button")) > 0) {
427 strcpy(send_this, "/who");
430 if (strlen(bstr("exit_button")) > 0) {
431 strcpy(send_this, "/quit");
434 if (setup_chat_socket() != 0) {
435 wprintf(_("An error occurred while setting up the chat socket."));
436 wprintf("</BODY></HTML>\n");
441 /* Temporarily swap the serv and chat sockets during chat talk */
443 WC->serv_sock = WC->chat_sock;
446 while (strlen(send_this) > 0) {
447 if (strlen(send_this) < 67) {
448 serv_puts(send_this);
449 strcpy(send_this, "");
452 for (i=55; i<67; ++i) {
453 if (send_this[i] == ' ') break;
455 strncpy(buf, send_this, i);
457 strcpy(send_this, &send_this[i]);
462 /* Unswap the sockets. */
464 WC->serv_sock = WC->chat_sock;
467 wprintf("<FORM METHOD=\"POST\" ACTION=\"/chat_send\" NAME=\"chatsendform\">\n");
468 wprintf("<INPUT TYPE=\"text\" SIZE=\"80\" MAXLENGTH=\"%d\" "
469 "NAME=\"send_this\">\n", SIZ-10);
471 wprintf("<INPUT TYPE=\"submit\" NAME=\"send_button\" VALUE=\"%s\">\n", _("Send"));
472 wprintf("<INPUT TYPE=\"submit\" NAME=\"help_button\" VALUE=\"%s\">\n", _("Help"));
473 wprintf("<INPUT TYPE=\"submit\" NAME=\"list_button\" VALUE=\"%s\">\n", _("List users"));
474 wprintf("<INPUT TYPE=\"submit\" NAME=\"exit_button\" VALUE=\"%s\">\n", _("Exit"));
475 wprintf("</FORM>\n");
477 wprintf("</BODY></HTML>\n");