Skip to content

Commit

Permalink
Big bfix
Browse files Browse the repository at this point in the history
  • Loading branch information
atul24112001 committed Nov 8, 2024
1 parent 191d834 commit dacf97e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
17 changes: 10 additions & 7 deletions server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ var upgrader = websocket.Upgrader{
WriteBufferSize: 1024,
CheckOrigin: func(r *http.Request) bool {
origin := r.Header.Get("origin")
log.Println("Origin", origin)
return origin == os.Getenv("FRONTEND_URL")
},
}
Expand All @@ -36,11 +35,6 @@ func handleWebSocket(w http.ResponseWriter, r *http.Request) {
return
}

if lib.UnderMaintenance {
log.Println("Under maintenance:", err)
return
}

var userId string
for {
_, message, err := conn.ReadMessage()
Expand Down Expand Up @@ -68,7 +62,16 @@ func handleWebSocket(w http.ResponseWriter, r *http.Request) {
case "add-user":
userId = gameManager.GetInstance().AddUser(messageData["userId"].(string), messageData["publicKey"].(string), conn)
case "join-random-game":
gameManager.GetInstance().JoinGame(userId, messageData["gameTypeId"].(string))
if lib.UnderMaintenance {
targetUser, exist := gameManager.GetInstance().GetUser(userId)
if exist {
targetUser.SendMessage("error", map[string]interface{}{
"message": "We are under maintenance please try after some time",
})
}
} else {
gameManager.GetInstance().JoinGame(userId, messageData["gameTypeId"].(string))
}
case "update-board":
gameManager.GetInstance().UpdateBoard(messageData["gameId"].(string), userId)
case "game-over":
Expand Down
5 changes: 5 additions & 0 deletions web/src/sections/game/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ export default function GameClient({ gameType }: Props) {
};
});
router.push("/");
} else if (type === "error") {
toast(data?.message || "Something went wrong", {
duration: 2000,
});
router.push("/");
}
};
}
Expand Down
2 changes: 1 addition & 1 deletion web/src/sections/home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export default function ClientHomePage() {
)}
{underMaintenance && (
<div className=" text-sm font-bold px-2 text-red-500 rounded-lg py-1">
We are currently under maintenance so please try to add
We are currently under maintenance so, please try to add
funds after sometime
</div>
)}
Expand Down

0 comments on commit dacf97e

Please sign in to comment.