Skip to content

Commit

Permalink
Add 7 Days to Die support #5
Browse files Browse the repository at this point in the history
  • Loading branch information
outdead committed Oct 8, 2020
1 parent be059e8 commit adc45e1
Show file tree
Hide file tree
Showing 11 changed files with 276 additions and 169 deletions.
4 changes: 2 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ linters-settings:
check-blank: false
funlen:
# default is 60
lines: 60
lines: 70
# default is 40
statements: 40
gocognit:
# minimal code complexity to report, 30 by default (but we recommend 10-20)
min-complexity: 15
min-complexity: 20
goconst:
# minimal length of string constant, 3 by default
min-len: 3
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file.
## [Unreleased]
## Added
- Added support amd64 darwin compilation.
- Added 7 Days to Die support #5. Add `-t telnet` argument when execute `rcon` cli.

## [v0.6.0] - 2020-07-10
### Fixed
Expand Down
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ CLI for executing queries on a remote [Source dedicated game server](https://dev
* [Conan Exiles](https://store.steampowered.com/app/440900)
* [Rust](https://store.steampowered.com/app/252490) (add +rcon.web 0 to the args when starting the server)
* [ARK: Survival Evolved](https://store.steampowered.com/app/346110)
* [7 Days to Die](https://store.steampowered.com/app/251570)

Open pull request if you have successfully used a package with another game with rcon support and add it to the list.

Expand Down Expand Up @@ -41,6 +42,7 @@ GLOBAL OPTIONS:
-l value, --log value path and name of the log file. if not specified, it is taken from the config.
--cfg value allows to specify the path and name of the configuration file. The default
value is rcon.yaml.
-t value, --type value Allows to specify type of connection. The default value is rcon.
--help, -h show help
--version, -v print the version
```
Expand Down Expand Up @@ -91,7 +93,11 @@ zomboid:
log: "rcon-zomboid.log"
rust:
address: "127.0.0.1:28003"
password: "password"
password: "password"
7dtd:
address: "172.19.0.2:8081"
password: "password"
type: "telnet"
```
You can choose the environment at the start:
Expand All @@ -107,6 +113,11 @@ You can use `-l` argument to specify path to log file.

./rcon -l /path/to/file.log

Since from `rcon-cli` 0.7.0 version support for the TELNET protocol has been added. On this protocol remote access to
the 7 Days to Die console is based. You can use `-t` argument to specify the protocol type.

./rcon -a 172.19.0.2:8081 -p banana -t telnet -c version

## Contribute

If you think that you have found a bug, create an issue and indicate your operating system, platform and the game on
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.15

require (
github.com/gorcon/rcon v1.2.1
github.com/gorcon/telnet v1.0.0
github.com/stretchr/testify v1.6.1
github.com/urfave/cli v1.22.4
gopkg.in/yaml.v2 v2.3.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gorcon/rcon v1.2.1 h1:zxclHuZS6mBwx4f2x9XwLDwLCQT+yx4/9bnOz6MmCog=
github.com/gorcon/rcon v1.2.1/go.mod h1:tR1u9kJLW1lKzOMLl9VpXT/JYN4efFtD3fSmmwSpOHc=
github.com/gorcon/telnet v1.0.0 h1:xSIE21WAVGwmL/gxrnLYg0kD9j1ZKR7ouPSyHBJPDDU=
github.com/gorcon/telnet v1.0.0/go.mod h1:KwU1iCwOxpp/G52AfvVsMxdSEA475k9tt9hMzQSx8Lc=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
Expand Down
34 changes: 34 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package config

import (
"io/ioutil"

"github.com/gorcon/rcon-cli/internal/session"
"gopkg.in/yaml.v2"
)

// Config allows to take a remote server address and password from
// the configuration file. This enables not to specify these flags when
// running the CLI.
//
// Example:
// ```yaml
// default:
// address: "127.0.0.1:16260"
// password: "password"
// ```.
type Config map[string]session.Session

// ReadYamlConfig reads config data from yaml file.
func ReadYamlConfig(path string) (cfg Config, err error) {
file, err := ioutil.ReadFile(path)
if err != nil {
return cfg, err
}

if err := yaml.Unmarshal(file, &cfg); err != nil {
return cfg, err
}

return cfg, nil
}
34 changes: 34 additions & 0 deletions internal/proto/rcon/rcon.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package rcon

import (
"errors"

"github.com/gorcon/rcon"
)

// Execute sends command to Execute to the remote server and returns
// the response.
func Execute(address string, password string, command string) (string, error) {
if command == "" {
return "", errors.New("command is not set")
}

console, err := rcon.Dial(address, password)
if err != nil {
return "", err
}
defer console.Close()

return console.Execute(command)
}

// CheckCredentials sends auth request for remote server. Returns en error if
// address or password is incorrect.
func CheckCredentials(address string, password string) error {
console, err := rcon.Dial(address, password)
if err != nil {
return err
}

return console.Close()
}
42 changes: 42 additions & 0 deletions internal/proto/telnet/telnet.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package telnet

import (
"errors"
"io"

"github.com/gorcon/telnet"
)

// Execute sends command to Execute to the remote server and returns
// the response.
func Execute(address string, password string, command string) (string, error) {
if command == "" {
return "", errors.New("command is not set")
}

console, err := telnet.Dial(address, password)
if err != nil {
return "", err
}
defer console.Close()

return console.Execute(command)
}

// DialInteractive parses commands from input reader, executes them on remote
// server and writes responses to output writer. Password can be empty string.
// In this case password will be prompted in an interactive window.
func Interactive(r io.Reader, w io.Writer, address string, password string) error {
return telnet.DialInteractive(r, w, address, password)
}

// CheckCredentials sends auth request for remote server. Returns en error if
// address or password is incorrect.
func CheckCredentials(address string, password string) error {
console, err := telnet.Dial(address, password)
if err != nil {
return err
}

return console.Close()
}
19 changes: 19 additions & 0 deletions internal/session/session.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package session

// Allowed protocols.
const (
ProtocolRCON = "rcon"
ProtocolTELNET = "telnet"
)

// DefaultProtocol contains the default protocol for connecting to a
// remote server.
const DefaultProtocol = ProtocolRCON

// Session contains details for making a request on a remote server.
type Session struct {
Address string `json:"address" yaml:"address"`
Password string `json:"password" yaml:"password"`
Log string `json:"log" yaml:"log"`
Type string `json:"type" yaml:"type"`
}
Loading

0 comments on commit adc45e1

Please sign in to comment.