Ejemplo n.º 1
0
static void dochatcommand(char *cmd)
{
	char *para;

	strtok(cmd, " \n");
	if ((para = strtok(NULL, "\n")) == NULL)
		para = cmd + strlen(cmd);

	if (*cmd == 'h')
	{
		printchatline(_msg_chat_41);
		printchatline("  /leave                  - Â÷¶}¥»ÀW¹D            [/le]");
		if (curuser.userlevel >= PERM_CLOAK)
			printchatline("  /cloak                  - Áô¨­                  [/cl]");
		printchatline(_msg_chat_43);
		return;
	}
	else if (!strcmp(cmd, "who") || !strcmp(cmd, "w"))
	{
		dowho(para, ac);
		return;
	}
	else if (!strcmp(cmd, "ws") || !strcmp(cmd, "whoall"))
	{
		dowhoall(ac);
		return;
	}
	else if (!strcmp(cmd, "list") || !strcmp(cmd, "l"))
	{
		dolist(ac);
		return;
	}
	else if (!strcmp(cmd, "leave") || !strcmp(cmd, "le"))
	{
		net_printf(ac, "JOIN\t%s\t%s\r\n", DEFAULT_CHANNAME, NOPASSWORD);
	}
	else if (!strcmp(cmd, "nopasswd") || !strcmp(cmd, "nps"))
	{
		net_printf(ac, "PASSWD\t%s\r\n", NOPASSWORD);
	}
	else if (!strcmp(cmd, "nick") || !strcmp(cmd, "n"))
	{

		fixchatid(para);

		net_printf(ac, "NICKNAME\t%s\r\n", para);
		net_gets(ac, genbuf, sizeof(genbuf));
		if (!strncmp(genbuf, "-ERR", 4))
			printchatline(genbuf + 5);
		else
		{
			xstrncpy(uinfo.chatid, para, sizeof(uinfo.chatid));
			update_ulist(cutmp, &uinfo);

			/* set prompt */
			strcpy(prompt, uinfo.chatid);
			strcat(prompt, ":           ");
			prompt[SAYWORD_POINT] = '\0';
		}
		return;
	}
	else if (!strcmp(cmd, "me"))
	{
		if (*para)
		{
			sprintf(genbuf, "*** %s ***", para);
			net_printf(ac, "SPEAK\t%s\r\n", genbuf);
			printchatline(genbuf);
		}
		else
			printchatline(_msg_chat_45);
		return;
	}
	else if (!strcmp(cmd, "pager") || !strcmp(cmd, "p"))
	{
#if 1
		add_io(0, 0);
#endif
		toggle_pager();
		printchatline(pagerstring(&uinfo));
#if 1
		add_io(ac, 0);
#endif
		return;
	}
	else if (!strcmp(cmd, "cloak") || !strcmp(cmd, "cl"))
	{
		if (HAS_PERM(PERM_CLOAK))
		{
			net_printf(ac, "CLOAK\r\n");
			net_gets(ac, genbuf, sizeof(genbuf));
			if (!strncmp(genbuf, "-ERR", 4))
				printchatline(genbuf + 5);
			else
			{
				uinfo.invisible = (uinfo.invisible) ? FALSE : TRUE;
				update_ulist(cutmp, &uinfo);
				if (!uinfo.invisible)
					printchatline("*** Cloak has been deactivated");
				else
					printchatline("*** Cloak has been activated");
			}
		}
		else
			printchatline("*** ERROR: unknown special chat command");
		return;
	}
	else if (!strcmp(cmd, "clear") || !strcmp(cmd, "c"))
	{
		clear();
		move(ECHATWIN, 0);
		outs("________________________________________________________________________________");
		chat_line = 0;	/* reset */
		printchatline(_msg_chat_46);
		return;
	}
	else if (!strcmp(cmd, "ignore") || !strcmp(cmd, "i"))
	{
		if (*para)
		{
			if (strlen(para) >= IDLEN)
				para[IDLEN - 1] = '\0';
			if (!cmp_wlist(iglist, para, strcmp))
			{
				sprintf(genbuf, _msg_chat_37, para);
				printchatline(genbuf);
				add_wlist(&iglist, para, malloc_str);
			}
		}
		return;
	}
	else if (!strcmp(cmd, "unignore") || !strcmp(cmd, "ui"))
	{
		if (*para)
		{
			if (strlen(para) >= IDLEN)
				para[IDLEN - 1] = '\0';
			if (cmp_wlist(iglist, para, strcmp))
			{
				sprintf(genbuf, _msg_chat_36, para);
				printchatline(genbuf);
				cmpd_wlist(&iglist, para, strcmp, free);
			}
		}
		return;
	}
	else if (!strcmp(cmd, "j") || !strcmp(cmd, "join"))
	{
		char *para2;

		para = strtok(para, " \n");
		if (!para)
			return;

		para2 = strtok(NULL, " \n");
		if (!para2)
			net_printf(ac, "JOIN\t%s\t%s\r\n", para, NOPASSWORD);
		else
			net_printf(ac, "JOIN\t%s\t%s\r\n", para, para2);
	}
	else if (!strcmp(cmd, "m") || !strcmp(cmd, "msg"))
	{
		char *para2;

		para = strtok(para, " \n");
		para2 = strtok(NULL, "");
		if (!para || !para2)
			return;

		net_printf(ac, "MSG\t%s\t%s\r\n", para, para2);
	}
	else if (!strcmp(cmd, "t") || !strcmp(cmd, "topic"))
	{
		net_printf(ac, "TOPIC\t%s\r\n", para);
	}
	else if (!strcmp(cmd, "ps") || !strcmp(cmd, "passwd"))
	{
		net_printf(ac, "PASSWD\t%s\r\n", para);
	}
	else
	{
		printchatline("*** ERROR: unknown special chat command");
		return;
	}

	net_gets(ac, genbuf, sizeof(genbuf));
	if (!strncmp(genbuf, "-ERR", 4))
	{
		genbuf[strlen(genbuf) - 1] = '\0';
		printchatline(genbuf + 5);
	}
}
Ejemplo n.º 2
0
Archivo: io.c Proyecto: chage/formosa
int igetch()
{
#ifdef _BBS_UTIL_
igetagain:
	if (ibufsize == icurrchar)
	{
		fd_set readfds;
		int sr;

		FD_ZERO(&readfds);
		FD_SET(0, &readfds);
		refresh();
		while ((sr = select(16, &readfds, NULL, NULL, NULL)) < 0)	/* bug fixed */
		{
			if (errno == EINTR)
				continue;
			else
			{
				perror("select");
				fprintf(stderr, "abnormal select conditions\n");
				return -1;
			}
		}
		while ((ibufsize = read(0, inbuf, IBUFSIZE)) <= 0)
		{
			if (ibufsize < 0 && errno == EINTR)
				continue;
			exit(0);
		}
		icurrchar = 0;
	}

	if (inbuf[icurrchar] == CTRL('L'))
	{
#ifdef USE_PFTERM
		redrawwin();
		refresh();
#else
		redoscr();
#endif
		icurrchar++;
		goto igetagain;
	}
/*
	else if (inbuf[icurrchar] == 0x0d)
	{
		icurrchar++;
		return '\n';
	}
*/
	return inbuf[icurrchar++];
#else
      igetagain:
	if (ibufsize == icurrchar)
	{
		int sr;
		struct pollfd pd[2];
		char npd;

#if 1	/* !! TEST !! */
		if (dumb_term)
			oflush();
		else
			refresh();
#endif
		if (flushf)
			(*flushf) ();

		pd[0].fd = 0;
		pd[0].events = POLLIN;
		pd[1].events = POLLIN;
		for (;;)
		{
			pd[0].revents = 0;
			if (i_newfd)
			{
				npd = 2;
				pd[1].fd = i_newfd;
				pd[1].revents = 0;
			}
			else
				npd = 1;
			sr = poll(pd, npd, 60000);
			if (sr < 0)
			{
				if (errno != EINTR)
				{
					perror("select");
					fprintf(stderr, "abnormal select conditions\n");
					return -1;
				}
			}
			else if (sr == 0)
			{
				if (i_top == &i_to)
					return I_TIMEOUT;
				if (uinfo.idle_time++ > IDLE_TIMEOUT)
				{
					if (!HAS_PERM(PERM_SYSOP))	/* lthuang */
					{
#ifdef BBSLOG_IDLEOUT
						bbsd_log_write("IDLEOUT", "%s", modestring(&uinfo, 0));
#endif
						clear();
						show_byebye(TRUE);
						refresh();
						abort_bbs(0);
					}
				}
				update_ulist(cutmp, &uinfo);
			}
			else
				break;
		}	/* for loop */
		if (i_newfd && (pd[1].events & pd[1].revents))
			return I_OTHERDATA;
		if (!(pd[0].events & pd[0].revents))
			goto igetagain;

		int len;
		do {
			len = tty_read(inbuf, IBUFSIZE);
#ifdef DBG_OUTRPT
			// if (0)
			{
				static char xbuf[128];
				sprintf(xbuf, ESC_STR "[s" ESC_STR "[2;1H [%ld] "
					ESC_STR "[u", len);
				write(1, xbuf, strlen(xbuf));
				fsync(1);
			}
#endif

		} while (len <= 0);
		ibufsize = len;

		icurrchar = 0;
	}

	i_top->tv_sec = 60;
	if(uinfo.idle_time)
	{
		uinfo.idle_time &= ~(uinfo.idle_time);
		update_ulist(cutmp, &uinfo);
	}

	if (inbuf[icurrchar] == CTRL('L'))
	{
		redoscr();
		icurrchar++;
		goto igetagain;
	}
	else if (inbuf[icurrchar] == 0x0d)
	{
		icurrchar++;
		if (init_enter)
		{
			if (two_enter)
				press_enter++;
			return KEY_ENTER;
		}
		else
		{
			press_enter++;
			return KEY_ENTER;
		}
	}
	else
	{
		if (press_enter)
		{
			if (init_enter)
			{
				press_enter &= ~press_enter;
				if (inbuf[icurrchar] == '\0' || inbuf[icurrchar] == 0x0a)
				{
					icurrchar++;
					goto igetagain;
				}
			}
			else
			{
				init_enter++;
				press_enter &= ~press_enter;
				if (inbuf[icurrchar] == '\0' || inbuf[icurrchar] == 0x0a)
				{
					two_enter++;
					icurrchar++;
					goto igetagain;
				}
				else
					two_enter &= ~two_enter;
			}
		}
	}
	return inbuf[icurrchar++];
#endif	/* !_BBS_UTIL_ */
}
Ejemplo n.º 3
0
int t_chat2()
{
	int currchar;
	char inbuf[120];
	BOOL page_pending = FALSE;
	int ch;
	char seedstr[STRLEN];
	long seed;
	char rcvbuf[512];
	int chatport;
	char *mycrypt();


	if (check_page_perm() < 0)
		return C_FOOT;

	chatport = CHATPORT;
#if 1
	if (chatport == 0)
		chatport = 6177;
#endif

#if 0
#if	defined(NSYSUBBS1)
	getdata(1, 0, _msg_chat_1, genbuf, 2, ECHONOSP);
	if (genbuf[0] == '2')
		chatport = CHATPORT + 1;
#endif
#endif

	/* initialize */
	inbuf[0] = '\0';
	currchar = 0;
	chat_line = 0;

	if (!getdata(1, 0, "Enter Chat id: ", mychatid, CHATIDLEN, ECHONOSP))
		xstrncpy(mychatid, curuser.userid, CHATIDLEN);

	fixchatid(mychatid);

	if ((ac = ConnectServer(CHAT_SERVER, chatport)) < 0)
	{
		move(2, 0);
		outs(_msg_chat_3);
		refresh();
		sprintf(genbuf, "bbschatd %d", chatport);
		outdoor(genbuf);
		sleep(2);
		if ((ac = ConnectServer(CHAT_SERVER, chatport)) < 0)
		{
			perror("connect failed");
			pressreturn();
			return C_FULL;
		}
	}

	/* receive ChatServer Hello Welcome VersionInfo */
	net_gets(ac, genbuf, sizeof(genbuf));
	/* receive Random Number for Checksum */
	net_gets(ac, seedstr, sizeof(seedstr));
	seed = atol(mycrypt(seedstr));
	net_printf(ac, "USRID\t%s\t%ld\r\n", curuser.userid, seed);
	net_gets(ac, genbuf, sizeof(genbuf));
	if (strncmp(genbuf, "+OK", 3))	/* lthuang */
	{
		outs(_msg_chat_4);
		pressreturn();
		return C_FULL;
	}

	uinfo.mode = CHATROOM;
	xstrncpy(uinfo.chatid, mychatid, sizeof(uinfo.chatid));
	update_ulist(cutmp, &uinfo);

	/* set prompt */
	strcpy(prompt, mychatid);
	strcat(prompt, ":           ");
	prompt[SAYWORD_POINT] = '\0';

	draw_chat_screen();

	add_io(ac, 0);

	net_gets(ac, genbuf, sizeof(genbuf));	/* welcome !! */
	genbuf[strlen(genbuf) - 1] = '\0';
	printchatline(genbuf);
#if 0
	net_printf(ac, "JOIN\t%s\t%s\r\n", DEFAULT_CHANNAME, NOPASSWORD);
	net_gets(ac, genbuf, sizeof(genbuf));
#endif
	if (strcmp(mychatid, curuser.userid))
	{
		net_printf(ac, "NICKNAME\t%s\r\n", mychatid);
		net_gets(ac, genbuf, sizeof(genbuf));
	}

	/* Chat Main */
	while (1)
	{
		ch = getkey();
		if (PLINE != CUR_PLINE) {
			draw_chat_screen();
			continue;
		}
		if (talkrequest)
			page_pending = TRUE;
		if (page_pending)
			page_pending = servicepage(0);
		if (msqrequest)
		{
			add_io(0, 0);
			msqrequest = FALSE;
			msq_reply();
			add_io(ac, 0);
			continue;
		}

		if (ch == I_OTHERDATA)
		{
			if (!net_gets(ac, rcvbuf, sizeof(rcvbuf)))
				break;
			rcvbuf[strlen(rcvbuf) - 1] = '\0';	/* lthuang */
			if (rcvbuf[0] == '/')
			{
				char *p, *nick;

				if ((p = strchr(rcvbuf, '\t')) != NULL)
				{
					*p = '\0';
					if (cmp_wlist(iglist, rcvbuf + 1, strcmp))
						continue;

					nick = p + 1;
					if ((p = strchr(nick, '\t')) != NULL)
					{
						*p = '\0';

						if (cmp_wlist(iglist, nick, strcmp))
							continue;

						strcpy(genbuf, nick);
						strcat(genbuf, ":           ");
						genbuf[SAYWORD_POINT] = '\0';
						strcat(genbuf, ++p);
						printchatline(genbuf);
					}
				}
			}
#if 0
			else if (rcvbuf[0] == '*')
			{
				sprintf(genbuf, "%s", rcvbuf);
				printchatline(genbuf);
			}
#endif
			else
				printchatline(rcvbuf);
		}
		else if (isprint2(ch))
		{
			if (SAYWORD_POINT + currchar - 1 >= t_columns - 3)
			{
				bell();
				continue;
			}
			inbuf[currchar++] = ch;
			inbuf[currchar] = '\0';
			move(PLINE, SAYWORD_POINT + currchar - 1);
			outc(ch);
		}
		else if (ch == '\n' || ch == '\r')
		{
			char *p = inbuf;

			currchar = 0;

			while (*p != '\0' && isspace((int)(*p)))
				p++;
			if (*p == '\0')
				continue;
			if (inbuf[0] == '/')
				dochatcommand(inbuf + 1);
			else
			{
				net_printf(ac, "SPEAK\t%s\r\n", inbuf);
				sprintf(genbuf, "%s%s", prompt, inbuf);
				printchatline(genbuf);
			}

			inbuf[0] = '\0';

			/* show prompt */
			move(PLINE, 0);
			clrtoeol();
			outs(prompt);
		}
		else if (ch == CTRL('H') || ch == '\177')
		{
			if (currchar == 0)
			{
				bell();
				continue;
			}
			move(PLINE, SAYWORD_POINT + --currchar);
			outs(" ");
			inbuf[currchar] = '\0';
		}
		else if (ch == CTRL('C') || ch == CTRL('D'))
		{
			net_printf(ac, "QUIT\r\n");	/* lthuang */
			break;
		}
		else if (ch == CTRL('R'))
		{
			msq_reply();
			continue;
		}
		else if (ch == CTRL('Q'))
		{
			add_io(0, 0);
			t_query();
			add_io(ac, 0);
			continue;
		}
		move(PLINE, currchar + SAYWORD_POINT);
	}
	add_io(0, 0);
	close(ac);
	uinfo.chatid[0] = '\0';
	update_ulist(cutmp, &uinfo);
	free_wlist(&iglist, free);

	return C_FULL;
}
Ejemplo n.º 4
0
void update_utmp()
{
    update_ulist(&uinfo, utmpent);
}