2022-03-13 02:09:35 +00:00
|
|
|
from flask import render_template, Blueprint, send_from_directory
|
2022-04-03 18:31:43 +00:00
|
|
|
from flask_user import current_user, login_required
|
2022-01-16 18:22:00 +00:00
|
|
|
|
2022-04-03 18:31:43 +00:00
|
|
|
from app.models import Account, CharacterInfo, ActivityLog
|
2022-01-16 18:22:00 +00:00
|
|
|
from app.schemas import AccountSchema, CharacterInfoSchema
|
|
|
|
|
2022-11-18 04:41:43 +00:00
|
|
|
import datetime
|
|
|
|
import time
|
|
|
|
|
2022-01-16 18:22:00 +00:00
|
|
|
main_blueprint = Blueprint('main', __name__)
|
|
|
|
|
|
|
|
account_schema = AccountSchema()
|
|
|
|
char_info_schema = CharacterInfoSchema()
|
|
|
|
|
2022-03-13 02:09:35 +00:00
|
|
|
|
2022-01-16 18:22:00 +00:00
|
|
|
@main_blueprint.route('/', methods=['GET'])
|
|
|
|
def index():
|
|
|
|
"""Home/Index Page"""
|
|
|
|
if current_user.is_authenticated:
|
|
|
|
account_data = Account.query.filter(Account.id == current_user.id).first()
|
|
|
|
|
|
|
|
return render_template(
|
|
|
|
'main/index.html.j2',
|
|
|
|
account_data=account_data
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
return render_template('main/index.html.j2')
|
|
|
|
|
|
|
|
|
|
|
|
@main_blueprint.route('/about')
|
2022-04-03 18:31:43 +00:00
|
|
|
@login_required
|
2022-01-16 18:22:00 +00:00
|
|
|
def about():
|
|
|
|
"""About Page"""
|
2022-04-03 18:42:06 +00:00
|
|
|
mods = Account.query.filter(Account.gm_level > 0).order_by(Account.gm_level.desc()).all()
|
2022-04-03 18:31:43 +00:00
|
|
|
online = 0
|
2022-11-18 04:41:43 +00:00
|
|
|
users = []
|
|
|
|
zones = {}
|
|
|
|
twodaysago = time.mktime((datetime.datetime.now() - datetime.timedelta(days=2)).timetuple())
|
|
|
|
chars = CharacterInfo.query.filter(CharacterInfo.last_login >= twodaysago).all()
|
|
|
|
|
2022-04-03 18:31:43 +00:00
|
|
|
for char in chars:
|
|
|
|
last_log = ActivityLog.query.with_entities(
|
2022-11-18 04:41:43 +00:00
|
|
|
ActivityLog.activity, ActivityLog.map_id
|
2022-04-03 18:31:43 +00:00
|
|
|
).filter(
|
|
|
|
ActivityLog.character_id == char.id
|
|
|
|
).order_by(ActivityLog.id.desc()).first()
|
2022-04-03 20:12:24 +00:00
|
|
|
|
2022-04-03 18:31:43 +00:00
|
|
|
if last_log:
|
|
|
|
if last_log[0] == 0:
|
|
|
|
online += 1
|
2022-11-18 04:41:43 +00:00
|
|
|
if current_user.gm_level >= 8: users.append([char.name, last_log[1]])
|
|
|
|
if str(last_log[1]) not in zones:
|
|
|
|
zones[str(last_log[1])] = 1
|
|
|
|
else:
|
|
|
|
zones[str(last_log[1])] += 1
|
2022-04-03 18:31:43 +00:00
|
|
|
|
2022-11-18 04:41:43 +00:00
|
|
|
return render_template('main/about.html.j2', mods=mods, online=online, users=users, zones=zones)
|
2022-01-16 18:22:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
@main_blueprint.route('/favicon.ico')
|
|
|
|
def favicon():
|
|
|
|
return send_from_directory(
|
|
|
|
'static/logo/',
|
|
|
|
'favicon.ico',
|
|
|
|
mimetype='image/vnd.microsoft.icon'
|
|
|
|
)
|