From 25c93b1ddcc5a5a9aaea9e3eb91074e7524bcfce Mon Sep 17 00:00:00 2001 From: Harsh Pandey Date: Thu, 13 Jul 2023 14:20:11 -0400 Subject: [PATCH] fix uno and poker --- .../client/web/src/context/GameContext.tsx | 19 ++++++++----------- examples/uno/Dockerfile | 14 ++++++-------- .../client/web/src/context/GameContext.tsx | 17 +++++++---------- 3 files changed, 21 insertions(+), 29 deletions(-) diff --git a/examples/poker/client/web/src/context/GameContext.tsx b/examples/poker/client/web/src/context/GameContext.tsx index 838848dc..18e33c6c 100644 --- a/examples/poker/client/web/src/context/GameContext.tsx +++ b/examples/poker/client/web/src/context/GameContext.tsx @@ -3,8 +3,8 @@ import { toast, ToastContainer } from "react-toastify"; import { useSessionstorageState } from "rooks"; import { HathoraClient, HathoraConnection } from "../../../.hathora/client"; import { ConnectionFailure } from "../../../.hathora/failures"; -import { IInitializeRequest, PlayerState, RoundStatus } from "../../../../api/types"; -import { lookupUser, Response, UserData } from "../../../../api/base"; +import { PlayerState, RoundStatus } from "../../../../api/types"; +import { Response } from "../../../../api/base"; interface GameContext { token?: string; @@ -19,7 +19,7 @@ interface GameContext { connectionError?: ConnectionFailure; endGame: () => void; getUserName: (id: string) => string; - user?: UserData; + user?: { id: string }; connecting?: boolean; loggingIn?: boolean; fold: () => Promise; @@ -60,11 +60,11 @@ export default function HathoraContextProvider({ children }: HathoraContextProvi const [connectionError, setConnectionError] = useState(); const [connecting, setConnecting] = useState(); const [loggingIn, setLoggingIn] = useState(); - const [playerNameMapping, setPlayerNameMapping] = useSessionstorageState>( + const [playerNameMapping, setPlayerNameMapping] = useSessionstorageState>( `${client.appId}_player_mapping`, {} ); - const [user, setUserInfo] = useState(); + const [user, setUserInfo] = useState<{id: string}>(); const isLoginIn = useRef(false); const login = async () => { @@ -112,11 +112,11 @@ export default function HathoraContextProvider({ children }: HathoraContextProvi const createGame = useCallback(async () => { if (token) { - return client.create(token, IInitializeRequest.default()); + return client.createPrivateLobby(token); } else { const token = (await login()) ?? ""; - return client.create(token, IInitializeRequest.default()); + return client.createPrivateLobby(token); } }, [token]); @@ -179,11 +179,8 @@ export default function HathoraContextProvider({ children }: HathoraContextProvi const getUserName = useCallback( (userId: string) => { if (Boolean(playerNameMapping[userId])) { - return playerNameMapping[userId].name; + return playerNameMapping[userId].id; } else { - lookupUser(userId).then((response) => { - setPlayerNameMapping((curr) => ({ ...curr, [userId]: response })); - }); return userId; } }, diff --git a/examples/uno/Dockerfile b/examples/uno/Dockerfile index 923e31b4..e45a3a1e 100644 --- a/examples/uno/Dockerfile +++ b/examples/uno/Dockerfile @@ -1,15 +1,13 @@ -FROM node:16 +FROM node:18 WORKDIR /app -RUN npm i -g hathora@0.9.26 - -ENV NODE_ENV=production +COPY . . -ARG APP_SECRET -ENV APP_SECRET=${APP_SECRET} +RUN npm i -g hathora@0.11.5 +RUN npx hathora build --only server -COPY . . -RUN hathora build --only server +ENV NODE_ENV=production +ENV DATA_DIR=/app/data CMD ["node", "server/dist/index.mjs"] diff --git a/examples/uno/client/web/src/context/GameContext.tsx b/examples/uno/client/web/src/context/GameContext.tsx index 03a33846..490debdd 100644 --- a/examples/uno/client/web/src/context/GameContext.tsx +++ b/examples/uno/client/web/src/context/GameContext.tsx @@ -4,7 +4,7 @@ import { useSessionstorageState } from "rooks"; import { HathoraClient, HathoraConnection } from "../../../.hathora/client"; import { ConnectionFailure } from "../../../.hathora/failures"; import { Card, PlayerState, IInitializeRequest } from "../../../../api/types"; -import { lookupUser, UserData, Response } from "../../../../api/base"; +import { Response, UserData } from "../../../../api/base"; interface GameContext { token?: string; @@ -20,7 +20,7 @@ interface GameContext { drawCard: () => Promise; endGame: () => void; getUserName: (id: string) => string; - user?: UserData; + user?: { id: string }; connecting?: boolean; loggingIn?: boolean; } @@ -58,11 +58,11 @@ export default function HathoraContextProvider({ children }: HathoraContextProvi const [connectionError, setConnectionError] = useState(); const [connecting, setConnecting] = useState(); const [loggingIn, setLoggingIn] = useState(); - const [playerNameMapping, setPlayerNameMapping] = useSessionstorageState>( + const [playerNameMapping, setPlayerNameMapping] = useSessionstorageState>( `${client.appId}_player_mapping`, {} ); - const [user, setUserInfo] = useState(); + const [user, setUserInfo] = useState<{ id: string }>(); const isLoginIn = useRef(false); const login = async () => { @@ -110,10 +110,10 @@ export default function HathoraContextProvider({ children }: HathoraContextProvi const createGame = useCallback(async () => { if (token) { - return client.create(token, IInitializeRequest.default()); + return client.createPrivateLobby(token); } else { const token = await login()!; - return client.create(token!, IInitializeRequest.default()); + return client.createPrivateLobby(token!); } }, [token]); @@ -160,11 +160,8 @@ export default function HathoraContextProvider({ children }: HathoraContextProvi const getUserName = useCallback( (userId: string) => { if (Boolean(playerNameMapping[userId])) { - return playerNameMapping[userId].name; + return playerNameMapping[userId].id; } else { - lookupUser(userId).then((response) => { - setPlayerNameMapping((curr) => ({ ...curr, [userId]: response })); - }); return userId; } },