local DONATIONTYPES = {}
if SERVER then
DONATIONTYPES["1"] = function(ply)
--code to apply reward for donation of type 1
ply:PrintMessage(HUD_PRINTTALK, "You received donation type 1")
end
DONATIONTYPES["2"] = function(ply)
--code to apply reward for donation of type 2
ply:PrintMessage(HUD_PRINTTALK, "You received donation type 2")
end
ULib.ucl.addUser( ply:SteamID(), nil, nil, "donator" )["3"] = function(ply)
--code to apply reward for donation of type 3
ply:PrintMessage(HUD_PRINTTALK, "You received Donator!")
end
DONATIONTYPES["4"] = function(ply)
--code to apply reward for donation of type 3
ply:PrintMessage(HUD_PRINTTALK, "You received donation type 3")
end
end
if CLIENT then
function jaooeDonationKeyEnter()
local frame = vgui.Create("DFrame")
frame:SetPos(ScrW()/2-200,ScrH()/2-100)
frame:SetSize(400,100)
frame:SetTitle("Enter Donation Key")
frame:SetVisible(true)
frame:ShowCloseButton(true)
frame:MakePopup()
frame.Paint = function()
draw.RoundedBox(4,0,0,frame:GetWide(),frame:GetTall(),Color(0,0,0,170))
end
local label = vgui.Create("DLabel", frame)
label:SetText("Enter your key and press enter: ")
label:SetPos(10,40)
label:SizeToContents()
local textbox = vgui.Create("DTextEntry", frame)
textbox:SetPos(15+label:GetWide(),40)
textbox:SetSize(200,20)
textbox:SetEnterAllowed(true)
textbox.OnEnter = function()
if(textbox:GetValue() == "") then return end
net.Start("cl_sendDonationKey")
net.WriteString(textbox:GetValue())
net.SendToServer()
end
end
concommand.Add("enterdonationkey",jaooeDonationKeyEnter)
end
if SERVER then
require("tmysql4")
local host = "YOU MAY NOT KNOW XD" //use this instead of locahost
local user = "YOU MAY NOT KNOW XD"
local pass = "YOU MAY NOT KNOW XD"
local dbname = "YOU MAY NOT KNOW XD"
local port = YOU MAY NOT KNOW XD
local db = {}
local err = ""
function jaooeConnectDatabase()
db, err = tmysql.initialize( host,user,pass,dbname,port)
end
hook.Add("Initialize", "jaooeConnectDatabase", jaooeConnectDatabase)
util.AddNetworkString("cl_sendDonationKey")
net.Receive("cl_sendDonationKey", function(len,ply)
local key = net.ReadString()
jaooeProcessKey(ply,key)
end)
function jaooeProcessKey(ply,key)
db:Query("SELECT * FROM activationkeys WHERE activationkey='"..tmysql.escape(key).."' AND used=0", function(result,status,error)
if status then
if #result > 0 and #result < 2 then
if DONATIONTYPES[result[1]["type"]] then
DONATIONTYPES[result[1]["type"]](ply)
db:Query("UPDATE activationkeys SET used=1 WHERE activationkey='"..tmysql.escape(key).."' AND used=0", function(res,stat,err)
if stat then
print(ply:Nick().."'s key was used, updated database")
else
print(ply:Nick().."'s key could not be updated, something went wrong: "..err)
end
end,1)
else
ply:PrintMessage(HUD_PRINTTALK,"Key found but no code exists, contact administrator")
end
elseif #result > 0 then
ply:PrintMessage(HUD_PRINTTALK, "Multiple keys exist, contact administrator")
else
ply:PrintMessage(HUD_PRINTTALK, "Nothing found")
end
else
ply:PrintMessage(HUD_PRINTTALK, "Could not contact server, contact administrator")
end
end, 1)
db:Poll()
end
end