Skip to content

Commit

Permalink
Merge pull request #48 from runeberry/jb-crossplay
Browse files Browse the repository at this point in the history
Add support for -crossplay flag
  • Loading branch information
dolphinspired authored Nov 10, 2022
2 parents e9e16f2 + 10201f2 commit 04ea66d
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 230 deletions.
15 changes: 15 additions & 0 deletions ValheimServerGUI/Forms/MainWindow.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions ValheimServerGUI/Forms/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,7 @@ private void StartServer()
NewWorld = newWorld,
Public = this.CommunityServerField.Value,
Port = this.ServerPortField.Value,
Crossplay = this.ServerCrossplayField.Value,
};

try
Expand All @@ -712,6 +713,7 @@ private void StartServer()
prefs.ServerPassword = this.ServerPasswordField.Value;
prefs.ServerWorldName = worldName;
prefs.ServerPublic = this.CommunityServerField.Value;
prefs.ServerCrossplay = this.ServerCrossplayField.Value;

this.UserPrefsProvider.SavePreferences(prefs);
}
Expand Down Expand Up @@ -927,6 +929,7 @@ private void RefreshFormStateForServer()
this.ServerPasswordField.Enabled = allowServerChanges;
this.WorldSelectGroupBox.Enabled = allowServerChanges;
this.CommunityServerField.Enabled = allowServerChanges;
this.ServerCrossplayField.Enabled = allowServerChanges;

this.ButtonStartServer.Enabled = this.Server.CanStart;
this.ButtonRestartServer.Enabled = this.Server.CanRestart;
Expand Down Expand Up @@ -961,6 +964,7 @@ private void LoadFormValuesFromUserPrefs(UserPreferences prefs)
this.ServerPortField.Value = prefs.ServerPort;
this.ServerPasswordField.Value = prefs.ServerPassword;
this.CommunityServerField.Value = prefs.ServerPublic;
this.ServerCrossplayField.Value = prefs.ServerCrossplay;
this.ShowPasswordField.Value = false;

this.WorldSelectExistingNameField.Value = prefs.ServerWorldName;
Expand Down
252 changes: 31 additions & 221 deletions ValheimServerGUI/Forms/MainWindow.resx

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion ValheimServerGUI/Game/UserPreferences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public class UserPreferences

public int ServerPort { get; set; } = DefaultServerPort;

public bool ServerCrossplay { get; set; }

public static UserPreferences FromFile(UserPreferencesFile file)
{
var prefs = new UserPreferences();
Expand All @@ -49,7 +51,7 @@ public static UserPreferences FromFile(UserPreferencesFile file)
prefs.StartMinimized = file.StartMinimized ?? prefs.StartMinimized;
prefs.CheckServerRunning = file.CheckServerRunning ?? prefs.CheckServerRunning;
prefs.CheckForUpdates = file.CheckForUpdates ?? prefs.CheckForUpdates;

var server = file.Servers?.FirstOrDefault();

if (server != null)
Expand All @@ -59,6 +61,7 @@ public static UserPreferences FromFile(UserPreferencesFile file)
prefs.ServerWorldName = server.WorldName ?? prefs.ServerWorldName;
prefs.ServerPublic = server.CommunityServer ?? prefs.ServerPublic;
prefs.ServerPort = server.Port ?? prefs.ServerPort;
prefs.ServerCrossplay = server.Crossplay ?? prefs.ServerCrossplay;
}

return prefs;
Expand All @@ -85,6 +88,7 @@ public UserPreferencesFile ToFile()
WorldName = this.ServerWorldName,
CommunityServer = this.ServerPublic,
Port = this.ServerPort,
Crossplay = this.ServerCrossplay,
}
}
};
Expand Down
3 changes: 3 additions & 0 deletions ValheimServerGUI/Game/UserPreferencesFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public class ServerPreferencesFile

[JsonProperty("port")]
public int? Port { get; set; }

