Skip to content

Commit

Permalink
Add ESLint, fix code accordingly, add rival scores
Browse files Browse the repository at this point in the history
  • Loading branch information
RubberDuckShobe committed May 13, 2023
1 parent fd371da commit ed29746
Show file tree
Hide file tree
Showing 9 changed files with 2,732 additions and 1,504 deletions.
8 changes: 8 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* eslint-env node */
module.exports = {
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
ignorePatterns: ["*.js"],
root: true,
};
2 changes: 1 addition & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const fastify = Fastify({
},
});

fastify.listen({ port: WavebreakerConfig.port }, (err, address) => {
fastify.listen({ port: WavebreakerConfig.port }, (err) => {
if (err) {
fastify.log.error(err);
process.exit(1);
Expand Down
3,689 changes: 2,426 additions & 1,263 deletions package-lock.json

Large diffs are not rendered by default.

11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,22 @@
"homepage": "https://github.com/AudiosurfResearch/Wavebreaker#readme",
"devDependencies": {
"@types/node": "^18.6.1",
"@types/steamapi": "^2.2.2",
"@types/steamid": "^2.0.1",
"@types/xml2js": "^0.4.11",
"@typescript-eslint/eslint-plugin": "^5.59.5",
"@typescript-eslint/parser": "^5.59.5",
"eslint": "^8.40.0",
"prisma": "^4.1.1",
"ts-node": "^10.9.1",
"tslint": "^6.1.3",
"typescript": "^4.7.4"
},
"dependencies": {
"@fastify/formbody": "^7.0.1",
"@prisma/client": "^4.1.1",
"fastify": "^4.3.0",
"musicbrainz-api": "^0.9.0",
"xml2js": "^0.4.23"
"steamapi": "^2.2.0",
"steamid": "^2.0.0",
"xml2js": "^0.5.0"
}
}
4 changes: 2 additions & 2 deletions prisma/seed.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PrismaClient, Prisma, User } from "@prisma/client";
import { PrismaClient, User } from "@prisma/client";
const prisma = new PrismaClient();

async function main() {
Expand All @@ -7,7 +7,7 @@ async function main() {
update: {},
create: {
username: "John Audiosurf",
steamid64: 76561198315672331,
steamid64: 76561198315672331n,
steamid32: 355406603,
locationid: 123,
},
Expand Down
127 changes: 58 additions & 69 deletions routes/as1/accounts.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FastifyInstance } from "fastify";
import { PrismaClient, User } from "@prisma/client";
import { SteamUtils } from "../../util/steam";
import * as SteamUtils from "../../util/steam";
import xml2js from "xml2js";
import SteamID from "steamid";

Expand Down Expand Up @@ -29,40 +29,29 @@ interface SteamSyncRequest {
achstates: string;
}

export default async function routes(
fastify: FastifyInstance,
options: Object
) {
export default async function routes(fastify: FastifyInstance) {
fastify.post<{
Body: SteamLoginRequest;
}>(
"/as_steamlogin/game_AttemptLoginSteamVerified.php",
async (request, reply) => {
try {
const steamTicketResponse = await SteamUtils.verifySteamTicket(
request.body.ticket
);
const steamId = new SteamID(
steamTicketResponse.response.params.steamid
);
const steamUser = await SteamUtils.steamApi.getUserSummary(
steamId.getSteamID64()
);
}>("/as_steamlogin/game_AttemptLoginSteamVerified.php", async (request) => {
try {
const steamTicketResponse = await SteamUtils.verifySteamTicket(
request.body.ticket
);
const steamId = new SteamID(steamTicketResponse.response.params.steamid);
const steamUser = await SteamUtils.steamApi.getUserSummary(
steamId.getSteamID64()
);

var user: User = await prisma.user.upsert({
where: { steamid64: steamId.getBigIntID() },
update: { username: steamUser.nickname },
create: {
username: steamUser.nickname,
steamid64: steamId.getBigIntID(),
steamid32: steamId.accountid,
locationid: 1,
},
});
} catch (e) {
console.error(e);
return e;
}
const user: User = await prisma.user.upsert({
where: { steamid64: steamId.getBigIntID() },
update: { username: steamUser.nickname },
create: {
username: steamUser.nickname,
steamid64: steamId.getBigIntID(),
steamid32: steamId.accountid,
locationid: 1,
},
});

return xmlBuilder.buildObject({
RESULT: {
Expand All @@ -75,72 +64,69 @@ export default async function routes(
steamid: user.steamid32, //SteamID32, not ID64
},
});
} catch (e) {
console.error(e);
return e;
}
);
});

fastify.post<{
Body: UpdateLocationRequest;
}>("/as_steamlogin/game_UpdateLocationid.php", async (request, reply) => {
}>("/as_steamlogin/game_UpdateLocationid.php", async (request) => {
try {
const steamTicketResponse = await SteamUtils.verifySteamTicket(
request.body.ticket
);

var user: User = await prisma.user.update({
await prisma.user.update({
where: {
steamid64: BigInt(steamTicketResponse.response.params.steamid),
},
data: {
locationid: +request.body.locationid,
},
});

return xmlBuilder.buildObject({
RESULT: {
$: {
status: "success",
},
},
});
} catch (e) {
console.error(e);
return e;
}

return xmlBuilder.buildObject({
RESULT: {
$: {
status: "success",
},
},
});
});

fastify.post<{
Body: SteamSyncRequest;
}>(
"/as_steamlogin/game_SteamSyncSteamVerified.php",
async (request, reply) => {
try {
const steamTicketResponse = await SteamUtils.verifySteamTicket(
request.body.ticket
);
}>("/as_steamlogin/game_SteamSyncSteamVerified.php", async (request) => {
try {
const steamTicketResponse = await SteamUtils.verifySteamTicket(
request.body.ticket
);

var steamFriendList: number[] = request.body.snums
.split("x")
.map(Number);
const steamFriendList: number[] = request.body.snums
.split("x")
.map(Number);

try {
await prisma.user.update({
where: {
steamid64: BigInt(steamTicketResponse.response.params.steamid),
},
data: {
rivals: {
connect: steamFriendList.map((steamid32) => ({ steamid32 })),
},
try {
await prisma.user.update({
where: {
steamid64: BigInt(steamTicketResponse.response.params.steamid),
},
data: {
rivals: {
connect: steamFriendList.map((steamid32) => ({ steamid32 })),
},
});
} catch (e) {
console.error(e);
}
},
});
} catch (e) {
console.error(e);
return e;
}

//Nowhere near close to the response the real server gives
//We do not need to care for this endpoint though, because neither will the client
return xmlBuilder.buildObject({
Expand All @@ -150,6 +136,9 @@ export default async function routes(
},
},
});
} catch (e) {
console.error(e);
return e;
}
);
});
}
Loading

0 comments on commit ed29746

Please sign in to comment.