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.
15 #include "textclient.h"
17 #define MIN(a, b) ((a) < (b) ? (a) : (b))
20 char last_paged[SIZ] = "";
22 void chatmode(CtdlIPC *ipc)
30 int send_complete_line;
39 CtdlIPC_chat_send(ipc, "RCHT enter");
40 CtdlIPC_chat_recv(ipc, buf);
42 scr_printf("%s\n", &buf[4]);
45 scr_printf("Entering chat mode (type /quit to exit)\n");
49 strcpy(last_user, "");
53 send_complete_line = 0;
61 retval = select(1, &rfds, NULL, NULL, &tv);
65 scr_printf("Server gone Exiting chat mode\n");
70 /* If there's data from the keyboard... */
71 if (FD_ISSET(0, &rfds)) {
72 ch = scr_getc(SCR_BLOCK);
73 if ((ch == 10) || (ch == 13)) {
74 send_complete_line = 1;
75 } else if ((ch == 8) || (ch == 127)) {
76 if (!IsEmptyStr(wbuf)) {
77 wbuf[strlen(wbuf) - 1] = 0;
78 scr_printf("%c %c", 8, 8);
82 wbuf[strlen(wbuf) + 1] = 0;
83 wbuf[strlen(wbuf)] = ch;
87 /* if the user hit return, send the line */
88 if (send_complete_line) {
90 if (!strcasecmp(wbuf, "/quit")) {
91 CtdlIPC_chat_send(ipc, "RCHT exit");
92 CtdlIPC_chat_recv(ipc, response); /* don't care about the result */
94 scr_printf("\rExiting chat mode\n");
99 CtdlIPC_chat_send(ipc, "RCHT send");
100 CtdlIPC_chat_recv(ipc, response);
101 if (response[0] == '4') {
102 CtdlIPC_chat_send(ipc, wbuf);
103 CtdlIPC_chat_send(ipc, "000");
106 send_complete_line = 0;
109 /* if it's time to word wrap, send a partial line */
110 if (strlen(wbuf) >= (77 - strlen(fullname))) {
112 for (a = 0; !IsEmptyStr(&wbuf[a]); ++a) {
117 CtdlIPC_chat_send(ipc, "RCHT send");
118 CtdlIPC_chat_recv(ipc, response);
119 if (response[0] == '4') {
120 CtdlIPC_chat_send(ipc, wbuf);
121 CtdlIPC_chat_send(ipc, "000");
124 send_complete_line = 0;
127 CtdlIPC_chat_send(ipc, "RCHT send");
128 CtdlIPC_chat_recv(ipc, response);
129 if (response[0] == '4') {
130 CtdlIPC_chat_send(ipc, wbuf);
131 CtdlIPC_chat_send(ipc, "000");
133 strcpy(wbuf, &wbuf[pos + 1]);
137 /* poll for incoming chat messages */
138 snprintf(buf, sizeof buf, "RCHT poll|%d", seq);
139 CtdlIPC_chat_send(ipc, buf);
140 CtdlIPC_chat_recv(ipc, response);
142 if (response[0] == '1') {
143 seq = extract_int(&response[4], 0);
144 extract_token(c_user, &response[4], 2, '|', sizeof c_user);
145 while (CtdlIPC_chat_recv(ipc, c_text), strcmp(c_text, "000")) {
146 scr_printf("\r%79s\r", "");
147 if (!strcmp(c_user, fullname)) {
148 color(BRIGHT_YELLOW);
149 } else if (!strcmp(c_user, ":")) {
154 if (strcmp(c_user, last_user)) {
155 snprintf(buf, sizeof buf, "%s: %s", c_user, c_text);
157 size_t i = MIN(sizeof buf - 1, strlen(c_user) + 2);
159 safestrncpy(&buf[i], c_text, sizeof buf - i);
161 while (strlen(buf) < 79) {
164 if (strcmp(c_user, last_user)) {
165 scr_printf("\r%79s\n", "");
166 strcpy(last_user, c_user);
168 scr_printf("\r%s\n", buf);
172 color(BRIGHT_YELLOW);
173 scr_printf("\r> %s", wbuf);
181 * send an instant message
183 void page_user(CtdlIPC *ipc)
185 char buf[SIZ], touser[SIZ], msg[SIZ];
188 strcpy(touser, last_paged);
189 strprompt("Page who", touser, 30);
191 /* old server -- use inline paging */
192 if (ipc->ServInfo.paging_level == 0) {
193 newprompt("Message: ", msg, 69);
194 snprintf(buf, sizeof buf, "SEXP %s|%s", touser, msg);
195 CtdlIPC_chat_send(ipc, buf);
196 CtdlIPC_chat_recv(ipc, buf);
197 if (!strncmp(buf, "200", 3)) {
198 strcpy(last_paged, touser);
200 scr_printf("%s\n", &buf[4]);
203 /* new server -- use extended paging */
204 else if (ipc->ServInfo.paging_level >= 1) {
205 snprintf(buf, sizeof buf, "SEXP %s||", touser);
206 CtdlIPC_chat_send(ipc, buf);
207 CtdlIPC_chat_recv(ipc, buf);
209 scr_printf("%s\n", &buf[4]);
212 if (client_make_message(ipc, temp, touser, 0, 0, 0, NULL, 0) != 0) {
213 scr_printf("No message sent.\n");
216 pagefp = fopen(temp, "r");
218 snprintf(buf, sizeof buf, "SEXP %s|-", touser);
219 CtdlIPC_chat_send(ipc, buf);
220 CtdlIPC_chat_recv(ipc, buf);
222 strcpy(last_paged, touser);
223 while (fgets(buf, sizeof buf, pagefp) != NULL) {
224 buf[strlen(buf) - 1] = 0;
225 CtdlIPC_chat_send(ipc, buf);
228 CtdlIPC_chat_send(ipc, "000");
229 scr_printf("Message sent.\n");
231 scr_printf("%s\n", &buf[4]);
237 void quiet_mode(CtdlIPC *ipc)
239 static int quiet = 0;
243 r = CtdlIPCEnableInstantMessageReceipt(ipc, !quiet, cret);
246 scr_printf("Quiet mode %sabled (%sother users may page you)\n",
247 (quiet) ? "en" : "dis",
248 (quiet) ? "no " : "");
250 scr_printf("Unable to change quiet mode: %s\n", cret);
255 void stealth_mode(CtdlIPC *ipc)
257 static int stealth = 0;
261 r = CtdlIPCStealthMode(ipc, !stealth, cret);
264 scr_printf("Stealth mode %sabled (you are %s)\n",
265 (stealth) ? "en" : "dis",
266 (stealth) ? "invisible" : "listed as online");
268 scr_printf("Unable to change stealth mode: %s\n", cret);