Skip to content

Commit

Permalink
Fix: Adjust Match PUT call to ensure servers in use cannot be used.
Browse files Browse the repository at this point in the history
Feat: Update versions of packages and fix errors.
  • Loading branch information
PhlexPlexico committed May 16, 2024
1 parent 6531892 commit 665983f
Show file tree
Hide file tree
Showing 5 changed files with 198 additions and 221 deletions.
12 changes: 5 additions & 7 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import config from "config";
import connectRedis from "connect-redis";
import RedisStore from "connect-redis";
import cookieParser from "cookie-parser";
import cors from "cors";
import express from "express";
Expand Down Expand Up @@ -57,11 +57,9 @@ app.use(helmet());
if (config.get("server.useRedis")) {
// Messy but avoids any open file handles.
const redisClient = createClient({
legacyMode: true,
url: config.get("server.redisUrl"),
});

const redisStore = connectRedis(session);
await redisClient.connect();
redisClient.on("error", (err) => {
console.log("Redis error: ", err);
Expand All @@ -77,8 +75,8 @@ if (config.get("server.useRedis")) {
name: "G5API",
resave: false,
saveUninitialized: true,
store: new redisStore(redisCfg),
cookie: { maxAge: 3600000 },
store: new RedisStore(redisCfg),
cookie: { maxAge: 86400000 },
})
);
} else {
Expand All @@ -88,7 +86,7 @@ if (config.get("server.useRedis")) {
name: "G5API",
resave: false,
saveUninitialized: true,
cookie: { maxAge: 3600000 },
cookie: { maxAge: 86400000 },
})
);
}
Expand Down Expand Up @@ -116,7 +114,7 @@ const options = {
openapi: "3.0.0", // Specification (optional, defaults to swagger: '2.0')
info: {
title: "G5API", // Title (required)
version: "2.0.0" // Version (required)
version: "2.0.2.4" // Version (required)
}
},
// Path to the API docs
Expand Down
38 changes: 19 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "g5api",
"version": "2.0.2.3",
"version": "2.0.2.4",
"private": true,
"type": "module",
"licenses": [
Expand Down Expand Up @@ -68,35 +68,35 @@
"dependencies": {
"@node-steam/id": "^1.2.0",
"aes-js": "^3.1.2",
"bcrypt": "^5.1.0",
"compare-versions": "^6.0.0-rc.2",
"config": "^3.3.7",
"connect-redis": "^6.1.3",
"bcrypt": "^5.1.1",
"compare-versions": "^6.1.0",
"config": "^3.3.11",
"connect-redis": "^7.1.1",
"cookie-parser": "~1.4.6",
"cors": "^2.8.5",
"db-migrate": "^0.11.13",
"db-migrate-mysql": "^2.2.0",
"debug": "~4.3.1",
"debug": "~4.3.4",
"express": "~4.19.2",
"express-bearer-token": "^2.4.0",
"express-rate-limit": "^6.7.0",
"express-session": "^1.17.0",
"helmet": "^6.0.0",
"http-errors": "~1.7.3",
"jszip": "^3.7.0",
"express-rate-limit": "^7.2.0",
"express-session": "^1.18.0",
"helmet": "^7.1.0",
"http-errors": "~2.0.0",
"jszip": "^3.10.1",
"morgan": "^1.10.0",
"mysql2": "^3.9.4",
"node-fetch": "^3.2.0",
"mysql2": "^3.9.7",
"node-fetch": "^3.3.2",
"passport": "^0.6.0",
"passport-local": "^1.0.0",
"passport-steam": "^1.0.18",
"pm2": "^5.3.0",
"randomstring": "^1.2.2",
"pm2": "^5.3.1",
"randomstring": "^1.3.0",
"rcon": "^1.1.0",
"redis": "^4.3.0",
"steamapi": "^2.2.0",
"swagger-jsdoc": "^6.2.5",
"swagger-ui-express": "^4.5.0"
"redis": "^4.6.13",
"steamapi": "^3.0.8",
"swagger-jsdoc": "^6.2.8",
"swagger-ui-express": "^5.0.0"
},
"devDependencies": {
"@types/aes-js": "^3.1.1",
Expand Down
6 changes: 6 additions & 0 deletions src/routes/matches/matches.js
Original file line number Diff line number Diff line change
Expand Up @@ -1371,6 +1371,12 @@ router.put("/", Utils.ensureAuthenticated, async (req, res, next) => {
return;
}
if (req.body[0].server_id != matchRow[0].server_id) diffServer = true;
if (returnedServer[0].in_use) {
res.status(401).json({
message: "Server is already in use, please select a different server."
});
return;
}
}

let vetoSql =
Expand Down
14 changes: 8 additions & 6 deletions src/utility/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import config from "config";
/** Steam API Handler for custom URLs
* @const
*/
import SteamURLResolver from "steamapi";
const SteamAPI = new SteamURLResolver(config.get("server.steamAPIKey"));
import SteamAPI from "steamapi";
const steam = new SteamAPI(config.get("server.steamAPIKey"));
/** Steam ID Handler for other IDs.
* @const
*/
Expand Down Expand Up @@ -217,7 +217,7 @@ class Utils {
// Remove any https tags, as they aren't needed.
authString = authString.replace(new RegExp("^(http|https)://", "i"), "");
if (authString.includes("steamcommunity.com/id/")) {
let steamID = await SteamAPI.resolve(authString);
let steamID = await steam.resolve(authString);
return steamID;
} else if (authString.includes("steamcommunity.com/profiles/")) {
return authString.split("/")[2];
Expand All @@ -232,7 +232,7 @@ class Utils {
} else if (authString.startsWith("7656119")) {
return authString;
} else {
let steamID = await SteamAPI.resolve(
let steamID = await steam.resolve(
"steamcommunity.com/id/" + authString
);
return steamID;
Expand All @@ -248,7 +248,8 @@ class Utils {
*/
static async getSteamName(auth64: string) {
try {
let summaryInfo = await SteamAPI.getUserSummary(auth64);
let summaryInfo = await steam.getUserSummary(auth64);
// @ts-expect-error
return summaryInfo.nickname;
} catch {
return null;
Expand All @@ -265,7 +266,8 @@ class Utils {
*/
static async getSteamImage(auth64: string) {
try {
let summaryInfo = await SteamAPI.getUserSummary(auth64);
let summaryInfo = await steam.getUserSummary(auth64);
// @ts-expect-error
return summaryInfo.avatar.medium;
} catch {
return null;
Expand Down
Loading

0 comments on commit 665983f

Please sign in to comment.