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.
98 lines
2.3 KiB
98 lines
2.3 KiB
|
1 year ago
|
package hall
|
||
|
|
|
||
|
|
import (
|
||
|
|
"server/call"
|
||
|
|
"server/common"
|
||
|
|
"server/config"
|
||
|
|
"server/db"
|
||
|
|
edb "server/db/es"
|
||
|
|
mdb "server/db/mysql"
|
||
|
|
rdb "server/db/redis"
|
||
|
|
"server/natsClient"
|
||
|
|
"server/pb"
|
||
|
|
"strconv"
|
||
|
|
"time"
|
||
|
|
|
||
|
|
"github.com/liangdas/mqant/conf"
|
||
|
|
"github.com/liangdas/mqant/log"
|
||
|
|
"github.com/liangdas/mqant/module"
|
||
|
|
basemodule "github.com/liangdas/mqant/module/base"
|
||
|
|
"github.com/liangdas/mqant/server"
|
||
|
|
)
|
||
|
|
|
||
|
|
type Hall struct {
|
||
|
|
basemodule.BaseModule
|
||
|
|
}
|
||
|
|
|
||
|
|
var Module = func() module.Module {
|
||
|
|
this := new(Hall)
|
||
|
|
return this
|
||
|
|
}
|
||
|
|
|
||
|
|
func (h *Hall) GetType() string {
|
||
|
|
//很关键,需要与配置文件中的Module配置对应
|
||
|
|
return "hall"
|
||
|
|
}
|
||
|
|
func (h *Hall) Version() string {
|
||
|
|
//可以在监控时了解代码版本
|
||
|
|
return "1.0.0"
|
||
|
|
}
|
||
|
|
|
||
|
|
func (h *Hall) OnInit(app module.App, settings *conf.ModuleSettings) {
|
||
|
|
h.BaseModule.OnInit(h, app, settings,
|
||
|
|
server.RegisterInterval(5*time.Second),
|
||
|
|
server.RegisterTTL(10*time.Second),
|
||
|
|
)
|
||
|
|
db.InitDB(&mdb.MysqlClient{}, &rdb.RedisClient{}, &edb.EsClient{})
|
||
|
|
|
||
|
|
log.Info("[%v]module init finish, config:%+v", h.GetType(), config.GetConfig().Hall)
|
||
|
|
|
||
|
|
// 初始化调用
|
||
|
|
call.NewCaller(h)
|
||
|
|
|
||
|
|
//LOGIN
|
||
|
|
h.GetServer().RegisterGO("/"+strconv.Itoa(int(pb.ServerGateReq_GateLoginReq)), h.login)
|
||
|
|
//LOGOUT
|
||
|
|
//h.GetServer().RegisterGO("/"+pb.ServerGatewayCmd_name[int32(pb.ServerGatewayCmd_CMD_GATEWAY_LOGOUT_REQ)], h.logout)
|
||
|
|
|
||
|
|
// 初始化订阅事件
|
||
|
|
h.NewNatsImp(natsClient.TopicNewPlayer)
|
||
|
|
initNats(h.App.Transport())
|
||
|
|
if err := loadConfig(); err != nil {
|
||
|
|
log.Error("err:%v", err)
|
||
|
|
panic(err)
|
||
|
|
}
|
||
|
|
StartTimer()
|
||
|
|
}
|
||
|
|
|
||
|
|
func (h *Hall) Run(closeSig chan bool) {
|
||
|
|
log.Info("[%v]module running", h.GetType())
|
||
|
|
call.InitTimeWheel(closeSig)
|
||
|
|
call.InitExecQueue()
|
||
|
|
// 初始化在线人数上报
|
||
|
|
call.InitOnline(GetOnline)
|
||
|
|
call.WriteRealOnline("Total", GetRealOnline)
|
||
|
|
|
||
|
|
// 加载配置
|
||
|
|
if err := loadConfig(); err != nil {
|
||
|
|
panic(err)
|
||
|
|
}
|
||
|
|
<-closeSig
|
||
|
|
log.Info("[%v]module stop", h.GetType())
|
||
|
|
}
|
||
|
|
|
||
|
|
func (h *Hall) OnDestroy() {
|
||
|
|
playerIdMap.Range(func(key, value interface{}) bool {
|
||
|
|
p := value.(*player)
|
||
|
|
p.session.Close()
|
||
|
|
// db.Redis().Delkey(common.GetRedisKeyToken(p.token))
|
||
|
|
return true
|
||
|
|
})
|
||
|
|
if err := db.Mysql().C().Model(&common.PlayerDBInfo{}).Where("online = 1").UpdateColumn("online", 2).Error; err != nil {
|
||
|
|
log.Error("err:%v", err)
|
||
|
|
}
|
||
|
|
//一定别忘了继承
|
||
|
|
h.BaseModule.OnDestroy()
|
||
|
|
log.Info("[%v]module destroy", h.GetType())
|
||
|
|
}
|