Skip to content

Commit db0c46d

Browse files
committed
New version 3.0.4.0
ENHANCEMENTS: - Squadron credits added - /squadron credits added - Lua: dcsbot.addSquadronPoints() / dcsbot.getSquadronPoints() / dcsbot.listSquadrons() added - Lua: dcsbot.getUserRoles() added to retrieve the roles of the user in mission. - Competitive: auto-join to matches added, win-types added. CHANGES: - MissionStats: changed to dynamic event names - MizEdit: can work better with variables now, performance improved syntax support for lists/searches - People can only be a member of ONE squadron at a time now! - CreditSystem: Squadrons will receive points on kills now for each squadron member. - Competitive: new event onMatchFinished to be used in other plugins BUGFIXES: - Competitive: match finish check was not activated
1 parent 9ff47b9 commit db0c46d

File tree

31 files changed

+981
-444
lines changed

31 files changed

+981
-444
lines changed

core/data/impl/serverimpl.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,8 @@ async def apply_mission_changes(self, filename: Optional[str] = None, *, use_ori
732732
orig_filename = utils.get_orig_file(new_filename)
733733
# and copy the orig file over
734734
shutil.copy2(orig_filename, new_filename)
735+
elif new_filename != filename:
736+
shutil.copy2(filename, new_filename)
735737
try:
736738
# process all mission modifications
737739
dirty = False
@@ -807,9 +809,17 @@ async def uploadMission(self, filename: str, url: str, *, missions_dir: str = No
807809
async def modifyMission(self, filename: str, preset: Union[list, dict], use_orig: bool = True) -> str:
808810
from extensions.mizedit import MizEdit
809811

812+
# create a writable mission
813+
new_filename = utils.create_writable_mission(filename)
810814
if use_orig:
811-
filename = utils.get_orig_file(filename)
812-
return await MizEdit.apply_presets(self, filename, preset)
815+
# get the orig file
816+
orig_filename = utils.get_orig_file(new_filename)
817+
# and copy the orig file over
818+
shutil.copy2(orig_filename, new_filename)
819+
elif new_filename != filename:
820+
shutil.copy2(filename, new_filename)
821+
await MizEdit.apply_presets(self, new_filename, preset)
822+
return new_filename
813823

814824
async def persist_settings(self):
815825
config_file = os.path.join(self.node.config_dir, 'servers.yaml')
@@ -937,22 +947,17 @@ async def loadMission(self, mission: Union[int, str], modify_mission: Optional[b
937947
if not mission:
938948
return False
939949
if use_orig:
940-
# now determine the original mission name
950+
new_filename = utils.create_writable_mission(mission)
941951
orig_mission = utils.get_orig_file(mission)
942-
# check if the orig file has been replaced
943-
if os.path.exists(orig_mission) and os.path.getmtime(orig_mission) > os.path.getmtime(mission):
944-
new_filename = utils.create_writable_mission(mission)
945-
# we can't write the original one, so use the copy
946-
if new_filename != mission:
947-
shutil.copy2(orig_mission, new_filename)
948-
await self.replaceMission(start_index, new_filename)
949-
else:
950-
shutil.copy2(orig_mission, mission)
951-
return await self.loadMission(start_index, modify_mission=modify_mission)
952-
else:
952+
shutil.copy2(orig_mission, new_filename)
953+
if new_filename != mission:
954+
await self.replaceMission(start_index, new_filename)
955+
return await self.loadMission(start_index, modify_mission=modify_mission)
956+
elif modify_mission:
953957
# don't use the orig file, still make sure we have a writable mission
954958
new_filename = utils.create_writable_mission(mission)
955959
if new_filename != mission:
960+
shutil.copy2(mission, new_filename)
956961
await self.replaceMission(start_index, new_filename)
957962
return await self.loadMission(start_index, modify_mission=modify_mission)
958963

core/mizfile.py

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,10 @@ def get_dir_path(name):
149149
finally:
150150
os.remove(tmpname)
151151

152-
def apply_preset(self, preset: Union[dict, list]):
152+
def apply_preset(self, preset: Union[dict, list], **kwargs):
153153
if isinstance(preset, list):
154154
for _preset in preset:
155-
self.apply_preset(_preset)
155+
self.apply_preset(_preset, **kwargs)
156156
return
157157

158158
for key, value in preset.items():
@@ -189,7 +189,7 @@ def apply_preset(self, preset: Union[dict, list]):
189189
else:
190190
self.log.warning("Value 'clouds', str or dict required.")
191191
elif key == 'modify':
192-
self.modify(value)
192+
self.modify(value, **kwargs)
193193
else:
194194
converted_value = int(value) if isinstance(value, str) and value.isdigit() else value
195195
try:
@@ -512,7 +512,7 @@ def parse_moment(self, value: str = "morning") -> int:
512512

513513
return (base_time.hour * 3600) + (base_time.minute * 60)
514514

515-
def modify(self, config: Union[list, dict]) -> None:
515+
def modify(self, config: Union[list, dict], **kwargs) -> None:
516516

517517
def sort_dict(d):
518518
sorted_items = sorted(d.items())
@@ -545,10 +545,18 @@ def process_elements(reference: dict, **kwargs):
545545
elif 'replace' in config:
546546
sort = False
547547
for _what, _with in config['replace'].items():
548-
if isinstance(_with, str):
549-
_with = utils.evaluate(_with, reference=reference, **kkwargs, **kwargs)
550548
if debug:
551-
self.log.debug(f"Replacing {_what} with {_with}")
549+
if isinstance(_with, str):
550+
_w = utils.evaluate(_with, reference=reference, **kkwargs, **kwargs)
551+
elif isinstance(_with, list):
552+
_w = [utils.evaluate(x, reference=reference, **kkwargs, **kwargs) for x in _with]
553+
elif isinstance(_with, dict):
554+
_w = {}
555+
for k, v in _with.items():
556+
_w[k] = utils.evaluate(v, reference=reference, **kkwargs, **kwargs)
557+
else:
558+
_w = _with
559+
self.log.debug(f"Replacing {_what} with {_w}")
552560
if isinstance(_what, int) and isinstance(element, (list, dict)):
553561
if isinstance(element, list):
554562
try:
@@ -560,17 +568,29 @@ def process_elements(reference: dict, **kwargs):
560568
element[_what] = utils.evaluate(_with, reference=reference, **kkwargs, **kwargs)
561569
sort = True
562570
elif isinstance(_with, dict) and isinstance(element[_what], (int, str, float, bool)):
563-
for key, value in _with.items():
564-
if utils.evaluate(key, reference=reference):
565-
element[_what] = utils.evaluate(value, reference=reference, **kkwargs, **kwargs)
571+
for k, v in _with.items():
572+
if utils.evaluate(k, reference=reference):
573+
element[_what] = utils.evaluate(v, reference=reference, **kkwargs, **kwargs)
566574
break
575+
elif isinstance(_with, list):
576+
element[_what] = [utils.evaluate(x, reference=reference, **kkwargs, **kwargs) for x in _with]
567577
else:
568578
element[_what] = utils.evaluate(_with, reference=reference, **kkwargs, **kwargs)
569579
if sort:
570580
sort_dict(element)
571581
elif 'merge' in config:
572582
for _what, _with in config['merge'].items():
573583
if debug:
584+
if isinstance(_with, str):
585+
_w = utils.evaluate(_with, reference=reference, **kkwargs, **kwargs)
586+
elif isinstance(_with, list):
587+
_w = [utils.evaluate(x, reference=reference, **kkwargs, **kwargs) for x in _with]
588+
elif isinstance(_with, dict):
589+
_w = {}
590+
for k, v in _with.items():
591+
_w[k] = utils.evaluate(v, reference=reference, **kkwargs, **kwargs)
592+
else:
593+
_w = _with
574594
self.log.debug(f"Merging {_what} with {_with}")
575595
if isinstance(_with, dict):
576596
if not element[_what]:
@@ -581,6 +601,9 @@ def process_elements(reference: dict, **kwargs):
581601
for value in utils.for_each(source, _with[1:].split('/'), debug=debug, **kwargs):
582602
if isinstance(element[_what], dict):
583603
element[_what] |= value
604+
elif isinstance(element[_what], list):
605+
# attention: merge of lists is not supported, as they need to keep the order
606+
element[_what] = value
584607
else:
585608
element[_what] += value
586609
if _with.startswith('/'):
@@ -642,7 +665,6 @@ def check_where(reference: dict, config: Union[list, str], debug: bool, **kwargs
642665
self.log.error(f"File {file} can not be changed.")
643666
return
644667

645-
kwargs = {}
646668
# check if we need to import stuff
647669
for imp in config.get('imports', []):
648670
try:

core/utils/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77
from core.utils.mizedit import *
88
from core.utils.os import *
99
from core.utils.performance import *
10+
from core.utils.squadrons import *
1011
from core.utils.validators import *

0 commit comments

Comments
 (0)