Skip to content

Commit 2d890e8

Browse files
committed
CHANGES:
- SRS: added /srs repair - Tacview: added /tacview update, /tacview repair
1 parent 9aaca83 commit 2d890e8

File tree

6 files changed

+145
-28
lines changed

6 files changed

+145
-28
lines changed

extensions/srs/extension.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ async def handle_update(self):
586586
})
587587

588588
except Exception as ex:
589-
self.log.exception(ex)
589+
self.log.error(f"DCS-SRS update failed: {ex}", exc_info=ex)
590590

591591
@tasks.loop(minutes=30)
592592
async def schedule(self):

extensions/tacview/extension.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def set_option(self, options: dict, name: str, value: Any, default: Any | None =
128128
return False
129129

130130
async def prepare(self) -> bool:
131-
await self.update_instance(False)
131+
await self.handle_update()
132132
options = self.server.options['plugins']
133133
dirty = False
134134

@@ -445,14 +445,25 @@ async def uninstall(self) -> bool:
445445
self.log.info(f" => {self.name} {version} uninstalled from instance {self.server.instance.name}.")
446446
return True
447447

448-
async def update_instance(self, force: bool) -> bool:
448+
async def check_for_updates(self) -> str | None:
449449
version = self.get_inst_version()
450-
if parse(self.version) < parse(version):
451-
if force or self.config.get('autoupdate', False):
452-
if not await self.uninstall():
453-
return False
454-
if not await self.install():
455-
return False
450+
return version if parse(self.version) < parse(version) else None
451+
452+
async def do_update(self) -> bool:
453+
if not await self.uninstall():
454+
return False
455+
if not await self.install():
456+
return False
457+
return True
458+
459+
async def handle_update(self):
460+
# don't run if autoupdate is disabled
461+
if not self.config.get('autoupdate', False):
462+
return
463+
464+
version = await self.check_for_updates()
465+
if version:
466+
if await self.do_update():
456467
await ServiceRegistry.get(ServiceBus).send_to_node({
457468
"command": "rpc",
458469
"service": BotService.__name__,
@@ -462,11 +473,6 @@ async def update_instance(self, force: bool) -> bool:
462473
version=version, instance=self.server.instance.name)
463474
}
464475
})
465-
return True
466-
else:
467-
self.log.info(f" => {self.name}: Instance {self.server.instance.name} is running version "
468-
f"{self.version}, where {version} is available!")
469-
return False
470476

