Skip to content

Commit

Permalink
Support for checking if Ground Control has password set
Browse files Browse the repository at this point in the history
  • Loading branch information
332fg-raven committed Apr 27, 2024
1 parent 8cefdb4 commit 3e05f23
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
7 changes: 7 additions & 0 deletions dcs/groundcontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ def unlock(self, coalition: Coalition, role: GroundControlRole) -> None:
role_password = self._find_role_password(role)
role_password[coalition] = None

def is_locked(self, coalition: Coalition, role: GroundControlRole) -> bool:
role_password = self._find_role_password(role)
return coalition in role_password and role_password[coalition] is not None

def dict(self) -> Dict[str, Dict[str, str]]:
d: Dict[str, Any] = {}
for coalition in [Coalition.Red, Coalition.Blue, Coalition.Neutral]:
Expand Down Expand Up @@ -115,6 +119,9 @@ def lock(self, coalition: Coalition, role: GroundControlRole, password: str) ->
def unlock(self, coalition: Coalition, role: GroundControlRole) -> None:
self.passwords.unlock(coalition, role)

def is_locked(self, coalition: Coalition, role: GroundControlRole) -> bool:
return self.passwords.is_locked(coalition, role)

def dict(self):
return {
"isPilotControlVehicles": self.pilot_can_control_vehicles,
Expand Down
3 changes: 3 additions & 0 deletions tests/test_mission.py
Original file line number Diff line number Diff line change
Expand Up @@ -1370,6 +1370,9 @@ def test_ground_control_password(self) -> None:
m.groundControl.lock(Coalition.Blue, GroundControlRole.OBSERVER, "p-observer-blue")
m.groundControl.lock(Coalition.Blue, GroundControlRole.TACTICAL_COMMANDER, "p-tc-blue")

self.assertTrue(m.groundControl.is_locked(Coalition.Blue, GroundControlRole.TACTICAL_COMMANDER))
self.assertFalse(m.groundControl.is_locked(Coalition.Red, GroundControlRole.TACTICAL_COMMANDER))

self.assertIn(Coalition.Blue.value,
m.groundControl.dict()["passwords"][GroundControlRole.TACTICAL_COMMANDER.value])
self.assertIn(Coalition.Blue.value,
Expand Down

0 comments on commit 3e05f23

Please sign in to comment.