From 6079f8bd6f8ed79f7ce6f5b20cbabda3c592b962 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 11 Mar 2024 21:27:12 +0800 Subject: [PATCH] 1 --- server/matchserver/common/types.go | 3 +++ server/matchserver/team/team.go | 32 +++++++++++++++++++++++++++++- server/matchserver/team/teammgr.go | 16 ++++++++++++++- 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/server/matchserver/common/types.go b/server/matchserver/common/types.go index 9c3606ea..f1c05510 100644 --- a/server/matchserver/common/types.go +++ b/server/matchserver/common/types.go @@ -17,6 +17,7 @@ type Team interface { GetMemberByAccountId(string) Player OnPlayerOffline(Player) OnPlayerOnline(Player) + IsCopy() bool } type TeamMgr interface { @@ -29,6 +30,8 @@ type Player interface { GetSocket() f5.WspCliConn GetAccountId() string GetSessionId() string + GetZoneId() int32 + GetNodeId() int32 GetName() string GetAvatarUrl() string GetHeroId() string diff --git a/server/matchserver/team/team.go b/server/matchserver/team/team.go index 1569fe5d..e0da1a45 100644 --- a/server/matchserver/team/team.go +++ b/server/matchserver/team/team.go @@ -8,8 +8,19 @@ import ( type team struct { cs.MsgHandlerImpl teamUuid string + isCopy bool zoneId int32 nodeId int32 + owner common.Player + accountIdHash map[string]common.Player +} + +func (this *team) init(teamUuid string, owner common.Player) { + this.teamUuid = teamUuid + this.zoneId = owner.GetZoneId() + this.nodeId = owner.GetNodeId() + this.owner = owner + this.accountIdHash[owner.GetAccountId()] = owner } func (this *team) GetZoneId() int32 { @@ -29,6 +40,10 @@ func (this *team) CanJoin(accountId string) bool { } func (this *team) GetMemberByAccountId(accountId string) common.Player { + hum, ok := this.accountIdHash[accountId] + if ok { + return hum + } return nil } @@ -41,5 +56,20 @@ func (this *team) OnPlayerOnline(hum common.Player) { } func (this *team) Join(hum common.Player) bool { - return false + this.accountIdHash[hum.GetAccountId()] = hum + return true +} + +func (this *team) isFull() bool { + return len(this.accountIdHash) >= 4 +} + +func (this *team) IsCopy() bool { + return this.isCopy +} + +func newTeam() *team { + t := new(team) + t.accountIdHash = map[string]common.Player{} + return t } diff --git a/server/matchserver/team/teammgr.go b/server/matchserver/team/teammgr.go index 6b911adb..6988ec49 100644 --- a/server/matchserver/team/teammgr.go +++ b/server/matchserver/team/teammgr.go @@ -23,10 +23,24 @@ func (this *teamMgr) UnInit() { } func (this *teamMgr) CreateTeam(hum common.Player, msg *cs.CMLogin) { - + teamUuid := this.genTeamUuid(hum.GetZoneId(), hum.GetNodeId()) + team := newTeam() + team.init(teamUuid, hum) + this.teamUuidHash[team.teamUuid] = team } func (this *teamMgr) genTeamUuid(zoneId int32, nodeId int32) string { + teamUuid := "" + for true { + teamUuid = this.internalGenTeamUuid(zoneId, nodeId) + if this.GetTeamByUuid(teamUuid) == nil { + return teamUuid + } + } + panic("genTeamUuid error") +} + +func (this *teamMgr) internalGenTeamUuid(zoneId int32, nodeId int32) string { this.curIdx++ teamUuid := q5.ToString(zoneId) + "_" + q5.ToString(nodeId) + "_" + q5.Md5Str(q5.ToString(f5.GetApp().NewUuid()) + q5.ToString(f5.GetApp().GetPid()) +