[JsonProperty("crossplay")]
public bool? Crossplay { get; set; }
}
}
}
18 changes: 12 additions & 6 deletions ValheimServerGUI/Game/ValheimServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class ValheimServer : IDisposable
/// </summary>
public IValheimServerOptions Options { get; private set; } = new ValheimServerOptions();

public ServerStatus Status
public ServerStatus Status
{
get => this._status;
private set
Expand All @@ -46,9 +46,9 @@ private set
private readonly IPlayerDataRepository PlayerDataRepository;
private readonly ValheimServerLogger ServerLogger;
private readonly IEventLogger ApplicationLogger;

public ValheimServer(
IProcessProvider processProvider,
IProcessProvider processProvider,
IValheimFileProvider fileProvider,
IPlayerDataRepository playerDataRepository,
ValheimServerLogger serverLogger,
Expand All @@ -71,18 +71,18 @@ public ValheimServer(
private void InitializeLogBasedActions()
{
LogBasedActions.Add(@"Game server connected", this.OnServerConnected);

LogBasedActions.Add(@"Got connection SteamID (\d+?)\D*?$", this.OnPlayerConnecting);
LogBasedActions.Add(@"Got character ZDOID from (.+?) : ([\d-]+?)\D*?:(\d+?)\D*?$", this.OnPlayerConnected);
LogBasedActions.Add(@"Peer (\d+?) has wrong password", this.OnPlayerDisconnecting);
LogBasedActions.Add(@"Closing socket (\d+?)\D*?$", this.OnPlayerDisconnected); // Technically "disconnecting" but it's the best terminator I can find

LogBasedActions.Add(@"World saved \(\s*?([[\d\.]+?)\s*?ms\s*?\)\s*?$", this.OnWorldSaved);
}

private void InitializeStatusBasedActions()
{
this.StatusChanged += BuildStatusHandler(ServerStatus.Stopped, () =>
this.StatusChanged += BuildStatusHandler(ServerStatus.Stopped, () =>
{
if (this.IsRestarting)
{
Expand Down Expand Up @@ -126,6 +126,12 @@ public void Start(IValheimServerOptions options)
var saveDataFolder = this.FileProvider.SaveDataFolder.FullName;
var publicFlag = options.Public ? 1 : 0;
var processArgs = @$"-nographics -batchmode -name ""{options.Name}"" -port {options.Port} -world ""{options.WorldName}"" -password ""{options.Password}"" -public {publicFlag} -savedir ""{saveDataFolder}""";

if (options.Crossplay)
{
processArgs += " -crossplay";
}

var process = this.ProcessProvider.AddBackgroundProcess(ProcessKeys.ValheimServer, exePath, processArgs);

process.StartInfo.EnvironmentVariables.Add("SteamAppId", Resources.ValheimSteamAppId);
Expand Down
5 changes: 4 additions & 1 deletion ValheimServerGUI/Game/ValheimServerOptions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.IO;

namespace ValheimServerGUI.Game
{
Expand All @@ -17,6 +16,8 @@ public class ValheimServerOptions : IValheimServerOptions

public int Port { get; set; }

public bool Crossplay { get; set; }

public void Validate()
{
// Ensure all required fields exist
Expand Down Expand Up @@ -55,5 +56,7 @@ public interface IValheimServerOptions
bool Public { get; }

int Port { get; set; }

bool Crossplay { get; }
}
}
2 changes: 1 addition & 1 deletion ValheimServerGUI/ValheimServerGUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<Description>A simple user interface for running Valheim Dedicated Server on Windows.</Description>
<Copyright>2022</Copyright>
<PackageLicenseExpression>GNU GPLv3</PackageLicenseExpression>
<Version>2.0.0-rc.2</Version>
<Version>2.0.0-rc.3</Version>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Release'">
<SignAssembly>true</SignAssembly>
Expand Down

0 comments on commit 04ea66d

Please sign in to comment.