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;
73 else if ((ch == 8) || (ch == 127)) {
74 if (!IsEmptyStr(wbuf)) {
75 wbuf[strlen(wbuf) - 1] = 0;
76 scr_printf("%c %c", 8, 8);
81 wbuf[strlen(wbuf) + 1] = 0;
82 wbuf[strlen(wbuf)] = ch;
86 /* if the user hit return, send the line */
87 if (send_complete_line) {
89 if (!strcasecmp(wbuf, "/quit")) {
90 CtdlIPC_chat_send(ipc, "RCHT exit");
91 CtdlIPC_chat_recv(ipc, response); /* don't care about the result */
93 scr_printf("\rExiting chat mode\n");
98 CtdlIPC_chat_send(ipc, "RCHT send");
99 CtdlIPC_chat_recv(ipc, response);
100 if (response[0] == '4') {
101 CtdlIPC_chat_send(ipc, wbuf);
102 CtdlIPC_chat_send(ipc, "000");
105 send_complete_line = 0;
108 /* if it's time to word wrap, send a partial line */
109 if (strlen(wbuf) >= (77 - strlen(fullname))) {
111 for (a = 0; !IsEmptyStr(&wbuf[a]); ++a) {
116 CtdlIPC_chat_send(ipc, "RCHT send");
117 CtdlIPC_chat_recv(ipc, response);
118 if (response[0] == '4') {
119 CtdlIPC_chat_send(ipc, wbuf);
120 CtdlIPC_chat_send(ipc, "000");
123 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);
150 else if (!strcmp(c_user, ":")) {
156 if (strcmp(c_user, last_user)) {
157 snprintf(buf, sizeof buf, "%s: %s", c_user, c_text);
160 size_t i = MIN(sizeof buf - 1, strlen(c_user) + 2);
162 strncpy(&buf[i], c_text, sizeof buf - i);
164 while (strlen(buf) < 79) {
167 if (strcmp(c_user, last_user)) {
168 scr_printf("\r%79s\n", "");
169 strcpy(last_user, c_user);
171 scr_printf("\r%s\n", buf);
175 color(BRIGHT_YELLOW);
176 scr_printf("\r> %s", wbuf);
183 // send an instant message
184 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 snprintf(buf, sizeof buf, "SEXP %s||", touser);
192 CtdlIPC_chat_send(ipc, buf);
193 CtdlIPC_chat_recv(ipc, buf);
195 scr_printf("%s\n", &buf[4]);
198 if (client_make_message(ipc, temp, touser, 0, 0, 0, NULL, 0) != 0) {
199 scr_printf("No message sent.\n");
202 pagefp = fopen(temp, "r");
204 snprintf(buf, sizeof buf, "SEXP %s|-", touser);
205 CtdlIPC_chat_send(ipc, buf);
206 CtdlIPC_chat_recv(ipc, buf);
208 strcpy(last_paged, touser);
209 while (fgets(buf, sizeof buf, pagefp) != NULL) {
210 buf[strlen(buf) - 1] = 0;
211 CtdlIPC_chat_send(ipc, buf);
214 CtdlIPC_chat_send(ipc, "000");
215 scr_printf("Message sent.\n");
218 scr_printf("%s\n", &buf[4]);
223 void quiet_mode(CtdlIPC * ipc) {
224 static int quiet = 0;
228 r = CtdlIPCEnableInstantMessageReceipt(ipc, !quiet, cret);
231 scr_printf("Quiet mode %sabled (%sother users may page you)\n", (quiet) ? "en" : "dis", (quiet) ? "no " : "");
234 scr_printf("Unable to change quiet mode: %s\n", cret);
239 void stealth_mode(CtdlIPC * ipc) {
240 static int stealth = 0;
244 r = CtdlIPCStealthMode(ipc, !stealth, cret);
247 scr_printf("Stealth mode %sabled (you are %s)\n",
248 (stealth) ? "en" : "dis", (stealth) ? "invisible" : "listed as online");
251 scr_printf("Unable to change stealth mode: %s\n", cret);