From a66e4aaf8055098a894b1c96cce56f0c4167b20e Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Sat, 19 Feb 2022 22:36:33 -0600 Subject: [PATCH 1/4] first pass --- app/characters.py | 51 ++++++++++++++++++++++- app/forms.py | 14 +++++++ app/mail.py | 1 - app/templates/character/index.html.j2 | 4 +- app/templates/character/rescue.html.j2 | 21 ++++++++++ app/templates/partials/_character.html.j2 | 24 ++++++++++- entrypoint.sh | 6 +++ 7 files changed, 115 insertions(+), 6 deletions(-) create mode 100644 app/templates/character/rescue.html.j2 diff --git a/app/characters.py b/app/characters.py index 2223119..13fda86 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["lzid"] = 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 %}
+ +
+ +
{% endif %} - {% if current_user.id != character.account_id and current_user.gm_level > 2 %} + {% if current_user.gm_level > 2 %}
@@ -83,6 +101,10 @@ {% endif %} + + Rescue + {% if character.permission_map|check_perm_map(4) %}Unrestrict{% else %}Restrict{% endif %} Trade diff --git a/entrypoint.sh b/entrypoint.sh index d98c4b6..9b25f15 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -3,5 +3,11 @@ # unzip brickdb from client to the right places unzip -n -q /app/luclient/res/brickdb.zip -d app/luclient/res/ +# TODO: preconvert images options +# TODO: preconvery models options + +# update the DB flask db upgrade + +# RUNNNNNNNNNNNNN gunicorn -b :8000 -w 4 wsgi:app From 76c862a2bafb0ef5105d53270eaca5413ba55a38 Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Sat, 19 Feb 2022 22:45:37 -0600 Subject: [PATCH 2/4] debug --- app/characters.py | 1 + 1 file changed, 1 insertion(+) diff --git a/app/characters.py b/app/characters.py index 13fda86..8f8b91a 100644 --- a/app/characters.py +++ b/app/characters.py @@ -197,6 +197,7 @@ def rescue(id): char.attrib["lzy"] = new_zone.attrib["y"] char.attrib["lzz"] = new_zone.attrib["z"] char.attrib["lzid"] = form.save_world.data + print(form.save_world.data) character_data.xml_data = ET.tostring(character_xml) character_data.save() From 78ab5b93bb82189d35ec94b7076ec2152f41feea Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Sun, 20 Feb 2022 08:18:18 -0600 Subject: [PATCH 3/4] use the lwid which overrides the lzid --- app/characters.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/characters.py b/app/characters.py index 8f8b91a..5d486dd 100644 --- a/app/characters.py +++ b/app/characters.py @@ -196,8 +196,7 @@ def rescue(id): char.attrib["lzx"] = new_zone.attrib["x"] char.attrib["lzy"] = new_zone.attrib["y"] char.attrib["lzz"] = new_zone.attrib["z"] - char.attrib["lzid"] = form.save_world.data - print(form.save_world.data) + char.attrib["lwid"] = form.save_world.data character_data.xml_data = ET.tostring(character_xml) character_data.save() From 7f37343de47b4a5a9084f9cc34b45d23f629f2bc Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Sun, 20 Feb 2022 08:35:58 -0600 Subject: [PATCH 4/4] change the displaed world they are in --- app/templates/partials/_charxml.html.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/templates/partials/_charxml.html.j2 b/app/templates/partials/_charxml.html.j2 index 7284488..f27dcce 100644 --- a/app/templates/partials/_charxml.html.j2 +++ b/app/templates/partials/_charxml.html.j2 @@ -19,7 +19,7 @@
{% set parsed_lzid = character_json.obj.char.attr_lzid|parse_lzid %} - Zone: {{ parsed_lzid[0]|get_zone_name }}
+ Zone: {{ character_json.obj.char.attr_lwid|get_zone_name }}
Zone Instance: {{ parsed_lzid[1] }}
Zone Clone: {{ parsed_lzid[2] }}