Skip to content

Commit

Permalink
Merge pull request #151 from egebilecen/v1.11.x
Browse files Browse the repository at this point in the history
v1.11.3
  • Loading branch information
egebilecen authored Jul 22, 2024
2 parents 75445cd + 9e0cf87 commit 1103551
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/Bot/Commands/PZServerCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,11 @@ public async Task AbortRestart()
{
Logger.WriteLog(string.Format("[PZServerCommand - abort_restart] Caller: {0}", Context.User.ToString()));

ServerUtility.ResetServerRestartInterval();
if(Application.BotSettings.ServerScheduleSettings.ServerRestartScheduleType.ToLower() == "time")
ServerUtility.AbortNextTimedServerRestart = true;
else
ServerUtility.ResetServerRestartInterval();

ServerUtility.Commands.ServerMsg(Localization.Get("disc_cmd_abort_restart_ok_server").KeyFormat(("minutes", Scheduler.GetItem("ServerRestart").NextExecuteTime.Subtract(DateTime.Now).TotalMinutes)));

await Context.Message.AddReactionAsync(EmojiList.GreenCheck);
Expand Down
2 changes: 1 addition & 1 deletion src/Bot/Scheduler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public static uint GetIntervalFromTimes(List<string> scheduleTimes)
interval = nextRestartTimeDT - DateTime.Parse(nowString);
}

Logger.WriteLog(string.Format("[GetIntervalFromTimes] - Next Restart Time: {0}", nextRestartTime));
Logger.WriteLog(string.Format("[Scheduler.GetIntervalFromTimes] - Next Restart Time: {0}", nextRestartTime));
return Convert.ToUInt32(interval.TotalMilliseconds);
}
catch (Exception)
Expand Down
9 changes: 9 additions & 0 deletions src/Bot/Schedules/ServerRestart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ public static partial class Schedules
{
public static void ServerRestart(List<object> args)
{
if(Application.BotSettings.ServerScheduleSettings.ServerRestartScheduleType.ToLower() == "time"
&& ServerUtility.AbortNextTimedServerRestart)
{
ServerUtility.AbortNextTimedServerRestart = false;
ServerUtility.ResetServerRestartInterval();

return;
}

bool isServerRunning = ServerUtility.IsServerRunning();
var publicChannel = DiscordUtility.GetTextChannelById(Application.BotSettings.PublicChannelId);
var logChannel = DiscordUtility.GetTextChannelById(Application.BotSettings.LogChannelId);
Expand Down
4 changes: 4 additions & 0 deletions src/Bot/Schedules/ServerRestartAnnouncer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ public static void ServerRestartAnnouncer(List<object> args)
{
if(!ServerUtility.IsServerRunning()) return;

if(Application.BotSettings.ServerScheduleSettings.ServerRestartScheduleType.ToLower() == "time"
&& ServerUtility.AbortNextTimedServerRestart)
return;

ScheduleItem serverRestartSchedule = Scheduler.GetItem("ServerRestart");
ScheduleItem self = Scheduler.GetItem("ServerRestartAnnouncer");

Expand Down
6 changes: 6 additions & 0 deletions src/Bot/Schedules/WorkshopItemUpdateChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ public static void WorkshopItemUpdateChecker(List<object> args)
}

string[] workshopIdList = iniData.GetValue("WorkshopItems").Split(';');
if(workshopIdList.Length < 1)
{
Logger.WriteLog($"[Workshop Item Update Checker Schedule] Couldn't find any workshop items in iniData. configFilePath: {configFilePath}");
return;
}

var fetchDetails = Task.Run(async () => await SteamWebAPI.GetWorkshopItemDetails(workshopIdList));
var itemDetails = fetchDetails.Result;

Expand Down
5 changes: 3 additions & 2 deletions src/Bot/Util/WebRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ public static async Task<string> PostAsync(HttpClient httpClient, string url, Li
{
var content = new FormUrlEncodedContent(paramList);
HttpResponseMessage response = await httpClient.PostAsync(url, content);
string responseContent = await response.Content.ReadAsStringAsync();

if(response.IsSuccessStatusCode)
return await response.Content.ReadAsStringAsync();
return responseContent;

Logger.WriteLog($"WebRequest.PostAsync() - Response status code is not 200. Status code: {response.StatusCode} | URL: {url}");
Logger.WriteLog($"WebRequest.PostAsync() - Response status code is not 200. Status code: {response.StatusCode} | URL: {url} | Body: {responseContent}");
return null;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/PZServer/Util/ServerUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public static class ServerUtility
{
private const string serverFile = ".\\server.bat";
public static Process ServerProcess = null;
public static bool AbortNextTimedServerRestart = false;

public static bool CanStartServer()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
public static class Application
{
public const string BotRepoURL = "https://github.com/egebilecen/PZServerDiscordBot";
public static readonly SemanticVersion BotVersion = new SemanticVersion(1, 11, 2, DevelopmentStage.Release);
public static readonly SemanticVersion BotVersion = new SemanticVersion(1, 11, 3, DevelopmentStage.Release);
public static Settings.BotSettings BotSettings;

public static DiscordSocketClient Client;
Expand Down

0 comments on commit 1103551

Please sign in to comment.