1
- const express = require ( 'express' ) ;
2
- var router = express . Router ( ) ;
3
- const { exec } = require ( 'child_process' ) ;
4
- var controlEmitter = require ( './controlEmitter.js' ) ;
5
- const logger = require ( './logger.js' ) ;
6
- var serverInfo = require ( './serverInfo.js' ) ;
7
- const sf = require ( './sharedFunctions.js' ) ;
8
- var cfg = require ( './configClass.js' ) ;
9
-
10
- router . post ( '/log' , ( req , res ) => {
11
- const data = req . body ;
12
- var logs = data . split ( / \r \n | \r | \n / ) ;
13
-
14
- logs . forEach ( line => {
15
- if ( line . length >= 20 ) {
16
- // Start authentication, when not authenticated.
17
- if ( ( line . indexOf ( 'Log file started' ) != - 1 ) && ! serverInfo . serverState . authenticated ) {
18
- // Start of logfile
19
- // L 08/13/2020 - 21:48:49: Log file started (file "logs/L000_000_000_000_27015_202008132148_000.log") (game "/home/user/csgo_ds/csgo") (version "7929")
20
- logger . verbose ( 'start authenticating RCON' ) ;
21
- // Since authentication is a vital step for the API to work, we start it automatically
22
- // once the server runs.
23
- sf . authenticate ( ) . then ( ( data ) => {
24
- logger . verbose ( `authentication ${ data . authenticated } ` ) ;
25
- } ) . catch ( ( data ) => {
26
- logger . verbose ( `authentication ${ data . authenticated } ` ) ;
27
- } ) ;
28
- if ( cfg . script ( 'logStart' ) != '' ) {
29
- exec ( cfg . script ( 'logStart' ) ) ;
30
- }
31
- } else if ( line . indexOf ( 'Loading map ' ) != - 1 ) {
32
- // Start of map.
33
- // L 10/13/2023 - 14:28:38: Loading map "de_anubis"
34
- let rex = / L o a d i n g m a p \" ( \S + ) \" / g;
35
- let matches = rex . exec ( line ) ;
36
- let mapstring = matches [ 1 ] ;
37
- mapstring = sf . cutMapName ( mapstring ) ;
38
- serverInfo . map = mapstring ;
39
- serverInfo . pause = false ;
40
- // since 'started map' is also reported on server-start, only emit on mapchange.
41
- if ( serverInfo . serverState . operationPending == 'mapchange' ) {
42
- controlEmitter . emit ( 'exec' , 'mapchange' , 'end' ) ;
43
- }
44
- logger . verbose ( `Started map: ${ mapstring } ` ) ;
45
- serverInfo . clearPlayers ( ) ;
46
- serverInfo . newMatch ( ) ;
47
- if ( cfg . script ( 'mapStart' ) != '' ) {
48
- exec ( cfg . script ( 'mapStart' ) ) ;
49
- }
50
- } else if ( line . indexOf ( 'World triggered "Match_Start" on' ) != - 1 ) {
51
- // Start of a new match.
52
- // L 08/13/2020 - 21:49:26: World triggered "Match_Start" on "de_nuke"
53
- logger . verbose ( 'Detected match start.' ) ;
54
- sf . queryMaxRounds ( ) ;
55
- serverInfo . newMatch ( ) ;
56
- let rex = / W o r l d t r i g g e r e d " M a t c h _ S t a r t " o n " ( .+ ) " /
57
- let matches = rex . exec ( line )
58
- serverInfo . map = matches [ 1 ] ;
59
- if ( cfg . script ( 'matchStart' ) != '' ) {
60
- exec ( cfg . script ( 'matchStart' ) ) ;
61
- }
62
- } else if ( line . indexOf ( 'World triggered "Round_Start"' ) != - 1 ) {
63
- // Start of round.
64
- // L 08/13/2020 - 21:49:28: World triggered "Round_Start"
65
- if ( cfg . script ( 'roundStart' ) != '' ) {
66
- exec ( cfg . script ( 'roundStart' ) ) ;
67
- }
68
- } else if ( / T e a m \" \S + \" s c o r e d / . test ( line ) ) {
69
- // Team scores at end of round.
70
- // L 02/10/2019 - 21:31:15: Team "CT" scored "1" with "2" players
71
- // L 02/10/2019 - 21:31:15: Team "TERRORIST" scored "1" with "2" players
72
- rex = / T e a m \" ( \S ) \S + \" s c o r e d \" ( \d + ) \" / g;
73
- let matches = rex . exec ( line ) ;
74
- serverInfo . score = matches ;
75
- } else if ( line . indexOf ( 'World triggered "Round_End"' ) != - 1 ) {
76
- // End of round.
77
- // L 08/13/2020 - 22:24:22: World triggered "Round_End"
78
- if ( cfg . script ( 'roundEnd' ) != '' ) {
79
- exec ( cfg . script ( 'roundEnd' ) ) ;
80
- }
81
- } else if ( line . indexOf ( "Game Over:" ) != - 1 ) {
82
- // End of match.
83
- // L 08/13/2020 - 22:24:22: Game Over: competitive 131399785 de_nuke score 16:9 after 35 min
84
- if ( cfg . script ( 'matchEnd' ) != '' ) {
85
- exec ( cfg . script ( 'matchEnd' ) ) ;
86
- }
87
- } else if ( / \" .{ 1 , 32 } < \d { 1 , 3 } > < \[ \w : \d : \d { 1 , 10 } \] > / . test ( line ) ) {
88
- // Player join or teamchange.
89
- // 10/12/2023 - 16:06:38: "[Klosser] Taraman<2><[U:1:12610374]><>" entered the game
90
- // 10/12/2023 - 18:57:47: "[Klosser] Taraman<2><[U:1:12610374]>" switched from team <Unassigned> to <CT>
91
- // 10/12/2023 - 18:59:25: "[Klosser] Taraman<2><[U:1:12610374]>" switched from team <TERRORIST> to <Spectator>
92
- // 10/16/2023 - 16:31:59.699 - "[Klosser] Taraman<2><[U:1:12610374]><CT>" disconnected (reason "NETWORK_DISCONNECT_DISCONNECT_BY_USER")
93
- let rex = / \" ( .{ 1 , 32 } ) < \d { 1 , 3 } > < \[ ( \w : \d : \d { 1 , 10 } ) \] > < / g;
94
- let matches = rex . exec ( line ) ;
95
- if ( line . indexOf ( 'entered the game' ) != - 1 ) {
96
- serverInfo . addPlayer ( { 'name' : matches [ 1 ] , 'steamID' : matches [ 2 ] } ) ;
97
- } else if ( line . search ( / d i s c o n n e c t e d \( r e a s o n / ) != - 1 ) {
98
- logger . debug ( line ) ;
99
- serverInfo . removePlayer ( matches [ 2 ] ) ;
100
- } else if ( line . indexOf ( 'switched from team' ) != - 1 ) {
101
- rex = / < \[ ( \w : \d : \d { 1 , 10 } ) \] > \" s w i t c h e d f r o m t e a m < \S { 1 , 10 } > t o < ( \S { 1 , 10 } ) > / g;
102
- matches = rex . exec ( line ) ;
103
- serverInfo . assignPlayer ( matches [ 1 ] , matches [ 2 ] ) ;
104
- }
105
- } else if ( line . indexOf ( 'Log file closed' ) != - 1 ) {
106
- // end of current log file. (Usually on mapchange or server quit.)
107
- // L 08/13/2020 - 22:25:00: Log file closed
108
- logger . verbose ( 'logfile closed!' ) ;
109
- if ( cfg . script ( 'logEnd' ) != '' ) {
110
- exec ( cfg . script ( 'logEnd' ) ) ;
111
- }
112
- }
113
- }
114
- } ) ;
115
-
116
- res . status ( 200 ) . send ( "Receiving logs" ) ;
117
- } ) ;
118
-
1
+ const express = require ( 'express' ) ;
2
+ var router = express . Router ( ) ;
3
+ const { exec } = require ( 'child_process' ) ;
4
+ var controlEmitter = require ( './controlEmitter.js' ) ;
5
+ const logger = require ( './logger.js' ) ;
6
+ var serverInfo = require ( './serverInfo.js' ) ;
7
+ const sf = require ( './sharedFunctions.js' ) ;
8
+ var cfg = require ( './configClass.js' ) ;
9
+
10
+ router . post ( '/log' , ( req , res ) => {
11
+ const data = req . body ;
12
+ var logs = data . split ( / \r \n | \r | \n / ) ;
13
+
14
+ logs . forEach ( line => {
15
+ if ( line . length >= 20 ) {
16
+ // Start authentication, when not authenticated.
17
+ if ( ( line . indexOf ( 'Log file started' ) != - 1 ) && ! serverInfo . serverState . authenticated ) {
18
+ // Start of logfile
19
+ // L 08/13/2020 - 21:48:49: Log file started (file "logs/L000_000_000_000_27015_202008132148_000.log") (game "/home/user/csgo_ds/csgo") (version "7929")
20
+ logger . verbose ( 'start authenticating RCON' ) ;
21
+ // Since authentication is a vital step for the API to work, we start it automatically
22
+ // once the server runs.
23
+ sf . authenticate ( ) . then ( ( data ) => {
24
+ logger . verbose ( `authentication ${ data . authenticated } ` ) ;
25
+ } ) . catch ( ( data ) => {
26
+ logger . verbose ( `authentication ${ data . authenticated } ` ) ;
27
+ } ) ;
28
+ if ( cfg . script ( 'logStart' ) != '' ) {
29
+ exec ( cfg . script ( 'logStart' ) ) ;
30
+ }
31
+ } else if ( line . indexOf ( 'Loading map ' ) != - 1 ) {
32
+ // Start of map.
33
+ // L 10/13/2023 - 14:28:38: Loading map "de_anubis"
34
+ let rex = / L o a d i n g m a p \" ( \S + ) \" / g;
35
+ let matches = rex . exec ( line ) ;
36
+ let mapstring = matches [ 1 ] ;
37
+ mapstring = sf . cutMapName ( mapstring ) ;
38
+ serverInfo . map = mapstring ;
39
+ serverInfo . pause = false ;
40
+ // since 'started map' is also reported on server-start, only emit on mapchange.
41
+ if ( serverInfo . serverState . operationPending == 'mapchange' ) {
42
+ controlEmitter . emit ( 'exec' , 'mapchange' , 'end' ) ;
43
+ }
44
+ logger . verbose ( `Started map: ${ mapstring } ` ) ;
45
+ serverInfo . clearPlayers ( ) ;
46
+ serverInfo . newMatch ( ) ;
47
+ if ( cfg . script ( 'mapStart' ) != '' ) {
48
+ exec ( cfg . script ( 'mapStart' ) ) ;
49
+ }
50
+ } else if ( line . indexOf ( 'World triggered "Match_Start" on' ) != - 1 ) {
51
+ // Start of a new match.
52
+ // L 08/13/2020 - 21:49:26: World triggered "Match_Start" on "de_nuke"
53
+ logger . verbose ( 'Detected match start.' ) ;
54
+ sf . queryMaxRounds ( ) ;
55
+ serverInfo . newMatch ( ) ;
56
+ let rex = / W o r l d t r i g g e r e d " M a t c h _ S t a r t " o n " ( .+ ) " /
57
+ let matches = rex . exec ( line )
58
+ serverInfo . map = matches [ 1 ] ;
59
+ if ( cfg . script ( 'matchStart' ) != '' ) {
60
+ exec ( cfg . script ( 'matchStart' ) ) ;
61
+ }
62
+ } else if ( line . indexOf ( 'World triggered "Round_Start"' ) != - 1 ) {
63
+ // Start of round.
64
+ // L 08/13/2020 - 21:49:28: World triggered "Round_Start"
65
+ if ( cfg . script ( 'roundStart' ) != '' ) {
66
+ exec ( cfg . script ( 'roundStart' ) ) ;
67
+ }
68
+ } else if ( / T e a m \" \S + \" s c o r e d / . test ( line ) ) {
69
+ // Team scores at end of round.
70
+ // L 02/10/2019 - 21:31:15: Team "CT" scored "1" with "2" players
71
+ // L 02/10/2019 - 21:31:15: Team "TERRORIST" scored "1" with "2" players
72
+ rex = / T e a m \" ( \S ) \S + \" s c o r e d \" ( \d + ) \" / g;
73
+ let matches = rex . exec ( line ) ;
74
+ serverInfo . score = matches ;
75
+ } else if ( line . indexOf ( 'World triggered "Round_End"' ) != - 1 ) {
76
+ // End of round.
77
+ // L 08/13/2020 - 22:24:22: World triggered "Round_End"
78
+ if ( cfg . script ( 'roundEnd' ) != '' ) {
79
+ exec ( cfg . script ( 'roundEnd' ) ) ;
80
+ }
81
+ } else if ( line . indexOf ( "Game Over:" ) != - 1 ) {
82
+ // End of match.
83
+ // L 08/13/2020 - 22:24:22: Game Over: competitive 131399785 de_nuke score 16:9 after 35 min
84
+ if ( cfg . script ( 'matchEnd' ) != '' ) {
85
+ exec ( cfg . script ( 'matchEnd' ) ) ;
86
+ }
87
+ } else if ( / \" .{ 1 , 32 } < \d { 1 , 3 } > < \[ \w : \d : \d { 1 , 10 } \] > / . test ( line ) ) {
88
+ // Player join or teamchange.
89
+ // 10/12/2023 - 16:06:38: "[Klosser] Taraman<2><[U:1:12610374]><>" entered the game
90
+ // 10/12/2023 - 18:57:47: "[Klosser] Taraman<2><[U:1:12610374]>" switched from team <Unassigned> to <CT>
91
+ // 10/12/2023 - 18:59:25: "[Klosser] Taraman<2><[U:1:12610374]>" switched from team <TERRORIST> to <Spectator>
92
+ // 10/16/2023 - 16:31:59.699 - "[Klosser] Taraman<2><[U:1:12610374]><CT>" disconnected (reason "NETWORK_DISCONNECT_DISCONNECT_BY_USER")
93
+ // "Strapper<6><BOT><TERRORIST>"
94
+ let rex = / \" ( .{ 1 , 32 } ) < \d { 1 , 3 } > < \[ ( \w : \d : \d { 1 , 10 } ) \] > < / g;
95
+ let matches = rex . exec ( line ) ;
96
+ if ( line . indexOf ( 'entered the game' ) != - 1 ) {
97
+ serverInfo . addPlayer ( { 'name' : matches [ 1 ] , 'steamID' : matches [ 2 ] } ) ;
98
+ } else if ( line . search ( / d i s c o n n e c t e d \( r e a s o n / ) != - 1 ) {
99
+ serverInfo . removePlayer ( matches [ 2 ] ) ;
100
+ } else if ( line . indexOf ( 'switched from team' ) != - 1 ) {
101
+ rex = / \" ( .{ 1 , 32 } ) < \d { 1 , 3 } > < \[ ( \w : \d : \d { 1 , 10 } ) \] > \" s w i t c h e d f r o m t e a m < \S { 1 , 10 } > t o < ( \S { 1 , 10 } ) > / g;
102
+ matches = rex . exec ( line ) ;
103
+ serverInfo . assignPlayer ( matches [ 1 ] , matches [ 2 ] , matches [ 3 ] ) ;
104
+ } else if ( line . search ( / \[ \w : \d : \d { 1 , 10 } \] > < \w { 1 , 10 } > \" \[ .{ 1 , 5 } .{ 1 , 5 } .{ 1 , 5 } \] k i l l e d \" .{ 1 , 32 } < \d { 1 , 3 } > < \[ \w : \d : \d { 1 , 10 } \] / ) != - 1 ) {
105
+ rex = / \[ ( \w : \d : \d { 1 , 10 } ) \] > < \w { 1 , 10 } > \" \[ .{ 1 , 5 } .{ 1 , 5 } .{ 1 , 5 } \] k i l l e d \" .{ 1 , 32 } < \d { 1 , 3 } > < \[ ( \w : \d : \d { 1 , 10 } ) \] /
106
+ matches = rex . exec ( line ) ;
107
+ serverInfo . recordKill ( matches [ 1 ] , matches [ 2 ] ) ;
108
+ }
109
+ } else if ( line . indexOf ( 'Log file closed' ) != - 1 ) {
110
+ // end of current log file. (Usually on mapchange or server quit.)
111
+ // L 08/13/2020 - 22:25:00: Log file closed
112
+ logger . verbose ( 'logfile closed!' ) ;
113
+ if ( cfg . script ( 'logEnd' ) != '' ) {
114
+ exec ( cfg . script ( 'logEnd' ) ) ;
115
+ }
116
+ }
117
+ }
118
+ } ) ;
119
+
120
+ res . status ( 200 ) . send ( "Receiving logs" ) ;
121
+ } ) ;
122
+
119
123
module . exports = router ;
0 commit comments