This commit is contained in:
aozhiwei 2023-09-14 15:49:41 +08:00
parent 0232a31f81
commit da1e56e5d8
3 changed files with 29 additions and 14 deletions

View File

@ -9,22 +9,26 @@ import (
)
type member struct {
room *room
joinTime int64
state int32
closeGameStartNotify bool
entry q5.ListHead
teamEntry q5.ListHead
team *team
hum common.Player
}
func (this *member) init(hum common.Player) {
this.entry.Init(this)
func (this *member) init(room *room, hum common.Player) {
this.room = room
this.teamEntry.Init(this)
this.hum = hum
this.joinTime = f5.GetApp().GetNowSeconds()
}
func (this *member) unInit() {
}
func (this *member) fillMFMember(pb *cs.MFMember) {
pb.AccountId = proto.String(this.hum.GetAccountId())
pb.Name = proto.String(this.hum.GetName())
@ -33,8 +37,8 @@ func (this *member) fillMFMember(pb *cs.MFMember) {
pb.Ping = proto.Int32(this.hum.GetPing())
}
func newMember(hum common.Player) *member {
func newMember(room *room, hum common.Player) *member {
m := new(member)
m.init(hum)
m.init(room, hum)
return m
}

View File

@ -45,11 +45,11 @@ func (this *room) init(roomId string, roomIdx int64, mapId int32, owner common.P
this.config.nodeId = owner.GetNodeId()
this.config.passwd = passwd
this.config.maxTeamNum = constant.ROOM_MAX_TEAM_NUM
this.owner = newMember(owner)
this.owner = newMember(this, owner)
this.members = map[string]*member{
owner.GetAccountId(): this.owner,
}
t := newTeam(this.genTeamId(), this.owner)
t := newTeam(this, this.genTeamId(), this.owner)
this.teamUuidHash = map[string]*team {
owner.GetTeamUuid(): t,
}
@ -115,11 +115,11 @@ func (this *room) join(hum common.Player, passwd string) bool {
if !this.canJoin(hum, passwd) {
return false
}
m := newMember(hum)
m := newMember(this, hum)
this.members[hum.GetAccountId()] = m
t := this.getTeam(hum.GetTeamUuid())
if t == nil {
t = newTeam(this.genTeamId(), m)
t = newTeam(this, this.genTeamId(), m)
this.teamUuidHash[hum.GetTeamUuid()] = t
this.teamIdHash[t.teamId] = t
} else {
@ -175,7 +175,7 @@ func (this *room) CMLeaveRoom(hdr *f5.MsgHdr, msg *cs.CMLeaveRoom) {
this.owner = nextOwner
}
} else {
this.removeMember(this.owner.hum.GetAccountId())
this.removeMember(hum.GetAccountId())
}
notifyMsg := &cs.SMRoomLeaveNotify{}
this.broadcastMsg(notifyMsg)
@ -392,6 +392,7 @@ func (this *room) genTeamId() int32 {
func (this *room) removeMember(accountId string) {
m := this.getMember(accountId)
if m != nil {
m.unInit()
delete(this.members, accountId)
}
}

View File

@ -5,11 +5,23 @@ import (
)
type team struct {
room *room
teamId int32
teamUuid string
members q5.ListHead
}
func (this *team) init(room *room, teamId int32, teamUuid string) {
this.room = room
this.teamId = teamId
this.members.Init(nil)
this.teamUuid = teamUuid
}
func (this *team) unInit() {
}
func (this *team) addMember(m *member) {
if this.teamUuid != m.hum.GetTeamUuid() {
panic("team.addMember team_uuid error")
@ -50,11 +62,9 @@ func (this *team) getOwnerCandidate() *member {
return ownerCandidate
}
func newTeam(teamId int32, leader *member) *team {
func newTeam(room *room, teamId int32, leader *member) *team {
t := new(team)
t.teamId = teamId
t.members.Init(nil)
t.teamUuid = leader.hum.GetTeamUuid()
t.init(room, teamId, leader.hum.GetTeamUuid())
t.addMember(leader)
return t
}