save
This commit is contained in:
parent
f09d6d9b03
commit
6e0ccdf125
@ -102,6 +102,7 @@ message MFRoom
|
||||
optional int32 player_num = 7; //玩家数
|
||||
optional int32 team_max_num = 8; //最大队伍数
|
||||
optional int32 player_max_num = 9; //最大玩家数
|
||||
optional int32 my_team_id = 10; //我的队伍id
|
||||
|
||||
optional MFMember owner = 20; //房主
|
||||
}
|
||||
@ -115,6 +116,7 @@ message MFMember
|
||||
optional string hero_id = 4; //英雄id
|
||||
optional string head_frame = 5; //头像框
|
||||
optional int32 state = 9; //0:准备 1:已准备
|
||||
optional int32 is_leader = 10; // 是否队长
|
||||
optional int32 ping = 20; //ping值(单位毫秒)
|
||||
}
|
||||
|
||||
@ -137,6 +139,7 @@ message MFCurrentRoom
|
||||
optional int32 player_num = 6; //玩家数
|
||||
optional int32 team_max_num = 7; //最大队伍数
|
||||
optional int32 player_max_num = 8; //最大玩家数
|
||||
optional int32 my_team_id = 9; //我的队伍id
|
||||
|
||||
optional MFMember owner = 20; //房主
|
||||
|
||||
@ -190,6 +193,7 @@ message CMCreateRoom
|
||||
optional int32 node_id = 3; //节点id
|
||||
optional string passwd = 4; //密码,空:无密码
|
||||
optional string team_uuid = 5; //队伍唯一id
|
||||
optional string team_info = 6; //队伍信息 json:{}
|
||||
}
|
||||
|
||||
message SMCreateRoom
|
||||
@ -351,6 +355,7 @@ message SMRoomGameStartNotify
|
||||
optional int32 node_id = 2; //节点id
|
||||
optional string team_uuid = 3; //CMJoin战斗服时用
|
||||
optional string custom_room_payload = 4; //自定义房间透传数据
|
||||
optional int32 map_id = 5; //地图id
|
||||
}
|
||||
|
||||
//进入观察队伍
|
||||
|
@ -21,4 +21,4 @@ const (
|
||||
ROOM_DISBAND_NO_NEXT_OWNER_REASON
|
||||
)
|
||||
|
||||
const ROOM_MIN_START_TEAM_NUM = 2
|
||||
const ROOM_MIN_START_TEAM_NUM = 1
|
||||
|
@ -16,6 +16,7 @@ type member struct {
|
||||
teamEntry q5.ListHead
|
||||
team *team
|
||||
hum common.Player
|
||||
isLeader int32
|
||||
}
|
||||
|
||||
func (this *member) init(room *room, hum common.Player) {
|
||||
@ -35,6 +36,10 @@ func (this *member) unInit() {
|
||||
this.team = nil
|
||||
}
|
||||
|
||||
func (this *member) setIsLeader() {
|
||||
this.isLeader = 1
|
||||
}
|
||||
|
||||
func (this *member) fillMFMember(pb *cs.MFMember) {
|
||||
pb.AccountId = proto.String(this.hum.GetAccountId())
|
||||
pb.Name = proto.String(this.hum.GetName())
|
||||
@ -42,6 +47,7 @@ func (this *member) fillMFMember(pb *cs.MFMember) {
|
||||
pb.HeroId = proto.String(this.hum.GetHeroId())
|
||||
pb.HeadFrame = proto.String(this.hum.GetHeadFrame())
|
||||
pb.State = proto.Int32(this.state)
|
||||
pb.IsLeader = proto.Int32(this.isLeader)
|
||||
pb.Ping = proto.Int32(this.hum.GetPing())
|
||||
}
|
||||
|
||||
|
@ -141,7 +141,7 @@ func (this *room) join(hum common.Player, msg *cs.CMJoinRoom) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (this *room) fillMFRoom(pb *cs.MFRoom) {
|
||||
func (this *room) fillMFRoom(hum common.Player, pb *cs.MFRoom) {
|
||||
pb.RoomId = proto.String(this.roomId)
|
||||
pb.MapId = proto.Int32(this.config.mapId)
|
||||
pb.ZoneId = proto.Int32(this.config.zoneId)
|
||||
@ -152,11 +152,17 @@ func (this *room) fillMFRoom(pb *cs.MFRoom) {
|
||||
pb.PlayerMaxNum = proto.Int32(constant.ROOM_MAX_PLAYER_NUM)
|
||||
pb.TeamNum = proto.Int32(int32(len(this.teamUuidHash)))
|
||||
pb.TeamMaxNum = proto.Int32(constant.ROOM_MAX_TEAM_NUM)
|
||||
|
||||
m := this.getMember(hum.GetAccountId())
|
||||
if m != nil {
|
||||
pb.MyTeamId = proto.Int32(m.team.teamId)
|
||||
}
|
||||
|
||||
pb.Owner = new(cs.MFMember)
|
||||
this.owner.fillMFMember(pb.Owner)
|
||||
}
|
||||
|
||||
func (this *room) fillMFCurrentRoom(pb *cs.MFCurrentRoom) {
|
||||
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)
|
||||
@ -167,6 +173,12 @@ func (this *room) fillMFCurrentRoom(pb *cs.MFCurrentRoom) {
|
||||
pb.PlayerMaxNum = proto.Int32(constant.ROOM_MAX_PLAYER_NUM)
|
||||
pb.TeamNum = proto.Int32(int32(len(this.teamUuidHash)))
|
||||
pb.TeamMaxNum = proto.Int32(constant.ROOM_MAX_TEAM_NUM)
|
||||
|
||||
m := this.getMember(hum.GetAccountId())
|
||||
if m != nil {
|
||||
pb.MyTeamId = proto.Int32(m.team.teamId)
|
||||
}
|
||||
|
||||
pb.Owner = new(cs.MFMember)
|
||||
this.owner.fillMFMember(pb.Owner)
|
||||
q5.NewSlice(&pb.TeamList, 0, 10)
|
||||
@ -218,7 +230,7 @@ func (this *room) CMLeaveRoom(hdr *f5.MsgHdr, msg *cs.CMLeaveRoom) {
|
||||
q5.NewSlice(¬ifyMsg.AccountIds, 0, 1)
|
||||
q5.AppendSlice(¬ifyMsg.AccountIds, m.hum.GetAccountId())
|
||||
this.broadcastMsg(notifyMsg)
|
||||
this.notifyRoomInfo()
|
||||
this.notifyRoomInfo(hum)
|
||||
}
|
||||
}
|
||||
|
||||
@ -234,7 +246,7 @@ func (this *room) CMModifyRoom(hdr *f5.MsgHdr, msg *cs.CMModifyRoom) {
|
||||
}
|
||||
}
|
||||
hum.SendMsg(&rspMsg)
|
||||
this.notifyRoomInfo()
|
||||
this.notifyRoomInfo(hum)
|
||||
}
|
||||
|
||||
func (this *room) CMStartGame(hdr *f5.MsgHdr, msg *cs.CMStartGame) {
|
||||
@ -270,7 +282,7 @@ func (this *room) CMKickoutTeam(hdr *f5.MsgHdr, msg *cs.CMKickoutTeam) {
|
||||
notifyMsg := &cs.SMRoomKickoutNotify{}
|
||||
this.broadcastMsg(notifyMsg)
|
||||
t.unInit()
|
||||
this.notifyRoomInfo()
|
||||
this.notifyRoomInfo(hum)
|
||||
}
|
||||
}
|
||||
|
||||
@ -283,7 +295,7 @@ func (this *room) CMKickoutMember(hdr *f5.MsgHdr, msg *cs.CMKickoutMember) {
|
||||
notifyMsg.AccountIds = append(notifyMsg.AccountIds, msg.GetTargetId())
|
||||
this.broadcastMsg(notifyMsg)
|
||||
this.removeMember(target.hum.GetAccountId())
|
||||
this.notifyRoomInfo()
|
||||
this.notifyRoomInfo(hum)
|
||||
}
|
||||
}
|
||||
|
||||
@ -395,6 +407,7 @@ func (this *room) genGameStartNotifyMsg() {
|
||||
this.gameStartNotifyMsg = &cs.SMRoomGameStartNotify{}
|
||||
this.gameStartNotifyMsg.ZoneId = proto.Int32(this.config.zoneId)
|
||||
this.gameStartNotifyMsg.NodeId = proto.Int32(this.config.nodeId)
|
||||
this.gameStartNotifyMsg.MapId = proto.Int32(this.config.mapId)
|
||||
this.gameStartNotifyMsg.TeamUuid = proto.String(q5.ToString(this.roomIdx))
|
||||
startInfo := struct {
|
||||
ZoneId int32 `json:"zone_id"`
|
||||
@ -497,10 +510,10 @@ func (this *room) removeMember(accountId string) {
|
||||
}
|
||||
}
|
||||
|
||||
func (this *room) notifyRoomInfo() {
|
||||
func (this *room) notifyRoomInfo(hum common.Player) {
|
||||
notifyMsg := &cs.SMRoomChangeNotify{}
|
||||
notifyMsg.Room = new(cs.MFRoom)
|
||||
this.fillMFRoom(notifyMsg.Room)
|
||||
this.fillMFRoom(hum, notifyMsg.Room)
|
||||
this.broadcastMsg(notifyMsg)
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@ package room
|
||||
|
||||
import (
|
||||
"cs"
|
||||
"encoding/json"
|
||||
"f5"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"main/common"
|
||||
@ -10,6 +11,11 @@ import (
|
||||
"q5"
|
||||
)
|
||||
|
||||
type TeamInfo struct {
|
||||
TeamUUID string `json:"team_uuid"`
|
||||
MemberList []memberInfo `json:"member_list"`
|
||||
}
|
||||
|
||||
type roomMgr struct {
|
||||
cs.MsgHandlerImpl
|
||||
currRoomId int32
|
||||
@ -73,8 +79,16 @@ func (this *roomMgr) CMCreateRoom(hdr *f5.MsgHdr, msg *cs.CMCreateRoom) {
|
||||
m.init(q5.ToString(this.genRoomId()), this.genRoomIdx(), hum, msg)
|
||||
this.idHash[m.roomId] = m
|
||||
this.roomList.AddTail(&m.entry)
|
||||
|
||||
rspMsg.RoomId = proto.String(m.roomId)
|
||||
|
||||
teamInfo := &TeamInfo{}
|
||||
err := json.Unmarshal([]byte(msg.GetTeamInfo()), teamInfo)
|
||||
if err != nil {
|
||||
f5.GetSysLog().Info(err.Error())
|
||||
} else {
|
||||
this.SaveTeamLeader(m, msg.GetTeamUuid(), teamInfo)
|
||||
}
|
||||
|
||||
hum.SendMsg(rspMsg)
|
||||
}
|
||||
|
||||
@ -123,7 +137,7 @@ func (this *roomMgr) CMSearchRoom(hdr *f5.MsgHdr, msg *cs.CMSearchRoom) {
|
||||
return true
|
||||
}
|
||||
pb := new(cs.MFRoom)
|
||||
r.fillMFRoom(pb)
|
||||
r.fillMFRoom(hum, pb)
|
||||
rspMsg.Rows = append(rspMsg.Rows, pb)
|
||||
sinceId = r.roomIdx
|
||||
if len(rspMsg.Rows) >= constant.SEARCH_ROOM_PAGE_SIZE {
|
||||
@ -140,7 +154,8 @@ 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(rspMsg.Room)
|
||||
|
||||
hum.GetRoom().(*room).fillMFCurrentRoom(hum, rspMsg.Room)
|
||||
hum.SendMsg(rspMsg)
|
||||
return
|
||||
}
|
||||
@ -149,7 +164,26 @@ func (this *roomMgr) CMGetCurrentRoom(hdr *f5.MsgHdr, msg *cs.CMGetCurrentRoom)
|
||||
|
||||
func (this *roomMgr) RemoveRoomMember(hdr *f5.MsgHdr) {
|
||||
hum := GetPlayerMgr().GetPlayerBySocket(hdr.GetSocket())
|
||||
if roomPtr, ok := hum.GetRoom().(*room); ok {
|
||||
roomPtr.removeMember(hum.GetAccountId())
|
||||
if hum != nil {
|
||||
if roomPtr, ok := hum.GetRoom().(*room); ok {
|
||||
roomPtr.removeMember(hum.GetAccountId())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (this *roomMgr) SaveTeamLeader(r *room, teamUUID string, teamInfo *TeamInfo) {
|
||||
t := r.getTeamByUuid(teamUUID)
|
||||
for _, mInfo := range teamInfo.MemberList {
|
||||
if mInfo.IsLeader == 1 {
|
||||
t.tmpTeamLeader = &memberInfo{
|
||||
AccountID: mInfo.AccountID,
|
||||
Name: mInfo.Name,
|
||||
Avatar: mInfo.Avatar,
|
||||
AvatarFrame: mInfo.AvatarFrame,
|
||||
HeroId: mInfo.HeroId,
|
||||
IsLeader: mInfo.IsLeader,
|
||||
State: mInfo.State,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,11 +6,22 @@ import (
|
||||
"q5"
|
||||
)
|
||||
|
||||
type memberInfo struct {
|
||||
AccountID string `json:"account_id"`
|
||||
Name string `json:"name"`
|
||||
Avatar string `json:"head_id"`
|
||||
AvatarFrame string `json:"head_frame"`
|
||||
HeroId string `json:"hero_id"`
|
||||
IsLeader int32 `json:"is_leader"`
|
||||
State int32 `json:"is_ready"`
|
||||
}
|
||||
|
||||
type team struct {
|
||||
room *room
|
||||
teamId int32
|
||||
teamUuid string
|
||||
members q5.ListHead
|
||||
room *room
|
||||
teamId int32
|
||||
teamUuid string
|
||||
members q5.ListHead
|
||||
tmpTeamLeader *memberInfo
|
||||
}
|
||||
|
||||
func (this *team) init(room *room, teamId int32, teamUuid string) {
|
||||
@ -39,11 +50,44 @@ func (this *team) fillMFTeam(pb *cs.MFTeam) {
|
||||
this.members.ForEach(
|
||||
func(data interface{}) bool {
|
||||
m := data.(*member)
|
||||
if this.tmpTeamLeader != nil && m.hum.GetAccountId() == this.tmpTeamLeader.AccountID {
|
||||
m.isLeader = this.tmpTeamLeader.IsLeader
|
||||
m.state = this.tmpTeamLeader.State
|
||||
this.tmpTeamLeader = nil
|
||||
}
|
||||
|
||||
pbM := &cs.MFMember{}
|
||||
m.fillMFMember(pbM)
|
||||
q5.AppendSlice(&pb.Members, pbM)
|
||||
return true
|
||||
})
|
||||
|
||||
if this.tmpTeamLeader != nil && this.getTeamLeader() == nil {
|
||||
pbM := &cs.MFMember{
|
||||
AccountId: proto.String(this.tmpTeamLeader.AccountID),
|
||||
Name: proto.String(this.tmpTeamLeader.Name),
|
||||
AvatarUrl: proto.String(this.tmpTeamLeader.Avatar),
|
||||
HeroId: proto.String(this.tmpTeamLeader.HeroId),
|
||||
HeadFrame: proto.String(this.tmpTeamLeader.AvatarFrame),
|
||||
State: proto.Int32(this.tmpTeamLeader.State),
|
||||
IsLeader: proto.Int32(this.tmpTeamLeader.IsLeader),
|
||||
}
|
||||
q5.AppendSlice(&pb.Members, pbM)
|
||||
}
|
||||
}
|
||||
|
||||
func (this *team) getTeamLeader() *member {
|
||||
var leader *member = nil
|
||||
this.members.ForEach(
|
||||
func(data interface{}) bool {
|
||||
m := data.(*member)
|
||||
if m.isLeader == 1 {
|
||||
leader = m
|
||||
return true
|
||||
}
|
||||
return false
|
||||
})
|
||||
return leader
|
||||
}
|
||||
|
||||
func (this *team) addMember(m *member) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user