@@ -6,6 +6,7 @@ var cfg = require('./configClass.js');
6
6
var serverInfo = require ( './serverInfo.js' ) ;
7
7
var controlEmitter = require ( './controlEmitter.js' ) ;
8
8
const config = require ( '../config.js' ) ;
9
+ const { response } = require ( 'express' ) ;
9
10
10
11
rconQ = new queue ( { "autostart" : true , "timeout" : 500 , "concurrency" : 1 } ) ;
11
12
@@ -90,12 +91,12 @@ async function reloadMaplist() {
90
91
} )
91
92
resolve ( colMaps ) ;
92
93
} catch ( e ) {
93
- reject ( [ ] ) ;
94
+ reject ( e ) ;
94
95
}
95
96
} ) ;
96
97
} ) . on ( 'error' , ( error ) => {
97
98
logger . warn ( `Steam Workshop Collection request failed: ${ error } ` ) ;
98
- reject ( [ ] ) ;
99
+ reject ( error ) ;
99
100
} ) ;
100
101
} ) ;
101
102
}
@@ -133,7 +134,7 @@ async function reloadMaplist() {
133
134
"name" : _mapName ,
134
135
"official" : official ,
135
136
"title" : details . title ,
136
- "workshopID" : details . publishedfileid ,
137
+ "workshopID" : details . publishedfileid . toString ( ) ,
137
138
"description" : details . description ,
138
139
"previewLink" : details . preview_url ,
139
140
"tags" : details . tags } )
@@ -147,12 +148,38 @@ async function reloadMaplist() {
147
148
} ) ;
148
149
} ) . on ( 'error' , ( error ) => {
149
150
logger . warn ( `Steam Workshop Maps Request failed: ${ error } ` ) ;
150
- reject ( [ ] ) ;
151
+ reject ( error ) ;
151
152
} ) ;
152
153
153
154
} ) ;
154
155
}
155
156
157
+ function getWorkshopCollectionMapsFromServer ( ) {
158
+ return new Promise ( ( resolve , reject ) => {
159
+ executeRcon ( 'ds_workshop_listmaps ' ) . then ( ( response ) => {
160
+ let mapArray = response . split ( / \r ? \n / ) ;
161
+ let details = [ ] ;
162
+ mapArray . forEach ( ( value ) => {
163
+ mapdetails . push ( {
164
+ "name" : value ,
165
+ "official" : false ,
166
+ "title" : value ,
167
+ "workshopID" : "" ,
168
+ "description" : "" ,
169
+ "previewLink" : "" ,
170
+ "tags" : [ ] ,
171
+ } ) ;
172
+ } ) ;
173
+
174
+ resolve ( details ) ;
175
+ } ) . catch ( ( err ) => {
176
+ logger . warn ( `Could not get workshop collection maps from server: ${ err } ` ) ;
177
+ reject ( err ) ;
178
+ } ) ;
179
+ } ) ;
180
+ }
181
+
182
+
156
183
157
184
// Available maps will be built from OfficialMaps.json static file,
158
185
// workshop collection and mapsfrom config.
@@ -172,25 +199,59 @@ async function reloadMaplist() {
172
199
mapdetails = await getMapDetails ( officialMapIds , true ) ;
173
200
} catch ( error ) {
174
201
logger . warn ( `Getting official maps details failed: ${ error } ` ) ;
202
+ logger . warn ( 'Falling back to name and ID only' ) ;
203
+ // As fallback use name and id from local file.
204
+ let alternateDetails = [ ] ;
205
+ omJson . forEach ( ( map ) => {
206
+ alternateDetails . push ( {
207
+ "name" : map . name ,
208
+ "official" : true ,
209
+ "title" : map . name ,
210
+ "workshopID" : map . id ,
211
+ "description" : "" ,
212
+ "previewLink" : "" ,
213
+ "tags" : [ ] ,
214
+ } ) ;
215
+ } ) ;
216
+ mapdetails = alternateDetails ;
175
217
}
176
-
218
+
177
219
if ( cfg . workshopCollection != '' ) {
178
220
logger . debug ( "getting collection ids" ) ;
179
221
try {
180
222
workshopMapIds = await getWorkshopCollection ( cfg . workshopCollection ) ;
181
223
} catch ( error ) {
182
- logger . warn ( `Getting Workshop map IDs failed: ${ error } ` ) ;
224
+ logger . warn ( `Getting Workshop map IDs failed: ${ error }
225
+ Trying to get names from server.` ) ;
226
+ // As a fallback try to get workshop maps from server via rcon command.
227
+ try {
228
+ mapdetails . push ( ...await getWorkshopCollectionMapsFromServer ( ) ) ;
229
+ } catch ( err ) {
230
+ logger . warn ( `Loading workshop maps from server failed: ${ err }
231
+ Workshop maps not available.` ) ;
232
+ }
183
233
}
184
234
}
185
235
workshopMapIds . push ( ...cfg . workshopMaps ) ;
186
236
187
- logger . debug ( "getting workshop maps" ) ;
188
- try {
189
- mapdetails . push ( ...await getMapDetails ( workshopMapIds , false ) ) ;
190
- } catch ( error ) {
191
- logger . warn ( `Getting Workshop maps details failed: ${ error } ` ) ;
237
+ if ( workshopMapIds . length > 0 ) {
238
+ logger . debug ( "getting workshop maps details" ) ;
239
+ try {
240
+ mapdetails . push ( ...await getMapDetails ( workshopMapIds , false ) ) ;
241
+ } catch ( error ) {
242
+ logger . warn ( `Getting Workshop maps details failed: ${ error } ` ) ;
243
+ // As a fallback try to get workshop maps from server via rcon command.
244
+ try {
245
+ mapdetails . push ( ...await getWorkshopCollectionMapsFromServer ( ) ) ;
246
+ } catch ( err ) {
247
+ logger . warn ( `Loading workshop maps from server failed: ${ err }
248
+ Workshop maps not available.` ) ;
249
+ }
250
+ }
251
+ }
252
+ if ( mapdetails . length > 1 ) {
253
+ mapdetails . sort ( ( a , b ) => a . title . localeCompare ( b . title ) ) ;
192
254
}
193
- // mapdetails.sort((a, b) => a.name.localeCompare(b.title));
194
255
195
256
serverInfo . mapsDetails = mapdetails ;
196
257
// TODO: Check if this is still needed.
0 commit comments