From 62ef4c3a262b1ef725c9ea9f3b68a91df4b5eb6c Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Fri, 15 Sep 2023 17:09:25 +0800 Subject: [PATCH] 1 --- server/hallserver/common/types.go | 1 + server/hallserver/room/room.go | 4 ++++ server/hallserver/room/roommgr.go | 7 ++++--- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/server/hallserver/common/types.go b/server/hallserver/common/types.go index 60772717..beeb7457 100644 --- a/server/hallserver/common/types.go +++ b/server/hallserver/common/types.go @@ -11,6 +11,7 @@ import ( ) type Room interface { + GetRoomState() int32 OnPlayerOffline(Player) } diff --git a/server/hallserver/room/room.go b/server/hallserver/room/room.go index 02f66009..a1208b8b 100644 --- a/server/hallserver/room/room.go +++ b/server/hallserver/room/room.go @@ -308,6 +308,10 @@ func (this *room) viewable() bool { return this.roomState == ROOM_INIT_STATE } +func (this *room) GetRoomState() int32 { + return this.roomState +} + func (this *room) notifyGameStart() { if this.gameStartNotifyMsg == nil { this.gameStartNotifyMsg = &cs.SMRoomGameStartNotify{} diff --git a/server/hallserver/room/roommgr.go b/server/hallserver/room/roommgr.go index f6776df8..cad88484 100644 --- a/server/hallserver/room/roommgr.go +++ b/server/hallserver/room/roommgr.go @@ -54,7 +54,7 @@ func (this *roomMgr) ProcessCMMsg(handler *cs.CsNetMsgHandler, hdr *f5.MsgHdr) { func (this *roomMgr) CMCreateRoom(hdr *f5.MsgHdr, msg *cs.CMCreateRoom) { hum := hdr.Context.(common.Player) rspMsg := &cs.SMCreateRoom{} - if hum.GetRoom() != nil { + if hum.GetRoom() != nil && hum.GetRoom().GetRoomState() == ROOM_INIT_STATE { rspMsg.Errcode = proto.Int32(1) rspMsg.Errmsg = proto.String("already room") hum.SendMsg(rspMsg) @@ -63,6 +63,7 @@ func (this *roomMgr) CMCreateRoom(hdr *f5.MsgHdr, msg *cs.CMCreateRoom) { m := new(room) m.init(q5.ToString(this.genRoomId()), this.genRoomIdx(), msg.GetMapId(), hum, msg.GetPasswd()) this.idHash[m.roomId] = m + this.roomList.AddTail(&m.entry) rspMsg.RoomId = proto.String(m.roomId) hum.SendMsg(rspMsg) @@ -102,11 +103,11 @@ func (this *roomMgr) CMJoinRoom(hdr *f5.MsgHdr, msg *cs.CMJoinRoom) { func (this *roomMgr) CMSearchRoom(hdr *f5.MsgHdr, msg *cs.CMSearchRoom) { hum := hdr.Context.(common.Player) rspMsg := cs.SMSearchRoom{} - rspMsg.Rows = make([]*cs.MFRoom, constant.SEARCH_ROOM_PAGE_SIZE, constant.SEARCH_ROOM_PAGE_SIZE) + rspMsg.Rows = make([]*cs.MFRoom, 0, constant.SEARCH_ROOM_PAGE_SIZE) sinceId := msg.GetSinceId() this.roomList.ForEach( func (data interface{}) bool { - r := data.(room) + r := data.(*room) if r.roomIdx > sinceId && r.viewable() { pb := new(cs.MFRoom) r.fillMFRoom(pb)