mirror of
https://github.com/WiiLink24/wfc-server.git
synced 2026-09-12 02:25:55 -05:00
Merge pull request #22 from MikeIsAStar/prevent-invalid-packets-from-stopping-server
NATNEG / SB: Prevent invalid packets from stopping the server
This commit is contained in:
@@ -2,6 +2,7 @@ package common
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"math/rand"
|
||||
)
|
||||
|
||||
@@ -25,9 +26,14 @@ func RandomHexString(n int) string {
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func GetString(buf []byte) string {
|
||||
func GetString(buf []byte) (string, error) {
|
||||
nullTerminator := bytes.IndexByte(buf, 0)
|
||||
return string(buf[:nullTerminator])
|
||||
|
||||
if nullTerminator == -1 {
|
||||
return "", errors.New("buf is not null-terminated")
|
||||
}
|
||||
|
||||
return string(buf[:nullTerminator]), nil
|
||||
}
|
||||
|
||||
// IsUppercaseAlphanumeric checks if the given string is composed exclusively of uppercase alphanumeric characters.
|
||||
|
||||
Reference in New Issue
Block a user