Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4bf639f080 | |||
| a10b632f9d |
@@ -1,7 +1,7 @@
|
||||
// =============================================================================
|
||||
// Auth: alex
|
||||
// File: client.go
|
||||
// Revn: 09-12-2026 3.0.2
|
||||
// Revn: 09-15-2026 3.0.3
|
||||
// Func: ask server for a message of the day quote
|
||||
//
|
||||
// TODO: remove ioutil import
|
||||
@@ -46,7 +46,11 @@
|
||||
// 09-07-2026: added fatih/color import
|
||||
// rewrote quoteAnswer() to handle coloring escape
|
||||
// sequences
|
||||
// 09-12-2026: commented quoteAnswer()
|
||||
//*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
|
||||
//
|
||||
// =============================================================================
|
||||
|
||||
@@ -242,7 +246,7 @@ func quoteAnswer( subcom []string ) string {
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@@ -388,16 +392,18 @@ func secondEdit( subcom []string ) string {
|
||||
return "te@success"
|
||||
}
|
||||
|
||||
// edit command is a removal and an add
|
||||
// edit command is an add and then a removal
|
||||
var resp string
|
||||
resp = "cr@r2@" + subcom[0] + "@ar@"
|
||||
// server response is text to be edited
|
||||
resp = "cr@ar@"
|
||||
|
||||
fmt.Println( "as is: " + subcom[1] )
|
||||
fmt.Print( "preview: " ) // won't be useful until pretty print
|
||||
fmt.Print( "preview: " ) // show raw of current quote
|
||||
_ = quoteAnswer( subcom[1:] ) // display quote properly
|
||||
|
||||
// get user input for new quote and send
|
||||
// server response is user input for new quote
|
||||
resp = resp + in( "\nupdate -> " )
|
||||
// and position of old quote to be removed
|
||||
resp = resp + "@r2@" + subcom[0]
|
||||
return resp
|
||||
}
|
||||
|
||||
@@ -558,6 +564,7 @@ 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
|
||||
@@ -572,6 +579,7 @@ 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" )
|
||||
@@ -579,7 +587,7 @@ func main() {
|
||||
flag.Parse()
|
||||
|
||||
// FIXME get better versioning method
|
||||
VERS = "3.0.2"
|
||||
VERS = "3.0.3"
|
||||
|
||||
if vv { // display info and exit
|
||||
fmt.Println( "ekho client v" + VERS )
|
||||
@@ -592,6 +600,54 @@ 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
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
// =============================================================================
|
||||
// Auth: alex
|
||||
// File: server.go
|
||||
// Revn: 09-12-2026 3.0.1
|
||||
// Revn: 09-15-2026 3.0.2
|
||||
// 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
|
||||
// =============================================================================
|
||||
@@ -53,6 +52,8 @@
|
||||
// 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
|
||||
//
|
||||
// =============================================================================
|
||||
|
||||
@@ -187,7 +188,7 @@ func handle( command []string ) string {
|
||||
case "qr": // /qr/, quote request
|
||||
// convert message argument to string to make sure it's a
|
||||
// valid number
|
||||
num, nerr := strconv.Atoi( command[0] )
|
||||
num, nerr := strconv.Atoi( command[1] )
|
||||
// nerr will not be nil if comm[1] is not a number
|
||||
if nerr != nil {
|
||||
// formulate an error message
|
||||
@@ -205,7 +206,7 @@ func handle( command []string ) string {
|
||||
// why bad? num is -
|
||||
default:
|
||||
// good num, get quote, send off
|
||||
resp = "qa@" + qlist[num - 1] // quote answer
|
||||
resp = "qa@" + qlist[num] // quote answer
|
||||
}
|
||||
}
|
||||
case "lr": // /lr/, list request
|
||||
@@ -453,7 +454,7 @@ func main() {
|
||||
flag.Parse()
|
||||
|
||||
// FIXME get better versioning method
|
||||
VERS = "3.0.1"
|
||||
VERS = "3.0.2"
|
||||
|
||||
if vv { // display info and exit
|
||||
fmt.Println( "ekho server v" + VERS )
|
||||
|
||||
Reference in New Issue
Block a user