115 lines
2.6 KiB
Go
115 lines
2.6 KiB
Go
package main
|
|
|
|
import (
|
|
"cs"
|
|
"f5"
|
|
"mt"
|
|
"q5"
|
|
"ss"
|
|
)
|
|
|
|
type App struct {
|
|
netMsgQueue q5.Queue
|
|
}
|
|
|
|
func (this *App) GetPkgName() string {
|
|
return "imserver"
|
|
}
|
|
|
|
func (this *App) Init() {
|
|
this.netMsgQueue.Init()
|
|
f5.LoadMetaTable(mt.Table)
|
|
this.registerDataSources()
|
|
|
|
handlerMgr.init()
|
|
playerMgr.init()
|
|
friendMgr.init()
|
|
guildMgr.init()
|
|
chatMgr.init()
|
|
cacheMgr.init()
|
|
wspListener.init()
|
|
}
|
|
|
|
func (this *App) UnInit() {
|
|
playerMgr.unInit()
|
|
handlerMgr.unInit()
|
|
wspListener.unInit()
|
|
}
|
|
|
|
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 WSP_LISTENER_HANDLER_ID:
|
|
ss.DispatchMsg(handler, hdr, wspListener)
|
|
}
|
|
}
|
|
} 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 PLAYER_MGR_HANDLER_ID:
|
|
cs.DispatchMsg(handler, hdr, playerMgr)
|
|
case PLAYER_HANDLER_ID:
|
|
player := playerMgr.getPlayerBySocket(hdr.GetSocket())
|
|
if player != nil {
|
|
cs.DispatchMsg(handler, hdr, player)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
func (this *App) addNetMsg(hdr *f5.MsgHdr) {
|
|
this.netMsgQueue.Push(&hdr.Entry)
|
|
f5.GetApp().NotifyLoopCond()
|
|
}
|
|
|
|
func (this *App) registerDataSources() {
|
|
f5.GetJsStyleDb().RegisterDataSource(
|
|
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(),
|
|
30)
|
|
f5.GetGoStyleDb().RegisterDataSource(
|
|
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(),
|
|
30)
|
|
f5.GetJsStyleDb().RegisterDataSource(
|
|
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(),
|
|
30)
|
|
f5.GetGoStyleDb().RegisterDataSource(
|
|
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(),
|
|
30)
|
|
}
|
|
|
|
func (this *App) GetHttpListenPort() int32 {
|
|
return mt.Table.IMCluster.GetHttpListenPort()
|
|
}
|