182 lines
3.9 KiB
Go
182 lines
3.9 KiB
Go
package service
|
|
|
|
import (
|
|
"blazing/common/utils"
|
|
"blazing/cool"
|
|
"blazing/modules/config/model"
|
|
"fmt"
|
|
"sort"
|
|
|
|
"github.com/gogf/gf/v2/database/gdb"
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
"github.com/gogf/gf/v2/util/gconv"
|
|
"github.com/qiniu/go-sdk/v7/auth/qbox"
|
|
"github.com/qiniu/go-sdk/v7/storage"
|
|
)
|
|
|
|
type ServerService struct {
|
|
*cool.Service
|
|
manager *storage.BucketManager
|
|
bucket string
|
|
}
|
|
|
|
func NewServerService() *ServerService {
|
|
cf := &ServerService{
|
|
Service: &cool.Service{
|
|
Model: model.NewServerList(),
|
|
PageQueryOp: &cool.QueryOp{
|
|
ModifyResult: func(ctx g.Ctx, data interface{}) interface{} {
|
|
var rr []g.MapStrAny
|
|
r, _ := gconv.Map(data)["list"].(gdb.Result)
|
|
for i := 0; i < len(r); i++ {
|
|
t, ok := cool.GetClient(gconv.Uint16(r[i].Map()["port"]))
|
|
// tt.Friends = v.Friends
|
|
subm := r[i].GMap()
|
|
|
|
if ok {
|
|
|
|
err := t.KickPerson(0) //实现指定服务器踢人
|
|
|
|
if err == nil {
|
|
r, _ := utils.TcpPing(fmt.Sprintf("%s:%d", r[i].Map()["ip"], r[i].Map()["port"]))
|
|
|
|
subm.Set("isonline", r)
|
|
|
|
} else {
|
|
subm.Set("isonline", 0)
|
|
}
|
|
|
|
} else {
|
|
subm.Set("isonline", 0)
|
|
}
|
|
rr = append(rr, subm.MapStrAny())
|
|
}
|
|
|
|
data.(map[string]interface{})["list"] = rr
|
|
|
|
return data
|
|
},
|
|
},
|
|
},
|
|
}
|
|
cfg := storage.Config{
|
|
Zone: &storage.ZoneHuadong,
|
|
UseHTTPS: true,
|
|
UseCdnDomains: true,
|
|
}
|
|
mac := qbox.NewMac("DzMpomnPxqBHkIcvxTbC-hl_8LjVB0LXZuhCky_u", "bhoxrpG1s7MBmSS2I1k5t9zMpuiderpBDZoIPQKU")
|
|
cf.bucket = "blazingt"
|
|
|
|
cf.manager = storage.NewBucketManager(mac, &cfg)
|
|
return cf
|
|
}
|
|
func (s *ServerService) GetPort(isdebug int) gdb.List {
|
|
var res gdb.Result
|
|
if isdebug == 1 {
|
|
res, _ = cool.DBM(s.Model).Where("is_open", 1).Fields("ip", "port", "online_id", "is_vip", "name").All()
|
|
|
|
} else {
|
|
res, _ = cool.DBM(s.Model).Where("is_open", 1).Where("is_debug", 0).Fields("ip", "port", "online_id", "is_vip", "name").All()
|
|
|
|
}
|
|
|
|
return res.List()
|
|
|
|
}
|
|
func (s *ServerService) GetServer() []model.ServerList {
|
|
var item []model.ServerList
|
|
cool.DBM(s.Model).Scan(&item)
|
|
|
|
return item
|
|
|
|
}
|
|
func (s *ServerService) StartUPdate(OnlineID uint16, isinstall int) model.ServerList {
|
|
|
|
m := cool.DBM(s.Model).Where("online_id", OnlineID)
|
|
|
|
var tttt model.ServerList
|
|
m.Scan(&tttt)
|
|
if isinstall == 1 {
|
|
tttt.IsOpen = uint8(0)
|
|
m.Save(tttt)
|
|
}
|
|
|
|
// s.CleanCache()
|
|
return tttt
|
|
|
|
}
|
|
func (s *ServerService) SetServerID(OnlineID uint16, Port uint16) error {
|
|
|
|
m := cool.DBM(s.Model).Where("online_id", OnlineID)
|
|
|
|
var tttt model.ServerList
|
|
m.Scan(&tttt)
|
|
tttt.Port = Port
|
|
tttt.OnlineID = OnlineID
|
|
tttt.IsOpen = 1
|
|
|
|
m.Save(tttt)
|
|
// s.CleanCache()
|
|
return nil
|
|
|
|
}
|
|
func (s *ServerService) GetServerID(OnlineID uint16) model.ServerList {
|
|
var tttt model.ServerList
|
|
cool.DBM(s.Model).Where("online_id", OnlineID).Scan(&tttt)
|
|
|
|
return tttt
|
|
|
|
}
|
|
|
|
// 保存版本号
|
|
func (s *ServerService) SetServerScreen(id uint16, name string) {
|
|
|
|
dbm(s.Model).Where("online_id", id).Data("old_screen", name).Update()
|
|
|
|
}
|
|
func (s *ServerService) GetFile() string {
|
|
var files []File
|
|
prefix := "logic"
|
|
delimiter := "" // 用于分隔目录
|
|
marker := "" // 初始标记为空
|
|
for {
|
|
entries, _, nextMarker, hasNext, err := s.manager.ListFiles(s.bucket, prefix, delimiter, marker, 100)
|
|
if err != nil {
|
|
return ""
|
|
}
|
|
// 添加文件到结果列表
|
|
for _, entry := range entries {
|
|
files = append(files, File{
|
|
Name: entry.Key,
|
|
Size: entry.Fsize,
|
|
Path: entry.Key,
|
|
Time: entry.PutTime,
|
|
})
|
|
}
|
|
|
|
// 如果没有更多文件,结束循环
|
|
if !hasNext {
|
|
break
|
|
}
|
|
|
|
// 更新标记,继续下一页
|
|
marker = nextMarker
|
|
}
|
|
|
|
sort.Slice(files, func(i, j int) bool {
|
|
return files[i].Time > files[j].Time
|
|
})
|
|
|
|
return files[0].Name
|
|
|
|
}
|
|
|
|
type File struct {
|
|
Name string `json:"name"`
|
|
Path string `json:"path"`
|
|
Url string `json:"url"`
|
|
Size int64 `json:"size"`
|
|
Modified string `json:"modified"`
|
|
Time int64 `json:"time"`
|
|
}
|