From d87aab9b717c16432cab089d8cf5904180aee8a5 Mon Sep 17 00:00:00 2001 From: Thom McGrath Date: Wed, 2 Oct 2019 09:20:10 -0400 Subject: [PATCH] Deploy supports custom stop messages --- Connector/App.xojo_code | 9 +- Connector/config.json | 2 +- Project/Beacon.xojo_project | 1 + .../ConnectorDeploymentEngine.xojo_code | 14 +- .../Beacon/ConnectorServerProfile.xojo_code | 6 + .../Modules/Beacon/DeploymentEngine.xojo_code | 2 +- .../Beacon/FTPDeploymentEngine.xojo_code | 3 +- .../Beacon/NitradoDeploymentEngine.xojo_code | 9 +- .../Beacon/NitradoServerProfile.xojo_code | 6 + .../Modules/Beacon/ServerProfile.xojo_code | 6 + Project/Modules/Preferences.xojo_code | 16 ++ .../Views/DocumentDeployWindow.xojo_window | 20 +- Project/Views/StopMessageDialog.xojo_window | 257 ++++++++++++++++++ 13 files changed, 341 insertions(+), 10 deletions(-) create mode 100644 Project/Views/StopMessageDialog.xojo_window diff --git a/Connector/App.xojo_code b/Connector/App.xojo_code index 5f82c3fc8..c98968faa 100644 --- a/Connector/App.xojo_code +++ b/Connector/App.xojo_code @@ -232,6 +232,8 @@ Inherits DaemonApplication Return Nil End If + Self.Log("Command: " + Message.Value("Command")) + Select Case Message.Value("Command") Case "Start" // Starts the server @@ -243,8 +245,13 @@ Inherits DaemonApplication Return Response Case "Stop" // Stops the server + Dim Command As String = Self.StopCommand + Dim StopMessage As String = Message.Lookup("Message", "") + Command = Command.ReplaceAll("%message%", StopMessage) + Command = Command.ReplaceAll("escape(%message%)", Self.QuoteValue(StopMessage)) + Dim Sh As New Shell - Sh.Execute(Self.StopCommand) + Sh.Execute(Command) Dim Response As New Dictionary Response.Value("Success") = Sh.ExitCode = 0 diff --git a/Connector/config.json b/Connector/config.json index c0356f830..f73d4e267 100644 --- a/Connector/config.json +++ b/Connector/config.json @@ -2,7 +2,7 @@ "Encryption Key": "1da467abc289bc9d608b90c684460797", "Port": 48962, "Start Command": "say 'Starting'", - "Stop Command": "say 'Stopping'", + "Stop Command": "say 'Stopping server with message %message%'", "Status Command": "say 'Status Check'", "Config Folder": "~/Scratch/Connector Test/WindowsServer", "Logs Folder": "~/Scratch/Connector Test/Logs", diff --git a/Project/Beacon.xojo_project b/Project/Beacon.xojo_project index b42360c67..56dc6a100 100644 --- a/Project/Beacon.xojo_project +++ b/Project/Beacon.xojo_project @@ -377,6 +377,7 @@ Window=ConnectorDiscoveryView;Views/Document Import/Discovery Views/ConnectorDis Window=ConnectorServerView;Views/Config Editors/Servers Config Editor/ConnectorServerView.xojo_window;&h00000000156B4FFF;&h000000002E7F7FFF;false Class=ConnectorDeploymentEngine;Modules/Beacon/ConnectorDeploymentEngine.xojo_code;&h00000000646037FF;&h0000000055ADDFFF;false Class=LogFile;Modules/Beacon/LogFile.xojo_code;&h000000004D9167FF;&h0000000055ADDFFF;false +Window=StopMessageDialog;Views/StopMessageDialog.xojo_window;&h00000000245037FF;&h0000000008A387FF;false AppMenuBar=MainMenuBar MajorVersion=1 MinorVersion=3 diff --git a/Project/Modules/Beacon/ConnectorDeploymentEngine.xojo_code b/Project/Modules/Beacon/ConnectorDeploymentEngine.xojo_code index 74ae306a0..ba5889ee6 100644 --- a/Project/Modules/Beacon/ConnectorDeploymentEngine.xojo_code +++ b/Project/Modules/Beacon/ConnectorDeploymentEngine.xojo_code @@ -31,13 +31,14 @@ Implements Beacon.DeploymentEngine #tag EndMethod #tag Method, Flags = &h0 - Sub Begin(Label As String, Document As Beacon.Document, Identity As Beacon.Identity) + Sub Begin(Label As String, Document As Beacon.Document, Identity As Beacon.Identity, StopMessage As String) // Part of the Beacon.DeploymentEngine interface. #Pragma Unused Label Self.mDocument = Document Self.mIdentity = Identity + Self.mStopMessage = StopMessage Self.mStatus = "Connecting…" Self.AppendTask(WeakAddressOf TaskStopServer, WeakAddressOf TaskDownloadLog, WeakAddressOf TaskSetNextCommandLineParam, WeakAddressOf TaskDownloadGameUserSettings, WeakAddressOf TaskDownloadGameIni, WeakAddressOf TaskRewriteIniFiles, WeakAddressOf TaskUploadGameUserSettings, WeakAddressOf TaskUploadGameIni, WeakAddressOf TaskStartServer) @@ -116,7 +117,10 @@ Implements Beacon.DeploymentEngine End If Self.mServerWasStarted = True - Sender.SendSimpleCommand("Stop") + Dim StopCommand As New Dictionary + StopCommand.Value("Command") = "Stop" + StopCommand.Value("Message") = Self.mStopMessage + Sender.Write(StopCommand) Self.mStatus = "Stopping server…" Case "Stop" Dim Stopped As Boolean = Message.Lookup("Success", False).BooleanValue @@ -249,7 +253,7 @@ Implements Beacon.DeploymentEngine Self.mGameUserSettingsRewritten = Sender.UpdatedContent End Select - If Self.mGameIniRewritten <> "" And Self.mGameIniRewritten <> "" Then + If Self.mGameIniRewritten <> "" And Self.mGameUserSettingsRewritten <> "" Then Self.RunNextTask() End If End Sub @@ -445,6 +449,10 @@ Implements Beacon.DeploymentEngine Private mStatus As String #tag EndProperty + #tag Property, Flags = &h21 + Private mStopMessage As String + #tag EndProperty + #tag ViewBehavior #tag ViewProperty diff --git a/Project/Modules/Beacon/ConnectorServerProfile.xojo_code b/Project/Modules/Beacon/ConnectorServerProfile.xojo_code index a8ef522ea..211b17ce8 100644 --- a/Project/Modules/Beacon/ConnectorServerProfile.xojo_code +++ b/Project/Modules/Beacon/ConnectorServerProfile.xojo_code @@ -51,6 +51,12 @@ Inherits Beacon.ServerProfile End Function #tag EndMethod + #tag Method, Flags = &h0 + Function SupportsCustomStopMessage() As Boolean + Return True + End Function + #tag EndMethod + #tag Method, Flags = &h0 Function SupportsRestart() As Boolean Return True diff --git a/Project/Modules/Beacon/DeploymentEngine.xojo_code b/Project/Modules/Beacon/DeploymentEngine.xojo_code index be2965b26..3517b9596 100644 --- a/Project/Modules/Beacon/DeploymentEngine.xojo_code +++ b/Project/Modules/Beacon/DeploymentEngine.xojo_code @@ -13,7 +13,7 @@ Protected Interface DeploymentEngine #tag EndMethod #tag Method, Flags = &h0 - Sub Begin(Label As String, Document As Beacon.Document, Identity As Beacon.Identity) + Sub Begin(Label As String, Document As Beacon.Document, Identity As Beacon.Identity, StopMessage As String) End Sub #tag EndMethod diff --git a/Project/Modules/Beacon/FTPDeploymentEngine.xojo_code b/Project/Modules/Beacon/FTPDeploymentEngine.xojo_code index 1f78bfa30..75957f841 100644 --- a/Project/Modules/Beacon/FTPDeploymentEngine.xojo_code +++ b/Project/Modules/Beacon/FTPDeploymentEngine.xojo_code @@ -14,10 +14,11 @@ Implements Beacon.DeploymentEngine #tag EndMethod #tag Method, Flags = &h0 - Sub Begin(Label As String, Document As Beacon.Document, Identity As Beacon.Identity) + Sub Begin(Label As String, Document As Beacon.Document, Identity As Beacon.Identity, StopMessage As String) // Part of the Beacon.DeploymentEngine interface. #Pragma Unused Label + #Pragma Unused StopMessage Self.mIdentity = Identity Self.mDocument = Document diff --git a/Project/Modules/Beacon/NitradoDeploymentEngine.xojo_code b/Project/Modules/Beacon/NitradoDeploymentEngine.xojo_code index 8672dfc8d..3726ddf11 100644 --- a/Project/Modules/Beacon/NitradoDeploymentEngine.xojo_code +++ b/Project/Modules/Beacon/NitradoDeploymentEngine.xojo_code @@ -26,10 +26,11 @@ Implements Beacon.DeploymentEngine #tag EndMethod #tag Method, Flags = &h0 - Sub Begin(Label As String, Document As Beacon.Document, Identity As Beacon.Identity) + Sub Begin(Label As String, Document As Beacon.Document, Identity As Beacon.Identity, StopMessage As String) Self.mLabel = Label Self.mDocument = Document Self.mIdentity = Identity + Self.mStopMessage = StopMessage Self.RunNextTask() End Sub @@ -843,7 +844,7 @@ Implements Beacon.DeploymentEngine Dim FormData As New Dictionary FormData.Value("message") = "Server is being updated by Beacon (https://beaconapp.cc)" - FormData.Value("stop_message") = "Server is now stopping for a few minutes for changes." + FormData.Value("stop_message") = Self.mStopMessage SimpleHTTP.Post("https://api.nitrado.net/services/" + Self.mProfile.ServiceID.ToString + "/gameservers/stop", FormData, AddressOf Callback_ServerStop, Nil, Headers) End Sub @@ -1016,6 +1017,10 @@ Implements Beacon.DeploymentEngine Private mStatus As String #tag EndProperty + #tag Property, Flags = &h21 + Private mStopMessage As String + #tag EndProperty + #tag Property, Flags = &h21 Private mWaitNitradoCallbackKey As String #tag EndProperty diff --git a/Project/Modules/Beacon/NitradoServerProfile.xojo_code b/Project/Modules/Beacon/NitradoServerProfile.xojo_code index 6d073eec5..f8d0e7e57 100644 --- a/Project/Modules/Beacon/NitradoServerProfile.xojo_code +++ b/Project/Modules/Beacon/NitradoServerProfile.xojo_code @@ -60,6 +60,12 @@ Inherits Beacon.ServerProfile End Function #tag EndMethod + #tag Method, Flags = &h0 + Function SupportsCustomStopMessage() As Boolean + Return True + End Function + #tag EndMethod + #tag Method, Flags = &h0 Function SupportsRestart() As Boolean Return True diff --git a/Project/Modules/Beacon/ServerProfile.xojo_code b/Project/Modules/Beacon/ServerProfile.xojo_code index 0f5183d3c..879ac3f3f 100644 --- a/Project/Modules/Beacon/ServerProfile.xojo_code +++ b/Project/Modules/Beacon/ServerProfile.xojo_code @@ -110,6 +110,12 @@ Protected Class ServerProfile End Function #tag EndMethod + #tag Method, Flags = &h0 + Function SupportsCustomStopMessage() As Boolean + Return False + End Function + #tag EndMethod + #tag Method, Flags = &h0 Function SupportsRestart() As Boolean Return False diff --git a/Project/Modules/Preferences.xojo_code b/Project/Modules/Preferences.xojo_code index a5cb987a0..2c5c0ba57 100644 --- a/Project/Modules/Preferences.xojo_code +++ b/Project/Modules/Preferences.xojo_code @@ -266,6 +266,22 @@ Protected Module Preferences Protected LastPresetMapFilter As UInt64 #tag EndComputedProperty + #tag ComputedProperty, Flags = &h1 + #tag Getter + Get + Init + Return mManager.StringValue("Last Stop Message", "Server is now stopping for a few minutes for changes.") + End Get + #tag EndGetter + #tag Setter + Set + Init + mManager.StringValue("Last Stop Message") = Value + End Set + #tag EndSetter + Protected LastStopMessage As String + #tag EndComputedProperty + #tag ComputedProperty, Flags = &h1 #tag Getter Get diff --git a/Project/Views/DocumentDeployWindow.xojo_window b/Project/Views/DocumentDeployWindow.xojo_window index a8feb8733..33ed1e786 100644 --- a/Project/Views/DocumentDeployWindow.xojo_window +++ b/Project/Views/DocumentDeployWindow.xojo_window @@ -498,7 +498,7 @@ End Next For Each DeploymentEngine As Beacon.DeploymentEngine In Self.mDeploymentEngines - DeploymentEngine.Begin(Self.mDeployLabel, Self.mDocument, App.IdentityManager.CurrentIdentity) + DeploymentEngine.Begin(Self.mDeployLabel, Self.mDocument, App.IdentityManager.CurrentIdentity, Self.mStopMessage) Next Self.DeployingWatchTimer.RunMode = Timer.RunModes.Multiple @@ -683,6 +683,10 @@ End Private mOAuthWindow As OAuthAuthorizationWindow #tag EndProperty + #tag Property, Flags = &h21 + Private mStopMessage As String + #tag EndProperty + #tag Constant, Name = PageDeploying, Type = Double, Dynamic = False, Default = \"1", Scope = Private #tag EndConstant @@ -724,6 +728,7 @@ End Dim SelectedCount As Integer Dim Supported As Integer = RestartSupportedUnknown + Dim SupportsCustomStopMessage As Boolean For I As Integer = 0 To Self.mDocument.ServerProfileCount - 1 Dim Profile As Beacon.ServerProfile = Self.mDocument.ServerProfile(I) If Not Profile.Enabled Then @@ -740,6 +745,8 @@ End ElseIf (CanRestart = True And Supported = RestartSupportedNone) Or (CanRestart = False And Supported = RestartSupportedAll) Then Supported = RestartSupportedMixed End If + + SupportsCustomStopMessage = SupportsCustomStopMessage Or Profile.SupportsCustomStopMessage Next Dim Predicate As String = If(SelectedCount = 1, "server", "servers") @@ -761,6 +768,17 @@ End End If End Select + // Prompt for server stop message here + Dim StopMessage As String = Preferences.LastStopMessage + If SupportsCustomStopMessage Then + StopMessage = StopMessageDialog.Present(Self, StopMessage) + If StopMessage = "" Then + Return + End If + Preferences.LastStopMessage = StopMessage + End If + Self.mStopMessage = StopMessage + Self.Pages.SelectedPanelIndex = Self.PageDeploying For I As Integer = 0 To Self.mDocument.ServerProfileCount - 1 diff --git a/Project/Views/StopMessageDialog.xojo_window b/Project/Views/StopMessageDialog.xojo_window new file mode 100644 index 000000000..85a086ac0 --- /dev/null +++ b/Project/Views/StopMessageDialog.xojo_window @@ -0,0 +1,257 @@ +#tag Window +Begin BeaconDialog StopMessageDialog + Backdrop = 0 + BackgroundColor = &cFFFFFF00 + Composite = False + DefaultLocation = "1" + FullScreen = False + HasBackgroundColor= False + HasCloseButton = False + HasFullScreenButton= False + HasMaximizeButton= False + HasMinimizeButton= False + Height = 166 + ImplicitInstance= False + MacProcID = 0 + MaximumHeight = 166 + MaximumWidth = 32000 + MenuBar = 0 + MenuBarVisible = True + MinimumHeight = 166 + MinimumWidth = 500 + Resizeable = True + Title = "Stop Message" + Type = "8" + Visible = True + Width = 500 + Begin UITweaks.ResizedTextField MessageField + AllowAutoDeactivate= True + AllowFocusRing = True + AllowSpellChecking= False + AllowTabs = False + BackgroundColor = &cFFFFFF00 + Bold = False + Border = True + DataField = "" + DataSource = "" + Enabled = True + FontName = "System" + FontSize = 0.0 + FontUnit = 0 + Format = "" + HasBorder = True + Height = 22 + Hint = "" + Index = -2147483648 + Italic = False + Left = 20 + LockBottom = False + LockedInPosition= False + LockLeft = True + LockRight = True + LockTop = True + MaximumCharactersAllowed= 0 + Password = False + ReadOnly = False + Scope = 2 + TabIndex = 0 + TabPanelIndex = 0 + TabStop = True + TextAlignment = "0" + TextColor = &c00000000 + Tooltip = "" + Top = 84 + Transparent = False + Underline = False + ValidationMask = "" + Value = "" + Visible = True + Width = 460 + End + Begin Label MessageLabel + AllowAutoDeactivate= True + Bold = True + DataField = "" + DataSource = "" + Enabled = True + FontName = "System" + FontSize = 0.0 + FontUnit = 0 + Height = 20 + Index = -2147483648 + InitialParent = "" + Italic = False + Left = 20 + LockBottom = False + LockedInPosition= False + LockLeft = True + LockRight = True + LockTop = True + Multiline = False + Scope = 2 + Selectable = False + TabIndex = 1 + TabPanelIndex = 0 + TabStop = True + TextAlignment = "0" + TextColor = &c00000000 + Tooltip = "" + Top = 20 + Transparent = False + Underline = False + Value = "Set Stop Message" + Visible = True + Width = 460 + End + Begin Label ExplanationLabel + AllowAutoDeactivate= True + Bold = False + DataField = "" + DataSource = "" + Enabled = True + FontName = "System" + FontSize = 0.0 + FontUnit = 0 + Height = 20 + Index = -2147483648 + InitialParent = "" + Italic = False + Left = 20 + LockBottom = False + LockedInPosition= False + LockLeft = True + LockRight = True + LockTop = True + Multiline = False + Scope = 2 + Selectable = False + TabIndex = 2 + TabPanelIndex = 0 + TabStop = True + TextAlignment = "0" + TextColor = &c00000000 + Tooltip = "" + Top = 52 + Transparent = False + Underline = False + Value = "This message should be displayed to players before the server stops." + Visible = True + Width = 460 + End + Begin UITweaks.ResizedPushButton ActionButton + AllowAutoDeactivate= True + Bold = False + Cancel = False + Caption = "OK" + Default = True + Enabled = False + FontName = "System" + FontSize = 0.0 + FontUnit = 0 + Height = 20 + Index = -2147483648 + InitialParent = "" + Italic = False + Left = 400 + LockBottom = False + LockedInPosition= False + LockLeft = False + LockRight = True + LockTop = True + MacButtonStyle = "0" + Scope = 2 + TabIndex = 3 + TabPanelIndex = 0 + TabStop = True + Tooltip = "" + Top = 126 + Transparent = False + Underline = False + Visible = True + Width = 80 + End + Begin UITweaks.ResizedPushButton CancelButton + AllowAutoDeactivate= True + Bold = False + Cancel = True + Caption = "Cancel" + Default = False + Enabled = True + FontName = "System" + FontSize = 0.0 + FontUnit = 0 + Height = 20 + Index = -2147483648 + InitialParent = "" + Italic = False + Left = 308 + LockBottom = False + LockedInPosition= False + LockLeft = False + LockRight = True + LockTop = True + MacButtonStyle = "0" + Scope = 2 + TabIndex = 4 + TabPanelIndex = 0 + TabStop = True + Tooltip = "" + Top = 126 + Transparent = False + Underline = False + Visible = True + Width = 80 + End +End +#tag EndWindow + +#tag WindowCode + #tag Method, Flags = &h0 + Sub Constructor(DefaultMessage As String) + Super.Constructor + Self.MessageField.Value = DefaultMessage + Self.SwapButtons() + End Sub + #tag EndMethod + + #tag Method, Flags = &h0 + Shared Function Present(Parent As Window, DefaultMessage As String) As String + If Parent = Nil Then + Return DefaultMessage + End If + + Dim Win As New StopMessageDialog(DefaultMessage) + Win.ShowModalWithin(Parent.TrueWindow) + + Dim Message As String = Win.MessageField.Value.Trim + Win.Close + + Return Message + End Function + #tag EndMethod + + +#tag EndWindowCode + +#tag Events MessageField + #tag Event + Sub TextChanged() + Self.ActionButton.Enabled = Me.Value.Trim <> "" + End Sub + #tag EndEvent +#tag EndEvents +#tag Events ActionButton + #tag Event + Sub Pressed() + Self.Hide + End Sub + #tag EndEvent +#tag EndEvents +#tag Events CancelButton + #tag Event + Sub Pressed() + Self.MessageField.Text = "" + Self.Hide + End Sub + #tag EndEvent +#tag EndEvents