Merge pull request #929 from Ebag333/Character_Import_Sanitization

Add some sanity checks and validation of imported character data
This commit is contained in:
Ryan Holmes
2017-01-02 00:38:48 -05:00
committed by GitHub

View File

@@ -34,6 +34,8 @@ import service
import config import config
import logging import logging
from eos.saveddata.character import Character as es_Character
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
class CharacterImportThread(threading.Thread): class CharacterImportThread(threading.Thread):
@@ -45,6 +47,12 @@ class CharacterImportThread(threading.Thread):
def run(self): def run(self):
paths = self.paths paths = self.paths
sCharacter = Character.getInstance() sCharacter = Character.getInstance()
all5_character = es_Character("All 5", 5)
all_skill_ids = []
for skill in all5_character.skills:
# Parse out the skill item IDs to make searching it easier later on
all_skill_ids.append(skill.itemID)
for path in paths: for path in paths:
try: try:
# we try to parse api XML data first # we try to parse api XML data first
@@ -59,19 +67,28 @@ class CharacterImportThread(threading.Thread):
charFile = open(path, mode='r').read() charFile = open(path, mode='r').read()
doc = minidom.parseString(charFile) doc = minidom.parseString(charFile)
if doc.documentElement.tagName not in ("SerializableCCPCharacter", "SerializableUriCharacter"): if doc.documentElement.tagName not in ("SerializableCCPCharacter", "SerializableUriCharacter"):
logger.error("Incorrect EVEMon XML sheet")
raise RuntimeError("Incorrect EVEMon XML sheet") raise RuntimeError("Incorrect EVEMon XML sheet")
name = doc.getElementsByTagName("name")[0].firstChild.nodeValue name = doc.getElementsByTagName("name")[0].firstChild.nodeValue
skill_els = doc.getElementsByTagName("skill") skill_els = doc.getElementsByTagName("skill")
skills = [] skills = []
for skill in skill_els: for skill in skill_els:
skills.append({ if int(skill.getAttribute("typeID")) in all_skill_ids and (0 <= int(skill.getAttribute("level")) <= 5):
"typeID": int(skill.getAttribute("typeID")), skills.append({
"level": int(skill.getAttribute("level")), "typeID": int(skill.getAttribute("typeID")),
}) "level": int(skill.getAttribute("level")),
})
else:
logger.error("Attempted to import unknown skill %s (ID: %s) (Level: %s)",
skill.getAttribute("name"),
skill.getAttribute("typeID"),
skill.getAttribute("level"),
)
char = sCharacter.new(name+" (EVEMon)") char = sCharacter.new(name+" (EVEMon)")
sCharacter.apiUpdateCharSheet(char.ID, skills) sCharacter.apiUpdateCharSheet(char.ID, skills)
except Exception, e: except Exception, e:
print e.message logger.error("Exception on character import:")
logger.error(e)
continue continue
wx.CallAfter(self.callback) wx.CallAfter(self.callback)
@@ -255,8 +272,11 @@ class Character(object):
return char return char
def rename(self, char, newName): def rename(self, char, newName):
char.name = newName if char.name in ("All 0", "All 5"):
eos.db.commit() logger.info("Cannot rename built in characters.")
else:
char.name = newName
eos.db.commit()
def copy(self, char): def copy(self, char):
newChar = copy.deepcopy(char) newChar = copy.deepcopy(char)