Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated MatchScrimMode #228

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions ConfigConvars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -309,5 +309,13 @@ public void BackupUploadHeaderValueCommand(CCSPlayerController? player, CommandI
if (headerValue != "") backupUploadHeaderValue = headerValue;
}

[ConsoleCommand("matchzy_enable_match_scrim", "Allows match setup with no players defined and run like a scrim. Default value: False")]
public void MatchZyEnableMatchScrimConvar(CCSPlayerController? player, CommandInfo command)
{
if (player != null) return;
string args = command.ArgString;

enableMatchScrim = bool.TryParse(args, out bool enableMatchScrimValue) ? enableMatchScrimValue : args != "0" && enableMatchScrim;
}
}
}
9 changes: 8 additions & 1 deletion ConsoleCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,14 @@ public void OnPlayerReady(CCSPlayerController? player, CommandInfo? command)
{
playerReadyStatus[player.UserId.Value] = true;
// player.PrintToChat($"{chatPrefix} {Localizer["matchzy.youareready"]}");
PrintToPlayerChat(player, Localizer["matchzy.ready.markedready"]);

if (enableMatchScrim && (player.TeamNum == (int)CsTeam.CounterTerrorist || player.TeamNum == (int)CsTeam.Terrorist)) {
string teamName = player.TeamNum == (int)CsTeam.CounterTerrorist ? reverseTeamSides["CT"].teamName : reverseTeamSides["TERRORIST"].teamName;
PrintToPlayerChat(player, Localizer["matchzy.ready.matchedreadyonteam", teamName]);
}
else {
PrintToPlayerChat(player, Localizer["matchzy.ready.markedready"]);
}
}
CheckLiveRequired();
HandleClanTags();
Expand Down
13 changes: 8 additions & 5 deletions EventHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@ public HookResult EventPlayerConnectFullHandler(EventPlayerConnectFull @event, G
if (isMatchSetup || matchModeOnly)
{
CsTeam team = GetPlayerTeam(player);
if (team == CsTeam.None)
if (enableMatchScrim && matchStarted || !enableMatchScrim)
{
Log($"[EventPlayerConnectFull] KICKING PLAYER STEAMID: {steamId}, Name: {player.PlayerName} (NOT ALLOWED!)");
PrintToAllChat($"Kicking player {player.PlayerName} - Not a player in this game.");
KickPlayer(player);
return HookResult.Continue;
if (team == CsTeam.None)
{
Log($"[EventPlayerConnectFull] KICKING PLAYER STEAMID: {steamId}, Name: {player.PlayerName} (NOT ALLOWED!)");
PrintToAllChat($"Kicking player {player.PlayerName} - Not a player in this game.");
KickPlayer(player);
return HookResult.Continue;
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions MapVeto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ public void FinishVeto()
// In case the sides don't match after selection, we check it here before writing the backup.
// Also required if the map doesn't need to change.
SetMapSides();
if (enableMatchScrim) LockTeamsManually();
ExecuteChangedConvars();
foreach (var key in playerReadyStatus.Keys) {
playerReadyStatus[key] = false;
Expand Down
40 changes: 36 additions & 4 deletions MatchManagement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public void LoadMatchFromURL(CCSPlayerController? player, CommandInfo command)
}
}

static string ValidateMatchJsonStructure(JObject jsonData)
private string ValidateMatchJsonStructure(JObject jsonData)
{
string[] requiredFields = { "maplist", "team1", "team2", "num_maps" };

Expand Down Expand Up @@ -196,7 +196,7 @@ static string ValidateMatchJsonStructure(JObject jsonData)
{
return $"{field} should be a JSON structure!";
}
if ((field != "spectators") && (jsonData[field]!["players"] == null || jsonData[field]!["players"]!.Type != JTokenType.Object))
if ((field != "spectators") && (!enableMatchScrim) && (jsonData[field]!["players"] == null || jsonData[field]!["players"]!.Type != JTokenType.Object))
{
return $"{field} should have 'players' JSON!";
}
Expand Down Expand Up @@ -277,8 +277,8 @@ public bool LoadMatchFromJSON(string jsonData)

matchzyTeam1.teamName = RemoveSpecialCharacters(team1["name"]!.ToString());
matchzyTeam2.teamName = RemoveSpecialCharacters(team2["name"]!.ToString());
matchzyTeam1.teamPlayers = team1["players"];
matchzyTeam2.teamPlayers = team2["players"];
matchzyTeam1.teamPlayers = team1["players"] == null || team1["players"]!.Type == JTokenType.Null ? null : team1["players"];
matchzyTeam2.teamPlayers = team2["players"] == null || team2["players"]!.Type == JTokenType.Null ? null : team2["players"];

matchConfig = new()
{
Expand Down Expand Up @@ -384,6 +384,38 @@ public bool LoadMatchFromJSON(string jsonData)
return true;
}

public bool LockTeamsManually()
{
try
{
CsTeam team1 = teamSides[matchzyTeam1] == "CT" ? CsTeam.CounterTerrorist : CsTeam.Terrorist;
CsTeam team2 = teamSides[matchzyTeam2] == "CT" ? CsTeam.CounterTerrorist : CsTeam.Terrorist;

Dictionary<ulong, string> team1Players = new();
Dictionary<ulong, string> team2Players = new();
Dictionary<ulong, string> spectatorPlayers = new();

foreach (var key in playerData.Keys)
{
if (!playerData[key].IsValid) continue;
if (playerData[key].TeamNum == (int)team1) team1Players.Add(playerData[key].SteamID, playerData[key].PlayerName);
else if (playerData[key].TeamNum == (int)team2) team2Players.Add(playerData[key].SteamID, playerData[key].PlayerName);
else if (playerData[key].TeamNum == (int)CsTeam.Spectator) spectatorPlayers.Add(playerData[key].SteamID, playerData[key].PlayerName);
}

matchzyTeam1.teamPlayers = JToken.FromObject(team1Players);
matchzyTeam2.teamPlayers = JToken.FromObject(team2Players);
matchConfig.Spectators = JToken.FromObject(spectatorPlayers);
}
catch (Exception e)
{
Log($"[LockTeamsManually - FATAL] An error occured: {e.Message}");
return false;
}

return true;
}

public void SetMapSides() {
int mapNumber = matchConfig.CurrentMapNumber;
if (matchConfig.MapSides[mapNumber] == "team1_ct" || matchConfig.MapSides[mapNumber] == "team2_t")
Expand Down
7 changes: 5 additions & 2 deletions MatchZy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,11 @@ public override void Load(bool hotReload) {
if ((isMatchSetup || isVeto) && player != null && player.IsValid) {
if (int.TryParse(info.ArgByIndex(1), out int joiningTeam)) {
int playerTeam = (int)GetPlayerTeam(player);
if (joiningTeam != playerTeam) {
return HookResult.Stop;
// if scrim, then only check once match has started
if ((enableMatchScrim && matchStarted) || !enableMatchScrim) {
if (joiningTeam != playerTeam) {
return HookResult.Stop;
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions PracticeMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ public static Dictionary<byte, List<Position>> GetEmptySpawnsData()
};
}

public bool enableMatchScrim = false;

public void StartPracticeMode()
{
if (matchStarted) return;
Expand Down
2 changes: 1 addition & 1 deletion Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ private void UpdatePlayersMap()
if (isMatchSetup || matchModeOnly)
{
CsTeam team = GetPlayerTeam(player);
if (team == CsTeam.None && player.UserId.HasValue)
if (((enableMatchScrim && matchStarted) || !enableMatchScrim) && team == CsTeam.None && player.UserId.HasValue)
{
Server.ExecuteCommand($"kickid {(ushort)player.UserId}");
continue;
Expand Down
3 changes: 3 additions & 0 deletions cfg/MatchZy/config.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,6 @@ matchzy_enable_damage_report true
// Available Colors: {Default}, {Darkred}, {Green}, {LightYellow}, {LightBlue}, {Olive}, {Lime}, {Red}, {Purple}, {Grey}, {Yellow}, {Gold}, {Silver}, {Blue}, {DarkBlue}
// Example: {Green} Welcome to the server! {Default} $$$ Agent models are not allowed and may lead to {Red}disqualification!{Default}
matchzy_match_start_message ""

// Allows match setup with no players defined and run like a scrim. Default value: False
matchzy_enable_match_scrim false
3 changes: 3 additions & 0 deletions documentation/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ Example: `matchzy_demo_upload_url "https://your-website.com/upload-endpoint"` <b
: Message to show when the match starts. Use $$$ to break message into multiple lines. Set to "" to disable. Available Colors: {Default}, {Darkred}, {Green}, {LightYellow}, {LightBlue}, {Olive}, {Lime}, {Red}, {Purple}, {Grey}, {Yellow}, {Gold}, {Silver}, {Blue}, {DarkBlue}. Example usage: matchzy_match_start_message {Green} Welcome to the server! {Default} $$$ Agent models are not allowed and may lead to {Red}disqualification!{Default}
<br>**`Default: ""`**

####`matchzy_enable_match_scrim`
: Allows match setup with no players defined and run like a scrim.<br>**`Default: false`**

####`matchzy_loadbackup`
: Loads a match backup from the given file. Relative to `csgo/MatchZyDataBackup/`.

Expand Down
1 change: 1 addition & 0 deletions lang/de.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"matchzy.ready.markedready": "Du bist bereit.",
"matchzy.ready.matchedreadyonteam": "Je bent gemarkeerd als klaar voor het team {green}{0}{default}!",
"matchzy.ready.markedunready": "Du bist nicht mehr bereit.",
"matchzy.ready.readytotestorebackupinfomessage": "Unready players: {0}. Please type .ready when you are ready to restore the match backup. {1}",

Expand Down
1 change: 1 addition & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"matchzy.ready.markedready": "You have been marked as ready.",
"matchzy.ready.matchedreadyonteam": "You have been marked ready on team {green}{0}{default}!",
"matchzy.ready.markedunready": "You have been marked as NOT ready.",
"matchzy.ready.readytotestorebackupinfomessage": "Unready players: {0}. Please type .ready when you are ready to restore the match backup. {1}",

Expand Down
1 change: 1 addition & 0 deletions lang/fr.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"matchzy.ready.markedready": "Vous avez été marqué comme prêt.",
"matchzy.ready.matchedreadyonteam": "Vous avez été marqué comme prêt dans l'équipe {green}{0}{default}!",
"matchzy.ready.markedunready": "Vous avez été marqué comme NON prêt.",
"matchzy.ready.readytotestorebackupinfomessage": "Unready players: {0}. Please type .ready when you are ready to restore the match backup. {1}",

Expand Down
1 change: 1 addition & 0 deletions lang/hu.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"matchzy.ready.markedready": "Készen állsz.",
"matchzy.ready.matchedreadyonteam": "Felkészült a csapatba {green}{0}{default}!",
"matchzy.ready.markedunready": "Nem állsz készen.",
"matchzy.ready.readytotestorebackupinfomessage": "Unready players: {0}. Please type .ready when you are ready to restore the match backup. {1}",
"matchzy.knife.sidedecisionpending": "{green}{0}{default} nyerte a késes kört. Várjuk, hogy beírják: {green}.stay{default} vagy {green}.switch{default}.",
Expand Down
1 change: 1 addition & 0 deletions lang/ja.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"matchzy.ready.markedready": "準備完了としてマークされました。",
"matchzy.ready.matchedreadyonteam": "あなたはチームで準備完了としてマークされています {green}{0}{default}!",
"matchzy.ready.markedunready": "準備ができていないとマークされています。",
"matchzy.ready.readytotestorebackupinfomessage": "Unready players: {0}. Please type .ready when you are ready to restore the match backup. {1}",

Expand Down
1 change: 1 addition & 0 deletions lang/pt-BR.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"matchzy.ready.markedready": "Você foi marcado como {green}READY{default}.",
"matchzy.ready.matchedreadyonteam": "Você foi marcado como pronto na equipe {green}{0}{default}!",
"matchzy.ready.markedunready": "Você foi marcado como {darkred}NOTREADY{default}.",
"matchzy.ready.readytotestorebackupinfomessage": "Unready players: {0}. Please type .ready when you are ready to restore the match backup. {1}",

Expand Down
1 change: 1 addition & 0 deletions lang/pt-PT.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"matchzy.ready.markedready": "Foi marcado como Pronto.",
"matchzy.ready.matchedreadyonteam": "Foi marcado como Pronto na equipe {green}{0}{default}!",
"matchzy.ready.markedunready": "Foi marcado como NÃO pronto",
"matchzy.ready.readytotestorebackupinfomessage": "Unready players: {0}. Please type .ready when you are ready to restore the match backup. {1}",

Expand Down
1 change: 1 addition & 0 deletions lang/ru.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"matchzy.ready.markedready": "Вас отметили как готового.",
"matchzy.ready.matchedreadyonteam": "Вы отмечены в команде как готовые {green}{0}{default}!",
"matchzy.ready.markedunready": "Вас отметили как НЕ готового.",
"matchzy.ready.readytotestorebackupinfomessage": "Unready players: {0}. Please type .ready when you are ready to restore the match backup. {1}",
"matchzy.knife.sidedecisionpending": "{green}{0}{default} выиграла ножевой раунд. Ждём, пока они введут {green}.stay{default} или {green}.switch{default}.",
Expand Down
1 change: 1 addition & 0 deletions lang/uz.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"matchzy.ready.markedready": "Siz tayyor deb belgilandingiz.",
"matchzy.ready.matchedreadyonteam": "Siz jamoada tayyor deb belgilandingiz {green}{0}{default}!",
"matchzy.ready.markedunready": "Siz tayyor emas deb belgilandingiz.",
"matchzy.ready.readytotestorebackupinfomessage": "Tayyormas oʻyinchilar: {0}. Oʻyinning zaxira nusxasini tiklashga tayyor boʻlganingizda .ready yozing. {1}",

Expand Down
1 change: 1 addition & 0 deletions lang/zh-Hans.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"matchzy.ready.markedready": "您已被标记为准备完成。",
"matchzy.ready.matchedreadyonteam": "您已被标记为团队就绪 {green}{0}{default}!",
"matchzy.ready.markedunready": "您已经被标记为未准备。",
"matchzy.ready.readytotestorebackupinfomessage": "Unready players: {0}. Please type .ready when you are ready to restore the match backup. {1}",

Expand Down
1 change: 1 addition & 0 deletions lang/zh-Hant.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"matchzy.ready.markedready": "您已被標記為準備完成。",
"matchzy.ready.matchedreadyonteam": "您已被標記為已準備好加入團隊 {green}{0}{default}!",
"matchzy.ready.markedunready": "您已經被標記為未準備。",
"matchzy.ready.readytotestorebackupinfomessage": "Unready players: {0}. Please type .ready when you are ready to restore the match backup. {1}",

Expand Down