From be4e0fc6e5526b609865057a105e1b9171858fed Mon Sep 17 00:00:00 2001 From: poikilos <7557867+poikilos@users.noreply.github.com> Date: Fri, 15 Apr 2016 13:08:57 -0400 Subject: [PATCH] added minetestoffline player name reset to filename --- expertmm.py | 25 +++++++ minetestoffline.py | 47 +++++++++++++ set_player_names_to_file_names.py | 5 ++ ...e_names DEPRECATED line by line version.py | 67 +++++++++++++++++++ 4 files changed, 144 insertions(+) create mode 100644 set_player_names_to_file_names.py create mode 100644 unused/set_player_names_to_file_names DEPRECATED line by line version.py diff --git a/expertmm.py b/expertmm.py index 8b75b48..2dd2418 100644 --- a/expertmm.py +++ b/expertmm.py @@ -588,6 +588,31 @@ def has_dups(this_list): return find_dup(this_list)>-1 #region formerly pcttext.py +#gets first instance of name, gets its value, then stops reading file +def get_initial_value_from_conf(path, name, assignment_operator="="): + result = None + line_count = 0 + if path is not None: + if os.path.isfile(path): + ins = open(path, 'r') + line = True + while line: + line = ins.readline() + line_count += 1 + if line: + ao_i=line.find(assignment_operator) + if ao_i>0: # intentionall skip when 0 + this_name = line[:ao_i].strip() + if this_name==name: + result = line[ao_i+1:].strip() #NOTE: blank is allowed + break + ins.close() + else: + print("ERROR in get_initial_value_from_conf: '"+str(path)+"' is not a file.") + else: + print("ERROR in get_initial_value_from_conf: path is None.") + return result + def find_unquoted_not_commented(haystack, needle, start=0, endbefore=-1, step=1, comment_delimiter="#"): result = -1 diff --git a/minetestoffline.py b/minetestoffline.py index fc086d6..5719d22 100644 --- a/minetestoffline.py +++ b/minetestoffline.py @@ -9,6 +9,8 @@ from datetime import datetime from expertmm import * from minetestinfo import * +import time + #C:\Users\jgustafson\Desktop\Backup\fcalocal\home\owner\.minetest\worlds\FCAGameAWorld\players #minetest_players_path = "C:\\Users\\jgustafson\\Desktop\\Backup\\fcalocal\\home\\owner\\.minetest\\worlds\\FCAGameAWorld\\players" players_path = os.path.join(minetestinfo.get_var("primary_world_path"), "players") @@ -662,6 +664,51 @@ def player_inventory_transfer(from_playerid, to_playerid): to_player_path = os.path.join(players_path, to_playerid) to_player_givescript_path = os.path.join(give_path, to_playerid) +def set_player_names_to_file_names(): + assignment_operator = "=" + correct_count = 0 + incorrect_count = 0 + #NOTE: uses global min_indent + line_count = 1 + print(min_indent+"set_player_names_to_file_names:") + if os.path.isdir(players_path): + folder_path = players_path + print(min_indent+" Examining players:") + for sub_name in os.listdir(folder_path): + sub_path = os.path.join(folder_path,sub_name) + if os.path.isfile(sub_path): + if (sub_name[:1]!="."): + print(min_indent+" "+sub_name) + #stated_name = get_initial_value_from_conf(sub_path, "name", "=") + stated_name = None + line_index = 0 + if sub_path is not None: + if os.path.isfile(sub_path): + player = MinetestPlayer(sub_name) + player.load_from_file(sub_path) + if "name" in player.player_args: + if player.player_args["name"] is not None: + if len(player.player_args["name"])>0: + if sub_name==player.player_args["name"]: #purposely case sensitive especially for minetest linux version + correct_count += 1 + else: + incorrect_count += 1 + print(min_indent+" Changing incorrect name "+player.player_args["name"]+" found in "+sub_name) + player.player_args["name"] = sub_name + player.save() + else: + print(min_indent+" WARNING: name is blank in "+sub_path) + else: + print(min_indent+" WARNING: name not found in "+sub_path) + + #else: + # print(min_indent+" ERROR in set_player_names_to_file_names: '"+str(sub_path)+"' is not a file.") + else: + print(min_indent+" ERROR in set_player_names_to_file_names: path is None.") + + print(min_indent+" Summary:") # of set_player_names_to_file_names:") + print(min_indent+" "+str(correct_count)+" correct name(s)") + print(min_indent+" "+str(incorrect_count)+" incorrect name(s)") #recover_player_files_by_content("C:\\1.RaiseDataRecovery", "C:\\Users\\jgustafson\\Desktop\\Backup\\fcalocal\\home\\owner\\.minetest\\worlds\\FCAGameAWorld\\players") ### RESTORE ITEMS FROM DEBUG.TXT: diff --git a/set_player_names_to_file_names.py b/set_player_names_to_file_names.py new file mode 100644 index 0000000..891dba8 --- /dev/null +++ b/set_player_names_to_file_names.py @@ -0,0 +1,5 @@ + +from minetestoffline import * + + +set_player_names_to_file_names() diff --git a/unused/set_player_names_to_file_names DEPRECATED line by line version.py b/unused/set_player_names_to_file_names DEPRECATED line by line version.py new file mode 100644 index 0000000..a6207c7 --- /dev/null +++ b/unused/set_player_names_to_file_names DEPRECATED line by line version.py @@ -0,0 +1,67 @@ +def set_player_names_to_file_names(): + assignment_operator = "=" + correct_count = 0 + incorrect_count = 0 + #NOTE: uses global min_indent + line_count = 1 + print(min_indent+"set_player_names_to_file_names:") + if os.path.isdir(players_path): + folder_path = players_path + print(min_indent+" Examining players:") + for sub_name in os.listdir(folder_path): + sub_path = os.path.join(folder_path,sub_name) + if os.path.isfile(sub_path): + if (sub_name[:1]!="."): + print(min_indent+" "+sub_name) + #stated_name = get_initial_value_from_conf(sub_path, "name", "=") + stated_name = None + line_index = 0 + path = sub_path + if path is not None: + if os.path.isfile(path): + ins = open(path, 'r') + lines = ins.readlines() + ins.close() + time.sleep(1) + os.remove(sub_path) + is_name_found = False + outs = open(sub_path, 'w') + #outs.seek(0) + print(min_indent+" Got "+str(len(lines))+" in "+sub_name) + while line_count0: # intentionally do not check for variable name when ao is at 0 + var_name = lines[line_index][:ao_i].strip() + if var_name=="name": + if not is_name_found: + is_name_found = True + stated_name = lines[line_index][ao_i+1:].strip() #NOTE: blank is allowed + if stated_name is not None: + if len(stated_name)>0: + if sub_name==stated_name: + correct_count += 1 + break + else: + incorrect_count += 1 + print(min_indent+" Incorrect name "+stated_name+" found in "+sub_name) + else: + print(min_indent+" WARNING: name is blank in "+sub_path) + else: + print(min_indent+" WARNING: name not found in "+sub_path) + else: + write_line_enable = False + print(min_indent+" WARNING: Removing second name in "+sub_path) + if (write_line_enable): + outs.write(lines[line_index]+"\n") + line_index += 1 + outs.close() + else: + print(min_indent+" ERROR in set_player_names_to_file_names: '"+str(path)+"' is not a file.") + else: + print(min_indent+" ERROR in set_player_names_to_file_names: path is None.") + + print(min_indent+" Summary:") # of set_player_names_to_file_names:") + print(min_indent+" "+str(correct_count)+" correct name(s)") + print(min_indent+" "+str(incorrect_count)+" incorrect name(s)")