Skip to content

Commit 0da6410

Browse files
committed
Try more hosts in getaddrinfo
- The current method apparently may fail on Windows. - Reword "Connected to TF2" to "Socket connected" - pointless formatting and bump minor version
1 parent fd326f4 commit 0da6410

File tree

3 files changed

+30
-14
lines changed

3 files changed

+30
-14
lines changed

demomgr/dialogues/play.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ def _rcon_send_gototick(self) -> None:
700700
def _launch(self) -> None:
701701
for cond, name in (
702702
(self.cfg.steam_path is None, "Steam"),
703-
(self.usehlae_var.get() and self.cfg.hlae_path is None, "HLAE")
703+
(self.usehlae_var.get() and self.cfg.hlae_path is None, "HLAE"),
704704
):
705705
if cond:
706706
tk_msg.showerror(

demomgr/main_app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from demomgr.tk_widgets import DmgrEntry, KeyValueDisplay, HeadedFrame, purge_commands
2727

2828

29-
__version__ = "1.11.0"
29+
__version__ = "1.11.1"
3030
__author__ = "Square789"
3131

3232

demomgr/threads/rcon.py

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,36 @@ def run(self):
7777
self.queue_out_put(THREADSIG.FAILURE)
7878
return
7979

80-
self.queue_out_put(THREADSIG.INFO_IDX_PARAM, 0, f"Connecting to TF2 (port {self.port})...")
81-
try:
82-
potential_targets = socket.getaddrinfo(socket.getfqdn(), self.port, socket.AF_INET)
83-
except OSError as error:
80+
self.queue_out_put(THREADSIG.INFO_IDX_PARAM, 0, f"Connecting on port {self.port}...")
81+
82+
potential_targets = []
83+
target_gathering_errors = []
84+
for hostname in ("127.0.0.1", "localhost", None):
85+
try:
86+
rhostname = socket.getfqdn() if hostname is None else hostname
87+
except OSError as error:
88+
target_gathering_errors.append(error)
89+
continue
90+
91+
try:
92+
potential_targets.extend(socket.getaddrinfo(rhostname, self.port, socket.AF_INET))
93+
except OSError as error:
94+
target_gathering_errors.append(error)
95+
continue
96+
97+
if not potential_targets:
8498
self.queue_out_put(
8599
THREADSIG.INFO_IDX_PARAM,
86100
0,
87-
f"Obscure error getting machine address: {error}"
101+
f"Failed gathering connection candidates: {target_gathering_errors}",
88102
)
89103
self.queue_out_put(THREADSIG.FAILURE)
90104
return
91105

92-
for idx, value in enumerate(potential_targets):
93-
af, type_, proto, _, addr = value
94-
self._socket = error = None
106+
error = None
107+
for idx, (af, type_, proto, _, addr) in enumerate(potential_targets):
108+
error = None
109+
self._socket = None
95110
self.queue_out_put(
96111
THREADSIG.INFO_IDX_PARAM,
97112
0,
@@ -116,7 +131,8 @@ def run(self):
116131

117132
if error is not None:
118133
self.queue_out_put(
119-
THREADSIG.INFO_IDX_PARAM, 0,
134+
THREADSIG.INFO_IDX_PARAM,
135+
0,
120136
f"Failure establishing connection. {MAKE_SURE}: {error}"
121137
)
122138
self.queue_out_put(THREADSIG.FAILURE)
@@ -126,7 +142,7 @@ def run(self):
126142
self.__stopsock(THREADSIG.ABORTED)
127143
return
128144

129-
self.queue_out_put(THREADSIG.INFO_IDX_PARAM, 0, "Connected to TF2")
145+
self.queue_out_put(THREADSIG.INFO_IDX_PARAM, 0, "Socket connected")
130146
self.queue_out_put(THREADSIG.INFO_IDX_PARAM, 1, "Authenticating...")
131147
try:
132148
authpacket = RCONPacket(622521, AUTH, encoded_pwd)
@@ -141,7 +157,7 @@ def run(self):
141157
self.queue_out_put(
142158
THREADSIG.INFO_IDX_PARAM,
143159
1,
144-
f"Failure sending auth packet. {MAKE_SURE}: {e}"
160+
f"Failure sending auth packet. {MAKE_SURE}: {e}",
145161
)
146162
self.__stopsock(THREADSIG.FAILURE)
147163
return
@@ -167,7 +183,7 @@ def run(self):
167183
self.queue_out_put(
168184
THREADSIG.INFO_IDX_PARAM,
169185
1,
170-
f"Error while authenticating. {MAKE_SURE}: {e}"
186+
f"Error while authenticating. {MAKE_SURE}: {e}",
171187
)
172188
self.__stopsock(THREADSIG.FAILURE)
173189
return

0 commit comments

Comments
 (0)