| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- package controller
- import (
- actorRemote "f1-game/internal/actor_remote"
- cherryApp "f1-game/internal/cherry_app"
- "f1-game/internal/code"
- "f1-game/internal/constant"
- nameActor "f1-game/internal/name/actor"
- nameKey "f1-game/internal/name/key"
- nameRemote "f1-game/internal/name/remote"
- "f1-game/internal/pb"
- "f1-game/nodes/ops/service"
- "fmt"
- cstring "github.com/cherry-game/cherry/extend/string"
- ctime "github.com/cherry-game/cherry/extend/time"
- cfacade "github.com/cherry-game/cherry/facade"
- cgin "github.com/cherry-game/components/gin"
- )
- type commonController struct {
- cgin.BaseController
- }
- func (p *commonController) Init() {
- p.GET("/common/db/queue/:nodeID", p.dbQueue) // 获取节点db队列
- p.GET("/common/ping/:nodeID", p.ping) // ping节点
- p.GET("/common/state/:nodeID/:state", p.state) // 更新节点状态
- }
- func (p *commonController) dbQueue(c *cgin.Context) {
- nodeID := c.GetString(nameKey.NodeID, "")
- if cstring.IsBlank(nodeID) {
- code.JSONResult(c, code.DataNotFound)
- return
- }
- nodeType, found := cherryApp.GetNodeType(nodeID)
- if !found {
- code.JSONResult(c, code.DataNotFound)
- return
- }
- var (
- list *pb.DBQueueReportList
- errCode int32
- )
- switch nodeType {
- case constant.NodeCenter:
- {
- list, errCode = actorRemote.CenterOps.GetDBReport()
- }
- case constant.NodeGame:
- {
- list, errCode = actorRemote.GameOps.GetDBReport(nodeID)
- }
- }
- if code.IsFail(errCode) {
- code.JSONResult(c, errCode)
- return
- }
- service.DBReportRenderHtml(c, list.List)
- }
- func (p *commonController) ping(c *cgin.Context) {
- nodeID := c.GetString(nameKey.NodeID, "")
- if cstring.IsBlank(nodeID) {
- code.JSONResult(c, code.DataNotFound)
- return
- }
- nodeType, found := cherryApp.GetNodeType(nodeID)
- if !found {
- code.JSONResult(c, code.DataNotFound)
- return
- }
- start := ctime.Now()
- switch nodeType {
- case constant.NodeCenter:
- {
- actorRemote.CenterOps.Ping()
- }
- }
- diffNanosecond := ctime.Now().ToNanosecond() - start.ToNanosecond()
- t := struct {
- Elapsed string `json:"elapsedTime"`
- }{
- Elapsed: fmt.Sprintf("%d Nanosecond", diffNanosecond),
- }
- c.RenderJSON(&t)
- }
- func (p *commonController) state(c *cgin.Context) {
- var (
- nodeID = c.GetString(nameKey.NodeID, "")
- state = c.GetInt32(nameKey.State, 0)
- )
- nodeType, found := cherryApp.GetNodeType(nodeID)
- if !found {
- code.JSONResult(c, code.DataNotFound)
- return
- }
- var (
- actorName string
- )
- switch nodeType {
- case constant.NodeGame:
- actorName = nameActor.GameOps
- case constant.NodeMap:
- actorName = nameActor.Map_Ops
- default:
- code.JSONResult(c, code.RequestParamsError)
- return
- }
- var (
- targetPath = cfacade.NewPath(nodeID, actorName)
- req = &pb.I32{
- Value: state,
- }
- )
- statusCode := cherryApp.CallWait(targetPath, nameRemote.Ops_ChangeNodeState, req, nil)
- code.JSONResult(c, statusCode)
- }
|