Skip to content

Commit

Permalink
Fixed GSA launch option import and deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
thommcgrath committed Jan 30, 2024
1 parent bae98c2 commit 4d5f52a
Show file tree
Hide file tree
Showing 11 changed files with 209 additions and 287 deletions.
18 changes: 0 additions & 18 deletions Project/Modules/Beacon/HostingProvider.xojo_code
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,6 @@ Protected Interface HostingProvider
End Sub
#tag EndMethod

#tag Method, Flags = &h0
Function GameSetting(Project As Beacon.Project, Profile As Beacon.ServerProfile, Setting As Beacon.GameSetting) As Variant

End Function
#tag EndMethod

#tag Method, Flags = &h0
Sub GameSetting(Project As Beacon.Project, Profile As Beacon.ServerProfile, Setting As Beacon.GameSetting, Assigns Value As Variant)

End Sub
#tag EndMethod

#tag Method, Flags = &h0
Function GetServerStatus(Project As Beacon.Project, Profile As Beacon.ServerProfile) As Beacon.ServerStatus

Expand Down Expand Up @@ -90,12 +78,6 @@ Protected Interface HostingProvider
End Function
#tag EndMethod

#tag Method, Flags = &h0
Function SupportsGameSettings() As Boolean

End Function
#tag EndMethod

#tag Method, Flags = &h0
Function SupportsRestarting() As Boolean

Expand Down
72 changes: 0 additions & 72 deletions Project/Modules/Game Support/Ark.xojo_code
Original file line number Diff line number Diff line change
Expand Up @@ -811,78 +811,6 @@ Protected Module Ark
End Function
#tag EndMethod

#tag Method, Flags = &h1
Protected Function ParseCommandLine1(CommandLine As String, PreserveSyntax As Boolean = False) As Dictionary
// This shouldn't take long, but still, probably best to only use this on a thread

