예제 #1
0
파일: board.c 프로젝트: foxfair/formosa
int namecomplete_board(BOARDHEADER *bhp, char *data, BOOL simple)
{
	struct word *bwtop = NULL;
	int i;


	if (!num_brds)
	{
		CreateBoardList(&curuser);
		if (num_brds <= 0)
			return -1;
	}
	if (!simple)
	{
		move(1, 0);
		clrtobot();
		move(2, 0);
		outs(_msg_board_5);
		move(1, 0);
		outs(_msg_board_6);
	}
	for (i = 0; i < num_brds; i++)
		add_wlist(&bwtop, (all_brds[i].bhr)->filename, NULL);
	namecomplete(bwtop, data, simple);
	free_wlist(&bwtop, NULL);
	if (data[0] == '\0')
		return -1;
	if (bhp)
		return get_board(bhp, data);
	return 0;
}
예제 #2
0
파일: chat2.c 프로젝트: PichuChen/formosa
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;
}