This commit is contained in:
aozhiwei 2023-09-11 11:56:29 +08:00
parent f1906b4c0d
commit 5cbbf70932
3 changed files with 25 additions and 6 deletions

View File

@ -212,7 +212,8 @@ message CMJoinRoom
message SMJoinRoom message SMJoinRoom
{ {
optional int32 errcode = 1; // 0 1:
optional string errmsg = 2; //
} }
// //

View File

@ -13,12 +13,12 @@ type member struct {
type room struct { type room struct {
cs.MsgHandlerImpl cs.MsgHandlerImpl
roomId int32 roomId string
owner *member owner *member
members map[string]*member members map[string]*member
} }
func (this *room) init(roomId int32, owner common.Player) { func (this *room) init(roomId string, owner common.Player) {
this.roomId = roomId this.roomId = roomId
this.owner = newMember(owner) this.owner = newMember(owner)
this.members = map[string]*member{ this.members = map[string]*member{

View File

@ -2,26 +2,36 @@ package room
import ( import (
"cs" "cs"
"q5"
"f5" "f5"
"main/constant" "main/constant"
"main/common" "main/common"
"github.com/golang/protobuf/proto"
. "main/global" . "main/global"
) )
type roomMgr struct { type roomMgr struct {
cs.MsgHandlerImpl cs.MsgHandlerImpl
currRoomId int32 currRoomId int32
idHash map[int32]*room idHash map[string]*room
} }
func (this *roomMgr) Init() { func (this *roomMgr) Init() {
this.idHash = make(map[int32]*room) this.idHash = make(map[string]*room)
this.currRoomId = 10000 this.currRoomId = 10000
} }
func (this *roomMgr) UnInit() { func (this *roomMgr) UnInit() {
} }
func (this *roomMgr) getRoom(roomId string) *room {
room, ok := this.idHash[roomId]
if ok {
return room
}
return nil
}
func (this *roomMgr) ProcessCMMsg(handler *cs.CsNetMsgHandler, hdr *f5.MsgHdr) { func (this *roomMgr) ProcessCMMsg(handler *cs.CsNetMsgHandler, hdr *f5.MsgHdr) {
switch handler.HandlerId { switch handler.HandlerId {
case constant.ROOM_MGR_HANDLER_ID: case constant.ROOM_MGR_HANDLER_ID:
@ -42,11 +52,13 @@ func (this *roomMgr) CMCreateRoom(hdr *f5.MsgHdr, msg *cs.CMCreateRoom) {
hum := hdr.Context.(common.Player) hum := hdr.Context.(common.Player)
rspMsg := &cs.SMCreateRoom{} rspMsg := &cs.SMCreateRoom{}
if hum.GetRoom() != nil { if hum.GetRoom() != nil {
rspMsg.Errcode = proto.Int32(1)
rspMsg.Errmsg = proto.String("")
hum.SendMsg(rspMsg) hum.SendMsg(rspMsg)
return return
} }
m := new(room) m := new(room)
m.init(this.genRoomIdx(), hum) m.init(q5.ToString(this.genRoomIdx()), hum)
this.idHash[m.roomId] = m this.idHash[m.roomId] = m
hum.SendMsg(rspMsg) hum.SendMsg(rspMsg)
} }
@ -55,8 +67,14 @@ func (this *roomMgr) CMJoinRoom(hdr *f5.MsgHdr, msg *cs.CMJoinRoom) {
hum := hdr.Context.(common.Player) hum := hdr.Context.(common.Player)
rspMsg := cs.SMJoinRoom{} rspMsg := cs.SMJoinRoom{}
if hum.GetRoom() != nil { if hum.GetRoom() != nil {
rspMsg.Errcode = proto.Int32(1)
rspMsg.Errmsg = proto.String("")
hum.SendMsg(&rspMsg) hum.SendMsg(&rspMsg)
return return
}
r := this.getRoom(msg.GetRoomId())
if r == nil {
} }
hum.SendMsg(&rspMsg) hum.SendMsg(&rspMsg)
} }