From 34dd537661e92635d6766bd8ac1e7d0b17ffe5cf Mon Sep 17 00:00:00 2001 From: Alejandro Aguilera Date: Tue, 5 Jul 2011 01:54:31 +0200 Subject: [PATCH] It now checks for level.dat and players *.dat files. At the moment only tries to read it (if not redable it's corrupted) but can't fix any problem with these files. Updated README file. --- README | 4 ++++ region-fixer.py | 56 ++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 57 insertions(+), 3 deletions(-) diff --git a/README b/README index e8022b0..9a842d0 100644 --- a/README +++ b/README @@ -11,6 +11,10 @@ Tries to fix corrupted chunks in region files using old backup copies of the Minecraft world. If you don't have a copy, you can eliminate the corrupted chunks. +Also it scans the 'level.dat' file and the player '*.dat' and tries to +read them. If there are problems prints warnings. At the moment it +doesn't fix any problem in these files. + Web page: https://github.com/Fenixin/Minecraft-Region-Fixer diff --git a/region-fixer.py b/region-fixer.py index 427bd52..33c521d 100644 --- a/region-fixer.py +++ b/region-fixer.py @@ -133,6 +133,30 @@ def check_chunk(region_file, x, z): return chunk +def check_level_file(level_file): + """ At the moment only tries to read a level.dat file and print a + warning if there are problems. """ + try: + level_dat = nbt.NBTFile(filename = level_file) + print "\'level.dat\' is redable." + del level_dat + + except Exception, e: + print "[WARNING!] The level.dat may be corrupted. Exception: \'{0}\'".format(e) + +def check_player_file(player_file): + """ At the moment only tries to read a .dat player file. it returns + 0 if it's ok and 1 if has some problem """ + try: + player_dat = nbt.NBTFile(filename = player_file) + del player_dat + return 0 + + except Exception, e: + print "[WARNING!] The player file {0} may be corrupted. Exception: \'{1}\'".format(player_file, e) + return 1 + + def get_global_chunk_coords(region_filename, chunkX, chunkZ): """ Takes the region filename and the chunk local coords and returns the global chunkcoords as integerss """ @@ -321,6 +345,9 @@ def main(): # do things with the option args + level_dat_filename = join(world_path, "level.dat") + player_files = glob(join(join(world_path, "players"), "*.dat")) + backups = options.backups use_backups = False if backups: # create a list of directories containing the backup of the region files @@ -350,7 +377,11 @@ def main(): print "Error: No region files found!" sys.exit() - print "There are {0} region files found on the world directory.".format(len(normal_region_files) + len(nether_region_files)) + if len(player_files) != 0: + print "There are {0} region files and {1} player files in the world directory.".format(len(normal_region_files) + len(nether_region_files), len(player_files)) + else: + print "There are {0} region files in the world directory.".format(len(normal_region_files) + len(nether_region_files)) + region_files = normal_region_files + nether_region_files # The program starts @@ -360,7 +391,7 @@ def main(): except: print 'Error: Wrong chunklist!' sys.exit() - + delete_list = parse_chunk_list(delete_list, world_region_dir) print "{0:#^60}".format(' Deleting the chunks on the list ') @@ -373,9 +404,28 @@ def main(): print "Deleted {0} chunks".format(counter) else: + # check the level.dat file and the *.dat files in players directory + + print "\n{0:#^60}".format(' Scanning level.dat ') + + if not exists(level_dat_filename): + print "[WARNING!] \'level.dat\' doesn't exist!" + else: + check_level_file(level_dat_filename) + + print "\n{0:#^60}".format(' Scanning player files ') + + problems = 0 + for player in player_files: + problems += check_player_file(player) + + if not problems: + print "All player files are redable." + + # check for corrupted chunks - print "\n{0:#^60}".format(' Scanning for corrupted chunks ') + print "\n{0:#^60}".format(' Scanning region files ') total_chunks = 0 corrupted_chunks = []