Skip to content

Commit

Permalink
Permissions & "remember my choice"
Browse files Browse the repository at this point in the history
  • Loading branch information
robotboy655 committed Jun 9, 2021
1 parent 43341ae commit 87e75a6
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 8 deletions.
58 changes: 51 additions & 7 deletions garrysmod/lua/menu/openurl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ local PANEL_Browser = {}
PANEL_Browser.Base = "DFrame"

function PANEL_Browser:Init()

self.HTML = vgui.Create( "HTML", self )

if ( !self.HTML ) then
Expand All @@ -20,10 +21,13 @@ function PANEL_Browser:Init()
self:SetSizable( true )
self:Center()
self:MakePopup()

end

function PANEL_Browser:SetURL( url )

self.HTML:OpenURL( url )

end

-- Called from the engine
Expand Down Expand Up @@ -92,6 +96,12 @@ function PANEL:Init()
self.Yes:DockMargin( 0, 0, 5, 0 )
self.Yes:Dock( RIGHT )

self.YesPerma = vgui.Create( "DCheckBoxLabel", self.Buttons )
self.YesPerma:SetText( "#openurl.yes_remember" )
self.YesPerma:DockMargin( 0, 0, 5, 0 )
self.YesPerma:Dock( RIGHT )
self.YesPerma:SetVisible( false )

self:SetSize( 680, 104 )
self:Center()
self:MakePopup()
Expand All @@ -104,13 +114,14 @@ function PANEL:Init()
end

function PANEL:LoadServerInfo()

self.CustomPanel:SetVisible( true )
self.CustomPanel:SetText( "Loading server info..." )
self.CustomPanel:SizeToContents()

serverlist.PingServer( self:GetURL(), function( ping, name, desc, map, players, maxplayers, bot, pass, lp, ip, gamemode )
if ( !IsValid( self ) ) then return end

if ( !ping ) then
self.CustomPanel.Color = Color( 200, 50, 50 )
self.CustomPanel:SetText( "#askconnect.no_response" )
Expand All @@ -119,9 +130,11 @@ function PANEL:LoadServerInfo()
end
self.CustomPanel:SizeToContents()
end )

end

function PANEL:AlwaysThink()

-- Ping the server for details
if ( SysTime() - self.StartTime > 0.1 && self.Type == "askconnect" && !self.CustomPanel:IsVisible() ) then
self:LoadServerInfo()
Expand All @@ -134,59 +147,85 @@ function PANEL:AlwaysThink()
if ( !self.Yes:IsEnabled() ) then
self.Yes:SetEnabled( true )
end

if ( !gui.IsGameUIVisible() ) then
self:Remove()
end

end

function PANEL:PerformLayout( w, h )

DFrame.PerformLayout( self, w, h )

self:SizeToChildren( false, true )

end

function PANEL:SetURL( url )

self.URL:SetText( url )

self.StartTime = SysTime()
self.Yes:SetEnabled( false )
self.CustomPanel:SetVisible( false )
self.CustomPanel.Color = Color( 0, 0, 0, 0 )
self:InvalidateLayout()

end

function PANEL:GetURL()

return self.URL:GetText()

end

function PANEL:DoNope()

self:Remove()
gui.HideGameUI()

end

function PANEL:DoYes()

if ( self.StartTime + 1 > SysTime() ) then
return
end

self:DoYesAction()
local saveYes = self.YesPerma:GetChecked()
self:DoYesAction( !saveYes )
self:Remove()
gui.HideGameUI()

end

function PANEL:DoYesAction()
function PANEL:DoYesAction( bSessionOnly )

if ( self.Type == "openurl" ) then
gui.OpenURL( self.URL:GetText() )
elseif ( self.Type == "askconnect" ) then
JoinServer( self.URL:GetText() )
permissions.Grant( "connect", bSessionOnly )
permissions.Connect( self.URL:GetText() )
elseif ( self.Type == "permission" ) then
permissions.Grant( self.URL:GetText(), bSessionOnly )
else
ErrorNoHaltWithStack( "Unhandled confirmation type '" .. tostring( self.Type ) .. "'!" )
end

end

function PANEL:SetType( t )

self.Type = t

self:SetTitle( "#" .. t .. ".title" )
self.Garble:SetText( "#" .. t .. ".text" )

if ( self.Type == "permission" || self.Type == "askconnect" ) then
self.YesPerma:SetVisible( true )
end

end

local PanelInst = nil
Expand All @@ -210,12 +249,17 @@ function RequestOpenURL( url )
OpenConfirmationDialog( url, "openurl" )

end

-- Called from the engine
function RequestConnectToServer( serverip )

OpenConfirmationDialog( serverip, "askconnect" )
if ( permissions.IsGranted( "connect" ) ) then
permissions.Connect( serverip )
else
OpenConfirmationDialog( serverip, "askconnect" )
end

end
function RequestPermission( perm )

-- OpenConfirmationDialog( perm, "permission" )

end
3 changes: 2 additions & 1 deletion garrysmod/resource/localization/en/main_menu.properties
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ problem.voice_fadeouttime=Your 'voice_fadeouttime' setting is set to a non stand
problem.cl_speeds=Your 'cl_forwardspeed', 'cl_sidespeed' or 'cl_backspeed' settings are misconfigured, which may negatively impact your player movement or the Drive option in Sandbox.
problem.screen_res=Looks like your screen resolution is below recommended size. You may want to select correct screen resolution for your monitor in the video options for a better experience.
problem.mat_dxlevel=Your DirectX level is set to an unsupported value '%i'. This may cause instability and severe graphical issues.
problem.missing_addon_file=Looks like one or more addons failed to download. Please make sure you have enough disk space and veirfy integrity of game files of Garry's Mod through Steam to fix the issue.
problem.missing_addon_file=Looks like one or more addons failed to download. Please make sure you have enough disk space and verify integrity of game files of Garry's Mod through Steam to fix the issue.
problem.menu_cleanupgmas=We have found some unused addon files. It is recommended to delete them to save disk space.
problem.gmod_mcore_test=Note: Multicore rendering is enabled. This feature is work in progress and may cause stability issues. This feature is automatically enabled on any beta branch.
Expand Down Expand Up @@ -415,6 +415,7 @@ askconnect.text=The server you are playing on has requested you to connect to th
openurl.title=Do you want to open this website?
openurl.text=You should only open websites that you recognize and trust.
openurl.yes=Yes
openurl.yes_remember=Don't ask again for this server
openurl.nope=Nope
openurl.disconnect=Disconnect

Expand Down

0 comments on commit 87e75a6

Please sign in to comment.