Skip to content

Commit

Permalink
allow matches even if random map
Browse files Browse the repository at this point in the history
  • Loading branch information
aaravbajaj012 committed Jan 27, 2024
1 parent 088dfae commit 72f88cb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
22 changes: 17 additions & 5 deletions src/pages/api/user/match-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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({
Expand Down
23 changes: 11 additions & 12 deletions src/pages/user/scrimmages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -145,7 +145,7 @@ const TeamInfo: React.FC<{
<Card className='mb-3'>
<Card.Body>
<Card.Title>
<small>Map: {map}</small> {/* Replace "map" with the actual property in your oppTeam object */}
<small>Map: {map ? map : "Random"}</small> {/* Replace "map" with the actual property in your oppTeam object */}
<br/>
<small>Opponent: {oppTeam.name}</small>
</Card.Title>
Expand Down Expand Up @@ -286,7 +286,7 @@ const Scrimmages: NextPage = ({
/>
</Card.Body>
</Card>
{CurrentTeamSearch && CurrentMapSearch && (
{CurrentTeamSearch && (
<TeamInfo
oppTeam={CurrentTeamSearch}
playerTeam={userTeam}
Expand Down Expand Up @@ -411,15 +411,14 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
}));
}

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: {
Expand Down

0 comments on commit 72f88cb

Please sign in to comment.