diff --git a/migrations/development/20230629010420-get5db.js b/migrations/development/20230629010420-get5db.js new file mode 100644 index 0000000..ef0b25c --- /dev/null +++ b/migrations/development/20230629010420-get5db.js @@ -0,0 +1,259 @@ +'use strict'; + +var dbm; +var type; +var seed; + +/** + * We receive the dbmigrate dependency from dbmigrate initially. + * This enables us to not have to rely on NODE_PATH. + */ +exports.setup = function(options, seedLink) { + dbm = options.dbmigrate; + type = dbm.dataType; + seed = seedLink; +}; + +exports.up = function(db) { + return db + .runSql("ALTER TABLE player_stats ALTER COLUMN knife_kills SET DEFAULT 0") + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN damage SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN util_damage SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN enemies_flashed SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN friendlies_flashed SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN bomb_plants SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN bomb_defuses SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN v1 SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN v2 SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN v3 SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN v4 SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN v5 SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN k1 SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN k2 SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN k3 SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN k4 SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN k5 SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN firstdeath_ct SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN firstdeath_t SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN firstkill_ct SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN firstkill_t SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN kast SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN contribution_score SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN mvp SET DEFAULT 0" + ); + }); +}; + +exports.down = function(db) { + return db + .runSql("ALTER TABLE player_stats ALTER COLUMN knife_kills SET DEFAULT NULL") + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN damage SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN util_damage SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN enemies_flashed SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN friendlies_flashed SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN bomb_plants SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN bomb_defuses SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN v1 SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN v2 SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN v3 SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN v4 SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN v5 SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN k1 SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN k2 SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN k3 SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN k4 SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN k5 SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN firstdeath_ct SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN firstdeath_t SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN firstkill_ct SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN firstkill_t SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN kast SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN contribution_score SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN mvp SET DEFAULT NULL" + ); + }); +}; + +exports._meta = { + "version": 1 +}; diff --git a/migrations/production/20230629010420-get5db.js b/migrations/production/20230629010420-get5db.js new file mode 100644 index 0000000..ef0b25c --- /dev/null +++ b/migrations/production/20230629010420-get5db.js @@ -0,0 +1,259 @@ +'use strict'; + +var dbm; +var type; +var seed; + +/** + * We receive the dbmigrate dependency from dbmigrate initially. + * This enables us to not have to rely on NODE_PATH. + */ +exports.setup = function(options, seedLink) { + dbm = options.dbmigrate; + type = dbm.dataType; + seed = seedLink; +}; + +exports.up = function(db) { + return db + .runSql("ALTER TABLE player_stats ALTER COLUMN knife_kills SET DEFAULT 0") + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN damage SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN util_damage SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN enemies_flashed SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN friendlies_flashed SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN bomb_plants SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN bomb_defuses SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN v1 SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN v2 SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN v3 SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN v4 SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN v5 SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN k1 SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN k2 SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN k3 SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN k4 SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN k5 SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN firstdeath_ct SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN firstdeath_t SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN firstkill_ct SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN firstkill_t SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN kast SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN contribution_score SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN mvp SET DEFAULT 0" + ); + }); +}; + +exports.down = function(db) { + return db + .runSql("ALTER TABLE player_stats ALTER COLUMN knife_kills SET DEFAULT NULL") + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN damage SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN util_damage SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN enemies_flashed SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN friendlies_flashed SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN bomb_plants SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN bomb_defuses SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN v1 SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN v2 SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN v3 SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN v4 SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN v5 SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN k1 SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN k2 SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN k3 SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN k4 SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN k5 SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN firstdeath_ct SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN firstdeath_t SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN firstkill_ct SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN firstkill_t SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN kast SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN contribution_score SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN mvp SET DEFAULT NULL" + ); + }); +}; + +exports._meta = { + "version": 1 +}; diff --git a/migrations/test/20230629010420-get5db.js b/migrations/test/20230629010420-get5db.js new file mode 100644 index 0000000..ef0b25c --- /dev/null +++ b/migrations/test/20230629010420-get5db.js @@ -0,0 +1,259 @@ +'use strict'; + +var dbm; +var type; +var seed; + +/** + * We receive the dbmigrate dependency from dbmigrate initially. + * This enables us to not have to rely on NODE_PATH. + */ +exports.setup = function(options, seedLink) { + dbm = options.dbmigrate; + type = dbm.dataType; + seed = seedLink; +}; + +exports.up = function(db) { + return db + .runSql("ALTER TABLE player_stats ALTER COLUMN knife_kills SET DEFAULT 0") + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN damage SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN util_damage SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN enemies_flashed SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN friendlies_flashed SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN bomb_plants SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN bomb_defuses SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN v1 SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN v2 SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN v3 SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN v4 SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN v5 SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN k1 SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN k2 SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN k3 SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN k4 SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN k5 SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN firstdeath_ct SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN firstdeath_t SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN firstkill_ct SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN firstkill_t SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN kast SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN contribution_score SET DEFAULT 0" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN mvp SET DEFAULT 0" + ); + }); +}; + +exports.down = function(db) { + return db + .runSql("ALTER TABLE player_stats ALTER COLUMN knife_kills SET DEFAULT NULL") + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN damage SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN util_damage SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN enemies_flashed SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN friendlies_flashed SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN bomb_plants SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN bomb_defuses SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN v1 SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN v2 SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN v3 SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN v4 SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN v5 SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN k1 SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN k2 SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN k3 SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN k4 SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN k5 SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN firstdeath_ct SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN firstdeath_t SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN firstkill_ct SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN firstkill_t SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN kast SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN contribution_score SET DEFAULT NULL" + ); + }) + .then(() => { + return db.runSql( + "ALTER TABLE player_stats ALTER COLUMN mvp SET DEFAULT NULL" + ); + }); +}; + +exports._meta = { + "version": 1 +}; diff --git a/package.json b/package.json index 37c62ea..61ac22c 100644 --- a/package.json +++ b/package.json @@ -68,7 +68,7 @@ "dependencies": { "@node-steam/id": "^1.2.0", "aes-js": "^3.1.2", - "bcrypt": "^5.0.0", + "bcrypt": "^5.1.0", "config": "^3.3.7", "connect-redis": "^6.1.3", "cookie-parser": "~1.4.6", diff --git a/src/routes/matches/matches.js b/src/routes/matches/matches.js index 9a6dde9..d2b175e 100644 --- a/src/routes/matches/matches.js +++ b/src/routes/matches/matches.js @@ -162,7 +162,7 @@ import GlobalEmitter from "../../utility/emitter.js"; * description: Key value pair containing an integer representing map order, and value representing map name. * min_spectators_to_ready: * type: integer - * description: Value representing specatators to ready up. + * description: Value representing spectators to ready up. * maps_to_win: * type: integer * description: The amount of maps required to win a match. @@ -1230,7 +1230,7 @@ router.post("/", Utils.ensureAuthenticated, async (req, res, next) => { )) ) { // Delete the match as it does not belong in the database. - sql = "DELETE FROM match_specatator WHERE match_id = ?"; + sql = "DELETE FROM match_spectator WHERE match_id = ?"; await db.query(sql, [insertMatch.insertId]); sql = "DELETE FROM match_cvar WHERE match_id = ?"; await db.query(sql, [insertMatch.insertId]); diff --git a/src/services/mapflowservices.ts b/src/services/mapflowservices.ts index db0c379..6eba36b 100644 --- a/src/services/mapflowservices.ts +++ b/src/services/mapflowservices.ts @@ -157,137 +157,6 @@ class MapFlowService { sqlString = "INSERT INTO player_stat_extras SET ?"; await db.query(sqlString, insertObj); - // Update player stats for what we can here, start with the victim. - sqlString = - "SELECT id, deaths, suicides FROM player_stats WHERE match_id = ? AND map_id = ? AND steam_id = ?"; - playerStatVals = await db.query(sqlString, [ - event.matchid, - mapInfo[0].id, - event.player.steamid - ]); - - if (playerStatVals.length) { - sqlString = "UPDATE player_stats SET ? WHERE id = ?"; - insertObj = { - deaths: playerStatVals[0].deaths + 1, - suicides: event.suicide ? playerStatVals[0].suicides + 1 : null - }; - insertObj = await db.buildUpdateStatement(insertObj); - await db.query(sqlString, [insertObj, playerStatVals[0].id]); - } else { - sqlString = "INSERT INTO player_stats SET ?"; - insertObj = { - match_id: event.matchid, - map_id: mapInfo[0].id, - team_id: playerTeamId[0].team_id, - steam_id: event.player.steamid, - name: event.player.name, - deaths: 1, - suicides: event.suicide ? 1 : null - }; - insertObj = await db.buildUpdateStatement(insertObj); - await db.query(sqlString, insertObj); - } - - if (event.attacker) { - sqlString = - "SELECT id, kills, headshot_kills, teamkills, knife_kills FROM player_stats WHERE match_id = ? AND map_id = ? AND steam_id = ?"; - playerStatVals = await db.query(sqlString, [ - event.matchid, - mapInfo[0].id, - event.attacker.steamid - ]); - if (playerStatVals.length) { - sqlString = "UPDATE player_stats SET ? WHERE id = ?"; - insertObj = { - kills: playerStatVals[0].kills + 1, - headshot_kills: event.headshot - ? playerStatVals[0].headshot_kills + 1 - : null, - teamkills: event.friendly_fire - ? playerStatVals[0].teamkills + 1 - : null, - knife_kills: - event.weapon.id == 28 || - event.weapon.id == 50 || - event.weapon.id == 28 || - event.weapon.id == 59 || - event.weapon.id == 80 || - event.weapon.id > 500 - ? playerStatVals[0].knife_kills + 1 - : null - }; - insertObj = await db.buildUpdateStatement(insertObj); - await db.query(sqlString, [insertObj, playerStatVals[0].id]); - } else { - sqlString = - "SELECT team_id FROM team_auth_names JOIN `match` m " + - "ON (m.team1_id = team_id OR m.team2_id = team_id) WHERE m.id = ? AND auth = ?"; - playerStatVals = await db.query(sqlString, [event.matchid, event.attacker.steamid]); - sqlString = "INSERT INTO player_stats SET ?"; - - insertObj = { - match_id: +event.matchid, - map_id: mapInfo[0].id, - team_id: playerStatVals[0].team_id, - steam_id: event.attacker.steamid, - name: event.attacker.name, - kills: 1, - headshot_kills: event.headshot ? 1 : null, - teamkills: event.friendly_fire ? 1 : null, - knife_kills: - event.weapon.id == 28 || - event.weapon.id == 50 || - event.weapon.id == 28 || - event.weapon.id == 59 || - event.weapon.id == 80 || - event.weapon.id > 500 - ? 1 - : null - }; - insertObj = await db.buildUpdateStatement(insertObj); - await db.query(sqlString, insertObj); - } - } - - if (event.assist) { - sqlString = - "SELECT id, assists, flashbang_assists FROM player_stats WHERE match_id = ? AND map_id = ? AND steam_id = ?"; - playerStatVals = await db.query(sqlString, [ - event.matchid, - mapInfo[0].id, - event.assist.player.steamid - ]); - if (playerStatVals.length) { - sqlString = "UPDATE player_stats SET ? WHERE id = ?"; - insertObj = { - assists: playerStatVals[0].assists + 1, - flashbang_assists: event.assist.flash_assist - ? playerStatVals[0].flashbang_assists + 1 - : null - }; - insertObj = await db.buildUpdateStatement(insertObj); - await db.query(sqlString, [insertObj, playerStatVals[0].id]); - } else { - sqlString = - "SELECT team_id FROM team_auth_names JOIN `match` m " + - "ON (m.team1_id = team_id OR m.team2_id = team_id) WHERE m.id = ? AND auth = ?"; - playerStatVals = await db.query(sqlString, [ - event.assist.player.steamid - ]); - sqlString = "INSERT INTO player_stats SET ?"; - insertObj = { - match_id: event.matchid, - map_id: mapInfo[0].id, - team_id: playerStatVals[0].team_id, - steam_id: event.assist.player.steamid, - assists: 1, - flashbang_assists: event.assist.flash_assist ? 1 : null - }; - insertObj = await db.buildUpdateStatement(insertObj); - await db.query(sqlString, insertObj); - } - } GlobalEmitter.emit("playerStatsUpdate"); return res.status(200).send({ message: "Success" }); } catch (error: unknown) { @@ -468,7 +337,6 @@ class MapFlowService { ) { let sqlString: string; let mapStatInfo: RowDataPacket[]; - // Check if round was backed up and nuke the additional player stats and bomb plants. sqlString = "SELECT round_restored, id FROM map_stats WHERE match_id = ? AND map_number = ?"; mapStatInfo = await db.query(sqlString, [event.matchid, event.map_number]); diff --git a/src/services/seriesflowservices.ts b/src/services/seriesflowservices.ts index 600c007..ed417f9 100644 --- a/src/services/seriesflowservices.ts +++ b/src/services/seriesflowservices.ts @@ -149,36 +149,6 @@ class SeriesFlowService { updateStmt = await db.buildUpdateStatement(updateStmt); await db.query(sqlString, [updateStmt, mapInfo[0].id]); - // Final update of playerstats. - sqlString = - "SELECT * FROM player_stats WHERE match_id = ? AND map_id = ?"; - playerStats = await db.query(sqlString, [event.matchid, mapInfo[0].id]); - for (let player of event.team1.players) { - singlePlayerStat = playerStats.filter( - (dbPlayer) => dbPlayer.steam_id == player.steamid - ); - await Utils.updatePlayerStats( - event.matchid, - event.team1.id, - mapInfo[0].id, - player, - singlePlayerStat[0].id - ); - } - for (let player of event.team2.players) { - singlePlayerStat = playerStats.filter( - (dbPlayer) => dbPlayer.steam_id == player.steamid - ); - await Utils.updatePlayerStats( - event.matchid, - event.team2.id, - mapInfo[0].id, - player, - singlePlayerStat[0].id - ); - } - GlobalEmitter.emit("playerStatsUpdate"); - // Update match table. updateStmt = { team1_score: event.team1.series_score, diff --git a/src/utility/utils.ts b/src/utility/utils.ts index dee62d0..f6ecb92 100644 --- a/src/utility/utils.ts +++ b/src/utility/utils.ts @@ -75,7 +75,7 @@ class Utils { return rating.toFixed(2); } catch (err) { - console.log("HELPER getRating Failed -- " + err); + console.error("HELPER getRating Failed -- " + err); return 0; } } diff --git a/yarn.lock b/yarn.lock index 01f7515..5ddc5fa 100644 --- a/yarn.lock +++ b/yarn.lock @@ -599,10 +599,10 @@ dependencies: lodash "^4.17.21" -"@mapbox/node-pre-gyp@^1.0.0": - version "1.0.9" - resolved "https://registry.npmjs.org/@mapbox/node-pre-gyp/-/node-pre-gyp-1.0.9.tgz" - integrity sha512-aDF3S3rK9Q2gey/WAttUlISduDItz5BU3306M9Eyv6/oS40aMprnopshtlKTykxRNIBEZuRMaZAnbrQ4QtKGyw== +"@mapbox/node-pre-gyp@^1.0.10": + version "1.0.10" + resolved "https://registry.yarnpkg.com/@mapbox/node-pre-gyp/-/node-pre-gyp-1.0.10.tgz#8e6735ccebbb1581e5a7e652244cadc8a844d03c" + integrity sha512-4ySo4CjzStuprMwk35H5pPbkymjv1SF3jGLj6rAHp/xT/RF7TL7bd9CTm1xDY49K2qF7jmR/g7k+SkLETP6opA== dependencies: detect-libc "^2.0.0" https-proxy-agent "^5.0.0" @@ -1263,13 +1263,13 @@ bcrypt-pbkdf@^1.0.2: dependencies: tweetnacl "^0.14.3" -bcrypt@^5.0.0: - version "5.0.1" - resolved "https://registry.npmjs.org/bcrypt/-/bcrypt-5.0.1.tgz" - integrity sha512-9BTgmrhZM2t1bNuDtrtIMVSmmxZBrJ71n8Wg+YgdjHuIWYF7SjjmCPZFB+/5i/o/PIeRpwVJR3P+NrpIItUjqw== +bcrypt@^5.1.0: + version "5.1.0" + resolved "https://registry.yarnpkg.com/bcrypt/-/bcrypt-5.1.0.tgz#bbb27665dbc400480a524d8991ac7434e8529e17" + integrity sha512-RHBS7HI5N5tEnGTmtR/pppX0mmDSBpQ4aCBsj7CEQfYXDcO74A8sIBYcJMuCsis2E81zDxeENYhv66oZwLiA+Q== dependencies: - "@mapbox/node-pre-gyp" "^1.0.0" - node-addon-api "^3.1.0" + "@mapbox/node-pre-gyp" "^1.0.10" + node-addon-api "^5.0.0" binary-extensions@^2.0.0: version "2.2.0" @@ -3528,10 +3528,10 @@ netmask@^2.0.2: resolved "https://registry.npmjs.org/netmask/-/netmask-2.0.2.tgz" integrity sha512-dBpDMdxv9Irdq66304OLfEmQ9tbNRFnFTuZiLo+bD+r332bBmMJ8GBLXklIXXgxd3+v9+KUnZaUR5PJMa75Gsg== -node-addon-api@^3.1.0: - version "3.2.1" - resolved "https://registry.npmjs.org/node-addon-api/-/node-addon-api-3.2.1.tgz" - integrity sha512-mmcei9JghVNDYydghQmeDX8KoAm0FAiYyIcUt/N4nhyAipB17pllZQDOJD2fotxABnt4Mdz+dKTO7eftLg4d0A== +node-addon-api@^5.0.0: + version "5.1.0" + resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-5.1.0.tgz#49da1ca055e109a23d537e9de43c09cca21eb762" + integrity sha512-eh0GgfEkpnoWDq+VY8OyvYhFEzBk6jIYbRKdIlyTiAXIVJ8PyBaKb0rp7oDtoddbdoHWhq8wwr+XZ81F1rpNdA== node-cleanup@^2.1.2: version "2.1.2"