@@ -121,7 +121,7 @@ private void HandleRestoreCommand(CCSPlayerController? player, string commandArg
121121 if ( ! string . IsNullOrWhiteSpace ( commandArg ) ) {
122122 if ( int . TryParse ( commandArg , out int roundNumber ) && roundNumber >= 0 ) {
123123 string round = roundNumber . ToString ( "D2" ) ;
124- string requiredBackupFileName = $ "matchzy_data_backup_ { liveMatchId } _{ matchConfig . CurrentMapNumber } _round_ { round } .json";
124+ string requiredBackupFileName = $ "matchzy_ { liveMatchId } _{ matchConfig . CurrentMapNumber } _round { round } .json";
125125 RestoreRoundBackup ( player , requiredBackupFileName ) ;
126126 }
127127 else {
@@ -186,6 +186,20 @@ private void RestoreRoundBackup(CCSPlayerController? player, string fileName) {
186186
187187 isRoundRestoring = true ;
188188
189+ // MatchID is set first to avoid generating a new one.
190+ if ( backupData . TryGetValue ( "matchid" , out var matchId ) )
191+ {
192+ liveMatchId = long . Parse ( matchId ) ;
193+ }
194+ if ( backupData . TryGetValue ( "match_loaded" , out var matchLoaded ) )
195+ {
196+ isMatchSetup = bool . Parse ( matchLoaded ) ;
197+ }
198+ if ( backupData . TryGetValue ( "match_config" , out var matchConfigValue ) )
199+ {
200+ matchConfig = Newtonsoft . Json . JsonConvert . DeserializeObject < MatchConfig > ( matchConfigValue ) ! ;
201+ SetupRoundBackupFile ( ) ;
202+ }
189203 if ( backupData . TryGetValue ( "map_name" , out var map_name ) )
190204 {
191205 if ( map_name != Server . MapName )
@@ -253,22 +267,18 @@ private void RestoreRoundBackup(CCSPlayerController? player, string fileName) {
253267 {
254268 gameRules . CTTimeOuts = int . Parse ( ctTimeouts ) ;
255269 }
256- if ( backupData . TryGetValue ( "matchid" , out var matchId ) )
257- {
258- liveMatchId = long . Parse ( matchId ) ;
259- }
260- if ( backupData . TryGetValue ( "match_loaded" , out var matchLoaded ) )
261- {
262- isMatchSetup = bool . Parse ( matchLoaded ) ;
263- }
264- if ( backupData . TryGetValue ( "match_config" , out var matchConfigValue ) )
265- {
266- matchConfig = Newtonsoft . Json . JsonConvert . DeserializeObject < MatchConfig > ( matchConfigValue ) ! ;
267- }
268270 if ( backupData . TryGetValue ( "valve_backup" , out var valveBackup ) )
269271 {
270- string tempFilePath = Path . Combine ( Server . GameDirectory , "csgo" , $ "{ fileName } .txt") ;
271- File . WriteAllText ( tempFilePath , valveBackup ) ;
272+ string tempFileName = fileName . Replace ( ".json" , ".txt" ) ;
273+ if ( backupData . TryGetValue ( "round" , out var roundNumber ) )
274+ {
275+ tempFileName = $ "matchzy_{ liveMatchId } _{ matchConfig . CurrentMapNumber } _round{ roundNumber } ";
276+ }
277+ string tempFilePath = Path . Combine ( Server . GameDirectory , "csgo" , tempFileName ) ;
278+ if ( ! File . Exists ( tempFilePath ) )
279+ {
280+ File . WriteAllText ( tempFilePath , valveBackup ) ;
281+ }
272282 int restoreTimer = liveSetupRequired ? 2 : 0 ;
273283 if ( liveSetupRequired )
274284 {
@@ -279,7 +289,7 @@ private void RestoreRoundBackup(CCSPlayerController? player, string fileName) {
279289 Server . ExecuteCommand ( $ "mp_backup_restore_load_file { tempFilePath } ") ;
280290 StartDemoRecording ( ) ;
281291 } ) ;
282- AddTimer ( 5 , ( ) => File . Delete ( tempFilePath ) ) ;
292+ // AddTimer(5, () => File.Delete(tempFilePath));
283293 }
284294 }
285295 catch ( Exception e ) {
@@ -307,7 +317,7 @@ public void CreateMatchZyRoundDataBackup()
307317 ( int t1score , int t2score ) = GetTeamsScore ( ) ;
308318 int roundNumber = t1score + t2score ;
309319 string round = roundNumber . ToString ( "D2" ) ;
310- string matchZyBackupFileName = $ "matchzy_data_backup_ { liveMatchId } _{ matchConfig . CurrentMapNumber } _round_ { round } .json";
320+ string matchZyBackupFileName = $ "matchzy_ { liveMatchId } _{ matchConfig . CurrentMapNumber } _round { round } .json";
311321 string filePath = Server . GameDirectory + "/csgo/MatchZyDataBackup/" + matchZyBackupFileName ;
312322 string ? directoryPath = Path . GetDirectoryName ( filePath ) ;
313323 if ( directoryPath != null && ! Directory . Exists ( directoryPath ) )
@@ -379,7 +389,7 @@ public List<string> GetBackups(string matchID)
379389 var directoryInfo = new DirectoryInfo ( backupDir ) ;
380390 var files = directoryInfo . GetFiles ( ) ;
381391
382- var pattern = $ "matchzy_data_backup_ { matchID } _";
392+ var pattern = $ "matchzy_ { matchID } _";
383393 var backups = new List < string > ( ) ;
384394
385395 foreach ( var file in files )
0 commit comments