/** /* $Id: show.c,v 1.1 1998/02/13 08:56:14 falcon Exp $ /* ORCUSSHOW.C display and response functions for orcus */ /**/ #include "config.h" #include #include #include #ifdef COLOR #include "ocolor.h" #endif #ifdef USEVARARGS #include #else #include #endif #include "prototypes.h" #include "defs.h" extern int squelch_status; extern lroot squelches; extern int silent_running; extern char *bretnag; static time_t laststamp = 0; static time_t lastflush = 0; /* interface */ time_t filestamp_period = 3600; void more_prompt() { char foo; extern int rows; extern int cols; extern int spat; extern int nomore; if ( nomore ) return; if ( !rows ) return; if ( silent_running ) return; if ( spat >= rows ) { printf ("[=more=]"); fflush ( stdout ); while (!fdpoll(0)) sleep(1); read ( 0, &foo, 1 ); switch ( foo ) { case ' ' : spat = 0; break; case '\n': spat--; break; default : spat = 0; nomore = foo; break; } printf ("%c%c%c%c%c%c%c%c %c%c%c%c%c%c%c%c", 8,8,8,8,8,8,8,8, 8,8,8,8,8,8,8,8); fflush ( stdout ); } } /* end of function more_prompt() */ void log_this ( char *this ) { extern FILE *logfile; extern int logstate; extern int logtimes; time_t curtm; if ( this == NULL ) return; if ( strlen(this) < 1 ) return; if ( logfile == NULL ) return; if ( logstate == 0 ) return; fprintf ( logfile, this ); if ( strstr ( this,"\n" ) ) { curtm = time(NULL); switch ( logtimes ) { case 1: if ( time(NULL) - laststamp > filestamp_period ) { fprintf ( logfile, "## timestamp1 %d = %s", curtm, ctime(&curtm) ); laststamp = curtm; } break; case 2: fprintf ( logfile, "## timestamp2 %d = %s", curtm, ctime(&curtm) ); laststamp = curtm; break; } // end of switch ( logtimes ) if ( time(NULL) - lastflush > 300 ) { fflush ( logfile ); lastflush = time(NULL); } } } void oprint ( char *fmt, ... ) { va_list argl; extern FILE *logfile; extern int logstate; extern int logtimes; extern int spat; time_t curtm; va_start ( argl, fmt ); if ( !silent_running ) { #ifdef COLOR if ( colorize ) { int new_color = ocolor_get(); if ( current_color != new_color ) ocolor_set ( new_color ); } #endif vprintf ( fmt, argl ); } if ( ( logfile != NULL ) && ( logstate != 0 ) ) { vfprintf ( logfile, fmt, argl ); if ( strstr ( fmt,"\n" ) ) { curtm = time(NULL); switch ( logtimes ) { case 1: if ( time(NULL) - laststamp > filestamp_period ) { fprintf ( logfile, "## timestamp3 %d = %s", curtm, ctime(&curtm) ); laststamp = curtm; } break; case 2: fprintf ( logfile, "## timestamp4 %d = %s", curtm, ctime(&curtm) ); laststamp = curtm; break; } // end of switch ( logtimes ) if ( time(NULL) - lastflush > 300 ) { fflush ( logfile ); lastflush = time(NULL); } } } va_end ( argl ); if ( !silent_running ) if ( strstr(fmt,"\n") != NULL ) { spat++; more_prompt(); } } /* end of function oprint() */ void go_show_open_message ( stub, buf ) char *stub, *buf; { char scratch[255]; int i, last_str, buflen, stublen, linelen, wrap; extern int cols; extern int spat; extern int stamping; int cols_ = cols; char stampstr[28]; char *stampptr = stampstr; strl *finger; if ( squelch_status && SQUELCH_OPEN ) { finger = squelches.h; for ( i = 0; i < squelches.n; i ++ ) { if ( strstr ( buf, finger->d ) != NULL ) return; finger = finger->next; } /* end of for */ } /* end of if */ stampstr[0] = 0; stampptr = stampstr; if ( stamping ) { time_t curtm; cols_ -= 26; if ( cols_ < 1 ) cols_ = 10; curtm = time(NULL); strcpy ( stampstr, ctime(&curtm) ); stampstr[strlen(stampstr)-1] = ' '; switch ( stamping ) { case 1 : stampptr = &(stampstr[11]); stampstr[20] = 0; break; case 2 : stampptr = &(stampstr[8]); stampstr[20] = 0; break; case 3 : stampstr[20] = 0; break; } } if ( !cols_ ) { oprint ("%s<%s> %s\n", stampptr, stub, buf ); } else { wrap = 10; if ( cols_ < 35 ) wrap = 5; if ( cols_ > 45 ) wrap = 15; buflen = strlen ( buf ); stublen = strlen ( stub ) + 3; last_str = 0; while ( ( buflen - last_str ) + stublen > cols_ ) { linelen = last_str - stublen + cols_; for ( i = linelen; ( i > linelen - wrap ) && ( buf[i] != ' ' ); i-- ); strncpy ( scratch, buf + last_str, i - last_str ); scratch[i-last_str] = 0; last_str = i; oprint ("%s<%s> %s\n", stampptr, stub, scratch); while ( buf[last_str] == ' ' ) last_str++; } /* end of while */ if ( last_str < buflen ) oprint ("%s<%s> %s\n", stampptr, stub, buf+last_str); } /* end of if */ } void go_show_pers_message ( stub, buf ) char *stub, *buf; { char scratch[255]; int i, last_str, buflen, stublen, linelen, wrap; extern int cols; extern int spat; extern int stamping; int cols_ = cols; char stampstr[28]; char *stampptr; strl *finger; if ( squelch_status && SQUELCH_PRIVATE ) { finger = squelches.h; for ( i = 0; i < squelches.n; i ++ ) { if ( strstr ( buf, finger->d ) != NULL ) return; finger = finger->next; } /* end of for */ } /* end of if */ stampstr[0] = 0; stampptr = stampstr; if ( stamping ) { time_t curtm; cols_ -= 26; if ( cols_ < 1 ) cols_ = 10; curtm = time(NULL); strcpy ( stampstr, ctime(&curtm) ); stampstr[strlen(stampstr)-1] = ' '; switch ( stamping ) { case 1 : stampptr = &(stampstr[11]); stampstr[20] = 0; break; case 2 : stampptr = &(stampstr[8]); stampstr[20] = 0; break; case 3 : stampstr[20] = 0; break; } } if ( !cols_ ) { oprint ("%s<*%s*> %s\n", stampptr, stub, buf ); } else { wrap = 10; if ( cols_ < 35 ) wrap = 5; if ( cols_ > 45 ) wrap = 15; buflen = strlen ( buf ); stublen = strlen ( stub ) + 3; last_str = 0; while ( ( buflen - last_str ) + stublen > cols_ ) { linelen = last_str - stublen + cols_; for ( i = linelen; ( i > linelen - wrap ) && ( buf[i] != ' ' ); i-- ); strncpy ( scratch, buf + last_str, i - last_str ); scratch[i-last_str] = 0; last_str = i; oprint ("%s<*%s*> %s\n", stampptr, stub, scratch); // TTK here -- trying to solve the stagger problem with this while loop: while ( buf[last_str] == ' ' ) last_str++; } /* end of while */ if ( last_str < buflen ) oprint ("%s<*%s*> %s\n", stampptr, stub, buf+last_str); } /* end of if */ } void go_show_status_update ( stub, buf ) char *stub, *buf; { oprint ("[=%s=] %s\n", stub, buf ); } void go_show_wholine ( buf ) char *buf; { int i, j, k; char nick[32]; char login[32]; char mach[128]; char dadate[32]; char whobuf[300]; int idle; time_t timestamp; extern int display_idle_threshold; extern int cols; k = strlen ( buf ); /* storing the length of original string */ idle = 0; timestamp = 0; for ( i = 0; i < k; i++ ) /* cutting up buf into substrings */ if ( buf[i] == 1 ) buf[i] = 0; if ( buf[0] == 'm' ) oprint (" *"); else oprint (" "); /* moderator? */ j = 0; /* j indexes the destination string buffer */ for ( i = 2; buf[i]; i++ ) { /* copying the user's nick */ nick[j] = buf[i]; j++; } nick[j] = 0; j = 0; /* terminating nick[], resetting j */ for ( i++; buf[i]; i++ ) { /* extracting idle seconds */ idle *= 10; idle += ( buf[i] - '0' ); } for ( i++; buf[i]; i++ ); /* skipping next field; dunno what it does */ for ( i++; buf[i]; i++ ) { /* extracting timestamp of user's login */ timestamp *= 10; timestamp += ( buf[i] - '0' ); } for ( i++; buf[i]; i++ ) { /* extracting user's account name */ login[j] = buf[i]; j++; } login[j] = 0; j = 0; for ( i++; buf[i]; i++ ) { /* extracting user's host system name */ mach[j] = buf[i]; j++; } mach[j] = ' '; j++; for ( i++; buf[i]; i++ ) { /* extracting unregistered field */ mach[j] = buf[i]; j++; } mach[j] = 0; j = 0; /* constructing time + date string */ dadate[0] = '0' + gmtime(×tamp)->tm_mon / 10; dadate[1] = '0' + gmtime(×tamp)->tm_mon % 10; dadate[2] = '/'; dadate[3] = '0' + gmtime(×tamp)->tm_mday / 10; dadate[4] = '0' + gmtime(×tamp)->tm_mday % 10; dadate[5] = ' '; dadate[6] = '0' + gmtime(×tamp)->tm_hour / 10; dadate[7] = '0' + gmtime(×tamp)->tm_hour % 10; dadate[8] = ':'; dadate[9] = '0' + gmtime(×tamp)->tm_min / 10; dadate[10] = '0' + gmtime(×tamp)->tm_min % 10; dadate[11] = 0; if ( idle < display_idle_threshold ) sprintf ( whobuf, "%-12s --- %s %s@%s\n", nick, dadate, login, mach ); else sprintf ( whobuf, "%-12s %2dh %2dm %2ds %s %s@%s\n", nick, (idle/3600), (idle/60)%60, idle%60, dadate, login, mach ); if ( cols ) if ( strlen(whobuf) >= cols ) if ( cols < 300 ) { whobuf[cols] = 0; whobuf[cols-1] = '\n'; } oprint ( whobuf ); } void go_show_command_output ( stub, buf ) char *stub, *buf; { extern int spat; if ( !strcmp ( "wh", stub ) ) oprint (" Nick Idle Login\n"); else if ( !strcmp ( "wl", stub ) ) go_show_wholine ( buf ); else oprint ("%s\n", buf ); } void go_login_verified() { /* stuff[] not valid */ oprint ("[=login-verified=]\n"); } void go_we_must_exit() { /* stuff[] not valid */ oprint ("[=ORCUS=] The server has told us to exit.\n"); orc_quit(); } void go_protocol_version() { /* stuff[] not valid */ oprint ("[=ORCUS=] Protocol verified with server.\n"); } void go_show_error(buf) char *buf; { oprint ("[=ERROR=] %s\n", buf ); } void go_announcement(what,buf) char *what, *buf; { oprint ("[=%s=] %s\n", what, buf ); } void go_gotum_beep(buf) char *buf; { extern int nobeep; extern int bmessage; extern int breturn; extern int s; if ( !nobeep ) { oprint ("%c",7); fflush(stdout); } if ( !nobeep || bmessage ) oprint ("[=beep=] from %s\n", buf ); if ( nobeep && breturn ) { if ( bretnag != NULL ) writepriv ( s, buf, bretnag ); else writepriv ( s, buf, "This user not accepting beeps" ); } } void go_gotum_ping(buf) char *buf; { oprint ("[=ping=] from %s\n", buf ); }