Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Galileo = Galileo or {} -- Fuck autorefresh yeaaah D:
- util.AddNetworkString("cl_sendGalileoRequest")
- function game.GetIP()
- local hostip = GetConVarString( "hostip" ) -- GetConVarNumber is inaccurate
- hostip = tonumber( hostip )
- local ip = {}
- ip[ 1 ] = bit.rshift( bit.band( hostip, 0xFF000000 ), 24 )
- ip[ 2 ] = bit.rshift( bit.band( hostip, 0x00FF0000 ), 16 )
- ip[ 3 ] = bit.rshift( bit.band( hostip, 0x0000FF00 ), 8 )
- ip[ 4 ] = bit.band( hostip, 0x000000FF )
- return table.concat( ip, "." )
- end
- -- Start Rank Check
- function Galileo:SetRank(ply, rank)
- if !ply:IsValid() then return end
- if ply:GetUserGroup() == rank then return end -- No need to check if the ranks are the same!
- PrintMessage(HUD_PRINTTALK, "[Galileo] Rank Mismatch for "..ply:Nick().."! Resetting...")
- if ULib then
- ulx.adduserid(Entity(0), ply:SteamID(), rank)
- elseif moderator then
- moderator:SetGroup( rank )
- elseif evolve then
- ply:EV_SetRank( rank )
- end
- hook.Call( "Galileo_SetRank", nil, ply, rank ) -- Fallback incase they use some other admin mod.
- end
- function Galileo:CheckRank(ply)
- if ply:IsBot() then return end
- if !IsValid(ply) then return end
- local query = "SELECT rank FROM `galileo_players` WHERE `steam`='" .. Galileo:escape( ply:SteamID() ) .. "';"
- Galileo:RunPreparedQuery({ sql = query,
- callback = function( data )
- if data[1] then
- data = data[1]
- local rank = data[1]
- Galileo:SetRank(ply, rank)
- end
- local DateTime = tostring( os.date("%Y-%m-%d %H:%M:%S", os.time() ) )
- local user_ip = string.sub( ply:IPAddress(), 1, string.find( ply:IPAddress(), ":" ) - 1 )
- 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 ).."';"
- Galileo:QuickQuery(query)
- end })
- end
- hook.Add("PlayerSpawn", "Galileo:CheckRank", function(ply) if IsValid(ply) then Galileo:CheckRank(ply) end end)
- -- End Rank Checks
- -- Start Requests
- function Galileo:RecieveRequest(ply, message)
- if !ply:IsValid() then return end
- if message and message == "" or !message then return end
- local DateTime = tostring( os.date("%Y-%m-%d %H:%M:%S", os.time() ) )
- local user_ip = string.sub( ply:IPAddress(), 1, string.find( ply:IPAddress(), ":" ) - 1 )
- local query = "INSERT INTO `galileo_requests`(`name`, `steam`, `user_ip` `message`, `datetime`) VALUES('"..ply:Nick().."', '"..ply:SteamID().."', '"..user_ip.."', \"'"..message.."'\", '"..DateTime.."')"
- Galileo:QuickQuery(query)
- end
- net.Receive("cl_sendGalileoRequest", function(len, ply) if net.ReadString() != "" then Galileo:RecieveRequest( ply, net.ReadString() ) end end)
- -- End Requests
- -- Start Server Check
- function Galileo:CheckServer()
- local query = "SELECT * FROM `galileo_servers` WHERE `server_ip`='" .. game.GetIP() .. "' AND `server_port` ='"..GetConVarNumber("hostport").."';"
- Galileo:RunPreparedQuery({ sql = query,
- callback = function( data )
- if !data[1] then
- local query = "INSERT INTO `galileo_servers`(`server_name`, `server_ip`, `server_port`) VALUES('"..GetConVarString("hostname").."', '"..game.GetIP().."', '"..GetConVarNumber("hostport").."');"
- Galileo:QuickQuery(query)
- end
- end })
- end
- hook.Add("Galileo_DatabaseConnected", "Galileo:CheckServer", Galileo.CheckServer)
- -- End Server Check
- -- Check Banned User
- function Galileo:CheckBan( ply, stid, unid )
- if !ply:IsValid() then return end
- local kicked = false
- 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') ;"
- Galileo:RunPreparedQuery({ sql = query,
- callback = function( data )
- if data[1] then
- data = data[1]
- local reason = data[1]
- local expire = data[2]
- ply:Kick( "You are banned! Reason: "..reason.." Expires: " ..expire.."" )
- Msg("[Galileo] Kicking "..ply:Name().." ("..stid.." - "..unid..") [BANNED]\n")
- RunConsoleCommand("ulx", "csay", "[Galileo] Connection attempt from banned player " .. ply:Name())
- Galileo.Notify(ply, 1, true, {text = "Connection attempt by banned player " .. ply:Name()})
- kicked = true
- end
- end })
- if kicked then return false end -- Stop other hooks running after this, because they'll most probably error.
- end
- hook.Add("PlayerAuthed", "CheckGalileoBan", function(ply, stid, unid) Galileo:CheckBan(ply, stid, unid) end)
- -- End Check Banned User
- hook.Add("PlayerSay","Galileo.Request",function(ply, text)
- local text = string.lower(text);
- if text == "request" or text == "!request" or text == "calladmin" or text == "!calladmin" then
- ply:ConCommand("galileo_request")
- return false;
- end
- end)
- concommand.Add("galileo_notification", function( ply, cmd, args )
- //if IsValid(ply) then return end
- local NotificationText = args[1]
- Galileo.Notify(ply, 1, true, {text = NotificationText})
- end)
Advertisement
Add Comment
Please, Sign In to add comment