public GameBL() { server = ServerBL.Instance; server.gameHubProxy.On("StartGame", (string roomId, Board board) => OnStartGame?.Invoke(roomId, board)); server.gameHubProxy.On("GetPlayerColor", (string roomId, CheckerColor color) => OnGetPlayerColor?.Invoke(roomId, color)); server.gameHubProxy.On("GetGameInvitation", (string room, string sender) => OnGameInvitation?.Invoke(room, sender)); server.gameHubProxy.On("DenyGame", (string username) => OnDenyInitation?.Invoke(username)); server.gameHubProxy.On("CurrentTurn", (string roomId, string username) => OnCurrentTurn?.Invoke(roomId, username)); server.gameHubProxy.On("GetUserName", (string userName) => OnGetPlayerName?.Invoke(userName)); server.gameHubProxy.On("UpdateBoard", (string roomId, Board board) => OnBoardUpdate?.Invoke(roomId, board)); server.gameHubProxy.On("DiceResult", (string room, int[] dice) => OnDiceResult?.Invoke(room, dice)); server.gameHubProxy.On("ChangeTurnStatus", (string roomId, TurnStatus turnStatus) => OnTurnStatusChange?.Invoke(roomId, turnStatus)); server.gameHubProxy.On("GameOver", (string roomid, string username) => OnGameOver?.Invoke(roomid, username)); server.gameHubProxy.On("GameClosed", (string room, string sender) => OnGameClosed?.Invoke(room, sender)); }
// On game close protected static void _onGameClosed() { OnGameClosed?.Invoke(typeof(Scanner), EventArgs.Empty); }
/// <summary> /// Callback when the game is closed. /// </summary> private async Task HandleGameClosed() { OnGameClosed?.Invoke(); // delete VDM file, we don't need it anymore string vdmPath = _config.Demo.GetVdmFilePath(); if (File.Exists(vdmPath)) { File.Delete(vdmPath); } // delete the CFG file, we don't need it anymore string cfgPath = GetCfgPath(); if (File.Exists(cfgPath)) { File.Delete(cfgPath); } // do not continue if TGA file not present, user may have close the game prematurely if (!IsFirstTgaExists()) { return; } // generate a video file if the user want it if (_config.GenerateVideoFile) { if (_config.UseVirtualDub) { // VirtualDub GenerateVirtualDubScript(); ProcessStartInfo psi = new ProcessStartInfo { Arguments = "/s csgodm.jobs /x", FileName = VirtualDubService.GetVirtualDubExePath(), WorkingDirectory = VirtualDubService.GetVirtualDubPath(), }; Process p = new Process { StartInfo = psi, }; p.Start(); OnVirtualDubStarted?.Invoke(); await p.WaitForExitAsync(); OnVirtualDubClosed?.Invoke(); HandleEncodingEnded(); } else { // FFmpeg List <string> argsList = GetFFmpegArgs(); string args = string.Join(" ", argsList.ToArray()); ProcessStartInfo psi = new ProcessStartInfo { Arguments = args, FileName = FFmpegService.GetFFmpegExePath(), UseShellExecute = false }; Process p = new Process { StartInfo = psi, }; OnFFmpegStarted?.Invoke(); p.Start(); await p.WaitForExitAsync(); OnFFmpegClosed?.Invoke(); HandleEncodingEnded(); } } }