pc-live/bridge/bridge_esx.lua
Bjoern Flessing be502d2834 IC-Computer: Schreibtisch, Fenster und Apps
Ein Computer im Spiel. Man tritt an ein Terminal, drueckt E, und bekommt eine
Oberflaeche mit Mail, Browser, Adressbuch, Kalender und weiteren Anwendungen.
Andere Resources haengen sich als App ein.

Auf ESX umgestellt:

  - Fuenf harte Abhaengigkeiten zeigten auf Resources, die es hier nicht gibt.
    Eine fehlende Abhaengigkeit verhindert den Start vollstaendig - die
    Resource waere nie hochgekommen.
  - Die Bruecke zum Framework neu geschrieben; Charakterdaten, Aktenverwaltung
    und Immobilien ausgebaut, weil die zugehoerigen Systeme fehlen.
  - pc_live_devices fehlte im Schema, wird vom Code aber gelesen. Ohne die
    Tabelle ist kein fester PC ansprechbar. Ein PC braucht ausserdem zwei
    Eintraege mit derselben Kennung: Standort in der Datenbank, Kamerafahrt in
    der config.lua.

Mail ueberarbeitet:

  - Postfaecher haengen an einer Anmeldung statt an der Person. Mehrere Leute
    koennen dasselbe Firmenpostfach gleichzeitig offen haben.
  - Ordner gehoeren zum Postfach, nicht zur Person. Eine Mail an ein geteiltes
    Postfach wird je Empfaenger einmal gespeichert; damit das Einsortieren
    trotzdem fuer alle gilt, tragen alle Kopien einer Zustellung dieselbe
    Kennung. Gelesen und geloescht bleibt persoenlich - das ist keine
    Eigenschaft der Nachricht, sondern der Person.
  - Signaturen gehoeren ebenfalls zum Postfach.
  - Kalender koennen privat, geteilt oder oeffentlich sein. Ein oeffentlicher
    Termin haengt bewusst auch an einem Postfach, sonst koennte ihn spaeter
    niemand mehr aendern oder absagen.

Neue Apps: Webhosting, Bleeter und dessen Verwaltung.

Behoben:

  - prompt(), confirm() und alert() froren das NUI ein. FiveMs CEF hat keinen
    Handler fuer die eingebauten Browserdialoge - der Aufruf oeffnet nichts und
    kehrt nie zurueck. Ersetzt durch eigene Dialoge.
  - Die Fenster tragen data-wid, keine id. Wer sie mit getElementById sucht,
    schreibt ins Leere und das Fenster bleibt leer.

Enthaelt README.md mit Einrichtung und PLUGINS.md: eine Anleitung, wie man eine
eigene App baut und einhaengt, mit vollstaendigem Beispiel von der Tabelle bis
zum Schreibtischsymbol.
2026-08-09 12:02:11 +00:00

