2025-04-24 20:39:31 +08:00
|
|
|
package smdl
|
|
|
|
|
|
|
|
import (
|
|
|
|
"admin/apps/game/domain/entity"
|
|
|
|
"admin/apps/game/model"
|
|
|
|
"admin/apps/game/model/dto"
|
|
|
|
"admin/internal/errcode"
|
|
|
|
"admin/lib/httpclient"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ServerHook struct {
|
|
|
|
}
|
|
|
|
|
2025-05-09 18:28:15 +08:00
|
|
|
func (hook *ServerHook) List(projectInfo *entity.Project, resource string, params *dto.CommonListReq,
|
|
|
|
fields []*dto.CommonDtoFieldDesc, totalCount int, rows []dto.CommonDtoValues) (
|
|
|
|
int, []*dto.CommonDtoFieldDesc, []dto.CommonDtoValues, error) {
|
2025-04-24 20:39:31 +08:00
|
|
|
alisrvAddr := projectInfo.GetApiAddr()
|
|
|
|
if alisrvAddr == "" {
|
2025-05-09 18:28:15 +08:00
|
|
|
return 0, nil, nil, errcode.New(errcode.ServerError, "项目%v没有配置api服务器地址", projectInfo.Po.Name)
|
2025-04-24 20:39:31 +08:00
|
|
|
}
|
|
|
|
|
2025-05-09 18:28:15 +08:00
|
|
|
fields = append(fields, getAttachFields()...)
|
2025-04-24 20:39:31 +08:00
|
|
|
|
2025-05-09 18:28:15 +08:00
|
|
|
serverInfoList, err := getRemoteServerInfoList(alisrvAddr)
|
2025-04-24 20:39:31 +08:00
|
|
|
if err != nil {
|
2025-05-09 18:28:15 +08:00
|
|
|
return 0, nil, nil, err
|
2025-04-24 20:39:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, row := range rows {
|
2025-05-09 18:28:15 +08:00
|
|
|
var findRemoteServerInfo *ServerInfo
|
|
|
|
for _, curRunning := range serverInfoList {
|
2025-04-24 20:39:31 +08:00
|
|
|
et := (&entity.CommonResource{}).FromPo(&model.Server{}).FromDto(row)
|
|
|
|
if et.ToPo().(*model.Server).ServerConfID == curRunning.ServerId {
|
|
|
|
// 运行中,给描述信息添加运行信息
|
2025-05-09 18:28:15 +08:00
|
|
|
findRemoteServerInfo = curRunning
|
2025-04-24 20:39:31 +08:00
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
2025-05-09 18:28:15 +08:00
|
|
|
if findRemoteServerInfo != nil {
|
2025-04-24 20:39:31 +08:00
|
|
|
row["RunningStatus"] = "运行中"
|
2025-05-09 18:28:15 +08:00
|
|
|
row["Ccu"] = findRemoteServerInfo.Ccu
|
|
|
|
row["TotalRoleCount"] = findRemoteServerInfo.TotalRoleCount
|
|
|
|
row["TotalAccountCount"] = findRemoteServerInfo.TotalAccountCount
|
|
|
|
if findRemoteServerInfo.OpenWhitelistLogin {
|
|
|
|
row["IsWhitelistLogin"] = "是"
|
|
|
|
} else {
|
|
|
|
row["IsWhitelistLogin"] = "否"
|
|
|
|
}
|
2025-04-24 20:39:31 +08:00
|
|
|
} else {
|
|
|
|
row["RunningStatus"] = "未知"
|
2025-05-09 18:28:15 +08:00
|
|
|
row["Ccu"] = 0
|
|
|
|
row["TotalRoleCount"] = 0
|
|
|
|
row["TotalAccountCount"] = 0
|
|
|
|
row["IsWhitelistLogin"] = "否"
|
2025-04-24 20:39:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-05-09 18:28:15 +08:00
|
|
|
return totalCount, fields, rows, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type ServerInfo struct {
|
|
|
|
ServerId string `json:"serverId"`
|
|
|
|
ServerName string `json:"serverName"`
|
|
|
|
Ccu int `json:"ccu"`
|
|
|
|
TotalRoleCount int `json:"total_role_count"`
|
|
|
|
TotalAccountCount int `json:"total_account_count"`
|
|
|
|
Addr string `json:"addr"`
|
|
|
|
OpenWhitelistLogin bool `json:"open_whitelist_login"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type RspData struct {
|
|
|
|
Code int `json:"code"`
|
|
|
|
Msg string `json:"msg"`
|
|
|
|
Data struct {
|
|
|
|
List []*ServerInfo `json:"list"`
|
|
|
|
} `json:"data"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func getRemoteServerInfoList(alisrvAddr string) ([]*ServerInfo, error) {
|
|
|
|
rsp := &RspData{}
|
|
|
|
err := httpclient.Request(alisrvAddr+"/server", "get", nil, rsp)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return rsp.Data.List, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func getAttachFields() []*dto.CommonDtoFieldDesc {
|
|
|
|
return []*dto.CommonDtoFieldDesc{
|
|
|
|
{
|
|
|
|
Name: "进程运行状态",
|
|
|
|
Key: "RunningStatus",
|
|
|
|
Type: "string",
|
|
|
|
HelpText: "进程运行状态:未知、运行中、停止",
|
|
|
|
Readonly: true,
|
|
|
|
Required: false,
|
|
|
|
Choices: make([]*dto.CommonDtoFieldChoice, 0),
|
|
|
|
MultiChoice: false,
|
|
|
|
Uneditable: true,
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
Name: "实时在线",
|
|
|
|
Key: "Ccu",
|
|
|
|
Type: "int",
|
|
|
|
HelpText: "ccu",
|
|
|
|
Readonly: true,
|
|
|
|
Required: false,
|
|
|
|
Choices: make([]*dto.CommonDtoFieldChoice, 0),
|
|
|
|
MultiChoice: false,
|
|
|
|
Uneditable: true,
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
Name: "总角色数",
|
|
|
|
Key: "TotalRoleCount",
|
|
|
|
Type: "int",
|
|
|
|
HelpText: "",
|
|
|
|
Readonly: true,
|
|
|
|
Required: false,
|
|
|
|
Choices: make([]*dto.CommonDtoFieldChoice, 0),
|
|
|
|
MultiChoice: false,
|
|
|
|
Uneditable: true,
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
Name: "总账号数",
|
|
|
|
Key: "TotalAccountCount",
|
|
|
|
Type: "int",
|
|
|
|
HelpText: "进程运行状态:未知、运行中、停止",
|
|
|
|
Readonly: true,
|
|
|
|
Required: false,
|
|
|
|
Choices: make([]*dto.CommonDtoFieldChoice, 0),
|
|
|
|
MultiChoice: false,
|
|
|
|
Uneditable: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "是否只允许白名单登录",
|
|
|
|
Key: "IsWhitelistLogin",
|
|
|
|
Type: "bool",
|
|
|
|
HelpText: "打开就是相当于停服维护中了",
|
|
|
|
Readonly: true,
|
|
|
|
Required: false,
|
|
|
|
Choices: make([]*dto.CommonDtoFieldChoice, 0),
|
|
|
|
MultiChoice: false,
|
|
|
|
Uneditable: true,
|
|
|
|
},
|
|
|
|
}
|
2025-04-24 20:39:31 +08:00
|
|
|
}
|