diff --git a/server/hallserver/room/room.go b/server/hallserver/room/room.go index 63caa80e..ac44f3f4 100644 --- a/server/hallserver/room/room.go +++ b/server/hallserver/room/room.go @@ -38,13 +38,8 @@ type room struct { func (this *room) init(roomId string, roomIdx int64, 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.roomIdx = roomIdx - this.entry.Init(this) this.config.mapId = msg.GetMapId() this.config.zoneId = msg.GetZoneId() this.config.nodeId = msg.GetNodeId() @@ -53,16 +48,16 @@ func (this *room) init(roomId string, roomIdx int64, this.owner = newMember(this, owner) this.addMember(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( - 1000 * mt.Table.Config.Get().GetAutoStartTime(), - func (e int32, args *q5.Args) { - if e == q5.TIMER_EXEC_EVENT { - this.autoStart() - } - }, - this.attacher) +} + +func (this *room) addMember(m *member) { + this.members[m.hum.GetAccountId()] = m + m.hum.SetRoom(this) +} + +func (this *room) addTeam(t *team) { + this.teamUuidHash[t.teamUuid] = t + this.teamIdHash[t.teamId] = t } func (this *room) getMember(accountId string) *member { @@ -128,19 +123,9 @@ func (this *room) join(hum common.Player, msg *cs.CMJoinRoom) bool { } else { t.addMember(m) } - hum.SetRoom(this) 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) { pb.RoomId = proto.String(this.roomId) 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()) } notifyMsg := &cs.SMRoomLeaveNotify{} + q5.NewSlice(¬ifyMsg.AccountIds, 0, 1) + q5.AppendSlice(¬ifyMsg.AccountIds, m.hum.GetAccountId()) 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 +} diff --git a/server/hallserver/room/roommgr.go b/server/hallserver/room/roommgr.go index cbb74e97..8bf2611e 100644 --- a/server/hallserver/room/roommgr.go +++ b/server/hallserver/room/roommgr.go @@ -60,7 +60,7 @@ func (this *roomMgr) CMCreateRoom(hdr *f5.MsgHdr, msg *cs.CMCreateRoom) { hum.SendMsg(rspMsg) return } - m := new(room) + m := newRoom() m.init(q5.ToString(this.genRoomId()), this.genRoomIdx(), hum, msg) this.idHash[m.roomId] = m this.roomList.AddTail(&m.entry) diff --git a/third_party/q5 b/third_party/q5 index b590bbd0..aa48a0c5 160000 --- a/third_party/q5 +++ b/third_party/q5 @@ -1 +1 @@ -Subproject commit b590bbd0fea20c05b89b9767c42a35af15cc0111 +Subproject commit aa48a0c5241057cd9fe00ab712638c61acd23a21