Skip to content
Snippets Groups Projects
js_bbs.cpp 108 KiB
Newer Older
rswindell's avatar
rswindell committed
	sbbs->multinodechat(channel);
rswindell's avatar
rswindell committed

	return(JS_TRUE);
}

js_private_message(JSContext *cx, uintN argc, jsval *arglist)
rswindell's avatar
rswindell committed
{
	sbbs_t*		sbbs;
deuce's avatar
deuce committed
	jsrefcount	rc;
	JS_SET_RVAL(cx, arglist, JSVAL_VOID);

	if((sbbs=js_GetPrivate(cx, JS_THIS_OBJECT(cx, arglist)))==NULL)
rswindell's avatar
rswindell committed
		return(JS_FALSE);

rswindell's avatar
rswindell committed
	sbbs->nodemsg();
rswindell's avatar
rswindell committed

	return(JS_TRUE);
}

js_private_chat(JSContext *cx, uintN argc, jsval *arglist)
	jsval *argv=JS_ARGV(cx, arglist);
rswindell's avatar
rswindell committed
	sbbs_t*		sbbs;
deuce's avatar
deuce committed
	jsrefcount	rc;
	JS_SET_RVAL(cx, arglist, JSVAL_VOID);

	if((sbbs=js_GetPrivate(cx, JS_THIS_OBJECT(cx, arglist)))==NULL)
rswindell's avatar
rswindell committed
		return(JS_FALSE);

	if(argc)
		JS_ValueToBoolean(cx,argv[0],&local);

	sbbs->privchat(local ? true:false);	// <- eliminates stupid msvc6 "performance warning"
rswindell's avatar
rswindell committed

	return(JS_TRUE);
}

js_get_node_message(JSContext *cx, uintN argc, jsval *arglist)
	jsval*		argv=JS_ARGV(cx, arglist);
rswindell's avatar
rswindell committed
	sbbs_t*		sbbs;
deuce's avatar
deuce committed
	jsrefcount	rc;
	JS_SET_RVAL(cx, arglist, JSVAL_VOID);

	if((sbbs=js_GetPrivate(cx, JS_THIS_OBJECT(cx, arglist)))==NULL)
rswindell's avatar
rswindell committed
		return(JS_FALSE);

	if(argc > 0 && JSVAL_IS_BOOLEAN(argv[0]))
		clearline = JSVAL_TO_BOOLEAN(argv[0]);

	sbbs->getnmsg(clearline ? true : false);
rswindell's avatar
rswindell committed

	return(JS_TRUE);
}

js_put_node_message(JSContext *cx, uintN argc, jsval *arglist)
	jsval *argv=JS_ARGV(cx, arglist);
rswindell's avatar
rswindell committed
	sbbs_t*		sbbs;
	int32		nodenum = 0;
rswindell's avatar
rswindell committed
	JSString*	js_msg;
	char*		msg = NULL;
	char 		str[256];
	char		tmp[512];
deuce's avatar
deuce committed
	jsrefcount	rc;
	JS_SET_RVAL(cx, arglist, JSVAL_FALSE);
	if((sbbs=js_GetPrivate(cx, JS_THIS_OBJECT(cx, arglist)))==NULL)
