Skip to content

Commit

Permalink
Merge pull request #650 from WatWowMap/develop
Browse files Browse the repository at this point in the history
Sync Dev to Main
  • Loading branch information
TurtIeSocks authored Jan 28, 2023
2 parents fc07369 + 69a83a2 commit 07a0c5f
Show file tree
Hide file tree
Showing 25 changed files with 366 additions and 211 deletions.
2 changes: 1 addition & 1 deletion .configref
Original file line number Diff line number Diff line change
@@ -1 +1 @@
18824
18881
19 changes: 0 additions & 19 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,29 +61,10 @@ <h4 class="loading-text">This app requires JavaScript</h4>
element.innerText = locales[locale.toLowerCase()] || locales.en
</script>
<div id="root"></div>
<link
rel="stylesheet"
href="https://unpkg.com/[email protected]/dist/leaflet.css"
integrity="sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ=="
crossorigin="anonymous"
/>
<link
rel="stylesheet"
href="https://unpkg.com/react-leaflet-markercluster/dist/styles.min.css"
/>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/L.Control.Locate.min.css"
/>

<link
rel="stylesheet"
href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap"
/>
<link
rel="stylesheet"
href="https://fonts.googleapis.com/icon?family=Material+Icons"
/>
<link
rel="stylesheet"
href="https://use.fontawesome.com/releases/v5.0.7/css/all.css"
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "reactmap",
"version": "1.9.3",
"version": "1.9.5",
"description": "React based frontend map.",
"main": "ReactMap.js",
"author": "TurtIeSocks <[email protected]>",
Expand Down Expand Up @@ -35,7 +35,7 @@
},
"devDependencies": {
"@sentry/cli": "^2.7.0",
"@vitejs/plugin-react": "^3.0.0",
"@vitejs/plugin-react": "^3.0.1",
"eslint": "^8.9.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-prettier": "^8.3.0",
Expand Down Expand Up @@ -69,7 +69,7 @@
"apollo-server-express": "^3.5.0",
"bcrypt": "^5.0.1",
"compression": "^1.7.4",
"config": "^3.3.6",
"config": "^3.3.9",
"discord.js": "^12.5.3",
"dotenv": "^10.0.0",
"express": "^4.17.3",
Expand All @@ -94,7 +94,7 @@
"node-fetch": "2",
"node-geocoder": "^4.0.0",
"nodes2ts": "^2.0.0",
"objection": "^3.0.0",
"objection": "^3.0.1",
"ohbem": "^1.4.1",
"passport": "^0.6.0",
"passport-discord": "https://github.com/tonestrike/passport-discord.git",
Expand Down
4 changes: 2 additions & 2 deletions server/scripts/generateMasterfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const generate = async (
...masterfile,
pokemon: Object.fromEntries(
Object.values(masterfile.pokemon).map((pokemon) => {
const { legendary, mythical, ultraBeast, ...rest } = pokemon
const { legendary, mythical, ultraBeast } = pokemon
const historic =
historicRarity.get(pokemon.pokedexId.toString()) || 'never'

Expand All @@ -53,7 +53,7 @@ const generate = async (
},
]),
)
return [pokemon.pokedexId, { ...rest, forms, rarity, historic }]
return [pokemon.pokedexId, { ...pokemon, forms, rarity, historic }]
}),
),
}
Expand Down
11 changes: 8 additions & 3 deletions server/src/configs/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,11 @@
1,
3,
5,
6
6,
7,
8,
9,
10
],
"baseTeamIds": [
0,
Expand Down Expand Up @@ -455,7 +459,8 @@
"rewardTypes": false,
"baseMegaEnergyAmounts": [
10,
20
20,
25
],
"baseLureIds": [
501,
Expand All @@ -466,7 +471,7 @@
],
"stardust": {
"min": 100,
"max": 2000,
"max": 2500,
"interval": 100,
"enabled": true
},
Expand Down
1 change: 1 addition & 0 deletions server/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const app = express()

const server = new ApolloServer({
cors: true,
cache: 'bounded',
typeDefs,
resolvers,
introspection: config.devOptions.enabled,
Expand Down
98 changes: 65 additions & 33 deletions server/src/models/Pokemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const {
} = require('../services/config')
const getAreaSql = require('../services/functions/getAreaSql')
const { Pvp } = require('../services/initialization')
const fetchJson = require('../services/api/fetchJson')

const levelCalc =
'IFNULL(IF(cp_multiplier < 0.734, ROUND(58.35178527 * cp_multiplier * cp_multiplier - 2.838007664 * cp_multiplier + 0.8539209906), ROUND(171.0112688 * cp_multiplier - 95.20425243)), NULL)'
Expand Down Expand Up @@ -78,7 +79,7 @@ module.exports = class Pokemon extends Model {
return 'pokemon'
}

static async getAll(perms, args, { isMad, pvpV2, hasSize, hasHeight }) {
static async getAll(perms, args, { isMad, pvpV2, mem, hasSize, hasHeight }) {
const { iv: ivs, pvp, areaRestrictions } = perms
const {
onlyStandard,
Expand Down Expand Up @@ -290,7 +291,7 @@ module.exports = class Pokemon extends Model {
return []
}

const results = await query.limit(queryLimits.pokemon)
const results = await this.evalQuery(mem, query.limit(queryLimits.pokemon))
const finalResults = []
const pvpResults = []
const listOfIds = []
Expand Down Expand Up @@ -321,6 +322,8 @@ module.exports = class Pokemon extends Model {
pvpResults.push(pkmn)
}
if (noPvp && globalCheck(pkmn)) {
pkmn.changed = !!pkmn.changed
pkmn.expire_timestamp_verified = !!pkmn.expire_timestamp_verified
finalResults.push(pkmn)
}
})
Expand Down Expand Up @@ -372,7 +375,10 @@ module.exports = class Pokemon extends Model {
return []
}
pvpResults.push(
...(await pvpQuery.limit(queryLimits.pokemonPvp - results.length)),
...(await this.evalQuery(
mem,
pvpQuery.limit(queryLimits.pokemonPvp - results.length),
)),
)
}

Expand Down Expand Up @@ -402,13 +408,30 @@ module.exports = class Pokemon extends Model {
(Object.keys(pkmn.cleanPvp).length || !pkmn.pvpCheck) &&
globalCheck(pkmn)
) {
pkmn.changed = !!pkmn.changed
pkmn.expire_timestamp_verified = !!pkmn.expire_timestamp_verified
finalResults.push(pkmn)
}
})
return finalResults
}

static async getLegacy(perms, args, { isMad, hasSize, hasHeight }) {
static async evalQuery(mem, query) {
return (
(mem
? fetchJson(mem, {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: query.toKnexQuery().toString(),
})
: query) || []
)
}

static async getLegacy(perms, args, { isMad, mem, hasSize, hasHeight }) {
const ts = Math.floor(new Date().getTime() / 1000)
const query = this.query()
.where(
Expand Down Expand Up @@ -440,30 +463,36 @@ module.exports = class Pokemon extends Model {
) {
return []
}
const results = await query
const results = await this.evalQuery(mem, query)
return legacyFilter(results, args, perms, ts)
}

static async getAvailable({ isMad }) {
const ts = Math.floor(new Date().getTime() / 1000)
const availableQuery = this.query()
.select(['pokemon_id', 'form'])
.where(
isMad ? 'disappear_time' : 'expire_timestamp',
'>=',
isMad ? this.knex().fn.now() : ts,
)
.groupBy('pokemon_id', 'form')
.orderBy('pokemon_id', 'form')
const rarityQuery = this.query()
.select(['pokemon_id AS id', 'form as formId'])
.count('pokemon_id AS count')
.groupBy('pokemon_id', 'form')
.where(
isMad ? 'disappear_time' : 'expire_timestamp',
'>=',
isMad ? this.knex().fn.now() : ts,
)
static async getAvailable({ isMad, mem }) {
const ts = Math.floor(Date.now() / 1000)
const availableQuery = this.evalQuery(
mem,
this.query()
.select(['pokemon_id', 'form'])
.where(
isMad ? 'disappear_time' : 'expire_timestamp',
'>=',
isMad ? this.knex().fn.now() : ts,
)
.groupBy('pokemon_id', 'form')
.orderBy('pokemon_id', 'form'),
)
const rarityQuery = this.evalQuery(
mem,
this.query()
.select(['pokemon_id AS id', 'form as formId'])
.count('pokemon_id AS count')
.groupBy('pokemon_id', 'form')
.where(
isMad ? 'disappear_time' : 'expire_timestamp',
'>=',
isMad ? this.knex().fn.now() : ts,
),
)

const [available, rarity] = await Promise.all([availableQuery, rarityQuery])

Expand All @@ -475,14 +504,17 @@ module.exports = class Pokemon extends Model {
}
}

static getOne(id, { isMad }) {
return this.query()
.select([
isMad ? 'latitude AS lat' : 'lat',
isMad ? 'longitude AS lon' : 'lon',
])
.where(isMad ? 'encounter_id' : 'id', id)
.first()
static getOne(id, { isMad, mem }) {
return this.evalQuery(
mem,
this.query()
.select([
isMad ? 'latitude AS lat' : 'lat',
isMad ? 'longitude AS lon' : 'lon',
])
.where(isMad ? 'encounter_id' : 'id', id)
.first(),
)
}

static async search(perms, args, { isMad }, distance) {
Expand Down
Loading

0 comments on commit 07a0c5f

Please sign in to comment.