/* NameError.c V1.3
 * This code will send pc's different error messages during the log-in/creation

 * process to tell them why their name isn't allowed.  As well as protecting

 * 'famous names' Like zugg, hatchet, erwin, darkoth, etc.

 *

 * Updated September 2, 2000
 * Written by Snafu Life. (copyright 2000) of the (coming soon) mud Aacacia. (Rom2.4b6).

 * Special thanx to Myles Skinner and Malcom Valentine for their contributions

 * in the creation/wording of the error messages.
Also, a special thanx to
 * Alex Fletcher, for his help in weeding out some extraneous code.
 * 

 * This code is given to you almost freely upon the following conditions:

 * These conditions must be included when distributed in any form including

 * but not limited to modified works.

 * 

 * Neither I nor anyone else that modifies or distributes this snip can

 * require credit be given in any form. Credit is welcomed but is at the

 * sole discretion of the End User. End User, as used here, is defined as the

 * person who has copyrights over the source this snip or a modified

 * version of this snip is being placed into. The End User shall not be charged

 * for access or use of this snip or a modified version. 

 */



/* In merc.h under the act_wiz.c comment, I also use Voltecs rename command so

 * that is why i define it there. If you don't use a rename command you could

 * define it comm.c by replacing bool check_parse_name args((char *name)); in

 * the local functions comment

 */

int check_parse_name	args((char *name));


/* Right before "Other local functions(OS-independant)"
 */

/* Used for Name validation */
#if defined(MSDOS) 
#define MAX_NAME_LENGTH   8 
#else    /* if defined(macintosh) || defined(unix) */ 
#define MAX_NAME_LENGTH  12 
#endif 



/* in comm.c under the "Other local functions (OS-indepent)" comment, delete

 * bool	check_parse_name	args( ( char *name ) );

 */







/* If you already have modified check_parse_name() you can use this

 * as a reference if not you may choose to replace as suggested

 */





/* in void nanny() at the top replace 



    char buf[MAX_STRING_LENGTH];

 */



    char buf[MAX_STRING_LENGTH],log_buf[MAX_STRING_LENGTH];



/* and     int iClass,race,i,weapon; 

   with:

 */



    int iClass,race,i,weapon,x;



/* Lower case cap freako's example CrashBurn becomes Crashburn

 *

 * After     while ( isspace(*argument) )

		argument++;

 */



    while ( isspace(*argument) ) {

	argument++;

    }




 /* This is a change from the second version.
    * If you don't add this you will experience
    * a lack of capital letters in various areas
    * of your code :(
   if (d->connected == CON_GET_NAME ) {
	c='0';

	x=0;

	while(c != '\0') {

		c = argument[x];

		c = tolower(c);

		argument[x] = c;

		x++;

        }



   }





/* In void nanny() under case CON_GET_Name right replace 



	if ( !check_parse_name( argument ) )

	{

	    write_to_buffer( d, "Illegal name, try another.\n\rName: ", 0 );

	    return;

	}



 * with: 

 */



	if(check_parse_name(argument) != 0) {

       switch(check_parse_name(argument)) {

		/* REPLACE Aacacian with your mud name */

	  case 1: write_to_buffer( d, 

	  "The name you have chosen has been reserved by the Aacacian Administration.\n\r",0);

 		  write_to_buffer(d,"Please choose again.\n\rName:\n\r",0);

   		break;

	  case 2: write_to_buffer( d, 

	  "A clan has reserved that name for their use. Please choose again.\n\rName: ", 0 );

		break;

          case 3: write_to_buffer(d,"This name is a well known name in the mud'ing community.\n\r",0);

		  write_to_buffer(d,"If you really are this person:\n\r",0);

 		  write_to_buffer(d,"Please, create under a different name and send an e-mail\n\r",0);

		/* REPLACE BELOW WITH YOUR E-mail Address */

		  write_to_buffer(d,"to aacacia@coming_soon from a verifiable e-mail address.\n\r",0);

		  write_to_buffer(d,"We welcome your presence, but to protect ourselves as\n\r",0);

		  write_to_buffer(d,"well as to protect you from impersonators, we have\n\r",0);

		  write_to_buffer(d,"temporarily placed your name on hold.\n\r",0);

 		  write_to_buffer(d,"If you are not this person, you have our apologies for\n\r",0);

 		  write_to_buffer(d,"the unavailability of this name but hope you will choose\n\r",0);



 		  write_to_buffer(d,"another name instead.\n\rName:",0);

		  sprintf(log_buf,"Log: Famous Name: %s@%s",argument,d->host);

		  wiznet(log_buf,ch,NULL,WIZ_SECURE,0,get_trust(ch));

		  log_string(log_buf);

		  break;



 	  case 4: write_to_buffer( d,
 
                "The name chosen must be between 3 and %d characters in length.\n", MAX_NAME_LENGTH);
		break;
 	  case 5: write_to_buffer(d,"Only letters (A-Z) are allowed.\n\rName: ", 0 );

  		break;

  	}

	return;

       }







