96 lines
2.0 KiB
Go
96 lines
2.0 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()
|
|
wspListener.init()
|
|
httpListener.init()
|
|
}
|
|
|
|
func (this *App) UnInit() {
|
|
httpListener.unInit()
|
|
playerMgr.unInit()
|
|
handlerMgr.unInit()
|
|
wspListener.unInit()
|
|
}
|
|
|
|
func (this *App) Update() {
|
|
this.netMsgQueue.Fetch()
|
|
for !this.netMsgQueue.WorkList.Empty() {
|
|
next := this.netMsgQueue.WorkList.Next()
|
|
hdr, ok := next.GetData().(*f5.MsgHdr)
|
|
if ok {
|
|
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 {
|
|
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)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
next.Del()
|
|
}
|
|
}
|
|
|
|
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.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)
|
|
}
|