Skip to content

Commit 558b5ab

Browse files
author
karel26
committed
Merge branch 'development'
2 parents ed66fd7 + 4a8bcce commit 558b5ab

File tree

6 files changed

+64
-26
lines changed

6 files changed

+64
-26
lines changed

COALITIONS.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,12 @@ My Fancy Server:
5151
# [...]
5252
channels:
5353
status: 1122334455667788
54-
chat: 8765432187654321 # general chat channel
54+
chat: 8765432187654321 # general chat channel
5555
admin: 8877665544332211
56-
blue: 1188227733664455 # chat channel for coalition blue
57-
red: 8811772266335544 # chat channel for coalition red
56+
blue: 1188227733664455 # chat channel for coalition blue
57+
blue_events: 987651234987651234 # Optional: to separate in-game event from chat messages (default: take blue instead).
58+
red: 8811772266335544 # chat channel for coalition red
59+
red_events: 123459876123459876 # Optional: same as blue_events for red.
5860
# [...]
5961
coalitions:
6062
lock_time: 1 day # time in which you are not allowed to move to the opposite coalition after leaving one coalition

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,7 @@ My Fancy Server: # Your server name, as displayed in the server l
430430
channels:
431431
status: 1122334455667788 # The Discord channel to display the server status embed and players embed into. Right-click on your channel and select "Copy Channel ID". You can disable it with -1
432432
chat: 8877665544332211 # The Discord channel for the in-game chat replication. You can disable it with setting it to -1.
433+
events: 1928374619283746 # Optional: if you want to split game events from chat messages, you can enable an optional events channel.
433434
admin: 1188227733664455 # The channel where you can fire admin commands to this server. You can decide if you want to have a central admin channel or server specific ones. See bot.yaml for more.
434435
voice: 1827364518273645 # The voice channel, where people need to connect to (if force_voice is true).
435436
chat_log:

core/commandline.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
parser.add_argument('-s', '--secret', action='store_true', help='Reveal all stored passwords')
2222
elif program == 'update.py':
2323
parser.add_argument('-n', '--node', help='Node name', default=platform.node())
24-
parser.add_argument('-d', '--delete', action='store_true', help='remove obsolete local files')
2524
parser.add_argument('-r', '--no-restart', action='store_true', default=False,
2625
help="don't start DCSServerBot after the update")
2726
elif program == 'install.py':

