feat 网关鉴权

This commit is contained in:
2025-12-22 18:04:36 +08:00
parent 69cc960fe5
commit 670140e7d3
68 changed files with 1424 additions and 492 deletions

View File

@@ -22,17 +22,17 @@ type Client struct {
cancel context.CancelFunc // 取消上下文
heartBeat time.Time // 最后一次心跳
UID int32 // 用户ID
USN int64 // 用户ID
SceneSID int64 // 场景服ID
InstanceID int32 // 副本ID副本类型
UniqueNo int64 // 副本唯一编号
}
func NewClient(uid int32, conn socket.ISocketConn) *Client {
func NewClient(usn int64, conn socket.ISocketConn) *Client {
client := &Client{
UID: uid,
USN: usn,
conn: conn,
logger: log.GetLogger().Named(fmt.Sprintf("uid:%v", uid)),
logger: log.GetLogger().Named(fmt.Sprintf("usn:%v", usn)),
heartBeat: time.Now(),
mailChan: make(chan Event, 1024),
}
@@ -99,7 +99,7 @@ func (c *Client) onClose() {
close(c.mailChan)
c.mailChan = nil
}
UserMgr.Delete(c.UID)
UserMgr.Delete(c.USN)
c.onLeave()
c.Done()
}

View File

@@ -48,7 +48,7 @@ func (c *Client) onEnter(msg *sc_pb.C2S_EnterInstance) {
return
}
resp, err := client.Enter(c.ctx, &grpc_pb.EnterReq{
UID: c.UID,
USN: c.USN,
GatewaySID: GatewaySID,
InstanceID: msg.InstanceID,
})
@@ -69,7 +69,7 @@ func (c *Client) onLeave() {
return
}
_, err = client.Leave(c.ctx, &grpc_pb.LeaveReq{
UID: c.UID,
USN: c.USN,
GatewaySID: GatewaySID,
InstanceID: c.InstanceID,
UniqueNo: c.UniqueNo,
@@ -86,7 +86,7 @@ func (c *Client) onAction(msg *sc_pb.C2S_Action) {
}
if err := stream_client.SendMessageToScene(c.SceneSID, stream_client.FunAction, &grpc_pb.ActionReq{
UniqueNo: c.UniqueNo,
UID: c.UID,
USN: c.USN,
Action: int32(msg.Action),
DirX: msg.DirX,
DirY: msg.DirY,

View File

@@ -7,33 +7,33 @@ import (
var UserMgr *userManager
type userManager struct {
userMap map[int32]*Client
userMap map[int64]*Client
sync.RWMutex
}
func init() {
UserMgr = &userManager{
userMap: make(map[int32]*Client),
userMap: make(map[int64]*Client),
}
}
func (m *userManager) Add(uid int32, client *Client) {
func (m *userManager) Add(usn int64, client *Client) {
m.Lock()
defer m.Unlock()
m.userMap[uid] = client
m.userMap[usn] = client
}
func (m *userManager) Delete(uid int32) {
func (m *userManager) Delete(usn int64) {
m.Lock()
defer m.Unlock()
delete(m.userMap, uid)
delete(m.userMap, usn)
}
func (m *userManager) GetAll() map[int32]*Client {
func (m *userManager) GetAll() map[int64]*Client {
m.RLock()
defer m.RUnlock()
copyMap := make(map[int32]*Client, len(m.userMap))
copyMap := make(map[int64]*Client, len(m.userMap))
for k, v := range m.userMap {
copyMap[k] = v
}
@@ -51,8 +51,8 @@ func (m *userManager) GetAllInterface() []interface{} {
return r
}
func (m *userManager) GetByUID(uid int32) *Client {
func (m *userManager) GetByUSN(usn int64) *Client {
m.RLock()
defer m.RUnlock()
return m.userMap[uid]
return m.userMap[usn]
}