update to 1.16 and removes usage of "io/ioutil"
This commit is contained in:
@ -10,7 +10,7 @@ import (
|
|||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -176,7 +176,7 @@ func loginAuth(AsTk, name, UUID string, shareSecret []byte, er encryptionRequest
|
|||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
body, _ := ioutil.ReadAll(resp.Body)
|
body, _ := io.ReadAll(resp.Body)
|
||||||
if resp.Status != "204 No Content" {
|
if resp.Status != "204 No Content" {
|
||||||
return fmt.Errorf("auth fail: %s", string(body))
|
return fmt.Errorf("auth fail: %s", string(body))
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,6 @@ import (
|
|||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
@ -117,7 +116,7 @@ func pack(f, o string) {
|
|||||||
checkerr(err)
|
checkerr(err)
|
||||||
defer r.Close()
|
defer r.Close()
|
||||||
|
|
||||||
mcc, err := ioutil.ReadFile(f)
|
mcc, err := os.ReadFile(f)
|
||||||
checkerr(err)
|
checkerr(err)
|
||||||
|
|
||||||
rx, rz := region.In(x, z)
|
rx, rz := region.In(x, z)
|
||||||
|
2
go.mod
2
go.mod
@ -1,6 +1,6 @@
|
|||||||
module github.com/Tnze/go-mc
|
module github.com/Tnze/go-mc
|
||||||
|
|
||||||
go 1.13
|
go 1.16
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/beefsack/go-astar v0.0.0-20200827232313-4ecf9e304482
|
github.com/beefsack/go-astar v0.0.0-20200827232313-4ecf9e304482
|
||||||
|
@ -3,7 +3,7 @@ package nbt
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
@ -225,7 +225,7 @@ func TestMarshal_bigTest(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
rd, _ := gzip.NewReader(bytes.NewReader(bigTestData[:]))
|
rd, _ := gzip.NewReader(bytes.NewReader(bigTestData[:]))
|
||||||
want, err := ioutil.ReadAll(rd)
|
want, err := io.ReadAll(rd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"math"
|
"math"
|
||||||
"reflect"
|
"reflect"
|
||||||
)
|
)
|
||||||
@ -382,7 +381,7 @@ func (d *Decoder) rawRead(tagType byte) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err = io.CopyN(ioutil.Discard, d.r, int64(aryLen)); err != nil {
|
if _, err = io.CopyN(io.Discard, d.r, int64(aryLen)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
case TagIntArray:
|
case TagIntArray:
|
||||||
|
@ -101,21 +101,21 @@ func UnCompress(data []byte) (*Packet, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
uncompressData := make([]byte, sizeUncompressed)
|
uncompressedData := make([]byte, sizeUncompressed)
|
||||||
if sizeUncompressed != 0 { // != 0 means compressed, let's decompress
|
if sizeUncompressed != 0 { // != 0 means compressed, let's decompress
|
||||||
r, err := zlib.NewReader(reader)
|
r, err := zlib.NewReader(reader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("decompress fail: %v", err)
|
return nil, fmt.Errorf("decompress fail: %v", err)
|
||||||
}
|
}
|
||||||
defer r.Close()
|
defer r.Close()
|
||||||
_, err = io.ReadFull(r, uncompressData)
|
_, err = io.ReadFull(r, uncompressedData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("decompress fail: %v", err)
|
return nil, fmt.Errorf("decompress fail: %v", err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
uncompressData = data[1:]
|
uncompressedData = data[1:]
|
||||||
}
|
}
|
||||||
buf := bytes.NewBuffer(uncompressData)
|
buf := bytes.NewBuffer(uncompressedData)
|
||||||
var packetID VarInt
|
var packetID VarInt
|
||||||
if err := packetID.Decode(buf); err != nil {
|
if err := packetID.Decode(buf); err != nil {
|
||||||
return nil, fmt.Errorf("read packet id fail: %v", err)
|
return nil, fmt.Errorf("read packet id fail: %v", err)
|
||||||
@ -130,7 +130,11 @@ func UnCompress(data []byte) (*Packet, error) {
|
|||||||
func Compress(data []byte) []byte {
|
func Compress(data []byte) []byte {
|
||||||
var b bytes.Buffer
|
var b bytes.Buffer
|
||||||
w := zlib.NewWriter(&b)
|
w := zlib.NewWriter(&b)
|
||||||
w.Write(data)
|
if _, err := w.Write(data); err != nil {
|
||||||
w.Close()
|
panic(err)
|
||||||
|
}
|
||||||
|
if err := w.Close(); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
return b.Bytes()
|
return b.Bytes()
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package packet
|
package packet
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"math"
|
"math"
|
||||||
@ -76,6 +77,7 @@ type (
|
|||||||
UUID uuid.UUID
|
UUID uuid.UUID
|
||||||
|
|
||||||
//NBT encode a value as Named Binary Tag
|
//NBT encode a value as Named Binary Tag
|
||||||
|
//Tips: define your own struct and implement pk.Field for better performance
|
||||||
NBT struct {
|
NBT struct {
|
||||||
V interface{}
|
V interface{}
|
||||||
}
|
}
|
||||||
@ -407,6 +409,15 @@ func (d *Double) Decode(r DecodeReader) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Encode a NBT
|
||||||
|
func (n NBT) Encode() []byte {
|
||||||
|
var buf bytes.Buffer
|
||||||
|
if err := nbt.NewEncoder(&buf).Encode(n.V); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return buf.Bytes()
|
||||||
|
}
|
||||||
|
|
||||||
// Decode a NBT
|
// Decode a NBT
|
||||||
func (n NBT) Decode(r DecodeReader) error {
|
func (n NBT) Decode(r DecodeReader) error {
|
||||||
return nbt.NewDecoder(r).Decode(n.V)
|
return nbt.NewDecoder(r).Decode(n.V)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package ptypes
|
package ptypes
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io"
|
||||||
|
|
||||||
"github.com/Tnze/go-mc/chat"
|
"github.com/Tnze/go-mc/chat"
|
||||||
"github.com/Tnze/go-mc/data/packetid"
|
"github.com/Tnze/go-mc/data/packetid"
|
||||||
@ -64,7 +64,7 @@ func (p PluginData) Encode() []byte {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *PluginData) Decode(r pk.DecodeReader) error {
|
func (p *PluginData) Decode(r pk.DecodeReader) error {
|
||||||
d, err := ioutil.ReadAll(r)
|
d, err := io.ReadAll(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package realms
|
package realms
|
||||||
|
|
||||||
import "io/ioutil"
|
import "io"
|
||||||
|
|
||||||
// Available returns whether the user can access the Minecraft Realms service
|
// Available returns whether the user can access the Minecraft Realms service
|
||||||
func (r *Realms) Available() (ok bool, err error) {
|
func (r *Realms) Available() (ok bool, err error) {
|
||||||
@ -19,7 +19,7 @@ func (r *Realms) Compatible() (string, error) {
|
|||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
rp, err := ioutil.ReadAll(resp.Body)
|
rp, err := io.ReadAll(resp.Body)
|
||||||
|
|
||||||
return string(rp), err
|
return string(rp), err
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ package yggdrasil
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Validate checks if an accessToken is usable for authentication with a Minecraft server.
|
// Validate checks if an accessToken is usable for authentication with a Minecraft server.
|
||||||
@ -28,7 +28,7 @@ func (a *Access) Invalidate() error {
|
|||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
if resp.StatusCode != 204 {
|
if resp.StatusCode != 204 {
|
||||||
content, _ := ioutil.ReadAll(resp.Body)
|
content, _ := io.ReadAll(resp.Body)
|
||||||
return fmt.Errorf("invalidate error: %v: %s", resp.Status, content)
|
return fmt.Errorf("invalidate error: %v: %s", resp.Status, content)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user