-
Notifications
You must be signed in to change notification settings - Fork 1
Kc 133 create ranked mode queuing system #82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tuc56407
wants to merge
6
commits into
develop
Choose a base branch
from
KC-133-Create-ranked-mode-queuing-system
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0113931
KC-133 Rename index to server, create matchmaker, create ranked queue…
tuc56407 aacb11e
KC-133 Get ranked game to start with multi-server communication
tuc56407 1e38c77
KC-133 Finished ranked communications, requeue and leave options
tuc56407 b63a779
Merge branch 'develop' into KC-133-Create-ranked-mode-queuing-system
tuc56407 0cbcde1
Update menu button command overwritten by merge
tuc56407 723e4f2
Fix logging
tuc56407 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,7 +48,8 @@ const MultiplayerGame = (props) => { | |
| useEffect( | ||
| () => { | ||
|
|
||
| socketRef.current = io.connect("https://generated-respected-python.glitch.me") //LOCALHOST for local testing | ||
| //socketRef.current = io.connect("https://generated-respected-python.glitch.me") | ||
| socketRef.current = io.connect("http://localhost:4000") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This as well |
||
|
|
||
| console.log(lobbyID, username) | ||
| socketRef.current.emit('switchLobby', { lobbyID }, username) | ||
|
|
@@ -69,6 +70,15 @@ const MultiplayerGame = (props) => { | |
| props.setJoinLobby(true) | ||
| }) | ||
|
|
||
| socketRef.current.on('findRankedMatchSuccess', (rankedLobby) => { | ||
| console.log(socketRef.current.id + " found a ranked match") | ||
| socketRef.current.disconnect() | ||
| props.setLobbyID(rankedLobby) | ||
| props.setShowModal(false) | ||
| props.setJoinLobby(false) | ||
| props.setJoinLobby(true) | ||
| }) | ||
|
|
||
| socketRef.current.on("gameStart", () => { | ||
| console.log("Game Start") | ||
| setInCountdown(true) | ||
|
|
@@ -280,7 +290,11 @@ const MultiplayerGame = (props) => { | |
| // --------------------------------------------------- | ||
|
|
||
| function readyUp() { | ||
| if(props.isFindMatch) { | ||
| if(props.isRanked) { | ||
| console.log("Requeue for Ranked") | ||
| props.setShowModal(true) | ||
| socketRef.current.emit('findRanked', {username, mmr: 5}) | ||
| } else if(props.isFindMatch) { | ||
| //get back in Find Match queue | ||
| props.setShowModal(true) | ||
| socketRef.current.emit('findMatch') | ||
|
|
@@ -293,11 +307,17 @@ const MultiplayerGame = (props) => { | |
|
|
||
| function leaveRoom() { | ||
| //back to mp menu | ||
| props.setRanked(false) | ||
| props.setJoinLobby(false) | ||
| props.setFindMatch(false) | ||
| } | ||
|
|
||
|
|
||
| var readyRequeueBtn | ||
| if(props.isRanked || props.isFindMatch) { | ||
| readyRequeueBtn = <button onClick={readyUp}>Requeue</button> | ||
| } else { | ||
| readyRequeueBtn = <button onClick={readyUp}>Ready Up</button> | ||
| } | ||
|
|
||
| return ( | ||
| <div className="container"> | ||
|
|
@@ -349,7 +369,7 @@ const MultiplayerGame = (props) => { | |
| </Leaderboard> | ||
| <PostMatchOptions> | ||
| <div style={{ color: 'var(--selection-color)', fontWeight: 'bold' }}> | ||
| <button onClick={readyUp}>Ready Up</button> | ||
| {readyRequeueBtn} | ||
| <button onClick={leaveRoom}>Leave</button> | ||
| </div> | ||
| </PostMatchOptions> | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| const app = require('express')() | ||
| const http = require('http').createServer(app) | ||
| const io = require('socket.io')(http, { | ||
| cors: { | ||
| origin: ["http://localhost:3000", "https://generated-respected-python.glitch.me", "https://keyctrl.net"], //CHANGE TO HOST URL | ||
| methods: ["GET", "POST"], | ||
| credentials: true, | ||
| transports: ['websocket', 'polling'] | ||
| }, | ||
| allowEIO3: true | ||
| }); | ||
|
|
||
| //Initialize Ranked Queue with MMR buckets | ||
| var rankedQueue = [] | ||
| rankedQueue[0] = new Array() //0-299 | ||
| rankedQueue[1] = new Array() //300-599 | ||
| rankedQueue[2] = new Array() //600-899 | ||
| rankedQueue[3] = new Array() //900+ | ||
|
|
||
| var bucketBracketOne = 300 | ||
| var bucketBracketTwo = 600 | ||
| var bucketBracketThree = 900 | ||
|
|
||
| var foundPlayers = [] //WARNING: CURRENTLY ALL LOGIC INVOLVING FOUNDPLAYERS WILL FAIL | ||
| //AS IT WILL OVERLAP WITH OTHER GAMES. NEEDS TO BE MADE GAME SPECIFIC SOMEHOW | ||
|
|
||
| io.on('connection', (socket) => { | ||
| console.log(socket.id + " connected") | ||
| socket.on('addToRankedQueue', function({socketID, username, mmr}) { | ||
| console.log("ADDED TO QUEUE - socket: " + socketID + " user: " + username + " mmr: " + mmr) | ||
| var queuingPlayer = {socketID, username, mmr} | ||
| //Place user in their bucket | ||
| if(queuingPlayer.mmr < bucketBracketOne) { | ||
| console.log("Player dropped in bucket one") | ||
| rankedQueue[0].push(queuingPlayer) | ||
| } else if(queuingPlayer.mmr < bucketBracketTwo) { | ||
| console.log("Player dropped in bucket two") | ||
| rankedQueue[1].push(queuingPlayer) | ||
| } else if(queuingPlayer.mmr < bucketBracketThree) { | ||
| console.log("Player dropped in bucket three") | ||
| rankedQueue[2].push(queuingPlayer) | ||
| } else { | ||
| console.log("Player dropped in bucket four") | ||
| rankedQueue[3].push(queuingPlayer) | ||
| } | ||
|
|
||
| if(rankedQueue[0].length >= 4) { | ||
| console.log("Match Found") | ||
| for(var i=0; i<4; i++) { | ||
| foundPlayers.push(rankedQueue[0].shift()) | ||
| } | ||
| socket.emit('rankedGameMatched', (foundPlayers)) | ||
| foundPlayers = [] | ||
| } | ||
| }) | ||
| socket.on('cancelFindRanked', function(socketID) { | ||
| rankedQueue.forEach(list => { | ||
| list.splice(list.indexOf(socketID), 1) | ||
| console.log(socketID + " left the queue") | ||
| }) | ||
| }) | ||
| }) | ||
|
|
||
| // if(rankedQueue[3].length >= 4) { | ||
| // for(var i=0; i<3; i++) { | ||
| // foundPlayers.push(rankedQueue[3].shift()) | ||
| // } | ||
| // } | ||
|
|
||
|
|
||
| http.listen(4001, () => { | ||
| console.log('listening on *:4001'); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to push this to develop?