Skip to content

Commit

Permalink
Created git repo.
Browse files Browse the repository at this point in the history
  • Loading branch information
expl0iit committed Aug 2, 2018
0 parents commit 203991b
Show file tree
Hide file tree
Showing 14 changed files with 3,919 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist/
node_modules/
49 changes: 49 additions & 0 deletions clientLauncher.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const { exec } = require('child_process');
const { existsSync } = require('fs');

class ClientLauncher{
constructor(binaryPath){
this.binaryPath = binaryPath;
}

launchClient(args){
var self = this;

return new Promise(function(resolve, reject){
var commandElements = [];
var udkArgs = [];

// Start the command off with the binary
if(self.binaryPath){
if(existsSync(self.binaryPath)){
commandElements.push('"' + self.binaryPath + '"');
}else{
reject("The game binary specified in the config does not exist.");
}
}else{
reject("The location of the game binary has not been specified in the config.");
}

// Dedicated Server?
if(args.dedicated) commandElements.push("server");

// Map/IP
if(args.map) commandElements.push(args.map);
else if(args.ip) commandElements.push(args.ip);

// Username
if(args.nickname) udkArgs.push("?name=" + args.nickname);

// If hosting server, listen for connections
if(args.action == "host") udkArgs.push("?listen=true");

// Generate the command
var command = commandElements.join(" ") + " " + udkArgs.join("");
exec(command);

resolve(command);
});
}
}

module.exports = ClientLauncher;
129 changes: 129 additions & 0 deletions configManager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
const fs = require('fs');

/*
module.exports = {
defaultConfig: {
binary: "Game\\Binaries\\Win64\\RxGame-Win64-Test.exe",
maps: {
"lv_canyon": "Ghost Reef",
"lv_mistforge": "Sanctum Falls",
"lv_valley": "Siren's Strand",
"lv_wizardwoods": "Ember Grove",
"lv_skycity": "Sky City",
"lv_magma": "Magma",
"lv_grassland": "Practice Range"
}
},
loadConfig: function(filePath){
var self = this;
return new Promise(function(resolve, reject){
fs.readFile(filePath, (err, data) => {
var config = self.defaultConfig;
if(err){
if(err.code == "ENOENT"){
resolve(config);
self.saveConfig(filePath, self.defaultConfig);
}else{
console.log(err);
resolve(config);
}
return false;
}
try{
config = JSON.parse(data);
}catch(err){
console.log(err);
console.log("Returning default config and resetting config file...");
resolve(config);
self.saveConfig(filePath, self.defaultConfig);
}
resolve(config);
});
});
},
saveConfig: function(filePath, config){
return new Promise(function(resolve, reject){
let configJSON = JSON.stringify(config);
fs.writeFile(filePath, configJSON, (err) => {
if(err) reject(err);
resolve();
});
});
}
};
*/

class ConfigManager{

constructor(filePath){
this.filePath = filePath;
this.defaultConfig = {
binaryPath: "Game\\Binaries\\Win64\\RxGame-Win64-Test.exe",
maps: {
"lv_canyon": "Ghost Reef",
"lv_mistforge": "Sanctum Falls",
"lv_valley": "Siren's Strand",
"lv_wizardwoods": "Ember Grove",
"lv_skycity": "Sky City",
"lv_magma": "Magma",
"lv_grassland": "Practice Range"
}
};
this.config = Object.assign({}, this.defaultConfig);
}

load(){
var self = this;

return new Promise(function(resolve, reject){
fs.readFile(self.filePath, (err, data) => {
var config = self.defaultConfig;

if(err){
if(err.code == "ENOENT"){
resolve(config);
self.save(config);
}else{
console.log(err);
resolve(config);
}
return false;
}

try{
config = JSON.parse(data);
self.config = config;
}catch(err){
console.log(err);
console.log("Returning default config and resetting config file...");
resolve(config);
self.save(config);
}

resolve(config);
});
});
}

save(){
var self = this;

return new Promise(function(resolve, reject){
let configJSON = JSON.stringify(self.config);

fs.writeFile(self.filePath, configJSON, (err) => {
if(err) reject(err);
resolve();
});
});
}
}

module.exports = ConfigManager;
Binary file added icon.ico
Binary file not shown.
64 changes: 64 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
const { app, ipcMain } = require('electron');
const ConfigManager = require('./configManager.js');
const MainWindow = require('./mainWindow.js');
const ClientLauncher = require('./clientLauncher.js');

var configManager = new ConfigManager("config.json");

// Main Window
app.on("ready", MainWindow.create);

app.on("window-all-closed", () => {
app.quit();
});

// Config
ipcMain.on("config-request", (event, data) => {
console.log("Config request recieved.");

configManager.load()
.then((config) => {
console.log(config);
console.log("Config loaded, sending to requester...");
event.sender.send("config", config);
});
});

ipcMain.on("change-config", (event, data) => {
console.log("Config change request recieved.");
console.log(data);

configManager.config = Object.assign(configManager.config, data);
configManager.save();

event.sender.send("config", configManager.config);
});

// Client Launching
ipcMain.on("launch-request", (event, data) => {
console.log("Launch request recieved.");
console.log(data);

// Save the nickname
if(typeof data.nickname != "undefined"){
configManager.config.nickname = data.nickname;
configManager.save();
}

// Launch the client
var launcher = new ClientLauncher(configManager.config.binaryPath);
launcher.launchClient(data)
.then((command) => {
console.log("Launching client with the following command:");
console.log(command);

event.sender.send("show-loading-overlay", {
message: "loading-client",
timeout: 60 * 1000
});
})
.catch((error) => {
console.log("An error occured while launching the game:", error);
event.sender.send("show-error", error);
});
});
29 changes: 29 additions & 0 deletions mainWindow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const { BrowserWindow } = require('electron');

module.exports = {
window: null,
create: function(){
var self = this;

self.window = new BrowserWindow({
width: 600,
height: 450,
resizable: false,
maximizable: false,
fullscreenable: false,
autoHideMenuBar: true,
//devTools: true,

title: "Gigantic Launcher",
icon: __dirname + "/icon.ico"
});

self.window.loadFile("./pages/index.html");

self.window.on("closed", function(){
self.window = null;
});

return self.window.mainWindow;
}
};
Loading

0 comments on commit 203991b

Please sign in to comment.