471477
async def get_ports(self) -> dict:
472478
return {

plugins/srs/README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ DEFAULT.
2525
## Discord Commands
2626
The following Discord commands are available through the SRS plugin:
2727
28-
| Command | Parameter | Channel | Role | Description |
29-
|-----------|---------------------|-----------------------|-----------------------|--------------------------------------------------------|
30-
| /srs list | | all | DCS | Shows active users on SRS with their connected radios. |
28+
| Command | Parameter | Channel | Role | Description |
29+
|-------------|-----------|---------|-----------|--------------------------------------------------------|
30+
| /srs list | | all | DCS | Shows active users on SRS with their connected radios. |
31+
| /srs update | server | all | DCS Admin | Updates SRS on the respective node. |
32+
| /srs repair | server | all | DCS Admin | Repairs (re-installs) SRS on the respective node. |

plugins/srs/commands.py

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,18 @@ async def update(self, interaction: discord.Interaction,
7575
# noinspection PyUnresolvedReferences
7676
await interaction.response.defer(ephemeral=ephemeral)
7777
await interaction.followup.send(_("DCS-SRS update to version {} available!").format(version))
78-
if not utils.yn_question(interaction, _("Do you want to update DCS-SRS now?")):
78+
if not await utils.yn_question(
79+
interaction,
80+
question=_("Do you want to update DCS-SRS now?"),
81+
message=_("This will terminate all DCS-SRS servers on node {}!").format(server.node.name)
82+
):
7983
await interaction.followup.send(_("Aborted."))
8084
return
81-
await server.run_on_extension(extension='SRS', method='do_update', version=version)
82-
await interaction.followup.send(_("DCS-SRS updated to version {}.").format(version))
85+
try:
86+
await server.run_on_extension(extension='SRS', method='do_update', version=version)
87+
await interaction.followup.send(_("DCS-SRS updated to version {}.").format(version))
88+
except Exception:
89+
await interaction.followup.send(_("Failed to update DCS-SRS. See log for defails."))
8390
else:
8491
# noinspection PyUnresolvedReferences
8592
await interaction.response.send_message(_("No update for DCS-SRS available."))
@@ -134,6 +141,41 @@ async def configure(self, interaction: discord.Interaction,
134141
_("Server {} needs to be shut down to configure SRS.").format(server.display_name),
135142
ephemeral=True)
136143

144+
@srs.command(description=_('Repair DCS-SRS'))
145+
@app_commands.guild_only()
146+
@app_commands.check(utils.restricted_check)
147+
@utils.app_has_role('DCS Admin')
148+
async def repair(self, interaction: discord.Interaction,
149+
server: app_commands.Transform[Server, utils.ServerTransformer(
150+
status=[Status.LOADING, Status.STOPPED, Status.RUNNING, Status.PAUSED])]):
151+
ephemeral = utils.get_ephemeral(interaction)
152+
try:
153+
data = await server.run_on_extension(extension='SRS', method='render')
154+
except ValueError:
155+
# noinspection PyUnresolvedReferences
156+
await interaction.response.send_message(_("Extension SRS is not loaded on server {}").format(
157+
server.display_name), ephemeral=True)
158+
return
159+
except NotImplementedError:
160+
# noinspection PyUnresolvedReferences
161+
await interaction.response.send_message(_("Extension SRS is not active on server {}").format(
162+
server.display_name), ephemeral=True)
163+
return
164+
165+
version = data['version']
166+
if not await utils.yn_question(
167+
interaction,
168+
question=_("Do you want to repair DCS-SRS now?"),
169+
message=_("This will terminate all DCS-SRS servers on node {}!").format(server.node.name)
170+
):
171+
await interaction.followup.send(_("Aborted."))
172+
return
173+
try:
174+
await server.run_on_extension(extension='SRS', method='do_update', version=version)
175+
await interaction.followup.send(_("DCS-SRS repaired on node {}.").format(server.node.name))
176+
except Exception:
177+
await interaction.followup.send(_("Failed to update DCS-SRS. See log for defails."))
178+
137179

138180
async def setup(bot: DCSServerBot):
139181
if 'missionstats' not in bot.plugins:

plugins/tacview/README.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ The additional configuration is handled in the [extension](../../extensions/tacv
1414
## Discord Commands
1515
The following Discord commands are available through the LotAtc plugin:
1616
17-
| Command | Parameter | Channel | Role | Description |
18-
|:----------------------|:--------------|:--------|:----------|:-------------------------------------------------------------------------------------------|
19-
| /tacview install | server | all | DCS Admin | Install Tacview into this server (needs to be available on the node). |
20-
| /tacview uninstall | server | all | DCS Admin | Uninstall Tacview from this server. |
21-
| /tacview configure | server | all | DCS Admin | Change the Tacview configuration on this server. |
22-
| /tacview download | server file | all | DCS | Download a server or player Tacview file. |
23-
| /tacview record_start | server [file] | all | DCS Admin | Start a temporary Tacview recording. |
24-
| /tacview record_stop | server | all | DCS Admin | Stop the temporary Tacview recording. If a target is specified, the file will be uploaded. |
17+
| Command | Parameter | Channel | Role | Description |
18+
|:----------------------|:--------------|:--------|:----------|:---------------------------------------------------------------------------------------------------------------|
19+
| /tacview install | server | all | DCS Admin | Install Tacview into this server (needs to be available on the node). |
20+
| /tacview uninstall | server | all | DCS Admin | Uninstall Tacview from this server. |
21+
| /tacview update | server | all | DCS Admin | Update the Tacview version in this instance (only possible if a newer Tacview version is installed on the PC). |
22+
| /tacview repair | server | all | DCS Admin | Reinstall Tacview on the respective instance. Same as /tacview uninstall + /tacview install. |
23+
| /tacview configure | server | all | DCS Admin | Change the Tacview configuration on this server. |
24+
| /tacview download | server file | all | DCS | Download a server or player Tacview file. |
25+
| /tacview record_start | server [file] | all | DCS Admin | Start a temporary Tacview recording. |
26+
| /tacview record_stop | server | all | DCS Admin | Stop the temporary Tacview recording. If a target is specified, the file will be uploaded. |

plugins/tacview/commands.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,71 @@ async def record_stop(self, interaction: discord.Interaction,
217217
except Exception as ex:
218218
await interaction.followup.send(str(ex))
219219

220+
@tacview.command(description=_('Update Tacview'))
221+
@app_commands.guild_only()
222+
@app_commands.check(utils.restricted_check)
223+
@utils.app_has_role('DCS Admin')
224+
async def update(self, interaction: discord.Interaction,
225+
server: app_commands.Transform[Server, utils.ServerTransformer(status=[Status.SHUTDOWN])]):
226+
ephemeral = utils.get_ephemeral(interaction)
227+
# noinspection PyUnresolvedReferences
228+
await interaction.response.defer(ephemeral=ephemeral)
229+
230+
if 'Tacview' not in await server.init_extensions():
231+
await interaction.followup.send(_("Tacview not installed on server {}!").format(server.display_name),
232+
ephemeral=True)
233+
return
234+
try:
235+
version = await server.run_on_extension(extension='Tacview', method='check_for_updates')
236+
if version:
237+
await interaction.followup.send(_("Tacview update to version {} available!").format(version))
238+
if not await utils.yn_question(interaction, _("Do you want to update Tacview now?")):
239+
await interaction.followup.send(_("Aborted."))
240+
return
241+
242+
msg = await interaction.followup.send(
243+
_("Updating Tacview on server {} ...").format(server.display_name), ephemeral=ephemeral)
244+
if await server.run_on_extension(extension='Tacview', method='do_update'):
245+
await msg.edit(content=_("Tacview updated to version {}.").format(version))
246+
else:
247+
await msg.edit(content=_("Tacview update failed. See log for details."))
248+
else:
249+
# noinspection PyUnresolvedReferences
250+
await interaction.response.send_message(_("No update for Tacview available."))
251+
except Exception:
252+
await interaction.followup.send(_("Tacview update failed. See log for details."))
253+
254+
@tacview.command(description=_('Repair Tacview'))
255+
@app_commands.guild_only()
256+
@app_commands.check(utils.restricted_check)
257+
@utils.app_has_role('DCS Admin')
258+
async def repair(self, interaction: discord.Interaction,
259+
server: app_commands.Transform[Server, utils.ServerTransformer(status=[Status.SHUTDOWN])]):
260+
ephemeral = utils.get_ephemeral(interaction)
261+
# noinspection PyUnresolvedReferences
262+
await interaction.response.defer(ephemeral=ephemeral)
263+
if 'Tacview' not in await server.init_extensions():
264+
await interaction.followup.send(_("Tacview not installed on server {}!").format(server.display_name),
265+
ephemeral=True)
266+
return
267+
268+
if not await utils.yn_question(interaction, _("Do you want to repair Tacview?")):
269+
await interaction.followup.send(_("Aborted."))
270+
return
271+
if server.status in [Status.STOPPED, Status.SHUTDOWN]:
272+
msg = await interaction.followup.send(
273+
_("Repairing Tacview on server {} ...").format(server.display_name), ephemeral=ephemeral)
274+
try:
275+
await server.uninstall_extension(name="Tacview")
276+
await server.install_extension(name="Tacview", config={})
277+
await msg.edit(content=_("Tacview repaired on server {}.").format(server.display_name))
278+
except (UninstallException, InstallException):
279+
await msg.edit(_("Tacview could not be repaired on server {}!").format(server.display_name))
280+
else:
281+
await interaction.followup.send(
282+
_("Server {} needs to be shut down to repair Tacview.").format(server.display_name),
283+
ephemeral=True)
284+
220285

221286
async def setup(bot: DCSServerBot):
222287
await bot.add_cog(Tacview(bot))

0 commit comments

Comments
 (0)