From 2ca100c0060a67654208a3bf9d484c55072d3b12 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Wed, 13 Sep 2023 12:29:34 +0800 Subject: [PATCH 1/6] 1 --- server/hallserver/room/room.go | 59 ++++++++++++++++++++++++------- server/hallserver/room/roommgr.go | 2 +- server/hallserver/room/team.go | 18 +++++++--- third_party/q5 | 2 +- 4 files changed, 62 insertions(+), 19 deletions(-) diff --git a/server/hallserver/room/room.go b/server/hallserver/room/room.go index 08118c4f..1fca4410 100644 --- a/server/hallserver/room/room.go +++ b/server/hallserver/room/room.go @@ -10,19 +10,17 @@ import ( "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 + config struct { + mapId int32 + zoneId int32 + nodeId int32 + passwd string + } owner *member roomState int32 startTime int64 @@ -225,20 +223,20 @@ func (this *room) started() bool { func (this *room) doDisband(reason int32) { this.roomState = ROOM_DISBAND_STATE - this.disbandTime = q5.GetTickCount() + this.disbandTime = f5.GetApp().GetNowSeconds() this.disbandReason = reason } func (this *room) doStart(reason int32) { this.roomState = ROOM_STARTED_STATE - this.startTime = q5.GetTickCount() + this.startTime = f5.GetApp().GetNowSeconds() this.startReason = ROOM_AUTO_START_TYPE f5.GetTimer().SetIntervalExWp( 1000, func (e int32, args *q5.Args) { if e == q5.TIMER_EXEC_EVENT { - if q5.GetTickCount() - this.startTime < - int64(1000 * mt.Table.Config.Get().GetGameStartNotifyTime()) { + if f5.GetApp().GetNowSeconds() - this.startTime < + int64(mt.Table.Config.Get().GetGameStartNotifyTime()) { this.notifyGameStart() } } @@ -246,7 +244,7 @@ func (this *room) doStart(reason int32) { this.attacher) } -func (this *room) view() bool { +func (this *room) viewable() bool { return this.roomState == ROOM_INIT_STATE } @@ -256,6 +254,41 @@ func (this *room) notifyGameStart() { this.gameStartNotifyMsg.ZoneId = proto.Int32(this.config.zoneId) this.gameStartNotifyMsg.NodeId = proto.Int32(this.config.nodeId) 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) + this.gameStartNotifyMsg.CustomRoomPayload = proto.String(q5.EncodeJson(&startInfo)) + for _, t := range(this.teams) { + 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 + }) + } + } } for _, m := range(this.members) { if m.state == MEMBER_READY_STATE && diff --git a/server/hallserver/room/roommgr.go b/server/hallserver/room/roommgr.go index c6d26983..dd2e9ce7 100644 --- a/server/hallserver/room/roommgr.go +++ b/server/hallserver/room/roommgr.go @@ -107,7 +107,7 @@ func (this *roomMgr) CMSearchRoom(hdr *f5.MsgHdr, msg *cs.CMSearchRoom) { this.roomList.ForEach_r( func (data interface{}) bool { r := data.(room) - if r.roomIdx > sinceId && r.view() { + if r.roomIdx > sinceId && r.viewable() { pb := new(cs.MFRoom) r.fillMFRoom(pb) rspMsg.Rows = append(rspMsg.Rows, pb) diff --git a/server/hallserver/room/team.go b/server/hallserver/room/team.go index 17ecd913..6ed1f93e 100644 --- a/server/hallserver/room/team.go +++ b/server/hallserver/room/team.go @@ -2,10 +2,6 @@ package room import ( "q5" - //"f5" - //"cs" - //"main/common" - //"github.com/golang/protobuf/proto" ) type team struct { @@ -24,6 +20,20 @@ func (this *team) getMemberNum() int32 { return this.members.Size() } +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(leader *member) *team { t := new(team) t.members.Init(nil) diff --git a/third_party/q5 b/third_party/q5 index 2ce4c46c..fe65489d 160000 --- a/third_party/q5 +++ b/third_party/q5 @@ -1 +1 @@ -Subproject commit 2ce4c46c710cce553a5a059dda83fdf72a038a46 +Subproject commit fe65489de27eef96e2c1879cb19dd84ee172be9c From 0c61ae146aa6a1c1d6780c55131c9ee2c214c5aa Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Wed, 13 Sep 2023 12:43:59 +0800 Subject: [PATCH 2/6] 1 --- server/hallserver/room/room.go | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/server/hallserver/room/room.go b/server/hallserver/room/room.go index 1fca4410..a57a43d8 100644 --- a/server/hallserver/room/room.go +++ b/server/hallserver/room/room.go @@ -169,6 +169,9 @@ func (this *room) CMStartGame(hdr *f5.MsgHdr, msg *cs.CMStartGame) { hum.SendMsg(rspMsg) return } + if this.canStart() { + this.doStart(1) + } hum.SendMsg(rspMsg) } @@ -209,10 +212,10 @@ func (this *room) broadcastMsg(msg proto.Message) { func (this *room) autoStart() { if this.roomState == ROOM_INIT_STATE { - if this.getTeamNum() < ROOM_MIN_START_TEAM_NUM { - this.doDisband(0) - } else { + if this.canStart() { this.doStart(0) + } else { + this.doDisband(0) } } } @@ -272,7 +275,6 @@ func (this *room) notifyGameStart() { StartTime: int32(this.startTime), } q5.NewSlice(&startInfo.TeamList, 0, 10) - this.gameStartNotifyMsg.CustomRoomPayload = proto.String(q5.EncodeJson(&startInfo)) for _, t := range(this.teams) { if t.hasAlreadMember() { ele := q5.NewSliceElement(&startInfo.TeamList) @@ -289,6 +291,7 @@ func (this *room) notifyGameStart() { }) } } + this.gameStartNotifyMsg.CustomRoomPayload = proto.String(q5.EncodeJson(&startInfo)) } for _, m := range(this.members) { if m.state == MEMBER_READY_STATE && @@ -298,3 +301,13 @@ func (this *room) notifyGameStart() { } } } + +func (this *room) canStart() bool { + alreadyNum := 0 + for _, t := range(this.teams) { + if t.hasAlreadMember() { + alreadyNum++ + } + } + return alreadyNum >- ROOM_MIN_START_TEAM_NUM +} From 85286a2443bd82fc345bfa36cad63eb2ae24b042 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Wed, 13 Sep 2023 12:56:12 +0800 Subject: [PATCH 3/6] 1 --- server/hallserver/proto/cs_proto.proto | 3 ++- server/hallserver/room/room.go | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/server/hallserver/proto/cs_proto.proto b/server/hallserver/proto/cs_proto.proto index e40cade2..d3c892e7 100644 --- a/server/hallserver/proto/cs_proto.proto +++ b/server/hallserver/proto/cs_proto.proto @@ -225,7 +225,8 @@ message CMDisbandRoom message SMDisbandRoom { - + optional int32 errcode = 1; //错误码 0:成功 1:权限不足 + optional string errmsg = 2; //错误描述 } //退出房间 diff --git a/server/hallserver/room/room.go b/server/hallserver/room/room.go index a57a43d8..d898342d 100644 --- a/server/hallserver/room/room.go +++ b/server/hallserver/room/room.go @@ -141,6 +141,12 @@ 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{} + 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 { this.doDisband(1) } @@ -311,3 +317,7 @@ func (this *room) canStart() bool { } return alreadyNum >- ROOM_MIN_START_TEAM_NUM } + +func (this *room) isOwner(hum common.Player) bool { + return this.owner.hum.GetAccountId() == hum.GetAccountId() +} From 2087028b4aff6de8c0e29e39231c620d3aac043d Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Wed, 13 Sep 2023 14:18:10 +0800 Subject: [PATCH 4/6] 1 --- server/hallserver/proto/cs_proto.proto | 3 +-- server/hallserver/room/member.go | 1 + server/hallserver/room/room.go | 22 +++++++++++++++++++++- server/hallserver/room/team.go | 2 ++ 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/server/hallserver/proto/cs_proto.proto b/server/hallserver/proto/cs_proto.proto index d3c892e7..4f323a49 100644 --- a/server/hallserver/proto/cs_proto.proto +++ b/server/hallserver/proto/cs_proto.proto @@ -288,7 +288,6 @@ message SMRoomMemberChangeNotify message SMRoomKickoutNotify { repeated string account_ids = 1; //成员account_id列表 - optional int32 reason = 2; //解散原因 1:房主解散 2:系统解散(倒计时超时后队伍数<2) } //房间玩家离开通知 @@ -301,7 +300,7 @@ message SMRoomLeaveNotify message SMRoomDisbandNotify { optional string room_id = 1; //房间id - optional int32 reason = 2; //解散原因 1:房主解散 2:系统解散(倒计时超时后队伍数<2) + optional int32 reason = 2; //解散原因 0:系统解散(倒计时超时后队伍数<2) 1:房主解散 } //房间信息变更通知 diff --git a/server/hallserver/room/member.go b/server/hallserver/room/member.go index 93a06afe..d5d61f3e 100644 --- a/server/hallserver/room/member.go +++ b/server/hallserver/room/member.go @@ -14,6 +14,7 @@ type member struct { closeGameStartNotify bool entry q5.ListHead teamEntry q5.ListHead + team *team hum common.Player } diff --git a/server/hallserver/room/room.go b/server/hallserver/room/room.go index d898342d..308abab1 100644 --- a/server/hallserver/room/room.go +++ b/server/hallserver/room/room.go @@ -156,7 +156,15 @@ func (this *room) CMDisbandRoom(hdr *f5.MsgHdr, msg *cs.CMDisbandRoom) { func (this *room) CMLeaveRoom(hdr *f5.MsgHdr, msg *cs.CMLeaveRoom) { hum := hdr.Context.(common.Player) m := this.getMember(hum.GetAccountId()) - if m != nil { + if m != nil && this.roomState == ROOM_INIT_STATE { + if this.isOwner(hum) { + if len(this.teams) < 2 { + this.doDisband(1) + return + } else { + + } + } notifyMsg := &cs.SMRoomLeaveNotify{} this.broadcastMsg(notifyMsg) } @@ -234,6 +242,14 @@ func (this *room) doDisband(reason int32) { this.roomState = ROOM_DISBAND_STATE this.disbandTime = f5.GetApp().GetNowSeconds() 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) { @@ -321,3 +337,7 @@ func (this *room) canStart() bool { func (this *room) isOwner(hum common.Player) bool { return this.owner.hum.GetAccountId() == hum.GetAccountId() } + +func (this *room) getNextOwner() *member { + return nil +} diff --git a/server/hallserver/room/team.go b/server/hallserver/room/team.go index 6ed1f93e..78d707b4 100644 --- a/server/hallserver/room/team.go +++ b/server/hallserver/room/team.go @@ -5,6 +5,7 @@ import ( ) type team struct { + teamId int32 teamUuid string members q5.ListHead } @@ -13,6 +14,7 @@ func (this *team) addMember(m *member) { if this.teamUuid != m.hum.GetTeamUuid() { panic("team.addMember team_uuid error") } + m.team = this this.members.AddTail(&m.teamEntry) } From 0ddb5f5297878417b796e52004fda75f490124ff Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Wed, 13 Sep 2023 14:44:47 +0800 Subject: [PATCH 5/6] 1 --- server/hallserver/room/room.go | 38 ++++++++++++++++++++++------------ server/hallserver/room/team.go | 3 ++- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/server/hallserver/room/room.go b/server/hallserver/room/room.go index 308abab1..c14adc3b 100644 --- a/server/hallserver/room/room.go +++ b/server/hallserver/room/room.go @@ -27,7 +27,8 @@ type room struct { startReason int32 disbandTime int64 disbandReason int32 - teams map[string]*team + teamUuidHash map[string]*team + teamIdHash map[int32]*team members map[string]*member startTimer *f5.TimerWp attacher *f5.TimerAttacher @@ -46,8 +47,12 @@ func (this *room) init(roomId string, roomIdx int64, mapId int32, owner common.P this.members = map[string]*member{ owner.GetAccountId(): this.owner, } - this.teams = map[string]*team { - owner.GetTeamUuid(): newTeam(this.owner), + t := newTeam(this.genTeamId(), this.owner) + this.teamUuidHash = map[string]*team { + owner.GetTeamUuid(): t, + } + this.teamIdHash = map[int32]*team { + t.teamId: t, } this.owner.hum.SetRoom(this) this.attacher = f5.GetTimer().NewTimerAttacher() @@ -70,7 +75,7 @@ func (this *room) getMember(accountId string) *member { } func (this *room) getTeam(teamUuid string) *team { - t, ok := this.teams[teamUuid] + t, ok := this.teamUuidHash[teamUuid] if ok { return t } @@ -78,7 +83,7 @@ func (this *room) getTeam(teamUuid string) *team { } 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 { @@ -88,7 +93,7 @@ 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 { + if len(this.teamUuidHash) >= constant.ROOM_MAX_TEAM_NUM { return false } if this.getMember(member.GetAccountId()) != nil { @@ -112,10 +117,12 @@ func (this *room) join(hum common.Player, passwd string) bool { this.members[hum.GetAccountId()] = m t := this.getTeam(hum.GetTeamUuid()) if t == nil { - t = newTeam(m) - this.teams[hum.GetTeamUuid()] = t + t = newTeam(this.genTeamId(), m) + this.teamUuidHash[hum.GetTeamUuid()] = t + this.teamIdHash[t.teamId] = t + } else { + t.addMember(m) } - t.addMember(m) hum.SetRoom(this) return false } @@ -129,7 +136,7 @@ func (this *room) fillMFRoom(pb *cs.MFRoom) { } 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.TeamNum = proto.Int32(int32(len(this.teamUuidHash))) pb.TeamMaxNum = proto.Int32(constant.ROOM_MAX_TEAM_NUM) pb.Owner = new(cs.MFMember) this.owner.fillMFMember(pb.Owner) @@ -158,7 +165,7 @@ func (this *room) CMLeaveRoom(hdr *f5.MsgHdr, msg *cs.CMLeaveRoom) { m := this.getMember(hum.GetAccountId()) if m != nil && this.roomState == ROOM_INIT_STATE { if this.isOwner(hum) { - if len(this.teams) < 2 { + if len(this.teamUuidHash) < 2 { this.doDisband(1) return } else { @@ -297,7 +304,7 @@ func (this *room) notifyGameStart() { StartTime: int32(this.startTime), } q5.NewSlice(&startInfo.TeamList, 0, 10) - for _, t := range(this.teams) { + for _, t := range(this.teamUuidHash) { if t.hasAlreadMember() { ele := q5.NewSliceElement(&startInfo.TeamList) ele.TeamUuid = t.teamUuid @@ -326,7 +333,7 @@ func (this *room) notifyGameStart() { func (this *room) canStart() bool { alreadyNum := 0 - for _, t := range(this.teams) { + for _, t := range(this.teamUuidHash) { if t.hasAlreadMember() { alreadyNum++ } @@ -341,3 +348,8 @@ func (this *room) isOwner(hum common.Player) bool { func (this *room) getNextOwner() *member { return nil } + +func (this *room) genTeamId() int32 { + teamId := int32(1) + return teamId +} diff --git a/server/hallserver/room/team.go b/server/hallserver/room/team.go index 78d707b4..4554e6ce 100644 --- a/server/hallserver/room/team.go +++ b/server/hallserver/room/team.go @@ -36,8 +36,9 @@ func (this *team) hasAlreadMember() bool { return ok } -func newTeam(leader *member) *team { +func newTeam(teamId int32, leader *member) *team { t := new(team) + t.teamId = teamId t.members.Init(nil) t.teamUuid = leader.hum.GetTeamUuid() t.addMember(leader) From b5aa526cd4c66e62b5cd1dc79989496503024dca Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Wed, 13 Sep 2023 14:47:10 +0800 Subject: [PATCH 6/6] 1 --- server/hallserver/room/room.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/server/hallserver/room/room.go b/server/hallserver/room/room.go index c14adc3b..8c169dd5 100644 --- a/server/hallserver/room/room.go +++ b/server/hallserver/room/room.go @@ -351,5 +351,8 @@ func (this *room) getNextOwner() *member { func (this *room) genTeamId() int32 { teamId := int32(1) + for i := 1; i < constant.ROOM_MAX_TEAM_NUM; i++ { + + } return teamId }