only matchmake when a new player enters the queue
This commit is contained in:
parent
deb6d24282
commit
a4227c9728
@ -3,7 +3,6 @@ package main
|
|||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
|
||||||
|
|
||||||
"git.saintnet.tech/stryan/snengame/internal/coordinator"
|
"git.saintnet.tech/stryan/snengame/internal/coordinator"
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
@ -56,7 +55,6 @@ func serveWs(c *coordinator.Coordinator, w http.ResponseWriter, r *http.Request)
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
if resp.Result == coordinator.SessionRespLeft {
|
if resp.Result == coordinator.SessionRespLeft {
|
||||||
time.Sleep(1 * time.Second) //give clients a second to respond
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,8 +25,6 @@ func MatchMaker(c *Coordinator) {
|
|||||||
MMR: 0,
|
MMR: 0,
|
||||||
QueueTime: time.Now()}] = true
|
QueueTime: time.Now()}] = true
|
||||||
log.Printf("Player %v has queued", p)
|
log.Printf("Player %v has queued", p)
|
||||||
default:
|
|
||||||
//no new players, let's try to matchmake
|
|
||||||
if len(c.PlayerPool) < 2 {
|
if len(c.PlayerPool) < 2 {
|
||||||
continue
|
continue
|
||||||
} else {
|
} else {
|
||||||
@ -58,8 +56,10 @@ func MatchMaker(c *Coordinator) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func QueueCleaner(c *Coordinator) {
|
func QueueCleaner(c *Coordinator) {
|
||||||
|
ticker := time.NewTicker(5 * time.Minute)
|
||||||
for {
|
for {
|
||||||
time.Sleep(5 * time.Minute)
|
select {
|
||||||
|
case <-ticker.C:
|
||||||
for v, _ := range c.PlayerPool {
|
for v, _ := range c.PlayerPool {
|
||||||
if time.Now().After(v.QueueTime.Add(time.Minute * 5)) {
|
if time.Now().After(v.QueueTime.Add(time.Minute * 5)) {
|
||||||
log.Printf("Removing player %v from pool", v.Id)
|
log.Printf("Removing player %v from pool", v.Id)
|
||||||
@ -68,10 +68,13 @@ func QueueCleaner(c *Coordinator) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func MatchCleaner(c *Coordinator) {
|
func MatchCleaner(c *Coordinator) {
|
||||||
|
ticker := time.NewTicker(10 * time.Second)
|
||||||
for {
|
for {
|
||||||
time.Sleep(10 * time.Second)
|
select {
|
||||||
|
case <-ticker.C:
|
||||||
c.MatchLock.Lock()
|
c.MatchLock.Lock()
|
||||||
for _, v := range c.Matches {
|
for _, v := range c.Matches {
|
||||||
if v.Game == nil && v.Active {
|
if v.Game == nil && v.Active {
|
||||||
@ -87,9 +90,11 @@ func MatchCleaner(c *Coordinator) {
|
|||||||
v.Watcher <- true
|
v.Watcher <- true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
c.MatchLock.Unlock()
|
c.MatchLock.Unlock()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func MatchWatcher(m *Session) {
|
func MatchWatcher(m *Session) {
|
||||||
ticker := time.NewTicker(1 * time.Second)
|
ticker := time.NewTicker(1 * time.Second)
|
||||||
|
Loading…
Reference in New Issue
Block a user