Merge branch 'master' of git.kingsome.cn:server/game2006go
This commit is contained in:
commit
544b0fa2d7
@ -225,7 +225,8 @@ message CMDisbandRoom
|
|||||||
|
|
||||||
message SMDisbandRoom
|
message SMDisbandRoom
|
||||||
{
|
{
|
||||||
|
optional int32 errcode = 1; //错误码 0:成功 1:权限不足
|
||||||
|
optional string errmsg = 2; //错误描述
|
||||||
}
|
}
|
||||||
|
|
||||||
//退出房间
|
//退出房间
|
||||||
@ -287,7 +288,6 @@ message SMRoomMemberChangeNotify
|
|||||||
message SMRoomKickoutNotify
|
message SMRoomKickoutNotify
|
||||||
{
|
{
|
||||||
repeated string account_ids = 1; //成员account_id列表
|
repeated string account_ids = 1; //成员account_id列表
|
||||||
optional int32 reason = 2; //解散原因 1:房主解散 2:系统解散(倒计时超时后队伍数<2)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//房间玩家离开通知
|
//房间玩家离开通知
|
||||||
@ -300,7 +300,7 @@ message SMRoomLeaveNotify
|
|||||||
message SMRoomDisbandNotify
|
message SMRoomDisbandNotify
|
||||||
{
|
{
|
||||||
optional string room_id = 1; //房间id
|
optional string room_id = 1; //房间id
|
||||||
optional int32 reason = 2; //解散原因 1:房主解散 2:系统解散(倒计时超时后队伍数<2)
|
optional int32 reason = 2; //解散原因 0:系统解散(倒计时超时后队伍数<2) 1:房主解散
|
||||||
}
|
}
|
||||||
|
|
||||||
//房间信息变更通知
|
//房间信息变更通知
|
||||||
|
@ -14,6 +14,7 @@ type member struct {
|
|||||||
closeGameStartNotify bool
|
closeGameStartNotify bool
|
||||||
entry q5.ListHead
|
entry q5.ListHead
|
||||||
teamEntry q5.ListHead
|
teamEntry q5.ListHead
|
||||||
|
team *team
|
||||||
hum common.Player
|
hum common.Player
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,26 +10,25 @@ import (
|
|||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
type roomConfg struct {
|
|
||||||
mapId int32
|
|
||||||
zoneId int32
|
|
||||||
nodeId int32
|
|
||||||
passwd string
|
|
||||||
}
|
|
||||||
|
|
||||||
type room struct {
|
type room struct {
|
||||||
cs.MsgHandlerImpl
|
cs.MsgHandlerImpl
|
||||||
roomId string
|
roomId string
|
||||||
roomIdx int64
|
roomIdx int64
|
||||||
entry q5.ListHead
|
entry q5.ListHead
|
||||||
config roomConfg
|
config struct {
|
||||||
|
mapId int32
|
||||||
|
zoneId int32
|
||||||
|
nodeId int32
|
||||||
|
passwd string
|
||||||
|
}
|
||||||
owner *member
|
owner *member
|
||||||
roomState int32
|
roomState int32
|
||||||
startTime int64
|
startTime int64
|
||||||
startReason int32
|
startReason int32
|
||||||
disbandTime int64
|
disbandTime int64
|
||||||
disbandReason int32
|
disbandReason int32
|
||||||
teams map[string]*team
|
teamUuidHash map[string]*team
|
||||||
|
teamIdHash map[int32]*team
|
||||||
members map[string]*member
|
members map[string]*member
|
||||||
startTimer *f5.TimerWp
|
startTimer *f5.TimerWp
|
||||||
attacher *f5.TimerAttacher
|
attacher *f5.TimerAttacher
|
||||||
@ -48,8 +47,12 @@ func (this *room) init(roomId string, roomIdx int64, mapId int32, owner common.P
|
|||||||
this.members = map[string]*member{
|
this.members = map[string]*member{
|
||||||
owner.GetAccountId(): this.owner,
|
owner.GetAccountId(): this.owner,
|
||||||
}
|
}
|
||||||
this.teams = map[string]*team {
|
t := newTeam(this.genTeamId(), this.owner)
|
||||||
owner.GetTeamUuid(): newTeam(this.owner),
|
this.teamUuidHash = map[string]*team {
|
||||||
|
owner.GetTeamUuid(): t,
|
||||||
|
}
|
||||||
|
this.teamIdHash = map[int32]*team {
|
||||||
|
t.teamId: t,
|
||||||
}
|
}
|
||||||
this.owner.hum.SetRoom(this)
|
this.owner.hum.SetRoom(this)
|
||||||
this.attacher = f5.GetTimer().NewTimerAttacher()
|
this.attacher = f5.GetTimer().NewTimerAttacher()
|
||||||
@ -72,7 +75,7 @@ func (this *room) getMember(accountId string) *member {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *room) getTeam(teamUuid string) *team {
|
func (this *room) getTeam(teamUuid string) *team {
|
||||||
t, ok := this.teams[teamUuid]
|
t, ok := this.teamUuidHash[teamUuid]
|
||||||
if ok {
|
if ok {
|
||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
@ -80,7 +83,7 @@ func (this *room) getTeam(teamUuid string) *team {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *room) getTeamNum() int32 {
|
func (this *room) getTeamNum() int32 {
|
||||||
return int32(len(this.teams))
|
return int32(len(this.teamUuidHash))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *room) canJoin(member common.Player, passwd string) bool {
|
func (this *room) canJoin(member common.Player, passwd string) bool {
|
||||||
@ -90,7 +93,7 @@ func (this *room) canJoin(member common.Player, passwd string) bool {
|
|||||||
if member.GetRoom() != nil {
|
if member.GetRoom() != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if len(this.teams) >= constant.ROOM_MAX_TEAM_NUM {
|
if len(this.teamUuidHash) >= constant.ROOM_MAX_TEAM_NUM {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if this.getMember(member.GetAccountId()) != nil {
|
if this.getMember(member.GetAccountId()) != nil {
|
||||||
@ -114,10 +117,12 @@ func (this *room) join(hum common.Player, passwd string) bool {
|
|||||||
this.members[hum.GetAccountId()] = m
|
this.members[hum.GetAccountId()] = m
|
||||||
t := this.getTeam(hum.GetTeamUuid())
|
t := this.getTeam(hum.GetTeamUuid())
|
||||||
if t == nil {
|
if t == nil {
|
||||||
t = newTeam(m)
|
t = newTeam(this.genTeamId(), m)
|
||||||
this.teams[hum.GetTeamUuid()] = t
|
this.teamUuidHash[hum.GetTeamUuid()] = t
|
||||||
|
this.teamIdHash[t.teamId] = t
|
||||||
|
} else {
|
||||||
|
t.addMember(m)
|
||||||
}
|
}
|
||||||
t.addMember(m)
|
|
||||||
hum.SetRoom(this)
|
hum.SetRoom(this)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@ -131,7 +136,7 @@ func (this *room) fillMFRoom(pb *cs.MFRoom) {
|
|||||||
}
|
}
|
||||||
pb.PlayerNum = proto.Int32(int32(len(this.members)))
|
pb.PlayerNum = proto.Int32(int32(len(this.members)))
|
||||||
pb.PlayerMaxNum = proto.Int32(constant.ROOM_MAX_PLAYER_NUM)
|
pb.PlayerMaxNum = proto.Int32(constant.ROOM_MAX_PLAYER_NUM)
|
||||||
pb.TeamNum = proto.Int32(int32(len(this.teams)))
|
pb.TeamNum = proto.Int32(int32(len(this.teamUuidHash)))
|
||||||
pb.TeamMaxNum = proto.Int32(constant.ROOM_MAX_TEAM_NUM)
|
pb.TeamMaxNum = proto.Int32(constant.ROOM_MAX_TEAM_NUM)
|
||||||
pb.Owner = new(cs.MFMember)
|
pb.Owner = new(cs.MFMember)
|
||||||
this.owner.fillMFMember(pb.Owner)
|
this.owner.fillMFMember(pb.Owner)
|
||||||
@ -143,6 +148,12 @@ func (this *room) OnPlayerOffline(hum common.Player) {
|
|||||||
func (this *room) CMDisbandRoom(hdr *f5.MsgHdr, msg *cs.CMDisbandRoom) {
|
func (this *room) CMDisbandRoom(hdr *f5.MsgHdr, msg *cs.CMDisbandRoom) {
|
||||||
hum := hdr.Context.(common.Player)
|
hum := hdr.Context.(common.Player)
|
||||||
rspMsg := &cs.SMDisbandRoom{}
|
rspMsg := &cs.SMDisbandRoom{}
|
||||||
|
if !this.isOwner(hum) {
|
||||||
|
rspMsg.Errcode = proto.Int32(1)
|
||||||
|
rspMsg.Errmsg = proto.String("insufficient permissions")
|
||||||
|
hum.SendMsg(rspMsg)
|
||||||
|
return
|
||||||
|
}
|
||||||
if this.roomState == ROOM_INIT_STATE {
|
if this.roomState == ROOM_INIT_STATE {
|
||||||
this.doDisband(1)
|
this.doDisband(1)
|
||||||
}
|
}
|
||||||
@ -152,7 +163,15 @@ func (this *room) CMDisbandRoom(hdr *f5.MsgHdr, msg *cs.CMDisbandRoom) {
|
|||||||
func (this *room) CMLeaveRoom(hdr *f5.MsgHdr, msg *cs.CMLeaveRoom) {
|
func (this *room) CMLeaveRoom(hdr *f5.MsgHdr, msg *cs.CMLeaveRoom) {
|
||||||
hum := hdr.Context.(common.Player)
|
hum := hdr.Context.(common.Player)
|
||||||
m := this.getMember(hum.GetAccountId())
|
m := this.getMember(hum.GetAccountId())
|
||||||
if m != nil {
|
if m != nil && this.roomState == ROOM_INIT_STATE {
|
||||||
|
if this.isOwner(hum) {
|
||||||
|
if len(this.teamUuidHash) < 2 {
|
||||||
|
this.doDisband(1)
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
notifyMsg := &cs.SMRoomLeaveNotify{}
|
notifyMsg := &cs.SMRoomLeaveNotify{}
|
||||||
this.broadcastMsg(notifyMsg)
|
this.broadcastMsg(notifyMsg)
|
||||||
}
|
}
|
||||||
@ -171,6 +190,9 @@ func (this *room) CMStartGame(hdr *f5.MsgHdr, msg *cs.CMStartGame) {
|
|||||||
hum.SendMsg(rspMsg)
|
hum.SendMsg(rspMsg)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if this.canStart() {
|
||||||
|
this.doStart(1)
|
||||||
|
}
|
||||||
hum.SendMsg(rspMsg)
|
hum.SendMsg(rspMsg)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -211,10 +233,10 @@ func (this *room) broadcastMsg(msg proto.Message) {
|
|||||||
|
|
||||||
func (this *room) autoStart() {
|
func (this *room) autoStart() {
|
||||||
if this.roomState == ROOM_INIT_STATE {
|
if this.roomState == ROOM_INIT_STATE {
|
||||||
if this.getTeamNum() < ROOM_MIN_START_TEAM_NUM {
|
if this.canStart() {
|
||||||
this.doDisband(0)
|
|
||||||
} else {
|
|
||||||
this.doStart(0)
|
this.doStart(0)
|
||||||
|
} else {
|
||||||
|
this.doDisband(0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -225,20 +247,28 @@ func (this *room) started() bool {
|
|||||||
|
|
||||||
func (this *room) doDisband(reason int32) {
|
func (this *room) doDisband(reason int32) {
|
||||||
this.roomState = ROOM_DISBAND_STATE
|
this.roomState = ROOM_DISBAND_STATE
|
||||||
this.disbandTime = q5.GetTickCount()
|
this.disbandTime = f5.GetApp().GetNowSeconds()
|
||||||
this.disbandReason = reason
|
this.disbandReason = reason
|
||||||
|
notifyMsg := &cs.SMRoomDisbandNotify{}
|
||||||
|
notifyMsg.RoomId = proto.String(this.roomId)
|
||||||
|
notifyMsg.Reason = proto.Int32(reason)
|
||||||
|
for _, m := range(this.members) {
|
||||||
|
if m.hum.GetRoom() == this {
|
||||||
|
m.hum.SendMsg(notifyMsg)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *room) doStart(reason int32) {
|
func (this *room) doStart(reason int32) {
|
||||||
this.roomState = ROOM_STARTED_STATE
|
this.roomState = ROOM_STARTED_STATE
|
||||||
this.startTime = q5.GetTickCount()
|
this.startTime = f5.GetApp().GetNowSeconds()
|
||||||
this.startReason = ROOM_AUTO_START_TYPE
|
this.startReason = ROOM_AUTO_START_TYPE
|
||||||
f5.GetTimer().SetIntervalExWp(
|
f5.GetTimer().SetIntervalExWp(
|
||||||
1000,
|
1000,
|
||||||
func (e int32, args *q5.Args) {
|
func (e int32, args *q5.Args) {
|
||||||
if e == q5.TIMER_EXEC_EVENT {
|
if e == q5.TIMER_EXEC_EVENT {
|
||||||
if q5.GetTickCount() - this.startTime <
|
if f5.GetApp().GetNowSeconds() - this.startTime <
|
||||||
int64(1000 * mt.Table.Config.Get().GetGameStartNotifyTime()) {
|
int64(mt.Table.Config.Get().GetGameStartNotifyTime()) {
|
||||||
this.notifyGameStart()
|
this.notifyGameStart()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -246,7 +276,7 @@ func (this *room) doStart(reason int32) {
|
|||||||
this.attacher)
|
this.attacher)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *room) view() bool {
|
func (this *room) viewable() bool {
|
||||||
return this.roomState == ROOM_INIT_STATE
|
return this.roomState == ROOM_INIT_STATE
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -256,6 +286,41 @@ func (this *room) notifyGameStart() {
|
|||||||
this.gameStartNotifyMsg.ZoneId = proto.Int32(this.config.zoneId)
|
this.gameStartNotifyMsg.ZoneId = proto.Int32(this.config.zoneId)
|
||||||
this.gameStartNotifyMsg.NodeId = proto.Int32(this.config.nodeId)
|
this.gameStartNotifyMsg.NodeId = proto.Int32(this.config.nodeId)
|
||||||
this.gameStartNotifyMsg.TeamUuid = proto.String(q5.ToString(this.roomIdx))
|
this.gameStartNotifyMsg.TeamUuid = proto.String(q5.ToString(this.roomIdx))
|
||||||
|
startInfo := struct {
|
||||||
|
ZoneId int32 `json:"zone_id"`
|
||||||
|
NodeId int32 `json:"node_id"`
|
||||||
|
RoomUuid string `json:"room_uuid"`
|
||||||
|
StartTime int32 `json:"start_time"`
|
||||||
|
TeamList [] struct {
|
||||||
|
TeamUuid string `json:"team_uuid"`
|
||||||
|
Members [] struct {
|
||||||
|
AccountId string `json:"account_id"`
|
||||||
|
} `json:"members"`
|
||||||
|
} `json:"team_list"`
|
||||||
|
}{
|
||||||
|
ZoneId: this.config.zoneId,
|
||||||
|
NodeId: this.config.nodeId,
|
||||||
|
RoomUuid: q5.ToString(this.roomIdx),
|
||||||
|
StartTime: int32(this.startTime),
|
||||||
|
}
|
||||||
|
q5.NewSlice(&startInfo.TeamList, 0, 10)
|
||||||
|
for _, t := range(this.teamUuidHash) {
|
||||||
|
if t.hasAlreadMember() {
|
||||||
|
ele := q5.NewSliceElement(&startInfo.TeamList)
|
||||||
|
ele.TeamUuid = t.teamUuid
|
||||||
|
q5.NewSlice(&ele.Members, 0, 4)
|
||||||
|
t.members.ForEach_r(
|
||||||
|
func (data interface{}) bool {
|
||||||
|
m := data.(*member)
|
||||||
|
if m.state == MEMBER_READY_STATE {
|
||||||
|
ele2 := q5.NewSliceElement(&ele.Members)
|
||||||
|
ele2.AccountId = m.hum.GetAccountId()
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.gameStartNotifyMsg.CustomRoomPayload = proto.String(q5.EncodeJson(&startInfo))
|
||||||
}
|
}
|
||||||
for _, m := range(this.members) {
|
for _, m := range(this.members) {
|
||||||
if m.state == MEMBER_READY_STATE &&
|
if m.state == MEMBER_READY_STATE &&
|
||||||
@ -265,3 +330,29 @@ func (this *room) notifyGameStart() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *room) canStart() bool {
|
||||||
|
alreadyNum := 0
|
||||||
|
for _, t := range(this.teamUuidHash) {
|
||||||
|
if t.hasAlreadMember() {
|
||||||
|
alreadyNum++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return alreadyNum >- ROOM_MIN_START_TEAM_NUM
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *room) isOwner(hum common.Player) bool {
|
||||||
|
return this.owner.hum.GetAccountId() == hum.GetAccountId()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *room) getNextOwner() *member {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *room) genTeamId() int32 {
|
||||||
|
teamId := int32(1)
|
||||||
|
for i := 1; i < constant.ROOM_MAX_TEAM_NUM; i++ {
|
||||||
|
|
||||||
|
}
|
||||||
|
return teamId
|
||||||
|
}
|
||||||
|
@ -107,7 +107,7 @@ func (this *roomMgr) CMSearchRoom(hdr *f5.MsgHdr, msg *cs.CMSearchRoom) {
|
|||||||
this.roomList.ForEach_r(
|
this.roomList.ForEach_r(
|
||||||
func (data interface{}) bool {
|
func (data interface{}) bool {
|
||||||
r := data.(room)
|
r := data.(room)
|
||||||
if r.roomIdx > sinceId && r.view() {
|
if r.roomIdx > sinceId && r.viewable() {
|
||||||
pb := new(cs.MFRoom)
|
pb := new(cs.MFRoom)
|
||||||
r.fillMFRoom(pb)
|
r.fillMFRoom(pb)
|
||||||
rspMsg.Rows = append(rspMsg.Rows, pb)
|
rspMsg.Rows = append(rspMsg.Rows, pb)
|
||||||
|
@ -2,13 +2,10 @@ package room
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"q5"
|
"q5"
|
||||||
//"f5"
|
|
||||||
//"cs"
|
|
||||||
//"main/common"
|
|
||||||
//"github.com/golang/protobuf/proto"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type team struct {
|
type team struct {
|
||||||
|
teamId int32
|
||||||
teamUuid string
|
teamUuid string
|
||||||
members q5.ListHead
|
members q5.ListHead
|
||||||
}
|
}
|
||||||
@ -17,6 +14,7 @@ func (this *team) addMember(m *member) {
|
|||||||
if this.teamUuid != m.hum.GetTeamUuid() {
|
if this.teamUuid != m.hum.GetTeamUuid() {
|
||||||
panic("team.addMember team_uuid error")
|
panic("team.addMember team_uuid error")
|
||||||
}
|
}
|
||||||
|
m.team = this
|
||||||
this.members.AddTail(&m.teamEntry)
|
this.members.AddTail(&m.teamEntry)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -24,8 +22,23 @@ func (this *team) getMemberNum() int32 {
|
|||||||
return this.members.Size()
|
return this.members.Size()
|
||||||
}
|
}
|
||||||
|
|
||||||
func newTeam(leader *member) *team {
|
func (this *team) hasAlreadMember() bool {
|
||||||
|
ok := false
|
||||||
|
this.members.ForEach_r(
|
||||||
|
func (data interface{}) bool {
|
||||||
|
m := data.(*member)
|
||||||
|
if m.state == MEMBER_READY_STATE {
|
||||||
|
ok = true
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
|
func newTeam(teamId int32, leader *member) *team {
|
||||||
t := new(team)
|
t := new(team)
|
||||||
|
t.teamId = teamId
|
||||||
t.members.Init(nil)
|
t.members.Init(nil)
|
||||||
t.teamUuid = leader.hum.GetTeamUuid()
|
t.teamUuid = leader.hum.GetTeamUuid()
|
||||||
t.addMember(leader)
|
t.addMember(leader)
|
||||||
|
2
third_party/q5
vendored
2
third_party/q5
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 2ce4c46c710cce553a5a059dda83fdf72a038a46
|
Subproject commit fe65489de27eef96e2c1879cb19dd84ee172be9c
|
Loading…
x
Reference in New Issue
Block a user