This commit is contained in:
aozhiwei 2023-09-07 13:06:29 +08:00
parent 33c2d6a622
commit fb2d1e78b3
4 changed files with 32 additions and 5 deletions

View File

@ -9,19 +9,28 @@ import (
type app struct { type app struct {
netMsgQueue q5.Queue netMsgQueue q5.Queue
initCb func()
unInitCb func()
} }
func (this *app) GetPkgName() string { func (this *app) GetPkgName() string {
return "imserver" return "imserver"
} }
func (this *app) SetCb(initCb func(), unInitCb func()) {
this.initCb = initCb
this.unInitCb = unInitCb
}
func (this *app) Init() { func (this *app) Init() {
this.netMsgQueue.Init() this.netMsgQueue.Init()
f5.LoadMetaTable(mt.Table) f5.LoadMetaTable(mt.Table)
this.registerDataSources() this.registerDataSources()
this.initCb()
} }
func (this *app) UnInit() { func (this *app) UnInit() {
this.unInitCb()
} }
func (this *app) Update() { func (this *app) Update() {

View File

@ -30,3 +30,7 @@ type WspListener interface {
type HttpListener interface { type HttpListener interface {
} }
type App interface {
SetCb(func(), func())
}

View File

@ -11,11 +11,25 @@ import (
) )
func Init() { func Init() {
app.GetApp().Init() app.GetApp().SetCb(initApp, unInitApp)
listener.GetHandlerMgr().Init() f5.Run(app.GetApp())
}
func initApp() {
global.SetPlayerMgr(player.GetPlayerMgr()) global.SetPlayerMgr(player.GetPlayerMgr())
global.SetRoomMgr(room.GetRoomMgr()) global.SetRoomMgr(room.GetRoomMgr())
global.SetWspListener(listener.GetWspListener()) global.SetWspListener(listener.GetWspListener())
listener.GetHandlerMgr().Init()
player.GetPlayerMgr().Init()
room.GetRoomMgr().Init()
listener.GetWspListener().Init()
listener.GetHttpListener().Init() listener.GetHttpListener().Init()
f5.Run(app.GetApp()) }
func unInitApp() {
listener.GetHttpListener().UnInit()
listener.GetWspListener().UnInit()
room.GetRoomMgr().UnInit()
player.GetPlayerMgr().UnInit()
} }

View File

@ -21,7 +21,7 @@ type WSPListener struct {
msgList q5.ListHead msgList q5.ListHead
} }
func (this *WSPListener) init() { func (this *WSPListener) Init() {
this.ch = make(chan *f5.MsgHdr) this.ch = make(chan *f5.MsgHdr)
listener, err := net.Listen("tcp", "0.0.0.0:"+ listener, err := net.Listen("tcp", "0.0.0.0:"+
q5.ToString(mt.Table.HallCluster.GetListenPort())) q5.ToString(mt.Table.HallCluster.GetListenPort()))
@ -34,7 +34,7 @@ func (this *WSPListener) init() {
} }
} }
func (this *WSPListener) unInit() { func (this *WSPListener) UnInit() {
} }
func (this *WSPListener) SS_ping(hdr *f5.MsgHdr, msg *ss.SS_Ping) { func (this *WSPListener) SS_ping(hdr *f5.MsgHdr, msg *ss.SS_Ping) {