From 3ad10e3fb3a1a91fc2de07458811570dfc511eb9 Mon Sep 17 00:00:00 2001 From: noarche <58564888+noarche@users.noreply.github.com> Date: Sun, 20 Apr 2025 22:41:06 -0400 Subject: [PATCH 1/6] update +Admin account 'admin:adminpass' +persistent messages +User auth +User registration + --- internal/server/ascii.go | 32 ++-- internal/server/errors.go | 2 +- internal/server/handler.go | 351 ++++++++++++++++++++++--------------- internal/server/server.go | 223 ++++------------------- 4 files changed, 267 insertions(+), 341 deletions(-) diff --git a/internal/server/ascii.go b/internal/server/ascii.go index c72c956..37d7e3a 100644 --- a/internal/server/ascii.go +++ b/internal/server/ascii.go @@ -2,21 +2,25 @@ package server import ( "fmt" + "os" + "strings" - "go.vxn.dev/bbs-go/internal/config" + "bbs-go/internal/config" ) -var WelcomeMessage = ` -+-------------------------------------------+ -| __ __ | -| / /_ / /_ _____ ____ ____ | -| / __ \/ __ \/ ___/_____/ __ \/ __ \ | -| / /_/ / /_/ (__ )_____/ /_/ / /_/ / | -| /_.___/_.___/____/ \__, /\____/ | -| /____/ | -| | -+-------------------------------------------+ -vxn-dev bbs-go service (` + config.Version + `) -telnet ` + config.Host + ` ` + fmt.Sprintf("%d", config.Port) + ` +var WelcomeMessage string -` +func LoadMOTD(path string) error { + content, err := os.ReadFile(path) + if err != nil { + return err + } + + msg := string(content) + msg = strings.ReplaceAll(msg, "{{VERSION}}", config.Version) + msg = strings.ReplaceAll(msg, "{{HOST}}", config.Host) + msg = strings.ReplaceAll(msg, "{{PORT}}", fmt.Sprintf("%d", config.Port)) + + WelcomeMessage = msg + return nil +} diff --git a/internal/server/errors.go b/internal/server/errors.go index 15f00fa..1b4b849 100644 --- a/internal/server/errors.go +++ b/internal/server/errors.go @@ -5,5 +5,5 @@ import ( ) var ( - ErrShutdownStarted = errors.New("the server shutdown process has been already started") + ErrShutdownStarted = errors.New("The server shutdown process has been already started") ) diff --git a/internal/server/handler.go b/internal/server/handler.go index 47fc69c..2b5ed82 100644 --- a/internal/server/handler.go +++ b/internal/server/handler.go @@ -1,71 +1,61 @@ package server import ( + "encoding/json" "fmt" "io" "net" + "os" "strings" "sync" + "time" - "go.vxn.dev/bbs-go/internal/config" + "bbs-go/internal/config" ) -const prompt = "> " -const crlf = "\r\n" -const shutdownMessage = "Shutdown" + crlf -const byeMessage = "*** Bye" + crlf -const helpMessage = "*** Commands" + crlf + - " exit --- quit the session" + crlf + crlf -const invalidCommandMessage = "*** Invalid command, try 'help'" + crlf - -// stripTelnetNegotiation removes Telnet command sequences from incoming data. -// These sequences begin with the IAC (Interpret As Command) byte (decimal 255), -// followed by one or more bytes indicating Telnet negotiation options (e.g., WILL, DO, etc.). -// See RFC 854 for details: https://datatracker.ietf.org/doc/html/rfc854 -func stripTelnetNegotiation(data []byte) []byte { - result := []byte{} - i := 0 - for i < len(data) { - if data[i] == 255 { // IAC - // Telnet command structure is typically IAC