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