refactor(login): 重构登录模块代码
- 移除未使用的 in.go 和 out.go 文件 - 优化 login.go 中的代码结构 - 添加新的 go.mod 依赖
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
module github.com/ECUST-XX/xml
|
||||
|
||||
go 1.20
|
||||
|
||||
require github.com/looplab/fsm v1.0.3 // indirect
|
||||
|
||||
2
common/serialize/xml/go.sum
Normal file
2
common/serialize/xml/go.sum
Normal file
@@ -0,0 +1,2 @@
|
||||
github.com/looplab/fsm v1.0.3 h1:qtxBsa2onOs0qFOtkqwf5zE0uP0+Te+wlIvXctPKpcw=
|
||||
github.com/looplab/fsm v1.0.3/go.mod h1:PmD3fFvQEIsjMEfvZdrCDZ6y8VwKTwWNjlpEr6IKPO4=
|
||||
@@ -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)
|
||||
|
||||
|
||||
36
logic/service/fight/fsm_test.go
Normal file
36
logic/service/fight/fsm_test.go
Normal 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())
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user