Skip to content

Commit

Permalink
Fix battle user count updates
Browse files Browse the repository at this point in the history
  • Loading branch information
inada-s committed Jul 14, 2023
1 parent 18c2b7d commit 6b840c2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
21 changes: 11 additions & 10 deletions gdxsv/lbs.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@ func (lbs *Lbs) cleanPeer(p *LbsPeer) {
}
}
if p.Battle != nil {
lbs.BroadcastBattleUserCount()
p.Battle = nil
}
delete(lbs.userPeers, p.UserID)
Expand All @@ -309,6 +308,7 @@ func (lbs *Lbs) cleanPeer(p *LbsPeer) {
func (lbs *Lbs) eventLoop() {
tick := time.Tick(1 * time.Second)
peers := map[string]*LbsPeer{}
battleUserCount := 0

for {
select {
Expand Down Expand Up @@ -383,6 +383,16 @@ func (lbs *Lbs) eventLoop() {
lobby.Update()
}
}

cnt := sharedData.GetMcsUserCount()
if cnt != battleUserCount {
battleUserCount = cnt
for userID := range lbs.userPeers {
if p := lbs.FindPeer(userID); p != nil {
p.SendMessage(NewServerNotice(lbsBattleUserCount).Writer().Write32(uint32(cnt)).Msg())
}
}
}
}
}
}
Expand Down Expand Up @@ -516,15 +526,6 @@ func (lbs *Lbs) BroadcastRoomState(room *LbsRoom) {
}
}

func (lbs *Lbs) BroadcastBattleUserCount() {
cnt := sharedData.GetMcsUserCount()
for userID := range lbs.userPeers {
if p := lbs.FindPeer(userID); p != nil {
p.SendMessage(NewServerNotice(lbsBattleUserCount).Writer().Write32(uint32(cnt)).Msg())
}
}
}

func (lbs *Lbs) RegisterBattleResult(p *LbsPeer, result *BattleResult) {
record, err := getDB().GetBattleRecordUser(result.BattleCode, p.UserID)
if err != nil {
Expand Down
7 changes: 6 additions & 1 deletion gdxsv/lbs_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ func RequestLineCheck(p *LbsPeer) {
p.SendMessage(NewServerQuestion(lbsLineCheck))
}

func NotifyBattleUserCount(p *LbsPeer) {
cnt := sharedData.GetMcsUserCount()
p.SendMessage(NewServerNotice(lbsBattleUserCount).Writer().Write32(uint32(cnt)).Msg())
}

var _ = register(lbsLineCheck, func(p *LbsPeer, m *LbsMessage) {
// the client is alive
})
Expand Down Expand Up @@ -777,7 +782,7 @@ var _ = register(lbsDeviceData, func(p *LbsPeer, m *LbsMessage) {
var _ = register(lbsServerMoney, func(p *LbsPeer, m *LbsMessage) {
p.SendMessage(NewServerAnswer(m).Writer().
Write16(0).Write16(0).Write16(0).Write16(0).Msg())
p.SendMessage(NewServerNotice(lbsBattleUserCount).Writer().Write32(uint32(sharedData.GetMcsUserCount())).Msg())
NotifyBattleUserCount(p)
})

var _ = register(lbsStartLobby, func(p *LbsPeer, m *LbsMessage) {
Expand Down
3 changes: 0 additions & 3 deletions gdxsv/lbs_lobby.go
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,6 @@ func (l *LbsLobby) checkLobbyBattleStart(force bool) {

l.app.BroadcastLobbyUserCount(l)
l.app.BroadcastLobbyMatchEntryUserCount(l)
l.app.BroadcastBattleUserCount()
}

func (l *LbsLobby) checkRoomBattleStart() {
Expand Down Expand Up @@ -1042,8 +1041,6 @@ func (l *LbsLobby) checkRoomBattleStart() {
if mcsPeer != nil {
sharedData.NotifyLatestLbsStatus(mcsPeer)
}

l.app.BroadcastBattleUserCount()
}

func (l *LbsLobby) prepareMcs(mcsRegion string) (newMcsRegion string, mcsPeer *LbsPeer, mcsAddr string, canStart bool, alloc bool) {
Expand Down

0 comments on commit 6b840c2

Please sign in to comment.