Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def sendGameMessage(ptype, message, user):
- global CommandNumber
- global UnconfirmedCommands
- try:
- tree = ET.parse(BANKFILE) #reload to account for new changes
- root = tree.getroot()
- #reset unconfirmed commands if it's a new game
- for child in root:
- if child.attrib['name'] == "NewGame":
- UnconfirmedCommands = dict()
- root.remove(child)
- break
- #update unconfirmed commands with those that were executed
- for child in root:
- if child.attrib['name'] == "ExecutedCommands":
- for command in child:
- com_number = command.attrib['name']
- if com_number in UnconfirmedCommands:
- lock.acquire()
- del UnconfirmedCommands[com_number]
- lock.release()
- root.remove(child) #removes the section
- break
- #delete old commands if there are any
- for child in root:
- if child.attrib['name'] == 'Commands':
- root.remove(child)
- break
- #get unconfirmed commands
- new_command_string = ""
- for command in UnconfirmedCommands:
- new_command_string = new_command_string + UnconfirmedCommands[command]
- #get new commmand
- lock.acquire()
- CommandNumber += 1
- lock.release()
- msg = message.replace('"',"''")
- msg = html.escape(msg) # convert & → &
- command_string = f'<Key name="{ptype} {str(CommandNumber)} #{user}"><Value string="{msg}"/></Key>'
- new_command_string = new_command_string + command_string
- lock.acquire()
- UnconfirmedCommands[str(CommandNumber)] = command_string
- lock.release()
- #create command section
- new_command_string = f'<Section name="Commands">{new_command_string}</Section>'
- root.append((ET.fromstring(new_command_string)))
- tree.write(BANKFILE)
- #log
- tree = ET.parse(BANKFILE)
- root = tree.getroot()
- for child in root:
- if child.attrib['name'] == 'Commands':
- with open('XLM_debugging.txt', 'ab') as file:
- file.write((f"{UnconfirmedCommands}\n{ET.tostring(child, encoding='unicode')}\n-------\n").replace('<Section name="Commands">','').replace('</Section>','').encode('utf-8'))
- break
- except Exception as e:
- print(e,'ERROR – bank not loaded properly, message not sent')
- with open('XLM_debugging.txt', 'a') as file:
- file.write(f'\nERROR, bank not loaded properly\n',traceback.format_exc(),'\n')
Advertisement
Add Comment
Please, Sign In to add comment