chat and debugs.

This commit is contained in:
dalbodeule
2025-10-14 10:16:18 +09:00
parent 301113a560
commit c55d3eda4f
2 changed files with 433 additions and 5 deletions

28
main.go
View File

@@ -1,7 +1,7 @@
package main
import (
"io"
"fmt"
"log"
"os"
@@ -11,6 +11,28 @@ import (
"github.com/joho/godotenv"
)
func sessionHandler(s ssh.Session) {
ptyReq, _, isPty := s.Pty()
if !isPty {
_, _ = fmt.Fprintln(s, "Err: PTY requires. Reconnect with -t option.")
_ = s.Exit(1)
return
}
remote := s.RemoteAddr().String()
username := s.User()
log.Printf("[sshchat] %s connected. %s", username, remote)
client := utils.NewClient(s, ptyReq.Window.Height, ptyReq.Window.Width, username, remote)
defer func() {
client.Close()
log.Printf("[sshchat] %s disconnected. %s", username, remote)
}()
client.EventLoop()
}
func main() {
err := godotenv.Load()
if err != nil {
@@ -33,10 +55,6 @@ func main() {
}
}
sessionHandler := func(s ssh.Session) {
_, _ = io.WriteString(s, "Hello World\n")
}
s := &ssh.Server{
Addr: ":" + port,
Handler: sessionHandler,