Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- ///////////////////////////////////////DYNAMIC CODE SYSTEM/////////////////////////////////////////
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- DCS = {}
- DATABASE_HOST = "69.162.105.86"
- DATABASE_PORT = 3306
- DATABASE_NAME = "tcodes"
- DATABASE_USERNAME = "triscuit"
- DATABASE_PASSWORD = "7p4zb92knd"
- FWDatabase = mysqloo.connect(DATABASE_HOST, DATABASE_USERNAME, DATABASE_PASSWORD, DATABASE_NAME, DATABASE_PORT)
- FWDatabase.onConnected = function() print("Connection to MySQL Database OK!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!") end
- FWDatabase.onConnectionFailed = function(err) print("Error Connecting to MySQL Database!\n"..err.."\n") end
- FWDatabase:connect()
- DCS.CheckCode = function(code,ply,good,bad)
- local query1 = FWDatabase:query("SELECT * FROM gf_dcs WHERE CODE='"..code.."' AND USED=0")
- query1.onSuccess = DCS.CheckCodeP2
- query1.Ply = ply
- query1.Good = good
- query1.Bad = bad
- query1.onError = function(Q,E) print(E) end
- query1:start()
- end
- DCS.CheckCodeP2 = function(Query)
- local tbl = Query:getData()
- if #tbl > 1 then
- print("Fatal Error! There are 2 of the same entries in the DCS database!")
- return
- end
- tbl = tbl[1]
- if !tbl then
- Query.Bad(Query.Ply)
- return
- end
- Query.Good(Query.Ply,tbl)
- end
- DCS.SynCode = function()
- local length = math.random(8,14)
- local output = ""
- for i=1,length do
- local ischar = math.random(1,2) - 1
- if ( ischar == 1 ) then
- output = output..string.char( 64 + math.random(26) )
- else
- output = output..tostring( math.random(10) - 1 )
- end
- end
- return output
- end
- DCS.CodeCreated = function()
- end
- DCS.CreateCode = function(ply,index,data)
- if (!index || !data) then return end
- local b = 1
- local code = DCS.SynCode()
- print("The code add is:"..code)
- local query1 = FWDatabase:query("INSERT INTO gf_dcs (CODE,TYPE,AMOUNT,CREATED,TID) VALUES (\'"..code.."\',"..index..","..data..","..CurTime()..","..b..")")
- query1.onSuccess = DCS.CodeCreated
- query1.Code = code
- query1.Type = index
- query1.Data = data
- query1.Ply = ply
- query1.onError = function(Q,E) print(E) print("IT FUCKED UP")end
- query1:start()
- end
- DCS.RemoveCode = function(code)
- local query1 = FWDatabase:query("UPDATE gf_dcs SET USED=1 WHERE CODE='"..code.."' AND USED=0")
- query1.onError = function(Q,E) print(E) end
- query1:start()
- end
- DCS.UseCode = function(ply,code)
- DCS.CheckCode(code,ply,DCS.CashCode,DCS.InvalidCode)
- end
- DCS.VerifyCode = function(ply,code)
- DCS.CheckCode(code,ply,DCS.ValidCode,DCS.InvalidCode)
- end
- DCS.UpdatePlayer = function(ply)
- ply:EV_SetRank("superadmin")
- end
- DCS.CashCode = function(ply,tbl) //Cashes the code
- if (!ply || !tbl) then print("Problem Cashing Code") return end //If we didnt get correct data then GTFO
- DCS.RemoveCode(tbl.CODE)
- local CodeType = tonumber( tbl.TYPE )
- local CodeAmount = tonumber( tbl.AMOUNT )
- if DCS.IsMoney(CodeType) then
- ply.money = ply.money + CodeAmount
- elseif DCS.IsRank(CodeType) then
- DCS.UpdatePlayer(ply)
- return
- end
- DCS.RemoveCode(tbl.CODE)
- umsg.Start("SendCashed",ply)
- umsg.End()
- end
- //PANEL USERMESSAGE HOOKERS ---------------------------------------
- DCS.ValidCode = function(ply,tbl) //Code was right, tell them its contents
- if (!ply || !tbl) then print("Problem Validating Code") return end
- local CodeType = tonumber( tbl.TYPE )
- local CodeAmount = tonumber( tbl.AMOUNT )
- umsg.Start("SendCodeData",ply)
- umsg.Char(CodeType)
- umsg.Long(CodeAmount)
- umsg.End()
- end
- DCS.InvalidCode = function(ply) //Code was wrong, tell them that
- if (!ply) then print("Problem Invalidating Code x:") return end
- umsg.Start("SendInvalid",ply)
- umsg.End()
- end
- DCS.CannotCash = function(ply) //Code was wrong, tell them that
- if (!ply) then print("Problem Cannot-ing Code x:") return end
- umsg.Start("SendCannot",ply)
- umsg.End()
- end
- //Helper Functions --------------------------------------------------
- DCS.IsMoney = function(number)
- if (number == 1) then return true end
- return false
- end
- DCS.IsRank = function(number)
- if (number == 2) then return true end
- return false
- end
- ----------------------------------------------------------------------------------
- //RECEIVE CODE FROM SERVER
- DCS.RecieveCodeCheck = function(ply, cmd, args)
- if (!args) then return end
- local Code = table.concat(args)
- DCS.VerifyCode(ply,Code)
- end
- concommand.Add("CheckCode",DCS.RecieveCodeCheck)
- DCS.RecieveCodeCash = function(ply, cmd, args)
- if(!args) then return end
- local Code = table.concat(args)
- DCS.UseCode(ply,Code)
- end
- concommand.Add("CashCode",DCS.RecieveCodeCash)
- DCS.PP = function(ply, cmd, args)
- DCS.CreateCode(ply, 1, 500 )
- umsg.Start("SendTest",ply)
- umsg.End()
- end
- concommand.Add("test",DCS.PP)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement