Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ go 1.20
require (
github.com/Tnze/go-mc v1.20.2
github.com/muesli/cache2go v0.0.0-20221011235721-518229cd8021
github.com/speedata/optionparser v1.0.2
)

require github.com/google/uuid v1.3.0 // indirect
require (
github.com/google/uuid v1.3.0 // indirect
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/muesli/cache2go v0.0.0-20221011235721-518229cd8021 h1:31Y+Yu373ymebRdJN1cWLLooHH8xAr0MhKTEJGV/87g=
github.com/muesli/cache2go v0.0.0-20221011235721-518229cd8021/go.mod h1:WERUkUryfUWlrHnFSO/BEUZ+7Ns8aZy7iVOGewxKzcc=
github.com/speedata/optionparser v1.0.2 h1:AzdBomgOBVjH1KyxvoFnEHjiqLch+B1PVxEWYske+aI=
github.com/speedata/optionparser v1.0.2/go.mod h1:JzOMd1kGlM5gtPBy7reOayfHsTXCvd6P4JU8BW0LicE=
20 changes: 17 additions & 3 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,24 @@ import (
"github.com/LockBlock-dev/MinePot/util"
"github.com/Tnze/go-mc/net"
"github.com/muesli/cache2go"
"github.com/speedata/optionparser"
)

func main() {
config, err := util.GetConfig()
var configPath string = "/etc/minepot/config.json"

parser := optionparser.NewOptionParser()

parser.On("-c", "--config <path>", "Path to the config file", &configPath)

err := parser.Parse()
if err != nil {
fmt.Println(err)
fmt.Println("\"MinePot -h --help\" for help")
return
}

config, err := util.GetConfig(configPath)
if err != nil {
log.Fatal(err)
}
Expand All @@ -39,7 +53,7 @@ func main() {
}
defer historyFile.Close()

_, err = historyFile.WriteString("datetime, ip, packets_count, reported, handshake, ping")
_, err = historyFile.WriteString("datetime, ip, packets_count, reported, handshake, ping\n")
if err != nil {
log.Fatal("Failed to write history headers:", err)
}
Expand All @@ -59,7 +73,7 @@ func main() {
listener.Close()
}()

log.Printf("Server listening on port %d\nYou can edit the config at /etc/minepot/config.json", config.Port)
log.Printf("Server listening on port %d\nYou can edit the config at %s", config.Port, configPath)

if config.WriteLogs {
// Logs the logs file path
Expand Down
4 changes: 2 additions & 2 deletions util/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"github.com/LockBlock-dev/MinePot/types"
)

func GetConfig() (*types.Config, error) {
file, err := os.Open("/etc/minepot/config.json")
func GetConfig(path string) (*types.Config, error) {
file, err := os.Open(path)
if err != nil {
return &types.Config{}, err
}
Expand Down