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

MySQL plugin is incompatible with anything setting a non-integer matchd #788

Closed
nickdnk opened this issue Jul 26, 2022 · 2 comments
Closed
Labels

Comments

@nickdnk
Copy link
Collaborator

nickdnk commented Jul 26, 2022

It would appear that the get5_scrim and get5_creatematch commands both set fixed, non-integer match IDs, which cannot be inserted into the MySQL tables if the schemas are what's defined in https://github.com/splewis/get5/blob/master/misc/import_stats.sql.

public Action Command_CreateMatch(int client, int args) {
if (g_GameState != Get5State_None) {
ReplyToCommand(client, "Cannot create a match when a match is already loaded");
return Plugin_Handled;
}
char matchid[MATCH_ID_LENGTH] = "manual";
char matchMap[PLATFORM_MAX_PATH];
GetCleanMapName(matchMap, sizeof(matchMap));

public Action Command_CreateScrim(int client, int args) {
if (g_GameState != Get5State_None) {
ReplyToCommand(client, "Cannot create a match when a match is already loaded");
return Plugin_Handled;
}
char matchid[MATCH_ID_LENGTH] = "scrim";
char matchMap[PLATFORM_MAX_PATH];
GetCleanMapName(matchMap, sizeof(matchMap));
char otherTeamName[MAX_CVAR_LENGTH] = "Away";

// Match ID defaults to an empty string, so if it's empty we use auto-increment from MySQL.
if (strlen(matchId) > 0) {
char matchIdSz[64];
db.Escape(matchId, matchIdSz, sizeof(matchIdSz));
Format(queryBuffer, sizeof(queryBuffer), "INSERT INTO `get5_stats_matches` \
(matchid, series_type, team1_name, team2_name, start_time, server_id) VALUES \
('%s', '%s', '%s', '%s', NOW(), %d)",
matchIdSz, seriesTypeSz, team1NameSz, team2NameSz, serverId);
LogDebug(queryBuffer);
db.Query(SQLErrorCheckCallback, queryBuffer);
LogMessage("Starting match with preset ID: %s", matchId);
} else {
Format(queryBuffer, sizeof(queryBuffer), "INSERT INTO `get5_stats_matches` \
(series_type, team1_name, team2_name, start_time, server_id) VALUES \
('%s', '%s', '%s', NOW(), %d)",
seriesTypeSz, team1NameSz, team2NameSz, serverId);
LogDebug(queryBuffer);
db.Query(MatchInitCallback, queryBuffer);

Solution 1: Let the match ID be empty for scrim and manually created matches. It's meaningless anyway when it's fixed to a string, as it won't distinguish any scrim or manual match from another.

Solution 2: If the MySQL plugin is loaded and sees "scrim" or "manual" as a match id; override it to empty string, which triggers the auto-insert logic to generate a new match ID.Edit: This is a bad idea as the match ID is immediately used for writing backup files and such. Approach 1 should work.

Problem: The init series forward sent to MySQL is async, and in that callback, a call to the Get5_SetMatchID native is placed, overriding the match ID. But since this is async, the original empty string is going to be used for everything until that call comes through, which could take quite a while. Not sure what's best here. I might have to look closer at this, but I still believe setting it to an empty string is the better solution for a quick-fix right now.

@nickdnk nickdnk added the bug label Jul 26, 2022
@nickdnk
Copy link
Collaborator Author

nickdnk commented Jul 27, 2022

@splewis Need your input on this one. I'm not 100% sure of the reasoning behind having a fixed string value as match ID, and as you can see it's a problem.

@nickdnk
Copy link
Collaborator Author

nickdnk commented Jul 28, 2022

An obvious solution here is to just always make the MySQL plugin use auto-increment and simply override the match ID. The column has auto-increment anyway, so you are not supposed to specify values for the column at all.

This creates only one problem: The round prelive backup will not have the correct match ID, as it is generated before MySQL can change the Match ID. What we can do is make the native Get5_SetMatchId call WriteBackup. That should fix it, but will of course leave a lingering "scrim" or "manual" prelive backup that will keep being overridden by the last scrim or manual match.

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

No branches or pull requests

1 participant