richardtanner

sv_funcs

Aug 5th, 2015
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.40 KB | None | 0 0
  1. Galileo = Galileo or {} -- Fuck autorefresh yeaaah D:
  2.  
  3. util.AddNetworkString("cl_sendGalileoRequest")
  4.  
  5. function game.GetIP()
  6.  
  7.     local hostip = GetConVarString( "hostip" ) -- GetConVarNumber is inaccurate
  8.     hostip = tonumber( hostip )
  9.  
  10.     local ip = {}
  11.     ip[ 1 ] = bit.rshift( bit.band( hostip, 0xFF000000 ), 24 )
  12.     ip[ 2 ] = bit.rshift( bit.band( hostip, 0x00FF0000 ), 16 )
  13.     ip[ 3 ] = bit.rshift( bit.band( hostip, 0x0000FF00 ), 8 )
  14.     ip[ 4 ] = bit.band( hostip, 0x000000FF )
  15.  
  16.     return table.concat( ip, "." )
  17. end
  18.  
  19. -- Start Rank Check
  20. function Galileo:SetRank(ply, rank)
  21.     if !ply:IsValid() then return end
  22.  
  23.     if ply:GetUserGroup() == rank then return end -- No need to check if the ranks are the same!
  24.  
  25.     PrintMessage(HUD_PRINTTALK, "[Galileo] Rank Mismatch for "..ply:Nick().."! Resetting...")
  26.     if ULib then
  27.        
  28.         ulx.adduserid(Entity(0), ply:SteamID(), rank)
  29.  
  30.     elseif moderator then
  31.        
  32.         moderator:SetGroup( rank )
  33.  
  34.     elseif evolve then
  35.        
  36.         ply:EV_SetRank( rank )
  37.  
  38.     end
  39.     hook.Call( "Galileo_SetRank", nil, ply, rank ) -- Fallback incase they use some other admin mod.
  40. end
  41.  
  42. function Galileo:CheckRank(ply)
  43.     if ply:IsBot() then return end
  44.     if !IsValid(ply) then return end
  45.    
  46.     local query = "SELECT rank FROM `galileo_players` WHERE `steam`='" .. Galileo:escape( ply:SteamID() ) .. "';"
  47.     Galileo:RunPreparedQuery({ sql = query,
  48.     callback = function( data )
  49.             if data[1] then
  50.             data = data[1]
  51.                 local rank = data[1]
  52.  
  53.                 Galileo:SetRank(ply, rank)
  54.         end
  55.         local DateTime = tostring( os.date("%Y-%m-%d %H:%M:%S", os.time() ) )
  56.         local user_ip = string.sub( ply:IPAddress(), 1, string.find( ply:IPAddress(), ":" ) - 1 )
  57.         local query = "INSERT INTO `galileo_players`( `steam`, `playerName`, `rank`, `connections`, `last_connection`, `user_ip` ) VALUES('"..Galileo:escape( ply:SteamID() ).."', '"..Galileo:escape( ply:Nick() ).."', 'user', '1', '"..Galileo:escape( DateTime ).."', '"..Galileo:escape( user_ip ).."') ON DUPLICATE KEY UPDATE `connections` = connections+1, last_connection = '"..Galileo:escape(DateTime ).."', `playerName` = '"..Galileo:escape( ply:Nick() ).."', `user_ip` = '"..Galileo:escape( user_ip ).."';"
  58.                
  59.         Galileo:QuickQuery(query)
  60.     end })
  61.  
  62. end
  63. hook.Add("PlayerSpawn", "Galileo:CheckRank", function(ply) if IsValid(ply) then Galileo:CheckRank(ply) end end)
  64. -- End Rank Checks
  65.  
  66. -- Start Requests
  67.  
  68. function Galileo:RecieveRequest(ply, message)
  69.     if !ply:IsValid() then return end
  70.     if message and message == "" or !message then return end
  71.  
  72.     local DateTime = tostring( os.date("%Y-%m-%d %H:%M:%S", os.time() ) )
  73.     local user_ip = string.sub( ply:IPAddress(), 1, string.find( ply:IPAddress(), ":" ) - 1 )
  74.     local query = "INSERT INTO `galileo_requests`(`name`, `steam`, `user_ip` `message`, `datetime`) VALUES('"..ply:Nick().."', '"..ply:SteamID().."', '"..user_ip.."', \"'"..message.."'\", '"..DateTime.."')"
  75.     Galileo:QuickQuery(query)
  76. end
  77. net.Receive("cl_sendGalileoRequest", function(len, ply) if net.ReadString() != "" then Galileo:RecieveRequest( ply, net.ReadString() ) end end)
  78.  
  79. -- End Requests
  80.  
  81. -- Start Server Check
  82. function Galileo:CheckServer()
  83.  
  84.     local query = "SELECT * FROM `galileo_servers` WHERE `server_ip`='" .. game.GetIP() .. "' AND `server_port` ='"..GetConVarNumber("hostport").."';"
  85.     Galileo:RunPreparedQuery({ sql = query,
  86.     callback = function( data )
  87.             if !data[1] then
  88.                 local query = "INSERT INTO `galileo_servers`(`server_name`, `server_ip`, `server_port`) VALUES('"..GetConVarString("hostname").."', '"..game.GetIP().."', '"..GetConVarNumber("hostport").."');"
  89.                 Galileo:QuickQuery(query)          
  90.             end
  91.     end })
  92.  
  93. end
  94. hook.Add("Galileo_DatabaseConnected", "Galileo:CheckServer", Galileo.CheckServer)
  95. -- End Server Check
  96.  
  97.    -- Check Banned User
  98.    function Galileo:CheckBan( ply, stid, unid )
  99.         if !ply:IsValid() then return end
  100.         local kicked = false
  101.         local query = "SELECT reason, expire FROM `galileo_players_bans` WHERE `steam`='" .. Galileo:escape( ply:SteamID() ) .. "' AND (`expire`>NOW() OR `expire` = '0000-00-00 00:00:00') ;"
  102.         Galileo:RunPreparedQuery({ sql = query,
  103.         callback = function( data )
  104.                 if data[1] then
  105.                     data = data[1]
  106.                     local reason = data[1]
  107.                     local expire = data[2]
  108.                     ply:Kick( "You are banned! Reason: "..reason.." Expires: " ..expire.."" )
  109.                     Msg("[Galileo] Kicking "..ply:Name().." ("..stid.." - "..unid..") [BANNED]\n")
  110.             RunConsoleCommand("ulx", "csay", "[Galileo] Connection attempt from banned player " .. ply:Name())
  111.             Galileo.Notify(ply, 1, true, {text = "Connection attempt by banned player " .. ply:Name()})
  112.                     kicked = true
  113.                 end
  114.         end })
  115.         if kicked then return false end -- Stop other hooks running after this, because they'll most probably error.
  116.     end
  117.     hook.Add("PlayerAuthed", "CheckGalileoBan", function(ply, stid, unid) Galileo:CheckBan(ply, stid, unid) end)
  118.     -- End Check Banned User
  119.  
  120. hook.Add("PlayerSay","Galileo.Request",function(ply, text)
  121.     local text = string.lower(text);
  122.     if text == "request" or text == "!request" or text == "calladmin" or text == "!calladmin" then
  123.         ply:ConCommand("galileo_request")
  124.         return false;
  125.     end
  126. end)
  127.  
  128. concommand.Add("galileo_notification", function( ply, cmd, args )
  129.     //if IsValid(ply) then return end
  130.    
  131.     local NotificationText = args[1]
  132.     Galileo.Notify(ply, 1, true, {text = NotificationText})
  133.  
  134. end)
Advertisement
Add Comment
Please, Sign In to add comment