From 72adda7fbb1d9257da7a02dd5e3b37c9df4cc227 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Tue, 19 Mar 2024 11:57:25 +0800 Subject: [PATCH] 1 --- server/matchserver/common/types.go | 2 ++ server/matchserver/player/player.go | 24 +++++++++---------- server/matchserver/team/team.go | 37 +++++++++++++++++++---------- 3 files changed, 39 insertions(+), 24 deletions(-) diff --git a/server/matchserver/common/types.go b/server/matchserver/common/types.go index fffb9550..1722a559 100644 --- a/server/matchserver/common/types.go +++ b/server/matchserver/common/types.go @@ -74,9 +74,11 @@ type Team interface { SendStateNotify() IsLeader(Player) bool Started() bool + Matching() bool CanStartGame(Player) bool StartGame() GetMemberNum() int32 + IsLock() bool Leave(Player) Disband() diff --git a/server/matchserver/player/player.go b/server/matchserver/player/player.go index 887184ba..54cca11a 100644 --- a/server/matchserver/player/player.go +++ b/server/matchserver/player/player.go @@ -189,7 +189,7 @@ func (this *player) FillMFTeamMember(member_pb *cs.MFTeamMember) { func (this *player) CMLeaveTeam(hdr *f5.MsgHdr, msg *cs.CMLeaveTeam) { rspMsg := &cs.SMLeaveTeam{} team := this.GetTeam() - if this.GetTeam().Started() { + if this.GetTeam().IsLock() { rspMsg.Errcode = proto.Int32(1) rspMsg.Errmsg = proto.String("team already started") this.SendMsg(rspMsg) @@ -206,7 +206,7 @@ func (this *player) CMLeaveTeam(hdr *f5.MsgHdr, msg *cs.CMLeaveTeam) { func (this *player) CMDisbandTeam(hdr *f5.MsgHdr, msg *cs.CMDisbandTeam) { rspMsg := &cs.SMDisbandTeam{} team := this.GetTeam() - if this.GetTeam().Started() { + if this.GetTeam().IsLock() { rspMsg.Errcode = proto.Int32(1) rspMsg.Errmsg = proto.String("team already started") } else { @@ -219,7 +219,7 @@ func (this *player) CMDisbandTeam(hdr *f5.MsgHdr, msg *cs.CMDisbandTeam) { func (this *player) CMKickOut(hdr *f5.MsgHdr, msg *cs.CMKickOut) { rspMsg := &cs.SMKickOut{} team := this.GetTeam() - if this.GetTeam().Started() { + if this.GetTeam().IsLock() { rspMsg.Errcode = proto.Int32(1) rspMsg.Errmsg = proto.String("team already started") } else { @@ -232,7 +232,7 @@ func (this *player) CMKickOut(hdr *f5.MsgHdr, msg *cs.CMKickOut) { func (this *player) CMHandoverLeader(hdr *f5.MsgHdr, msg *cs.CMHandoverLeader) { rspMsg := &cs.SMHandoverLeader{} team := this.GetTeam() - if this.GetTeam().Started() { + if this.GetTeam().IsLock() { rspMsg.Errcode = proto.Int32(1) rspMsg.Errmsg = proto.String("team already started") } else { @@ -244,7 +244,7 @@ func (this *player) CMHandoverLeader(hdr *f5.MsgHdr, msg *cs.CMHandoverLeader) { func (this *player) CMStartGame(hdr *f5.MsgHdr, msg *cs.CMStartGame) { rspMsg := &cs.SMStartGame{} - if !this.GetTeam().Started() { + if !this.GetTeam().IsLock() { if this.GetTeam().CanStartGame(this) { this.GetTeam().StartGame() } @@ -267,7 +267,7 @@ func (this *player) CMCancel(hdr *f5.MsgHdr, msg *cs.CMCancel) { func (this *player) CMSetReady(hdr *f5.MsgHdr, msg *cs.CMSetReady) { rspMsg := &cs.SMSetReady{} - if this.GetTeam().Started() { + if this.GetTeam().IsLock() { rspMsg.Errcode = proto.Int32(1) rspMsg.Errmsg = proto.String("team already started") } else { @@ -283,7 +283,7 @@ func (this *player) CMSetReady(hdr *f5.MsgHdr, msg *cs.CMSetReady) { func (this *player) CMSetSpecSkill(hdr *f5.MsgHdr, msg *cs.CMSetSpecSkill) { rspMsg := &cs.SMSetSpecSkill{} - if this.GetTeam().Started() { + if this.GetTeam().IsLock() { rspMsg.Errcode = proto.Int32(1) rspMsg.Errmsg = proto.String("team already started") return @@ -308,7 +308,7 @@ func (this *player) CMSetSpecSkill(hdr *f5.MsgHdr, msg *cs.CMSetSpecSkill) { func (this *player) CMChooseHero(hdr *f5.MsgHdr, msg *cs.CMChooseHero) { rspMsg := &cs.SMChooseHero{} - if this.GetTeam().Started() { + if this.GetTeam().IsLock() { rspMsg.Errcode = proto.Int32(1) rspMsg.Errmsg = proto.String("team already started") this.SendMsg(rspMsg) @@ -334,7 +334,7 @@ func (this *player) CMChooseHero(hdr *f5.MsgHdr, msg *cs.CMChooseHero) { func (this *player) CMChooseMap(hdr *f5.MsgHdr, msg *cs.CMChooseMap) { rspMsg := &cs.SMChooseMap{} - if this.GetTeam().Started() { + if this.GetTeam().IsLock() { rspMsg.Errcode = proto.Int32(1) rspMsg.Errmsg = proto.String("team already started") this.SendMsg(rspMsg) @@ -371,7 +371,7 @@ func (this *player) updateChoose(skillId int32, heroUniId string, url, params, func(rsp f5.HttpCliResponse) { - if this.GetTeam() != nil && !this.GetTeam().Started() { + if this.GetTeam() != nil && !this.GetTeam().IsLock() { if rsp.GetErr() != nil { cb(500, "server internal error") return @@ -416,7 +416,7 @@ func (this *player) updateMap(mapId int32, url, params, func(rsp f5.HttpCliResponse) { - if this.GetTeam() != nil && !this.GetTeam().Started() { + if this.GetTeam() != nil && !this.GetTeam().IsLock() { if rsp.GetErr() != nil { cb(500, "server internal error") return @@ -448,7 +448,7 @@ func (this *player) updateMap(mapId int32, func (this *player) CMGrantInvitePermission(hdr *f5.MsgHdr, msg *cs.CMGrantInvitePermission) { rspMsg := &cs.SMGrantInvitePermission{} - if this.GetTeam().Started() { + if this.GetTeam().IsLock() { rspMsg.Errcode = proto.Int32(1) rspMsg.Errmsg = proto.String("team already started") } else { diff --git a/server/matchserver/team/team.go b/server/matchserver/team/team.go index 87a3f239..1764633f 100644 --- a/server/matchserver/team/team.go +++ b/server/matchserver/team/team.go @@ -107,8 +107,16 @@ func (this *team) Started() bool { return this.state == constant.TEAM_STATE_STARTED } +func (this *team) Matching() bool { + return this.state == constant.TEAM_STATE_MATCHING +} + +func (this *team) IsLock() bool { + return this.Started() || this.Matching() +} + func (this *team) CanStartGame(hum common.Player) bool { - if !this.Started() { + if !this.IsLock() { if this.GetMemberNum() > 0 { allReady := true for _, m := range this.accountIdHash { @@ -124,17 +132,22 @@ func (this *team) CanStartGame(hum common.Player) bool { } func (this *team) StartGame() { - if !this.Started() && this.CanStartGame(this.owner) { - this.state = constant.TEAM_STATE_STARTED - this.startTime = f5.GetApp().GetNowSeconds() - this.stateNotifyMsg.State = proto.Int32(this.state) - this.genStartGameInfo() - this.SendStateNotify() - f5.GetTimer().SetInterval(1000, func(e int32, args *q5.Args) { - if e == q5.TIMER_EXEC_EVENT { - this.SendStateNotify() - } - }) + if !this.IsLock() && this.CanStartGame(this.owner) { + if this.IsMobaMode() { + this.state = constant.TEAM_STATE_MATCHING + this.SendStateNotify() + } else { + this.state = constant.TEAM_STATE_STARTED + this.startTime = f5.GetApp().GetNowSeconds() + this.stateNotifyMsg.State = proto.Int32(this.state) + this.genStartGameInfo() + this.SendStateNotify() + f5.GetTimer().SetInterval(1000, func(e int32, args *q5.Args) { + if e == q5.TIMER_EXEC_EVENT { + this.SendStateNotify() + } + }) + } } }