Skip to content

Commit e9f0aaa

Browse files
committed
BUGFIX:
- DCS bug workaround added for listStartIndex handling on empty mission lists
1 parent ad17fc0 commit e9f0aaa

File tree

5 files changed

+23
-9
lines changed

5 files changed

+23
-9
lines changed

core/data/impl/serverimpl.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,8 @@ def prepare(self):
296296
if self.settings.get('name', 'DCS Server') != self.name:
297297
self.settings['name'] = self.name
298298
# enable persistence
299-
if not self.settings.get('sav_autosave', False):
300-
self.settings['sav_autosave'] = True
299+
if not self.settings.get('advanced', {}).get('sav_autosave', False):
300+
self.settings.setdefault('advanced', {})['sav_autosave'] = True
301301
if 'serverSettings' in self.locals:
302302
for key, value in self.locals['serverSettings'].items():
303303
if key == 'advanced':

plugins/mission/commands.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ async def modify(self, interaction: discord.Interaction,
690690
server.on_empty = dict()
691691
startup = False
692692
msg = await interaction.followup.send(_('Changing mission ...'), ephemeral=ephemeral)
693-
if not server.locals.get('mission_rewrite', True) and server.status != Status.STOPPED:
693+
if not server.locals.get('mission_rewrite', True) and server.status in [Status.PAUSED, Status.RUNNING]:
694694
await server.stop()
695695
startup = True
696696
filename = await server.get_current_mission_file()

plugins/mission/lua/commands.lua

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,11 +260,12 @@ function dcsbot.addMission(json)
260260
end
261261
net.missionlist_append(path)
262262
local current_missions = net.missionlist_get()
263-
local listStartIndex
263+
local listStartIndex = current_missions["listStartIndex"]
264264
if json.autostart == true then
265265
listStartIndex = #current_missions['missionList']
266-
else
267-
listStartIndex = current_missions["listStartIndex"]
266+
-- workaround DCS bug
267+
elseif #current_missions['missionList'] < listStartIndex then
268+
listStartIndex = 1
268269
end
269270
utils.saveSettings({
270271
missionList = current_missions["missionList"],
@@ -277,9 +278,14 @@ function dcsbot.deleteMission(json)
277278
log.write('DCSServerBot', log.DEBUG, 'Mission: deleteMission()')
278279
net.missionlist_delete(json.id)
279280
local current_missions = net.missionlist_get()
281+
-- workaround DCS bug
282+
local listStartIndex = current_missions["listStartIndex"]
283+
if #current_missions['missionList'] < listStartIndex then
284+
listStartIndex = 1
285+
end
280286
utils.saveSettings({
281287
missionList = current_missions["missionList"],
282-
listStartIndex = current_missions["listStartIndex"]
288+
listStartIndex = listStartIndex
283289
})
284290
dcsbot.listMissions(json)
285291
end
@@ -291,8 +297,14 @@ function dcsbot.replaceMission(json)
291297
net.missionlist_append(json.path)
292298
net.missionlist_move(#current_missions["missionList"], tonumber(json.index))
293299
current_missions = net.missionlist_get()
300+
-- workaround DCS bug
301+
local listStartIndex = current_missions["listStartIndex"]
302+
if #current_missions['missionList'] < listStartIndex then
303+
listStartIndex = 1
304+
end
294305
utils.saveSettings({
295-
missionList = current_missions["missionList"]
306+
missionList = current_missions["missionList"],
307+
listStartIndex = listStartIndex
296308
})
297309
dcsbot.listMissions(json)
298310
end

plugins/mission/status.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,8 @@ async def render(self, server: Server):
206206
(server.name in listener.active_servers):
207207
text += '\n\n- User statistics are enabled.'
208208
break
209-
if (await server.get_current_mission_file()).endswith('.sav'):
209+
current_mission = await server.get_current_mission_file()
210+
if current_mission and current_mission.endswith('.sav'):
210211
text += '\n- Mission persistence is enabled.'
211212
text += f'\n\nLast updated: {datetime.now(timezone.utc):%y-%m-%d %H:%M:%S UTC}'
212213
self.embed.set_footer(text=text)

schemas/servers_schema.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ schema;settings_schema:
5454
event_Takeoff: {type: bool, nullable: false}
5555
bluePasswordHash: {type: str, nullable: false, range: {min: 1}}
5656
redPasswordHash: {type: str, nullable: false, range: {min: 1}}
57+
sav_autosave: {type: bool, nullable: false}
5758

5859
type: map
5960
mapping:

0 commit comments

Comments
 (0)