Advertisement
Guest User

Untitled

a guest
May 27th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.63 KB | None | 0 0
  1. /*-------------------------------------------------------------------------------------------------------------------------
  2.     Define Plugin
  3. -------------------------------------------------------------------------------------------------------------------------*/
  4. local Plugin = {}
  5.  
  6. function Plugin:Load()
  7.     Msg("Ban System Loaded\n")
  8. end
  9.  
  10. require("gatekeeper")
  11. require( "mysql" )
  12.  
  13. local host = "localhost"
  14. local username = "skillgam"
  15. local password = "skillgam1"
  16. local db = "skillgam_smf1"
  17.  
  18. function StripForHTTP ( Name, Stop )
  19.     if !Name then return "NA"; end
  20.  
  21.     Name = mysql.escape(db, Name);
  22.    
  23.     return tostring(Name);
  24. end
  25. /*-------------------------------------------------------------------------------------------------------------------------
  26.     SERVER
  27. -------------------------------------------------------------------------------------------------------------------------*/
  28. function Plugin:Server()
  29. /*-------------------------------------------------------------------------------------------------------------------------
  30.     BAN SID
  31. -------------------------------------------------------------------------------------------------------------------------*/
  32.     function self.BanSID(sid,time,reason,steam,banner)     
  33.         function ASS_ShortBan (sid,time,reason,steam,banner)
  34.        
  35.             local db, error = mysql.connect(host, username, password, db)
  36.        
  37.             if time >= (60 * 24) then
  38.                 local Res = mysql.query(db, "UPDATE `smf_members` SET `num_bans`=`num_bans`+1 WHERE `steamid`='" .. sid:SteamID() .. "'");
  39.        
  40.                     local numbans = mysql.query(db, "SELECT `num_bans` FROM `smf_members` WHERE `steamid`='" .. sid:SteamID() .. "'");
  41.                     ShortBanContinued(sid,time,reason,steam,banner,numbans);
  42.             end
  43.    
  44.             ShortBanContinued(sid,time,reason,steam,banner);
  45.         end
  46.        
  47.         function ShortBanContinued (sid,time,reason,steam,banner,Res )
  48.            
  49.             local db, error = mysql.connect(host, username, password, db)
  50.            
  51.             if !IsValid(sid) then return false; end
  52.  
  53.             local SendTime = 0;
  54.    
  55.             if time == 0 then
  56.                 SendTime = 0;
  57.             else
  58.                 SendTime = os.time() + (time * 60)
  59.             end
  60.        
  61.             if Res and Res[1] and Res[1][1] and tonumber(Res[1][1]) >= 5 then
  62.                 SendTime = 0;
  63.             end
  64.            
  65.             local BannerID = banner:SteamID() or "AUTOBOT";
  66.        
  67.             mysql.query(db, "INSERT INTO `bans` (`ID`, `NAME`, `UNBAN`, `BANNER`, `REASON`, `BANNER_STEAMID`) VALUES ('" .. StripForHTTP(sid:SteamID()) .. "', '" .. StripForHTTP(sid:Nick()) .. "', '" .. StripForHTTP(SendTime)) .. "', '" .. StripForHTTP(banner) .. "', '" .. StripForHTTP(reason) .. "', '" .. BannerID .. "')");
  68.                
  69.             sid:Kick(REASON);
  70.                    
  71.             local TimeLeft = (time * 60);
  72.                    
  73.             local Minutes = math.floor(TimeLeft / 60);
  74.             local Minutes2 = math.floor(TimeLeft / 60);
  75.             local Seconds = TimeLeft - (Minutes * 60);
  76.             local Hours = math.floor(Minutes / 60);
  77.             local Minutes = Minutes - (Hours * 60);
  78.             local Days = math.floor(Hours / 24);
  79.             local Hours = Hours - (Days * 24);
  80.                    
  81.             local ToDoTime = 0;
  82.             local ToDoWord = "Error";
  83.             if TimeLeft == 0 then
  84.                 ToDoWord = "Perma";
  85.             elseif Minutes == 0 and Seconds != 0 then
  86.                 ToDoTime = Seconds;
  87.                 ToDoWord = "Seconds";
  88.             elseif Hours == 0 and Minutes != 0 then
  89.                 ToDoTime = Minutes;
  90.                 ToDoWord = "Minutes";
  91.             elseif Days == 0 and Hours != 0 then
  92.                 ToDoTime = Hours;
  93.                 ToDoWord = "Hours";
  94.             else
  95.                 ToDoTime = Days;
  96.                 ToDoWord = "Days";
  97.             end
  98.            
  99.             //if nomessage then return false; end
  100.            
  101.             if ToDoWord == "Perma" then        
  102.                 for k, v in pairs(player.GetAll()) do
  103.                     v:PrintMessage(HUD_PRINTTALK, sid:Nick() .. " has been banned permanently.");
  104.                     v:PrintMessage(HUD_PRINTTALK, "Reason: " .. reason .. ".");
  105.                 end
  106.             else
  107.                 for k, v in pairs(player.GetAll()) do
  108.                     v:PrintMessage(HUD_PRINTTALK, sid:Nick() .. " has been banned for " .. ToDoTime .. " " .. ToDoWord .. ".");
  109.                     v:PrintMessage(HUD_PRINTTALK, "Reason: " .. reason .. ".");
  110.                 end
  111.             end
  112.         end
  113.     end
  114.    
  115. /*-------------------------------------------------------------------------------------------------------------------------
  116.     BAN PLY
  117. -------------------------------------------------------------------------------------------------------------------------*/
  118.     function self.BanPly(ply,time,reason,banner)
  119.         self.BanSID(ply:WAMID(),time,reason,banner)
  120.         ply:SetNetworkedBool("Ignore_Disconect",true)
  121.         if ( gatekeeper ) then
  122.             gatekeeper.Drop( ply:UserID(), "Banned (" .. reason .. ")" )
  123.         else
  124.             ply:Kick( "Banned (" .. reason .. ")" )
  125.         end
  126.     end
  127.    
  128. /*-------------------------------------------------------------------------------------------------------------------------
  129.     Is ID Banned
  130. -------------------------------------------------------------------------------------------------------------------------*/
  131.     function self.IsBan(sid,steam)
  132.         if steam then
  133.             sid = string.lower(sid)
  134.             sid = string.Replace(sid,":","__")
  135.         end
  136.         if not sid then return end 
  137.    
  138.         local db, error = mysql.connect(host, username, password, db)
  139.         local CheckBans, Success, Error = mysql.query(db, "SELECT `UNBAN` FROM `bans` WHERE `ID`='" .. sid .. "'", mysql.QUERY_FIELDS);
  140.    
  141.         if !Success then
  142.             return {false, "MySQL Connection Error - Contact Administration"}
  143.         end
  144.        
  145.         if #CheckBans != 0 then
  146.             local Time = os.time();
  147.             local UnbanTime = tonumber(CheckBans[1]['UNBAN']);
  148.        
  149.             if UnbanTime == 0 then
  150.                 return {false, "You are permanently banned from all Skill Gaming servers."};
  151.             elseif UnbanTime < Time then
  152.                 mysql.query(db, "DELETE FROM `bans` WHERE `ID`='" .. sid .. "'");
  153.             elseif UnbanTime >= Time then
  154.                 local TimeLeft = UnbanTime - os.time();
  155.                 local FormattedTime = string.FormattedTime(UnbanTime - os.time());
  156.                
  157.                 local Minutes = math.floor(TimeLeft / 60);
  158.                 local Minutes2 = math.floor(TimeLeft / 60);
  159.                 local Seconds = TimeLeft - (Minutes * 60);
  160.                 local Hours = math.floor(Minutes / 60);
  161.                 local Minutes = Minutes - (Hours * 60);
  162.                 local Days = math.floor(Hours / 24);
  163.                 local Hours = Hours - (Days * 24);
  164.                
  165.                 if Minutes == 0 then
  166.                     return {false, "Banned. Lifted In: " .. Seconds + 1 .. " Seconds"};
  167.                 elseif Hours == 0 then
  168.                     return {false, "Banned. Lifted In: " .. Minutes + 1 .. " Minutes"};
  169.                 elseif Days == 0 then
  170.                     return {false, "Banned. Lifted In: " .. Hours + 1 .. " Hours"};
  171.                 else
  172.                     return {false, "Banned. Lifted In: " .. Days + 1 .. " Days"};
  173.                 end
  174.             end
  175.         end
  176.     end
  177.  
  178. /*-------------------------------------------------------------------------------------------------------------------------
  179.     UnBann
  180. -------------------------------------------------------------------------------------------------------------------------*/
  181.     function self.Unban(sid,steam)
  182.         for k, v in pairs(player.GetAll()) do
  183.             v:PrintMessage(HUD_PRINTTALK, sid:Nick() .. " cannot be unbanned!  Please use the website to unban players!");
  184.         end
  185.     end
  186.    
  187. /*-------------------------------------------------------------------------------------------------------------------------
  188.     PlayerAuthed
  189. -------------------------------------------------------------------------------------------------------------------------*/
  190.     function self:PlayerAuthed( ply, sid )
  191.         if self.IsBan(sid,true) == true then
  192.             if ( gatekeeper ) then
  193.                 gatekeeper.Drop( ply:UserID(), "Banned" )
  194.             else
  195.                 ply:Kick( "Banned" )
  196.             end
  197.             ply:SetNetworkedBool("Ignore_Disconect",true)
  198.         end
  199.     end
  200.    
  201. /*-------------------------------------------------------------------------------------------------------------------------
  202.     GateKeep Authed
  203. -------------------------------------------------------------------------------------------------------------------------*/
  204.     function self:PlayerPasswordAuth(name, pass, steam, ip)
  205.         if self.IsBan(steam,true) == true then
  206.             return "Banned"
  207.         end
  208.         return
  209.     end
  210.    
  211. /*-------------------------------------------------------------------------------------------------------------------------
  212.     Chat Command To Ban
  213. -------------------------------------------------------------------------------------------------------------------------*/
  214.     function self.CmdBan(ply,args)
  215.         if not args[1] then return end
  216.         local targ = WAM.Target(args[1],ply)[1]
  217.         if not targ or targ == ply then return "" end
  218.         if not ply:IsRank( targ:GetRank() + 1 ) == true then return "" end
  219.         local time = tonumber(args[2]) or 320
  220.         local reason = args[3] or "Banned By: " .. ply:Name()
  221.         self.BanPly(targ,time,reason,ply)
  222.     end
  223.     WAM.ChatAdd("!ban",self.CmdBan,4,"ban")
  224.    
  225.    
  226. /*-------------------------------------------------------------------------------------------------------------------------
  227.     Ban Steam
  228. -------------------------------------------------------------------------------------------------------------------------*/
  229.     function self.CmdBan(ply,args)
  230.         local sid = string.lower(args[1])
  231.         if not sid then return end
  232.         if not ply:IsRank( rank + 1 ) == true then return "" end
  233.         local time = tonumber(args[2]) or 320
  234.         local reason = args[3] or "Banned By: " .. ply:Name()
  235.         self.BanSid(sid,time,reason,ply)
  236.     end
  237.     WAM.ChatAdd(nil,self.CmdBan,4,"ban_sid")
  238.  
  239. /*-------------------------------------------------------------------------------------------------------------------------
  240.     Ban Steam
  241. -------------------------------------------------------------------------------------------------------------------------*/
  242.     function self.CmdUnBan(ply,args)
  243.  
  244.         ply:AddChat("[SYSTEM] ",sid," cannot be unbanned!  Please use the website to unban players!")
  245.     end
  246.     WAM.ChatAdd(nil,self.CmdUnBan,4,"unban_sid")
  247.    
  248.    
  249. /*-------------------------------------------------------------------------------------------------------------------------
  250.     TIME -- Thanks to Divran
  251. -------------------------------------------------------------------------------------------------------------------------*/
  252.     function WAM.TimeExpired(when)
  253.         return when < os.time()
  254.     end
  255.  
  256.     function WAM.TimeAdd( mins )
  257.         return os.time() + mins
  258.     end
  259.    
  260. end
  261.  
  262.  
  263. function Plugin:Client()
  264. /*-------------------------------------------------------------------------------------------------------------------------
  265.     Ban time Menu
  266. -------------------------------------------------------------------------------------------------------------------------*/
  267.     function WAM.Ban_Show(ply,Reason)
  268.         if not ply or not ply:IsValid() or not ply:IsPlayer() then return end
  269.         local width = surface.ScreenWidth()
  270.         local height = surface.ScreenHeight()
  271.        
  272.         local BP = vgui.Create("WolfFrame")
  273.         BP:SetPos((width / 2) - 100, (height / 2) - 50)
  274.         BP:SetSize(170,100)
  275.         BP:SetTitle("Wolf Ban Time:")
  276.         BP:SetDraggable(true)
  277.         BP:SetSizable(false)
  278.         BP:ShowCloseButton(true)
  279.         BP:SetDeleteOnClose(true)
  280.         BP:SetMouseInputEnabled( true )
  281.        
  282.         local HourL = vgui.Create( "DLabel", BP )
  283.         HourL:SetPos( 5,30 )
  284.         HourL:SetSize( 50,20 )
  285.         HourL:SetText("Hour:")
  286.        
  287.         local Hour = vgui.Create( "DNumberWang", BP )
  288.         Hour:SetPos( 5,50 )
  289.         Hour:SetSize( 50,20 )
  290.        
  291.         local MinL = vgui.Create( "DLabel", BP )
  292.         MinL:SetPos( 60,30 )
  293.         MinL:SetSize( 50,20 )
  294.         MinL:SetText("Min:")
  295.        
  296.         local Min = vgui.Create( "DNumberWang", BP )
  297.         Min:SetPos( 60,50 )
  298.         Min:SetSize( 50,20 )
  299.        
  300.         local SecL = vgui.Create( "DLabel", BP )
  301.         SecL:SetPos( 115,30 )
  302.         SecL:SetSize( 50,20 )
  303.         SecL:SetText("Sec:")
  304.        
  305.         local Sec = vgui.Create( "DNumberWang", BP )
  306.         Sec:SetPos( 115,50 )
  307.         Sec:SetSize( 50,20 )
  308.        
  309.         local Ban = vgui.Create( "WolfButton", BP )
  310.         Ban:SetPos( 5,75 )
  311.         Ban:SetSize( 160,20 )
  312.         Ban:SetText("BAN")
  313.        
  314.         function Ban:DoClick()
  315.             local time = ( ( ( ( Hour:GetValue() * 60 ) + Min:GetValue() ) * 60 ) + Sec:GetValue() )
  316.             RunConsoleCommand("wam","ban",ply:WAMID(),time,Reason)
  317.             BP:Close()
  318.         end
  319.         BP:MakePopup()
  320.     end
  321.    
  322. end
  323.  
  324. WAM.RegisterPlug("Ban Core",Plugin)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement