Well, the easy way is to just try to open the pfile. Here's my
do_rename. It's an immortal command to rename players, so it'll
obviously need to be changed a bit.
void do_rename(CHAR_DATA *ch, char *argument)
{
char buf[MAX_INPUT_LENGTH];
char origfile[MAX_INPUT_LENGTH];
CHAR_DATA *victim;
FILE *fp;
if (IS_NULLSTR(argument))
{
chprintf(ch, "Syntax: RENAME <current-name> <new-name>\n\r");
return;
}
argument = one_argument(argument, buf);
victim = get_char_world(ch, buf);
if (!victim || IS_NPC(victim))
{
chprintf(ch, "Unable to find character named %s.\n\r", buf);
return;
}
if (get_trust(ch) <= get_trust(victim))
{
chprintf(ch, "You don't have permission to rename %s.\n\r", buf);
return;
}
strcpy(buf, capitalize(argument));
if (!check_parse_name(buf))
{
chprintf(ch, "%s is not a legal name.\n\r", argument);
return;
}
sprintf(origfile, "%s%s", PLAYER_DIR, buf);
fp = fopen(origfile, "r");
if (fp)
{
fclose(fp);
chprintf(ch, "Sorry, that character already exists.\n\r");
return;
}
wiznet("$N has been renamed.",victim,NULL,0,0,get_trust(ch));
sprintf(origfile, "%s%s", PLAYER_DIR, capitalize(victim->name));
unlink(origfile);
chprintf(ch, "Player %s renamed.\n\r", victim->name);
free_string(victim->name);
victim->name = str_dup(buf);
save_char_obj(victim);
chprintf(victim, "Your name is now %s.\n\r",victim->name);
}
If you want to look through the directory for some reason, you can use
the opendir/readdir functions. Something like this (untested):
bool player_exists(char *name)
{
DIR *dp = opendir("../player");
struct dirent *de;
while ((de = readdir(dp)) != NULL)
{
if (de->d_name[0] == '.') continue;
if (!strcasecmp(de->d_name, name))
return TRUE;
}
closedir(dp);
return FALSE;
}
Or you can do it with glob(3) too, but that thing kind of scares me.
--Palrich.
On 6/27/05, Sandi Fallon <[EMAIL PROTECTED]> wrote:
> Sorry, Mike, I should have explained a bit more.
>
> On my MUD, after choosing a name and password, you're in the game.
> All the "creation" stuff is done in rooms, so you can ask questions
> on channels, or even have someone there to help you. So, at the time
> of renaming, the player is logged into the game.
>
> I need to check that their new name doesn't match some other player's
> name, even if the other player isn't logged in, and that's the reason
> for the list. Unless opening and closing a file is more efficient...
>
>
> Sandi
>
>
> PS: Speaking of player names, Dom, have you been dropping by?
>
> --
> ROM mailing list
> [email protected]
> Unsubscribe here ->>> http://www.rom.org/cgi-bin/mailman/listinfo/rom
>