Skip to content

Commit

Permalink
Store server ID in match table (#613)
Browse files Browse the repository at this point in the history
* Store server ID in match table

* Adjust SQL script
  • Loading branch information
nickdnk authored Feb 7, 2021
1 parent 4846cac commit 358a67a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
10 changes: 6 additions & 4 deletions misc/import_stats.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ CREATE TABLE `get5_stats_matches`
`team1_score` smallint(5) unsigned NOT NULL DEFAULT '0',
`team2_name` varchar(64) NOT NULL DEFAULT '',
`team2_score` smallint(5) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`matchid`)
`server_id` int(10) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`matchid`),
KEY `server_id` (`server_id`)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4;

CREATE TABLE `get5_stats_maps`
(
`matchid` int(10) unsigned NOT NULL,
`mapnumber` smallint(5) unsigned NOT NULL,
`mapnumber` tinyint(3) unsigned NOT NULL,
`start_time` datetime NOT NULL,
`end_time` datetime NULL DEFAULT NULL,
`winner` varchar(16) NOT NULL DEFAULT '',
Expand All @@ -35,8 +37,8 @@ CREATE TABLE `get5_stats_maps`
CREATE TABLE `get5_stats_players`
(
`matchid` int(10) unsigned NOT NULL,
`mapnumber` smallint(5) unsigned NOT NULL,
`steamid64` varchar(32) NOT NULL,
`mapnumber` tinyint(3) unsigned NOT NULL,
`steamid64` bigint(21) unsigned NOT NULL,
`team` varchar(16) NOT NULL DEFAULT '',
`rounds_played` smallint(5) unsigned NOT NULL,
`name` varchar(64) NOT NULL,
Expand Down
5 changes: 5 additions & 0 deletions scripting/get5/natives.sp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max
CreateNative("Get5_GetTeamScores", Native_GetTeamScores);
CreateNative("Get5_GetMatchID", Native_GetMatchID);
CreateNative("Get5_SetMatchID", Native_SetMatchID);
CreateNative("Get5_GetServerID", Native_GetServerID);
CreateNative("Get5_AddLiveCvar", Native_AddLiveCvar);
CreateNative("Get5_IncreasePlayerStat", Native_IncreasePlayerStat);
CreateNative("Get5_GetMatchStats", Native_GetMatchStats);
Expand Down Expand Up @@ -193,6 +194,10 @@ public int Native_SetMatchID(Handle plugin, int numParams) {
return 0;
}

public int Native_GetServerID(Handle plugin, int numParams) {
return g_ServerIdCvar.IntValue;
}

public int Native_AddLiveCvar(Handle plugin, int numParams) {
char cvarName[MAX_CVAR_LENGTH];
char cvarValue[MAX_CVAR_LENGTH];
Expand Down
14 changes: 8 additions & 6 deletions scripting/get5_mysqlstats.sp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public void Get5_OnSeriesInit() {
char team1Name[64];
char team2Name[64];

int serverId = Get5_GetServerID();

char seriesTypeSz[sizeof(seriesType) * 2 + 1];
char team1NameSz[sizeof(team1Name) * 2 + 1];
char team2NameSz[sizeof(team2Name) * 2 + 1];
Expand All @@ -103,19 +105,19 @@ public void Get5_OnSeriesInit() {
SetMatchID(g_ForceMatchIDCvar.IntValue);
g_ForceMatchIDCvar.IntValue = 0;
Format(queryBuffer, sizeof(queryBuffer), "INSERT INTO `get5_stats_matches` \
(matchid, series_type, team1_name, team2_name, start_time) VALUES \
(%d, '%s', '%s', '%s', NOW())",
g_MatchID, seriesTypeSz, team1NameSz, team2NameSz);
(matchid, series_type, team1_name, team2_name, start_time, server_id) VALUES \
(%d, '%s', '%s', '%s', NOW(), %d)",
g_MatchID, seriesTypeSz, team1NameSz, team2NameSz, serverId);
LogDebug(queryBuffer);
db.Query(SQLErrorCheckCallback, queryBuffer);

LogMessage("Starting match id %d", g_MatchID);

} else {
Format(queryBuffer, sizeof(queryBuffer), "INSERT INTO `get5_stats_matches` \
(series_type, team1_name, team2_name, start_time) VALUES \
('%s', '%s', '%s', NOW())",
seriesTypeSz, team1NameSz, team2NameSz);
(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);
}
Expand Down
4 changes: 4 additions & 0 deletions scripting/include/get5.inc
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ native void Get5_GetMatchID(char[] id, int length);
// Sets the current matchid.
native void Get5_SetMatchID(const char[] id);

// Returns the server ID as defined by get5_server_id.
native int Get5_GetServerID();

// Adds a cvar to be set when going live. If the cvar is already in the cvars for the match, the new
// value will replace the old value if the override parameter is true.
// Note: this should only be used when a match config loaded.
Expand Down Expand Up @@ -224,6 +227,7 @@ public __pl_get5_SetNTVOptional() {
MarkNativeAsOptional("Get5_GetTeamScores");
MarkNativeAsOptional("Get5_GetMatchID");
MarkNativeAsOptional("Get5_SetMatchID");
MarkNativeAsOptional("Get5_GetServerID");
MarkNativeAsOptional("Get5_AddLiveCvar");
MarkNativeAsOptional("Get5_IncreasePlayerStat");
MarkNativeAsOptional("Get5_GetMatchStats");
Expand Down

0 comments on commit 358a67a

Please sign in to comment.