Skip to content

Commit

Permalink
Patch v1.2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
K4ryuu committed May 11, 2024
1 parent 8a3e327 commit 3652b27
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 19 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
-- 2024.05.11 - v1.2.4

- feat: Automatically detect the permission problem and suggest to enable the fix
- fix: The directories not read/set properly if the fix is enabled
- fix: Not to generate directory of demos if the fix is enabled
- Finally ended the suffer of Slynx

-- 2024.05.11 - v1.2.3

- feat: Added file-open-problem-fix setting to fix the problem if you dont have access for directories other than game root
Expand Down
43 changes: 24 additions & 19 deletions src/CS2-GOTV-Discord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public class DemoRequestSettings
public class CS2GOTVDiscordPlugin : BasePlugin, IPluginConfig<PluginConfig>
{
public override string ModuleName => "CS2 GOTV Discord";
public override string ModuleVersion => "1.2.3";
public override string ModuleVersion => "1.2.4";
public override string ModuleAuthor => "K4ryuu";

public required PluginConfig Config { get; set; } = new PluginConfig();
Expand Down Expand Up @@ -163,7 +163,7 @@ public override void Load(bool hotReload)
{
foreach (string fileName in DelayedUploads)
{
string demoPath = Path.Combine(Server.GameDirectory, "csgo", "discord_demos", $"{fileName}.dem");
string demoPath = Config.General.FileOpenProblemFix ? Path.Combine(Server.GameDirectory, "csgo", $"{fileName}.dem") : Path.Combine(Server.GameDirectory, "csgo", "discord_demos", $"{fileName}.dem");
ProcessUpload(fileName, demoPath);
}
}
Expand All @@ -179,7 +179,8 @@ public override void Load(bool hotReload)
return HookResult.Continue;
});

Directory.CreateDirectory(Path.Combine(Server.GameDirectory, "csgo", "discord_demos"));
if (!Config.General.FileOpenProblemFix)
Directory.CreateDirectory(Path.Combine(Server.GameDirectory, "csgo", "discord_demos"));

if (Config.DemoRequest.Enabled)
AddCommand($"css_demo", "Request a demo upload at the end of the round", Command_DemoRequest);
Expand Down Expand Up @@ -242,16 +243,14 @@ private HookResult CommandListener_Record(CCSPlayerController? player, CommandIn
if (Config.AutoRecord.Enabled && Config.AutoRecord.CropRounds)
fileName = $"{fileName}-{Utilities.FindAllEntitiesByDesignerName<CCSGameRulesProxy>("cs_gamerules").FirstOrDefault()?.GameRules?.TotalRoundsPlayed + 1}";

if (Config.General.UseTimestampedFilename || File.Exists(Path.Combine(Server.GameDirectory, "csgo", "discord_demos", $"{fileName}.dem")))
bool fileExists = Config.General.FileOpenProblemFix ? File.Exists(Path.Combine(Server.GameDirectory, "csgo", $"{fileName}.dem")) : File.Exists(Path.Combine(Server.GameDirectory, "csgo", "discord_demos", $"{fileName}.dem"));
if (Config.General.UseTimestampedFilename || fileExists)
fileName = $"{fileName}-{DateTime.Now:yyyy-MM-dd_HH-mm-ss}";

if (!fileName.EndsWith(".dem"))
fileName = $"{fileName}.dem";

if (!Config.General.FileOpenProblemFix)
fileName = $"discord_demos/{fileName}";

Server.ExecuteCommand($"tv_record \"{fileName}\"");
Server.ExecuteCommand($"tv_record \"{(!fileName.EndsWith(".dem") ? fileName : $"{fileName}.dem")}\"");
return HookResult.Stop;
}
else
Expand All @@ -269,7 +268,13 @@ private HookResult CommandListener_StopRecord(CCSPlayerController? player, Comma
return HookResult.Continue;
}

string demoPath = Path.Combine(Server.GameDirectory, "csgo", "discord_demos", $"{fileName}.dem");
string demoPath = Config.General.FileOpenProblemFix ? Path.Combine(Server.GameDirectory, "csgo", $"{fileName}.dem") : Path.Combine(Server.GameDirectory, "csgo", "discord_demos", $"{fileName}.dem");

if (!File.Exists(demoPath))
{
Logger.LogError($"Demo file not found: {demoPath} - Recording stopped without processing. {(!Config.General.FileOpenProblemFix ? "You should probably set FileOpenProblemFix to true in the config." : "")}");
return HookResult.Continue;
}

if (Config.DemoRequest.Enabled && !DemoRequestedThisRound)
{
Expand Down Expand Up @@ -299,19 +304,19 @@ private HookResult CommandListener_StopRecord(CCSPlayerController? player, Comma

public void ProcessUpload(string fileName, string demoPath)
{
string zipPath = Path.Combine(Server.GameDirectory, "csgo", "discord_demos", $"{fileName}.zip");
string zipPath = Config.General.FileOpenProblemFix ? Path.Combine(Server.GameDirectory, "csgo", $"{fileName}.zip") : Path.Combine(Server.GameDirectory, "csgo", "discord_demos", $"{fileName}.zip");

var demoLength = TimeSpan.FromSeconds(Server.EngineTime - DemoStartTime);
var placeholderValues = new Dictionary<string, string>
{
{ "map", Server.MapName },
{ "date", DateTime.Now.ToString("yyyy-MM-dd") },
{ "time", DateTime.Now.ToString("HH:mm:ss") },
{ "timedate", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") },
{ "length", $"{demoLength.Minutes:00}:{demoLength.Seconds:00}" },
{ "round", (Utilities.FindAllEntitiesByDesignerName<CCSGameRulesProxy>("cs_gamerules").FirstOrDefault()?.GameRules?.TotalRoundsPlayed + 1)?.ToString() ?? "Unknown" },
{ "mega_link", "Not uploaded to mega." },
};
{
{ "map", Server.MapName },
{ "date", DateTime.Now.ToString("yyyy-MM-dd") },
{ "time", DateTime.Now.ToString("HH:mm:ss") },
{ "timedate", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") },
{ "length", $"{demoLength.Minutes:00}:{demoLength.Seconds:00}" },
{ "round", (Utilities.FindAllEntitiesByDesignerName<CCSGameRulesProxy>("cs_gamerules").FirstOrDefault()?.GameRules?.TotalRoundsPlayed + 1)?.ToString() ?? "Unknown" },
{ "mega_link", "Not uploaded to mega." },
};

Task.Run(async () =>
{
Expand Down

0 comments on commit 3652b27

Please sign in to comment.