update the description text of the examples
This commit is contained in:
@ -1,3 +1,5 @@
|
|||||||
|
// This is an example of how to use the go-mc/save/region package to read and write .mca files.
|
||||||
|
// It can unpack .mca files to .mcc files, or repack .mcc files to .mca files, controlled by the -p flags.
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -29,8 +31,7 @@ func main() {
|
|||||||
usage()
|
usage()
|
||||||
}
|
}
|
||||||
for _, f := range args[1:] {
|
for _, f := range args[1:] {
|
||||||
fs, err := filepath.Glob(f)
|
fs := must(filepath.Glob(f))
|
||||||
checkerr(err)
|
|
||||||
|
|
||||||
if *repack {
|
if *repack {
|
||||||
for _, f := range fs {
|
for _, f := range fs {
|
||||||
@ -49,24 +50,12 @@ func usage() {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// we use this function to check for laziness. Don't scold me >_<
|
|
||||||
func checkerr(err error) {
|
|
||||||
if err != nil {
|
|
||||||
_, _ = fmt.Fprintln(os.Stderr, err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func unpack(f, o string) {
|
func unpack(f, o string) {
|
||||||
var x, z int
|
var x, z int
|
||||||
rn := filepath.Base(f)
|
rn := filepath.Base(f)
|
||||||
_, err := fmt.Sscanf(rn, "r.%d.%d.mca", &x, &z)
|
must(fmt.Sscanf(rn, "r.%d.%d.mca", &x, &z))
|
||||||
if err != nil {
|
|
||||||
checkerr(fmt.Errorf("cannot use %s as mca file name: %v", rn, err))
|
|
||||||
}
|
|
||||||
|
|
||||||
r, err := region.Open(f)
|
r := must(region.Open(f))
|
||||||
checkerr(err)
|
|
||||||
defer r.Close()
|
defer r.Close()
|
||||||
|
|
||||||
for i := 0; i < 32; i++ {
|
for i := 0; i < 32; i++ {
|
||||||
@ -75,12 +64,12 @@ func unpack(f, o string) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err := r.ReadSector(i, j)
|
data := must(r.ReadSector(i, j))
|
||||||
checkerr(err)
|
|
||||||
var r io.Reader = bytes.NewReader(data[1:])
|
var r io.Reader = bytes.NewReader(data[1:])
|
||||||
|
|
||||||
fn := fmt.Sprintf("c.%d.%d.mcc", x*32+i, z*32+j)
|
fn := fmt.Sprintf("c.%d.%d.mcc", x<<5+i, z<<5+j)
|
||||||
if *decomp {
|
if *decomp {
|
||||||
|
var err error
|
||||||
fn += ".nbt" // 解压后就是一个标准的NBT文件,可以加个.nbt后缀
|
fn += ".nbt" // 解压后就是一个标准的NBT文件,可以加个.nbt后缀
|
||||||
switch data[0] {
|
switch data[0] {
|
||||||
default:
|
default:
|
||||||
@ -90,14 +79,12 @@ func unpack(f, o string) {
|
|||||||
case 2:
|
case 2:
|
||||||
r, err = zlib.NewReader(r)
|
r, err = zlib.NewReader(r)
|
||||||
}
|
}
|
||||||
checkerr(err)
|
must(0, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
cf, err := os.OpenFile(filepath.Join(o, fn), os.O_CREATE|os.O_RDWR|os.O_EXCL, 0o666)
|
cf := must(os.OpenFile(filepath.Join(o, fn), os.O_CREATE|os.O_RDWR|os.O_EXCL, 0o666))
|
||||||
checkerr(err)
|
|
||||||
|
|
||||||
_, err = io.Copy(cf, r)
|
must(io.Copy(cf, r))
|
||||||
checkerr(err)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -105,23 +92,27 @@ func unpack(f, o string) {
|
|||||||
func pack(f, o string) {
|
func pack(f, o string) {
|
||||||
var x, z int
|
var x, z int
|
||||||
rn := filepath.Base(f)
|
rn := filepath.Base(f)
|
||||||
_, err := fmt.Sscanf(rn, "c.%d.%d.mcc", &x, &z)
|
must(fmt.Sscanf(rn, "c.%d.%d.mcc", &x, &z))
|
||||||
if err != nil {
|
|
||||||
checkerr(fmt.Errorf("cannot use %s as mcc file name: %v", rn, err))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn := fmt.Sprintf("r.%d.%d.mca", x>>5, z>>5)
|
fn := fmt.Sprintf("r.%d.%d.mca", x>>5, z>>5)
|
||||||
r, err := region.Open(fn)
|
r, err := region.Open(fn)
|
||||||
if err != nil && os.IsNotExist(err) {
|
if err != nil && os.IsNotExist(err) {
|
||||||
r, err = region.Create(filepath.Join(o, fn))
|
r = must(region.Create(filepath.Join(o, fn)))
|
||||||
|
} else {
|
||||||
|
must(0, err)
|
||||||
}
|
}
|
||||||
checkerr(err)
|
|
||||||
defer r.Close()
|
defer r.Close()
|
||||||
|
|
||||||
mcc, err := os.ReadFile(f)
|
mcc := must(os.ReadFile(f))
|
||||||
checkerr(err)
|
|
||||||
|
|
||||||
rx, rz := region.In(x, z)
|
rx, rz := region.In(x, z)
|
||||||
err = r.WriteSector(rx, rz, mcc)
|
must(0, r.WriteSector(rx, rz, mcc))
|
||||||
checkerr(err)
|
}
|
||||||
|
|
||||||
|
func must[T any](v T, err error) T {
|
||||||
|
if err != nil {
|
||||||
|
_, _ = fmt.Fprintln(os.Stderr, err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
return v
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,6 @@ import (
|
|||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"image"
|
"image"
|
||||||
_ "image/jpeg"
|
|
||||||
"image/png"
|
"image/png"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -1,3 +1,9 @@
|
|||||||
|
// This example is used to apply pressure test on the server.
|
||||||
|
// Testing the performance of the login handling system of go-mc/server package.
|
||||||
|
// It can be used to test other server implementations too.
|
||||||
|
//
|
||||||
|
// This program will create a lot of clients and let them log in to the server.
|
||||||
|
// The number of clients can be set by the -number flag.
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -6,8 +12,6 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
//"github.com/mattn/go-colorable"
|
|
||||||
|
|
||||||
"github.com/Tnze/go-mc/bot"
|
"github.com/Tnze/go-mc/bot"
|
||||||
"github.com/Tnze/go-mc/bot/basic"
|
"github.com/Tnze/go-mc/bot/basic"
|
||||||
"github.com/Tnze/go-mc/chat"
|
"github.com/Tnze/go-mc/chat"
|
||||||
@ -20,7 +24,6 @@ var (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
// log.SetOutput(colorable.NewColorableStdout())
|
|
||||||
|
|
||||||
for i := 0; i < *number; i++ {
|
for i := 0; i < *number; i++ {
|
||||||
go func(i int) {
|
go func(i int) {
|
||||||
@ -60,6 +63,7 @@ func (i *individual) run(address string) {
|
|||||||
log.Printf("[%d]Login fail: %v", i.id, err)
|
log.Printf("[%d]Login fail: %v", i.id, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
defer i.client.Close()
|
||||||
log.Printf("[%d]Login success", i.id)
|
log.Printf("[%d]Login success", i.id)
|
||||||
|
|
||||||
// JoinGame
|
// JoinGame
|
||||||
@ -79,7 +83,7 @@ type DisconnectErr struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d DisconnectErr) Error() string {
|
func (d DisconnectErr) Error() string {
|
||||||
return "disconnect: " + d.Reason.String()
|
return "disconnect: " + d.Reason.ClearString()
|
||||||
}
|
}
|
||||||
|
|
||||||
func onDisconnect(reason chat.Message) error {
|
func onDisconnect(reason chat.Message) error {
|
||||||
|
@ -1,4 +1,11 @@
|
|||||||
// Example minecraft 1.15.2 server
|
// This example is a minimal minecraft 1.15.2 server allowing vanilla clients or go-mc/bot to connect.
|
||||||
|
//
|
||||||
|
// This example handles "ping and list", so you can see its motd and player count in server list.
|
||||||
|
// Players can join the server and seeing an empty world. No authentication profile is checked.
|
||||||
|
// The KeepAlive packet is not handled, so client might exit 20 seconds later.
|
||||||
|
//
|
||||||
|
// It doesn't use go-mc/server but the go-mc/net package to handle the connection and implement basic 1.15.2 protocol,
|
||||||
|
// proving that even latest go-mc also support old minecraft versions.
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
// Example minecraft 1.17.1 server
|
// This example is a minimal minecraft 1.17.1 server allowing vanilla clients or go-mc/bot to connect.
|
||||||
|
// Has the same functionality as "simpleServer1.15.2", but with 1.17.1 protocol.
|
||||||
|
//
|
||||||
|
// It is used to test DimensionCodec stuffs during go-mc development.
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -1,3 +1,8 @@
|
|||||||
|
// This example used to act as a launcher, log in and obtain the access token.
|
||||||
|
// The Yggdrasil Authentication is no longer available. This example doesn't work now.
|
||||||
|
//
|
||||||
|
// For now, you should use Microsoft Authentication. The description and example code can be found here:
|
||||||
|
// https://wiki.vg/Microsoft_Authentication_Scheme
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
Reference in New Issue
Block a user