public override bool HandlePacket(IPacket packet) { if (_mapStateRepository.MapWarpState != WarpState.None) { throw new InvalidOperationException("Attempted to warp while another warp was in progress"); } _mapStateRepository.MapWarpState = WarpState.WarpStarted; var warpType = packet.ReadChar(); switch (warpType) { case WARP_SAME_MAP: SendWarpAcceptToServer(packet); break; case WARP_NEW_MAP: var mapID = packet.ReadShort(); var mapRid = packet.ReadBytes(4).ToArray(); var fileSize = packet.ReadThree(); var mapIsDownloaded = true; try { if (!_mapFileProvider.MapFiles.ContainsKey(mapID)) { _mapFileLoadActions.LoadMapFileByID(mapID); } } catch (IOException) { mapIsDownloaded = false; } if (!mapIsDownloaded || _fileRequestActions.NeedsMapForWarp(mapID, mapRid, fileSize)) { _fileRequestActions.GetMapForWarp(mapID).Wait(5000); } SendWarpAcceptToServer(packet); break; default: _mapStateRepository.MapWarpState = WarpState.None; return(false); } return(true); }
public async Task LoginToCharacter(ICharacter character) { var requestCharacterLoginOperation = _networkOperationFactory.CreateSafeBlockingOperation( async() => await _loginActions.RequestCharacterLogin(character), SetInitialStateAndShowError, SetInitialStateAndShowError); if (!await requestCharacterLoginOperation.Invoke()) { return; } var unableToLoadMap = false; try { _mapFileLoadActions.LoadMapFileByID(_currentMapStateProvider.CurrentMapID); } catch (IOException) { // Try to load the map now that we know what Map ID we need // non-fatal exception unableToLoadMap = true; } GameLoadingDialog gameLoadingDialog = null; try { gameLoadingDialog = _gameLoadingDialogFactory.CreateGameLoadingDialog(); gameLoadingDialog.ShowDialog(); await InitialDelayInReleaseMode(); if (unableToLoadMap || _fileRequestActions.NeedsFileForLogin(InitFileType.Map, _currentMapStateProvider.CurrentMapID)) { gameLoadingDialog.SetState(GameLoadingDialogState.Map); if (!await SafeGetFile(async() => await _fileRequestActions.GetMapFromServer(_currentMapStateProvider.CurrentMapID))) { return; } await Task.Delay(1000); } if (_fileRequestActions.NeedsFileForLogin(InitFileType.Item)) { gameLoadingDialog.SetState(GameLoadingDialogState.Item); if (!await SafeGetFile(_fileRequestActions.GetItemFileFromServer)) { return; } await Task.Delay(1000); } if (_fileRequestActions.NeedsFileForLogin(InitFileType.Npc)) { gameLoadingDialog.SetState(GameLoadingDialogState.NPC); if (!await SafeGetFile(_fileRequestActions.GetNPCFileFromServer)) { return; } await Task.Delay(1000); } if (_fileRequestActions.NeedsFileForLogin(InitFileType.Spell)) { gameLoadingDialog.SetState(GameLoadingDialogState.Spell); if (!await SafeGetFile(_fileRequestActions.GetSpellFileFromServer)) { return; } await Task.Delay(1000); } if (_fileRequestActions.NeedsFileForLogin(InitFileType.Class)) { gameLoadingDialog.SetState(GameLoadingDialogState.Class); if (!await SafeGetFile(_fileRequestActions.GetClassFileFromServer)) { return; } await Task.Delay(1000); } gameLoadingDialog.SetState(GameLoadingDialogState.LoadingGame); var completeCharacterLoginOperation = _networkOperationFactory.CreateSafeBlockingOperation( _loginActions.CompleteCharacterLogin, SetInitialStateAndShowError, SetInitialStateAndShowError); if (!await completeCharacterLoginOperation.Invoke()) { return; } await Task.Delay(1000); //always wait 1 second } finally { if (gameLoadingDialog != null) { gameLoadingDialog.CloseDialog(); } } _gameStateActions.ChangeToState(GameStates.PlayingTheGame); _chatTextBoxActions.FocusChatTextBox(); _statusLabelSetter.SetStatusLabel(EOResourceID.STATUS_LABEL_TYPE_WARNING, EOResourceID.LOADING_GAME_HINT_FIRST); _firstTimePlayerActions.WarnFirstTimePlayers(); _mapChangedActions.ActiveCharacterEnterMapForLogin(); }