rswindell's avatar
rswindell committed
		return(JS_FALSE);

	/* Get the destination node number */
	if(argn < argc && JSVAL_IS_NUMBER(argv[argn])) {
		if(!JS_ValueToInt32(cx,argv[argn], &nodenum))
		argn++;
	} else {
		rc=JS_SUSPENDREQUEST(cx);
		nodenum = sbbs->getnodetopage(/* all: */TRUE, /* telegram: */FALSE);
		JS_RESUMEREQUEST(cx, rc);
	if(nodenum == 0)
		return JS_TRUE;
	int usernumber = 0;
	node_t node;
	if(nodenum >= 1) {	/* !all */
		sbbs->getnodedat(nodenum, &node, false);
		usernumber = node.useron;
		if((node.misc&NODE_POFF) && sbbs->useron.level < SYSOP_LEVEL) {
			sbbs->bprintf(sbbs->text[CantPageNode]
				, node.misc&NODE_ANON ? sbbs->text[UNKNOWN_USER] : username(&sbbs->cfg,node.useron,tmp));
			return JS_TRUE;
		}
	}
	/* Get the node message text */
	if(argn < argc) {
		if((js_msg = JS_ValueToString(cx, argv[argn])) == NULL)
			return JS_FALSE;
		argn++;
		JSSTRING_TO_MSTRING(cx, js_msg, msg, NULL);
	} else {
		if(nodenum >= 1)
			sbbs->bprintf(sbbs->text[SendingMessageToUser]
				,node.misc&NODE_ANON ? sbbs->text[UNKNOWN_USER]
				: username(&sbbs->cfg,node.useron, tmp)
				,node.misc&NODE_ANON ? 0 : node.useron);
		sbbs->bputs(sbbs->text[NodeMsgPrompt]);
		rc=JS_SUSPENDREQUEST(cx);
		char line[128];
		int result = sbbs->getstr(line,69,K_LINE);
		JS_RESUMEREQUEST(cx, rc);
		if(result < 1)
			return JS_TRUE;
		sprintf(str, sbbs->text[nodenum >= 1 ? NodeMsgFmt : AllNodeMsgFmt]
			,sbbs->cfg.node_num
			,sbbs->thisnode.misc&NODE_ANON
				? sbbs->text[UNKNOWN_USER] : sbbs->useron.alias, line);
		msg = strdup(str);
	}

	if(msg == NULL)
		return JS_FALSE;

	/* Send the message(s) */
	if(nodenum < 0 ) {	/* ALL */
		for(int i=1; i<=sbbs->cfg.sys_nodes && success; i++) {
			if(i==sbbs->cfg.node_num)
				continue;
			sbbs->getnodedat(i, &node, false);
			if((node.status==NODE_INUSE
				|| (sbbs->useron.level >= SYSOP_LEVEL && node.status==NODE_QUIET))
				&& (sbbs->useron.level >= SYSOP_LEVEL || !(node.misc&NODE_POFF)))
				if(putnmsg(&sbbs->cfg, i, msg) != 0)
					success = FALSE;
		}
		if(success) {
			sbbs->logline("C", "sent message to all nodes");
			sbbs->logline(nulstr, msg);
		success = putnmsg(&sbbs->cfg, nodenum, msg) == 0;
		if(success && !(node.misc&NODE_ANON))
			sbbs->bprintf(sbbs->text[MsgSentToUser],"Message"
				,username(&sbbs->cfg,usernumber,tmp), usernumber);
		SAFEPRINTF3(str, "%s message to %s on node %d:"
			,success ? "sent" : "FAILED to send", username(&sbbs->cfg, usernumber, tmp), nodenum);
		sbbs->logline("C",str);
		sbbs->logline(nulstr, msg);
	}
	JS_SET_RVAL(cx, arglist, BOOLEAN_TO_JSVAL(success));
rswindell's avatar
rswindell committed

	return(JS_TRUE);
}

js_get_telegram(JSContext *cx, uintN argc, jsval *arglist)
	jsval *argv=JS_ARGV(cx, arglist);
rswindell's avatar
rswindell committed
	sbbs_t*		sbbs;
deuce's avatar
deuce committed
	jsrefcount	rc;
	JS_SET_RVAL(cx, arglist, JSVAL_VOID);

	if((sbbs=js_GetPrivate(cx, JS_THIS_OBJECT(cx, arglist)))==NULL)
rswindell's avatar
rswindell committed
		return(JS_FALSE);

	usernumber=sbbs->useron.number;
	if(argc && JSVAL_IS_NUMBER(argv[0])) {
		if(!JS_ValueToInt32(cx,argv[0],&usernumber))
			return JS_FALSE;
	}
	if(argc > 1 && JSVAL_IS_BOOLEAN(argv[1]))
		clearline = JSVAL_TO_BOOLEAN(argv[1]);
	sbbs->getsmsg(usernumber, clearline ? true : false);
rswindell's avatar
rswindell committed

	return(JS_TRUE);
}

js_put_telegram(JSContext *cx, uintN argc, jsval *arglist)
	jsval *argv=JS_ARGV(cx, arglist);
rswindell's avatar
rswindell committed
	sbbs_t*		sbbs;
	int32		usernumber = 0;
	JSString*	js_msg = NULL;
	char*		msg = NULL;
	char 		str[256];
	char		tmp[512];
	char		logbuf[512] = "";
