/********************************************************************* v.1 wildcard.c functions for quick, powerful wildcard name banishment Requirments: ewtoo direvitive talker glob package (http://benland.muc.edu/~clouds/code/glob.tar.gz) Installing: place this file in src directory edit your Makefile to have this compiled as an object file and added into the finished binary that is your talker add handling of the varible 'wildcard_file' of type file to approiate places (such as its initial loading in plists.c, and its reload in admin.c, and an extern in proto.h) ... it should be loaded from files/banish_wildcard as currently set in this code add commands in clist.h for the following functions: add_wildcard accepts argument, that argument will be added to the wildcard banish file and the file reloaded check_wildcard used without arguments it shows the player the entire wildcard banish file used with an argument it attempts to match arg and determine if a given string is wildcarded or not extern the function int wildcard_banish ( char * ); at least in plists.c, preferply in proto.h or player.h change ez_su_wall_but and ez_tell_player to whutever your version of these printf format functions are if needed in plists.c : got_name() function towards the bottom of the function, directly above the line tell_player(p, newpage1_msg.where); add the following bit: if (wildcard_banish (p->name) < 0) { tell_player (p, "\n\n That name is banished (wildcard) ...\n" " Please try another.\n\n"); do_prompt (p, "Please enter a name:"); p->input_to_fn = got_name; stack = oldstack; return; } in plists.c : got_new_name() just above the line newbie_get_gender(p, str); add the following: if (wildcard_banish (p->name) < 0) { tell_player (p, "\n\n That name is banished (wildcard) ...\n" " Please try another.\n\n"); do_prompt (p, "Please enter a name:"); p->input_to_fn = got_new_name; stack = oldstack; return; } Notes: you dont have to have a files/banish_wildcard existant... if there isnt one the first time you use the command to add an entry, it will be created and filled with default stuff and some basic glob info. in the actual wildcard file, any whitespace delimits entries it is suggested you use \n's for the sake of readablity if you edit it directly... this only checks (if installed as instructed) for wildcards on newbies...not for residents... this is most likely how you want it... so you can give sus this command and not have to worry about them inadvertantly banishing an admin name or some other minor havok make sure you have the glob thinger installed (its only two files... so it wont take long) 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 #include #include "proto.h" /* player.h if you arent sensi enhanced */ #include "config.h" #include "glob.h" file wildcard_file; /* given a str, see if it matches any entries in the wildcard file... return -1 if there is a match, 0 if non */ int wildcard_banish ( char * str ) { char *oldstack = stack; char *fptr; if (!wildcard_file.where) return 0; fptr = wildcard_file.where; while (*fptr) { for (stack = oldstack; /* reset the stack */ (*fptr && !isspace (*fptr) && *fptr != '#'); /* while line and !# */ *stack++ = *fptr++); /* copy in and increment*/ if (*fptr == '#') /* increment past comments */ { while (*fptr && *fptr != '\n') fptr++; if (*fptr) fptr++; continue; } if (*fptr) /* if *ptr is NULL, dont increment past it */ fptr++; *stack++ = '\0'; if (glob (str, oldstack)) { stack = oldstack; return -1; } } stack = oldstack; return 0; } /* command function used without arguments it shows the player the entire wildcard banish file used with an argument it attempts to match arg and determine if a given string is wildcarded or not */ void check_wildcard ( player * p, char * str ) { if (!*str) { if (!(wildcard_file.where) || !(wildcard_file.where[0])) { tell_player (p, " No wildcard file loaded atm.\n"); return; } if (p->saved_flags & NO_PAGER) tell_player (p, wildcard_file.where); else pager (p, wildcard_file.where, 1); return; } if (wildcard_banish (str) < 0) ez_tell_player (p, " The string '%s' is wildcard banished.\n" " (assuming its not the name of a resident)\n", str); else ez_tell_player (p, " The string '%s' is Not wildcard banished.\n", str); } /* command function ... accepts argument, that argument will be added to the wildcard banish file and the file reloaded */ void add_wildcard ( player * p, char * str ) { int fd; if (!*str) { tell_player (p, " Format : banish_wildcard \n"); return; } if (smatch_check (str) == FALSE) { ez_tell_player (p, " Bad glob pattern : %s\n", glob_error); return; } fd = open ("files/banish_wildcard", (O_WRONLY | O_CREAT | O_TRUNC | O_SYNC), (S_IRUSR | S_IWUSR)); if (fd < 0) { ez_tell_player (p, " Failed to open the wildcard banish file...\n" " Errno %d, %s\n", errno, strerror (errno)); return; } if (wildcard_file.where && wildcard_file.where[0]) sprintf (stack, "%s\n# %s - %s\n%s\n", wildcard_file.where, sys_time (), p->name, str); else sprintf (stack, "# Wildcard Banished Names File\n" "# Lines beginning with # are comments\n#\n" "# tokens are as follows:\n" "# * match any string of characters or no characters\n" "# ? match any single character\n" "# {} match diffrent sets of characters, seperated by a |\n" "# [] match any characters, or not if proceeded by a ^\n" "# \\ designates the next character to be taken literally\n" "#\n" "# all other characters match themselves, case is INsensitive\n" "#\n" "# Examples:\n" "# Pattern Possible matches\n" "# *foo* kungfoo, foobar, foOLIsh\n" "# b?d bud, bod, bad\n" "# m[sr]. Mr., Ms., ms., mr.\n" "# [a-z]ah aah, bah, cah, dah, eah, fah\n" "# {fog|blunt} * fog cover, blunt edge\n\n" "# %s - %s\n%s\n", sys_time (), p->name, str); write (fd, stack, strlen (stack)); close (fd); if (wildcard_file.where) FREE (wildcard_file.where); wildcard_file = load_file ("files/banish_wildcard"); tell_player (p, " Banish successful.\n"); ez_su_wall_but (p, " <*> %s wildcard banishes : %s\n", p->name, str); }