forked from shobhit-pathak/MatchZy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDemoManagement.cs
43 lines (37 loc) · 1.53 KB
/
DemoManagement.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using CounterStrikeSharp.API;
namespace MatchZy
{
public partial class MatchZy
{
public string demoPath = "MatchZy/";
public void StartDemoRecording()
{
string formattedTime = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss").Replace(" ", "_");
string demoFileName = $"{formattedTime}_{liveMatchId}_{Server.MapName}_{CT_TEAM_NAME.Replace(" ", "_")}_vs_{T_TEAM_NAME.Replace(" ", "_")}";
try
{
string? directoryPath = Path.GetDirectoryName(Path.Join(Server.GameDirectory + "/csgo/", demoPath));
if (directoryPath != null)
{
if (!Directory.Exists(directoryPath))
{
Directory.CreateDirectory(directoryPath);
}
}
string tempDemoPath = demoPath == "" ? demoFileName : demoPath + demoFileName;
Log($"[StartDemoRecoding] Starting demo recording, path: {tempDemoPath}");
Server.ExecuteCommand($"tv_record {tempDemoPath}");
}
catch (Exception ex)
{
Log($"[StartDemoRecording - FATAL] Error: {ex.Message}. Starting demo recording with path. Name: {demoFileName}");
// This is to avoid demo loss in any case of exception
Server.ExecuteCommand($"tv_record {demoFileName}");
}
}
public void StopDemoRecording()
{
Server.ExecuteCommand($"tv_stoprecord");
}
}
}