Browse Source

added minetestoffline player name reset to filename

master
poikilos 9 years ago
committed by Jacob Gustafson
parent
commit
be4e0fc6e5
  1. 25
      expertmm.py
  2. 47
      minetestoffline.py
  3. 5
      set_player_names_to_file_names.py
  4. 67
      unused/set_player_names_to_file_names DEPRECATED line by line version.py

25
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

47
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:

5
set_player_names_to_file_names.py

@ -0,0 +1,5 @@
from minetestoffline import *
set_player_names_to_file_names()

67
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_count<len(lines):
print (min_indent+" index "+str(line_index)+":")
ao_i=lines[line_index].find(assignment_operator)
write_line_enable = True
if ao_i>0: # 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)")
Loading…
Cancel
Save