deuce's avatar
deuce committed
	jsrefcount	rc;
	JS_SET_RVAL(cx, arglist, JSVAL_FALSE);
	if((sbbs=js_GetPrivate(cx, JS_THIS_OBJECT(cx, arglist)))==NULL)
rswindell's avatar
rswindell committed
		return(JS_FALSE);

	/* Get the destination user number */
	if(argn < argc && JSVAL_IS_NUMBER(argv[argn])) {
		if(!JS_ValueToInt32(cx,argv[argn], &usernumber))
	} else {
		rc=JS_SUSPENDREQUEST(cx);
		usernumber = sbbs->getnodetopage(/* all: */FALSE, /* telegram: */TRUE);
		JS_RESUMEREQUEST(cx, rc);
	}

	/* Validate the destination user number */
	if(usernumber < 1)
		return JS_TRUE;

	if(usernumber == 1 && sbbs->useron.rest&FLAG('S')) { /* ! val fback */
		sbbs->bprintf(sbbs->text[R_Feedback], sbbs->cfg.sys_op);
		return JS_TRUE;
	}
	if(usernumber > 1 && sbbs->useron.rest&FLAG('E')) {
		sbbs->bputs(sbbs->text[R_Email]);
		return JS_TRUE;
	/* Get the telegram message text */
	if(argn < argc) {
		if((js_msg = JS_ValueToString(cx, argv[argn])) == NULL)
			return JS_FALSE;
		argn++;
		JSSTRING_TO_MSTRING(cx, js_msg, msg, NULL);
	} else {
		char buf[512];

		rc=JS_SUSPENDREQUEST(cx);
		sbbs->bprintf(sbbs->text[SendingTelegramToUser]
			,username(&sbbs->cfg,usernumber,tmp),usernumber);
		SAFEPRINTF2(buf,sbbs->text[TelegramFmt]
			,sbbs->thisnode.misc&NODE_ANON ? sbbs->text[UNKNOWN_USER] : sbbs->useron.alias
			,sbbs->timestr(time(NULL)));
		int i=0;
		while(sbbs->online && i<5) {
			char line[256];
			sbbs->bputs("\1n: \1h");
			if(!sbbs->getstr(line, 70, i < 4 ? (K_WRAP|K_MSG) : (K_MSG)))
				break;
			sprintf(str,"%4s%s\r\n",nulstr,line);
			SAFECAT(buf, str);
			if(i && line[0])
				SAFECAT(logbuf, " ");
			SAFECAT(logbuf, line);
			i++;
		}
		JS_RESUMEREQUEST(cx, rc);
		if(!i)
			return JS_TRUE;
		if(sbbs->sys_status&SS_ABORT) {
			sbbs->bputs(crlf);
			return JS_TRUE;
		}
		msg = strdup(buf);
	}
rswindell's avatar
rswindell committed
		return(JS_FALSE);

	bool success = putsmsg(&sbbs->cfg,usernumber,msg)==0;
	JS_SET_RVAL(cx, arglist, BOOLEAN_TO_JSVAL(success));
deuce's avatar
deuce committed
	free(msg);
	SAFEPRINTF3(str,"%s telegram to %s #%u"
		,success ? "sent" : "FAILED to send", username(&sbbs->cfg,usernumber,tmp), usernumber);
	sbbs->logline("C",str);
	if(logbuf[0])
		sbbs->logline(nulstr,logbuf);
	if(success)
		sbbs->bprintf(sbbs->text[MsgSentToUser], "Telegram", username(&sbbs->cfg,usernumber,tmp), usernumber);
rswindell's avatar
rswindell committed

	return(JS_TRUE);
}

js_cmdstr(JSContext *cx, uintN argc, jsval *arglist)
	jsval *argv=JS_ARGV(cx, arglist);
deuce's avatar
deuce committed
	const char	*def="";
	char*		fpath=(char *)def;
	char*		fspec=(char *)def;
deuce's avatar
deuce committed
	jsrefcount	rc;
	JS_SET_RVAL(cx, arglist, JSVAL_VOID);

 	if(!js_argc(cx, argc, 1))
		return(JS_FALSE);
	if((sbbs=js_GetPrivate(cx, JS_THIS_OBJECT(cx, arglist)))==NULL)
		return(JS_FALSE);

 	js_str = JS_ValueToString(cx, argv[0]);
 	if (!js_str)
 		return(JS_FALSE);

