Compare commits

...

2 commits

Author SHA1 Message Date
Augusto Dwenger J. 3e532d98c5
Switch from SimpleClient to MinecraftClient
Minecrafts server implementation doesn't behave like valves and the
SimpleClient followes strictly the documentation from valve.

Switching the implementation I also refactored the code so that future
implementation changes won't change mutch due to the usage of an
interface.
2022-03-05 15:54:32 +01:00
Augusto Dwenger J. cef38a85eb
Update grcon lib to v0.2.0
This version contains a minecraft client.
2022-03-05 15:53:26 +01:00
3 changed files with 10 additions and 10 deletions

2
go.mod
View file

@ -1,7 +1,7 @@
module github.com/hamburghammer/rcon-cli
require (
github.com/hamburghammer/grcon v0.1.0
github.com/hamburghammer/grcon v0.2.0
github.com/spf13/pflag v1.0.5
)

4
go.sum
View file

@ -1,4 +1,4 @@
github.com/hamburghammer/grcon v0.1.0 h1:xpG2VfqSoE3Z95k9aPotn/x/dz3waLup2LbyJ5ik5GM=
github.com/hamburghammer/grcon v0.1.0/go.mod h1:KFU2Z3ESvao7Rhx40+SMc/Vw2LSiQ7sdcUmbGI7bmU8=
github.com/hamburghammer/grcon v0.2.0 h1:19vfliPzCwYdwtFsU9/kMRs0RTVyOWqk4plNKAOGNYw=
github.com/hamburghammer/grcon v0.2.0/go.mod h1:KFU2Z3ESvao7Rhx40+SMc/Vw2LSiQ7sdcUmbGI7bmU8=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=

14
main.go
View file

@ -87,16 +87,16 @@ func run(cmd string) error {
defer conn.Close()
remoteConsole := grcon.NewRemoteConsole(conn)
simpleClient := client.NewSimpleClient(remoteConsole, util.GenerateRequestId)
err = simpleClient.Auth(password)
rconClient := client.NewMinecraftClient(remoteConsole, util.GenerateRequestId)
err = rconClient.Auth(password)
if err != nil {
return fmt.Errorf("failed to connect to RCON server: %w", err)
return fmt.Errorf("failed to authenticate: %w", err)
}
if len(cmd) == 0 {
err = executeInteractive(simpleClient)
err = executeInteractive(rconClient)
} else {
resp, err := execute(cmd, simpleClient)
resp, err := execute(cmd, rconClient)
if err != nil {
return err
}
@ -127,7 +127,7 @@ EXAMPLES:
`, envVarPrefix, envVarPrefix)
}
func executeInteractive(remoteConsole client.SimpleClient) error {
func executeInteractive(remoteConsole client.Client) error {
scanner := bufio.NewScanner(os.Stdin)
fmt.Println("To quit the session type 'exit'.")
for scanner.Scan() {
@ -151,7 +151,7 @@ func executeInteractive(remoteConsole client.SimpleClient) error {
return nil
}
func execute(cmd string, client client.SimpleClient) (string, error) {
func execute(cmd string, client client.Client) (string, error) {
response, err := client.Exec(cmd)
if err != nil {
return "", fmt.Errorf("failed to execute command: %w", err)