Skip to content

Commit 317351a

Browse files
committed
fixed logout endpoint & notauth page, lint fixes
1 parent 5bbbf9e commit 317351a

File tree

13 files changed

+635
-635
lines changed

13 files changed

+635
-635
lines changed

OfficialMaps.json

Lines changed: 37 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,37 @@
1-
{
2-
"ar_baggage": 125440026,
3-
"ar_monastery": 125440154,
4-
"ar_shoots": 125440261,
5-
"cs_agency": 1464919827,
6-
"cs_assault": 125432575,
7-
"de_boyard": 2926953717,
8-
"de_chalice": 2926952684,
9-
"cs_climb": 2537983994,
10-
"cs_insertion2": 2650330155,
11-
"cs_italy": 125436057,
12-
"cs_militia": 133256570,
13-
"cs_office": 125444404,
14-
"de_ancient": 2627571649,
15-
"de_anubis": 1984883124,
16-
"de_crete": 1220681096,
17-
"de_bank": 125440342,
18-
"de_basalt": 2627569615,
19-
"de_blagai": 2791116183,
20-
"de_breach": 1258599704,
21-
"de_cache": 2606407435,
22-
"de_canals": 951287718,
23-
"de_cbble": 205239595,
24-
"de_dust2": 125438255,
25-
"de_extraction": 2650340943,
26-
"de_hive": 2539316567,
27-
"de_inferno": 125438669,
28-
"de_iris": 1591780701,
29-
"de_lake": 125440557,
30-
"de_mirage": 152508932,
31-
"de_nuke": 125439125,
32-
"de_overpass": 205240106,
33-
"de_prime": 2831565855,
34-
"de_ravine": 2615546425,
35-
"de_safehouse": 125440714,
36-
"de_shortnuke": 2131550446,
37-
"de_stmarc": 125441004,
38-
"de_sugarcane": 125440847,
39-
"de_train": 125438372,
40-
"de_tuscan": 2458920550,
41-
"de_vertigo": 125439851,
42-
"dz_ember": 2681770529,
43-
"dz_vineyard": 2587298130,
44-
"gd_cbble": 782012846
45-
}
1+
[{
2+
"name": "ar_baggage",
3+
"id": 125440026
4+
},{
5+
"name": "ar_shoots",
6+
"id" : 125440261
7+
},{
8+
"name": "cs_italy",
9+
"id": 125436057
10+
},{
11+
"name": "cs_office",
12+
"id": 125444404
13+
},{
14+
"name": "de_ancient",
15+
"id": 2627571649
16+
},{
17+
"name": "de_anubis",
18+
"id": 1984883124
19+
},{
20+
"name": "de_dust2",
21+
"id": 125438255
22+
},{
23+
"name": "de_inferno",
24+
"id": 125438669
25+
},{
26+
"name": "de_mirage",
27+
"id": 152508932
28+
},{
29+
"name": "de_nuke",
30+
"id": 125439125
31+
},{
32+
"name": "de_overpass",
33+
"id": 205240106
34+
},{
35+
"name": "de_vertigo",
36+
"id": 125439851
37+
}]

