Skip to content

Commit

Permalink
fix find mcs
Browse files Browse the repository at this point in the history
  • Loading branch information
inada-s committed Apr 19, 2020
1 parent 9c343d6 commit 9fbd326
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
12 changes: 12 additions & 0 deletions gdxsv/lbs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"net"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -114,6 +115,17 @@ func (lbs *Lbs) NewPeer(conn *net.TCPConn) *LbsPeer {
}
}

func (lbs *Lbs) FindMcs(region string) *McsStatus {
for _, mcs := range lbs.mcs {
if strings.HasPrefix(mcs.Region, region) &&
mcs.PublicAddr != "" &&
time.Since(mcs.Updated).Seconds() <= 10 {
return mcs
}
}
return nil
}

func (lbs *Lbs) FindPeer(userID string) *LbsPeer {
p, ok := lbs.users[userID]
if !ok {
Expand Down
24 changes: 4 additions & 20 deletions gdxsv/lbs_lobby.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ package main

import (
"fmt"
"time"

"github.com/golang/glog"
)

type LbsLobby struct {
Expand Down Expand Up @@ -220,16 +217,12 @@ func (l *LbsLobby) CheckLobbyBattleStart() {
}

mcsAddr := conf.BattlePublicAddr

if McsFuncEnabled() && l.McsRegion != "" {
stat, ok := l.app.mcs[l.McsRegion]
if !ok {
stat := l.app.FindMcs(l.McsRegion)
if stat == nil {
GoMcsFuncAlloc(l.McsRegion)
return
}
if stat.PublicAddr != "" && 10 <= time.Since(stat.Updated).Seconds() {
return
}
mcsAddr = stat.PublicAddr
}

Expand Down Expand Up @@ -306,20 +299,11 @@ func (l *LbsLobby) CheckRoomBattleStart() {

mcsAddr := conf.BattlePublicAddr
if McsFuncEnabled() && l.McsRegion != "" {
stat, ok := l.app.mcs[l.McsRegion]
if !ok {
glog.Info("mcs not found. request alloc", l.McsRegion)
stat := l.app.FindMcs(l.McsRegion)
if stat == nil {
GoMcsFuncAlloc(l.McsRegion)
return
}
if 10 <= time.Since(stat.Updated).Seconds() {
glog.Info("the mcs is too old.", stat)
return
}
if stat.PublicAddr == "" {
glog.Info("the mcs does not have public addr.", stat)
return
}
mcsAddr = stat.PublicAddr
}

Expand Down

0 comments on commit 9fbd326

Please sign in to comment.