/// <summary> /// Prepare to set up a new game in a specified channel. /// </summary> /// <param name="context"> /// Context of where this game is intended to be opened. /// </param> /// <returns> /// <see langword="true"/> if the operation succeeded, otherwise <see langword="false"/>. /// </returns> public async Task <bool> OpenNewGameAsync(ICommandContext context) { if (GameTracker.Instance.TryAddGameString(context.Channel, GameName)) { await Logger(new LogMessage(LogSeverity.Verbose, LogSource, _mpconfig.LogStrings.CreatingGame(context.Channel, _gameName))).ConfigureAwait(false); var data = new PersistentGameData(context.Channel, context.User, this); return(_dataList.TryAdd(context.Channel, data) && data.TryUpdateOpenToJoin(newValue: true, oldValue: false)); } return(false); }
/// <summary> Prepare to set up a new game in a specified channel. </summary> /// <param name="channel">Public facing channel of this game.</param> /// <returns><see langword="true"/> if the operation succeeded, otherwise <see langword="false"/>.</returns> public bool OpenNewGame(ICommandContext context) { lock (_lock) { if (GameTracker.Instance.TryGetGameString(context.Channel, out var _)) { return(false); } var data = new PersistentGameData(context.Channel, context.User); GameTracker.Instance.TryAddGameString(context.Channel, GameName); data.NewPlayerList(); _dataList.AddOrUpdate(context.Channel, data, (k, v) => data); return(data.TryUpdateOpenToJoin(newValue: true, oldValue: false)); } }