Var InQuotes As Boolean
Var Characters() As String = CommandLine.Split("")
Var Buffer, Params() As String
For Each Char As String In Characters
If Char = """" Then
If InQuotes Then
Params.Add(Buffer)
Buffer = ""
InQuotes = False
Else
InQuotes = True
End If
ElseIf Char = " " Then
If InQuotes = False And Buffer.Length > 0 Then
Params.Add(Buffer)
Buffer = ""
End If
ElseIf Char = "-" And Buffer.Length = 0 Then
Continue
Else
Buffer = Buffer + Char
End If
Next
If Buffer.Length > 0 Then
Params.Add(Buffer)
Buffer = ""
End If

Var StartupParams() As String = Params.Shift.Split("?")
Var Map As String = StartupParams.Shift
Call StartupParams.Shift // The listen statement
If PreserveSyntax Then
For Idx As Integer = 0 To Params.LastIndex
Params(Idx) = "-" + Params(Idx)
Next
For Idx As Integer = 0 To StartupParams.LastIndex
StartupParams(Idx) = "?" + StartupParams(Idx)
Next
End If
StartupParams.Merge(Params)

Var CommandLineOptions As New Dictionary
For Each Parameter As String In StartupParams
Var KeyPos As Integer = Parameter.IndexOf("=")
Var Key As String
Var Value As Variant
If KeyPos = -1 Then
Key = Parameter
Value = True
Else
Key = Parameter.Left(KeyPos)
Value = Parameter.Middle(KeyPos + 1)
End If
If PreserveSyntax Then
Value = Parameter
End If
CommandLineOptions.Value(Key) = Value
Next

If PreserveSyntax Then
CommandLineOptions.Value("?Map") = Map
Else
CommandLineOptions.Value("Map") = Map
End If
Return CommandLineOptions
End Function
#tag EndMethod

#tag Method, Flags = &h1
Protected Function PickWeightedMember(Members() As Ark.Weighted) As Ark.Weighted
If Members Is Nil Or Members.Count = 0 Then
Expand Down
99 changes: 82 additions & 17 deletions Project/Modules/Game Support/Ark/DeployIntegration.xojo_code
Original file line number Diff line number Diff line change
Expand Up @@ -175,25 +175,84 @@ Inherits Beacon.DeployIntegration
End If

// Make command line changes
If Self.Provider.SupportsGameSettings Then
Self.Log("Updating other settings…")
Call Self.ApplySettings(Organizer, False)
If Self.Finished Then
Return
End If
End If
Select Case Self.Provider
Case IsA Nitrado.HostingProvider
Call Self.NitradoApplySettings(Organizer, False)
Case IsA GameServerApp.HostingProvider
Call Self.GameServerAppApplySettings(Organizer)
End Select
End Sub
#tag EndEvent


#tag Method, Flags = &h1
Protected Function ApplySettings(Organizer As Ark.ConfigOrganizer, Full As Boolean) As Boolean
Select Case Self.Provider
Case IsA Nitrado.HostingProvider
Return Self.NitradoApplySettings(Organizer, Full)
Else
Return True
End Select
Protected Function GameServerAppApplySettings(Organizer As Ark.ConfigOrganizer) As Boolean
If (Self.Provider IsA GameServerApp.HostingProvider) = False Then
Return False
End If

Var ChainDownloaded As Boolean
Var Chain As String = Self.GetFile("chain", "Launch Options: Chain", Beacon.Integration.DownloadFailureMode.MissingAllowed, False, ChainDownloaded)

Var TailDownloaded As Boolean
Var Tail As String = Self.GetFile("end", "Launch Options: End", Beacon.Integration.DownloadFailureMode.MissingAllowed, False, TailDownloaded)

Var Launch As String = "TheIsland?listen" + Chain + " " + Tail
Var CommandLine As Dictionary = Ark.ParseCommandLine(Launch, True)
If CommandLine.HasKey("?Map") Then
CommandLine.Remove("?Map")
ElseIf CommandLine.HasKey("Map") Then
CommandLine.Remove("Map")
End If

// Options are key value pairs, flags are just keys
Var Options() As Ark.ConfigValue = Organizer.FilteredValues("CommandLineOption")
Var Flags() As Ark.ConfigValue = Organizer.FilteredValues("CommandLineFlag")

For Each Option As Ark.ConfigValue In Options
Var Key As String = Option.Header + Option.AttributedKey
CommandLine.Value(Key) = Option.Command
Next
For Each Flag As Ark.ConfigValue In Flags
Var Key As String = Flag.Header + Flag.AttributedKey
If Flag.Details.ValueType = Ark.ConfigOption.ValueTypes.TypeBoolean Then
If Flag.Value = "True" Then
CommandLine.Value(Key) = Flag.AttributedKey
ElseIf CommandLine.HasKey(Key) Then
CommandLine.Remove(Key)
End If
End If
Next

Var ChainElements(), TailElements() As String
For Each Entry As DictionaryEntry In CommandLine
Var Key As String = Entry.Key
Var Command As String = Entry.Value
If Key.BeginsWith("-") Then
If Command.BeginsWith("-") = False Then
Command = "-" + Command
End If
TailElements.Add(Command)
ElseIf Key.BeginsWith("?") Then
If Command.BeginsWith("?") = False Then
Command = "?" + Command
End If
ChainElements.Add(Command)
End If
Next

Var NewChain As String = ChainElements.Join("")
Var NewTail As String = TailElements.Join(" ")

If Not Self.PutFile(NewChain, "chain", "Launch Options: Chain") Then
Return False
End If

If Not Self.PutFile(NewTail, "end", "Launch Options: End") Then
Return False
End If

Return True
End Function
#tag EndMethod

Expand All @@ -203,6 +262,8 @@ Inherits Beacon.DeployIntegration
Return False
End If

Self.Log("Updating other settings…")

Var Project As Ark.Project = Self.Project
Var Profile As Ark.ServerProfile = Self.Profile
Var Keys() As Ark.ConfigOption = Organizer.DistinctKeys
Expand Down Expand Up @@ -267,7 +328,7 @@ Inherits Beacon.DeployIntegration
Var Changes As New Dictionary
For Each Entry As DictionaryEntry In NewValues
Var ConfigOption As Ark.ConfigOption = Entry.Key
Var CurrentValue As Variant = Self.Provider.GameSetting(Project, Profile, ConfigOption)
Var CurrentValue As Variant = Nitrado.HostingProvider(Self.Provider).GameSetting(Project, Profile, ConfigOption)
Var FinishedValue As String
If Entry.Value.Type = Variant.TypeString Then
// Value comparison
Expand Down Expand Up @@ -385,7 +446,7 @@ Inherits Beacon.DeployIntegration
Var NewValue As String = Entry.Value

Try
Self.Provider.GameSetting(Project, Profile, Setting) = NewValue
Nitrado.HostingProvider(Self.Provider).GameSetting(Project, Profile, Setting) = NewValue
Catch Err As RuntimeException
Self.SetError(Err)
Return False
Expand Down Expand Up @@ -491,6 +552,10 @@ Inherits Beacon.DeployIntegration

#tag Method, Flags = &h21
Private Sub SwitchToExpertMode(OffendingKey As String, ContentLength As Integer)
If (Self.Provider IsA Nitrado.HostingProvider) = False Then
Return
End If

Var UserData As New Dictionary
UserData.Value("OffendingKey") = OffendingKey
UserData.Value("ContentLength") = ContentLength
Expand Down Expand Up @@ -547,7 +612,7 @@ Inherits Beacon.DeployIntegration
End If

Try
Self.Provider.GameSetting(Self.Project, Self.Profile, New Beacon.GenericGameSetting(Beacon.GenericGameSetting.TypeBoolean, "general.expertMode")) = True
Nitrado.HostingProvider(Self.Provider).GameSetting(Self.Project, Self.Profile, New Beacon.GenericGameSetting(Beacon.GenericGameSetting.TypeBoolean, "general.expertMode")) = True
Catch Err As RuntimeException
Self.SetError("Could not enable expert mode: " + Err.Message)
Return
Expand Down
32 changes: 24 additions & 8 deletions Project/Modules/Game Support/Ark/DiscoverIntegration.xojo_code
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ Inherits Beacon.DiscoverIntegration
Case IsA Nitrado.HostingProvider
Self.Log("Checking server status…")
Try
Profile.BasePath = Provider.GameSetting(Project, Profile, New Beacon.GenericGameSetting(Beacon.GenericGameSetting.TypeString, "/game_specific.path"))
Profile.BasePath = Nitrado.HostingProvider(Provider).GameSetting(Project, Profile, New Beacon.GenericGameSetting(Beacon.GenericGameSetting.TypeString, "/game_specific.path"))
Catch Err As RuntimeException
Self.SetError("Could not find server base path: " + Err.Message)
Return Nil
End Try

Try
Var MapIdentifier As String = Provider.GameSetting(Project, Profile, New Beacon.GenericGameSetting(Beacon.GenericGameSetting.TypeString, "config.map"))
Var MapIdentifier As String = Nitrado.HostingProvider(Provider).GameSetting(Project, Profile, New Beacon.GenericGameSetting(Beacon.GenericGameSetting.TypeString, "config.map"))
Profile.Mask = Ark.Maps.MaskForIdentifier(MapIdentifier.LastField(","))
GetMapFromLogs = False
Catch Err As RuntimeException
Expand All @@ -33,15 +33,15 @@ Inherits Beacon.DiscoverIntegration

Var ExpertMode As Boolean
Try
ExpertMode = Provider.GameSetting(Project, Profile, New Beacon.GenericGameSetting(Beacon.GenericGameSetting.TypeBoolean, "general.expertMode"))
ExpertMode = Nitrado.HostingProvider(Provider).GameSetting(Project, Profile, New Beacon.GenericGameSetting(Beacon.GenericGameSetting.TypeBoolean, "general.expertMode"))
Catch Err As RuntimeException
Self.SetError("Could not determine if the server is in expert mode: " + Err.Message)
Return Nil
End Try

GatherGameSettings = False
DownloadIniFiles = ExpertMode
Data.CommandLineOptions = Beacon.ParseJSON(JSONItem(Provider.GameSetting(Project, Profile, New Beacon.GenericGameSetting(Beacon.GenericGameSetting.TypeString, "start-param"))).ToString) // Weird way to convert JSONItem to Dictionary
Data.CommandLineOptions = Beacon.ParseJSON(JSONItem(Nitrado.HostingProvider(Provider).GameSetting(Project, Profile, New Beacon.GenericGameSetting(Beacon.GenericGameSetting.TypeString, "start-param"))).ToString) // Weird way to convert JSONItem to Dictionary

If ExpertMode = False Then
Var GuidedOrganizer As New Ark.ConfigOrganizer
Expand All @@ -53,7 +53,7 @@ Inherits Beacon.DiscoverIntegration

Var Value As Variant
Try
Value = Provider.GameSetting(Project, Profile, Setting)
Value = Nitrado.HostingProvider(Provider).GameSetting(Project, Profile, Setting)
Catch Err As RuntimeException
Self.SetError("Failed to get value for setting '" + Setting.Key + "': " + Err.Message)
Return Nil
Expand Down Expand Up @@ -141,13 +141,14 @@ Inherits Beacon.DiscoverIntegration
End If
End If

If GatherGameSettings And Provider.SupportsGameSettings Then
Select Case Provider
Case IsA Nitrado.HostingProvider
Var CommandLineOptions As New Dictionary
Var Settings() As Ark.ConfigOption = Ark.DataSource.Pool.Get(False).GetConfigOptions("", "", "", False)
For Each Setting As Ark.ConfigOption In Settings
Var Value As Variant
Try
Value = Provider.GameSetting(Project, Profile, Setting)
Value = Nitrado.HostingProvider(Provider).GameSetting(Project, Profile, Setting)
If Value.IsNull = False Then
CommandLineOptions.Value(Setting.Key) = Value
End If
Expand All @@ -157,7 +158,22 @@ Inherits Beacon.DiscoverIntegration
End Try
Next
Data.CommandLineOptions = CommandLineOptions
End If
Case IsA GameServerApp.HostingProvider
Var ChainDownloaded As Boolean
Var Chain As String = Self.GetFile("chain", "Launch Options: Chain", Beacon.Integration.DownloadFailureMode.MissingAllowed, False, ChainDownloaded)

Var TailDownloaded As Boolean
Var Tail As String = Self.GetFile("end", "Launch Options: End", Beacon.Integration.DownloadFailureMode.MissingAllowed, False, TailDownloaded)

Var Launch As String = "TheIsland?listen" + Chain + " " + Tail
Var CommandLine As Dictionary = Ark.ParseCommandLine(Launch, False)
If CommandLine.HasKey("?Map") Then
CommandLine.Remove("?Map")
ElseIf CommandLine.HasKey("Map") Then
CommandLine.Remove("Map")
End If
Data.CommandLineOptions = CommandLine
End Select

Self.mImportProgress = New Beacon.DummyProgressDisplayer
Var NewProject As Ark.Project = Ark.ImportThread.RunSynchronous(Data, Self.mDestinationProject, Self.mImportProgress)
Expand Down
Loading

0 comments on commit 4d5f52a

Please sign in to comment.