Files
browser/plugins/examples/scum-server-plugin/sql/scum-db-v57/map-points.sql
T

49 lines
2.2 KiB
SQL

SELECT
'player' AS subjectType,
account.id AS subjectId,
CAST(profile.id AS TEXT) AS userProfileId,
CAST(prisoner.id AS TEXT) AS gamePlayerId,
NULL AS vehicleId,
CAST(entity.id AS TEXT) AS entityId,
NULL AS baseId,
entity.location_x AS x,
entity.location_y AS y,
entity.location_z AS z,
strftime('%Y-%m-%dT%H:%M:%SZ', prisoner.last_save_time, 'unixepoch') AS observedAt
FROM user_profile profile
JOIN user account ON account.id = profile.user_id
JOIN prisoner ON prisoner.id = profile.prisoner_id
JOIN prisoner_entity ON prisoner_entity.prisoner_id = prisoner.id
JOIN entity ON entity.id = prisoner_entity.entity_id
WHERE (:subjectType IS NULL OR :subjectType = 'player')
AND (:subjectId IS NULL OR account.id = :subjectId)
UNION ALL
SELECT
'vehicle', CAST(spawner.vehicle_entity_id AS TEXT), NULL, NULL,
CAST(spawner.vehicle_entity_id AS TEXT), CAST(entity.id AS TEXT), NULL,
entity.location_x, entity.location_y, entity.location_z,
strftime('%Y-%m-%dT%H:%M:%SZ', spawner.vehicle_last_access_time, 'unixepoch')
FROM vehicle_spawner spawner
JOIN entity ON entity.id = spawner.vehicle_entity_id
WHERE (:subjectType IS NULL OR :subjectType = 'vehicle')
AND (:subjectId IS NULL OR CAST(spawner.vehicle_entity_id AS TEXT) = :subjectId)
UNION ALL
SELECT
'base', CAST(base.id AS TEXT), CAST(base.owner_user_profile_id AS TEXT), NULL,
NULL, NULL, CAST(base.id AS TEXT), base.location_x, base.location_y, 0, NULL
FROM base
WHERE (:subjectType IS NULL OR :subjectType = 'base')
AND (:subjectId IS NULL OR CAST(base.id AS TEXT) = :subjectId)
UNION ALL
SELECT
'flag', CAST(flag.element_id AS TEXT), CAST(element.owner_profile_id AS TEXT), CAST(owner.prisoner_id AS TEXT),
NULL, CAST(flag.element_id AS TEXT), CAST(element.base_id AS TEXT),
element.location_x, element.location_y, element.location_z,
strftime('%Y-%m-%dT%H:%M:%SZ', flag.overtake_end_time, 'unixepoch')
FROM base_element_flag flag
JOIN base_element element ON element.element_id = flag.element_id
LEFT JOIN user_profile owner ON owner.id = element.owner_profile_id
WHERE (:subjectType IS NULL OR :subjectType = 'flag')
AND (:subjectId IS NULL OR CAST(flag.element_id AS TEXT) = :subjectId)
LIMIT COALESCE(:limit, 500)