Skip to content

Commit

Permalink
Fixes stale user issue for longer play durations.
Browse files Browse the repository at this point in the history
  • Loading branch information
zachrip committed Mar 19, 2023
1 parent 7fef028 commit bea050c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 44 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "valpal",
"version": "0.0.4",
"version": "0.0.5",
"private": true,
"sideEffects": false,
"scripts": {
Expand Down
26 changes: 8 additions & 18 deletions server/appman.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,11 @@ export class AppManager {
rejectUnauthorized: false,
});

let user: User;

const matchCharacterSelectionStates = new Map<string, string>();

ws.on('open', async () => {
try {
console.log('Connected to websocket');

user = (await getUser())!;

ws.send(JSON.stringify([5, 'OnJsonApiEvent']));
} catch (e) {
console.warn('Caught error in websocket open handler', e);
Expand All @@ -152,10 +147,6 @@ export class AppManager {

ws.on('message', async (data) => {
try {
if (!user) {
return;
}

const parsed = tryParseJson<[number, string, object]>(
data.toString()
);
Expand Down Expand Up @@ -188,6 +179,13 @@ export class AppManager {
return;
}

const user = await getUser();

if (!user) {
console.log('User not found');
return;
}

const match = await user.getPregame();

const player = match.AllyTeam.Players.find(
Expand Down Expand Up @@ -228,15 +226,7 @@ export class AppManager {
});

ws.on('error', (err) => {
try {
abortController?.abort();
console.log('Error:', err);
setTimeout(() => {
this.connect();
}, 5000);
} catch (e) {
console.warn('Caught error in websocket error handler:', e);
}
console.warn('WS error:', err);
});
} catch (e) {
console.warn('Caught error in connect method:', e);
Expand Down
9 changes: 0 additions & 9 deletions server/userman.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,6 @@ const httpClient = axios.create({
httpsAgent: agent,
});

const parseTokensFromUrl = (uri: string) => {
const url = new URL(uri);

return {
accessToken: url.searchParams.get('access_token')!,
idToken: url.searchParams.get('id_token')!,
};
};

function getPlayerDataServiceUrl(region: Regions) {
return `https://pd.${region}.a.pvp.net`;
}
Expand Down
17 changes: 1 addition & 16 deletions server/valorantApi.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import https from 'https';

import axios from 'axios';
import type {
Buddy,
Expand All @@ -10,20 +8,7 @@ import type {
PlayerTitle,
} from 'types';

const agent = new https.Agent({
ciphers: [
'TLS_CHACHA20_POLY1305_SHA256',
'TLS_AES_128_GCM_SHA256',
'TLS_AES_256_GCM_SHA384',
'TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256',
].join(':'),
honorCipherOrder: true,
minVersion: 'TLSv1.2',
});

const httpClient = axios.create({
httpsAgent: agent,
});
const httpClient = axios.create();

async function getWeapons() {
const { data } = await httpClient.get<{
Expand Down
2 changes: 2 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"target": "ES2019",
"strict": true,
"allowJs": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"forceConsistentCasingInFileNames": true,
"baseUrl": ".",
"paths": {
Expand Down

0 comments on commit bea050c

Please sign in to comment.