Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.02 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 = "lol626465"
  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()..","..2..")")
  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.  
  115.  
  116.  
  117. DCS.CashCode = function(ply,tbl) //Cashes the code
  118. if (!ply || !tbl) then print("Problem Cashing Code") return end //If we didnt get correct data then GTFO
  119.  
  120.     DCS.RemoveCode(tbl.CODE)
  121.    
  122.     local CodeType = tonumber( tbl.TYPE )
  123.     local CodeAmount = tonumber( tbl.AMOUNT )
  124.    
  125.     if DCS.IsMoney(CodeType) then
  126.         ply.money = ply.money + CodeAmount
  127.         return
  128.     elseif DCS.IsRank(CodeType) then
  129.         ply:GiveVIP()
  130.         return
  131.     end
  132.    
  133. DCS.RemoveCode(tbl.CODE)
  134.     umsg.Start("SendCashed",ply)
  135.     umsg.End()
  136. end
  137.  
  138.  
  139.  
  140. //PANEL USERMESSAGE HOOKERS ---------------------------------------
  141.  
  142. DCS.ValidCode = function(ply,tbl) //Code was right, tell them its contents
  143.     if (!ply || !tbl) then print("Problem Validating Code") return end
  144.    
  145.     local CodeType = tonumber( tbl.TYPE )
  146.     local CodeAmount = tonumber( tbl.AMOUNT )
  147.    
  148.    
  149.     umsg.Start("SendCodeData",ply)
  150.         umsg.Char(CodeType)
  151.         umsg.Long(CodeAmount)
  152.     umsg.End()
  153.    
  154. end
  155.  
  156.  
  157. DCS.InvalidCode = function(ply) //Code was wrong, tell them that
  158.     if (!ply) then print("Problem Invalidating Code x:") return end
  159.    
  160.     umsg.Start("SendInvalid",ply)
  161.     umsg.End()
  162.    
  163. end
  164.    
  165.  
  166. DCS.CannotCash = function(ply) //Code was wrong, tell them that
  167.     if (!ply) then print("Problem Cannot-ing Code x:") return end
  168.    
  169.     umsg.Start("SendCannot",ply)
  170.     umsg.End()
  171.    
  172. end
  173.    
  174.  
  175.    
  176. //Helper Functions --------------------------------------------------
  177.  
  178. DCS.IsMoney = function(number)
  179.     if (number == 1) then return true end
  180.     return false
  181. end
  182.  
  183.  
  184. DCS.IsRank = function(number)
  185.     if (number == 2) then return true end
  186.     return false
  187. end
  188.  
  189. ----------------------------------------------------------------------------------
  190.  
  191.  
  192.  
  193. //RECEIVE CODE FROM SERVER
  194.  
  195. DCS.RecieveCodeCheck = function(ply, cmd, args)
  196.     if (!args) then return end
  197.    
  198.     local Code = table.concat(args)
  199.     DCS.VerifyCode(ply,Code)
  200.    
  201. end
  202. concommand.Add("CheckCode",DCS.RecieveCodeCheck)
  203.  
  204.  
  205. DCS.RecieveCodeCash = function(ply, cmd, args)
  206.     if(!args) then return end
  207.    
  208.     local Code = table.concat(args)
  209.     DCS.UseCode(ply,Code)
  210.    
  211. end
  212. concommand.Add("CashCode",DCS.RecieveCodeCash)
  213. -- DCS.PP = function(ply, cmd, args)
  214.     -- DCS.CreateCode(ply, 1, 500 )
  215.  
  216. -- end
  217. -- concommand.Add("test",DCS.PP)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement