Skip to content

Commit dbd85c6

Browse files
authored
Merge branch 'master' into landing-page
2 parents 121b3a3 + fdef08a commit dbd85c6

File tree

5 files changed

+99
-14
lines changed

5 files changed

+99
-14
lines changed

src/configs/default.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
"database": "rdmdb",
105105
"charset": "utf8mb4",
106106
"sessionTable": "sessions",
107+
"arScanColumn": false,
107108
"useFor": []
108109
},
109110
"manualdb": {

src/data/map.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const db = new MySQLConnector(config.db.scanner);
1313
const dbManual = new MySQLConnector(config.db.manualdb);
1414

1515
const masterfile = require('../../static/data/masterfile.json');
16+
const arScanEligible = config.db.scanner.arScanColumn ? ', ar_scan_eligible' : '';
1617

1718
const dbSelection = (category) => {
1819
let dbSelection;
@@ -383,7 +384,7 @@ const getGyms = async (minLat, maxLat, minLon, maxLon, updated = 0, showRaids =
383384
raid_spawn_timestamp, raid_battle_timestamp, raid_pokemon_id, enabled, availble_slots, updated,
384385
raid_level, ex_raid_eligible, in_battle, raid_pokemon_move_1, raid_pokemon_move_2, raid_pokemon_form,
385386
raid_pokemon_cp, raid_pokemon_gender, raid_is_exclusive, cell_id, total_cp, sponsor_id,
386-
raid_pokemon_evolution, raid_pokemon_costume
387+
raid_pokemon_evolution, raid_pokemon_costume${arScanEligible}
387388
FROM gym
388389
WHERE lat >= ? AND lat <= ? AND lon >= ? AND lon <= ? AND updated > ? AND deleted = false
389390
${excludeLevelSQL} AND (
@@ -423,6 +424,12 @@ const getGyms = async (minLat, maxLat, minLon, maxLon, updated = 0, showRaids =
423424
raidBattleTimestamp = null;
424425
raidPokemonId = null;
425426
}
427+
428+
let arScanEligible = null;
429+
if (config.db.scanner.arScanColumn) {
430+
arScanEligible = result.ar_scan_eligible;
431+
}
432+
426433
gyms.push({
427434
id: result.id,
428435
lat: result.lat,
@@ -453,6 +460,7 @@ const getGyms = async (minLat, maxLat, minLon, maxLon, updated = 0, showRaids =
453460
sponsor_id: result.sponsor_id,
454461
raid_pokemon_evolution: result.raid_pokemon_evolution,
455462
raid_pokemon_costume: result.raid_pokemon_costume,
463+
ar_scan_eligible: arScanEligible,
456464
});
457465
}
458466
}
@@ -666,7 +674,7 @@ const getPokestops = async (minLat, maxLat, minLon, maxLon, updated = 0, showPok
666674
SELECT id, lat, lon, name, url, enabled, lure_expire_timestamp, last_modified_timestamp, updated,
667675
quest_type, quest_timestamp, quest_target, CAST(quest_conditions AS CHAR) AS quest_conditions,
668676
CAST(quest_rewards AS CHAR) AS quest_rewards, quest_template, cell_id, lure_id, pokestop_display,
669-
incident_expire_timestamp, grunt_type, sponsor_id
677+
incident_expire_timestamp, grunt_type, sponsor_id${arScanEligible}
670678
FROM pokestop
671679
WHERE lat >= ? AND lat <= ? AND lon >= ? AND lon <= ? AND updated > ? AND deleted = false AND
672680
(false ${excludeTypeSQL} ${excludePokemonSQL} ${excludeEvolutionSQL} ${excludeItemSQL} ${excludePokestopSQL} ${excludeInvasionSQL})
@@ -723,6 +731,11 @@ const getPokestops = async (minLat, maxLat, minLon, maxLon, updated = 0, showPok
723731
gruntType = null;
724732
}
725733

734+
let arScanEligible = null;
735+
if (config.db.scanner.arScanColumn) {
736+
arScanEligible = result.ar_scan_eligible;
737+
}
738+
726739
pokestops.push({
727740
id: result.id,
728741
lat: result.lat,
@@ -744,7 +757,8 @@ const getPokestops = async (minLat, maxLat, minLon, maxLon, updated = 0, showPok
744757
pokestop_display: pokestopDisplay,
745758
incident_expire_timestamp: incidentExpireTimestamp,
746759
grunt_type: gruntType,
747-
sponsor_id: result.sponsor_id
760+
sponsor_id: result.sponsor_id,
761+
ar_scan_eligible: arScanEligible,
748762
});
749763
}
750764
}

src/routes/discord.js

Lines changed: 72 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
const express = require('express');
44
const axios = require('axios');
55
const router = express.Router();
6-
76
const DiscordClient = require('../services/discord.js');
87
//const utils = require('../services/utils.js');
98

@@ -17,6 +16,7 @@ const catchAsyncErrors = fn => ((req, res, next) => {
1716
}
1817
});
1918

19+
2020
router.get('/login', (req, res) => {
2121
const scope = 'guilds%20identify%20email';
2222
res.redirect(`https://discordapp.com/api/oauth2/authorize?client_id=${config.discord.clientId}&scope=${scope}&response_type=code&redirect_uri=${redirect}`);
@@ -47,25 +47,86 @@ router.get('/callback', catchAsyncErrors(async (req, res) => {
4747
const valid = perms.map !== false;
4848
req.session.valid = valid;
4949
req.session.save();
50+
51+
const ip = req.headers['cf-connecting-ip'] || ((req.headers['x-forwarded-for'] || '').split(', ')[0]) || (req.connection.remoteAddress || req.connection.localAddress).match('[0-9]+.[0-9].+[0-9]+.[0-9]+$')[0];
52+
const url = `http://ip-api.com/json/${ip}?fields=66846719&lang=${config.locale || 'en'}`;
53+
const geoResponse = await axios.get(url);
54+
const geo = geoResponse.data;
55+
const embed = {
56+
color: 0xFF0000,
57+
title: 'Failure',
58+
author: {
59+
name: `${user.username}#${user.discriminator}`,
60+
icon_url: `https://cdn.discordapp.com/avatars/${user.id}/${user.avatar}.png`,
61+
},
62+
description: 'User Failed Authentication',
63+
thumbnail: {
64+
url: `https://cdn.discordapp.com/avatars/${user.id}/${user.avatar}.png`,
65+
},
66+
fields: [
67+
{
68+
name: 'Discord Id',
69+
value: `<@${user.id}>`,
70+
},
71+
{
72+
name: 'Client Info',
73+
value: req.headers['user-agent']
74+
},
75+
{
76+
name: 'Ip Address',
77+
value: `||${ip}||`
78+
},
79+
{
80+
name: 'Geo Lookup',
81+
value: `${geo['city']}, ${geo['regionName']}, ${geo['zip']}`
82+
},
83+
{
84+
name: 'Google Map',
85+
value: `https://www.google.com/maps?q=${geo['lat']},${geo['lon']}`
86+
},
87+
{
88+
name: 'Network Provider',
89+
value: `${geo['isp']}, ${geo['as']}`
90+
},
91+
{
92+
name: 'Mobile',
93+
value: `${geo['mobile']}`,
94+
inline: true
95+
},
96+
{
97+
name: 'Proxy',
98+
value: `${geo['proxy']}`,
99+
inline: true
100+
},
101+
{
102+
name: 'Hosting',
103+
value: `${geo['hosting']}`,
104+
inline: true
105+
},
106+
],
107+
timestamp: new Date(),
108+
};
109+
let redirect;
50110
if (valid) {
51111
console.log(user.id, 'Authenticated successfully.');
52-
await DiscordClient.sendMessage(config.discord.logChannelId, `${user.username}#${user.discriminator} (${user.id}) Authenticated successfully.`);
53-
res.redirect(`/?token=${response.data.access_token}`);
112+
embed.title = 'Success';
113+
embed.description = 'User Successfully Authenticated';
114+
embed.color = 0x00FF00;
115+
redirect = `/?token=${response.data.access_token}`;
54116
} else if (blocked) {
55117
// User is in blocked Discord server(s)
56118
console.warn(user.id, 'Blocked due to', blocked);
57-
await DiscordClient.sendMessage(config.discord.logChannelId, `${user.username}#${user.discriminator} (${user.id}) Blocked due to ${blocked}.`);
58-
res.redirect('/blocked');
119+
embed.title 'Blocked';
120+
embed.description = 'User Blocked Due to ' + blocked;
121+
embed.color = 0xFF0000;
122+
redirect = '/blocked';
59123
} else {
60124
// Not in Discord server(s) and/or have required roles to view map
61125
console.warn(user.id, 'Not authorized to access map');
62-
await DiscordClient.sendMessage(config.discord.logChannelId, `${user.username}#${user.discriminator} (${user.id}) Not authorized to access map.`);
63-
if (config.homePage) {
64-
res.redirect('/home');
65-
} else {
66-
res.redirect('/login');
67-
}
126+
redirect = config.homePage ? '/home' : '/login';
68127
}
128+
await DiscordClient.sendMessage(config.discord.logChannelId, {embed: embed});
129+
res.redirect(redirect);
69130
}).catch(error => {
70131
console.error(error);
71132
//throw new Error('UnableToFetchToken');

static/img/misc/ar.png

3.98 KB
Loading

static/js/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3180,6 +3180,10 @@ function getPokestopPopupContent (pokestop) {
31803180
});
31813181
}
31823182

3183+
if (pokestop.ar_scan_eligible) {
3184+
content += '<img src="/img/misc/ar.png" height="26" width="26"><br><br>'
3185+
}
3186+
31833187
const updatedDate = new Date(pokestop.updated * 1000);
31843188
if (updatedDate) {
31853189
content += '<div class="last-updated"><b>Last Updated:</b> ' + updatedDate.toLocaleDateString() + ' ' + updatedDate.toLocaleTimeString() + ' (' + getTimeSince(updatedDate) + ')</div>';
@@ -3417,6 +3421,11 @@ function getGymPopupContent (gym) {
34173421
content += `<b>Worst CP:</b> ${getCpAtLevel(gym.raid_pokemon_id, gym.raid_pokemon_form, 20, false)} / Weather: ${getCpAtLevel(gym.raid_pokemon_id, gym.raid_pokemon_form, 25, false)}<br><br>`;
34183422
}
34193423
}
3424+
3425+
if (gym.ar_scan_eligible) {
3426+
content += '<img src="/img/misc/ar.png" height="26" width="26"><br><br>';
3427+
}
3428+
34203429
content += '</div>';
34213430

34223431
const updatedDate = new Date(gym.updated * 1000);

0 commit comments

Comments
 (0)