2 * front end for multiuser chat
4 * Copyright (c) 1987-2016 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.
25 #if TIME_WITH_SYS_TIME
26 # include <sys/time.h>
30 # include <sys/time.h>
36 #include <sys/types.h>
37 #ifdef HAVE_SYS_SELECT_H
38 #include <sys/select.h>
41 #include <libcitadel.h>
42 #include "citadel_ipc.h"
43 #include "client_chat.h"
46 #include "citadel_decls.h"
51 #define MIN(a, b) ((a) < (b) ? (a) : (b))
54 char last_paged[SIZ] = "";
56 void chatmode(CtdlIPC *ipc)
64 int send_complete_line;
73 CtdlIPC_chat_send(ipc, "RCHT enter");
74 CtdlIPC_chat_recv(ipc, buf);
76 scr_printf("%s\n", &buf[4]);
79 scr_printf("Entering chat mode (type /quit to exit)\n");
83 strcpy(last_user, "");
87 send_complete_line = 0;
95 retval = select(1, &rfds, NULL, NULL, &tv);
99 scr_printf("Server gone Exiting chat mode\n");
104 /* If there's data from the keyboard... */
105 if (FD_ISSET(0, &rfds)) {
106 ch = scr_getc(SCR_BLOCK);
107 if ((ch == 10) || (ch == 13)) {
108 send_complete_line = 1;
109 } else if ((ch == 8) || (ch == 127)) {
110 if (!IsEmptyStr(wbuf)) {
111 wbuf[strlen(wbuf) - 1] = 0;
112 scr_printf("%c %c", 8, 8);
116 wbuf[strlen(wbuf) + 1] = 0;
117 wbuf[strlen(wbuf)] = ch;
121 /* if the user hit return, send the line */
122 if (send_complete_line) {
124 if (!strcasecmp(wbuf, "/quit")) {
125 CtdlIPC_chat_send(ipc, "RCHT exit");
126 CtdlIPC_chat_recv(ipc, response); /* don't care about the result */
128 scr_printf("\rExiting chat mode\n");
133 CtdlIPC_chat_send(ipc, "RCHT send");
134 CtdlIPC_chat_recv(ipc, response);
135 if (response[0] == '4') {
136 CtdlIPC_chat_send(ipc, wbuf);
137 CtdlIPC_chat_send(ipc, "000");
140 send_complete_line = 0;
143 /* if it's time to word wrap, send a partial line */
144 if (strlen(wbuf) >= (77 - strlen(fullname))) {
146 for (a = 0; !IsEmptyStr(&wbuf[a]); ++a) {
151 CtdlIPC_chat_send(ipc, "RCHT send");
152 CtdlIPC_chat_recv(ipc, response);
153 if (response[0] == '4') {
154 CtdlIPC_chat_send(ipc, wbuf);
155 CtdlIPC_chat_send(ipc, "000");
158 send_complete_line = 0;
161 CtdlIPC_chat_send(ipc, "RCHT send");
162 CtdlIPC_chat_recv(ipc, response);
163 if (response[0] == '4') {
164 CtdlIPC_chat_send(ipc, wbuf);
165 CtdlIPC_chat_send(ipc, "000");
167 strcpy(wbuf, &wbuf[pos + 1]);
171 /* poll for incoming chat messages */
172 snprintf(buf, sizeof buf, "RCHT poll|%d", seq);
173 CtdlIPC_chat_send(ipc, buf);
174 CtdlIPC_chat_recv(ipc, response);
176 if (response[0] == '1') {
177 seq = extract_int(&response[4], 0);
178 extract_token(c_user, &response[4], 2, '|', sizeof c_user);
179 while (CtdlIPC_chat_recv(ipc, c_text), strcmp(c_text, "000")) {
180 scr_printf("\r%79s\r", "");
181 if (!strcmp(c_user, fullname)) {
182 color(BRIGHT_YELLOW);
183 } else if (!strcmp(c_user, ":")) {
188 if (strcmp(c_user, last_user)) {
189 snprintf(buf, sizeof buf, "%s: %s", c_user, c_text);
191 size_t i = MIN(sizeof buf - 1, strlen(c_user) + 2);
193 safestrncpy(&buf[i], c_text, sizeof buf - i);
195 while (strlen(buf) < 79) {
198 if (strcmp(c_user, last_user)) {
199 scr_printf("\r%79s\n", "");
200 strcpy(last_user, c_user);
202 scr_printf("\r%s\n", buf);
206 color(BRIGHT_YELLOW);
207 scr_printf("\r> %s", wbuf);
215 * send an instant message
217 void page_user(CtdlIPC *ipc)
219 char buf[SIZ], touser[SIZ], msg[SIZ];
222 strcpy(touser, last_paged);
223 strprompt("Page who", touser, 30);
225 /* old server -- use inline paging */
226 if (ipc->ServInfo.paging_level == 0) {
227 newprompt("Message: ", msg, 69);
228 snprintf(buf, sizeof buf, "SEXP %s|%s", touser, msg);
229 CtdlIPC_chat_send(ipc, buf);
230 CtdlIPC_chat_recv(ipc, buf);
231 if (!strncmp(buf, "200", 3)) {
232 strcpy(last_paged, touser);
234 scr_printf("%s\n", &buf[4]);
237 /* new server -- use extended paging */
238 else if (ipc->ServInfo.paging_level >= 1) {
239 snprintf(buf, sizeof buf, "SEXP %s||", touser);
240 CtdlIPC_chat_send(ipc, buf);
241 CtdlIPC_chat_recv(ipc, buf);
243 scr_printf("%s\n", &buf[4]);
246 if (client_make_message(ipc, temp, touser, 0, 0, 0, NULL, 0) != 0) {
247 scr_printf("No message sent.\n");
250 pagefp = fopen(temp, "r");
252 snprintf(buf, sizeof buf, "SEXP %s|-", touser);
253 CtdlIPC_chat_send(ipc, buf);
254 CtdlIPC_chat_recv(ipc, buf);
256 strcpy(last_paged, touser);
257 while (fgets(buf, sizeof buf, pagefp) != NULL) {
258 buf[strlen(buf) - 1] = 0;
259 CtdlIPC_chat_send(ipc, buf);
262 CtdlIPC_chat_send(ipc, "000");
263 scr_printf("Message sent.\n");
265 scr_printf("%s\n", &buf[4]);
271 void quiet_mode(CtdlIPC *ipc)
273 static int quiet = 0;
277 r = CtdlIPCEnableInstantMessageReceipt(ipc, !quiet, cret);
280 scr_printf("Quiet mode %sabled (%sother users may page you)\n",
281 (quiet) ? "en" : "dis",
282 (quiet) ? "no " : "");
284 scr_printf("Unable to change quiet mode: %s\n", cret);
289 void stealth_mode(CtdlIPC *ipc)
291 static int stealth = 0;
295 r = CtdlIPCStealthMode(ipc, !stealth, cret);
298 scr_printf("Stealth mode %sabled (you are %s)\n",
299 (stealth) ? "en" : "dis",
300 (stealth) ? "invisible" : "listed as online");
302 scr_printf("Unable to change stealth mode: %s\n", cret);