Navigation Menu

Skip to content

Commit

Permalink
Deploy supports custom stop messages
Browse files Browse the repository at this point in the history
  • Loading branch information
thommcgrath committed Oct 2, 2019
1 parent 7103b52 commit d87aab9
Show file tree
Hide file tree
Showing 13 changed files with 341 additions and 10 deletions.
9 changes: 8 additions & 1 deletion Connector/App.xojo_code
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Connector/config.json
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions Project/Beacon.xojo_project
Expand Up @@ -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
Expand Down
14 changes: 11 additions & 3 deletions Project/Modules/Beacon/ConnectorDeploymentEngine.xojo_code
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions Project/Modules/Beacon/ConnectorServerProfile.xojo_code
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Project/Modules/Beacon/DeploymentEngine.xojo_code
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion Project/Modules/Beacon/FTPDeploymentEngine.xojo_code
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions Project/Modules/Beacon/NitradoDeploymentEngine.xojo_code
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions Project/Modules/Beacon/NitradoServerProfile.xojo_code
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions Project/Modules/Beacon/ServerProfile.xojo_code
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions Project/Modules/Preferences.xojo_code
Expand Up @@ -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
Expand Down
20 changes: 19 additions & 1 deletion Project/Views/DocumentDeployWindow.xojo_window
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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")
Expand All @@ -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
Expand Down

0 comments on commit d87aab9

Please sign in to comment.