refactor(login): 修改登录服务相关功能
- 修改端口配置:将 .vscode/launch.json 中的端口从 27777 改为 27000 - 优化会话管理:更新 session 包中的 GetSession 和 SaveSession 函数,使用新的 sessionprx 变量 - 调整登录逻辑:修改 login 控制器中的 Login 函数,优化会话验证流程 - 扩展服务器信息结构:在 CommendSvrInfo 结构中添加好友和黑名单信息字段 - 修复 GetSessionId 函数:改进错误处理,确保返回值的一致性 - 更新服务器配置:修改 ServerR.xml 中的 EmailLogin URL 为本地地址 - 其他 minor changes:删除了一些不必要的注释和打印语句
This commit is contained in:
2
.vscode/launch.json
vendored
2
.vscode/launch.json
vendored
@@ -19,7 +19,7 @@
|
|||||||
"request": "launch",
|
"request": "launch",
|
||||||
"mode": "auto",
|
"mode": "auto",
|
||||||
"cwd": "${workspaceFolder}",
|
"cwd": "${workspaceFolder}",
|
||||||
"args": ["-port=27777"],
|
"args": ["-port=27000"],
|
||||||
"program": "${workspaceFolder}/logic"
|
"program": "${workspaceFolder}/logic"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,13 +3,14 @@ package session
|
|||||||
import (
|
import (
|
||||||
"blazing/cool"
|
"blazing/cool"
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gogf/gf/v2/os/gctx"
|
"github.com/gogf/gf/v2/os/gctx"
|
||||||
)
|
)
|
||||||
|
|
||||||
var session = "blazing:session:"
|
var sessionprx = "blazing:session:"
|
||||||
|
|
||||||
// GetSession 通过给定的键从缓存中获取会话数据。
|
// GetSession 通过给定的键从缓存中获取会话数据。
|
||||||
// 该函数主要执行以下操作:
|
// 该函数主要执行以下操作:
|
||||||
@@ -24,18 +25,18 @@ func GetSession(t1 string) (userid uint32, err error) {
|
|||||||
|
|
||||||
// 从缓存中获取与键 t2 关联的数据。这里假设 cool.CacheManager 已经初始化,并且 Get 方法可用。
|
// 从缓存中获取与键 t2 关联的数据。这里假设 cool.CacheManager 已经初始化,并且 Get 方法可用。
|
||||||
// 此处不处理 err,可能是因为上层调用者期望处理这个错误,或者在特定上下文中,错误被视为可接受。
|
// 此处不处理 err,可能是因为上层调用者期望处理这个错误,或者在特定上下文中,错误被视为可接受。
|
||||||
t, err := cool.CacheManager.Get(context.Background(), session+t2)
|
t, err := cool.CacheManager.Get(context.Background(), sessionprx+t2)
|
||||||
|
|
||||||
userid = t.Uint32()
|
userid = t.Uint32()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
func SaveSession(session string, userid string) error {
|
func SaveSession(session string, userid string) error {
|
||||||
|
|
||||||
err := cool.CacheManager.Set(gctx.New(), session+strings.Trim(session, " "), userid, time.Hour*24)
|
err := cool.CacheManager.Set(gctx.New(), sessionprx+strings.Trim(session, " "), userid, time.Hour*24)
|
||||||
// gsvc.SetRegistry(etcd.New(`127.0.0.1:2379`))
|
// gsvc.SetRegistry(etcd.New(`127.0.0.1:2379`))
|
||||||
//t, err := cool.CacheManager.Contains(context.Background(), strings.Trim(session, " "))
|
//t, err := cool.CacheManager.Contains(context.Background(), strings.Trim(session, " "))
|
||||||
|
|
||||||
// //fmt.Println("前端获取", session, t, err)
|
fmt.Println("前端获取", session, err)
|
||||||
// if t {
|
// if t {
|
||||||
// return nil
|
// return nil
|
||||||
// }
|
// }
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import (
|
|||||||
// 处理命令: 1001
|
// 处理命令: 1001
|
||||||
func (h Controller) Login(data login.LoginSidInfo, c gnet.Conn) []byte { //这个时候player应该是空的
|
func (h Controller) Login(data login.LoginSidInfo, c gnet.Conn) []byte { //这个时候player应该是空的
|
||||||
|
|
||||||
fmt.Println(data.CheakSession()) //检查结构体
|
//fmt.Println(data.CheakSession()) //检查结构体
|
||||||
|
|
||||||
if tt := data.CheakSession(); tt { //说明sid正确
|
if tt := data.CheakSession(); tt { //说明sid正确
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,10 @@ type CommendSvrInfo struct {
|
|||||||
IsVip uint32 // 建议为0
|
IsVip uint32 // 建议为0
|
||||||
ServerInfoLen uint32 `struc:"sizeof=ServerList"` // 服务器信息长度 ServerInfo
|
ServerInfoLen uint32 `struc:"sizeof=ServerList"` // 服务器信息长度 ServerInfo
|
||||||
ServerList []ServerInfo // 服务器具体信息
|
ServerList []ServerInfo // 服务器具体信息
|
||||||
Reversed uint32 // 保留字段
|
FriendInfoLen uint32 `struc:"sizeof=FriendInfo"`
|
||||||
|
FriendInfo []FriendInfo // 好友id
|
||||||
|
BlackInfoLen uint32 `struc:"sizeof=BlackInfo"`
|
||||||
|
BlackInfo []BlackInfo // 黑名单id
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCommendSvrInfo() *CommendSvrInfo {
|
func NewCommendSvrInfo() *CommendSvrInfo {
|
||||||
@@ -17,7 +20,9 @@ func NewCommendSvrInfo() *CommendSvrInfo {
|
|||||||
IsVip: 0,
|
IsVip: 0,
|
||||||
ServerInfoLen: 0,
|
ServerInfoLen: 0,
|
||||||
ServerList: make([]ServerInfo, 0),
|
ServerList: make([]ServerInfo, 0),
|
||||||
Reversed: 0,
|
FriendInfo: make([]FriendInfo, 0),
|
||||||
|
BlackInfo: make([]BlackInfo, 0),
|
||||||
|
//Reversed: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,3 +44,13 @@ type ServerInfo struct {
|
|||||||
func NewServerInfo() *ServerInfo {
|
func NewServerInfo() *ServerInfo {
|
||||||
return &ServerInfo{}
|
return &ServerInfo{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type FriendInfo struct {
|
||||||
|
BlackInfo
|
||||||
|
TimePoke uint32
|
||||||
|
}
|
||||||
|
|
||||||
|
type BlackInfo struct {
|
||||||
|
Userid uint32
|
||||||
|
//TimePoke uint32
|
||||||
|
}
|
||||||
|
|||||||
@@ -22,10 +22,10 @@ func (l *LoginSidInfo) CheakSession() bool {
|
|||||||
t1 := hex.EncodeToString(l.Sid)
|
t1 := hex.EncodeToString(l.Sid)
|
||||||
|
|
||||||
t, err := session.GetSession(t1)
|
t, err := session.GetSession(t1)
|
||||||
fmt.Println("后端获取", string(l.Sid), t, err)
|
if err != nil {
|
||||||
if t == l.Head.UserID {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
fmt.Println("后端获取", t1, t, err)
|
||||||
|
|
||||||
|
return t == l.Head.UserID
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/hex"
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
_ "github.com/gogf/gf/contrib/nosql/redis/v2"
|
_ "github.com/gogf/gf/contrib/nosql/redis/v2"
|
||||||
"github.com/panjf2000/gnet/v2"
|
"github.com/panjf2000/gnet/v2"
|
||||||
|
|
||||||
@@ -59,7 +56,7 @@ func recv(c gnet.Conn, data handler.TomeeHeader) {
|
|||||||
ret.ServerList = append(ret.ServerList, *lofin)
|
ret.ServerList = append(ret.ServerList, *lofin)
|
||||||
|
|
||||||
tt := core.Pack(data, ret)
|
tt := core.Pack(data, ret)
|
||||||
fmt.Println(hex.EncodeToString(tt))
|
//fmt.Println(hex.EncodeToString(tt))
|
||||||
c.Write(tt)
|
c.Write(tt)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,7 +62,11 @@ func (c *BlazingController) GetSession(ctx context.Context, req *SessionReq) (re
|
|||||||
res.Code = 400
|
res.Code = 400
|
||||||
res.Msg = err.Error()
|
res.Msg = err.Error()
|
||||||
}
|
}
|
||||||
|
if res1 == nil {
|
||||||
|
res.Code = 400
|
||||||
|
res.Msg = err.Error()
|
||||||
|
return
|
||||||
|
}
|
||||||
accountID := res1.ID
|
accountID := res1.ID
|
||||||
retsid, sid, err := biazing_service.GetSessionId(accountID)
|
retsid, sid, err := biazing_service.GetSessionId(accountID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -41,12 +41,12 @@ func (s *LoginService) GetSessionId(accountID uint) (string, string, error) {
|
|||||||
binary.BigEndian.PutUint32(buf2, uint32(accountID))
|
binary.BigEndian.PutUint32(buf2, uint32(accountID))
|
||||||
|
|
||||||
//fmt.Printf("小端序: %v (十六进制: %x)\n", buf2, buf2) // 输出: [252 255 255 255] (0xFCFFFFFF)
|
//fmt.Printf("小端序: %v (十六进制: %x)\n", buf2, buf2) // 输出: [252 255 255 255] (0xFCFFFFFF)
|
||||||
|
ttid, _ := hex.DecodeString(tt)
|
||||||
//fmt.Println(bytes, "随机字节")
|
//fmt.Println(bytes, "随机字节")
|
||||||
ret := append(bytes, hex.EncodeToString([]byte(tt))...)
|
ret := append(buf2, ttid...)
|
||||||
ret = append(ret, bytes...)
|
ret = append(ret, bytes...)
|
||||||
|
|
||||||
return string(ret), tt, nil
|
return hex.EncodeToString(ret), tt, nil
|
||||||
// /t1.
|
// /t1.
|
||||||
// 以上过程只需全局一次,且应在生成ID之前完成。
|
// 以上过程只需全局一次,且应在生成ID之前完成。
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
<ipConfig>
|
<ipConfig>
|
||||||
<http url="/ip.txt"/>
|
<http url="/ip.txt"/>
|
||||||
<!--http url="http://login.51seer.com/ip.txt"/-->
|
<!--http url="http://login.51seer.com/ip.txt"/-->
|
||||||
<EmailLogin url="http://14.103.145.161:8080/"/>
|
<EmailLogin url="http://127.0.0.1:8080/"/>
|
||||||
<Email ip="10.1.1.4" port="7777"/>
|
<Email ip="10.1.1.4" port="7777"/>
|
||||||
<DirSer ip="10.1.1.4" port="7777"/>
|
<DirSer ip="10.1.1.4" port="7777"/>
|
||||||
<Visitor ip="10.1.1.4" port="7777"/>
|
<Visitor ip="10.1.1.4" port="7777"/>
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user