internal static async Task _RunAndTrack(IZGameProcess gameProcess) { var resetEvent = new ManualResetEvent(false); // track game pipe gameProcess.StateChanged += (sender, pipeArgs) => { Console.WriteLine(pipeArgs.RawFullMessage); // return from _RunAndTrack if game closed if (pipeArgs.Event == ZGameEvent.StateChanged && pipeArgs.States.Contains(ZGameState.State_GameClose)) { resetEvent.Set(); } }; // run game process var runResult = await gameProcess.RunAsync(); // the result will be an enumeration // that will help determine if the game was launched successfully (returned directly by the ZClient) if (runResult != ZRunResult.Success) { // TODO: Do some stuff here } resetEvent.WaitOne(); }
public async Task Begin(IZGameProcess gameProcess, GameSetting gameSettings, CreateGameParametersBase parameters) { _gameProcess = gameProcess; _gameSettings = gameSettings; // track game pipe _gameProcess.StateChanged += _gamePipeHandler; // run game and go to work ;) var runResult = await _gameProcess.RunAsync(); if (runResult != ZRunResult.Success) { // log some info var message = $"For {runResult} reason can't run game"; _logger.Error(message); _OnError(message); _OnWorkComplete(); } else { // enable server discord presence _discord.UpdateSingle(parameters.Game, ZPlayMode.TestRange); } }