gotunnelserver/server/handleAgent.go

27 lines
623 B
Go
Raw Normal View History

package server
import (
"net/http"
"git.pyer.club/kingecg/gotunnelserver/util"
"github.com/gorilla/websocket"
)
func (s *Server) HandleAgent(c *websocket.Conn, r *http.Request) {
2024-11-13 22:26:29 +08:00
agentSession := NewSession(c)
agentSession.Start()
authEntity := r.Context().Value("authEntity")
if authEntity == nil {
agentSession.Close()
return
}
agentSession.Name = authEntity.(*util.AuthEntity).Username
2024-11-13 22:26:29 +08:00
s.agentSession[agentSession.Id] = agentSession
2024-11-15 16:49:01 +08:00
command := NcmdSession(agentSession.Id)
2024-11-13 22:26:29 +08:00
agentSession.Send(command)
agentSession.Once("Close", func(p ...interface{}) {
delete(s.agentSession, agentSession.Id)
})
}