protected override void OnActionCompleted(IAsyncResult asyncResult, MySectorServiceClient client) { try { client.EndSaveCheckpoint(asyncResult); MyEditorActions.ResetActionHistory(); var handler = Saved; if (handler != null) { handler(this); } } catch (FaultException <MyCustomFault> faultException) { if (faultException.Detail.ErrorCode == MyCustomFaultCode.SectorNameExists) { MyGuiManager.AddScreen(new MyGuiScreenMessageBox(MyMessageBoxType.ERROR, MyTextsWrapperEnum.CantSaveSectorNameExists, MyTextsWrapperEnum.MessageBoxCaptionError, MyTextsWrapperEnum.Ok, null)); } else { throw faultException; // Causes parent to call OnError } } CloseScreen(); }
protected override void OnActionCompleted(IAsyncResult asyncResult, MySectorServiceClient client) { Debug.Assert((EndAction != null && EndActionWait == null) || (EndAction == null && EndActionWait != null), "Set only one of EndAction, EndActionWait"); if (EndActionWait != null) { var innerAction = EndActionWait(client, asyncResult); if (innerAction != null) { innerAction.ActionSuccess += RaiseActionSuccess; innerAction.ActionFailed += RaiseActionFailed; } else { RaiseActionSuccess(); } } else if (EndAction != null) { // When error occures, OnError is called EndAction(client, asyncResult); RaiseActionSuccess(); } CloseScreen(); }
private void HandleLogout() { MyClientServer.Logout(); MySectorServiceClient.ClearAndClose(); m_onLogoutProgressClosed(); CloseScreen(); }
protected override void OnActionCompleted(IAsyncResult asyncResult, MySectorServiceClient client) { try { byte[] result = client.EndLoadSectorObjects(asyncResult); var sectorBuilder = MyMwcObjectBuilder_Base.FromBytes <MyMwcObjectBuilder_Sector>(result); m_parentScreen.CloseScreen(); MyGuiManager.AddScreen(new MyGuiScreenEditorCopyTool(sectorBuilder)); } catch (FaultException <MyCustomFault> faultException) { if (faultException.Detail.ErrorCode == MyCustomFaultCode.UserNotFound) { MyGuiManager.AddScreen(new MyGuiScreenMessageBox(MyMessageBoxType.ERROR, MyTextsWrapperEnum.PlayerNotFound, MyTextsWrapperEnum.MessageBoxCaptionError, MyTextsWrapperEnum.Ok, null)); } else if (faultException.Detail.ErrorCode == MyCustomFaultCode.SectorNotFound) { MyGuiManager.AddScreen(new MyGuiScreenMessageBox(MyMessageBoxType.ERROR, MyTextsWrapperEnum.SectorNotFound, MyTextsWrapperEnum.MessageBoxCaptionError, MyTextsWrapperEnum.Ok, null)); } else { throw faultException; } } CloseScreen(); }
void FillList() { Func <IAsyncResult> begin = () => { var client = MySectorServiceClient.GetCheckedInstance(); return(client.BeginLoadTemplateCheckpointNames(null, client)); }; Action <IAsyncResult, MyGuiScreenProgressAsync> end = (result, screen) => { try { var client = (MySectorServiceClient)result.AsyncState; var info = client.EndLoadTemplateCheckpointNames(result); InsertItems(info); } catch (Exception) { MyGuiManager.AddScreen(new MyGuiScreenMessageBox(MyMessageBoxType.ERROR, MyTextsWrapperEnum.PleaseTryAgain, MyTextsWrapperEnum.MessageBoxNetworkErrorCaption, MyTextsWrapperEnum.Ok, null)); } screen.CloseScreenNow(); }; var progress = new MyGuiScreenProgressAsync(MyTextsWrapperEnum.LoadSectorIdentifiersPleaseWait, false, begin, end); MyGuiManager.AddScreen(progress); }
protected override void OnActionCompleted(IAsyncResult asyncResult, MySectorServiceClient client) { try { byte[] result = client.EndLoadCheckpoint(asyncResult); m_checkpoint = MyMwcObjectBuilder_Base.FromBytes <MyMwcObjectBuilder_Checkpoint>(result); //if (m_checkpoint.SectorObjectBuilder == null) // Server told us to use cache //{ // LoadSector(); // return; //} MyGuiScreenGamePlay.StoreLastLoadedCheckpoint(m_checkpoint); m_loadCheckpointSuccessfulAction(m_checkpoint); CloseScreen(); } catch (FaultException <MyCustomFault> faultException) { if (faultException.Detail.ErrorCode == MyCustomFaultCode.CheckpointTemplateNotExists) { HandleNonexistentCheckpoint(); } else { // Handled by base class throw faultException; } } }
// Override default behaviour - default behaviour logs exception, aborts client and closes screen protected override void OnError(Exception exception, MySectorServiceClient client) { MySectorServiceClient.SafeClose(); MyMwcLog.WriteLine(exception); // log exception ShowRetryDialog(); CloseScreen(); }
// We are unloading the game here (in this event), because when player presses Alt+F4 during loading phase, sometimes // graphic device is disposed during we are unloading - with is weird. But this event finishes always before even // graphic device disposing starts, so it's safe. // Add any code that must execute before the game ends (e.g. when player suddenly presses Alt+F4) void MyMinerGame_Exiting(object sender, EventArgs e) { MyMwcLog.WriteLine("MyMinerGame.MyMinerGame_Exiting"); MySectorServiceClient.ClearAndClose(); // In case of exception on different thread IsMouseVisible = true; UnloadData(); // MinerWars.AppCode.Game.Render.MyOcclusionQuery.UnloadAllQueries(); }
protected override void ServiceProgressStart(MySectorServiceClient client) { if (MySectorServiceClient.HasCredentials && MySectorServiceClient.HasUrl) { AddAction(client.BeginLogout(null, client), OnLogoutCompleted); } else { CloseScreen(); } }
protected override void ServiceProgressStart(MySectorServiceClient client) { if (m_loadGlobal) { AddAction(client.BeginLoadSectorIdentifiers(m_sectorType, null, client)); } else { AddAction(client.BeginLoadUserSectorIdentifiers(null, client)); } }
protected override void ServiceProgressStart(MySectorServiceClient client) { if (!MySession.PlayerShip.IsDead()) { SaveSector(client); } else { this.CloseScreen(); } }
private static MySectorServiceClient GetSectorServiceClient() { MySectorServiceClient client = MySectorServiceClient.GetCheckedInstance(); var channelContext = client.GetChannelContext(); if (channelContext != null) { channelContext.OperationTimeout = TimeSpan.FromSeconds(180); } return(client); }
protected override void OnActionCompleted(IAsyncResult asyncResult, MySectorServiceClient client) { Vector3 newShipPosition; byte[] result = client.EndTravelToSector(out newShipPosition, asyncResult); var sectorBuilder = MyMwcObjectBuilder_Base.FromBytes <MyMwcObjectBuilder_Sector>(result); m_enterSectorSuccessfulAction(sectorBuilder, newShipPosition); CloseScreen(); }
protected override void OnActionCompleted(IAsyncResult asyncResult, MySectorServiceClient client) { if (m_loadGlobal) { m_successAction(client.EndLoadSectorIdentifiers(asyncResult)); } else { m_successAction(client.EndLoadUserSectorIdentifiers(asyncResult)); } this.CloseScreen(); }
void OnLogoutCompleted(IAsyncResult result, MySectorServiceClient client) { try { client.EndLogout(result); } catch (Exception e) // We don't care about exceptions here, just log exception { MyMwcLog.WriteLine(e); } HandleLogout(); }
void OnGetSectorServer(IAsyncResult result, object asyncState) { try { var client = (MyMasterServiceClient)result.AsyncState; string sectorServerUrl = client.EndGetSectorServer(result); client.Close(); MySectorServiceClient.SetUrl(sectorServerUrl); AddAction(MySectorServiceClient.BeginLoginStatic(), OnLoginCompleted); } catch (Exception e) { HandleLoginError(e); } }
private void OnReceiveCheckpoint(ref MyEventCheckpoint sectorData) { MyMultiplayerGameplay.Log("JOIN 7. - Checkpoint received (#SectorData), join completed, loading"); MyMultiplayerGameplay.Log("MTU: " + sectorData.SenderConnection.GetMTU()); if (MySession.PlayerShip != null) { MyMultiplayerGameplay.StoredShip = (MyMwcObjectBuilder_SmallShip)MySession.PlayerShip.GetObjectBuilder(false); } var loadedPlayer = sectorData.Checkpoint.LoadCoopPlayer(MyClientServer.LoggedPlayer.GetDisplayName().ToString()); if (loadedPlayer != null) { var faction = sectorData.Checkpoint.PlayerObjectBuilder.ShipObjectBuilder.Faction; sectorData.Checkpoint.PlayerObjectBuilder = loadedPlayer; sectorData.Checkpoint.PlayerObjectBuilder.ShipObjectBuilder = new MyMwcObjectBuilder_SmallShip_Player(sectorData.Checkpoint.PlayerObjectBuilder.ShipObjectBuilder); sectorData.Checkpoint.PlayerObjectBuilder.ShipObjectBuilder.Faction = faction; } else { // Set default values for playership (coop) sectorData.Checkpoint.PlayerObjectBuilder.ShipConfigObjectBuilder = null; sectorData.Checkpoint.PlayerObjectBuilder.ShipObjectBuilder.ReflectorLight = true; sectorData.Checkpoint.PlayerObjectBuilder.ShipObjectBuilder.ReflectorLongRange = false; sectorData.Checkpoint.PlayerObjectBuilder.ShipObjectBuilder.IsDummy = false; } if (sectorData.Checkpoint.CurrentSector.SectorType == MyMwcSectorTypeEnum.SANDBOX && !MinerWars.AppCode.Networking.MySteam.IsActive) { sectorData.Checkpoint.PlayerObjectBuilder.Money = (float)MySectorServiceClient.GetCheckedInstance().GetGameMoney(); MySectorServiceClient.SafeClose(); } else { // Keep money sectorData.Checkpoint.PlayerObjectBuilder.Money = MySession.Static != null ? MySession.Static.Player.Money : 0; } MyMultiplayerGameplay.StartBufferingGameEvents(); var handler = m_gameJoinedAction; if (handler != null) { handler(m_game, MyResultCodeEnum.OK, sectorData.Checkpoint); // Will handle sector loading } }
protected override void ProgressStart() { if (String.IsNullOrEmpty(m_playerName) || String.IsNullOrEmpty(m_password)) { LoginResponse = MyMwcLoginResponseResultEnum.USERNAME_OR_PASSWORD_EMPTY; } else { MyMasterServiceClient.SetCredentials(m_playerName, PasswordHash); MySectorServiceClient.SetCredentials(m_playerName, PasswordHash); MyMwcLog.WriteLine("Login request: " + m_playerName); var client = MyMasterServiceClient.GetCheckedInstance(); AddAction(client.BeginCheckVersion(MyMwcFinalBuildConstants.SERVER_PROTOCOL_VERSION, null, client), OnCheckVersion); } }
void RenameTemplate(string oldName, string newName, MyGuiScreenBase renameScreen) { renameScreen.CloseScreenNow(); Func <IAsyncResult> begin = () => { var client = MySectorServiceClient.GetCheckedInstance(); return(client.BeginRenameTemplateCheckpoint(oldName, newName, null, client)); }; Action <IAsyncResult, MyGuiScreenProgressAsync> end = (result, screen) => { try { var client = (MySectorServiceClient)result.AsyncState; client.EndRenameTemplateCheckpoint(result); } catch (FaultException <MyCheckpointRenameFault> e) { switch (e.Detail.Reason) { case MyCheckpointRenameFaultReason.CheckpointNotFound: MyGuiManager.AddScreen(new MyGuiScreenMessageBox(MyMessageBoxType.ERROR, MyTextsWrapperEnum.SectorNotFound, MyTextsWrapperEnum.MessageBoxTimeoutCaption, MyTextsWrapperEnum.Ok, null)); break; case MyCheckpointRenameFaultReason.NameAlreadyExists: MyGuiManager.AddScreen(new MyGuiScreenMessageBox(MyMessageBoxType.ERROR, MyTextsWrapperEnum.CantSaveSectorNameExists, MyTextsWrapperEnum.MessageBoxTimeoutCaption, MyTextsWrapperEnum.Ok, null)); break; } } catch (Exception) { MyGuiManager.AddScreen(new MyGuiScreenMessageBox(MyMessageBoxType.ERROR, MyTextsWrapperEnum.PleaseTryAgain, MyTextsWrapperEnum.MessageBoxNetworkErrorCaption, MyTextsWrapperEnum.Ok, null)); } screen.CloseScreenNow(); FillList(); }; var progress = new MyGuiScreenProgressAsync(MyTextsWrapperEnum.LoadSectorIdentifiersPleaseWait, false, begin, end); MyGuiManager.AddScreen(progress); }
private void SaveSector(MySectorServiceClient client) { if (m_pause) { if (!MinerWars.AppCode.App.MyMinerGame.IsPaused()) { MinerWars.AppCode.App.MyMinerGame.SwitchPause(); } } m_checkpoint.CurrentSector = m_sectorIdentifier; //if (MyLocalCache.CanBeSaved(m_checkpoint)) //{ // MyLocalCache.Save(m_checkpoint); // m_checkpoint.SectorObjectBuilder = null; //} AddAction(client.BeginSaveCheckpoint(m_checkpoint.ToBytes(), m_savePlayer, null, client)); }
protected override void OnActionCompleted(IAsyncResult asyncResult, MySectorServiceClient client) { List <MyMwcUserDetail> users; var sectorIdentifiers = client.EndSelectSandbox(out users, asyncResult); m_responseHandler(sectorIdentifiers, users); if (m_openAfterSuccessfulEnter.GetState() != MyGuiScreenState.HIDDEN && m_openAfterSuccessfulEnter.GetState() != MyGuiScreenState.HIDING) { if (m_openAfterSuccessfulEnter.GetState() != MyGuiScreenState.OPENED) { MyGuiManager.AddScreen(m_openAfterSuccessfulEnter); } } else { //this screen should be unhide automaticaly //m_openAfterSuccessfulEnter.UnhideScreen(); } CloseScreen(); }
protected override void OnError(Exception exception, MySectorServiceClient client) { MyMwcLog.WriteLine(exception); // log exception if (EnableRetry) { ShowRetryDialog(exception); } else { RaiseActionFailed(exception); if (ShowErrorMessage) { MyGuiManager.AddScreen(new MyGuiScreenMessageBox(MyMessageBoxType.ERROR, ErrorMessageText, ErrorCaptionText, MyTextsWrapperEnum.Ok, null)); } CloseScreen(); if (OnErrorReturnToMainMenu) { MyGuiManager.BackToMainMenu(); } } }
private MyServerAction LoadSandbox(MyMwcVector3Int position, int?userId, MyMissionID?startMission) { var sectorId = new MyMwcSectorIdentifier(MyMwcSectorTypeEnum.SANDBOX, userId, position, null); var sector = MyLocalCache.LoadSector(sectorId); int?version = sector != null ? (int?)sector.Version : null; MyMwcStartSessionRequestTypeEnum startSessionType = userId == MyClientServer.LoggedPlayer.GetUserId() ? MyMwcStartSessionRequestTypeEnum.SANDBOX_OWN : MyMwcStartSessionRequestTypeEnum.SANDBOX_FRIENDS; if (userId != null) { MyServerAction loadAction = new MyServerAction(MyTextsWrapperEnum.EnterSectorInProgressPleaseWait, TimeSpan.FromSeconds(360)); loadAction.BeginAction = c => c.BeginLoadSandbox(position, userId, version, null, c); loadAction.EndAction = (c, r) => SandboxSectorLoaded(position, MyMwcObjectBuilder_Base.FromBytes <MyMwcObjectBuilder_Checkpoint>(c.EndLoadSandbox(r)), sector, startSessionType, startMission); loadAction.Start(); return(loadAction); } else if (sector != null) { var checkpoint = MyLocalCache.MultiplayerCheckpoint(); if (checkpoint == null) { throw new MyDataCorruptedException("Cannot load MP checkpoint"); } if (!MySteam.IsActive && MyClientServer.IsMwAccount) { checkpoint.PlayerObjectBuilder.Money = (float)MySectorServiceClient.GetCheckedInstance().GetGameMoney(); MySectorServiceClient.SafeClose(); } checkpoint.SectorObjectBuilder = sector; SandboxSectorLoaded(position, checkpoint, sector, startSessionType, startMission); return(null); } else { throw new MyDataCorruptedException("Cannot load sandbox/MP sector"); } }
void OnLoginCompleted(IAsyncResult result, object asyncState) { try { MyUserInfo userInfo = MySectorServiceClient.EndLoginStatic(result); MyMwcLog.WriteLine("Login successful, userId: " + userInfo.UserId); // 2.5D and cheats for everyone var player = new MyPlayerLocal(new StringBuilder(userInfo.DisplayName), userInfo.UserId, userInfo.CanAccessDemo, userInfo.CanSave, userInfo.CanAccessEditorForStory, userInfo.CanAccessEditorForMMO, userInfo.HasAnyCheckpoints, true, userInfo.CanAccessMMO, new StringBuilder(m_playerName), new StringBuilder(PasswordHash), true); player.AdditionalInfo = userInfo.AdditionalInfo; MyClientServer.LoggedPlayer = player; LoginResponse = MyMwcLoginResponseResultEnum.OK; } catch (Exception e) { HandleLoginError(e); } }
public static void SaveToServer(bool displaySuccessMessage = false) { MyMwcLog.WriteLine("MySmallShipTemplates.SaveToServer() - START"); MyMwcLog.IncreaseIndent(); List <MyMwcObjectBuilder_SmallShipTemplate> templates = new List <MyMwcObjectBuilder_SmallShipTemplate>(); foreach (var templatesForType in m_templates) { foreach (var template in templatesForType) { template.SavedToServer = true; templates.Add(template.GetObjectBuilder()); } } try { var client = GetSectorServiceClient(); var templatesBuilder = new MyMwcObjectBuilder_SmallShipTemplates(templates); client.SaveSmallShipTemplates(templatesBuilder.ToBytes()); MySectorServiceClient.SafeClose(); MyMwcLog.WriteLine("Save state - OK"); if (displaySuccessMessage) { MyGuiManager.AddScreen(new MyGuiScreenMessageBox(MyMessageBoxType.MESSAGE, Localization.MyTextsWrapperEnum.TemplatesSaveSuccess, Localization.MyTextsWrapperEnum.Success, Localization.MyTextsWrapperEnum.Ok, null)); } } catch (Exception ex) { MyMwcLog.WriteLine("Save state - ERROR"); MyMwcLog.WriteLine(ex.Message); MyGuiManager.AddScreen(new MyGuiScreenMessageBox(MyMessageBoxType.ERROR, Localization.MyTextsWrapperEnum.TemplatesSaveError, Localization.MyTextsWrapperEnum.Error, Localization.MyTextsWrapperEnum.Ok, null)); } MyMwcLog.DecreaseIndent(); MyMwcLog.WriteLine("MySmallShipTemplates.SaveToServer() - END"); }
protected override void OnActionCompleted(IAsyncResult asyncResult, MySectorServiceClient client) { try { var response = client.EndLoadObjectGroups(asyncResult); List <MyMwcObjectBuilder_ObjectGroup> groups = new List <MyMwcObjectBuilder_ObjectGroup>(); List <MyMwcObjectBuilder_Base> entities = new List <MyMwcObjectBuilder_Base>(); var fakeEndpoint = new System.Net.IPEndPoint(0, MyClientServer.LoggedPlayer.GetUserId()); var sectorGroupBuilder = MyMwcObjectBuilder_Base.FromBytes <MyMwcObjectBuilder_SectorObjectGroups>(response); if (sectorGroupBuilder == null) { throw new InvalidOperationException("Cannot deserialize SectorObjectGroups object builder"); } MyGuiManager.AddScreen(new MyGuiScreenEditorLoadGroup(sectorGroupBuilder.Groups, sectorGroupBuilder.Entities)); } catch (Exception) { MyGuiManager.AddScreen(new MyGuiScreenMessageBox(MyMessageBoxType.ERROR, MyTextsWrapperEnum.PleaseTryAgain, MyTextsWrapperEnum.MessageBoxNetworkErrorCaption, MyTextsWrapperEnum.Ok, null)); } CloseScreen(); }
void client_UpdateGameMoneyCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e) { MySectorServiceClient.SafeClose(); }
protected override void ServiceProgressStart(MySectorServiceClient client) { AddAction(client.BeginSelectSandbox(m_selectSandboxType, m_findPlayerName, null, client)); }
protected override void ServiceProgressStart(MySectorServiceClient client) { // Send save request and wait for callback AddAction(client.BeginLoadSectorObjects(m_playerName, m_sectorIdentifier.SectorName, m_sectorIdentifier.Position, null, client)); }
protected override void OnError(Exception exception, MySectorServiceClient asyncState) { // It's same like when logout succeded HandleLogout(); }