Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals

rename.c

Go to the documentation of this file.
00001 /* rename, written by Andreasen. Changes by Tribul */
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); /* find new/old name */
00028     one_argument (argument, new_name);
00029     
00030     /* Trivial checks */
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     /* allow rename self new_name,but otherwise only lower level */ 
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     /* Insert check for clan here!! */
00071     /*
00072 
00073     if (victim->clan)
00074     {
00075         send_to_char ("This player is member of a clan, remove him from there first.\n\r",ch);
00076         return;
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     /* First, check if there is a player named that off-line */ 
00087     sprintf( strsave, "%s%s", PLAYER_DIR, capitalize( new_name ) );
00088 
00089 
00090     fclose (fpReserve); /* close the reserve file */
00091     file = fopen (strsave, "r"); /* attempt to to open pfile */
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" ); /* is this really necessary these days? */
00097         return;     
00098     }
00099     fpReserve = fopen( NULL_FILE, "r" );  /* reopen the extra file */
00100 
00101     /* Check .gz file ! */
00102     sprintf( strsave, "%s%s.gz", PLAYER_DIR, capitalize( new_name ) );
00103 
00104     fclose (fpReserve); /* close the reserve file */
00105     file = fopen (strsave, "r"); /* attempt to to open pfile */
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" );  /* reopen the extra file */
00114 
00115     if (get_char_world(ch,new_name)) /* check for playing level-1 non-saved */
00116     {
00117         send_to_char ("A player with the name you specified already exists!\n\r",ch);
00118         return;
00119     }
00120 
00121     /* Save the filename of the old name */
00122 
00123     sprintf( strsave, "%s%s", PLAYER_DIR, capitalize( victim->name ) );
00124 
00125 
00126 
00127     /* Rename the character and save him to a new file */
00128     /* NOTE: Players who are level 1 do NOT get saved under a new name */
00129 
00130     free_string (victim->name);
00131     victim->name = str_dup (capitalize(new_name));
00132     
00133     save_char_obj (victim);
00134     
00135     /* unlink the old file */
00136     unlink (strsave); /* unlink does return a value.. but we do not care */
00137 
00138     /* That's it! */
00139     
00140     send_to_char ("Character renamed.\n\r",ch);
00141 
00142     victim->position = POS_STANDING; /* I am laaazy */
00143     act ("$n has renamed you to {R$N{x.",ch,NULL,victim,TO_VICT);
00144             
00145 } /* do_rename */
00146 

Generated on Thu Jan 13 21:48:14 2005 for Beyond the Shadows by  doxygen 1.4.0