Clean imports

This commit is contained in:
Tnze
2022-02-20 19:23:41 +08:00
parent fee2e0c939
commit 23bcf9149a
11 changed files with 63 additions and 42 deletions

View File

@ -5,6 +5,7 @@ import (
"time"
"github.com/google/uuid"
//"github.com/mattn/go-colorable"
"github.com/Tnze/go-mc/bot"
"github.com/Tnze/go-mc/bot/basic"
@ -12,7 +13,6 @@ import (
_ "github.com/Tnze/go-mc/data/lang/en-us"
"github.com/Tnze/go-mc/data/packetid"
pk "github.com/Tnze/go-mc/net/packet"
"github.com/mattn/go-colorable"
)
const timeout = 45
@ -25,7 +25,7 @@ var (
)
func main() {
log.SetOutput(colorable.NewColorableStdout())
//log.SetOutput(colorable.NewColorableStdout()) // optional for colorable output
c = bot.NewClient()
p = basic.NewPlayer(c, basic.DefaultSettings)

View File

@ -9,7 +9,7 @@ import (
"time"
"github.com/google/uuid"
"github.com/mattn/go-colorable"
//"github.com/mattn/go-colorable"
"github.com/Tnze/go-mc/bot"
"github.com/Tnze/go-mc/bot/basic"
@ -26,7 +26,7 @@ var screenManager *screen.Manager
func main() {
flag.Parse()
log.SetOutput(colorable.NewColorableStdout())
//log.SetOutput(colorable.NewColorableStdout())
client = bot.NewClient()
client.Auth.Name = "Daze"
player = basic.NewPlayer(client, basic.DefaultSettings)

View File

@ -5,7 +5,6 @@ import (
_ "embed"
"flag"
"fmt"
"github.com/Tnze/go-mc/server/command"
"image"
_ "image/png"
"log"
@ -17,6 +16,7 @@ import (
"github.com/Tnze/go-mc/save"
"github.com/Tnze/go-mc/save/region"
"github.com/Tnze/go-mc/server"
"github.com/Tnze/go-mc/server/command"
)
var motd = chat.Message{Text: "A Minecraft Server ", Extra: []chat.Message{{Text: "Powered by go-mc", Color: "yellow"}}}

View File

@ -2,10 +2,14 @@
package main
import (
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"os"
"strings"
"text/template"
"time"
"github.com/Tnze/go-mc/bot"
"github.com/Tnze/go-mc/chat"
@ -26,12 +30,34 @@ type status struct {
Name string
Protocol int
}
//favicon ignored
Favicon Icon
Delay time.Duration
}
// Icon should be a PNG image that is Base64 encoded
// (without newlines: \n, new lines no longer work since 1.13)
// and prepended with "data:image/png;base64,".
type Icon string
var IconFormatErr = errors.New("data format error")
var IconAbsentErr = errors.New("icon not present")
// ToPNG decode base64-icon, return a PNG image
// Take care of there is no safety check, image may contain malicious code.
func (i Icon) ToPNG() ([]byte, error) {
const prefix = "data:image/png;base64,"
if i == "" {
return nil, IconAbsentErr
}
if !strings.HasPrefix(string(i), prefix) {
return nil, IconFormatErr
}
return base64.StdEncoding.DecodeString(strings.TrimPrefix(string(i), prefix))
}
func main() {
addr := getAddr()
fmt.Printf("MCPING (%s):\n", addr)
fmt.Printf("MCPING (%s):", addr)
resp, delay, err := bot.PingAndList(addr)
if err != nil {
fmt.Printf("ping and list server fail: %v", err)
@ -44,9 +70,9 @@ func main() {
fmt.Print("unmarshal resp fail:", err)
os.Exit(1)
}
s.Delay = delay
fmt.Print(s)
fmt.Println("Delay:", delay)
fmt.Print(&s)
}
func getAddr() string {
@ -59,14 +85,20 @@ func getAddr() string {
return os.Args[1]
}
func (s status) String() string {
var outTemp = template.Must(template.New("output").Parse(`
Version: [{{ .Version.Protocol }}] {{ .Version.Name }}
Description:
{{ .Description }}
Delay: {{ .Delay }}
Players: {{ .Players.Online }}/{{ .Players.Max }}{{ range .Players.Sample }}
- [{{ .Name }}] {{ .ID }}{{ end }}
`))
func (s *status) String() string {
var sb strings.Builder
fmt.Fprintln(&sb, "Server:", s.Version.Name)
fmt.Fprintln(&sb, "Protocol:", s.Version.Protocol)
fmt.Fprintln(&sb, "Description:", s.Description)
fmt.Fprintf(&sb, "Players: %d/%d\n", s.Players.Online, s.Players.Max)
for _, v := range s.Players.Sample {
fmt.Fprintf(&sb, "- [%s] %v\n", v.Name, v.ID)
err := outTemp.Execute(&sb, s)
if err != nil {
panic(err)
}
return sb.String()
}

View File

@ -6,7 +6,7 @@ import (
"strconv"
"time"
"github.com/mattn/go-colorable"
//"github.com/mattn/go-colorable"
"github.com/Tnze/go-mc/bot"
"github.com/Tnze/go-mc/bot/basic"
@ -18,7 +18,7 @@ var number = flag.Int("number", 1023, "The number of clients")
func main() {
flag.Parse()
log.SetOutput(colorable.NewColorableStdout())
//log.SetOutput(colorable.NewColorableStdout())
for i := 0; i < *number; i++ {
go func(i int) {

View File

@ -2,11 +2,13 @@
package main
import (
"log"
"github.com/google/uuid"
"github.com/Tnze/go-mc/net"
pk "github.com/Tnze/go-mc/net/packet"
"github.com/Tnze/go-mc/offline"
"github.com/google/uuid"
"log"
)
const ProtocolVersion = 578

View File

@ -2,11 +2,13 @@ package main
import (
"encoding/json"
"log"
"github.com/google/uuid"
"github.com/Tnze/go-mc/chat"
"github.com/Tnze/go-mc/net"
pk "github.com/Tnze/go-mc/net/packet"
"github.com/google/uuid"
"log"
)
func acceptListPing(conn net.Conn) {

View File

@ -5,11 +5,12 @@ import (
_ "embed"
"log"
"github.com/google/uuid"
"github.com/Tnze/go-mc/nbt"
"github.com/Tnze/go-mc/net"
pk "github.com/Tnze/go-mc/net/packet"
"github.com/Tnze/go-mc/offline"
"github.com/google/uuid"
)
const ProtocolVersion = 756