Skip to content

Commit

Permalink
Merge pull request #35 from drumglow/main
Browse files Browse the repository at this point in the history
Unified hello handling with chat server requirements
  • Loading branch information
fzovpec authored Apr 11, 2024
2 parents 993045e + 66fd1b6 commit aa90168
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions unreliable_chat_check/BrokenChatServerLocal.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,18 +369,20 @@ func handleHello(message string, addr net.Addr, output BrokenMessageOutputStream
} else { // HELLO-FROM format is correct. Enough space for new client
name := match[3]
if cb.IsKnown(name) { // But this username already exists
output.Send(addr, ReplyInUse)
if cb.nameToAddr[name] == addr.String(){ // check if username belongs to this address
output.Send(addr, ReplyBadHdr)
} else {
output.Send(addr, ReplyInUse)
}
} else { // We don't know this user
cb.Add(addr, name)
output.Send(addr, "HELLO "+name+"\n")
}
}
} else {
if match := regexDisallowedNameCharacters.FindStringSubmatch(message); match != nil {
output.Send(addr, ReplyBadHdr)
} else {
output.Send(addr, ReplyBadBody)
}
}
}
}

Expand Down

0 comments on commit aa90168

Please sign in to comment.