-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.lua
63 lines (57 loc) · 2.12 KB
/
server.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
local QRCore = exports['qr-core']:GetCoreObject()
-- Fetch all blips
QRCore.Functions.CreateCallback('getBlips', function(source, cb)
MySQL.Async.fetchAll('SELECT * FROM blips', {}, function(result)
local blips = {}
for i=1, #result, 1 do
table.insert(blips, {
name = result[i].name,
sprite = result[i].sprite,
position = json.decode(result[i].position),
openTime = result[i].openTime,
closeTime = result[i].closeTime,
openColor = result[i].openColor,
closeColor = result[i].closeColor
})
end
cb(blips)
end)
end)
-- Add New Blip
QRCore.Functions.CreateCallback('addBlip', function(source, cb, blipData)
MySQL.Async.fetchScalar('SELECT COUNT(*) FROM blips WHERE name = @name', {
['@name'] = blipData.name
}, function(count)
if count > 0 then
cb(false, "A blip with the same name already exists!")
return
end
MySQL.Async.insert('INSERT INTO blips (name, sprite, position, openTime, closeTime, openColor, closeColor) VALUES (@name, @sprite, @position, @openTime, @closeTime, @openColor, @closeColor)', {
['@name'] = blipData.name,
['@sprite'] = blipData.sprite,
['@position'] = json.encode(blipData.position),
['@openTime'] = blipData.openTime,
['@closeTime'] = blipData.closeTime,
['@openColor'] = blipData.openColor,
['@closeColor'] = blipData.closeColor
}, function(insertId)
if insertId then
cb(true)
else
cb(false, "Failed to add blip to the database.")
end
end)
end)
end)
--Remove Blip
QRCore.Functions.CreateCallback('removeBlip', function(source, cb, blipName)
MySQL.Async.execute('DELETE FROM blips WHERE name = @name', {
['@name'] = blipName
}, function(rowsChanged)
if rowsChanged > 0 then
cb(true)
else
cb(false, "Failed to remove blip from the database.")
end
end)
end)