public async Task <Guid> HostGame(Chat.HostGameRequest req, User u) { // Try to kill every other game this asshole started before this one. var others = GameListener.Games.Where(x => x.Username.Equals(u.UserName, StringComparison.InvariantCultureIgnoreCase)) .ToArray(); foreach (var g in others) { g.TryKillGame(); } var bport = AppConfig.Instance.BroadcastPort; var gameId = Guid.NewGuid(); var waitTask = GameListener.WaitForGame(gameId); var game = new HostedGame(Ports.NextPort, req.GameGuid, req.GameVersion, req.GameName, req.GameIconUrl, req.Name, req.Password, u, req.Spectators, false, true , gameId, bport, req.SasVersion); if (game.StartProcess(true)) { await waitTask; return(game.Id); } return(Guid.Empty); }
public static async Task <Guid> HostGame(HostedGame req) { // Try to kill every other game this asshole started before this one. if (req.HostUser.Id != "26950") { var others = _gameListener.Games.Where(x => x.HostUser.Equals(req.HostUser)) .ToArray(); foreach (var g in others) { try { g.KillGame(); } catch (InvalidOperationException ex) { Log.Error($"{nameof(HostGame)}: Error killing game. See inner exception for more details.", ex); } } } req.Id = Guid.NewGuid(); req.HostAddress = AppConfig.Instance.HostName + ":" + _networkHelper.NextPort.ToString(); var waitTask = _gameListener.WaitForGame(req.Id); StartHostedGameProcess(req); await waitTask; return(req.Id); }
public static async Task <Guid> HostGame(HostedGame req, User u) { // Try to kill every other game this asshole started before this one. var others = _gameListener.Games.Where(x => x.HostUser.Equals(u)) .ToArray(); foreach (var g in others) { try { g.KillGame(); } catch (InvalidOperationException ex) { Log.Error($"{nameof(HostGame)}: Error killing game. See inner exception for more details.", ex); } } var bport = AppConfig.Instance.GameBroadcastPort; req.Id = Guid.NewGuid(); req.HostAddress = AppConfig.Instance.HostName + ":" + Ports.NextPort.ToString(); var waitTask = _gameListener.WaitForGame(req.Id); var gameProcess = new HostedGameProcess(req, Service.IsDebug, false, AppConfig.Instance.GameBroadcastPort); gameProcess.Start(); await waitTask; return(req.Id); }
public async Task Test() { var game = new HostedGame() { Id = Guid.NewGuid(), HostUser = new User("id", "name") }; using (var broadcaster = new GameBroadcaster(game, 3456)) { using (var listener = new GameBroadcastListener(3456)) { broadcaster.StartBroadcasting(); listener.StartListening(); var waitedGame = await listener.WaitForGame(game.Id); Assert.AreEqual(game.HostUser.Id, waitedGame.HostUser.Id); Assert.AreEqual(game.HostUser.DisplayName, waitedGame.HostUser.DisplayName); } } }