/********************************************************************* v.1 last.c track last ppl logins similar to '/var/log/wtmp' and 'last' on unicies. Requirments: ewtoo derivitive talker Installing: place this file into your src directory edit your Makefile to include this file in compliation of your talker place the lines: extern void stampLogin ( char * ); extern void stampLogout ( char * ); in proto.h (player.h for those without a prototypes file) modify the include of proto.h (to player.h) if neccessary add stuff for the command in clist.h calling the function 'viewLast' in parse.c ... process_players () make the following addition... if (scan->location && scan->name[0] && !(scan->flags & RECONNECTION)) { /** add this line **/ stampLogout (scan->name); /*******************/ in plists.c ... link_to_program() if (p->flags & RECONNECTION) { . . . } else { /** add this line **/ stampLogin (p->name); /*******************/ Notes: the installation point in plists.c may appear not exactly as shown here... as long as the function is called at some point when the player is going to successfully login (and isnt reconnecting), it shouldnt matter where you place it. Bug Reports: send to phypor@benland.muc.edu Licences: freely distributable and modifiable, as long as credit given in appropritate places for any distrubitions (be it this alone or within another package) Warranty: non, the author is in no way responsible for use, misuse, abuse, or any other actions misactions, reactions of this code, its provided as is. Author: phypor "if it breaks you get to keep both pieces" ~old linux proverb *********************************************************************/ #include #include #include #include #include "proto.h" #include "config.h" /* how many entries are kept total */ #define LAST_KEPT 200 /* the default entries shown when 'last' command used */ #define LAST_SHOW 20 /* non configuration define */ #define STILL_IN -1 struct lastinfo { char name[MAX_NAME]; int in; int out; }; typedef struct lastinfo lastinfo; lastinfo Wtmp[LAST_KEPT]; char *diff_time ( int, int ); char *diff_time ( int start, int end ) { int ne; static char be[40]; start -= time (0); end -= time (0); ne = end - start; if (ne < 1) return "Quick"; memset (be, 0, 40); sprintf (be, "%.2d:%.2d.%.2d", (ne / (60 * 60)), ((ne / 60) % 60), (ne % 60)); return be; } void stampLogin ( char * name ) { int i = 0; for (i = LAST_KEPT; i > 0; i--) memcpy (&Wtmp[i], &Wtmp[i - 1], sizeof (lastinfo)); strncpy (Wtmp[0].name, name, MAX_NAME - 1); Wtmp[0].in = time (0); Wtmp[0].out = STILL_IN; } void stampLogout ( char * name ) { int i = 0; while (i < LAST_KEPT) { if (!strcasecmp (Wtmp[i].name, name)) break; i++; } if (i == LAST_KEPT) return; Wtmp[i].out = time (0); } void viewLast ( player * p, char * str ) { int i, j, hit = 0; char *oldstack = stack; if (*str && isdigit (*str)) { j = atoi (str); if (j < 1) j = LAST_SHOW; if (j > LAST_KEPT) j = LAST_KEPT; *str = '\0'; } else if (*str) j = LAST_KEPT; else j = LAST_SHOW; for (i = 0; (i < LAST_KEPT && hit < j); i++) { if (Wtmp[i].name && Wtmp[i].name[0]) { if (Wtmp[i].out == STILL_IN) continue; if (*str && strcasecmp (str, Wtmp[i].name)) continue; stack += sprintf (stack, "%-15s %-42s ", Wtmp[i].name, convert_time ((Wtmp[i].out + (p->jetlag * 3600)))); stack += sprintf (stack, "%s\n", diff_time (Wtmp[i].in, Wtmp[i].out)); hit++; } } if (!hit) stack += sprintf (stack, " None found in last logins\n"); stack = end_string (stack); tell_player (p, oldstack); stack = oldstack; }