deuce's avatar
deuce committed
	JSSTRING_TO_MSTRING(cx, js_str, p, NULL);

	for(uintN i=1;i<argc;i++) {
		if(JSVAL_IS_STRING(argv[i])) {
			js_str = JS_ValueToString(cx, argv[i]);
deuce's avatar
deuce committed
			if(fpath==def) {
				JSSTRING_TO_MSTRING(cx, js_str, fpath, NULL);
				if(fpath==NULL) {
					if(fspec != def)
						free(fspec);
deuce's avatar
deuce committed
					return JS_FALSE;
deuce's avatar
deuce committed
			}
			else if(fspec==def) {
				JSSTRING_TO_MSTRING(cx, js_str, fspec, NULL);
				if(fspec==NULL) {
					if(fpath != def)
						free(fpath);
deuce's avatar
deuce committed
					return JS_FALSE;
	char* cmd = sbbs->cmdstr(p, fpath, fspec, NULL);
	free(p);
deuce's avatar
deuce committed
	if(fpath != def)
		free(fpath);
	if(fspec != def)
		free(fspec);
	if((js_str=JS_NewStringCopyZ(cx, cmd))==NULL)
		return(JS_FALSE);
	JS_SET_RVAL(cx, arglist, STRING_TO_JSVAL(js_str));
js_getfilespec(JSContext *cx, uintN argc, jsval *arglist)
deuce's avatar
deuce committed
	jsrefcount	rc;
	JS_SET_RVAL(cx, arglist, JSVAL_VOID);

	if((sbbs=js_GetPrivate(cx, JS_THIS_OBJECT(cx, arglist)))==NULL)
		JS_SET_RVAL(cx, arglist,JSVAL_NULL);
	else {
		JSString* js_str = JS_NewStringCopyZ(cx, p);
		if(js_str==NULL)
			return(JS_FALSE);
		JS_SET_RVAL(cx, arglist, STRING_TO_JSVAL(js_str));
js_listfiles(JSContext *cx, uintN argc, jsval *arglist)
	jsval *argv=JS_ARGV(cx, arglist);
deuce's avatar
deuce committed
	const char	*def=ALLFILES;
deuce's avatar
deuce committed
	char*		fspec=(char *)def;
	uint		dirnum;
    JSString*	js_str;
	sbbs_t*		sbbs;
deuce's avatar
deuce committed
	jsrefcount	rc;
	JS_SET_RVAL(cx, arglist, JSVAL_VOID);

	if((sbbs=js_GetPrivate(cx, JS_THIS_OBJECT(cx, arglist)))==NULL)
	dirnum=get_dirnum(cx,sbbs,argv[0], argc == 0);

	if(dirnum>=sbbs->cfg.total_dirs) {
		JS_SET_RVAL(cx, arglist, INT_TO_JSVAL(0));
		return(JS_TRUE);
	}

	for(uintN i=1;i<argc;i++) {
		if(JSVAL_IS_NUMBER(argv[i])) {
			if(!JS_ValueToInt32(cx,argv[i],&mode)) {
				if(fspec != def)
					FREE_AND_NULL(fspec);
		else if(JSVAL_IS_STRING(argv[i])) {
			js_str = JS_ValueToString(cx, argv[i]);
			JSSTRING_TO_MSTRING(cx, js_str, afspec, NULL);
			if(afspec==NULL)
deuce's avatar
deuce committed
				return JS_FALSE;
	if(!(mode&(FL_FINDDESC|FL_EXFIND)))
	JS_SET_RVAL(cx, arglist, INT_TO_JSVAL(sbbs->listfiles(dirnum,fspec,0 /* tofile */,mode)));
js_listfileinfo(JSContext *cx, uintN argc, jsval *arglist)
	jsval *argv=JS_ARGV(cx, arglist);
deuce's avatar
deuce committed
	const char	*def=ALLFILES;
	char*		fspec=(char *)def;
	uint		dirnum;
    JSString*	js_str;
	sbbs_t*		sbbs;
deuce's avatar
deuce committed
	jsrefcount	rc;
	JS_SET_RVAL(cx, arglist, JSVAL_VOID);

	if((sbbs=js_GetPrivate(cx, JS_THIS_OBJECT(cx, arglist)))==NULL)
	dirnum=get_dirnum(cx,sbbs,argv[0], argc == 0);

	if(dirnum>=sbbs->cfg.total_dirs) {
		JS_SET_RVAL(cx, arglist, INT_TO_JSVAL(0));
		return(JS_TRUE);
	}

	for(uintN i=1;i<argc;i++) {
		if(JSVAL_IS_NUMBER(argv[i])) {
			if(!JS_ValueToInt32(cx,argv[i],&mode))
				return JS_FALSE;
		}
		else if(JSVAL_IS_STRING(argv[i])) {
			js_str = JS_ValueToString(cx, argv[i]);
			if(fspec != def && fspec != NULL)
				free(fspec);
deuce's avatar
deuce committed
			JSSTRING_TO_MSTRING(cx, js_str, fspec, NULL);
			if(fspec==NULL)
				return JS_FALSE;
	JS_SET_RVAL(cx, arglist, INT_TO_JSVAL(sbbs->listfileinfo(dirnum,padfname(fspec,buf),mode)));
deuce's avatar
deuce committed
	if(fspec != def)
		free(fspec);
js_post_msg(JSContext *cx, uintN argc, jsval *arglist)
	jsval *argv=JS_ARGV(cx, arglist);
	smb_t*		resmb = NULL;
	smbmsg_t*	remsg = NULL;
deuce's avatar
deuce committed
	jsrefcount	rc;
	JS_SET_RVAL(cx, arglist, JSVAL_FALSE);
	if((sbbs=js_GetPrivate(cx, JS_THIS_OBJECT(cx, arglist)))==NULL)
	subnum=get_subnum(cx,sbbs,argv,argc,0);
	if(subnum>=sbbs->cfg.total_subs) 	// invalid sub-board
		if(JSVAL_IS_NUMBER(argv[n])) {
			if(!JS_ValueToInt32(cx,argv[n],&mode))
				return JS_FALSE;
		}
		else if(JSVAL_IS_OBJECT(argv[n])) {
			if((hdrobj=JSVAL_TO_OBJECT(argv[n]))==NULL)
				return JS_FALSE;
			if(!js_GetMsgHeaderObjectPrivates(cx, hdrobj, &resmb, &remsg)) {
				if(!js_ParseMsgHeaderObject(cx, hdrobj, &msg))
					return JS_FALSE;
				remsg = &msg;
			}
	JS_SET_RVAL(cx, arglist, BOOLEAN_TO_JSVAL(sbbs->postmsg(subnum, mode, resmb, remsg)));
js_msgscan_cfg(JSContext *cx, uintN argc, jsval *arglist)
	jsval *argv=JS_ARGV(cx, arglist);
deuce's avatar
deuce committed
	jsrefcount	rc;
	JS_SET_RVAL(cx, arglist, JSVAL_VOID);

	if((sbbs=js_GetPrivate(cx, JS_THIS_OBJECT(cx, arglist)))==NULL)
	if(argc && JSVAL_IS_NUMBER(argv[0])) {
		if(!JS_ValueToInt32(cx,argv[0],&mode))
			return JS_FALSE;
	}
js_msgscan_ptrs(JSContext *cx, uintN argc, jsval *arglist)
deuce's avatar
deuce committed
	jsrefcount	rc;
	JS_SET_RVAL(cx, arglist, JSVAL_VOID);

	if((sbbs=js_GetPrivate(cx, JS_THIS_OBJECT(cx, arglist)))==NULL)
js_msgscan_reinit(JSContext *cx, uintN argc, jsval *arglist)
deuce's avatar
deuce committed
	jsrefcount	rc;
	JS_SET_RVAL(cx, arglist, JSVAL_VOID);

	if((sbbs=js_GetPrivate(cx, JS_THIS_OBJECT(cx, arglist)))==NULL)
	for(uint i=0;i<sbbs->cfg.total_subs;i++) {
		sbbs->subscan[i].ptr=sbbs->subscan[i].sav_ptr;
		sbbs->subscan[i].last=sbbs->subscan[i].sav_last;
	}
	sbbs->bputs(sbbs->text[MsgPtrsInitialized]);
js_scansubs(JSContext *cx, uintN argc, jsval *arglist)
	jsval *argv=JS_ARGV(cx, arglist);
deuce's avatar
deuce committed
	jsrefcount	rc;
	JS_SET_RVAL(cx, arglist, JSVAL_VOID);

	if((sbbs=js_GetPrivate(cx, JS_THIS_OBJECT(cx, arglist)))==NULL)
		if(JSVAL_IS_NUMBER(argv[i])) {
			if(!JS_ValueToInt32(cx,argv[i],&mode))
				return JS_FALSE;
		}
		else if(JSVAL_IS_BOOLEAN(argv[i]))
			all=JSVAL_TO_BOOLEAN(argv[i]);
	}

	if(all)
		sbbs->scanallsubs(mode);
	else
		sbbs->scansubs(mode);
js_scandirs(JSContext *cx, uintN argc, jsval *arglist)
	jsval *argv=JS_ARGV(cx, arglist);
deuce's avatar
deuce committed
	jsrefcount	rc;
	JS_SET_RVAL(cx, arglist, JSVAL_VOID);

	if((sbbs=js_GetPrivate(cx, JS_THIS_OBJECT(cx, arglist)))==NULL)
		if(JSVAL_IS_NUMBER(argv[i])) {
			if(!JS_ValueToInt32(cx,argv[i],&mode))
				return JS_FALSE;
		}
		else if(JSVAL_IS_BOOLEAN(argv[i]))
			all=JSVAL_TO_BOOLEAN(argv[i]);
	}

	if(all)
		sbbs->scanalldirs(mode);
	else
		sbbs->scandirs(mode);
js_scanposts(JSContext *cx, uintN argc, jsval *arglist)
	jsval *argv=JS_ARGV(cx, arglist);
deuce's avatar
deuce committed
	const char	*def="";
	char*		find=(char *)def;
deuce's avatar
deuce committed
	jsrefcount	rc;
	JS_SET_RVAL(cx, arglist, JSVAL_VOID);

	if((sbbs=js_GetPrivate(cx, JS_THIS_OBJECT(cx, arglist)))==NULL)
	subnum=get_subnum(cx,sbbs,argv,argc,0);

	if(subnum>=sbbs->cfg.total_subs) {	// invalid sub-board
		JS_SET_RVAL(cx, arglist, JSVAL_FALSE);
		if(JSVAL_IS_NUMBER(argv[i])) {
			if(!JS_ValueToInt32(cx,argv[i],&mode)) {
				if(find != def)
					free(find);
deuce's avatar
deuce committed
		else if(JSVAL_IS_STRING(argv[i]) && find==def) {
			JSVALUE_TO_MSTRING(cx, argv[i], find, NULL);
			if(find==NULL)
				return JS_FALSE;
		}
	JS_SET_RVAL(cx, arglist, BOOLEAN_TO_JSVAL(sbbs->scanposts(subnum,mode,find)==0));
deuce's avatar
deuce committed
	if(find != def)
		free(find);
js_listmsgs(JSContext *cx, uintN argc, jsval *arglist)
	jsval *argv=JS_ARGV(cx, arglist);
deuce's avatar
deuce committed
	const char	*def="";
	char*		find=(char *)def;
	uint		subnum;
	sbbs_t*		sbbs;
	uintN		argn=0;
deuce's avatar
deuce committed
	jsrefcount	rc;
	JS_SET_RVAL(cx, arglist, JSVAL_VOID);

	if((sbbs=js_GetPrivate(cx, JS_THIS_OBJECT(cx, arglist)))==NULL)
	JS_SET_RVAL(cx, arglist, INT_TO_JSVAL(0));
	subnum=get_subnum(cx,sbbs,argv,argc,argn++);

	if(subnum>=sbbs->cfg.total_subs) 	// invalid sub-board
		return(JS_TRUE);

	if(argc > argn && JSVAL_IS_NUMBER(argv[argn])) {
		if(!JS_ValueToInt32(cx,argv[argn++],&mode))
			return JS_FALSE;
	}
	if(argc > argn && JSVAL_IS_NUMBER(argv[argn])) {
		if(!JS_ValueToInt32(cx,argv[argn++],&start))
			return JS_FALSE;
	}
deuce's avatar
deuce committed
	if(argc > argn && JSVAL_IS_STRING(argv[argn])) {
		JSVALUE_TO_MSTRING(cx, argv[argn], find, NULL);
deuce's avatar
deuce committed
		if(find==NULL)
			return JS_FALSE;
	JS_SET_RVAL(cx, arglist, INT_TO_JSVAL(sbbs->listsub(subnum,mode,start,find)));
deuce's avatar
deuce committed
	if(find != def)
		free(find);
js_getnstime(JSContext *cx, uintN argc, jsval *arglist)
	jsval *argv=JS_ARGV(cx, arglist);
deuce's avatar
deuce committed
	jsrefcount	rc;
	JS_SET_RVAL(cx, arglist, JSVAL_NULL);
	if((sbbs=js_GetPrivate(cx, JS_THIS_OBJECT(cx, arglist)))==NULL)
	if(argc && JSVAL_IS_NUMBER(argv[0])) {
		int32 i;
		if(!JS_ValueToInt32(cx,argv[0],&i))
deuce's avatar
deuce committed
	if(sbbs->inputnstime(&t)==true) {
		JS_SET_RVAL(cx, arglist,DOUBLE_TO_JSVAL((double)t));
js_select_shell(JSContext *cx, uintN argc, jsval *arglist)
deuce's avatar
deuce committed
	jsrefcount	rc;
	JS_SET_RVAL(cx, arglist, JSVAL_VOID);

	if((sbbs=js_GetPrivate(cx, JS_THIS_OBJECT(cx, arglist)))==NULL)
	JS_SET_RVAL(cx, arglist, BOOLEAN_TO_JSVAL(sbbs->select_shell()));
js_select_editor(JSContext *cx, uintN argc, jsval *arglist)
deuce's avatar
deuce committed
	jsrefcount	rc;
	JS_SET_RVAL(cx, arglist, JSVAL_VOID);

	if((sbbs=js_GetPrivate(cx, JS_THIS_OBJECT(cx, arglist)))==NULL)
	JS_SET_RVAL(cx, arglist, BOOLEAN_TO_JSVAL(sbbs->select_editor()));
js_get_time_left(JSContext *cx, uintN argc, jsval *arglist)
deuce's avatar
deuce committed
	jsrefcount	rc;
	JS_SET_RVAL(cx, arglist, JSVAL_VOID);

	if((sbbs=js_GetPrivate(cx, JS_THIS_OBJECT(cx, arglist)))==NULL)
	JS_SET_RVAL(cx, arglist, INT_TO_JSVAL(sbbs->gettimeleft()));
js_chk_ar(JSContext *cx, uintN argc, jsval *arglist)
	jsval *argv=JS_ARGV(cx, arglist);
deuce's avatar
deuce committed
	char		*p;
	JS_SET_RVAL(cx, arglist, JSVAL_VOID);

	if((sbbs=js_GetPrivate(cx, JS_THIS_OBJECT(cx, arglist)))==NULL)
deuce's avatar
deuce committed
	JSVALUE_TO_MSTRING(cx, argv[0], p, NULL);
deuce's avatar
deuce committed
	if(p==NULL)
		return JS_FALSE;

	rc=JS_SUSPENDREQUEST(cx);
deuce's avatar
deuce committed
	ar = arstr(NULL,p,&sbbs->cfg);
deuce's avatar
deuce committed
	free(p);
	JS_SET_RVAL(cx, arglist, BOOLEAN_TO_JSVAL(sbbs->chk_ar(ar,&sbbs->useron,&sbbs->client)));

	if(ar!=NULL && ar!=nular)
		free(ar);
	JS_RESUMEREQUEST(cx, rc);

	return JS_TRUE;
}

static JSBool
js_select_node(JSContext *cx, uintN argc, jsval *arglist)
{
	jsval *argv=JS_ARGV(cx, arglist);
	sbbs_t*		sbbs;
	jsrefcount	rc;
	BOOL		all = FALSE;

	if((sbbs=js_GetPrivate(cx, JS_THIS_OBJECT(cx, arglist)))==NULL)
		return(JS_FALSE);

	if(argc > 0 && JSVAL_IS_BOOLEAN(argv[0]))
		all = JSVAL_TO_BOOLEAN(argv[0]);

	rc=JS_SUSPENDREQUEST(cx);
	JS_SET_RVAL(cx, arglist, INT_TO_JSVAL(sbbs->getnodetopage(all, /* telegram: */FALSE)));
	JS_RESUMEREQUEST(cx, rc);

	return JS_TRUE;
}

static JSBool
js_select_user(JSContext *cx, uintN argc, jsval *arglist)
{
	sbbs_t*		sbbs;
	jsrefcount	rc;

	if((sbbs=js_GetPrivate(cx, JS_THIS_OBJECT(cx, arglist)))==NULL)
		return(JS_FALSE);

	rc=JS_SUSPENDREQUEST(cx);
	JS_SET_RVAL(cx, arglist, INT_TO_JSVAL(sbbs->getnodetopage(/* all: */FALSE, /* telegram: */TRUE)));
	JS_RESUMEREQUEST(cx, rc);

	return JS_TRUE;
}

static jsSyncMethodSpec js_bbs_functions[] = {
rswindell's avatar
rswindell committed
	{"atcode",			js_atcode,			1,	JSTYPE_STRING,	JSDOCSTR("code_string")
rswindell's avatar
rswindell committed
	,JSDOCSTR("returns @-code value, specified <i>code</i> string does not include @ character delimiters")
rswindell's avatar
rswindell committed
	/* text.dat */
rswindell's avatar
rswindell committed
	{"text",			js_text,			1,	JSTYPE_STRING,	JSDOCSTR("line_number")
rswindell's avatar
rswindell committed
	,JSDOCSTR("returns specified text string from text.dat")
	{"replace_text",	js_replace_text,	2,	JSTYPE_BOOLEAN,	JSDOCSTR("line_number, text")
rswindell's avatar
rswindell committed
	,JSDOCSTR("replaces specified text string in memory")
rswindell's avatar
rswindell committed
	{"revert_text",		js_revert_text,		1,	JSTYPE_BOOLEAN,	JSDOCSTR("[line_number=<i>all</i>]")
rswindell's avatar
rswindell committed
	,JSDOCSTR("reverts specified text string to original text string; "
rswindell's avatar
rswindell committed
		"if <i>line_number</i> unspecified, reverts all text lines")
rswindell's avatar
rswindell committed
	{"load_text",		js_load_text,		1,	JSTYPE_BOOLEAN,	JSDOCSTR("base_filename")
	,JSDOCSTR("load an alternate text.dat from ctrl directory, automatically appends '.dat' to basefilename")
rswindell's avatar
rswindell committed
	/* procedures */
	{"newuser",			js_newuser,			0,	JSTYPE_VOID,	JSDOCSTR("")
rswindell's avatar
rswindell committed
	,JSDOCSTR("interactive new user procedure")
	{"login",			js_login,			4,	JSTYPE_BOOLEAN,	JSDOCSTR("user_name [,password_prompt] [,user_password] [,system_password]")
	,JSDOCSTR("login with <i>user_name</i>, displaying <i>password_prompt</i> for user's password (if required), "
	"optionally supplying the user's password and the system password as arguments so as to not be prompted")
	{"logon",			js_logon,			0,	JSTYPE_BOOLEAN,	JSDOCSTR("")
rswindell's avatar
rswindell committed
	,JSDOCSTR("interactive logon procedure")
	{"logoff",			js_logoff,			1,	JSTYPE_VOID,	JSDOCSTR("[prompt=<i>true</i>]")
	,JSDOCSTR("interactive logoff procedure, pass <i>false</i> for <i>prompt</i> argument to avoid yes/no prompt")
	,315
	{"logout",			js_logout,			0,	JSTYPE_VOID,	JSDOCSTR("")
rswindell's avatar
rswindell committed
	,JSDOCSTR("non-interactive logout procedure")
	{"hangup",			js_hangup,			0,	JSTYPE_VOID,	JSDOCSTR("")
rswindell's avatar
rswindell committed
	,JSDOCSTR("hangup (disconnect) immediately")
	{"node_sync",		js_nodesync,		1,	JSTYPE_ALIAS },
	{"nodesync",		js_nodesync,		1,	JSTYPE_VOID,	JSDOCSTR("[clearline=<i>false</i>]")
	,JSDOCSTR("synchronize with node database, checks for messages, interruption, etc. (AKA node_sync), "
	"clears the current console line if there's a message to print when <i>clearline</i> is <i>true</i>.")
	{"auto_msg",		js_automsg,			0,	JSTYPE_VOID,	JSDOCSTR("")
rswindell's avatar
rswindell committed
	,JSDOCSTR("read/create system's auto-message")
	{"time_bank",		js_time_bank,		0,	JSTYPE_VOID,	JSDOCSTR("")