You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
95 lines
2.3 KiB
95 lines
2.3 KiB
|
1 year ago
|
package game
|
||
|
|
|
||
|
|
import (
|
||
|
|
"fmt"
|
||
|
|
"server/call"
|
||
|
|
"server/common"
|
||
|
|
"server/config"
|
||
|
|
"server/db"
|
||
|
|
"server/pb"
|
||
|
|
"strconv"
|
||
|
|
|
||
|
|
edb "server/db/es"
|
||
|
|
mdb "server/db/mysql"
|
||
|
|
rdb "server/db/redis"
|
||
|
|
|
||
|
|
"github.com/liangdas/mqant/conf"
|
||
|
|
"github.com/liangdas/mqant/log"
|
||
|
|
"github.com/liangdas/mqant/module"
|
||
|
|
basemodule "github.com/liangdas/mqant/module/base"
|
||
|
|
)
|
||
|
|
|
||
|
|
type Module struct {
|
||
|
|
*basemodule.BaseModule
|
||
|
|
GameID int
|
||
|
|
GameName string
|
||
|
|
Sub SubModule
|
||
|
|
}
|
||
|
|
|
||
|
|
func NewModule(gameID, gameType int, gameName string, newTable func() SubTable) *Module {
|
||
|
|
one := &Module{
|
||
|
|
BaseModule: new(basemodule.BaseModule),
|
||
|
|
GameName: gameName,
|
||
|
|
GameID: gameID,
|
||
|
|
}
|
||
|
|
ThisGameID = gameID
|
||
|
|
ThisGameType = gameType
|
||
|
|
NewTable = newTable
|
||
|
|
return one
|
||
|
|
}
|
||
|
|
|
||
|
|
type SubModule interface {
|
||
|
|
RegistHandler()
|
||
|
|
}
|
||
|
|
|
||
|
|
func (m *Module) GetType() string {
|
||
|
|
return fmt.Sprintf("%s%d", common.GameModulePrefix, m.GameID)
|
||
|
|
}
|
||
|
|
|
||
|
|
func (m *Module) Version() string {
|
||
|
|
//可以在监控时了解代码版本
|
||
|
|
return "1.0.0"
|
||
|
|
}
|
||
|
|
|
||
|
|
func (m *Module) OnInit(app module.App, settings *conf.ModuleSettings) {
|
||
|
|
InitModule(m.BaseModule, m, app, settings)
|
||
|
|
db.InitDB(&mdb.MysqlClient{}, &rdb.RedisClient{}, &edb.EsClient{})
|
||
|
|
|
||
|
|
LoadConfigs()
|
||
|
|
InitNats(m.App.Transport())
|
||
|
|
m.Regist()
|
||
|
|
m.Sub.RegistHandler()
|
||
|
|
log.Info("[%v]module init finish", m.GetType())
|
||
|
|
}
|
||
|
|
|
||
|
|
func (m *Module) Regist() {
|
||
|
|
m.GetServer().RegisterGO("/"+strconv.Itoa(int(pb.GameProtocol_EnterGameReq)), Enter)
|
||
|
|
m.GetServer().RegisterGO("/"+strconv.Itoa(int(pb.GameProtocol_TableInfoReq)), OnTableInfo)
|
||
|
|
m.GetServer().RegisterGO("/"+strconv.Itoa(int(pb.GameProtocol_LeaveReq)), OnLeave)
|
||
|
|
|
||
|
|
if ThisGameType == GameTypeMillion {
|
||
|
|
m.GetServer().RegisterGO("/"+strconv.Itoa(int(pb.GameProtocol_BetReq)), OnMillionBet)
|
||
|
|
m.GetServer().RegisterGO("/"+strconv.Itoa(int(pb.GameProtocol_HistoryReq)), OnHistory)
|
||
|
|
m.GetServer().RegisterGO("/"+strconv.Itoa(int(pb.GameProtocol_BetListReq)), OnBetList)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func (m *Module) Run(closeSig chan bool) {
|
||
|
|
log.Info("[%v]module running", m.GetType())
|
||
|
|
call.InitTimeWheel(closeSig)
|
||
|
|
call.NewCaller(m)
|
||
|
|
call.InitExecQueue()
|
||
|
|
call.NewSnowflake(int64(config.GetConfig().WorkID))
|
||
|
|
call.InitOnline(GetOnline)
|
||
|
|
call.WriteRealOnline(m.GameName, GetRealOnline)
|
||
|
|
InitRooms(NewTable)
|
||
|
|
<-closeSig
|
||
|
|
log.Info("[%v]module stop", m.GetType())
|
||
|
|
}
|
||
|
|
|
||
|
|
func (m *Module) OnDestroy() {
|
||
|
|
ModuleOnDestroy()
|
||
|
|
m.BaseModule.OnDestroy()
|
||
|
|
log.Info("[%v]module destroy", m.GetType())
|
||
|
|
}
|