public ZMachineSession(InstantMessagingCall call) { _state = ZMachineSessionState.InitialMessage; _call = call; Log.Debug("CallID: " + call.CallId); _call.StateChanged += CallOnStateChanged; _call.Flow.MessageReceived += FlowOnMessageReceived; try { _gameChoices = Directory.GetFiles(Path.Combine(ZMachineSettings.AppDataFolder,"Games"), "*"); } catch (Exception ex) { Log.Error("Exception in " + ex.TargetSite.Name, ex); _gameChoices = new string[0]; } }
private async void FlowOnMessageReceived(object sender, InstantMessageReceivedEventArgs e) { switch (_state) { case ZMachineSessionState.InitialMessage: _state = ZMachineSessionState.PickGame; await SendGameChoiceMenu(); break; case ZMachineSessionState.PickGame: uint pickedOption; if (uint.TryParse(e.TextBody, out pickedOption) && _gameChoices.Length >= pickedOption) { _state = ZMachineSessionState.PlayingGame; await SendMessage("HINT: You can resume your last session by sending \"restore\""); StartFrotz(pickedOption); } else { await SendMessage("That's not a valid option..."); await SendGameChoiceMenu(); } break; case ZMachineSessionState.PlayingGame: AddInput(e.TextBody); //_frotz.AddInput(e.TextBody); if (e.TextBody.Trim().Equals("quit", StringComparison.InvariantCultureIgnoreCase)) { _state = ZMachineSessionState.Quiting; } break; case ZMachineSessionState.Quiting: AddInput(e.TextBody); //_frotz.AddInput(e.TextBody); if (e.TextBody.Trim().Equals("y", StringComparison.InvariantCultureIgnoreCase)) { await SendMessage("Thanks for playing!"); await _call.TerminateAsync(); ZMachineHub.SendQuit(ID); } else { _state = ZMachineSessionState.PlayingGame; } break; default: throw new ArgumentOutOfRangeException(); } }