MCPcopy Create free account
hub / github.com/TyphoonMC/TyphoonCore / ReadNStringLimited

Method ReadNStringLimited

utils.go:240–259  ·  view source on GitHub ↗
(max int)

Source from the content-addressed store, hash-verified

238}
239
240func (player *Player) ReadNStringLimited(max int) (s string, read int, err error) {
241 max = (max * 4) + 3
242
243 length, err := player.ReadVarInt()
244 buff := make([]byte, 8)
245 read = binary.PutUvarint(buff, uint64(length))
246 if err != nil {
247 return "", read, err
248 }
249 if length > max {
250 player.Kick("Invalid packet")
251 return "", read, nil
252 }
253 buffer := make([]byte, length)
254 _, err = io.ReadFull(player.io.rdr, buffer)
255 if err != nil {
256 return "", read + length, err
257 }
258 return string(buffer), read + length, nil
259}
260
261func (player *Player) WriteByteArray(data []byte) (err error) {
262 _, err = player.io.wtr.Write(data)

Callers 1

ReadMethod · 0.80

Calls 2

ReadVarIntMethod · 0.95
KickMethod · 0.95

Tested by

no test coverage detected