modules/apiV10.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ router.get('/control/start', (req, res) => {
294294
}
295295
let commandLine = `${cfg.serverCommandline} +map ${startMap}`;
296296
logger.info(commandLine);
297-
let serverProcess = exec(commandLine, (error, stdout, stderr) => {
297+
exec(commandLine, (error, stdout, stderr) => {
298298
if (error) {
299299
// node couldn't execute the command.
300300
res.status(501).json({ "error": error.code });
@@ -443,12 +443,17 @@ router.get('/control/stop', (req, res) => {
443443
controlEmitter.emit('exec', 'stop', 'start');
444444
logger.verbose("sending quit.");
445445
sf.executeRcon('quit').then((answer) => {
446-
// CHostStateMgr::QueueNewRequest( Quitting, 8 )
447-
// TODO: find out if command quit can fail.
448-
serverInfo.serverState.serverRunning = false;
449-
serverInfo.serverState.authenticated = false;
450-
serverInfo.reset();
451-
res.json({ "success": true });
446+
if (answer.indexOf("CHostStateMgr::QueueNewRequest( Quitting") != -1) {
447+
// CHostStateMgr::QueueNewRequest( Quitting, 8 )
448+
// TODO: find out if command quit can fail.
449+
serverInfo.serverState.serverRunning = false;
450+
serverInfo.serverState.authenticated = false;
451+
serverInfo.reset();
452+
res.json({ "success": true });
453+
} else {
454+
res.status(501).json({ "error": `RCON response not correct.` });
455+
logger.warn("Stopping the server failed - rcon command not successful");
456+
}
452457
controlEmitter.emit('exec', 'stop', 'end');
453458
}).catch((err) => {
454459
logger.error('Stopping server Failed: ' + err);
@@ -484,12 +489,13 @@ router.get('/control/stop', (req, res) => {
484489
router.get('/control/kill', (req, res) => {
485490
exec('/bin/ps -A |grep cs2', (error, stdout, stderr) => {
486491
if (error) {
487-
logger.error(`exec error: ${error}`);
492+
logger.error(`exec error: ${error}, ${stderr}`);
488493
res.status(501).json({ "error": "Could not find csgo server process" });
489494
} else if (stdout.match(/cs2/) != null) {
490495
let pid = stdout.split(/\s+/)[1];
491496
exec(`/bin/kill ${pid}`, (error, stdout, stderr) => {
492497
if (error) {
498+
logger.warn(`Server process could not be killed: ${error}: ${stderr}`);
493499
res.status(501).json({ "error": "Could not kill csgo server process" });
494500
} else {
495501
// reset API-State
@@ -563,7 +569,7 @@ router.get('/control/update', (req, res) => {
563569
res.json(`{ "success": true }`);
564570
updateProcess.once('close', (code) => {
565571
if (!updateSuccess) {
566-
logger.warn('Update exited without success.');
572+
logger.warn(`Update exited without success. Exit code: ${code}`);
567573
controlEmitter.emit('progress', 'Update failed!', 100);
568574
controlEmitter.emit('exec', 'update', 'fail');
569575
}
@@ -573,7 +579,7 @@ router.get('/control/update', (req, res) => {
573579
if (updateSuccess) {
574580
res.json({ "success": true });
575581
} else {
576-
logger.warn('Update exited without success.');
582+
logger.warn(`Update exited without success. Exit code: ${code}`);
577583
res.status(501).json({ "error": "Update was not successful" });
578584
}
579585
controlEmitter.emit('exec', 'update', 'end');

modules/configClass.js

Lines changed: 52 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,146 +2,150 @@
22
* Config class for CSGO Server API
33
*/
44
class config {
5-
constructor() {
6-
this._userOptions = require('../config.js');
5+
#userOptions = require('../config.js');
6+
#screenCommand;
7+
#csgoCommand;
8+
#serverTokenCommand;
9+
#localIp;
710

8-
this._screenCommand = `${this._userOptions.screen} -L -Logfile ${this._userOptions.screenLog} -dmS ${this._userOptions.screenName}`;
9-
this._csgoCommand = `${this._userOptions.csgoDir}game/bin/linuxsteamrt64/cs2 -dedicated`;
10-
this._serverTokenCommand = `+sv_setsteamaccount ${this._userOptions.serverToken}`;
11-
this._localIp = '';
11+
constructor() {
12+
this.#screenCommand = `${this.#userOptions.screen} -L -Logfile ${this.#userOptions.screenLog} -dmS ${this.#userOptions.screenName}`;
13+
this.#csgoCommand = `${this.#userOptions.csgoDir}game/bin/linuxsteamrt64/cs2 -dedicated`;
14+
this.#serverTokenCommand = `+sv_setsteamaccount ${this.#userOptions.serverToken}`;
15+
this.#localIp = '';
1216
}
13-
get _csgoArgs() {
14-
return `-console -usercon -ip 0.0.0.0 +sv_logfile 1 -serverlogging +logaddress_add_http "http://${this._localIp}:${this.logPort}/log" ${this._userOptions.csgoOptionalArgs}`;
17+
get #csgoArgs() {
18+
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}`;
1519
}
1620

1721
get apiToken() {
18-
return this._userOptions.apiToken;
22+
return this.#userOptions.apiToken;
1923
}
2024
get rconPass() {
21-
return this._userOptions.rconPass;
25+
return this.#userOptions.rconPass;
2226
}
2327

2428
get admins() {
25-
return this._userOptions.admins;
29+
return this.#userOptions.admins;
2630
}
2731

2832
get workshopCollection() {
29-
return this._userOptions.workshopCollection;
33+
return this.#userOptions.workshopCollection;
3034
}
3135
set workshopCollection(id) {
32-
this._userOptions.workshopCollection = id;
36+
this.#userOptions.workshopCollection = id;
3337
}
3438
get workshopMaps() {
35-
return this._userOptions.workshopMaps;
39+
return this.#userOptions.workshopMaps;
3640
}
3741
set workshopMaps(maps) {
38-
this._userOptions.workshopMaps = maps;
42+
this.#userOptions.workshopMaps = maps;
3943
}
4044

4145
get redirectPage() {
42-
if (this._userOptions.redirectPage) {
43-
return this._userOptions.redirectPage;
46+
if (this.#userOptions.redirectPage) {
47+
return this.#userOptions.redirectPage;
4448
} else {
4549
return ('/gameserver.htm');
4650
}
4751
}
4852

4953
get loginValidity() {
50-
return this._userOptions.loginValidity * 60000;
54+
return this.#userOptions.loginValidity * 60000;
5155
}
5256

5357
get httpAuth() {
54-
return this._userOptions.httpAuth;
58+
return this.#userOptions.httpAuth;
5559
}
5660
get httpUser() {
57-
return this._userOptions.httpUser;
61+
return this.#userOptions.httpUser;
5862
}
5963

6064
get iface() {
61-
return this._userOptions.iface;
65+
return this.#userOptions.iface;
6266
}
6367

6468
get localIp() {
65-
return this._localIp;
69+
return this.#localIp;
6670
}
6771
set localIp(ip) {
68-
this._localIp = ip;
72+
this.#localIp = ip;
6973
}
7074
get host() {
71-
if (this._userOptions.host != '') {
72-
return this._userOptions.host;
75+
if (this.#userOptions.host != '' && this.#userOptions.useHttps) {
76+
return this.#userOptions.host;
7377
} else {
74-
return this._localIp
78+
return this.#localIp
7579
}
7680
}
7781

7882
get apiPort() {
79-
return this._userOptions.apiPort;
83+
return this.#userOptions.apiPort;
8084
}
8185
get socketPort() {
82-
return this._userOptions.socketPort;
86+
return this.#userOptions.socketPort;
8387
}
8488
get logPort() {
85-
return this._userOptions.logPort;
89+
return this.#userOptions.logPort;
8690
}
8791

8892
get serverCommandline() {
89-
let command = `${this._screenCommand} ${this._csgoCommand} ${this._csgoArgs}`;
93+
let command = `${this.#screenCommand} ${this.#csgoCommand} ${this.#csgoArgs}`;
9094
if (this._csgoToken != '') {
91-
command = `${command} ${this._serverTokenCommand}`;
95+
command = `${command} ${this.#serverTokenCommand}`;
9296
}
9397
return command;
9498
}
9599
get steamCommand() {
96-
return this._userOptions.steamExe
100+
return this.#userOptions.steamExe
97101
}
98102
get updateScript() {
99-
if (this._userOptions.updateScript != ''){
100-
return this._userOptions.updateScript;
103+
if (this.#userOptions.updateScript != ''){
104+
return this.#userOptions.updateScript;
101105
} else {
102-
return `${this._userOptions.csgoDir}update_cs2.txt`;
106+
return `${this.#userOptions.csgoDir}update_cs2.txt`;
103107
}
104108
}
105109

106110
get webSockets() {
107-
return this._userOptions.webSockets;
111+
return this.#userOptions.webSockets;
108112
}
109113
get useHttps() {
110-
return this._userOptions.useHttps;
114+
return this.#userOptions.useHttps;
111115
}
112116
get scheme() {
113-
return (this._userOptions.useHttps ? 'https' : 'http');
117+
return (this.#userOptions.useHttps ? 'https' : 'http');
114118
}
115119
get httpsCertificate() {
116-
return this._userOptions.httpsCertificate;
120+
return this.#userOptions.httpsCertificate;
117121
}
118122
get httpsPrivateKey() {
119-
return this._userOptions.httpsPrivateKey;
123+
return this.#userOptions.httpsPrivateKey;
120124
}
121125
get httpsCa() {
122-
return this._userOptions.httpsCa;
126+
return this.#userOptions.httpsCa;
123127
}
124128

125129
get corsOrigin() {
126-
return this._userOptions.corsOrigin;
130+
return this.#userOptions.corsOrigin;
127131
}
128132
get sessionSecret() {
129-
return this._userOptions.sessionSecret;
133+
return this.#userOptions.sessionSecret;
130134
}
131135

132136
script(type) {
133-
return this._userOptions[`${type}Script`];
137+
return this.#userOptions[`${type}Script`];
134138
}
135139

136140
get logFile() {
137-
return this._userOptions.logFile;
141+
return this.#userOptions.logFile;
138142
}
139143
get logLevel() {
140-
return this._userOptions.logLevel;
144+
return this.#userOptions.logLevel;
141145
}
142146
get logDays() {
143-
return this._userOptions.logDays;
147+
return this.#userOptions.logDays;
144148
}
145-
};
149+
}
146150

147151
module.exports = new config();

0 commit comments

Comments
 (0)