"feat(socket): 添加跨域请求处理并集成enum依赖,优化TCP连接数据注入"

This commit is contained in:
1
2025-06-22 00:50:40 +00:00
parent ef3ce43a14
commit 8c9fbbb3a8
38 changed files with 728 additions and 409 deletions

View File

@@ -0,0 +1,41 @@
package info
// ServerInfo 服务器信息结构体
type ServerInfo struct {
// 连接ID, 即服务器序号
OnlineID uint32
// 当前服务器玩家在线数量, 供SWF显示
UserCnt uint32
// 服务器IP, 16字节UTF-8, 不足16补齐到16
IP []byte `v:"FIXED_LENGTH|length:16"`
// 端口
Port uint16
// 好友在线的个数
Friends uint32
}
// NewServerInfo 创建新的服务器信息实例
func NewServerInfo() *ServerInfo {
return &ServerInfo{
OnlineID: 0,
UserCnt: 0,
IP: []byte{},
Port: 0,
Friends: 0,
}
}
// // SetIP 设置IP地址并自动填充到16字节
// func (s *ServerInfo) SetIP(ip string) {
// copy(s.IP[:], ip)
// if len(ip) < 16 {
// for i := len(ip); i < 16; i++ {
// s.IP[i] = 0 // 用0填充剩余字节
// }
// }
// }
// // GetIP 获取IP地址去除填充的0
// func (s *ServerInfo) GetIP() string {
// return strings.TrimRight(string(s.IP[:]), "\x00")
// }