forked from Red-Killer/lb-musicapp
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.lua
More file actions
69 lines (58 loc) · 2.37 KB
/
server.lua
File metadata and controls
69 lines (58 loc) · 2.37 KB
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
QBCore = exports['qb-core']:GetCoreObject()
QBCore.Functions.CreateCallback('getSavedTracks', function(source, cb, citizenid)
local selectQuery = "SELECT url FROM lb_music WHERE citizenID = @citizenid"
local selectParams = { ['@citizenid'] = citizenid }
MySQL.Async.fetchAll(selectQuery, selectParams, function(results)
if results then
cb(results)
else
cb({})
end
end)
end)
function SaveSongToPlaylist(citizenid, url)
local insertQuery = "INSERT INTO lb_music (citizenID, url) VALUES (?, ?)"
local insertParams = { citizenid, url }
MySQL.query.await(insertQuery, insertParams)
end
-- Implement a function to delete the song from the database
function DeleteSongFromPlaylist(citizenid, trackId)
-- Update the query to ensure only the first matching row is deleted
local deleteQuery = "DELETE FROM lb_music WHERE citizenID = ? AND url = ? LIMIT 1"
local deleteParams = { citizenid, trackId }
MySQL.query.await(deleteQuery, deleteParams)
end
RegisterNetEvent("phone:youtube_music:soundStatus", function(type, data)
local src = source
local musicId = "phone_youtubemusic_id_" ..src
if type ~= "position" and type ~= "play" and type ~= "volume" and type ~= "stop" then
print("Invalid type for phone:youtube_music:soundStatus: " .. type)
end
TriggerClientEvent("phone:youtube_music:soundStatus", -1, type, musicId, data)
end)
RegisterNetEvent('saveSong')
AddEventHandler('saveSong', function(data)
local youtubeUrl = data.url
local src = source
local playerId = src
local Player = QBCore.Functions.GetPlayer(playerId)
if Player then
local citizenid = Player.PlayerData.citizenid
SaveSongToPlaylist(citizenid, youtubeUrl)
TriggerClientEvent('notification', playerId, { type = 'success', title = 'Song saved successfully!' })
else
print("Player not found!")
end
end)
-- Add a new event handler for song deletion
RegisterNetEvent('deleteSong')
AddEventHandler('deleteSong', function(data)
local src = source
local playerId = src
local trackId = data.trackId
local Player = QBCore.Functions.GetPlayer(playerId)
if Player then
local citizenid = Player.PlayerData.citizenid
DeleteSongFromPlaylist(citizenid, trackId)
end
end)