Skip to content

Commit cb97839

Browse files
committed
added a warning message if the message is empty
1 parent 4a67179 commit cb97839

File tree

4 files changed

+11
-4
lines changed

4 files changed

+11
-4
lines changed

.DS_Store

6 KB
Binary file not shown.

chat/chat

0 Bytes
Binary file not shown.

chat/client.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,15 @@ func (c *client) readInput() {
2020
if err != nil {
2121
return
2222
}
23-
2423
msg = strings.Trim(msg, "\r\n")
25-
2624
args := strings.Split(msg, " ")
2725
cmd := strings.TrimSpace(args[0])
28-
26+
//make sure that the length of the input is at least 1
27+
if len(args) == 1 && args[0] != "/help" && args[0] != "/rooms" {
28+
c.err(fmt.Errorf("Cannot pass empty characters after the commands except the help command.\n" +
29+
"Example of a valid Command: /msg Once upon a time in a far far away galaxy" +
30+
"\n"))
31+
}
2932
switch cmd {
3033
case "/nick":
3134
c.commands <- command{

chat/server.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ func (s *server) newClient(conn net.Conn) {
5050
}
5151

5252
func (s *server) nick(c *client, nick string) {
53-
c.nick = nick
53+
if nick != "" {
54+
c.nick = nick
55+
} else {
56+
log.Printf("Bc error hogga\n")
57+
}
5458
c.msg(fmt.Sprintf("all right, I will call you %s", nick))
5559
}
5660

0 commit comments

Comments
 (0)