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