Added the ability to change a player's name (using the set command) --Jamdog

This commit is contained in:
JamDog 2009-02-05 18:11:27 +00:00
parent cebf6cc9f9
commit 4afedefb30
5 changed files with 264 additions and 156 deletions

View file

@ -35,6 +35,8 @@ export (QQ's a zone into a tarball)t
Xlist (mlist, olist, rlist, zlist, slist, tlist, qlist)
(lots of major bugfixes too)
tbaMUD 3.59
[Feb 05 2009] - Jamdog
Added "set <player> name <newname>", which renames a character, including pfile and index entry
[Feb 01 2009] - Jamdog
Changed documentation /doc unixshelladminguide to PDF format.
[Jan 31 2009] - Jamdog

View file

@ -278,6 +278,7 @@ int script_command_interpreter(struct char_data *ch, char *arg);
room_rnum find_target_room(struct char_data *ch, char *rawroomstr);
void perform_immort_vis(struct char_data *ch);
void snoop_check(struct char_data *ch);
bool change_player_name(struct char_data *ch, struct char_data *vict, char *new_name);
/* Functions with subcommands */
/* do_date */
ACMD(do_date);

View file

@ -31,6 +31,8 @@
#include "house.h"
#include "modify.h"
#include "quest.h"
#include "ban.h"
#include "screen.h"
/* local utility functions with file scope */
static int perform_set(struct char_data *ch, struct char_data *vict, int mode, char *val_arg);
@ -2709,30 +2711,31 @@ ACMD(do_show)
{ "maxmana", LVL_BUILDER, BOTH, NUMBER },
{ "maxmove", LVL_BUILDER, BOTH, NUMBER }, /* 30 */
{ "move", LVL_BUILDER, BOTH, NUMBER },
{ "name", LVL_IMMORT, PC, MISC },
{ "nodelete", LVL_GOD, PC, BINARY },
{ "nohassle", LVL_GOD, PC, BINARY },
{ "nosummon", LVL_BUILDER, PC, BINARY },
{ "nowizlist", LVL_GRGOD, PC, BINARY }, /* 35 */
{ "nosummon", LVL_BUILDER, PC, BINARY }, /* 35 */
{ "nowizlist", LVL_GRGOD, PC, BINARY },
{ "olc", LVL_GRGOD, PC, MISC },
{ "password", LVL_IMPL, PC, MISC },
{ "poofin", LVL_IMMORT, PC, MISC },
{ "poofout", LVL_IMMORT, PC, MISC },
{ "practices", LVL_GOD, PC, NUMBER }, /* 40 */
{ "poofout", LVL_IMMORT, PC, MISC }, /* 40 */
{ "practices", LVL_GOD, PC, NUMBER },
{ "quest", LVL_GOD, PC, BINARY },
{ "room", LVL_BUILDER, BOTH, NUMBER },
{ "screenwidth", LVL_GOD, PC, NUMBER },
{ "sex", LVL_GOD, BOTH, MISC },
{ "showvnums", LVL_BUILDER, PC, BINARY }, /* 45 */
{ "sex", LVL_GOD, BOTH, MISC }, /* 45 */
{ "showvnums", LVL_BUILDER, PC, BINARY },
{ "siteok", LVL_GOD, PC, BINARY },
{ "str", LVL_BUILDER, BOTH, NUMBER },
{ "stradd", LVL_BUILDER, BOTH, NUMBER },
{ "thief", LVL_GOD, PC, BINARY },
{ "thirst", LVL_BUILDER, BOTH, MISC }, /* 50 */
{ "thief", LVL_GOD, PC, BINARY }, /* 50 */
{ "thirst", LVL_BUILDER, BOTH, MISC },
{ "title", LVL_GOD, PC, MISC },
{ "variable", LVL_GRGOD, PC, MISC },
{ "weight", LVL_BUILDER, BOTH, NUMBER },
{ "wis", LVL_BUILDER, BOTH, NUMBER },
{ "questpoints", LVL_GOD, PC, NUMBER }, /* 55 */
{ "wis", LVL_BUILDER, BOTH, NUMBER }, /* 55 */
{ "questpoints", LVL_GOD, PC, NUMBER },
{ "questhistory", LVL_GOD, PC, NUMBER },
{ "\n", 0, BOTH, MISC }
};
@ -2967,24 +2970,34 @@ static int perform_set(struct char_data *ch, struct char_data *vict, int mode, c
vict->points.move = RANGE(0, vict->points.max_move);
affect_total(vict);
break;
case 32: /* nodelete */
case 32: /* name */
if (ch != vict && GET_LEVEL(ch) < LVL_IMPL) {
send_to_char(ch, "Only Imps can change the name of other players.\r\n");
return (0);
}
if (!change_player_name(ch, vict, val_arg)) {
send_to_char(ch, "Name has not been changed!\r\n");
return (0);
}
break;
case 33: /* nodelete */
SET_OR_REMOVE(PLR_FLAGS(vict), PLR_NODELETE);
break;
case 33: /* nohassle */
case 34: /* nohassle */
if (GET_LEVEL(ch) < LVL_GOD && ch != vict) {
send_to_char(ch, "You aren't godly enough for that!\r\n");
return (0);
}
SET_OR_REMOVE(PRF_FLAGS(vict), PRF_NOHASSLE);
break;
case 34: /* nosummon */
case 35: /* nosummon */
SET_OR_REMOVE(PRF_FLAGS(vict), PRF_SUMMONABLE);
send_to_char(ch, "Nosummon %s for %s.\r\n", ONOFF(!on), GET_NAME(vict));
break;
case 35: /* nowiz */
case 36: /* nowiz */
SET_OR_REMOVE(PLR_FLAGS(vict), PLR_NOWIZLIST);
break;
case 36: /* olc */
case 37: /* olc */
if (is_abbrev(val_arg, "socials") || is_abbrev(val_arg, "actions") || is_abbrev(val_arg, "aedit"))
GET_OLC_ZONE(vict) = AEDIT_PERMISSION;
else if (is_abbrev(val_arg, "hedit") || is_abbrev(val_arg, "help"))
@ -2999,7 +3012,7 @@ static int perform_set(struct char_data *ch, struct char_data *vict, int mode, c
} else
GET_OLC_ZONE(vict) = atoi(val_arg);
break;
case 37: /* password */
case 38: /* password */
if (GET_LEVEL(vict) >= LVL_GRGOD) {
send_to_char(ch, "You cannot change that.\r\n");
return (0);
@ -3008,7 +3021,7 @@ static int perform_set(struct char_data *ch, struct char_data *vict, int mode, c
*(GET_PASSWD(vict) + MAX_PWD_LENGTH) = '\0';
send_to_char(ch, "Password changed to '%s'.\r\n", val_arg);
break;
case 38: /* poofin */
case 39: /* poofin */
if ((vict == ch) || (GET_LEVEL(ch) == LVL_IMPL)) {
skip_spaces(&val_arg);
@ -3021,7 +3034,7 @@ static int perform_set(struct char_data *ch, struct char_data *vict, int mode, c
POOFIN(vict) = strdup(val_arg);
}
break;
case 39: /* poofout */
case 40: /* poofout */
if ((vict == ch) || (GET_LEVEL(ch) == LVL_IMPL)) {
skip_spaces(&val_arg);
@ -3034,13 +3047,13 @@ static int perform_set(struct char_data *ch, struct char_data *vict, int mode, c
POOFOUT(vict) = strdup(val_arg);
}
break;
case 40: /* practices */
case 41: /* practices */
GET_PRACTICES(vict) = RANGE(0, 100);
break;
case 41: /* quest */
case 42: /* quest */
SET_OR_REMOVE(PRF_FLAGS(vict), PRF_QUEST);
break;
case 42: /* room */
case 43: /* room */
if ((rnum = real_room(value)) == NOWHERE) {
send_to_char(ch, "No room exists with that number.\r\n");
return (0);
@ -3049,23 +3062,23 @@ static int perform_set(struct char_data *ch, struct char_data *vict, int mode, c
char_from_room(vict);
char_to_room(vict, rnum);
break;
case 43: /* screenwidth */
case 44: /* screenwidth */
GET_SCREEN_WIDTH(vict) = RANGE(40, 200);
break;
case 44: /* sex */
case 45: /* sex */
if ((i = search_block(val_arg, genders, FALSE)) < 0) {
send_to_char(ch, "Must be 'male', 'female', or 'neutral'.\r\n");
return (0);
}
GET_SEX(vict) = i;
break;
case 45: /* showvnums */
case 46: /* showvnums */
SET_OR_REMOVE(PRF_FLAGS(vict), PRF_SHOWVNUMS);
break;
case 46: /* siteok */
case 47: /* siteok */
SET_OR_REMOVE(PLR_FLAGS(vict), PLR_SITEOK);
break;
case 47: /* str */
case 48: /* str */
if (IS_NPC(vict) || GET_LEVEL(vict) >= LVL_GRGOD)
RANGE(3, 25);
else
@ -3074,16 +3087,16 @@ static int perform_set(struct char_data *ch, struct char_data *vict, int mode, c
vict->real_abils.str_add = 0;
affect_total(vict);
break;
case 48: /* stradd */
case 49: /* stradd */
vict->real_abils.str_add = RANGE(0, 100);
if (value > 0)
vict->real_abils.str = 18;
affect_total(vict);
break;
case 49: /* thief */
case 50: /* thief */
SET_OR_REMOVE(PLR_FLAGS(vict), PLR_THIEF);
break;
case 50: /* thirst */
case 51: /* thirst */
if (!str_cmp(val_arg, "off")) {
GET_COND(vict, THIRST) = -1;
send_to_char(ch, "%s's thirst is now off.\r\n", GET_NAME(vict));
@ -3097,18 +3110,18 @@ static int perform_set(struct char_data *ch, struct char_data *vict, int mode, c
return (0);
}
break;
case 51: /* title */
case 52: /* title */
set_title(vict, val_arg);
send_to_char(ch, "%s's title is now: %s\r\n", GET_NAME(vict), GET_TITLE(vict));
break;
case 52: /* variable */
case 53: /* variable */
return perform_set_dg_var(ch, vict, val_arg);
break;
case 53: /* weight */
case 54: /* weight */
GET_WEIGHT(vict) = value;
affect_total(vict);
break;
case 54: /* wis */
case 55: /* wis */
if (IS_NPC(vict) || GET_LEVEL(vict) >= LVL_GRGOD)
RANGE(3, 25);
else
@ -3116,10 +3129,10 @@ static int perform_set(struct char_data *ch, struct char_data *vict, int mode, c
vict->real_abils.wis = value;
affect_total(vict);
break;
case 55: /* questpoints */
case 56: /* questpoints */
GET_QUESTPOINTS(vict) = RANGE(0, 100000000);
break;
case 56: /* questhistory */
case 57: /* questhistory */
qvnum = atoi(val_arg);
if (real_quest(qvnum) == NOTHING) {
send_to_char(ch, "That quest doesn't exist.\r\n");
@ -4425,3 +4438,95 @@ ACMD(do_wizupdate)
run_autowiz();
send_to_char(ch, "Wizlists updated.\n\r");
}
/* NOTE: This is called from perform_set */
bool change_player_name(struct char_data *ch, struct char_data *vict, char *new_name)
{
struct char_data *temp_ch=NULL;
int plr_i = 0, i, j, k;
char old_name[MAX_NAME_LENGTH], old_pfile[50], new_pfile[50], buf[MAX_STRING_LENGTH];
if (!ch)
{
log("SYSERR: No char passed to change_player_name.");
return FALSE;
}
if (!vict)
{
log("SYSERR: No victim passed to change_player_name.");
send_to_char(ch, "Invalid victim.\r\n");
return FALSE;
}
if (!new_name || !(*new_name) || strlen(new_name) < 2 ||
strlen(new_name) > MAX_NAME_LENGTH || !valid_name(new_name) ||
fill_word(new_name) || reserved_word(new_name) ) {
send_to_char(ch, "Invalid new name.\r\n");
return FALSE;
}
// Check that someone with new_name isn't already logged in
if ((temp_ch = get_player_vis(ch, new_name, NULL, FIND_CHAR_WORLD)) != NULL) {
send_to_char(ch, "Sorry, the new name already exists.\r\n");
return FALSE;
} else {
/* try to load the player off disk */
CREATE(temp_ch, struct char_data, 1);
clear_char(temp_ch);
CREATE(temp_ch->player_specials, struct player_special_data, 1);
if ((plr_i = load_char(new_name, temp_ch)) > -1) {
free_char(temp_ch);
send_to_char(ch, "Sorry, the new name already exists.\r\n");
return FALSE;
}
}
/* New playername is OK - find the entry in the index */
for (i = 0; i <= top_of_p_table; i++)
if (player_table[i].id == GET_IDNUM(vict))
break;
if (player_table[i].id != GET_IDNUM(vict))
{
send_to_char(ch, "Your target was not found in the player index.\r\n");
log("SYSERR: Player %s, with ID %ld, could not be found in the player index.", GET_NAME(vict), GET_IDNUM(vict));
return FALSE;
}
/* Set up a few variables that will be needed */
sprintf(old_name, "%s", GET_NAME(vict));
if (!get_filename(old_pfile, sizeof(old_pfile), PLR_FILE, old_name))
{
send_to_char(ch, "Unable to ascertain player's old pfile name.\r\n");
return FALSE;
}
if (!get_filename(new_pfile, sizeof(new_pfile), PLR_FILE, new_name))
{
send_to_char(ch, "Unable to ascertain player's new pfile name.\r\n");
return FALSE;
}
/* Now start changing the name over - all checks and setup have passed */
free(player_table[i].name); // Free the old name in the index
player_table[i].name = strdup(new_name); // Insert the new name into the index
for (k=0; (*(player_table[i].name+k) = LOWER(*(player_table[i].name+k))); k++);
free(GET_PC_NAME(vict));
GET_PC_NAME(vict) = strdup(CAP(new_name)); // Change the name in the victims char struct
/* Rename the player's pfile */
sprintf(buf, "mv %s %s", old_pfile, new_pfile);
j = system(buf);
/* Save the changed player index - the pfile is saved by perform_set, even though it is theorhetically un-necessary in this case */
save_player_index();
mudlog(BRF, LVL_IMMORT, TRUE, "(GC) %s changed the name of %s to %s", GET_NAME(ch), old_name, new_name);
if (vict->desc) /* Descriptor is set if the victim is logged in */
send_to_char(vict, "Your login name has changed from %s%s%s to %s%s%s.\r\n", CCYEL(vict, C_NRM), old_name, CCNRM(vict, C_NRM),
CCYEL(vict, C_NRM), new_name, CCNRM(vict, C_NRM));
return TRUE;
}

View file

@ -41,7 +41,6 @@
static int perform_dupe_check(struct descriptor_data *d);
static struct alias_data *find_alias(struct alias_data *alias_list, char *str);
static void perform_complex_alias(struct txt_q *input_q, char *orig, struct alias_data *a);
static int reserved_word(char *argument);
static int _parse_name(char *arg, char *name);
/* sort_commands utility */
static int sort_commands_helper(const void *a, const void *b);
@ -819,7 +818,7 @@ int fill_word(char *argument)
return (search_block(argument, fill, TRUE) >= 0);
}
static int reserved_word(char *argument)
int reserved_word(char *argument)
{
return (search_block(argument, reserved, TRUE) >= 0);
}

View file

@ -28,6 +28,7 @@ char *one_word(char *argument, char *first_arg);
char *any_one_arg(char *argument, char *first_arg);
char *two_arguments(char *argument, char *first_arg, char *second_arg);
int fill_word(char *argument);
int reserved_word(char *argument);
void half_chop(char *string, char *arg1, char *arg2);
void nanny(struct descriptor_data *d, char *arg);
int is_abbrev(const char *arg1, const char *arg2);