Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- MYSQL
- ]]
- require("mysqloo")
- Breach = (Breach or {})
- Breach.MySQL = {}
- BREACH_MYSQL_DB = (BREACH_MYSQL_DB or nil)
- BREACH_MYSQL_HOST = "web-panel01.gmchosting.com"
- BREACH_MYSQL_USER = "empirese_misfit"
- BREACH_MYSQL_PASS = "cuine123"
- BREACH_MYSQL_DBNM = "empirese_breachlevels"
- BREACH_MYSQL_PORT = 3306
- function Breach.MySQL:Connect()
- if (BREACH_MYSQL_DB && BREACH_MYSQL_DB:status() != mysqloo.DATABASE_NOT_CONNECTED) then
- return true
- end
- local db = mysqloo.connect( BREACH_MYSQL_HOST, BREACH_MYSQL_USER, BREACH_MYSQL_PASS, BREACH_MYSQL_DBNM, BREACH_MYSQL_PORT )
- function db:onConnected()
- MsgC( "[Breach MySQL] ", Color(255,255,255), "Database has connected!\n" )
- BREACH_MYSQL_DB = self
- Breach.MySQL:CreateTables()
- end
- function db:onConnectionFailed( err )
- MsgC( "[Breach MySQL] ", Color(255,255,255), "Connection to database failed!\n" )
- MsgC( "[Breach MySQL] ", Color(255,255,255), "Error:", err )
- end
- db:connect()
- end
- function Breach.MySQL:CreateTables()
- local q = BREACH_MYSQL_DB:query( "SELECT 1 FROM `breach_pdata` LIMIT 1;" )
- function q:onSuccess( data )
- MsgC("[Breach MySQL] ", Color(255,255,255), "breach_pdata table exists!\n")
- MsgC("[Breach MySQL] ", Color(255,255,255), "Successfully loaded!\n")
- end
- function q:onError( err, sql )
- local ctbl = BREACH_MYSQL_DB:query( [[
- CREATE TABLE `breach_pdata` (
- stid VARCHAR (255),
- level INT,
- exp INT,
- PRIMARY KEY (stid)
- )]] )
- function ctbl:onSuccess( data )
- MsgC("[Breach MySQL] ", Color(255,255,255), "Created breach_pdata table!\n")
- end
- function ctbl:onError( err, sql )
- MsgC("[Breach MySQL] ", Color(255,255,255), "Failed to create breach_pdata table!\n")
- MsgC("[Breach MySQL] ", Color(255,255,255), "SQL: " .. sql .. "\n")
- MsgC("[Breach MySQL] ", Color(255,255,255), "Error: " .. err .. "\n")
- end
- ctbl:start()
- end
- q:start()
- end
- Breach.MySQL:Connect()
- -- [[PLAYER INIT]]
- hook.Add("PlayerSpawn", "Breach.MySQL.PInit",
- function(ply)
- local checkply = BREACH_MYSQL_DB:query( "SELECT * FROM `breach_pdata` WHERE stid = '" .. ply:SteamID() .. "'")
- function checkply:onSuccess( data )
- if (#data <= 0) then
- local cp = BREACH_MYSQL_DB:query( "INSERT INTO `breach_pdata` (stid, level, exp) VALUES ('" .. ply:SteamID() .. "','1','0')" )
- function cp:onSuccess( data )
- MsgC("[Breach MySQL] ", Color(255,255,255), "Created " .. ply:Nick() .. "'s data!\n")
- end
- function cp:onError( err, sql )
- print( "Query errored!" )
- print( "Query:", sql )
- print( "Error:", err )
- end
- cp:start()
- end
- ply:SetNLevel( data[1] && data[1].level || 1 )
- ply:SetPData( "breach_level", data[1] && data[1].level || 1 )
- ply:SetNEXP( data[1] && data[1].exp || 0 )
- ply:SetPData( "breach_exp", data[1] && data[1].exp || 1 )
- end
- function checkply:onError( err, sql )
- print( "Query errored!" )
- print( "Query:", sql )
- print( "Error:", err )
- end
- checkply:start()
- end)
- -- [[LEVEL HOOKS]]
- hook.Add("Breach_EXP_UPD", "Breach.EXP.Upd_MySQL",
- function(ply, amt)
- local updexp = BREACH_MYSQL_DB:query( "UPDATE `breach_pdata` SET exp = '" .. amt .. "' WHERE stid = '" .. ply:SteamID() .. "'" )
- function updexp:onSuccess( data )
- MsgC("[Breach MySQL] ", Color(255,255,255), "Updated " .. ply:Nick() .. "'s EXP!\n")
- end
- function updexp:onError( err, sql )
- print( "Query errored!" )
- print( "Query:", sql )
- print( "Error:", err )
- end
- updexp:start()
- end)
- hook.Add("Breach_LVL_UPD", "Breach.LVL.Upd_MySQL",
- function(ply, amt)
- local updlvl = BREACH_MYSQL_DB:query( "UPDATE `breach_pdata` SET level = '" .. amt .. "' WHERE stid = '" .. ply:SteamID() .. "'" )
- function updlvl:onSuccess( data )
- MsgC("[Breach MySQL] ", Color(255,255,255), "Updated " .. ply:Nick() .. "'s level!\n")
- end
- function updlvl:onError( err, sql )
- print( "Query errored!" )
- print( "Query:", sql )
- print( "Error:", err )
- end
- updlvl:start()
- end)
- timer.Create("Breach_MYSQL_INFO_UPDATE", 30, 0,
- function()
- local plys = player.GetAll()
- for i = 1,#plys do
- local updlvl = BREACH_MYSQL_DB:query( "UPDATE `breach_pdata` SET level = '" .. plys[i]:GetPData( "breach_level" ) ..
- "', exp = '" .. plys[i]:GetPData( "breach_exp" ) .. "' WHERE stid = '" .. ply:SteamID() .. "'" )
- function updlvl:onSuccess( data )
- MsgC("[Breach MySQL] ", Color(255,255,255), "Updated " .. ply:Nick() .. "'s level!\n")
- end
- function updlvl:onError( err, sql )
- print( "Query errored!" )
- print( "Query:", sql )
- print( "Error:", err )
- end
- updlvl:start()
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement