Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Fingerprint saving & Search by fingerprint #312

Merged
merged 1 commit into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ RegisterNUICallback("searchProfiles", function(data, cb)
end)


RegisterNetEvent('mdt:client:searchProfile', function(sentData, isLimited)
SendNUIMessage({ type = "profiles", data = sentData, isLimited = isLimited })
RegisterNetEvent('mdt:client:searchProfile', function(sentData, isLimited, fingerprint)
SendNUIMessage({ action = "updateFingerprintData", fingerprint = fingerprint })
end)

RegisterNUICallback("saveProfile", function(data, cb)
Expand All @@ -301,8 +301,8 @@ RegisterNUICallback("saveProfile", function(data, cb)
local tags = data.tags
local gallery = data.gallery
local licenses = data.licenses

TriggerServerEvent("mdt:server:saveProfile", profilepic, information, cid, fName, sName, tags, gallery, licenses)
local fingerprint = data.fingerprint
TriggerServerEvent("mdt:server:saveProfile", profilepic, information, cid, fName, sName, tags, gallery, licenses, fingerprint)
cb(true)
end)

Expand Down Expand Up @@ -335,6 +335,8 @@ RegisterNUICallback("getProfileData", function(data, cb)
end
end
p = nil

result['fingerprint'] = result['searchFingerprint']
return cb(result)
end)

Expand Down
20 changes: 2 additions & 18 deletions server/dbm.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,10 @@ 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)
Expand All @@ -29,37 +26,29 @@ function GetNameFromId(cid)
--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 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 })
local result = MySQL.query.await('SELECT information, tags, gallery, pfp, fingerprint FROM mdt_data WHERE cid = ? and jobtype = ?', { cid, jobtype})
return result[1]
end

function GetIncidentName(id)
-- Should also be a scalar
local result = MySQL.query.await('SELECT title FROM `mdt_incidents` WHERE id = :id LIMIT 1', { id = id })
return result[1]
-- 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

Expand All @@ -69,7 +58,6 @@ 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)
Expand All @@ -85,20 +73,16 @@ function GetPlayerDataById(id)
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

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)
Expand Down
76 changes: 42 additions & 34 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -206,43 +206,48 @@ RegisterNetEvent('mdt:server:openMDT', function()
end)

