1
This commit is contained in:
parent
b97cd2c799
commit
4b5d1da32c
@ -126,6 +126,7 @@ message MFTeam
|
||||
optional int32 team_id = 1; //队伍id
|
||||
optional string team_uuid = 2; //队伍唯一id
|
||||
repeated MFMember members = 3; //成员列表
|
||||
optional int32 sort_idx = 4 [default = 0]; //排序索引
|
||||
}
|
||||
|
||||
//自己所在房间信息
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
"main/constant"
|
||||
"mt"
|
||||
"q5"
|
||||
"sort"
|
||||
)
|
||||
|
||||
type room struct {
|
||||
@ -71,12 +72,32 @@ func (this *room) addMember(m *member) {
|
||||
}
|
||||
|
||||
func (this *room) addTeam(t *team) {
|
||||
this.curSortIdx += 1
|
||||
t.sortIdx = this.curSortIdx
|
||||
t.sortIdx = this.genSortIdx()
|
||||
this.teamUuidHash[t.teamUuid] = 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 {
|
||||
m, ok := this.members[accountId]
|
||||
if ok {
|
||||
@ -101,6 +122,22 @@ func (this *room) getTeamById(teamId int32) *team {
|
||||
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 {
|
||||
return int32(len(this.teamUuidHash))
|
||||
}
|
||||
@ -190,7 +227,7 @@ func (this *room) fillMFRoom(hum common.Player, pb *cs.MFRoom) {
|
||||
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.MapId = proto.Int32(this.config.mapId)
|
||||
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 {
|
||||
pbT := &cs.MFTeam{}
|
||||
t.fillMFTeam(pbT)
|
||||
pbT.SortIdx = proto.Int32(t.sortIdx)
|
||||
q5.AppendSlice(&pb.TeamList, pbT)
|
||||
}
|
||||
|
||||
if observerTeam != nil && observerTeam.room != nil {
|
||||
pbT2 := &cs.MFTeam{}
|
||||
observerTeam.fillMFTeam(pbT2)
|
||||
q5.AppendSlice(&pb.ObserverTeamList, pbT2)
|
||||
sort.Slice(pb.TeamList, func(i, j int) bool {
|
||||
return *pb.TeamList[i].SortIdx < *pb.TeamList[j].SortIdx
|
||||
})
|
||||
for _, t := range this.obTeamUuidHash {
|
||||
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) {
|
||||
@ -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(
|
||||
q5.Md5Str(q5.EncodeJson(&startInfo) + "520d8eAbB(8cf1^#$^&!@d833a42c820432PDAFE^^)") + "|" +
|
||||
q5.EncodeJson(&startInfo))
|
||||
|
@ -16,7 +16,6 @@ type roomMgr struct {
|
||||
currRoomId int32
|
||||
idHash map[string]*room
|
||||
roomList q5.ListHead
|
||||
observerTeam *team
|
||||
}
|
||||
|
||||
func (this *roomMgr) Init() {
|
||||
@ -170,7 +169,7 @@ func (this *roomMgr) CMGetCurrentRoom(hdr *f5.MsgHdr, msg *cs.CMGetCurrentRoom)
|
||||
rspMsg := &cs.SMGetCurrentRoom{}
|
||||
if hum.GetRoom() != nil && hum.GetRoom().GetRoomState() == ROOM_INIT_STATE {
|
||||
rspMsg.Room = new(cs.MFCurrentRoom)
|
||||
hum.GetRoom().(*room).fillMFCurrentRoom(hum, rspMsg.Room, this.observerTeam)
|
||||
hum.GetRoom().(*room).fillMFCurrentRoom(hum, rspMsg.Room)
|
||||
hum.SendMsg(rspMsg)
|
||||
return
|
||||
}
|
||||
@ -201,24 +200,23 @@ func (this *roomMgr) CMEnterObserver(hdr *f5.MsgHdr, msg *cs.CMEnterObserver) {
|
||||
return
|
||||
}
|
||||
|
||||
if !roomPtr.isOwner(hum) {
|
||||
memberPtr := roomPtr.getMember(hum.GetAccountId())
|
||||
if memberPtr == nil || memberPtr.isLeader == 0 {
|
||||
rspMsg.Errcode = proto.Int32(2)
|
||||
rspMsg.Errmsg = proto.String("not owner")
|
||||
rspMsg.Errmsg = proto.String("not team leader")
|
||||
hum.SendMsg(&rspMsg)
|
||||
return
|
||||
}
|
||||
|
||||
if this.observerTeam != nil && this.observerTeam.room != nil {
|
||||
rspMsg.Errcode = proto.Int32(3)
|
||||
rspMsg.Errmsg = proto.String("exists observer team")
|
||||
if memberPtr.team.isObserver() {
|
||||
hum.SendMsg(&rspMsg)
|
||||
return
|
||||
roomPtr.notifyRoomInfo(hum)
|
||||
return;
|
||||
}
|
||||
|
||||
t := roomPtr.owner.team
|
||||
delete(roomPtr.teamUuidHash, t.teamUuid)
|
||||
delete(roomPtr.teamIdHash, t.teamId)
|
||||
this.observerTeam = roomPtr.owner.team
|
||||
t := memberPtr.team
|
||||
roomPtr.removeTeam(t)
|
||||
roomPtr.addObTeam(t)
|
||||
|
||||
hum.SendMsg(&rspMsg)
|
||||
roomPtr.notifyRoomInfo(hum)
|
||||
@ -229,32 +227,30 @@ func (this *roomMgr) CMLeaveObserver(hdr *f5.MsgHdr, msg *cs.CMLeaveObserver) {
|
||||
rspMsg := cs.SMLeaveObserver{}
|
||||
|
||||
roomPtr, ok := hum.GetRoom().(*room)
|
||||
if !ok {
|
||||
if !ok || roomPtr == nil {
|
||||
rspMsg.Errcode = proto.Int32(1)
|
||||
rspMsg.Errmsg = proto.String("room is empty")
|
||||
hum.SendMsg(&rspMsg)
|
||||
return
|
||||
}
|
||||
|
||||
if !roomPtr.isOwner(hum) {
|
||||
memberPtr := roomPtr.getMember(hum.GetAccountId())
|
||||
if memberPtr == nil || memberPtr.isLeader == 0 {
|
||||
rspMsg.Errcode = proto.Int32(2)
|
||||
rspMsg.Errmsg = proto.String("not owner")
|
||||
rspMsg.Errmsg = proto.String("not team leader")
|
||||
hum.SendMsg(&rspMsg)
|
||||
return
|
||||
}
|
||||
|
||||
if roomPtr.getTeamNum() >= roomPtr.config.maxTeamNum {
|
||||
rspMsg.Errcode = proto.Int32(3)
|
||||
rspMsg.Errmsg = proto.String("teams is full")
|
||||
if !memberPtr.team.isObserver() {
|
||||
hum.SendMsg(&rspMsg)
|
||||
return
|
||||
roomPtr.notifyRoomInfo(hum)
|
||||
return;
|
||||
}
|
||||
|
||||
t := roomPtr.owner.team
|
||||
t := memberPtr.team
|
||||
roomPtr.removeObTeam(t)
|
||||
roomPtr.addTeam(t)
|
||||
roomPtr.autoStartCountdown()
|
||||
|
||||
this.observerTeam = nil
|
||||
|
||||
hum.SendMsg(&rspMsg)
|
||||
roomPtr.notifyRoomInfo(hum)
|
||||
|
@ -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 {
|
||||
t := new(team)
|
||||
t.init(room, teamId, teamUuid)
|
||||
|
Loading…
x
Reference in New Issue
Block a user