From dae792a0f5ad505383a249616cde403f1247fa2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20Nu=C8=9Biu?= Date: Thu, 9 Nov 2017 23:03:00 +0200 Subject: [PATCH] Adding prompt for the client --- server/server/connection.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/server/server/connection.go b/server/server/connection.go index 1c36664..b4f3709 100644 --- a/server/server/connection.go +++ b/server/server/connection.go @@ -66,6 +66,13 @@ func HandleConnection(client Client) { // Process input input := bufio.NewScanner(client.Connection()) + + stack, ok := client.Stack().(*StringStack) + if ok == false { + panic("Cannot cast client.Stack() to *StringStack!") + } + + prompt(client, stack) for input.Scan() { log.Println(client.Connection().RemoteAddr(), ":", input.Text()) @@ -74,8 +81,17 @@ func HandleConnection(client Client) { log.Println(err) io.WriteString(client.Connection(), err.Error()+"\n") } + prompt(client, stack) } // Client has left. log.Println(client.Connection().RemoteAddr(), "has disconnected.") } + +func prompt(client Client, stack *StringStack) (int, error) { + var str string + if !stack.IsEmpty() { + str = stack.Top().(string) + " " + } + return io.WriteString(client.Connection(), str+"ftp> ") +}