Exemple #1
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;
}
Exemple #2
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);
	}
}
Exemple #3
0
/*
 * 列印? Index List Lines
 */
void read_entry(int x, void *ent, int idx, int top, int last, int rows)
{
	register int num, len;
	int score;
	unsigned char *str;
	static char chdate[9];
	time_t date;
	struct tm *tm;
	register unsigned char type;
	FILEHEADER *fhr = &(((FILEHEADER *) ent)[top - idx]);

	for (num = top; num <= last && (num - top) < rows; num++, fhr++)
	{
		chk_str(fhr->title);
		chk_str(fhr->owner);

		/* by lmj */
		date = atol((fhr->filename) + 2);
		if (!date)
			sprintf(chdate, "%-8.8s", "unknown");
		else
		{
			tm = localtime(&date);
			sprintf(chdate, "%02d.%02d.%02d",
				tm->tm_year - 11, tm->tm_mon + 1, tm->tm_mday);
		}

		type = fhr->accessed;

		if (in_mail)
		{
			if (type & FILE_RESV)
				type = (type & FILE_READ) ? 'g' : 'G';
			else if (type & FILE_DELE)
				type = (type & FILE_READ) ? 'd' : 'D';
			else if (type & FILE_REPD)
				type = 'r';
			else
				type = (type & FILE_READ) ? ' ' : 'N';
		}
		else if (in_board)
		{
			if (type & FILE_RESV)
				type = (ReadRC_UnRead(fhr)) ? 'G' : 'g';
			else if (type & FILE_DELE)
				type = (ReadRC_UnRead(fhr)) ? 'D' : 'd';
			else {
				switch (ReadRC_UnRead(fhr)) {
				case UNREAD_NEW:
					type = 'N';
					break;
				case UNREAD_MOD:
					type = 'M';
					break;
				default:
					type = ' ';
				}
			}
		}
		else
		{
			/* 若為精華區, 則皆視為已讀過 */
			type = ' ';
		}

		/* 顯示指標區域 */
		outs("   ");

		if (cmp_wlist(artwtop, fhr->filename, strcmp))
			prints("%4d*%c", num, type);
		else
			prints("%4d %c", num, type);

#if USE_THREAD
		if (thr_mode && !art_mode)
		{
			if (fhr->unused_int2 > 1 && fhr->unused_int2 < 10)
				prints(" %d ", fhr->unused_int2);
			else if (fhr->unused_int2 >= 10)
				prints(" %d", fhr->unused_int2);
			else
				outs("   ");
		}
		else
			outs("   ");
#else
		score = get_pushcnt(fhr);
		if (score != PUSH_FIRST) {
			if (score == SCORE_MAX)
				prints("\033[1;31m\xA1\xDB\033[m");
			else if (score > 0)
				prints("\033[1;31m%2.2X\033[m", score);
			else if (score == SCORE_MIN)
				prints("\033[32m\xA3\x58\033[m");
			else if (score < 0)
				prints("\033[32m%2.2X\033[m", 0 - score);
			else
				prints("\033[1;33m 0\033[m");
		} else {
			outs("  ");
		}
#endif

		/* if treausure sub-folder */
		if (fhr->accessed & FILE_TREA)
			prints("  %-11.11s", _msg_read_4);
		else
		{
			len = 11;
			if (curuser.ident == 7 && fhr->ident == 7) {
				outs(_str_marker);
			} else if (fhr->owner[0] == '#') {
				len = 12;
				outs(" ");
			} else {
				outs("  ");
			}

			str = (unsigned char *)fhr->owner;
			while (len > 0 && *str && *str != '@' && *str != '.')
			{
				outc(*str++);
				len--;
			}
			while (len-- > 0)
				outc(' ');
		}

		outs(" ");
		outs(chdate);
		outs(" ");

		if (type == 'd' || type == 'D')
			prints(_msg_read_7, fhr->delby);
		else
		{
			if (memtitle[0] && !strcmp(fhr->title, memtitle))
				outs("#");
			else if (memtitle[0] && !strcmp(fhr->title, memtitle + REPLY_LEN))
				outs("#");
			else
				outs(" ");
#if USE_THREAD
			len = 40;
#else
			len = 42;
#endif
			str = (unsigned char *)fhr->title;
			while (len-- > 0 && *str)
				outc(*str++);
/*
			if (len == -1 && *(str - 1) > 0x80)
				outc(*str);
*/
			outs("");
		}

		outs("\n");
	}
}