Check player name (#74)
parent
1f293cc5ca
commit
c372e1a8d4
26
init.go
26
init.go
|
@ -8,6 +8,7 @@ import (
|
|||
"io"
|
||||
"log"
|
||||
"net"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
@ -284,6 +285,31 @@ func Init(c, c2 *Conn, ignMedia, noAccessDenied bool, fin chan *Conn) {
|
|||
return
|
||||
}
|
||||
|
||||
msg := c2.Addr().String() + " tried to connect with "
|
||||
if len(c2.Username()) == 0 {
|
||||
c2.CloseWith(AccessDeniedWrongName, "", false)
|
||||
fin <- c
|
||||
log.Print(msg + "empty name")
|
||||
return
|
||||
} else if len(c2.Username()) > MaxPlayerNameLength {
|
||||
c2.CloseWith(AccessDeniedWrongCharsInName, "", false)
|
||||
fin <- c
|
||||
log.Print(msg + "too long name")
|
||||
return
|
||||
}
|
||||
|
||||
ok, err := regexp.MatchString(PlayerNameChars, c2.Username())
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
|
||||
if !ok || err != nil {
|
||||
c2.CloseWith(AccessDeniedWrongCharsInName, "", false)
|
||||
fin <- c
|
||||
log.Print(c2.Addr().String() + " tried to connect with invalid name")
|
||||
return
|
||||
}
|
||||
|
||||
// Send HELLO
|
||||
data := make([]byte, 13+len(c2.Username()))
|
||||
data[0] = uint8(0x00)
|
||||
|
|
Loading…
Reference in New Issue