Skip to content

Commit

Permalink
fixed logout endpoint & notauth page, lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Taraman17 committed Feb 26, 2024
1 parent 5bbbf9e commit 317351a
Show file tree
Hide file tree
Showing 13 changed files with 635 additions and 635 deletions.
82 changes: 37 additions & 45 deletions OfficialMaps.json
Original file line number Diff line number Diff line change
@@ -1,45 +1,37 @@
{
"ar_baggage": 125440026,
"ar_monastery": 125440154,
"ar_shoots": 125440261,
"cs_agency": 1464919827,
"cs_assault": 125432575,
"de_boyard": 2926953717,
"de_chalice": 2926952684,
"cs_climb": 2537983994,
"cs_insertion2": 2650330155,
"cs_italy": 125436057,
"cs_militia": 133256570,
"cs_office": 125444404,
"de_ancient": 2627571649,
"de_anubis": 1984883124,
"de_crete": 1220681096,
"de_bank": 125440342,
"de_basalt": 2627569615,
"de_blagai": 2791116183,
"de_breach": 1258599704,
"de_cache": 2606407435,
"de_canals": 951287718,
"de_cbble": 205239595,
"de_dust2": 125438255,
"de_extraction": 2650340943,
"de_hive": 2539316567,
"de_inferno": 125438669,
"de_iris": 1591780701,
"de_lake": 125440557,
"de_mirage": 152508932,
"de_nuke": 125439125,
"de_overpass": 205240106,
"de_prime": 2831565855,
"de_ravine": 2615546425,
"de_safehouse": 125440714,
"de_shortnuke": 2131550446,
"de_stmarc": 125441004,
"de_sugarcane": 125440847,
"de_train": 125438372,
"de_tuscan": 2458920550,
"de_vertigo": 125439851,
"dz_ember": 2681770529,
"dz_vineyard": 2587298130,
"gd_cbble": 782012846
}
[{
"name": "ar_baggage",
"id": 125440026
},{
"name": "ar_shoots",
"id" : 125440261
},{
"name": "cs_italy",
"id": 125436057
},{
"name": "cs_office",
"id": 125444404
},{
"name": "de_ancient",
"id": 2627571649
},{
"name": "de_anubis",
"id": 1984883124
},{
"name": "de_dust2",
"id": 125438255
},{
"name": "de_inferno",
"id": 125438669
},{
"name": "de_mirage",
"id": 152508932
},{
"name": "de_nuke",
"id": 125439125
},{
"name": "de_overpass",
"id": 205240106
},{
"name": "de_vertigo",
"id": 125439851
}]
26 changes: 16 additions & 10 deletions modules/apiV10.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ router.get('/control/start', (req, res) => {
}
let commandLine = `${cfg.serverCommandline} +map ${startMap}`;
logger.info(commandLine);
let serverProcess = exec(commandLine, (error, stdout, stderr) => {
exec(commandLine, (error, stdout, stderr) => {
if (error) {
// node couldn't execute the command.
res.status(501).json({ "error": error.code });
Expand Down Expand Up @@ -443,12 +443,17 @@ router.get('/control/stop', (req, res) => {
controlEmitter.emit('exec', 'stop', 'start');
logger.verbose("sending quit.");
sf.executeRcon('quit').then((answer) => {
// CHostStateMgr::QueueNewRequest( Quitting, 8 )
// TODO: find out if command quit can fail.
serverInfo.serverState.serverRunning = false;
serverInfo.serverState.authenticated = false;
serverInfo.reset();
res.json({ "success": true });
if (answer.indexOf("CHostStateMgr::QueueNewRequest( Quitting") != -1) {
// CHostStateMgr::QueueNewRequest( Quitting, 8 )
// TODO: find out if command quit can fail.
serverInfo.serverState.serverRunning = false;
serverInfo.serverState.authenticated = false;
serverInfo.reset();
res.json({ "success": true });
} else {
res.status(501).json({ "error": `RCON response not correct.` });
logger.warn("Stopping the server failed - rcon command not successful");
}
controlEmitter.emit('exec', 'stop', 'end');
}).catch((err) => {
logger.error('Stopping server Failed: ' + err);
Expand Down Expand Up @@ -484,12 +489,13 @@ router.get('/control/stop', (req, res) => {
router.get('/control/kill', (req, res) => {
exec('/bin/ps -A |grep cs2', (error, stdout, stderr) => {
if (error) {
logger.error(`exec error: ${error}`);
logger.error(`exec error: ${error}, ${stderr}`);
res.status(501).json({ "error": "Could not find csgo server process" });
} else if (stdout.match(/cs2/) != null) {
let pid = stdout.split(/\s+/)[1];
exec(`/bin/kill ${pid}`, (error, stdout, stderr) => {
if (error) {
logger.warn(`Server process could not be killed: ${error}: ${stderr}`);
res.status(501).json({ "error": "Could not kill csgo server process" });
} else {
// reset API-State
Expand Down Expand Up @@ -563,7 +569,7 @@ router.get('/control/update', (req, res) => {
res.json(`{ "success": true }`);
updateProcess.once('close', (code) => {
if (!updateSuccess) {
logger.warn('Update exited without success.');
logger.warn(`Update exited without success. Exit code: ${code}`);
controlEmitter.emit('progress', 'Update failed!', 100);
controlEmitter.emit('exec', 'update', 'fail');
}
Expand All @@ -573,7 +579,7 @@ router.get('/control/update', (req, res) => {
if (updateSuccess) {
res.json({ "success": true });
} else {
logger.warn('Update exited without success.');
logger.warn(`Update exited without success. Exit code: ${code}`);
res.status(501).json({ "error": "Update was not successful" });
}
controlEmitter.emit('exec', 'update', 'end');
Expand Down
100 changes: 52 additions & 48 deletions modules/configClass.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,146 +2,150 @@
* Config class for CSGO Server API
*/
class config {
constructor() {
this._userOptions = require('../config.js');
#userOptions = require('../config.js');
#screenCommand;
#csgoCommand;
#serverTokenCommand;
#localIp;

this._screenCommand = `${this._userOptions.screen} -L -Logfile ${this._userOptions.screenLog} -dmS ${this._userOptions.screenName}`;
this._csgoCommand = `${this._userOptions.csgoDir}game/bin/linuxsteamrt64/cs2 -dedicated`;
this._serverTokenCommand = `+sv_setsteamaccount ${this._userOptions.serverToken}`;
this._localIp = '';
constructor() {
this.#screenCommand = `${this.#userOptions.screen} -L -Logfile ${this.#userOptions.screenLog} -dmS ${this.#userOptions.screenName}`;
this.#csgoCommand = `${this.#userOptions.csgoDir}game/bin/linuxsteamrt64/cs2 -dedicated`;
this.#serverTokenCommand = `+sv_setsteamaccount ${this.#userOptions.serverToken}`;
this.#localIp = '';
}
get _csgoArgs() {
return `-console -usercon -ip 0.0.0.0 +sv_logfile 1 -serverlogging +logaddress_add_http "http://${this._localIp}:${this.logPort}/log" ${this._userOptions.csgoOptionalArgs}`;
get #csgoArgs() {
return `-console -usercon -ip 0.0.0.0 +sv_logfile 1 -serverlogging +logaddress_add_http "http://${this.#localIp}:${this.#userOptions.logPort}/log" ${this.#userOptions.csgoOptionalArgs}`;
}

get apiToken() {
return this._userOptions.apiToken;
return this.#userOptions.apiToken;
}
get rconPass() {
return this._userOptions.rconPass;
return this.#userOptions.rconPass;
}

get admins() {
return this._userOptions.admins;
return this.#userOptions.admins;
}

get workshopCollection() {
return this._userOptions.workshopCollection;
return this.#userOptions.workshopCollection;
}
set workshopCollection(id) {
this._userOptions.workshopCollection = id;
this.#userOptions.workshopCollection = id;
}
get workshopMaps() {
return this._userOptions.workshopMaps;
return this.#userOptions.workshopMaps;
}
set workshopMaps(maps) {
this._userOptions.workshopMaps = maps;
this.#userOptions.workshopMaps = maps;
}

get redirectPage() {
if (this._userOptions.redirectPage) {
return this._userOptions.redirectPage;
if (this.#userOptions.redirectPage) {
return this.#userOptions.redirectPage;
} else {
return ('/gameserver.htm');
}
}

get loginValidity() {
return this._userOptions.loginValidity * 60000;
return this.#userOptions.loginValidity * 60000;
}

get httpAuth() {
return this._userOptions.httpAuth;
return this.#userOptions.httpAuth;
}
get httpUser() {
return this._userOptions.httpUser;
return this.#userOptions.httpUser;
}

get iface() {
return this._userOptions.iface;
return this.#userOptions.iface;
}

get localIp() {
return this._localIp;
return this.#localIp;
}
set localIp(ip) {
this._localIp = ip;
this.#localIp = ip;
}
get host() {
if (this._userOptions.host != '') {
return this._userOptions.host;
if (this.#userOptions.host != '' && this.#userOptions.useHttps) {
return this.#userOptions.host;
} else {
return this._localIp
return this.#localIp
}
}

get apiPort() {
return this._userOptions.apiPort;
return this.#userOptions.apiPort;
}
get socketPort() {
return this._userOptions.socketPort;
return this.#userOptions.socketPort;
}
get logPort() {
return this._userOptions.logPort;
return this.#userOptions.logPort;
}

get serverCommandline() {
let command = `${this._screenCommand} ${this._csgoCommand} ${this._csgoArgs}`;
let command = `${this.#screenCommand} ${this.#csgoCommand} ${this.#csgoArgs}`;
if (this._csgoToken != '') {
command = `${command} ${this._serverTokenCommand}`;
command = `${command} ${this.#serverTokenCommand}`;
}
return command;
}
get steamCommand() {
return this._userOptions.steamExe
return this.#userOptions.steamExe
}
get updateScript() {
if (this._userOptions.updateScript != ''){
return this._userOptions.updateScript;
if (this.#userOptions.updateScript != ''){
return this.#userOptions.updateScript;
} else {
return `${this._userOptions.csgoDir}update_cs2.txt`;
return `${this.#userOptions.csgoDir}update_cs2.txt`;
}
}

get webSockets() {
return this._userOptions.webSockets;
return this.#userOptions.webSockets;
}
get useHttps() {
return this._userOptions.useHttps;
return this.#userOptions.useHttps;
}
get scheme() {
return (this._userOptions.useHttps ? 'https' : 'http');
return (this.#userOptions.useHttps ? 'https' : 'http');
}
get httpsCertificate() {
return this._userOptions.httpsCertificate;
return this.#userOptions.httpsCertificate;
}
get httpsPrivateKey() {
return this._userOptions.httpsPrivateKey;
return this.#userOptions.httpsPrivateKey;
}
get httpsCa() {
return this._userOptions.httpsCa;
return this.#userOptions.httpsCa;
}

get corsOrigin() {
return this._userOptions.corsOrigin;
return this.#userOptions.corsOrigin;
}
get sessionSecret() {
return this._userOptions.sessionSecret;
return this.#userOptions.sessionSecret;
}

script(type) {
return this._userOptions[`${type}Script`];
return this.#userOptions[`${type}Script`];
}

get logFile() {
return this._userOptions.logFile;
return this.#userOptions.logFile;
}
get logLevel() {
return this._userOptions.logLevel;
return this.#userOptions.logLevel;
}
get logDays() {
return this._userOptions.logDays;
return this.#userOptions.logDays;
}
};
}

module.exports = new config();
Loading

0 comments on commit 317351a

Please sign in to comment.