Skip to content

Commit

Permalink
0.8.3: backup/restore fix, live.cfg update
Browse files Browse the repository at this point in the history
  • Loading branch information
shobhit-pathak committed Aug 25, 2024
1 parent d90e49c commit b91bb6b
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 29 deletions.
46 changes: 28 additions & 18 deletions BackupManagement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ private void HandleRestoreCommand(CCSPlayerController? player, string commandArg
if (!string.IsNullOrWhiteSpace(commandArg)) {
if (int.TryParse(commandArg, out int roundNumber) && roundNumber >= 0) {
string round = roundNumber.ToString("D2");
string requiredBackupFileName = $"matchzy_data_backup_{liveMatchId}_{matchConfig.CurrentMapNumber}_round_{round}.json";
string requiredBackupFileName = $"matchzy_{liveMatchId}_{matchConfig.CurrentMapNumber}_round{round}.json";
RestoreRoundBackup(player, requiredBackupFileName);
}
else {
Expand Down Expand Up @@ -186,6 +186,20 @@ private void RestoreRoundBackup(CCSPlayerController? player, string fileName) {

isRoundRestoring = true;

// MatchID is set first to avoid generating a new one.
if (backupData.TryGetValue("matchid", out var matchId))
{
liveMatchId = long.Parse(matchId);
}
if (backupData.TryGetValue("match_loaded", out var matchLoaded))
{
isMatchSetup = bool.Parse(matchLoaded);
}
if (backupData.TryGetValue("match_config", out var matchConfigValue))
{
matchConfig = Newtonsoft.Json.JsonConvert.DeserializeObject<MatchConfig>(matchConfigValue)!;
SetupRoundBackupFile();
}
if (backupData.TryGetValue("map_name", out var map_name))
{
if (map_name != Server.MapName)
Expand Down Expand Up @@ -253,22 +267,18 @@ private void RestoreRoundBackup(CCSPlayerController? player, string fileName) {
{
gameRules.CTTimeOuts = int.Parse(ctTimeouts);
}
if (backupData.TryGetValue("matchid", out var matchId))
{
liveMatchId = long.Parse(matchId);
}
if (backupData.TryGetValue("match_loaded", out var matchLoaded))
{
isMatchSetup = bool.Parse(matchLoaded);
}
if (backupData.TryGetValue("match_config", out var matchConfigValue))
{
matchConfig = Newtonsoft.Json.JsonConvert.DeserializeObject<MatchConfig>(matchConfigValue)!;
}
if (backupData.TryGetValue("valve_backup", out var valveBackup))
{
string tempFilePath = Path.Combine(Server.GameDirectory, "csgo", $"{fileName}.txt");
File.WriteAllText(tempFilePath, valveBackup);
string tempFileName = fileName.Replace(".json", ".txt");
if (backupData.TryGetValue("round", out var roundNumber))
{
tempFileName = $"matchzy_{liveMatchId}_{matchConfig.CurrentMapNumber}_round{roundNumber}";
}
string tempFilePath = Path.Combine(Server.GameDirectory, "csgo", tempFileName);
if (!File.Exists(tempFilePath))
{
File.WriteAllText(tempFilePath, valveBackup);
}
int restoreTimer = liveSetupRequired ? 2 : 0;
if (liveSetupRequired)
{
Expand All @@ -279,7 +289,7 @@ private void RestoreRoundBackup(CCSPlayerController? player, string fileName) {
Server.ExecuteCommand($"mp_backup_restore_load_file {tempFilePath}");
StartDemoRecording();
});
AddTimer(5, () => File.Delete(tempFilePath));
// AddTimer(5, () => File.Delete(tempFilePath));
}
}
catch (Exception e) {
Expand Down Expand Up @@ -307,7 +317,7 @@ public void CreateMatchZyRoundDataBackup()
(int t1score, int t2score) = GetTeamsScore();
int roundNumber = t1score + t2score;
string round = roundNumber.ToString("D2");
string matchZyBackupFileName = $"matchzy_data_backup_{liveMatchId}_{matchConfig.CurrentMapNumber}_round_{round}.json";
string matchZyBackupFileName = $"matchzy_{liveMatchId}_{matchConfig.CurrentMapNumber}_round{round}.json";
string filePath = Server.GameDirectory + "/csgo/MatchZyDataBackup/" + matchZyBackupFileName;
string? directoryPath = Path.GetDirectoryName(filePath);
if (directoryPath != null && !Directory.Exists(directoryPath))
Expand Down Expand Up @@ -379,7 +389,7 @@ public List<string> GetBackups(string matchID)
var directoryInfo = new DirectoryInfo(backupDir);
var files = directoryInfo.GetFiles();

var pattern = $"matchzy_data_backup_{matchID}_";
var pattern = $"matchzy_{matchID}_";
var backups = new List<string>();

foreach (var file in files)
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# MatchZy Changelog

# 0.8.3

#### August 25, 2024

- Fixed issues with backup restore where `.restore` command would show as round restored, but nothing happened. (Improved file naming and backup saving logic)
- Updated live.cfg as per new rules (mp_team_timeout_max 3; mp_team_timeout_ot_max 1; mp_team_timeout_ot_add_each 1)
- Added css_globalnades alias (!globalnades) for css_save_nades_as_global / .globalnades

# 0.8.2

#### August 25, 2024
Expand Down
1 change: 1 addition & 0 deletions ConsoleCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public void OnWLCommand(CCSPlayerController? player, CommandInfo? command)
}

[ConsoleCommand("css_save_nades_as_global", "Toggles Global Lineups for players")]
[ConsoleCommand("css_globalnades", "Toggles Global Lineups for players")]
public void OnSaveNadesAsGlobalCommand(CCSPlayerController? player, CommandInfo? command)
{
if (IsPlayerAdmin(player, "css_save_nades_as_global", "@css/config"))
Expand Down
2 changes: 1 addition & 1 deletion MatchZy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public partial class MatchZy : BasePlugin
{

public override string ModuleName => "MatchZy";
public override string ModuleVersion => "0.8.2";
public override string ModuleVersion => "0.8.3";

public override string ModuleAuthor => "WD- (https://github.com/shobhit-pathak/)";

Expand Down
2 changes: 1 addition & 1 deletion PracticeMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1245,7 +1245,7 @@ public void ExecDryRunCFG()
} else {
Log($"[ExecDryRunCFG] Starting Dryrun! Dryrun CFG not found in {absolutePath}, using default CFG!");
Server.ExecuteCommand("ammo_grenade_limit_default 1;ammo_grenade_limit_flashbang 2;ammo_grenade_limit_total 4;bot_quota 0;cash_player_bomb_defused 300;cash_player_bomb_planted 300;cash_player_damage_hostage -30;cash_player_interact_with_hostage 300;cash_player_killed_enemy_default 300;cash_player_killed_enemy_factor 1;cash_player_killed_hostage -1000;cash_player_killed_teammate -300;cash_player_rescued_hostage 1000;cash_team_elimination_bomb_map 3250;cash_team_elimination_hostage_map_ct 3000;cash_team_elimination_hostage_map_t 3000;cash_team_hostage_alive 0;cash_team_hostage_interaction 600;cash_team_loser_bonus 1400;cash_team_loser_bonus_consecutive_rounds 500;cash_team_planted_bomb_but_defused 600;cash_team_rescued_hostage 600;cash_team_terrorist_win_bomb 3500;cash_team_win_by_defusing_bomb 3500;");
Server.ExecuteCommand("cash_team_win_by_hostage_rescue 2900;cash_team_win_by_time_running_out_bomb 3250;cash_team_win_by_time_running_out_hostage 3250;ff_damage_reduction_bullets 0.33;ff_damage_reduction_grenade 0.85;ff_damage_reduction_grenade_self 1;ff_damage_reduction_other 0.4;mp_afterroundmoney 0;mp_autokick 0;mp_autoteambalance 0;mp_backup_restore_load_autopause 1;mp_backup_round_auto 1;mp_buy_anywhere 0;mp_buy_during_immunity 0;mp_buytime 20;mp_c4timer 40;mp_ct_default_melee weapon_knife;mp_ct_default_primary \"\";mp_ct_default_secondary weapon_hkp2000;mp_death_drop_defuser 1;mp_death_drop_grenade 2;mp_death_drop_gun 1;mp_defuser_allocation 0;mp_display_kill_assists 1;mp_endmatch_votenextmap 0;mp_forcecamera 1;mp_free_armor 0;mp_freezetime 6;mp_friendlyfire 1;mp_give_player_c4 1;mp_halftime 1;mp_halftime_duration 15;mp_halftime_pausetimer 0;mp_ignore_round_win_conditions 0;mp_limitteams 0;mp_match_can_clinch 1;mp_match_end_restart 0;mp_maxmoney 16000;mp_maxrounds 24;mp_overtime_enable 1;mp_overtime_halftime_pausetimer 0;mp_overtime_maxrounds 6;mp_overtime_startmoney 10000;mp_playercashawards 1;mp_randomspawn 0;mp_respawn_immunitytime 0;mp_respawn_on_death_ct 0;mp_respawn_on_death_t 0;mp_round_restart_delay 5;mp_roundtime 1.92;mp_roundtime_defuse 1.92;mp_roundtime_hostage 1.92;mp_solid_teammates 1;mp_starting_losses 1;mp_startmoney 16000;mp_t_default_melee weapon_knife;mp_t_default_primary \"\";mp_t_default_secondary weapon_glock;mp_teamcashawards 1;mp_timelimit 0;mp_weapons_allow_map_placed 1;mp_weapons_allow_zeus 1;mp_win_panel_display_time 3;spec_freeze_deathanim_time 0;spec_freeze_time 2;spec_freeze_time_lock 2;spec_replay_enable 0;sv_allow_votes 1;sv_auto_full_alltalk_during_warmup_half_end 0;sv_damage_print_enable 0;sv_deadtalk 1;sv_hibernate_postgame_delay 300;sv_ignoregrenaderadio 0;sv_infinite_ammo 0;sv_talk_enemy_dead 0;sv_talk_enemy_living 0;sv_voiceenable 1;tv_relayvoice 1;mp_team_timeout_max 4;mp_team_timeout_time 30;sv_vote_command_delay 0;cash_team_bonus_shorthanded 0;mp_spectators_max 20;mp_team_intro_time 0;mp_restartgame 3;mp_warmup_end;");
Server.ExecuteCommand("cash_team_win_by_hostage_rescue 2900;cash_team_win_by_time_running_out_bomb 3250;cash_team_win_by_time_running_out_hostage 3250;ff_damage_reduction_bullets 0.33;ff_damage_reduction_grenade 0.85;ff_damage_reduction_grenade_self 1;ff_damage_reduction_other 0.4;mp_afterroundmoney 0;mp_autokick 0;mp_autoteambalance 0;mp_backup_restore_load_autopause 1;mp_backup_round_auto 1;mp_buy_anywhere 0;mp_buy_during_immunity 0;mp_buytime 20;mp_c4timer 40;mp_ct_default_melee weapon_knife;mp_ct_default_primary \"\";mp_ct_default_secondary weapon_hkp2000;mp_death_drop_defuser 1;mp_death_drop_grenade 2;mp_death_drop_gun 1;mp_defuser_allocation 0;mp_display_kill_assists 1;mp_endmatch_votenextmap 0;mp_forcecamera 1;mp_free_armor 0;mp_freezetime 6;mp_friendlyfire 1;mp_give_player_c4 1;mp_halftime 1;mp_halftime_duration 15;mp_halftime_pausetimer 0;mp_ignore_round_win_conditions 0;mp_limitteams 0;mp_match_can_clinch 1;mp_match_end_restart 0;mp_maxmoney 16000;mp_maxrounds 24;mp_overtime_enable 1;mp_overtime_halftime_pausetimer 0;mp_overtime_maxrounds 6;mp_overtime_startmoney 10000;mp_playercashawards 1;mp_randomspawn 0;mp_respawn_immunitytime 0;mp_respawn_on_death_ct 0;mp_respawn_on_death_t 0;mp_round_restart_delay 5;mp_roundtime 1.92;mp_roundtime_defuse 1.92;mp_roundtime_hostage 1.92;mp_solid_teammates 1;mp_starting_losses 1;mp_startmoney 16000;mp_t_default_melee weapon_knife;mp_t_default_primary \"\";mp_t_default_secondary weapon_glock;mp_teamcashawards 1;mp_timelimit 0;mp_weapons_allow_map_placed 1;mp_weapons_allow_zeus 1;mp_win_panel_display_time 3;spec_freeze_deathanim_time 0;spec_freeze_time 2;spec_freeze_time_lock 2;spec_replay_enable 0;sv_allow_votes 1;sv_auto_full_alltalk_during_warmup_half_end 0;sv_damage_print_enable 0;sv_deadtalk 1;sv_hibernate_postgame_delay 300;sv_ignoregrenaderadio 0;sv_infinite_ammo 0;sv_talk_enemy_dead 0;sv_talk_enemy_living 0;sv_voiceenable 1;tv_relayvoice 1;mp_team_timeout_max 3;mp_team_timeout_ot_max 1;mp_team_timeout_ot_add_each 1;mp_team_timeout_time 30;sv_vote_command_delay 0;cash_team_bonus_shorthanded 0;mp_spectators_max 20;mp_team_intro_time 0;mp_restartgame 3;mp_warmup_end;");
}
}

Expand Down
6 changes: 3 additions & 3 deletions Teams.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ public void OnAddPlayerCommand(CCSPlayerController? player, CommandInfo? command
command.ReplyToCommand($"Player {playerName} added to {playerTeam} successfully!");
}

[ConsoleCommand("matchzy_removeplayer", "Adds player to the provided team")]
[ConsoleCommand("get5_removeplayer", "Adds player to the provided team")]
[ConsoleCommand("matchzy_removeplayer", "Removes the player from all the teams")]
[ConsoleCommand("get5_removeplayer", "Removes the player from all the teams")]
[CommandHelper(minArgs: 1, usage: "<steam64>")]
public void OnRemovePlayerCommand(CCSPlayerController? player, CommandInfo? command)
{
Expand All @@ -127,7 +127,7 @@ public void OnRemovePlayerCommand(CCSPlayerController? player, CommandInfo? comm
}
if (IsHalfTimePhase())
{
command.ReplyToCommand("Cannot add players during halftime. Please wait until the next round starts.");
command.ReplyToCommand("Cannot remove players during halftime. Please wait until the next round starts.");
return;
}

Expand Down
6 changes: 3 additions & 3 deletions Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ private void StartLive()

// Storing 0-0 score backup file as lastBackupFileName, so that .stop functions properly in first round.
lastBackupFileName = $"matchzy_{liveMatchId}_{matchConfig.CurrentMapNumber}_round00.txt";
lastMatchZyBackupFileName = $"matchzy_data_backup_{liveMatchId}_{matchConfig.CurrentMapNumber}_round_00.json";
lastMatchZyBackupFileName = $"matchzy_{liveMatchId}_{matchConfig.CurrentMapNumber}_round00.json";

// This is to reload the map once it is over so that all flags are reset accordingly
Server.ExecuteCommand("mp_match_end_restart true");
Expand Down Expand Up @@ -1047,7 +1047,7 @@ private void HandlePostRoundEndEvent(EventRoundEnd @event)

string round = GetRoundNumer().ToString("D2");
lastBackupFileName = $"matchzy_{liveMatchId}_{matchConfig.CurrentMapNumber}_round{round}.txt";
lastMatchZyBackupFileName = $"matchzy_data_backup_{liveMatchId}_{matchConfig.CurrentMapNumber}_round_{round}.json";
lastMatchZyBackupFileName = $"matchzy_{liveMatchId}_{matchConfig.CurrentMapNumber}_round{round}.json";
Log($"[HandlePostRoundEndEvent] Setting lastBackupFileName to {lastBackupFileName} and lastMatchZyBackupFileName to {lastMatchZyBackupFileName}");

// One of the team did not use .stop command hence display the proper message after the round has ended.
Expand Down Expand Up @@ -1305,7 +1305,7 @@ private void ExecLiveCFG()
else
{
Server.ExecuteCommand("ammo_grenade_limit_default 1;ammo_grenade_limit_flashbang 2;ammo_grenade_limit_total 4;bot_quota 0;cash_player_bomb_defused 300;cash_player_bomb_planted 300;cash_player_damage_hostage -30;cash_player_interact_with_hostage 300;cash_player_killed_enemy_default 300;cash_player_killed_enemy_factor 1;cash_player_killed_hostage -1000;cash_player_killed_teammate -300;cash_player_rescued_hostage 1000;cash_team_elimination_bomb_map 3250;cash_team_elimination_hostage_map_ct 3000;cash_team_elimination_hostage_map_t 3000;cash_team_hostage_alive 0;cash_team_hostage_interaction 600;cash_team_loser_bonus 1400;cash_team_loser_bonus_consecutive_rounds 500;cash_team_planted_bomb_but_defused 600;cash_team_rescued_hostage 600;cash_team_terrorist_win_bomb 3500;cash_team_win_by_defusing_bomb 3500;");
Server.ExecuteCommand("cash_team_win_by_hostage_rescue 2900;cash_team_win_by_time_running_out_bomb 3250;cash_team_win_by_time_running_out_hostage 3250;ff_damage_reduction_bullets 0.33;ff_damage_reduction_grenade 0.85;ff_damage_reduction_grenade_self 1;ff_damage_reduction_other 0.4;mp_afterroundmoney 0;mp_autokick 0;mp_autoteambalance 0;mp_backup_restore_load_autopause 1;mp_backup_round_auto 1;mp_buy_anywhere 0;mp_buy_during_immunity 0;mp_buytime 20;mp_c4timer 40;mp_ct_default_melee weapon_knife;mp_ct_default_primary \"\";mp_ct_default_secondary weapon_hkp2000;mp_death_drop_defuser 1;mp_death_drop_grenade 2;mp_death_drop_gun 1;mp_defuser_allocation 0;mp_display_kill_assists 1;mp_endmatch_votenextmap 0;mp_forcecamera 1;mp_free_armor 0;mp_freezetime 18;mp_friendlyfire 1;mp_give_player_c4 1;mp_halftime 1;mp_halftime_duration 15;mp_halftime_pausetimer 0;mp_ignore_round_win_conditions 0;mp_limitteams 0;mp_match_can_clinch 1;mp_match_end_restart 0;mp_maxmoney 16000;mp_maxrounds 24;mp_overtime_enable 1;mp_overtime_halftime_pausetimer 0;mp_overtime_maxrounds 6;mp_overtime_startmoney 10000;mp_playercashawards 1;mp_randomspawn 0;mp_respawn_immunitytime 0;mp_respawn_on_death_ct 0;mp_respawn_on_death_t 0;mp_round_restart_delay 5;mp_roundtime 1.92;mp_roundtime_defuse 1.92;mp_roundtime_hostage 1.92;mp_solid_teammates 1;mp_starting_losses 1;mp_startmoney 800;mp_t_default_melee weapon_knife;mp_t_default_primary \"\";mp_t_default_secondary weapon_glock;mp_teamcashawards 1;mp_timelimit 0;mp_weapons_allow_map_placed 1;mp_weapons_allow_zeus 1;mp_win_panel_display_time 3;spec_freeze_deathanim_time 0;spec_freeze_time 2;spec_freeze_time_lock 2;spec_replay_enable 0;sv_allow_votes 1;sv_auto_full_alltalk_during_warmup_half_end 0;sv_damage_print_enable 0;sv_deadtalk 1;sv_hibernate_postgame_delay 300;sv_ignoregrenaderadio 0;sv_infinite_ammo 0;sv_talk_enemy_dead 0;sv_talk_enemy_living 0;sv_voiceenable 1;tv_relayvoice 1;mp_team_timeout_max 4;mp_team_timeout_time 30;sv_vote_command_delay 0;cash_team_bonus_shorthanded 0;mp_spectators_max 20;mp_team_intro_time 0;mp_restartgame 3;mp_warmup_end;");
Server.ExecuteCommand("cash_team_win_by_hostage_rescue 2900;cash_team_win_by_time_running_out_bomb 3250;cash_team_win_by_time_running_out_hostage 3250;ff_damage_reduction_bullets 0.33;ff_damage_reduction_grenade 0.85;ff_damage_reduction_grenade_self 1;ff_damage_reduction_other 0.4;mp_afterroundmoney 0;mp_autokick 0;mp_autoteambalance 0;mp_backup_restore_load_autopause 1;mp_backup_round_auto 1;mp_buy_anywhere 0;mp_buy_during_immunity 0;mp_buytime 20;mp_c4timer 40;mp_ct_default_melee weapon_knife;mp_ct_default_primary \"\";mp_ct_default_secondary weapon_hkp2000;mp_death_drop_defuser 1;mp_death_drop_grenade 2;mp_death_drop_gun 1;mp_defuser_allocation 0;mp_display_kill_assists 1;mp_endmatch_votenextmap 0;mp_forcecamera 1;mp_free_armor 0;mp_freezetime 18;mp_friendlyfire 1;mp_give_player_c4 1;mp_halftime 1;mp_halftime_duration 15;mp_halftime_pausetimer 0;mp_ignore_round_win_conditions 0;mp_limitteams 0;mp_match_can_clinch 1;mp_match_end_restart 0;mp_maxmoney 16000;mp_maxrounds 24;mp_overtime_enable 1;mp_overtime_halftime_pausetimer 0;mp_overtime_maxrounds 6;mp_overtime_startmoney 10000;mp_playercashawards 1;mp_randomspawn 0;mp_respawn_immunitytime 0;mp_respawn_on_death_ct 0;mp_respawn_on_death_t 0;mp_round_restart_delay 5;mp_roundtime 1.92;mp_roundtime_defuse 1.92;mp_roundtime_hostage 1.92;mp_solid_teammates 1;mp_starting_losses 1;mp_startmoney 800;mp_t_default_melee weapon_knife;mp_t_default_primary \"\";mp_t_default_secondary weapon_glock;mp_teamcashawards 1;mp_timelimit 0;mp_weapons_allow_map_placed 1;mp_weapons_allow_zeus 1;mp_win_panel_display_time 3;spec_freeze_deathanim_time 0;spec_freeze_time 2;spec_freeze_time_lock 2;spec_replay_enable 0;sv_allow_votes 1;sv_auto_full_alltalk_during_warmup_half_end 0;sv_damage_print_enable 0;sv_deadtalk 1;sv_hibernate_postgame_delay 300;sv_ignoregrenaderadio 0;sv_infinite_ammo 0;sv_talk_enemy_dead 0;sv_talk_enemy_living 0;sv_voiceenable 1;tv_relayvoice 1;mp_team_timeout_max 3;mp_team_timeout_ot_max 1;mp_team_timeout_ot_add_each 1;mp_team_timeout_time 30;sv_vote_command_delay 0;cash_team_bonus_shorthanded 0;mp_spectators_max 20;mp_team_intro_time 0;mp_restartgame 3;mp_warmup_end;");
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion cfg/MatchZy/dryrun.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,10 @@ sv_talk_enemy_dead 0
sv_talk_enemy_living 0
sv_voiceenable 1
tv_relayvoice 1
mp_team_timeout_max 4
mp_team_timeout_max 3
mp_team_timeout_time 30
mp_team_timeout_ot_max 1
mp_team_timeout_ot_add_each 1
sv_vote_command_delay 0
cash_team_bonus_shorthanded 0
mp_spectators_max 20
Expand Down
4 changes: 3 additions & 1 deletion cfg/MatchZy/live.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,10 @@ sv_talk_enemy_dead 0
sv_talk_enemy_living 0
sv_voiceenable 1
tv_relayvoice 1
mp_team_timeout_max 4
mp_team_timeout_max 3
mp_team_timeout_time 30
mp_team_timeout_ot_max 1
mp_team_timeout_ot_add_each 1
sv_vote_command_delay 0
cash_team_bonus_shorthanded 0
mp_spectators_max 20
Expand Down
Loading

0 comments on commit b91bb6b

Please sign in to comment.