diff --git a/app/characters.py b/app/characters.py index 2223119..5d486dd 100644 --- a/app/characters.py +++ b/app/characters.py @@ -5,8 +5,12 @@ from datatables import ColumnDT, DataTables import datetime, time from app.models import CharacterInfo, CharacterXML, Account, db from app.schemas import CharacterInfoSchema +from app.forms import RescueForm from app import gm_level, log_audit +from app.luclient import translate_from_locale import xmltodict +import xml.etree.ElementTree as ET + character_blueprint = Blueprint('characters', __name__) @@ -92,7 +96,6 @@ def view(id): @character_blueprint.route('/view_xml/', methods=['GET']) @login_required -@gm_level(9) def view_xml(id): character_data = CharacterInfo.query.filter(CharacterInfo.id == id).first() @@ -101,6 +104,11 @@ def view_xml(id): abort(404) return + if current_user.gm_level < 3: + if character_data.account_id and character_data.account_id != current_user.id: + abort(403) + return + character_xml = CharacterXML.query.filter( CharacterXML.id==id ).first().xml_data @@ -111,7 +119,6 @@ def view_xml(id): @character_blueprint.route('/get_xml/', methods=['GET']) @login_required -@gm_level(9) def get_xml(id): character_data = CharacterInfo.query.filter(CharacterInfo.id == id).first() @@ -119,6 +126,10 @@ def get_xml(id): if character_data == {}: abort(404) return + if current_user.gm_level < 3: + if character_data.account_id and character_data.account_id != current_user.id: + abort(403) + return character_xml = CharacterXML.query.filter( CharacterXML.id==id @@ -158,6 +169,42 @@ def restrict(id, bit): return redirect(request.referrer if request.referrer else url_for("main.index")) +@character_blueprint.route('/rescue/', methods=['GET', 'POST']) +@login_required +@gm_level(3) +def rescue(id): + + form = RescueForm() + + character_data = CharacterXML.query.filter( + CharacterXML.id==id + ).first() + + character_xml = ET.XML(character_data.xml_data) + for zone in character_xml.findall('.//r'): + if int(zone.attrib["w"]) % 100 == 0: + form.save_world.choices.append( + ( + zone.attrib["w"], + translate_from_locale(f"ZoneTable_{zone.attrib['w']}_DisplayDescription") + ) + ) + + if form.validate_on_submit(): + new_zone = character_xml.find(f'.//r[@w="{form.save_world.data}"]') + char = character_xml.find(".//char") + char.attrib["lzx"] = new_zone.attrib["x"] + char.attrib["lzy"] = new_zone.attrib["y"] + char.attrib["lzz"] = new_zone.attrib["z"] + char.attrib["lwid"] = form.save_world.data + + character_data.xml_data = ET.tostring(character_xml) + character_data.save() + + return redirect(url_for('characters.view', id=id)) + + return render_template("character/rescue.html.j2", form=form) + @character_blueprint.route('/get/', methods=['GET']) @login_required @gm_level(3) diff --git a/app/forms.py b/app/forms.py index 7f4b5a3..9246272 100644 --- a/app/forms.py +++ b/app/forms.py @@ -171,3 +171,17 @@ class SendMailForm(FlaskForm): ) submit = SubmitField('Submit') + + +class RescueForm(FlaskForm): + + save_world = SelectField( + 'Move to:', + coerce=str, + choices=[ + ("",""), + ], + validators=[validators.DataRequired()] + ) + + submit = SubmitField('Submit') diff --git a/app/mail.py b/app/mail.py index 33e073c..9c5c390 100644 --- a/app/mail.py +++ b/app/mail.py @@ -25,7 +25,6 @@ def send(): form = SendMailForm() if request.method == "POST": - # if form.validate_on_submit(): if form.attachment.data != "0" and form.attachment_count.data == 0: form.attachment_count.data = 1 if form.recipient.data == "0": diff --git a/app/templates/character/index.html.j2 b/app/templates/character/index.html.j2 index b1b73d1..b163833 100644 --- a/app/templates/character/index.html.j2 +++ b/app/templates/character/index.html.j2 @@ -1,11 +1,11 @@ {% extends 'base.html.j2' %} {% block title %} - Account Management + Character Management {% endblock title %} {% block content_before %} - Account Management + Character Management {% endblock content_before %} {% block content %} diff --git a/app/templates/character/rescue.html.j2 b/app/templates/character/rescue.html.j2 new file mode 100644 index 0000000..61a5259 --- /dev/null +++ b/app/templates/character/rescue.html.j2 @@ -0,0 +1,21 @@ +{% extends 'base.html.j2' %} + +{% block title %} + Character Rescue +{% endblock title %} + +{% block content_before %} + Character Rescue +{% endblock content_before %} + +{% block content %} +
+ {{ form.csrf_token }} +
+
+ {{ helper.render_field(form.save_world) }} + {{ helper.render_submit_field(form.submit) }} +
+
+
+{% endblock %} diff --git a/app/templates/partials/_character.html.j2 b/app/templates/partials/_character.html.j2 index 1b247a7..46724bb 100644 --- a/app/templates/partials/_character.html.j2 +++ b/app/templates/partials/_character.html.j2 @@ -52,6 +52,24 @@ {% else %}
+ +
+ +