/*  in comm.c replace bool check_parse_name() with: 

 */



/*

 * Parse a name for acceptability.

 */

int check_parse_name( char *name )

{

    int clan;



    /*

     * Reserved words.

     */

	/* If you have changed is_exact_name you may want to replace it with

         * your keywaords, if not change aacacia to your mud name

         */

    if (is_exact_name(name,

	"all aac mob aacacia auto immortal self someone something the you loner none"))

      {

	return 1;

      }



    /* check clans */

    for (clan = 0; clan < MAX_CLAN; clan++)

    {

	if (LOWER(name[0]) == LOWER(clan_table[clan].name[0])

	&&  !str_cmp(name,clan_table[clan].name))

	   return 2;

    }



	/* PROTECT OURSELF FROM IMPOSTERS IF ONE OF THESE VISITS

	 * And sends you confirmation that is who they are then all

         * you have to do is remove their name from the list and

         * change their temp pfile accordingly */

    if ((str_cmp(capitalize(name),   "Alander")

	 || str_cmp(capitalize(name),"Zugg")

	 || str_cmp(capitalize(name),"Snafu") /* Hopefully, Someday ;) */

         || str_cmp(capitalize(name),"Lope")

	 || str_cmp(capitalize(name),"Ivan")

	 || str_cmp(capitalize(name),"Askirius")

	 || str_cmp(capitalize(name),"Erwin")

	 || str_cmp(capitalize(name),"Furey")

	 || str_cmp(capitalize(name),"Hatchet")

	 || str_cmp(capitalize(name),"Kahn")

	 || str_cmp(capitalize(name),"Darkoth")

	 || str_cmp(capitalize(name),"Voltec")

	 || str_cmp(capitalize(name),"Kavir"))

	&& (!str_prefix("Alan",name) 

           || !str_suffix("Alander",name))){

	   /* This is a list in progress There may be more

	    * you want to add

            */

	return 3;

    }



    /*

     * Length restrictions.

     */

	  if ( (strlen(name) <  3) || strlen(name) > MAX_NAME_LENGTH) { 
		return 4; 
	  }


    /*

     * Alphanumerics only.

     * Lock out IllIll twits.

     *

     * Most of the old stuff is now no longer needed

     * cut-off to save space.

     */

    {

	char *pc;

	bool fIll=TRUE;



	for ( pc = name; *pc != '\0'; pc++ )

	{

            /* No digits (0-1) or punctuation in name */

	    if(!isalpha(*pc))

		return 5;



	    /* Took out ugly anti-caps hace replaced in nanny() */





	    if ( LOWER(*pc) != 'i' && LOWER(*pc) != 'l' )

		fIll = FALSE;

	}



	if ( fIll ) {

	   return 1;

	}

    }



    /*

     * Prevent players from naming themselves after mobs.

     */

    {

	extern MOB_INDEX_DATA *mob_index_hash[MAX_KEY_HASH];

	MOB_INDEX_DATA *pMobIndex;

	int iHash;



	for ( iHash = 0; iHash < MAX_KEY_HASH; iHash++ ) {

	    for ( pMobIndex  = mob_index_hash[iHash];

		  pMobIndex != NULL;

		  pMobIndex  = pMobIndex->next ) {

		if ( is_name( name, pMobIndex->player_name ) ) {

		    return 1;
		}

	    }

	}

    }



    /* Prevent players from naming themselves objects */

    {

	extern OBJ_INDEX_DATA *obj_index_hash[MAX_KEY_HASH];

	OBJ_INDEX_DATA *pObjIndex;

	int iHash;



	for ( iHash = 0; iHash < MAX_KEY_HASH; iHash++ )

	{

	    for ( pObjIndex  = obj_index_hash[iHash];

		  pObjIndex != NULL;

		  pObjIndex  = pObjIndex->next )

	    {

		if ( is_name( name, pObjIndex->name ) ) {

		    return 1;

		}

	    }

	}

    }



    /* Prevent players from naming themselves command names */

    {

	int cmd, iHash;



	for ( iHash = 0; iHash < MAX_KEY_HASH; iHash++ )

	{

		for ( cmd = 0; cmd_table[cmd].name[0] != '\0'; cmd++ )

		{

			if (is_name( name, cmd_table[cmd].name))

			{

			return 1;

			}

		}

	}

     }

	return 0;

}



/* Make sure your replace references to Aacacia or Aacacian

 * with your mud's name and/or e-mail addy as the case may be.

 * that is all there is to it. if you want to drop me a line:

 * snafulife@home.com or snafu.life@usa.net if I have moved and

 * the previous doesn't work.

 */