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