This commit is contained in:
aozhiwei 2024-02-17 18:27:46 +08:00
parent 19281910ab
commit d3e5a14871
7 changed files with 200 additions and 116 deletions

View File

@ -1,114 +0,0 @@
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()
}

View File

@ -0,0 +1,88 @@
package app
import (
"cs"
"f5"
"main/constant"
. "main/global"
"mt"
"q5"
"ss"
)
type app struct {
netMsgQueue q5.Queue
initCb func()
unInitCb func()
}
func (this *app) GetPkgName() string {
return "imserver"
}
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.HallCluster.GetIp(),
mt.Table.HallCluster.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)
case constant.ROOM_HANDLER_ID:
fallthrough
case constant.ROOM_MGR_HANDLER_ID:
GetRoomMgr().ProcessCMMsg(handler, hdr)
}
}
}
}
}
func (this *app) AddNetMsg(hdr *f5.MsgHdr) {
this.netMsgQueue.Push(&hdr.Entry)
f5.GetApp().NotifyLoopCond()
}
func (this *app) registerDataSources() {
}
func (this *app) GetHttpListenPort() int32 {
return mt.Table.HallCluster.GetHttpListenPort()
}

View File

@ -0,0 +1,14 @@
package common
import (
"net"
"ss"
"f5"
proto "github.com/golang/protobuf/proto"
)
type WspListener interface {
ProcessSSMMsg(*ss.SsNetMsgHandler, *f5.MsgHdr)
SendProxyMsg(net.Conn, uint16, proto.Message)
}

View File

@ -0,0 +1,11 @@
package constant
const (
ROOMMGR_MODULE_IDX = iota
APP_MODULE_IDX
WSPLISTENER_MODULE_IDX
HANDLER_MGR_MODULE_IDX
HTTP_LISTENER_MODULE_IDX
PLAYER_MGR_MODULE_IDX
MAX_MODULE_IDX
)

View File

@ -1,7 +1,5 @@
package main
var app = new(App)
var wspListener = new(WSPListener)
var playerMgr = new(PlayerMgr)
var handlerMgr = new(HandlerMgr)
var friendMgr = new(FriendsMgr)

View File

@ -0,0 +1,87 @@
package global
import (
"q5"
"fmt"
"main/constant"
"main/common"
)
var modules [constant.MAX_MODULE_IDX]q5.Module
var initOrders = []int32 {
constant.HANDLER_MGR_MODULE_IDX,
constant.HTTP_LISTENER_MODULE_IDX,
constant.PLAYER_MGR_MODULE_IDX,
constant.ROOMMGR_MODULE_IDX,
constant.WSPLISTENER_MODULE_IDX,
}
var app common.App
var roomMgr common.RoomMgr
var playerMgr common.PlayerMgr
var wspListener common.WspListener
func GetRoomMgr() common.RoomMgr {
return roomMgr
}
func GetPlayerMgr() common.PlayerMgr {
return playerMgr
}
func GetWspListener() common.WspListener {
return wspListener
}
func GetApp() common.App {
return app
}
func RegModule(idx int32, m q5.Module) {
fmt.Printf("RegModule module %d\n", idx)
modules[idx] = m
switch (idx) {
case constant.APP_MODULE_IDX:
{
app = m.(common.App)
}
case constant.WSPLISTENER_MODULE_IDX:
{
wspListener = m.(common.WspListener)
}
case constant.HANDLER_MGR_MODULE_IDX:
{
//wspListener = m.(.common.H)
}
case constant.HTTP_LISTENER_MODULE_IDX:
{
//wspListener = m.(.common.H)
}
case constant.PLAYER_MGR_MODULE_IDX:
{
playerMgr = m.(common.PlayerMgr)
}
case constant.ROOMMGR_MODULE_IDX:
{
roomMgr = m.(common.RoomMgr)
}
default:
{
panic("unknow module")
}
}
}
func InitModules() {
for _, val := range(initOrders) {
fmt.Printf("init module %d\n", val)
modules[val].Init()
}
}
func UnInitModules() {
for _, val := range(initOrders) {
fmt.Printf("unInit module %d", val)
modules[val].UnInit()
}
}