/* left this for copyright stuff, and so i dont get ppl mad at me */ /****************************************************************** * RENAME.C Version 1.1 * * Written by Voltec (Voltec@cyberdude.com) 1998 * * For Empire Of The Night (eotn.oaktree.co.uk 4100) * * All the usual DIKU/MERC/ROM/EOTN Licences apply * * If you use this code, drop me a line so I can see if people * * Actually find this usefull. * * REMEMBER * * Share and Enjoy! -Voltec 98 * ******************************************************************/ /* add to act_wiz.c * and other apporpriate places :) * code by belial, idea taken from voltec's rename * code....basically hacked up and made smaller :), * also, comes complete with comments! for the budding * coder to know whats going on */ #include #include #include "merc.h" #include "recycle.h" #include "tables.h" bool valid_name args( (char *name) ); bool check_parse_name args( ( char *name ) ); bool valid_name(char *name) { bool valid = FALSE; char pfile_path[MAX_STRING_LENGTH]; FILE *renamefp; fclose(fpReserve); sprintf(pfile_path, "%s%s", PLAYER_DIR, capitalize( name ) ); /* if its == NULL, then the pfile doesnt exists...right? */ if ( (renamefp = fopen(pfile_path, "r")) == NULL) valid = check_parse_name(name); else { valid = FALSE; fclose(renamefp); } fpReserve = fopen( NULL_FILE, "r" ); return valid; } void do_renamepc(CHAR_DATA *ch, char *argument) { CHAR_DATA *victim; char buf[MAX_STRING_LENGTH]; char arg1[MAX_STRING_LENGTH]; char new_name[MAX_STRING_LENGTH]; char old_name[MAX_STRING_LENGTH]; char old_pfile[MAX_STRING_LENGTH]; argument = one_argument(argument, arg1); argument = one_argument(argument, new_name); /* sorry, no forcing and switching to run this command */ if (IS_NPC(ch)) return; /* check for NULL Parameters, so mud dont crash */ if ((arg1[0] =='\0') || (new_name[0]=='\0')) { send_to_char("Syntax: Rename \n\r", ch); return; } /* find the sucker, i mean person to be renamed :) */ if ((victim = get_char_world(ch, arg1)) == NULL) { send_to_char("To rename, they have to be online.\n\r", ch); return; } /* Sorry, Morts only */ if (IS_NPC(victim)) { send_to_char("Not on NPC's\n\r", ch); return; } /* no fucking with your superiors :P */ if (get_trust(ch) < victim->level) { send_to_char("Not on your superiors or peers.\n\r",ch); return; } /* YEAH!, if valid we rename!, if not, choose another name *doh* */ if (valid_name(new_name)) { strcpy(new_name, capitalize(new_name)); /* log who was changed to who and who changed them :) */ sprintf(buf, "%s renamed to %s\n\r", victim->name, new_name); send_to_char(buf,ch); sprintf(buf, "%s renamed %s to %s", ch->name, victim->name, new_name); log_string( buf ); send_to_char("Your name has been changed.\n\r", victim); /* grab old name, insert new name, Save the new p-file */ update_wizlist(victim,1); strcpy(old_name, victim->name); strcpy(victim->name, new_name); update_wizlist(victim,victim->level); save_char_obj(victim); /* Delete the old p-file, AFTER THE NEW ONE IS SAVED, in case of crash */ sprintf( old_pfile, "%s%s", PLAYER_DIR, capitalize( old_name ) ); unlink( old_pfile ); } else { /* Try again! */ send_to_char("Illegal Name, try another.\n\r", ch); return; } }