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, or disclosure is subject to the GNU General Public License version 3.
7 #include "textclient.h"
9 #define MIN(a, b) ((a) < (b) ? (a) : (b))
12 char last_paged[SIZ] = "";
14 void chatmode(CtdlIPC * ipc) {
21 int send_complete_line;
30 CtdlIPC_chat_send(ipc, "RCHT enter");
31 CtdlIPC_chat_recv(ipc, buf);
33 scr_printf("%s\n", &buf[4]);
36 scr_printf("Entering chat mode (type /quit to exit)\n");
40 strcpy(last_user, "");
44 send_complete_line = 0;
52 retval = select(1, &rfds, NULL, NULL, &tv);
56 scr_printf("Server gone Exiting chat mode\n");
61 /* If there's data from the keyboard... */
62 if (FD_ISSET(0, &rfds)) {
63 ch = scr_getc(SCR_BLOCK);
64 if ((ch == 10) || (ch == 13)) {
65 send_complete_line = 1;
67 else if ((ch == 8) || (ch == 127)) {
68 if (!IsEmptyStr(wbuf)) {
69 wbuf[strlen(wbuf) - 1] = 0;
70 scr_printf("%c %c", 8, 8);
75 wbuf[strlen(wbuf) + 1] = 0;
76 wbuf[strlen(wbuf)] = ch;
80 /* if the user hit return, send the line */
81 if (send_complete_line) {
83 if (!strcasecmp(wbuf, "/quit")) {
84 CtdlIPC_chat_send(ipc, "RCHT exit");
85 CtdlIPC_chat_recv(ipc, response); /* don't care about the result */
87 scr_printf("\rExiting chat mode\n");
92 CtdlIPC_chat_send(ipc, "RCHT send");
93 CtdlIPC_chat_recv(ipc, response);
94 if (response[0] == '4') {
95 CtdlIPC_chat_send(ipc, wbuf);
96 CtdlIPC_chat_send(ipc, "000");
99 send_complete_line = 0;
102 /* if it's time to word wrap, send a partial line */
103 if (strlen(wbuf) >= (77 - strlen(fullname))) {
105 for (a = 0; !IsEmptyStr(&wbuf[a]); ++a) {
110 CtdlIPC_chat_send(ipc, "RCHT send");
111 CtdlIPC_chat_recv(ipc, response);
112 if (response[0] == '4') {
113 CtdlIPC_chat_send(ipc, wbuf);
114 CtdlIPC_chat_send(ipc, "000");
117 send_complete_line = 0;
121 CtdlIPC_chat_send(ipc, "RCHT send");
122 CtdlIPC_chat_recv(ipc, response);
123 if (response[0] == '4') {
124 CtdlIPC_chat_send(ipc, wbuf);
125 CtdlIPC_chat_send(ipc, "000");
127 strcpy(wbuf, &wbuf[pos + 1]);
131 /* poll for incoming chat messages */
132 snprintf(buf, sizeof buf, "RCHT poll|%d", seq);
133 CtdlIPC_chat_send(ipc, buf);
134 CtdlIPC_chat_recv(ipc, response);
136 if (response[0] == '1') {
137 seq = extract_int(&response[4], 0);
138 extract_token(c_user, &response[4], 2, '|', sizeof c_user);
139 while (CtdlIPC_chat_recv(ipc, c_text), strcmp(c_text, "000")) {
140 scr_printf("\r%79s\r", "");
141 if (!strcmp(c_user, fullname)) {
142 color(BRIGHT_YELLOW);
144 else if (!strcmp(c_user, ":")) {
150 if (strcmp(c_user, last_user)) {
151 snprintf(buf, sizeof buf, "%s: %s", c_user, c_text);
154 size_t i = MIN(sizeof buf - 1, strlen(c_user) + 2);
156 strncpy(&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) {
218 static int quiet = 0;
222 r = CtdlIPCEnableInstantMessageReceipt(ipc, !quiet, cret);
225 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) {
234 static int stealth = 0;
238 r = CtdlIPCStealthMode(ipc, !stealth, cret);
241 scr_printf("Stealth mode %sabled (you are %s)\n",
242 (stealth) ? "en" : "dis", (stealth) ? "invisible" : "listed as online");
245 scr_printf("Unable to change stealth mode: %s\n", cret);