/* v.1 comm_stats.c tracks command stats usage ...how many of each command is used ...and whut percentage that is to all commands used Requirments: ewtoo derivitive talker Installing: place this file in src directory edit the Makefile to have it compile this as one of your talkers object files... in parse.c : add the following extern... extern void commandUsed ( char * ); in parse.c : match_commands () rol = do_match (str, comlist); if (rol) { ***** add this line here ***** commandUsed (comlist->text); ****************************** last_com = comlist; add a command for the function statCommands() it in clist.h... at whut level of privs is your perogative Notes: be prepared to see 0% usage.... it rounds downish when calculating percents and many commands are rarely touched like that. Bug Reports: send to phypor@benland.muc.edu Licences: freely distributable and modifiable, as long as this full header kept with any distributions and any modifications to original marked plainly so. Warrenty: 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 #include #include #include #include "proto.h" #include "config.h" #include "fix.h" /* this should be larger than the amount of commands you have */ #define COM_ARRAY_SIZE 500 typedef struct comentry { char which[80]; int hitz; } comentry; comentry *ExistantCommands[COM_ARRAY_SIZE]; comentry *findExistantCommand ( char * str ) { int i; for (i = 0; ExistantCommands[i]; i++) if (!strcasecmp (ExistantCommands[i]->which, str)) return ExistantCommands[i]; return (comentry *) NULL; } void addToExistantCommand ( comentry * this ) { int i; for (i = 0; (ExistantCommands[i] && i < COM_ARRAY_SIZE); i++); if (i == COM_ARRAY_SIZE) /* array is full dammit */ return; ExistantCommands[i] = this; } void commandUsed ( char * str ) { comentry *that; that = findExistantCommand (str); if (that) { that->hitz++; return; } that = (comentry *) MALLOC (sizeof (comentry)); if (!that) { log ("error", "malloc fails in commandUsed()"); return; } memset (that, 0, sizeof (comentry)); that->hitz = 1; strncpy (that->which, str, strlen (str)); addToExistantCommand (that); } /* we have to loop through twice, the first time to get the total, the second to get ratios and stuff */ void statCommands ( player * p, char * str ) { char *oldstack = stack; int total, masstotal; int i, l; int tp; stack += sprintf (stack, "------------------------- Commands " "Statistics -------------------------------\n"); for (masstotal = 0, total = 0; ExistantCommands[total]; total++) masstotal += ExistantCommands[total]->hitz; /* the way this is formated for output isnt perfect (altho works) it wouldnt mind some tlc making it so */ for (i = 0, l = 1; ExistantCommands[i]; i++, l++) { tp = ((ExistantCommands[i]->hitz * 10000) / masstotal); stack += sprintf (stack, "%13s %4d %3d%%", ExistantCommands[i]->which, ExistantCommands[i]->hitz, tp / 100); if (l > 2) { stack += sprintf (stack, "\n"); l = 0; } } stack += sprintf (stack, "\n----------------- %4d commands " "used %6d times ---------------------------\n", total, masstotal); stack = end_string (stack); if (p->saved_flags & NO_PAGER) tell_player (p, oldstack); else pager (p, oldstack, 1); stack = oldstack; }