Files
bl/login/main.go
昔念 e25fe776eb refactor(common): 重构 Pack 函数并优化数据处理
- 重构了 Pack 函数,支持处理不同类型的 data 参数
- 优化了数据打包过程,使用反射处理结构体和切片
- 修改了 TomeeHeader 结构体,使用 EnumCommandID 类型
- 调整了 login 相关的结构体定义
- 优化了 main 函数中的数据处理逻辑
2025-06-27 00:30:15 +08:00

66 lines
1.3 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 main
import (
"encoding/hex"
"fmt"
_ "github.com/gogf/gf/contrib/nosql/redis/v2"
"github.com/panjf2000/gnet/v2"
"blazing/common/core"
"blazing/common/socket"
"blazing/common/socket/handler"
_ "blazing/contrib/files/local"
"blazing/cool"
"blazing/logic/service/login"
// Minio按需启用
// _ "blazing/contrib/files/minio"
// 阿里云OSS按需启用
// _ "blazing/contrib/files/oss"
// _ "blazing/contrib/drivers/sqlite"
_ "blazing/contrib/drivers/mysql"
//_ "blazing/contrib/drivers/pgsql"
_ "blazing/modules"
"github.com/gogf/gf/v2/os/gctx"
"blazing/login/internal/cmd"
)
func main() {
go Start(cool.Config.Port)
cmd.Main.Run(gctx.New())
}
func Start(port string) {
head := handler.NewTomeeHandler()
head.Callback = recv
socket.NewServer(socket.WithPort(port), socket.WithCORS(), socket.WithSocketHandler(head)).Start()
}
func recv(c gnet.Conn, data handler.TomeeHeader) {
ret := login.NewCommendSvrInfo()
lofin := login.NewServerInfo()
lofin.OnlineID = 1
lofin.UserCnt = 77
lofin.IP = "127.0.0.1"
lofin.Port = 27777
lofin.Friends = 1
ret.ServerList = append(ret.ServerList, *lofin)
tt := core.Pack(data.UserID, data.CMD, ret, 0)
fmt.Println(hex.EncodeToString(tt))
c.Write(tt)
}