184 lines
4.1 KiB
Go
184 lines
4.1 KiB
Go
package room
|
|
|
|
import (
|
|
"cs"
|
|
"q5"
|
|
"f5"
|
|
"mt"
|
|
"main/common"
|
|
"main/constant"
|
|
"github.com/golang/protobuf/proto"
|
|
)
|
|
|
|
type roomConfg struct {
|
|
mapId int32
|
|
zoneId int32
|
|
nodeId int32
|
|
passwd string
|
|
}
|
|
|
|
type room struct {
|
|
cs.MsgHandlerImpl
|
|
roomId string
|
|
roomIdx int64
|
|
entry q5.ListHead
|
|
config roomConfg
|
|
owner *member
|
|
teams map[string]*team
|
|
members map[string]*member
|
|
startTimer *f5.TimerWp
|
|
}
|
|
|
|
func (this *room) init(roomId string, roomIdx int64, mapId int32, owner common.Player, passwd string) {
|
|
this.roomId = roomId
|
|
this.roomIdx = roomIdx
|
|
this.entry.Init(this)
|
|
this.config.mapId = mapId
|
|
this.config.zoneId = owner.GetZoneId()
|
|
this.config.nodeId = owner.GetNodeId()
|
|
this.config.passwd = passwd
|
|
this.owner = newMember(owner)
|
|
this.members = map[string]*member{
|
|
owner.GetAccountId(): this.owner,
|
|
}
|
|
this.teams = map[string]*team {
|
|
owner.GetTeamUuid(): newTeam(this.owner),
|
|
}
|
|
this.owner.hum.SetRoom(this)
|
|
this.startTimer = f5.GetTimer().SetTimeoutWp(
|
|
mt.Table.Config.Get().GetAutoStartTime(),
|
|
func (e int32, args *q5.Args) {
|
|
if e == q5.TIMER_EXEC_EVENT {
|
|
this.autoStart()
|
|
}
|
|
})
|
|
}
|
|
|
|
func (this *room) getMember(accountId string) *member {
|
|
m, ok := this.members[accountId]
|
|
if ok {
|
|
return m
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (this *room) getTeam(teamUuid string) *team {
|
|
t, ok := this.teams[teamUuid]
|
|
if ok {
|
|
return t
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (this *room) canJoin(member common.Player, passwd string) bool {
|
|
if member.GetRoom() != nil {
|
|
return false
|
|
}
|
|
if len(this.teams) >= constant.ROOM_MAX_TEAM_NUM {
|
|
return false
|
|
}
|
|
if this.getMember(member.GetAccountId()) != nil {
|
|
return false
|
|
}
|
|
if this.config.passwd != passwd {
|
|
return false
|
|
}
|
|
t := this.getTeam(member.GetTeamUuid())
|
|
if t != nil && t.getMemberNum() >= constant.ROOM_MAX_TEAM_MEMBER_NUM {
|
|
return false
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (this *room) join(hum common.Player, passwd string) bool {
|
|
if !this.canJoin(hum, passwd) {
|
|
return false
|
|
}
|
|
m := newMember(hum)
|
|
this.members[hum.GetAccountId()] = m
|
|
t := this.getTeam(hum.GetTeamUuid())
|
|
if t == nil {
|
|
t = newTeam(m)
|
|
this.teams[hum.GetTeamUuid()] = t
|
|
}
|
|
t.addMember(m)
|
|
hum.SetRoom(this)
|
|
return false
|
|
}
|
|
|
|
func (this *room) fillMFRoom(pb *cs.MFRoom) {
|
|
pb.RoomId = proto.String(this.roomId)
|
|
pb.MapId = proto.Int32(this.config.mapId)
|
|
pb.ZoneId = proto.Int32(this.config.zoneId)
|
|
if this.config.passwd != "" {
|
|
pb.HasPasswd = proto.Int32(1)
|
|
}
|
|
pb.PlayerNum = proto.Int32(int32(len(this.members)))
|
|
pb.PlayerMaxNum = proto.Int32(constant.ROOM_MAX_PLAYER_NUM)
|
|
pb.TeamNum = proto.Int32(int32(len(this.teams)))
|
|
pb.TeamMaxNum = proto.Int32(constant.ROOM_MAX_TEAM_NUM)
|
|
pb.Owner = new(cs.MFMember)
|
|
this.owner.fillMFMember(pb.Owner)
|
|
}
|
|
|
|
func (this *room) OnPlayerOffline(hum common.Player) {
|
|
}
|
|
|
|
func (this *room) CMDisbandRoom(hdr *f5.MsgHdr, msg *cs.CMDisbandRoom) {
|
|
hum := hdr.Context.(common.Player)
|
|
rspMsg := cs.SMDisbandRoom{}
|
|
hum.SendMsg(&rspMsg)
|
|
}
|
|
|
|
func (this *room) CMLeaveRoom(hdr *f5.MsgHdr, msg *cs.CMLeaveRoom) {
|
|
hum := hdr.Context.(common.Player)
|
|
m := this.getMember(hum.GetAccountId())
|
|
if m != nil {
|
|
notifyMsg := &cs.SMRoomLeaveNotify{}
|
|
this.broadcastMsg(notifyMsg)
|
|
}
|
|
}
|
|
|
|
func (this *room) CMModifyRoom(hdr *f5.MsgHdr, msg *cs.CMModifyRoom) {
|
|
hum := hdr.Context.(common.Player)
|
|
rspMsg := cs.SMModifyRoom{}
|
|
hum.SendMsg(&rspMsg)
|
|
}
|
|
|
|
func (this *room) CMStartGame(hdr *f5.MsgHdr, msg *cs.CMStartGame) {
|
|
hum := hdr.Context.(common.Player)
|
|
rspMsg := cs.SMStartGame{}
|
|
hum.SendMsg(&rspMsg)
|
|
}
|
|
|
|
func (this *room) CMSetPrepare(hdr *f5.MsgHdr, msg *cs.CMSetPrepare) {
|
|
hum := hdr.Context.(common.Player)
|
|
m := this.getMember(hum.GetAccountId())
|
|
if m != nil {
|
|
m.state = MEMBER_READY_STATE
|
|
notifyMsg := &cs.SMRoomMemberChangeNotify{}
|
|
notifyMsg.Member = new(cs.MFMember)
|
|
m.fillMFMember(notifyMsg.Member)
|
|
this.broadcastMsg(notifyMsg)
|
|
}
|
|
}
|
|
|
|
func (this *room) CMKickout(hdr *f5.MsgHdr, msg *cs.CMKickout) {
|
|
hum := hdr.Context.(common.Player)
|
|
m := this.getMember(hum.GetAccountId())
|
|
if m != nil {
|
|
notifyMsg := &cs.SMRoomKickoutNotify{}
|
|
this.broadcastMsg(notifyMsg)
|
|
}
|
|
}
|
|
|
|
func (this *room) broadcastMsg(msg proto.Message) {
|
|
for _, m := range(this.members) {
|
|
m.hum.SendMsg(msg)
|
|
}
|
|
}
|
|
|
|
func (this *room) autoStart() {
|
|
|
|
}
|