This commit is contained in:
aozhiwei 2023-09-15 17:09:25 +08:00
parent e80dd01574
commit 62ef4c3a26
3 changed files with 9 additions and 3 deletions

View File

@ -11,6 +11,7 @@ import (
)
type Room interface {
GetRoomState() int32
OnPlayerOffline(Player)
}

View File

@ -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{}

View File

@ -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)