/** /* $Id: utils.c,v 1.1 1998/02/13 08:56:15 falcon Exp $ /**/ #include "config.h" #include #include #include #include #include #include #include #include #ifdef HAVE_SYS_FILIO_H #include #endif #include "returns.h" #include "defs.h" #include "prototypes.h" #include "orcus.h" #include "show.h" struct termios orcus_term; struct termios saved_term; extern int squelch_status; extern int server_wrap; extern char commandchar; extern FILE *logfile; /* Paranoia is GOOD! */ /* Use scrub_free() instead of free(). It will write 0's to */ /* the data area before free()ing it. The first parameter */ /* points to the data block being freed and the second is its */ /* length in bytes. Security measure against garbage snoops. */ void scrub_free ( void *p, int n ) { int i; if ( p == NULL ) return; for ( i = 0; i < n; i++ ) ((char*)p)[i] = 0; free ( (char*)p ); } void alstrcpy ( dest, src ) char **dest, *src; { int sz; sz = strlen ( src ) + 1; *dest = (char*) malloc ( sz ); strcpy ( *dest, src ); } char *nibble ( buf, n ) char *buf; int n; { int x, i, j, k; int beginning, ending; char *retval = NULL; k = strlen ( buf ); for ( j = 0; ( j < k ) && ( buf[j] == ' ' ); j++ ); if ( j >= k ) return NULL; x = j; for ( i = 0; ( i < n ) && ( x < k ); i++ ) { while ( ( buf[x] != ' ' ) && ( x < k ) ) x++; while ( ( buf[x] == ' ' ) && ( x < k ) ) x++; } if ( x >= k ) return NULL; beginning = x; while ( ( buf[x] != ' ' ) && ( x < k ) ) x++; ending = x; retval = (char*) malloc ( ending - beginning + 1 ); strncpy ( retval, buf + beginning, ending - beginning ); retval[ending-beginning] = 0; return retval; } char *gobble ( buf, n ) char *buf; int n; { int x, i, j, k; int beginning, ending; char *retval; if ( buf == NULL ) { retval = (char*) malloc ( 1 ); retval[0] = 0; return retval; } k = strlen ( buf ); for ( j = 0; ( j < k ) && ( buf[j] == ' ' ); j++ ); if ( j >= k ) return NULL; x = j; for ( i = 0; ( i < n ) && ( x < k ); i++ ) { while ( ( buf[x] != ' ' ) && ( x < k ) ) x++; while ( ( buf[x] == ' ' ) && ( x < k ) ) x++; } if ( x >= k ) return NULL; beginning = x; ending = k; retval = (char*) malloc ( ending - beginning + 1 ); strncpy ( retval, buf + beginning, ending - beginning ); retval[ending-beginning] = 0; return retval; } void nab_one ( buf, n, dest ) char *buf; int n; char *dest; { char *foo; extern int debug; extern char *bigbuf; if ( dest ) dest[0] = 0; if ( buf[0] == 0 ) return; foo = nibble ( buf, n ); if ( foo == NULL ) { if(debug) oprint ("ARGH! 1\n"); return; } if ( dest == NULL ) alstrcpy ( &bigbuf, foo ); else strcpy ( dest, foo ); scrub_free ( foo, strlen(foo) ); } void nab_rest ( buf, n, dest ) char *buf; int n; char *dest; { char *foo; extern int debug; extern char *bigbuf; if ( dest != NULL ) dest[0] = 0; if ( buf[0] == 0 ) return; foo = gobble ( buf, n ); if ( foo == NULL ) { if(debug) oprint ("ARGH! 2\n"); return; } if ( dest == NULL ) alstrcpy ( &bigbuf, foo ); else { while ( ( foo != buf ) && ( foo[-1] == ' ' ) ) foo--; /* zzapp - experimental */ strcpy ( dest, foo ); } scrub_free ( foo, strlen(foo) ); } int snork_file ( f, buf ) FILE *f; char **buf; { int retval; fseek ( f, 0, SEEK_END ); retval = ftell ( f ); fseek ( f, 0, SEEK_SET ); *buf = (char*) malloc ( retval + 1 ); fread ( *buf, 1, retval, f ); (*buf)[retval] = 0; return retval; } int deebee = 0; #define DBG { deebee++; oprint ("*fnord %d\n",deebee); } void load_orcusrc ( fnameparam ) char *fnameparam; { char fname[256]; char buf[2048]; FILE *f; int i,j; int commandresult; if ( fnameparam == NULL ) { fname[0] = 0; if ( getenv("HOME") != NULL ) { strcpy ( fname, getenv("HOME") ); strcat ( fname, "/" ); } strcat ( fname, ".orcusrc" ); } else strcpy ( fname, fnameparam ); f = fopen ( fname, "r" ); if ( f == NULL ) { oprint ("[=ORCUS=] cannot open '%s'\n",fname); return; } while (!feof(f)) { char last; last = 0; for ( i = 0; (i < 2047) && (last != '\n') && (!feof(f)); i++ ) { fread ( &last, 1, 1, f ); buf[i] = last; } if ( i ) buf[i-1] = 0; else buf[0] = 0; push_command_queue(buf); } for(i=0;i<256; i++) fname[i] = 0; for(i=0;i<2048;i++) buf[i] = 0; fclose ( f ); } /* end of function load_orcusrc() */ int quit(int *confirm_quit) { extern int debug; char quit_choice; if(debug) oprint("confirm_quit is : %d\n", confirm_quit); if(confirm_quit) { oprint("Are you sure you want to quit? (Y/n) "); quit_choice = toupper(getc(stdin)); if(debug) oprint("I got \"%c\"...\n", quit_choice); switch(quit_choice) { case 'Y' : orc_quit(); case '\n' : orc_quit(); default : dont_quit(); } } else orc_quit(); } /* end of function quit() */ int orc_quit(void) { extern char *chunkoram; extern int s; extern int debug; scrub_free ( chunkoram, REALLYHUGE ); /* free up alloced space. */ nuke_command_queue(); oprint("Connection closed.\n"); close ( s ); /* Close up the socket */ sttyinputreset(); /* reset the tty to blocking linemode */ if ( debug ) oprint ("[=Exiting=]\n"); if ( logfile != NULL ) { fclose ( logfile ); logfile = NULL; } exit(0); /* and we quit */ } void dont_quit(void) /* don't quit and return to orcus */ { oprint("\n"); /* to make it look pretty after you say no */ return; } int sttyinputset(void) { extern int debug; /* Make sure we have stdin */ if(isatty(STDIN_FILENO) == 0) { if(debug) perror("stdin is not a terminal device"); return(1); } if(tcgetattr(STDIN_FILENO, &orcus_term) < 0) { if(debug) perror("tcgetattr error"); return(1); } /* make a copy of the term settings and store them away */ memcpy (&saved_term, &orcus_term, sizeof(orcus_term)); #ifndef HAVE_SGTTY /* defined SYSV || defined __OpenBSD__ || defined __FreeBSD__*/ orcus_term.c_lflag &= ~(ECHO); orcus_term.c_lflag &= ~(ICANON); orcus_term.c_cc[VTIME] = 0; orcus_term.c_cc[VEOF] = 1; #else /* BSD */ orcus_term.sg_flags |= (CBREAK); orcus_term.sg_flags &= ~(ECHO); #endif tcsetattr(STDIN_FILENO, TCSAFLUSH, &orcus_term ); return(0); } int sttyinputreset(void) { extern int debug; if(tcsetattr(STDIN_FILENO, TCSAFLUSH, &saved_term) < 0) { if(debug) perror("tcgetattr error"); return(1); } return(0); } /** Function fdpoll **/ int fdpoll(fd) int fd; { int retval; ioctl ( fd, FIONREAD, &retval ); return retval; } /** end of function fdpoll **/ extern int oset ( char *what, char *buf ); int analyze_input_string ( buf ) /* puts parts into stuff[] */ char *buf; { char foo[64]; char *bar; int i; int isacommand = 0; extern int debug; extern char *bigbuf; extern char stuff[4][255]; extern int noidle; extern int do_free_idlecmd; extern char *idlecmd; extern int *confirm_quit; extern int bmessage; extern int breturn; extern int nobeep; extern int cols; extern int rows; extern int spat; extern int s; extern int logstate; extern int logtimes; extern char *logfname; extern time_t logtimer; if(debug) oprint ("analyze: alpha %d\n", (long) buf ); if ( !buf[0] ) return NO_CMD; if(debug) oprint ("analyze: beta\n"); if ( bigbuf != NULL ) { if(debug) oprint ("analyze: gamma\n"); scrub_free ( bigbuf, strlen(bigbuf) ); if(debug) oprint ("analyze: delta\n"); bigbuf = NULL; } if(debug) oprint ("analyze: epsilon\n"); if ( ( buf[0] == commandchar ) && ( buf[1] != commandchar ) ) { if(debug) oprint ("analyze: iota\n"); buf[0] = '/'; bar = nibble ( buf, 0 ); if ( bar == NULL ) return NO_CMD; if ( strlen(bar) > 60 ) { scrub_free(bar,strlen(bar)); return NO_CMD; } strcpy ( foo, bar ); scrub_free ( bar, strlen(bar) ); if ( !strcmp ( foo, "/m" ) ) { nab_one ( buf, 1, stuff[0] ); nab_rest ( buf, 2, bigbuf ); return PRIVATE_MSG; } if ( !strcmp ( foo, "/write" ) ) { strcpy ( stuff[0], "server" ); nab_rest ( buf, 0, bigbuf ); bigbuf[0] = ' '; server_wrap = 1; return PRIVATE_MSG; } if ( !strcmp ( foo, "/read" ) ) { strcpy ( stuff[0], "server" ); nab_rest ( buf, 0, bigbuf ); bigbuf[0] = ' '; return PRIVATE_MSG; } if ( !strcmp ( foo, "/g" ) ) { nab_one ( buf, 1, stuff[0] ); return CHANGE_GRP; } if ( !strcmp ( foo, "/echo" ) ) { strcpy( stuff[0], "echoback" ); nab_one ( buf, 1, stuff[1] ); return ECHOBACK; } if ( ( !strcmp ( foo, "/who" ) ) || ( !strcmp ( foo, "/w" ) ) ) { stuff[0][0] = 'w'; stuff[0][1] = 0; nab_one ( buf, 1, stuff[1] ); return WHO; } if ( !strcmp ( foo, "/boot" ) ) { strcpy ( stuff[0], "boot" ); nab_rest ( buf, 1, stuff[1] ); return BOOT; } if ( !strcmp ( foo, "/s_help" ) ) { strcpy ( stuff[0], "s_help" ); nab_rest ( buf, 1, stuff[1] ); return CMD2; } if ( !strcmp ( foo, "/shuttime" ) ) { strcpy ( stuff[0], "shuttime" ); nab_rest ( buf, 1, stuff[1] ); return CMD2; } if ( !strcmp ( foo, "/shutdown" ) ) { strcpy ( stuff[0], "shutdown" ); nab_rest ( buf, 1, stuff[1] ); return CMD2; } if ( !strcmp ( foo, "/beep" ) ) { strcpy ( stuff[0], "beep" ); nab_one ( buf, 1, stuff[1] ); return BEEP; } if ( !strcmp ( foo, "/talk" ) ) { strcpy ( stuff[0], "talk" ); nab_rest ( buf, 1, stuff[1] ); return CMD2; } if ( !strcmp ( foo, "/rname" ) ) { strcpy ( stuff[0], "rname" ); nab_rest ( buf, 1, stuff[1] ); return CMD2; } if ( !strcmp ( foo, "/text" ) ) { strcpy ( stuff[0], "text" ); nab_rest ( buf, 1, stuff[1] ); return CMD2; } if ( !strcmp ( foo, "/addr" ) ) { strcpy ( stuff[0], "addr" ); nab_rest ( buf, 1, stuff[1] ); return CMD2; } if ( !strcmp ( foo, "/phone" ) ) { strcpy ( stuff[0], "phone" ); nab_rest ( buf, 1, stuff[1] ); return CMD2; } if ( !strcmp ( foo, "/delete" ) ) { strcpy ( stuff[0], "delete" ); nab_rest ( buf, 1, stuff[1] ); return CMD2; } if ( !strcmp ( foo, "/info" ) ) { strcpy ( stuff[0], "info" ); nab_rest ( buf, 1, stuff[1] ); return CMD2; } if ( !strcmp ( foo, "/cp" ) ) { strcpy ( stuff[0], "cp" ); nab_rest ( buf, 1, stuff[1] ); return CMD2; } if ( !strcmp ( foo, "/email" ) ) { strcpy ( stuff[0], "email" ); nab_rest ( buf, 1, stuff[1] ); return CMD2; } if ( !strcmp ( foo, "/secure" ) ) { strcpy ( stuff[0], "secure" ); nab_rest ( buf, 1, stuff[1] ); return CMD2; } if ( !strcmp ( foo, "/nosecure" ) ) { strcpy ( stuff[0], "nosecure" ); nab_rest ( buf, 1, stuff[1] ); return CMD2; } if ( !strcmp ( foo, "/www" ) ) { strcpy ( stuff[0], "www" ); nab_rest ( buf, 1, stuff[1] ); return CMD2; } if ( !strcmp ( foo, "/idlec" ) ) { nab_rest ( buf, 1, stuff[1] ); if ( stuff[1][0] == 0 ) return NO_CMD; if ( do_free_idlecmd ) free(idlecmd); idlecmd = strdup ( stuff[1] ); return NO_CMD; } if ( !strcmp ( foo, "/oset" ) ) { nab_one ( buf, 1, stuff[0] ); nab_rest ( buf, 2, stuff[1] ); if ( oset ( stuff[0], stuff[1] ) == 0 ) return NO_CMD; oprint ( "[=oset=] set %s to %s\n", stuff[0], stuff[1] ); return NO_CMD; } if ( ( !strcmp ( foo, "/keepalive" ) ) || ( !strcmp ( foo, "/noidle" ) ) || ( !strcmp ( foo, "/idle" ) ) ) { nab_one ( buf, 1, stuff[1] ); if ( stuff[1][0] ) { if ( !strcmp ( stuff[1], "on" ) ) noidle = 1; else noidle = 0; } else noidle = !noidle; if ( noidle ) oprint ("[=Idle=] keeping connection alive\n"); else oprint ("[=Idle=] will let connection timeout\n"); return NOIDLE; } if ( strcmp ( foo, "/log" ) == 0 ) { nab_one ( buf, 1, stuff[1] ); if ( stuff[1][0] ) { if ( ( strcmp ( stuff[1], "on" ) == 0 ) && ( !logstate ) ) { if ( logfile == NULL ) { if ( logfname != NULL ) { scrub_free ( logfname, strlen(logfname)); logfname = NULL; } if ( getenv ( "HOME" ) == NULL ) logfname = strdup ( ".orcuslog" ); else { logfname = (char*) malloc ( strlen ( getenv ( "HOME" ) ) + 20 ); sprintf ( logfname, "%s/.orcuslog", getenv("HOME") ); } logfile = fopen ( logfname, "a" ); if ( logfile == NULL ) { oprint ("[=ORCUS=] error -- cannot open logfile '%s'\n", logfname ); return NO_CMD; } } /* END of if logfile == NULL */ { time_t datime; struct tm *dalocaltime; datime = time(NULL); dalocaltime = localtime ( (const time_t *) &datime ); datime = mktime ( dalocaltime ); logstate = 1; oprint ("[=ORCUS=] logging started '%s' %s", logfname, ctime( (const time_t*) &datime) ); } return NO_CMD; } else if ( !strcmp ( stuff[1], "off" ) ) { logstate = 0; if ( logfile != NULL ) fclose(logfile); logfile = NULL; } else if ( !strcmp ( stuff[1], "on" ) ) { oprint ( "[=ORCUS=] " ); if ( ( logstate != 0 ) && ( logfile != NULL ) ) logstate = 0; if ( logfname != NULL ) oprint ( "log file set to '%s', ", logfname ); oprint ( "logging is " ); if ( logstate == 0 ) oprint ("not on\n"); else oprint ("on\n"); } else { /* nab_one ( buf, 1, stuff[1] ); */ if ( logfname != NULL ) scrub_free ( logfname, strlen(logfname) ); if ( logfile != NULL ) { fclose ( logfile ); logfile = NULL; } logfname = strdup ( stuff[1] ); /* FIXME -- should expand "~/" */ logfile = fopen ( logfname, "a" ); if ( logfile == NULL ) { oprint ("[=ORCUS=] error -- cannot open file '%s'\n", logfname); scrub_free ( logfname, strlen(logfname) ); logfname = NULL; logstate = 0; return NO_CMD; } oprint ( "[=ORCUS=] log file set to '%s', logging is ", logfname ); if ( logstate != 0 ) oprint ("on\n"); else oprint ("not on\n"); return NO_CMD; } } if ( logfile == NULL ) logstate = 0; if ( logstate ) oprint ("[=ORCUS=] logfile %s active\n",logfname); if ( logstate ) fflush ( logfile ); else oprint ("[=ORCUS=] logging is not active\n"); return NO_CMD; } if ( ( !strcmp ( foo, "/reload" ) ) || ( !strcmp ( foo, "/run" ) ) ) { nab_rest ( buf, 1, stuff[1] ); if ( stuff[1][0] ) load_orcusrc ( stuff[1] ); else load_orcusrc ( NULL ); return RELOAD; } if ( ( !strcmp ( foo, "/idlep" ) ) || ( !strcmp ( foo, "/idleperiod" ) ) ) { extern int idleperiod; nab_one ( buf, 1, stuff[1] ); idleperiod = 0; for ( i = 0; stuff[1][i]; i++ ) idleperiod = ( idleperiod * 10 ) + ( stuff[1][i] - '0' ); if ( idleperiod < 10 ) idleperiod = 10; oprint ("[=Idle=] period set to %u seconds\n",idleperiod); return NO_CMD; } /* end of if idleperiod */ if ( ( !strcmp ( foo, "/sq" ) ) || ( !strcmp ( foo, "/squelch" ) ) ) { extern lroot squelches; nab_one ( buf, 1, stuff[1] ); nab_rest ( buf, 2, stuff[2] ); if ( !stuff[1][0] ) { oprint ("[=TYPO=] need argument\n"); return NO_CMD; } if ( !strcmp ( stuff[1], "on" ) ) { squelch_status = SQUELCH_PRIVATE | SQUELCH_OPEN; } else if ( !strcmp ( stuff[1], "off" ) ) { squelch_status = 0; } else if ( !strcmp ( stuff[1], "pub" ) ) { squelch_status = SQUELCH_OPEN; } else if ( !strcmp ( stuff[1], "pri" ) ) { squelch_status = SQUELCH_PRIVATE; } else if ( !strcmp ( stuff[1], "add" ) ) { strl *finger, *thumb; if ( !stuff[2][0] ) { oprint ("[=TYPO=] needs second argument\n"); return NO_CMD; } finger = squelches.t; if ( finger == NULL ) { squelches.h = (strl*)malloc(sizeof(strl)); squelches.t = squelches.h; squelches.h->d = strdup ( stuff[2] ); squelches.h->next = NULL; squelches.n = 1; } else { thumb = (strl*)malloc(sizeof(strl)); thumb->d = strdup ( stuff[2] ); thumb->next = NULL; finger->next = thumb; squelches.t = thumb; squelches.n++; } /* end of if..else */ } else /* end of "add" */ if ( ( !strcmp ( stuff[1], "sub" ) ) || ( !strcmp ( stuff[1], "rm" ) ) ) { int finis = 0; strl *finger, *thumb; if ( !stuff[2][0] ) { oprint ("[=TYPO=] needs second argument\n"); return NO_CMD; } if ( squelches.n == 0 ) { oprint ("[=ERROR=] no items in squelch list to remove\n"); return NO_CMD; } thumb = NULL; finger = squelches.h; while ( !finis ) { if ( !strcmp ( finger->d, stuff[2] ) ) { if ( squelches.n == 1 ) { squelches.n = 0; squelches.h = NULL; squelches.t = NULL; scrub_free ( finger->d, strlen(finger->d) ); scrub_free ( finger, sizeof(strl) ); } else { if ( thumb == NULL ) { /* first node in list */ squelches.h = finger->next; squelches.n--; scrub_free ( finger->d, strlen(finger->d) ); scrub_free ( finger, sizeof(strl) ); } else { /* not first node in list */ if ( finger->next == NULL ) { /* end of list */ thumb->next = NULL; squelches.t = thumb; scrub_free ( finger->d, strlen(finger->d) ); scrub_free ( finger, sizeof(strl) ); squelches.n--; } else { /* not at end of list */ thumb->next = finger->next; scrub_free ( finger->d, strlen(finger->d) ); scrub_free ( finger, sizeof(strl) ); squelches.n--; } /* end of end of list check */ } /* end of not first node in list */ } /* end of if..else clause for n == 1 */ finis = 1; } else { /* not a match */ thumb = finger; finger = finger->next; if ( finger == NULL ) finis = 1; } /* end of if..else */ } /* end of while */ } else /* end of "rm" */ if ( !strcmp ( stuff[1], "nuke" ) ) { strl *finger, *thumb; squelches.n = 0; finger = squelches.h; while ( finger != NULL ) { thumb = finger->next; scrub_free ( finger->d, strlen(finger->d) ); scrub_free ( finger, sizeof(strl) ); finger = thumb; } /* end of while */ squelches.h = NULL; squelches.t = NULL; oprint ("[=ORCUS=] squelch list has been nuked\n"); } else /* end of "nuke" */ if ( !strcmp ( stuff[1], "list" ) ) { strl *finger; finger = squelches.h; if ( finger == NULL ) { oprint ("[=ORCUS=] no strings in squelch list\n"); return NO_CMD; } spat = 0; oprint ("[=ORCUS=] squelching these strings:\n"); spat ++; while ( finger != NULL ) { oprint ("%s\n",finger->d); spat++; more_prompt(); finger = finger->next; } /* end of while */ oprint ("[=ORCUS=] end of squelch list\n"); } /* end of "list" */ return NO_CMD; } /* end of if squelch */ if ( ( !strcmp ( foo, "/v" ) ) || ( !strcmp ( foo, "/ver" ) ) || ( !strcmp ( foo, "/version" ) ) ) { oprint ("[=ORCUS=] %s\n",ORCUS_VERSION); return NO_CMD; } if ( ( !strcmp ( foo, "/?" ) ) || ( !strcmp ( foo, "/h" ) ) || ( !strcmp ( foo, "/help" ) ) ) { oprint ("/m Send private message\n"); oprint ("/g Go to a group\n"); oprint ("/w List who is in the group\n"); oprint ("/boot Boot someones ass outta there\n"); oprint ("/beep Beep someone\n"); oprint ("/idle Toggle noidle\n"); oprint ("/idlep Set idle period to N seconds\n"); oprint ("/debug Toggle verbose debug mode on or off\n"); oprint ("/drop Drop an idle connection (yours)\n"); oprint ("/log 'on' 'off' or name of log file\n"); oprint ("/oset See or set misc variables\n"); oprint ("/p Set your password\n"); oprint ("/name Set your name\n"); oprint ("/nick Set your name\n"); oprint ("/notify Be informed of when someones online\n"); oprint ("/topic Set the topic\n"); oprint ("/bmsg Toggle beep messages\n"); oprint ("/bret Toggle beep return messages\n"); oprint ("/hush Hush someone\n"); oprint ("/unhush Unhush someone\n"); oprint ("/status Change group status\n"); oprint ("/exclude Prevent a user from seeing your message\n"); oprint ("/nobeep Toggle beeps\n"); oprint ("/pass Pass the modship\n"); oprint ("/cols Set display columns (0 for infinite)\n"); oprint ("/rows Set display rows (0 for infinite)\n"); oprint ("/write nick message write message\n"); oprint ("/read read saved messages\n"); oprint ("/confirm ask if you want to quit\n"); oprint ("/time display the time and date\n"); oprint ("/squelch squelch a substring from your display:\n"); oprint (" on Turn on squelching\n"); oprint (" off Turn off squelching\n"); oprint (" pub Turn on squelching for public msgs only\n"); oprint (" pri Turn on squelching for private msgs only\n"); oprint (" add Add a squelch string to the list\n"); oprint (" sub Remove a squelch string from the list\n"); oprint (" rm Remove a squelch string from the list\n"); oprint (" nuke Remove all squelch strings from the list\n"); oprint (" list List your squelch strings\n"); oprint ("/reload Reload a config file\n"); oprint ("/ver Show the version of this icb client\n"); oprint ("/cc X change the command character from '/' to X\n"); oprint ("/q Quit\n"); return HELP; } if ( !strcmp ( foo, "/drop" ) ) { strcpy ( stuff[0], "drop" ); nab_rest ( buf, 1, stuff[1] ); return DROP; } if ( !strcmp ( foo, "/cc" ) ) { nab_one ( buf, 1, stuff[0] ); commandchar = stuff[0][0]; if ( commandchar < ' ' ) commandchar = '/'; if ( commandchar > 126 ) commandchar = '/'; oprint ("[=ORCUS=] Command character is now '%c'\n",commandchar); return NO_CMD; } if ( !strcmp ( foo, "/tabhist" ) ) { dump_tabhistory(0); return NO_CMD; } if ( !strcmp ( foo, "/tabhist-full" ) ) { dump_tabhistory(1); return NO_CMD; } if ( !strcmp ( foo, "/time" ) ) { time_t thetime; thetime = time(NULL); oprint ("%s",ctime(&thetime)); return NO_CMD; } if(!strcmp(foo, "/debug")) /* realtime toggle of debug output */ { if(!debug) { oprint("[=DEBUG=] debug mode on!\n"); debug = YES; } else { oprint("[=DEBUG=] debug mode off!\n"); debug = NO; } return NO_CMD; } if(!strcmp(foo, "/confirm")) /* toggle if quit asks or not */ { if(!confirm_quit) { oprint("[=Confirm=] You will now be asked if you want to quit.\n"); confirm_quit = (int *) YES; } else { oprint("[=Confirm=] You will no longer be asked if you want to quit.\n"); confirm_quit = NO; } return NO_CMD; } if ( !strcmp ( foo, "/p" ) ) { strcpy ( stuff[0], "p" ); nab_one ( buf, 1, stuff[1] ); return PASSWD; } if ( !strcmp ( foo, "/name" ) ) { strcpy ( stuff[0], "name" ); nab_one ( buf, 1, stuff[1] ); return NAME; } if ( !strcmp ( foo, "/nick" ) ) { strcpy ( stuff[0], "name" ); nab_one ( buf, 1, stuff[1] ); return NICK; } if ( !strcmp ( foo, "/notify" ) ) { strcpy ( stuff[0], "server" ); nab_rest ( buf, 0, bigbuf ); bigbuf[0] = ' '; return PRIVATE_MSG; } if ( !strcmp ( foo, "/topic" ) ) { strcpy ( stuff[0], "topic" ); nab_rest ( buf, 1, stuff[1] ); return TOPIC; } if ( !strcmp ( foo, "/bmsg" ) ) { nab_one ( buf, 1, stuff[1] ); if ( !strcmp ( stuff[1], "on" ) ) { bmessage = 1; oprint ("[=Set=] /beep messages displayed when /nobeep is on\n"); return NO_CMD; } if ( !strcmp ( stuff[1], "off" ) ) { bmessage = 0; oprint ("[=Set=] /beep messages ignored when /nobeep is on\n"); return NO_CMD; } bmessage = !bmessage; if ( bmessage ) oprint ("[=Set=] /beep messages displayed when /nobeep is on\n"); else oprint ("[=Set=] /beep messages ignored when /nobeep is on\n"); return NO_CMD; } if ( !strcmp ( foo, "/bret" ) ) { nab_one ( buf, 1, stuff[1] ); if ( !strcmp ( stuff[1], "on" ) ) { breturn = 1; oprint ("[=Set=] senders of ignored /beeps informed\n"); return NO_CMD; } if ( !strcmp ( stuff[1], "off" ) ) { breturn = 0; oprint ("[=Set=] senders of ignored /beeps remain unclued\n"); return NO_CMD; } breturn = !breturn; if ( breturn ) oprint ("[=Set=] senders of ignored /beeps informed\n"); else oprint ("[=Set=] senders of ignored /beeps remain unclued\n"); return NO_CMD; } if ( !strcmp ( foo, "/hush" ) ) { strcpy ( stuff[0], "server" ); nab_rest ( buf, 0, bigbuf ); bigbuf[0] = ' '; return PRIVATE_MSG; } if ( !strcmp ( foo, "/unhush" ) ) { strcpy ( stuff[0], "server" ); nab_rest ( buf, 0, bigbuf ); bigbuf[0] = ' '; return PRIVATE_MSG; } if ( !strcmp ( foo, "/exclude" ) ) { strcpy ( stuff[0], "exclude" ); nab_one ( buf, 1, stuff[1] ); nab_rest ( buf, 2, stuff[2] ); return EXCLUDE; } if ( !strcmp ( foo, "/nobeep" ) ) { nab_one ( buf, 1, stuff[1] ); if ( !strcmp ( stuff[1], "on" ) ) { nobeep = 1; oprint ("[=Set=] nobeep is on\n"); return NO_CMD; } if ( !strcmp ( stuff[1], "off" ) ) { nobeep = 0; oprint ("[=Set=] nobeep is off\n"); return NO_CMD; } nobeep = !nobeep; if ( nobeep ) oprint ("[=Set=] nobeep is on\n"); else oprint ("[=Set=] nobeep is off\n"); return 0; } if ( !strcmp ( foo, "/pass" ) ) { nab_one ( buf, 1, stuff[0] ); return PASS; } if ( !strcmp ( foo, "/cols" ) ) { stuff[0][0] = 0; nab_one ( buf, 1, stuff[0] ); if ( strcasecmp ( &(stuff[0][0]), "auto" ) == 0 ) { /* zzapp -- not implemented yet */ cols = 0; oprint ("[=Set=] columns set to AUTO\n" ); return NO_CMD; } cols = 0; for ( i = 0; stuff[0][i]; i++ ) { cols *= 10; cols += stuff[0][i] - '0'; } if ( cols != 0 ) if ( cols < 23 ) cols = 23; if ( cols > 240 ) cols = 0; oprint ("[=Set=] columns set to %d\n", cols ); return NO_CMD; } if ( !strcmp ( foo, "/rows" ) ) { stuff[0][0] = 0; nab_one ( buf, 1, stuff[0] ); rows = 0; for ( i = 0; stuff[0][i]; i++ ) { rows *= 10; rows += stuff[0][i] - '0'; } if ( rows != 0 ) if ( rows < 2 ) rows = 2; oprint ("[=Set=] rows set to %d\n", rows ); spat = 0; return NO_CMD; } if ( !strcmp ( foo, "/q" ) ) return QUIT; if ( buf[0] == '/' ) if ( buf[1] != commandchar ) { strcpy ( stuff[0], "server" ); nab_rest ( buf, 0, bigbuf ); bigbuf[0] = ' '; server_wrap = 1; return PRIVATE_MSG; } return NO_CMD; } /* end of if "text is a command" */ if(debug) oprint ("analyze: kappa\n"); if ( ( buf[0] == commandchar ) && ( buf[1] == commandchar ) ) alstrcpy ( &bigbuf, buf+1 ); else alstrcpy ( &bigbuf, buf ); if(debug) oprint ("analyze: lambda\n"); return PUB_MSG; } /* end of function */