refactor(login): 重构登录模块代码

- 移除未使用的 in.go 和 out.go 文件
- 优化 login.go 中的代码结构
- 添加新的 go.mod 依赖
This commit is contained in:
2025-07-02 22:02:56 +08:00
parent c4e80f80e4
commit 738a897c4d
6 changed files with 46 additions and 6 deletions

View File

@@ -13,9 +13,9 @@ import (
// 处理命令: 1001
func (h Controller) Login(data login.LoginSidInfo, c gnet.Conn) []byte { //这个时候player应该是空的
fmt.Println(login.CheakSession(data)) //检查结构体
fmt.Println(data.CheakSession()) //检查结构体
if tt := login.CheakSession(data); tt { //说明sid正确
if tt := data.CheakSession(); tt { //说明sid正确
service.SetPlayer(c, data.Head.UserID)

View File

@@ -0,0 +1,36 @@
package fight
import (
"context"
"fmt"
"testing"
"github.com/looplab/fsm"
)
func Test_main(t *testing.T) {
fsm := fsm.NewFSM(
"closed",
fsm.Events{
{Name: "open", Src: []string{"closed"}, Dst: "open"},
{Name: "close", Src: []string{"open"}, Dst: "closed"},
},
fsm.Callbacks{},
)
fmt.Println(fsm.Current())
err := fsm.Event(context.Background(), "open")
if err != nil {
fmt.Println(err)
}
fmt.Println(fsm.Current())
err = fsm.Event(context.Background(), "close")
if err != nil {
fmt.Println(err)
}
fmt.Println(fsm.Current())
}

View File

@@ -18,15 +18,15 @@ type LoginSidInfo struct { //这里直接使用组合来实现将传入的原始
// ErrorPassWord uint32 `struc:"[0]pad"`
}
func CheakSession(c LoginSidInfo) bool {
func (l *LoginSidInfo) CheakSession() bool {
// tt, _ := cool.CacheManager.Keys(context.Background())
//g.Dump(tt)
t1 := hex.EncodeToString(c.Sid)
t1 := hex.EncodeToString(l.Sid)
t2 := strings.Trim(t1, " ")
t, err := cool.CacheManager.Get(context.Background(), t2)
fmt.Println("后端获取", string(c.Sid), t, err)
if t.Uint32() == c.Head.UserID {
fmt.Println("后端获取", string(l.Sid), t, err)
if t.Uint32() == l.Head.UserID {
return true
}