forked from spacebar/SplatNet-Backend
fix: sanitize & handle #s over integer limit
This commit is contained in:
parent
30089971a1
commit
8d94df35d3
1 changed files with 41 additions and 30 deletions
|
|
@ -4,50 +4,61 @@ const { SplatfestResult } = require('../models/splatfest_result');
|
||||||
const { Equipment } = require('../models/equipment');
|
const { Equipment } = require('../models/equipment');
|
||||||
const { EquipmentLast } = require('../models/equipmentLast');
|
const { EquipmentLast } = require('../models/equipmentLast');
|
||||||
const { PlayerRank } = require('../models/playerRank');
|
const { PlayerRank } = require('../models/playerRank');
|
||||||
|
const MAX_INT32 = 2147483647;
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
type: 'telemetry',
|
type: 'telemetry',
|
||||||
result_model: {
|
result_model: {
|
||||||
create: async (data) => {
|
create: async (data) => {
|
||||||
const result = await SplatfestResult.create(data);
|
const sanitizedData = { ...data };
|
||||||
|
|
||||||
|
const rankValue = parseInt(data.Rank);
|
||||||
|
if (isNaN(rankValue) || rankValue > MAX_INT32 || rankValue < 0) {
|
||||||
|
sanitizedData.Rank = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parseInt(data.SessionID) > MAX_INT32) sanitizedData.SessionID = 0;
|
||||||
|
|
||||||
|
const result = await SplatfestResult.create(sanitizedData);
|
||||||
|
|
||||||
await Equipment.upsert({
|
await Equipment.upsert({
|
||||||
PId: data.PId,
|
PId: sanitizedData.PId,
|
||||||
weapon: data.Weapon,
|
weapon: sanitizedData.Weapon,
|
||||||
sumpaint: data.SumPaint
|
sumpaint: sanitizedData.SumPaint
|
||||||
});
|
});
|
||||||
|
|
||||||
await EquipmentLast.upsert({
|
await EquipmentLast.upsert({
|
||||||
PId: data.PId,
|
PId: sanitizedData.PId,
|
||||||
weapon: data.Weapon,
|
weapon: sanitizedData.Weapon,
|
||||||
Gear_Shoes: data.Gear_Shoes,
|
Gear_Shoes: sanitizedData.Gear_Shoes,
|
||||||
Gear_Shoes_Skill0: data.Gear_Shoes_Skill0,
|
Gear_Shoes_Skill0: sanitizedData.Gear_Shoes_Skill0,
|
||||||
Gear_Shoes_Skill1: data.Gear_Shoes_Skill1,
|
Gear_Shoes_Skill1: sanitizedData.Gear_Shoes_Skill1,
|
||||||
Gear_Shoes_Skill2: data.Gear_Shoes_Skill2,
|
Gear_Shoes_Skill2: sanitizedData.Gear_Shoes_Skill2,
|
||||||
Gear_Clothes: data.Gear_Clothes,
|
Gear_Clothes: sanitizedData.Gear_Clothes,
|
||||||
Gear_Clothes_Skill0: data.Gear_Clothes_Skill0,
|
Gear_Clothes_Skill0: sanitizedData.Gear_Clothes_Skill0,
|
||||||
Gear_Clothes_Skill1: data.Gear_Clothes_Skill1,
|
Gear_Clothes_Skill1: sanitizedData.Gear_Clothes_Skill1,
|
||||||
Gear_Clothes_Skill2: data.Gear_Clothes_Skill2,
|
Gear_Clothes_Skill2: sanitizedData.Gear_Clothes_Skill2,
|
||||||
Gear_Head: data.Gear_Head,
|
Gear_Head: sanitizedData.Gear_Head,
|
||||||
Gear_Head_Skill0: data.Gear_Head_Skill0,
|
Gear_Head_Skill0: sanitizedData.Gear_Head_Skill0,
|
||||||
Gear_Head_Skill1: data.Gear_Head_Skill1,
|
Gear_Head_Skill1: sanitizedData.Gear_Head_Skill1,
|
||||||
Gear_Head_Skill2: data.Gear_Head_Skill2,
|
Gear_Head_Skill2: sanitizedData.Gear_Head_Skill2,
|
||||||
Rank: data.Rank,
|
Rank: sanitizedData.Rank,
|
||||||
Udemae: data.Udemae
|
Udemae: sanitizedData.Udemae
|
||||||
});
|
});
|
||||||
const gameMode = parseInt(data.GameMode);
|
|
||||||
|
const gameMode = parseInt(sanitizedData.GameMode);
|
||||||
|
|
||||||
if (gameMode !== 3 && gameMode !== 4) {
|
if (gameMode !== 3 && gameMode !== 4) {
|
||||||
const isWin = Number(data.IsWinGame) === 1;
|
const isWin = Number(sanitizedData.IsWinGame) === 1;
|
||||||
const [stats, created] = await PlayerRank.findOrCreate({
|
const [stats, created] = await PlayerRank.findOrCreate({
|
||||||
where: {
|
where: {
|
||||||
PId: data.PId,
|
PId: sanitizedData.PId,
|
||||||
GameMode: data.GameMode
|
GameMode: sanitizedData.GameMode
|
||||||
},
|
},
|
||||||
defaults: {
|
defaults: {
|
||||||
MiiName: data.MiiName,
|
MiiName: sanitizedData.MiiName,
|
||||||
Rank: data.Rank,
|
Rank: sanitizedData.Rank,
|
||||||
FesPower: parseFloat(data.FesPower) || 0,
|
FesPower: parseFloat(sanitizedData.FesPower) || 0,
|
||||||
WinSum: 0,
|
WinSum: 0,
|
||||||
LoseSum: 0,
|
LoseSum: 0,
|
||||||
RankingScore: 0
|
RankingScore: 0
|
||||||
|
|
@ -68,9 +79,9 @@ module.exports = {
|
||||||
const newRankingScore = currentWins * winRate * 10;
|
const newRankingScore = currentWins * winRate * 10;
|
||||||
|
|
||||||
await stats.update({
|
await stats.update({
|
||||||
MiiName: data.MiiName,
|
MiiName: sanitizedData.MiiName,
|
||||||
Rank: data.Rank,
|
Rank: sanitizedData.Rank,
|
||||||
FesPower: parseFloat(data.FesPower) || 0,
|
FesPower: parseFloat(sanitizedData.FesPower) || 0,
|
||||||
WinSum: currentWins,
|
WinSum: currentWins,
|
||||||
LoseSum: currentLosses,
|
LoseSum: currentLosses,
|
||||||
RankingScore: newRankingScore
|
RankingScore: newRankingScore
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue