00001
00002
00003 #if defined(macintosh)
00004 #include <types.h>
00005 #else
00006 #include <sys/types.h>
00007 #endif
00008 #include <stdio.h>
00009 #include <stdlib.h>
00010 #include <string.h>
00011 #include <time.h>
00012 #include <assert.h>
00013 #include <unistd.h>
00014 #include <string.h>
00015 #include "merc.h"
00016
00017
00018 void do_rename (CHAR_DATA* ch, char* argument)
00019 {
00020 char old_name[MAX_INPUT_LENGTH],
00021 new_name[MAX_INPUT_LENGTH],
00022 strsave [MAX_INPUT_LENGTH];
00023
00024 CHAR_DATA* victim;
00025 FILE* file;
00026
00027 argument = one_argument(argument, old_name);
00028 one_argument (argument, new_name);
00029
00030
00031 if (!old_name[0])
00032 {
00033 send_to_char ("Rename who?\n\r",ch);
00034 return;
00035 }
00036
00037 victim = get_char_world (ch, old_name);
00038
00039 if (!victim)
00040 {
00041 send_to_char ("There is no such a person online.\n\r",ch);
00042 return;
00043 }
00044
00045 if (IS_NPC(victim))
00046 {
00047 send_to_char ("You cannot use Rename on NPCs.\n\r",ch);
00048 return;
00049 }
00050
00051
00052 if ( (victim != ch) && (get_trust (victim) >= get_trust (ch)) )
00053 {
00054 send_to_char ("You failed.\n\r",ch);
00055 return;
00056 }
00057
00058 if (!victim->desc || (victim->desc->connected != CON_PLAYING) )
00059 {
00060 send_to_char ("This player has lost his link or is inside a pager or the like.\n\r",ch);
00061 return;
00062 }
00063
00064 if (!new_name[0])
00065 {
00066 send_to_char ("Rename to what new name?\n\r",ch);
00067 return;
00068 }
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080 if (!check_parse_name(new_name))
00081 {
00082 send_to_char ("The new name is illegal.\n\r",ch);
00083 return;
00084 }
00085
00086
00087 sprintf( strsave, "%s%s", PLAYER_DIR, capitalize( new_name ) );
00088
00089
00090 fclose (fpReserve);
00091 file = fopen (strsave, "r");
00092 if (file)
00093 {
00094 send_to_char ("A player with that name already exists!\n\r",ch);
00095 fclose (file);
00096 fpReserve = fopen( NULL_FILE, "r" );
00097 return;
00098 }
00099 fpReserve = fopen( NULL_FILE, "r" );
00100
00101
00102 sprintf( strsave, "%s%s.gz", PLAYER_DIR, capitalize( new_name ) );
00103
00104 fclose (fpReserve);
00105 file = fopen (strsave, "r");
00106 if (file)
00107 {
00108 send_to_char ("A player with that name already exists in a compressed file!\n\r",ch);
00109 fclose (file);
00110 fpReserve = fopen( NULL_FILE, "r" );
00111 return;
00112 }
00113 fpReserve = fopen( NULL_FILE, "r" );
00114
00115 if (get_char_world(ch,new_name))
00116 {
00117 send_to_char ("A player with the name you specified already exists!\n\r",ch);
00118 return;
00119 }
00120
00121
00122
00123 sprintf( strsave, "%s%s", PLAYER_DIR, capitalize( victim->name ) );
00124
00125
00126
00127
00128
00129
00130 free_string (victim->name);
00131 victim->name = str_dup (capitalize(new_name));
00132
00133 save_char_obj (victim);
00134
00135
00136 unlink (strsave);
00137
00138
00139
00140 send_to_char ("Character renamed.\n\r",ch);
00141
00142 victim->position = POS_STANDING;
00143 act ("$n has renamed you to {R$N{x.",ch,NULL,victim,TO_VICT);
00144
00145 }
00146