Skip to content

Commit 714c3d7

Browse files
0.7.7 | Wingman support and optimizations
1 parent b632a74 commit 714c3d7

File tree

7 files changed

+177
-32
lines changed

7 files changed

+177
-32
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# MatchZy Changelog
22

3+
# 0.7.7
4+
5+
#### April 29, 2024
6+
7+
- 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.
8+
- 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.
9+
- Removed `UpdatePlayersMap` from player connect and disconnect methods to avoid it getting called multiple times on map change.
10+
- Made `SetMatchEndData` to be an async operation.
11+
- Added updated pt-PT translations.
12+
313
# 0.7.6
414

515
#### April 28, 2024

DatabaseStats.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ UPDATE matchzy_stats_matches
329329
}
330330
}
331331

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

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

345345
Log($"[SetMatchEndData] Data updated for matchId: {matchId} winnerName: {winnerName}");
346346
}

EventHandlers.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ public HookResult EventPlayerConnectFullHandler(EventPlayerConnectFull @event, G
6868
}
6969
}
7070
// May not be required, but just to be on safe side so that player data is properly updated in dictionaries
71-
UpdatePlayersMap();
71+
// Update: Commenting the below function as it was being called multiple times on map change.
72+
// UpdatePlayersMap();
7273

7374
if (readyAvailable && !matchStarted)
7475
{

MatchManagement.cs

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ static string ValidateMatchJsonStructure(JObject jsonData)
239239

240240
case "skip_veto":
241241
case "clinch_series":
242+
case "wingman":
242243
if (!bool.TryParse(jsonData[field]!.ToString(), out bool result))
243244
{
244245
return $"{field} should be a boolean!";
@@ -338,18 +339,13 @@ public bool LoadMatchFromJSON(string jsonData)
338339
}
339340
}
340341
}
342+
string currentMapName = Server.MapName;
341343
string mapName = matchConfig.Maplist[0].ToString();
342344

343-
if (long.TryParse(mapName, out _)) {
344-
Server.ExecuteCommand($"bot_kick");
345-
Server.ExecuteCommand($"host_workshop_map \"{mapName}\"");
346-
} else if (Server.IsMapValid(mapName)) {
347-
Server.ExecuteCommand($"bot_kick");
348-
Server.ExecuteCommand($"changelevel \"{mapName}\"");
349-
} else {
350-
Log($"[LoadMatchFromJSON] Invalid map name: {mapName}, cannot setup match!");
351-
ResetMatch(false);
352-
return false;
345+
if (IsMapReloadRequiredForGameMode(matchConfig.Wingman) || mapReloadRequired || currentMapName != mapName)
346+
{
347+
SetCorrectGameMode();
348+
ChangeMap(mapName, 0);
353349
}
354350
}
355351
else
@@ -481,6 +477,10 @@ public void GetOptionalMatchValues(JObject jsonDataObject)
481477
{
482478
matchConfig.SkipVeto = bool.Parse(jsonDataObject["skip_veto"]!.ToString());
483479
}
480+
if (jsonDataObject["wingman"] != null)
481+
{
482+
matchConfig.Wingman = bool.Parse(jsonDataObject["wingman"]!.ToString());
483+
}
484484
if (jsonDataObject["veto_mode"] != null)
485485
{
486486
matchConfig.MapBanOrder = jsonDataObject["veto_mode"]!.ToObject<List<string>>()!;
@@ -569,8 +569,10 @@ private CsTeam GetPlayerTeam(CCSPlayerController player)
569569
return playerTeam;
570570
}
571571

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

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

585-
(int t1score, int t2score) = GetTeamsScore();
586587
var seriesResultEvent = new MatchZySeriesResultEvent()
587588
{
588-
MatchId = liveMatchId.ToString(),
589+
MatchId = matchId.ToString(),
589590
Winner = new Winner(t1score > t2score && reverseTeamSides["CT"] == matchzyTeam1 ? "3" : "2", winnerTeam),
590-
Team1SeriesScore = matchzyTeam1.seriesScore,
591-
Team2SeriesScore = matchzyTeam2.seriesScore,
591+
Team1SeriesScore = team1Score,
592+
Team2SeriesScore = team2Score,
592593
TimeUntilRestore = 10,
593594
};
595+
594596
Task.Run(async () => {
597+
await database.SetMatchEndData(matchId, winnerName ?? "Draw", team1Score, team2Score);
595598
// Making sure that map end event is fired first
596599
await Task.Delay(2000);
597600
await SendEventAsync(seriesResultEvent);
598601
});
599-
database.SetMatchEndData(liveMatchId, winnerName ?? "Draw", matchzyTeam1.seriesScore, matchzyTeam2.seriesScore);
602+
600603
if (resetCvarsOnSeriesEnd) ResetChangedConvars();
601604
isMatchLive = false;
602605
AddTimer(restartDelay, () => {

MatchZy.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public partial class MatchZy : BasePlugin
1313
{
1414

1515
public override string ModuleName => "MatchZy";
16-
public override string ModuleVersion => "0.7.6";
16+
public override string ModuleVersion => "0.7.7";
1717

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

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

0 commit comments

Comments
 (0)