public virtual async Task PlaytestFifteenMinuteTask(RconService rconService, SrcdsLogService srcdsLogService) { if (_dataService.RSettings.ProgramSettings.Debug) { _ = _log.LogMessage("Base class PlaytestFifteenMinuteTask", false, color: LOG_COLOR); } _dataService.SetIncludePlayerCount(true); //Ensure server is awake and RCON connection is established. Run other things while waking server _ = rconService.WakeRconServer(ServerLocation); //Get rid of the old log file if one exists. Just scrap it. srcdsLogService.RemoveFeedbackFile(server); //Make a feedback file var logResult = srcdsLogService.CreateFeedbackFile(server, GetFeedbackFileName()); if (logResult) { await _log.LogMessage($"Log file created: {GetFeedbackFileName()}"); var fbf = srcdsLogService.GetFeedbackFile(server); await fbf.LogFeedback($"Pre-test feedback started at: {DateTime.Now} CT"); } }
/// <summary> /// Releases a server reservation /// </summary> /// <param name="userId">userId of server to release</param> /// <param name="reason">Reason for release</param> /// <returns>A prebuilt embed message containing the reason</returns> public Embed ReleaseServer(ulong userId, string reason, SocketTextChannel channel) { var reservation = DatabaseUtil.GetServerReservation(userId); var userName = "" + reservation.UserId; try { userName = _dataService.Guild.GetUser(reservation.UserId).ToString(); } catch { //Can't get user, they likely left. } var embed = BuildServerReleaseEmbed(userName, reservation, reason); //Find the job that is a reservation, and has the user ID var job = JobManager.AllSchedules.SingleOrDefault(x => x.Name.Contains($"{userId}") && x.Name.StartsWith("[TSRelease_")); //Remove it if not null if (job != null) { JobManager.RemoveJob(job.Name); } var hasServer = DatabaseUtil.GetTestServer(reservation.ServerId); //Get their feedback file and send it, then delete it. var fbf = _srcdsLogService.GetFeedbackFile(hasServer); if (fbf != null) { var file = fbf.FileName; if (File.Exists(file)) { channel.SendFileAsync(file, ""); _ = Task.Run(async() => { //Give some time to send the file before deletion. await Task.Delay(5000); try { File.Delete(file); } catch (Exception e) { Console.WriteLine(e); } }); } } _srcdsLogService.RemoveFeedbackFile(hasServer); //If there is feedback running on this server, remove it. Also delete the file. DatabaseUtil.RemoveServerReservation(userId); return(embed); }
public virtual async Task PlaytestCommandPost(bool replyInContext, SrcdsLogService srcdsLogService, RconService rconService) { if (_dataService.RSettings.ProgramSettings.Debug) { _ = _log.LogMessage("Base class PlaytestCommandPost", false, color: LOG_COLOR); } PlaytestCommandRunning = true; //Force the next alert to true _dataService.SetStartAlert(true); await _log.LogMessage("Running Playtest Post Tasks!", color : LOG_COLOR); //No context to send these messages to - default them if (!replyInContext) { await _dataService.CSGOTestingChannel.SendMessageAsync(embed : new EmbedBuilder() .WithAuthor($"Post playtest of {PlaytestCommandInfo.Title}") .WithColor(new Color(55, 55, 165)) .WithDescription($"\nOn **{PlaytestCommandInfo.ServerAddress}**" + $"\nWorkshop ID **{PlaytestCommandInfo.WorkshopId}**" + $"\nDemo Name **{PlaytestCommandInfo.DemoName}**").Build()); } var fbf = srcdsLogService.GetFeedbackFile(server); if (fbf != null && File.Exists(fbf.FileName)) { Directory.CreateDirectory( $"{_dataService.RSettings.ProgramSettings.PlaytestDemoPath}\\{PlaytestCommandInfo.StartDateTime:yyyy}" + $"\\{PlaytestCommandInfo.StartDateTime:MM} - {PlaytestCommandInfo.StartDateTime:MMMM}" + $"\\{PlaytestCommandInfo.DemoName}"); File.Copy(fbf.FileName, $"{_dataService.RSettings.ProgramSettings.PlaytestDemoPath}\\{PlaytestCommandInfo.StartDateTime:yyyy}" + $"\\{PlaytestCommandInfo.StartDateTime:MM} - {PlaytestCommandInfo.StartDateTime:MMMM}" + $"\\{PlaytestCommandInfo.DemoName}\\{PlaytestCommandInfo.DemoName}.txt" , true); await AnnouncmentChannel.SendFileAsync(fbf.FileName, ""); } _ = Task.Run(async() => { await Task.Delay(35000); var patreonUsers = _dataService.PatreonsRole.Members.ToArray(); GeneralUtil.Shuffle(patreonUsers); var thanks = ""; foreach (var patreonsRoleMember in patreonUsers) { thanks += $"{patreonsRoleMember.Username}, "; } await rconService.RconCommand(PlaytestCommandInfo.ServerAddress, $"say Thanks to these supporters: {thanks.TrimEnd(',', ' ')}"); await Task.Delay(2000); await rconService.RconCommand(PlaytestCommandInfo.ServerAddress, @"Say Become a supporter at www.patreon.com/tophattwaffle"); }); //Stop getting more feedback srcdsLogService.RemoveFeedbackFile(server); }
public virtual async Task PlaytestCommandPre(bool replyInContext, SrcdsLogService srcdsLogService, RconService rconService) { if (_dataService.RSettings.ProgramSettings.Debug) { _ = _log.LogMessage("Base class PlaytestCommandPre", false, color: LOG_COLOR); } PlaytestCommandRunning = true; _dataService.SetStartAlert(false); await _log.LogMessage("Running Playtest Pre Tasks!", color : LOG_COLOR); //Store test information for later use. Will be written to the DB. var gameMode = IsCasual ? "casual" : "comp"; string mentions = null; Creators.ForEach(x => mentions += $"{x.Mention} "); PlaytestCommandInfo = new PlaytestCommandInfo { Id = 1, //Only storing 1 of these in the DB at a time, so hard code to 1. Mode = gameMode, DemoName = $"{StartDateTime:MM_dd_yyyy}" + $"_{CleanedTitle.Substring(0, CleanedTitle.IndexOf(' ')).Trim()}" + $"_{gameMode}", WorkshopId = GeneralUtil.GetWorkshopIdFromFqdn(WorkshopLink.ToString()), ServerAddress = ServerLocation, Title = CleanedTitle, ThumbNailImage = CanUseGallery ? GalleryImages[0] : _dataService.RSettings.General.FallbackTestImageUrl, ImageAlbum = ImageGallery.ToString(), CreatorMentions = mentions, StartDateTime = StartDateTime.GetValueOrDefault(), Game = Game.ToString() }; var fbf = srcdsLogService.GetFeedbackFile(server); //If somehow the session does not exist... if (fbf == null) { srcdsLogService.CreateFeedbackFile(server, GetFeedbackFileName()); fbf = srcdsLogService.GetFeedbackFile(server); } await fbf.LogFeedback($"Playtest starting feedback started at: {DateTime.Now} CT"); //Write to the DB so we can restore this info next boot DatabaseUtil.StorePlaytestCommandInfo(PlaytestCommandInfo); //Figure out where to send the no context message //No context to send these messages to - default them if (!replyInContext) { await TestingChannel.SendMessageAsync(embed : new EmbedBuilder() .WithAuthor($"Pre-start playtest of {CleanedTitle}") .WithColor(new Color(55, 55, 165)) .WithDescription($"\nOn **{PlaytestCommandInfo.ServerAddress}**" + $"\nWith config of **{PlaytestCommandInfo.Mode}**" + $"\nWorkshop ID **{PlaytestCommandInfo.WorkshopId}**").Build()); } }