This commit is contained in:
aozhiwei 2024-02-01 16:11:56 +08:00
parent b97cd2c799
commit 4b5d1da32c
4 changed files with 86 additions and 31 deletions

View File

@ -126,6 +126,7 @@ message MFTeam
optional int32 team_id = 1; //id optional int32 team_id = 1; //id
optional string team_uuid = 2; //id optional string team_uuid = 2; //id
repeated MFMember members = 3; // repeated MFMember members = 3; //
optional int32 sort_idx = 4 [default = 0]; //
} }
// //

View File

@ -8,6 +8,7 @@ import (
"main/constant" "main/constant"
"mt" "mt"
"q5" "q5"
"sort"
) )
type room struct { type room struct {
@ -71,12 +72,32 @@ func (this *room) addMember(m *member) {
} }
func (this *room) addTeam(t *team) { func (this *room) addTeam(t *team) {
this.curSortIdx += 1 t.sortIdx = this.genSortIdx()
t.sortIdx = this.curSortIdx
this.teamUuidHash[t.teamUuid] = t this.teamUuidHash[t.teamUuid] = t
this.teamIdHash[t.teamId] = t this.teamIdHash[t.teamId] = t
} }
func (this *room) removeTeam(t *team) {
delete(this.teamUuidHash, t.teamUuid)
delete(this.teamIdHash, t.teamId)
}
func (this *room) addObTeam(t *team) {
t.obSortIdx = this.genSortIdx()
this.obTeamUuidHash[t.teamUuid] = t
this.obTeamIdHash[t.teamId] = t
}
func (this *room) removeObTeam(t *team) {
delete(this.obTeamUuidHash, t.teamUuid)
delete(this.obTeamIdHash, t.teamId)
}
func (this *room) genSortIdx() int32 {
this.curSortIdx += 1
return this.curSortIdx;
}
func (this *room) getMember(accountId string) *member { func (this *room) getMember(accountId string) *member {
m, ok := this.members[accountId] m, ok := this.members[accountId]
if ok { if ok {
@ -101,6 +122,22 @@ func (this *room) getTeamById(teamId int32) *team {
return nil return nil
} }
func (this *room) getObTeamByUuid(teamUuid string) *team {
t, ok := this.obTeamUuidHash[teamUuid]
if ok {
return t
}
return nil
}
func (this *room) getObTeamById(teamId int32) *team {
t, ok := this.obTeamIdHash[teamId]
if ok {
return t
}
return nil
}
func (this *room) getTeamNum() int32 { func (this *room) getTeamNum() int32 {
return int32(len(this.teamUuidHash)) return int32(len(this.teamUuidHash))
} }
@ -190,7 +227,7 @@ func (this *room) fillMFRoom(hum common.Player, pb *cs.MFRoom) {
this.owner.fillMFMember(pb.Owner) this.owner.fillMFMember(pb.Owner)
} }
func (this *room) fillMFCurrentRoom(hum common.Player, pb *cs.MFCurrentRoom, observerTeam *team) { func (this *room) fillMFCurrentRoom(hum common.Player, pb *cs.MFCurrentRoom) {
pb.RoomId = proto.String(this.roomId) pb.RoomId = proto.String(this.roomId)
pb.MapId = proto.Int32(this.config.mapId) pb.MapId = proto.Int32(this.config.mapId)
pb.ZoneId = proto.Int32(this.config.zoneId) pb.ZoneId = proto.Int32(this.config.zoneId)
@ -213,14 +250,21 @@ func (this *room) fillMFCurrentRoom(hum common.Player, pb *cs.MFCurrentRoom, obs
for _, t := range this.teamUuidHash { for _, t := range this.teamUuidHash {
pbT := &cs.MFTeam{} pbT := &cs.MFTeam{}
t.fillMFTeam(pbT) t.fillMFTeam(pbT)
pbT.SortIdx = proto.Int32(t.sortIdx)
q5.AppendSlice(&pb.TeamList, pbT) q5.AppendSlice(&pb.TeamList, pbT)
} }
sort.Slice(pb.TeamList, func(i, j int) bool {
if observerTeam != nil && observerTeam.room != nil { return *pb.TeamList[i].SortIdx < *pb.TeamList[j].SortIdx
pbT2 := &cs.MFTeam{} })
observerTeam.fillMFTeam(pbT2) for _, t := range this.obTeamUuidHash {
q5.AppendSlice(&pb.ObserverTeamList, pbT2) pbT := &cs.MFTeam{}
t.fillMFTeam(pbT)
pbT.SortIdx = proto.Int32(t.obSortIdx)
q5.AppendSlice(&pb.TeamList, pbT)
} }
sort.Slice(pb.ObserverTeamList, func(i, j int) bool {
return *pb.ObserverTeamList[i].SortIdx < *pb.ObserverTeamList[j].SortIdx
})
} }
func (this *room) OnPlayerOffline(hum common.Player) { func (this *room) OnPlayerOffline(hum common.Player) {
@ -484,6 +528,16 @@ func (this *room) genGameStartNotifyMsg() {
}) })
} }
} }
q5.NewSlice(&startInfo.ObList, 0, 10)
for _, t := range this.obTeamUuidHash {
t.members.ForEach(
func(data interface{}) bool {
m := data.(*member)
ele := q5.NewSliceElement(&startInfo.ObList)
ele.AccountId = m.hum.GetAccountId()
return true
})
}
this.gameStartNotifyMsg.CustomRoomPayload = proto.String( this.gameStartNotifyMsg.CustomRoomPayload = proto.String(
q5.Md5Str(q5.EncodeJson(&startInfo) + "520d8eAbB(8cf1^#$^&!@d833a42c820432PDAFE^^)") + "|" + q5.Md5Str(q5.EncodeJson(&startInfo) + "520d8eAbB(8cf1^#$^&!@d833a42c820432PDAFE^^)") + "|" +
q5.EncodeJson(&startInfo)) q5.EncodeJson(&startInfo))