core/data/impl/nodeimpl.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ async def _upgrade_pending_non_git(self) -> bool:
386386
try:
387387
async with aiohttp.ClientSession() as session:
388388
async with session.get(REPO_URL) as response:
389+
response.raise_for_status()
389390
result = await response.json()
390391
current_version = re.sub('^v', '', __version__)
391392
latest_version = re.sub('^v', '', result[0]["tag_name"])
@@ -661,6 +662,7 @@ def has_timeout(row: dict, timeout: int):
661662
FROM cluster c LEFT OUTER JOIN nodes n
662663
ON c.guild_id = n.guild_id AND c.master = n.node
663664
WHERE c.guild_id = %s
665+
AND n.last_seen > (NOW() AT TIME ZONE 'UTC' - interval '1 minute')
664666
""", (self.guild_id, ))
665667
cluster = await cursor.fetchone()
666668
# No master there? we take it!

plugins/mission/listener.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -823,12 +823,14 @@ async def onMissionEvent(self, server: Server, data: dict) -> None:
823823
"menu": menu
824824
})
825825
elif data['eventName'] == 'S_EVENT_PLAYER_LEAVE_UNIT':
826-
group_id = data.get('initiator', {}).get('group', {}).get('id_')
827-
if group_id is not None:
828-
await server.send_to_dcs({
829-
"command": "deleteMenu",
830-
"groupID": group_id
831-
})
826+
initiator = data.get('initiator', {})
827+
if initiator:
828+
group_id = initiator.get('group', {}).get('id_')
829+
if group_id is not None:
830+
await server.send_to_dcs({
831+
"command": "deleteMenu",
832+
"groupID": group_id
833+
})
832834

833835
@chat_command(name='pause', help='pause the mission', roles=['DCS Admin', 'GameMaster'])
834836
async def pause(self, server: Server, player: Player, params: list[str]):

update.py

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import io
22
import os
33
import re
4+
from pathlib import Path
5+
46
import requests
57
import shutil
68
import subprocess
@@ -15,7 +17,7 @@
1517
from version import __version__
1618

1719

18-
def do_update_git(delete: Optional[bool]) -> int:
20+
def do_update_git() -> int:
1921
import git
2022

2123
try:
@@ -42,7 +44,7 @@ def do_update_git(delete: Optional[bool]) -> int:
4244
print(' Please run update.cmd manually.')
4345
return -1
4446
except git.exc.InvalidGitRepositoryError:
45-
return do_update_github(delete)
47+
return do_update_github()
4648
except git.exc.GitCommandError:
4749
print(' => Autoupdate failed!')
4850
print(' Please revert back the changes in these files:')
@@ -53,25 +55,56 @@ def do_update_git(delete: Optional[bool]) -> int:
5355
print('- No update found for DCSServerBot.')
5456
return 0
5557
except git.exc.InvalidGitRepositoryError:
56-
return do_update_github(delete)
58+
return do_update_github()
5759

5860

59-
def cleanup_local_files(to_delete_set: Iterable):
61+
def cleanup_local_files(to_delete_set: Iterable, extracted_folder: str):
6062
# Exclude directories from deletion
61-
# exclude_dirs = {'__pycache__', '.git', 'config', 'reports', 'sounds', 'services', 'extensions', 'plugins', 'logs'}
62-
exclude_dirs = {'__pycache__', '.git', 'config', 'reports', 'sounds', 'services', 'plugins', 'logs'}
63-
to_delete_set = {f for f in to_delete_set if not any(excluded_dir in f for excluded_dir in exclude_dirs)}
63+
root_exclude_dirs = {'__pycache__', '.git', 'config', 'reports', 'logs'}
64+
plugins_dir = Path('plugins')
65+
services_dir = Path('services')
66+
67+
to_delete_set = {f for f in to_delete_set if not any(excluded_dir in f for excluded_dir in root_exclude_dirs)}
6468

6569
# Delete each old file that is not in the updated directory.
6670
for relative_path in to_delete_set:
6771
full_path = os.path.join(os.getcwd(), relative_path)
72+
# Skip special handling for plugins and services if outside their context
73+
if plugins_dir in Path(relative_path).parents:
74+
# Delete only subdirectories inside `plugins` that exist in the zip
75+
sub_path = relative_path.replace(f"{plugins_dir}/", "") # Subpath inside plugins directory
76+
if not os.path.isdir(os.path.join(extracted_folder, plugins_dir, sub_path)):
77+
print(f" => Deleting {full_path} (from plugins directory)")
78+
if os.path.isfile(full_path):
79+
os.remove(full_path)
80+
elif os.path.isdir(full_path):
81+
shutil.rmtree(full_path)
82+
continue
83+
elif services_dir in Path(relative_path).parents:
84+
# Delete only subdirectories inside `services` that exist in zip
85+
sub_path = relative_path.replace(f"{services_dir}/", "") # Subpath inside services directory
86+
if not os.path.isdir(os.path.join(extracted_folder, services_dir, sub_path)):
87+
print(f" => Deleting {full_path} (from services directory)")
88+
if os.path.isfile(full_path):
89+
os.remove(full_path)
90+
elif os.path.isdir(full_path):
91+
shutil.rmtree(full_path)
92+
continue
93+
94+
# Delete rest normally
6895
if os.path.isfile(full_path):
6996
print(f" => Deleting {full_path}")
7097
os.remove(full_path)
98+
elif os.path.isdir(full_path):
99+
print(f" => Removing directory {full_path}")
100+
shutil.rmtree(full_path)
71101

72102

73-
def do_update_github(delete: Optional[bool] = False) -> int:
103+
def do_update_github() -> int:
74104
response = requests.get(f"https://api.github.com/repos/Special-K-s-Flightsim-Bots/DCSServerBot/releases")
105+
if response.status_code != 200:
106+
print(f' => Autoupdate failed: {response.reason} ({response.status_code})')
107+
return -2
75108
current_version = re.sub('^v', '', __version__)
76109
latest_version = re.sub('^v', '', response.json()[0]["tag_name"])
77110

@@ -91,12 +124,11 @@ def do_update_github(delete: Optional[bool] = False) -> int:
91124

92125
extracted_folder = os.path.join(temp_dir, os.listdir(temp_dir)[0]) # there is one folder
93126

94-
if delete:
95-
# check for necessary file deletions
96-
old_files_set = set(utils.list_all_files(os.getcwd()))
97-
new_files_set = set(utils.list_all_files(extracted_folder))
98-
to_delete_set = old_files_set - new_files_set
99-
cleanup_local_files(to_delete_set)
127+
# check for necessary file deletions
128+
old_files_set = set(utils.list_all_files(os.getcwd()))
129+
new_files_set = set(utils.list_all_files(extracted_folder))
130+
to_delete_set = old_files_set - new_files_set
131+
cleanup_local_files(to_delete_set, extracted_folder)
100132

101133
for root, dirs, files in os.walk(extracted_folder):
102134
for file in files:
@@ -124,9 +156,9 @@ def do_update_github(delete: Optional[bool] = False) -> int:
124156
# get the command line args from core
125157
args = COMMAND_LINE_ARGS
126158
try:
127-
rc = do_update_git(args.delete)
159+
rc = do_update_git()
128160
except ImportError:
129-
rc = do_update_github(args.delete)
161+
rc = do_update_github()
130162
if args.no_restart:
131163
exit(-2)
132164
else:

0 commit comments

Comments
 (0)