Skip to content

Commit

Permalink
0.7.7 | Wingman support and optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
shobhit-pathak committed Apr 29, 2024
1 parent b632a74 commit 714c3d7
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 32 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# MatchZy Changelog

# 0.7.7

#### April 29, 2024

- Added wingman support. Now, if `game_mode` is 2, plugin will automatically execute `live_wingman.cfg`. If `game_mode` is 1, `live.cfg` will be executed.
- Setting `wingman` as `true` in match config json will now automatically set `game_mode 2` and reload the map. Wingman toggle from G5V will now also work.
- Removed `UpdatePlayersMap` from player connect and disconnect methods to avoid it getting called multiple times on map change.
- Made `SetMatchEndData` to be an async operation.
- Added updated pt-PT translations.

# 0.7.6

#### April 28, 2024
Expand Down
4 changes: 2 additions & 2 deletions DatabaseStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ UPDATE matchzy_stats_matches
}
}

public void SetMatchEndData(long matchId, string winnerName, int t1score, int t2score)
public async Task SetMatchEndData(long matchId, string winnerName, int t1score, int t2score)
{
try
{
Expand All @@ -340,7 +340,7 @@ UPDATE matchzy_stats_matches
SET winner = @winnerName, end_time = {dateTimeExpression}, team1_score = @t1score, team2_score = @t2score
WHERE matchid = @matchId";

connection.Execute(sqlQuery, new { matchId, winnerName, t1score, t2score });
await connection.ExecuteAsync(sqlQuery, new { matchId, winnerName, t1score, t2score });

Log($"[SetMatchEndData] Data updated for matchId: {matchId} winnerName: {winnerName}");
}
Expand Down
3 changes: 2 additions & 1 deletion EventHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ public HookResult EventPlayerConnectFullHandler(EventPlayerConnectFull @event, G
}
}
// May not be required, but just to be on safe side so that player data is properly updated in dictionaries
UpdatePlayersMap();
// Update: Commenting the below function as it was being called multiple times on map change.
// UpdatePlayersMap();

if (readyAvailable && !matchStarted)
{
Expand Down
35 changes: 19 additions & 16 deletions MatchManagement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ static string ValidateMatchJsonStructure(JObject jsonData)

case "skip_veto":
case "clinch_series":
case "wingman":
if (!bool.TryParse(jsonData[field]!.ToString(), out bool result))
{
return $"{field} should be a boolean!";
Expand Down Expand Up @@ -338,18 +339,13 @@ public bool LoadMatchFromJSON(string jsonData)
}
}
}
string currentMapName = Server.MapName;
string mapName = matchConfig.Maplist[0].ToString();

if (long.TryParse(mapName, out _)) {
Server.ExecuteCommand($"bot_kick");
Server.ExecuteCommand($"host_workshop_map \"{mapName}\"");
} else if (Server.IsMapValid(mapName)) {
Server.ExecuteCommand($"bot_kick");
Server.ExecuteCommand($"changelevel \"{mapName}\"");
} else {
Log($"[LoadMatchFromJSON] Invalid map name: {mapName}, cannot setup match!");
ResetMatch(false);
return false;
if (IsMapReloadRequiredForGameMode(matchConfig.Wingman) || mapReloadRequired || currentMapName != mapName)
{
SetCorrectGameMode();
ChangeMap(mapName, 0);
}
}
else
Expand Down Expand Up @@ -481,6 +477,10 @@ public void GetOptionalMatchValues(JObject jsonDataObject)
{
matchConfig.SkipVeto = bool.Parse(jsonDataObject["skip_veto"]!.ToString());
}
if (jsonDataObject["wingman"] != null)
{
matchConfig.Wingman = bool.Parse(jsonDataObject["wingman"]!.ToString());
}
if (jsonDataObject["veto_mode"] != null)
{
matchConfig.MapBanOrder = jsonDataObject["veto_mode"]!.ToObject<List<string>>()!;
Expand Down Expand Up @@ -569,8 +569,10 @@ private CsTeam GetPlayerTeam(CCSPlayerController player)
return playerTeam;
}

public void EndSeries(string? winnerName, int restartDelay)
public void EndSeries(string? winnerName, int restartDelay, int t1score, int t2score)
{
long matchId = liveMatchId;
(int team1Score, int team2Score) = (matchzyTeam1.seriesScore, matchzyTeam2.seriesScore);
if (winnerName == null)
{
PrintToAllChat($"{ChatColors.Green}{matchzyTeam1.teamName}{ChatColors.Default} and {ChatColors.Green}{matchzyTeam2.teamName}{ChatColors.Default} have tied the match");
Expand All @@ -582,21 +584,22 @@ public void EndSeries(string? winnerName, int restartDelay)

string winnerTeam = (winnerName == null) ? "none" : matchzyTeam1.seriesScore > matchzyTeam2.seriesScore ? "team1" : "team2";

(int t1score, int t2score) = GetTeamsScore();
var seriesResultEvent = new MatchZySeriesResultEvent()
{
MatchId = liveMatchId.ToString(),
MatchId = matchId.ToString(),
Winner = new Winner(t1score > t2score && reverseTeamSides["CT"] == matchzyTeam1 ? "3" : "2", winnerTeam),
Team1SeriesScore = matchzyTeam1.seriesScore,
Team2SeriesScore = matchzyTeam2.seriesScore,
Team1SeriesScore = team1Score,
Team2SeriesScore = team2Score,
TimeUntilRestore = 10,
};

Task.Run(async () => {
await database.SetMatchEndData(matchId, winnerName ?? "Draw", team1Score, team2Score);
// Making sure that map end event is fired first
await Task.Delay(2000);
await SendEventAsync(seriesResultEvent);
});
database.SetMatchEndData(liveMatchId, winnerName ?? "Draw", matchzyTeam1.seriesScore, matchzyTeam2.seriesScore);

if (resetCvarsOnSeriesEnd) ResetChangedConvars();
isMatchLive = false;
AddTimer(restartDelay, () => {
Expand Down
5 changes: 3 additions & 2 deletions 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.7.6";
public override string ModuleVersion => "0.7.7";

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

Expand Down Expand Up @@ -187,7 +187,8 @@ public override void Load(bool hotReload) {
RegisterEventHandler<EventRoundFreezeEnd>(EventRoundFreezeEndHandler);
RegisterListener<Listeners.OnClientDisconnectPost>(playerSlot => {
// May not be required, but just to be on safe side so that player data is properly updated in dictionaries
UpdatePlayersMap();
// Update: Commenting the below function as it was being called multiple times on map change.
// UpdatePlayersMap();
});
RegisterListener<Listeners.OnEntitySpawned>(OnEntitySpawnedHandler);

Expand Down
Loading

0 comments on commit 714c3d7

Please sign in to comment.