Skip to content

Commit

Permalink
Merge pull request #107 from agrattan0820/dev
Browse files Browse the repository at this point in the history
v0.3.15
  • Loading branch information
agrattan0820 authored Oct 12, 2023
2 parents 14748f3 + 7394246 commit 692dada
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 25 deletions.
2 changes: 1 addition & 1 deletion apps/client/src/components/game/game-machine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export const gameMachine = createMachine(

faceOffResults: {
after: {
20000: [
18000: [
{
target: "winnerLeadUp",
cond: "completedRounds",
Expand Down
12 changes: 6 additions & 6 deletions apps/client/src/components/game/game-machine.typegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export interface Typegen0 {
"xstate.after(10000)#Machine.winner": {
type: "xstate.after(10000)#Machine.winner";
};
"xstate.after(20000)#Machine.faceOffResults": {
type: "xstate.after(20000)#Machine.faceOffResults";
"xstate.after(18000)#Machine.faceOffResults": {
type: "xstate.after(18000)#Machine.faceOffResults";
};
"xstate.after(4000)#Machine.nextRound": {
type: "xstate.after(4000)#Machine.nextRound";
Expand All @@ -34,14 +34,14 @@ export interface Typegen0 {
services: never;
};
eventsCausingActions: {
incrementQuestionIdx: "xstate.after(20000)#Machine.faceOffResults";
incrementQuestionIdx: "xstate.after(18000)#Machine.faceOffResults";
resetContext: "NEXT";
startNewRound: "xstate.after(20000)#Machine.faceOffResults";
startNewRound: "xstate.after(18000)#Machine.faceOffResults";
};
eventsCausingDelays: {};
eventsCausingGuards: {
completedCurrentRound: "xstate.after(20000)#Machine.faceOffResults";
completedRounds: "xstate.after(20000)#Machine.faceOffResults";
completedCurrentRound: "xstate.after(18000)#Machine.faceOffResults";
completedRounds: "xstate.after(18000)#Machine.faceOffResults";
};
eventsCausingServices: {};
matchesStates:
Expand Down
19 changes: 1 addition & 18 deletions apps/server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,6 @@ export function buildServer() {
// Rate limiter
// Based on https://redis.io/commands/incr#pattern-rate-limiter-1
app.use(async (req, res, next) => {
const isIPBlocked = await redis.get(`BLOCKED_${req.ip}`);

if (isIPBlocked) {
res.status(429).send("Too many requests - try again tomorrow");
return;
}

let redisIncr: number;
try {
redisIncr = await redis.incr(req.ip);
Expand All @@ -82,17 +75,7 @@ export function buildServer() {
throw error;
}
if (redisIncr > 10) {
const today = new Date();
const tomorrow = new Date(today);
tomorrow.setDate(tomorrow.getDate() + 1);
tomorrow.setHours(0, 0, 0, 0);
await redis.set(`BLOCKED_${req.ip}`, tomorrow.toISOString());
await redis.expireat(
`BLOCKED_${req.ip}`,
Math.floor(tomorrow.getTime() / 1000)
);
console.log("Blocked the IP Address:", req.ip);
res.status(429).send("Too many requests - try again tomorrow");
res.status(429).send("Too many requests - try again later");
return;
}
await redis.expire(req.ip, 10);
Expand Down

1 comment on commit 692dada

@vercel
Copy link

@vercel vercel bot commented on 692dada Oct 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.