daily pastebin goal
23%
SHARE
TWEET

Untitled

a guest Apr 29th, 2017 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. require( "mysqloo" )
  2.  
  3. local HOST = "127.0.0.1"
  4. local USER = "gmod_deathrun"
  5. local PASS = "DmxCaMHudGaWr8UU"
  6. local NAME = "gmod_deathrun"
  7. local PORT = 3306
  8. local mysql_socket = ""
  9.  
  10. CLANSdatabase = mysqloo.connect( HOST, USER, PASS, NAME, PORT, mysql_socket)
  11. local db = CLANSdatabase
  12. db:connect()
  13. function db:onConnected()
  14.   MsgN('ClanSystem MySQL: Connected!')
  15.  
  16.   CreateClansTable()
  17.   CreatePlayersTable()
  18. end
  19.  
  20. function CreateClansTable()
  21.   local qs = [[
  22.   CREATE TABLE IF NOT EXISTS `clansystem_clans` (
  23.     `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
  24.     `clan_name` VARCHAR(20) NOT NULL,
  25.     `kuerzel` VARCHAR(10) NOT NULL,
  26.     `date` TIMESTAMP NOT NULL DEFAULT NOW(),
  27.     `leader_steamid` VARCHAR(25) NOT NULL,
  28.     `member` int(10) NOT NULL DEFAULT '1',
  29.     `max_member` int(10) NOT NULL DEFAULT '5',
  30.     `xp_bonus` float NOT NULL DEFAULT '0.02',
  31.     `clan_color` VARCHAR(10) NOT NULL DEFAULT 'Default',
  32.     `clan_image` VARCHAR(20) NOT NULL DEFAULT 'NONE',
  33.     PRIMARY KEY (`id`)
  34.   ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  35.   ]]
  36.   local q = db:query(qs)
  37.   q:start()
  38. end
  39.  
  40. function CreatePlayersTable()
  41.   local qs = [[
  42.   CREATE TABLE IF NOT EXISTS `clansystem_players` (
  43.     `steamid` VARCHAR(25) NOT NULL,
  44.     `clanid` BIGINT(20) NOT NULL DEFAULT '0',
  45.     `name` VARCHAR(40) NOT NULL DEFAULT 'N/A',
  46.     `kills` Int(20) NOT NULL DEFAULT '0',
  47.     `deaths` Int(20) NOT NULL DEFAULT '0',
  48.     PRIMARY KEY (`steamid`)
  49.   ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  50.   ]]
  51.  
  52.   local q = db:query(qs)
  53.   q:start()
  54. end
  55.  
  56. function db:onConnectionFailed(err)
  57.     MsgN('ClanSystem MySQL: Connection Failed: ' .. err)
  58. end
  59. function CLANS:GetMembersLevel(members)
  60.        for k, v in pairs(members) do
  61.        local id = v[2]
  62.         local qs = [[
  63.     SELECT *
  64.     FROM `levelsystem_data`
  65.     WHERE steamid = '%s'
  66.     ]]
  67.     qs = string.format(qs, id)
  68.     local q = db:query(qs)
  69.     function q:onSuccess(data)
  70.    
  71.         local i = 1
  72.         while #data >= i do
  73.         local row = data[i]
  74.          table.insert(v,row.level)
  75.           i = i + 1
  76.         end
  77.         print("FUNCTION FERTIG")
  78.         PrintTable(members)
  79.     end
  80.      
  81.     function q:onError(err, sql)
  82.         if db:status() ~= mysqloo.DATABASE_CONNECTED then
  83.             db:connect()
  84.             db:wait()
  85.             if db:status() ~= mysqloo.DATABASE_CONNECTED then
  86.                 ErrorNoHalt("Re-connection to database server failed.")
  87.                 return
  88.             end
  89.         end
  90.         MsgN('ClanSystem MySQL: Query Failed: ' .. err .. ' (' .. sql .. ')')
  91.         q:start()
  92.     end
  93.     q:start()  
  94. end
  95. return members
  96. end
  97.  
  98. function CLANS:GetMembersRank(members)
  99.        for k, v in pairs(members) do
  100.        local id = util.SteamIDFrom64( v[2] )
  101.         local qs = [[
  102.     SELECT *
  103.     FROM `users`
  104.     WHERE steamid = '%s'
  105.     ]]
  106.     qs = string.format(qs, id)
  107.     local q = db:query(qs)
  108.     function q:onSuccess(data)
  109.    
  110.         local i = 1
  111.         local group = "User"
  112.         v[7] = group
  113.         while #data >= i do
  114.         local row = data[i]
  115.           v[7] = row.group
  116.           i = i + 1
  117.         end
  118.         print("FUNCTION FERTIG")
  119.         PrintTable(members)
  120.     end
  121.      
  122.     function q:onError(err, sql)
  123.         if db:status() ~= mysqloo.DATABASE_CONNECTED then
  124.             db:connect()
  125.             db:wait()
  126.             if db:status() ~= mysqloo.DATABASE_CONNECTED then
  127.                 ErrorNoHalt("Re-connection to database server failed.")
  128.                 return
  129.             end
  130.         end
  131.         MsgN('ClanSystem MySQL: Query Failed: ' .. err .. ' (' .. sql .. ')')
  132.         q:start()
  133.     end
  134.     q:start()  
  135. end
  136. return members
  137. end
  138.  
  139. function CLANS:GetClanMembers(id)
  140.     local qs = [[
  141.     SELECT *
  142.     FROM `clansystem_players`
  143.     WHERE clanid = '%s'
  144.     ]]
  145.     qs = string.format(qs, id)
  146.     local q = db:query(qs)
  147.    
  148.     members = {}
  149.    
  150.     function q:onSuccess(data)
  151.    
  152.         local i = 1
  153.         while #data >= i do
  154.         local row = data[i]
  155.           local pl = {}
  156.           table.insert(pl,row.clanid)
  157.           table.insert(pl,row.steamid)
  158.           table.insert(pl,row.name)
  159.           table.insert(pl,row.kills)
  160.           table.insert(pl,row.deaths)
  161.           table.insert(members,pl)
  162.           i = i + 1
  163.         end
  164.         print("FUNCTION FERTIG")
  165.         PrintTable(members)
  166.         return members 
  167.     end
  168.      
  169.     function q:onError(err, sql)
  170.         if db:status() ~= mysqloo.DATABASE_CONNECTED then
  171.             db:connect()
  172.             db:wait()
  173.             if db:status() ~= mysqloo.DATABASE_CONNECTED then
  174.                 ErrorNoHalt("Re-connection to database server failed.")
  175.                 return
  176.             end
  177.         end
  178.         MsgN('ClanSystem MySQL: Query Failed: ' .. err .. ' (' .. sql .. ')')
  179.         q:start()
  180.     end
  181.     q:start()
  182. return members 
  183. end
  184.  
  185. function CLANS:UpdateClansMemberAmount(oldid,amount)
  186.     local member
  187.     member = 0
  188.     local qs = [[
  189.     SELECT *
  190.     FROM `clansystem_clans`
  191.     WHERE id = '%s'
  192.     ]]
  193.     qs = string.format(qs, oldid)
  194.     local q = db:query(qs)
  195.      
  196.     function q:onSuccess(data)
  197.         if #data > 0 then
  198.             local row = data[1]
  199.             member = row.member
  200.         end
  201.     end
  202.      
  203.     function q:onError(err, sql)
  204.         if db:status() ~= mysqloo.DATABASE_CONNECTED then
  205.             db:connect()
  206.             db:wait()
  207.         if db:status() ~= mysqloo.DATABASE_CONNECTED then
  208.             ErrorNoHalt("Re-connection to database server failed.")
  209.             return
  210.             end
  211.         end
  212.         MsgN('ClanSystem MySQL: Query Failed: ' .. err .. ' (' .. sql .. ')')
  213.         q:start()
  214.     end
  215.     q:start()
  216. --
  217.  local qs = [[
  218.   INSERT INTO `clansystem_clans` (id, member)
  219.   VALUES ('%s', '%s')
  220.   ON DUPLICATE KEY UPDATE
  221.     member = VALUES(member)
  222.   ]]
  223.   qs = string.format(qs, oldid, member + amount)
  224.   local q = db:query(qs)
  225.  
  226.   function q:onSuccess()
  227.         print("Members from Clan: "..oldid .. " Changed To: "..member + amount)
  228.   end
  229.  
  230.   function q:onError(err, sql)
  231.     if db:status() ~= mysqloo.DATABASE_CONNECTED then
  232.       db:connect()
  233.       db:wait()
  234.       if db:status() ~= mysqloo.DATABASE_CONNECTED then
  235.         error("Database server has gone away.")
  236.         return
  237.       end
  238.     end
  239.     MsgN('ClanSystem MySQL: Query Failed: ' .. err .. ' (' .. sql .. ')')
  240.     q:start()
  241.   end
  242.   q:start()
  243.  
  244. end
  245. ----------------------
  246. function CLANS:kickPlayerFromClanID(ply)
  247.   local qs = [[
  248.   INSERT INTO `clansystem_players` (steamid, clanid)
  249.   VALUES ('%s', '%s')
  250.   ON DUPLICATE KEY UPDATE
  251.     clanid = VALUES(clanid)
  252.   ]]
  253.   qs = string.format(qs, ply:SteamID64(),0)
  254.   local q = db:query(qs)
  255.  
  256.   function q:onSuccess()
  257.     local oldid = ply:GetNWInt("CLANSYSTEM_CLANID")
  258.     CLANS:SetClanID(ply,0)
  259.     if(oldid == 0 or oldid=="0")then
  260.         return
  261.     else
  262.         CLANS:UpdateClansMemberAmount(oldid,-1)
  263.     end
  264.   end
  265.  
  266.   function q:onError(err, sql)
  267.     if db:status() ~= mysqloo.DATABASE_CONNECTED then
  268.       db:connect()
  269.       db:wait()
  270.       if db:status() ~= mysqloo.DATABASE_CONNECTED then
  271.         error("Database server has gone away.")
  272.         return
  273.       end
  274.     end
  275.     MsgN('ClanSystem MySQL: Query Failed: ' .. err .. ' (' .. sql .. ')')
  276.     q:start()
  277.   end
  278.   q:start()
  279. end
  280.  
  281. function CLANS:AddNewClan(clan_name, kuerzel, leader)
  282.     -- Start Setting to Database
  283.     local qs = [[
  284.   INSERT INTO `clansystem_clans` (clan_name, kuerzel, leader_steamid)
  285.   VALUES ('%s', '%s', '%s')
  286.   ]]
  287.   qs = string.format(qs, clan_name, kuerzel, leader:SteamID64() )
  288.   local q = db:query(qs)
  289.    
  290.    function q:onSuccess()
  291.     CLANS:SetLeaderIntoOwnClan(leader)
  292.     net.Start("Clan_Create_Successfull")
  293.     net.Send(leader)
  294.    end
  295.  
  296.   function q:onError(err, sql)
  297.     if db:status() ~= mysqloo.DATABASE_CONNECTED then
  298.       db:connect()
  299.       db:wait()
  300.       if db:status() ~= mysqloo.DATABASE_CONNECTED then
  301.         error("Database server has gone away.")
  302.         return
  303.       end
  304.     end
  305.     MsgN('ClanSystem MySQL: Query Failed: ' .. err .. ' (' .. sql .. ')')
  306.     q:start()
  307.     end
  308. q:start()
  309. end
  310.  
  311. function CLANS:SetLeaderIntoOwnClan(leader)
  312. local qs = [[
  313.    INSERT INTO `clansystem_players` (steamid, clanid)
  314.    VALUES ('%s', LAST_INSERT_ID())
  315.    ON DUPLICATE KEY UPDATE
  316.    clanid = VALUES(clanid)
  317.     ]]
  318.     qs = string.format(qs, leader:SteamID64())
  319.     local q = db:query(qs)
  320.      
  321.     function q:onSuccess(data)
  322.         CLANS:ForceUpdate(leader)
  323.  
  324.         CLANS:Remove1Slot(leader:GetNWInt("CLANSYSTEM_CLANID"),leader:GetNWInt("CLANSYSTEM_MEMBER",-10))
  325.         --[[if #data > 0 then
  326.             local row = data[1]
  327.             clanid = row.id
  328.             CLANS:SetClanID(leader,clanid)
  329.         end]]
  330.     end
  331.      
  332.     function q:onError(err, sql)
  333.         if db:status() ~= mysqloo.DATABASE_CONNECTED then
  334.             db:connect()
  335.             db:wait()
  336.         if db:status() ~= mysqloo.DATABASE_CONNECTED then
  337.             ErrorNoHalt("Re-connection to database server failed.")
  338.             return
  339.             end
  340.         end
  341.         MsgN('ClanSystem MySQL: Query Failed: ' .. err .. ' (' .. sql .. ')')
  342.         q:start()
  343.     end
  344.     q:start()
  345.  
  346. end
  347. ---------------
  348. function CLANS:GetPlayersClanInfo(ids)
  349.     local players = {}
  350.     for v, k in pairs(ids) do
  351.     local clanPlayer = player.GetByID(k)
  352.     local qs = [[
  353.     SELECT *
  354.     FROM `clansystem_players`
  355.     WHERE steamid = '%s'
  356.     ]]
  357.     qs = string.format(qs, clanPlayer:SteamID64())
  358.     local q = db:query(qs)
  359.    
  360.     function q:onSuccess(data)
  361.    
  362.         local i = 1
  363.         while #data >= i do
  364.         local row = data[i]
  365.           local pl = {}
  366.           table.insert(pl,row.clanid)
  367.           table.insert(pl,row.steamid)
  368.           table.insert(pl,row.name)
  369.           table.insert(pl,row.kills)
  370.           table.insert(pl,row.deaths)
  371.           table.insert(players,pl)
  372.           i = i + 1
  373.         end
  374.         return players 
  375.     end
  376.      
  377.     function q:onError(err, sql)
  378.         if db:status() ~= mysqloo.DATABASE_CONNECTED then
  379.             db:connect()
  380.             db:wait()
  381.             if db:status() ~= mysqloo.DATABASE_CONNECTED then
  382.                 ErrorNoHalt("Re-connection to database server failed.")
  383.                 return
  384.             end
  385.         end
  386.         MsgN('ClanSystem MySQL: Query Failed: ' .. err .. ' (' .. sql .. ')')
  387.         q:start()
  388.     end
  389.     q:start()
  390.     end
  391. return players 
  392. end
  393.  
  394. function CLANS:GetClanIdByPlayer(id)
  395.  
  396.  local qs = [[
  397.     SELECT *
  398.     FROM `clansystem_players`
  399.     WHERE steamid = '%s'
  400.     ]]
  401.     qs = string.format(qs, id)
  402.     local q = db:query(qs)
  403.    
  404.     function q:onSuccess(data)
  405.         local i = 1
  406.             while #data >= i do
  407.             local row = data[i]
  408.             local pl = {}
  409.             clanid=row.clanid
  410.             i = i + 1
  411.         end
  412.         return clanid  
  413.     end
  414.      
  415.     function q:onError(err, sql)
  416.         if db:status() ~= mysqloo.DATABASE_CONNECTED then
  417.             db:connect()
  418.             db:wait()
  419.             if db:status() ~= mysqloo.DATABASE_CONNECTED then
  420.                 ErrorNoHalt("Re-connection to database server failed.")
  421.                 return
  422.             end
  423.         end
  424.         MsgN('ClanSystem MySQL: Query Failed: ' .. err .. ' (' .. sql .. ')')
  425.         q:start()
  426.     end
  427.     q:start()
  428. return clanid  
  429. end
  430.  
  431. function CLANS:ClanCreateDB(name,kurzel,ply)
  432. local ClanKuerzelValid
  433. local ClanNameValid
  434.  local qs = [[
  435.     SELECT *
  436.     FROM `clansystem_clans`
  437.     WHERE clan_name = '%s'
  438.     ]]
  439.     qs = string.format(qs, name)
  440.     local q = db:query(qs)
  441.    
  442.     function q:onSuccess(data)
  443.         local clanid
  444.         if #data > 0 then
  445.               local row = data[1]
  446.               clanid = row.id
  447.             end
  448.         if(clanid or clanid != nil)then
  449.             net.Start("clan_create_name_used")
  450.             net.WriteString(name)
  451.             net.Send(ply)
  452.             else
  453.             ClanNameValid = true
  454.         end
  455.     end
  456.      
  457.     function q:onError(err, sql)
  458.         if db:status() ~= mysqloo.DATABASE_CONNECTED then
  459.             db:connect()
  460.             db:wait()
  461.             if db:status() ~= mysqloo.DATABASE_CONNECTED then
  462.                 ErrorNoHalt("Re-connection to database server failed.")
  463.                 return
  464.             end
  465.         end
  466.         MsgN('ClanSystem MySQL: Query Failed: ' .. err .. ' (' .. sql .. ')')
  467.         q:start()
  468.     end
  469.     q:start()
  470. --
  471.  local qs = [[
  472.     SELECT *
  473.     FROM `clansystem_clans`
  474.     WHERE kuerzel = '%s'
  475.     ]]
  476.     qs = string.format(qs, kurzel)
  477.     local q = db:query(qs)
  478.    
  479.     function q:onSuccess(data)
  480.         local clanid
  481.         if #data > 0 then
  482.               local row = data[1]
  483.               clanid = row.id
  484.             end
  485.         if(clanid or clanid != nil)then
  486.             net.Start("clan_create_kuerzel_used")
  487.             net.WriteString(kurzel)
  488.             net.Send(ply)
  489.             else
  490.             ClanKuerzelValid = true
  491.             end
  492.     end
  493.      
  494.     function q:onError(err, sql)
  495.         if db:status() ~= mysqloo.DATABASE_CONNECTED then
  496.             db:connect()
  497.             db:wait()
  498.             if db:status() ~= mysqloo.DATABASE_CONNECTED then
  499.                 ErrorNoHalt("Re-connection to database server failed.")
  500.                 return
  501.             end
  502.         end
  503.         MsgN('ClanSystem MySQL: Query Failed: ' .. err .. ' (' .. sql .. ')')
  504.         q:start()
  505.     end
  506.     q:start()
  507.     --
  508.     if ply:GetNWInt("CLANSYSTEM_CLANID",0) == "0" then
  509.         timer.Simple(1,function()
  510.         if ClanNameValid == true and ClanKuerzelValid == true then
  511.         CLANS:AddNewClan(name,kurzel,ply)
  512.         end
  513.         end)
  514.     end
  515. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top