diff --git a/gdxsv/lbs.go b/gdxsv/lbs.go index 52285be..ce0c85f 100644 --- a/gdxsv/lbs.go +++ b/gdxsv/lbs.go @@ -5,6 +5,7 @@ import ( "encoding/json" "fmt" "net" + "strings" "sync" "time" @@ -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 { diff --git a/gdxsv/lbs_lobby.go b/gdxsv/lbs_lobby.go index 0781d5f..2eb6330 100644 --- a/gdxsv/lbs_lobby.go +++ b/gdxsv/lbs_lobby.go @@ -2,9 +2,6 @@ package main import ( "fmt" - "time" - - "github.com/golang/glog" ) type LbsLobby struct { @@ -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 } @@ -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 }