This commit is contained in:
aozhiwei 2023-10-10 15:17:23 +08:00
commit effe90537f
10 changed files with 120 additions and 133 deletions

View File

@ -1,19 +1,19 @@
package app package app
import ( import (
"f5"
"q5"
"mt"
"cs" "cs"
"ss" "f5"
"main/constant" "main/constant"
. "main/global" . "main/global"
"mt"
"q5"
"ss"
) )
type app struct { type app struct {
netMsgQueue q5.Queue netMsgQueue q5.Queue
initCb func() initCb func()
unInitCb func() unInitCb func()
} }
func (this *app) GetPkgName() string { func (this *app) GetPkgName() string {
@ -82,3 +82,7 @@ func (this *app) AddNetMsg(hdr *f5.MsgHdr) {
func (this *app) registerDataSources() { func (this *app) registerDataSources() {
} }
func (this *app) GetHttpListenPort() int32 {
return mt.Table.HallCluster.GetHttpListenPort()
}

View File

@ -4,8 +4,8 @@ import (
"net" "net"
"cs" "cs"
"ss"
"f5" "f5"
"ss"
proto "github.com/golang/protobuf/proto" proto "github.com/golang/protobuf/proto"
) )
@ -42,11 +42,10 @@ type PlayerMgr interface {
type WspListener interface { type WspListener interface {
ProcessSSMMsg(*ss.SsNetMsgHandler, *f5.MsgHdr) ProcessSSMMsg(*ss.SsNetMsgHandler, *f5.MsgHdr)
SendProxyMsg(net.Conn, uint16, proto.Message); SendProxyMsg(net.Conn, uint16, proto.Message)
} }
type HttpListener interface { type HttpListener interface {
} }
type App interface { type App interface {

View File

@ -10,8 +10,8 @@ type httpListener struct {
} }
func (this *httpListener) Init() { func (this *httpListener) Init() {
this.httpServer = new (f5.HttpServer) this.httpServer = new(f5.HttpServer)
this.httpServer.Init("imserver.httplistener", 1000 * 10) this.httpServer.Init("hallserver.httplistener", 1000*10)
this.httpServer.Start(mt.Table.HallCluster.GetHttpListenPort()) this.httpServer.Start(mt.Table.HallCluster.GetHttpListenPort())
} }

View File

@ -1,21 +1,21 @@
package room package room
import ( import (
"q5"
"f5"
"cs" "cs"
"main/common" "f5"
"github.com/golang/protobuf/proto" "github.com/golang/protobuf/proto"
"main/common"
"q5"
) )
type member struct { type member struct {
room *room room *room
joinTime int64 joinTime int64
state int32 state int32
closeGameStartNotify bool closeGameStartNotify bool
teamEntry q5.ListHead teamEntry q5.ListHead
team *team team *team
hum common.Player hum common.Player
} }
func (this *member) init(room *room, hum common.Player) { func (this *member) init(room *room, hum common.Player) {

View File

@ -2,38 +2,38 @@ package room
import ( import (
"cs" "cs"
"q5"
"f5" "f5"
"mt" "github.com/golang/protobuf/proto"
"main/common" "main/common"
"main/constant" "main/constant"
"github.com/golang/protobuf/proto" "mt"
"q5"
) )
type room struct { type room struct {
cs.MsgHandlerImpl cs.MsgHandlerImpl
roomId string roomId string
roomIdx int64 roomIdx int64
entry q5.ListHead entry q5.ListHead
config struct { config struct {
mapId int32 mapId int32
zoneId int32 zoneId int32
nodeId int32 nodeId int32
passwd string passwd string
maxTeamNum int32 maxTeamNum int32
} }
owner *member owner *member
roomState int32 roomState int32
startTime int64 startTime int64
startReason int32 startReason int32
disbandTime int64 disbandTime int64
disbandReason int32 disbandReason int32
teamUuidHash map[string]*team teamUuidHash map[string]*team
teamIdHash map[int32]*team teamIdHash map[int32]*team
members map[string]*member members map[string]*member
startTimer *f5.TimerWp startTimer *f5.TimerWp
delayDeleteTimer *f5.TimerWp delayDeleteTimer *f5.TimerWp
attacher *f5.TimerAttacher attacher *f5.TimerAttacher
gameStartNotifyMsg *cs.SMRoomGameStartNotify gameStartNotifyMsg *cs.SMRoomGameStartNotify
} }
@ -54,8 +54,8 @@ func (this *room) init(roomId string,
} }
func (this *room) unInit() { func (this *room) unInit() {
for ; len(this.teamUuidHash) > 0; { for len(this.teamUuidHash) > 0 {
for _, t := range(this.teamUuidHash) { for _, t := range this.teamUuidHash {
t.unInit() t.unInit()
break break
} }
@ -170,7 +170,7 @@ func (this *room) fillMFCurrentRoom(pb *cs.MFCurrentRoom) {
pb.Owner = new(cs.MFMember) pb.Owner = new(cs.MFMember)
this.owner.fillMFMember(pb.Owner) this.owner.fillMFMember(pb.Owner)
q5.NewSlice(&pb.TeamList, 0, 10) q5.NewSlice(&pb.TeamList, 0, 10)
for _, t := range(this.teamUuidHash) { for _, t := range this.teamUuidHash {
pbT := &cs.MFTeam{} pbT := &cs.MFTeam{}
t.fillMFTeam(pbT) t.fillMFTeam(pbT)
q5.AppendSlice(&pb.TeamList, pbT) q5.AppendSlice(&pb.TeamList, pbT)
@ -266,7 +266,7 @@ func (this *room) CMKickoutTeam(hdr *f5.MsgHdr, msg *cs.CMKickoutTeam) {
hum := hdr.Context.(common.Player) hum := hdr.Context.(common.Player)
m := this.getMember(hum.GetAccountId()) m := this.getMember(hum.GetAccountId())
t := this.getTeamByUuid(msg.GetTeamUuid()) t := this.getTeamByUuid(msg.GetTeamUuid())
if m == this.owner && t != nil && t != m.team && this.roomState == ROOM_INIT_STATE{ if m == this.owner && t != nil && t != m.team && this.roomState == ROOM_INIT_STATE {
notifyMsg := &cs.SMRoomKickoutNotify{} notifyMsg := &cs.SMRoomKickoutNotify{}
this.broadcastMsg(notifyMsg) this.broadcastMsg(notifyMsg)
t.unInit() t.unInit()
@ -296,7 +296,7 @@ func (this *room) CMCloseNotify(hdr *f5.MsgHdr, msg *cs.CMCloseNotify) {
} }
func (this *room) broadcastMsg(msg proto.Message) { func (this *room) broadcastMsg(msg proto.Message) {
for _, m := range(this.members) { for _, m := range this.members {
if m.hum.GetRoom() == this { if m.hum.GetRoom() == this {
m.hum.SendMsg(msg) m.hum.SendMsg(msg)
} }
@ -324,7 +324,7 @@ func (this *room) doDisband(reason int32) {
notifyMsg := &cs.SMRoomDisbandNotify{} notifyMsg := &cs.SMRoomDisbandNotify{}
notifyMsg.RoomId = proto.String(this.roomId) notifyMsg.RoomId = proto.String(this.roomId)
notifyMsg.Reason = proto.Int32(reason) notifyMsg.Reason = proto.Int32(reason)
for _, m := range(this.members) { for _, m := range this.members {
if m.hum.GetRoom() == this { if m.hum.GetRoom() == this {
m.hum.SendMsg(notifyMsg) m.hum.SendMsg(notifyMsg)
} }
@ -338,9 +338,9 @@ func (this *room) doStart(reason int32) {
this.startReason = ROOM_AUTO_START_TYPE this.startReason = ROOM_AUTO_START_TYPE
f5.GetTimer().SetIntervalExWp( f5.GetTimer().SetIntervalExWp(
1000, 1000,
func (e int32, args *q5.Args) { func(e int32, args *q5.Args) {
if e == q5.TIMER_EXEC_EVENT { if e == q5.TIMER_EXEC_EVENT {
if f5.GetApp().GetNowSeconds() - this.startTime < if f5.GetApp().GetNowSeconds()-this.startTime <
int64(mt.Table.Config.Get().GetGameStartNotifyTime()) { int64(mt.Table.Config.Get().GetGameStartNotifyTime()) {
this.notifyGameStart() this.notifyGameStart()
} }
@ -362,7 +362,7 @@ func (this *room) notifyGameStart() {
if this.gameStartNotifyMsg == nil { if this.gameStartNotifyMsg == nil {
this.genGameStartNotifyMsg() this.genGameStartNotifyMsg()
} }
for _, m := range(this.members) { for _, m := range this.members {
if m.state == MEMBER_READY_STATE && if m.state == MEMBER_READY_STATE &&
m.hum.GetRoom() == this && m.hum.GetRoom() == this &&
!m.closeGameStartNotify { !m.closeGameStartNotify {
@ -372,52 +372,54 @@ func (this *room) notifyGameStart() {
} }
func (this *room) genGameStartNotifyMsg() { func (this *room) genGameStartNotifyMsg() {
if this.gameStartNotifyMsg == nil { if this.gameStartNotifyMsg != nil {
this.gameStartNotifyMsg = &cs.SMRoomGameStartNotify{} return
this.gameStartNotifyMsg.ZoneId = proto.Int32(this.config.zoneId)
this.gameStartNotifyMsg.NodeId = proto.Int32(this.config.nodeId)
this.gameStartNotifyMsg.TeamUuid = proto.String(q5.ToString(this.roomIdx))
startInfo := struct {
ZoneId int32 `json:"zone_id"`
NodeId int32 `json:"node_id"`
RoomUuid string `json:"room_uuid"`
StartTime int32 `json:"start_time"`
TeamList [] struct {
TeamUuid string `json:"team_uuid"`
Members [] struct {
AccountId string `json:"account_id"`
} `json:"members"`
} `json:"team_list"`
}{
ZoneId: this.config.zoneId,
NodeId: this.config.nodeId,
RoomUuid: q5.ToString(this.roomIdx),
StartTime: int32(this.startTime),
}
q5.NewSlice(&startInfo.TeamList, 0, 10)
for _, t := range(this.teamUuidHash) {
if t.hasAlreadMember() {
ele := q5.NewSliceElement(&startInfo.TeamList)
ele.TeamUuid = t.teamUuid
q5.NewSlice(&ele.Members, 0, 4)
t.members.ForEach(
func (data interface{}) bool {
m := data.(*member)
if m.state == MEMBER_READY_STATE {
ele2 := q5.NewSliceElement(&ele.Members)
ele2.AccountId = m.hum.GetAccountId()
}
return true
})
}
}
this.gameStartNotifyMsg.CustomRoomPayload = proto.String(q5.EncodeJson(&startInfo))
} }
this.gameStartNotifyMsg = &cs.SMRoomGameStartNotify{}
this.gameStartNotifyMsg.ZoneId = proto.Int32(this.config.zoneId)
this.gameStartNotifyMsg.NodeId = proto.Int32(this.config.nodeId)
this.gameStartNotifyMsg.TeamUuid = proto.String(q5.ToString(this.roomIdx))
startInfo := struct {
ZoneId int32 `json:"zone_id"`
NodeId int32 `json:"node_id"`
RoomUuid string `json:"room_uuid"`
StartTime int32 `json:"start_time"`
TeamList []struct {
TeamUuid string `json:"team_uuid"`
Members []struct {
AccountId string `json:"account_id"`
} `json:"members"`
} `json:"team_list"`
}{
ZoneId: this.config.zoneId,
NodeId: this.config.nodeId,
RoomUuid: q5.ToString(this.roomIdx),
StartTime: int32(this.startTime),
}
q5.NewSlice(&startInfo.TeamList, 0, 10)
for _, t := range this.teamUuidHash {
if t.hasAlreadMember() {
ele := q5.NewSliceElement(&startInfo.TeamList)
ele.TeamUuid = t.teamUuid
q5.NewSlice(&ele.Members, 0, 4)
t.members.ForEach(
func(data interface{}) bool {
m := data.(*member)
if m.state == MEMBER_READY_STATE {
ele2 := q5.NewSliceElement(&ele.Members)
ele2.AccountId = m.hum.GetAccountId()
}
return true
})
}
}
this.gameStartNotifyMsg.CustomRoomPayload = proto.String(q5.EncodeJson(&startInfo))
} }
func (this *room) canStart() bool { func (this *room) canStart() bool {
alreadyNum := 0 alreadyNum := 0
for _, t := range(this.teamUuidHash) { for _, t := range this.teamUuidHash {
if t.hasAlreadMember() { if t.hasAlreadMember() {
alreadyNum++ alreadyNum++
} }
@ -491,8 +493,8 @@ func (this *room) delayDeleteRoom() {
panic("errror dealyDeleteRoom") panic("errror dealyDeleteRoom")
} }
this.delayDeleteTimer = f5.GetTimer().SetTimeoutExWp( this.delayDeleteTimer = f5.GetTimer().SetTimeoutExWp(
1000 * mt.Table.Config.Get().GetDelayDeleteTime(), 1000*mt.Table.Config.Get().GetDelayDeleteTime(),
func (e int32, args *q5.Args) { func(e int32, args *q5.Args) {
if e == q5.TIMER_EXEC_EVENT { if e == q5.TIMER_EXEC_EVENT {
this.unInit() this.unInit()
} }
@ -508,8 +510,8 @@ func newRoom() *room {
r.entry.Init(r) r.entry.Init(r)
r.attacher = f5.GetTimer().NewTimerAttacher() r.attacher = f5.GetTimer().NewTimerAttacher()
r.startTimer = f5.GetTimer().SetTimeoutExWp( r.startTimer = f5.GetTimer().SetTimeoutExWp(
1000 * mt.Table.Config.Get().GetAutoStartTime(), 1000*mt.Table.Config.Get().GetAutoStartTime(),
func (e int32, args *q5.Args) { func(e int32, args *q5.Args) {
if e == q5.TIMER_EXEC_EVENT { if e == q5.TIMER_EXEC_EVENT {
r.autoStart() r.autoStart()
} }

View File

@ -2,19 +2,19 @@ package room
import ( import (
"cs" "cs"
"q5"
"f5" "f5"
"main/constant"
"main/common"
"github.com/golang/protobuf/proto" "github.com/golang/protobuf/proto"
"main/common"
"main/constant"
. "main/global" . "main/global"
"q5"
) )
type roomMgr struct { type roomMgr struct {
cs.MsgHandlerImpl cs.MsgHandlerImpl
currRoomId int32 currRoomId int32
idHash map[string]*room idHash map[string]*room
roomList q5.ListHead roomList q5.ListHead
} }
func (this *roomMgr) Init() { func (this *roomMgr) Init() {
@ -53,7 +53,7 @@ func (this *roomMgr) ProcessCMMsg(handler *cs.CsNetMsgHandler, hdr *f5.MsgHdr) {
} }
case constant.ROOM_HANDLER_ID: case constant.ROOM_HANDLER_ID:
hum := GetPlayerMgr().GetPlayerBySocket(hdr.GetSocket()) hum := GetPlayerMgr().GetPlayerBySocket(hdr.GetSocket())
if hum != nil && hum.GetRoom() != nil { if hum != nil && hum.GetRoom() != nil {
hdr.Context = hum hdr.Context = hum
cs.DispatchMsg(handler, hdr, hum.GetRoom().(*room)) cs.DispatchMsg(handler, hdr, hum.GetRoom().(*room))
} }
@ -116,7 +116,7 @@ func (this *roomMgr) CMSearchRoom(hdr *f5.MsgHdr, msg *cs.CMSearchRoom) {
sinceId := msg.GetSinceId() sinceId := msg.GetSinceId()
roomId := msg.GetRoomId() roomId := msg.GetRoomId()
this.roomList.ForEach( this.roomList.ForEach(
func (data interface{}) bool { func(data interface{}) bool {
r := data.(*room) r := data.(*room)
if r.roomIdx > sinceId && r.viewable() { if r.roomIdx > sinceId && r.viewable() {
if roomId != "" && roomId != r.roomId { if roomId != "" && roomId != r.roomId {

View File

@ -1,16 +1,16 @@
package room package room
import ( import (
"q5"
"cs" "cs"
"github.com/golang/protobuf/proto" "github.com/golang/protobuf/proto"
"q5"
) )
type team struct { type team struct {
room *room room *room
teamId int32 teamId int32
teamUuid string teamUuid string
members q5.ListHead members q5.ListHead
} }
func (this *team) init(room *room, teamId int32, teamUuid string) { func (this *team) init(room *room, teamId int32, teamUuid string) {
@ -22,7 +22,7 @@ func (this *team) init(room *room, teamId int32, teamUuid string) {
func (this *team) unInit() { func (this *team) unInit() {
this.members.ForEach( this.members.ForEach(
func (data interface{}) bool { func(data interface{}) bool {
m := data.(*member) m := data.(*member)
m.unInit() m.unInit()
return true return true
@ -37,7 +37,7 @@ func (this *team) fillMFTeam(pb *cs.MFTeam) {
pb.TeamUuid = proto.String(this.teamUuid) pb.TeamUuid = proto.String(this.teamUuid)
q5.NewSlice(&pb.Members, 0, 4) q5.NewSlice(&pb.Members, 0, 4)
this.members.ForEach( this.members.ForEach(
func (data interface{}) bool { func(data interface{}) bool {
m := data.(*member) m := data.(*member)
pbM := &cs.MFMember{} pbM := &cs.MFMember{}
m.fillMFMember(pbM) m.fillMFMember(pbM)
@ -58,7 +58,7 @@ func (this *team) getMemberNum() int32 {
func (this *team) hasAlreadMember() bool { func (this *team) hasAlreadMember() bool {
ok := false ok := false
this.members.ForEach( this.members.ForEach(
func (data interface{}) bool { func(data interface{}) bool {
m := data.(*member) m := data.(*member)
if m.state == MEMBER_READY_STATE { if m.state == MEMBER_READY_STATE {
ok = true ok = true
@ -72,7 +72,7 @@ func (this *team) hasAlreadMember() bool {
func (this *team) getOwnerCandidate() *member { func (this *team) getOwnerCandidate() *member {
var ownerCandidate *member var ownerCandidate *member
this.members.ForEach( this.members.ForEach(
func (data interface{}) bool { func(data interface{}) bool {
m := data.(*member) m := data.(*member)
if m.hum.IsOnline() { if m.hum.IsOnline() {
ownerCandidate = m ownerCandidate = m

View File

@ -28,11 +28,9 @@ func (this *App) Init() {
chatMgr.init() chatMgr.init()
cacheMgr.init() cacheMgr.init()
wspListener.init() wspListener.init()
httpListener.init()
} }
func (this *App) UnInit() { func (this *App) UnInit() {
httpListener.unInit()
playerMgr.unInit() playerMgr.unInit()
handlerMgr.unInit() handlerMgr.unInit()
wspListener.unInit() wspListener.unInit()
@ -110,3 +108,7 @@ func (this *App) registerDataSources() {
mt.Table.FriendDb.GetById(0).GetDatabase(), mt.Table.FriendDb.GetById(0).GetDatabase(),
30) 30)
} }
func (this *App) GetHttpListenPort() int32 {
return mt.Table.IMCluster.GetHttpListenPort()
}

View File

@ -4,7 +4,6 @@ var app = new(App)
var wspListener = new(WSPListener) var wspListener = new(WSPListener)
var playerMgr = new(PlayerMgr) var playerMgr = new(PlayerMgr)
var handlerMgr = new(HandlerMgr) var handlerMgr = new(HandlerMgr)
var httpListener = new(HttpListener)
var friendMgr = new(FriendsMgr) var friendMgr = new(FriendsMgr)
var cacheMgr = new(CacheMgr) var cacheMgr = new(CacheMgr)

View File

@ -1,19 +0,0 @@
package main
import (
"f5"
"mt"
)
type HttpListener struct {
httpServer *f5.HttpServer
}
func (this *HttpListener) init() {
this.httpServer = new (f5.HttpServer)
this.httpServer.Init("imserver.httplistener", 1000 * 10)
this.httpServer.Start(mt.Table.IMCluster.GetHttpListenPort())
}
func (this *HttpListener) unInit() {
}