|
@@ -116,9 +116,9 @@ public class MainWindowViewModel : ViewModelBase
|
|
|
_logger.Debug("Connecting to WebSoket");
|
|
|
//conection to my servers
|
|
|
|
|
|
- var serverNames = await Downloader.DownloadAndDeserializeJsonData<List<string>>("https://files.veloe.link/launcher/servers.json");
|
|
|
+ var serverInfo = await Downloader.DownloadAndDeserializeJsonData<Dictionary<string, string[]>>("https://files.veloe.link/launcher/serversInfo.json");
|
|
|
|
|
|
- if (serverNames is not null)
|
|
|
+ if (serverInfo is not null)
|
|
|
{
|
|
|
_connection = new HubConnectionBuilder()
|
|
|
.WithUrl("https://monitor.veloe.link/hubs/data")
|
|
@@ -132,23 +132,26 @@ public class MainWindowViewModel : ViewModelBase
|
|
|
Func<string, Task> reconnected = str => Task.Run(() =>
|
|
|
{
|
|
|
_logger.Warning("Reconnected to WebCoket.");
|
|
|
- foreach (var server in serverNames)
|
|
|
+ foreach (var server in serverInfo)
|
|
|
{
|
|
|
- _connection.InvokeAsync("ConnectToGroup", server);
|
|
|
+ _connection.InvokeAsync("ConnectToGroup", server.Key);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
_connection.Reconnecting += reconnecting;
|
|
|
_connection.Reconnected += reconnected;
|
|
|
-
|
|
|
- foreach (var server in serverNames)
|
|
|
- ServerPanels.Add(CreateServerPanel(server));
|
|
|
+
|
|
|
+ await Dispatcher.UIThread.InvokeAsync(()=>
|
|
|
+ {
|
|
|
+ foreach (var server in serverInfo)
|
|
|
+ ServerPanels.Add(CreateServerPanel(server.Key, server.Value[0], server.Value[1]));
|
|
|
+ });
|
|
|
|
|
|
await _connection.StartAsync();
|
|
|
|
|
|
- foreach (var server in serverNames)
|
|
|
+ foreach (var server in serverInfo)
|
|
|
{
|
|
|
- await _connection.InvokeAsync("ConnectToGroup", server);
|
|
|
+ await _connection.InvokeAsync("ConnectToGroup", server.Key);
|
|
|
}
|
|
|
_logger.Debug("Connected to WebSoket");
|
|
|
}
|
|
@@ -267,6 +270,8 @@ public class MainWindowViewModel : ViewModelBase
|
|
|
set => this.RaiseAndSetIfChanged(ref _downloadedVersion, value);
|
|
|
}
|
|
|
|
|
|
+ public bool DownloadedVersionNotNull => DownloadedVersion is not null;
|
|
|
+
|
|
|
public int DownloadedIndex
|
|
|
{
|
|
|
get => _downloadedIndex;
|
|
@@ -378,8 +383,15 @@ public class MainWindowViewModel : ViewModelBase
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public async void StartMinecraft()
|
|
|
+ public void StartMinecraft()
|
|
|
{
|
|
|
+ StartMinecraft(string.Empty);
|
|
|
+ }
|
|
|
+
|
|
|
+ public async void StartMinecraft(string additionalArgs)
|
|
|
+ {
|
|
|
+ if (!IsNoGameRunning) return;
|
|
|
+
|
|
|
await Task.Run(async() =>
|
|
|
{
|
|
|
try
|
|
@@ -391,6 +403,8 @@ public class MainWindowViewModel : ViewModelBase
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ IsNoGameRunning = false;
|
|
|
+
|
|
|
int version = 0;
|
|
|
var arguments = string.Empty;
|
|
|
|
|
@@ -409,7 +423,7 @@ public class MainWindowViewModel : ViewModelBase
|
|
|
|
|
|
var parameters = new DownloaderParameters();
|
|
|
parameters.Action.DownloadingFileName = value => StartButtonOutput = value;
|
|
|
- parameters.Action.IsControlsEnabled = value => IsNoGameRunning = value;
|
|
|
+ parameters.Action.IsControlsEnabled = value => IsNoGameRunning = false;
|
|
|
|
|
|
if (string.IsNullOrEmpty(versionJson.InheritsFrom))
|
|
|
{
|
|
@@ -502,14 +516,14 @@ public class MainWindowViewModel : ViewModelBase
|
|
|
ProcessStartInfo proc;
|
|
|
proc = new ProcessStartInfo
|
|
|
{
|
|
|
- UseShellExecute = false,
|
|
|
+ UseShellExecute = false,
|
|
|
RedirectStandardOutput = true,
|
|
|
RedirectStandardError = true,
|
|
|
CreateNoWindow = true,
|
|
|
FileName = Path.GetFullPath(Path.Combine(SettingsService.Instance.MinecraftForlderPath, javaPath)),
|
|
|
StandardErrorEncoding = Encoding.UTF8,
|
|
|
WorkingDirectory = Path.GetDirectoryName(Path.Combine(SettingsService.Instance.MinecraftForlderPath, javaPath)),
|
|
|
- Arguments = arguments
|
|
|
+ Arguments = arguments + additionalArgs
|
|
|
};
|
|
|
|
|
|
Process minecraft = new()
|
|
@@ -571,7 +585,8 @@ public class MainWindowViewModel : ViewModelBase
|
|
|
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
- {
|
|
|
+ {
|
|
|
+ IsNoGameRunning = true;
|
|
|
OpenErrorWindow(ex);
|
|
|
}
|
|
|
});
|
|
@@ -840,16 +855,20 @@ public class MainWindowViewModel : ViewModelBase
|
|
|
|
|
|
}
|
|
|
|
|
|
- private ServerPanelModel CreateServerPanel(string name)
|
|
|
+ private ServerPanelModel CreateServerPanel(string name, string address, string clientName)
|
|
|
{
|
|
|
- ServerPanelModel serverPanelModel = new(name, "Wait for update...", "No players.","-/-");
|
|
|
+ ServerPanelModel serverPanelModel = new(name, "Wait for update...", "No players.","-/-", address, clientName);
|
|
|
+
|
|
|
+ if (SettingsService.Instance.ServerAutoConnectLinks.ContainsKey(name))
|
|
|
+ serverPanelModel.UserClientName = SettingsService.Instance.ServerAutoConnectLinks[name];
|
|
|
|
|
|
System.Timers.Timer timeoutTimer = new System.Timers.Timer(30000);
|
|
|
|
|
|
timeoutTimer.Elapsed += (object? source, ElapsedEventArgs e) =>
|
|
|
{
|
|
|
serverPanelModel.Status = $"{serverPanelModel.Name}: Offline";
|
|
|
- serverPanelModel.Players = "-/-";
|
|
|
+ serverPanelModel.Players = "-/-";
|
|
|
+ serverPanelModel.Tip = "Server timeout.";
|
|
|
};
|
|
|
timeoutTimer.Start();
|
|
|
|
|
@@ -874,6 +893,56 @@ public class MainWindowViewModel : ViewModelBase
|
|
|
return serverPanelModel;
|
|
|
}
|
|
|
|
|
|
+ public void OnServerPanelClick(ServerPanelModel server)
|
|
|
+ {
|
|
|
+ if (string.IsNullOrWhiteSpace(server?.Name))
|
|
|
+ return;
|
|
|
+
|
|
|
+ if (SettingsService.Instance.ServerAutoConnectLinks.ContainsKey(server.Name))
|
|
|
+ {
|
|
|
+ var downloadedVersion = DownloadedVersions.FirstOrDefault(x => string.Equals(x.Version, SettingsService.Instance.ServerAutoConnectLinks[server.Name], StringComparison.Ordinal));
|
|
|
+
|
|
|
+ if (downloadedVersion != null)
|
|
|
+ {
|
|
|
+ DownloadedIndex = DownloadedVersions.IndexOf(downloadedVersion);
|
|
|
+ StartMinecraft($" -server {server.Address}");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!string.IsNullOrWhiteSpace(server.ClientName))
|
|
|
+ {
|
|
|
+ var downloadedVersion = DownloadedVersions.FirstOrDefault(x => string.Equals(x.Version, server.ClientName, StringComparison.Ordinal));
|
|
|
+
|
|
|
+ if (downloadedVersion != null)
|
|
|
+ {
|
|
|
+ DownloadedIndex = DownloadedVersions.IndexOf(downloadedVersion);
|
|
|
+ StartMinecraft($" -server {server.Address}");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //version not found
|
|
|
+ Debug.WriteLine("Version not found, or not set on server!");
|
|
|
+ }
|
|
|
+
|
|
|
+ public void SetNewPreferredVersion(ServerPanelModel server)
|
|
|
+ {
|
|
|
+ SettingsService.Instance.ServerAutoConnectLinks.Add(server.Name, DownloadedVersion?.Version);
|
|
|
+ server.UserClientName = DownloadedVersion?.Version;
|
|
|
+ SettingsService.SaveSettings();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void ResetPreferredVersion(ServerPanelModel server)
|
|
|
+ {
|
|
|
+ if (SettingsService.Instance.ServerAutoConnectLinks.ContainsKey(server.Name))
|
|
|
+ {
|
|
|
+ SettingsService.Instance.ServerAutoConnectLinks.Remove(server.Name);
|
|
|
+ server.UserClientName = string.Empty;
|
|
|
+ SettingsService.SaveSettings();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public void OnClosing(object sender, CancelEventArgs args)
|
|
|
{
|
|
|
_tokenSource.Cancel();
|