QBCore.Functions.CreateCallback('mdt:server:SearchProfile', function(source, cb, sentData)
if not sentData then return cb({}) end
local src = source
local Player = QBCore.Functions.GetPlayer(src)
if Player then
local JobType = GetJobType(Player.PlayerData.job.name)
if JobType ~= nil then
local people = MySQL.query.await("SELECT p.citizenid, p.charinfo, md.pfp FROM players p LEFT JOIN mdt_data md on p.citizenid = md.cid WHERE LOWER(CONCAT(JSON_VALUE(p.charinfo, '$.firstname'), ' ', JSON_VALUE(p.charinfo, '$.lastname'))) LIKE :query OR LOWER(`charinfo`) LIKE :query OR LOWER(`citizenid`) LIKE :query AND jobtype = :jobtype LIMIT 20", { query = string.lower('%'..sentData..'%'), jobtype = JobType })
local citizenIds = {}
local citizenIdIndexMap = {}
if not next(people) then cb({}) return end

for index, data in pairs(people) do
people[index]['warrant'] = false
people[index]['convictions'] = 0
people[index]['licences'] = GetPlayerLicenses(data.citizenid)
people[index]['pp'] = ProfPic(data.gender, data.pfp)
citizenIds[#citizenIds+1] = data.citizenid
citizenIdIndexMap[data.citizenid] = index
end

local convictions = GetConvictions(citizenIds)
if not sentData then return cb({}) end
local src = source
local Player = QBCore.Functions.GetPlayer(src)
if Player then
local JobType = GetJobType(Player.PlayerData.job.name)
if JobType ~= nil then
local people = MySQL.query.await("SELECT p.citizenid, p.charinfo, md.pfp, md.fingerprint FROM players p LEFT JOIN mdt_data md on p.citizenid = md.cid WHERE LOWER(CONCAT(JSON_VALUE(p.charinfo, '$.firstname'), ' ', JSON_VALUE(p.charinfo, '$.lastname'))) LIKE :query OR LOWER(`charinfo`) LIKE :query OR LOWER(`citizenid`) LIKE :query OR LOWER(md.fingerprint) LIKE :query AND jobtype = :jobtype LIMIT 20", { query = string.lower('%'..sentData..'%'), jobtype = JobType })
local citizenIds = {}
local citizenIdIndexMap = {}
if not next(people) then cb({}) return end

for index, data in pairs(people) do
people[index]['warrant'] = false
people[index]['convictions'] = 0
people[index]['licences'] = GetPlayerLicenses(data.citizenid)
people[index]['pp'] = ProfPic(data.gender, data.pfp)
if data.fingerprint and data.fingerprint ~= "" then
people[index]['fingerprint'] = data.fingerprint
else
people[index]['fingerprint'] = ""
end
citizenIds[#citizenIds+1] = data.citizenid
citizenIdIndexMap[data.citizenid] = index
end

if next(convictions) then
for _, conv in pairs(convictions) do
if conv.warrant == "1" then people[citizenIdIndexMap[conv.cid]].warrant = true end
local convictions = GetConvictions(citizenIds)

local charges = json.decode(conv.charges)
people[citizenIdIndexMap[conv.cid]].convictions = people[citizenIdIndexMap[conv.cid]].convictions + #charges
end
end
if next(convictions) then
for _, conv in pairs(convictions) do
if conv.warrant == "1" then people[citizenIdIndexMap[conv.cid]].warrant = true end

local charges = json.decode(conv.charges)
people[citizenIdIndexMap[conv.cid]].convictions = people[citizenIdIndexMap[conv.cid]].convictions + #charges
end
end
TriggerClientEvent('mdt:client:searchProfile', src, people, false, people[1].fingerprint)

return cb(people)
end
end
return cb(people)
end
end

return cb({})
return cb({})
end)

QBCore.Functions.CreateCallback("mdt:server:getWarrants", function(source, cb)
Expand Down Expand Up @@ -418,26 +423,29 @@ QBCore.Functions.CreateCallback('mdt:server:GetProfileData', function(source, cb
person.profilepic = mdtData.pfp
person.tags = json.decode(mdtData.tags)
person.gallery = json.decode(mdtData.gallery)
person.fingerprint = mdtData.fingerprint
print("Fetched fingerprint from mdt_data:", mdtData.fingerprint)
end

return cb(person)
end)

RegisterNetEvent("mdt:server:saveProfile", function(pfp, information, cid, fName, sName, tags, gallery, licenses)
RegisterNetEvent("mdt:server:saveProfile", function(pfp, information, cid, fName, sName, tags, gallery, licenses, fingerprint)
local src = source
local Player = QBCore.Functions.GetPlayer(src)
UpdateAllLicenses(cid, licenses)
if Player then
local JobType = GetJobType(Player.PlayerData.job.name)
if JobType == 'doj' then JobType = 'police' end

MySQL.Async.insert('INSERT INTO mdt_data (cid, information, pfp, jobtype, tags, gallery) VALUES (:cid, :information, :pfp, :jobtype, :tags, :gallery) ON DUPLICATE KEY UPDATE cid = :cid, information = :information, pfp = :pfp, jobtype = :jobtype, tags = :tags, gallery = :gallery', {
MySQL.Async.insert('INSERT INTO mdt_data (cid, information, pfp, jobtype, tags, gallery, fingerprint) VALUES (:cid, :information, :pfp, :jobtype, :tags, :gallery, :fingerprint) ON DUPLICATE KEY UPDATE cid = :cid, information = :information, pfp = :pfp, jobtype = :jobtype, tags = :tags, gallery = :gallery, fingerprint = :fingerprint', {
cid = cid,
information = information,
pfp = pfp,
jobtype = JobType,
tags = json.encode(tags),
gallery = json.encode(gallery),
fingerprint = fingerprint,
}, function()
end)
end
Expand Down
Loading