89 lines
1.7 KiB
Go
89 lines
1.7 KiB
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"compress/gzip"
|
|
"fmt"
|
|
"io"
|
|
"io/ioutil"
|
|
"log"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
mclookup "codehub.onpointcoding.net/sean/go-mclookup"
|
|
"github.com/Tnze/go-mc/nbt"
|
|
)
|
|
|
|
func main() {
|
|
fmt.Printf("MC Server Player Locator -- by MrMelon\n")
|
|
if pddir, err := os.Stat("playerdata/"); !os.IsNotExist(err) {
|
|
if pddir.IsDir() {
|
|
files, err := filepath.Glob("playerdata/*dat")
|
|
if err != nil {
|
|
fmt.Printf("Error getting playerdata NBT files\n")
|
|
return
|
|
}
|
|
for _, file := range files {
|
|
base := filepath.Base(file)
|
|
fmt.Printf("Parsing %s...\r", base)
|
|
|
|
uuid := strings.Replace(base, ".dat", "", -1)
|
|
|
|
apiResult, err := mclookup.LookupPlayer(uuid)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
filedata, err := ioutil.ReadFile(file)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
zr, err := gzip.NewReader(bytes.NewBuffer(filedata))
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
var content bytes.Buffer
|
|
|
|
if _, err := io.Copy(&content, zr); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
if err := zr.Close(); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
player := playerCompound{}
|
|
err = nbt.Unmarshal(content.Bytes(), &player)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
if len(player.Pos) == 3 {
|
|
fmt.Printf("%s (%s): %v, %v, %v\n", apiResult.Data.Player.Username, uuid, player.Pos[0], player.Pos[1], player.Pos[2])
|
|
}
|
|
|
|
continue
|
|
}
|
|
} else {
|
|
fmt.Printf("playerdata isn't a folder\n")
|
|
}
|
|
} else {
|
|
fmt.Printf("playerdata folder doesn't exist\n")
|
|
}
|
|
}
|
|
|
|
type playerCompound struct {
|
|
Pos []float64 `nbt:"Pos"`
|
|
}
|
|
|
|
func fileExists(filename string) bool {
|
|
info, err := os.Stat(filename)
|
|
if os.IsNotExist(err) {
|
|
return false
|
|
}
|
|
return !info.IsDir()
|
|
}
|