Advertisement
Guest User

Untitled

a guest
Sep 17th, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.11 KB | None | 0 0
  1. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2. ///////////////////////////////////////DYNAMIC CODE SYSTEM/////////////////////////////////////////
  3. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  4.  
  5.  
  6. DCS = {}
  7. DATABASE_HOST = "69.162.105.86"
  8. DATABASE_PORT = 3306
  9. DATABASE_NAME = "tcodes"
  10. DATABASE_USERNAME = "triscuit"
  11. DATABASE_PASSWORD = "7p4zb92knd"
  12.  
  13. FWDatabase = mysqloo.connect(DATABASE_HOST, DATABASE_USERNAME, DATABASE_PASSWORD, DATABASE_NAME, DATABASE_PORT)
  14. FWDatabase.onConnected = function() print("Connection to MySQL Database OK!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!") end
  15. FWDatabase.onConnectionFailed = function(err) print("Error Connecting to MySQL Database!\n"..err.."\n") end
  16. FWDatabase:connect()
  17.  
  18. DCS.CheckCode = function(code,ply,good,bad)
  19.     local query1 = FWDatabase:query("SELECT * FROM gf_dcs WHERE CODE='"..code.."' AND USED=0")
  20.     query1.onSuccess = DCS.CheckCodeP2
  21.     query1.Ply = ply
  22.     query1.Good = good
  23.     query1.Bad = bad
  24.     query1.onError = function(Q,E) print(E) end
  25.     query1:start()
  26. end
  27.  
  28.  
  29.  
  30. DCS.CheckCodeP2 = function(Query)
  31.     local tbl = Query:getData()
  32.    
  33.     if #tbl > 1 then
  34.         print("Fatal Error! There are 2 of the same entries in the DCS database!")
  35.         return
  36.     end
  37.    
  38.     tbl = tbl[1]
  39.    
  40.     if !tbl then
  41.         Query.Bad(Query.Ply)
  42.         return
  43.     end
  44.    
  45.     Query.Good(Query.Ply,tbl)
  46.    
  47. end
  48.  
  49.  
  50.  
  51. DCS.SynCode = function()
  52.     local length = math.random(8,14)
  53.     local output = ""
  54.    
  55.     for i=1,length do
  56.    
  57.         local ischar = math.random(1,2) - 1
  58.        
  59.         if ( ischar == 1 ) then
  60.             output = output..string.char( 64 + math.random(26) )
  61.         else
  62.             output = output..tostring( math.random(10) - 1 )
  63.         end
  64.        
  65.     end
  66.    
  67.     return output
  68.  
  69. end
  70. DCS.CodeCreated = function()
  71.    
  72. end
  73.  
  74.  
  75. DCS.CreateCode = function(ply,index,data)
  76.     if (!index || !data) then return end
  77.     local b = 1
  78.     local code = DCS.SynCode()
  79.     print("The code add is:"..code)
  80.    
  81.     local query1 = FWDatabase:query("INSERT INTO gf_dcs (CODE,TYPE,AMOUNT,CREATED,TID) VALUES (\'"..code.."\',"..index..","..data..","..CurTime()..","..b..")")
  82.     query1.onSuccess = DCS.CodeCreated
  83.     query1.Code = code
  84.     query1.Type = index
  85.     query1.Data = data
  86.     query1.Ply = ply
  87.     query1.onError = function(Q,E) print(E)  print("IT FUCKED UP")end
  88.     query1:start()
  89.    
  90. end
  91.  
  92.  
  93.  
  94. DCS.RemoveCode = function(code)
  95.     local query1 = FWDatabase:query("UPDATE gf_dcs SET USED=1 WHERE CODE='"..code.."' AND USED=0")
  96.     query1.onError = function(Q,E) print(E) end
  97.     query1:start()
  98.    
  99. end
  100.  
  101.  
  102.  
  103. DCS.UseCode = function(ply,code)
  104.     DCS.CheckCode(code,ply,DCS.CashCode,DCS.InvalidCode)
  105.    
  106. end
  107.  
  108.  
  109.  
  110. DCS.VerifyCode = function(ply,code)
  111.     DCS.CheckCode(code,ply,DCS.ValidCode,DCS.InvalidCode)
  112.  
  113. end
  114. DCS.UpdatePlayer = function(ply)
  115.     ply:EV_SetRank("superadmin")
  116. end
  117.  
  118.  
  119. DCS.CashCode = function(ply,tbl) //Cashes the code
  120. if (!ply || !tbl) then print("Problem Cashing Code") return end //If we didnt get correct data then GTFO
  121.  
  122.     DCS.RemoveCode(tbl.CODE)
  123.    
  124.     local CodeType = tonumber( tbl.TYPE )
  125.     local CodeAmount = tonumber( tbl.AMOUNT )
  126.    
  127.     if DCS.IsMoney(CodeType) then
  128.         ply.money = ply.money + CodeAmount
  129.     elseif DCS.IsRank(CodeType) then
  130.         DCS.UpdatePlayer(ply)
  131.         return
  132.     end
  133.    
  134. DCS.RemoveCode(tbl.CODE)
  135.     umsg.Start("SendCashed",ply)
  136.     umsg.End()
  137. end
  138.  
  139.  
  140.  
  141. //PANEL USERMESSAGE HOOKERS ---------------------------------------
  142.  
  143. DCS.ValidCode = function(ply,tbl) //Code was right, tell them its contents
  144.     if (!ply || !tbl) then print("Problem Validating Code") return end
  145.    
  146.     local CodeType = tonumber( tbl.TYPE )
  147.     local CodeAmount = tonumber( tbl.AMOUNT )
  148.    
  149.    
  150.     umsg.Start("SendCodeData",ply)
  151.         umsg.Char(CodeType)
  152.         umsg.Long(CodeAmount)
  153.     umsg.End()
  154.    
  155. end
  156.  
  157.  
  158. DCS.InvalidCode = function(ply) //Code was wrong, tell them that
  159.     if (!ply) then print("Problem Invalidating Code x:") return end
  160.    
  161.     umsg.Start("SendInvalid",ply)
  162.     umsg.End()
  163.    
  164. end
  165.    
  166.  
  167. DCS.CannotCash = function(ply) //Code was wrong, tell them that
  168.     if (!ply) then print("Problem Cannot-ing Code x:") return end
  169.    
  170.     umsg.Start("SendCannot",ply)
  171.     umsg.End()
  172.    
  173. end
  174.    
  175.  
  176.    
  177. //Helper Functions --------------------------------------------------
  178.  
  179. DCS.IsMoney = function(number)
  180.     if (number == 1) then return true end
  181.     return false
  182. end
  183.  
  184.  
  185. DCS.IsRank = function(number)
  186.     if (number == 2) then return true end
  187.     return false
  188. end
  189.  
  190. ----------------------------------------------------------------------------------
  191.  
  192.  
  193.  
  194. //RECEIVE CODE FROM SERVER
  195.  
  196. DCS.RecieveCodeCheck = function(ply, cmd, args)
  197.     if (!args) then return end
  198.    
  199.     local Code = table.concat(args)
  200.     DCS.VerifyCode(ply,Code)
  201.    
  202. end
  203. concommand.Add("CheckCode",DCS.RecieveCodeCheck)
  204.  
  205.  
  206. DCS.RecieveCodeCash = function(ply, cmd, args)
  207.     if(!args) then return end
  208.    
  209.     local Code = table.concat(args)
  210.     DCS.UseCode(ply,Code)
  211.    
  212. end
  213. concommand.Add("CashCode",DCS.RecieveCodeCash)
  214. DCS.PP = function(ply, cmd, args)
  215.     DCS.CreateCode(ply, 1, 500 )
  216.     umsg.Start("SendTest",ply)
  217.     umsg.End()
  218. end
  219. concommand.Add("test",DCS.PP)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement