From 7f802a1e75916fa276e9e8d3a2b78684bf000df7 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 1 Feb 2024 16:42:08 +0800 Subject: [PATCH] 1 --- server/hallserver/room/room.go | 57 +++++++++++++++++++++++++++------- server/hallserver/room/team.go | 5 +++ 2 files changed, 51 insertions(+), 11 deletions(-) diff --git a/server/hallserver/room/room.go b/server/hallserver/room/room.go index b8ac6a9e..676a6024 100644 --- a/server/hallserver/room/room.go +++ b/server/hallserver/room/room.go @@ -142,6 +142,10 @@ func (this *room) getTeamNum() int32 { return int32(len(this.teamUuidHash)) } +func (this *room) getObTeamNum() int32 { + return int32(len(this.obTeamUuidHash)) +} + func (this *room) canJoin(member common.Player, msg *cs.CMJoinRoom) bool { if this.started() { return false @@ -149,9 +153,6 @@ func (this *room) canJoin(member common.Player, msg *cs.CMJoinRoom) bool { if member.GetRoom() != nil { return false } - if this.getTeamNum() >= this.config.maxTeamNum { - return false - } if this.getMember(member.GetAccountId()) != nil { return false } @@ -159,8 +160,24 @@ func (this *room) canJoin(member common.Player, msg *cs.CMJoinRoom) bool { return false } t := this.getTeamByUuid(msg.GetTeamUuid()) - if t != nil && t.getMemberNum() >= constant.ROOM_MAX_TEAM_MEMBER_NUM { - return false + if t == nil { + t = this.getObTeamByUuid(msg.GetTeamUuid()) + } + if t != nil { + if t.isFull() { + return false + } else { + return true + } + } + if msg.GetIsObserver() != 0 { + if this.isObTeamFull() { + return false + } + } else { + if this.isTeamFull() { + return false + } } return true } @@ -169,19 +186,37 @@ func (this *room) isTeamFull() bool { return this.getTeamNum() >= this.config.maxTeamNum } +func (this *room) isObTeamFull() bool { + return this.getObTeamNum() >= this.config.maxTeamNum +} + func (this *room) join(hum common.Player, msg *cs.CMJoinRoom) bool { if !this.canJoin(hum, msg) { return false } - m := newMember(this, hum) - this.addMember(m) t := this.getTeamByUuid(msg.GetTeamUuid()) if t == nil { - this.addTeam(newTeam(this, this.genTeamId(), msg.GetTeamUuid(), m)) - } else { - t.addMember(m) + t = this.getObTeamByUuid(msg.GetTeamUuid()) + } + if t != nil { + if t.isFull() { + return false + } + m := newMember(this, hum) + this.addMember(m) + this.autoStartCountdown() + return true + } + m := newMember(this, hum) + this.addMember(m) + t = newTeam(this, this.genTeamId(), msg.GetTeamUuid(), m) + t.addMember(m) + if msg.GetIsObserver() != 0 { + this.addObTeam(t) + } else { + this.addTeam(t) + this.autoStartCountdown() } - this.autoStartCountdown() return true } diff --git a/server/hallserver/room/team.go b/server/hallserver/room/team.go index ba907e4c..8ce2557d 100644 --- a/server/hallserver/room/team.go +++ b/server/hallserver/room/team.go @@ -4,6 +4,7 @@ import ( "cs" "github.com/golang/protobuf/proto" "q5" + "main/constant" ) // TeamInfo from client data @@ -163,6 +164,10 @@ func (this *team) isObserver() bool { return this.room.getObTeamById(this.teamId) != nil } +func (this *team) isFull() bool { + return this.getMemberNum() >= constant.ROOM_MAX_TEAM_MEMBER_NUM +} + func newTeam(room *room, teamId int32, teamUuid string, leader *member) *team { t := new(team) t.init(room, teamId, teamUuid)