forked from github-mirrorer/quake-kube
Allow user to set server address
This commit is contained in:
@ -119,7 +119,7 @@ The content server hosts a small upload app to allow uploading `pk3` or `zip` fi
|
|||||||
The easiest way to develop quake-kube is building the binary locally with `make` and running it directly. This only requires that you have the `ioq3ded` binary in your path:
|
The easiest way to develop quake-kube is building the binary locally with `make` and running it directly. This only requires that you have the `ioq3ded` binary in your path:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
$ bin/q3 -c config.yaml --assets-dir $HOME/.q3a --agree-eula
|
$ bin/q3 server -c config.yaml --assets-dir $HOME/.q3a --agree-eula
|
||||||
```
|
```
|
||||||
|
|
||||||
## Credits
|
## Credits
|
||||||
|
|||||||
@ -40,13 +40,7 @@ func NewCommand() *cobra.Command {
|
|||||||
}
|
}
|
||||||
opts.ClientAddr = fmt.Sprintf("%s:8080", hostIPv4)
|
opts.ClientAddr = fmt.Sprintf("%s:8080", hostIPv4)
|
||||||
}
|
}
|
||||||
if opts.ServerAddr == "" {
|
|
||||||
hostIPv4, err := netutil.DetectHostIPv4()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
opts.ServerAddr = fmt.Sprintf("%s:27960", hostIPv4)
|
|
||||||
}
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
@ -72,6 +66,7 @@ func NewCommand() *cobra.Command {
|
|||||||
Dir: opts.AssetsDir,
|
Dir: opts.AssetsDir,
|
||||||
WatchInterval: opts.WatchInterval,
|
WatchInterval: opts.WatchInterval,
|
||||||
ConfigFile: opts.ConfigFile,
|
ConfigFile: opts.ConfigFile,
|
||||||
|
Addr: opts.ServerAddr,
|
||||||
}
|
}
|
||||||
if err := s.Start(ctx); err != nil {
|
if err := s.Start(ctx); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@ -100,7 +95,7 @@ func NewCommand() *cobra.Command {
|
|||||||
cmd.Flags().BoolVar(&opts.AcceptEula, "agree-eula", false, "agree to the Quake 3 demo EULA")
|
cmd.Flags().BoolVar(&opts.AcceptEula, "agree-eula", false, "agree to the Quake 3 demo EULA")
|
||||||
cmd.Flags().StringVar(&opts.AssetsDir, "assets-dir", "assets", "location for game files")
|
cmd.Flags().StringVar(&opts.AssetsDir, "assets-dir", "assets", "location for game files")
|
||||||
cmd.Flags().StringVar(&opts.ClientAddr, "client-addr", "", "client address <host>:<port>")
|
cmd.Flags().StringVar(&opts.ClientAddr, "client-addr", "", "client address <host>:<port>")
|
||||||
cmd.Flags().StringVar(&opts.ServerAddr, "server-addr", "", "dedicated server <host>:<port>")
|
cmd.Flags().StringVar(&opts.ServerAddr, "server-addr", "0.0.0.0:27960", "dedicated server <host>:<port>")
|
||||||
cmd.Flags().DurationVar(&opts.WatchInterval, "watch-interval", 15*time.Second, "dedicated server <host>:<port>")
|
cmd.Flags().DurationVar(&opts.WatchInterval, "watch-interval", 15*time.Second, "dedicated server <host>:<port>")
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
@ -17,10 +18,24 @@ type Server struct {
|
|||||||
Dir string
|
Dir string
|
||||||
WatchInterval time.Duration
|
WatchInterval time.Duration
|
||||||
ConfigFile string
|
ConfigFile string
|
||||||
|
Addr string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) Start(ctx context.Context) error {
|
func (s *Server) Start(ctx context.Context) error {
|
||||||
cmd := exec.CommandContext(ctx, "ioq3ded", "+set", "dedicated", "1", "+exec", "server.cfg")
|
if s.Addr == "" {
|
||||||
|
s.Addr = "0.0.0.0:27960"
|
||||||
|
}
|
||||||
|
host, port, err := net.SplitHostPort(s.Addr)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
args := []string{
|
||||||
|
"+set", "dedicated", "1",
|
||||||
|
"+set", "net_ip", host,
|
||||||
|
"+set", "net_port", port,
|
||||||
|
"+exec", "server.cfg",
|
||||||
|
}
|
||||||
|
cmd := exec.CommandContext(ctx, "ioq3ded", args...)
|
||||||
cmd.Dir = s.Dir
|
cmd.Dir = s.Dir
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
|
|||||||
Reference in New Issue
Block a user