Clean imports
This commit is contained in:
@ -185,7 +185,7 @@ var colors = map[string]string{
|
||||
// By default, it's en-us.
|
||||
var translateMap = en_us.Map
|
||||
|
||||
// SetLanguage set the translate map to this map.
|
||||
// SetLanguage set the default language used by String() and ClearString().
|
||||
func SetLanguage(trans map[string]string) {
|
||||
translateMap = trans
|
||||
}
|
||||
@ -205,11 +205,7 @@ func (m Message) ClearString() string {
|
||||
args[i] = arg.ClearString()
|
||||
}
|
||||
|
||||
if translateMap != nil {
|
||||
_, _ = fmt.Fprintf(&msg, translateMap[m.Translate], args...)
|
||||
} else {
|
||||
_, _ = fmt.Fprint(&msg, m.Translate, m.With)
|
||||
}
|
||||
_, _ = fmt.Fprintf(&msg, translateMap[m.Translate], args...)
|
||||
}
|
||||
|
||||
if m.Extra != nil {
|
||||
@ -256,11 +252,7 @@ func (m Message) String() string {
|
||||
args[i] = arg
|
||||
}
|
||||
|
||||
if translateMap != nil {
|
||||
_, _ = fmt.Fprintf(&msg, translateMap[m.Translate], args...)
|
||||
} else {
|
||||
_, _ = fmt.Fprint(&msg, m.Translate, m.With)
|
||||
}
|
||||
_, _ = fmt.Fprintf(&msg, translateMap[m.Translate], args...)
|
||||
}
|
||||
|
||||
if m.Extra != nil {
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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"}}}
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
|
1
go.mod
1
go.mod
@ -5,5 +5,4 @@ go 1.16
|
||||
require (
|
||||
github.com/google/uuid v1.1.1
|
||||
github.com/iancoleman/strcase v0.1.3
|
||||
github.com/mattn/go-colorable v0.1.8
|
||||
)
|
||||
|
7
go.sum
7
go.sum
@ -2,10 +2,3 @@ github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
|
||||
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/iancoleman/strcase v0.1.3 h1:dJBk1m2/qjL1twPLf68JND55vvivMupZ4wIzE8CTdBw=
|
||||
github.com/iancoleman/strcase v0.1.3/go.mod h1:SK73tn/9oHe+/Y0h39VT4UCxmurVJkR5NA7kMEAOgSE=
|
||||
github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8=
|
||||
github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
|
||||
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
|
||||
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
||||
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae h1:/WDfKMnPU+m5M4xB+6x4kaepxRw6jWvR5iDRdvjHgy8=
|
||||
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
|
Reference in New Issue
Block a user