View File

@ -16,7 +16,6 @@ type roomMgr struct {
currRoomId int32 currRoomId int32
idHash map[string]*room idHash map[string]*room
roomList q5.ListHead roomList q5.ListHead
observerTeam *team
} }
func (this *roomMgr) Init() { func (this *roomMgr) Init() {
@ -170,7 +169,7 @@ func (this *roomMgr) CMGetCurrentRoom(hdr *f5.MsgHdr, msg *cs.CMGetCurrentRoom)
rspMsg := &cs.SMGetCurrentRoom{} rspMsg := &cs.SMGetCurrentRoom{}
if hum.GetRoom() != nil && hum.GetRoom().GetRoomState() == ROOM_INIT_STATE { if hum.GetRoom() != nil && hum.GetRoom().GetRoomState() == ROOM_INIT_STATE {
rspMsg.Room = new(cs.MFCurrentRoom) rspMsg.Room = new(cs.MFCurrentRoom)
hum.GetRoom().(*room).fillMFCurrentRoom(hum, rspMsg.Room, this.observerTeam) hum.GetRoom().(*room).fillMFCurrentRoom(hum, rspMsg.Room)
hum.SendMsg(rspMsg) hum.SendMsg(rspMsg)
return return
} }
@ -201,24 +200,23 @@ func (this *roomMgr) CMEnterObserver(hdr *f5.MsgHdr, msg *cs.CMEnterObserver) {
return return
} }
if !roomPtr.isOwner(hum) { memberPtr := roomPtr.getMember(hum.GetAccountId())
if memberPtr == nil || memberPtr.isLeader == 0 {
rspMsg.Errcode = proto.Int32(2) rspMsg.Errcode = proto.Int32(2)
rspMsg.Errmsg = proto.String("not owner") rspMsg.Errmsg = proto.String("not team leader")
hum.SendMsg(&rspMsg) hum.SendMsg(&rspMsg)
return return
} }
if this.observerTeam != nil && this.observerTeam.room != nil { if memberPtr.team.isObserver() {
rspMsg.Errcode = proto.Int32(3)
rspMsg.Errmsg = proto.String("exists observer team")
hum.SendMsg(&rspMsg) hum.SendMsg(&rspMsg)
return roomPtr.notifyRoomInfo(hum)
return;
} }
t := roomPtr.owner.team t := memberPtr.team
delete(roomPtr.teamUuidHash, t.teamUuid) roomPtr.removeTeam(t)
delete(roomPtr.teamIdHash, t.teamId) roomPtr.addObTeam(t)
this.observerTeam = roomPtr.owner.team
hum.SendMsg(&rspMsg) hum.SendMsg(&rspMsg)
roomPtr.notifyRoomInfo(hum) roomPtr.notifyRoomInfo(hum)
@ -229,32 +227,30 @@ func (this *roomMgr) CMLeaveObserver(hdr *f5.MsgHdr, msg *cs.CMLeaveObserver) {
rspMsg := cs.SMLeaveObserver{} rspMsg := cs.SMLeaveObserver{}
roomPtr, ok := hum.GetRoom().(*room) roomPtr, ok := hum.GetRoom().(*room)
if !ok { if !ok || roomPtr == nil {
rspMsg.Errcode = proto.Int32(1) rspMsg.Errcode = proto.Int32(1)
rspMsg.Errmsg = proto.String("room is empty") rspMsg.Errmsg = proto.String("room is empty")
hum.SendMsg(&rspMsg) hum.SendMsg(&rspMsg)
return return
} }
if !roomPtr.isOwner(hum) { memberPtr := roomPtr.getMember(hum.GetAccountId())
if memberPtr == nil || memberPtr.isLeader == 0 {
rspMsg.Errcode = proto.Int32(2) rspMsg.Errcode = proto.Int32(2)
rspMsg.Errmsg = proto.String("not owner") rspMsg.Errmsg = proto.String("not team leader")
hum.SendMsg(&rspMsg) hum.SendMsg(&rspMsg)
return return
} }
if roomPtr.getTeamNum() >= roomPtr.config.maxTeamNum { if !memberPtr.team.isObserver() {
rspMsg.Errcode = proto.Int32(3)
rspMsg.Errmsg = proto.String("teams is full")
hum.SendMsg(&rspMsg) hum.SendMsg(&rspMsg)
return roomPtr.notifyRoomInfo(hum)
return;
} }
t := roomPtr.owner.team t := memberPtr.team
roomPtr.removeObTeam(t)
roomPtr.addTeam(t) roomPtr.addTeam(t)
roomPtr.autoStartCountdown()
this.observerTeam = nil
hum.SendMsg(&rspMsg) hum.SendMsg(&rspMsg)
roomPtr.notifyRoomInfo(hum) roomPtr.notifyRoomInfo(hum)

View File

@ -159,6 +159,10 @@ func (this *team) SaveTeamLeader(teamInfo *TeamInfo) {
} }
} }
func (this *team) isObserver() bool {
return this.room.getObTeamById(this.teamId) != nil
}
func newTeam(room *room, teamId int32, teamUuid string, leader *member) *team { func newTeam(room *room, teamId int32, teamUuid string, leader *member) *team {
t := new(team) t := new(team)
t.init(room, teamId, teamUuid) t.init(room, teamId, teamUuid)