started tracking of factorio-versions

This commit is contained in:
knoxfighter 2018-02-11 21:03:54 +01:00
parent 2afc6dbbe7
commit 9e8eecb3fa
5 changed files with 91 additions and 15 deletions

View File

@ -17,21 +17,24 @@ import (
"time"
"github.com/majormjr/rcon"
"regexp"
)
type FactorioServer struct {
Cmd *exec.Cmd `json:"-"`
Savefile string `json:"savefile"`
Latency int `json:"latency"`
BindIP string `json:"bindip"`
Port int `json:"port"`
Running bool `json:"running"`
StdOut io.ReadCloser `json:"-"`
StdErr io.ReadCloser `json:"-"`
StdIn io.WriteCloser `json:"-"`
Settings map[string]interface{} `json:"-"`
Rcon *rcon.RemoteConsole `json:"-"`
LogChan chan []string `json:"-"`
Cmd *exec.Cmd `json:"-"`
Savefile string `json:"savefile"`
Latency int `json:"latency"`
BindIP string `json:"bindip"`
Port int `json:"port"`
Running bool `json:"running"`
Version string `json:"fac_version"`
BaseModVersion string `json:"base_mod_version"`
StdOut io.ReadCloser `json:"-"`
StdErr io.ReadCloser `json:"-"`
StdIn io.WriteCloser `json:"-"`
Settings map[string]interface{} `json:"-"`
Rcon *rcon.RemoteConsole `json:"-"`
LogChan chan []string `json:"-"`
}
func randomPort() int {
@ -92,6 +95,34 @@ func initFactorio() (f *FactorioServer, err error) {
log.Printf("Loaded Factorio settings from %s\n", settingsPath)
//Load factorio version
out, err := exec.Command(config.FactorioBinary, "--version").Output()
if err != nil {
log.Printf("error on loading factorio version: %s", err)
return
}
reg := regexp.MustCompile("Version.*?((\\d+\\.)?(\\d+\\.)?(\\*|\\d+)+)")
found := reg.FindStringSubmatch(string(out))
f.Version = found[1]
//Load baseMod version
baseModInfoFile := filepath.Join(config.FactorioDir, "data", "base", "info.json")
bmifBa, err := ioutil.ReadFile(baseModInfoFile)
if err != nil {
log.Printf("couldn't open baseMods info.json: %s", err)
return
}
var modInfo ModInfo
err = json.Unmarshal(bmifBa, &modInfo)
if err != nil {
log.Printf("error unmarshalling baseMods info.json to a modInfo: %s", err)
return
}
f.BaseModVersion = modInfo.Version
return
}

View File

@ -435,6 +435,18 @@ func CheckServer(w http.ResponseWriter, r *http.Request) {
}
}
func FactorioVersion(w http.ResponseWriter, r *http.Request) {
resp := JSONResponse{
Success: true,
}
status := map[string]string{}
status["version"] = FactorioServ.Version
status["base_mod_version"] = FactorioServ.BaseModVersion
resp.Data = status
}
func LoginUser(w http.ResponseWriter, r *http.Request) {
resp := JSONResponse{
Success: false,

View File

@ -273,6 +273,11 @@ var apiRoutes = Routes{
"GET",
"/server/status",
CheckServer,
}, {
"FactorioVersion",
"GET",
"/server/facVersion",
FactorioVersion,
}, {
"LogoutUser",
"GET",

View File

@ -15,9 +15,12 @@ class App extends React.Component {
this.getSaves = this.getSaves.bind(this);
this.getStatus = this.getStatus.bind(this);
this.connectWebSocket = this.connectWebSocket.bind(this);
this.getFactorioVersion = this.getFactorioVersion.bind(this);
this.state = {
serverRunning: "stopped",
serverStatus: {},
factorioVersion: {},
saves: [],
loggedIn: false,
username: "",
@ -35,6 +38,7 @@ class App extends React.Component {
}
}, 1000);
this.connectWebSocket();
this.getFactorioVersion(); //Init serverStatus, so i know, which factorio-version is installed
}
connectWebSocket() {
@ -67,7 +71,9 @@ class App extends React.Component {
url: "/api/server/status",
dataType: "json",
success: (data) => {
this.setState({serverRunning: data.data.status})
this.setState({
serverRunning: data.data.status
})
}
})
}
@ -98,7 +104,22 @@ class App extends React.Component {
url: "/api/server/status",
dataType: "json",
success: (data) => {
this.setState({serverStatus: data.data})
this.setState({
serverStatus: data.data
})
},
error: (xhr, status, err) => {
console.log('api/server/status', status, err.toString());
}
})
}
getFactorioVersion() {
$:ajax({
url: "/api/server/facVersion",
dataType: "json",
success: (data) => {
},
error: (xhr, status, err) => {
console.log('api/server/status', status, err.toString());

View File

@ -24,6 +24,9 @@ class ModsContent extends React.Component {
this.updateCountSubtract = this.updateCountSubtract.bind(this);
this.updateCountAdd = this.updateCountAdd.bind(this);
this.test = this.test.bind(this);
this.state = {
loggedIn: false,
installedMods: null,
@ -479,7 +482,6 @@ class ModsContent extends React.Component {
e.stopPropagation();
let updateButtons = $('#manage-mods').find(".update-button");
// $('.update-button').click();
$.each(updateButtons, (k, v) => {
v.click();
});
@ -503,6 +505,10 @@ class ModsContent extends React.Component {
});
}
test() {
console.log(this.props);
}
render() {
return(
<div className="content-wrapper">
@ -533,6 +539,7 @@ class ModsContent extends React.Component {
factorioLogoutHandler={this.factorioLogoutHandler}
/>
</section>
<section onClick={this.test}>TEST</section>
</div>
)
}