2024-11-13 00:00:06 +08:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2024-11-16 13:18:22 +08:00
|
|
|
"git.pyer.club/kingecg/gotunnelserver/util"
|
2024-11-13 00:00:06 +08:00
|
|
|
"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()
|
2024-11-16 13:18:22 +08:00
|
|
|
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)
|
2024-11-16 13:18:22 +08:00
|
|
|
agentSession.Once("Close", func(p ...interface{}) {
|
|
|
|
delete(s.agentSession, agentSession.Id)
|
|
|
|
})
|
2024-11-13 00:00:06 +08:00
|
|
|
}
|