From 87e75a6803905bbd1189f7b6f48680dc5b3beb48 Mon Sep 17 00:00:00 2001 From: Rubat Date: Wed, 9 Jun 2021 21:00:00 +0300 Subject: [PATCH] Permissions & "remember my choice" --- garrysmod/lua/menu/openurl.lua | 58 ++++++++++++++++--- .../localization/en/main_menu.properties | 3 +- 2 files changed, 53 insertions(+), 8 deletions(-) diff --git a/garrysmod/lua/menu/openurl.lua b/garrysmod/lua/menu/openurl.lua index 9dbd459097..36ce748c49 100644 --- a/garrysmod/lua/menu/openurl.lua +++ b/garrysmod/lua/menu/openurl.lua @@ -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 @@ -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 @@ -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() @@ -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" ) @@ -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() @@ -134,18 +147,23 @@ 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() @@ -153,40 +171,61 @@ function PANEL:SetURL( url ) 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 @@ -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 diff --git a/garrysmod/resource/localization/en/main_menu.properties b/garrysmod/resource/localization/en/main_menu.properties index 4ad14d838c..b0bdd9bed0 100644 --- a/garrysmod/resource/localization/en/main_menu.properties +++ b/garrysmod/resource/localization/en/main_menu.properties @@ -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. @@ -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