Merge branch 'master' of git.kingsome.cn:server/game2006go

This commit is contained in:
殷勇 2023-09-13 15:02:25 +08:00
commit 544b0fa2d7
6 changed files with 142 additions and 37 deletions

View File

@ -225,7 +225,8 @@ message CMDisbandRoom
message SMDisbandRoom
{
optional int32 errcode = 1; // 0 1:
optional string errmsg = 2; //
}
//退
@ -287,7 +288,6 @@ message SMRoomMemberChangeNotify
message SMRoomKickoutNotify
{
repeated string account_ids = 1; //account_id列表
optional int32 reason = 2; // 1: 2:(<2)
}
//
@ -300,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:
}
//

View File

@ -14,6 +14,7 @@ type member struct {
closeGameStartNotify bool
entry q5.ListHead
teamEntry q5.ListHead
team *team
hum common.Player
}

View File

@ -10,26 +10,25 @@ 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
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
@ -48,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()
@ -72,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
}
@ -80,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 {
@ -90,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 {
@ -114,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
}
@ -131,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)
@ -143,6 +148,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)
}
@ -152,7 +163,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.teamUuidHash) < 2 {
this.doDisband(1)
return
} else {
}
}
notifyMsg := &cs.SMRoomLeaveNotify{}
this.broadcastMsg(notifyMsg)
}
@ -171,6 +190,9 @@ func (this *room) CMStartGame(hdr *f5.MsgHdr, msg *cs.CMStartGame) {
hum.SendMsg(rspMsg)
return
}
if this.canStart() {
this.doStart(1)
}
hum.SendMsg(rspMsg)
}
@ -211,10 +233,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)
}
}
}
@ -225,20 +247,28 @@ 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
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) {
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 +276,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 +286,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)
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) {
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
}

View File

@ -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)

View File

@ -2,13 +2,10 @@ package room
import (
"q5"
//"f5"
//"cs"
//"main/common"
//"github.com/golang/protobuf/proto"
)
type team struct {
teamId int32
teamUuid string
members q5.ListHead
}
@ -17,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)
}
@ -24,8 +22,23 @@ func (this *team) getMemberNum() int32 {
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.teamId = teamId
t.members.Init(nil)
t.teamUuid = leader.hum.GetTeamUuid()
t.addMember(leader)

2
third_party/q5 vendored

@ -1 +1 @@
Subproject commit 2ce4c46c710cce553a5a059dda83fdf72a038a46
Subproject commit fe65489de27eef96e2c1879cb19dd84ee172be9c