2025-11-03 19:14:34 +08:00
|
|
|
|
package rpc
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
|
"blazing/cool"
|
|
|
|
|
|
"blazing/modules/base/service"
|
|
|
|
|
|
"blazing/modules/blazing/model"
|
|
|
|
|
|
"context"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/butoften/array"
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2025-11-03 15:30:41 +00:00
|
|
|
|
func GetServerInfoList() []ServerInfo {
|
2025-11-03 19:14:34 +08:00
|
|
|
|
dictInfoModel1 := model.NewServerList()
|
|
|
|
|
|
mType := cool.DBM(dictInfoModel1)
|
|
|
|
|
|
t, _ := mType.All()
|
|
|
|
|
|
//fmt.Println(t)
|
|
|
|
|
|
var ret []model.ServerList
|
|
|
|
|
|
t.Structs(&ret)
|
|
|
|
|
|
//fmt.Println(t)
|
|
|
|
|
|
var ret1 []ServerInfo
|
|
|
|
|
|
ip, _ := service.NewBaseSysParamService().DataByKey(context.Background(), "server_ip")
|
|
|
|
|
|
testip, _ := service.NewBaseSysParamService().DataByKey(context.Background(), "test_ip")
|
|
|
|
|
|
for _, v := range ret {
|
|
|
|
|
|
tt := newServerInfo()
|
|
|
|
|
|
tt.OnlineID = uint32(v.OnlineID)
|
|
|
|
|
|
|
|
|
|
|
|
tt.IP = ip
|
|
|
|
|
|
if tt.OnlineID == 2 {
|
|
|
|
|
|
tt.UserCnt = 300
|
|
|
|
|
|
tt.IP = testip
|
|
|
|
|
|
}
|
|
|
|
|
|
tt.Port = v.Port
|
|
|
|
|
|
t, ok := Clientmap[v.Port]
|
|
|
|
|
|
|
2025-11-03 15:30:41 +00:00
|
|
|
|
if ok {
|
|
|
|
|
|
cool.Loger.Info(context.TODO(), "服务器假踢人")
|
|
|
|
|
|
err := t.KickPerson(0) //实现指定服务器踢人
|
|
|
|
|
|
if err == nil {
|
|
|
|
|
|
// tt.Friends = v.Friends
|
|
|
|
|
|
ret1 = append(ret1, *tt)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-03 19:14:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
array.Sort(&ret1, func(a ServerInfo, b ServerInfo) bool {
|
|
|
|
|
|
return a.OnlineID < b.OnlineID
|
|
|
|
|
|
})
|
|
|
|
|
|
//fmt.Printf("升序 Sort: %v\n", ret1)
|
|
|
|
|
|
return ret1
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// CommendSvrInfo 初始连接请求信息结构体
|
|
|
|
|
|
type CommendSvrInfo struct {
|
|
|
|
|
|
//Handler player.TomeeHeader //` struc:"[0]pad"` //消息头 ,这里为传入的头部数据,遍历此头部实现解析CommendSvrInfo
|
|
|
|
|
|
MaxOnlineID uint32 `struc:"sizeof=ServerList"` // 最大连接数
|
|
|
|
|
|
IsVip uint32 // 建议为0
|
|
|
|
|
|
ServerInfoLen uint32 `struc:"sizeof=ServerList"` // 服务器信息长度 ServerInfo
|
|
|
|
|
|
ServerList []ServerInfo // 服务器具体信息
|
|
|
|
|
|
FriendInfoLen uint32 `struc:"sizeof=FriendInfo"`
|
|
|
|
|
|
FriendInfo []FriendInfo // 好友id
|
|
|
|
|
|
BlackInfoLen uint32 `struc:"sizeof=BlackInfo"`
|
|
|
|
|
|
BlackInfo []BlackInfo // 黑名单id
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// NewInInfo 创建并返回一个新的 commendSvrInfo 结构体实例
|
|
|
|
|
|
// 返回的实例包含初始化的 ServerList、FriendInfo 和 BlackInfo 切片
|
|
|
|
|
|
// IsVip 和 ServerInfoLen 字段被初始化为 0
|
|
|
|
|
|
func NewInInfo() *CommendSvrInfo {
|
|
|
|
|
|
return &CommendSvrInfo{
|
|
|
|
|
|
// Handler: player.TomeeHeader{},
|
|
|
|
|
|
// MaxOnlineID: 100,
|
|
|
|
|
|
IsVip: 0,
|
|
|
|
|
|
ServerInfoLen: 0,
|
|
|
|
|
|
ServerList: make([]ServerInfo, 0),
|
|
|
|
|
|
FriendInfo: make([]FriendInfo, 0),
|
|
|
|
|
|
BlackInfo: make([]BlackInfo, 0),
|
|
|
|
|
|
//Reversed: 0,
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ServerInfo 服务器信息结构体
|
|
|
|
|
|
type ServerInfo struct {
|
|
|
|
|
|
// 连接ID, 即服务器序号
|
|
|
|
|
|
OnlineID uint32
|
|
|
|
|
|
// 当前服务器玩家在线数量, 供SWF显示
|
|
|
|
|
|
UserCnt uint32
|
|
|
|
|
|
// 服务器IP, 16字节UTF-8, 不足16补齐到16
|
|
|
|
|
|
IP string `struc:"[16]byte"` // 定长模式:16字节
|
|
|
|
|
|
// 端口
|
|
|
|
|
|
Port uint16
|
|
|
|
|
|
// 好友在线的个数
|
|
|
|
|
|
Friends uint32
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// NewServerInfo 创建新的服务器信息实例
|
|
|
|
|
|
func newServerInfo() *ServerInfo {
|
|
|
|
|
|
//getServerInfoList()
|
|
|
|
|
|
return &ServerInfo{
|
|
|
|
|
|
//OnlineID: 0,
|
|
|
|
|
|
UserCnt: 20,
|
|
|
|
|
|
//IP: "",
|
|
|
|
|
|
// Port: 0,
|
|
|
|
|
|
Friends: 1,
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type FriendInfo struct {
|
|
|
|
|
|
BlackInfo
|
|
|
|
|
|
TimePoke uint32
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type BlackInfo struct {
|
|
|
|
|
|
Userid uint32
|
|
|
|
|
|
//TimePoke uint32
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-03 15:30:41 +00:00
|
|
|
|
// func Refurh() {
|
|
|
|
|
|
// l.Lock()
|
|
|
|
|
|
// defer l.Unlock()
|
|
|
|
|
|
// GetServerInfoList = GetServerInfoList1()
|
2025-11-03 19:14:34 +08:00
|
|
|
|
|
2025-11-03 15:30:41 +00:00
|
|
|
|
// }
|
2025-11-03 19:14:34 +08:00
|
|
|
|
|
2025-11-03 15:30:41 +00:00
|
|
|
|
// func GetServer() []ServerInfo {
|
|
|
|
|
|
// l.RLock()
|
|
|
|
|
|
// defer l.RUnlock()
|
|
|
|
|
|
// return GetServerInfoList
|
2025-11-03 19:14:34 +08:00
|
|
|
|
|
2025-11-03 15:30:41 +00:00
|
|
|
|
// }
|
2025-11-03 19:14:34 +08:00
|
|
|
|
|
2025-11-03 15:30:41 +00:00
|
|
|
|
// var GetServerInfoList = GetServerInfoList1()
|
|
|
|
|
|
// var l sync.RWMutex
|