From 4928800fb0f8130b61327ccc5d632651396d559e Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Sat, 16 Sep 2023 09:24:38 +0800 Subject: [PATCH] 1 --- server/hallserver/room/room.go | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/server/hallserver/room/room.go b/server/hallserver/room/room.go index 4521d193..63caa80e 100644 --- a/server/hallserver/room/room.go +++ b/server/hallserver/room/room.go @@ -38,6 +38,10 @@ 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) @@ -47,16 +51,8 @@ func (this *room) init(roomId string, roomIdx int64, this.config.passwd = msg.GetPasswd() this.config.maxTeamNum = constant.ROOM_MAX_TEAM_NUM this.owner = newMember(this, owner) - this.members = map[string]*member{ - owner.GetAccountId(): this.owner, - } - t := newTeam(this, this.genTeamId(), msg.GetTeamUuid(), this.owner) - this.teamUuidHash = map[string]*team { - msg.GetTeamUuid(): t, - } - this.teamIdHash = map[int32]*team { - t.teamId: t, - } + 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( @@ -125,12 +121,10 @@ func (this *room) join(hum common.Player, msg *cs.CMJoinRoom) bool { return false } m := newMember(this, hum) - this.members[hum.GetAccountId()] = m + this.addMember(m) t := this.getTeamByUuid(msg.GetTeamUuid()) if t == nil { - t = newTeam(this, this.genTeamId(), msg.GetTeamUuid(), m) - this.teamUuidHash[msg.GetTeamUuid()] = t - this.teamIdHash[t.teamId] = t + this.addTeam(newTeam(this, this.genTeamId(), msg.GetTeamUuid(), m)) } else { t.addMember(m) } @@ -138,6 +132,15 @@ func (this *room) join(hum common.Player, msg *cs.CMJoinRoom) bool { 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)