Skip to content

Commit 35c0e19

Browse files
committed
Add wpm validation
1 parent 42ae627 commit 35c0e19

File tree

1 file changed

+10
-1
lines changed
  • backend/internal/wsserver

1 file changed

+10
-1
lines changed

backend/internal/wsserver/hub.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -391,16 +391,25 @@ func handleMorseCommand(
391391
messageText, messageDuration, isMalformed := morse.Translate(cmd.Message, cmd.Wpm)
392392
if isMalformed {
393393
//TODO; metrics
394-
logger.Printf("HandleMorseCommand: malformed message:\n")
394+
logger.Printf("HandleMorseCommand: malformed message\n")
395395
MessageUserMorseStatusError(client, logger, "Malformed message", "")
396396
return
397397
}
398+
399+
if cmd.Wpm < 5 {
400+
logger.Printf("HandleMorseCommand: malformed command\n")
401+
MessageUserMorseStatusError(client, logger, "Malformed message", "")
402+
return
403+
}
404+
405+
398406
isBadLanguage := morse.ContainsBadLanguage(messageText)
399407
if isBadLanguage{
400408
//TODO; metrics
401409
logger.Printf("HandleMorseCommand: bad language: %v\n", messageText)
402410
}
403411

412+
404413
//ratelimiting logic
405414
//minimum seconds between each message sent, which double
406415
//if the user is suspiciously fast

0 commit comments

Comments
 (0)