Files
bl/logic/service/server/CommendSvrInfo.go
昔念 b6231f6eb9 refactor(controller): 重构控制器处理逻辑
- 优化了 Recv 函数中的参数处理方式
- 修改了 GetServer 和 Login 函数的返回类型和逻辑
- 调整了 LoginSidInfo 和 SidInfo 结构体的方法
- 移除了未使用的 Blazingservice 接口
2025-07-16 11:30:37 +08:00

125 lines
3.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package server
import (
"blazing/common/socket/handler"
"blazing/cool"
"blazing/modules/base/service"
"blazing/modules/blazing/model"
"github.com/butoften/array"
)
//var _ entity.Blazingservice = (*SidInfo)(nil)
type SidInfo struct { //这里直接使用组合来实现将传入的原始头部数据和结构体参数序列化
Head handler.TomeeHeader `cmd:"105" struc:"[0]pad"` //玩家登录
Sid []byte `struc:"[20]byte"` // 登录会话ID固定长度16字节
ret []byte `struc:"[0]pad"`
// NotLogin uint32 `error="10001"|struc:"[0]pad"` //返回错误码 ,不序列化,仅作为错误码
// ErrorPassWord uint32 `struc:"[0]pad"`
}
func (s *SidInfo) Init() *commendSvrInfo { //默认返回方法
r := newCommendSvrInfo()
r.ServerList = GetServerInfoList()
s.Head.Set(r) //返回传参
return r
}
// CommendSvrInfo 初始连接请求信息结构体
type commendSvrInfo struct {
//Handler handler.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
}
// NewCommendSvrInfo 创建并返回一个新的 commendSvrInfo 结构体实例
// 返回的实例包含初始化的 ServerList、FriendInfo 和 BlackInfo 切片
// IsVip 和 ServerInfoLen 字段被初始化为 0
func newCommendSvrInfo() *commendSvrInfo {
return &commendSvrInfo{
// Handler: handler.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,
}
}
func GetServerInfoList() []ServerInfo {
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.NewBaseSysConfService().GetValue("server_ip")
for _, v := range ret {
tt := newServerInfo()
tt.OnlineID = v.OnlineID
// tt.UserCnt = v.UserCnt
//tt.IP = v.IP
tt.IP = ip
tt.Port = v.Port
// tt.Friends = v.Friends
ret1 = append(ret1, *tt)
}
array.Sort(&ret1, func(a ServerInfo, b ServerInfo) bool {
return a.OnlineID < b.OnlineID
})
//fmt.Printf("升序 Sort: %v\n", ret1)
return ret1
}
type FriendInfo struct {
BlackInfo
TimePoke uint32
}
type BlackInfo struct {
Userid uint32
//TimePoke uint32
}