forked from Project-Sloth/ps-mdt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdbm.lua
184 lines (160 loc) · 7.54 KB
/
dbm.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
local QBCore = exports['qb-core']:GetCoreObject()
-- Get CitizenIDs from Player License
function GetCitizenID(license)
local result = MySQL.query.await("SELECT citizenid FROM players WHERE license = ?", {license,})
if result ~= nil then
return result
else
print("Cannot find a CitizenID for License: "..license)
return nil
end
end
-- (Start) Opening the MDT and sending data
function AddLog(text)
--print(text)
return MySQL.insert.await('INSERT INTO `mdt_logs` (`text`, `time`) VALUES (?,?)', {text, os.time() * 1000})
-- return exports.oxmysql:execute('INSERT INTO `mdt_logs` (`text`, `time`) VALUES (:text, :time)', { text = text, time = os.time() * 1000 })
end
function GetNameFromId(cid)
-- Should be a scalar?
local result = MySQL.scalar.await('SELECT charinfo FROM players WHERE citizenid = @citizenid', { ['@citizenid'] = cid })
if result ~= nil then
local charinfo = json.decode(result)
local fullname = charinfo['firstname']..' '..charinfo['lastname']
return fullname
else
--print('Player does not exist')
return nil
end
-- return exports.oxmysql:executeSync('SELECT firstname, lastname FROM `users` WHERE id = :id LIMIT 1', { id = cid })
end
-- idk what this is used for either
function GetPersonInformation(cid, jobtype)
local result = MySQL.query.await('SELECT information, tags, gallery, pfp, fingerprint FROM mdt_data WHERE cid = ? and jobtype = ?', { cid, jobtype})
return result[1]
-- return exports.oxmysql:executeSync('SELECT information, tags, gallery FROM mdt WHERE cid= ? and type = ?', { cid, jobtype })
end
function GetPfpFingerPrintInformation(cid)
local result = MySQL.query.await('SELECT pfp, fingerprint FROM mdt_data WHERE cid = ?', { cid })
return result[1]
end
-- idk but I guess sure?
function GetIncidentName(id)
-- Should also be a scalar
return MySQL.query.await('SELECT title FROM `mdt_incidents` WHERE id = :id LIMIT 1', { id = id })
-- return exports.oxmysql:executeSync('SELECT title FROM `mdt_incidents` WHERE id = :id LIMIT 1', { id = id })
end
function GetConvictions(cids)
return MySQL.query.await('SELECT * FROM `mdt_convictions` WHERE `cid` IN(?)', { cids })
-- return exports.oxmysql:executeSync('SELECT * FROM `mdt_convictions` WHERE `cid` IN(?)', { cids })
end
function GetLicenseInfo(cid)
local result = MySQL.query.await('SELECT * FROM `licenses` WHERE `cid` = ?', { cid })
return result
-- return exports.oxmysql:executeSync('SELECT * FROM `licenses` WHERE `cid`=:cid', { cid = cid })
end
function CreateUser(cid, tableName)
AddLog("A user was created with the CID: "..cid)
-- return exports.oxmysql:insert("INSERT INTO `"..dbname.."` (cid) VALUES (:cid)", { cid = cid })
return MySQL.insert.await("INSERT INTO `"..tableName.."` (cid) VALUES (:cid)", { cid = cid })
end
function GetPlayerVehicles(cid, cb)
return MySQL.query.await('SELECT id, plate, vehicle FROM player_vehicles WHERE citizenid=:cid', { cid = cid })
end
function GetBulletins(JobType)
return MySQL.query.await('SELECT * FROM `mdt_bulletin` WHERE `jobtype` = ? LIMIT 10', { JobType })
-- return exports.oxmysql:executeSync('SELECT * FROM `mdt_bulletin` WHERE `type`= ? LIMIT 10', { JobType })
end
function GetPlayerProperties(cid, cb)
local result = MySQL.query.await('SELECT houselocations.label, houselocations.coords FROM player_houses INNER JOIN houselocations ON player_houses.house = houselocations.name where player_houses.citizenid = ?', {cid})
return result
end
function GetPlayerDataById(id)
local Player = QBCore.Functions.GetPlayerByCitizenId(id)
if Player ~= nil then
local response = {citizenid = Player.PlayerData.citizenid, charinfo = Player.PlayerData.charinfo, metadata = Player.PlayerData.metadata, job = Player.PlayerData.job}
return response
else
return MySQL.single.await('SELECT citizenid, charinfo, job, metadata FROM players WHERE citizenid = ? LIMIT 1', { id })
end
-- return exports.oxmysql:executeSync('SELECT citizenid, charinfo, job FROM players WHERE citizenid = ? LIMIT 1', { id })
end
-- Probs also best not to use
--[[ function GetImpoundStatus(vehicleid, cb)
cb( #(exports.oxmysql:executeSync('SELECT id FROM `impound` WHERE `vehicleid`=:vehicleid', {['vehicleid'] = vehicleid })) > 0 )
end ]]
function GetBoloStatus(plate)
local result = MySQL.scalar.await('SELECT id FROM `mdt_bolos` WHERE LOWER(`plate`)=:plate', { plate = string.lower(plate)})
return result
-- return exports.oxmysql:scalarSync('SELECT id FROM `mdt_bolos` WHERE LOWER(`plate`)=:plate', { plate = string.lower(plate)})
end
function GetOwnerName(cid)
local result = MySQL.scalar.await('SELECT charinfo FROM `players` WHERE LOWER(`citizenid`) = ? LIMIT 1', {cid})
return result
-- return exports.oxmysql:scalarSync('SELECT charinfo FROM `players` WHERE id=:cid LIMIT 1', { cid = cid})
end
function GetVehicleInformation(plate, cb)
local result = MySQL.query.await('SELECT id, information FROM `mdt_vehicleinfo` WHERE plate=:plate', { plate = plate})
cb(result)
end
function GetPlayerLicenses(identifier)
local response = false
local Player = QBCore.Functions.GetPlayerByCitizenId(identifier)
if Player ~= nil then
return Player.PlayerData.metadata.licences
else
local result = MySQL.scalar.await('SELECT metadata FROM players WHERE citizenid = @identifier', {['@identifier'] = identifier})
if result ~= nil then
local metadata = json.decode(result)
if metadata["licences"] ~= nil and metadata["licences"] then
return metadata["licences"]
else
return {
['driver'] = false,
['business'] = false,
['weapon'] = false,
['pilot'] = false
}
end
end
end
end
function ManageLicense(identifier, type, status)
local Player = QBCore.Functions.GetPlayerByCitizenId(identifier)
local licenseStatus = nil
if status == "give" then licenseStatus = true elseif status == "revoke" then licenseStatus = false end
if Player ~= nil then
local licences = Player.PlayerData.metadata["licences"]
local newLicenses = {}
for k, v in pairs(licences) do
local status = v
if k == type then
status = licenseStatus
end
newLicenses[k] = status
end
Player.Functions.SetMetaData("licences", newLicenses)
else
local licenseType = '$.licences.'..type
local result = MySQL.query.await('UPDATE `players` SET `metadata` = JSON_REPLACE(`metadata`, ?, ?) WHERE `citizenid` = ?', {licenseType, licenseStatus, identifier}) --seems to not work on older MYSQL versions, think about alternative
end
end
function ManageLicenses(identifier, incomingLicenses)
local Player = QBCore.Functions.GetPlayerByCitizenId(identifier)
if Player ~= nil then
Player.Functions.SetMetaData("licences", incomingLicenses)
else
local result = MySQL.scalar.await('SELECT metadata FROM players WHERE citizenid = @identifier', {['@identifier'] = identifier})
result = json.decode(result)
result.licences = result.licences or {
['driver'] = true,
['business'] = false,
['weapon'] = false,
['pilot'] = false
}
for k, _ in pairs(incomingLicenses) do
result.licences[k] = incomingLicenses[k]
end
MySQL.query.await('UPDATE `players` SET `metadata` = @metadata WHERE citizenid = @citizenid', {['@metadata'] = json.encode(result), ['@citizenid'] = identifier})
end
end