This commit is contained in:
aozhiwei 2023-09-16 10:01:27 +08:00
parent 4928800fb0
commit cd47d92256
3 changed files with 32 additions and 27 deletions

View File

@ -38,13 +38,8 @@ type room struct {
func (this *room) init(roomId string, roomIdx int64, func (this *room) init(roomId string, roomIdx int64,
owner common.Player, msg *cs.CMCreateRoom) { owner common.Player, msg *cs.CMCreateRoom) {
this.teamUuidHash = map[string]*team{}
this.teamIdHash = map[int32]*team{}
this.members = map[string]*member{}
this.roomId = roomId this.roomId = roomId
this.roomIdx = roomIdx this.roomIdx = roomIdx
this.entry.Init(this)
this.config.mapId = msg.GetMapId() this.config.mapId = msg.GetMapId()
this.config.zoneId = msg.GetZoneId() this.config.zoneId = msg.GetZoneId()
this.config.nodeId = msg.GetNodeId() this.config.nodeId = msg.GetNodeId()
@ -53,16 +48,16 @@ func (this *room) init(roomId string, roomIdx int64,
this.owner = newMember(this, owner) this.owner = newMember(this, owner)
this.addMember(this.owner) this.addMember(this.owner)
this.addTeam(newTeam(this, this.genTeamId(), msg.GetTeamUuid(), this.owner)) this.addTeam(newTeam(this, this.genTeamId(), msg.GetTeamUuid(), this.owner))
this.owner.hum.SetRoom(this) }
this.attacher = f5.GetTimer().NewTimerAttacher()
this.startTimer = f5.GetTimer().SetTimeoutExWp( func (this *room) addMember(m *member) {
1000 * mt.Table.Config.Get().GetAutoStartTime(), this.members[m.hum.GetAccountId()] = m
func (e int32, args *q5.Args) { m.hum.SetRoom(this)
if e == q5.TIMER_EXEC_EVENT { }
this.autoStart()
} func (this *room) addTeam(t *team) {
}, this.teamUuidHash[t.teamUuid] = t
this.attacher) this.teamIdHash[t.teamId] = t
} }
func (this *room) getMember(accountId string) *member { func (this *room) getMember(accountId string) *member {
@ -128,19 +123,9 @@ func (this *room) join(hum common.Player, msg *cs.CMJoinRoom) bool {
} else { } else {
t.addMember(m) t.addMember(m)
} }
hum.SetRoom(this)
return false return false
} }
func (this *room) addMember(m *member) {
this.members[m.hum.GetAccountId()] = m
}
func (this *room) addTeam(t *team) {
this.teamUuidHash[t.teamUuid] = t
this.teamIdHash[t.teamId] = t
}
func (this *room) fillMFRoom(pb *cs.MFRoom) { func (this *room) fillMFRoom(pb *cs.MFRoom) {
pb.RoomId = proto.String(this.roomId) pb.RoomId = proto.String(this.roomId)
pb.MapId = proto.Int32(this.config.mapId) pb.MapId = proto.Int32(this.config.mapId)
@ -191,6 +176,8 @@ func (this *room) CMLeaveRoom(hdr *f5.MsgHdr, msg *cs.CMLeaveRoom) {
this.removeMember(hum.GetAccountId()) this.removeMember(hum.GetAccountId())
} }
notifyMsg := &cs.SMRoomLeaveNotify{} notifyMsg := &cs.SMRoomLeaveNotify{}
q5.NewSlice(&notifyMsg.AccountIds, 0, 1)
q5.AppendSlice(&notifyMsg.AccountIds, m.hum.GetAccountId())
this.broadcastMsg(notifyMsg) this.broadcastMsg(notifyMsg)
} }
} }
@ -430,3 +417,21 @@ func (this *room) removeMember(accountId string) {
} }
} }
} }
func newRoom() *room {
r := new(room)
r.teamUuidHash = map[string]*team{}
r.teamIdHash = map[int32]*team{}
r.members = map[string]*member{}
r.entry.Init(r)
r.attacher = f5.GetTimer().NewTimerAttacher()
r.startTimer = f5.GetTimer().SetTimeoutExWp(
1000 * mt.Table.Config.Get().GetAutoStartTime(),
func (e int32, args *q5.Args) {
if e == q5.TIMER_EXEC_EVENT {
r.autoStart()
}
},
r.attacher)
return r
}

View File

@ -60,7 +60,7 @@ func (this *roomMgr) CMCreateRoom(hdr *f5.MsgHdr, msg *cs.CMCreateRoom) {
hum.SendMsg(rspMsg) hum.SendMsg(rspMsg)
return return
} }
m := new(room) m := newRoom()
m.init(q5.ToString(this.genRoomId()), this.genRoomIdx(), hum, msg) m.init(q5.ToString(this.genRoomId()), this.genRoomIdx(), hum, msg)
this.idHash[m.roomId] = m this.idHash[m.roomId] = m
this.roomList.AddTail(&m.entry) this.roomList.AddTail(&m.entry)

2
third_party/q5 vendored

@ -1 +1 @@
Subproject commit b590bbd0fea20c05b89b9767c42a35af15cc0111 Subproject commit aa48a0c5241057cd9fe00ab712638c61acd23a21