1 Commits

Author SHA1 Message Date
oracle a7183cd560 hotfix -> fixed Atoi bug and quote OOB error 2026-09-12 23:26:39 -04:00
6 changed files with 55 additions and 194 deletions
+2 -2
View File
@@ -65,8 +65,7 @@ The client uses the following flags
-ip <ip:port> - specify alternate server destination
-l - list all quotes
-r [i] - remove; may be run with or without argument
-e [i] - edit; may be run with or without argument
-c - list color format specifiers with examples
-e - edit
-s <i> - specify the size of the receipt buffer
-v - display version and exit
-vv - display version and about info and exit
@@ -83,6 +82,7 @@ The server uses the following flags
- Log all uses/transaction data each day
- Request, send, and receive the logfile
- User-specific quotes/quotefiles
- Colored printing and coloring quotes
[golang]: <https://go.dev/doc/install>
[just]: <https://github.com/casey/just>
+10 -141
View File
@@ -1,7 +1,7 @@
// =============================================================================
// Auth: alex
// File: client.go
// Revn: 09-16-2026 4.0.0
// Revn: 09-06-2026 3.0.0
// Func: ask server for a message of the day quote
//
// TODO: remove ioutil import
@@ -43,16 +43,6 @@
// 09-04-2026: rewrote in() with bufio instead of scanln
//#09-06-2026: fixed blank message error in secondEdit()
// comments
// 09-07-2026: added fatih/color import
// rewrote quoteAnswer() to handle coloring escape
// sequences
//*09-12-2026: commented quoteAnswer()
//*09-15-2026: added -c flag and color code example printing
// changed edit command to be add and then remove instead
// of remove and then add, fixing server OOB error when
// editting only quote in list
//#09-15-2026: finished pretty print implementation
// made listAnswer() print list with color print
//
// =============================================================================
@@ -70,7 +60,6 @@ import (
"strconv" // Atoi, Itoa
"strings" // Split
"time" // Now, UnixNano
"github.com/fatih/color" // color.New, Printf, Println
)
@@ -180,75 +169,7 @@ func sizeAnswer( subcom []string ) string {
// receive quote, print
func quoteAnswer( subcom []string ) string {
// split subcommand over spaces
words := strings.Split( subcom[0], " " )
// default text is white
c := color.New( color.FgWhite )
for _, w := range words {
// if first char is normal color escape character
if string( w[0] ) == "$" {
// see which color is requested
switch string( w[1] ) {
case "1": // 1 -> red
c = color.New( color.FgRed )
case "2": // 2 -> yellow
c = color.New( color.FgYellow )
case "3": // 3 -> green
c = color.New( color.FgGreen )
case "4": // 4 -> blue
c = color.New( color.FgBlue )
case "5": // 5 -> cyan
c = color.New( color.FgCyan )
case "6": // 6 -> magenta
c = color.New( color.FgMagenta )
case "7": // 7 -> black
c = color.New( color.FgBlack )
case "0": // 0 -> white again
c = color.New( color.FgWhite )
default:
// none of these, continue with the last color
}
// color chosen, print string with trailing space, minus
// first two characters
c.Printf( "%s ", w[2:] )
// if first char is bold color escape character
} else if string( w[0] ) == "#" {
// see which color is requested
switch string( w[1] ) {
case "1": // 1 -> red
c = color.New( color.FgRed, color.Bold )
case "2": // 2 -> yellow
c = color.New( color.FgYellow, color.Bold )
case "3": // 3 -> green
c = color.New( color.FgGreen, color.Bold )
case "4": // 4 -> blue
c = color.New( color.FgBlue, color.Bold )
case "5": // 5 -> cyan
c = color.New( color.FgCyan, color.Bold )
case "6": // 6 -> magenta
c = color.New( color.FgMagenta, color.Bold )
case "7": // 7 -> black
c = color.New( color.FgBlack, color.Bold )
case "0": // 0 -> white again
c = color.New( color.FgWhite, color.Bold )
default:
// none of these, continue with the last color
}
// color chosen, print string with trailing space, minus
// first two characters
c.Printf( "%s ", w[2:] )
} else { // TODO add if for if w[0] is "\"
// using the currently selected color, print the next work
// and a trailing space
c.Printf( "%s ", w )
}
}
c.Println() // print final newline
//fmt.Println( subcom[0] ) // whole-ass just print quote
fmt.Println( subcom[0] ) // whole-ass just print quote
return "te@success" // set transaction end message
}
@@ -322,8 +243,7 @@ func listAnswer( subcom []string ) string {
quotes := strings.Split( subcom[0], "\n" )
for p, v := range quotes { // iterate over quotes
// print num of quote, followed by that quote
fmt.Print( p + 1, "\t" )
quoteAnswer( []string{ v } )
fmt.Println( p + 1, "\t", v )
}
resp = "te@success" // set transaction end message
}
@@ -395,18 +315,16 @@ func secondEdit( subcom []string ) string {
return "te@success"
}
// edit command is an add and then a removal
// edit command is a removal and an add
var resp string
resp = "cr@ar@"
resp = "cr@r2@" + subcom[0] + "@ar@"
// server response is text to be edited
fmt.Println( "as is: " + subcom[1] )
fmt.Print( "preview: " ) // show raw of current quote
fmt.Print( "preview: " ) // won't be useful until pretty print
_ = quoteAnswer( subcom[1:] ) // display quote properly
// server response is user input for new quote
// get user input for new quote and send
resp = resp + in( "\nupdate -> " )
// and position of old quote to be removed
resp = resp + "@r2@" + subcom[0]
return resp
}
@@ -562,12 +480,12 @@ func handle( conn net.Conn ) {
//var qsize int // keep track of num of quotes
var conn net.Conn // keep track of connection
// global flag variables
var add bool // add new quotes to quote file ( on server )
var remove bool // remove quotes from quote file ( on server )
var list bool // request entire quote file from server
var edit bool // edit a pre-existing quote from quote file ( on server )
var co bool // list color codes
var dest string // provide a new destination ip and port
var tsize int // size of transmission buffer
var VERS string // version
@@ -582,7 +500,6 @@ func main() {
flag.BoolVar( &remove, "r", false, "remove quote from list" )
flag.BoolVar( &list, "l", false, "print quote list" )
flag.BoolVar( &edit, "e", false, "edit quote from list" )
flag.BoolVar( &co, "c", false, "list color codes with examples" )
flag.StringVar( &dest, "ip", "127.0.0.1:1300", "ip:port of server" )
flag.IntVar( &tsize, "s", 256, "transmission size ( bytes )" )
flag.BoolVar( &v, "v", false, "display version and exit" )
@@ -590,7 +507,7 @@ func main() {
flag.Parse()
// FIXME get better versioning method
VERS = "4.0.0"
VERS = "3.0.0"
if vv { // display info and exit
fmt.Println( "ekho client v" + VERS )
@@ -603,54 +520,6 @@ func main() {
return
}
if co { // display color codes and examples and quit
// print color code and color example on same line
// color.XYZ print inserts newline
fmt.Print( "$1: " )
color.Red( "red" )
fmt.Print( "$2: " )
color.Yellow( "yellow" )
fmt.Print( "$3: " )
color.Green( "green" )
fmt.Print( "$4: " )
color.Blue( "blue" )
fmt.Print( "$5: " )
color.Cyan( "cyan" )
fmt.Print( "$6: " )
color.Magenta( "magenta" )
fmt.Print( "$7: " )
color.Black( "black" )
fmt.Print( "$0: " )
color.White( "white (reset)" )
// print bold codes
fmt.Print( "\n#1: " )
// create bold color object, change out actual color and print
bold := color.New( color.Bold, color.FgRed )
bold.Println( "bold red" )
fmt.Print( "#2: " )
bold.Add( color.FgYellow )
bold.Println( "bold yellow" )
fmt.Print( "#3: " )
bold.Add( color.FgGreen )
bold.Println( "bold green" )
fmt.Print( "#4: " )
bold.Add( color.FgBlue )
bold.Println( "bold blue" )
fmt.Print( "#5: " )
bold.Add( color.FgCyan )
bold.Println( "bold Cyan" )
fmt.Print( "#6: " )
bold.Add( color.FgMagenta )
bold.Println( "bold magenta" )
fmt.Print( "#7: " )
bold.Add( color.FgBlack )
bold.Println( "bold black" )
fmt.Print( "#0: " )
bold.Add( color.FgWhite )
bold.Println( "bold white" )
return // bail
}
service := dest // declare server ip:port
// create address object
-11
View File
@@ -1,11 +0,0 @@
module earth-1.net/oracle/ekho
go 1.27.1
require github.com/fatih/color v1.19.0
require (
github.com/mattn/go-colorable v0.1.14 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
golang.org/x/sys v0.42.0 // indirect
)
-9
View File
@@ -1,9 +0,0 @@
github.com/fatih/color v1.19.0 h1:Zp3PiM21/9Ld6FzSKyL5c/BULoe/ONr9KlbYVOfG8+w=
github.com/fatih/color v1.19.0/go.mod h1:zNk67I0ZUT1bEGsSGyCZYZNrHuTkJJB+r6Q9VuMi0LE=
github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE=
github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.42.0 h1:omrd2nAlyT5ESRdCLYdm3+fMfNFE/+Rf4bDIQImRJeo=
golang.org/x/sys v0.42.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
+1 -1
View File
@@ -1 +1 @@
thank you for using $1ekho
thank you for using ekho
+22 -10
View File
@@ -1,13 +1,14 @@
// =============================================================================
// Auth: alex
// File: server.go
// Revn: 09-15-2026 3.0.2
// Revn: 09-06-2026 3.0.0
// Func: host MOTD connection
//
// TODO: add user-specific prints
// write usage and errors to logfile
// remove ioutil import
// send logfile to client on request
// add color printing to qfile
// add flags?
// add more /codes/ to handle
// =============================================================================
@@ -51,10 +52,11 @@
// 05-12-2026: added v and vv input flags
// 09-05-2026: buncha shit happened, dropped the commit
//#09-06-2026: added /e1/, /e2/, and /cr/, got edit working
// 09-12-2026: minor comments in receive()
//*09-15-2026: fixed OOB error in /qa/ for perhaps the last time
// fixed bad Atoi conversion bug for perhaps the last time
//
//H09-12-2026: minor comments in receive()
// hotfix -> accidentally trying to Atoi the command
// instead of the argument
// hotfix -> subtracting 1 from int before getting quote
// from list
// =============================================================================
package main
@@ -153,16 +155,25 @@ func receive( conn net.Conn ) {
n, err := conn.Read( buffer[:] )
checkN( err, conn ) // make sure read worked
// message anatomy
// command@number[@user]
// @ @ delimiter
// command command, like list request or quote request
// number sequence or quote number
// user quote username if applicable, default if not give
// add request message anatomy
// command@quote[@user]
// quote quote to be added
// user quote username, default if not given
// cast message to string, take first n bytes, split over @
command := strings.Split( string( buffer[:n] ), "@" )
// if command is to end transaction
if command[0] == "te" {
conn.Close() // end transaction
return // and bail
conn.Close()
return
}
// process command get response
resp := handle( command )
// write response to client
@@ -431,6 +442,7 @@ func handle( command []string ) string {
// globals
var qlist []string // list of quotes
//var qlist = make( map[string][]string )
var qfile string // file object
var tsize int // size of transmission buffer
var VERS string // version
@@ -454,7 +466,7 @@ func main() {
flag.Parse()
// FIXME get better versioning method
VERS = "3.0.2"
VERS = "3.0.0"
if vv { // display info and exit
fmt.Println( "ekho server v" + VERS )