diff --git a/app/config.py b/app/config.py index 5a198ef..aa2462d 100644 --- a/app/config.py +++ b/app/config.py @@ -58,6 +58,7 @@ DEFAULTS = { 'enabled': True, 'username': None, # Must be set via setup 'password_hash': None, # Argon2 hash, never plaintext + 'shell_enabled': True, }, 'logging': { 'level': 'INFO', @@ -73,6 +74,7 @@ DEFAULTS = { 'default_map': 'DeepDesert', 'DeepDesert': { 'image': 'maps/Deep_Desert_Map1.jpg', + 'label': 'The Deep Desert', 'bounds': { 'min_x': 466906, 'max_x': 466907, @@ -80,10 +82,11 @@ DEFAULTS = { 'max_y': -620340 }, 'flip_y': False, - 'image_size': {'width': 1200, 'height': 800} + 'image_size': {'width': 683, 'height': 683} }, 'HaggaBasin': { - 'image': None, + 'image': 'maps/T_WorldMap_Survival_1_D.png', + 'label': 'Hagga Basin', 'bounds': { 'min_x': 21352, 'max_x': 23166, @@ -91,7 +94,7 @@ DEFAULTS = { 'max_y': 237943 }, 'flip_y': False, - 'image_size': {'width': 800, 'height': 600} + 'image_size': {'width': 1228, 'height': 1228} } }, } diff --git a/app/factory.py b/app/factory.py index 210968f..197509a 100644 --- a/app/factory.py +++ b/app/factory.py @@ -73,7 +73,7 @@ def create_app(settings_path=None): # Content Security Policy response.headers['Content-Security-Policy'] = ( "default-src 'self'; " - "script-src 'self'; " + "script-src 'self' 'unsafe-inline'; " "style-src 'self' 'unsafe-inline'; " "img-src 'self' data:; " "connect-src 'self' ws: wss:; " diff --git a/app/routes/main.py b/app/routes/main.py index b215c55..a751141 100644 --- a/app/routes/main.py +++ b/app/routes/main.py @@ -456,7 +456,61 @@ def register_routes(app, services, settings): @app.route('/map') @login_required def map_page(): + def get_map_context(): + map_config = settings.get('maps', {}) + try: + from app.config import DEFAULTS + default_map_config = DEFAULTS.get('maps', {}) + merged_map_config = {} + for name, default_cfg in default_map_config.items(): + if not isinstance(default_cfg, dict): + continue + cfg = dict(default_cfg) + cfg.update(map_config.get(name, {}) if isinstance(map_config.get(name), dict) else {}) + for fallback_key in ('image', 'label', 'image_size'): + if not cfg.get(fallback_key) and default_cfg.get(fallback_key): + cfg[fallback_key] = default_cfg[fallback_key] + merged_map_config[name] = cfg + for name, cfg in map_config.items(): + if isinstance(cfg, dict) and name not in merged_map_config: + merged_map_config[name] = cfg + map_config = merged_map_config + except Exception: + pass + + configured_maps = { + name: cfg for name, cfg in map_config.items() + if isinstance(cfg, dict) and cfg.get('image') and cfg.get('bounds') + } + default_map = map_config.get('default_map', 'DeepDesert') + + return map_config, configured_maps, default_map + + def build_map_options(configured_maps, player_locations=None, vehicle_locations=None, building_locations=None): + player_locations = player_locations or [] + vehicle_locations = vehicle_locations or [] + building_locations = building_locations or [] + map_options = [] + for key, cfg in configured_maps.items(): + image_size = cfg.get('image_size', {}) + map_options.append({ + 'key': key, + 'label': cfg.get('label') or key, + 'image': cfg.get('image'), + 'width': image_size.get('width', 1000), + 'height': image_size.get('height', 1000), + 'counts': { + 'players': sum(1 for p in player_locations if p.get('map') == key and p.get('in_bounds')), + 'vehicles': sum(1 for v in vehicle_locations if v.get('map') == key and v.get('in_bounds')), + 'bases': sum(1 for b in building_locations if b.get('map') == key and b.get('in_bounds')), + } + }) + return map_options + try: + map_config, configured_maps, default_map = get_map_context() + selected_map_keys = list(configured_maps.keys()) or ['DeepDesert', 'HaggaBasin'] + # Get players with coordinates players = db.query(""" SELECT @@ -466,28 +520,33 @@ def register_routes(app, services, settings): a.transform FROM dune.actors a JOIN dune.player_state ps ON a.id = ps.player_pawn_id - WHERE a.transform IS NOT NULL + WHERE a.transform IS NOT NULL AND a.map = ANY(%s) ORDER BY a.map, ps.character_name - """) or [] + """, [selected_map_keys]) or [] - # Get vehicles with coordinates (only DeepDesert and HaggaBasin) + # Get vehicles with coordinates for configured map assets vehicles = db.query(""" SELECT v.id, 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 AND a.map IN ('DeepDesert', 'HaggaBasin') + WHERE a.transform IS NOT NULL AND a.map = ANY(%s) ORDER BY a.map, a.class - """) or [] + """, [selected_map_keys]) or [] - # Get buildings with coordinates (only DeepDesert and HaggaBasin) + # Get bases/buildings with coordinates for configured map assets buildings = db.query(""" - SELECT b.id, a.map, a.transform, a.class + SELECT b.id, a.map, a.transform, a.class, + COALESCE(NULLIF(ps.character_name, ''), NULLIF(ea.platform_name, ''), 'Base ' || b.id::text) as owner_name FROM dune.buildings b JOIN dune.actors a ON b.id = a.id - WHERE a.transform IS NOT NULL AND a.map IN ('DeepDesert', 'HaggaBasin') + LEFT JOIN dune.player_state ps ON b.owner_id = ps.player_pawn_id + LEFT JOIN dune.encrypted_accounts ea ON ea.id = ( + SELECT ps2.account_id FROM dune.player_state ps2 WHERE ps2.player_pawn_id = b.owner_id LIMIT 1 + ) + WHERE a.transform IS NOT NULL AND a.map = ANY(%s) ORDER BY a.map - LIMIT 200 - """) or [] + LIMIT 500 + """, [selected_map_keys]) or [] # Parse coordinates from transform field def parse_transform(t): @@ -518,7 +577,8 @@ def register_routes(app, services, settings): 'map': p['map'], 'x': coords['x'], 'y': coords['y'], - 'z': coords['z'] + 'z': coords['z'], + 'type': 'player', }) # Process vehicles @@ -533,7 +593,8 @@ def register_routes(app, services, settings): 'class': v.get('class', '').split('/')[-1] if v.get('class') else '', 'x': coords['x'], 'y': coords['y'], - 'z': coords['z'] + 'z': coords['z'], + 'type': 'vehicle', }) # Process buildings @@ -544,23 +605,14 @@ def register_routes(app, services, settings): building_locations.append({ 'id': b['id'], 'map': b['map'], + 'name': b.get('owner_name') or f"Base {b['id']}", 'class': b.get('class', '').split('/')[-1] if b.get('class') else '', 'x': coords['x'], 'y': coords['y'], - 'z': coords['z'] + 'z': coords['z'], + 'type': 'base', }) - # 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) - - # Get map configuration from settings - map_config = settings.get('maps', {}) - default_map = map_config.get('default_map', 'DeepDesert') - # Calculate pixel positions for markers def to_pixel_coords(x, y, map_name): cfg = map_config.get(map_name, {}) @@ -585,23 +637,45 @@ def register_routes(app, services, settings): return int(px), int(py) - # Add pixel positions + def is_in_bounds(loc): + img_size = map_config.get(loc.get('map'), {}).get('image_size', {}) + width = img_size.get('width', 0) + height = img_size.get('height', 0) + return ( + loc.get('px') is not None + and loc.get('py') is not None + and 0 <= loc['px'] <= width + and 0 <= loc['py'] <= height + ) + + # Add pixel positions and hide out-of-bounds markers until bounds are calibrated. for p in player_locations: p['px'], p['py'] = to_pixel_coords(p['x'], p['y'], p.get('map', '')) + p['in_bounds'] = is_in_bounds(p) for v in vehicle_locations: v['px'], v['py'] = to_pixel_coords(v['x'], v['y'], v.get('map', '')) + v['in_bounds'] = is_in_bounds(v) for b in building_locations: b['px'], b['py'] = to_pixel_coords(b['x'], b['y'], b.get('map', '')) + b['in_bounds'] = is_in_bounds(b) + + map_options = build_map_options(configured_maps, player_locations, vehicle_locations, building_locations) return render_template('map.html', players=player_locations, vehicles=vehicle_locations, buildings=building_locations, - maps=maps, + map_options=map_options, map_config=map_config, default_map=default_map) except Exception as e: logger.exception("Error in map route") - return render_template('map.html', db_error=f"{type(e).__name__}: {e}") + map_config, configured_maps, default_map = get_map_context() + return render_template('map.html', + players=[], vehicles=[], buildings=[], + map_options=build_map_options(configured_maps), + map_config=map_config, + default_map=default_map, + db_error=f"{type(e).__name__}: {e}") diff --git a/app/services/ssh.py b/app/services/ssh.py index 26bfbba..380de9d 100644 --- a/app/services/ssh.py +++ b/app/services/ssh.py @@ -11,19 +11,43 @@ class SSHService: def __init__(self, host, user, ssh_key=None): self.host = host self.user = user - self.ssh_key = ssh_key - logger.info(f"SSHService initialized: {user}@{host}") + self.ssh_key = self._resolve_ssh_key(ssh_key) + key_status = self.ssh_key if self.ssh_key else 'default ssh identity/agent' + logger.info(f"SSHService initialized: {user}@{host} using {key_status}") + + def _resolve_ssh_key(self, ssh_key): + if ssh_key: + key = str(ssh_key).strip("'\"") + if os.path.exists(key): + return key + + base_dir = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) + temp_dir = os.environ.get('TEMP') or os.environ.get('TMPDIR') or ('/tmp' if os.name != 'nt' else 'C:\\Temp') + local_appdata = os.environ.get('LOCALAPPDATA', '') + potential_paths = [ + os.path.join(temp_dir, 'dune-tunnel-key'), + os.path.join(temp_dir, 'dune-awakening-server-sshKey'), + os.path.join(base_dir, 'internal-scripts', 'ssh', 'sshKey'), + os.path.join(os.path.dirname(base_dir), 'internal-scripts', 'ssh', 'sshKey'), + ] + if local_appdata: + potential_paths.insert(2, os.path.join(local_appdata, 'DuneAwakeningServer', 'sshKey')) + + for path in potential_paths: + if os.path.exists(path): + return path + return None def run(self, command, timeout=30): args = [ 'ssh', - '-i', self.ssh_key, '-o', 'StrictHostKeyChecking=accept-new', '-o', 'ConnectTimeout=10', '-o', 'BatchMode=yes', - f'{self.user}@{self.host}', - command ] + if self.ssh_key: + args.extend(['-i', self.ssh_key]) + args.extend([f'{self.user}@{self.host}', command]) logger.debug(f"SSH command: {command[:100]}...") try: result = subprocess.run( diff --git a/app/websocket/shell.py b/app/websocket/shell.py index 1349e4c..f504f45 100644 --- a/app/websocket/shell.py +++ b/app/websocket/shell.py @@ -45,7 +45,7 @@ def register_websocket_handlers(socketio, settings): @socketio.on('shell_create') def handle_shell_create(data): # Check if shell access is enabled - shell_enabled = settings.get('auth', {}).get('shell_enabled', False) + shell_enabled = settings.get('auth', {}).get('shell_enabled', True) if not shell_enabled: logger.warning(f"WebSocket shell rejected: shell disabled (sid={request.sid})") return emit('shell_created', {'success': False, 'error': 'Shell access is disabled'}) diff --git a/static/maps/T_WorldMap_Survival_1_D.png b/static/maps/T_WorldMap_Survival_1_D.png index 1f809fd..2b1ee46 100644 Binary files a/static/maps/T_WorldMap_Survival_1_D.png and b/static/maps/T_WorldMap_Survival_1_D.png differ diff --git a/templates/map.html b/templates/map.html index ac4505b..7fbcbc2 100644 --- a/templates/map.html +++ b/templates/map.html @@ -4,398 +4,679 @@ {% block content %} -