-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
misc: refactoring for bedrock ping support
- Loading branch information
Showing
8 changed files
with
78 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
"fmt" | ||
"github.com/google/subcommands" | ||
"github.com/itzg/go-flagsfiller" | ||
"log" | ||
"net" | ||
"strconv" | ||
) | ||
|
||
type statusBedrockCmd struct { | ||
Host string `default:"localhost"` | ||
Port int `default:"19132"` | ||
} | ||
|
||
func (c *statusBedrockCmd) Name() string { | ||
return "status-bedrock" | ||
} | ||
|
||
func (c *statusBedrockCmd) Synopsis() string { | ||
return "Retrieves and displays the status of the given Minecraft Bedrock Dedicated server" | ||
} | ||
|
||
func (c *statusBedrockCmd) Usage() string { | ||
return "" | ||
} | ||
|
||
func (c *statusBedrockCmd) SetFlags(flags *flag.FlagSet) { | ||
filler := flagsfiller.New() | ||
err := filler.Fill(flags, c) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
func (c *statusBedrockCmd) Execute(ctx context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus { | ||
address := net.JoinHostPort(c.Host, strconv.Itoa(c.Port)) | ||
|
||
info, err := PingBedrockServer(address) | ||
if err != nil { | ||
log.Fatal(err) | ||
return subcommands.ExitFailure | ||
} | ||
|
||
fmt.Printf("%s : version=%s online=%d max=%d", | ||
address, | ||
info.Version, info.Players, info.MaxPlayers) | ||
|
||
return subcommands.ExitSuccess | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.