Skip to content

Commit 5612d8e

Browse files
mariokeksrtldg
authored andcommitted
Add admin commands !playreplayfile & !replayfileinfo
1 parent a4e9e6d commit 5612d8e

2 files changed

Lines changed: 85 additions & 0 deletions

File tree

addons/sourcemod/scripting/shavit-replay-playback.sp

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,8 @@ public void OnPluginStart()
483483

484484
// commands
485485
RegAdminCmd("sm_deletereplay", Command_DeleteReplay, ADMFLAG_RCON, "Open replay deletion menu.");
486+
RegAdminCmd("sm_playreplayfile", Command_PlayReplayFile, ADMFLAG_RCON, "Start a replay from file. Usage: sm_playreplayfile <path>");
487+
RegAdminCmd("sm_replayfileinfo", Command_ReplayFileInfo, ADMFLAG_RCON, "Prints a replay-file's header to console. Usage: sm_replayfileinfo <path>");
486488
RegConsoleCmd("sm_replay", Command_Replay, "Opens the central bot menu. For admins: 'sm_replay stop' to stop the playback.");
487489

488490
// database
@@ -2886,6 +2888,75 @@ public void Shavit_OnWRDeleted(int style, int id, int track, int accountid, cons
28862888
DeleteReplay(style, track, accountid, mapname);
28872889
}
28882890

2891+
Action Command_ReplayFileInfo(int client, int args)
2892+
{
2893+
if(args == 0)
2894+
{
2895+
Shavit_PrintToChat(client, "%T", "ArgumentsMissing", client, "sm_replayfileinfo <path>");
2896+
return Plugin_Handled;
2897+
}
2898+
2899+
char sPath[PLATFORM_MAX_PATH];
2900+
GetCmdArgString(sPath, sizeof(sPath));
2901+
2902+
if(!FileExists(sPath))
2903+
{
2904+
Shavit_PrintToChat(client, "%T", "ReplayFileNotFound", client, sPath);
2905+
return Plugin_Handled;
2906+
}
2907+
2908+
replay_header_t aHeader;
2909+
File hFile = ReadReplayHeader(sPath, aHeader, -1, -1);
2910+
if(hFile == null)
2911+
{
2912+
Shavit_PrintToChat(client, "%T", "FailedToReadReplayHeader", client);
2913+
return Plugin_Handled;
2914+
}
2915+
delete hFile;
2916+
2917+
int iFileSize = FileSize(sPath);
2918+
2919+
PrintToConsole(client, "%T", "ReplayFileInfo", client, sPath, iFileSize,
2920+
aHeader.sReplayFormat, aHeader.iReplayVersion, aHeader.sMap, aHeader.iStyle, aHeader.iTrack, aHeader.iPreFrames, aHeader.iFrameCount,
2921+
aHeader.fTime, aHeader.iSteamID, aHeader.iPostFrames, aHeader.fTickrate, aHeader.fZoneOffset[0], aHeader.fZoneOffset[1], aHeader.iTimestamp);
2922+
2923+
return Plugin_Handled;
2924+
}
2925+
2926+
Action Command_PlayReplayFile(int client, int args)
2927+
{
2928+
if(args == 0)
2929+
{
2930+
Shavit_PrintToChat(client, "%T", "ArgumentsMissing", client, "sm_playreplayfile <path>");
2931+
return Plugin_Handled;
2932+
}
2933+
2934+
char sPath[PLATFORM_MAX_PATH];
2935+
GetCmdArgString(sPath, sizeof(sPath));
2936+
2937+
if(!FileExists(sPath))
2938+
{
2939+
Shavit_PrintToChat(client, "%T", "ReplayFileNotFound", client, sPath);
2940+
return Plugin_Handled;
2941+
}
2942+
2943+
replay_header_t aHeader;
2944+
File hFile = ReadReplayHeader(sPath, aHeader);
2945+
if(hFile == null)
2946+
{
2947+
Shavit_PrintToChat(client, "%T", "FailedToReadHeader", client);
2948+
return Plugin_Handled;
2949+
}
2950+
delete hFile;
2951+
2952+
if(Shavit_StartReplayFromFile(aHeader.iStyle, aHeader.iTrack, -1.0, client, -1, Replay_Dynamic, true, sPath) == 0)
2953+
{
2954+
Shavit_PrintToChat(client, "%T", "FailedToCreateReplay", client);
2955+
}
2956+
2957+
return Plugin_Handled;
2958+
}
2959+
28892960
public Action Command_DeleteReplay(int client, int args)
28902961
{
28912962
if(!IsValidClient(client))

addons/sourcemod/translations/shavit-replay.phrases.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
"Phrases"
22
{
3+
"ReplayFileInfo"
4+
{
5+
"#format" "{1:s},{2:d},{3:s},{4:0x},{5:s},{6:d},{7:d},{8:d},{9:d},{10:f},{11:u},{12:d},{13:f},{14:f},{15:f},{16:d}"
6+
"en" "File: {1} ({2} Bytes)\nFormat: {3}\nVersion: {4}\nMap: {5}\nStyle: {6}\nTrack: {7}\nPreframes: {8}\nFramecount: {9}\nTime: {10}\nAccountID: {11}\nPostframes: {12}\nTickrate: {13}\nZoneoffsets: {14}/{15}\nTimestamp: {16}"
7+
}
8+
"ReplayFileNotFound"
9+
{
10+
"#format" "{1:s}"
11+
"en" "File not found. ({1})"
12+
}
13+
"FailedToReadReplayHeader"
14+
{
15+
"en" "Failed to read replay header."
16+
}
317
// ---------- Menus ---------- //
418
"DeleteReplayAdminMenu"
519
{

0 commit comments

Comments
 (0)