190 lines
7.3 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- ─────────────────────────────────────────────────────────────────────────────
-- Bridge ESX Legacy
-- Nur aktiv, wenn Config.Framework == "esx"
--
-- Angepasst an ESX Legacy 1.13+. Drei Dinge waren gegen aeltere ESX-Staende
-- geschrieben und haetten hier nicht funktioniert:
--
-- 1. Clientseitig wurde das Objekt ueber TriggerEvent('esx:getSharedObject')
-- geholt. Dieses Event gibt es in ESX Legacy nicht mehr; ESX waere
-- dauerhaft nil geblieben und der PC haette weder Namen noch Identifier
-- gehabt. Richtig ist der Export.
-- 2. Benachrichtigungen liefen ueber 'ESX:ShowNotification'. Das Event heisst
-- 'esx:showNotification' (klein) der Aufruf ging ins Leere. Serverseitig
-- gibt es dafuer ohnehin xPlayer.showNotification.
-- 3. HasPermission verglich die Gruppe auf Gleichheit, konnte also immer nur
-- genau eine Gruppe zulassen. Jetzt sind Listen moeglich.
-- ─────────────────────────────────────────────────────────────────────────────
if not Bridge then Bridge = {} end
if Config.Framework ~= "esx" then return end
-- ESX erst bei Bedarf holen, nicht beim Laden der Datei.
-- Beim Start ist es je nach Reihenfolge noch nicht bereit; ein einmal
-- fehlgeschlagener Versuch haette die Bridge dauerhaft lahmgelegt.
local ESX
local function esx()
if ESX then return ESX end
local ok, obj = pcall(function()
return exports['es_extended']:getSharedObject()
end)
if ok and obj then ESX = obj end
return ESX
end
if IsDuplicityVersion() then
-- ── SERVER ────────────────────────────────────────────────────────────────
local function player(source)
local api = esx()
return api and api.GetPlayerFromId(source) or nil
end
function Bridge.GetIdentifier(source)
local xPlayer = player(source)
if not xPlayer then return tostring(source) end
return xPlayer.identifier
end
function Bridge.GetName(source)
local xPlayer = player(source)
if not xPlayer then return "Unknown" end
if xPlayer.getName then return xPlayer.getName() end
return xPlayer.name or "Unknown"
end
function Bridge.Notify(source, message, notifType)
local xPlayer = player(source)
if xPlayer and xPlayer.showNotification then
xPlayer.showNotification(message, notifType)
return
end
-- Rueckfall, falls der Spieler (noch) nicht geladen ist.
TriggerClientEvent('esx:showNotification', source, message, notifType)
end
-- perm darf ein einzelner Gruppenname oder eine Liste sein.
-- Vorher war nur Gleichheit moeglich, also genau eine erlaubte Gruppe.
function Bridge.HasPermission(source, perm)
local xPlayer = player(source)
if not xPlayer or not xPlayer.getGroup then return false end
local group = xPlayer.getGroup()
if not group then return false end
if type(perm) == "table" then
-- Beide Schreibweisen: Liste { 'admin', 'superadmin' }
-- und Menge { admin = true, superadmin = true }.
if perm[group] == true then return true end
for _, allowed in ipairs(perm) do
if allowed == group then return true end
end
return false
end
return group == perm
end
function Bridge.GetMoney(source, moneyType)
local xPlayer = player(source)
if not xPlayer then return 0 end
if moneyType == "cash" or moneyType == "money" then
return xPlayer.getMoney()
end
local account = xPlayer.getAccount(moneyType)
return account and account.money or 0
end
function Bridge.RemoveMoney(source, moneyType, amount)
local xPlayer = player(source)
if not xPlayer then return false end
amount = tonumber(amount) or 0
if amount <= 0 then return false end
-- Deckung pruefen: ohne das erzeugt ESX negative Kontostaende.
if Bridge.GetMoney(source, moneyType) < amount then return false end
if moneyType == "cash" or moneyType == "money" then
xPlayer.removeMoney(amount)
else
xPlayer.removeAccountMoney(moneyType, amount)
end
return true
end
function Bridge.AddMoney(source, moneyType, amount)
local xPlayer = player(source)
if not xPlayer then return false end
amount = tonumber(amount) or 0
if amount <= 0 then return false end
if moneyType == "cash" or moneyType == "money" then
xPlayer.addMoney(amount)
else
xPlayer.addAccountMoney(moneyType, amount)
end
return true
end
function Bridge.GetJob(source)
local xPlayer = player(source)
if not xPlayer then return nil end
return xPlayer.job and xPlayer.job.name or nil
end
-- Firmenzugehoerigkeit.
--
-- Im Ursprungssystem war das eine numerische Firmen-ID aus einer eigenen
-- Tabelle. ESX kennt so etwas nicht dort ist die Zugehoerigkeit der Job.
-- Ueber Config.CompanyJobs laesst sich eine ID auf einen ESX-Job abbilden;
-- ohne Eintrag gibt es keine Zugehoerigkeit, statt sie zu erfinden.
function Bridge.IsCompanyEmployee(source, companyId)
if not companyId then return false end
local map = Config.CompanyJobs or {}
local wanted = map[companyId] or map[tostring(companyId)]
if not wanted then return false end
local job = Bridge.GetJob(source)
return job ~= nil and job == wanted
end
else
-- ── CLIENT ────────────────────────────────────────────────────────────────
function Bridge.GetLocalIdentifier()
local api = esx()
local data = api and api.GetPlayerData()
return (data and data.identifier) or ""
end
function Bridge.GetLocalName()
local api = esx()
local data = api and api.GetPlayerData()
if not data then return "Unknown" end
-- ESX Legacy fuehrt den Namen je nach Aufbau unterschiedlich.
if data.name and data.name ~= "" then return data.name end
if data.firstName then
return ("%s %s"):format(data.firstName, data.lastName or ""):gsub("%s+$", "")
end
return GetPlayerName(PlayerId()) or "Unknown"
end
-- pc-live sendet Benachrichtigungen teils ueber ein eigenes Event.
-- Auf ESX wird daraus eine ESX-Notification.
RegisterNetEvent('pc-live:notification', function(message, notifType)
local api = esx()
if api and api.ShowNotification then
api.ShowNotification(message, notifType)
else
SetNotificationTextEntry("STRING")
AddTextComponentString(tostring(message))
DrawNotification(false, true)
end
end)
end