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
{
optional int32 errcode = 1; // 0 1:
optional string errmsg = 2; //
}
//

View File

@ -13,12 +13,12 @@ type member struct {
type room struct {
cs.MsgHandlerImpl
roomId int32
roomId string
owner *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.owner = newMember(owner)
this.members = map[string]*member{

View File

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