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

@@ -21,7 +21,7 @@ func (g *GatewayWsServer) OnOpen(conn socket.ISocketConn) ([]byte, socket.Action
func (g *GatewayWsServer) OnHandShake(conn socket.ISocketConn) {
token, ok := conn.GetParam("token").(string)
if !ok || len(token) == 0 {
if !ok || token == "" {
g.logger.Warnf("token is not string")
_ = conn.Close()
return
@@ -30,17 +30,17 @@ func (g *GatewayWsServer) OnHandShake(conn socket.ISocketConn) {
if err != nil {
_ = conn.Close()
}
if oldClient := ws_handler2.UserMgr.GetByUID(int32(t)); oldClient != nil {
if oldClient := ws_handler2.UserMgr.GetByUSN(int64(t)); oldClient != nil {
oldClient.CloseClient()
}
client := ws_handler2.NewClient(int32(t), conn)
ws_handler2.UserMgr.Add(int32(t), client)
client := ws_handler2.NewClient(int64(t), conn)
ws_handler2.UserMgr.Add(int64(t), client)
conn.SetParam("client", client)
}
func (g *GatewayWsServer) OnMessage(conn socket.ISocketConn, bytes []byte) socket.Action {
client, ok := conn.GetParam("client").(*ws_handler2.Client)
if !ok || client.UID == 0 {
if !ok || client.USN == 0 {
return socket.Close
}
client.OnEvent(&ws_handler2.ClientEvent{Msg: bytes})
@@ -49,7 +49,7 @@ func (g *GatewayWsServer) OnMessage(conn socket.ISocketConn, bytes []byte) socke
func (g *GatewayWsServer) OnPong(conn socket.ISocketConn) {
client, ok := conn.GetParam("client").(*ws_handler2.Client)
if !ok || client.UID == 0 {
if !ok || client.USN == 0 {
return
}
client.OnEvent(&ws_handler2.PongEvent{})