feat 网关鉴权
This commit is contained in:
@@ -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{})
|
||||
|
||||
Reference in New Issue
Block a user