Skip to content

Commit

Permalink
Merge pull request #68 from donjo9/donjo9/demoname-formatter
Browse files Browse the repository at this point in the history
Demoname formatting
  • Loading branch information
shobhit-pathak authored Dec 27, 2023
2 parents 9cb97c6 + 9158cf2 commit c8cb1ef
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 8 deletions.
14 changes: 14 additions & 0 deletions ConfigConvars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,20 @@ public void MatchZyDemoPath(CCSPlayerController? player, CommandInfo command)
}
}

[ConsoleCommand("matchzy_demo_format", "Format of demo filname")]
public void MatchZyDemoFormat(CCSPlayerController? player, CommandInfo command)
{
if (player != null) return;
if (command.ArgCount == 2)
{
string format = command.ArgByIndex(1);
demoFormat = format;
} else
{
Log($"{demoFormat}");
}
}

[ConsoleCommand("get5_demo_upload_url", "If defined, recorded demos will be uploaded to this URL once the map ends.")]
[ConsoleCommand("matchzy_demo_upload_url", "If defined, recorded demos will be uploaded to this URL once the map ends.")]
public void MatchZyDemoUploadURL(CCSPlayerController? player, CommandInfo command)
Expand Down
32 changes: 25 additions & 7 deletions DemoManagement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
using System.Net.Http.Json;
using System.Text;


namespace MatchZy
{
public partial class MatchZy
{
public string demoPath = "MatchZy/";
public string demoFormat = "{TIME}_{MATCH_ID}_{MAP}_{TEAM1}_{TEAM2}";
public string demoUploadURL = "";
public string demoUploadHeaderKey = "";
public string demoUploadHeaderValue = "";
Expand All @@ -23,8 +23,8 @@ public partial class MatchZy

public void StartDemoRecording()
{
string formattedTime = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss").Replace(" ", "_");
string demoFileName = $"{formattedTime}_{liveMatchId}_{Server.MapName}_{matchzyTeam1.teamName.Replace(" ", "_")}_vs_{matchzyTeam2.teamName.Replace(" ", "_")}";

string demoFileName = FormatDemoName();
try
{
string? directoryPath = Path.GetDirectoryName(Path.Join(Server.GameDirectory + "/csgo/", demoPath));
Expand Down Expand Up @@ -55,10 +55,13 @@ public void StopDemoRecording(float delay, string activeDemoFile, long liveMatch
{
Log($"[StopDemoRecording] Going to stop demorecording in {delay}s");
string demoPath = Path.Join(Server.GameDirectory + "/csgo/", activeDemoFile);
AddTimer(delay, () => {
AddTimer(delay, () =>
{
if (isDemoRecording) Server.ExecuteCommand($"tv_stoprecord");
AddTimer(15, () => {
Task.Run(async () => {
AddTimer(15, () =>
{
Task.Run(async () =>
{
await UploadDemoAsync(demoPath, liveMatchId, currentMapNumber);
});
});
Expand All @@ -82,7 +85,7 @@ public int GetTvDelay()

public async Task UploadDemoAsync(string? demoPath, long matchId, int mapNumber)
{
if (demoPath == null || demoUploadURL == "")
if (demoPath == null || demoUploadURL == "")
{
Log($"[UploadDemoAsync] Not able to upload demo, either demoPath or demoUploadURL is not set. demoPath: {demoPath} demoUploadURL: {demoUploadURL}");
}
Expand Down Expand Up @@ -137,6 +140,21 @@ public async Task UploadDemoAsync(string? demoPath, long matchId, int mapNumber)
}
}


private string FormatDemoName()
{
string formattedTime = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss");

var demoName = demoFormat
.Replace("{TIME}", formattedTime)
.Replace("{MATCH_ID}", $"{liveMatchId}")
.Replace("{MAP}", Server.MapName)
.Replace("{TEAM1}", matchzyTeam1.teamName)
.Replace("{TEAM2}", matchzyTeam2.teamName)
.Replace(" ", "_");
return $"{demoName}.dem";
}

[ConsoleCommand("get5_demo_upload_header_key", "If defined, a custom HTTP header with this name is added to the HTTP requests for demos")]
[ConsoleCommand("matchzy_demo_upload_header_key", "If defined, a custom HTTP header with this name is added to the HTTP requests for demos")]
public void DemoUploadHeaderKeyCommand(CCSPlayerController? player, CommandInfo command)
Expand Down
2 changes: 1 addition & 1 deletion Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ private void HandleMatchEnd() {
int currentMapNumber = matchConfig.CurrentMapNumber;
Log($"[HandleMatchEnd] MAP ENDED, isMatchSetup: {isMatchSetup} matchid: {liveMatchId} currentMapNumber: {currentMapNumber} tvFlushDelay: {tvFlushDelay}");

StopDemoRecording(tvFlushDelay - 0.5f, activeDemoFile + ".dem", liveMatchId, currentMapNumber);
StopDemoRecording(tvFlushDelay - 0.5f, activeDemoFile, liveMatchId, currentMapNumber);

string winnerName = GetMatchWinnerName();
(int t1score, int t2score) = GetTeamsScore();
Expand Down
4 changes: 4 additions & 0 deletions cfg/MatchZy/config.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ matchzy_minimum_ready_required 2
// A folder named MatchZy will be created in csgo folder if it does not exist and will store the recorded demos in it. Default value is MatchZy/ which means demos will be stored in MatchZy/
matchzy_demo_path MatchZy/

//Format of demo filname. You may use {TIME}, {MATCH_ID}, {MAP}, {TEAM1} and {TEAM2}
//Demo files will be named according to the format specified.
matchzy_demo_format {TIME}_{MATCH_ID}_{MAP}_{TEAM1}_{TEAM2}

// Whether !stop/.stop command is enabled by default or not. Default value: false
// Note: We are using Valve backup system to record and restore the backups. In most of the cases, this should be just fine.
// But in some cases, this may not be reliable hence default value is false
Expand Down
3 changes: 3 additions & 0 deletions documentation/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ Again, inside `csgo/cfg/MatchZy`, a file named `config.cfg` should be present. T
####`matchzy_demo_path`
: Path of folder in which demos will be saved. If defined, it must not start with a slash and must end with a slash. Set to empty string to use the csgo root. Example: `matchzy_demo_path MatchZy/`<br>**`Default: MatchZy/`**

####`matchzy_demo_format`
: Format of demo filname. You may use {TIME}, {MATCH_ID}, {MAP}, {TEAM1} and {TEAM2} . <br>**`Default: {TIME}_{MATCH_ID}_{MAP}_{TEAM1}_{TEAM2}`**

####`matchzy_demo_upload_url`
: If defined, recorded demo will be [uploaded](../gotv#automatic-upload) to this URL once the map ends. Make sure that the URL is wrapped in double quotes ("").
Example: `matchzy_demo_upload_url "https://your-website.com/upload-endpoint"` <br>**`Default: ""`**
Expand Down
2 changes: 2 additions & 0 deletions documentation/docs/gotv.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ MatchZy records the demos automatically. It recording starts once all teams have

Path of demos can be configured using `matchzy_demo_path <directory>/`. If defined, it must not start with a slash and must end with a slash. Set to empty string to use the csgo root.

Demo files will be named according to `matchzy_demo_format`. The default format is: `{TIME}_{MATCH_ID}_{MAP}_{TEAM1}_{TEAM2}`

!!! info "Broadcast delay on GOTV recording"

When the GOTV recording stops, the server will flush its framebuffer to disk. This may cause a lag spike or a
Expand Down

0 comments on commit c8cb1ef

Please sign in to comment.