1
This commit is contained in:
parent
89f73cc4d9
commit
729058cb84
@ -19,9 +19,13 @@ type RoomMgr interface {
|
||||
}
|
||||
|
||||
type Player interface {
|
||||
GetAccountId() string
|
||||
GetRoom() Room
|
||||
SetRoom(Room)
|
||||
GetAccountId() string
|
||||
GetName() string
|
||||
GetAvatarUrl() string
|
||||
GetHeroId() int32
|
||||
GetPing() int32
|
||||
SendMsg(rspMsg proto.Message)
|
||||
}
|
||||
|
||||
|
@ -28,3 +28,5 @@ const (
|
||||
)
|
||||
|
||||
const SEARCH_ROOM_PAGE_SIZE = 20
|
||||
const ROOM_MAX_PLAYER_NUM = 40
|
||||
const ROOM_MAX_TEAM_NUM = 10
|
||||
|
@ -13,6 +13,7 @@ type player struct {
|
||||
socket f5.WspCliConn
|
||||
accountId string
|
||||
sessionId string
|
||||
ping int32
|
||||
room common.Room
|
||||
}
|
||||
|
||||
@ -44,3 +45,20 @@ func (this *player) onOffline(){
|
||||
this.room.OnPlayerOffline(this)
|
||||
}
|
||||
}
|
||||
|
||||
func (this *player) GetName() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
|
||||
func (this *player) GetAvatarUrl() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (this *player) GetHeroId() int32 {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (this *player) GetPing() int32 {
|
||||
return this.ping
|
||||
}
|
||||
|
@ -193,13 +193,13 @@ message SMCreateRoom
|
||||
//获取房间列表
|
||||
message CMSearchRoom
|
||||
{
|
||||
optional int32 page = 1; //第几页
|
||||
optional int64 since_id = 1; //为0时表示从第一条数据开始
|
||||
optional int32 room_id = 2; //房间id
|
||||
}
|
||||
|
||||
message SMSearchRoom
|
||||
{
|
||||
optional MFPagination Pagination = 1; //分页信息
|
||||
optional int64 since_id = 1; //客户端需缓存
|
||||
repeated MFRoom rows = 2; //数据
|
||||
}
|
||||
|
||||
|
21
server/hallserver/room/member.go
Normal file
21
server/hallserver/room/member.go
Normal file
@ -0,0 +1,21 @@
|
||||
package room
|
||||
|
||||
import (
|
||||
"cs"
|
||||
"main/common"
|
||||
"github.com/golang/protobuf/proto"
|
||||
)
|
||||
|
||||
type member struct {
|
||||
joinTime int64
|
||||
state int32
|
||||
hum common.Player
|
||||
}
|
||||
|
||||
func (this *member) fillMFMember(pb *cs.MFMember) {
|
||||
pb.AccountId = proto.String(this.hum.GetAccountId())
|
||||
pb.Name = proto.String(this.hum.GetName())
|
||||
pb.AvatarUrl = proto.String(this.hum.GetAvatarUrl())
|
||||
pb.State = proto.Int32(this.state)
|
||||
pb.Ping = proto.Int32(this.hum.GetPing())
|
||||
}
|
@ -2,16 +2,16 @@ package room
|
||||
|
||||
import (
|
||||
"cs"
|
||||
"q5"
|
||||
"f5"
|
||||
"main/common"
|
||||
"main/constant"
|
||||
"github.com/golang/protobuf/proto"
|
||||
)
|
||||
|
||||
type member struct {
|
||||
joinTime int64
|
||||
hum common.Player
|
||||
}
|
||||
|
||||
type roomConfg struct {
|
||||
mapId int32
|
||||
zoneId int32
|
||||
passwd string
|
||||
}
|
||||
|
||||
@ -19,6 +19,7 @@ type room struct {
|
||||
cs.MsgHandlerImpl
|
||||
roomId string
|
||||
roomIdx int64
|
||||
entry q5.ListHead
|
||||
config roomConfg
|
||||
owner *member
|
||||
members map[string]*member
|
||||
@ -27,6 +28,7 @@ type room struct {
|
||||
func (this *room) init(roomId string, roomIdx int64, owner common.Player, passwd string) {
|
||||
this.roomId = roomId
|
||||
this.roomIdx = roomIdx
|
||||
this.entry.Init(this)
|
||||
this.config.passwd = passwd
|
||||
this.owner = newMember(owner)
|
||||
this.members = map[string]*member{
|
||||
@ -65,6 +67,21 @@ func (this *room) join(member common.Player, passwd string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (this *room) fillMFRoom(pb *cs.MFRoom) {
|
||||
pb.RoomId = proto.String(this.roomId)
|
||||
pb.MapId = proto.Int32(this.config.mapId)
|
||||
pb.ZoneId = proto.Int32(this.config.zoneId)
|
||||
if this.config.passwd != "" {
|
||||
pb.HasPasswd = proto.Int32(1)
|
||||
}
|
||||
pb.PlayerNum = proto.Int32(int32(len(this.members)))
|
||||
pb.PlayerMaxNum = proto.Int32(constant.ROOM_MAX_PLAYER_NUM)
|
||||
//pb.TeamNum = proto.Int32(40)
|
||||
pb.TeamMaxNum = proto.Int32(constant.ROOM_MAX_TEAM_NUM)
|
||||
pb.Owner = new(cs.MFMember)
|
||||
this.owner.fillMFMember(pb.Owner)
|
||||
}
|
||||
|
||||
func (this *room) OnPlayerOffline(hum common.Player) {
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,6 @@ import (
|
||||
"cs"
|
||||
"q5"
|
||||
"f5"
|
||||
"math"
|
||||
"main/constant"
|
||||
"main/common"
|
||||
"github.com/golang/protobuf/proto"
|
||||
@ -16,12 +15,12 @@ type roomMgr struct {
|
||||
currRoomId int32
|
||||
currRoomIdx int64
|
||||
idHash map[string]*room
|
||||
searchRoomIdxHash map[string]int64
|
||||
roomList q5.ListHead
|
||||
}
|
||||
|
||||
func (this *roomMgr) Init() {
|
||||
this.idHash = make(map[string]*room)
|
||||
this.searchRoomIdxHash = make(map[string]int64)
|
||||
this.roomList.Init(nil)
|
||||
this.currRoomId = 10000
|
||||
this.currRoomIdx = 10000
|
||||
}
|
||||
@ -37,14 +36,6 @@ func (this *roomMgr) getRoom(roomId string) *room {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this *roomMgr) getSearchRoomLastIdx(accountId string) int64 {
|
||||
idx, ok := this.searchRoomIdxHash[accountId]
|
||||
if ok {
|
||||
return idx
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (this *roomMgr) ProcessCMMsg(handler *cs.CsNetMsgHandler, hdr *f5.MsgHdr) {
|
||||
switch handler.HandlerId {
|
||||
case constant.ROOM_MGR_HANDLER_ID:
|
||||
@ -73,6 +64,7 @@ func (this *roomMgr) CMCreateRoom(hdr *f5.MsgHdr, msg *cs.CMCreateRoom) {
|
||||
m := new(room)
|
||||
m.init(q5.ToString(this.genRoomId()), this.genRoomIdx(), hum, msg.GetPasswd())
|
||||
this.idHash[m.roomId] = m
|
||||
|
||||
hum.SendMsg(rspMsg)
|
||||
}
|
||||
|
||||
@ -104,20 +96,22 @@ func (this *roomMgr) CMJoinRoom(hdr *f5.MsgHdr, msg *cs.CMJoinRoom) {
|
||||
func (this *roomMgr) CMSearchRoom(hdr *f5.MsgHdr, msg *cs.CMSearchRoom) {
|
||||
hum := hdr.Context.(common.Player)
|
||||
rspMsg := cs.SMSearchRoom{}
|
||||
rspMsg.Pagination = &cs.MFPagination{}
|
||||
lastIdx := this.getSearchRoomLastIdx(hum.GetAccountId())
|
||||
if msg.GetPage() <= 0 {
|
||||
lastIdx = 0
|
||||
}
|
||||
for _, room := range(this.idHash) {
|
||||
if room.roomIdx > lastIdx {
|
||||
|
||||
}
|
||||
}
|
||||
this.searchRoomIdxHash[hum.GetAccountId()] = lastIdx
|
||||
rspMsg.Pagination.Total = proto.Int32((int32)(len(this.idHash)))
|
||||
rspMsg.Pagination.TotalPage = proto.Int32((int32(math.Ceil(
|
||||
(float64)(len(this.idHash)) / constant.SEARCH_ROOM_PAGE_SIZE))))
|
||||
rspMsg.Rows = make([]*cs.MFRoom, constant.SEARCH_ROOM_PAGE_SIZE, constant.SEARCH_ROOM_PAGE_SIZE)
|
||||
sinceId := msg.GetSinceId()
|
||||
this.roomList.ForEach_r(
|
||||
func (data interface{}) bool {
|
||||
r := data.(room)
|
||||
if r.roomIdx > sinceId {
|
||||
pb := new(cs.MFRoom)
|
||||
r.fillMFRoom(pb)
|
||||
rspMsg.Rows = append(rspMsg.Rows, pb)
|
||||
sinceId = r.roomIdx
|
||||
if len(rspMsg.Rows) >= constant.SEARCH_ROOM_PAGE_SIZE {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
})
|
||||
hum.SendMsg(&rspMsg)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user