-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathinstance.py
89 lines (71 loc) · 2.69 KB
/
instance.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
from __future__ import annotations
from core import DataObject
from core.data.node import FatalException
from dataclasses import dataclass, field
from typing import Optional, TYPE_CHECKING
if TYPE_CHECKING:
from core import Server
__all__ = [
"Instance",
"InstanceBusyError"
]
class InstanceBusyError(Exception):
def __init__(self):
super().__init__("There is a server assigned to this instance atm.")
@dataclass
class Instance(DataObject):
locals: dict = field(repr=False, default_factory=dict)
_server: Optional[Server] = field(compare=False, repr=False, default=None, init=False)
missions_dir: str = field(repr=False, init=False, default=None)
@property
def home(self) -> str:
raise NotImplementedError()
@property
def dcs_host(self) -> str:
if self.server:
return self.server.settings.get('bind_address') or '127.0.0.1'
else:
return "127.0.0.1"
@property
def dcs_port(self) -> int:
if self.server:
port = int(self.server.settings.get('port', 10308))
else:
port = int(self.locals.get('dcs_port', 10308))
if port < 1024:
self.log.warning(f"The DCS port of instance {self.name} is < 1024. "
f"You need to run this server as Administrator!")
elif port > 65535:
raise FatalException(f"The DCS port of instance {self.name} is > 65535!")
return port
@property
def webgui_port(self) -> int:
webgui_port = int(self.locals.get('webgui_port', 8088))
if webgui_port < 1024:
self.log.warning(f"The WebGUI-port of instance {self.name} is < 1024. "
f"You need to run this server as Administrator!")
elif webgui_port > 65535:
raise FatalException(f"The WebGUI-port of instance {self.name} is > 65535!")
return webgui_port
@property
def bot_port(self) -> int:
bot_port = int(self.locals.get('bot_port', 6666))
if bot_port < 1024 or bot_port > 65535:
raise FatalException(f"The bot-port of instance {self.name} needs to be between 1024 and 65535!")
return bot_port
@property
def extensions(self) -> dict:
return self.locals.get('extensions') or {}
@property
def server_user(self) -> str:
return self.locals.get('server_user', 'Admin')
@property
def server(self) -> Optional[Server]:
return self._server
@server.setter
def server(self, server: Optional[Server]):
self.set_server(server)
def set_server(self, server: Optional[Server]):
self._server = server
def prepare(self):
raise NotImplemented()