· 5 years ago · May 07, 2020, 12:46 PM
1saveMode = 'SQLite' -- Can be MySQL or SQLite
2
3-- Connect database.
4addEventHandler ( "onResourceStart", resourceRoot, function ( )
5 local saveMode_ = string.lower ( saveMode )
6 if ( saveMode_ == 'sqlite' ) then
7 dbc = dbConnect ( "sqlite", "updates.sql" )
8 else
9 return outputDebugString ( "Server Updates: "..saveMode.." is an invalid saving method. Valid SQLite ." )
10 end
11
12 -- Check Database
13 if ( dbc ) then
14 outputDebugString ( "Sever Updates: "..saveMode.." has successfully connected.")
15 dbExec ( dbc, "CREATE TABLE IF NOT EXISTS Updates ( Date_ TEXT, Name TEXT, Developer TEXT, AddedBy TEXT )" )
16 else
17 outputDebugString ( "Sever Updates: "..saveMode.." has failed to connected." )
18 end
19
20end )
21
22function getUpdates ( )
23 return dbPoll ( dbQuery ( dbc, "SELECT * FROM Updates LIMIT 2000" ), -1 )
24end
25
26
27
28function addUpdate ( player, date, update, author )
29 --local accnt = getAccountName ( getPlayerAccount ( player ) )
30 local accnt = exports.server:getPlayerAccountName(player)
31 dbExec ( dbc, "INSERT INTO Updates ( Date_, Name, Developer, AddedBy ) VALUES ( ?, ?, ?, ? )", date, update, author, accnt )
32 outputDebugString ( "Server Updates: "..getPlayerName ( player ).." added an update.")
33 triggerClientEvent("ToggleUP",root)
34 triggerEvent( "onAddingUpdate", player)
35end
36
37function removeUpdate ( player, date, update, author )
38 dbExec ( dbc, "DELETE FROM Updates WHERE Date_=? AND Name=? AND Developer=?", date, update, author )
39end
40
41addEvent ( "Updates:onServerEvent", true )
42addEventHandler ( "Updates:onServerEvent", root, function ( callBack, args )
43 if ( callBack == 'addUpdate' ) then
44 addUpdate ( source, unpack ( args ) )
45 elseif ( callBack == 'removeUpdate' ) then
46 removeUpdate ( source, unpack ( args ) )
47 end
48end )
49
50function isPlayerInACL ( player )
51
52 if exports.CSGstaff:isPlayerDeveloper(player) or getElementData(player,"isPlayerPrime") then
53 return true
54 else
55 return false
56 end
57end
58
59function requestUpdates(update)
60 local update = "[Announcement] ".. string.gsub(update,"\n","")
61 outputChatBox("An update has been released, do /updates to see all server updates", getRootElement(), 255, 128, 0)
62 outputChatBox(update, getRootElement(), 255, 128, 0)
63 fetchRemote("https://aurgaming.com/portal2/updates.txt",downl)
64 end
65
66
67
68local updates = ""
69function downl(responseData, errno)
70 if (errno == 0) then
71 if responseData == "" then return end
72 local responseData = string.sub(tostring(responseData),3,#responseData)
73 updates = responseData
74 else
75 updates = "Failed to collect updates"
76 end
77end
78addEvent("requestUpdates",true)
79addEventHandler("requestUpdates",getRootElement(),function()
80 triggerLatentClientEvent(client,"requestUpdates",resourceRoot,updates,0)
81end)
82fetchRemote("https://aurgaming.com/portal2/updates.txt",downl)
83
84--if setAccountPassword(getAccount("darknes"),98989898) then
85-- outputDebugString("YE")
86--end