From b50a2fe4fc4789277f4d78fbb95b227039f50fc4 Mon Sep 17 00:00:00 2001 From: haranp Date: Sun, 24 Sep 2006 20:53:55 +0000 Subject: More cleanups of file handling. Removed the useless "anticheat check." git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/branches/stone_soup@108 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/AppHdr.h | 4 --- crawl-ref/source/misc.cc | 31 +++-------------------- crawl-ref/source/newgame.cc | 61 ++++++++------------------------------------- crawl-ref/source/ouch.cc | 47 ++++++++++------------------------ 4 files changed, 26 insertions(+), 117 deletions(-) (limited to 'crawl-ref') diff --git a/crawl-ref/source/AppHdr.h b/crawl-ref/source/AppHdr.h index 3866b27afd..28c8413730 100644 --- a/crawl-ref/source/AppHdr.h +++ b/crawl-ref/source/AppHdr.h @@ -334,10 +334,6 @@ #endif #define PACKAGE_SUFFIX ".zip" - // This provides some rudimentary protection against people using - // save file cheats on multi-user systems. - #define DO_ANTICHEAT_CHECKS - // This defines the chmod permissions for score and bones files. #define SHARED_FILES_CHMOD_PRIVATE 0664 #define SHARED_FILES_CHMOD_PUBLIC 0664 diff --git a/crawl-ref/source/misc.cc b/crawl-ref/source/misc.cc index 4c18229f15..4c132dcf54 100644 --- a/crawl-ref/source/misc.cc +++ b/crawl-ref/source/misc.cc @@ -890,36 +890,11 @@ void down_stairs( bool remove_stairs, int old_level, bool force ) if (you.level_type == LEVEL_LABYRINTH || you.level_type == LEVEL_ABYSS || you.level_type == LEVEL_PANDEMONIUM) { - char glorpstr[kFileNameSize]; - char del_file[kFileNameSize]; + std::string del_file = get_savedir_filename(you.your_name, "", "lab"); int sysg; - - snprintf( glorpstr, sizeof(glorpstr), -#ifdef SAVE_DIR_PATH - SAVE_DIR_PATH -#endif -#ifdef MULTIUSER - "%s%d" -#else - "%s" -#endif - , you.your_name -#ifdef MULTIUSER - , (int) getuid() -#endif - ); - - strcpy(del_file, glorpstr); - strcat(del_file, ".lab"); - -#ifdef DOS - strupr(del_file); -#endif - sysg = unlink(del_file); - + sysg = unlink(del_file.c_str()); #if DEBUG_DIAGNOSTICS - strcpy( info, "Deleting: " ); - strcat( info, del_file ); + snprintf( info, INFO_SIZE, "Deleting: %s", del_file.c_str() ); mpr( info, MSGCH_DIAGNOSTICS ); more(); #endif diff --git a/crawl-ref/source/newgame.cc b/crawl-ref/source/newgame.cc index c68c9893e3..dce5049a28 100644 --- a/crawl-ref/source/newgame.cc +++ b/crawl-ref/source/newgame.cc @@ -284,76 +284,35 @@ static void pick_random_species_and_class( void ) static bool check_saved_game(void) { FILE *handle; - char char_fil[kFileNameSize]; -#ifdef LOAD_UNPACKAGE_CMD - // Create the file name base - char name_buff[kFileNameLen]; - - snprintf( name_buff, sizeof(name_buff), -#ifdef SAVE_DIR_PATH - SAVE_DIR_PATH -#endif -#ifdef MULTIUSER - "%s%d", -#else - "%s", -#endif - you.your_name -#ifdef MULTIUSER - , (int) getuid() -#endif - ); - - char zip_buff[kFileNameLen]; - - strcpy(zip_buff, name_buff); - strcat(zip_buff, PACKAGE_SUFFIX); - - // Create save dir name - strcpy(char_fil, name_buff); - strcat(char_fil, ".sav"); + std::string basename = get_savedir_filename( you.your_name, "", ""); + std::string savename = basename + ".sav"; - handle = fopen(zip_buff, "rb+"); +#ifdef LOAD_UNPACKAGE_CMD + std::string zipname = basename + PACKAGE_SUFFIX; + handle = fopen(zipname.c_str(), "rb+"); if (handle != NULL) { + fclose(handle); cprintf(EOL "Loading game..." EOL); // Create command char cmd_buff[1024]; - snprintf( cmd_buff, sizeof(cmd_buff), LOAD_UNPACKAGE_CMD, name_buff ); + snprintf( cmd_buff, sizeof(cmd_buff), LOAD_UNPACKAGE_CMD, + basename.c_str() ); if (system( cmd_buff ) != 0) { cprintf( EOL "Warning: Zip command (LOAD_UNPACKAGE_CMD) returned non-zero value!" EOL ); } - fclose(handle); - // Remove save game package - unlink(zip_buff); + unlink(zipname.c_str()); } - else - { -#ifdef DO_ANTICHEAT_CHECKS - // Simple security patch -- must have zip file otherwise invalidate - // the character. Right now this just renames the .sav file to - // .bak, allowing anyone with the appropriate permissions to - // fix a character in the case of a bug. This could be changed - // to unlinking the file(s) which would remove the character. - strcat(name_buff, ".bak"); - rename(char_fil, name_buff); -#endif - } - -#else - strcpy(char_fil, ""); - strncat(char_fil, you.your_name, kFileNameLen); - strcat(char_fil, ".sav"); #endif - handle = fopen(char_fil, "rb+"); + handle = fopen(savename.c_str(), "rb+"); if (handle != NULL) { diff --git a/crawl-ref/source/ouch.cc b/crawl-ref/source/ouch.cc index 4375ad025e..7161aee1da 100644 --- a/crawl-ref/source/ouch.cc +++ b/crawl-ref/source/ouch.cc @@ -935,7 +935,6 @@ void ouch( int dam, int death_source, char death_type, const char *aux ) void end_game( struct scorefile_entry &se ) { int i; - char del_file[300]; // massive overkill! bool dead = true; if (se.death_type == KILLED_BY_LEAVING || @@ -963,44 +962,24 @@ void end_game( struct scorefile_entry &se ) unlink(info); // create base file name - snprintf( info, INFO_SIZE, -#ifdef SAVE_DIR_PATH - SAVE_DIR_PATH -#endif -#ifdef MULTIUSER - "%s%d", -#else - "%s", -#endif - you.your_name -#ifdef MULTIUSER - , (int) getuid() -#endif - ); + std::string basename = get_savedir_filename( you.your_name, "", "" ); - // this is to catch the game package if it still exists. + const char* suffixes[] = { +#ifdef CLUA_BINDINGS + ".lua", +#endif #ifdef PACKAGE_SUFFIX - strcpy(del_file, info); - strcat(del_file, "." PACKAGE_SUFFIX); - unlink(del_file); + PACKAGE_SUFFIX , #endif + ".st", ".kil", ".tc", ".nts", ".sav" + }; - // last, but not least, delete player .sav file - strcpy(del_file, info); - - std::string basefile = del_file; - - strcat(del_file, ".sav"); - unlink(del_file); + const int num_suffixes = sizeof(suffixes) / sizeof(const char*); - // Delete record of stashes, kills, travel cache and lua save. - unlink( (basefile + ".st").c_str() ); - unlink( (basefile + ".kil").c_str() ); - unlink( (basefile + ".tc").c_str() ); - unlink( (basefile + ".nts").c_str() ); -#ifdef CLUA_BINDINGS - unlink( (basefile + ".lua").c_str() ); -#endif + for ( int i = 0; i < num_suffixes; ++i ) { + std::string tmpname = basename + suffixes[i]; + unlink( tmpname.c_str() ); + } // death message if (dead) -- cgit v1.2.3-54-g00ecf