diff --git a/server.go b/server.go index e04833c..4e53831 100644 --- a/server.go +++ b/server.go @@ -1193,7 +1193,7 @@ func (server *Server) initPerLaunchData() { } // Clean per-launch data -func (server *Server) cleanPerLaunchData() { +func (server *Server) cleanPerLaunchData() { server.pool = nil server.clients = nil server.hclients = nil @@ -1213,7 +1213,7 @@ func (server *Server) Port() int { if port == 0 { return DefaultPort + int(server.Id) - 1 } - return 0 + return port } // Returns the port the server is currently listning @@ -1235,7 +1235,7 @@ func (server *Server) HostAddress() string { if host == "" { return "0.0.0.0" } - return "" + return host } // Start the server. @@ -1248,7 +1248,7 @@ func (server *Server) Start() (err error) { port := server.Port() // Setup our UDP listener - server.udpconn, err = net.ListenUDP("udp", &net.UDPAddr{ net.ParseIP(host), port }) + server.udpconn, err = net.ListenUDP("udp", &net.UDPAddr{net.ParseIP(host), port}) if err != nil { return err } @@ -1258,7 +1258,7 @@ func (server *Server) Start() (err error) { } // Set up our TCP connection - server.tcpl, err = net.ListenTCP("tcp", &net.TCPAddr{ net.ParseIP(host), port }) + server.tcpl, err = net.ListenTCP("tcp", &net.TCPAddr{net.ParseIP(host), port}) if err != nil { return err } diff --git a/ssh.go b/ssh.go index c88f7f6..ecf1bd5 100644 --- a/ssh.go +++ b/ssh.go @@ -62,6 +62,10 @@ func RunSSH() { StopServerCmd, "", "Stops the server with the given id") + RegisterSSHCmd("restart", + RestartServerCmd, + "", + "Restarts the server with the given id") RegisterSSHCmd("supw", SetSuperUserPasswordCmd, " ", @@ -262,6 +266,38 @@ func StopServerCmd(reply SshCmdReply, args []string) error { return nil } +func RestartServerCmd(reply SshCmdReply, args []string) error { + if len(args) != 2 { + return errors.New("argument count mismatch") + } + + serverId, err := strconv.Atoi64(args[1]) + if err != nil { + return errors.New("bad server id") + } + + server, exists := servers[serverId] + if !exists { + return errors.New("no such server") + } + + err = server.Stop() + if err != nil { + return fmt.Errorf("unable to stop: %v", err.Error()) + } + + reply.WriteString(fmt.Sprintf("[%v] Stopped\r\n", serverId)) + + err = server.Start() + if err != nil { + return fmt.Errorf("unable to start: %v", err.Error()) + } + + reply.WriteString(fmt.Sprintf("[%v] Started\r\n", serverId)) + + return nil +} + func SetSuperUserPasswordCmd(reply SshCmdReply, args []string) error { if len(args) != 3 { return errors.New("argument count mismatch")