1
This commit is contained in:
parent
0232a31f81
commit
da1e56e5d8
@ -9,22 +9,26 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type member struct {
|
type member struct {
|
||||||
|
room *room
|
||||||
joinTime int64
|
joinTime int64
|
||||||
state int32
|
state int32
|
||||||
closeGameStartNotify bool
|
closeGameStartNotify bool
|
||||||
entry q5.ListHead
|
|
||||||
teamEntry q5.ListHead
|
teamEntry q5.ListHead
|
||||||
team *team
|
team *team
|
||||||
hum common.Player
|
hum common.Player
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *member) init(hum common.Player) {
|
func (this *member) init(room *room, hum common.Player) {
|
||||||
this.entry.Init(this)
|
this.room = room
|
||||||
this.teamEntry.Init(this)
|
this.teamEntry.Init(this)
|
||||||
this.hum = hum
|
this.hum = hum
|
||||||
this.joinTime = f5.GetApp().GetNowSeconds()
|
this.joinTime = f5.GetApp().GetNowSeconds()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *member) unInit() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func (this *member) fillMFMember(pb *cs.MFMember) {
|
func (this *member) fillMFMember(pb *cs.MFMember) {
|
||||||
pb.AccountId = proto.String(this.hum.GetAccountId())
|
pb.AccountId = proto.String(this.hum.GetAccountId())
|
||||||
pb.Name = proto.String(this.hum.GetName())
|
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())
|
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 := new(member)
|
||||||
m.init(hum)
|
m.init(room, hum)
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
@ -45,11 +45,11 @@ func (this *room) init(roomId string, roomIdx int64, mapId int32, owner common.P
|
|||||||
this.config.nodeId = owner.GetNodeId()
|
this.config.nodeId = owner.GetNodeId()
|
||||||
this.config.passwd = passwd
|
this.config.passwd = passwd
|
||||||
this.config.maxTeamNum = constant.ROOM_MAX_TEAM_NUM
|
this.config.maxTeamNum = constant.ROOM_MAX_TEAM_NUM
|
||||||
this.owner = newMember(owner)
|
this.owner = newMember(this, owner)
|
||||||
this.members = map[string]*member{
|
this.members = map[string]*member{
|
||||||
owner.GetAccountId(): this.owner,
|
owner.GetAccountId(): this.owner,
|
||||||
}
|
}
|
||||||
t := newTeam(this.genTeamId(), this.owner)
|
t := newTeam(this, this.genTeamId(), this.owner)
|
||||||
this.teamUuidHash = map[string]*team {
|
this.teamUuidHash = map[string]*team {
|
||||||
owner.GetTeamUuid(): t,
|
owner.GetTeamUuid(): t,
|
||||||
}
|
}
|
||||||
@ -115,11 +115,11 @@ func (this *room) join(hum common.Player, passwd string) bool {
|
|||||||
if !this.canJoin(hum, passwd) {
|
if !this.canJoin(hum, passwd) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
m := newMember(hum)
|
m := newMember(this, hum)
|
||||||
this.members[hum.GetAccountId()] = m
|
this.members[hum.GetAccountId()] = m
|
||||||
t := this.getTeam(hum.GetTeamUuid())
|
t := this.getTeam(hum.GetTeamUuid())
|
||||||
if t == nil {
|
if t == nil {
|
||||||
t = newTeam(this.genTeamId(), m)
|
t = newTeam(this, this.genTeamId(), m)
|
||||||
this.teamUuidHash[hum.GetTeamUuid()] = t
|
this.teamUuidHash[hum.GetTeamUuid()] = t
|
||||||
this.teamIdHash[t.teamId] = t
|
this.teamIdHash[t.teamId] = t
|
||||||
} else {
|
} else {
|
||||||
@ -175,7 +175,7 @@ func (this *room) CMLeaveRoom(hdr *f5.MsgHdr, msg *cs.CMLeaveRoom) {
|
|||||||
this.owner = nextOwner
|
this.owner = nextOwner
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.removeMember(this.owner.hum.GetAccountId())
|
this.removeMember(hum.GetAccountId())
|
||||||
}
|
}
|
||||||
notifyMsg := &cs.SMRoomLeaveNotify{}
|
notifyMsg := &cs.SMRoomLeaveNotify{}
|
||||||
this.broadcastMsg(notifyMsg)
|
this.broadcastMsg(notifyMsg)
|
||||||
@ -392,6 +392,7 @@ func (this *room) genTeamId() int32 {
|
|||||||
func (this *room) removeMember(accountId string) {
|
func (this *room) removeMember(accountId string) {
|
||||||
m := this.getMember(accountId)
|
m := this.getMember(accountId)
|
||||||
if m != nil {
|
if m != nil {
|
||||||
|
m.unInit()
|
||||||
delete(this.members, accountId)
|
delete(this.members, accountId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,11 +5,23 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type team struct {
|
type team struct {
|
||||||
|
room *room
|
||||||
teamId int32
|
teamId int32
|
||||||
teamUuid string
|
teamUuid string
|
||||||
members q5.ListHead
|
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) {
|
func (this *team) addMember(m *member) {
|
||||||
if this.teamUuid != m.hum.GetTeamUuid() {
|
if this.teamUuid != m.hum.GetTeamUuid() {
|
||||||
panic("team.addMember team_uuid error")
|
panic("team.addMember team_uuid error")
|
||||||
@ -50,11 +62,9 @@ func (this *team) getOwnerCandidate() *member {
|
|||||||
return ownerCandidate
|
return ownerCandidate
|
||||||
}
|
}
|
||||||
|
|
||||||
func newTeam(teamId int32, leader *member) *team {
|
func newTeam(room *room, teamId int32, leader *member) *team {
|
||||||
t := new(team)
|
t := new(team)
|
||||||
t.teamId = teamId
|
t.init(room, teamId, leader.hum.GetTeamUuid())
|
||||||
t.members.Init(nil)
|
|
||||||
t.teamUuid = leader.hum.GetTeamUuid()
|
|
||||||
t.addMember(leader)
|
t.addMember(leader)
|
||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user