From 72f88cbc653cf150a4d4771b1a9ab9af6b7289b5 Mon Sep 17 00:00:00 2001
From: aaravbajaj012 <97072650+aaravbajaj012@users.noreply.github.com>
Date: Sat, 27 Jan 2024 13:50:00 -0500
Subject: [PATCH] allow matches even if random map
---
src/pages/api/user/match-request.ts | 22 +++++++++++++++++-----
src/pages/user/scrimmages.tsx | 23 +++++++++++------------
2 files changed, 28 insertions(+), 17 deletions(-)
diff --git a/src/pages/api/user/match-request.ts b/src/pages/api/user/match-request.ts
index 505904f..375218a 100644
--- a/src/pages/api/user/match-request.ts
+++ b/src/pages/api/user/match-request.ts
@@ -10,16 +10,27 @@ export default async function handler(
const { player, opp, map } = req.body;
- if (!player || !opp || !map) {
+ if (!player || !opp) {
return res
.status(400)
.send({ message: 'Error creating match request', error: 'No player' });
}
- const matchRequestData = {
- players: [{ username: player }, { username: opp }],
- mapId: map,
- };
+
+ let matchRequestData = {};
+
+ if(map) {
+ matchRequestData = {
+ players: [{ username: player }, { username: opp }],
+ map: map,
+ shuffler: 'random',
+ }
+ } else {
+ matchRequestData = {
+ players: [{ username: player }, { username: opp }],
+ shuffler: 'random',
+ }
+ }
try {
const response = await axios.post(
@@ -34,6 +45,7 @@ export default async function handler(
return res.status(200).send({ message: 'Success', data: response.data });
} catch (err) {
+ console.log(err);
return res
.status(500)
.send({
diff --git a/src/pages/user/scrimmages.tsx b/src/pages/user/scrimmages.tsx
index f0d7b9d..994a73c 100644
--- a/src/pages/user/scrimmages.tsx
+++ b/src/pages/user/scrimmages.tsx
@@ -109,7 +109,7 @@ const TeamInfo: React.FC<{
oppTeam: Team;
playerTeam: string;
disabledScrimmageRequests: boolean;
- map: string;
+ map: string | null;
}> = ({ oppTeam, playerTeam, disabledScrimmageRequests, map }) => {
const requestMatch = async () => {
if (disabledScrimmageRequests) {
@@ -145,7 +145,7 @@ const TeamInfo: React.FC<{
- Map: {map} {/* Replace "map" with the actual property in your oppTeam object */}
+ Map: {map ? map : "Random"} {/* Replace "map" with the actual property in your oppTeam object */}
Opponent: {oppTeam.name}
@@ -286,7 +286,7 @@ const Scrimmages: NextPage = ({
/>
- {CurrentTeamSearch && CurrentMapSearch && (
+ {CurrentTeamSearch && (
{
}));
}
- let maps: string[] = [];
- const maps_req_url = 'http://' + process.env.MATCHMAKING_SERVER_IP + "/maps/list?pool=unranked"
-
- await axios.get(maps_req_url)
- .then(response => {
- maps = response.data.pools[0].mapIds;
- }).catch(error => {
- toast.error('Error fetching maps, Cannot run scrimmages:', error.message);
- });
+ let maps : string[] = [];
+
+ await axios.get(`${process.env.MATCHMAKING_SERVER_IP}/maps/list?pool=unranked`)
+ .then((response : AxiosResponse) => {
+ if(response.status === 200)
+ maps = response.data.pools[0].mapIds;
+ }
+ );
return {
props: {