public static async void ExecuteCommandJoinServer(ViewModelServerInfo serverInfo) { if (Api.IsEditor) { DialogWindow.ShowDialog( DialogEditorMode_Title, DialogEditorMode_Message); return; } var address = serverInfo.Address; if (address == default) { // should be impossible throw new Exception("Bad server address"); } if (serverInfo.IsInaccessible) { var title = serverInfo.IsOfficial ? null : GameServerLoginFailedDialogHelper.TitleDefault; var message = serverInfo.IsOfficial ? DialogServerInaccessible : GameServerLoginFailedDialogHelper.ServerUnreachable; DialogWindow.ShowDialog( title: title, message, okAction: () => { if (!serverInfo.IsInaccessible) { // became accessible while dialog was displayed ExecuteCommandJoinServer(serverInfo); return; } // still inaccessible serverInfo.CommandRefresh?.Execute(serverInfo); serverInfo.RefreshAndDisplayPleaseWaitDialog( onInfoReceivedOrCannotReach: () => ExecuteCommandJoinServer(serverInfo)); }, cancelAction: () => { }, okText: CoreStrings.Button_Retry, cancelText: CoreStrings.Button_Cancel, closeByEscapeKey: true, zIndexOffset: 100000); return; } if (!serverInfo.IsInfoReceived) { serverInfo.RefreshAndDisplayPleaseWaitDialog( onInfoReceivedOrCannotReach: () => ExecuteCommandJoinServer(serverInfo)); return; } if (!(serverInfo.IsCompatible ?? false)) { var serverVersion = serverInfo.Version; var clientVersion = Api.Shared.GameVersionNumber; string problemTitle, advice; if (serverVersion > clientVersion) { problemTitle = DialogIncompatibleServer_VersionTitle_Newer; advice = DialogIncompatibleServer_Advice_UpdateClient; } else { problemTitle = DialogIncompatibleServer_VersionTitle_Older; advice = DialogIncompatibleServer_Advice_ConnectNewServer; } var message = problemTitle // ReSharper disable once CanExtractXamlLocalizableStringCSharp + ":[br]" + string.Format(DialogIncompatibleServer_MessageFormat, serverVersion, clientVersion) // ReSharper disable once CanExtractXamlLocalizableStringCSharp + "[br][br]" + advice; DialogWindow.ShowDialog( DialogIncompatibleServer_Title, message, closeByEscapeKey: true, zIndexOffset: 100000); return; } if (Api.Client.MasterServer.IsDemoVersion && !serverInfo.IsOfficial && !serverInfo.IsFeatured) { DialogWindow.ShowDialog( CoreStrings.Demo_Title, CoreStrings.Demo_OnlyOfficialServers, okText: CoreStrings.Demo_Button_BuyGameOnSteam, okAction: () => Api.Client.SteamApi.OpenBuyGamePage(), cancelText: CoreStrings.Button_Cancel, cancelAction: () => { }, focusOnCancelButton: true, closeByEscapeKey: true, zIndexOffset: 100000); return; } // can display a dialog before player joins the server //await JoinServerAgreementDialogHelper.Display(); Api.Client.CurrentGame.ConnectToServer(address); }
public ViewModelServerInfoListEntry(ViewModelServerInfo viewModelServerInfo) : base(isAutoDisposeFields: false) { this.ViewModelServerInfo = viewModelServerInfo; }
public static async void ExecuteCommandJoinServer(ViewModelServerInfo serverInfo) { if (Api.IsEditor) { DialogWindow.ShowDialog( DialogEditorMode_Title, DialogEditorMode_Message); return; } var address = serverInfo.Address; if (string.IsNullOrEmpty(address.HostAddress)) { // should be impossible throw new Exception("Bad server name"); } if (serverInfo.IsNotAccessible) { DialogWindow.ShowDialog( title: null, DialogServerInaccessible, okAction: () => serverInfo.CommandRefresh.Execute(serverInfo), cancelAction: () => { }, okText: CoreStrings.Button_Retry, cancelText: CoreStrings.Button_Cancel, closeByEscapeKey: true, zIndexOffset: 100000); return; } if (!serverInfo.IsInfoReceived) { serverInfo.RefreshAndDisplayPleaseWaitDialog(); return; } if (!(serverInfo.IsCompatible ?? false)) { var serverVersion = serverInfo.Version; var clientVersion = Api.Shared.GameVersionNumber; string problemTitle, advice; if (serverVersion > clientVersion) { problemTitle = DialogIncompatibleServer_VersionTitle_Newer; advice = DialogIncompatibleServer_Advice_UpdateClient; } else { problemTitle = DialogIncompatibleServer_VersionTitle_Older; advice = DialogIncompatibleServer_Advice_ConnectNewServer; } var message = problemTitle // ReSharper disable once CanExtractXamlLocalizableStringCSharp + ":[br]" + string.Format(DialogIncompatibleServer_MessageFormat, serverVersion, clientVersion) // ReSharper disable once CanExtractXamlLocalizableStringCSharp + "[br][br]" + advice; DialogWindow.ShowDialog( DialogIncompatibleServer_Title, message, closeByEscapeKey: true, zIndexOffset: 100000); return; } await JoinServerAgreementDialogHelper.Display(); Api.Client.CurrentGame.ConnectToServer(address); }