1
This commit is contained in:
parent
5cbbf70932
commit
a22900cda8
@ -11,15 +11,21 @@ type member struct {
|
||||
hum common.Player
|
||||
}
|
||||
|
||||
type roomConfg struct {
|
||||
passwd string
|
||||
}
|
||||
|
||||
type room struct {
|
||||
cs.MsgHandlerImpl
|
||||
roomId string
|
||||
config roomConfg
|
||||
owner *member
|
||||
members map[string]*member
|
||||
}
|
||||
|
||||
func (this *room) init(roomId string, owner common.Player) {
|
||||
func (this *room) init(roomId string, owner common.Player, passwd string) {
|
||||
this.roomId = roomId
|
||||
this.config.passwd = passwd
|
||||
this.owner = newMember(owner)
|
||||
this.members = map[string]*member{
|
||||
owner.GetAccountId(): this.owner,
|
||||
@ -27,6 +33,36 @@ func (this *room) init(roomId string, owner common.Player) {
|
||||
this.owner.hum.SetRoom(this)
|
||||
}
|
||||
|
||||
func (this *room) getMember(accountId string) *member {
|
||||
m, ok := this.members[accountId]
|
||||
if ok {
|
||||
return m
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this *room) canJoin(member common.Player, passwd string) bool {
|
||||
if member.GetRoom() != nil {
|
||||
return false
|
||||
}
|
||||
if this.getMember(member.GetAccountId()) != nil {
|
||||
return false
|
||||
}
|
||||
if this.config.passwd != passwd {
|
||||
return false
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (this *room) join(member common.Player, passwd string) bool {
|
||||
if !this.canJoin(member, passwd) {
|
||||
return false
|
||||
}
|
||||
this.members[member.GetAccountId()] = newMember(member)
|
||||
member.SetRoom(this)
|
||||
return false
|
||||
}
|
||||
|
||||
func (this *room) OnPlayerOffline(hum common.Player) {
|
||||
}
|
||||
|
||||
|
@ -53,12 +53,12 @@ func (this *roomMgr) CMCreateRoom(hdr *f5.MsgHdr, msg *cs.CMCreateRoom) {
|
||||
rspMsg := &cs.SMCreateRoom{}
|
||||
if hum.GetRoom() != nil {
|
||||
rspMsg.Errcode = proto.Int32(1)
|
||||
rspMsg.Errmsg = proto.String("")
|
||||
rspMsg.Errmsg = proto.String("already room")
|
||||
hum.SendMsg(rspMsg)
|
||||
return
|
||||
}
|
||||
m := new(room)
|
||||
m.init(q5.ToString(this.genRoomIdx()), hum)
|
||||
m.init(q5.ToString(this.genRoomIdx()), hum, msg.GetPasswd())
|
||||
this.idHash[m.roomId] = m
|
||||
hum.SendMsg(rspMsg)
|
||||
}
|
||||
@ -68,13 +68,22 @@ func (this *roomMgr) CMJoinRoom(hdr *f5.MsgHdr, msg *cs.CMJoinRoom) {
|
||||
rspMsg := cs.SMJoinRoom{}
|
||||
if hum.GetRoom() != nil {
|
||||
rspMsg.Errcode = proto.Int32(1)
|
||||
rspMsg.Errmsg = proto.String("")
|
||||
rspMsg.Errmsg = proto.String("already room")
|
||||
hum.SendMsg(&rspMsg)
|
||||
return
|
||||
}
|
||||
r := this.getRoom(msg.GetRoomId())
|
||||
if r == nil {
|
||||
|
||||
rspMsg.Errcode = proto.Int32(2)
|
||||
rspMsg.Errmsg = proto.String("room not found")
|
||||
hum.SendMsg(&rspMsg)
|
||||
return
|
||||
}
|
||||
if !r.canJoin(hum, msg.GetPasswd()) {
|
||||
rspMsg.Errcode = proto.Int32(3)
|
||||
rspMsg.Errmsg = proto.String("cant join")
|
||||
hum.SendMsg(&rspMsg)
|
||||
return
|
||||
}
|
||||
hum.SendMsg(&rspMsg)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user