diff --git a/app/routes/main.py b/app/routes/main.py index 313c8a9..340e13f 100644 --- a/app/routes/main.py +++ b/app/routes/main.py @@ -451,3 +451,117 @@ def register_routes(app, services, settings): except Exception as e: logger.exception("Error in server_status route") return render_template('server.html', db_error=f"{type(e).__name__}: {e}") + + # Map - shows locations of players, vehicles, buildings + @app.route('/map') + @login_required + def map_page(): + try: + # Get players with coordinates + players = db.query(""" + SELECT + a.id, + COALESCE(NULLIF(ps.character_name, ''), 'Unknown') as name, + a.map, + a.transform + FROM dune.actors a + JOIN dune.player_state ps ON a.id = ps.player_pawn_id + WHERE a.transform IS NOT NULL + ORDER BY a.map, ps.character_name + """) or [] + + # Get vehicles with coordinates + vehicles = db.query(""" + SELECT v.id, v.name, a.map, a.transform, a.class + FROM dune.vehicles v + JOIN dune.actors a ON v.id = a.id + WHERE a.transform IS NOT NULL + ORDER BY a.map, v.name + """) or [] + + # Get buildings with coordinates + buildings = db.query(""" + SELECT b.id, a.map, a.transform, a.class + FROM dune.buildings b + JOIN dune.actors a ON b.id = a.id + WHERE a.transform IS NOT NULL + ORDER BY a.map + LIMIT 200 + """) or [] + + # Parse coordinates from transform field + def parse_transform(t): + if not t: + return None + try: + # Format: ("(x,y,z)","(x,y,z,w)") + import re + pos_match = re.search(r'\(([0-9.e+-]+),([0-9.e+-]+),([0-9.e+-]+)\)', str(t)) + if pos_match: + return { + 'x': float(pos_match.group(1)), + 'y': float(pos_match.group(2)), + 'z': float(pos_match.group(3)) + } + except Exception: + pass + return None + + # Process players + player_locations = [] + for p in players: + coords = parse_transform(p.get('transform')) + if coords: + player_locations.append({ + 'id': p['id'], + 'name': p['name'], + 'map': p['map'], + 'x': coords['x'], + 'y': coords['y'], + 'z': coords['z'] + }) + + # Process vehicles + vehicle_locations = [] + for v in vehicles: + coords = parse_transform(v.get('transform')) + if coords: + vehicle_locations.append({ + 'id': v['id'], + 'name': v.get('name', 'Unknown'), + 'map': v['map'], + 'class': v.get('class', '').split('/')[-1] if v.get('class') else '', + 'x': coords['x'], + 'y': coords['y'], + 'z': coords['z'] + }) + + # Process buildings + building_locations = [] + for b in buildings: + coords = parse_transform(b.get('transform')) + if coords: + building_locations.append({ + 'id': b['id'], + 'map': b['map'], + 'class': b.get('class', '').split('/')[-1] if b.get('class') else '', + 'x': coords['x'], + 'y': coords['y'], + 'z': coords['z'] + }) + + # Get unique maps + all_maps = set() + for loc in player_locations + vehicle_locations + building_locations: + if loc.get('map'): + all_maps.add(loc['map']) + maps = sorted(all_maps) + + return render_template('map.html', + players=player_locations, + vehicles=vehicle_locations, + buildings=building_locations, + maps=maps) + except Exception as e: + logger.exception("Error in map route") + return render_template('map.html', db_error=f"{type(e).__name__}: {e}") diff --git a/app/utils/constants.py b/app/utils/constants.py index b53498b..9d3e3ae 100644 --- a/app/utils/constants.py +++ b/app/utils/constants.py @@ -37,4 +37,5 @@ NAV_PAGES = [ ('/vehicles', 'Vehicles'), ('/guilds', 'Guilds'), ('/buildings', 'Buildings'), + ('/map', 'Map'), ] diff --git a/debug_coords.py b/debug_coords.py new file mode 100644 index 0000000..7f9c7d3 --- /dev/null +++ b/debug_coords.py @@ -0,0 +1,39 @@ +import sys +sys.path.insert(0, '.') +from app.config import load_settings +from app.services.database import DatabaseService + +settings = load_settings() +db_config = { + 'host': settings['database']['host'], + 'port': settings['database']['port'], + 'user': settings['database']['user'], + 'password': settings['database']['password'], + 'database': settings['database']['name'], +} +db = DatabaseService(db_config, 2, 10) + +# Check sample transform data for players +sample = db.query(''' + SELECT id, class, map, transform FROM dune.actors + WHERE class LIKE '%DunePlayerCharacter_%' + LIMIT 3 +''') +for s in sample: + print('Class:', s['class']) + print('Map:', s['map']) + print('Transform:', s['transform'][:500] if s['transform'] else 'None') + print('---') + +# Also check vehicles +print('\n=== Vehicles ===') +veh = db.query(''' + SELECT id, class, map, transform FROM dune.actors + WHERE class LIKE '%Vehicle%' + LIMIT 2 +''') +for v in veh: + print('Class:', v['class']) + print('Map:', v['map']) + print('Transform:', v['transform'][:500] if v['transform'] else 'None') + print('---') \ No newline at end of file diff --git a/templates/map.html b/templates/map.html new file mode 100644 index 0000000..79889df --- /dev/null +++ b/templates/map.html @@ -0,0 +1,301 @@ +{% extends "base.html" %} + +{% block title %}Map - Dune Dashboard{% endblock %} + +{% block content %} + + +

World Map

+ +{% if db_error %} +
{{ db_error }}
+{% endif %} + +
+
+
{{ players|length }}
+
Players
+
+
+
{{ vehicles|length }}
+
Vehicles
+
+
+
{{ buildings|length }}
+
Buildings
+
+
+ +
+
+

Filter by Type

+ + + + +

Filter by Map

+ + +

Players

+
+ {% for p in players %} +
+ {{ p.name }} + {{ p.map }} +
+ {% endfor %} + {% if not players %} +
No player locations
+ {% endif %} +
+ +

Vehicles

+
+ {% for v in vehicles %} +
+ {{ v.name|truncate(15) }} + {{ v.map }} +
+ {% endfor %} + {% if not vehicles %} +
No vehicle locations
+ {% endif %} +
+ +

Buildings

+
+ {% for b in buildings[:50] %} +
+ {{ b.class|truncate(20) }} + {{ b.map }} +
+ {% endfor %} + {% if not buildings %} +
No building locations
+ {% endif %} + {% if buildings|length > 50 %} +
+{{ buildings|length - 50 }} more
+ {% endif %} +
+
+ +
+
+
🗺️
+

Map Image Coming Soon

+

This is a prototype showing coordinate data.
Once you source a map image, markers will be overlaid here.

+
+ Data available:
+ Players: {{ players|length }} locations
+ Vehicles: {{ vehicles|length }} locations
+ Buildings: {{ buildings|length }} locations

+ Coordinates are extracted from the game world. Once a map image is added, these will appear as clickable markers. +
+ +
+
+
+ + +{% endblock %} \ No newline at end of file