2024-08-03 14:37:54 +08:00

129 lines
3.2 KiB
Go

package app
import (
"cs"
"f5"
"main/constant"
. "main/global"
"main/mt"
"q5"
"ss"
)
type app struct {
netMsgQueue q5.Queue
initCb func()
unInitCb func()
}
func (this *app) GetPkgName() string {
return "imserver_new"
}
func (this *app) Run(initCb func(), unInitCb func()) {
this.initCb = initCb
this.unInitCb = unInitCb
f5.Run(this)
}
func (this *app) Init() {
this.netMsgQueue.Init()
f5.LoadMetaTable(mt.Table)
this.registerDataSources()
this.initCb()
f5.GetSysLog().Info("%s start host:%s port:%d",
this.GetPkgName(),
mt.Table.IMCluster.GetIp(),
mt.Table.IMCluster.GetListenPort())
}
func (this *app) UnInit() {
this.unInitCb()
}
func (this *app) Update() {
this.netMsgQueue.Fetch()
for !this.netMsgQueue.WorkList.Empty() {
hdr := this.netMsgQueue.WorkList.FirstEntry().(*f5.MsgHdr)
hdr.Entry.DelInit()
if hdr.MsgId < f5.WSP_SS_MAX_MSGID {
handler := ss.GetNetMsgHandler(hdr.MsgId)
if handler != nil {
switch handler.HandlerId {
case constant.WSP_LISTENER_HANDLER_ID:
GetWspListener().ProcessSSMMsg(handler, hdr)
}
}
} else {
handler := cs.GetNetMsgHandler(hdr.MsgId)
if handler != nil {
if !f5.IsOnlineEnv() {
f5.GetSysLog().Info("%s %s", q5.GetTypeName(hdr.Msg), q5.EncodeJson(hdr.Msg))
}
switch handler.HandlerId {
case constant.PLAYER_MGR_HANDLER_ID:
fallthrough
case constant.PLAYER_HANDLER_ID:
GetPlayerMgr().ProcessCMMsg(handler, hdr)
}
}
}
}
}
func (this *app) AddNetMsg(hdr *f5.MsgHdr) {
this.netMsgQueue.Push(&hdr.Entry)
f5.GetApp().NotifyLoopCond()
}
func (this *app) registerDataSources() {
f5.GetJsStyleDb().RegisterDataSource(
constant.GAME_DB,
mt.Table.GameDb.GetById(0).GetHost(),
mt.Table.GameDb.GetById(0).GetPort(),
mt.Table.GameDb.GetById(0).GetUser(),
mt.Table.GameDb.GetById(0).GetPasswd(),
mt.Table.GameDb.GetById(0).GetDatabase(),
1,
mt.Table.GameDb.GetById(0).GetMaxOpenConns(),
mt.Table.GameDb.GetById(0).GetMaxIdleConns())
f5.GetGoStyleDb().RegisterDataSource(
constant.GAME_DB,
mt.Table.GameDb.GetById(0).GetHost(),
mt.Table.GameDb.GetById(0).GetPort(),
mt.Table.GameDb.GetById(0).GetUser(),
mt.Table.GameDb.GetById(0).GetPasswd(),
mt.Table.GameDb.GetById(0).GetDatabase(),
1,
mt.Table.GameDb.GetById(0).GetMaxOpenConns(),
mt.Table.GameDb.GetById(0).GetMaxIdleConns())
f5.GetJsStyleDb().RegisterDataSource(
constant.FRIEND_DB,
mt.Table.FriendDb.GetById(0).GetHost(),
mt.Table.FriendDb.GetById(0).GetPort(),
mt.Table.FriendDb.GetById(0).GetUser(),
mt.Table.FriendDb.GetById(0).GetPasswd(),
mt.Table.FriendDb.GetById(0).GetDatabase(),
1,
mt.Table.FriendDb.GetById(0).GetMaxOpenConns(),
mt.Table.FriendDb.GetById(0).GetMaxIdleConns())
f5.GetGoStyleDb().RegisterDataSource(
constant.FRIEND_DB,
mt.Table.FriendDb.GetById(0).GetHost(),
mt.Table.FriendDb.GetById(0).GetPort(),
mt.Table.FriendDb.GetById(0).GetUser(),
mt.Table.FriendDb.GetById(0).GetPasswd(),
mt.Table.FriendDb.GetById(0).GetDatabase(),
1,
mt.Table.FriendDb.GetById(0).GetMaxOpenConns(),
mt.Table.FriendDb.GetById(0).GetMaxIdleConns())
}
func (this *app) GetHttpListenPort() int32 {
return mt.Table.IMCluster.GetHttpListenPort()
}
func (this *app) HasTask() bool {
return !this.netMsgQueue.IsEmpty()
}