Skip to content

Commit

Permalink
Merge pull request #1 from crqch/alpha
Browse files Browse the repository at this point in the history
0.1.1
  • Loading branch information
crqch authored Aug 30, 2024
2 parents c83c1b8 + 8a3a099 commit 404fbc2
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 25 deletions.
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "maz3",
"version": "0.1.0",
"version": "0.1.1",
"private": true,
"type": "module",
"author": {
Expand Down
15 changes: 10 additions & 5 deletions src/app/_components/leaderboard.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
"use client";

import React from "react";
import React, { useState } from "react";
import { MdArrowDownward, MdArrowUpward } from "react-icons/md";
import { api } from "~/trpc/react";

export default function Leaderboard() {
const query = api.get.getLeaderboard.useQuery()
const [page, setPage] = useState<number>(0);

const query = api.get.getLeaderboard.useQuery(page)

return <div className="flex flex-col gap-y-4">
{query.data?.length === 0 && <p className="text-black/80">Be first to appear on the leaderboard!</p>}
{query.data?.map(score => <div key={"score-" + score.name + score.time} className="flex flex-row justify-between items-center p-2 bg-black text-white">
return <div className="flex flex-col gap-y-4 items-center">
{(query.data?.maxPage ?? 1) === 0 && <p className="text-black/80">Be first to appear on the leaderboard!</p>}
{page > 0 && <MdArrowUpward className="cursor-pointer text-black/50" onClick={() => setPage(page - 1)} />}
{query.data?.results.map(score => <div key={"score-" + score.name + score.time} className="flex w-full flex-row justify-between items-center p-2 bg-black text-white">
<p className="font-bold">{score.time.toFixed(2)}</p>
<p>{score.name}</p>
</div>)}
{page < ((query.data?.maxPage ?? 20) - 1) && <MdArrowDownward className="cursor-pointer text-black/50" onClick={() => setPage(page + 1)} />}
<p onClick={() => query.refetch()} className="text-black/80 cursor-pointer">Refresh</p>
</div>
}
21 changes: 15 additions & 6 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,12 @@ export default function Game() {
const [lastMove, setLastMove] = useState("");
const timerRef = useRef<NodeJS.Timer>(null);
const [nickname, setNickname] = useState<string>("");
const [postResult, setPostResult] = useState<string>("");

const mutation = api.post.putScore.useMutation({
onSuccess: () => {
setGameTime(-1)
onSuccess: (r) => {
if(r[0] === 1) setGameTime(-1)
setPostResult(r[1])
}
})

Expand All @@ -90,6 +92,7 @@ export default function Game() {
const startGame = () => {
setGameStarted(true);
setGameTime(0);
setPostResult("")
//@ts-expect-error because it is necessary
timerRef.current = setInterval(() => {
setGameTime(prevTime => prevTime + 0.01);
Expand Down Expand Up @@ -129,6 +132,9 @@ export default function Game() {
let newX = playerPosition.x;
let newY = playerPosition.y;
let key = e.key

// Do not react if the target element is input
if(e.target !== undefined && (e.target as HTMLElement).tagName === "INPUT") return

switch(key.toLowerCase()){
case "a":
Expand Down Expand Up @@ -167,6 +173,8 @@ export default function Game() {
preventDefault(e)
if (isValidMove(newX, newY)) {
if (newY === 0 && !gameStarted) {
setFinished(false);
setPostResult("")
startGame()
} else if (newY < 0 && gameStarted) {
stopGame()
Expand Down Expand Up @@ -262,14 +270,15 @@ export default function Game() {
<div className="min-h-[80vh] flex flex-col">
{finished && <div style={{ marginTop: TILE_SIZE }} className="flex flex-col">
<h1>Congrats!</h1>
{gameTime !== -1 ? <>
{postResult !== "" && <div className="flex mb-8 flex-row justify-between items-center p-2 bg-black text-white">
<p>{postResult}</p>
</div>}
{gameTime !== -1 && <>
<p className="text-gray-400 mb-12">Your time: {gameTime.toFixed(2)}</p>
<p>Input your name to appear on the leaderboard!</p>
<input value={nickname} onChange={(e) => setNickname(e.target.value)} placeholder="Name or nickname" className="py-2 px-4 mt-4 bg-black/10 placeholder:text-black text-black hover:bg-black/10 active:bg-black/20 focus:bg-black/20 focus:outline-none transition-colors" />
<button onClick={submitScore} className="py-2 px-4 mb-8 bg-black/10 transition-colors hover:bg-black/20 active:bg-blue-700 active:text-white">Submit score</button>
</> : <div className="flex mb-8 flex-row justify-between items-center p-2 bg-black text-white">
<p>Successfully reported the score</p>
</div>}
</> }
<Leaderboard />
</div>}
</div>
Expand Down
2 changes: 2 additions & 0 deletions src/server/api/profanity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const profanity = ["4r5e", "5h1t", "5hit", "a55", "anal", "anus", "ar5e", "arrse", "arse", "ass", "ass-fucker", "asses", "assfucker", "assfukka", "asshole", "assholes", "asswhole", "a_s_s", "b!tch", "b00bs", "b17ch", "b1tch", "ballbag", "balls", "ballsack", "bastard", "beastial", "beastiality", "bellend", "bestial", "bestiality", "bi+ch", "biatch", "bitch", "bitcher", "bitchers", "bitches", "bitchin", "bitching", "bloody", "blow job", "blowjob", "blowjobs", "boiolas", "bollock", "bollok", "boner", "boob", "boobs", "booobs", "boooobs", "booooobs", "booooooobs", "breasts", "buceta", "bugger", "bum", "bunny fucker", "butt", "butthole", "buttmuch", "buttplug", "c0ck", "c0cksucker", "carpet muncher", "cawk", "chink", "cipa", "cl1t", "clit", "clitoris", "clits", "cnut", "cock", "cock-sucker", "cockface", "cockhead", "cockmunch", "cockmuncher", "cocks", "cocksuck", "cocksucked", "cocksucker", "cocksucking", "cocksucks", "cocksuka", "cocksukka", "cok", "cokmuncher", "coksucka", "coon", "cox", "crap", "cum", "cummer", "cumming", "cums", "cumshot", "cunilingus", "cunillingus", "cunnilingus", "cunt", "cuntlick", "cuntlicker", "cuntlicking", "cunts", "cyalis", "cyberfuc", "cyberfuck", "cyberfucked", "cyberfucker", "cyberfuckers", "cyberfucking", "d1ck", "damn", "dick", "dickhead", "dildo", "dildos", "dink", "dinks", "dirsa", "dlck", "dog-fucker", "doggin", "dogging", "donkeyribber", "doosh", "duche", "dyke", "ejaculate", "ejaculated", "ejaculates", "ejaculating", "ejaculatings", "ejaculation", "ejakulate", "f u c k", "f u c k e r", "f4nny", "fag", "fagging", "faggitt", "faggot", "faggs", "fagot", "fagots", "fags", "fanny", "fannyflaps", "fannyfucker", "fanyy", "fatass", "fcuk", "fcuker", "fcuking", "feck", "fecker", "felching", "fellate", "fellatio", "fingerfuck", "fingerfucked", "fingerfucker", "fingerfuckers", "fingerfucking", "fingerfucks", "fistfuck", "fistfucked", "fistfucker", "fistfuckers", "fistfucking", "fistfuckings", "fistfucks", "flange", "fook", "fooker", "fuck", "fucka", "fucked", "fucker", "fuckers", "fuckhead", "fuckheads", "fuckin", "fucking", "fuckings", "fuckingshitmotherfucker", "fuckme", "fucks", "fuckwhit", "fuckwit", "fudge packer", "fudgepacker", "fuk", "fuker", "fukker", "fukkin", "fuks", "fukwhit", "fukwit", "fux", "fux0r", "f_u_c_k", "gangbang", "gangbanged", "gangbangs", "gaylord", "gaysex", "goatse", "God", "god-dam", "god-damned", "goddamn", "goddamned", "hardcoresex", "hell", "heshe", "hoar", "hoare", "hoer", "homo", "hore", "horniest", "horny", "hotsex", "jack-off", "jackoff", "jap", "jerk-off", "jism", "jiz", "jizm", "jizz", "kawk", "knob", "knobead", "knobed", "knobend", "knobhead", "knobjocky", "knobjokey", "kock", "kondum", "kondums", "kum", "kummer", "kumming", "kums", "kunilingus", "l3i+ch", "l3itch", "labia", "lust", "lusting", "m0f0", "m0fo", "m45terbate", "ma5terb8", "ma5terbate", "masochist", "master-bate", "masterb8", "masterbat*", "masterbat3", "masterbate", "masterbation", "masterbations", "masturbate", "mo-fo", "mof0", "mofo", "mothafuck", "mothafucka", "mothafuckas", "mothafuckaz", "mothafucked", "mothafucker", "mothafuckers", "mothafuckin", "mothafucking", "mothafuckings", "mothafucks", "mother fucker", "motherfuck", "motherfucked", "motherfucker", "motherfuckers", "motherfuckin", "motherfucking", "motherfuckings", "motherfuckka", "motherfucks", "muff", "mutha", "muthafecker", "muthafuckker", "muther", "mutherfucker", "n1gga", "n1gger", "nazi", "nigg3r", "nigg4h", "nigga", "niggah", "niggas", "niggaz", "nigger", "niggers", "nob", "nob jokey", "nobhead", "nobjocky", "nobjokey", "numbnuts", "nutsack", "orgasim", "orgasims", "orgasm", "orgasms", "p0rn", "pawn", "pecker", "penis", "penisfucker", "phonesex", "phuck", "phuk", "phuked", "phuking", "phukked", "phukking", "phuks", "phuq", "pigfucker", "pimpis", "piss", "pissed", "pisser", "pissers", "pisses", "pissflaps", "pissin", "pissing", "pissoff", "poop", "porn", "porno", "pornography", "pornos", "prick", "pricks", "pron", "pube", "pusse", "pussi", "pussies", "pussy", "pussys", "rectum", "retard", "rimjaw", "rimming", "s hit", "s.o.b.", "sadist", "schlong", "screwing", "scroat", "scrote", "scrotum", "semen", "sex", "sh!+", "sh!t", "sh1t", "shag", "shagger", "shaggin", "shagging", "shemale", "shi+", "shit", "shitdick", "shite", "shited", "shitey", "shitfuck", "shitfull", "shithead", "shiting", "shitings", "shits", "shitted", "shitter", "shitters", "shitting", "shittings", "shitty", "skank", "slut", "sluts", "smegma", "smut", "snatch", "son-of-a-bitch", "spac", "spunk", "s_h_i_t", "t1tt1e5", "t1tties", "teets", "teez", "testical", "testicle", "tit", "titfuck", "tits", "titt", "tittie5", "tittiefucker", "titties", "tittyfuck", "tittywank", "titwank", "tosser", "turd", "tw4t", "twat", "twathead", "twatty", "twunt", "twunter", "v14gra", "v1gra", "vagina", "viagra", "vulva", "w00se", "wang", "wank", "wanker", "wanky", "whoar", "whore", "willies", "willy", "xrated", "xxx"];
export default profanity;
60 changes: 47 additions & 13 deletions src/server/api/root.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,65 @@
import { z } from "zod";
import { createCallerFactory, createTRPCRouter, publicProcedure } from "~/server/api/trpc";

import profanity from "~/server/api/profanity"

let leaderboard: {
name: string,
time: number
}[] = []

const lastRun: Record<string, number> = {}

const blacklist: Record<string, number> = {}

const addBlacklist = (ip: string) => {
if (blacklist[ip] !== undefined) {
blacklist[ip]++
} else {
blacklist[ip] = 1
}
}

export const appRouter = createTRPCRouter({
post: createTRPCRouter({
putScore: publicProcedure
.input(z.object({
name: z.string(),
time: z.number()
}))
.mutation(({ input }) => {
leaderboard.push(input)
leaderboard = leaderboard.sort((a, b) => a.time - b.time)
return "OK";
})
.input(z.object({
name: z.string(),
time: z.number()
}))
.mutation(({ input, ctx }): [number, string] => {
const ip = (ctx.headers.get('x-forwarded-for') ?? '127.0.0.1').split(',')[0]
if (input.time < 7) return [1, "Couldn't upload the score because it's too fast!"]
if (input.name.length < 3 && input.name !== "") return [0, "The name is too short"]
if (ip !== undefined && blacklist[ip] !== undefined) {
if (blacklist[ip] > 3) return [1, "You have been blacklisted"]
}
if (ip !== undefined && lastRun[ip] !== undefined) {
if (new Date().getTime() - input.time * 1000 + lastRun[ip] > 0) {
addBlacklist(ip)
return [1, "Timestamps mismatch"]
}
}
if (profanity.includes(input.name.toLowerCase())) {
if (ip !== undefined) {
addBlacklist(ip)
}
return [1, "This name contains profanity"]
}
leaderboard.push(input)
leaderboard = leaderboard.sort((a, b) => a.time - b.time)
if (ip !== undefined) lastRun[ip] = new Date().getTime()
return [1, "Successfully reported the score"];
})
}),
get: createTRPCRouter({
getLeaderboard: publicProcedure
.query(() => {
return leaderboard.slice(0, 10);
})
.input(z.number())
.query(({ input }) => {
return {
results: leaderboard.slice(input * 15, input * 15 + 15),
maxPage: Math.ceil(leaderboard.length / 15)
};
})
})
});

Expand Down

0 comments on commit 404fbc2

Please sign in to comment.