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

[BUG] Fix First Map Name in matchzydb #274

Open
Cherno-Beliy opened this issue Mar 8, 2025 · 2 comments
Open

[BUG] Fix First Map Name in matchzydb #274

Cherno-Beliy opened this issue Mar 8, 2025 · 2 comments

Comments

@Cherno-Beliy
Copy link

Cherno-Beliy commented Mar 8, 2025

Currently, the wrong name is recorded in the database for the first map. The first map should be the one on which BAN/PICK was performed. As a visual example, before loading the match configuration I set the maps to ar_pool_day / ar_baggage / ar_sheets (see screenshot).

Image

However, the first map — which should correspond to the map chosen during BAN/PICK — is recorded incorrectly; instead, the name returned by Server.MapName is used.

To fix the bug with determining the first map’s name, the method of obtaining the map name during match initialization must be changed. Currently, in the InitMatch method (in the file DatabaseStats.cs) the following line is used:
string mapName = Server.MapName;
I propose to replace it with obtaining the map name from the selected map pool stored in the MatchConfig object, i.e.:
string mapName = matchConfig.Maplist[mapNumber];
Below is a fragment of the corrected InitMatch method:

public long InitMatch(string team1name, string team2name, string serverIp, bool isMatchSetup, long liveMatchId, int mapNumber, string seriesType, MatchConfig matchConfig)
{
    try
    {
        string mapName = matchConfig.Maplist[mapNumber];
        string dateTimeExpression = (connection is SqliteConnection) ? "datetime('now')" : "NOW()";

        if (mapNumber == 0) {
            if (isMatchSetup && liveMatchId != -1) {
                connection.Execute(@"
                    INSERT INTO matchzy_stats_matches (matchid, start_time, team1_name, team2_name, series_type, server_ip)
                    VALUES (@liveMatchId, " + dateTimeExpression + ", @team1name, @team2name, @seriesType, @serverIp)",
                    new { liveMatchId, team1name, team2name, seriesType, serverIp });
            } else {
                connection.Execute(@"
                    INSERT INTO matchzy_stats_matches (start_time, team1_name, team2_name, series_type, server_ip)
                    VALUES (" + dateTimeExpression + ", @team1name, @team2name, @seriesType, @serverIp)",
                    new { team1name, team2name, seriesType, serverIp });
            }
        }

        if (isMatchSetup && liveMatchId != -1) {
            connection.Execute(@"
                INSERT INTO matchzy_stats_maps (matchid, start_time, mapnumber, mapname)
                VALUES (@liveMatchId, " + dateTimeExpression + ", @mapNumber, @mapName)",
                new { liveMatchId, mapNumber, mapName });
            return liveMatchId;
        }
        // … (rest of the method)
    }
    catch (Exception ex)
    {
        Log($"[InsertMatchData - FATAL] Error inserting data: {ex.Message}");
        return liveMatchId;
    }
}

Also, in the file Utility.cs (starting around line 769) a correction must be made in the call to InitMatch so that the MatchConfig object is passed:

string seriesType = "BO" + matchConfig.NumMaps.ToString();
liveMatchId = database.InitMatch(matchzyTeam1.teamName, matchzyTeam2.teamName, "-", isMatchSetup, liveMatchId, matchConfig.CurrentMapNumber, seriesType, matchConfig);
SetupRoundBackupFile();

This change ensures that the map name recorded in the database corresponds to the map chosen during the BAN/PICK process rather than the name returned by Server.MapName.

Image

@Cherno-Beliy
Copy link
Author

I’ve been working on a few improvements and bug fixes for MatchZy. If you don’t mind, could you please invite me as a collaborator so I can create pull requests directly? This would help streamline the contribution process.

Thanks in advance!

@mrc4tt
Copy link

mrc4tt commented Mar 9, 2025

You can fork it, (edit the files) and PR, for example. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants