1 // front end for multiuser chat
3 // Copyright (c) 1987-2016 by the citadel.org team
5 // This program is open source software. Use, duplication, and/or
6 // disclosure are subject to the GNU General Purpose License version 3.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
13 #include "textclient.h"
15 #define MIN(a, b) ((a) < (b) ? (a) : (b))
18 char last_paged[SIZ] = "";
20 void chatmode(CtdlIPC *ipc) {
27 int send_complete_line;
36 CtdlIPC_chat_send(ipc, "RCHT enter");
37 CtdlIPC_chat_recv(ipc, buf);
39 scr_printf("%s\n", &buf[4]);
42 scr_printf("Entering chat mode (type /quit to exit)\n");
46 strcpy(last_user, "");
50 send_complete_line = 0;
58 retval = select(1, &rfds, NULL, NULL, &tv);
62 scr_printf("Server gone Exiting chat mode\n");
67 /* If there's data from the keyboard... */
68 if (FD_ISSET(0, &rfds)) {
69 ch = scr_getc(SCR_BLOCK);
70 if ((ch == 10) || (ch == 13)) {
71 send_complete_line = 1;
72 } else if ((ch == 8) || (ch == 127)) {
73 if (!IsEmptyStr(wbuf)) {
74 wbuf[strlen(wbuf) - 1] = 0;
75 scr_printf("%c %c", 8, 8);
79 wbuf[strlen(wbuf) + 1] = 0;
80 wbuf[strlen(wbuf)] = ch;
84 /* if the user hit return, send the line */
85 if (send_complete_line) {
87 if (!strcasecmp(wbuf, "/quit")) {
88 CtdlIPC_chat_send(ipc, "RCHT exit");
89 CtdlIPC_chat_recv(ipc, response); /* don't care about the result */
91 scr_printf("\rExiting chat mode\n");
96 CtdlIPC_chat_send(ipc, "RCHT send");
97 CtdlIPC_chat_recv(ipc, response);
98 if (response[0] == '4') {
99 CtdlIPC_chat_send(ipc, wbuf);
100 CtdlIPC_chat_send(ipc, "000");
103 send_complete_line = 0;
106 /* if it's time to word wrap, send a partial line */
107 if (strlen(wbuf) >= (77 - strlen(fullname))) {
109 for (a = 0; !IsEmptyStr(&wbuf[a]); ++a) {
114 CtdlIPC_chat_send(ipc, "RCHT send");
115 CtdlIPC_chat_recv(ipc, response);
116 if (response[0] == '4') {
117 CtdlIPC_chat_send(ipc, wbuf);
118 CtdlIPC_chat_send(ipc, "000");
121 send_complete_line = 0;
124 CtdlIPC_chat_send(ipc, "RCHT send");
125 CtdlIPC_chat_recv(ipc, response);
126 if (response[0] == '4') {
127 CtdlIPC_chat_send(ipc, wbuf);
128 CtdlIPC_chat_send(ipc, "000");
130 strcpy(wbuf, &wbuf[pos + 1]);
134 /* poll for incoming chat messages */
135 snprintf(buf, sizeof buf, "RCHT poll|%d", seq);
136 CtdlIPC_chat_send(ipc, buf);
137 CtdlIPC_chat_recv(ipc, response);
139 if (response[0] == '1') {
140 seq = extract_int(&response[4], 0);
141 extract_token(c_user, &response[4], 2, '|', sizeof c_user);
142 while (CtdlIPC_chat_recv(ipc, c_text), strcmp(c_text, "000")) {
143 scr_printf("\r%79s\r", "");
144 if (!strcmp(c_user, fullname)) {
145 color(BRIGHT_YELLOW);
146 } else if (!strcmp(c_user, ":")) {
151 if (strcmp(c_user, last_user)) {
152 snprintf(buf, sizeof buf, "%s: %s", c_user, c_text);
154 size_t i = MIN(sizeof buf - 1, strlen(c_user) + 2);
156 safestrncpy(&buf[i], c_text, sizeof buf - i);
158 while (strlen(buf) < 79) {
161 if (strcmp(c_user, last_user)) {
162 scr_printf("\r%79s\n", "");
163 strcpy(last_user, c_user);
165 scr_printf("\r%s\n", buf);
169 color(BRIGHT_YELLOW);
170 scr_printf("\r> %s", wbuf);
177 // send an instant message
178 void page_user(CtdlIPC * ipc) {
179 char buf[SIZ], touser[SIZ], msg[SIZ];
182 strcpy(touser, last_paged);
183 strprompt("Page who", touser, 30);
185 snprintf(buf, sizeof buf, "SEXP %s||", touser);
186 CtdlIPC_chat_send(ipc, buf);
187 CtdlIPC_chat_recv(ipc, buf);
189 scr_printf("%s\n", &buf[4]);
192 if (client_make_message(ipc, temp, touser, 0, 0, 0, NULL, 0) != 0) {
193 scr_printf("No message sent.\n");
196 pagefp = fopen(temp, "r");
198 snprintf(buf, sizeof buf, "SEXP %s|-", touser);
199 CtdlIPC_chat_send(ipc, buf);
200 CtdlIPC_chat_recv(ipc, buf);
202 strcpy(last_paged, touser);
203 while (fgets(buf, sizeof buf, pagefp) != NULL) {
204 buf[strlen(buf) - 1] = 0;
205 CtdlIPC_chat_send(ipc, buf);
208 CtdlIPC_chat_send(ipc, "000");
209 scr_printf("Message sent.\n");
212 scr_printf("%s\n", &buf[4]);
217 void quiet_mode(CtdlIPC * ipc)
219 static int quiet = 0;
223 r = CtdlIPCEnableInstantMessageReceipt(ipc, !quiet, cret);
226 scr_printf("Quiet mode %sabled (%sother users may page you)\n", (quiet) ? "en" : "dis", (quiet) ? "no " : "");
228 scr_printf("Unable to change quiet mode: %s\n", cret);
233 void stealth_mode(CtdlIPC * ipc)
235 static int stealth = 0;
239 r = CtdlIPCStealthMode(ipc, !stealth, cret);
242 scr_printf("Stealth mode %sabled (you are %s)\n",
243 (stealth) ? "en" : "dis", (stealth) ? "invisible" : "listed as online");
245 scr_printf("Unable to change stealth mode: %s\n", cret);